aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYuta Doi <yuta-d@witz-inc.co.jp>2018-05-10 13:10:28 +0900
committerYuta Doi <yuta-d@witz-inc.co.jp>2018-05-10 13:10:28 +0900
commit2ea71aa957634ce69681ae34abace0566d52b744 (patch)
treeb9d9ee097a78d3d21ee07d85193a2e2e6862fce6
parent0dcb9ae1f99cffcafac62a324f8f054cc212a880 (diff)
Modify for restriction role
- Add policy for restriction to dummy stm. - Add the function which inputs json file because json_object_from_file can not allows up to only 4KB file. - Bug fix in json files. - Delete unexpected characters. - Delete description because it does not follow the format of json array. Change-Id: I2f8fba1d1001cf244e2531fe3a1a738d5a48091b Signed-off-by: Yuta Doi <yuta-d@witz-inc.co.jp>
-rw-r--r--src/app.cpp7
-rw-r--r--src/db/app.db4
-rw-r--r--src/json_helper.cpp61
-rw-r--r--src/json_helper.hpp1
-rw-r--r--src/layout_manager/db/layout.db4
-rw-r--r--src/layout_manager/layout.cpp11
-rw-r--r--src/policy_manager/db/role.db4
-rw-r--r--src/policy_manager/policy_manager.cpp20
-rw-r--r--src/policy_manager/zipc/dummy_stm.c118
-rw-r--r--src/policy_manager/zipc/dummy_stm.h26
10 files changed, 216 insertions, 40 deletions
diff --git a/src/app.cpp b/src/app.cpp
index b9338a9..777a07f 100644
--- a/src/app.cpp
+++ b/src/app.cpp
@@ -293,6 +293,9 @@ void App::allocateWindowResource(char const *event, char const *drawing_name,
else if (0 == strcmp("normal.full", drawing_area)) {
new_area = "normal";
}
+ else if (0 == strcmp("restriction.split.sub", drawing_area)) {
+ new_area = "restriction.split.sub";
+ }
else if (0 == strcmp("homescreen", new_role)) {
// Now homescreen specifies "normalfull"
new_area = "full";
@@ -909,7 +912,7 @@ int App::allocateSurface() {
itr_layers != crr_layers.end(); ++itr_layers) {
// Get layer
std::string layer = itr_layers->first;
- HMI_DEBUG("wm", "Update resource in %s layer", layer.c_str());
+ HMI_DEBUG("wm", "Try to update resource in %s layer", layer.c_str());
// If layout is changed, update resouce
if (this->lm_.isLayoutChanged(layer.c_str())) {
@@ -953,7 +956,7 @@ int App::allocateSurface() {
// Get category name
std::string crr_ctg = crr_rol_ctg.begin()->second;
- // Serch relevant role fron previous displayed role list
+ // Serch relevant role from previous displayed role list
for (auto itr_role = prv_role_list.begin();
itr_role != prv_role_list.end(); ++itr_role) {
std::string prv_ctg = this->pm_.roleToCategory((*itr_role).c_str());
diff --git a/src/db/app.db b/src/db/app.db
index 32155ac..7ec632b 100644
--- a/src/db/app.db
+++ b/src/db/app.db
@@ -63,6 +63,10 @@
{
"name": "Splitable2",
"role": "splitable2"
+ },
+ {
+ "name": "Restriction",
+ "role": "restriction"
}
]
} \ No newline at end of file
diff --git a/src/json_helper.cpp b/src/json_helper.cpp
index ac3d2b0..f9b916e 100644
--- a/src/json_helper.cpp
+++ b/src/json_helper.cpp
@@ -123,13 +123,13 @@ const char* getStringFromJson(json_object* obj, const char* key) {
int getIntFromJson(json_object* obj, const char* key) {
if ((nullptr == obj) || (nullptr == key)) {
- HMI_ERROR("wm", "Argument is nullptr!!!");
+ HMI_ERROR("wm:jh", "Argument is nullptr!!!");
return 0;
}
json_object* tmp;
if (!json_object_object_get_ex(obj, key, &tmp)) {
- HMI_DEBUG("wm", "Not found key \"%s\"", key);
+ HMI_DEBUG("wm:jh", "Not found key \"%s\"", key);
return 0;
}
@@ -138,17 +138,70 @@ int getIntFromJson(json_object* obj, const char* key) {
json_bool getBoolFromJson(json_object* obj, const char* key) {
if ((nullptr == obj) || (nullptr == key)) {
- HMI_ERROR("wm", "Argument is nullptr!!!");
+ HMI_ERROR("wm:jh", "Argument is nullptr!!!");
return 0;
}
json_object* tmp;
if (!json_object_object_get_ex(obj, key, &tmp)) {
- HMI_DEBUG("wm", "Not found key \"%s\"", key);
+ HMI_DEBUG("wm:jh", "Not found key \"%s\"", key);
return 0;
}
return json_object_get_boolean(tmp);
}
+int inputJsonFilie(const char* file, json_object** obj) {
+ const int input_size = 128;
+ int ret = -1;
+
+ if ((nullptr == file) || (nullptr == obj)) {
+ HMI_ERROR("wm:jh", "Argument is nullptr!!!");
+ return ret;
+ }
+
+ HMI_DEBUG("wm:jh", "Input file: %s", file);
+
+ // Open json file
+ FILE *fp = fopen(file, "rb");
+ if (nullptr == fp) {
+ HMI_ERROR("wm:jh", "Could not open file");
+ return ret;
+ }
+
+ // Parse file data
+ struct json_tokener *tokener = json_tokener_new();
+ enum json_tokener_error json_error;
+ char buffer[input_size];
+ int block_cnt = 1;
+ while (1) {
+ size_t len = fread(buffer, sizeof(char), input_size, fp);
+ *obj = json_tokener_parse_ex(tokener, buffer, len);
+ if (nullptr != *obj) {
+ HMI_DEBUG("wm:jh", "File input is success");
+ ret = 0;
+ break;
+ }
+
+ json_error = json_tokener_get_error(tokener);
+ if ((json_tokener_continue != json_error)
+ || (input_size > len)) {
+ HMI_ERROR("wm:jh", "Failed to parse file (byte:%d err:%s)",
+ (input_size * block_cnt), json_tokener_error_desc(json_error));
+ HMI_ERROR("wm:jh", "\n%s", buffer);
+ *obj = nullptr;
+ break;
+ }
+ block_cnt++;
+ }
+
+ // Close json file
+ fclose(fp);
+
+ // Free json_tokener
+ json_tokener_free(tokener);
+
+ return ret;
+}
+
} // namespace jh
diff --git a/src/json_helper.hpp b/src/json_helper.hpp
index c2087cf..22ec3e6 100644
--- a/src/json_helper.hpp
+++ b/src/json_helper.hpp
@@ -33,5 +33,6 @@ namespace jh {
const char* getStringFromJson(json_object* obj, const char* key);
int getIntFromJson(json_object* obj, const char* key);
json_bool getBoolFromJson(json_object* obj, const char* key);
+int inputJsonFilie(const char* file, json_object** obj);
} // namespace jh
#endif // TMCAGLWM_JSON_HELPER_HPP
diff --git a/src/layout_manager/db/layout.db b/src/layout_manager/db/layout.db
index 0de262f..02139e6 100644
--- a/src/layout_manager/db/layout.db
+++ b/src/layout_manager/db/layout.db
@@ -1,6 +1,5 @@
{
"layouts": [
- "description": "The layout is what roles the layer has in the areas.",
{
"name": "pu",
"layer": "on_screen",
@@ -169,7 +168,7 @@
},
{
"name": "split.sub",
- "role", "general"
+ "role": "general"
}
]
},
@@ -195,7 +194,6 @@
}
],
"areas": [
- "description": "The area is in the layer. The layout attaches areas to the layer"
{
"name": "fullscreen",
"rect": {
diff --git a/src/layout_manager/layout.cpp b/src/layout_manager/layout.cpp
index 3f4013e..faab316 100644
--- a/src/layout_manager/layout.cpp
+++ b/src/layout_manager/layout.cpp
@@ -104,7 +104,7 @@ bool LayoutManager::updateLayout(json_object* obj,
json_object_object_foreach(json_tmp, key, val) {
layer = key;
json_layer = val;
- HMI_DEBUG("wm:lm", "Update %s layer state", layer);
+ HMI_DEBUG("wm:lm", "Try to update %s layer state", layer);
}
// Store previous state
@@ -253,6 +253,7 @@ bool LayoutManager::isLayoutChanged(const char* layer) {
return this->is_layout_changed_[layer];
}
+
extern const char* kDefaultLayoutDb;
int LayoutManager::loadLayoutDb() {
HMI_DEBUG("wm:lm", "Call");
@@ -270,10 +271,10 @@ int LayoutManager::loadLayoutDb() {
}
// Load layout.db
- HMI_DEBUG("wm:lm", "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:lm", "Could not open layout.db, so use default role information");
+ json_object* json_obj;
+ int ret = jh::inputJsonFilie(file_name.c_str(), &json_obj);
+ if (0 > ret) {
+ HMI_DEBUG("wm:lm", "Could not open layout.db, so use default layout information");
json_obj = json_tokener_parse(kDefaultLayoutDb);
}
HMI_DEBUG("wm:lm", "json_obj dump:%s", json_object_get_string(json_obj));
diff --git a/src/policy_manager/db/role.db b/src/policy_manager/db/role.db
index 247aab2..6c5d715 100644
--- a/src/policy_manager/db/role.db
+++ b/src/policy_manager/db/role.db
@@ -2,13 +2,13 @@
"roles":[
{
"category": "homescreen",
- "role": "homescreen | "software_keyboard",
+ "role": "homescreen | software_keyboard",
"area": "full | software_keyboard",
},
{
"category": "restriction",
"role": "restriction",
- "area": "normal | restriction.split.main | restriction.split.sub",
+ "area": "restriction.normal | restriction.split.main | restriction.split.sub",
},
{
"category": "map",
diff --git a/src/policy_manager/policy_manager.cpp b/src/policy_manager/policy_manager.cpp
index 9ece573..3b0eac6 100644
--- a/src/policy_manager/policy_manager.cpp
+++ b/src/policy_manager/policy_manager.cpp
@@ -68,9 +68,8 @@ int PolicyManager::initialize() {
return ret;
}
- // TODO:
// Initialize StateTransitioner
- // stmInitialize();
+ stm::stmInitialize();
return ret;
}
@@ -123,7 +122,7 @@ int PolicyManager::checkPolicy(json_object* json_in, json_object** json_out) {
// 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),
+ int ret = stm::stmTransitionState((event_no | category_no | area_no),
&(this->current_state_));
if (0 > ret) {
HMI_ERROR("wm:pm", "Error!!");
@@ -187,6 +186,19 @@ int PolicyManager::checkPolicy(json_object* json_in, json_object** json_out) {
json_object_array_add(json_layer, json_tmp);
// {
+ // "restriction": {
+ // "is_changed": <bool>,
+ // "state": <const char*>
+ // }
+ // },
+ json_tmp = json_object_new_object();
+ this->addStateToJson("restriction",
+ this->current_state_.layer.restriction.is_changed,
+ stm::gStmLayoutNo2Name[this->current_state_.layer.restriction.state],
+ &json_tmp);
+ json_object_array_add(json_layer, json_tmp);
+
+ // {
// "apps": {
// "is_changed": <bool>,
// "state": <const char*>
@@ -217,8 +229,6 @@ int PolicyManager::checkPolicy(json_object* json_in, json_object** json_out) {
// 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;
}
diff --git a/src/policy_manager/zipc/dummy_stm.c b/src/policy_manager/zipc/dummy_stm.c
index 459f58c..07694cf 100644
--- a/src/policy_manager/zipc/dummy_stm.c
+++ b/src/policy_manager/zipc/dummy_stm.c
@@ -31,7 +31,8 @@ const char* gStmCategoryName[] = {
"general",
"splitable",
"popup",
- "system_alert"
+ "system_alert",
+ "restriction",
};
const int gStmCategoryNo[] = {
@@ -40,7 +41,8 @@ const int gStmCategoryNo[] = {
STM_CTG_NO_GENERAL,
STM_CTG_NO_SPLITABLE,
STM_CTG_NO_POPUP,
- STM_CTG_NO_SYSTEM_ALERT
+ STM_CTG_NO_SYSTEM_ALERT,
+ STM_CTG_NO_RESTRICTION,
};
const char* gStmAreaName[] = {
@@ -48,7 +50,10 @@ const char* gStmAreaName[] = {
"normal",
"split.main",
"split.sub",
- "onscreen"
+ "onscreen",
+ "restriction.normal",
+ "restriction.split.main",
+ "restriction.split.sub",
};
const int gStmAreaNo[] = {
@@ -56,7 +61,10 @@ const int gStmAreaNo[] = {
STM_ARA_NO_NORMAL,
STM_ARA_NO_SPLIT_MAIN,
STM_ARA_NO_SPLIT_SUB,
- STM_ARA_NO_ON_SCREEN
+ STM_ARA_NO_ON_SCREEN,
+ STM_ARA_NO_RESTRICTION_NORMAL,
+ STM_ARA_NO_RESTRICTION_SPLIT_MAIN,
+ STM_ARA_NO_RESTRICTION_SPLIT_SUB,
};
// String for state
@@ -86,15 +94,34 @@ const char* gStmLayoutNo2Name[] = {
"s2",
"g",
"hs",
+ "restriction",
+ "restriction.split.main",
+ "restriction.split.sub",
};
-stm_state_t g_crr_state = {0};
-stm_state_t g_prv_state = {0};
+stm_state_t g_crr_state;
+stm_state_t g_prv_state;
int g_prv_apps_state_car_stop = 0;
+void stmInitialize() {
+ // Initialize previous state
+ memset(&g_prv_state, 0, sizeof(g_prv_state));
+
+ g_prv_state.layer.on_screen.state = gStmLayoutNoNone;
+ g_prv_state.layer.restriction.state = gStmLayoutNoNone;
+ g_prv_state.layer.apps.state = gStmLayoutNoNone;
+ g_prv_state.layer.homescreen.state = gStmLayoutNoNone;
+ g_prv_state.parking_brake.state = gStmParkingBrakeStateNoOn;
+ g_prv_state.car.state = gStmCarStateNoStop;
+ g_prv_state.lamp.state = gStmLampStateNoOff;
+
+ // Initialize current state
+ g_crr_state = g_prv_state;
+}
+
int stmTransitionState(int event, stm_state_t* state) {
int event_no, category_no, area_no;
- int apps_state, parking_brake_state, car_state, lamp_state;
+ int restriction_state, apps_state, parking_brake_state, car_state, lamp_state;
event_no = event & STM_MSK_EVT_NO;
category_no = event & STM_MSK_CTG_NO;
@@ -104,13 +131,20 @@ int stmTransitionState(int event, stm_state_t* state) {
g_prv_state = g_crr_state;
// Get previous state
+ restriction_state = g_prv_state.layer.restriction.state;
apps_state = g_prv_state.layer.apps.state;
parking_brake_state = g_prv_state.parking_brake.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));
+ // Clear flags
+ g_crr_state.layer.on_screen.is_changed = STM_FALSE;
+ g_crr_state.layer.restriction.is_changed = STM_FALSE;
+ g_crr_state.layer.apps.is_changed = STM_FALSE;
+ g_crr_state.layer.homescreen.is_changed = STM_FALSE;
+ g_crr_state.parking_brake.is_changed = STM_FALSE;
+ g_crr_state.car.is_changed = STM_FALSE;
+ g_crr_state.lamp.is_changed = STM_FALSE;
switch (event_no) {
case STM_EVT_NO_ACTIVATE:
@@ -250,9 +284,71 @@ int stmTransitionState(int event, stm_state_t* state) {
break;
}
break;
+ case STM_CTG_NO_RESTRICTION:
+ switch (area_no) {
+ case STM_ARA_NO_RESTRICTION_NORMAL:
+ // restriction Layer
+ switch (restriction_state) {
+ case gStmLayoutNoNone:
+ g_crr_state.layer.restriction.state = gStmLayoutNoRestriction;
+ g_crr_state.layer.restriction.is_changed = STM_TRUE;
+ break;
+ default:
+ // nop
+ break;
+ }
+ break;
+ case STM_ARA_NO_RESTRICTION_SPLIT_MAIN:
+ // restriction Layer
+ switch (restriction_state) {
+ case gStmLayoutNoNone:
+ g_crr_state.layer.restriction.state = gStmLayoutNoRestrictionSplitMain;
+ g_crr_state.layer.restriction.is_changed = STM_TRUE;
+ break;
+ default:
+ // nop
+ break;
+ }
+ break;
+ case STM_ARA_NO_RESTRICTION_SPLIT_SUB:
+ // restriction Layer
+ switch (restriction_state) {
+ case gStmLayoutNoNone:
+ g_crr_state.layer.restriction.state = gStmLayoutNoRestrictionSplitSub;
+ g_crr_state.layer.restriction.is_changed = STM_TRUE;
+ break;
+ default:
+ // nop
+ break;
+ }
+ break;
+ default:
+ // nop
+ break;
+ }
+ break;
default:
- // nop
- break;
+ // nop
+ break;
+ }
+ case STM_EVT_NO_DEACTIVATE:
+ switch (category_no) {
+ case STM_CTG_NO_RESTRICTION:
+ // restriction Layer
+ switch (restriction_state) {
+ case gStmLayoutNoRestriction:
+ case gStmLayoutNoRestrictionSplitMain:
+ case gStmLayoutNoRestrictionSplitSub:
+ g_crr_state.layer.restriction.state = gStmLayoutNoNone;
+ g_crr_state.layer.restriction.is_changed = STM_TRUE;
+ break;
+ default:
+ // nop
+ break;
+ }
+ default:
+ // nop
+ break;
}
break;
case STM_EVT_NO_PARKING_BRAKE_OFF:
diff --git a/src/policy_manager/zipc/dummy_stm.h b/src/policy_manager/zipc/dummy_stm.h
index ae438db..38d3912 100644
--- a/src/policy_manager/zipc/dummy_stm.h
+++ b/src/policy_manager/zipc/dummy_stm.h
@@ -41,13 +41,17 @@
#define STM_CTG_NO_SPLITABLE 0x0400
#define STM_CTG_NO_POPUP 0x0500
#define STM_CTG_NO_SYSTEM_ALERT 0x0600
+#define STM_CTG_NO_RESTRICTION 0x0700
// 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
+#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
+#define STM_ARA_NO_RESTRICTION_NORMAL 0x060000
+#define STM_ARA_NO_RESTRICTION_SPLIT_MAIN 0x070000
+#define STM_ARA_NO_RESTRICTION_SPLIT_SUB 0x080000
// Mask
#define STM_MSK_EVT_NO 0x0000FF
@@ -56,8 +60,8 @@
// Number of events, categories and areas
#define STM_NUM_EVT 9
-#define STM_NUM_CTG 6
-#define STM_NUM_ARA 5
+#define STM_NUM_CTG 7
+#define STM_NUM_ARA 8
// Enum for state
enum stm_parking_brake_state_ {
@@ -85,7 +89,10 @@ enum stm_layout_ {
gStmLayoutNoS1,
gStmLayoutNoS2,
gStmLayoutNoG,
- gStmLayoutNoHs
+ gStmLayoutNoHs,
+ gStmLayoutNoRestriction,
+ gStmLayoutNoRestrictionSplitMain,
+ gStmLayoutNoRestrictionSplitSub,
};
@@ -110,6 +117,7 @@ typedef struct 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;
@@ -121,6 +129,8 @@ typedef struct {
stm_layer_state layer;
} stm_state_t;
+
+void stmInitialize();
int stmTransitionState(int event_no, stm_state_t* state);