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) Lumiera.org
5  2009, Hermann Vosseler <Ichthyostega@web.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 * *****************************************************/
22 
23 
36 #include "lib/depend.hpp"
37 
38 extern "C" {
40 }
41 
42 
43 namespace stage {
44 
45 
46 
47  namespace { // hidden local details of the service implementation....
48 
49 
50 
51  /* ================== define an lumieraorg_Display instance ======================= */
52 
53  LUMIERA_INTERFACE_INSTANCE (lumieraorg_interfacedescriptor, 0
54  ,lumieraorg_DisplayFacade_descriptor
55  , NULL, NULL, NULL
56  , LUMIERA_INTERFACE_INLINE (name,
57  const char*, (LumieraInterface ifa),
58  { (void)ifa; return "Display"; }
59  )
60  , LUMIERA_INTERFACE_INLINE (brief,
61  const char*, (LumieraInterface ifa),
62  { (void)ifa; return "UI Interface: service for outputting frames to a viewer or display"; }
63  )
64  , LUMIERA_INTERFACE_INLINE (homepage,
65  const char*, (LumieraInterface ifa),
66  { (void)ifa; return "http://www.lumiera.org/develompent.html" ;}
67  )
68  , LUMIERA_INTERFACE_INLINE (version,
69  const char*, (LumieraInterface ifa),
70  { (void)ifa; return "0.1~pre"; }
71  )
72  , LUMIERA_INTERFACE_INLINE (author,
73  const char*, (LumieraInterface ifa),
74  { (void)ifa; return "Hermann Vosseler"; }
75  )
76  , LUMIERA_INTERFACE_INLINE (email,
77  const char*, (LumieraInterface ifa),
78  { (void)ifa; return "Ichthyostega@web.de"; }
79  )
80  , LUMIERA_INTERFACE_INLINE (copyright,
81  const char*, (LumieraInterface ifa),
82  {
83  (void)ifa;
84  return
85  "Copyright (C) Lumiera.org\n"
86  " 2009 Hermann Vosseler <Ichthyostega@web.de>";
87  }
88  )
89  , LUMIERA_INTERFACE_INLINE (license,
90  const char*, (LumieraInterface ifa),
91  {
92  (void)ifa;
93  return
94  "This program is free software; you can redistribute it and/or modify\n"
95  "it under the terms of the GNU General Public License as published by\n"
96  "the Free Software Foundation; either version 2 of the License, or\n"
97  "(at your option) any later version.\n"
98  "\n"
99  "This program is distributed in the hope that it will be useful,\n"
100  "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
101  "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
102  "GNU General Public License for more details.\n"
103  "\n"
104  "You should have received a copy of the GNU General Public License\n"
105  "along with this program; if not, write to the Free Software\n"
106  "Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA";
107  }
108  )
109  , LUMIERA_INTERFACE_INLINE (state,
110  int, (LumieraInterface ifa),
111  {(void)ifa; return LUMIERA_INTERFACE_EXPERIMENTAL; }
112  )
113  , LUMIERA_INTERFACE_INLINE (versioncmp,
114  int, (const char* a, const char* b),
115  {(void)a;(void)b; return 0;}
116  )
117  );
118 
119 
120 
121 
122 
123  using LERR_(LIFECYCLE);
124 
126 
127 
128 
129  LUMIERA_INTERFACE_INSTANCE (lumieraorg_Display, 0
130  ,lumieraorg_DisplayService
131  , LUMIERA_INTERFACE_REF(lumieraorg_interfacedescriptor, 0, lumieraorg_DisplayFacade_descriptor)
132  , NULL /* on open */
133  , NULL /* on close */
134  , LUMIERA_INTERFACE_INLINE (allocate,
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  try
145  {
146  _instance().allocate (slotHandle,true);
147  }
148  catch (lumiera::Error&){ /* error state remains set */ }
149  }
150  )
151  , LUMIERA_INTERFACE_INLINE (release,
152  void, (LumieraDisplaySlot slotHandle),
153  {
154  if (!_instance)
155  {
156  lumiera_error_set (LUMIERA_ERROR_LIFECYCLE, 0);
157  return;
158  }
159 
160  REQUIRE (slotHandle);
161  _instance().allocate (slotHandle,false);
162  }
163  )
164  , LUMIERA_INTERFACE_INLINE (put,
165  void, (LumieraDisplaySlot slotHandle, LumieraDisplayFrame frame),
166  {
167  //skipping full checks for performance reasons
168  REQUIRE (_instance && !lumiera_error_peek());
169 
170  REQUIRE (slotHandle);
171  DisplayerSlot& slot = _instance().resolve (slotHandle);
172  slot.put (frame);
173  }
174  )
175  );
176 
177 
178 
179 
180  } // (End) hidden service impl details
181 
182 
183 
184 
185  DisplayService::DisplayService()
186  : error_{}
187  , serviceInstance_( LUMIERA_INTERFACE_REF (lumieraorg_Display, 0, lumieraorg_DisplayService))
188  {
189  INFO (progress, "Display Facade opened.");
190  }
191 
192 
193 
194  LumieraDisplaySlot
195  DisplayService::setUp (FrameDestination const& outputDestination)
196  {
197  DisplayerTab& slots (_instance().slots_);
198  return &slots.manage (new DisplayerSlot (outputDestination));
199  }
200 
201 
202 
203  void
204  DisplayService::allocate (LumieraDisplaySlot handle, bool doAllocate)
205  {
206  REQUIRE (handle);
207  if (doAllocate)
208  {
209  if (handle->put_)
210  throw lumiera::error::Logic("slot already allocated for output");
211  else
212  // Mark the handle as "allocated" and ready for output:
213  // Place the function pointer from the C interface into the handle struct.
214  // calling it will invoke the implementing instance's "put" function
215  // (see the LUMIERA_INTERFACE_INLINE above in this file!)
216  handle->put_ = serviceInstance_.get().put;
217  }
218  else
219  handle->put_ = 0;
220  }
221 
222 
223 
224  DisplayerSlot&
225  DisplayService::resolve (LumieraDisplaySlot handle)
226  {
227  REQUIRE (handle);
228  REQUIRE (handle->put_, "accessing a DisplayerSlot, which hasn't been locked for output");
229 
230  return *static_cast<DisplayerSlot*> (handle);
231  }
232 
233 
234 
235 
236 
237  /* === DisplayerSlot Implementation === */
238 
239 
240  DisplayerSlot::DisplayerSlot (FrameDestination const& outputDestination)
241  : currBuffer_(0)
242  {
243  put_ = 0; // mark as not allocated
244  hasFrame_.connect (outputDestination);
245  dispatcher_.connect (sigc::mem_fun (this, &DisplayerSlot::displayCurrentFrame));
246  }
247 
248 
249  DisplayerSlot::~DisplayerSlot()
250  {
251  TRACE (gui_dbg, "Displayer Slot closing...");
252  }
253 
254 
255  void
257  {
258  hasFrame_.emit (currBuffer_);
259  }
260 
261 
262 } // 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:142
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:289
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:194
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:199
#define LUMIERA_INTERFACE_REF(iname, version, dname)
Return a reference (pointer) to an interface implementation.
Definition: interface.h:128
Lumiera GTK UI implementation root.
Definition: guifacade.cpp:46
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:105
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:71
ElementBoxWidget::Config::Qualifier name(string id)
define the name-ID displayed in the caption