31ec00220214a834717e2963901277e541931ffa
[apps/agl-service-windowmanager-2017.git] / src / pm_wrapper.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_PM_WRAPPER_HPP
18 #define TMCAGLWM_PM_WRAPPER_HPP
19
20 #include <functional>
21 #include <vector>
22 #include <string>
23 #include <map>
24 #include "policy_manager.hpp"
25 #include "request.hpp"
26
27 struct json_object;
28 struct sd_event;
29 struct sd_event_source;
30 struct StmState;
31
32 namespace wm
33 {
34
35 class PMWrapper
36 {
37   public:
38     explicit PMWrapper();
39     ~PMWrapper() = default;
40
41     using StateTransitionHandler = std::function<void(std::vector<WMAction>)>;
42     using ErrorHandler = std::function<void(void)>;
43
44     int initialize();
45     void registerCallback(StateTransitionHandler on_state_transitioned,
46                           ErrorHandler on_error);
47     int setInputEventData(Task task, std::string role, std::string area);
48     int executeStateTransition();
49     void undoState();
50
51     // Do not use these functions
52     void updateStates(json_object *json_out);
53     void processError();
54
55   private:
56     // Disable copy and move
57     PMWrapper(PMWrapper const &) = delete;
58     PMWrapper &operator=(PMWrapper const &) = delete;
59     PMWrapper(PMWrapper &&) = delete;
60     PMWrapper &operator=(PMWrapper &&) = delete;
61
62     typedef std::map<std::string, std::string> RoleState;
63
64     PolicyManager pm;
65     StateTransitionHandler on_state_transitioned;
66     ErrorHandler on_error;
67     std::map<std::string, RoleState> prvlayer2rolestate;
68     std::map<std::string, RoleState> crrlayer2rolestate;
69
70     void createLayoutChangeAction(json_object *json_out, std::vector<WMAction> &actions);
71 };
72
73 } // namespace wm
74
75 #endif // TMCAGLWM_PM_WRAPPER_HPP