Fawkes API  Fawkes Development Version
filter_thread.h
1 
2 /***************************************************************************
3  * filter_thread.h - Thread to filter laser data
4  *
5  * Created: Sun Mar 13 01:11:11 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.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Library General Public License for more details.
19  *
20  * Read the full text in the LICENSE.GPL file in the doc directory.
21  */
22 
23 #ifndef _PLUGINS_LASER_FILTER_FILTER_THREAD_H_
24 #define _PLUGINS_LASER_FILTER_FILTER_THREAD_H_
25 
26 #include "filters/filter.h"
27 
28 #include <aspect/blackboard.h>
29 #include <aspect/blocked_timing.h>
30 #include <aspect/configurable.h>
31 #include <aspect/logging.h>
32 #include <core/threading/thread.h>
33 #ifdef HAVE_TF
34 # include <aspect/tf.h>
35 #endif
36 
37 #include <list>
38 #include <string>
39 #include <vector>
40 
41 namespace fawkes {
42 class Laser360Interface;
43 class Laser720Interface;
44 class Laser1080Interface;
45 } // namespace fawkes
46 
49  public fawkes::LoggingAspect,
51 #ifdef HAVE_TF
53 #endif
55 {
56 public:
57  LaserFilterThread(std::string &cfg_name, std::string &cfg_prefix);
58 
59  virtual void init();
60  virtual void finalize();
61  virtual void loop();
62 
63  void wait_done();
64 
65  void set_wait_threads(std::list<LaserFilterThread *> &threads);
66  void set_wait_barrier(fawkes::Barrier *barrier);
67 
68 private:
69  /// @cond INTERNALS
70  typedef struct
71  {
72  std::string id;
73  unsigned int size;
74  union {
78  } interface_typed;
79  fawkes::Interface *interface;
81  /// @endcond
82 
83  void open_interfaces(std::string prefix,
84  std::vector<LaserInterface> & ifs,
85  std::vector<LaserDataFilter::Buffer *> &bufs,
86  bool writing);
87 
88  LaserDataFilter *create_filter(std::string filter_name,
89  std::string filter_type,
90  std::string prefix,
91  unsigned int in_data_size,
92  std::vector<LaserDataFilter::Buffer *> &inbufs);
93 
94  /** Stub to see name in backtrace for easier debugging. @see Thread::run() */
95 protected:
96  virtual void
97  run()
98  {
99  Thread::run();
100  }
101 
102 private:
103  std::vector<LaserInterface> in_;
104  std::vector<LaserInterface> out_;
105 
106  std::vector<LaserDataFilter::Buffer *> in_bufs_;
107  std::vector<LaserDataFilter::Buffer *> out_bufs_;
108 
109  LaserDataFilter *filter_;
110 
111  std::string cfg_name_;
112  std::string cfg_prefix_;
113 
114  std::list<LaserFilterThread *> wait_threads_;
115  bool wait_done_;
116  fawkes::Mutex * wait_mutex_;
117  fawkes::WaitCondition * wait_cond_;
118  fawkes::Barrier * wait_barrier_;
119 };
120 
121 #endif
LaserFilterThread::init
virtual void init()
Initialize the thread.
Definition: filter_thread.cpp:77
fawkes::Mutex
Definition: mutex.h:38
LaserFilterThread::run
virtual void run()
Stub to see name in backtrace for easier debugging.
Definition: filter_thread.h:97
LaserFilterThread::set_wait_barrier
void set_wait_barrier(fawkes::Barrier *barrier)
Set wait barrier.
Definition: filter_thread.cpp:557
fawkes::WaitCondition
Definition: wait_condition.h:42
LaserFilterThread::LaserFilterThread
LaserFilterThread(std::string &cfg_name, std::string &cfg_prefix)
Constructor.
Definition: filter_thread.cpp:66
fawkes::BlockedTimingAspect
Definition: blocked_timing.h:56
fawkes::BlackBoardAspect
Definition: blackboard.h:38
fawkes
fawkes::LoggingAspect
Definition: logging.h:38
fawkes::Laser1080Interface
Definition: Laser1080Interface.h:39
fawkes::TransformAspect
Definition: tf.h:43
fawkes::Interface
Definition: interface.h:78
LaserFilterThread::loop
virtual void loop()
Code to execute in the thread.
Definition: filter_thread.cpp:204
LaserDataFilter
Definition: filter.h:32
LaserFilterThread
Definition: filter_thread.h:47
fawkes::Thread
Definition: thread.h:45
fawkes::Laser720Interface
Definition: Laser720Interface.h:39
fawkes::ConfigurableAspect
Definition: configurable.h:38
fawkes::Laser360Interface
Definition: Laser360Interface.h:39
fawkes::Barrier
Definition: barrier.h:37
LaserFilterThread::set_wait_threads
void set_wait_threads(std::list< LaserFilterThread * > &threads)
Set threads to wait for in loop.
Definition: filter_thread.cpp:545
LaserFilterThread::finalize
virtual void finalize()
Finalize the thread.
Definition: filter_thread.cpp:187
LaserFilterThread::wait_done
void wait_done()
Wait until thread is done.
Definition: filter_thread.cpp:271