aboutsummaryrefslogtreecommitdiffstats
path: root/src/policy_manager/stm
diff options
context:
space:
mode:
Diffstat (limited to 'src/policy_manager/stm')
-rw-r--r--src/policy_manager/stm/stub/src/CMakeLists.txt53
-rw-r--r--src/policy_manager/stm/stub/src/include/stm.h170
-rw-r--r--src/policy_manager/stm/stub/src/stm.c237
3 files changed, 460 insertions, 0 deletions
diff --git a/src/policy_manager/stm/stub/src/CMakeLists.txt b/src/policy_manager/stm/stub/src/CMakeLists.txt
new file mode 100644
index 0000000..76b4eff
--- /dev/null
+++ b/src/policy_manager/stm/stub/src/CMakeLists.txt
@@ -0,0 +1,53 @@
+#
+# 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_STM libstm)
+
+add_library(${TARGETS_STM} MODULE
+ stm.c
+)
+
+target_include_directories(${TARGETS_STM}
+ PRIVATE
+ ./include
+)
+
+target_compile_definitions(${TARGETS_STM}
+ PRIVATE
+ _GNU_SOURCE
+)
+
+target_compile_options(${TARGETS_STM}
+ PRIVATE
+ -Wall -Wextra -Wno-unused-parameter -Wno-comment)
+
+set_target_properties(${TARGETS_STM}
+ PROPERTIES
+ C_EXTENSIONS OFF
+ C_STANDARD 99
+ C_STANDARD_REQUIRED ON
+)
+
+install(
+ TARGETS ${TARGET_STM}
+ DESTINATION ${CMAKE_INSTALL_LIBDIR}
+ COMPONENT "runtime"
+)
diff --git a/src/policy_manager/stm/stub/src/include/stm.h b/src/policy_manager/stm/stub/src/include/stm.h
new file mode 100644
index 0000000..5f672b1
--- /dev/null
+++ b/src/policy_manager/stm/stub/src/include/stm.h
@@ -0,0 +1,170 @@
+/*
+ * 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_STUB_STM_HPP
+#define TMCAGLWM_STUB_STM_HPP
+
+#define STM_TRUE 1
+#define STM_FALSE 0
+
+#define STM_CREATE_EVENT_ID(evt, ctg, area) \
+ ((evt) | ((ctg) << 8) | ((area) << 16))
+
+#define STM_GET_EVENT_FROM_ID(id) \
+ ((id) & 0xFF)
+
+#define STM_GET_CATEGORY_FROM_ID(id) \
+ (((id) >> 8) & 0xFF)
+
+#define STM_GET_AREA_FROM_ID(id) \
+ (((id) >> 16) & 0xFF)
+
+// Event number
+enum StmEvtNo {
+ StmEvtNoNone = 0,
+ StmEvtNoActivate,
+ StmEvtNoDeactivate,
+ StmEvtNoRestrictionModeOff,
+ StmEvtNoRestrictionMode1On,
+ StmEvtNoRestrictionMode2On,
+ StmEvtNoUndo,
+
+ StmEvtNoNum,
+
+ StmEvtNoMin = StmEvtNoNone,
+ StmEvtNoMax = StmEvtNoNum - 1,
+};
+
+// Category number
+enum StmCtgNo {
+ StmCtgNoNone = 0,
+ StmCtgNoHomescreen,
+ StmCtgNoMap,
+ StmCtgNoGeneral,
+ StmCtgNoSplitable,
+ StmCtgNoPopUp,
+ StmCtgNoSystemAlert,
+ StmCtgNoRestriction,
+ StmCtgNoSystem,
+ StmCtgNoSoftwareKeyboard,
+
+ StmCtgNoNum,
+
+ StmCtgNoMin = StmCtgNoNone,
+ StmCtgNoMax = StmCtgNoNum - 1,
+};
+
+// Area number
+enum StmAreaNo {
+ StmAreaNoNone = 0,
+ StmAreaNoFullscreen,
+ StmAreaNoNormal,
+ StmAreaNoSplitMain,
+ StmAreaNoSplitSub,
+ StmAreaNoOnScreen,
+ StmAreaNoRestrictionNormal,
+ StmAreaNoRestrictionSplitMain,
+ StmAreaNoRestrictionSplitSub,
+ StmAreaNoSoftwareKyeboard,
+
+ StmAreaNoNum,
+
+ StmAreaNoMin = StmAreaNoNone,
+ StmAreaNoMax = StmAreaNoNum - 1,
+};
+
+// Layer number
+enum StmLayerNo {
+ StmLayerNoHomescreen = 0,
+ StmLayerNoApps,
+ StmLayerNoNearHomescreen,
+ StmLayerNoRestriction,
+ StmLayerNoOnScreen,
+
+ StmLayerNoNum,
+
+ StmLayerNoMin = StmLayerNoHomescreen,
+ StmLayerNoMax = StmLayerNoNum - 1,
+};
+
+// Layout kind number
+enum StmLayoutNo {
+ StmLayoutNoNone = 0,
+ StmLayoutNoPopUp,
+ StmLayoutNoSysAlt,
+ StmLayoutNoMapNml,
+ StmLayoutNoMapSpl,
+ StmLayoutNoMapFll,
+ StmLayoutNoSplNml,
+ StmLayoutNoSplSpl,
+ StmLayoutNoGenNml,
+ StmLayoutNoHms,
+ StmLayoutNoRstNml,
+ StmLayoutNoRstSplMain,
+ StmLayoutNoRstSplSub,
+ StmLayoutNoSysNml,
+ StmLayoutNoSftKbd,
+
+ StmLayoutNoNum,
+
+ StmLayoutNoMin = StmLayoutNoNone,
+ StmLayoutNoMax = StmLayoutNoNum - 1,
+};
+
+// Mode kind number
+enum StmModeNo {
+ StmModeNoRestrictionMode = 0,
+
+ StmModeNoNum,
+
+ StmModeNoMin = StmModeNoRestrictionMode,
+ StmModeNoMax = StmModeNoNum - 1,
+};
+
+// Enum for mode state
+enum StmRestrictionModeSttNo {
+ StmRestrictionModeSttNoOff = 0,
+ StmRestrictionModeSttNo1On,
+ StmRestrictionModeSttNo2On,
+};
+
+// String for state
+extern const char* kStmEventName[];
+extern const char* kStmCategoryName[];
+extern const char* kStmAreaName[];
+extern const char* kStmLayoutName[];
+extern const char* kStmLayerName[];
+extern const char* kStmModeName[];
+extern const char** kStmModeStateNameList[];
+
+// Struct for state
+typedef struct StmBaseState {
+ int changed;
+ int state;
+} StmBaseState;
+
+typedef struct StmState {
+ StmBaseState mode[StmModeNoNum];
+ StmBaseState layer[StmLayerNoNum];
+} StmState;
+
+// API
+void stmInitialize();
+int stmTransitionState(int event_no, StmState* state);
+void stmUndoState();
+
+
+#endif // TMCAGLWM_STUB_STM_HPP
diff --git a/src/policy_manager/stm/stub/src/stm.c b/src/policy_manager/stm/stub/src/stm.c
new file mode 100644
index 0000000..222dc91
--- /dev/null
+++ b/src/policy_manager/stm/stub/src/stm.c
@@ -0,0 +1,237 @@
+/*
+ * 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 <string.h>
+#include "stm.h"
+
+const char* kStmEventName[] = {
+ "none",
+ "activate",
+ "deactivate",
+ "restriction_mode_off",
+ "restriction_mode_1_on",
+ "restriction_mode_2_on",
+ "undo",
+};
+
+const char* kStmCategoryName[] = {
+ "none",
+ "homescreen",
+ "map",
+ "general",
+ "splitable",
+ "pop_up",
+ "system_alert",
+ "restriction",
+ "system",
+ "software_keyboard",
+};
+
+const char* kStmAreaName[] = {
+ "none",
+ "fullscreen",
+ "normal",
+ "split.main",
+ "split.sub",
+ "on_screen",
+ "restriction.normal",
+ "restriction.split.main",
+ "restriction.split.sub",
+ "software_keyboard",
+};
+
+const char* kStmLayoutName[] = {
+ "none",
+ "pop_up",
+ "system_alert",
+ "map.normal",
+ "map.split",
+ "map.fullscreen",
+ "splitable.normal",
+ "splitable.split",
+ "general.normal",
+ "homescreen",
+ "restriction.normal",
+ "restriction.split.main",
+ "restriction.split.sub",
+ "system.normal",
+ "software_keyboard",
+};
+
+const char* kStmLayerName[] = {
+ "homescreen",
+ "apps",
+ "near_homescreen",
+ "restriction",
+ "on_screen",
+};
+
+const char* kStmModeName[] = {
+ "trans_gear",
+ "parking_brake",
+ "accel_pedal",
+ "running",
+ "lamp",
+ "lightstatus_brake",
+ "restriction_mode",
+};
+
+const char* kStmRestrictionModeStateName[] = {
+ "off",
+ "1on",
+ "2on",
+};
+
+const char** kStmModeStateNameList[] = {
+ kStmRestrictionModeStateName,
+};
+
+static StmState g_crr_state;
+static StmState g_prv_state;
+
+void stmInitialize() {
+ // Initialize previous state
+ memset(&g_prv_state, 0, sizeof(g_prv_state));
+
+ // Initialize current state
+ g_crr_state = g_prv_state;
+}
+
+int stmTransitionState(int event, StmState* state) {
+ int event_no, category_no;
+
+ event_no = STM_GET_EVENT_FROM_ID(event);
+ category_no = STM_GET_CATEGORY_FROM_ID(event);
+
+ // Backup previous state
+ g_prv_state = g_crr_state;
+
+ // Clear current state
+ memset(&g_prv_state, 0, sizeof(g_prv_state));
+
+ // -------------------------------------------------------
+ // There is no policy table by default.
+ // Therefore update each layers
+ // to draw the applications in normal.full area
+ // in accordance with inputed activate/deactivate events.
+ // -------------------------------------------------------
+ if (StmEvtNoActivate == event_no)
+ {
+ if (StmCtgNoHomescreen == category_no)
+ {
+ g_crr_state.layer[StmLayerNoHomescreen].state = StmLayoutNoHms;
+ g_crr_state.layer[StmLayerNoHomescreen].changed = STM_TRUE;
+
+ g_crr_state.layer[StmLayerNoApps].state = StmLayoutNoNone;
+ g_crr_state.layer[StmLayerNoApps].changed = STM_TRUE;
+ }
+ else if (StmCtgNoMap == category_no)
+ {
+ g_crr_state.layer[StmLayerNoApps].state = StmLayoutNoMapNml;
+ g_crr_state.layer[StmLayerNoApps].changed = STM_TRUE;
+ }
+ else if (StmCtgNoGeneral == category_no)
+ {
+ g_crr_state.layer[StmLayerNoApps].state = StmLayoutNoGenNml;
+ g_crr_state.layer[StmLayerNoApps].changed = STM_TRUE;
+ }
+ else if (StmCtgNoSystem == category_no)
+ {
+ g_crr_state.layer[StmLayerNoApps].state = StmLayoutNoSysNml;
+ g_crr_state.layer[StmLayerNoApps].changed = STM_TRUE;
+ }
+ else if (StmCtgNoSplitable == category_no)
+ {
+ g_crr_state.layer[StmLayerNoApps].state = StmLayoutNoSplNml;
+ g_crr_state.layer[StmLayerNoApps].changed = STM_TRUE;
+ }
+ else if (StmCtgNoPopUp == category_no)
+ {
+ g_crr_state.layer[StmLayerNoOnScreen].state = StmLayoutNoPopUp;
+ g_crr_state.layer[StmLayerNoOnScreen].changed = STM_TRUE;
+ }
+ else if (StmCtgNoSystemAlert == category_no)
+ {
+ g_crr_state.layer[StmLayerNoOnScreen].state = StmLayoutNoSysAlt;
+ g_crr_state.layer[StmLayerNoOnScreen].changed = STM_TRUE;
+ }
+ }
+ else if (StmEvtNoDeactivate == event_no)
+ {
+ if (StmCtgNoHomescreen == category_no)
+ {
+ g_crr_state.layer[StmLayerNoHomescreen].state = StmLayoutNoNone;
+ g_crr_state.layer[StmLayerNoHomescreen].changed = STM_TRUE;
+ }
+ else if (StmCtgNoMap == category_no)
+ {
+ if (StmLayoutNoMapNml == g_prv_state.layer[StmLayerNoApps].state )
+ {
+ g_crr_state.layer[StmLayerNoApps].state = StmLayoutNoNone;
+ g_crr_state.layer[StmLayerNoApps].changed = STM_TRUE;
+ }
+ }
+ else if (StmCtgNoGeneral == category_no)
+ {
+ if (StmLayoutNoGenNml == g_prv_state.layer[StmLayerNoApps].state )
+ {
+ g_crr_state.layer[StmLayerNoApps].state = StmLayoutNoNone;
+ g_crr_state.layer[StmLayerNoApps].changed = STM_TRUE;
+ }
+ }
+ else if (StmCtgNoSystem == category_no)
+ {
+ if (StmLayoutNoSysNml == g_prv_state.layer[StmLayerNoApps].state )
+ {
+ g_crr_state.layer[StmLayerNoApps].state = StmLayoutNoNone;
+ g_crr_state.layer[StmLayerNoApps].changed = STM_TRUE;
+ }
+ }
+ else if (StmCtgNoSplitable == category_no)
+ {
+ if (StmLayoutNoSplNml == g_prv_state.layer[StmLayerNoApps].state )
+ {
+ g_crr_state.layer[StmLayerNoApps].state = StmLayoutNoNone;
+ g_crr_state.layer[StmLayerNoApps].changed = STM_TRUE;
+ }
+ }
+ else if (StmCtgNoPopUp == category_no)
+ {
+ if (StmLayoutNoPopUp == g_prv_state.layer[StmLayerNoOnScreen].state )
+ {
+ g_crr_state.layer[StmLayerNoOnScreen].state = StmLayoutNoNone;
+ g_crr_state.layer[StmLayerNoOnScreen].changed = STM_TRUE;
+ }
+ }
+ else if (StmCtgNoSystemAlert == category_no)
+ {
+ if (StmLayoutNoSysAlt == g_prv_state.layer[StmLayerNoOnScreen].state )
+ {
+ g_crr_state.layer[StmLayerNoOnScreen].state = StmLayoutNoNone;
+ g_crr_state.layer[StmLayerNoOnScreen].changed = STM_TRUE;
+ }
+ }
+ }
+
+ // Copy current state for return
+ memcpy(state, &g_crr_state, sizeof(g_crr_state));
+
+ return 0;
+}
+
+void stmUndoState() {
+ g_crr_state = g_prv_state;
+}