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
fawkes::MongoDBAspect
Thread aspect to access MongoDB.
Definition: mongodb.h:39
MongoLogBlackboardThread::MongoLogBlackboardThread
MongoLogBlackboardThread()
Constructor.
Definition: mongodb_log_bb_thread.cpp:45
fawkes::LockMap< std::string, InterfaceListener * >
fawkes::MongoDBAspect::mongodb_client
mongocxx::client * mongodb_client
MongoDB client to use to interact with the database.
Definition: mongodb.h:54
fawkes::LockSet< std::string >
fawkes::BlackBoardInterfaceListener
BlackBoard interface listener.
Definition: interface_listener.h:42
MongoLogBlackboardThread::init
virtual void init()
Initialize the thread.
Definition: mongodb_log_bb_thread.cpp:56
MongoLogBlackboardThread::finalize
virtual void finalize()
Finalize the thread.
Definition: mongodb_log_bb_thread.cpp:114
fawkes::BlackBoard
The BlackBoard abstract class.
Definition: blackboard.h:46
MongoLogBlackboardThread::loop
virtual void loop()
Code to execute in the thread.
Definition: mongodb_log_bb_thread.cpp:128
MongoLogBlackboardThread::run
virtual void run()
Stub to see name in backtrace for easier debugging.
Definition: mongodb_log_bb_thread.h:61
MongoLogBlackboardThread::~MongoLogBlackboardThread
virtual ~MongoLogBlackboardThread()
Destructor.
Definition: mongodb_log_bb_thread.cpp:51
fawkes::LoggingAspect::logger
Logger * logger
This is the Logger member used to access the logger.
Definition: logging.h:41
fawkes::Logger
Interface for logging.
Definition: logger.h:42
fawkes::BlackBoardAspect
Thread aspect to access to BlackBoard.
Definition: blackboard.h:34
fawkes::LoggingAspect
Thread aspect to log output.
Definition: logging.h:33
fawkes::BlackBoardInterfaceObserver
BlackBoard interface observer.
Definition: interface_observer.h:37
fawkes::Interface
Base class for all Fawkes BlackBoard interfaces.
Definition: interface.h:79
fawkes::Time
A class for handling time.
Definition: time.h:93
MongoLogBlackboardThread::bb_interface_created
virtual void bb_interface_created(const char *type, const char *id)
BlackBoard interface created notification.
Definition: mongodb_log_bb_thread.cpp:134
fawkes::Thread
Thread class encapsulation of pthreads.
Definition: thread.h:46
fawkes::BlackBoardAspect::blackboard
BlackBoard * blackboard
This is the BlackBoard instance you can use to interact with the BlackBoard.
Definition: blackboard.h:44
fawkes::ConfigurableAspect
Thread aspect to access configuration data.
Definition: configurable.h:33
fawkes::ClockAspect
Thread aspect that allows to obtain the current time from the clock.
Definition: clock.h:34
MongoLogBlackboardThread
MongoDB Logging Thread.
Definition: mongodb_log_bb_thread.h:46