summaryrefslogtreecommitdiff
path: root/src/app_main_legacy.c
blob: daf6a58e24ee58fce4e3b8410d1ddd69e1db9dd7 (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/*
 * Copyright (c) 2011 - 2016 Samsung Electronics Co., Ltd All Rights Reserved
 *
 * 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 <stdio.h>
#include <stdlib.h>
#include <dlog.h>

#include <app_internal.h>
#include <tizen_error.h>

#include <app.h>
#include "app_extension.h"

#ifdef LOG_TAG
#undef LOG_TAG
#endif

#define LOG_TAG "CAPI_APPFW_APPLICATION"

typedef struct {
	app_event_callback_s *callback;
	void *data;
} app_context_s;

static bool __on_create(void *data)
{
	app_context_s *context = data;

	if (context->callback->create)
		return context->callback->create(context->data);

	return false;
}

static void __on_terminate(void *data)
{
	app_context_s *context = data;

	if (context->callback->terminate)
		context->callback->terminate(context->data);
}

/* LCOV_EXCL_START */
static void __on_pause(void *data)
{
	app_context_s *context = data;

	if (context->callback->pause)
		context->callback->pause(context->data);
}
/* LCOV_EXCL_STOP */

/* LCOV_EXCL_START */
static void __on_resume(void *data)
{
	app_context_s *context = data;

	if (context->callback->resume)
		context->callback->resume(context->data);

}
/* LCOV_EXCL_STOP */

static void __on_app_control(app_control_h app_control, void *data)
{
	app_context_s *context = data;

	if (context->callback->app_control)
		context->callback->app_control(app_control, context->data);
}

static void __on_low_memory(app_event_info_h event_info, void *data)
{
	app_context_s *context = data;

	if (context->callback->low_memory)
		context->callback->low_memory(context->data);
}

static void __on_low_battery(app_event_info_h event_info, void *data)
{
	app_context_s *context = data;

	if (context->callback->low_battery)
		context->callback->low_battery(context->data);
}

/* LCOV_EXCL_START */
static void __on_rotation_event(app_event_info_h event_info, void *data)
{
	app_context_s *context = data;

	if (context->callback->device_orientation) {
		app_device_orientation_e ori;
		app_event_get_device_orientation(event_info, &ori);
		context->callback->device_orientation(ori, context->data);
	}

}
/* LCOV_EXCL_STOP */

static void __on_lang_changed(app_event_info_h event_info, void *data)
{
	app_context_s *context = data;

	if (context->callback->language_changed)
		context->callback->language_changed(context->data);
}

static void __on_region_changed(app_event_info_h event_info, void *data)
{
	app_context_s *context = data;

	if (context->callback->region_format_changed)
		context->callback->region_format_changed(context->data);
}

int app_main(int argc, char **argv, app_event_callback_s *callback, void *data)
{
	ui_app_lifecycle_callback_s cb = {
		.create = __on_create,
		.terminate = __on_terminate,
		.pause = __on_pause,
		.resume = __on_resume,
		.app_control = __on_app_control
	};

	app_context_s app_context = {
		.callback = callback,
		.data = data
	};

	app_event_handler_h handler;

	if (!callback)
		return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);

	if (callback->low_memory)
		ui_app_add_event_handler(&handler, APP_EVENT_LOW_MEMORY, __on_low_memory, &app_context);
	if (callback->low_battery)
		ui_app_add_event_handler(&handler, APP_EVENT_LOW_BATTERY, __on_low_battery, &app_context);
	if (callback->language_changed)
		ui_app_add_event_handler(&handler, APP_EVENT_LANGUAGE_CHANGED, __on_lang_changed, &app_context);
	if (callback->device_orientation)
		ui_app_add_event_handler(&handler, APP_EVENT_DEVICE_ORIENTATION_CHANGED, __on_rotation_event, &app_context);
	if (callback->region_format_changed)
		ui_app_add_event_handler(&handler, APP_EVENT_REGION_FORMAT_CHANGED, __on_region_changed, &app_context);

	return ui_app_main(argc, argv, &cb, &app_context);
}

int app_efl_main(int *argc, char ***argv, app_event_callback_s *callback, void *user_data)
{
	return app_main(*argc, *argv, callback, user_data);
}

void app_exit(void)
{
	ui_app_exit();
}

void app_efl_exit(void)
{
	ui_app_exit();
}