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 <aspect/blackboard.h>
27 #include <aspect/clock.h>
28 #include <aspect/configurable.h>
29 #include <aspect/logging.h>
30 #include <blackboard/interface_listener.h>
31 #include <blackboard/interface_observer.h>
32 #include <core/threading/thread.h>
33 #include <core/utils/lock_map.h>
34 #include <core/utils/lock_set.h>
35 #include <plugins/mongodb/aspect/mongodb.h>
36 
37 #include <string>
38 
40  public fawkes::LoggingAspect,
42  public fawkes::ClockAspect,
44  public fawkes::MongoDBAspect,
46 {
47 public:
49  virtual ~MongoLogBlackboardThread();
50 
51  virtual void init();
52  virtual void loop();
53  virtual void finalize();
54 
55  // for BlackBoardInterfaceObserver
56  virtual void bb_interface_created(const char *type, const char *id) throw();
57 
58  /** Stub to see name in backtrace for easier debugging. @see Thread::run() */
59 protected:
60  virtual void
61  run()
62  {
63  Thread::run();
64  }
65 
66 private:
67  /** Mongo Logger interface listener. */
68  class InterfaceListener : public fawkes::BlackBoardInterfaceListener
69  {
70  public:
71  InterfaceListener(fawkes::BlackBoard * blackboard,
72  fawkes::Interface * interface,
73  mongocxx::client * mongodb,
74  std::string & database,
76  const std::string & agent_name,
78  fawkes::Time * now);
79  ~InterfaceListener();
80 
81  /** Get MongoDB Client.
82  * @return MongoDB client */
83  mongocxx::client *
84  mongodb_client() const
85  {
86  return mongodb_;
87  }
88 
89  // for BlackBoardInterfaceListener
90  virtual void bb_interface_data_changed(fawkes::Interface *interface) throw();
91 
92  private:
93  fawkes::BlackBoard * blackboard_;
94  fawkes::Interface * interface_;
95  mongocxx::client * mongodb_;
96  fawkes::Logger * logger_;
97  std::string collection_;
98  std::string & database_;
99  fawkes::LockSet<std::string> &collections_;
100  const std::string agent_name_;
101  fawkes::Time * now_;
102  };
103 
105  fawkes::LockSet<std::string> collections_;
106  std::string database_;
107  fawkes::Time * now_;
108 
109  std::vector<std::string> excludes_;
110 };
111 
112 #endif
MongoDB Logging Thread.
virtual void finalize()
Finalize the thread.
virtual ~MongoLogBlackboardThread()
Destructor.
virtual void init()
Initialize the thread.
virtual void bb_interface_created(const char *type, const char *id)
BlackBoard interface created notification.
virtual void loop()
Code to execute in the thread.
virtual void run()
Stub to see name in backtrace for easier debugging.
Thread aspect to access to BlackBoard.
Definition: blackboard.h:34
BlackBoard * blackboard
This is the BlackBoard instance you can use to interact with the BlackBoard.
Definition: blackboard.h:44
BlackBoard interface listener.
BlackBoard interface observer.
The BlackBoard abstract class.
Definition: blackboard.h:46
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
Base class for all Fawkes BlackBoard interfaces.
Definition: interface.h:79
Interface for logging.
Definition: logger.h:42
Thread aspect to log output.
Definition: logging.h:33
Logger * logger
This is the Logger member used to access the logger.
Definition: logging.h:41
Thread aspect to access MongoDB.
Definition: mongodb.h:39
mongocxx::client * mongodb_client
MongoDB client to use to interact with the database.
Definition: mongodb.h:54
Thread class encapsulation of pthreads.
Definition: thread.h:46
A class for handling time.
Definition: time.h:93