X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;ds=inline;f=src%2Fpolicy_manager%2Fpolicy_manager.hpp;fp=src%2Fpolicy_manager%2Fpolicy_manager.hpp;h=1f69474847069a7ecb113a5d514c561911e46c22;hb=99b6f4d2fcd421d3a760a88a67e511fb6fc98068;hp=0000000000000000000000000000000000000000;hpb=8ab10aaafc6fb3dc7bbad755dce9b4bdaa41f287;p=apps%2Fagl-service-windowmanager.git diff --git a/src/policy_manager/policy_manager.hpp b/src/policy_manager/policy_manager.hpp new file mode 100644 index 0000000..1f69474 --- /dev/null +++ b/src/policy_manager/policy_manager.hpp @@ -0,0 +1,144 @@ +/* + * Copyright (c) 2018 TOYOTA MOTOR CORPORATION + * + * 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 TMCAGLWM_POLICY_MANAGER_HPP +#define TMCAGLWM_POLICY_MANAGER_HPP + +#include +#include +#include +#include + +struct json_object; +struct sd_event; +struct sd_event_source; +struct StmState; + +class PolicyManager +{ + + public: + explicit PolicyManager(); + ~PolicyManager() = default; + + using Handler = std::function; + + typedef struct + { + Handler onStateTransitioned; + Handler onError; + } CallbackTable; + + int initialize(); + void registerCallback(CallbackTable callback_table); + int setInputEventData(json_object *json_in); + int executeStateTransition(); + void undoState(); + + // Do not use these functions + int transitionState(sd_event_source *source, void *data); + int timerEvent(sd_event_source *source, uint64_t usec, void *data); + + private: + // Disable copy and move + PolicyManager(PolicyManager const &) = delete; + PolicyManager &operator=(PolicyManager const &) = delete; + PolicyManager(PolicyManager &&) = delete; + PolicyManager &operator=(PolicyManager &&) = delete; + + typedef struct EventInfo + { + int event; + std::string role; + uint64_t delay; + } EventInfo; + + typedef struct AreaState + { + std::string name; + std::string category; + std::string role; + } AreaState; + + typedef std::vector AreaList; + typedef struct LayoutState + { + std::string name; + std::map category_num; + AreaList area_list; + } LayoutState; + + typedef struct LayerState + { + std::string name; + LayoutState layout_state; + bool changed; + } LayerState; + + // Convert map + std::unordered_map eventname2no; + std::unordered_map categoryname2no; + std::unordered_map areaname2no; + + std::unordered_map role2category; + std::unordered_map category2role; + std::unordered_map role2defaultarea; + + struct sd_event *event_loop; + std::queue event_info_queue; + std::map event_source_list; + std::map req_role_list; + + CallbackTable callback; + + std::unordered_map prv_layers; + std::unordered_map crr_layers; + + std::unordered_map default_layouts; + + std::map> role_history; + + void initializeState(); + void initializeLayerState(); + void updateState(int event_data, StmState crr_state); + void updateLayerState(int event_data, StmState crr_state); + void createOutputInformation(StmState crr_state, json_object **json_out); + int setStateTransitionProcessToSystemd(int event, uint64_t delay_ms, std::string role); + + void pushRoleHistory(std::string category, std::string role); + std::string popRoleHistory(std::string category); + + int loadRoleDb(); + int loadLayoutDb(); + + void dumpLayerState(std::unordered_map &layers); + void dumpRoleHistory(); + + void addStateToJson(const char *name, bool changed, + std::string state, json_object **json_out); + void addStateToJson(const char *layer_name, bool changed, + AreaList area_list, json_object **json_out); + const char *getStringFromJson(json_object *obj, const char *key); + int inputJsonFilie(const char *file, json_object **obj); + + std::vector parseString(std::string str, char delimiter); + std::string deleteSpace(std::string str); + + static const char *kDefaultRoleDb; + static const char *kDefaultLayoutDb; +}; + +#endif // TMCAGLWM_POLICY_MANAGER_HPP