summaryrefslogtreecommitdiff
path: root/src/ug.c
blob: 2f0c5a6f787905e608f5ffdbcf5f760198f8f9de (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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
/*
 *  UI Gadget
 *
 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
 *
 * Contact: Jayoun Lee <airjany@samsung.com>
 *
 * 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 <stdlib.h>
#include <string.h>
#include <errno.h>
#include <stdio.h>

#include "ug.h"
#include "ug-module.h"
#include "ug-manager.h"
#include "ug-dbg.h"

#ifndef UG_API
#define UG_API __attribute__ ((visibility("default")))
#endif

ui_gadget_h ug_root_create(void)
{
	ui_gadget_h ug;

	ug = calloc(1, sizeof(struct ui_gadget_s));
	if (!ug) {
		_ERR("ug root create failed: Memory allocation failed");
		return NULL;
	}

	ug->mode = UG_MODE_FULLVIEW;
	ug->state = UG_STATE_RUNNING;
	ug->children = NULL;

	return ug;
}

int ug_free(ui_gadget_h ug)
{
	if (!ug) {
		_ERR("ug free failed: Invalid ug");
		errno = EINVAL;
		return -1;
	}

	if (ug->module)
		ug_module_unload(ug->module);
	if (ug->name) {
		free((void *)ug->name);
		ug->name = NULL;
	}
	if (ug->app_control) {
		app_control_destroy(ug->app_control);
		ug->app_control = NULL;
	}
	free(ug);
	ug = NULL;
	return 0;
}

UG_API ui_gadget_h ug_create(ui_gadget_h parent,
				   const char *name,
				   enum ug_mode mode,
				   app_control_h app_control, struct ug_cbs *cbs)
{
	if (!name) {
		_ERR("ug_create() failed: Invalid name");
		errno = EINVAL;
		return NULL;
	}

	if (mode < UG_MODE_FULLVIEW || mode >= UG_MODE_INVALID) {
		_ERR("ug_create() failed: Invalid mode");
		errno = EINVAL;
		return NULL;
	}

	return ugman_ug_load(parent, name, mode, app_control, cbs);
}

#ifndef UG_WAYLAND
UG_API int ug_init(Display *disp, Window xid, void *win, enum ug_option opt)
{
	if (!win || !xid || !disp) {
		_ERR("ug_init() failed: Invalid arguments");
		return -1;
	}

	if (opt < UG_OPT_INDICATOR_ENABLE || opt >= UG_OPT_MAX) {
		_ERR("ug_init() failed: Invalid option");
		return -1;
	}

	return ugman_init(disp, xid, win, opt);
}
#else
UG_API int ug_init(void *win, enum ug_option opt)
{
	if (opt < UG_OPT_INDICATOR_ENABLE || opt >= UG_OPT_MAX) {
		_ERR("ug_init() failed: Invalid option");
		return -1;
	}

	return ugman_init(win, opt);
}
#endif

UG_API int ug_init_efl(Evas_Object *win, enum ug_option opt)
{
	if (!win) {
		_ERR("ug_init_efl() failed: Invalid arguments");
		return -1;
	}

	if (opt < UG_OPT_INDICATOR_ENABLE || opt >= UG_OPT_MAX) {
		_ERR("ug_init_efl() failed: Invalid option");
		return -1;
	}

	return ugman_init_efl(win, opt);
}

UG_API int ug_pause(void)
{
	return ugman_pause();
}

UG_API int ug_pause_ug(ui_gadget_h ug)
{
	if (!ug || !ugman_ug_exist(ug)) {
		_ERR("ug_pause_ug() failed: Invalid ug");
		errno = EINVAL;
		return -1;
	}

	return ugman_pause_ug(ug);
}

UG_API int ug_resume(void)
{
	return ugman_resume();
}

UG_API int ug_resume_ug(ui_gadget_h ug)
{
	if (!ug || !ugman_ug_exist(ug)) {
		_ERR("ug_resume_ug() failed: Invalid ug");
		errno = EINVAL;
		return -1;
	}

	return ugman_resume_ug(ug);
}

UG_API int ug_destroy(ui_gadget_h ug)
{
	return ugman_ug_del(ug);
}

UG_API int ug_destroy_all(void)
{
	return ugman_ug_del_all();
}

UG_API int ug_destroy_me(ui_gadget_h ug)
{
	if (!ug || !ugman_ug_exist(ug)) {
		_ERR("ug_destroy_me() failed: Invalid ug");
		errno = EINVAL;
		return -1;
	}

	if (ug->state == UG_STATE_DESTROYING) {
		_ERR("ug_destory_me() failed:ug(%p) is already on destroying", ug);
		return -1;
	}

	if (!ug->cbs.destroy_cb) {
		_ERR("ug_destroy_me() failed: destroy callback does not "
			"exist");
		return -1;
	}

	ug->cbs.destroy_cb(ug, ug->cbs.priv);
	return 0;
}

UG_API void *ug_get_layout(ui_gadget_h ug)
{
	if (!ug || !ugman_ug_exist(ug)) {
		_ERR("ug_get_layout() failed: Invalid ug");
		errno = EINVAL;
		return NULL;
	}
	return ug->layout;
}

UG_API void *ug_get_parent_layout(ui_gadget_h ug)
{
	ui_gadget_h parent;
	if (!ug || !ugman_ug_exist(ug)) {
		_ERR("ug_get_parent_layout() failed: Invalid ug");
		errno = EINVAL;
		return NULL;
	}

	parent = ug->parent;

	if (parent)
		return parent->layout;
	return NULL;
}

UG_API enum ug_mode ug_get_mode(ui_gadget_h ug)
{
	if (!ug || !ugman_ug_exist(ug)) {
		_ERR("ug_get_mode() failed: Invalid ug");
		errno = EINVAL;
		return UG_MODE_INVALID;
	}

	return ug->mode;
}

UG_API void *ug_get_window(void)
{
	return ugman_get_window();
}

UG_API void *ug_get_conformant(void)
{
	return ugman_get_conformant();
}

UG_API int ug_send_event(enum ug_event event)
{
	if (event <= UG_EVENT_NONE || event >= UG_EVENT_MAX) {
		_ERR("ug_send_event() failed: Invalid event");
		return -1;
	}

	return ugman_send_event(event);
}

UG_API int ug_send_key_event(enum ug_key_event event)
{
	if (event <= UG_KEY_EVENT_NONE || event >= UG_KEY_EVENT_MAX) {
		_ERR("ug_send_key_event() failed: Invalid event");
		return -1;
	}

	return ugman_send_key_event(event);
}

UG_API int ug_send_result(ui_gadget_h ug, app_control_h send)
{
	app_control_h send_dup = NULL;

	if (!ug || !ugman_ug_exist(ug)) {
		_ERR("ug_send_result() failed: Invalid ug");
		errno = EINVAL;
		return -1;
	}

	if (!ug->cbs.result_cb) {
		_ERR("ug_send_result() failed: result callback does not exist");
		return -1;
	}

	if (send) {
		app_control_clone(&send_dup, send);
		if (!send_dup) {
			_ERR("ug_send_result() failed: app_control_destroy failed");
			return -1;
		}
	}

	ug->cbs.result_cb(ug, send_dup, ug->cbs.priv);

	if (send_dup)
		app_control_destroy(send_dup);

	return 0;
}

UG_API int ug_send_result_full(ui_gadget_h ug, app_control_h send, app_control_result_e result)
{
	app_control_h send_dup = NULL;
	char tmp_result[4] = {0,};

	if (!ug || !ugman_ug_exist(ug)) {
		_ERR("ug_send_result() failed: Invalid ug");
		errno = EINVAL;
		return -1;
	}

	if (!ug->cbs.result_cb) {
		_ERR("ug_send_result() failed: result callback does not exist");
		return -1;
	}

	if (send) {
		app_control_clone(&send_dup, send);
		if (!send_dup) {
			_ERR("ug_send_result() failed: app_control_destroy failed");
			return -1;
		}
	}

	snprintf(tmp_result, 4, "%d", result);

	app_control_add_extra_data(send_dup, UG_SERVICE_DATA_RESULT, (const char*)tmp_result);

	ug->cbs.result_cb(ug, send_dup, ug->cbs.priv);

	if (send_dup)
		app_control_destroy(send_dup);

	return 0;
}

UG_API int ug_send_message(ui_gadget_h ug, app_control_h msg)
{
	int r;

	app_control_h msg_dup = NULL;
	if (msg) {
		app_control_clone(&msg_dup, msg);
		if (!msg_dup) {
			_ERR("ug_send_message() failed: app_control_destroy failed");
			return -1;
		}
	}

	r = ugman_send_message(ug, msg_dup);

	if (msg_dup)
		app_control_destroy(msg_dup);

	return r;
}

UG_API int ug_disable_effect(ui_gadget_h ug)
{
	if (!ug) {
		_ERR("ug input param is null");
		return -1;
	}
	if (ug->layout_state != UG_LAYOUT_INIT) {
		_ERR("ug_disable_effect() failed: ug has already been shown");
		return -1;
	}
	ug->layout_state = UG_LAYOUT_NOEFFECT;

	return 0;
}

UG_API int ug_is_installed(const char *name)
{
	if (name == NULL) {
		_ERR("name is null");
		return -1;
	}

	return ug_exist(name);
}

#ifdef ENABLE_UG_CREATE_CB
UG_API int ug_create_cb(void (*create_cb)(char *, char *, char *, void *), void *user_data)
{
	int ret;

	ret = ugman_create_cb(create_cb, user_data);
	if (ret == -1)
		_ERR("trace cb register fail");

	return ret;
}
#endif