Add server run method for maintenance mode. 27/167427/5
authorseolheui kim <s414.kim@samsung.com>
Wed, 17 Jan 2018 13:00:37 +0000 (22:00 +0900)
committerseolheui kim <s414.kim@samsung.com>
Thu, 18 Jan 2018 07:48:23 +0000 (16:48 +0900)
Change-Id: Ibb0d5683c13ef04f9e4da9b2184b590fad445b56
Signed-off-by: seolheui kim <s414.kim@samsung.com>
server/main.cpp
server/server.cpp
server/server.h

index 902d92c..70ce62a 100644 (file)
@@ -86,7 +86,7 @@ int main(int argc, char *argv[])
                manager.loadPolicyPlugins();
                manager.applyPolicies();
 
-               manager.start(ondemand, timeout);
+               manager.run(ondemand, timeout);
        } catch (std::exception &e) {
                ERROR(DPM, e.what());
                return EXIT_FAILURE;
index a955c95..8d5d70f 100644 (file)
@@ -43,6 +43,13 @@ const std::string PolicyPluginBase = PLUGIN_INSTALL_DIR;
 
 } // namespace
 
+void DevicePolicyManager::modeChangeDispatcher(keynode_t *node, void *data)
+{
+       DevicePolicyManager *manager = reinterpret_cast<DevicePolicyManager*>(data);
+       if (!manager->getMaintenanceMode())
+               manager->stop();
+}
+
 DevicePolicyManager::DevicePolicyManager() :
        rmi::Service(PolicyManagerSocket)
 {
@@ -62,6 +69,8 @@ DevicePolicyManager::~DevicePolicyManager()
 {
        if (policyApplyThread.joinable())
                policyApplyThread.join();
+
+       ::vconf_ignore_key_changed(VCONFKEY_DPM_MODE_STATE, modeChangeDispatcher);
 }
 
 void DevicePolicyManager::loadPolicyPlugins()
@@ -98,10 +107,11 @@ void DevicePolicyManager::initPolicyStorage()
        PolicyStorage::setBackend(backend);
        DEBUG(DPM, "Success to init policy-storage.");
 
-       bool mode = false;
+       int mode = 0;
        if(loadManagedClients() > 0) {
-               mode = true;
+               mode = 1;
        }
+
        if(::vconf_set_bool(VCONFKEY_DPM_MODE_STATE, mode) != 0) {
                DEBUG(DPM, "VCONFKEY_DPM_MODE_STATE set  failed.");
        }
@@ -112,15 +122,31 @@ void DevicePolicyManager::applyPolicies()
        policyApplyThread = std::thread(PolicyStorage::notify);
 }
 
+bool DevicePolicyManager::getMaintenanceMode()
+{
+       return loadManagedClients() > 0 ? true : false;
+}
+
+void DevicePolicyManager::run(int activation, int timeout)
+{
+       if (getMaintenanceMode()) {
+               /* Maintenance mode */
+               ::vconf_notify_key_changed(VCONFKEY_DPM_MODE_STATE, modeChangeDispatcher, reinterpret_cast<void*>(this));
+               timeout = -1;
+               DEBUG(DPM, "Set maintenance mode");
+       }
+
+       start(activation, timeout);
+}
+
 int DevicePolicyManager::enroll(const std::string& name, uid_t uid)
 {
        int ret = PolicyStorage::enroll(name, uid);
        if(ret == 0) {
-               if(::vconf_set_bool(VCONFKEY_DPM_MODE_STATE, true) != 0) {
+               if(::vconf_set_bool(VCONFKEY_DPM_MODE_STATE, 1) != 0) {
                        DEBUG(DPM, "VCONFKEY_DPM_MODE_STATE set  failed.");
                }
        }
-
        return ret;
 }
 
@@ -129,12 +155,11 @@ int DevicePolicyManager::disenroll(const std::string& name, uid_t uid)
        int ret = PolicyStorage::unenroll(name, uid);
        if(ret == 0) {
                if(loadManagedClients() == 0) {
-                       if(::vconf_set_bool(VCONFKEY_DPM_MODE_STATE, false) != 0) {
+                       if(::vconf_set_bool(VCONFKEY_DPM_MODE_STATE, 0) != 0) {
                                DEBUG(DPM, "VCONFKEY_DPM_MODE_STATE set  failed.");
                        }
                }
        }
-
        return ret;
 }
 
index d28f2a0..c65d770 100644 (file)
@@ -21,6 +21,8 @@
 #include <memory>
 #include <vector>
 
+#include <vconf.h>
+
 #include <klay/filesystem.h>
 #include <klay/file-descriptor.h>
 #include <klay/rmi/service.h>
@@ -39,6 +41,8 @@ public:
        void loadPolicyPlugins();
        void applyPolicies();
 
+       void run(int activation, int timeout);
+
 private:
        void initPolicyStorage();
 
@@ -49,6 +53,9 @@ private:
        bool checkNewConnection(const rmi::Connection& connection);
        bool checkCloseConnection(const rmi::Connection& connection);
 
+       bool getMaintenanceMode();
+       static void modeChangeDispatcher(keynode_t *node, void *data);
+
 private:
        typedef std::unordered_map<int, int> ClientRegistry;
        ClientRegistry clientRegistry;