Fawkes API  Fawkes Development Version
openni_inifin.cpp
1 
2 /***************************************************************************
3  * openni_inifin.cpp - Fawkes OpenNiAspect initializer/finalizer
4  *
5  * Created: Sat Feb 26 15:42:56 2011
6  * Copyright 2006-2011 Tim Niemueller [www.niemueller.de]
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version. A runtime exception applies to
14  * this software (see LICENSE.GPL_WRE file mentioned below for details).
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Library General Public License for more details.
20  *
21  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22  */
23 
24 #include <plugins/openni/aspect/openni_inifin.h>
25 #include <core/threading/thread_finalizer.h>
26 #include <XnCppWrapper.h>
27 
28 namespace fawkes {
29 #if 0 /* just to make Emacs auto-indent happy */
30 }
31 #endif
32 
33 /** @class OpenNiAspectIniFin <plugins/openni/aspect/openni_inifin.h>
34  * OpenNiAspect initializer/finalizer.
35  * This initializer/finalizer will provide the OpenNI context to threads
36  * with the OpenNiAspect.
37  * @author Tim Niemueller
38  */
39 
40 /** Constructor. */
42  : AspectIniFin("OpenNiAspect")
43 {
44 }
45 
46 void
48 {
49  OpenNiAspect *openni_thread;
50  openni_thread = dynamic_cast<OpenNiAspect *>(thread);
51  if (openni_thread == NULL) {
52  throw CannotInitializeThreadException("Thread '%s' claims to have the "
53  "OpenNiAspect, but RTTI says it "
54  "has not. ", thread->name());
55  }
56  if (! __openni_context) {
57  throw CannotInitializeThreadException("OpenNI context has not been set.");
58  }
59 
60  openni_thread->init_OpenNiAspect(__openni_context);
61 }
62 
63 void
65 {
66 }
67 
68 
69 /** Set the OpenNI context to use for aspect initialization.
70  * @param openni_context OpenNI context to pass to threads with OpenNiAspect.
71  */
72 void
74 {
75  __openni_context = openni_context;
76 }
77 
78 } // end namespace fawkes
OpenNiAspectIniFin()
Constructor.
virtual void init(Thread *thread)
Initialize thread.
Fawkes library namespace.
Thread aspect to get access to the OpenNI context.
Definition: openni.h:39
Thread class encapsulation of pthreads.
Definition: thread.h:42
Thread cannot be initialized.
void set_openni_context(LockPtr< xn::Context > openni_context)
Set the OpenNI context to use for aspect initialization.
const char * name() const
Get name of thread.
Definition: thread.h:95
virtual void finalize(Thread *thread)
Finalize thread.
Aspect initializer/finalizer base class.
Definition: inifin.h:36