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 <core/threading/thread_finalizer.h>
25 #include <plugins/openni/aspect/openni_inifin.h>
26 
27 #include <XnCppWrapper.h>
28 
29 namespace fawkes {
30 
31 /** @class OpenNiAspectIniFin <plugins/openni/aspect/openni_inifin.h>
32  * OpenNiAspect initializer/finalizer.
33  * This initializer/finalizer will provide the OpenNI context to threads
34  * with the OpenNiAspect.
35  * @author Tim Niemueller
36  */
37 
38 /** Constructor. */
40 {
41 }
42 
43 void
45 {
46  OpenNiAspect *openni_thread;
47  openni_thread = dynamic_cast<OpenNiAspect *>(thread);
48  if (openni_thread == NULL) {
49  throw CannotInitializeThreadException("Thread '%s' claims to have the "
50  "OpenNiAspect, but RTTI says it "
51  "has not. ",
52  thread->name());
53  }
54  if (!openni_context_) {
55  throw CannotInitializeThreadException("OpenNI context has not been set.");
56  }
57 
58  openni_thread->init_OpenNiAspect(openni_context_);
59 }
60 
61 void
63 {
64 }
65 
66 /** Set the OpenNI context to use for aspect initialization.
67  * @param openni_context OpenNI context to pass to threads with OpenNiAspect.
68  */
69 void
71 {
72  openni_context_ = openni_context;
73 }
74 
75 } // end namespace fawkes
fawkes::LockPtr< xn::Context >
fawkes::OpenNiAspectIniFin::OpenNiAspectIniFin
OpenNiAspectIniFin()
Constructor.
Definition: openni_inifin.cpp:39
fawkes::CannotInitializeThreadException
Thread cannot be initialized.
Definition: thread_initializer.h:34
fawkes::Thread::name
const char * name() const
Get name of thread.
Definition: thread.h:100
fawkes::AspectIniFin
Aspect initializer/finalizer base class.
Definition: inifin.h:34
fawkes::OpenNiAspect
Thread aspect to get access to the OpenNI context.
Definition: openni.h:39
fawkes::OpenNiAspectIniFin::finalize
virtual void finalize(Thread *thread)
Finalize thread.
Definition: openni_inifin.cpp:62
fawkes
Fawkes library namespace.
fawkes::OpenNiAspectIniFin::init
virtual void init(Thread *thread)
Initialize thread.
Definition: openni_inifin.cpp:44
fawkes::Thread
Thread class encapsulation of pthreads.
Definition: thread.h:46
fawkes::OpenNiAspectIniFin::set_openni_context
void set_openni_context(LockPtr< xn::Context > openni_context)
Set the OpenNI context to use for aspect initialization.
Definition: openni_inifin.cpp:70