Commit 47bcc980 authored by Axel Auweter's avatar Axel Auweter
Browse files

Implented sensor unpublish feature.

parent b85f1a1c
......@@ -55,6 +55,7 @@ protected:
public:
SCError publishSensor(const char* publicName, const char* sensorPattern);
SCError unPublishSensor(const char* publicName);
SCError getPublicSensorNames(std::list<std::string>& publicSensors);
SCError getPublicSensorsVerbose(std::list<DCDBPublicSensor>& publicSensors);
......
......@@ -29,6 +29,7 @@ protected:
public:
SCError publishSensor(std::string publicName, std::string sensorPattern);
SCError unPublishSensor(std::string publicName);
SCError getPublicSensorNames(std::list<std::string>& publicSensors);
SCError getPublicSensorsVerbose(std::list<DCDBPublicSensor>& publicSensors);
......
......@@ -43,6 +43,11 @@ SCError SensorConfig::publishSensor(const char* publicName, const char* sensorPa
return impl->publishSensor(publicName, sensorPattern);
}
SCError SensorConfig::unPublishSensor(const char* publicName)
{
return impl->unPublishSensor(publicName);
}
SCError SensorConfig::getPublicSensorNames(std::list<std::string>& publicSensors)
{
return impl->getPublicSensorNames(publicSensors);
......@@ -242,6 +247,59 @@ SCError SensorConfigImpl::publishSensor(std::string publicName, std::string sens
return SC_OK;
}
SCError SensorConfigImpl::unPublishSensor(std::string publicName)
{
/* Check if the session is valid */
if (!session) {
return SC_INVALIDSESSION;
}
/* Remove the entry */
CassError rc = CASS_OK;
CassStatement* statement = nullptr;
CassFuture* future = nullptr;
const CassPrepared* prepared = nullptr;
const char* query = "DELETE FROM " CONFIG_KEYSPACE_NAME "." CF_PUBLISHEDSENSORS " WHERE name = ? ;";
future = cass_session_prepare(session, query);
cass_future_wait(future);
rc = cass_future_error_code(future);
if (rc != CASS_OK) {
connection->printError(future);
cass_future_free(future);
return SC_UNKNOWNERROR;
} else {
prepared = cass_future_get_prepared(future);
}
cass_future_free(future);
statement = cass_prepared_bind(prepared);
cass_statement_bind_string_by_name(statement, "name", publicName.c_str());
future = cass_session_execute(session, statement);
cass_future_wait(future);
rc = cass_future_error_code(future);
if (rc != CASS_OK) {
connection->printError(future);
cass_prepared_free(prepared);
cass_future_free(future);
cass_statement_free(statement);
return SC_UNKNOWNERROR;
}
cass_prepared_free(prepared);
cass_future_free(future);
cass_statement_free(statement);
return SC_OK;
}
SCError SensorConfigImpl::getPublicSensorNames(std::list<std::string>& publicSensors)
{
/* Check if the session is valid */
......
......@@ -33,6 +33,7 @@ void SensorAction::printHelp(int argc, char* argv[])
std::cout << " SCALINGFACTOR <public name> <fac> - Set scaling factor to <fac>." << std::endl;
std::cout << " UNIT <public name> <unit> - Set unit to <unit>." << std::endl;
std::cout << " INTEGRABLE <public name> [ON|OFF] - Mark sensor integrable." << std::endl;
std::cout << " UNPUBLISH <public name> - Unpublish a sensor." << std::endl;
}
/*
......@@ -101,6 +102,14 @@ int SensorAction::executeCommand(int argc, char* argv[], int argvidx, const char
}
doIntegrable(argv[argvidx+1], argv[argvidx+2]);
}
else if (strcasecmp(argv[argvidx], "UNPUBLISH") == 0) {
/* UNPUBLISH needs one more parameter */
if (argvidx+1 >= argc) {
std::cout << "UNPUBLISH needs a parameter!" << std::endl;
goto executeCommandError;
}
doUnPublishSensor(argv[argvidx+1]);
}
else {
std::cout << "Invalid SENSOR command: " << argv[argvidx] << std::endl;
goto executeCommandError;
......@@ -271,3 +280,12 @@ void SensorAction::doIntegrable(const char* publicName, const char* cmd)
std::cout << "Internal error." << std::endl;
}
}
/*
* Unpublish a sensor
*/
void SensorAction::doUnPublishSensor(const char* publicName)
{
SensorConfig sensorConfig(connection);
sensorConfig.unPublishSensor(publicName);
}
......@@ -31,6 +31,7 @@ protected:
void doScalingfactor(const char* publicName, const char* factor);
void doUnit(const char* publicName, const char* unit);
void doIntegrable(const char* publicName, const char* cmd);
void doUnPublishSensor(const char* publicName);
};
#endif
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