#include "application_service.h"
#include "logging.h"
#include "device_control.h"
+#include "dpm/dpm_api_mapper.h"
#define TAG "nmdaemon"
case DeviceCommands::UNINSTALL:
LOG_D(TAG, "Uninstall command received");
return uninstallCommand(command);
+ case DeviceCommands::SHUTDOWN:
+ LOG_D(TAG, "Shutdown command received");
+ return shutdownCommand(command);
default:
LOG_E(TAG, "Error: unknown command received");
return false;
return result;
}
+bool CommandHandler::shutdownCommand(const OC::OCRepresentation& command)
+{
+ std::string duid = command.getValue<std::string>("duid");
+ LOG_D(TAG, "Request to shutdown \"%s\"", duid.c_str());
+
+ if (duid.empty()) {
+ return false;
+ }
+
+ bool result = false;
+
+ if (duid == m_iotivity->getDeviceID()) {
+ LOG_D(TAG, "Request for this device");
+ result = (dpm_api::Mapper::device_power_off() == dpm_api::SUCCESS);
+ } else {
+ LOG_D(TAG, "Request for device: %s", duid.c_str());
+
+ if ((result = m_hub->isOwned(duid))) {
+ LOG_D(TAG, "Proxying shutdown request");
+ NetworkManager::IoTivity* iot = m_iotivity;
+ auto task = [duid, iot] {
+ NetworkManager::DeviceControl control("", duid, iot);
+ control.shutdownDevice(duid);
+ };
+
+ m_proxy_thread->addDefferedTask(task);
+ }
+ }
+
+ return result;
+}
+
bool CommandHandler::unOwnCommand(const OC::OCRepresentation& command)
{
m_proxy_thread->addDefferedTask(&CommandHandler::unOwnTask, this);
typedef function<int(dpmh, const char*)> ApiStr;
typedef function<int(dpmh, int, const char*)> ApiIntStr;
-int dpm_device_power_off(dpmh)
+dpm_api::error_code Mapper::device_power_off()
{
sync();
- return reboot(RB_POWER_OFF);
+ return (reboot(RB_POWER_OFF) == 0) ? dpm_api::SUCCESS : dpm_api::UNKNOWN;
}
#if defined(__BUILD_UBUNTU__) || defined(__MOCK_THIRDPARTY__)
#endif
const map<const string, ApiNone> m = {
- {"device_power_off", dpm_device_power_off},
-
{"lockout-screen", dpm_security_lockout_screen},
};