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 Application Resource Control API
11 * for general applications
21 #include "ico_syc_application.h"
22 #include "ico_syc_msg_cmd_def.h"
23 #include "ico_syc_msg.h"
24 #include "ico_syc_private.h"
26 /*============================================================================*/
27 /* define static function prototype */
28 /*============================================================================*/
29 static ico_syc_res_window_t *_create_res_window(const char *ECU,
34 const char *dispatchApp,
37 static ico_syc_res_sound_t *_create_res_sound(char *zone, char *name, char *id,
39 static ico_syc_res_input_t *_create_res_input(char *name, int event);
40 static void _free_res_window(ico_syc_res_window_t *window);
41 static void _free_res_sound(ico_syc_res_sound_t *sound);
42 static void _free_res_input(ico_syc_res_input_t *input);
43 static struct ico_syc_res_context * _create_context(
45 const ico_syc_res_window_t *window,
46 const ico_syc_res_sound_t *sound,
47 const ico_syc_res_input_t *input,
49 /* create send message */
50 static JsonObject *_create_window_msg(ico_syc_res_window_t *window);
51 static JsonObject *_create_sound_msg(ico_syc_res_sound_t *sound);
52 static JsonObject *_create_input_msg(ico_syc_res_input_t *input);
53 static msg_t _create_acquire_res_msg(const struct ico_syc_res_context *context);
54 static msg_t _create_release_res_msg(const struct ico_syc_res_context *context);
55 static msg_t _create_set_region_msg(const char *appid,
56 const ico_syc_input_region_t *input,
58 static msg_t _create_unset_region_msg(const char *appid,
59 const ico_syc_input_region_t *input);
61 /*============================================================================*/
63 /*============================================================================*/
64 /*--------------------------------------------------------------------------*/
66 * @brief _create_res_window
67 * Allocate memory for window resource information.
69 * @param[in] zone window zone
70 * @param[in] name windo name
71 * @param[in] id window id
72 * @return resource info
73 * @retval address success
76 /*--------------------------------------------------------------------------*/
77 static ico_syc_res_window_t *
78 _create_res_window(const char *ECU, const char *display, const char *layer,
79 const char *layout, const char *area,
80 const char *dispatchApp, const char *role,
83 ico_syc_res_window_t *info = NULL;
85 if ((NULL == ECU) || (NULL == display) || (NULL == layer) ||
86 (NULL == layout) || (NULL == area) || (NULL == dispatchApp) ||
88 _ERR("invalid parameter (zone, name is NULL)");
93 info = calloc(1, sizeof(ico_syc_res_window_t));
95 _ERR("calloc failed");
100 info->ECU = strdup(ECU);
101 info->display = strdup(display);
102 info->layer = strdup(layer);
103 info->layout = strdup(layout);
104 info->area = strdup(area);
105 info->dispatchApp = strdup(dispatchApp);
106 info->role = strdup(role);
107 info->resourceId = resourceId;
112 /*--------------------------------------------------------------------------*/
114 * @brief _create_res_sound
115 * Allocate memory for sound resource information.
117 * @param[in] zone sound zone
118 * @param[in] name sound name
119 * @param[in] id sound id
120 * @param[in] adjust adjust type
121 * @return resource info
122 * @retval address success
125 /*--------------------------------------------------------------------------*/
126 static ico_syc_res_sound_t *
127 _create_res_sound(char *zone, char *name, char *id, int adjust)
129 ico_syc_res_sound_t *info = NULL;
131 if (zone == NULL || name == NULL) {
132 _ERR("invalid parameter (zone, name is NULL)");
137 info = calloc(1, sizeof(ico_syc_res_sound_t));
139 _ERR("calloc failed");
144 info->zone = strdup(zone);
145 info->name = strdup(name);
147 info->id = strdup(id);
149 info->adjust = adjust;
154 /*--------------------------------------------------------------------------*/
156 * @brief _create_res_input
157 * Allocate memory for input resource information.
159 * @param[in] name input device name
160 * @param[in] event input event
161 * @return resource info
162 * @retval address success
165 /*--------------------------------------------------------------------------*/
166 static ico_syc_res_input_t *
167 _create_res_input(char *name, int event)
169 ico_syc_res_input_t *info = NULL;
172 _ERR("invalid parameter (name is NULL)");
177 info = calloc(1, sizeof(ico_syc_res_input_t));
179 _ERR("calloc failed");
184 info->name = strdup(name);
190 /*--------------------------------------------------------------------------*/
192 * @brief _free_res_window
193 * Free memory of window resource information.
195 * @param[in] window window resource's information
198 /*--------------------------------------------------------------------------*/
200 _free_res_window(ico_syc_res_window_t *w)
207 if (NULL != w->ECU) free(w->ECU);
208 if (NULL != w->display) free(w->display);
209 if (NULL != w->layer) free(w->layer);
210 if (NULL != w->layout) free(w->layout);
211 if (NULL != w->area) free(w->area);
212 if (NULL != w->dispatchApp) free(w->dispatchApp);
213 if (NULL != w->role) free(w->role);
220 /*--------------------------------------------------------------------------*/
222 * @brief _free_res_sound
223 * Free memory of sound resource information.
225 * @param[in] sound sound resource's information
228 /*--------------------------------------------------------------------------*/
230 _free_res_sound(ico_syc_res_sound_t *sound)
237 if (sound->zone != NULL) free(sound->zone);
238 if (sound->name != NULL) free(sound->name);
239 if (sound->id != NULL) free(sound->id);
246 /*--------------------------------------------------------------------------*/
248 * @brief _free_res_input
249 * Free memory of input resource information.
251 * @param[in] input input resource's information
254 /*--------------------------------------------------------------------------*/
256 _free_res_input(ico_syc_res_input_t *input)
263 if (input->name != NULL) free(input->name);
270 /*--------------------------------------------------------------------------*/
272 * @brief _create_context
273 * Create resource information context.
275 * @param[in] appid application id
276 * @param[in] window window resource's information
277 * @param[in] sound sound resource's information
278 * @param[in] input input resource's information
279 * @param[in] type window and sound resource type
280 * (basic or interruption)
281 * @return resource's context address
282 * @retval address success
285 /*--------------------------------------------------------------------------*/
286 static struct ico_syc_res_context *
287 _create_context(char *appid, const ico_syc_res_window_t *w,
288 const ico_syc_res_sound_t *sound,
289 const ico_syc_res_input_t *input,
292 struct ico_syc_res_context *context = NULL;
294 context = (struct ico_syc_res_context *)
295 calloc(1, sizeof(struct ico_syc_res_context));
296 if (context == NULL) {
297 _ERR("calloc failed");
302 strcpy(context->appid, appid);
304 /* set window info */
306 context->window = _create_res_window(w->ECU, w->display, w->layer,
308 w->dispatchApp, w->role,
313 context->sound = _create_res_sound(sound->zone, sound->name,
314 sound->id, sound->adjust);
318 context->input = _create_res_input(input->name, input->event);
321 /* set resource type */
322 if (w != NULL || sound != NULL) {
323 context->type = type;
329 /*--------------------------------------------------------------------------*/
331 * @brief _create_window_msg
332 * Create the JsonObject to set the window resource information.
334 * @param[in] window window resource information
335 * @return json object
336 * @retval json object success
339 /*--------------------------------------------------------------------------*/
341 _create_window_msg(ico_syc_res_window_t *w)
343 JsonObject *info = NULL;
346 _ERR("invalid parameter (window is NULL)");
350 /* create json object */
351 info = json_object_new();
353 _ERR("json_object_new failed");
358 json_object_set_string_member(info, MSG_PRMKEY_ECU, w->ECU);
359 json_object_set_string_member(info, MSG_PRMKEY_DISPLAY, w->display);
360 json_object_set_string_member(info, MSG_PRMKEY_LAYER, w->layer);
361 json_object_set_string_member(info, MSG_PRMKEY_LAYOUT, w->layout);
362 json_object_set_string_member(info, MSG_PRMKEY_AREA, w->area);
363 json_object_set_string_member(info, MSG_PRMKEY_DISPATCHAPP, w->dispatchApp);
364 json_object_set_string_member(info, MSG_PRMKEY_ROLE, w->role);
365 json_object_set_int_member(info, MSG_PRMKEY_RESOURCEID, w->resourceId);
370 /*--------------------------------------------------------------------------*/
372 * @brief _create_sound_msg
373 * Create the JsonObject to set the sound resource information.
375 * @param[in] sound sound resource information
376 * @return json object
377 * @retval json object success
380 /*--------------------------------------------------------------------------*/
382 _create_sound_msg(ico_syc_res_sound_t *sound)
384 JsonObject *info = NULL;
387 _ERR("invalid parameter (sound is NULL)");
391 /* create json object */
392 info = json_object_new();
394 _ERR("json_object_new failed");
399 json_object_set_string_member(info, MSG_PRMKEY_RES_ZONE, sound->zone);
400 json_object_set_string_member(info, MSG_PRMKEY_RES_NAME, sound->name);
401 json_object_set_string_member(info, MSG_PRMKEY_RES_ID, sound->id);
402 json_object_set_int_member(info, MSG_PRMKEY_RES_ADJUST, sound->adjust);
407 /*--------------------------------------------------------------------------*/
409 * @brief _create_input_msg
410 * Create the JsonObject to set the input resource information.
412 * @param[in] input input resource information
413 * @return json object
414 * @retval json object success
417 /*--------------------------------------------------------------------------*/
419 _create_input_msg(ico_syc_res_input_t *input)
421 JsonObject *info = NULL;
424 _ERR("invalid parameter (input is NULL)");
428 /* create json object */
429 info = json_object_new();
431 _ERR("json_object_new failed");
436 json_object_set_string_member(info, MSG_PRMKEY_RES_NAME, input->name);
437 json_object_set_int_member(info, MSG_PRMKEY_RES_EV, input->event);
443 /*--------------------------------------------------------------------------*/
445 * @brief _create_acquire_res_msg
446 * Create the message to acquire the resource (window/sound/input).
448 * @param[in] context resource context
449 * @return json generator
450 * @retval json generator success
453 /*--------------------------------------------------------------------------*/
455 _create_acquire_res_msg(const struct ico_syc_res_context *context)
457 JsonObject *obj = NULL;
458 JsonObject *resobj = NULL;
459 JsonObject *info = NULL;
460 JsonGenerator *gen = NULL;
461 JsonNode *root = NULL;
463 /* create json object */
464 obj = json_object_new();
465 resobj = json_object_new();
466 if (obj == NULL || resobj == NULL) {
467 _ERR("json_object_new failed");
472 json_object_set_int_member(obj, MSG_PRMKEY_CMD, MSG_CMD_ACQUIRE_RES);
473 json_object_set_string_member(obj, MSG_PRMKEY_APPID, context->appid);
474 json_object_set_int_member(obj, MSG_PRMKEY_PID, getpid());
476 /* window resource */
477 if (context->window != NULL) {
478 info = _create_window_msg(context->window);
480 json_object_set_object_member(resobj, MSG_PRMKEY_RES_WINDOW, info);
484 if (context->sound != NULL) {
485 info = _create_sound_msg(context->sound);
487 json_object_set_object_member(resobj, MSG_PRMKEY_RES_SOUND, info);
491 if (context->input != NULL) {
492 info = _create_input_msg(context->input);
494 json_object_set_object_member(resobj, MSG_PRMKEY_RES_INPUT, info);
498 if (context->window != NULL || context->sound != NULL) {
499 json_object_set_int_member(resobj, MSG_PRMKEY_RES_TYPE, context->type);
501 /* set resource object */
502 json_object_set_object_member(obj, MSG_PRMKEY_RES, resobj);
504 /* create root object */
505 root = json_node_new(JSON_NODE_OBJECT);
506 json_node_take_object(root, obj);
508 /* create generator object */
509 gen = json_generator_new();
510 json_generator_set_root(gen, root);
515 /*--------------------------------------------------------------------------*/
517 * @brief _create_release_res_msg
518 * Create the message to release the resource (window/sound/input).
520 * @param[in] context resource context
521 * @return json generator
522 * @retval json generator success
525 /*--------------------------------------------------------------------------*/
527 _create_release_res_msg(const struct ico_syc_res_context *context)
529 JsonObject *obj = NULL;
530 JsonObject *resobj = NULL;
531 JsonObject *info = NULL;
532 JsonGenerator *gen = NULL;
533 JsonNode *root = NULL;
535 /* create json object */
536 obj = json_object_new();
537 resobj = json_object_new();
538 if (obj == NULL || resobj == NULL) {
539 _ERR("json_object_new failed");
544 json_object_set_int_member(obj, MSG_PRMKEY_CMD, MSG_CMD_RELEASE_RES);
545 json_object_set_string_member(obj, MSG_PRMKEY_APPID, context->appid);
546 json_object_set_int_member(obj, MSG_PRMKEY_PID, getpid());
548 /* window resource */
549 if (context->window != NULL) {
550 info = _create_window_msg(context->window);
552 json_object_set_object_member(resobj, MSG_PRMKEY_RES_WINDOW, info);
556 if (context->sound != NULL) {
557 info = _create_sound_msg(context->sound);
559 json_object_set_object_member(resobj, MSG_PRMKEY_RES_SOUND, info);
563 if (context->input != NULL) {
564 info = _create_input_msg(context->input);
566 json_object_set_object_member(resobj, MSG_PRMKEY_RES_INPUT, info);
569 if (context->window != NULL || context->sound != NULL) {
570 json_object_set_int_member(resobj, MSG_PRMKEY_RES_TYPE, context->type);
572 /* set resource object */
573 json_object_set_object_member(obj, MSG_PRMKEY_RES, resobj);
575 /* create root object */
576 root = json_node_new(JSON_NODE_OBJECT);
577 json_node_take_object(root, obj);
579 /* create generator object */
580 gen = json_generator_new();
581 json_generator_set_root(gen, root);
586 /*--------------------------------------------------------------------------*/
588 * @brief _create_set_region_msg
589 * Create the message to set the input region.
591 * @param[in] appid application id
592 * @param[in] input input region's information
593 * @param[in] attr input region's attribute
594 * @return json generator
595 * @retval json generator success
598 /*--------------------------------------------------------------------------*/
600 _create_set_region_msg(const char *appid, const ico_syc_input_region_t *input,
603 JsonObject *obj = NULL;
604 JsonObject *resobj = NULL;
605 JsonGenerator *gen = NULL;
606 JsonNode *root = NULL;
608 /* create json object */
609 obj = json_object_new();
610 resobj = json_object_new();
611 if (obj == NULL || resobj == NULL) {
612 _ERR("json_object_new failed");
617 json_object_set_int_member(obj, MSG_PRMKEY_CMD, MSG_CMD_SET_REGION);
618 json_object_set_string_member(obj, MSG_PRMKEY_APPID, appid);
619 json_object_set_int_member(obj, MSG_PRMKEY_PID, getpid());
621 json_object_set_string_member(resobj, MSG_PRMKEY_WINNAME, input->winname);
622 json_object_set_int_member(resobj, MSG_PRMKEY_RES_POS_X, input->pos_x);
623 json_object_set_int_member(resobj, MSG_PRMKEY_RES_POS_Y, input->pos_y);
624 json_object_set_int_member(resobj, MSG_PRMKEY_RES_WIDTH, input->width);
625 json_object_set_int_member(resobj, MSG_PRMKEY_RES_HEIGHT, input->height);
626 json_object_set_int_member(resobj, MSG_PRMKEY_RES_HOT_X, input->hotspot_x);
627 json_object_set_int_member(resobj, MSG_PRMKEY_RES_HOT_Y, input->hotspot_y);
628 json_object_set_int_member(resobj, MSG_PRMKEY_RES_CUR_X, input->cursor_x);
629 json_object_set_int_member(resobj, MSG_PRMKEY_RES_CUR_Y, input->cursor_y);
630 json_object_set_int_member(resobj, MSG_PRMKEY_RES_CUR_WIDTH, input->cursor_width);
631 json_object_set_int_member(resobj, MSG_PRMKEY_RES_CUR_HEIGHT, input->cursor_height);
632 json_object_set_int_member(resobj, MSG_PRMKEY_RES_ATTR, attr);
633 json_object_set_object_member(obj, MSG_PRMKEY_REGION, resobj);
635 /* create root object */
636 root = json_node_new(JSON_NODE_OBJECT);
637 json_node_take_object(root, obj);
639 /* create generator object */
640 gen = json_generator_new();
641 json_generator_set_root(gen, root);
646 /*--------------------------------------------------------------------------*/
648 * @brief _create_unset_region_msg
649 * Create the message to unset the input region.
651 * @param[in] appid application id
652 * @param[in] input input region's information
653 * @return json generator
654 * @retval json generator success
657 /*--------------------------------------------------------------------------*/
659 _create_unset_region_msg(const char *appid, const ico_syc_input_region_t *input)
661 JsonObject *obj = NULL;
662 JsonObject *resobj = NULL;
663 JsonGenerator *gen = NULL;
664 JsonNode *root = NULL;
666 /* create json object */
667 obj = json_object_new();
668 resobj = json_object_new();
669 if (obj == NULL || resobj == NULL) {
670 _ERR("json_object_new failed");
675 json_object_set_int_member(obj, MSG_PRMKEY_CMD, MSG_CMD_UNSET_REGION);
676 json_object_set_string_member(obj, MSG_PRMKEY_APPID, appid);
677 json_object_set_int_member(obj, MSG_PRMKEY_PID, getpid());
680 json_object_set_string_member(resobj, MSG_PRMKEY_WINNAME, input->winname);
681 json_object_set_int_member(resobj, MSG_PRMKEY_RES_POS_X, input->pos_x);
682 json_object_set_int_member(resobj, MSG_PRMKEY_RES_POS_Y, input->pos_y);
683 json_object_set_int_member(resobj, MSG_PRMKEY_RES_WIDTH, input->width);
684 json_object_set_int_member(resobj, MSG_PRMKEY_RES_HEIGHT, input->height);
687 json_object_set_string_member(resobj, MSG_PRMKEY_WINNAME, " ");
688 json_object_set_int_member(resobj, MSG_PRMKEY_RES_POS_X, 0);
689 json_object_set_int_member(resobj, MSG_PRMKEY_RES_POS_Y, 0);
690 json_object_set_int_member(resobj, MSG_PRMKEY_RES_WIDTH, 0);
691 json_object_set_int_member(resobj, MSG_PRMKEY_RES_HEIGHT, 0);
693 json_object_set_object_member(obj, MSG_PRMKEY_REGION, resobj);
695 /* create root object */
696 root = json_node_new(JSON_NODE_OBJECT);
697 json_node_take_object(root, obj);
699 /* create generator object */
700 gen = json_generator_new();
701 json_generator_set_root(gen, root);
706 /*============================================================================*/
707 /* internal common function */
708 /*============================================================================*/
709 /*--------------------------------------------------------------------------*/
712 * @brief ico_syc_cb_res
713 * Execute callback function. (ICO_SYC_EV_RES_ACQUIRE
714 * ICO_SYC_EV_RES_DEPRIVE
715 * ICO_SYC_EV_RES_WAITING
716 * ICO_SYC_EV_RES_REVERT
717 * ICO_SYC_EV_RES_RELEASE)
719 * @param[in] callback callback function
720 * @param[in] user_data pased data on called callback function
721 * @param[in] event event code
722 * @param[in] data message data
723 * @param[in] len length of data
726 /*--------------------------------------------------------------------------*/
728 ico_syc_cb_res(ico_syc_callback_t callback, void *user_data,
729 int event, const void *data, size_t len)
731 JsonParser *parser = NULL;
732 GError *error = NULL;
733 gboolean gbool = FALSE;
734 JsonNode *root = NULL;
735 JsonObject *obj = NULL;
736 JsonObject *resobj = NULL;
737 JsonObject *info = NULL;
739 ico_syc_res_info_t *res_info = NULL;
740 char *zone, *name, *id;
741 int adjust, input_ev;
742 char *ECU, *display, *layer, *layout, *area, *dispatchApp, *role;
747 res_info = calloc(1, sizeof(ico_syc_res_info_t));
748 if (res_info == NULL) {
749 _ERR("calloc failed");
754 parser = json_parser_new();
755 gbool = json_parser_load_from_data(parser, data, len, &error);
756 if (gbool == FALSE) {
757 g_object_unref(parser);
759 _ERR("json_parser_load_from_data failed");
764 root = json_parser_get_root(parser);
766 g_object_unref(parser);
768 _ERR("json_parser_get_root failed (root is NULL)");
772 /* get object from root */
773 obj = json_node_get_object(root);
775 if (json_object_has_member(obj, MSG_PRMKEY_RES) == FALSE) {
776 _ERR("invalid message");
779 resobj = json_object_get_object_member(obj, MSG_PRMKEY_RES);
781 /* window resource */
782 if (json_object_has_member(resobj, MSG_PRMKEY_RES_WINDOW) == TRUE) {
783 info = json_object_get_object_member(resobj, MSG_PRMKEY_RES_WINDOW);
784 ECU = ico_syc_get_str_member(info, MSG_PRMKEY_ECU);
785 display = ico_syc_get_str_member(info, MSG_PRMKEY_DISPLAY);
786 layer = ico_syc_get_str_member(info, MSG_PRMKEY_LAYER);
787 layout = ico_syc_get_str_member(info, MSG_PRMKEY_LAYOUT);
788 area = ico_syc_get_str_member(info, MSG_PRMKEY_AREA);
789 dispatchApp = ico_syc_get_str_member(info, MSG_PRMKEY_DISPATCHAPP);
790 role = ico_syc_get_str_member(info, MSG_PRMKEY_ROLE);
791 resourceId = (uint32_t)
792 ico_syc_get_int_member(info, MSG_PRMKEY_RESOURCEID);
793 res_info->window = _create_res_window(ECU, display, layer, layout,
794 area, dispatchApp, role,
799 if (json_object_has_member(resobj, MSG_PRMKEY_RES_SOUND) == TRUE) {
800 info = json_object_get_object_member(resobj, MSG_PRMKEY_RES_SOUND);
801 zone = ico_syc_get_str_member(info, MSG_PRMKEY_RES_ZONE);
802 name = ico_syc_get_str_member(info, MSG_PRMKEY_RES_NAME);
803 id = ico_syc_get_str_member(info, MSG_PRMKEY_RES_ID);
804 adjust = ico_syc_get_int_member(info, MSG_PRMKEY_RES_ADJUST);
806 res_info->sound = _create_res_sound(zone, name, id, adjust);
810 if (json_object_has_member(resobj, MSG_PRMKEY_RES_INPUT) == TRUE) {
811 info = json_object_get_object_member(resobj, MSG_PRMKEY_RES_INPUT);
812 name = ico_syc_get_str_member(info, MSG_PRMKEY_RES_NAME);
813 input_ev = ico_syc_get_int_member(info, MSG_PRMKEY_RES_EV);
815 res_info->input = _create_res_input(name, input_ev);
819 callback(event, res_info, user_data);
822 g_object_unref(parser);
823 _free_res_window(res_info->window);
824 _free_res_sound(res_info->sound);
825 _free_res_input(res_info->input);
831 /*--------------------------------------------------------------------------*/
834 * @brief ico_syc_cb_region
835 * Execute callback function. (ICO_SYC_EV_INPUT_SET
836 * ICO_SYC_EV_INPUT_UNSET)
838 * @param[in] callback callback function
839 * @param[in] user_data pased data on called callback function
840 * @param[in] event event code
841 * @param[in] data message data
842 * @param[in] len length of data
845 /*--------------------------------------------------------------------------*/
847 ico_syc_cb_region(ico_syc_callback_t callback, void *user_data,
848 int event, const void *data, size_t len)
850 JsonParser *parser = NULL;
851 GError *error = NULL;
852 gboolean gbool = FALSE;
853 JsonNode *root = NULL;
854 JsonObject *obj = NULL;
855 JsonObject *resobj = NULL;
857 ico_syc_input_region_t *region = NULL;
860 region = calloc(1, sizeof(ico_syc_input_region_t));
861 if (region == NULL) {
862 _ERR("calloc failed");
867 parser = json_parser_new();
868 gbool = json_parser_load_from_data(parser, data, len, &error);
869 if (gbool == FALSE) {
870 g_object_unref(parser);
872 _ERR("json_parser_load_from_data failed");
877 root = json_parser_get_root(parser);
879 g_object_unref(parser);
881 _ERR("json_parser_get_root failed (root is NULL)");
885 /* get object from root */
886 obj = json_node_get_object(root);
888 if (json_object_has_member(obj, MSG_PRMKEY_REGION) == FALSE) {
889 _ERR("invalid message");
892 resobj = json_object_get_object_member(obj, MSG_PRMKEY_REGION);
894 /* get input region information */
895 char *p = ico_syc_get_str_member(resobj, MSG_PRMKEY_WINNAME);
897 strncpy(region->winname, p, ICO_SYC_MAX_WINNAME_LEN-1);
899 region->pos_x = ico_syc_get_int_member(resobj, MSG_PRMKEY_RES_POS_X);
900 region->pos_y = ico_syc_get_int_member(resobj, MSG_PRMKEY_RES_POS_Y);
901 region->width = ico_syc_get_int_member(resobj, MSG_PRMKEY_RES_WIDTH);
902 region->height = ico_syc_get_int_member(resobj, MSG_PRMKEY_RES_HEIGHT);
903 region->hotspot_x = ico_syc_get_int_member(resobj, MSG_PRMKEY_RES_HOT_X);
904 region->hotspot_y = ico_syc_get_int_member(resobj, MSG_PRMKEY_RES_HOT_Y);
905 region->cursor_x = ico_syc_get_int_member(resobj, MSG_PRMKEY_RES_CUR_X);
906 region->cursor_y = ico_syc_get_int_member(resobj, MSG_PRMKEY_RES_CUR_Y);
907 region->cursor_width = ico_syc_get_int_member(resobj, MSG_PRMKEY_RES_CUR_WIDTH);
908 region->cursor_height = ico_syc_get_int_member(resobj, MSG_PRMKEY_RES_CUR_HEIGHT);
909 region->attr = ico_syc_get_int_member(resobj, MSG_PRMKEY_RES_ATTR);
912 callback(event, region, user_data);
915 g_object_unref(parser);
921 /*============================================================================*/
922 /* public interface function */
923 /*============================================================================*/
924 /*--------------------------------------------------------------------------*/
926 * @brief ico_syc_acquire_res
927 * Acquire the resources(window/sound/input).
928 * User can choose window and sound resource's type
929 * "basic" or "interruption".
930 * If user want to acquire the sound resource only,
931 * user sets NULL to argument "window" and "input".
933 * @param[in] window window resource's information
934 * @param[in] sound sound resource's information
935 * @param[in] input input resource's information
936 * @param[in] type window and sound resource's type
937 * (basic or interruption)
938 * @return resource's context address
939 * @retval address success
941 * @see ico_syc_res_type_e
943 /*--------------------------------------------------------------------------*/
944 ICO_API struct ico_syc_res_context *
945 ico_syc_acquire_res(const ico_syc_res_window_t *window,
946 const ico_syc_res_sound_t *sound,
947 const ico_syc_res_input_t *input,
952 struct ico_syc_res_context *context = NULL;
955 if (window == NULL && sound == NULL && input == NULL) {
956 _ERR("invalid parameter (all resources is NULL)");
961 appid = ico_syc_get_appid();
964 context = _create_context(appid, window, sound, input, type);
965 if (context == NULL) {
966 _ERR("context is NULL");
971 msg = _create_acquire_res_msg(context);
973 (void)ico_syc_send_msg(msg);
974 /* free send message */
975 ico_syc_free_msg(msg);
980 /*--------------------------------------------------------------------------*/
982 * @brief ico_syc_release_res
983 * Release the resources(window/sound/input).
985 * @param[in] context resource context
988 * @retval not 0 error
990 /*--------------------------------------------------------------------------*/
992 ico_syc_release_res(struct ico_syc_res_context *context)
997 if (context == NULL) {
998 _ERR("invalid parameter (context is NULL)");
999 return ICO_SYC_ERR_INVALID_PARAM;
1003 msg = _create_release_res_msg(context);
1005 (void)ico_syc_send_msg(msg);
1006 /* free send message */
1007 ico_syc_free_msg(msg);
1009 /* free resource info */
1010 _free_res_window(context->window);
1011 _free_res_sound(context->sound);
1012 _free_res_input(context->input);
1016 return ICO_SYC_ERR_NONE;
1019 /*--------------------------------------------------------------------------*/
1021 * @brief ico_syc_set_input_region
1022 * Set the input region. (for haptic device)
1023 * Callback function notifies the result of setting the input region.
1025 * @param[in] input input region's information
1026 * @param[in] attr input region's attribute
1029 * @retval not 0 error
1031 /*--------------------------------------------------------------------------*/
1033 ico_syc_set_input_region(const ico_syc_input_region_t *input, int attr)
1038 /* check argument */
1039 if (input == NULL) {
1040 _ERR("invalid parameter (ico_syc_input_region_t is NULL)");
1041 return ICO_SYC_ERR_INVALID_PARAM;
1045 appid = ico_syc_get_appid();
1048 msg = _create_set_region_msg(appid, input, attr);
1050 (void)ico_syc_send_msg(msg);
1051 /* free send message */
1052 ico_syc_free_msg(msg);
1054 return ICO_SYC_ERR_NONE;
1057 /*--------------------------------------------------------------------------*/
1059 * @brief ico_syc_unset_input_region
1060 * Unset the input region. (for haptic device)
1061 * Callback function notifies the result of unsetting the input region.
1063 * @param[in] input input region's information
1066 * @retval not 0 error
1068 /*--------------------------------------------------------------------------*/
1070 ico_syc_unset_input_region(const ico_syc_input_region_t *input)
1075 /* check argument */
1076 if (input == NULL) {
1077 _ERR("invalid parameter (ico_syc_input_region_t is NULL)");
1078 return ICO_SYC_ERR_INVALID_PARAM;
1082 appid = ico_syc_get_appid();
1085 msg = _create_unset_region_msg(appid, input);
1087 (void)ico_syc_send_msg(msg);
1088 /* free send message */
1089 ico_syc_free_msg(msg);
1091 return ICO_SYC_ERR_NONE;
1094 /* vim: set expandtab ts=4 sw=4: */