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>
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
#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;
}
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;
}
--- /dev/null
+/*\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
--- /dev/null
+/*
+ *
+ * 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__ */