Fawkes API  Fawkes Development Version
mongodb_log_bb_thread.h
1 
2 /***************************************************************************
3  * mongodb_log_bb_thread.h - MongoDB blackboard logging thread
4  *
5  * Created: Wed Dec 08 23:08:14 2010
6  * Copyright 2010-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_BB_THREAD_H_
24 #define __PLUGINS_MONGODB_LOG_MONGODB_LOG_BB_THREAD_H_
25 
26 #include <core/threading/thread.h>
27 #include <aspect/logging.h>
28 #include <aspect/configurable.h>
29 #include <aspect/clock.h>
30 #include <aspect/blackboard.h>
31 #include <plugins/mongodb/aspect/mongodb.h>
32 
33 #include <blackboard/interface_observer.h>
34 #include <blackboard/interface_listener.h>
35 #include <core/utils/lock_map.h>
36 #include <core/utils/lock_set.h>
37 
38 #include <string>
39 
40 
42 : public fawkes::Thread,
43  public fawkes::LoggingAspect,
45  public fawkes::ClockAspect,
47  public fawkes::MongoDBAspect,
49 {
50  public:
52  virtual ~MongoLogBlackboardThread();
53 
54  virtual void init();
55  virtual void loop();
56  virtual void finalize();
57 
58  // for BlackBoardInterfaceObserver
59  virtual void bb_interface_created(const char *type, const char *id) throw();
60 
61  /** Stub to see name in backtrace for easier debugging. @see Thread::run() */
62  protected: virtual void run() { Thread::run(); }
63 
64  private:
65  /** Mongo Logger interface listener. */
66  class InterfaceListener : public fawkes::BlackBoardInterfaceListener
67  {
68  public:
69  InterfaceListener(fawkes::BlackBoard *blackboard,
70  fawkes::Interface *interface,
71  mongo::DBClientBase *mongodb,
72  std::string &database,
75  fawkes::Time *now);
76  ~InterfaceListener();
77 
78  /** Get MongoDB Client.
79  * @return MongoDB client */
80  mongo::DBClientBase * mongodb_client() const
81  { return mongodb_; }
82 
83  // for BlackBoardInterfaceListener
84  virtual void bb_interface_data_changed(fawkes::Interface *interface) throw();
85 
86  private:
87  fawkes::BlackBoard *blackboard_;
88  fawkes::Interface *interface_;
89  mongo::DBClientBase *mongodb_;
90  fawkes::Logger *logger_;
91  std::string collection_;
92  std::string &database_;
93  fawkes::LockSet<std::string> &collections_;
94  fawkes::Time *now_;
95  };
96 
97 
99  fawkes::LockSet<std::string> collections_;
100  std::string database_;
101  fawkes::Time *now_;
102 
103  std::vector<std::string> excludes_;
104 };
105 
106 #endif
virtual void run()
Stub to see name in backtrace for easier debugging.
Thread aspect to access to BlackBoard.
Definition: blackboard.h:34
Thread aspect that allows to obtain the current time from the clock.
Definition: clock.h:36
virtual void loop()
Code to execute in the thread.
mongo::DBClientBase * mongodb_client
MongoDB client to use to interact with the database.
Definition: mongodb.h:51
A class for handling time.
Definition: time.h:91
virtual ~MongoLogBlackboardThread()
Destructor.
Thread class encapsulation of pthreads.
Definition: thread.h:42
Base class for all Fawkes BlackBoard interfaces.
Definition: interface.h:79
Logger * logger
This is the Logger member used to access the logger.
Definition: logging.h:44
Map with a lock.
Definition: lock_map.h:37
Thread aspect to access MongoDB.
Definition: mongodb.h:40
Thread aspect to log output.
Definition: logging.h:35
BlackBoard interface observer.
Thread aspect to access configuration data.
Definition: configurable.h:35
MongoDB Logging Thread.
virtual void finalize()
Finalize the thread.
virtual void init()
Initialize the thread.
The BlackBoard abstract class.
Definition: blackboard.h:48
virtual void bb_interface_created(const char *type, const char *id)
BlackBoard interface created notification.
BlackBoard interface listener.
BlackBoard * blackboard
This is the BlackBoard instance you can use to interact with the BlackBoard.
Definition: blackboard.h:44
Interface for logging.
Definition: logger.h:34