Add classes associated with policy of dpm 34/139734/10
authoryeji01kim <yeji01.kim@samsung.com>
Thu, 20 Jul 2017 07:50:56 +0000 (16:50 +0900)
committeryeji01kim <yeji01.kim@samsung.com>
Fri, 11 Aug 2017 07:32:08 +0000 (16:32 +0900)
Dpm-toolkit provides dpm policy testing.
Add dpm policy related classes for testing.

AbstractPolicy : parent of each policy group.
PolicyBuilder : build policies to testing.

Change-Id: Ice749c8dcd79cd34e2a72cbdc41d2e5cb9a9dcf3
Signed-off-by: yeji01kim <yeji01.kim@samsung.com>
CMakeLists.txt
src/main.cpp
src/policy.cpp [new file with mode: 0755]
src/policy.h [new file with mode: 0755]

index 61f9841..d711d76 100755 (executable)
@@ -49,12 +49,13 @@ else()
        SET(CXX_STD "c++11")
 endif()
 
-INCLUDE_DIRECTORIES(${test_pkgs_INCLUDE_DIRS} include)
+INCLUDE_DIRECTORIES(${test_pkgs_INCLUDE_DIRS} include src)
 LINK_DIRECTORIES(${test_pkgs_LIBRARY_DIRS})
 
 SET(BASE_SRCS   src/main.cpp
                                src/workbench-factory.cpp
-                               src/workbench.cpp)
+                               src/workbench.cpp
+                               src/policy.cpp)
 
 SET(UI_SRCS  src/ui/widget.cpp
                         src/ui/window.cpp
index 0e328cf..e84ec99 100755 (executable)
 
 #include "dpmtoolkit.h"
 #include "workbench-factory.h"
+#include "policy.h"
 
 int main(int argc, char *argv[])
 {
+       int ret;
        char *nullCheck =::strrchr(argv[0], '/');
        std::unique_ptr<Workbench> workbench = NULL;
        std::string name;
@@ -36,8 +38,12 @@ int main(int argc, char *argv[])
        }
        catch(runtime::Exception & e) {
                ::dlog_print(DLOG_ERROR, LOG_TAG, "%s", e.what());
+               PolicyCleaner::deletePolicies();
                return -1;
        }
 
-       return workbench->run(argc, argv);
+       ret = workbench->run(argc, argv);
+       PolicyCleaner::deletePolicies();
+
+       return ret;
 }
diff --git a/src/policy.cpp b/src/policy.cpp
new file mode 100755 (executable)
index 0000000..27df440
--- /dev/null
@@ -0,0 +1,20 @@
+/*\r
+ *\r
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ */\r
+#include "policy.h"\r
+\r
+std::vector<AbstractPolicy *> managedPolicy;\r
diff --git a/src/policy.h b/src/policy.h
new file mode 100755 (executable)
index 0000000..d0a6304
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ *
+ * Copyright (c) 2017 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.
+ *
+ */
+
+#ifndef __ABSTRACT_POLICY_H__
+#define __ABSTRACT_POLICY_H__
+
+#include "dpmtoolkit.h"
+#include "workbench.h"
+
+#include <vector>
+
+#define POLICY_RESULT_FAIL -1
+#define POLICY_RESULT_SUCCESS 0
+
+class AbstractPolicy {
+public:
+       virtual ~AbstractPolicy() {}
+
+       virtual std::vector<WorkbenchActionDelegate> inspect() = 0;
+
+protected:
+       AbstractPolicy(const std::string& name) : description(name) { }
+
+public:
+       std::string description;
+};
+
+extern std::vector<AbstractPolicy *> managedPolicy;
+
+template<typename T>
+class PolicyBuilder {
+public:
+       PolicyBuilder(const std::string& name) {
+               managedPolicy.emplace_back(new T(name));
+       }
+};
+
+class PolicyCleaner {
+public:
+       static void deletePolicies() {
+               std::vector<AbstractPolicy *>::iterator iter;
+               for (iter = managedPolicy.begin(); iter != managedPolicy.end(); ++iter) {
+                       delete (*iter);
+               }
+               managedPolicy.clear();
+       }
+};
+#endif /* __ABSTRACT_POLICY_H__ */