Reset race now activates the 'Select car view'
[apps/native/gear-racing-controller.git] / src / gear-racing-controller.c
1 /*
2 * Copyright (c) 2018 Samsung Electronics Co., Ltd.
3 *
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/license/
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include "steering_setup.h"
18 #include "gear-racing-controller.h"
19 #include "config.h"
20 #include "view_manager/view_manager.h"
21 #include "model/model_sensors.h"
22 #include "model/model_hw.h"
23 #include "model/model_car_connection.h"
24 #include "net-util.h"
25 #include "log.h"
26
27 static bool app_create(void *data)
28 {
29         _D("--------========================================================--------");
30         _D("--------========================================================--------");
31         _D("--------=============== APP %s %s ===============--------", __DATE__, __TIME__);
32         _D("--------========================================================--------");
33         _D("--------========================================================--------");
34
35
36         model_sensors_init();
37         model_hw_init();
38         model_car_connection_init();
39         view_manager_initialize_ui();
40         net_util_init();
41         return true;
42 }
43
44 static void
45 app_control(app_control_h app_control, void *data)
46 {
47         char *appid;
48         int ret = app_control_get_app_id(app_control, &appid);
49         ASSERT_FUNCTION(ret != APP_CONTROL_ERROR_NONE);
50
51         char *config_file = NULL;
52
53         _D("APPID: %s", appid);
54
55         if (!strncmp(appid, "org.tizen.gear-racing-controller.bs", strlen(appid))) {
56                 _D("BS");
57                 config_file = "config-azim-thr-dir-elev.ini";
58         } else if (!strncmp(appid, "org.tizen.gear-racing-controller.sb", strlen(appid))) {
59                 _D("SB");
60                 config_file = "config-dir-elev-thr-azim.ini";
61         } else if (!strncmp(appid, "org.tizen.gear-racing-controller.ssa", strlen(appid))) {
62                 _D("SSA");
63                 config_file = "config-dir-thr-azim-elev.ini";
64         } else if (!strncmp(appid, "org.tizen.gear-racing-controller.sse", strlen(appid))) {
65                 _D("SSE");
66                 config_file = "config-dir-thr-elev-azim.ini";
67         } else {
68                 _D("DEFAULT");
69                 config_file = "config-azim-thr-dir-elev.ini";
70         }
71
72         config_init(config_file);
73         steering_setup();
74 }
75
76 static void
77 app_pause(void *data)
78 {
79         model_car_connection_set_paused(true);
80 }
81
82 static void
83 app_resume(void *data)
84 {
85         model_car_connection_set_paused(false);
86 }
87
88 static void
89 app_terminate(void *data)
90 {
91         net_util_fini();
92         /* Release all resources. */
93 }
94
95 static void
96 ui_app_lang_changed(app_event_info_h event_info, void *user_data)
97 {
98         /*APP_EVENT_LANGUAGE_CHANGED*/
99
100         int ret;
101         char *language;
102
103         ret = app_event_get_language(event_info, &language);
104         if (ret != APP_ERROR_NONE) {
105                 dlog_print(DLOG_ERROR, LOG_TAG, "app_event_get_language() failed. Err = %d.", ret);
106                 return;
107         }
108
109         if (language != NULL) {
110                 elm_language_set(language);
111                 free(language);
112         }
113 }
114
115 static void
116 ui_app_orient_changed(app_event_info_h event_info, void *user_data)
117 {
118         /*APP_EVENT_DEVICE_ORIENTATION_CHANGED*/
119         return;
120 }
121
122 static void
123 ui_app_region_changed(app_event_info_h event_info, void *user_data)
124 {
125         /*APP_EVENT_REGION_FORMAT_CHANGED*/
126 }
127
128 static void
129 ui_app_low_battery(app_event_info_h event_info, void *user_data)
130 {
131         /*APP_EVENT_LOW_BATTERY*/
132 }
133
134 static void
135 ui_app_low_memory(app_event_info_h event_info, void *user_data)
136 {
137         /*APP_EVENT_LOW_MEMORY*/
138 }
139
140 int
141 main(int argc, char *argv[])
142 {
143         int ret = 0;
144
145         ui_app_lifecycle_callback_s event_callback = {0,};
146         app_event_handler_h handlers[5] = {NULL, };
147
148         event_callback.create = app_create;
149         event_callback.terminate = app_terminate;
150         event_callback.pause = app_pause;
151         event_callback.resume = app_resume;
152         event_callback.app_control = app_control;
153
154         ui_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, ui_app_low_battery, NULL);
155         ui_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, ui_app_low_memory, NULL);
156         ui_app_add_event_handler(&handlers[APP_EVENT_DEVICE_ORIENTATION_CHANGED], APP_EVENT_DEVICE_ORIENTATION_CHANGED, ui_app_orient_changed, NULL);
157         ui_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, ui_app_lang_changed, NULL);
158         ui_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, ui_app_region_changed, NULL);
159
160         ret = ui_app_main(argc, argv, &event_callback, NULL);
161         if (ret != APP_ERROR_NONE) {
162                 dlog_print(DLOG_ERROR, LOG_TAG, "ui_app_main() is failed. err = %d", ret);
163         }
164
165         return ret;
166 }