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 <aspect/blocked_timing.h>
27 #include <aspect/clock.h>
28 #include <aspect/configurable.h>
29 #include <aspect/logging.h>
30 #include <aspect/pointcloud.h>
31 #include <core/threading/mutex.h>
32 #include <core/threading/thread.h>
33 #include <plugins/mongodb/aspect/mongodb.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 } // namespace fawkes
48 
49 namespace mongo {
50 class GridFS;
51 }
52 
54  public fawkes::ClockAspect,
55  public fawkes::LoggingAspect,
58 {
59 public:
61  virtual ~MongoLogImagesThread();
62 
63  virtual void init();
64  virtual void loop();
65  virtual bool prepare_finalize_user();
66  virtual void finalize();
67 
68  /** Stub to see name in backtrace for easier debugging. @see Thread::run() */
69 protected:
70  virtual void
71  run()
72  {
73  Thread::run();
74  }
75 
76 private:
77  void update_images();
78  void get_sets(std::set<std::string> &missing_images, std::set<std::string> &unbacked_images);
79 
80 private:
81  /// @cond INTERNALS
82  typedef struct
83  {
84  std::string topic_name;
85  fawkes::Time last_sent;
87  } ImageInfo;
88  /// @endcond
89  std::map<std::string, ImageInfo> imgs_;
90 
91  fawkes::Time * last_update_;
92  fawkes::Time * now_;
93  mongo::DBClientBase *mongodb_;
94  mongo::GridFS * gridfs_;
95  std::string collection_;
96  std::string database_;
97 
98  fawkes::Mutex * mutex_;
99  fawkes::TimeWait *wait_;
100 
101  std::vector<std::string> includes_;
102  std::vector<std::string> excludes_;
103 
104  unsigned int cfg_chunk_size_;
105  float cfg_storage_interval_;
106 };
107 
108 #endif
Thread aspect that allows to obtain the current time from the clock.
Definition: clock.h:33
Fawkes library namespace.
virtual ~MongoLogImagesThread()
Destructor.
A class for handling time.
Definition: time.h:92
Thread class encapsulation of pthreads.
Definition: thread.h:45
virtual void finalize()
Finalize the thread.
virtual void init()
Initialize the thread.
Thread aspect to access MongoDB.
Definition: mongodb.h:39
virtual void loop()
Code to execute in the thread.
Shared memory image buffer.
Definition: shm_image.h:183
virtual bool prepare_finalize_user()
Prepare finalization user implementation.
Thread aspect to log output.
Definition: logging.h:32
Thread aspect to access configuration data.
Definition: configurable.h:32
Thread to export Fawkes images to MongoDB.
Mutex mutual exclusion lock.
Definition: mutex.h:32
ImageInfo representation for JSON transfer.
Definition: ImageInfo.h:26
virtual void run()
Stub to see name in backtrace for easier debugging.
Time wait utility.
Definition: wait.h:32