@media only all and (prefers-color-scheme: dark) { .highlight .hll { background-color: #49483e } .highlight .c { color: #75715e } /* Comment */ .highlight .err { color: #960050; background-color: #1e0010 } /* Error */ .highlight .k { color: #66d9ef } /* Keyword */ .highlight .l { color: #ae81ff } /* Literal */ .highlight .n { color: #f8f8f2 } /* Name */ .highlight .o { color: #f92672 } /* Operator */ .highlight .p { color: #f8f8f2 } /* Punctuation */ .highlight .ch { color: #75715e } /* Comment.Hashbang */ .highlight .cm { color: #75715e } /* Comment.Multiline */ .highlight .cp { color: #75715e } /* Comment.Preproc */ .highlight .cpf { color: #75715e } /* Comment.PreprocFile */ .highlight .c1 { color: #75715e } /* Comment.Single */ .highlight .cs { color: #75715e } /* Comment.Special */ .highlight .gd { color: #f92672 } /* Generic.Deleted */ .highlight .ge { font-style: italic } /* Generic.Emph */ .highlight .gi { color: #a6e22e } /* Generic.Inserted */ .highlight .gs { font-weight: bold } /* Generic.Strong */ .highlight .gu { color: #75715e } /* Generic.Subheading */ .highlight .kc { color: #66d9ef } /* Keyword.Constant */ .highlight .kd { color: #66d9ef } /* Keyword.Declaration */ .highlight .kn { color: #f92672 } /* Keyword.Namespace */ .highlight .kp { color: #66d9ef } /* Keyword.Pseudo */ .highlight .kr { color: #66d9ef } /* Keyword.Reserved */ .highlight .kt { color: #66d9ef } /* Keyword.Type */ .highlight .ld { color: #e6db74 } /* Literal.Date */ .highlight .m { color: #ae81ff } /* Literal.Number */ .highlight .s { color: #e6db74 } /* Literal.String */ .highlight .na { color: #a6e22e } /* Name.Attribute */ .highlight .nb { color: #f8f8f2 } /* Name.Builtin */ .highlight .nc { color: #a6e22e } /* Name.Class */ .highlight .no { color: #66d9ef } /* Name.Constant */ .highlight .nd { color: #a6e22e } /* Name.Decorator */ .highlight .ni { color: #f8f8f2 } /* Name.Entity */ .highlight .ne { color: #a6e22e } /* Name.Exception */ .highlight .nf { color: #a6e22e } /* Name.Function */ .highlight .nl { color: #f8f8f2 } /* Name.Label */ .highlight .nn { color: #f8f8f2 } /* Name.Namespace */ .highlight .nx { color: #a6e22e } /* Name.Other */ .highlight .py { color: #f8f8f2 } /* Name.Property */ .highlight .nt { color: #f92672 } /* Name.Tag */ .highlight .nv { color: #f8f8f2 } /* Name.Variable */ .highlight .ow { color: #f92672 } /* Operator.Word */ .highlight .w { color: #f8f8f2 } /* Text.Whitespace */ .highlight .mb { color: #ae81ff } /* Literal.Number.Bin */ .highlight .mf { color: #ae81ff } /* Literal.Number.Float */ .highlight .mh { color: #ae81ff } /* Literal.Number.Hex */ .highlight .mi { color: #ae81ff } /* Literal.Number.Integer */ .highlight .mo { color: #ae81ff } /* Literal.Number.Oct */ .highlight .sa { color: #e6db74 } /* Literal.String.Affix */ .highlight .sb { color: #e6db74 } /* Literal.String.Backtick */ .highlight .sc { color: #e6db74 } /* Literal.String.Char */ .highlight .dl { color: #e6db74 } /* Literal.String.Delimiter */ .highlight .sd { color: #e6db74 } /* Literal.String.Doc */ .highlight .s2 { color: #e6db74 } /* Literal.String.Double */ .highlight .se { color: #ae81ff } /* Literal.String.Escape */ .highlight .sh { color: #e6db74 } /* Literal.String.Heredoc */ .highlight .si { color: #e6db74 } /* Literal.String.Interpol */ .highlight .sx { color: #e6db74 } /* Literal.String.Other */ .highlight .sr { color: #e6db74 } /* Literal.String.Regex */ .highlight .s1 { color: #e6db74 } /* Literal.String.Single */ .highlight .ss { color: #e6db74 } /* Literal.String.Symbol */ .highlight .bp { color: #f8f8f2 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #a6e22e } /* Name.Function.Magic */ .highlight .vc { color: #f8f8f2 } /* Name.Variable.Class */ .highlight .vg { color: #f8f8f2 } /* Name.Variable.Global */ .highlight .vi { color: #f8f8f2 } /* Name.Variable.Instance */ .highlight .vm { color: #f8f8f2 } /* Name.Variable.Magic */ .highlight .il { color: #ae81ff } /* Literal.Number.Integer.Long */ } @media (prefers-color-scheme: light) { .highlight .hll { background-color: #ffffcc } .highlight .c { color: #888888 } /* Comment */ .highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */ .highlight .k { color: #008800; font-weight: bold } /* Keyword */ .highlight .ch { color: #888888 } /* Comment.Hashbang */ .highlight .cm { color: #888888 } /* Comment.Multiline */ .highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */ .highlight .cpf { color: #888888 } /* Comment.PreprocFile */ .highlight .c1 { color: #888888 } /* Comment.Single */ .highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */ .highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */ .highlight .ge { font-style: italic } /* Generic.Emph */ .highlight .gr { color: #aa0000 } /* Generic.Error */ .highlight .gh { color: #333333 } /* Generic.Heading */ .highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */ .highlight .go { color: #888888 } /* Generic.Output */ .highlight .gp { color: #555555 } /* Generic.Prompt */ .highlight .gs { font-weight: bold } /* Generic.Strong */ .highlight .gu { color: #666666 } /* Generic.Subheading */ .highlight .gt { color: #aa0000 } /* Generic.Traceback */ .highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */ }
[gerrit]
host=gerrit.automotivelinux.org
port=29418
project=src/inputeventmanager
defaultbranch=icefish
'ctx'> // Update car states
this->updateCarStates(json_out);
diff --git a/src/policy_manager/policy_manager.cpp b/src/policy_manager/policy_manager.cpp
index 6ae80c6..19a6a0b 100644
--- a/src/policy_manager/policy_manager.cpp
+++ b/src/policy_manager/policy_manager.cpp
@@ -51,8 +51,14 @@ typedef struct LayoutState {
typedef struct LayerState {
std::string name;
LayoutState layout_state;
+ int changed;
} LayerState;
+typedef struct CarElement {
+ std::string state;
+ int changed;
+} CarElement;
+
typedef struct EventInfo {
int event;
std::string role;
@@ -65,9 +71,14 @@ std::map<int, std::string> g_req_role_list;
PolicyManager::CallbackTable callback;
std::queue<EventInfo> g_event_info_queue;
+std::unordered_map<std::string, CarElement> g_prv_car_elements;
+std::unordered_map<std::string, CarElement> g_crr_car_elements;
+
std::unordered_map<std::string, LayerState> g_prv_layers;
std::unordered_map<std::string, LayerState> g_crr_layers;
+
std::unordered_map<std::string, LayerState> g_prv_layers_car_stop;
+
std::unordered_map<std::string, LayoutState> g_default_layouts;
} // namespace pm
@@ -118,33 +129,57 @@ int PolicyManager::initialize() {
return ret;
}
- // Initialize current/previous state of layers
+ // Initialize state which is managed by PolicyManager
+ this->initializeLocalState();
+
+ // Initialize StateTransitioner
+ stm::stmInitialize();
+
+ // Initialize sd_event loop
+ ret = this->initializeSdEventLoop();
+ if (0 > ret) {
+ HMI_ERROR("wm:pm", "Failed to initializeSdEventLoop!!");
+ return ret;
+ }
+
+ return ret;
+}
+
+static void initializeLocalCarElementState() {
+ pm::CarElement init_car_ele;
+ init_car_ele.state = "none";
+ init_car_ele.changed = 0;
+
+ for (int i = stm::gStmCarElementNoMin; i <= stm::gStmCarElementNoMax; i++) {
+ const char* car_ele_name = stm::gStmCarElementName[i];
+ pm::g_crr_car_elements[car_ele_name] = init_car_ele;
+ }
+
+ pm::g_prv_car_elements = pm::g_crr_car_elements;
+}
+
+static void initializeLocalLayerState() {
pm::AreaState init_area;
pm::LayoutState init_layout;
init_area.name = "none";
init_area.category = "none";
init_area.role = "none";
+ init_layout.name = "none";
init_layout.area_list.push_back(init_area);
for (int i = stm::gStmLayerNoMin; i <= stm::gStmLayerNoMax; i++) {
const char* layer_name = stm::gStmLayerName[i];
- pm::g_crr_layers[layer_name].name = layer_name;
- pm::g_crr_layers[layer_name].layout_state = init_layout;
+ pm::g_crr_layers[layer_name].name = layer_name;
+ pm::g_crr_layers[layer_name].layout_state = init_layout;
+ pm::g_crr_layers[layer_name].changed = 0;
}
pm::g_prv_layers = pm::g_crr_layers;
+}
- // Initialize StateTransitioner
- stm::stmInitialize();
-
- // Initialize sd_event loop
- ret = this->initializeSdEventLoop();
- if (0 > ret) {
- HMI_ERROR("wm:pm", "Failed to initializeSdEventLoop!!");
- return ret;
- }
-
- return ret;
+void PolicyManager::initializeLocalState() {
+ initializeLocalCarElementState();
+ initializeLocalLayerState();
}
int PolicyManager::initializeSdEventLoop() {
@@ -167,8 +202,8 @@ int PolicyManager::initializeSdEventLoop() {
}
static void addStateToJson(
- const char* key, int is_changed, const char* state, json_object** json_out) {
- if ((nullptr == key) || (nullptr == state) || (nullptr == json_out)) {
+ const char* key, int is_changed, std::string state, json_object** json_out) {
+ if ((nullptr == key) || (nullptr == json_out)) {
HMI_ERROR("wm:pm", "Argument is nullptr!!!");
return;
}
@@ -176,8 +211,8 @@ static void addStateToJson(
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));
+ HMI_DEBUG("wm:pm", "%s: state changed (%s)", key, state.c_str());
+ json_object_object_add(json_obj, "state", json_object_new_string(state.c_str()));
}
json_object_object_add(*json_out, key, json_obj);
}
@@ -203,7 +238,34 @@ static void addStateToJson(const char* layer_name, unsigned int changed,
json_object_object_add(*json_out, "areas", json_areas);
}
-static void updateLocalState(int event_data, stm::stm_state_t crr_state) {
+static void updateLocalCarElementState(stm::stm_state_t crr_state) {
+ int car_state_no;
+ std::string car_state;
+ bool changed;
+
+ // Store previous layers
+ pm::g_prv_car_elements = pm::g_crr_car_elements;
+
+ // Update car elements
+ HMI_DEBUG("wm:pm", ">>> CAR ELEMENT");
+ for (int car_ele_no = stm::gStmCarElementNoMin;
+ car_ele_no <= stm::gStmCarElementNoMax; car_ele_no++) {
+ const char* car_ele_name = stm::gStmCarElementName[car_ele_no];
+
+ car_state_no = crr_state.car_element[car_ele_no].state;
+ car_state = stm::gStmCarStateNameList[car_ele_no][car_state_no];
+ changed = crr_state.car_element[car_ele_no].is_changed;
+
+ pm::g_crr_car_elements[car_ele_name].state = car_state;
+ pm::g_crr_car_elements[car_ele_name].changed = changed;
+
+ HMI_DEBUG("wm:pm", ">>> >>> NAME: %s", car_ele_name);
+ HMI_DEBUG("wm:pm", ">>> >>> >>> STATE:%s", car_state.c_str());
+ HMI_DEBUG("wm:pm", ">>> >>> >>> CHANGED:%d", changed);
+ }
+}
+
+static void updateLocalLayerState(int event_data, stm::stm_state_t crr_state) {
int event_no, category_no, area_no;
event_no = (event_data & STM_MSK_EVT_NO) - 1;
@@ -229,8 +291,8 @@ static void updateLocalState(int event_data, stm::stm_state_t crr_state) {
#if 1
// If restriction mode is changed off -> on,
// store current state for state of restriction mode off
- if ((crr_state.restriction_mode.is_changed)
- && (stm::gStmRestrictionModeStateNoOn == crr_state.restriction_mode.state)) {
+ if ((crr_state.car_element[stm::gStmCarElementNoRestrictionMode].is_changed)
+ && (stm::gStmRestrictionModeStateNoOn == crr_state.car_element[stm::gStmCarElementNoRestrictionMode].state)) {
HMI_DEBUG("wm:lm", "Store current state for state of restriction mode off");
pm::g_prv_layers_car_stop[layer_name] = pm::g_crr_layers[layer_name];
}
@@ -238,7 +300,7 @@ static void updateLocalState(int event_data, stm::stm_state_t crr_state) {
// If car state is changed car_stop -> car_run,
// store current state for state of car stop
if ((crr_state.car.is_changed)
- && (stm::gStmCarStateNoRun == crr_state.car.state)) {
+ && (stm::gStmRunningNoRun == crr_state.car.state)) {
HMI_DEBUG("wm:lm", "Store current state for state of car stop");
pm::g_prv_layers_car_stop[layer_name] = pm::g_crr_layers[layer_name];
}
@@ -257,15 +319,15 @@ static void updateLocalState(int event_data, stm::stm_state_t crr_state) {
pm::LayoutState crr_layout_state;
#if 1
- if ((crr_state.restriction_mode.is_changed)
- && (stm::gStmRestrictionModeStateNoOff == crr_state.restriction_mode.state)) {
+ if ((crr_state.car_element[stm::gStmCarElementNoRestrictionMode].is_changed)
+ && (stm::gStmRestrictionModeStateNoOff == crr_state.car_element[stm::gStmCarElementNoRestrictionMode].state)) {
// If restriction mode is changed on -> off,
// restore state of restriction mode off
HMI_DEBUG("wm:lm", "Restriction mode is changed on -> off, so restore state of restriction mode off");
crr_layout_state = pm::g_prv_layers_car_stop[layer_name].layout_state;
#else
- if ((crr_state.car.is_changed)
- && (stm::gStmCarStateNoStop == crr_state.car.state)) {
+ if ((crr_state.car_element[gStmCarElementNoRunning].is_changed)
+ && (stm::gStmCarElementNoStop == crr_state.car_element[gStmCarElementNoRunning].state)) {
// If car state is changed car_run -> car_stop,
// restore state of car stop
HMI_DEBUG("wm:lm", "Car state is changed car_run -> car_stop, so restore state of car stop");
@@ -404,6 +466,7 @@ static void updateLocalState(int event_data, stm::stm_state_t crr_state) {
}
// Update current layout of this layer
pm::g_crr_layers[layer_name].layout_state = crr_layout_state;
+ pm::g_crr_layers[layer_name].changed = crr_state.layer[layer_no].is_changed;
}
}
@@ -421,65 +484,41 @@ static void updateLocalState(int event_data, stm::stm_state_t crr_state) {
HMI_DEBUG("wm:pm", ">>> >>> >>> >>> CTG:%s", as.category.c_str());
HMI_DEBUG("wm:pm", ">>> >>> >>> >>> ROLE:%s", as.role.c_str());
}
+ HMI_DEBUG("wm:pm", ">>> >>> CHANGED:%d", ls.changed);
}
}
+static void updateLocalState(int event_data, stm::stm_state_t crr_state) {
+ updateLocalCarElementState(crr_state);
+ updateLocalLayerState(event_data, crr_state);
+}
+
static void createOutputInformation(stm::stm_state_t crr_state, json_object **json_out) {
- // Create result
+ json_object* json_tmp;
+
+ // Create car element information
// {
- // "parking_brake": {
- // "is_changed": <bool>,
- // "state": <const char*>
- // },
- addStateToJson("parking_brake",
- crr_state.parking_brake.is_changed,
- stm::gStmParkingBrakeStateNo2Name[crr_state.parking_brake.state],
- json_out);
-
- // "accel_pedal": {
- // "is_changed": <bool>,
- // "state": <const char*>
- // },
- addStateToJson("accel_pedal",
- crr_state.accel_pedal.is_changed,
- stm::gStmAccelPedalStateNo2Name[crr_state.accel_pedal.state],
- json_out);
-
- // "lightstatus_brake": {
- // "is_changed": <bool>,
- // "state": <const char*>
- // },
- addStateToJson("lightstatus_brake",
- crr_state.lightstatus_brake.is_changed,
- stm::gStmLightstatusBrakeStateNo2Name[crr_state.lightstatus_brake.state],
- json_out);
-
- // "car": {
- // "is_changed": <bool>,
- // "state": <const char*>
- // },
- addStateToJson("car",
- crr_state.car.is_changed,
- stm::gStmCarStateNo2Name[crr_state.car.state],
- json_out);
-
- // "lamp": {
- // "is_changed": <bool>,
- // "state": <const char*>
- // },
- addStateToJson("lamp",
- crr_state.lamp.is_changed,
- stm::gStmLampStateNo2Name[crr_state.lamp.state],
- json_out);
-
- // "restriction_mode": {
- // "is_changed": <bool>,
- // "state": <const char*>
+ // "car_elements": [
+ // {
+ // "parking_brake": {
+ // "is_changed": <bool>,
+ // "state": <const char*>
+ // },
+ // ...
// },
- addStateToJson("restriction_mode",
- crr_state.restriction_mode.is_changed,
- stm::gStmRestrictionModeStateNo2Name[crr_state.restriction_mode.state],
- json_out);
+ json_object* json_car_ele = json_object_new_array();
+ const char* car_ele_name;
+ for (int car_ele_no = stm::gStmCarElementNoMin;
+ car_ele_no <= stm::gStmCarElementNoMax; car_ele_no++) {
+ car_ele_name = stm::gStmCarElementName[car_ele_no];
+ json_tmp = json_object_new_object();
+ addStateToJson(car_ele_name,
+ pm::g_crr_car_elements[car_ele_name].changed,
+ pm::g_crr_car_elements[car_ele_name].state,
+ &json_tmp);
+ json_object_array_add(json_car_ele, json_tmp);
+ }
+ json_object_object_add(*json_out, "car_elements", json_car_ele);
// Create layout information
//
@@ -498,32 +537,28 @@ static void createOutputInformation(stm::stm_state_t crr_state, json_object **js
// },
// ...
json_object* json_layer = json_object_new_array();
- json_object* json_tmp;
+ const char* layer_name;
for (int layer_no = stm::gStmLayerNoMin;
layer_no <= stm::gStmLayerNoMax; layer_no++) {
- const char* layer_name = stm::gStmLayerName[layer_no];
- HMI_DEBUG("wm:pm", "LAYER:%s", layer_name);
-
+ layer_name = stm::gStmLayerName[layer_no];
json_tmp = json_object_new_object();
addStateToJson(layer_name,
- crr_state.layer[layer_no].is_changed,
+ pm::g_crr_layers[layer_name].changed,
pm::g_crr_layers[layer_name].layout_state.area_list,
&json_tmp);
json_object_array_add(json_layer, json_tmp);
}
-
- // Add json array of layer
json_object_object_add(*json_out, "layers", json_layer);
}
static int checkPolicyEntry(int event, uint64_t delay_ms, std::string role);
static void controlTimerEvent(stm::stm_state_t crr_state) {
- if (crr_state.car.is_changed) {
- if (stm::gStmCarStateNoRun == crr_state.car.state) {
+ if (crr_state.car_element[stm::gStmCarElementNoRunning].is_changed) {
+ if (stm::gStmRunningNoRun == crr_state.car_element[stm::gStmCarElementNoRunning].state) {
// Set delay event(restriction mode on)
checkPolicyEntry(STM_EVT_NO_RESTRICTION_MODE_ON, 3000, "");
}
- else if (stm::gStmCarStateNoStop == crr_state.car.state) {
+ else if (stm::gStmRunningNoStop == crr_state.car_element[stm::gStmCarElementNoRunning].state) {
// Stop timer for restriction on event
if (pm::event_source_list.find(STM_EVT_NO_RESTRICTION_MODE_ON)
!= pm::event_source_list.end()) {
@@ -578,47 +613,6 @@ static int checkPolicy(sd_event_source *source, void *data) {
return -1;
}
- HMI_DEBUG("wm:pm", "parking brake state (is_changed:%d state:%d:%s)",
- crr_state.parking_brake.is_changed,
- crr_state.parking_brake.state,
- stm::gStmParkingBrakeStateNo2Name[crr_state.parking_brake.state]);
- HMI_DEBUG("wm:pm", "accelerator pedal state (is_changed:%d state:%d:%s)",
- crr_state.accel_pedal.is_changed,
- crr_state.accel_pedal.state,
- stm::gStmAccelPedalStateNo2Name[crr_state.accel_pedal.state]);
- HMI_DEBUG("wm:pm", "lightstatus brake state (is_changed:%d state:%d:%s)",
- crr_state.lightstatus_brake.is_changed,
- crr_state.lightstatus_brake.state,
- stm::gStmLightstatusBrakeStateNo2Name[crr_state.lightstatus_brake.state]);
- HMI_DEBUG("wm:pm", "car state (is_changed:%d state:%d:%s)",
- crr_state.car.is_changed,
- crr_state.car.state,
- stm::gStmCarStateNo2Name[crr_state.car.state]);
- HMI_DEBUG("wm:pm", "lamp state (is_changed:%d state:%d:%s)",
- crr_state.lamp.is_changed,
- crr_state.lamp.state,
- stm::gStmLampStateNo2Name[crr_state.lamp.state]);
- HMI_DEBUG("wm:pm", "restriction mode state (is_changed:%d state:%d:%s)",
- crr_state.restriction_mode.is_changed,
- crr_state.restriction_mode.state,
- stm::gStmRestrictionModeStateNo2Name[crr_state.restriction_mode.state]);
- HMI_DEBUG("wm:pm", "homescreen state (is_changed:%d state:%d:%s)",
- crr_state.layer[stm::gStmLayerNoHomescreen].is_changed,
- crr_state.layer[stm::gStmLayerNoHomescreen].state,
- stm::gStmLayoutNo2Name[crr_state.layer[stm::gStmLayerNoHomescreen].state]);
- HMI_DEBUG("wm:pm", "apps state (is_changed:%d state:%d:%s)",
- crr_state.layer[stm::gStmLayerNoApps].is_changed,
- crr_state.layer[stm::gStmLayerNoApps].state,
- stm::gStmLayoutNo2Name[crr_state.layer[stm::gStmLayerNoApps].state]);
- HMI_DEBUG("wm:pm", "restriction state (is_changed:%d state:%d:%s)",
- crr_state.layer[stm::gStmLayerNoRestriction].is_changed,
- crr_state.layer[stm::gStmLayerNoRestriction].state,
- stm::gStmLayoutNo2Name[crr_state.layer[stm::gStmLayerNoRestriction].state]);
- HMI_DEBUG("wm:pm", "on_screen state (is_changed:%d state:%d:%s)",
- crr_state.layer[stm::gStmLayerNoOnScreen].is_changed,
- crr_state.layer[stm::gStmLayerNoOnScreen].state,
- stm::gStmLayoutNo2Name[crr_state.layer[stm::gStmLayerNoOnScreen].state]);
-
// Update state which is managed by PolicyManager
updateLocalState(event_data, crr_state);
diff --git a/src/policy_manager/policy_manager.hpp b/src/policy_manager/policy_manager.hpp
index 6b37316..3e380f0 100644
--- a/src/policy_manager/policy_manager.hpp
+++ b/src/policy_manager/policy_manager.hpp
@@ -61,6 +61,7 @@ private:
std::unordered_map<std::string, std::string> category2role_;
std::unordered_map<std::string, std::string> role2defaultarea_;
+ void initializeLocalState();
int initializeSdEventLoop();
// Load role.db
diff --git a/src/policy_manager/zipc/dummy_stm.c b/src/policy_manager/zipc/dummy_stm.c
index 50b4586..50efaf3 100644
--- a/src/policy_manager/zipc/dummy_stm.c
+++ b/src/policy_manager/zipc/dummy_stm.c
@@ -104,7 +104,7 @@ const char* gStmAccelPedalStateNo2Name[] = {
"accel_pedal_on"
};
-const char* gStmCarStateNo2Name[] = {
+const char* gStmRunningNo2Name[] = {
"car_stop",
"car_run"
};
@@ -149,6 +149,26 @@ const char* gStmLayerName[] = {
"on_screen",
};
+const char* gStmCarElementName[] = {
+ "trans_gear",
+ "parking_brake",
+ "accel_pedal",
+ "running",
+ "lamp",
+ "lightstatus_brake",
+ "restriction_mode",
+};
+
+const char** gStmCarStateNameList[] = {
+ gStmTransGearStateNo2Name,
+ gStmParkingBrakeStateNo2Name,
+ gStmAccelPedalStateNo2Name,
+ gStmRunningNo2Name,
+ gStmLampStateNo2Name,
+ gStmLightstatusBrakeStateNo2Name,
+ gStmRestrictionModeStateNo2Name,
+};
+
stm_state_t g_crr_state;
stm_state_t g_prv_state;
int g_prv_restriction_state_car_stop = 0;
@@ -159,17 +179,17 @@ void stmInitialize() {
// Initialize previous state
memset(&g_prv_state, 0, sizeof(g_prv_state));
- g_prv_state.layer[gStmLayerNoOnScreen].state = gStmLayoutNoNone;
+ g_prv_state.layer[gStmLayerNoOnScreen].state = gStmLayoutNoNone;
g_prv_state.layer[gStmLayerNoRestriction].state = gStmLayoutNoNone;
g_prv_state.layer[gStmLayerNoApps].state = gStmLayoutNoNone;
g_prv_state.layer[gStmLayerNoHomescreen].state = gStmLayoutNoNone;
- g_prv_state.trans_gear.state = gStmTransGearStateNoN;
- g_prv_state.lightstatus_brake.state = gStmLightstatusBrakeStateNoOn;
- g_prv_state.accel_pedal.state = gStmAccelPedalStateNoOff;
- g_prv_state.car.state = gStmCarStateNoStop;
- g_prv_state.lamp.state = gStmLampStateNoOff;
- g_prv_state.parking_brake.state = gStmParkingBrakeStateNoOn;
- g_prv_state.restriction_mode.state = gStmRestrictionModeStateNoOff;
+ g_prv_state.car_element[gStmCarElementNoTransGear].state = gStmTransGearStateNoN;
+ g_prv_state.car_element[gStmCarElementNoLightstatusBrake].state = gStmLightstatusBrakeStateNoOn;
+ g_prv_state.car_element[gStmCarElementNoAccelPedal].state = gStmAccelPedalStateNoOff;
+ g_prv_state.car_element[gStmCarElementNoRunning].state = gStmRunningNoStop;
+ g_prv_state.car_element[gStmCarElementNoLamp].state = gStmLampStateNoOff;
+ g_prv_state.car_element[gStmCarElementNoParkingBrake].state = gStmParkingBrakeStateNoOn;
+ g_prv_state.car_element[gStmCarElementNoRestrictionMode].state = gStmRestrictionModeStateNoOff;
// Initialize current state
g_crr_state = g_prv_state;
@@ -190,88 +210,88 @@ int stmTransitionState(int event, stm_state_t* state) {
// Get previous state
restriction_state = g_prv_state.layer[gStmLayerNoRestriction].state;
apps_state = g_prv_state.layer[gStmLayerNoApps].state;
- trans_gear_state = g_prv_state.trans_gear.state;
- parking_brake_state = g_prv_state.parking_brake.state;
- accel_pedal_state = g_prv_state.accel_pedal.state;
- car_state = g_prv_state.car.state;
- lamp_state = g_prv_state.lamp.state;
- lightstatus_brake_state = g_prv_state.lightstatus_brake.state;
- restriction_mode_state = g_prv_state.restriction_mode.state;
+ trans_gear_state = g_prv_state.car_element[gStmCarElementNoTransGear].state;
+ parking_brake_state = g_prv_state.car_element[gStmCarElementNoParkingBrake].state;
+ accel_pedal_state = g_prv_state.car_element[gStmCarElementNoAccelPedal].state;
+ car_state = g_prv_state.car_element[gStmCarElementNoRunning].state;
+ lamp_state = g_prv_state.car_element[gStmCarElementNoLamp].state;
+ lightstatus_brake_state = g_prv_state.car_element[gStmCarElementNoLightstatusBrake].state;
+ restriction_mode_state = g_prv_state.car_element[gStmCarElementNoRestrictionMode].state;
// Clear flags
- g_crr_state.layer[gStmLayerNoOnScreen].is_changed = STM_FALSE;
+ g_crr_state.layer[gStmLayerNoOnScreen].is_changed = STM_FALSE;
g_crr_state.layer[gStmLayerNoRestriction].is_changed = STM_FALSE;
g_crr_state.layer[gStmLayerNoApps].is_changed = STM_FALSE;
g_crr_state.layer[gStmLayerNoHomescreen].is_changed = STM_FALSE;
- g_crr_state.trans_gear.is_changed = STM_FALSE;
- g_crr_state.parking_brake.is_changed = STM_FALSE;
- g_crr_state.lightstatus_brake.is_changed = STM_FALSE;
- g_crr_state.accel_pedal.is_changed = STM_FALSE;
- g_crr_state.car.is_changed = STM_FALSE;
- g_crr_state.lamp.is_changed = STM_FALSE;
- g_crr_state.restriction_mode.is_changed = STM_FALSE;
+ g_crr_state.car_element[gStmCarElementNoTransGear].is_changed = STM_FALSE;
+ g_crr_state.car_element[gStmCarElementNoParkingBrake].is_changed = STM_FALSE;
+ g_crr_state.car_element[gStmCarElementNoLightstatusBrake].is_changed = STM_FALSE;
+ g_crr_state.car_element[gStmCarElementNoAccelPedal].is_changed = STM_FALSE;
+ g_crr_state.car_element[gStmCarElementNoRunning].is_changed = STM_FALSE;
+ g_crr_state.car_element[gStmCarElementNoLamp].is_changed = STM_FALSE;
+ g_crr_state.car_element[gStmCarElementNoRestrictionMode].is_changed = STM_FALSE;
// Set car state
switch (event_no) {
case STM_EVT_NO_TRANS_GEAR_N:
if (gStmTransGearStateNoN != trans_gear_state) {
- g_crr_state.trans_gear.state = gStmTransGearStateNoN;
- g_crr_state.trans_gear.is_changed = STM_TRUE;
+ g_crr_state.car_element[gStmCarElementNoTransGear].state = gStmTransGearStateNoN;
+ g_crr_state.car_element[gStmCarElementNoTransGear].is_changed = STM_TRUE;
}
break;
case STM_EVT_NO_TRANS_GEAR_NOT_N:
if (gStmTransGearStateNoNotN != trans_gear_state) {
- g_crr_state.trans_gear.state = gStmTransGearStateNoNotN;
- g_crr_state.trans_gear.is_changed = STM_TRUE;
+ g_crr_state.car_element[gStmCarElementNoTransGear].state = gStmTransGearStateNoNotN;
+ g_crr_state.car_element[gStmCarElementNoTransGear].is_changed = STM_TRUE;
}
break;
case STM_EVT_NO_PARKING_BRAKE_OFF:
if (gStmParkingBrakeStateNoOff != parking_brake_state) {
- g_crr_state.parking_brake.state = gStmParkingBrakeStateNoOff;
- g_crr_state.parking_brake.is_changed = STM_TRUE;
+ g_crr_state.car_element[gStmCarElementNoParkingBrake].state = gStmParkingBrakeStateNoOff;
+ g_crr_state.car_element[gStmCarElementNoParkingBrake].is_changed = STM_TRUE;
}
break;
case STM_EVT_NO_PARKING_BRAKE_ON:
if (gStmParkingBrakeStateNoOn != parking_brake_state) {
- g_crr_state.parking_brake.state = gStmParkingBrakeStateNoOn;
- g_crr_state.parking_brake.is_changed = STM_TRUE;
+ g_crr_state.car_element[gStmCarElementNoParkingBrake].state = gStmParkingBrakeStateNoOn;
+ g_crr_state.car_element[gStmCarElementNoParkingBrake].is_changed = STM_TRUE;
}
break;
case STM_EVT_NO_ACCEL_PEDAL_OFF:
if (gStmAccelPedalStateNoOff != accel_pedal_state) {
- g_crr_state.accel_pedal.state = gStmAccelPedalStateNoOff;
- g_crr_state.accel_pedal.is_changed = STM_TRUE;
+ g_crr_state.car_element[gStmCarElementNoAccelPedal].state = gStmAccelPedalStateNoOff;
+ g_crr_state.car_element[gStmCarElementNoAccelPedal].is_changed = STM_TRUE;
}
break;
case STM_EVT_NO_ACCEL_PEDAL_ON:
if (gStmAccelPedalStateNoOn != accel_pedal_state) {
- g_crr_state.accel_pedal.state = gStmAccelPedalStateNoOn;
- g_crr_state.accel_pedal.is_changed = STM_TRUE;
+ g_crr_state.car_element[gStmCarElementNoAccelPedal].state = gStmAccelPedalStateNoOn;
+ g_crr_state.car_element[gStmCarElementNoAccelPedal].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;
+ g_crr_state.car_element[gStmCarElementNoLamp].state = gStmLampStateNoOff;
+ g_crr_state.car_element[gStmCarElementNoLamp].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;
+ g_crr_state.car_element[gStmCarElementNoLamp].state = gStmLampStateNoOn;
+ g_crr_state.car_element[gStmCarElementNoLamp].is_changed = STM_TRUE;
}
break;
case STM_EVT_NO_LIGHTSTATUS_BRAKE_OFF:
if (gStmLightstatusBrakeStateNoOff != lightstatus_brake_state) {
- g_crr_state.lightstatus_brake.state = gStmLightstatusBrakeStateNoOff;
- g_crr_state.lightstatus_brake.is_changed = STM_TRUE;
+ g_crr_state.car_element[gStmCarElementNoLightstatusBrake].state = gStmLightstatusBrakeStateNoOff;
+ g_crr_state.car_element[gStmCarElementNoLightstatusBrake].is_changed = STM_TRUE;
}
break;
case STM_EVT_NO_LIGHTSTATUS_BRAKE_ON:
if (gStmLightstatusBrakeStateNoOn != lightstatus_brake_state) {
- g_crr_state.lightstatus_brake.state = gStmLightstatusBrakeStateNoOn;
- g_crr_state.lightstatus_brake.is_changed = STM_TRUE;
+ g_crr_state.car_element[gStmCarElementNoLightstatusBrake].state = gStmLightstatusBrakeStateNoOn;
+ g_crr_state.car_element[gStmCarElementNoLightstatusBrake].is_changed = STM_TRUE;
}
break;
default:
@@ -280,27 +300,27 @@ int stmTransitionState(int event, stm_state_t* state) {
}
#if 1 // FOR ALS
- if (g_crr_state.lightstatus_brake.is_changed
- || g_crr_state.accel_pedal.is_changed) {
- if ((gStmLightstatusBrakeStateNoOff == g_crr_state.lightstatus_brake.state)
- && (gStmAccelPedalStateNoOn == g_crr_state.accel_pedal.state)){
+ if (g_crr_state.car_element[gStmCarElementNoLightstatusBrake].is_changed
+ || g_crr_state.car_element[gStmCarElementNoAccelPedal].is_changed) {
+ if ((gStmLightstatusBrakeStateNoOff == g_crr_state.car_element[gStmCarElementNoLightstatusBrake].state)
+ && (gStmAccelPedalStateNoOn == g_crr_state.car_element[gStmCarElementNoAccelPedal].state)){
#else
- if (g_crr_state.parking_brake.is_changed
- || g_crr_state.trans_gear.is_changed) {
- if ((gStmParkingBrakeStateNoOff == g_crr_state.parking_brake.state)
- && (gStmTransGearStateNoNotN == g_crr_state.trans_gear.state)){
+ if (g_crr_state.car_element[gStmCarElementNoParkingBrake].is_changed
+ || g_crr_state.car_element[gStmCarElementNoTransGear].is_changed) {
+ if ((gStmParkingBrakeStateNoOff == g_crr_state.car_element[gStmCarElementNoParkingBrake].state)
+ && (gStmTransGearStateNoNotN == g_crr_state.car_element[gStmCarElementNoTransGear].state)){
#endif
- if (gStmCarStateNoRun != car_state) {
+ if (gStmRunningNoRun != car_state) {
// Car state is changed stop -> run
- g_crr_state.car.state = gStmCarStateNoRun;
- g_crr_state.car.is_changed = STM_TRUE;
+ g_crr_state.car_element[gStmCarElementNoRunning].state = gStmRunningNoRun;
+ g_crr_state.car_element[gStmCarElementNoRunning].is_changed = STM_TRUE;
}
}
else {
- if (gStmCarStateNoStop != car_state) {
+ if (gStmRunningNoStop != car_state) {
// Car state is changed run -> stop
- g_crr_state.car.state = gStmCarStateNoStop;
- g_crr_state.car.is_changed = STM_TRUE;
+ g_crr_state.car_element[gStmCarElementNoRunning].state = gStmRunningNoStop;
+ g_crr_state.car_element[gStmCarElementNoRunning].is_changed = STM_TRUE;
}
}
}
@@ -311,8 +331,8 @@ int stmTransitionState(int event, stm_state_t* state) {
HMI_DEBUG("wm:pm:stm", "Restriction mode OFF -> ON");
// Restriction mode is changed OFF -> ON
- g_crr_state.restriction_mode.state = gStmRestrictionModeStateNoOn;
- g_crr_state.restriction_mode.is_changed = STM_TRUE;
+ g_crr_state.car_element[gStmCarElementNoRestrictionMode].state = gStmRestrictionModeStateNoOn;
+ g_crr_state.car_element[gStmCarElementNoRestrictionMode].is_changed = STM_TRUE;
// Update restriction layer
g_prv_restriction_state_car_stop = restriction_state;
@@ -332,8 +352,8 @@ int stmTransitionState(int event, stm_state_t* state) {
HMI_DEBUG("wm:pm:stm", "Restriction mode ON -> OFF");
// Restriction mode is changed ON -> OFF
- g_crr_state.restriction_mode.state = gStmRestrictionModeStateNoOff;
- g_crr_state.restriction_mode.is_changed = STM_TRUE;
+ g_crr_state.car_element[gStmCarElementNoRestrictionMode].state = gStmRestrictionModeStateNoOff;
+ g_crr_state.car_element[gStmCarElementNoRestrictionMode].is_changed = STM_TRUE;
// Update restriction layer
g_crr_state.layer[gStmLayerNoRestriction].state = g_prv_restriction_state_car_stop;
@@ -570,7 +590,7 @@ int stmTransitionState(int event, stm_state_t* state) {
// Set restriction layer
if (STM_CTG_NO_RESTRICTION == category_no) {
if (STM_EVT_NO_ACTIVATE == event_no) {
- if (gStmLightstatusBrakeStateNoOff == g_crr_state.lightstatus_brake.state) {
+ if (gStmLightstatusBrakeStateNoOff == g_crr_state.car_element[gStmCarElementNoLightstatusBrake].state) {
switch (area_no) {
case STM_ARA_NO_RESTRICTION_NORMAL:
switch (restriction_state) {
@@ -630,7 +650,7 @@ int stmTransitionState(int event, stm_state_t* state) {
}
}
else if (g_crr_state.layer[gStmLayerNoApps].is_changed) {
- if (gStmLightstatusBrakeStateNoOff == g_crr_state.lightstatus_brake.state) {
+ if (gStmLightstatusBrakeStateNoOff == g_crr_state.car_element[gStmCarElementNoLightstatusBrake].state) {
if (gStmLayoutNoM2 == g_crr_state.layer[gStmLayerNoApps].state) {
g_crr_state.layer[gStmLayerNoRestriction].state = gStmLayoutNoRestrictionSplitSub;
g_crr_state.layer[gStmLayerNoRestriction].is_changed = STM_TRUE;
diff --git a/src/policy_manager/zipc/dummy_stm.h b/src/policy_manager/zipc/dummy_stm.h
index 73feed9..3748ecd 100644
--- a/src/policy_manager/zipc/dummy_stm.h
+++ b/src/policy_manager/zipc/dummy_stm.h
@@ -85,8 +85,8 @@ enum stm_accel_pedal_state_ {
};
enum stm_car_state_ {
- gStmCarStateNoStop = 0,
- gStmCarStateNoRun
+ gStmRunningNoStop = 0,
+ gStmRunningNoRun
};
enum stm_lamp_state_ {
@@ -191,6 +191,21 @@ enum stm_layer_ {
gStmLayerNoMax = gStmLayerNoNum - 1,
};
+enum stm_car_element_ {
+ gStmCarElementNoTransGear = 0,
+ gStmCarElementNoParkingBrake,
+ gStmCarElementNoAccelPedal,
+ gStmCarElementNoRunning,
+ gStmCarElementNoLamp,
+ gStmCarElementNoLightstatusBrake,
+ gStmCarElementNoRestrictionMode,
+
+ gStmCarElementNoNum,
+
+ gStmCarElementNoMin = gStmCarElementNoTransGear,
+ gStmCarElementNoMax = gStmCarElementNoNum - 1,
+};
+
extern const char* gStmEventName[];
extern const int gStmEventNo[];
extern const char* gStmCategoryName[];
@@ -198,15 +213,11 @@ extern const int gStmCategoryNo[];
extern const char* gStmAreaName[];
extern const int gStmAreaNo[];
extern const char* gStmLayerName[];
+extern const char* gStmCarElementName[];
// String for state
-extern const char* gStmParkingBrakeStateNo2Name[];
-extern const char* gStmAccelPedalStateNo2Name[];
-extern const char* gStmCarStateNo2Name[];
-extern const char* gStmLampStateNo2Name[];
extern const char* gStmLayoutNo2Name[];
-extern const char* gStmLightstatusBrakeStateNo2Name[];
-extern const char* gStmRestrictionModeStateNo2Name[];
+extern const char** gStmCarStateNameList[];
// Struct for state
typedef struct stm_base_state_ {
@@ -214,23 +225,9 @@ typedef struct stm_base_state_ {
int state;
} stm_base_state;
-typedef struct stm_layer_state_ {
- stm_base_state on_screen;
- stm_base_state restriction;
- stm_base_state apps;
- stm_base_state homescreen;
-} stm_layer_state;
-
typedef struct {
- stm_base_state trans_gear;
- stm_base_state parking_brake;
- stm_base_state accel_pedal;
- stm_base_state car;
- stm_base_state lamp;
- stm_base_state lightstatus_brake;
- stm_base_state restriction_mode;
+ stm_base_state car_element[gStmCarElementNoNum];
stm_base_state layer[gStmLayerNoNum];
-// stm_layer_state layer;
} stm_state_t;