Fawkes API  Fawkes Development Version
mongodb_client_config.h
1 
2 /***************************************************************************
3  * mongodb_client_config.h - MongoDB configuration for a single client
4  *
5  * Created: Wed Jul 12 13:43:35 2017
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.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU Library General Public License for more details.
18  *
19  * Read the full text in the LICENSE.GPL file in the doc directory.
20  */
21 
22 #ifndef _PLUGINS_MONGODB_MONGODB_CLIENT_CONFIG_H_
23 #define _PLUGINS_MONGODB_MONGODB_CLIENT_CONFIG_H_
24 
25 #include <mongocxx/client.hpp>
26 #include <mongocxx/uri.hpp>
27 #include <string>
28 #include <vector>
29 
30 namespace fawkes {
31 class Configuration;
32 class Logger;
33 } // namespace fawkes
34 
35 /** Client configuration. */
37 {
38 public:
39  /** Connection mode enumeration. */
40  typedef enum {
41  CONNECTION, /**< connect to single node */
42  REPLICA_SET, /**< connect to replica set */
44 
46  fawkes::Logger * logger,
47  std::string cfgname,
48  std::string prefix);
49  mongocxx::client *create_client();
50 
51  /** Check if configuration is enabled.
52  * @return true if configuration is enabled, false otherwise
53  */
54  bool
55  is_enabled() const
56  {
57  return enabled_;
58  }
59 
60  std::string hostport() const;
61 
62  void log(fawkes::Logger *logger, const char *component, const char *indent);
63 
64  ConnectionMode mode() const;
65 
66 private:
67  void read_authinfo(fawkes::Configuration *config,
68  fawkes::Logger * logger,
69  std::string cfgname,
70  std::string prefix);
71 
72 private:
73  std::string logcomp_;
74  bool enabled_;
75  ConnectionMode mode_;
76  mongocxx::uri conn_uri_;
77  std::string replicaset_name_;
78  std::string auth_dbname;
79  std::string auth_string_;
80 };
81 
82 #endif
MongoDBClientConfig
Client configuration.
Definition: mongodb_client_config.h:36
MongoDBClientConfig::hostport
std::string hostport() const
Get host and port of configuration.
Definition: mongodb_client_config.cpp:172
MongoDBClientConfig::MongoDBClientConfig
MongoDBClientConfig(fawkes::Configuration *config, fawkes::Logger *logger, std::string cfgname, std::string prefix)
Constructor.
Definition: mongodb_client_config.cpp:44
MongoDBClientConfig::create_client
mongocxx::client * create_client()
Create MongoDB client for this configuration.
Definition: mongodb_client_config.cpp:138
MongoDBClientConfig::mode
ConnectionMode mode() const
Get client configuration mode.
Definition: mongodb_client_config.cpp:187
fawkes::Configuration
Definition: config.h:70
MongoDBClientConfig::log
void log(fawkes::Logger *logger, const char *component, const char *indent)
Write client configuration information to log.
Definition: mongodb_client_config.cpp:149
MongoDBClientConfig::CONNECTION
@ CONNECTION
connect to single node
Definition: mongodb_client_config.h:41
fawkes::Logger
Definition: logger.h:41
fawkes
MongoDBClientConfig::REPLICA_SET
@ REPLICA_SET
connect to replica set
Definition: mongodb_client_config.h:42
MongoDBClientConfig::ConnectionMode
ConnectionMode
Connection mode enumeration.
Definition: mongodb_client_config.h:40
MongoDBClientConfig::is_enabled
bool is_enabled() const
Check if configuration is enabled.
Definition: mongodb_client_config.h:55