Lumiera  0.pre.03
»edit your freedom«
display-service.cpp
Go to the documentation of this file.
1 /*
2  DisplayService - service providing access to a display for outputting frames
3 
4  Copyright (C)
5  2009, Hermann Vosseler <Ichthyostega@web.de>
6 
7   **Lumiera** is free software; you can redistribute it and/or modify it
8   under the terms of the GNU General Public License as published by the
9   Free Software Foundation; either version 2 of the License, or (at your
10   option) any later version. See the file COPYING for further details.
11 
12 * *****************************************************************/
13 
14 
27 #include "lib/depend.hpp"
28 
29 extern "C" {
31 }
32 
33 
34 namespace stage {
35 
36 
37 
38  namespace { // hidden local details of the service implementation....
39 
40 
41 
42  /* ================== define an lumieraorg_Display instance ======================= */
43 
44  LUMIERA_INTERFACE_INSTANCE (lumieraorg_interfacedescriptor, 0
45  ,lumieraorg_DisplayFacade_descriptor
46  , NULL, NULL, NULL
47  , LUMIERA_INTERFACE_INLINE (name,
48  const char*, (LumieraInterface ifa),
49  { (void)ifa; return "Display"; }
50  )
51  , LUMIERA_INTERFACE_INLINE (brief,
52  const char*, (LumieraInterface ifa),
53  { (void)ifa; return "UI Interface: service for outputting frames to a viewer or display"; }
54  )
55  , LUMIERA_INTERFACE_INLINE (homepage,
56  const char*, (LumieraInterface ifa),
57  { (void)ifa; return "http://www.lumiera.org/develompent.html" ;}
58  )
59  , LUMIERA_INTERFACE_INLINE (version,
60  const char*, (LumieraInterface ifa),
61  { (void)ifa; return "0.1~pre"; }
62  )
63  , LUMIERA_INTERFACE_INLINE (author,
64  const char*, (LumieraInterface ifa),
65  { (void)ifa; return "Hermann Vosseler"; }
66  )
67  , LUMIERA_INTERFACE_INLINE (email,
68  const char*, (LumieraInterface ifa),
69  { (void)ifa; return "Ichthyostega@web.de"; }
70  )
71  , LUMIERA_INTERFACE_INLINE (copyright,
72  const char*, (LumieraInterface ifa),
73  {
74  (void)ifa;
75  return
76  "Copyright (C)\n"
77  " 2009, Hermann Vosseler <Ichthyostega@web.de>";
78  }
79  )
80  , LUMIERA_INTERFACE_INLINE (license,
81  const char*, (LumieraInterface ifa),
82  {
83  (void)ifa;
84  return
85  "**Lumiera** is free software; you can redistribute it and/or modify it\n"
86  "under the terms of the GNU General Public License as published by the\n"
87  "Free Software Foundation; either version 2 of the License, or (at your\n"
88  "option) any later version. See the file COPYING for further details."
89  ;
90  }
91  )
92  , LUMIERA_INTERFACE_INLINE (state,
93  int, (LumieraInterface ifa),
94  {(void)ifa; return LUMIERA_INTERFACE_EXPERIMENTAL; }
95  )
96  , LUMIERA_INTERFACE_INLINE (versioncmp,
97  int, (const char* a, const char* b),
98  {(void)a;(void)b; return 0;}
99  )
100  );
101 
102 
103 
104 
105 
106  using LERR_(LIFECYCLE);
107 
109 
110 
111 
112  LUMIERA_INTERFACE_INSTANCE (lumieraorg_Display, 0
113  ,lumieraorg_DisplayService
114  , LUMIERA_INTERFACE_REF(lumieraorg_interfacedescriptor, 0, lumieraorg_DisplayFacade_descriptor)
115  , NULL /* on open */
116  , NULL /* on close */
117  , LUMIERA_INTERFACE_INLINE (allocate,
118  void, (LumieraDisplaySlot slotHandle),
119  {
120  if (!_instance)
121  {
122  lumiera_error_set (LUMIERA_ERROR_LIFECYCLE, 0);
123  return;
124  }
125 
126  REQUIRE (slotHandle);
127  try
128  {
129  _instance().allocate (slotHandle,true);
130  }
131  catch (lumiera::Error&){ /* error state remains set */ }
132  }
133  )
134  , LUMIERA_INTERFACE_INLINE (release,
135  void, (LumieraDisplaySlot slotHandle),
136  {
137  if (!_instance)
138  {
139  lumiera_error_set (LUMIERA_ERROR_LIFECYCLE, 0);
140  return;
141  }
142 
143  REQUIRE (slotHandle);
144  _instance().allocate (slotHandle,false);
145  }
146  )
147  , LUMIERA_INTERFACE_INLINE (put,
148  void, (LumieraDisplaySlot slotHandle, LumieraDisplayFrame frame),
149  {
150  //skipping full checks for performance reasons
151  REQUIRE (_instance && !lumiera_error_peek());
152 
153  REQUIRE (slotHandle);
154  DisplayerSlot& slot = _instance().resolve (slotHandle);
155  slot.put (frame);
156  }
157  )
158  );
159 
160 
161 
162 
163  } // (End) hidden service impl details
164 
165 
166 
167 
168  DisplayService::DisplayService()
169  : error_{}
170  , serviceInstance_( LUMIERA_INTERFACE_REF (lumieraorg_Display, 0, lumieraorg_DisplayService))
171  {
172  INFO (progress, "Display Facade opened.");
173  }
174 
175 
176 
177  LumieraDisplaySlot
178  DisplayService::setUp (FrameDestination const& outputDestination)
179  {
180  DisplayerTab& slots (_instance().slots_);
181  return &slots.manage (new DisplayerSlot (outputDestination));
182  }
183 
184 
185 
186  void
187  DisplayService::allocate (LumieraDisplaySlot handle, bool doAllocate)
188  {
189  REQUIRE (handle);
190  if (doAllocate)
191  {
192  if (handle->put_)
193  throw lumiera::error::Logic("slot already allocated for output");
194  else
195  // Mark the handle as "allocated" and ready for output:
196  // Place the function pointer from the C interface into the handle struct.
197  // calling it will invoke the implementing instance's "put" function
198  // (see the LUMIERA_INTERFACE_INLINE above in this file!)
199  handle->put_ = serviceInstance_.get().put;
200  }
201  else
202  handle->put_ = 0;
203  }
204 
205 
206 
207  DisplayerSlot&
208  DisplayService::resolve (LumieraDisplaySlot handle)
209  {
210  REQUIRE (handle);
211  REQUIRE (handle->put_, "accessing a DisplayerSlot, which hasn't been locked for output");
212 
213  return *static_cast<DisplayerSlot*> (handle);
214  }
215 
216 
217 
218 
219 
220  /* === DisplayerSlot Implementation === */
221 
222 
223  DisplayerSlot::DisplayerSlot (FrameDestination const& outputDestination)
224  : currBuffer_(0)
225  {
226  put_ = 0; // mark as not allocated
227  hasFrame_.connect (outputDestination);
228  dispatcher_.connect (sigc::mem_fun (this, &DisplayerSlot::displayCurrentFrame));
229  }
230 
231 
232  DisplayerSlot::~DisplayerSlot()
233  {
234  TRACE (gui_dbg, "Displayer Slot closing...");
235  }
236 
237 
238  void
240  {
241  hasFrame_.emit (currBuffer_);
242  }
243 
244 
245 } // namespace stage
lumiera_err lumiera_error_peek(void)
Check current error state without clearing it Please avoid this function and use lumiera_error() if p...
Definition: error-state.c:133
A public service provided by the GUI, implementing the lumiera::Display facade interface.
I & get() const
directly access the instance via the CL interface
lib::Depend< DisplayService > _instance
a backdoor for the C Language impl to access the actual SessionCommand implementation...
Actual implementation of a single displayer slot.
Access point to singletons and other kinds of dependencies designated by type.
Definition: depend.hpp:280
Not finished development code.
void put(LumieraDisplayFrame)
receive a frame to be displayed
#define LUMIERA_INTERFACE_INSTANCE(iname, version, name, descriptor, acquire, release,...)
Define an interface instance.
Definition: interface.h:185
static LumieraDisplaySlot setUp(FrameDestination const &)
open a new display, sending frames to the given output destination
Derived specific exceptions within Lumiera&#39;s exception hierarchy.
Definition: error.hpp:190
#define LUMIERA_INTERFACE_REF(iname, version, dname)
Return a reference (pointer) to an interface implementation.
Definition: interface.h:119
Lumiera GTK UI implementation root.
Definition: guifacade.cpp:37
DisplayerSlot & resolve(LumieraDisplaySlot)
resolve the given display slot handle to yield a ref to an actual implementation object.
Singleton services and Dependency Injection.
void displayCurrentFrame()
internal: activated via Dispatcher and running in GTK main thread
lumiera_err lumiera_error_set(lumiera_err nerr, const char *extra)
Set error state for the current thread.
Definition: error-state.c:96
void allocate(LumieraDisplaySlot, bool doAllocate)
prepare and the given slot for output
A data record to describe interface, interface instances and plug-in instances.
T & manage(T *obj)
take ownership of the given object, adding it at the end of the collection
Interface and Base definition for all Lumiera Exceptions.
Definition: error.hpp:62
ElementBoxWidget::Config::Qualifier name(string id)
define the name-ID displayed in the caption