summaryrefslogtreecommitdiff
path: root/src/controller/controller_car_selection.c
blob: c399da7d82395f983d29431f30d9aa29141fc3b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
* 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 "model/model_cloud_connection.h"
#include "model/model_car_connection.h"
#include "controller/controller_car_selection.h"
#include "view_manager/view_manager.h"

static s_controller s_info = { 0, };

void controller_car_selection_destroy(void)
{
	model_car_connection_unsubscirbe_event();
	model_cloud_connection_unsubscirbe_event();
}

static void _car_connected_cb(s_model_car_connection_cb_data *model_data)
{
	switch (model_data->type) {
		case MODEL_TYPE_END:
			view_manager_set_view(VIEW_CONNECTION_SUCCESSED);
			break;
		case MODEL_TYPE_FAIL:
			view_manager_set_view(VIEW_NETWORK_FAILURE);
			break;
		case MODEL_TYPE_WAIT:
			view_manager_show_popup(VIEW_POPUP_PROGRESS);
			break;
		default:
			break;
	}
}

static void _cloud_connection_cb(s_model_cloud_connection_cb_data *model_data)
{
	s_info.view_update_cb(model_data->name);
}

void controller_car_selection_init(t_view_update_cb view_update_cb)
{
	s_info.view_update_cb = view_update_cb;

	model_cloud_connection_subscribe_event(_cloud_connection_cb);
	model_car_connection_subscribe_event(_car_connected_cb);
}

void controller_car_selection_back(void)
{
	controller_car_selection_destroy();
}

void controller_car_selection_next()
{
	model_car_connection_model_state_change();
}

void controller_get_car_names()
{
	model_cloud_connection_get_names();
}