Fawkes API  Fawkes Development Version
context_thread.h
00001 
00002 /***************************************************************************
00003  *  context_thread.h - OpenNI context providing thread
00004  *
00005  *  Created: Sat Feb 26 15:23:16 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.
00014  *
00015  *  This program is distributed in the hope that it will be useful,
00016  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  *  GNU Library General Public License for more details.
00019  *
00020  *  Read the full text in the LICENSE.GPL file in the doc directory.
00021  */
00022 
00023 #ifndef __PLUGINS_OPENNI_CONTEXT_THREAD_H_
00024 #define __PLUGINS_OPENNI_CONTEXT_THREAD_H_
00025 
00026 #include <core/threading/thread.h>
00027 #include <core/utils/lockptr.h>
00028 #include <aspect/logging.h>
00029 #include <aspect/configurable.h>
00030 #include <aspect/clock.h>
00031 #include <aspect/blocked_timing.h>
00032 #include <aspect/aspect_provider.h>
00033 #include <plugins/openni/aspect/openni_inifin.h>
00034 #include <utils/time/time.h>
00035 
00036 #include <sys/types.h>
00037 #include <map>
00038 #include <string>
00039 
00040 namespace xn {
00041   class Context;
00042   class Device;
00043 }
00044 
00045 class OpenNiContextThread
00046 : public fawkes::Thread,
00047   public fawkes::BlockedTimingAspect,
00048   public fawkes::LoggingAspect,
00049   public fawkes::ConfigurableAspect,
00050   public fawkes::ClockAspect,
00051   public fawkes::AspectProviderAspect
00052 {
00053  public:
00054   OpenNiContextThread();
00055   virtual ~OpenNiContextThread();
00056 
00057   virtual void init();
00058   virtual void loop();
00059   virtual void finalize();
00060 
00061  private:
00062   void print_nodes();
00063   void verify_active();
00064   void start_sensor_server();
00065   void stop_sensor_server();
00066 
00067  /** Stub to see name in backtrace for easier debugging. @see Thread::run() */
00068  protected: virtual void run() { Thread::run(); }
00069 
00070  private:
00071   fawkes::LockPtr<xn::Context>  __openni;
00072   fawkes::OpenNiAspectIniFin    __openni_aspect_inifin;
00073 
00074   bool         __cfg_run_sensor_server;
00075   std::string  __cfg_sensor_bin;
00076   pid_t        __sensor_server_pid;
00077   xn::Device  *__device;
00078 
00079   int __last_refcount;
00080 
00081   fawkes::Time __check_last;
00082   fawkes::Time __check_now;
00083 
00084   unsigned int __device_no_data_loops;
00085 
00086   std::map<std::string, unsigned int> __dead_loops;
00087 };
00088 
00089 #endif