Fawkes API  Fawkes Development Version
mongodb_log_image_thread.h
1 
2 /***************************************************************************
3  * image_thread.h - Thread to log images to MongoDB
4  *
5  * Created: Tue Apr 10 22:12:27 2012
6  * Copyright 2011-2012 Tim Niemueller [www.niemueller.de]
7  * 2012 Bastian Klingen
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_MONGODB_LOG_MONGODB_LOG_IMAGE_THREAD_H_
24 #define __PLUGINS_MONGODB_LOG_MONGODB_LOG_IMAGE_THREAD_H_
25 
26 #include <core/threading/thread.h>
27 #include <aspect/blocked_timing.h>
28 #include <aspect/clock.h>
29 #include <aspect/configurable.h>
30 #include <aspect/logging.h>
31 #include <aspect/pointcloud.h>
32 #include <plugins/mongodb/aspect/mongodb.h>
33 #include <core/threading/mutex.h>
34 
35 #include <list>
36 #include <queue>
37 #include <set>
38 #include <string>
39 
40 namespace firevision {
41  class SharedMemoryImageBuffer;
42 }
43 
44 namespace fawkes {
45  class Mutex;
46  class TimeWait;
47 }
48 
49 namespace mongo {
50  class GridFS;
51 }
52 
54 : public fawkes::Thread,
55  public fawkes::ClockAspect,
56  public fawkes::LoggingAspect,
59 {
60  public:
62  virtual ~MongoLogImagesThread();
63 
64  virtual void init();
65  virtual void loop();
66  virtual bool prepare_finalize_user();
67  virtual void finalize();
68 
69  /** Stub to see name in backtrace for easier debugging. @see Thread::run() */
70  protected: virtual void run() { Thread::run(); }
71 
72  private:
73  void update_images();
74  void get_sets(std::set<std::string> &missing_images,
75  std::set<std::string> &unbacked_images);
76 
77  private:
78  /// @cond INTERNALS
79  typedef struct {
80  std::string topic_name;
81  fawkes::Time last_sent;
83  } ImageInfo;
84  /// @endcond
85  std::map<std::string, ImageInfo> imgs_;
86 
87  fawkes::Time *last_update_;
88  fawkes::Time *now_;
89  mongo::DBClientBase *mongodb_;
90  mongo::GridFS *gridfs_;
91  std::string collection_;
92  std::string database_;
93 
94  fawkes::Mutex *mutex_;
95  fawkes::TimeWait *wait_;
96 
97  std::vector<std::string> includes_;
98  std::vector<std::string> excludes_;
99 
100  unsigned int cfg_chunk_size_;
101  float cfg_storage_interval_;
102 };
103 
104 #endif
Thread aspect that allows to obtain the current time from the clock.
Definition: clock.h:36
Fawkes library namespace.
Definition: mongodb.h:29
A class for handling time.
Definition: time.h:91
Thread class encapsulation of pthreads.
Definition: thread.h:42
Thread aspect to access MongoDB.
Definition: mongodb.h:40
Shared memory image buffer.
Definition: shm_image.h:181
Thread aspect to log output.
Definition: logging.h:35
Thread aspect to access configuration data.
Definition: configurable.h:35
Thread to export Fawkes images to MongoDB.
Mutex mutual exclusion lock.
Definition: mutex.h:32
virtual void run()
Stub to see name in backtrace for easier debugging.
Time wait utility.
Definition: wait.h:32