Go to the documentation of this file.
5 #ifndef CCFCOMMON_DB_HPP_
6 #define CCFCOMMON_DB_HPP_
10 #include <mal/Cii.hpp>
11 #include <mal/utility/LoadMal.hpp>
13 #include <rad/topicPub.hpp>
14 #include <rad/mal/publisher.hpp>
15 #include <rad/dbAdapterRedis.hpp>
16 #include <rad/dbAdapter.hpp>
17 #include <rad/smAdapter.hpp>
35 void Config(
const std::string& endpoint,
const timeval& timeout);
38 int Delete(
const std::vector<std::string>& keys);
41 bool Exists(
const std::string& key);
44 std::string
Get(
const std::string& key);
47 std::vector<std::string>
MultiGet(
const std::vector<std::string>& keys);
50 std::string
Get(
const std::string& key,
const std::string& field);
53 std::vector<std::string>
MultiGet(
const std::string& key,
54 const std::vector<std::string>& fields);
57 std::map<std::string, std::string>
Scan(
const std::string& key,
const std::string& pattern);
60 void Set(
const std::string& key,
const std::string& value);
63 void MultiSet(
const std::vector<std::string>& kvs);
66 void Set(
const std::string& key,
const std::string& field,
const std::string& value);
69 void MultiSet(
const std::string& key,
const std::vector<std::string>& fvs);
85 std::map<std::string, std::string> m_db;
104 Db(
const std::string& prefix);
115 std::map<std::string, std::string>
Scan(
const std::string& key,
const std::string& pattern);
136 std::string
Get(
const std::string& key);
139 std::vector<std::string>
MultiGet(
const std::vector<std::string>& keys);
142 bool Exists(
const std::string& key);
145 int Delete(
const std::vector<std::string>& keys);
148 void Set(
const std::string& key,
const std::string& value);
151 template <
class TYPE>
152 void Set(
const std::string& key, TYPE value) {
154 std::string str_value = std::to_string(value);
159 const std::string&
GetAddress(
const std::string& key);
165 rad::DbAdapter&
GetDb();
170 static bool s_simulation;
172 std::string m_prefix;
173 rad::DbAdapterRedis m_redis_db;
175 std::map<std::string, std::string> m_key_address_map;
178 std::unique_ptr<rad::cii::Publisher<stdif::StatusTopic>> m_status_publisher;
180 std::string m_current_status;
181 std::string m_sm_state;
182 std::string m_sm_status_state;
183 std::string m_sm_status_substate;
193 #endif // CCFCOMMON_DB_HPP_
std::vector< std::string > MultiGet(const std::vector< std::string > &keys)
Get a set of keys.
Definition: db.cpp:271
void Connect()
Connect to the DB.
Definition: db.cpp:350
bool IsConnected()
Returns true if connection is establihed.
Definition: db.cpp:360
std::string GetSmStatusSubstate()
Definition: db.cpp:78
std::vector< std::string > MultiGet(const std::vector< std::string > &keys)
Get multiple keys from the DB.
Definition: db.cpp:95
static Db * s_instance
Singleton instance.
Definition: db.hpp:95
std::map< std::string, std::string > Scan(const std::string &key, const std::string &pattern)
Scan the DB for the given key applying the given key/field.
Definition: db.cpp:307
std::map< std::string, std::string > Scan(const std::string &key, const std::string &pattern)
Scan the namespace of the associated DB, applying the key and pattern.
Definition: db.cpp:90
std::string Get(const std::string &key)
Get the value of the given key.
Definition: db.cpp:262
std::string Get(const std::string &key)
Get value for the given key.
Definition: db.cpp:84
Interface to the OLDB and Pub/Sub.
Definition: db.hpp:91
Db & GetDb()
Return the reference to the CCF DB Singleton instance.
Definition: db.hpp:187
void Connect()
Connect to the associated database(s).
Definition: db.cpp:195
void Disconnect()
Disconnect from the DB.
Definition: db.cpp:355
InternalDb()
Definition: db.hpp:30
bool Exists(const std::string &key)
Check if the given key exists.
Definition: db.cpp:231
Db(const std::string &prefix)
Constructor. The prefix indicates location in database of this application.
Definition: db.cpp:25
void MultiSet(const std::vector< std::string > &kvs)
Set a set of keys and values.
Definition: db.cpp:326
~InternalDb()
Definition: db.hpp:32
std::string GetSmState()
Definition: db.cpp:66
Db & operator=(const Db &)=delete
Disable copy constructor.
virtual ~Db()
Definition: db.cpp:62
const std::string & GetAddress(const std::string &key)
Get the complete address of the given key (append the index if missing and cache the name).
Definition: db.cpp:211
void Set(const std::string &key, TYPE value)
Set the referenced key to the given value.
Definition: db.hpp:152
InternalDb(const InternalDb &)=delete
void Config(const std::string &endpoint, const timeval &timeout)
Configure the endpoint and timeout to apply for this interface.
Definition: db.cpp:245
void UpdateSmStatus(std::set< scxml4cpp::State * > &status)
Update the state/substate/status in the OLDB/PubSub.
Definition: db.cpp:104
static void Simulate()
Put the object in simulation, using an internal map as DB.
Definition: db.cpp:226
Definition: appBase.cpp:8
static Db & Instance()
Return reference to Singleton instance of the application class.
Definition: db.cpp:17
InternalDb & operator=(const InternalDb &)=delete
Disable copy constructor.
rad::DbAdapter & GetDb()
Disable assignment operator.
Definition: db.cpp:236
DB implementing (partially) the rad::DbAdapter interface; used for internal/test purposes.
Definition: db.hpp:27
void Set(const std::string &key, const std::string &value)
Set the referenced key to the given value.
Definition: db.cpp:179
std::string GetSmStatusState()
Definition: db.cpp:72
bool Exists(const std::string &key)
Check if the given key exists.
Definition: db.cpp:258
void Set(const std::string &key, const std::string &value)
Set the given key to the given value.
Definition: db.cpp:317
#define CCFTRACE
TRACE log macro. Includes the location ("CCFLOC") in the log message.
Definition: base.hpp:403
void Disconnect()
Disconnect from the assosicated database(s).
Definition: db.cpp:189
int Delete(const std::vector< std::string > &keys)
Delete the keys specified.
Definition: db.cpp:221
int Delete(const std::vector< std::string > &keys)
Delete the keys listed.
Definition: db.cpp:249
bool IsConnected()
Check if connected to the associated database(s).
Definition: db.cpp:205