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
91e1e5a5
Commit
91e1e5a5
authored
Apr 16, 2019
by
Michael Ott
Browse files
Add SensorConfig::getPublicSensorByPattern() to lookup sensors by MQTT pattern
parent
398683b3
Changes
3
Show whitespace changes
Inline
Side-by-side
lib/include/dcdb/sensorconfig.h
View file @
91e1e5a5
...
@@ -162,6 +162,15 @@ public:
...
@@ -162,6 +162,15 @@ public:
*/
*/
SCError
getPublicSensorByName
(
PublicSensor
&
sensor
,
const
char
*
publicName
);
SCError
getPublicSensorByName
(
PublicSensor
&
sensor
,
const
char
*
publicName
);
/**
* @brief Retrieve a public sensor by pattern.
*
* @param sensor Reference to a PublicSensor object that will be populated with the sensor's definition.
* @param pattern Pattern to search for.
* @return See SCError.
*/
SCError
getPublicSensorByPattern
(
PublicSensor
&
sensor
,
const
char
*
pattern
);
/**
/**
* @brief Retrieve a list of public sensors that match a wildcard.
* @brief Retrieve a list of public sensors that match a wildcard.
*
*
...
...
lib/include_internal/sensorconfig_internal.h
View file @
91e1e5a5
...
@@ -50,6 +50,7 @@ protected:
...
@@ -50,6 +50,7 @@ protected:
typedef
std
::
unordered_map
<
std
::
string
,
std
::
reference_wrapper
<
PublicSensor
>>
SensorMap_t
;
typedef
std
::
unordered_map
<
std
::
string
,
std
::
reference_wrapper
<
PublicSensor
>>
SensorMap_t
;
SensorMap_t
sensorMapByName
;
SensorMap_t
sensorMapByName
;
SensorMap_t
sensorMapByPattern
;
std
::
list
<
PublicSensor
>
sensorList
;
std
::
list
<
PublicSensor
>
sensorList
;
bool
validateSensorPattern
(
const
char
*
sensorPattern
);
bool
validateSensorPattern
(
const
char
*
sensorPattern
);
...
@@ -64,6 +65,7 @@ public:
...
@@ -64,6 +65,7 @@ public:
SCError
getPublicSensorsVerbose
(
std
::
list
<
PublicSensor
>&
publicSensors
);
SCError
getPublicSensorsVerbose
(
std
::
list
<
PublicSensor
>&
publicSensors
);
SCError
getPublicSensorByName
(
PublicSensor
&
sensor
,
const
char
*
publicName
);
SCError
getPublicSensorByName
(
PublicSensor
&
sensor
,
const
char
*
publicName
);
SCError
getPublicSensorByPattern
(
PublicSensor
&
sensor
,
const
char
*
pattern
);
SCError
getPublicSensorsByWildcard
(
std
::
list
<
PublicSensor
>&
sensors
,
const
char
*
wildcard
);
SCError
getPublicSensorsByWildcard
(
std
::
list
<
PublicSensor
>&
sensors
,
const
char
*
wildcard
);
SCError
isVirtual
(
bool
&
isVirtual
,
std
::
string
publicName
);
SCError
isVirtual
(
bool
&
isVirtual
,
std
::
string
publicName
);
...
...
lib/src/sensorconfig.cpp
View file @
91e1e5a5
...
@@ -113,6 +113,11 @@ SCError SensorConfig::getPublicSensorByName(PublicSensor& sensor, const char* pu
...
@@ -113,6 +113,11 @@ SCError SensorConfig::getPublicSensorByName(PublicSensor& sensor, const char* pu
return
impl
->
getPublicSensorByName
(
sensor
,
publicName
);
return
impl
->
getPublicSensorByName
(
sensor
,
publicName
);
}
}
SCError
SensorConfig
::
getPublicSensorByPattern
(
PublicSensor
&
sensor
,
const
char
*
pattern
)
{
return
impl
->
getPublicSensorByPattern
(
sensor
,
pattern
);
}
SCError
SensorConfig
::
getPublicSensorsByWildcard
(
std
::
list
<
PublicSensor
>&
sensors
,
const
char
*
wildcard
)
SCError
SensorConfig
::
getPublicSensorsByWildcard
(
std
::
list
<
PublicSensor
>&
sensors
,
const
char
*
wildcard
)
{
{
return
impl
->
getPublicSensorsByWildcard
(
sensors
,
wildcard
);
return
impl
->
getPublicSensorsByWildcard
(
sensors
,
wildcard
);
...
@@ -276,6 +281,7 @@ SCError SensorConfigImpl::loadCache()
...
@@ -276,6 +281,7 @@ SCError SensorConfigImpl::loadCache()
{
{
sensorList
.
clear
();
sensorList
.
clear
();
sensorMapByName
.
clear
();
sensorMapByName
.
clear
();
sensorMapByPattern
.
clear
();
SCError
rc
=
getPublicSensorsVerbose
(
sensorList
);
SCError
rc
=
getPublicSensorsVerbose
(
sensorList
);
if
(
rc
!=
SC_OK
)
{
if
(
rc
!=
SC_OK
)
{
...
@@ -283,6 +289,7 @@ SCError SensorConfigImpl::loadCache()
...
@@ -283,6 +289,7 @@ SCError SensorConfigImpl::loadCache()
}
else
{
}
else
{
for
(
auto
&
s
:
sensorList
)
{
for
(
auto
&
s
:
sensorList
)
{
sensorMapByName
.
insert
(
std
::
make_pair
(
s
.
name
,
std
::
ref
(
s
)));
sensorMapByName
.
insert
(
std
::
make_pair
(
s
.
name
,
std
::
ref
(
s
)));
sensorMapByPattern
.
insert
(
std
::
make_pair
(
s
.
pattern
,
std
::
ref
(
s
)));
}
}
return
SC_OK
;
return
SC_OK
;
}
}
...
@@ -761,6 +768,7 @@ SCError SensorConfigImpl::getPublicSensorByName(PublicSensor& sensor, const char
...
@@ -761,6 +768,7 @@ SCError SensorConfigImpl::getPublicSensorByName(PublicSensor& sensor, const char
/* Add to sensorPropertyCache for later use */
/* Add to sensorPropertyCache for later use */
sensorMapByName
.
insert
(
std
::
make_pair
(
publicName
,
std
::
ref
(
sensor
)));
sensorMapByName
.
insert
(
std
::
make_pair
(
publicName
,
std
::
ref
(
sensor
)));
sensorMapByPattern
.
insert
(
std
::
make_pair
(
sensor
.
pattern
,
std
::
ref
(
sensor
)));
}
}
else
{
else
{
cass_result_free
(
result
);
cass_result_free
(
result
);
...
@@ -780,6 +788,21 @@ SCError SensorConfigImpl::getPublicSensorByName(PublicSensor& sensor, const char
...
@@ -780,6 +788,21 @@ SCError SensorConfigImpl::getPublicSensorByName(PublicSensor& sensor, const char
return
SC_OK
;
return
SC_OK
;
}
}
SCError
SensorConfigImpl
::
getPublicSensorByPattern
(
PublicSensor
&
sensor
,
const
char
*
pattern
)
{
if
(
sensorList
.
size
()
==
0
)
{
loadCache
();
}
SensorMap_t
::
const_iterator
got
=
sensorMapByPattern
.
find
(
pattern
);
if
(
got
!=
sensorMapByPattern
.
end
())
{
sensor
=
got
->
second
;
return
SC_OK
;
}
else
{
return
SC_UNKNOWNSENSOR
;
}
}
SCError
SensorConfigImpl
::
getPublicSensorsByWildcard
(
std
::
list
<
PublicSensor
>&
sensors
,
const
char
*
wildcard
)
SCError
SensorConfigImpl
::
getPublicSensorsByWildcard
(
std
::
list
<
PublicSensor
>&
sensors
,
const
char
*
wildcard
)
{
{
SCError
err
=
SC_OK
;
SCError
err
=
SC_OK
;
...
...
Write
Preview
Supports
Markdown
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