Fawkes API  Fawkes Development Version
openni_inifin.cpp
00001 
00002 /***************************************************************************
00003  *  openni_inifin.cpp - Fawkes OpenNiAspect initializer/finalizer
00004  *
00005  *  Created: Sat Feb 26 15:42:56 2011
00006  *  Copyright  2006-2011  Tim Niemueller [www.niemueller.de]
00007  *
00008  ****************************************************************************/
00009 
00010 /*  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version. A runtime exception applies to
00014  *  this software (see LICENSE.GPL_WRE file mentioned below for details).
00015  *
00016  *  This program is distributed in the hope that it will be useful,
00017  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  *  GNU Library General Public License for more details.
00020  *
00021  *  Read the full text in the LICENSE.GPL_WRE file in the doc directory.
00022  */
00023 
00024 #include <plugins/openni/aspect/openni_inifin.h>
00025 #include <core/threading/thread_finalizer.h>
00026 #include <XnCppWrapper.h>
00027 
00028 namespace fawkes {
00029 #if 0 /* just to make Emacs auto-indent happy */
00030 }
00031 #endif
00032 
00033 /** @class OpenNiAspectIniFin <plugins/openni/aspect/openni_inifin.h>
00034  * OpenNiAspect initializer/finalizer.
00035  * This initializer/finalizer will provide the OpenNI context to threads
00036  * with the OpenNiAspect.
00037  * @author Tim Niemueller
00038  */
00039 
00040 /** Constructor. */
00041 OpenNiAspectIniFin::OpenNiAspectIniFin()
00042   : AspectIniFin("OpenNiAspect")
00043 {
00044 }
00045 
00046 void
00047 OpenNiAspectIniFin::init(Thread *thread)
00048 {
00049   OpenNiAspect *openni_thread;
00050   openni_thread = dynamic_cast<OpenNiAspect *>(thread);
00051   if (openni_thread == NULL) {
00052     throw CannotInitializeThreadException("Thread '%s' claims to have the "
00053                                           "OpenNiAspect, but RTTI says it "
00054                                           "has not. ", thread->name());
00055   }
00056   if (! __openni_context) {
00057     throw CannotInitializeThreadException("OpenNI context has not been set.");
00058   }
00059 
00060   openni_thread->init_OpenNiAspect(__openni_context);
00061 }
00062 
00063 void
00064 OpenNiAspectIniFin::finalize(Thread *thread)
00065 {
00066 }
00067 
00068 
00069 /** Set the OpenNI context to use for aspect initialization.
00070  * @param openni_context OpenNI context to pass to threads with OpenNiAspect.
00071  */
00072 void
00073 OpenNiAspectIniFin::set_openni_context(LockPtr<xn::Context> openni_context)
00074 {
00075   __openni_context = openni_context;
00076 }
00077 
00078 } // end namespace fawkes