Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
9.2.2023: Due to updates GitLab will be unavailable for some minutes between 9:00 and 11:00.
Open sidebar
dcdb
dcdb
Commits
84f185bc
Commit
84f185bc
authored
Jan 18, 2016
by
Axel Auweter
Browse files
Refactor DCDBLib to introduce DCDB namespace & prepare DB schema for virtual sensor support.
parent
4fd356ec
Changes
26
Hide whitespace changes
Inline
Side-by-side
CollectAgent/collectagent.cpp
View file @
84f185bc
...
...
@@ -30,7 +30,7 @@ int keepRunning;
bool
statistics
;
uint64_t
msgCtr
;
uint64_t
pmsgCtr
;
SensorDataStore
*
mySensorDataStore
;
DCDB
::
SensorDataStore
*
mySensorDataStore
;
std
::
string
listenHost
,
cassandraHost
,
ttl
;
/* Normal termination (SIGINT, CTRL+C) */
...
...
@@ -93,7 +93,7 @@ void mqttCallback(SimpleMQTTMessage *msg)
* into a valid SensorId. If successful, store
* the record in the database.
*/
SensorId
sid
;
DCDB
::
SensorId
sid
;
if
(
sid
.
mqttTopicConvert
(
msg
->
getTopic
()))
{
#if 0
cout << "Topic decode successful:"
...
...
@@ -185,8 +185,8 @@ int main(int argc, char* const argv[]) {
* Allocate and initialize connection to Cassandra.
*/
std
::
string
sdHost
=
cassandraHost
;
DCDBConnection
*
dcdbConn
;
dcdbConn
=
new
DCDBConnection
(
sdHost
,
9042
);
DCDB
::
Connection
*
dcdbConn
;
dcdbConn
=
new
DCDB
::
Connection
(
sdHost
,
9042
);
if
(
!
dcdbConn
->
connect
())
{
std
::
cout
<<
"Cannot connect to Cassandra!"
<<
std
::
endl
;
...
...
@@ -201,7 +201,7 @@ int main(int argc, char* const argv[]) {
/*
* Allocate the SensorDataStore.
*/
mySensorDataStore
=
new
SensorDataStore
(
dcdbConn
);
mySensorDataStore
=
new
DCDB
::
SensorDataStore
(
dcdbConn
);
/*
* Set TTL for data store inserts if TTL > 0.
...
...
DCDBLib/include/connection.h
View file @
84f185bc
...
...
@@ -9,7 +9,7 @@
* @file
* @brief This file contains parts of the public API for the
* DCDBLib library.
* It contains the class definition of the
DCDB
Connection class,
* It contains the class definition of the Connection class,
* that handles connections to the data store and schema
* initialization.
*/
...
...
@@ -19,16 +19,18 @@
#include
"cassandra.h"
#ifndef CONNECTION_H
#define CONNECTION_H
#ifndef DCDB_CONNECTION_H
#define DCDB_CONNECTION_H
namespace
DCDB
{
/* Forward-declaration of the implementation-internal classes */
class
DCDB
ConnectionImpl
;
class
ConnectionImpl
;
class
DCDB
Connection
class
Connection
{
private:
DCDB
ConnectionImpl
*
impl
;
/**< The object which implements the core functionality of this class */
ConnectionImpl
*
impl
;
/**< The object which implements the core functionality of this class */
public:
/**
...
...
@@ -99,21 +101,23 @@ public:
bool
initSchema
();
/**
* @brief Standard constructor for
DCDB
Connections.
* @brief Standard constructor for Connections.
*
* If not set explicitly, hostname and port will default to localhost and 9042.
*/
DCDB
Connection
();
Connection
();
/**
* @brief Construct a
DCDB
Connection to the specific host and port.
* @brief Construct a Connection to the specific host and port.
*/
DCDB
Connection
(
std
::
string
hostname
,
uint16_t
port
);
Connection
(
std
::
string
hostname
,
uint16_t
port
);
/**
* @brief Standard destructor for
DCDB
Connections.
* @brief Standard destructor for Connections.
*/
virtual
~
DCDB
Connection
();
virtual
~
Connection
();
};
#endif
/* CONNECTION_H */
}
/* End of namespace DCDB */
#endif
/* DCDB_CONNECTION_H */
DCDBLib/include/sensorconfig.h
View file @
84f185bc
...
...
@@ -22,12 +22,14 @@
#include
"cassandra.h"
#ifndef SENSORCONFIG_H
#define SENSORCONFIG_H
#ifndef DCDB_SENSORCONFIG_H
#define DCDB_SENSORCONFIG_H
namespace
DCDB
{
class
SensorConfigImpl
;
class
DCDB
PublicSensor
class
PublicSensor
{
public:
std
::
string
name
;
...
...
@@ -36,8 +38,8 @@ public:
std
::
string
unit
;
bool
integrable
;
DCDB
PublicSensor
();
DCDB
PublicSensor
(
const
DCDB
PublicSensor
&
copy
);
PublicSensor
();
PublicSensor
(
const
PublicSensor
&
copy
);
};
typedef
enum
{
...
...
@@ -58,21 +60,22 @@ public:
SCError
publishSensor
(
const
char
*
publicName
,
const
char
*
sensorPattern
);
SCError
unPublishSensor
(
const
char
*
publicName
);
SCError
getPublicSensorNames
(
std
::
list
<
std
::
string
>&
publicSensors
);
SCError
getPublicSensorsVerbose
(
std
::
list
<
DCDB
PublicSensor
>&
publicSensors
);
SCError
getPublicSensorsVerbose
(
std
::
list
<
PublicSensor
>&
publicSensors
);
SCError
getPublicSensorByName
(
DCDB
PublicSensor
&
sensor
,
const
char
*
publicName
);
SCError
getPublicSensorByName
(
PublicSensor
&
sensor
,
const
char
*
publicName
);
SCError
getSensorPattern
(
std
::
string
&
pattern
,
std
::
string
publicName
);
SCError
getSensorListForPattern
(
std
::
list
<
SensorId
>&
sensorIds
,
std
::
string
pattern
);
SCError
getSensorListForPattern
(
std
::
list
<
SensorId
>&
sensorIds
,
std
::
string
pattern
,
DCDB
TimeStamp
start
,
DCDB
TimeStamp
end
);
SCError
getSensorListForPattern
(
std
::
list
<
SensorId
>&
sensorIds
,
std
::
string
pattern
,
TimeStamp
start
,
TimeStamp
end
);
SCError
setSensorScalingFactor
(
std
::
string
publicName
,
double
scalingFactor
);
SCError
setSensorUnit
(
std
::
string
publicName
,
std
::
string
unit
);
SCError
setSensorIntegrable
(
std
::
string
publicName
,
bool
integrable
);
SensorConfig
(
DCDB
Connection
*
conn
);
SensorConfig
(
Connection
*
conn
);
virtual
~
SensorConfig
();
};
}
/* End of namespace DCDB */
#endif
/* CONFIG_H */
#endif
/*
DCDB_SENSOR
CONFIG_H */
DCDBLib/include/sensordatastore.h
View file @
84f185bc
...
...
@@ -21,8 +21,10 @@
#include
"timestamp.h"
#include
"connection.h"
#ifndef SENSORDATASTORE_H_
#define SENSORDATASTORE_H_
#ifndef DCDB_SENSORDATASTORE_H
#define DCDB_SENSORDATASTORE_H
namespace
DCDB
{
typedef
enum
{
SDS_OK
,
...
...
@@ -40,7 +42,7 @@ class SensorDataStoreReading
{
public:
SensorId
sensorId
;
DCDB
TimeStamp
timeStamp
;
TimeStamp
timeStamp
;
int64_t
value
;
#if 0
...
...
@@ -85,7 +87,7 @@ public:
* @param start Start of the time series.
* @param end End of the time series.
*/
void
query
(
std
::
list
<
SensorDataStoreReading
>&
result
,
SensorId
&
sid
,
DCDB
TimeStamp
&
start
,
DCDB
TimeStamp
&
end
);
void
query
(
std
::
list
<
SensorDataStoreReading
>&
result
,
SensorId
&
sid
,
TimeStamp
&
start
,
TimeStamp
&
end
);
/**
* @brief This function queries the integrated value (val * sec)
...
...
@@ -96,7 +98,7 @@ public:
* @param end End of the time series.
* @return SDS_OK if ok, SDS_EMPTYSET if not at least 2 readings in interval.
*/
SDSQueryResult
querySum
(
int64_t
&
result
,
SensorId
&
sid
,
DCDB
TimeStamp
&
start
,
DCDB
TimeStamp
&
end
);
SDSQueryResult
querySum
(
int64_t
&
result
,
SensorId
&
sid
,
TimeStamp
&
start
,
TimeStamp
&
end
);
/**
* @brief This function truncates all sensor data that is older than
...
...
@@ -109,10 +111,10 @@ public:
* @brief A shortcut constructor for a SensorDataStore object
* that allows accessing the data store through a
* connection that is already established.
* @param conn The
DCDB
Connection object of an established
* @param conn The Connection object of an established
* connection to Cassandra.
*/
SensorDataStore
(
DCDB
Connection
*
conn
);
SensorDataStore
(
Connection
*
conn
);
/**
* @brief The standard destructor for a SensorDatStore object.
...
...
@@ -120,5 +122,6 @@ public:
virtual
~
SensorDataStore
();
};
}
/* End of namespace DCDB */
#endif
/* SENSORDATASTORE_H
_
*/
#endif
/*
DCDB_
SENSORDATASTORE_H */
DCDBLib/include/sensorid.h
View file @
84f185bc
...
...
@@ -8,8 +8,10 @@
#include
<cstdint>
#include
<string>
#ifndef SENSORID_H
#define SENSORID_H
#ifndef DCDB_SENSORID_H
#define DCDB_SENSORID_H
namespace
DCDB
{
/* Ensure that the unions and structs are created without padding */
#pragma pack(push,1)
...
...
@@ -122,4 +124,6 @@ public:
#pragma pack(pop)
#endif
/* SENSORID_H */
}
/* End of namespace DCDB */
#endif
/* DCDB_SENSORID_H */
DCDBLib/include/timestamp.h
View file @
84f185bc
/*
*
dcdb
timestamp.h
* timestamp.h
*
* Created on: Feb 18, 2015
* Author: Axel Auweter
...
...
@@ -8,7 +8,7 @@
/**
* @file
* @brief This file is a companion to the sensordatastore API.
* It contains the
DCDB
TimeStamp class definition that helps in
* It contains the TimeStamp class definition that helps in
* creating and modifying timestamps in the SensorDataStore.
*/
...
...
@@ -17,26 +17,28 @@
#include
<string>
#include
<stdexcept>
#ifndef DCDBTIMESTAMP_H
#define DCDBTIMESTAMP_H
#ifndef DCDB
_
TIMESTAMP_H
#define DCDB
_
TIMESTAMP_H
class
DCDBTimeStampConversionException
:
public
std
::
runtime_error
namespace
DCDB
{
class
TimeStampConversionException
:
public
std
::
runtime_error
{
public:
DCDB
TimeStampConversionException
()
:
runtime_error
(
"Time stamp conversion error."
)
{}
TimeStampConversionException
()
:
runtime_error
(
"Time stamp conversion error."
)
{}
};
/**
* @brief The
DCDB
TimeStamp class contains a single TimeStamp.
* @brief The TimeStamp class contains a single TimeStamp.
*/
class
DCDB
TimeStamp
class
TimeStamp
{
protected:
uint64_t
raw
;
/**< The raw timestamp data (nanoseconds since Unix Epoch) */
/**
* @brief Parses a string and tries to derive the time from it by
* guessing the format. Throws
DCDB
TimeStampException on failure.
* guessing the format. Throws TimeStampException on failure.
* @param timestr A string containing a representation of time
* @param localTime Denotes if the timestr contains local time instead of UTC
*/
...
...
@@ -47,27 +49,27 @@ public:
/**
* @brief Standard constructor. Initializes the object with the current time.
*/
DCDB
TimeStamp
();
TimeStamp
();
/**
* @brief Raw constructor. Initializes the object with an existing raw time.
*/
DCDB
TimeStamp
(
uint64_t
ts
)
{
raw
=
ts
;}
TimeStamp
(
uint64_t
ts
)
{
raw
=
ts
;}
/**
* @brief String constructor. Initializes the object by best guess from a time string.
*/
DCDB
TimeStamp
(
std
::
string
ts
,
bool
localTime
=
false
);
TimeStamp
(
std
::
string
ts
,
bool
localTime
=
false
);
/**
* @brief Time_t constructor. Initializes the object from a time_t struct.
*/
DCDB
TimeStamp
(
time_t
ts
);
TimeStamp
(
time_t
ts
);
/**
* @brief Standard destructor.
*/
virtual
~
DCDB
TimeStamp
();
virtual
~
TimeStamp
();
/**
* @brief Sets the object's value to the current time.
...
...
@@ -103,13 +105,14 @@ public:
uint16_t
getWeekstamp
(
void
);
/* Overloaded operators (compare raw values) */
inline
bool
operator
==
(
const
DCDB
TimeStamp
&
rhs
)
const
{
return
raw
==
rhs
.
raw
;}
inline
bool
operator
!=
(
const
DCDB
TimeStamp
&
rhs
)
const
{
return
raw
!=
rhs
.
raw
;}
inline
bool
operator
<
(
const
DCDB
TimeStamp
&
rhs
)
const
{
return
raw
<
rhs
.
raw
;}
inline
bool
operator
>
(
const
DCDB
TimeStamp
&
rhs
)
const
{
return
raw
>
rhs
.
raw
;}
inline
bool
operator
<=
(
const
DCDB
TimeStamp
&
rhs
)
const
{
return
raw
<=
rhs
.
raw
;}
inline
bool
operator
>=
(
const
DCDB
TimeStamp
&
rhs
)
const
{
return
raw
>=
rhs
.
raw
;}
inline
bool
operator
==
(
const
TimeStamp
&
rhs
)
const
{
return
raw
==
rhs
.
raw
;}
inline
bool
operator
!=
(
const
TimeStamp
&
rhs
)
const
{
return
raw
!=
rhs
.
raw
;}
inline
bool
operator
<
(
const
TimeStamp
&
rhs
)
const
{
return
raw
<
rhs
.
raw
;}
inline
bool
operator
>
(
const
TimeStamp
&
rhs
)
const
{
return
raw
>
rhs
.
raw
;}
inline
bool
operator
<=
(
const
TimeStamp
&
rhs
)
const
{
return
raw
<=
rhs
.
raw
;}
inline
bool
operator
>=
(
const
TimeStamp
&
rhs
)
const
{
return
raw
>=
rhs
.
raw
;}
};
}
/* End of namespace DCDB */
#endif
/* DCDBTIMESTAMP_H */
#endif
/* DCDB
_
TIMESTAMP_H */
DCDBLib/include/unitconv.h
View file @
84f185bc
...
...
@@ -5,68 +5,72 @@
* Author: Axel Auweter
*/
#ifndef UNITCONV_H
#define UNITCONV_H
#include
<cstdint>
#include
<string>
#ifndef DCDB_UNITCONV_H
#define DCDB_UNITCONV_H
namespace
DCDB
{
typedef
enum
{
/* Undefined */
DCDB
Unit_None
,
Unit_None
,
/* Base units */
DCDB
Unit_Meter
,
DCDB
Unit_Second
,
DCDB
Unit_Ampere
,
DCDB
Unit_Kelvin
,
DCDB
Unit_Watt
,
DCDB
Unit_Volt
,
DCDB
Unit_Hertz
,
Unit_Meter
,
Unit_Second
,
Unit_Ampere
,
Unit_Kelvin
,
Unit_Watt
,
Unit_Volt
,
Unit_Hertz
,
/* Others */
DCDB
Unit_Celsius
,
DCDB
Unit_Fahrenheit
,
Unit_Celsius
,
Unit_Fahrenheit
,
/* 1e3 */
DCDB
Unit_KiloHertz
,
Unit_KiloHertz
,
/* 1e6 */
DCDB
Unit_MegaHertz
,
Unit_MegaHertz
,
/* 1e9 */
DCDB
Unit_GigaHertz
,
Unit_GigaHertz
,
/* 1e-2 */
DCDB
Unit_CentiMeter
,
DCDB
Unit_CentiCelsius
,
Unit_CentiMeter
,
Unit_CentiCelsius
,
/* 1e-3 */
DCDB
Unit_MilliMeter
,
DCDB
Unit_MilliSecond
,
DCDB
Unit_MilliAmpere
,
DCDB
Unit_MilliKelvin
,
DCDB
Unit_MilliWatt
,
DCDB
Unit_MilliVolt
,
DCDB
Unit_MilliCelsius
,
Unit_MilliMeter
,
Unit_MilliSecond
,
Unit_MilliAmpere
,
Unit_MilliKelvin
,
Unit_MilliWatt
,
Unit_MilliVolt
,
Unit_MilliCelsius
,
/* 1e-6 */
DCDB
Unit_MicroMeter
,
DCDB
Unit_MicroSecond
,
DCDB
Unit_MicroAmpere
,
DCDB
Unit_MicroKelvin
,
DCDB
Unit_MicroWatt
,
DCDB
Unit_MicroVolt
,
DCDB
Unit_MicroCelsius
,
}
DCDB
Unit
;
Unit_MicroMeter
,
Unit_MicroSecond
,
Unit_MicroAmpere
,
Unit_MicroKelvin
,
Unit_MicroWatt
,
Unit_MicroVolt
,
Unit_MicroCelsius
,
}
Unit
;
class
UnitConv
{
public:
static
DCDB
Unit
fromString
(
std
::
string
unit
);
static
std
::
string
toString
(
DCDB
Unit
unit
);
static
bool
convert
(
int64_t
&
value
,
DCDB
Unit
from
,
DCDB
Unit
to
);
static
bool
convert
(
double
&
value
,
DCDB
Unit
from
,
DCDB
Unit
to
);
static
Unit
fromString
(
std
::
string
unit
);
static
std
::
string
toString
(
Unit
unit
);
static
bool
convert
(
int64_t
&
value
,
Unit
from
,
Unit
to
);
static
bool
convert
(
double
&
value
,
Unit
from
,
Unit
to
);
};
#endif
}
/* End of namespace DCDB */
#endif
/* DCDB_UNITCONV_H */
DCDBLib/include_internal/connection_internal.h
View file @
84f185bc
...
...
@@ -8,8 +8,8 @@
/*
* @file
* @brief This file contains the internal functions of the
*
DCDB
Connection which are provided by the
*
DCDB
ConnectionImpl class.
* Connection which are provided by the
* ConnectionImpl class.
*/
#include
<string>
...
...
@@ -17,10 +17,12 @@
#include
"connection.h"
#ifndef CONNECTION_INTERNAL_H
#define CONNECTION_INTERNAL_H
#ifndef
DCDB_
CONNECTION_INTERNAL_H
#define
DCDB_
CONNECTION_INTERNAL_H
class
DCDBConnectionImpl
namespace
DCDB
{
class
ConnectionImpl
{
protected:
std
::
string
hostname_
;
/**< The hostname of a DB front-end node. */
...
...
@@ -92,57 +94,59 @@ protected:
public:
/**
* @brief The implementation function of
DCDB
Connection::printError().
* @brief The implementation function of Connection::printError().
*/
void
printError
(
CassFuture
*
future
);
/**
* @brief The implementation function of
DCDB
Connection::setHostname().
* @brief The implementation function of Connection::setHostname().
*/
void
setHostname
(
std
::
string
hostname
);
/**
* @brief The implementation function of
DCDB
Connection::getHostname().
* @brief The implementation function of Connection::getHostname().
*/
std
::
string
getHostname
();
/**
* @brief The implementation function of
DCDB
Connection::setPort().
* @brief The implementation function of Connection::setPort().
*/
void
setPort
(
uint16_t
port
);
/**
* @brief The implementation function of
DCDB
Connection::getPort().
* @brief The implementation function of Connection::getPort().
*/
uint16_t
getPort
();
/**
* @brief The implementation function of
DCDB
Connection::connect().
* @brief The implementation function of Connection::connect().
*/
bool
connect
();
/**
* @brief The implementation function of
DCDB
Connection::disconnect().
* @brief The implementation function of Connection::disconnect().
*/
void
disconnect
();
/**
* @brief The implementation function of
DCDB
Connection::getSessionHandle().
* @brief The implementation function of Connection::getSessionHandle().
*/
CassSession
*
getSessionHandle
();
/**
* @brief The implementation function of
DCDB
Connection::executeSimpleQuery().
* @brief The implementation function of Connection::executeSimpleQuery().
*/
CassError
executeSimpleQuery
(
std
::
string
query
);
/**
* @brief The implementation function of
DCDB
Connection::initSchema().
* @brief The implementation function of Connection::initSchema().
*/
bool
initSchema
();
DCDB
ConnectionImpl
();
virtual
~
DCDB
ConnectionImpl
();
ConnectionImpl
();
virtual
~
ConnectionImpl
();
};
#endif
/* CONNECTION_INTERNAL_H */
}
/* End of namespace DCDB */
#endif
/* DCDB_CONNECTION_INTERNAL_H */
DCDBLib/include_internal/sensorconfig_internal.h
View file @
84f185bc
...
...
@@ -16,13 +16,15 @@
#include
"sensorconfig.h"
#ifndef SENSORCONFIG_INTERNAL_H
#define SENSORCONFIG_INTERNAL_H
#ifndef DCDB_SENSORCONFIG_INTERNAL_H
#define DCDB_SENSORCONFIG_INTERNAL_H
namespace
DCDB
{
class
SensorConfigImpl
{
protected:
DCDB
Connection
*
connection
;
Connection
*
connection
;
CassSession
*
session
;
bool
validateSensorPattern
(
const
char
*
sensorPattern
);
...
...
@@ -32,20 +34,22 @@ public:
SCError
publishSensor
(
std
::
string
publicName
,
std
::
string
sensorPattern
);
SCError
unPublishSensor
(
std
::
string
publicName
);
SCError
getPublicSensorNames
(
std
::
list
<
std
::
string
>&
publicSensors
);
SCError
getPublicSensorsVerbose
(
std
::
list
<
DCDB
PublicSensor
>&
publicSensors
);
SCError
getPublicSensorsVerbose
(
std
::
list
<
PublicSensor
>&
publicSensors
);
SCError
getPublicSensorByName
(
DCDB
PublicSensor
&
sensor
,
const
char
*
publicName
);
SCError
getPublicSensorByName
(
PublicSensor
&
sensor
,
const
char
*
publicName
);
SCError
getSensorPattern
(
std
::
string
&
pattern
,
std
::
string
publicName
);
SCError
getSensorListForPattern
(
std
::
list
<
SensorId
>&
sensorIds
,
std
::
string
pattern
);
SCError
getSensorListForPattern
(
std
::
list
<
SensorId
>&
sensorIds
,
std
::
string
pattern
,
DCDB
TimeStamp
start
,
DCDB
TimeStamp
end
);
SCError
getSensorListForPattern
(
std
::
list
<
SensorId
>&
sensorIds
,
std
::
string
pattern
,
TimeStamp
start
,
TimeStamp
end
);
SCError
setSensorScalingFactor
(
std
::
string
publicName
,
double
scalingFactor
);
SCError
setSensorUnit
(
std
::
string
publicName
,
std
::
string
unit
);
SCError
setSensorIntegrable
(
std
::
string
publicName
,
bool
integrable
);
SensorConfigImpl
(
DCDB
Connection
*
conn
);
SensorConfigImpl
(
Connection
*
conn
);
virtual
~
SensorConfigImpl
();
};
#endif
/* SENSORCONFIG_INTERNAL_H */
}
/* End of namespace DCDB */
#endif
/* DCDB_SENSORCONFIG_INTERNAL_H */
DCDBLib/include_internal/sensordatastore_internal.h
View file @
84f185bc
/*
*
dcdb
_internal.h
*
sensordatastore
_internal.h
*
* Internal data structures and definitions for the DCDB
Library
* Internal data structures and definitions for the DCDB
SensorDataStore Class.
*
*/
...
...
@@ -12,14 +12,16 @@
* SensorDataStoreImpl class.
*/
#ifndef DCDB_INTERNAL_H
#define DCDB_INTERNAL_H
#ifndef DCDB_
SENSORDATASTORE_
INTERNAL_H
#define DCDB_
SENSORDATASTORE_
INTERNAL_H
#include
<string>
#include
"sensordatastore.h"
#include
"connection.h"
namespace
DCDB
{
/**