2 * Copyright (c) 2013, TOYOTA MOTOR CORPORATION.
4 * This program is licensed under the terms and conditions of the
5 * Apache License, version 2.0. The full text of the Apache License is at
6 * http://www.apache.org/licenses/LICENSE-2.0
10 * @brief Window Control API
11 * for privilege applications
18 #include "ico_syc_msg_cmd_def.h"
19 #include "ico_syc_msg.h"
20 #include "ico_syc_private.h"
21 #include "ico_syc_privilege.h"
23 /*============================================================================*/
25 /*============================================================================*/
26 #define _CMD_SHOW_WIN 0
27 #define _CMD_HIDE_WIN 1
28 #define _CMD_SHOW_LAYER 10
29 #define _CMD_HIDE_LAYER 11
30 #define _CMD_SET_LAYER_ATTR 12
32 /*============================================================================*/
33 /* define static function prototype */
34 /*============================================================================*/
35 static msg_t _create_win_msg(const char *appid, int surface,
36 const ico_syc_animation_t *animation,
38 static msg_t _create_win_move_msg(const char *appid, int surface,
39 const ico_syc_win_move_t *move,
40 const ico_syc_animation_t *animation);
41 static msg_t _create_win_animation_msg(const char *appid, int surface,
42 int type, const char *animation, int time);
43 static msg_t _create_active_win_msg(const char *appid, int surface);
44 static msg_t _create_change_layer_msg(const char *appid, int surface, int layer);
45 static msg_t _create_map_get_msg(const char *appid, int surface, const char *filepath);
46 static msg_t _create_map_thumb_msg(const char *appid, int surface, int framerate,
47 const char *filepath);
48 static msg_t _create_unmap_thumb_msg(const char *appid, int surface);
49 static msg_t _create_layer_msg(const char *appid, int layer, int type);
51 /*============================================================================*/
53 /*============================================================================*/
54 /*--------------------------------------------------------------------------*/
56 * @brief _create_win_msg
57 * Create the message to show/hide the application window.
59 * @param[in] appid application id
60 * @param[in] surface window's surface id
61 * @param[in] animation animation information
62 * @param[in] type type of command
63 * @return json generator
64 * @retval json generator success
67 /*--------------------------------------------------------------------------*/
69 _create_win_msg(const char *appid, int surface,
70 const ico_syc_animation_t *animation, int type)
72 JsonObject *obj = NULL;
73 JsonObject *argobj = NULL;
74 JsonGenerator *gen = NULL;
75 JsonNode *root = NULL;
78 /* create json object */
79 obj = json_object_new();
80 argobj = json_object_new();
81 if (obj == NULL || argobj == NULL) {
82 _ERR("json_object_new failed");
87 if (type == _CMD_SHOW_WIN) {
90 else if (type == _CMD_HIDE_WIN) {
95 json_object_set_int_member(obj, MSG_PRMKEY_CMD, cmd);
96 json_object_set_string_member(obj, MSG_PRMKEY_APPID, appid);
97 json_object_set_int_member(obj, MSG_PRMKEY_PID, getpid());
99 json_object_set_int_member(argobj, MSG_PRMKEY_SURFACE, surface);
100 /* set animation info */
101 if (animation != NULL) {
102 json_object_set_string_member(argobj, MSG_PRMKEY_ANIM_NAME,
104 json_object_set_int_member(argobj, MSG_PRMKEY_ANIM_TIME,
107 json_object_set_object_member(obj, MSG_PRMKEY_ARG, argobj);
109 /* create root object */
110 root = json_node_new(JSON_NODE_OBJECT);
111 json_node_take_object(root, obj);
113 /* create generator object */
114 gen = json_generator_new();
115 json_generator_set_root(gen, root);
120 /*--------------------------------------------------------------------------*/
122 * @brief _create_win_move_msg
123 * Create the message to move the application window.
125 * @param[in] appid application id
126 * @param[in] surface window's surface id
127 * @param[in] move move information (zone/position/size)
128 * @param[in] animation animation information
129 * @return json generator
130 * @retval json generator success
133 /*--------------------------------------------------------------------------*/
135 _create_win_move_msg(const char *appid, int surface,
136 const ico_syc_win_move_t *move,
137 const ico_syc_animation_t *animation)
139 JsonObject *obj = NULL;
140 JsonObject *argobj = NULL;
141 JsonGenerator *gen = NULL;
142 JsonNode *root = NULL;
144 /* create json object */
145 obj = json_object_new();
146 argobj = json_object_new();
147 if (obj == NULL || argobj == NULL) {
148 _ERR("json_object_new failed");
153 json_object_set_int_member(obj, MSG_PRMKEY_CMD, MSG_CMD_MOVE);
154 json_object_set_string_member(obj, MSG_PRMKEY_APPID, appid);
155 json_object_set_int_member(obj, MSG_PRMKEY_PID, getpid());
157 json_object_set_int_member(argobj, MSG_PRMKEY_SURFACE, surface);
159 if (move->zone != NULL) {
160 json_object_set_string_member(argobj, MSG_PRMKEY_ZONE, move->zone);
161 json_object_set_int_member(argobj, MSG_PRMKEY_LAYER, move->layer);
164 json_object_set_int_member(argobj, MSG_PRMKEY_POS_X, move->pos_x);
165 json_object_set_int_member(argobj, MSG_PRMKEY_POS_Y, move->pos_y);
166 json_object_set_int_member(argobj, MSG_PRMKEY_LAYER, -1);
168 json_object_set_int_member(argobj, MSG_PRMKEY_WIDTH, move->width);
169 json_object_set_int_member(argobj, MSG_PRMKEY_HEIGHT, move->height);
170 /* set animation info */
171 if (animation != NULL) {
172 json_object_set_string_member(argobj, MSG_PRMKEY_ANIM_NAME,
174 json_object_set_int_member(argobj, MSG_PRMKEY_ANIM_TIME,
177 json_object_set_object_member(obj, MSG_PRMKEY_ARG, argobj);
179 /* create root object */
180 root = json_node_new(JSON_NODE_OBJECT);
181 json_node_take_object(root, obj);
183 /* create generator object */
184 gen = json_generator_new();
185 json_generator_set_root(gen, root);
190 /*--------------------------------------------------------------------------*/
192 * @brief _create_win_animation_msg
193 * Create the message to set animation the application window.
195 * @param[in] appid application id
196 * @param[in] surface window's surface id
197 * @param[in] type set animation target
198 * @param[in] animation animation information
199 * @param[in] time animation time
200 * @return json generator
201 * @retval json generator success
204 /*--------------------------------------------------------------------------*/
206 _create_win_animation_msg(const char *appid, int surface,
207 int type, const char *animation, int time)
209 JsonObject *obj = NULL;
210 JsonObject *argobj = NULL;
211 JsonGenerator *gen = NULL;
212 JsonNode *root = NULL;
214 /* create json object */
215 obj = json_object_new();
216 argobj = json_object_new();
217 if (obj == NULL || argobj == NULL) {
218 _ERR("json_object_new failed");
223 json_object_set_int_member(obj, MSG_PRMKEY_CMD, MSG_CMD_ANIMATION);
224 json_object_set_string_member(obj, MSG_PRMKEY_APPID, appid);
225 json_object_set_int_member(obj, MSG_PRMKEY_PID, getpid());
227 json_object_set_int_member(argobj, MSG_PRMKEY_SURFACE, surface);
228 json_object_set_int_member(argobj, MSG_PRMKEY_ANIM_TYPE, type);
229 json_object_set_string_member(argobj, MSG_PRMKEY_ANIM_NAME, animation);
230 json_object_set_int_member(argobj, MSG_PRMKEY_ANIM_TIME, time);
232 json_object_set_object_member(obj, MSG_PRMKEY_ARG, argobj);
234 /* create root object */
235 root = json_node_new(JSON_NODE_OBJECT);
236 json_node_take_object(root, obj);
238 /* create generator object */
239 gen = json_generator_new();
240 json_generator_set_root(gen, root);
245 /*--------------------------------------------------------------------------*/
247 * @brief _create_active_win_msg
248 * Create the message to change active window.
250 * @param[in] appid application id
251 * @param[in] surface window's surface id
252 * @return json generator
253 * @retval json generator success
256 /*--------------------------------------------------------------------------*/
258 _create_active_win_msg(const char *appid, int surface)
260 JsonObject *obj = NULL;
261 JsonObject *argobj = NULL;
262 JsonGenerator *gen = NULL;
263 JsonNode *root = NULL;
265 /* create json object */
266 obj = json_object_new();
267 argobj = json_object_new();
268 if (obj == NULL || argobj == NULL) {
269 _ERR("json_object_new failed");
274 json_object_set_int_member(obj, MSG_PRMKEY_CMD, MSG_CMD_CHANGE_ACTIVE);
275 json_object_set_string_member(obj, MSG_PRMKEY_APPID, appid);
276 json_object_set_int_member(obj, MSG_PRMKEY_PID, getpid());
278 json_object_set_int_member(argobj, MSG_PRMKEY_SURFACE, surface);
279 json_object_set_object_member(obj, MSG_PRMKEY_ARG, argobj);
281 /* create root object */
282 root = json_node_new(JSON_NODE_OBJECT);
283 json_node_take_object(root, obj);
285 /* create generator object */
286 gen = json_generator_new();
287 json_generator_set_root(gen, root);
292 /*--------------------------------------------------------------------------*/
294 * @brief _create_change_layer_msg
295 * Create the message to change application window's layer.
297 * @param[in] appid application id
298 * @param[in] surface window's surface id
299 * @param[in] layer window's layer id
300 * @return json generator
301 * @retval json generator success
304 /*--------------------------------------------------------------------------*/
306 _create_change_layer_msg(const char *appid, int surface, int layer)
308 JsonObject *obj = NULL;
309 JsonObject *argobj = NULL;
310 JsonGenerator *gen = NULL;
311 JsonNode *root = NULL;
313 /* create json object */
314 obj = json_object_new();
315 argobj = json_object_new();
316 if (obj == NULL || argobj == NULL) {
317 _ERR("json_object_new failed");
322 json_object_set_int_member(obj, MSG_PRMKEY_CMD, MSG_CMD_CHANGE_LAYER);
323 json_object_set_string_member(obj, MSG_PRMKEY_APPID, appid);
324 json_object_set_int_member(obj, MSG_PRMKEY_PID, getpid());
326 json_object_set_int_member(argobj, MSG_PRMKEY_SURFACE, surface);
327 json_object_set_int_member(argobj, MSG_PRMKEY_LAYER, layer);
328 json_object_set_object_member(obj, MSG_PRMKEY_ARG, argobj);
330 /* create root object */
331 root = json_node_new(JSON_NODE_OBJECT);
332 json_node_take_object(root, obj);
334 /* create generator object */
335 gen = json_generator_new();
336 json_generator_set_root(gen, root);
341 /*--------------------------------------------------------------------------*/
343 * @brief _create_map_get_msg
344 * Create the message to map get.
346 * @param[in] appid application id
347 * @param[in] surface window's surface id
348 * @param[in] filepath pixel image file path
349 * @return json generator
350 * @retval json generator success
353 /*--------------------------------------------------------------------------*/
355 _create_map_get_msg(const char *appid, int surface, const char *filepath)
357 JsonObject *obj = NULL;
358 JsonObject *argobj = NULL;
359 JsonGenerator *gen = NULL;
360 JsonNode *root = NULL;
362 /* create json object */
363 obj = json_object_new();
364 argobj = json_object_new();
365 if (obj == NULL || argobj == NULL) {
366 _ERR("json_object_new failed");
371 json_object_set_int_member(obj, MSG_PRMKEY_CMD, MSG_CMD_MAP_GET);
372 json_object_set_string_member(obj, MSG_PRMKEY_APPID, appid);
373 json_object_set_int_member(obj, MSG_PRMKEY_PID, getpid());
375 json_object_set_int_member(argobj, MSG_PRMKEY_SURFACE, surface);
376 json_object_set_string_member(argobj, MSG_PRMKEY_ANIM_NAME, filepath);
377 json_object_set_object_member(obj, MSG_PRMKEY_ARG, argobj);
379 /* create root object */
380 root = json_node_new(JSON_NODE_OBJECT);
381 json_node_take_object(root, obj);
383 /* create generator object */
384 gen = json_generator_new();
385 json_generator_set_root(gen, root);
390 /*--------------------------------------------------------------------------*/
392 * @brief _create_map_thumb_msg
393 * Create the message to map thumbnail.
395 * @param[in] appid application id
396 * @param[in] surface window's surface id
397 * @param[in] framerate notify cycle [frames par sec]
398 * @param[in] filepath pixel image file path
399 * @return json generator
400 * @retval json generator success
403 /*--------------------------------------------------------------------------*/
405 _create_map_thumb_msg(const char *appid, int surface, int framerate, const char *filepath)
407 JsonObject *obj = NULL;
408 JsonObject *argobj = NULL;
409 JsonGenerator *gen = NULL;
410 JsonNode *root = NULL;
412 /* create json object */
413 obj = json_object_new();
414 argobj = json_object_new();
415 if (obj == NULL || argobj == NULL) {
416 _ERR("json_object_new failed");
421 json_object_set_int_member(obj, MSG_PRMKEY_CMD, MSG_CMD_MAP_THUMB);
422 json_object_set_string_member(obj, MSG_PRMKEY_APPID, appid);
423 json_object_set_int_member(obj, MSG_PRMKEY_PID, getpid());
425 json_object_set_int_member(argobj, MSG_PRMKEY_SURFACE, surface);
426 json_object_set_int_member(argobj, MSG_PRMKEY_RATE, framerate);
427 if ((filepath != NULL) && (*filepath != 0) && (*filepath != ' ')) {
428 json_object_set_string_member(argobj, MSG_PRMKEY_ANIM_NAME, filepath);
431 json_object_set_string_member(argobj, MSG_PRMKEY_ANIM_NAME, " ");
433 json_object_set_object_member(obj, MSG_PRMKEY_ARG, argobj);
435 /* create root object */
436 root = json_node_new(JSON_NODE_OBJECT);
437 json_node_take_object(root, obj);
439 /* create generator object */
440 gen = json_generator_new();
441 json_generator_set_root(gen, root);
446 /*--------------------------------------------------------------------------*/
448 * @brief _create_unmap_thumb_msg
449 * Create the message to unmap thumbnail.
451 * @param[in] appid application id
452 * @param[in] surface window's surface id
453 * @return json generator
454 * @retval json generator success
457 /*--------------------------------------------------------------------------*/
459 _create_unmap_thumb_msg(const char *appid, int surface)
461 JsonObject *obj = NULL;
462 JsonObject *argobj = NULL;
463 JsonGenerator *gen = NULL;
464 JsonNode *root = NULL;
466 /* create json object */
467 obj = json_object_new();
468 argobj = json_object_new();
469 if (obj == NULL || argobj == NULL) {
470 _ERR("json_object_new failed");
475 json_object_set_int_member(obj, MSG_PRMKEY_CMD, MSG_CMD_UNMAP_THUMB);
476 json_object_set_string_member(obj, MSG_PRMKEY_APPID, appid);
477 json_object_set_int_member(obj, MSG_PRMKEY_PID, getpid());
479 json_object_set_int_member(argobj, MSG_PRMKEY_SURFACE, surface);
480 json_object_set_object_member(obj, MSG_PRMKEY_ARG, argobj);
482 /* create root object */
483 root = json_node_new(JSON_NODE_OBJECT);
484 json_node_take_object(root, obj);
486 /* create generator object */
487 gen = json_generator_new();
488 json_generator_set_root(gen, root);
493 /*--------------------------------------------------------------------------*/
495 * @brief _create_layer_msg
496 * Create the message to show/hide layer or to set layer attribute.
498 * @param[in] appid application id
499 * @param[in] layer window's layer id
500 * @param[in] type type of command
501 * @return json generator
502 * @retval json generator success
505 /*--------------------------------------------------------------------------*/
507 _create_layer_msg(const char *appid, int layer, int type)
509 JsonObject *obj = NULL;
510 JsonObject *argobj = NULL;
511 JsonGenerator *gen = NULL;
512 JsonNode *root = NULL;
515 /* create json object */
516 obj = json_object_new();
517 argobj = json_object_new();
518 if (obj == NULL || argobj == NULL) {
519 _ERR("json_object_new failed");
524 if (type == _CMD_SHOW_LAYER) {
525 cmd = MSG_CMD_SHOW_LAYER;
527 else if (type == _CMD_HIDE_LAYER) {
528 cmd = MSG_CMD_HIDE_LAYER;
532 json_object_set_int_member(obj, MSG_PRMKEY_CMD, cmd);
533 json_object_set_string_member(obj, MSG_PRMKEY_APPID, appid);
534 json_object_set_int_member(obj, MSG_PRMKEY_PID, getpid());
536 json_object_set_int_member(argobj, MSG_PRMKEY_LAYER, layer);
537 json_object_set_object_member(obj, MSG_PRMKEY_ARG, argobj);
539 /* create root object */
540 root = json_node_new(JSON_NODE_OBJECT);
541 json_node_take_object(root, obj);
543 /* create generator object */
544 gen = json_generator_new();
545 json_generator_set_root(gen, root);
550 /*============================================================================*/
551 /* internal common function */
552 /*============================================================================*/
553 /*--------------------------------------------------------------------------*/
556 * @brief ico_syc_cb_win
557 * Execute callback function. (ICO_SYC_EV_WIN_ACTIVE
558 * ICO_SYC_EV_WIN_CREATE
559 * ICO_SYC_EV_WIN_DESTROY)
561 * @param[in] callback callback function
562 * @param[in] user_data passed data on called callback function
563 * @param[in] event event code
564 * @param[in] data message data
565 * @param[in] len length of data
568 /*--------------------------------------------------------------------------*/
570 ico_syc_cb_win(ico_syc_callback_t callback, void *user_data,
571 int event, const void *data, size_t len)
573 JsonParser *parser = NULL;
574 GError *error = NULL;
575 gboolean gbool = FALSE;
576 JsonNode *root = NULL;
577 JsonObject *obj = NULL;
578 JsonObject *argobj = NULL;
580 ico_syc_win_info_t *win_info = NULL;
583 win_info = calloc(1, sizeof(ico_syc_win_info_t));
584 if (win_info == NULL) {
585 _ERR("calloc failed");
590 parser = json_parser_new();
591 gbool = json_parser_load_from_data(parser, data, len, &error);
592 if (gbool == FALSE) {
593 g_object_unref(parser);
595 _ERR("json_parser_load_from_data failed");
600 root = json_parser_get_root(parser);
602 g_object_unref(parser);
604 _ERR("json_parser_get_root failed (root is NULL)");
608 /* get object from root */
609 obj = json_node_get_object(root);
611 if (json_object_has_member(obj, MSG_PRMKEY_ARG) == FALSE) {
612 g_object_unref(parser);
614 _ERR("invalid message" );
617 /* get object from obj */
618 argobj = json_object_get_object_member(obj, MSG_PRMKEY_ARG);
621 win_info->appid = strdup(ico_syc_get_str_member(obj, MSG_PRMKEY_APPID));
622 win_info->name = strdup(ico_syc_get_str_member(argobj, MSG_PRMKEY_WINNAME));
623 win_info->surface = ico_syc_get_int_member(argobj, MSG_PRMKEY_SURFACE);
626 callback(event, win_info, user_data);
629 g_object_unref(parser);
630 if (win_info->appid != NULL) free(win_info->appid);
631 if (win_info->name != NULL) free(win_info->name);
637 /*--------------------------------------------------------------------------*/
640 * @brief ico_syc_cb_win_attr
641 * Execute callback function. (ICO_SYC_EV_WIN_ATTR_CHANGE)
643 * @param[in] callback callback function
644 * @param[in] user_data :assed data on called callback function
645 * @param[in] event event code
646 * @param[in] data message data
647 * @param[in] len length of data
650 /*--------------------------------------------------------------------------*/
652 ico_syc_cb_win_attr(ico_syc_callback_t callback, void *user_data,
653 int event, const void *data, size_t len)
655 JsonParser *parser = NULL;
656 GError *error = NULL;
657 gboolean gbool = FALSE;
658 JsonNode *root = NULL;
659 JsonObject *obj = NULL;
660 JsonObject *argobj = NULL;
662 ico_syc_win_attr_t *win_attr = NULL;
665 win_attr = calloc(1, sizeof(ico_syc_win_attr_t));
666 if (win_attr == NULL) {
667 _ERR("calloc failed");
672 parser = json_parser_new();
673 gbool = json_parser_load_from_data(parser, data, len, &error);
674 if (gbool == FALSE) {
675 g_object_unref(parser);
677 _ERR("json_parser_load_from_data failed");
682 root = json_parser_get_root(parser);
684 g_object_unref(parser);
686 _ERR("json_parser_get_root failed (root is NULL)");
690 /* get object from root */
691 obj = json_node_get_object(root);
693 if (json_object_has_member(obj, MSG_PRMKEY_ARG) == FALSE) {
694 g_object_unref(parser);
696 _ERR("invalid message" );
699 /* get object from obj */
700 argobj = json_object_get_object_member(obj, MSG_PRMKEY_ARG);
703 win_attr->appid = strdup(ico_syc_get_str_member(obj, MSG_PRMKEY_APPID));
704 win_attr->name = strdup(ico_syc_get_str_member(argobj, MSG_PRMKEY_WINNAME));
705 win_attr->zone = strdup(ico_syc_get_str_member(argobj, MSG_PRMKEY_ZONE));
706 win_attr->surface = ico_syc_get_int_member(argobj, MSG_PRMKEY_SURFACE);
707 win_attr->nodeid = ico_syc_get_int_member(argobj, MSG_PRMKEY_NODE);
708 win_attr->layer = ico_syc_get_int_member(argobj, MSG_PRMKEY_LAYER);
709 win_attr->pos_x = ico_syc_get_int_member(argobj, MSG_PRMKEY_POS_X);
710 win_attr->pos_y = ico_syc_get_int_member(argobj, MSG_PRMKEY_POS_Y);
711 win_attr->width = ico_syc_get_int_member(argobj, MSG_PRMKEY_WIDTH);
712 win_attr->height = ico_syc_get_int_member(argobj, MSG_PRMKEY_HEIGHT);
713 win_attr->raise = ico_syc_get_int_member(argobj, MSG_PRMKEY_RAISE);
714 win_attr->visible = ico_syc_get_int_member(argobj, MSG_PRMKEY_VISIBLE);
715 win_attr->active = ico_syc_get_int_member(argobj, MSG_PRMKEY_ACTIVE);
718 callback(event, win_attr, user_data);
721 g_object_unref(parser);
722 if (win_attr->appid != NULL) free(win_attr->appid);
723 if (win_attr->name != NULL) free(win_attr->name);
724 if (win_attr->zone != NULL) free(win_attr->zone);
730 /*--------------------------------------------------------------------------*/
733 * @brief ico_syc_cb_thumb
734 * Execute callback function. (ICO_SYC_EV_THUMB_ERROR
735 * ICO_SYC_EV_THUMB_CHANGE
736 * ICO_SYC_EV_THUMB_UNMAP)
738 * @param[in] callback callback function
739 * @param[in] user_data passed data on called callback function
740 * @param[in] event event code
741 * @param[in] data message data
742 * @param[in] len length of data
745 /*--------------------------------------------------------------------------*/
747 ico_syc_cb_thumb(ico_syc_callback_t callback, void *user_data,
748 int event, const void *data, size_t len)
750 JsonParser *parser = NULL;
751 GError *error = NULL;
752 gboolean gbool = FALSE;
753 JsonNode *root = NULL;
754 JsonObject *obj = NULL;
755 JsonObject *argobj = NULL;
757 ico_syc_thumb_info_t *thumb_info = NULL;
760 thumb_info = calloc(1, sizeof(ico_syc_thumb_info_t));
761 if (thumb_info == NULL) {
762 _ERR("calloc failed");
767 parser = json_parser_new();
768 gbool = json_parser_load_from_data(parser, data, len, &error);
769 if (gbool == FALSE) {
770 g_object_unref(parser);
772 _ERR("json_parser_load_from_data failed");
777 root = json_parser_get_root(parser);
779 g_object_unref(parser);
781 _ERR("json_parser_get_root failed (root is NULL)");
785 /* get object from root */
786 obj = json_node_get_object(root);
788 if (json_object_has_member(obj, MSG_PRMKEY_ARG) == FALSE) {
789 g_object_unref(parser);
791 _ERR("invalid message" );
794 /* get object from obj */
795 argobj = json_object_get_object_member(obj, MSG_PRMKEY_ARG);
798 thumb_info->appid = strdup(ico_syc_get_str_member(obj, MSG_PRMKEY_APPID));
800 thumb_info->surface = ico_syc_get_int_member(argobj,
802 thumb_info->type = ico_syc_get_int_member(argobj, MSG_PRMKEY_ATTR);
803 thumb_info->width = ico_syc_get_int_member(argobj, MSG_PRMKEY_WIDTH);
804 thumb_info->height = ico_syc_get_int_member(argobj, MSG_PRMKEY_HEIGHT);
805 thumb_info->stride = ico_syc_get_int_member(argobj, MSG_PRMKEY_STRIDE);
806 thumb_info->format = ico_syc_get_int_member(argobj, MSG_PRMKEY_FORMAT);
809 callback(event, thumb_info, user_data);
812 g_object_unref(parser);
813 free(thumb_info->appid);
819 /*--------------------------------------------------------------------------*/
822 * @brief ico_syc_cb_layer
823 * Execute callback function. (ICO_SYC_EV_LAYER_ATTR_CHANGE)
825 * @param[in] callback callback function
826 * @param[in] user_data passed data on called callback function
827 * @param[in] event event code
828 * @param[in] data message data
829 * @param[in] len length of data
832 /*--------------------------------------------------------------------------*/
834 ico_syc_cb_layer(ico_syc_callback_t callback, void *user_data,
835 int event, const void *data, size_t len)
837 JsonParser *parser = NULL;
838 GError *error = NULL;
839 gboolean gbool = FALSE;
840 JsonNode *root = NULL;
841 JsonObject *obj = NULL;
842 JsonObject *argobj = NULL;
844 ico_syc_layer_attr_t *layer_attr = NULL;
847 layer_attr = calloc(1, sizeof(ico_syc_layer_attr_t));
848 if (layer_attr == NULL) {
849 _ERR("calloc failed");
854 parser = json_parser_new();
855 gbool = json_parser_load_from_data(parser, data, len, &error);
856 if (gbool == FALSE) {
857 g_object_unref(parser);
859 _ERR("json_parser_load_from_data failed");
864 root = json_parser_get_root(parser);
866 g_object_unref(parser);
868 _ERR("json_parser_get_root failed (root is NULL)");
872 /* get object from root */
873 obj = json_node_get_object(root);
875 if (json_object_has_member(obj, MSG_PRMKEY_ARG) == FALSE) {
876 g_object_unref(parser);
878 _ERR("invalid message" );
881 /* get object from obj */
882 argobj = json_object_get_object_member(obj, MSG_PRMKEY_ARG);
884 layer_attr->layer = ico_syc_get_int_member(argobj, MSG_PRMKEY_LAYER);
885 layer_attr->visible = ico_syc_get_int_member(argobj,
889 callback(event, layer_attr, user_data);
892 g_object_unref(parser);
898 /*============================================================================*/
899 /* public interface function */
900 /*============================================================================*/
901 /*--------------------------------------------------------------------------*/
903 * @brief ico_syc_show
904 * Show the application window with animation.
905 * If user sets argument surface "ICO_SYC_WIN_SHOW_ALL",
906 * show all of the application windows.
908 * @param[in] appid application id
909 * @param[in] surface window's surface id
910 * @param[in] animation animation information
913 * @retval not 0 error
915 /*--------------------------------------------------------------------------*/
917 ico_syc_show(const char *appid, int surface,
918 const ico_syc_animation_t *animation)
920 int ret = ICO_SYC_ERR_NONE;
925 _ERR("invalid parameter (appid is NULL)");
926 return ICO_SYC_ERR_INVALID_PARAM;
930 msg = _create_win_msg(appid, surface, animation, _CMD_SHOW_WIN);
932 ret = ico_syc_send_msg(msg);
933 /* free send message */
934 ico_syc_free_msg(msg);
939 /*--------------------------------------------------------------------------*/
941 * @brief ico_syc_hide
942 * Hide the application window with animation.
944 * @param[in] appid application id
945 * @param[in] surface window's surface id
946 * @param[in] animation animation information
949 * @retval not 0 error
951 /*--------------------------------------------------------------------------*/
953 ico_syc_hide(const char *appid, int surface,
954 const ico_syc_animation_t *animation)
956 int ret = ICO_SYC_ERR_NONE;
961 _ERR("invalid parameter (appid is NULL)");
962 return ICO_SYC_ERR_INVALID_PARAM;
966 msg = _create_win_msg(appid, surface, animation, _CMD_HIDE_WIN);
968 ret = ico_syc_send_msg(msg);
969 /* free send message */
970 ico_syc_free_msg(msg);
975 /*--------------------------------------------------------------------------*/
977 * @brief ico_syc_move
978 * Move the application window with animation.
980 * @param[in] appid application id
981 * @param[in] surface window's surface id
982 * @param[in] move move information (zone/position/size)
983 * @param[in] animation animation information
986 * @retval not 0 error
988 /*--------------------------------------------------------------------------*/
990 ico_syc_move(const char *appid, int surface,
991 const ico_syc_win_move_t *move,
992 const ico_syc_animation_t *animation)
994 int ret = ICO_SYC_ERR_NONE;
999 _ERR("invalid parameter (appid is NULL)");
1000 return ICO_SYC_ERR_INVALID_PARAM;
1004 msg = _create_win_move_msg(appid, surface, move, animation);
1006 ret = ico_syc_send_msg(msg);
1007 /* free send message */
1008 ico_syc_free_msg(msg);
1013 /*--------------------------------------------------------------------------*/
1015 * @brief ico_syc_set_animation
1016 * Set the application window animation.
1018 * @param[in] appid application id
1019 * @param[in] surface window's surface id
1020 * @param[in] type set animation target
1021 * @param[in] animation animation information
1024 * @retval not 0 error
1026 /*--------------------------------------------------------------------------*/
1028 ico_syc_set_animation(const char *appid, int surface, int type,
1029 const ico_syc_animation_t *animation)
1031 int ret = ICO_SYC_ERR_NONE;
1034 /* check argument */
1035 if (appid == NULL) {
1036 _ERR("invalid parameter (appid is NULL)");
1037 return ICO_SYC_ERR_INVALID_PARAM;
1041 msg = _create_win_animation_msg(appid, surface, type, animation->name, animation->time);
1043 ret = ico_syc_send_msg(msg);
1044 /* free send message */
1045 ico_syc_free_msg(msg);
1050 /*--------------------------------------------------------------------------*/
1052 * @brief ico_syc_change_active
1053 * Change the active window which receives the win-event notification
1054 * from System Controller.
1056 * @param[in] appid application id
1057 * @param[in] surface window's surface id
1060 * @retval not 0 error
1062 /*--------------------------------------------------------------------------*/
1064 ico_syc_change_active(const char *appid, int surface)
1066 int ret = ICO_SYC_ERR_NONE;
1069 /* check argument */
1070 if (appid == NULL) {
1071 _ERR("invalid parameter (appid is NULL)");
1072 return ICO_SYC_ERR_INVALID_PARAM;
1076 msg = _create_active_win_msg(appid, surface);
1078 ret = ico_syc_send_msg(msg);
1079 /* free send message */
1080 ico_syc_free_msg(msg);
1085 /*--------------------------------------------------------------------------*/
1087 * @brief ico_syc_change_layer
1088 * Change the window's layer.
1090 * @param[in] appid application id
1091 * @param[in] surface window's surface id
1092 * @param[in] layer window's layer id
1095 * @retval not 0 error
1097 /*--------------------------------------------------------------------------*/
1099 ico_syc_change_layer(const char *appid, int surface, int layer)
1101 int ret = ICO_SYC_ERR_NONE;
1104 /* check argument */
1105 if (appid == NULL) {
1106 _ERR("invalid parameter (appid is NULL)");
1107 return ICO_SYC_ERR_INVALID_PARAM;
1111 msg = _create_change_layer_msg(appid, surface, layer);
1113 ret = ico_syc_send_msg(msg);
1114 /* free send message */
1115 ico_syc_free_msg(msg);
1120 /*--------------------------------------------------------------------------*/
1122 * @brief ico_syc_map_get
1123 * Get the surface thumbnail pixel image to the file.
1125 * @param[in] surface window's surface id
1126 * @param[in] filepath surface image pixel file path
1129 * @retval not 0 error
1131 /*--------------------------------------------------------------------------*/
1133 ico_syc_map_get(int surface, const char *filepath)
1135 int ret = ICO_SYC_ERR_NONE;
1140 appid = ico_syc_get_appid();
1143 msg = _create_map_get_msg(appid, surface, filepath);
1145 ret = ico_syc_send_msg(msg);
1146 /* free send message */
1147 ico_syc_free_msg(msg);
1152 /*--------------------------------------------------------------------------*/
1154 * @brief ico_syc_map_thumb
1155 * Prepare the thumbnail data
1157 * @param[in] surface window's surface id
1158 * @param[in] framerate notify cycle [ms]
1159 * @param[in] filepath pixel image file path
1162 * @retval not 0 error
1164 /*--------------------------------------------------------------------------*/
1166 ico_syc_map_thumb(int surface, int framerate, const char *filepath)
1168 int ret = ICO_SYC_ERR_NONE;
1173 appid = ico_syc_get_appid();
1176 msg = _create_map_thumb_msg(appid, surface, framerate, filepath);
1178 ret = ico_syc_send_msg(msg);
1179 /* free send message */
1180 ico_syc_free_msg(msg);
1185 /*--------------------------------------------------------------------------*/
1187 * @brief ico_syc_unmap_thumb
1188 * Unmap the thumbnail data.
1189 * User calls this API when receiving the notification that
1190 * terminated the application.
1192 * @param[in] surface window's surface id
1195 * @retval not 0 error
1197 /*--------------------------------------------------------------------------*/
1199 ico_syc_unmap_thumb(int surface)
1201 int ret = ICO_SYC_ERR_NONE;
1206 appid = ico_syc_get_appid();
1209 msg = _create_unmap_thumb_msg(appid, surface);
1211 ret = ico_syc_send_msg(msg);
1212 /* free send message */
1213 ico_syc_free_msg(msg);
1218 /*--------------------------------------------------------------------------*/
1220 * @brief ico_syc_show_layer
1223 * @param[in] layer window's layer id
1226 * @retval not 0 error
1228 /*--------------------------------------------------------------------------*/
1230 ico_syc_show_layer(int layer)
1232 int ret = ICO_SYC_ERR_NONE;
1237 appid = ico_syc_get_appid();
1240 msg = _create_layer_msg(appid, layer, _CMD_SHOW_LAYER);
1242 ret = ico_syc_send_msg(msg);
1243 /* free send message */
1244 ico_syc_free_msg(msg);
1249 /*--------------------------------------------------------------------------*/
1251 * @brief ico_syc_hide_layer
1254 * @param[in] layer window's layer id
1257 * @retval not 0 error
1259 /*--------------------------------------------------------------------------*/
1261 ico_syc_hide_layer(int layer)
1263 int ret = ICO_SYC_ERR_NONE;
1268 appid = ico_syc_get_appid();
1271 msg = _create_layer_msg(appid, layer, _CMD_HIDE_LAYER);
1273 ret = ico_syc_send_msg(msg);
1274 /* free send message */
1275 ico_syc_free_msg(msg);
1279 /* vim: set expandtab ts=4 sw=4: */