diff options
author | 2018-04-27 19:01:36 +0900 | |
---|---|---|
committer | 2018-04-27 19:01:36 +0900 | |
commit | 55be85ed4bdfea6fc037d781b8cd8f58487718d1 (patch) | |
tree | 279a88e26c74aee58f11e2a5d20348569ce34667 /src/policy_manager | |
parent | d50188f726b15a0ae2777bf2d91ee88836feeac5 (diff) |
Add PolicyManager, related classes and some config files
- PolicyManager
Decide next layout by using occured event and current state
based on policy table.
This PolicyManger is reference and the OEMs can replace it.
- LayoutManager
Change the current layout to the layout
which decided by PolicyManager.
NOTE:
The functions of this class had been included in App class.
The part of function of this class remain there yet.
- LowCanClient
Receive the CAN signal from low level CAN service.
- app.db
Define the applications name and its role.
This file will be deleted
when the names and roles can be given by other module.
- layout.cb
Define the layouts and areas which are included by the layout.
- role.db
Define the roles of the applications.
Change-Id: I2f84bdf5e68355e022f516cee9a1db88efe58825
Signed-off-by: Yuta Doi <yuta-d@witz-inc.co.jp>
Diffstat (limited to 'src/policy_manager')
-rw-r--r-- | src/policy_manager/CMakeLists.txt | 65 | ||||
-rw-r--r-- | src/policy_manager/db/role.db | 44 | ||||
-rw-r--r-- | src/policy_manager/policy_manager.cpp | 497 | ||||
-rw-r--r-- | src/policy_manager/policy_manager.hpp | 67 | ||||
-rw-r--r-- | src/policy_manager/zipc/category.db | 32 | ||||
-rw-r--r-- | src/policy_manager/zipc/dummy_stm.c | 212 | ||||
-rw-r--r-- | src/policy_manager/zipc/dummy_stm.h | 127 |
7 files changed, 1044 insertions, 0 deletions
diff --git a/src/policy_manager/CMakeLists.txt b/src/policy_manager/CMakeLists.txt new file mode 100644 index 0000000..ca31e5f --- /dev/null +++ b/src/policy_manager/CMakeLists.txt @@ -0,0 +1,65 @@ +# +# Copyright (c) 2017 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. +# + +include(FindPkgConfig) + +# We do not want a prefix for our module +set(CMAKE_SHARED_MODULE_PREFIX "") + +set(TARGETS_PM lib${PLUGIN_PM}) + +# Set use STM name +set(USE_STM_NAME zipc) + +add_library(${TARGETS_PM} MODULE + policy_manager.cpp + policy_manager.hpp + ${USE_STM_NAME}/dummy_stm.c +) + +target_include_directories(${TARGETS_PM} + PRIVATE + ../../include + ../ + ./ + ./${USE_STM_NAME} +) + +target_compile_definitions(${TARGETS_PM} + PRIVATE + _GNU_SOURCE +) + +target_compile_options(${TARGETS_PM} + PRIVATE + -Wall -Wextra -Wno-unused-parameter -Wno-comment) + +set_target_properties(${TARGETS_PM} + PROPERTIES + CXX_EXTENSIONS OFF + CXX_STANDARD 14 + CXX_STANDARD_REQUIRED ON + + C_EXTENSIONS OFF + C_STANDARD 99 + C_STANDARD_REQUIRED ON +) + +install( + TARGETS ${TARGET_PM} + DESTINATION ${CMAKE_INSTALL_LIBDIR} + COMPONENT "runtime" +) diff --git a/src/policy_manager/db/role.db b/src/policy_manager/db/role.db new file mode 100644 index 0000000..2807fde --- /dev/null +++ b/src/policy_manager/db/role.db @@ -0,0 +1,44 @@ +{ + "roles":[ + { + "category": "homescreen", + "role": "homescreen", + "area": "full", + }, + { + "category": "map", + "role": "map", + "area": "full | normal | split.main", + }, + { + "category": "general", + "role": "poi | music | video | browser | sdl | settings | mixer | radio | hvac | dashboard | debug", + "area": "normal", + }, + { + "category": "phone", + "role": "phone", + "area": "normal", + }, + { + "category": "splitable", + "role": "splitable1 | splitable2", + "area": "normal | split.main | split.sub", + }, + { + "category": "popup", + "role": "popup", + "area": "on_screen", + }, + { + "category": "system_alert", + "role": "system_alert", + "area": "on_screen", + }, + { + "category": "tbt", + "role": "tbt", + "area": "hud", + } + ] +}
\ No newline at end of file diff --git a/src/policy_manager/policy_manager.cpp b/src/policy_manager/policy_manager.cpp new file mode 100644 index 0000000..61d1d7c --- /dev/null +++ b/src/policy_manager/policy_manager.cpp @@ -0,0 +1,497 @@ +/* + * 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. + */ + + +#include <fstream> +#include <sstream> +#include <istream> +#include <json-c/json.h> +#include "policy_manager.hpp" +#include "dummy_stm.h" +#include "hmi-debug.h" + + +namespace { + +static const char* kEventName[] = { + "activate", + "deactivate", + "car_stop", + "car_run", + "timer_expired", + "lamp_off", + "lamp_on" +}; + +static const int kEventNo[] = { + STM_EVT_NO_ACTIVATE, + STM_EVT_NO_DEACTIVATE, + STM_EVT_NO_CAR_STOP, + STM_EVT_NO_CAR_RUN, + STM_EVT_NO_TIMER_EXPIRED, + STM_EVT_NO_LAMP_OFF, + STM_EVT_NO_LAMP_ON +}; + +static const char* kCategoryName[] = { + "homescreen", + "map", + "general", + "splitable", + "popup", + "system_alert" +}; + +static const int kCategoryNo[] = { + STM_CTG_NO_HOMESCREEN, + STM_CTG_NO_MAP, + STM_CTG_NO_GENERAL, + STM_CTG_NO_SPLITABLE, + STM_CTG_NO_POPUP, + STM_CTG_NO_SYSTEM_ALERT +}; + +static const char* kAreaName[] = { + "full", + "normal", + "split.main", + "split.sub", + "onscreen" +}; + +static const int kAreaNo[] = { + STM_ARA_NO_FULL, + STM_ARA_NO_NORMAL, + STM_ARA_NO_SPLIT_MAIN, + STM_ARA_NO_SPLIT_SUB, + STM_ARA_NO_ON_SCREEN +}; + +// String for state +const char* gStmCarStateNo2Name[] = { + "car_stop", + "car_run" +}; + +const char* gStmLampStateNo2Name[] = { + "lamp_off", + "lamp_on" +}; + +const char* gStmLayoutNo2Name[] = { + "none", + "pu", + "sa", + "m1", + "m2", + "mf", + "s1", + "s2", + "g", + "hs", +}; + +} // namespace + +PolicyManager::PolicyManager() : + eventname2no_(), + categoryname2no_(), + areaname2no_(), + role2category_(), + category2role_(), + role2defaultarea_(), + current_state_() +{ + HMI_DEBUG("wm:pm", "Call"); +} + +int PolicyManager::initialize() { + HMI_DEBUG("wm:pm", "Call"); + + int ret = 0; + + // Create convert map + for (unsigned int i=0; i<(sizeof(kEventNo)/sizeof(int)); i++) { + HMI_DEBUG("wm:pm", "event name:%s no:%d", kEventName[i], kEventNo[i]); + this->eventname2no_[kEventName[i]] = kEventNo[i]; + } + + for (unsigned int i=0; i<(sizeof(kCategoryNo)/sizeof(int)); i++) { + HMI_DEBUG("wm:pm", "category name:%s no:%d", kCategoryName[i], kCategoryNo[i]); + this->categoryname2no_[kCategoryName[i]] = kCategoryNo[i]; + } + + for (unsigned int i=0; i<(sizeof(kAreaNo)/sizeof(int)); i++) { + HMI_DEBUG("wm:pm", "area name:%s no:%d", kAreaName[i], kAreaNo[i]); + this->areaname2no_[kAreaName[i]] = kAreaNo[i]; + } + + // Load role.db + ret = loadRoleDb(); + if (0 > ret) { + HMI_ERROR("wm:pm", "Load role.db Error!!"); + return ret; + } + + // TODO: + // Initialize StateTransitioner + // stmInitialize(); + + return ret; +} + +int PolicyManager::checkPolicy(json_object* json_in, json_object** json_out) { + HMI_DEBUG("wm:pm", "Call"); + + // Check arguments + if ((nullptr == json_in) || (nullptr == json_out)) { + HMI_ERROR("wm:pm", "Argument is NULL!!"); + return -1; + } + + // Get event from json_object + const char* event = getStringFromJson(json_in, "event"); + int event_no = 0; + if (nullptr != event) { + // Convert name to number + event_no = this->eventname2no_[event]; + HMI_DEBUG("wm:pm", "event(%s:%d)", event, event_no); + } + + // Get role from json_object + const char* role = getStringFromJson(json_in, "role"); + int category_no = 0; + if (nullptr != role) { + HMI_DEBUG("wm:pm", "role(%s)", role); + + // Convert role to category + const char* category = this->role2category_[role].c_str(); + if (0 == strcmp("", category)) { + HMI_ERROR("wm:pm", "Error!!"); + return -1; + } + HMI_DEBUG("wm:pm", "category(%s)", category); + + // Convert name to number + category_no = categoryname2no_[category]; + HMI_DEBUG("wm:pm", "role(%s), category(%s:%d)", role, category, category_no); + } + + // Get areat from json_object + const char* area = getStringFromJson(json_in, "area"); + int area_no = 0; + if (nullptr != area) { + // Convert name to number + area_no = areaname2no_[area]; + HMI_DEBUG("wm:pm", "area(%s:%d)", area, area_no); + } + + // Transition state + HMI_DEBUG("wm:pm", "set event:0x%x", (event_no | category_no | area_no)); + int ret = stmTransitionState((event_no | category_no | area_no), + &(this->current_state_)); + if (0 > ret) { + HMI_ERROR("wm:pm", "Error!!"); + return -1; + } + + // Create result + // { + // "car": { + // "is_changed": <bool>, + // "state": <const char*> + // }, + HMI_DEBUG("wm", "@@@@@ car state (is_changed:%d state:%d:%s)", + this->current_state_.car.is_changed, + this->current_state_.car.state, + gStmCarStateNo2Name[this->current_state_.car.state]); + this->addStateToJson("car", + this->current_state_.car.is_changed, + gStmCarStateNo2Name[this->current_state_.car.state], + json_out); + + // "lamp": { + // "is_changed": <bool>, + // "state": <const char*> + // }, + HMI_DEBUG("wm", "@@@@@ lamp state (is_changed:%d state:%d:%s)", + this->current_state_.lamp.is_changed, + this->current_state_.lamp.state, + gStmLampStateNo2Name[this->current_state_.lamp.state]); + this->addStateToJson("lamp", + this->current_state_.lamp.is_changed, + gStmLampStateNo2Name[this->current_state_.lamp.state], + json_out); + + // "layers": [ + // { + // "on_screen": { + // "is_changed": <bool>, + // "state": <const char*> + // } + // }, + json_object* json_layer = json_object_new_array(); + json_object* json_tmp = json_object_new_object(); + this->addStateToJson("on_screen", + this->current_state_.layer.on_screen.is_changed, + gStmLayoutNo2Name[this->current_state_.layer.on_screen.state], + &json_tmp); + json_object_array_add(json_layer, json_tmp); + + // { + // "apps": { + // "is_changed": <bool>, + // "state": <const char*> + // } + // }, + json_tmp = json_object_new_object(); + this->addStateToJson("apps", + this->current_state_.layer.apps.is_changed, + gStmLayoutNo2Name[this->current_state_.layer.apps.state], + &json_tmp); + json_object_array_add(json_layer, json_tmp); + + // { + // "homescreen": { + // "is_changed": <bool>, + // "state": <const char*> + // } + // }, + // ] + // } + json_tmp = json_object_new_object(); + this->addStateToJson("homescreen", + this->current_state_.layer.homescreen.is_changed, + gStmLayoutNo2Name[this->current_state_.layer.homescreen.state], + &json_tmp); + json_object_array_add(json_layer, json_tmp); + + // Add json array of layer + json_object_object_add(*json_out, "layers", json_layer); + + HMI_DEBUG("wm:pm", "json_out.dump:%s", json_object_get_string(*json_out)); + + return 0; +} + +std::string PolicyManager::roleToCategory(const char* role) { + return this->role2category_[role]; +} + +extern const char* kDefaultRoleDb; +int PolicyManager::loadRoleDb() { + HMI_DEBUG("wm:pm", "Call"); + + std::string file_name; + + // Get afm application installed dir + char const *afm_app_install_dir = getenv("AFM_APP_INSTALL_DIR"); + HMI_DEBUG("wm:pm", "afm_app_install_dir:%s", afm_app_install_dir); + + if (!afm_app_install_dir) { + HMI_ERROR("wm:pm", "AFM_APP_INSTALL_DIR is not defined"); + } + else { + file_name = std::string(afm_app_install_dir) + std::string("/etc/role.db"); + } + + // Load role.db + HMI_DEBUG("wm:pm", "file_name:%s", file_name.c_str()); + json_object* json_obj = json_object_from_file(file_name.c_str()); + if (nullptr == json_obj) { + HMI_ERROR("wm:pm", "Could not open role.db, so use default role information"); + json_obj = json_tokener_parse(kDefaultRoleDb); + } + HMI_DEBUG("wm:pm", "json_obj dump:%s", json_object_get_string(json_obj)); + + json_object* json_roles; + if (!json_object_object_get_ex(json_obj, "roles", &json_roles)) { + HMI_ERROR("wm:pm", "Parse Error!!"); + return -1; + } + + int len = json_object_array_length(json_roles); + HMI_DEBUG("wm:pm", "json_cfg len:%d", len); + HMI_DEBUG("wm:pm", "json_cfg dump:%s", json_object_get_string(json_roles)); + + json_object* json_tmp; + const char* category; + const char* roles; + const char* areas; + for (int i=0; i<len; i++) { + json_tmp = json_object_array_get_idx(json_roles, i); + + category = this->getStringFromJson(json_tmp, "category"); + roles = this->getStringFromJson(json_tmp, "role"); + areas = this->getStringFromJson(json_tmp, "area"); + + if ((nullptr == category) || (nullptr == roles) || (nullptr == areas)) { + HMI_ERROR("wm:pm", "Parse Error!!"); + return -1; + } + + // Parse roles by '|' + std::vector<std::string> vct_roles; + vct_roles = this->parseString(std::string(roles), '|'); + + // Parse areas by '|' + std::vector<std::string> vct_areas; + vct_areas = this->parseString(std::string(areas), '|'); + + // Set role, category, default area + for (auto itr = vct_roles.begin(); itr != vct_roles.end(); ++itr) { + // Delete space from role and area name + std::string role = this->deleteSpace(*itr); + std::string area = this->deleteSpace(vct_areas[0]); + + this->role2category_[role] = std::string(category); + this->role2defaultarea_[role] = area; + } + + this->category2role_[std::string(category)] = std::string(roles); + } + + // Check + HMI_DEBUG("wm:pm", "Check role2category_"); + for (auto& x:this->role2category_){ + HMI_DEBUG("wm:pm", "key:%s, val:%s", x.first.c_str(), x.second.c_str()); + } + + HMI_DEBUG("wm:pm", "Check role2defaultarea_"); + for (auto& x:this->role2defaultarea_){ + HMI_DEBUG("wm:pm", "key:%s, val:%s", x.first.c_str(), x.second.c_str()); + } + + HMI_DEBUG("wm:pm", "Check category2role_"); + for (auto& x:this->category2role_){ + HMI_DEBUG("wm:pm", "key:%s, val:%s", x.first.c_str(), x.second.c_str()); + } + + return 0; +} + +const char* PolicyManager::getStringFromJson(json_object* obj, const char* key) { + if ((nullptr == obj) || (nullptr == key)) { + HMI_ERROR("wm:pm", "Argument is nullptr!!!"); + return nullptr; + } + + json_object* tmp; + if (!json_object_object_get_ex(obj, key, &tmp)) { + HMI_DEBUG("wm:pm", "Not found key \"%s\"", key); + return nullptr; + } + + return json_object_get_string(tmp); +} + +int PolicyManager::getIntFromJson(json_object* obj, const char* key) { + if ((nullptr == obj) || (nullptr == key)) { + HMI_ERROR("wm:pm", "Argument is nullptr!!!"); + return 0; + } + + json_object* tmp; + if (!json_object_object_get_ex(obj, key, &tmp)) { + HMI_DEBUG("wm:pm", "Not found key \"%s\"", key); + return 0; + } + + return json_object_get_int(tmp); +} + +void PolicyManager::addStateToJson( + const char* key, int is_changed, const char* state, json_object** json_out) { + if ((nullptr == key) || (nullptr == state) || (nullptr == json_out)) { + HMI_ERROR("wm:pm", "Argument is nullptr!!!"); + return; + } + + json_object* json_obj = json_object_new_object(); + json_object_object_add(json_obj, "is_changed", json_object_new_boolean(is_changed)); + if (is_changed) { + HMI_DEBUG("wm:pm", "%s: state changed (%s)", key, state); + json_object_object_add(json_obj, "state", json_object_new_string(state)); + } + json_object_object_add(*json_out, key, json_obj); +} + +std::vector<std::string> PolicyManager::parseString(std::string str, char delimiter) { + // Parse string by delimiter + std::vector<std::string> vct; + std::stringstream ss{str}; + std::string buf; + while (std::getline(ss, buf, delimiter)) { + if (!buf.empty()) { + vct.push_back(buf); + } + } + return vct; +} + +std::string PolicyManager::deleteSpace(std::string str) { + std::string ret = str; + size_t pos; + while ((pos = ret.find_first_of(" ")) != std::string::npos) { + ret.erase(pos, 1); + } + return ret; +} + +const char* kDefaultRoleDb = "{ \ + \"roles\":[ \ + { \ + \"category\": \"homescreen\", \ + \"role\": \"homescreen\", \ + \"area\": \"full\", \ + }, \ + { \ + \"category\": \"map\", \ + \"role\": \"map\", \ + \"area\": \"full | normal | split.main\", \ + }, \ + { \ + \"category\": \"general\", \ + \"role\": \"poi | music | video | browser | sdl | settings | mixer | radio | hvac | dashboard | debug\", \ + \"area\": \"normal\", \ + }, \ + { \ + \"category\": \"phone\", \ + \"role\": \"phone\", \ + \"area\": \"normal\", \ + }, \ + { \ + \"category\": \"splitable\", \ + \"role\": \"splitable1 | splitable2\", \ + \"area\": \"normal | split.main | split.sub\", \ + }, \ + { \ + \"category\": \"popup\", \ + \"role\": \"popup\", \ + \"area\": \"on_screen\", \ + }, \ + { \ + \"category\": \"system_alert\", \ + \"role\": \"system_alert\", \ + \"area\": \"on_screen\", \ + }, \ + { \ + \"category\": \"tbt\", \ + \"role\": \"tbt\", \ + \"area\": \"hud\", \ + } \ + ] \ +}"; diff --git a/src/policy_manager/policy_manager.hpp b/src/policy_manager/policy_manager.hpp new file mode 100644 index 0000000..500120c --- /dev/null +++ b/src/policy_manager/policy_manager.hpp @@ -0,0 +1,67 @@ +/* + * 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 <unordered_map> +#include <vector> + +//namespace stm { +extern "C" { +#include "dummy_stm.h" +} +//} // namespace stm + +class PolicyManager { + +public: + explicit PolicyManager(); + ~PolicyManager() = default; + + int initialize(); + int checkPolicy(json_object* json_in, json_object** json_out); + std::string roleToCategory(const char* role); +private: + // Disable copy and move + PolicyManager(PolicyManager const &) = delete; + PolicyManager &operator=(PolicyManager const &) = delete; + PolicyManager(PolicyManager &&) = delete; + PolicyManager &operator=(PolicyManager &&) = delete; + + // Convert map + std::unordered_map<std::string, int> eventname2no_; + std::unordered_map<std::string, int> categoryname2no_; + std::unordered_map<std::string, int> areaname2no_; + + std::unordered_map<std::string, std::string> role2category_; + std::unordered_map<std::string, std::string> category2role_; + std::unordered_map<std::string, std::string> role2defaultarea_; + + stm_state_t current_state_; + + // Load role.db + int loadRoleDb(); + + const char* getStringFromJson(json_object* obj, const char* key); + int getIntFromJson(json_object* obj, const char* key); + void addStateToJson(const char* key, int is_changed, const char* state, json_object** json_out); + std::vector<std::string> parseString(std::string str, char delimiter); + std::string deleteSpace(std::string str); +}; + +#endif // TMCAGLWM_POLICY_MANAGER_HPP diff --git a/src/policy_manager/zipc/category.db b/src/policy_manager/zipc/category.db new file mode 100644 index 0000000..4867260 --- /dev/null +++ b/src/policy_manager/zipc/category.db @@ -0,0 +1,32 @@ +{ + "categories":[ + { + "name": "homescreen", + "role": "homescreen" + }, + { + "name": "map", + "role": "map" + }, + { + "name": "general", + "role": "poi | music | radio | video | browser | sdl | phone | settings | mixer | hvac | dashboard | fallback" + }, + { + "name": "pop_up", + "role": "incoming_call" + }, + { + "name": "system_alert", + "role": "system_alert" + }, + { + "name": "tbt", + "role": "tbt" + }, + { + "name": "splitable", + "role": "test_splitable1 | test_splitable2" + } + ] +} diff --git a/src/policy_manager/zipc/dummy_stm.c b/src/policy_manager/zipc/dummy_stm.c new file mode 100644 index 0000000..3c9cba2 --- /dev/null +++ b/src/policy_manager/zipc/dummy_stm.c @@ -0,0 +1,212 @@ + +#include <string.h> +#include "dummy_stm.h" + +stm_state_t g_crr_state = {0}; +stm_state_t g_prv_state = {0}; +int g_prv_apps_state_car_stop = 0; + +int stmTransitionState(int event, stm_state_t* state) { + int event_no, category_no, area_no; + int apps_state, car_state, lamp_state; + + event_no = event & STM_MSK_EVT_NO; + category_no = event & STM_MSK_CTG_NO; + area_no = event & STM_MSK_ARA_NO; + + // Backup previous state + g_prv_state = g_crr_state; + + // Get previous state + apps_state = g_prv_state.layer.apps.state; + car_state = g_prv_state.car.state; + lamp_state = g_prv_state.lamp.state; + + // Clear current state + memset(&g_crr_state, 0, sizeof(g_crr_state)); + + switch (event_no) { + case STM_EVT_NO_ACTIVATE: + switch (category_no) { + case STM_CTG_NO_HOMESCREEN: + // Apps layer + g_crr_state.layer.apps.state = gStmLayoutNoNone; + g_crr_state.layer.apps.is_changed = STM_TRUE; + + // Homescreen layer + g_crr_state.layer.homescreen.state = gStmLayoutNoHs; + g_crr_state.layer.homescreen.is_changed = STM_TRUE; + break; + case STM_CTG_NO_MAP: + switch (area_no) { + case STM_ARA_NO_FULL: + // Apps layer + switch (apps_state) { + case gStmLayoutNoMf: + // nop + break; + default: + g_crr_state.layer.apps.state = gStmLayoutNoMf; + g_crr_state.layer.apps.is_changed = STM_TRUE; + break; + } + break; + case STM_ARA_NO_NORMAL: + // Apps layer + switch (apps_state) { + case gStmLayoutNoM1: + // nop + break; + case gStmLayoutNoS1: + g_crr_state.layer.apps.state = gStmLayoutNoM2; + g_crr_state.layer.apps.is_changed = STM_TRUE; + break; + default: + g_crr_state.layer.apps.state = gStmLayoutNoM1; + g_crr_state.layer.apps.is_changed = STM_TRUE; + } + break; + case STM_ARA_NO_SPLIT_MAIN: + // Apps layer + switch (apps_state) { + case gStmLayoutNoS1: + case gStmLayoutNoS2: + g_crr_state.layer.apps.state = gStmLayoutNoS2; + g_crr_state.layer.apps.is_changed = STM_TRUE; + break; + default: + // nop + break; + } + break; + } + break; + case STM_CTG_NO_GENERAL: + switch (area_no) { + case STM_ARA_NO_NORMAL: + // Apps layer + switch (apps_state) { + case gStmLayoutNoMf: + // nop + break; + default: + g_crr_state.layer.apps.state = gStmLayoutNoG; + g_crr_state.layer.apps.is_changed = STM_TRUE; + break; + } + break; + default: + // nop + break; + } + break; + case STM_CTG_NO_SPLITABLE: + switch (area_no) { + case STM_ARA_NO_NORMAL: + // Apps layer + switch (apps_state) { + case gStmLayoutNoMf: + // nop + break; + case gStmLayoutNoS1: + g_crr_state.layer.apps.state = gStmLayoutNoS2; + g_crr_state.layer.apps.is_changed = STM_TRUE; + break; + default: + g_crr_state.layer.apps.state = gStmLayoutNoS1; + g_crr_state.layer.apps.is_changed = STM_TRUE; + break; + } + break; + case STM_ARA_NO_SPLIT_MAIN: + // Apps layer + switch (apps_state) { + case gStmLayoutNoS1: + g_crr_state.layer.apps.state = gStmLayoutNoS2; + g_crr_state.layer.apps.is_changed = STM_TRUE; + break; + case gStmLayoutNoS2: + g_crr_state.layer.apps.state = gStmLayoutNoS2; + g_crr_state.layer.apps.is_changed = STM_TRUE; + break; + default: + // nop + break; + } + break; + case STM_ARA_NO_SPLIT_SUB: + // Apps layer + switch (apps_state) { + case gStmLayoutNoM1: + g_crr_state.layer.apps.state = gStmLayoutNoM2; + g_crr_state.layer.apps.is_changed = STM_TRUE; + break; + case gStmLayoutNoM2: + g_crr_state.layer.apps.state = gStmLayoutNoM2; + g_crr_state.layer.apps.is_changed = STM_TRUE; + break; + case gStmLayoutNoS1: + g_crr_state.layer.apps.state = gStmLayoutNoS2; + g_crr_state.layer.apps.is_changed = STM_TRUE; + break; + case gStmLayoutNoS2: + g_crr_state.layer.apps.state = gStmLayoutNoS2; + g_crr_state.layer.apps.is_changed = STM_TRUE; + break; + default: + // nop + break; + } + break; + default: + // nop + break; + } + break; + default: + // nop + break; + } + break; + case STM_EVT_NO_CAR_STOP: + if (gStmCarStateNoStop != car_state) { + g_crr_state.layer.apps.state = g_prv_apps_state_car_stop; + g_crr_state.layer.apps.is_changed = STM_TRUE; + + g_crr_state.car.state = gStmCarStateNoStop; + g_crr_state.car.is_changed = STM_TRUE; + } + break; + case STM_EVT_NO_CAR_RUN: + if (gStmCarStateNoRun != car_state) { + g_prv_apps_state_car_stop = apps_state; + g_crr_state.layer.apps.state = gStmLayoutNoM1; + g_crr_state.layer.apps.is_changed = STM_TRUE; + + g_crr_state.car.state = gStmCarStateNoRun; + g_crr_state.car.is_changed = STM_TRUE; + } + break; + case STM_EVT_NO_LAMP_OFF: + if (gStmLampStateNoOff != lamp_state) { + g_crr_state.lamp.state = gStmLampStateNoOff; + g_crr_state.lamp.is_changed = STM_TRUE; + } + break; + case STM_EVT_NO_LAMP_ON: + if (gStmLampStateNoOn != lamp_state) { + g_crr_state.lamp.state = gStmLampStateNoOn; + g_crr_state.lamp.is_changed = STM_TRUE; + } + break; + default: + // nop + break; + } + + // Copy current state for return + memcpy(state, &g_crr_state, sizeof(g_crr_state)); + + return 0; +} + diff --git a/src/policy_manager/zipc/dummy_stm.h b/src/policy_manager/zipc/dummy_stm.h new file mode 100644 index 0000000..18af99b --- /dev/null +++ b/src/policy_manager/zipc/dummy_stm.h @@ -0,0 +1,127 @@ +/* + * 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_DUMMY_STM_HPP +#define TMCAGLWM_DUMMY_STM_HPP + +// TODO: This file should be existed in STM + +// +#define STM_TRUE 1 +#define STM_FALSE 0 + +// Event number +#define STM_EVT_NO_ACTIVATE 0x01 +#define STM_EVT_NO_DEACTIVATE 0x02 +#define STM_EVT_NO_CAR_STOP 0x03 +#define STM_EVT_NO_CAR_RUN 0x04 +#define STM_EVT_NO_TIMER_EXPIRED 0x05 +#define STM_EVT_NO_LAMP_OFF 0x06 +#define STM_EVT_NO_LAMP_ON 0x07 + +// Category number +#define STM_CTG_NO_HOMESCREEN 0x0100 +#define STM_CTG_NO_MAP 0x0200 +#define STM_CTG_NO_GENERAL 0x0300 +#define STM_CTG_NO_SPLITABLE 0x0400 +#define STM_CTG_NO_POPUP 0x0500 +#define STM_CTG_NO_SYSTEM_ALERT 0x0600 + +// Area number +#define STM_ARA_NO_FULL 0x010000 +#define STM_ARA_NO_NORMAL 0x020000 +#define STM_ARA_NO_SPLIT_MAIN 0x030000 +#define STM_ARA_NO_SPLIT_SUB 0x040000 +#define STM_ARA_NO_ON_SCREEN 0x050000 + +// Mask +#define STM_MSK_EVT_NO 0x0000FF +#define STM_MSK_CTG_NO 0x00FF00 +#define STM_MSK_ARA_NO 0xFF0000 + +// Enum for state +enum stm_car_state_ { + gStmCarStateNoStop = 0, + gStmCarStateNoRun +}; + +enum stm_lamp_state_ { + gStmLampStateNoOff = 0, + gStmLampStateNoOn +}; + +enum stm_layout_ { + gStmLayoutNoNone = 0, + gStmLayoutNoPu, + gStmLayoutNoSa, + gStmLayoutNoM1, + gStmLayoutNoM2, + gStmLayoutNoMf, + gStmLayoutNoS1, + gStmLayoutNoS2, + gStmLayoutNoG, + gStmLayoutNoHs +}; + + +#if 0 +// String for state +const char* gStmCarStateNo2Name[] { + "car_stop", + "car_run" +}; + +const char* gStmLampStateNo2Name[] { + "lamp_off", + "lamp_on" +}; + +const char* gStmLayoutNo2Name[] { + "none", + "pu", + "sa", + "m1", + "m2", + "mf", + "s1", + "s2", + "g", + "hs", +}; +#endif + +typedef struct stm_base_state_ { + int is_changed; + int state; +} stm_base_state; + +typedef struct stm_layer_state_ { + stm_base_state on_screen; + stm_base_state apps; + stm_base_state homescreen; +} stm_layer_state; + +// Struct for state +typedef struct { + stm_base_state car; + stm_base_state lamp; + stm_layer_state layer; +} stm_state_t; + +int stmTransitionState(int event_no, stm_state_t* state); + + +#endif // TMCAGLWM_DUMMY_STM_HPP |