Fawkes API  Fawkes Development Version
mongodb.cpp
1 
2 /***************************************************************************
3  * mongodb.h - MongoDB aspect for Fawkes
4  *
5  * Created: Mon Dec 06 00:28:55 2010
6  * Copyright 2006-2017 Tim Niemueller [www.niemueller.de]
7  ****************************************************************************/
8 
9 /* This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version. A runtime exception applies to
13  * this software (see LICENSE.GPL_WRE file mentioned below for details).
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_WRE file in the doc directory.
21  */
22 
23 #include <plugins/mongodb/aspect/mongodb.h>
24 #include <plugins/mongodb/aspect/mongodb_conncreator.h>
25 
26 namespace fawkes {
27 
28 /** @class MongoDBAspect <plugins/mongodb/aspect/mongodb.h>
29  * Thread aspect to access MongoDB.
30  * Give this aspect to your thread to gain access to MongoDB. This will
31  * setup the mongodb_client member with an active, auto-recovering connection
32  * to MongoDB (can be any kind of connection, single server, replicat set,
33  * or sync cluster).
34  *
35  * @ingroup Aspects
36  * @author Tim Niemueller
37  */
38 
39 /** @fn const std::string & MongoDBAspect::mongodb_config_name() const
40  * Get MongoDB configuration name.
41  * @return MongoDB path name for the configuration settings from the
42  * global configuration. Note that this may return 0 if the default
43  * configuration should be used.
44  */
45 
46 /** @var mongo::DBClientBase * MongoDBAspect::mongodb_client
47  * MongoDB client to use to interact with the database. If database name, user
48  * and password were given to constructor, authentication has been executed
49  * (and only on success the aspect is considered to be successfully
50  * initialized).
51  */
52 
53 /** @var fawkes::MongoDBConnCreator * MongoDBAspect::mongodb_connmgr
54  * Connection manager to retrieve more client connections from if necessary.
55  */
56 
57 /** Constructor.
58  * @param config_name optional configuration name from which the
59  * configuration for the database is read from the global configuration.
60  */
61 MongoDBAspect::MongoDBAspect(const char *config_name)
62 {
63  add_aspect("MongoDBAspect");
64  mongodb_config_name_ = config_name;
65 }
66 
67 /** Constructor.
68  * Using this constructor will leave the mongodb_client member uninitialized.
69  * The mongodb_connmgr can be used to create connections at a later point in time.
70  */
72 {
73  add_aspect("MongoDBAspect");
74 }
75 
76 /** Virtual empty destructor. */
78 {
79  mongodb_config_name_.clear();
80 }
81 
82 /** Init MongoDB aspect.
83  * This set the MongoDB client to access MongoDB.
84  * It is guaranteed that this is called for a MongoDBThread before start
85  * is called (when running regularly inside Fawkes).
86  * @param mongodb_client MongoDB connection
87  * @param mongodb_connmgr MongoDB connection manager
88  */
89 void
90 MongoDBAspect::init_MongoDBAspect(mongo::DBClientBase *mongodb_client,
91  MongoDBConnCreator * mongodb_connmgr)
92 {
93  this->mongodb_client = mongodb_client;
94  this->mongodb_connmgr = mongodb_connmgr;
95 }
96 
97 } // end namespace fawkes
Fawkes library namespace.
mongo::DBClientBase * mongodb_client
MongoDB client to use to interact with the database.
Definition: mongodb.h:55
MongoDBConnCreator * mongodb_connmgr
Connection manager to retrieve more client connections from if necessary.
Definition: mongodb.h:56
void add_aspect(const char *name)
Add an aspect to a thread.
Definition: aspect.cpp:49
MongoDBAspect()
Constructor.
Definition: mongodb.cpp:71
virtual ~MongoDBAspect()
Virtual empty destructor.
Definition: mongodb.cpp:77
Interface for a MongoDB connection creator.