[SECIOTSRK-586] : Notification for shutdown
authori.metelytsia <i.metelytsia@samsung.com>
Tue, 3 Oct 2017 13:53:04 +0000 (16:53 +0300)
committeri.metelytsia <i.metelytsia@samsung.com>
Tue, 3 Oct 2017 13:53:53 +0000 (16:53 +0300)
device_core/nmdaemon/commandhandler.cpp
device_core/nmdaemon/commandhandler.h
device_core/nmdaemon/dpm/dpm_api_mapper.cpp
device_core/nmdaemon/dpm/dpm_api_mapper.h

index b4645ce..11bce08 100644 (file)
@@ -4,6 +4,7 @@
 #include "application_service.h"
 #include "logging.h"
 #include "device_control.h"
+#include "dpm/dpm_api_mapper.h"
 
 #define TAG "nmdaemon"
 
@@ -43,6 +44,9 @@ bool CommandHandler::process(const OC::OCRepresentation& command)
     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;
@@ -82,6 +86,38 @@ bool CommandHandler::uninstallCommand(const OC::OCRepresentation& command)
     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);
index c480122..f24cc37 100644 (file)
@@ -41,6 +41,8 @@ public:
 
     bool uninstallCommand(const OC::OCRepresentation& command);
 
+    bool shutdownCommand(const OC::OCRepresentation& command);
+
     void unOwnTask();
 
 private:
index defa44b..52b006a 100644 (file)
@@ -38,10 +38,10 @@ typedef function<int(dpmh, int)>  ApiInt;
 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__)
@@ -88,8 +88,6 @@ int dpm_restriction_get_tuner_state(dpmh handle, int* is_allowed)
 #endif
 
 const map<const string, ApiNone> m = {
-    {"device_power_off", dpm_device_power_off},
-
     {"lockout-screen",         dpm_security_lockout_screen},
 };
 
index d5d3c61..026afc8 100644 (file)
@@ -34,6 +34,8 @@ public:
 
     error_code apply(const std::string& name, const int param, const std::vector<std::string>& items);
 
+    static error_code device_power_off();
+
 protected:
     error_code work(const std::string& name, const int param, const std::vector<std::string>& items);
 };