Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
dcdb
dcdb
Commits
22931a04
Commit
22931a04
authored
Jun 24, 2019
by
Micha Müller
Browse files
Pusher: ensure entities are only initialized once
parent
30a60213
Changes
3
Hide whitespace changes
Inline
Side-by-side
dcdbpusher/includes/EntityInterface.h
View file @
22931a04
...
...
@@ -55,6 +55,7 @@ public:
EntityInterface
(
const
std
::
string
&
name
)
:
_name
(
name
),
_mqttPart
(
""
),
_initialized
(
false
),
_strand
(
nullptr
)
{}
/**
...
...
@@ -67,6 +68,7 @@ public:
EntityInterface
(
const
EntityInterface
&
other
)
:
_name
(
other
.
_name
),
_mqttPart
(
other
.
_mqttPart
),
_initialized
(
false
),
_strand
(
nullptr
)
{}
/**
...
...
@@ -86,6 +88,7 @@ public:
EntityInterface
&
operator
=
(
const
EntityInterface
&
other
)
{
_name
=
other
.
_name
;
_mqttPart
=
other
.
_mqttPart
;
_initialized
=
false
;
_strand
=
nullptr
;
return
*
this
;
...
...
@@ -123,10 +126,12 @@ public:
* @param io IO service to initialize _strand with.
*/
void
init
(
boost
::
asio
::
io_service
&
io
)
{
if
(
!
_stran
d
)
{
_strand
.
reset
(
new
strand
(
io
))
;
if
(
_initialize
d
)
{
return
;
}
_strand
.
reset
(
new
strand
(
io
));
this
->
execOnInit
();
_initialized
=
true
;
}
/**
...
...
@@ -163,12 +168,13 @@ protected:
*/
virtual
void
printEntityConfig
(
LOG_LEVEL
ll
)
{
/* do nothing if not overwritten */
}
std
::
string
_name
;
/
**
< Name of the entity
*/
std
::
string
_mqttPart
;
/
**
< Partial MQTT topic identifying this entity
*/
std
::
string
_name
;
/
//
< Name of the entity
std
::
string
_mqttPart
;
/
//
< Partial MQTT topic identifying this entity
std
::
unique_ptr
<
strand
>
_strand
;
/**< Provides serialized handler execution
to avoid race conditions */
LOGGER
lg
;
/**< Logging instance */
bool
_initialized
;
///< An entity should only be initialized once
std
::
unique_ptr
<
strand
>
_strand
;
///< Provides serialized handler execution to avoid race conditions
LOGGER
lg
;
///< Logging instance
};
#endif
/* DCDBPUSHER_INCLUDES_ENTITYINTERFACE_H_ */
dcdbpusher/sensors/snmp/SNMPConnection.cpp
View file @
22931a04
...
...
@@ -30,7 +30,6 @@
SNMPConnection
::
SNMPConnection
(
const
std
::
string
&
name
)
:
EntityInterface
(
name
),
_isInitialized
(
false
),
_snmpCommunity
(
""
),
_oidPrefix
(
""
),
_username
(
""
),
...
...
@@ -51,7 +50,6 @@ SNMPConnection::SNMPConnection(const std::string& name) :
SNMPConnection
::
SNMPConnection
(
const
SNMPConnection
&
other
)
:
EntityInterface
(
other
),
_isInitialized
(
false
),
_snmpCommunity
(
other
.
_snmpCommunity
),
_oidPrefix
(
other
.
_oidPrefix
),
_username
(
other
.
_username
),
...
...
@@ -84,7 +82,6 @@ SNMPConnection::~SNMPConnection() {
SNMPConnection
&
SNMPConnection
::
operator
=
(
const
SNMPConnection
&
other
)
{
EntityInterface
::
operator
=
(
other
);
_isInitialized
=
false
;
_snmpCommunity
=
other
.
_snmpCommunity
;
_oidPrefix
=
other
.
_oidPrefix
;
_username
=
other
.
_username
;
...
...
@@ -104,10 +101,6 @@ SNMPConnection& SNMPConnection::operator=(const SNMPConnection& other) {
}
void
SNMPConnection
::
execOnInit
()
{
if
(
_isInitialized
)
{
return
;
}
snmp_sess_init
(
&
_snmpSession
);
int
liberr
,
syserr
;
char
*
errstr
;
...
...
@@ -175,7 +168,6 @@ void SNMPConnection::execOnInit() {
}
else
{
LOG
(
warning
)
<<
"SNMP Version "
<<
_version
<<
" not supported!"
;
}
_isInitialized
=
true
;
}
bool
SNMPConnection
::
open
()
{
...
...
dcdbpusher/sensors/snmp/SNMPConnection.h
View file @
22931a04
...
...
@@ -184,8 +184,6 @@ public:
int64_t
get
(
const
oid
*
const
OID
,
size_t
OIDLen
);
private:
bool
_isInitialized
;
std
::
string
_snmpCommunity
;
std
::
string
_oidPrefix
;
std
::
string
_username
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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