Replace json_object_from_file to inputJsonFilie
[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 namespace stm {
25 extern "C" {
26 #include "dummy_stm.h"
27 }
28 } // namespace stm
29
30 struct json_object;
31
32 class PolicyManager {
33
34 public:
35     explicit PolicyManager();
36     ~PolicyManager() = default;
37
38     int initialize();
39     int checkPolicy(json_object* json_in, json_object** json_out);
40     std::string roleToCategory(const char* role);
41 private:
42     // Disable copy and move
43     PolicyManager(PolicyManager const &) = delete;
44     PolicyManager &operator=(PolicyManager const &) = delete;
45     PolicyManager(PolicyManager &&) = delete;
46     PolicyManager &operator=(PolicyManager &&) = delete;
47
48     // Convert map
49     std::unordered_map<std::string, int> eventname2no_;
50     std::unordered_map<std::string, int> categoryname2no_;
51     std::unordered_map<std::string, int> areaname2no_;
52
53     std::unordered_map<std::string, std::string> role2category_;
54     std::unordered_map<std::string, std::string> category2role_;
55     std::unordered_map<std::string, std::string> role2defaultarea_;
56
57     stm::stm_state_t current_state_;
58
59     // Load role.db
60     int loadRoleDb();
61
62     const char* getStringFromJson(json_object* obj, const char* key);
63     int inputJsonFilie(const char* file, json_object** obj);
64     void addStateToJson(const char* key, int is_changed, const char* state, json_object** json_out);
65     std::vector<std::string> parseString(std::string str, char delimiter);
66     std::string deleteSpace(std::string str);
67 };
68
69
70 extern const char* getStringFromJson(json_object* obj, const char* key);
71 extern int getIntFromJson(json_object* obj, const char* key);
72
73
74 #endif  // TMCAGLWM_POLICY_MANAGER_HPP