Commit 8de75a8c authored by Axel Auweter's avatar Axel Auweter
Browse files

Cleanups.

parent 6ff0040e
......@@ -25,6 +25,7 @@ typedef enum {
DCDB_C_OK,
DCDB_C_CONNERR,
DCDB_C_SENSORNOTFOUND,
DCDB_C_EMPTYSET,
DCDB_C_UNKNOWN
} DCDB_C_RESULT;
......
......@@ -24,6 +24,11 @@
#ifndef SENSORDATASTORE_H_
#define SENSORDATASTORE_H_
typedef enum {
SDS_OK,
SDS_EMPTYSET
} SDSQueryResult;
/* Forward-declaration of the implementation-internal classes */
class SensorDataStoreImpl;
......@@ -89,8 +94,9 @@ public:
* @param sid The SensorId to query.
* @param start Start of the time series.
* @param end End of the time series.
* @return SDS_OK if ok, SDS_EMPTYSET if not at least 2 readings in interval.
*/
void querySum(int64_t& result, SensorId sid, DCDBTimeStamp start, DCDBTimeStamp end);
SDSQueryResult querySum(int64_t& result, SensorId sid, DCDBTimeStamp start, DCDBTimeStamp end);
/**
* @brief A shortcut constructor for a SensorDataStore object
......
......@@ -70,8 +70,9 @@ public:
* @param sid The SensorId to query.
* @param start Start of the time series.
* @param end End of the time series.
* @return SDS_OK if ok, SDS_EMPTYSET if not at least 2 readings in interval.
*/
void querySum(int64_t& result, SensorId sid, DCDBTimeStamp start, DCDBTimeStamp end);
SDSQueryResult querySum(int64_t& result, SensorId sid, DCDBTimeStamp start, DCDBTimeStamp end);
/**
* @brief This is the standard constructor of the SensorDataStoreImpl class.
......
......@@ -81,7 +81,11 @@ DCDB_C_RESULT dcdbQuerySum(
/* Iterate over the expanded list of sensorIds and sum up the results */
for (std::list<SensorId>::iterator sit = sensorIds.begin(); sit != sensorIds.end(); sit++) {
int64_t tmp_result = 0;
sensorDataStore.querySum(tmp_result, *sit, start, end);
if (sensorDataStore.querySum(tmp_result, *sit, start, end) == SDS_EMPTYSET) {
/* In case there is no reading for this sensor, invalidate everything */
*result = 0;
return DCDB_C_EMPTYSET;
}
*result += tmp_result;
}
......
......@@ -233,13 +233,17 @@ void SensorDataStoreImpl::query(std::list<SensorDataStoreReading>& result, Senso
* by first querying for the result set list using query() and then
* summing up the result.
*/
void SensorDataStoreImpl::querySum(int64_t& result, SensorId sid, DCDBTimeStamp start, DCDBTimeStamp end)
SDSQueryResult SensorDataStoreImpl::querySum(int64_t& result, SensorId sid, DCDBTimeStamp start, DCDBTimeStamp end)
{
std::list<SensorDataStoreReading> queryResult;
/* Issue a standard query */
query(queryResult, sid, start, end);
/* Check if at least 2 readings in result */
if (queryResult.size() < 2)
return SDS_EMPTYSET;
/* Integrate the result */
result = 0;
......@@ -268,6 +272,7 @@ void SensorDataStoreImpl::querySum(int64_t& result, SensorId sid, DCDBTimeStamp
}
prev = *it;
}
return SDS_OK;
}
/**
......@@ -337,9 +342,9 @@ void SensorDataStore::query(std::list<SensorDataStoreReading>& result, SensorId
* forwards to the insert function of the SensorDataStoreImpl
* class.
*/
void SensorDataStore::querySum(int64_t& result, SensorId sid, DCDBTimeStamp start, DCDBTimeStamp end)
SDSQueryResult SensorDataStore::querySum(int64_t& result, SensorId sid, DCDBTimeStamp start, DCDBTimeStamp end)
{
impl->querySum(result, sid, start, end);
return impl->querySum(result, sid, start, end);
}
/**
......
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