From: i.metelytsia Date: Tue, 3 Oct 2017 13:53:04 +0000 (+0300) Subject: [SECIOTSRK-586] : Notification for shutdown X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=45a25e964a3ee8d06bff7886084b3afe92da16cf;p=platform%2Fcore%2Fsecurity%2Fsuspicious-activity-monitor.git [SECIOTSRK-586] : Notification for shutdown --- diff --git a/device_core/nmdaemon/commandhandler.cpp b/device_core/nmdaemon/commandhandler.cpp index b4645ce..11bce08 100644 --- a/device_core/nmdaemon/commandhandler.cpp +++ b/device_core/nmdaemon/commandhandler.cpp @@ -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("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); diff --git a/device_core/nmdaemon/commandhandler.h b/device_core/nmdaemon/commandhandler.h index c480122..f24cc37 100644 --- a/device_core/nmdaemon/commandhandler.h +++ b/device_core/nmdaemon/commandhandler.h @@ -41,6 +41,8 @@ public: bool uninstallCommand(const OC::OCRepresentation& command); + bool shutdownCommand(const OC::OCRepresentation& command); + void unOwnTask(); private: diff --git a/device_core/nmdaemon/dpm/dpm_api_mapper.cpp b/device_core/nmdaemon/dpm/dpm_api_mapper.cpp index defa44b..52b006a 100644 --- a/device_core/nmdaemon/dpm/dpm_api_mapper.cpp +++ b/device_core/nmdaemon/dpm/dpm_api_mapper.cpp @@ -38,10 +38,10 @@ typedef function ApiInt; typedef function ApiStr; typedef function 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 m = { - {"device_power_off", dpm_device_power_off}, - {"lockout-screen", dpm_security_lockout_screen}, }; diff --git a/device_core/nmdaemon/dpm/dpm_api_mapper.h b/device_core/nmdaemon/dpm/dpm_api_mapper.h index d5d3c61..026afc8 100644 --- a/device_core/nmdaemon/dpm/dpm_api_mapper.h +++ b/device_core/nmdaemon/dpm/dpm_api_mapper.h @@ -34,6 +34,8 @@ public: error_code apply(const std::string& name, const int param, const std::vector& items); + static error_code device_power_off(); + protected: error_code work(const std::string& name, const int param, const std::vector& items); };