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-2010 Tim Niemueller [www.niemueller.de]
7  *
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. A runtime exception applies to
14  * this software (see LICENSE.GPL_WRE file mentioned below for details).
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Library General Public License for more details.
20  *
21  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22  */
23 
24 #include <plugins/mongodb/aspect/mongodb.h>
25 #include <plugins/mongodb/aspect/mongodb_conncreator.h>
26 
27 #include <cstring>
28 #include <cstdlib>
29 
30 namespace fawkes {
31 #if 0 /* just to make Emacs auto-indent happy */
32 }
33 #endif
34 
35 /** @class MongoDBAspect <plugins/mongodb/aspect/mongodb.h>
36  * Thread aspect to access MongoDB.
37  * Give this aspect to your thread to gain access to MongoDB. This will
38  * setup the mongodb_client member with an active, auto-recovering connection
39  * to MongoDB (can be any kind of connection, single server, replicat set,
40  * or sync cluster).
41  *
42  * @ingroup Aspects
43  * @author Tim Niemueller
44  */
45 
46 /** @fn const char * MongoDBAspect::mongodb_config_name() const
47  * Get MongoDB configuration name.
48  * @return MongoDB path name for the configuration settings from the
49  * global configuration. Note that this may return 0 if the default
50  * configuration should be used.
51  */
52 
53 /** @var mongo::DBClientBase * MongoDBAspect::mongodb_client
54  * MongoDB client to use to interact with the database. If database name, user
55  * and password were given to constructor, authentication has been executed
56  * (and only on success the aspect is considered to be successfully
57  * initialized).
58  */
59 
60 /** @var fawkes::MongoDBConnCreator * MongoDBAspect::mongodb_connmgr
61  * Connection manager to retrieve more client connections from if necessary.
62  */
63 
64 /** Constructor.
65  * @param config_name optional configuration name from which the
66  * configuration for the database is read from the global configuration.
67  */
68 MongoDBAspect::MongoDBAspect(const char *config_name)
69 {
70  add_aspect("MongoDBAspect");
71  __config_name = config_name ? strdup(config_name) : 0;
72 }
73 
74 
75 /** Virtual empty destructor. */
77 {
78  if (__config_name) free(__config_name);
79 }
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,
92 {
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:51
MongoDBAspect(const char *config_prefix=0)
Constructor.
Definition: mongodb.cpp:68
MongoDBConnCreator * mongodb_connmgr
Connection manager to retrieve more client connections from if necessary.
Definition: mongodb.h:52
void add_aspect(const char *name)
Add an aspect to a thread.
Definition: aspect.cpp:52
virtual ~MongoDBAspect()
Virtual empty destructor.
Definition: mongodb.cpp:76
Interface for a MongoDB connection creator.