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