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 <mongo/client/dbclient.h>
26 
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  mongo::DBClientBase *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  mongo::HostAndPort conn_hostport_;
77  std::vector<mongo::HostAndPort> replicaset_hostports_;
78  std::string replicaset_name_;
79 
80  /// @cond INTERNALS
81  typedef struct _AuthInfo
82  {
83  _AuthInfo(std::string dbname, std::string username, std::string clearpwd)
84  {
85  this->dbname = dbname;
86  this->username = username;
87  this->clearpwd = clearpwd;
88  }
89  std::string dbname;
90  std::string username;
91  std::string clearpwd;
92  } AuthInfo;
93  /// @endcond
94 
95  std::list<AuthInfo> auth_infos_;
96 };
97 
98 #endif
bool is_enabled() const
Check if configuration is enabled.
ConnectionMode mode() const
Get client configuration mode.
std::string hostport() const
Get host and port of configuration.
Fawkes library namespace.
Client configuration.
mongo::DBClientBase * create_client()
Create MongoDB client for this configuration.
MongoDBClientConfig(fawkes::Configuration *config, fawkes::Logger *logger, std::string cfgname, std::string prefix)
Constructor.
void log(fawkes::Logger *logger, const char *component, const char *indent)
Write client configuration information to log.
ConnectionMode
Connection mode enumeration.
Interface for configuration handling.
Definition: config.h:64
Interface for logging.
Definition: logger.h:41