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
30namespace fawkes {
31class Configuration;
32class Logger;
33} // namespace fawkes
34
35/** Client configuration. */
37{
38public:
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
66private:
67 void read_authinfo(fawkes::Configuration *config,
68 fawkes::Logger * logger,
69 std::string cfgname,
70 std::string prefix);
71
72private:
73 std::string logcomp_;
74 bool enabled_;
75 ConnectionMode mode_;
76 unsigned int startup_grace_period_;
77 mongocxx::uri conn_uri_;
78 std::string replicaset_name_;
79 std::string auth_dbname;
80 std::string auth_string_;
81};
82
83#endif
Client configuration.
mongocxx::client * create_client()
Create MongoDB client for this configuration.
bool is_enabled() const
Check if configuration is enabled.
ConnectionMode
Connection mode enumeration.
@ CONNECTION
connect to single node
@ REPLICA_SET
connect to replica set
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.
std::string hostport() const
Get host and port of configuration.
ConnectionMode mode() const
Get client configuration mode.
Interface for configuration handling.
Definition: config.h:68
Interface for logging.
Definition: logger.h:42
Fawkes library namespace.