Commit bd5ce41a authored by Michael Ott's avatar Michael Ott
Browse files

Add SensorConfig::getPublicSensorsByWildcard() to search for public sensors via wildcards

parent edc7490c
......@@ -145,13 +145,22 @@ public:
SCError getPublicSensorsVerbose(std::list<PublicSensor>& publicSensors);
/**
* @brief Get the definition of a virtual sensor.
* @brief Retrieve a public sensor by name.
*
* @param sensor Reference to a PublicSensor object that will be populated with the sensor's definition.
* @param publicName Name of the sensor whose information should be retrieved.
* @return See SCError.
*/
SCError getPublicSensorByName(PublicSensor& sensor, const char* publicName);
/**
* @brief Retrieve a list of public sensors that match a wildcard.
*
* @param sensors Reference to a list of PublicSensor that will be populated with the sensors' definition.
* @param wildcard Wildcard to search for in the list of public sensors.
* @return See SCError.
*/
SCError getPublicSensorsByWildcard(std::list<PublicSensor>& sensors, const char* wildcard);
/**
* @brief Determine whether a given sensor is a virtual sensor.
......
......@@ -61,7 +61,8 @@ public:
SCError getPublicSensorsVerbose(std::list<PublicSensor>& publicSensors);
SCError getPublicSensorByName(PublicSensor& sensor, const char* publicName);
SCError getPublicSensorsByWildcard(std::list<PublicSensor>& sensors, const char* wildcard);
SCError isVirtual(bool& isVirtual, std::string publicName);
SCError getSensorPattern(std::string& pattern, std::string publicName);
......
......@@ -33,6 +33,7 @@
#include <utility>
#include "cassandra.h"
#include <boost/regex.hpp>
#include "sensorconfig_internal.h"
#include "dcdbglobals.h"
......@@ -106,6 +107,11 @@ SCError SensorConfig::getPublicSensorByName(PublicSensor& sensor, const char* pu
return impl->getPublicSensorByName(sensor, publicName);
}
SCError SensorConfig::getPublicSensorsByWildcard(std::list<PublicSensor>& sensors, const char* wildcard)
{
return impl->getPublicSensorsByWildcard(sensors, wildcard);
}
SCError SensorConfig::isVirtual(bool& isVirtual, std::string publicName)
{
return impl->isVirtual(isVirtual, publicName);
......@@ -752,6 +758,63 @@ SCError SensorConfigImpl::getPublicSensorByName(PublicSensor& sensor, const char
return SC_OK;
}
SCError SensorConfigImpl::getPublicSensorsByWildcard(std::list<PublicSensor>& sensors, const char* wildcard)
{
SCError err = SC_OK;
if (strpbrk(wildcard, "*?") == NULL) {
PublicSensor sen;
if ((err = getPublicSensorByName(sen, wildcard)) == SC_OK) {
sensors.push_back(sen);
}
return err;
} else {
if ((err = getPublicSensorsVerbose(sensors)) == SC_OK) {
std::string w("^");
while (*wildcard != 0) {
switch (*wildcard) {
case '.':
case '[':
case '\\':
case '^':
case '$':
w.append("\\");
w.append(wildcard, 1);
break;
case '?':
w.append(".");
break;
case '*':
w.append(".*");
break;
default:
w.append(wildcard, 1);
break;
}
wildcard++;
}
boost::regex r(w, boost::regex::basic);
auto it = sensors.begin();
while(it != sensors.end()) {
if (!boost::regex_match(it->name, r)) {
it = sensors.erase(it);
} else {
it++;
}
}
if (sensors.size() > 0) {
return SC_OK;
} else {
return SC_UNKNOWNSENSOR;
}
} else {
return err;
}
}
}
SCError SensorConfigImpl::isVirtual(bool& isVirtual, std::string publicName)
{
/* Check if the session is valid */
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment