Fawkes API  Fawkes Development Version
base_thread.h
00001 
00002 /***************************************************************************
00003  *  base_thread.h - FireVision Base Thread
00004  *
00005  *  Created: Tue May 29 16:40:10 2007
00006  *  Copyright  2006-2009  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 __FIREVISION_APPS_BASE_BASE_THREAD_H_
00024 #define __FIREVISION_APPS_BASE_BASE_THREAD_H_
00025 
00026 #include <core/threading/thread.h>
00027 #include <core/threading/thread_notification_listener.h>
00028 #include <core/utils/lock_map.h>
00029 #include <core/utils/lock_list.h>
00030 
00031 #include <aspect/blocked_timing.h>
00032 #include <aspect/logging.h>
00033 #include <aspect/vision_master.h>
00034 #include <aspect/clock.h>
00035 #include <aspect/thread_producer.h>
00036 #include <aspect/configurable.h>
00037 
00038 #include <fvutils/base/vision_master.h>
00039 #include <string>
00040 
00041 namespace fawkes {
00042   class Barrier;
00043 }
00044 class FvAcquisitionThread;
00045 
00046 class FvBaseThread
00047 : public fawkes::Thread,
00048   public fawkes::BlockedTimingAspect,
00049   public fawkes::LoggingAspect,
00050   public fawkes::VisionMasterAspect,
00051   public fawkes::ClockAspect,
00052   public fawkes::ThreadProducerAspect,
00053   public fawkes::ConfigurableAspect,
00054   public fawkes::ThreadNotificationListener,
00055   public firevision::VisionMaster
00056 {
00057  public:
00058   FvBaseThread();
00059   virtual ~FvBaseThread();
00060 
00061   virtual void init();
00062   virtual void loop();
00063   virtual void finalize();
00064 
00065   virtual firevision::VisionMaster *  vision_master();
00066 
00067   virtual firevision::Camera *  register_for_camera(const char *camera_string,
00068                                                     fawkes::Thread *thread,
00069                                                     firevision::colorspace_t cspace = firevision::YUV422_PLANAR);
00070   virtual firevision::Camera *  register_for_raw_camera(const char *camera_string,
00071                                                         fawkes::Thread *thread);
00072   virtual void      unregister_thread(fawkes::Thread *thread);
00073 
00074 
00075   virtual firevision::CameraControl *acquire_camctrl(const char *cam_string);
00076   virtual void                       release_camctrl(firevision::CameraControl *cc);
00077 
00078   virtual bool thread_started(fawkes::Thread *thread) throw();
00079   virtual bool thread_init_failed(fawkes::Thread *thread) throw();
00080 
00081  /** Stub to see name in backtrace for easier debugging. @see Thread::run() */
00082  protected: virtual void run() { Thread::run(); }
00083 
00084  protected:
00085   virtual firevision::CameraControl *acquire_camctrl(const char *cam_string,
00086                                                      const std::type_info &typeinf);
00087 
00088  private:
00089   void cond_recreate_barrier(unsigned int num_cyclic_threads);
00090   firevision::CameraControl * create_camctrl(const char *camera_string);
00091 
00092  private:
00093   fawkes::LockMap<std::string, FvAcquisitionThread *> __aqts;
00094   fawkes::LockMap<std::string, FvAcquisitionThread *>::iterator __ait;
00095   unsigned int __aqt_timeout;
00096 
00097   fawkes::LockList<firevision::CameraControl *>  __owned_controls;
00098   fawkes::LockMap<Thread *, FvAcquisitionThread *> __started_threads;
00099 
00100   fawkes::Barrier *__aqt_barrier;
00101 };
00102 
00103 
00104 #endif