Apply template-method-pattern to policy-model
authorSangwan Kwon <sangwan.kwon@samsung.com>
Tue, 17 Sep 2019 06:03:23 +0000 (15:03 +0900)
committer권상완/Security 2Lab(SR)/Engineer/삼성전자 <sangwan.kwon@samsung.com>
Thu, 10 Oct 2019 06:26:21 +0000 (15:26 +0900)
Signed-off-by: Sangwan Kwon <sangwan.kwon@samsung.com>
12 files changed:
plugins/bluetooth/bluetooth.cpp
src/policyd/pil/CMakeLists.txt
src/policyd/pil/domain-policy.h [new file with mode: 0644]
src/policyd/pil/global-policy.h [new file with mode: 0644]
src/policyd/pil/policy-model.h
src/policyd/server/CMakeLists.txt
src/policyd/server/plugin.cpp
src/policyd/server/plugin.h
src/policyd/server/server.cpp
src/policyd/server/server.h
src/policyd/tests/CMakeLists.txt
src/policyd/tests/test-server.cpp

index 553ae3b..f9df95c 100644 (file)
 #include <bluetooth-api.h>
 #include <bluetooth_internal.h>
 
-#include <policyd/pil/policy-context.h>
-#include <policyd/pil/policy-model.h>
+#include <policyd/pil/global-policy.h>
 #include <policyd/pil/policy-storage.h>
 #include <policyd/pil/policy-event.h>
 
+#include <memory>
+
 #include "../dlog.h"
 
 #define BT_FAILED(ret)                                       \
@@ -46,14 +47,14 @@ inline int canonicalize(int value)
 
 } // namespace
 
-class ModeChange : public GlobalPolicy<DataSetInt> {
+class ModeChange : public GlobalPolicy {
 public:
        ModeChange() : GlobalPolicy("bluetooth")
        {
                PolicyEventNotifier::create("bluetooth");
        }
 
-       bool apply(const DataType& value)
+       bool apply(const DataSetInt& value, uid_t)
        {
                int ret = bluetooth_dpm_set_allow_mode(STATE_CHANGE_IS_ALLOWED(value));
                if (!BT_FAILED(ret)) {
@@ -65,14 +66,14 @@ public:
        }
 };
 
-class DesktopConnectivity : public GlobalPolicy<DataSetInt> {
+class DesktopConnectivity : public GlobalPolicy {
 public:
        DesktopConnectivity() : GlobalPolicy("bluetooth-desktop-connectivity")
        {
                PolicyEventNotifier::create("bluetooth_desktop_connectivity");
        }
 
-       bool apply(const DataType & value)
+       bool apply(const DataSetInt & value, uid_t)
        {
                int ret = bluetooth_dpm_set_desktop_connectivity_state(POLICY_IS_ALLOWED(value));
                if (!BT_FAILED(ret)) {
@@ -85,14 +86,14 @@ public:
        }
 };
 
-class Pairing: public GlobalPolicy<DataSetInt> {
+class Pairing: public GlobalPolicy {
 public:
        Pairing() : GlobalPolicy("bluetooth-pairing")
        {
                PolicyEventNotifier::create("bluetooth_pairing");
        }
 
-       bool apply(const DataType& value)
+       bool apply(const DataSetInt& value, uid_t)
        {
                int ret = bluetooth_dpm_set_pairing_state(POLICY_IS_ALLOWED(value));
                if (!BT_FAILED(ret)) {
@@ -105,14 +106,14 @@ public:
        }
 };
 
-class Tethering: public GlobalPolicy<DataSetInt> {
+class Tethering: public GlobalPolicy {
 public:
        Tethering() : GlobalPolicy("bluetooth-tethering")
        {
                PolicyEventNotifier::create("bluetooth_tethering");
        }
 
-       bool apply(const DataType& value)
+       bool apply(const DataSetInt& value, uid_t)
        {
                int enable = value;
                PolicyEventNotifier::emit("bluetooth_tethering",
@@ -126,34 +127,19 @@ public:
        Bluetooth();
        ~Bluetooth();
 
-       int setModeChangeState(bool enable);
-       bool getModeChangeState();
-       int setDesktopConnectivityState(bool enable);
-       bool getDesktopConnectivityState();
-       int setTetheringState(bool enable);
-       bool getTetheringState();
-       int setPairingState(bool enable);
-       bool getPairingState();
-
 private:
        static void onStateChanged(int result, bt_adapter_state_e state, void *user_data);
-
-private:
-       ModeChange          modeChange;
-       DesktopConnectivity connectivity;
-       Pairing             pairing;
-       Tethering          tethering;
 };
 
 Bluetooth::Bluetooth()
 {
        if (::bt_initialize() != BT_ERROR_NONE) {
-               ERROR(PLUGINS, "Bluetooth framework was not initilaized");
+               ERROR(PLUGINS,"Bluetooth framework was not initilaized");
                return;
        }
 
        if (::bt_adapter_set_state_changed_cb(onStateChanged, this) != BT_ERROR_NONE) {
-               ERROR(PLUGINS, "Failed to register Bluetooth callback");
+               ERROR(PLUGINS,"Failed to register Bluetooth callback");
                return;
        }
 }
@@ -174,96 +160,3 @@ void Bluetooth::onStateChanged(int result, bt_adapter_state_e state, void *user_
 //             pimpl->uuidRestriction.enforce();
        }
 }
-
-int Bluetooth::setModeChangeState(bool enable)
-{
-       try {
-               modeChange.set(enable);
-       } catch (runtime::Exception& e) {
-               ERROR(PLUGINS, "Exception: " << e.what());
-               return -1;
-       }
-
-       return 0;
-}
-
-bool Bluetooth::getModeChangeState()
-{
-       return modeChange.get();
-}
-
-int Bluetooth::setDesktopConnectivityState(bool enable)
-{
-       try {
-               connectivity.set(enable);
-       } catch (runtime::Exception& e) {
-               ERROR(PLUGINS, "Exception: " << e.what());
-               return -1;
-       }
-
-       return 0;
-}
-
-bool Bluetooth::getDesktopConnectivityState()
-{
-       return connectivity.get();
-}
-
-int Bluetooth::setPairingState(bool enable)
-{
-       try {
-               pairing.set(enable);
-       } catch (runtime::Exception& e) {
-               ERROR(PLUGINS, "Exception: " << e.what());
-               return -1;
-       }
-
-       return 0;
-}
-
-bool Bluetooth::getPairingState()
-{
-       return pairing.get();
-}
-
-int Bluetooth::setTetheringState(bool enable)
-{
-       try {
-               tethering.set(enable);
-       } catch (runtime::Exception& e) {
-               ERROR(PLUGINS, "Exception " << e.what());
-               return -1;
-       }
-
-       return 0;
-}
-
-bool Bluetooth::getTetheringState()
-{
-       return tethering.get();
-}
-
-
-extern "C" {
-
-#define PRIVILEGE "http://tizen.org/privilege/dpm.bluetooth"
-
-AbstractPolicyProvider *PolicyFactory(PolicyControlContext& context)
-{
-       INFO(PLUGINS, "Bluetooth plugin loaded");
-       Bluetooth *policy = new Bluetooth();
-
-       context.expose(policy, PRIVILEGE, (int)(Bluetooth::setModeChangeState)(bool));
-       context.expose(policy, PRIVILEGE, (int)(Bluetooth::setDesktopConnectivityState)(bool));
-       context.expose(policy, PRIVILEGE, (int)(Bluetooth::setTetheringState)(bool));
-       context.expose(policy, PRIVILEGE, (int)(Bluetooth::setPairingState)(bool));
-
-       context.expose(policy, "", (bool)(Bluetooth::getModeChangeState)());
-       context.expose(policy, "", (bool)(Bluetooth::getDesktopConnectivityState)());
-       context.expose(policy, "", (bool)(Bluetooth::getTetheringState)());
-       context.expose(policy, "", (bool)(Bluetooth::getPairingState)());
-
-       return policy;
-}
-
-} // extern "C"
index 6756bb4..4cf1a88 100644 (file)
@@ -32,7 +32,6 @@ SET(PAPIS app-bundle.h
                  logger.h
                  packman.h
                  policy-event.h
-                 policy-context.h
                  policy-admin.h
                  policy-client.h
                  policy-model.h
@@ -40,27 +39,28 @@ SET(PAPIS app-bundle.h
                  status.h
                  observer.h)
 
-SET(PIL_DEPENDENCY klay
-                                  glib-2.0
-                                  gio-2.0
-                                  sqlite3
-                                  bundle
-                                  aul
-                                  appsvc
-                                  pkgmgr
-                                  pkgmgr-info
-                                  syspopup-caller
-                                  deviced
-                                  libtzplatform-config
-                                  security-privilege-manager
-                                  capi-system-info
-                                  capi-base-common
-                                  capi-system-system-settings
-                                  cynara-client
-                                  notification
-                                  cynara-session)
+SET(DEPENDENCY klay
+                          glib-2.0
+                          gio-2.0
+                          sqlite3
+                          bundle
+                          aul
+                          appsvc
+                          pkgmgr
+                          pkgmgr-info
+                          vconf
+                          syspopup-caller
+                          deviced
+                          libtzplatform-config
+                          security-privilege-manager
+                          capi-system-info
+                          capi-base-common
+                          capi-system-system-settings
+                          notification
+                          cynara-client
+                          cynara-session)
 
-PKG_CHECK_MODULES(PIL_DEPS REQUIRED ${PIL_DEPENDENCY})
+PKG_CHECK_MODULES(PIL_DEPS REQUIRED ${DEPENDENCY})
 
 INCLUDE_DIRECTORIES(SYSTEM "${PIL_DEPS_INCLUDE_DIRS}")
 
diff --git a/src/policyd/pil/domain-policy.h b/src/policyd/pil/domain-policy.h
new file mode 100644 (file)
index 0000000..87bfca1
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+ *  Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+
+#pragma once
+
+#include <string>
+#include <unordered_map>
+
+#include <klay/rmi/service.h>
+
+#include "policy-model.h"
+
+class DomainPolicy : public AbstractPolicy {
+public:
+       DomainPolicy(const std::string& name) : AbstractPolicy(name) {}
+       virtual ~DomainPolicy() = default;
+
+       DomainPolicy(const DomainPolicy&) = delete;
+       DomainPolicy& operator=(const DomainPolicy&) = delete;
+
+       DomainPolicy(DomainPolicy&&) = default;
+       DomainPolicy& operator=(DomainPolicy&&) = default;
+
+       inline void set(const DataSetInt& val) override
+       {
+               PolicyAdmin admin(rmi::Service::getPeerPid(), rmi::Service::getPeerUid());
+               PolicyStorage::update(id, admin.getName(), admin.getUid(), val);
+
+               std::lock_guard<std::mutex> mtxGuard(mtx);
+               this->enforce(admin.getUid());
+       }
+
+       inline DataSetInt get() override
+       {
+               uid_t domain = rmi::Service::getPeerUid();
+
+               std::lock_guard<std::mutex> mtxGuard(mtx);
+               if (!current.count(domain))
+                       enforce(domain);
+
+               return current[domain].value;
+       }
+
+private:
+       inline void enforce(uid_t domain) override
+       {
+               auto value = initial;
+               if (!ready[domain])
+                       current[domain] = initial;
+
+               PolicyStorage::strictize(id, value, domain);
+               if (current[domain] != value) {
+                       apply(value, domain);
+                       current[domain] = value;
+               }
+
+               ready[domain] = true;
+       }
+
+private:
+       std::unordered_map<uid_t, DataSetInt> current;
+       std::unordered_map<uid_t, bool> ready;
+};
diff --git a/src/policyd/pil/global-policy.h b/src/policyd/pil/global-policy.h
new file mode 100644 (file)
index 0000000..a99198b
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ *  Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+
+#pragma once
+
+#include <string>
+#include <unordered_map>
+
+#include <klay/rmi/service.h>
+
+#include "policy-model.h"
+
+class GlobalPolicy : public AbstractPolicy {
+public:
+       GlobalPolicy(const std::string& name) : AbstractPolicy(name) {}
+       virtual ~GlobalPolicy() = default;
+
+       GlobalPolicy(const GlobalPolicy&) = delete;
+       GlobalPolicy& operator=(const GlobalPolicy&) = delete;
+
+       GlobalPolicy(GlobalPolicy&&) = default;
+       GlobalPolicy& operator=(GlobalPolicy&&) = default;
+
+       inline void set(const DataSetInt& val) override
+       {
+               PolicyAdmin admin(rmi::Service::getPeerPid(), rmi::Service::getPeerUid());
+               PolicyStorage::update(id, admin.getName(), admin.getUid(), val);
+
+               std::lock_guard<std::mutex> mtxGuard(mtx);
+               enforce(-1);
+       }
+
+       inline DataSetInt get() override
+       {
+               std::lock_guard<std::mutex> mtxGuard(mtx);
+               if (!ready) {
+                       enforce(-1);
+                       ready = true;
+               }
+               return current.value;
+       }
+
+private:
+       inline void enforce(uid_t) override
+       {
+               auto value = initial;
+               PolicyStorage::strictize(id, value);
+               if (current != value) {
+                       apply(value);
+                       current = value;
+               }
+       }
+
+private:
+       DataSetInt current;
+       bool ready = false;
+};
index c9df02c..2f0580a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *  Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
  *  limitations under the License
  */
 
-#ifndef __DPM_POLICY_MODEL_H__
-#define __DPM_POLICY_MODEL_H__
+#pragma once
+
 #include <string>
 #include <vector>
-#include <unordered_map>
-#include <iostream>
 #include <mutex>
+#include <memory>
 
 #include <klay/exception.h>
 
 #include "policy-admin.h"
 #include "observer.h"
 
-class AbstractPolicyProvider {
-public:
+class AbstractPolicy;
+
+struct AbstractPolicyProvider {
        AbstractPolicyProvider() {}
        virtual ~AbstractPolicyProvider() {}
+
+       std::vector<std::shared_ptr<AbstractPolicy>> policies;
 };
 
-template<typename Type>
-class DomainPolicy : public Observer {
+class AbstractPolicy : public Observer {
 public:
-       typedef Type DataType;
-
-       DomainPolicy(const std::string& name);
-       virtual ~DomainPolicy();
-
-       void set(const Type& value);
-       DataType get();
-
-       void onEvent(uid_t domain);
-
-       virtual bool apply(const Type& value, uid_t domain)
+       explicit AbstractPolicy(const std::string& name) : name(name)
        {
-               return true;
-       }
+               this->id = PolicyStorage::define(name, initial);
+               if (id < 0)
+                       throw runtime::Exception("Failed to define policy");
 
-private:
-       void enforce(uid_t domid);
-
-private:
-       int id;
-       Type initial;
-       std::unordered_map<uid_t, Type> current;
-       std::unordered_map<uid_t, bool> ready;
-       std::mutex mtx;
-};
-
-template<typename Type>
-DomainPolicy<Type>::DomainPolicy(const std::string& name) :
-       id(-1), current()
-{
-       id = PolicyStorage::define(name, initial);
-       if (id < 0) {
-               throw runtime::Exception("Failed to define policy");
+               PolicyStorage::subscribeEvent(this);
        }
 
-       PolicyStorage::subscribeEvent(this);
-}
-
-template<typename Type>
-DomainPolicy<Type>::~DomainPolicy()
-{
-}
-
-template<typename Type>
-void DomainPolicy<Type>::enforce(uid_t domid)
-{
-       Type value = initial;
-       if (!ready[domid])
-               current[domid] = initial;
-
-       PolicyStorage::strictize(id, value, domid);
-       if (current[domid] != value) {
-               apply(value, domid);
-               current[domid] = value;
-       }
+       ~AbstractPolicy() = default;
 
-       ready[domid] = true;
-}
+       AbstractPolicy(const AbstractPolicy&) = delete;
+       AbstractPolicy& operator=(const AbstractPolicy&) = delete;
 
-template<typename Type>
-void DomainPolicy<Type>::set(const DataType& val)
-{
-       PolicyAdmin admin(rmi::Service::getPeerPid(), rmi::Service::getPeerUid());
-       PolicyStorage::update(id, admin.getName(), admin.getUid(), val);
+       AbstractPolicy(AbstractPolicy&&) = default;
+       AbstractPolicy& operator=(AbstractPolicy&&) = default;
 
-       std::lock_guard<std::mutex> mtxGuard(mtx);
-       enforce(admin.getUid());
-}
+       virtual void set(const DataSetInt& value) = 0;
+       virtual DataSetInt get() = 0;
 
-template<typename Type>
-Type DomainPolicy<Type>::get()
-{
-       uid_t domain = rmi::Service::getPeerUid();
+       virtual bool apply(const DataSetInt& value, uid_t domain = 0) = 0;
 
-       std::lock_guard<std::mutex> mtxGuard(mtx);
-       if (!current.count(domain)) {
+       inline void onEvent(uid_t domain)
+       {
+               std::lock_guard<std::mutex> mtxGuard(mtx);
                enforce(domain);
        }
 
-       return current[domain].value;
-}
+       std::string name;
 
-template<typename Type>
-void DomainPolicy<Type>::onEvent(uid_t domain)
-{
-       std::lock_guard<std::mutex> mtxGuard(mtx);
-       enforce(domain);
-}
-
-template<typename Type>
-class GlobalPolicy : public Observer {
-public:
-       typedef Type DataType;
-
-       GlobalPolicy(const std::string& name);
-       virtual ~GlobalPolicy();
-
-       void set(const Type& value);
-       Type get();
-
-       void onEvent(uid_t domain);
-
-       virtual bool apply(const Type& value)
-       {
-               return true;
-       }
-
-private:
-       void enforce();
+protected:
+       int id = -1;
+       std::mutex mtx;
+       DataSetInt initial;
 
 private:
-       int id;
-       Type initial;
-       Type current;
-       bool ready;
-       std::mutex mtx;
+       virtual void enforce(uid_t domain = 0) = 0;
 };
-
-template<typename Type>
-GlobalPolicy<Type>::GlobalPolicy(const std::string& name) :
-       id(-1), current(), ready(false)
-{
-       id = PolicyStorage::define(name, initial);
-       if (id < 0) {
-               throw runtime::Exception("Failed to define policy");
-       }
-
-       current = initial;
-       PolicyStorage::subscribeEvent(this);
-}
-
-template<typename Type>
-GlobalPolicy<Type>::~GlobalPolicy()
-{
-}
-
-template<typename Type>
-void GlobalPolicy<Type>::enforce()
-{
-       Type value = initial;
-       PolicyStorage::strictize(id, value);
-       if (current != value) {
-               apply(value);
-               current = value;
-       }
-}
-
-template<typename Type>
-void GlobalPolicy<Type>::set(const Type& val)
-{
-       PolicyAdmin admin(rmi::Service::getPeerPid(), rmi::Service::getPeerUid());
-       PolicyStorage::update(id, admin.getName(), admin.getUid(), val);
-
-       std::lock_guard<std::mutex> mtxGuard(mtx);
-       enforce();
-}
-
-template<typename Type>
-Type GlobalPolicy<Type>::get()
-{
-       std::lock_guard<std::mutex> mtxGuard(mtx);
-       if (!ready) {
-               enforce();
-               ready = true;
-       }
-       return current.value;
-}
-
-template<typename Type>
-void GlobalPolicy<Type>::onEvent(uid_t domain)
-{
-       std::lock_guard<std::mutex> mtxGuard(mtx);
-       enforce();
-}
-#endif //__DPM_POLICY_MODEL_H__
index e0872ca..7d179be 100644 (file)
@@ -55,4 +55,4 @@ TARGET_LINK_LIBRARIES(${TARGET} dl pthread sqlite3 dpm-pil ${TARGET_SERVER_LIB})
 SET_TARGET_PROPERTIES(${TARGET} PROPERTIES COMPILE_FLAGS "-fPIE")
 SET_TARGET_PROPERTIES(${TARGET} PROPERTIES LINK_FLAGS "-pie")
 
-INSTALL(TARGETS ${TARGET} DESTINATION ${CMAKE_INSTALL_BINDIR})
+INSTALL(TARGETS ${TARGET} DESTINATION bin)
index 6fae176..34e218d 100644 (file)
@@ -53,7 +53,7 @@ PolicyLoader::PolicyLoader(const std::string& base) :
 {
 }
 
-AbstractPolicyProvider* PolicyLoader::instantiate(const std::string& name, PolicyControlContext& context)
+std::shared_ptr<AbstractPolicyProvider> PolicyLoader::instantiate(const std::string& name)
 {
        PluginMap::iterator iter = pluginMap.find(name);
        if (iter == pluginMap.end()) {
@@ -72,7 +72,8 @@ AbstractPolicyProvider* PolicyLoader::instantiate(const std::string& name, Polic
 
                pluginMap[name] = std::move(plguin);
 
-               return (*factory)(context);
+               auto provider = (*factory)();
+               return std::shared_ptr<AbstractPolicyProvider>(provider);
        }
 
        return nullptr;
index a709fc7..7fe3013 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *  Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
  *  limitations under the License
  */
 
-#ifndef __DPM_PLUGIN_H__
-#define __DPM_PLUGIN_H__
+#pragma once
+
 #include <string>
 #include <exception>
 #include <unordered_map>
+#include <memory>
 
-#include "pil/policy-context.h"
 #include "pil/policy-model.h"
 
 class Plugin {
@@ -48,10 +48,10 @@ private:
 
 class PolicyLoader {
 public:
-       typedef AbstractPolicyProvider* (*PolicyFactory)(PolicyControlContext& context);
+       typedef AbstractPolicyProvider* (*PolicyFactory)();
 
        PolicyLoader(const std::string& base);
-       AbstractPolicyProvider* instantiate(const std::string& name, rmi::Service& context);
+       std::shared_ptr<AbstractPolicyProvider> instantiate(const std::string& name);
 
 private:
        typedef std::unordered_map<std::string, Plugin> PluginMap;
@@ -59,5 +59,3 @@ private:
        std::string basename;
        PluginMap pluginMap;
 };
-
-#endif /*!__DPM_PLUGIN_H__*/
index ff932e1..c5894f8 100644 (file)
@@ -94,7 +94,7 @@ std::pair<int, int> DevicePolicyManager::loadPolicyPlugins()
                        continue;
                }
 
-               auto instance = policyLoader->instantiate(iter->getName(), *this);
+               auto instance = policyLoader->instantiate(iter->getName());
                if (instance == nullptr) {
                        ERROR(DPM, "Failed to instantiate.: " << iter->getName());
                        ++failed;
@@ -102,7 +102,7 @@ std::pair<int, int> DevicePolicyManager::loadPolicyPlugins()
                        continue;
                }
 
-               policyList.push_back(instance);
+               providerList.emplace_back(std::move(instance));
                ++passed;
                ++iter;
        }
index 38931e2..bd4cd99 100644 (file)
@@ -44,6 +44,12 @@ public:
 
        void run(int activation, int timeout);
 
+       // Temporary debug method
+       inline std::vector<std::shared_ptr<AbstractPolicyProvider>>& getProviderList()
+       {
+               return this->providerList;
+       }
+
 private:
        void initPolicyStorage();
 
@@ -60,7 +66,7 @@ private:
        typedef std::unordered_map<int, int> ClientRegistry;
        ClientRegistry clientRegistry;
 
-       std::vector<AbstractPolicyProvider *> policyList;
+       std::vector<std::shared_ptr<AbstractPolicyProvider>> providerList;
        std::unique_ptr<PolicyLoader> policyLoader;
        std::thread policyApplyThread;
 
index e60c3e8..0d63b83 100644 (file)
@@ -1,4 +1,4 @@
-#  Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+#  Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
 #
 #  Licensed under the Apache License, Version 2.0 (the "License");
 #  you may not use this file except in compliance with the License.
index a1b30bb..bd8d5ea 100644 (file)
 
 #include <klay/testbench.h>
 
+#include <iostream>
+
 TESTCASE(LOAD_PLUGINS)
 {
        DevicePolicyManager manager;
        auto result = manager.loadPolicyPlugins();
+
+       // Temporary debug method
+       auto providers = manager.getProviderList();
+       for (const auto& provider : providers) {
+               for (const auto& policy : provider->policies) {
+                       std::cout << "Policy Lists:" << std::endl;
+                       std::cout << "\t" << policy->name << std::endl;
+               }
+       }
+
        TEST_EXPECT(true, result.first > 0);
        TEST_EXPECT(true, result.second == 0);
 }