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

Allow for wildcards (* and ?) to be used when specifying sensornames

parent cd53294b
...@@ -109,7 +109,7 @@ void DCDBQuery::genOutput(std::list<DCDB::SensorDataStoreReading> &results, quer ...@@ -109,7 +109,7 @@ void DCDBQuery::genOutput(std::list<DCDB::SensorDataStoreReading> &results, quer
DCDB::TimeStamp ts = (*reading).timeStamp; DCDB::TimeStamp ts = (*reading).timeStamp;
/* Print the sensor's public name */ /* Print the sensor's public name */
std::cout << start->first << ","; std::cout << start->first.name << ",";
/* Print the time stamp */ /* Print the time stamp */
if (useLocalTime) if (useLocalTime)
...@@ -180,6 +180,9 @@ void DCDBQuery::doQuery(const char* hostname, std::list<std::string> sensors, DC ...@@ -180,6 +180,9 @@ void DCDBQuery::doQuery(const char* hostname, std::list<std::string> sensors, DC
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
/* Initialize the SensorConfig interface */
DCDB::SensorConfig sensorConfig(connection);
/* Iterate over list of sensors requested by the user */ /* Iterate over list of sensors requested by the user */
for (std::list<std::string>::iterator it = sensors.begin(); it != sensors.end(); it++) { for (std::list<std::string>::iterator it = sensors.begin(); it != sensors.end(); it++) {
notifyOverflow = false; notifyOverflow = false;
...@@ -229,32 +232,31 @@ void DCDBQuery::doQuery(const char* hostname, std::list<std::string> sensors, DC ...@@ -229,32 +232,31 @@ void DCDBQuery::doQuery(const char* hostname, std::list<std::string> sensors, DC
queryCfg.unit = DCDB::UnitConv::fromString(modifierStr); queryCfg.unit = DCDB::UnitConv::fromString(modifierStr);
} }
} }
queries.insert(std::pair<std::string,queryConfig_t>(sensorName, queryCfg)); std::list<DCDB::PublicSensor> publicSensors;
sensorConfig.getPublicSensorsByWildcard(publicSensors, sensorName.c_str());
for (auto sen: publicSensors) {
queries.insert(std::pair<DCDB::PublicSensor,queryConfig_t>(sen, queryCfg));
}
} }
} }
/* Initialize the SensorConfig interface */
DCDB::SensorConfig sensorConfig(connection);
std::string prevSensorName; std::string prevSensorName;
for (auto q: queries) { for (auto q: queries) {
if (q.first != prevSensorName) { if (q.first.name != prevSensorName) {
std::pair<queryMap_t::iterator, queryMap_t::iterator> range = queries.equal_range(q.first); std::pair<queryMap_t::iterator, queryMap_t::iterator> range = queries.equal_range(q.first);
DCDB::PublicSensor sen;
sensorConfig.getPublicSensorByName(sen, q.first.c_str());
/* Base scaling factor and unit of the public sensor */ /* Base scaling factor and unit of the public sensor */
baseUnit = DCDB::UnitConv::fromString(sen.unit); baseUnit = DCDB::UnitConv::fromString(q.first.unit);
baseScalingFactor = sen.scaling_factor; baseScalingFactor = q.first.scaling_factor;
std::list<DCDB::SensorDataStoreReading> results; std::list<DCDB::SensorDataStoreReading> results;
DCDB::Sensor sensor(connection, sen); DCDB::Sensor sensor(connection, q.first);
sensor.query(results, start, end, DCDB::AGGREGATE_NONE); sensor.query(results, start, end, DCDB::AGGREGATE_NONE);
genOutput(results, range.first, range.second); genOutput(results, range.first, range.second);
if(notifyOverflow) if(notifyOverflow)
std::cout << "Overflow detected." << std::endl; std::cout << "Overflow detected." << std::endl;
prevSensorName = q.first; prevSensorName = q.first.name;
} }
} }
......
...@@ -58,7 +58,7 @@ typedef struct queryConfig { ...@@ -58,7 +58,7 @@ typedef struct queryConfig {
DCDB::Unit unit; DCDB::Unit unit;
DCDB_OP_TYPE operation; DCDB_OP_TYPE operation;
} queryConfig_t; } queryConfig_t;
typedef std::multimap<std::string, queryConfig_t> queryMap_t; typedef std::multimap<DCDB::PublicSensor, queryConfig_t> queryMap_t;
typedef enum { typedef enum {
CONVERT_OK, CONVERT_OK,
...@@ -70,7 +70,7 @@ protected: ...@@ -70,7 +70,7 @@ protected:
bool useLocalTime; bool useLocalTime;
bool useRawOutput; bool useRawOutput;
std::multimap<std::string, queryConfig_t> queries; queryMap_t queries;
double baseScalingFactor; double baseScalingFactor;
DCDB::Unit baseUnit; DCDB::Unit baseUnit;
......
Markdown is supported
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