Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
dcdb
dcdb
Commits
26585a60
Commit
26585a60
authored
Aug 06, 2018
by
Micha Mueller
Browse files
Complete non-virtual interface template. Remaining TODO: adapt all plugins
parent
6e62af04
Changes
9
Hide whitespace changes
Inline
Side-by-side
src/Configurator.h
View file @
26585a60
...
...
@@ -8,10 +8,8 @@
#ifndef SRC_CONFIGURATOR_H_
#define SRC_CONFIGURATOR_H_
#include
"
Sensor
.h"
#include
"
ConfiguratorInterface
.h"
#include
<vector>
#include
<string>
#include
<map>
#include
<boost/foreach.hpp>
...
...
@@ -19,20 +17,15 @@
#include
<boost/property_tree/ptree.hpp>
#include
<boost/property_tree/info_parser.hpp>
typedef
struct
{
std
::
string
mqttPrefix
;
std
::
string
tempdir
;
unsigned
int
cacheInterval
;
}
pluginSettings_t
;
/**
* Non-virtual interface template for the configurators.
*/
template
<
typename
S
>
class
Configurator
{
//the template shall only be instantiated for
the sensors corresponding to the configurator
class
Configurator
:
public
ConfiguratorInterface
{
//the template shall only be instantiated for
classes which implement the sensor interface
static_assert
(
std
::
is_base_of
<
Sensor
,
S
>::
value
,
"S must derive from Sensor!"
);
protected:
typedef
std
::
map
<
std
::
string
,
S
>
sensorMap_t
;
public:
...
...
@@ -51,7 +44,7 @@ public:
*
* @return True on success, false otherwise
*/
bool
readConfig
(
std
::
string
cfgPath
)
{
bool
readConfig
(
std
::
string
cfgPath
)
final
{
_cfgPath
=
cfgPath
;
boost
::
property_tree
::
iptree
cfg
;
...
...
@@ -81,7 +74,7 @@ public:
if
(
!
sens
.
second
.
empty
())
{
S
sensor
(
sens
.
second
.
data
());
if
(
readSensor
(
sensor
,
sens
.
second
))
{
_templateSensors
.
insert
(
s
ensorMap_t
::
value_type
(
sensor
.
getName
(),
sensor
));
_templateSensors
.
insert
(
s
td
::
pair
<
std
::
string
,
S
>
(
sensor
.
getName
(),
sensor
));
}
else
{
LOG
(
warning
)
<<
"Template sensor
\"
"
<<
sens
.
second
.
data
()
<<
"
\"
has bad values! Ignoring..."
;
}
...
...
@@ -98,7 +91,7 @@ public:
*
* @return True on success, false otherwise
*/
bool
reReadConfig
()
{
bool
reReadConfig
()
final
{
for
(
auto
s
:
_sensors
)
{
s
->
stopPolling
();
}
...
...
@@ -121,7 +114,7 @@ public:
*
* @param pluginSettings Struct with global default settings for the plugins.
*/
void
setGlobalSettings
(
const
pluginSettings_t
&
pluginSettings
)
{
void
setGlobalSettings
(
const
pluginSettings_t
&
pluginSettings
)
final
{
_mqttPrefix
=
pluginSettings
.
mqttPrefix
;
_cacheInterval
=
pluginSettings
.
cacheInterval
;
...
...
@@ -133,7 +126,7 @@ public:
*
* @return Vector containing pointers to all sensors of this plugin
*/
std
::
vector
<
Sensor
*>&
getSensors
()
{
std
::
vector
<
Sensor
*>&
getSensors
()
final
{
return
_sensors
;
}
...
...
@@ -213,8 +206,4 @@ protected:
boost
::
log
::
sources
::
severity_logger
<
boost
::
log
::
trivial
::
severity_level
>
lg
;
};
//typedef for more readable usage of create()- and destroy()-methods, required for dynamic libraries
typedef
Configurator
<
Sensor
>*
create_t
();
typedef
void
destroy_t
(
Configurator
<
Sensor
>*
);
#endif
/* SRC_CONFIGURATOR_H_ */
src/ConfiguratorInterface.h
0 → 100644
View file @
26585a60
/*
* ConfiguratorInterface.h
*
* Created on: 06.08.2018
* Author: Micha Mueller
*/
#ifndef SRC_CONFIGURATORINTERFACE_H_
#define SRC_CONFIGURATORINTERFACE_H_
#include
"Sensor.h"
#include
<string>
#include
<vector>
typedef
struct
{
std
::
string
mqttPrefix
;
std
::
string
tempdir
;
unsigned
int
cacheInterval
;
}
pluginSettings_t
;
/**
* Abstract interface which defines the functionality of a configurator
*/
class
ConfiguratorInterface
{
public:
virtual
~
ConfiguratorInterface
()
{}
virtual
bool
readConfig
(
std
::
string
cfgPath
)
=
0
;
virtual
bool
reReadConfig
()
=
0
;
virtual
void
setGlobalSettings
(
const
pluginSettings_t
&
pluginSettings
)
=
0
;
virtual
std
::
vector
<
Sensor
*>&
getSensors
()
=
0
;
};
//typedef for more readable usage of create()- and destroy()-methods, required for dynamic libraries
typedef
ConfiguratorInterface
*
create_t
();
typedef
void
destroy_t
(
ConfiguratorInterface
*
);
#endif
/* SRC_CONFIGURATORINTERFACE_H_ */
src/PluginDefinitions.h
View file @
26585a60
...
...
@@ -17,13 +17,13 @@
#include
<string>
#include
<vector>
#include
"Configurator.h"
#include
"Configurator
Interface
.h"
//struct of values required for a dynamic library.
typedef
struct
{
std
::
string
id
;
void
*
DL
;
Configurator
<
Sensor
>
*
configurator
;
Configurator
Interface
*
configurator
;
create_t
*
create
;
destroy_t
*
destroy
;
}
dl_t
;
...
...
src/sensors/bacnet/BACnetConfigurator.h
View file @
26585a60
...
...
@@ -18,7 +18,7 @@
#include
<map>
#include
<boost/property_tree/ptree.hpp>
class
BACnetConfigurator
:
public
Configurator
{
class
BACnetConfigurator
:
public
Configurator
<
BACnetSensor
>
{
typedef
std
::
map
<
std
::
string
,
BACnetSensor
>
sensorMap_t
;
...
...
src/sensors/ipmi/IPMIConfigurator.h
View file @
26585a60
...
...
@@ -20,7 +20,7 @@
namespace
DCDB
{
class
IPMIConfigurator
:
public
Configurator
{
class
IPMIConfigurator
:
public
Configurator
<
IPMISensor
>
{
typedef
std
::
list
<
DCDB
::
IPMIHost
>
hostList_t
;
typedef
std
::
map
<
std
::
string
,
DCDB
::
IPMISensor
>
sensorMap_t
;
...
...
src/sensors/pdu/PDUConfigurator.h
View file @
26585a60
...
...
@@ -17,7 +17,7 @@
#ifndef SRC_SENSORS_PDU_PDUCONFIGURATOR_H_
#define SRC_SENSORS_PDU_PDUCONFIGURATOR_H_
class
PDUConfigurator
:
public
Configurator
{
class
PDUConfigurator
:
public
Configurator
<
PDUSensor
>
{
typedef
std
::
map
<
std
::
string
,
PDUSensor
>
sensorMap_t
;
typedef
std
::
list
<
PDUUnit
>
pduList_t
;
...
...
src/sensors/perfevent/PerfeventConfigurator.h
View file @
26585a60
...
...
@@ -16,7 +16,7 @@
#include
<set>
#include
<boost/property_tree/ptree.hpp>
class
PerfeventConfigurator
:
public
Configurator
{
class
PerfeventConfigurator
:
public
Configurator
<
PerfCounter
>
{
typedef
std
::
map
<
std
::
string
,
PerfCounter
>
counterMap_t
;
typedef
std
::
map
<
std
::
string
,
std
::
set
<
int
>>
templateCpuMap_t
;
...
...
src/sensors/snmp/SNMPConfigurator.h
View file @
26585a60
...
...
@@ -36,11 +36,11 @@ private:
connectionList_t
_connections
;
};
extern
"C"
Configurator
*
create
()
{
extern
"C"
Configurator
Interface
*
create
()
{
return
new
SNMPConfigurator
;
}
extern
"C"
void
destroy
(
Configurator
*
c
)
{
extern
"C"
void
destroy
(
Configurator
Interface
*
c
)
{
delete
c
;
}
...
...
src/sensors/sysfs/SysfsConfigurator.h
View file @
26585a60
...
...
@@ -15,7 +15,7 @@
#include
<map>
#include
<boost/property_tree/ptree.hpp>
class
SysfsConfigurator
:
public
Configurator
{
class
SysfsConfigurator
:
public
Configurator
<
SysfsSensor
>
{
typedef
std
::
map
<
std
::
string
,
SysfsSensor
>
sensorMap_t
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment