diff options
author | Michal Skorupinski <m.skorupinsk@samsung.com> | 2018-07-04 14:36:53 +0200 |
---|---|---|
committer | Michal Skorupinski <m.skorupinsk@samsung.com> | 2018-07-12 12:43:27 +0200 |
commit | e07813531cd5ff389b35f66a4be39d48bee043b3 (patch) | |
tree | 77af9d7f23e46f2eaa55f306bbebb42f248508c0 | |
parent | 500b0da3480afb2afd359ebc2fef474a4d93f450 (diff) | |
download | gear-racing-controller-e07813531cd5ff389b35f66a4be39d48bee043b3.tar.gz gear-racing-controller-e07813531cd5ff389b35f66a4be39d48bee043b3.tar.bz2 gear-racing-controller-e07813531cd5ff389b35f66a4be39d48bee043b3.zip |
Connection model added.
Change-Id: I29b30d583e9b99a2188310fe6850a00523630079
Signed-off-by: Michal Skorupinski <m.skorupinsk@samsung.com>
-rw-r--r-- | inc/model/model_base.h | 27 | ||||
-rw-r--r-- | inc/model/model_connection.h | 29 | ||||
-rw-r--r-- | src/controller/controller_car_selection.c | 20 | ||||
-rw-r--r-- | src/controller/controller_connect_to_car.c | 23 | ||||
-rw-r--r-- | src/model/model_connection.c | 40 |
5 files changed, 125 insertions, 14 deletions
diff --git a/inc/model/model_base.h b/inc/model/model_base.h new file mode 100644 index 0000000..a7f27c5 --- /dev/null +++ b/inc/model/model_base.h @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2018 Samsung Electronics Co., Ltd. +* +* Licensed under the Flora License, Version 1.1 (the License); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://floralicense.org/license/ +* +* 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 MODEL_MODEL_BASE_H_ +#define MODEL_MODEL_BASE_H_ + +typedef void (*t_model_update_cb)(void *data); + +typedef struct _s_model { + t_model_update_cb view_update_cb; +} s_model; + +#endif /* MODEL_MODEL_BASE_H_ */ diff --git a/inc/model/model_connection.h b/inc/model/model_connection.h new file mode 100644 index 0000000..347ded8 --- /dev/null +++ b/inc/model/model_connection.h @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2018 Samsung Electronics Co., Ltd. +* +* Licensed under the Flora License, Version 1.1 (the License); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://floralicense.org/license/ +* +* 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 MODEL_MODEL_CONNECTION_H_ +#define MODEL_MODEL_CONNECTION_H_ + +#include "model/model_base.h" + +typedef void (*t_model_update_cb)(void *data); + +void model_connection_init(void); +void model_connection_subscribe_event(t_model_update_cb model_update_cb); +void model_connection_connect(void); + +#endif /* MODEL_MODEL_CONNECTION_H_ */ diff --git a/src/controller/controller_car_selection.c b/src/controller/controller_car_selection.c index 5583704..58aa987 100644 --- a/src/controller/controller_car_selection.c +++ b/src/controller/controller_car_selection.c @@ -14,20 +14,29 @@ * limitations under the License. */ +#include "model/model_connection.h" #include "controller/controller_car_selection.h" #include "view_manager/view_manager.h" static s_controller *controller = NULL; +static void controller_car_selection_destroy(void) +{ + free(controller); +} + +static void _connected_cb(void *is_connected) +{ + view_manager_set_view(VIEW_CONNECT_TO_CAR); + controller_car_selection_destroy(); +} + void controller_car_selection_init(t_view_update_cb view_update_cb) { controller = calloc(1, sizeof(s_controller)); controller->view_update_cb = view_update_cb; -} -void controller_car_selection_destroy(void) -{ - free(controller); + model_connection_subscribe_event(_connected_cb); } void controller_car_selection_back_btn(void) @@ -37,6 +46,5 @@ void controller_car_selection_back_btn(void) void controller_car_selection_next_page() { - view_manager_set_view(VIEW_CAR_SELECTION); - controller_car_selection_destroy(); + model_connection_connect(); } diff --git a/src/controller/controller_connect_to_car.c b/src/controller/controller_connect_to_car.c index 1799389..11b3f0c 100644 --- a/src/controller/controller_connect_to_car.c +++ b/src/controller/controller_connect_to_car.c @@ -14,14 +14,26 @@ * limitations under the License. */ -#include <controller/controller_base.h> #include <assert.h> +#include <controller/controller_base.h> +#include "model/model_connection.h" #include "gear-racing-controller.h" #include "controller/controller_connect_to_car.h" #include "view_manager/view_manager.h" static s_controller *controller = NULL; +static void controller_connect_to_car_destroy(void) +{ + free(controller); +} + +static void _connected_cb(void *is_connected) +{ + view_manager_set_view(VIEW_CAR_SELECTION); + controller_connect_to_car_destroy(); +} + void controller_connect_to_car_init(t_view_update_cb view_update_cb) { controller = calloc(1, sizeof(s_controller)); @@ -30,11 +42,8 @@ void controller_connect_to_car_init(t_view_update_cb view_update_cb) } controller->view_update_cb = view_update_cb; -} -void controller_connect_to_car_destroy(void) -{ - free(controller); + model_connection_subscribe_event(_connected_cb); } void controller_connect_to_car_back_btn(void) { @@ -44,7 +53,5 @@ void controller_connect_to_car_back_btn(void) void controller_connect_to_car_next_page() { - //TODO model - view_manager_set_view(VIEW_CAR_SELECTION); - controller_connect_to_car_destroy(); + model_connection_connect(); } diff --git a/src/model/model_connection.c b/src/model/model_connection.c new file mode 100644 index 0000000..0856400 --- /dev/null +++ b/src/model/model_connection.c @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2018 Samsung Electronics Co., Ltd. +* +* Licensed under the Flora License, Version 1.1 (the License); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://floralicense.org/license/ +* +* 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 "gear-racing-controller.h" +#include "model/model_connection.h" + +typedef struct _s_model_connection { + t_model_update_cb model_update_cb; +} s_model_connection; + +s_model_connection model_connection = { 0, }; + +void model_connection_init(void) +{ + //TODO init stuff +} + +void model_connection_subscribe_event(t_model_update_cb model_update_cb) +{ + model_connection.model_update_cb = model_update_cb; +} + +void model_connection_connect(void) +{ + model_connection.model_update_cb((void *)true); +} + |