- 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>
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";
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())) {
// 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());
{
"name": "Splitable2",
"role": "splitable2"
+ },
+ {
+ "name": "Restriction",
+ "role": "restriction"
}
]
}
\ No newline at end of file
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;
}
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
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
{
"layouts": [
- "description": "The layout is what roles the layer has in the areas.",
{
"name": "pu",
"layer": "on_screen",
},
{
"name": "split.sub",
- "role", "general"
+ "role": "general"
}
]
},
}
],
"areas": [
- "description": "The area is in the layer. The layout attaches areas to the layer"
{
"name": "fullscreen",
"rect": {
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
return this->is_layout_changed_[layer];
}
+
extern const char* kDefaultLayoutDb;
int LayoutManager::loadLayoutDb() {
HMI_DEBUG("wm:lm", "Call");
}
// 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));
"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",
return ret;
}
- // TODO:
// Initialize StateTransitioner
- // stmInitialize();
+ stm::stmInitialize();
return ret;
}
// 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!!");
&json_tmp);
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>,
// 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;
}
"general",
"splitable",
"popup",
- "system_alert"
+ "system_alert",
+ "restriction",
};
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[] = {
"normal",
"split.main",
"split.sub",
- "onscreen"
+ "onscreen",
+ "restriction.normal",
+ "restriction.split.main",
+ "restriction.split.sub",
};
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
"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;
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:
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:
#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
// 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_ {
gStmLayoutNoS1,
gStmLayoutNoS2,
gStmLayoutNoG,
- gStmLayoutNoHs
+ gStmLayoutNoHs,
+ gStmLayoutNoRestriction,
+ gStmLayoutNoRestrictionSplitMain,
+ gStmLayoutNoRestrictionSplitSub,
};
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;
stm_layer_state layer;
} stm_state_t;
+
+void stmInitialize();
int stmTransitionState(int event_no, stm_state_t* state);