Add vconf notify handler for maintenance mode 60/167160/7
authorseolheui kim <s414.kim@samsung.com>
Tue, 16 Jan 2018 02:32:32 +0000 (11:32 +0900)
committerseolheui kim <s414.kim@samsung.com>
Fri, 19 Jan 2018 04:07:17 +0000 (13:07 +0900)
Change-Id: I166c4fce71734958e6a891e38993300188b7af26
Signed-off-by: seolheui kim <s414.kim@samsung.com>
libs/policy-client.cpp
libs/policy-client.h

index 67f336c88df83ef139b0c856030ba81650ec5eab..4794fa74755c6e827d1f5baa5bd4261306069523 100644 (file)
@@ -22,8 +22,6 @@
 
 #include "policy-client.h"
 
-#include <vconf.h>
-
 #define VCONFKEY_DPM_MODE_STATE "db/dpm/mode_state"
 
 namespace {
@@ -35,23 +33,31 @@ const std::string POLICY_MANAGER_ADDRESS = "/tmp/.device-policy-manager.sock";
 
 } // namespace
 
+void DevicePolicyClient::maintenanceModeDispatcher(keynode_t *node, void *data)
+{
+       int *mode = reinterpret_cast<int *>(data);
+       ::vconf_get_bool(VCONFKEY_DPM_MODE_STATE, mode);
+}
 
 DevicePolicyClient::DevicePolicyClient() noexcept :
-       clientAddress(POLICY_MANAGER_ADDRESS)
+       maintenanceMode(0), clientAddress(POLICY_MANAGER_ADDRESS)
 {
        mainloop.reset(new ScopedGMainLoop);
+       ::vconf_notify_key_changed(VCONFKEY_DPM_MODE_STATE, maintenanceModeDispatcher, reinterpret_cast<void*>(&this->maintenanceMode));
+       ::vconf_get_bool(VCONFKEY_DPM_MODE_STATE, &maintenanceMode);
 }
 
 DevicePolicyClient::~DevicePolicyClient() noexcept
 {
        mainloop.reset();
+       ::vconf_ignore_key_changed(VCONFKEY_DPM_MODE_STATE, maintenanceModeDispatcher);
 }
 
 int DevicePolicyClient::subscribeSignal(const std::string& name,
                                                                                const SignalHandler& handler,
                                                                                void* data) noexcept
 {
-       if (!getMaintenanceMode())
+       if (!maintenanceMode)
                return 0;
 
        int ret = -1;
@@ -76,7 +82,7 @@ int DevicePolicyClient::subscribeSignal(const std::string& name,
 
 int DevicePolicyClient::unsubscribeSignal(int id) noexcept
 {
-       if (!getMaintenanceMode())
+       if (!maintenanceMode)
                return 0;
 
        try {
@@ -91,12 +97,3 @@ int DevicePolicyClient::unsubscribeSignal(int id) noexcept
                return -1;
        }
 }
-
-int DevicePolicyClient::getMaintenanceMode()
-{
-       int value = 0;
-
-       ::vconf_get_bool(VCONFKEY_DPM_MODE_STATE, &value);
-
-       return value;
-}
index f37cdee5de88dc4bd02bb0308a0f7dd58fb7803d..f07eb8ef4ffce78e4765024e0b501b92a0a10b56 100644 (file)
@@ -22,6 +22,8 @@
 #include <functional>
 #include <cerrno>
 
+#include <vconf.h>
+
 #include <klay/rmi/method.h>
 #include <klay/gmainloop.h>
 
@@ -36,12 +38,11 @@ public:
                                                const SignalHandler& handler,
                                                void* data) noexcept;
        int unsubscribeSignal(int subscriberId) noexcept;
-       int getMaintenanceMode();
 
        template<typename Type, typename... Args>
        Type methodCall(const std::string& method, Args&&... args)
        {
-               if (!getMaintenanceMode()) {
+               if (!maintenanceMode) {
                        errno = EPROTONOSUPPORT;
                        return Type();
                }
@@ -52,6 +53,10 @@ public:
        }
 
 private:
+       static void maintenanceModeDispatcher(keynode_t *node, void *data);
+
+private:
+       int maintenanceMode;
        std::string clientAddress;
        std::unique_ptr<ScopedGMainLoop> mainloop;
 };