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
Laser data filter.
Definition: filter.h:33
Laser filter thread.
Definition: filter_thread.h:55
virtual void init()
Initialize the thread.
void set_wait_barrier(fawkes::Barrier *barrier)
Set wait barrier.
void set_wait_threads(std::list< LaserFilterThread * > &threads)
Set threads to wait for in loop.
virtual void loop()
Code to execute in the thread.
virtual void finalize()
Finalize the thread.
void wait_done()
Wait until thread is done.
LaserFilterThread(std::string &cfg_name, std::string &cfg_prefix)
Constructor.
virtual void run()
Stub to see name in backtrace for easier debugging.
Definition: filter_thread.h:97
A barrier is a synchronization tool which blocks until a given number of threads have reached the bar...
Definition: barrier.h:32
Thread aspect to access to BlackBoard.
Definition: blackboard.h:34
Thread aspect to use blocked timing.
Thread aspect to access configuration data.
Definition: configurable.h:33
Base class for all Fawkes BlackBoard interfaces.
Definition: interface.h:80
Laser1080Interface Fawkes BlackBoard Interface.
Laser360Interface Fawkes BlackBoard Interface.
Laser720Interface Fawkes BlackBoard Interface.
Thread aspect to log output.
Definition: logging.h:33
Mutex mutual exclusion lock.
Definition: mutex.h:33
Thread class encapsulation of pthreads.
Definition: thread.h:46
Thread aspect to access the transform system.
Definition: tf.h:39
Wait until a given condition holds.
Fawkes library namespace.