PolicyManager can judge the current car state
[apps/agl-service-windowmanager.git] / src / policy_manager / policy_manager.hpp
1 /*
2  * Copyright (c) 2018 TOYOTA MOTOR CORPORATION
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef TMCAGLWM_POLICY_MANAGER_HPP
18 #define TMCAGLWM_POLICY_MANAGER_HPP
19
20
21 #include <unordered_map>
22 #include <vector>
23
24
25 struct json_object;
26
27 class PolicyManager {
28
29 public:
30     explicit PolicyManager();
31     ~PolicyManager() = default;
32
33     int initialize();
34     int checkPolicy(json_object* json_in, json_object** json_out);
35     std::string roleToCategory(const char* role);
36 private:
37     // Disable copy and move
38     PolicyManager(PolicyManager const &) = delete;
39     PolicyManager &operator=(PolicyManager const &) = delete;
40     PolicyManager(PolicyManager &&) = delete;
41     PolicyManager &operator=(PolicyManager &&) = delete;
42
43     // Convert map
44     std::unordered_map<std::string, int> eventname2no_;
45     std::unordered_map<std::string, int> categoryname2no_;
46     std::unordered_map<std::string, int> areaname2no_;
47
48     std::unordered_map<std::string, std::string> role2category_;
49     std::unordered_map<std::string, std::string> category2role_;
50     std::unordered_map<std::string, std::string> role2defaultarea_;
51
52     // Load role.db
53     int loadRoleDb();
54
55     const char* getStringFromJson(json_object* obj, const char* key);
56     int inputJsonFilie(const char* file, json_object** obj);
57     void addStateToJson(const char* key, int is_changed, const char* state, json_object** json_out);
58     std::vector<std::string> parseString(std::string str, char delimiter);
59     std::string deleteSpace(std::string str);
60 };
61
62
63 extern const char* getStringFromJson(json_object* obj, const char* key);
64 extern int getIntFromJson(json_object* obj, const char* key);
65
66
67 #endif  // TMCAGLWM_POLICY_MANAGER_HPP