From 243cbebfdcd215d0b98b2af7aa836adf079301c6 Mon Sep 17 00:00:00 2001 From: Sung-jae Park Date: Thu, 30 Oct 2014 10:44:48 +0900 Subject: [PATCH] Replace livebox with dynamicbox [model] Redwood,Kiran,B3(Wearable) [binary_type] AP [customer] Docomo/Orange/ATT/Open [issue#] N/A [problem] [cause] [solution] [team] HomeTF [request] [horizontal_expansion] Change-Id: Ice061e1c38e707d85a496feb20877c4984d3e84f --- include/conf.h | 12 +- include/debug.h | 4 +- include/dlist.h | 14 +- include/dynamicbox.h | 354 +- include/dynamicbox_internal.h | 366 +- include/util.h | 6 +- live.viewer/dbox.app-dbox.only/src/main.c | 2 +- live.viewer/dbox.video/src/player.c | 3 +- .../packaging/com.samsung.w-add-viewer.spec | 4 +- live.viewer/viewer/src/dynamicbox_evas.c | 6788 ++++++++++---------- src/client.c | 3691 ++++++----- src/conf.c | 53 +- src/desc_parser.c | 1097 ++-- src/dlist.c | 192 +- src/dynamicbox.c | 6391 +++++++++--------- src/dynamicbox_internal.c | 1657 +++-- src/fb.c | 1103 ++-- src/fb_wayland.c | 666 +- src/file_service.c | 1158 ++-- src/master_rpc.c | 397 +- src/util.c | 160 +- 21 files changed, 12519 insertions(+), 11599 deletions(-) diff --git a/include/conf.h b/include/conf.h index ce49357..de5375a 100644 --- a/include/conf.h +++ b/include/conf.h @@ -18,12 +18,12 @@ * \note * milli seconds */ -#define MAX_LOG_FILE 3 -#define MAX_LOG_LINE 1000 -#define SLAVE_LOG_PATH "/tmp/.dbox.service/log/" +#define MAX_LOG_FILE 3 +#define MAX_LOG_LINE 1000 +#define SLAVE_LOG_PATH "/tmp/.dbox.service/log/" #if !defined(VCONFKEY_MASTER_STARTED) -#define VCONFKEY_MASTER_STARTED "memory/data-provider-master/started" +#define VCONFKEY_MASTER_STARTED "memory/data-provider-master/started" #endif #if !defined(VCONFKEY_MASTER_CLIENT_ADDR) @@ -40,5 +40,9 @@ extern double conf_event_filter(void); extern void conf_set_event_filter(double filter); extern void conf_set_direct_update(int flag); extern int conf_direct_update(void); +extern int conf_extra_buffer_count(void); +extern void conf_set_extra_buffer_count(int buffer_count); +extern dynamicbox_status_e conf_last_status(void); +extern void conf_set_last_status(dynamicbox_status_e status); /* End of a file */ diff --git a/include/debug.h b/include/debug.h index d06862c..a6563ee 100644 --- a/include/debug.h +++ b/include/debug.h @@ -15,8 +15,8 @@ */ #if !defined(FLOG) -#define DbgPrint(format, arg...) SECURE_LOGD(format, ##arg) -#define ErrPrint(format, arg...) SECURE_LOGE(format, ##arg) +#define DbgPrint(format, arg...) SECURE_LOGD(format, ##arg) +#define ErrPrint(format, arg...) SECURE_LOGE(format, ##arg) #else extern FILE *__file_log_fp; #define DbgPrint(format, arg...) do { fprintf(__file_log_fp, "[LOG] [%s/%s:%d] " format, util_basename(__FILE__), __func__, __LINE__, ##arg); fflush(__file_log_fp); } while (0) diff --git a/include/dlist.h b/include/dlist.h index cd1a421..3f19827 100644 --- a/include/dlist.h +++ b/include/dlist.h @@ -15,18 +15,18 @@ */ #define dlist_remove_data(list, data) do { \ - struct dlist *l; \ - l = dlist_find_data(list, data); \ - list = dlist_remove(list, l); \ + struct dlist *l; \ + l = dlist_find_data(list, data); \ + list = dlist_remove(list, l); \ } while (0) #define dlist_foreach(list, l, data) \ - for ((l) = (list); (l) && ((data) = dlist_data(l)); (l) = dlist_next(l)) + for ((l) = (list); (l) && ((data) = dlist_data(l)); (l) = dlist_next(l)) #define dlist_foreach_safe(list, l, n, data) \ - for ((l) = (list), (n) = dlist_next(l); \ - (l) && ((data) = dlist_data(l)); \ - (l) = (n), (n) = dlist_next(l)) + for ((l) = (list), (n) = dlist_next(l); \ + (l) && ((data) = dlist_data(l)); \ + (l) = (n), (n) = dlist_next(l)) struct dlist; diff --git a/include/dynamicbox.h b/include/dynamicbox.h index da1ed9e..c69a85d 100644 --- a/include/dynamicbox.h +++ b/include/dynamicbox.h @@ -54,7 +54,7 @@ typedef struct dynamicbox *dynamicbox_h; * @details Viewer should send these events to dynamicbox. * @since_tizen 2.3 */ -enum dynamicbox_mouse_event_type { +typedef enum dynamicbox_mouse_event_type { DBOX_MOUSE_EVENT_MASK = 0x20000000, /**< Mask value for mouse event */ DBOX_MOUSE_EVENT_GBAR_MASK = 0x10000000, /**< Mask value for Glance Bar event */ DBOX_MOUSE_EVENT_DBOX_MASK = 0x40000000, /**< Mask value for Dynamic Box event */ @@ -99,9 +99,9 @@ enum dynamicbox_mouse_event_type { DBOX_GBAR_MOUSE_UNSET = DBOX_MOUSE_EVENT_GBAR_MASK | DBOX_MOUSE_EVENT_MASK | DBOX_MOUSE_EVENT_UNSET, /**< Mouse event, stop feeding event by master */ DBOX_MOUSE_EVENT_MAX = 0xFFFFFFFF /**< Unknown event */ -}; +} dynamicbox_mouse_event_type_e; -enum dynamicbox_key_event_type { +typedef enum dynamicbox_key_event_type { DBOX_KEY_EVENT_MASK = 0x80000000, /**< Mask value for key event */ DBOX_KEY_EVENT_GBAR_MASK = 0x10000000, /**< Mask value for Glance Bar event */ DBOX_KEY_EVENT_DBOX_MASK = 0x40000000, /**< Mask value for Dynamic Box event */ @@ -128,7 +128,7 @@ enum dynamicbox_key_event_type { DBOX_GBAR_KEY_FOCUS_OUT = DBOX_KEY_EVENT_MASK | DBOX_KEY_EVENT_GBAR_MASK | DBOX_KEY_EVENT_FOCUS_OUT, /**< Key event, focus out */ DBOX_KEY_EVENT_MAX = 0xFFFFFFFF /**< Unknown event */ -}; +} dynamicbox_key_event_type_e; /** * @internal @@ -136,7 +136,7 @@ enum dynamicbox_key_event_type { * @details These events are sync'd with Tizen accessibility event set. * @since_tizen 2.3 */ -enum dynamicbox_access_event_type { +typedef enum dynamicbox_access_event_type { DBOX_ACCESS_EVENT_GBAR_MASK = 0x10000000, /**< Glance Bar Accessibilivent mask */ DBOX_ACCESS_EVENT_DBOX_MASK = 0x20000000, /**< Dynamic Box Accessibility event mask */ @@ -173,21 +173,21 @@ enum dynamicbox_access_event_type { DBOX_GBAR_ACCESS_READ = DBOX_ACCESS_EVENT_GBAR_MASK | DBOX_ACCESS_EVENT_READ, /**< Highlight an object */ DBOX_GBAR_ACCESS_ENABLE = DBOX_ACCESS_EVENT_GBAR_MASK | DBOX_ACCESS_EVENT_ENABLE, /**< Enable highlight and read ability */ DBOX_GBAR_ACCESS_EVENT_MAX = 0xFFFFFFFF -}; +} dynamicbox_access_event_type_e; /** * @internal * @brief Enumeration for Dynamic Box content type. * @since_tizen 2.3 */ -enum dynamicbox_type { +typedef enum dynamicbox_type { DBOX_CONTENT_TYPE_IMAGE = 0x01, /**< Contents of a dynamicbox is based on the image file */ DBOX_CONTENT_TYPE_BUFFER = 0x02, /**< Contents of a dynamicbox is based on canvas buffer(shared) */ DBOX_CONTENT_TYPE_TEXT = 0x04, /**< Contents of a dynamicbox is based on formatted text file */ DBOX_CONTENT_TYPE_RESOURCE_ID = 0x08, /**< Contens of a dynamicbox is shared by the resource id(depends on window system) */ DBOX_CONTENT_TYPE_UIFW = 0x10, /**< Using UI F/W resource for sharing content & event */ DBOX_CONTENT_TYPE_INVALID = 0xFF /**< Unknown Dynamic Box type */ -}; +} dynamicbox_type_e; /** * @internal @@ -195,9 +195,11 @@ enum dynamicbox_type { * @details These events will be sent from the provider. * @since_tizen 2.3 */ -enum dynamicbox_event_type { /**< dynamicbox_event_handler_set Event list */ +typedef enum dynamicbox_event_type { /**< dynamicbox_event_handler_set Event list */ DBOX_EVENT_DBOX_UPDATED, /**< Contents of the given dynamicbox is updated */ + DBOX_EVENT_DBOX_EXTRA_UPDATED, DBOX_EVENT_GBAR_UPDATED, /**< Contents of the given pd is updated */ + DBOX_EVENT_GBAR_EXTRA_UPDATED, DBOX_EVENT_CREATED, /**< A new dynamicbox is created */ DBOX_EVENT_DELETED, /**< A dynamicbox is deleted */ @@ -227,33 +229,40 @@ enum dynamicbox_event_type { /**< dynamicbox_event_handler_se DBOX_EVENT_EXTRA_INFO_UPDATED, /**< Extra information is updated */ + DBOX_EVENT_DBOX_EXTRA_BUFFER_CREATED, /**< DBOX Extra Buffer created event */ + DBOX_EVENT_GBAR_EXTRA_BUFFER_CREATED, /**< GBAR Extra Buffer created event */ + + DBOX_EVENT_DBOX_EXTRA_BUFFER_DESTROYED, /**< DBOX Extra Buffer destroyed event */ + DBOX_EVENT_GBAR_EXTRA_BUFFER_DESTROYED, /**< DBOX Extra Buffer destroyed event */ + DBOX_EVENT_IGNORED = 0xFF /**< Request is ignored */ -}; +} dynamicbox_event_type_e; /** * @internal * @brief Enumeration for Dynamicbox option types. * @since_tizen 2.3 */ -enum dynamicbox_option_type { - DBOX_OPTION_MANUAL_SYNC, /**< Sync frame manually */ - DBOX_OPTION_FRAME_DROP_FOR_RESIZE, /**< Drop frames while resizing */ - DBOX_OPTION_SHARED_CONTENT, /**< Use only one real instance for multiple fake instances if user creates dbox for same content */ - DBOX_OPTION_DIRECT_UPDATE, /**< Use the private socket for receiving updated event */ +typedef enum dynamicbox_option_type { + DBOX_OPTION_MANUAL_SYNC, /**< Sync frame manually */ + DBOX_OPTION_FRAME_DROP_FOR_RESIZE, /**< Drop frames while resizing */ + DBOX_OPTION_SHARED_CONTENT, /**< Use only one real instance for multiple fake instances if user creates dbox for same content */ + DBOX_OPTION_DIRECT_UPDATE, /**< Use the private socket for receiving updated event */ + DBOX_OPTION_EXTRA_BUFFER_CNT, /**< Extra buffer count, ReadOnly value */ - DBOX_OPTION_ERROR = 0xFFFFFFFF /**< To specify the size of this enumeration type */ -}; + DBOX_OPTION_ERROR = 0xFFFFFFFF /**< To specify the size of this enumeration type */ +} dynamicbox_option_type_e; /** * @internal * @brief Reason of faults * @since_tizen 2.3 */ -enum dynamicbox_fault_type { +typedef enum dynamicbox_fault_type { DBOX_FAULT_DEACTIVATED, /**< Dynamicbox is deactivated by its fault operation */ DBOX_FAULT_PROVIDER_DISCONNECTED, /**< Provider is disconnected */ DBOX_FAULT_MAX = 0xFF /**< To specify the size of this enumeration type, some compiler enjoy of this kind of notation */ -}; +} dynamicbox_fault_type_e; /** * @internal @@ -261,25 +270,23 @@ enum dynamicbox_fault_type { * @details Must be sync'd with a provider. * @since_tizen 2.3 */ -enum dynamicbox_visible_state { +typedef enum dynamicbox_visible_state { DBOX_SHOW = 0x00, /**< Dynamicbox is shown. Default state */ DBOX_HIDE = 0x01, /**< Dynamicbox is hidden, Update timer will not be freezed. but you cannot receive any updates events. */ DBOX_HIDE_WITH_PAUSE = 0x02, /**< Dynamicbox is hidden, it will pause the update timer, but if a dynamicbox updates its contents, update event will be triggered */ DBOX_VISIBLE_ERROR = 0xFF /**< To specify the size of this enumeration type */ -}; +} dynamicbox_visible_state_e; /** * @internal - * @brief Accessibility Event Information + * @brief Accessibility Event type * @since_tizen 2.3 + * @see dynamicbox_feed_access_event() */ -struct dynamicbox_access_event_info { - double x; /**< X Coordinates that the event occurred */ - double y; /**< Y Coordinates that the event occurred */ - enum _dynamicbox_access_type { - DBOX_ACCESS_TYPE_NONE = 0x00, /**< Initialized */ +typedef enum dynamicbox_access_info_type { + DBOX_ACCESS_TYPE_NONE = 0x00, /**< Initialized */ DBOX_ACCESS_TYPE_DOWN = 0x00, /**< Mouse down */ DBOX_ACCESS_TYPE_MOVE = 0x01, /**< Mouse move */ @@ -292,9 +299,19 @@ struct dynamicbox_access_event_info { DBOX_ACCESS_TYPE_DISABLE = 0x00, /**< Disable */ DBOX_ACCESS_TYPE_ENABLE = 0x01 /**< Enable */ - } type; +} dynamicbox_access_info_type_e; + +/** + * @internal + * @brief Accessibility Event Information + * @since_tizen 2.3 + */ +typedef struct dynamicbox_access_event_info { + double x; /**< X Coordinates that the event occurred */ + double y; /**< Y Coordinates that the event occurred */ + dynamicbox_access_info_type_e type; /**< Accessibility event type */ int info; /**< Extra information for this event */ -}; +} *dynamicbox_access_event_info_t; /** * @internal @@ -302,10 +319,10 @@ struct dynamicbox_access_event_info { * @since_tizen 2.3 */ typedef struct dynamicbox_damage_region { - int x; /**< Coordinates X of Left-Top corner */ - int y; /**< Coordinates Y of Left-Top corner */ - int w; /**< Damage'd Width */ - int h; /**< Damage'd Height */ + int x; /**< Coordinates X of Left-Top corner */ + int y; /**< Coordinates Y of Left-Top corner */ + int w; /**< Damage'd Width */ + int h; /**< Damage'd Height */ } dynamicbox_damage_region_t; /** @@ -329,6 +346,22 @@ typedef struct dynamicbox_key_event_info { /** * @internal + * @brief Text Event Information + * @since_tizen 2.3 + */ +typedef struct dynamicbox_text_event { + const char *emission; + const char *source; + struct { + double sx; + double sy; + double ex; + double ey; + } geometry; +} *dynamicbox_text_event_t; + +/** + * @internal * @brief Structure for TEXT type dynamicbox contents handling opertators. * @since_tizen 2.3 */ @@ -399,7 +432,7 @@ typedef int (*dynamicbox_fault_handler_cb)(enum dynamicbox_fault_type type, cons * @return @c EXIT_FAILURE delete this event callback from the event callback list * @return @c EXIT_SUCCESS successfully handled, keep this callback in the event callback list */ -typedef int (*dynamicbox_event_handler_cb)(dynamicbox_h handler, enum dynamicbox_event_type event, void *data); +typedef int (*dynamicbox_event_handler_cb)(dynamicbox_h handler, dynamicbox_event_type_e event, void *data); /** * @internal @@ -424,7 +457,7 @@ typedef int (*dynamicbox_auto_launch_handler_cb)(dynamicbox_h handler, const cha * @param[in] event_filter If the dynamicbox_feed_mouse_event() is called again in this secs, it will be ignored and the dynamicbox_feed_mouse_event() will returns DBOX_STATUS_ERROR_BUSY status code * @param[in] use_thread If this value has true, the viewer library will create a new thread to communicate with master service * @privlevel public - * @privilege %http://tizen.org/privilege/dynamicbox.viewer + * @privilege %http://tizen.org/privilege/dynamicbox * @return int Integer, Dynamicbox status code * @retval #DBOX_STATUS_ERROR_NONE if successfully initialized. * @retval #DBOX_STATUS_ERROR_OUT_OF_MEMORY If a memory is not enough to do this operation. @@ -439,7 +472,7 @@ extern int dynamicbox_init(void *disp, int prevent_overwrite, double event_filte * @brief Finalizes the dynamicbox system. * @since_tizen 2.3 * @privlevel public - * @privilege %http://tizen.org/privilege/dynamicbox.viewer + * @privilege %http://tizen.org/privilege/dynamicbox * @return int * @retval #DBOX_STATUS_SUCCES if success * @retval #DBOX_STATUS_ERROR_INVALID_PARAMETER if dynamicbox_init is not called @@ -452,7 +485,7 @@ extern int dynamicbox_fini(void); * @brief Notifies the status of a client ("it is paused") to the provider. * @since_tizen 2.3 * @privlevel public - * @privilege %http://tizen.org/privilege/dynamicbox.viewer + * @privilege %http://tizen.org/privilege/dynamicbox * @return int * @retval #DBOX_STATUS_ERROR_NONE if success * @retval #DBOX_STATUS_ERROR_FAULT if it failed to send state (paused) info @@ -465,7 +498,7 @@ extern int dynamicbox_viewer_set_paused(void); * @brief Notifies the status of client ("it is resumed") to the provider. * @since_tizen 2.3 * @privlevel public - * @privilege %http://tizen.org/privilege/dynamicbox.viewer + * @privilege %http://tizen.org/privilege/dynamicbox * @return int * @retval #DBOX_STATUS_ERROR_NONE if success * @retval #DBOX_STATUS_ERROR_FAULT if it failed to send state (resumed) info @@ -508,22 +541,23 @@ extern int dynamicbox_viewer_set_resumed(void); * It can be initialized only after getting the return callback with "ret == #DBOX_STATUS_ERROR_NONE" * This function is Asynchronous, so you will get result of add requst from @a cb, if you failed to send request to create a new dynamicbox, * This function will returns proper error code + * If this returns @c NULL, you can get the reason of failure using dynamicbox_last_status() * @param[in] dbox_id DynamicBox Id * @param[in] content Contents that will be given to the dynamicbox instance * @param[in] cluster Main group * @param[in] category Sub group - * @param[in] period Update period (@c DEFAULT_PERIOD can be used for this; this argument will be used to specify the period of updating contents of a dynamicbox) + * @param[in] period Update period (@c DBOX_DEFAULT_PERIOD can be used for this; this argument will be used to specify the period of updating contents of a dynamicbox) * @param[in] type Size type (defined from libdynamicbox-service package) * @param[in] cb After the request is sent to the master provider, this callback will be called * @param[in] data This data will be passed to the callback * @privlevel public - * @privilege %http://tizen.org/privilege/dynamicbox.viewer + * @privilege %http://tizen.org/privilege/dynamicbox * @return handle * @retval Handle Dynamicbox handle but not yet initialized * @retval @c NULL if it fails to create a handle * @see dynamicbox_ret_cb */ -extern dynamicbox_h dynamicbox_add(const char *dbox_id, const char *content, const char *cluster, const char *category, double period, enum dynamicbox_size_type type, dynamicbox_ret_cb cb, void *data); +extern dynamicbox_h dynamicbox_add(const char *dbox_id, const char *content, const char *cluster, const char *category, double period, dynamicbox_size_type_e type, dynamicbox_ret_cb cb, void *data); /** * @internal @@ -540,7 +574,7 @@ extern dynamicbox_h dynamicbox_add(const char *dbox_id, const char *content, con * @param[in] cb Return callback * @param[in] data User data for return callback * @privlevel public - * @privilege %http://tizen.org/privilege/dynamicbox.viewer + * @privilege %http://tizen.org/privilege/dynamicbox * @return int * @retval #DBOX_STATUS_ERROR_INVALID_PARAMETER Invalid argument * @retval #DBOX_STATUS_ERROR_BUSY Already in process @@ -548,7 +582,7 @@ extern dynamicbox_h dynamicbox_add(const char *dbox_id, const char *content, con * @retval #DBOX_STATUS_ERROR_NONE Successfully sent, return callack will be called * @see dynamicbox_ret_cb */ -extern int dynamicbox_del(dynamicbox_h handler, enum dynamicbox_delete_type type, dynamicbox_ret_cb cb, void *data); +extern int dynamicbox_del(dynamicbox_h handler, dynamicbox_delete_type_e type, dynamicbox_ret_cb cb, void *data); /** * @internal @@ -565,7 +599,7 @@ extern int dynamicbox_del(dynamicbox_h handler, enum dynamicbox_delete_type type * @retval #DBOX_STATUS_ERROR_OUT_OF_MEMORY Not enough memory * @see dynamicbox_unset_event_handler() */ -extern int dynamicbox_set_event_handler(dynamicbox_event_handler_cb cb, void *data); +extern int dynamicbox_add_event_handler(dynamicbox_event_handler_cb cb, void *data); /** * @internal @@ -576,7 +610,7 @@ extern int dynamicbox_set_event_handler(dynamicbox_event_handler_cb cb, void *da * @retval pointer Pointer of 'data' which is used with the dynamicbox_set_event_handler * @see dynamicbox_set_event_handler() */ -extern void *dynamicbox_unset_event_handler(dynamicbox_event_handler_cb cb); +extern void *dynamicbox_remove_event_handler(dynamicbox_event_handler_cb cb); /** * @internal @@ -591,7 +625,7 @@ extern void *dynamicbox_unset_event_handler(dynamicbox_event_handler_cb cb); * @retval #DBOX_STATUS_ERROR_OUT_OF_MEMORY Not enough memory * @see dynamicbox_unset_fault_handler() */ -extern int dynamicbox_set_fault_handler(dynamicbox_fault_handler_cb cb, void *data); +extern int dynamicbox_add_fault_handler(dynamicbox_fault_handler_cb cb, void *data); /** * @internal @@ -602,7 +636,7 @@ extern int dynamicbox_set_fault_handler(dynamicbox_fault_handler_cb cb, void *da * @retval pointer Pointer of 'data' which is used with the dynamicbox_set_fault_handler * @see dynamicbox_set_fault_handler() */ -extern void *dynamicbox_unset_fault_handler(dynamicbox_fault_handler_cb cb); +extern void *dynamicbox_remove_fault_handler(dynamicbox_fault_handler_cb cb); /** * @internal @@ -619,7 +653,7 @@ extern void *dynamicbox_unset_fault_handler(dynamicbox_fault_handler_cb cb); * @param[in] cb Result callback * @param[in] data Callback data * @privlevel public - * @privilege %http://tizen.org/privilege/dynamicbox.viewer + * @privilege %http://tizen.org/privilege/dynamicbox * @return int type * @retval #DBOX_STATUS_ERROR_NONE Successfully sent a request * @retval #DBOX_STATUS_ERROR_INVALID_PARAMETER Invalid argument @@ -662,7 +696,7 @@ extern int dynamicbox_activate(const char *dbox_id, dynamicbox_ret_cb cb, void * * @param[in] cb Result callback of the resize operation * @param[in] data User data for return callback * @privlevel public - * @privilege %http://tizen.org/privilege/dynamicbox.viewer + * @privilege %http://tizen.org/privilege/dynamicbox * @return int type * @retval #DBOX_STATUS_ERROR_INVALID_PARAMETER Invalid argument * @retval #DBOX_STATUS_ERROR_BUSY Previous request of resize is in progress @@ -671,7 +705,7 @@ extern int dynamicbox_activate(const char *dbox_id, dynamicbox_ret_cb cb, void * * @retval #DBOX_STATUS_ERROR_FAULT Failed to make a request * @see dynamicbox_ret_cb */ -extern int dynamicbox_resize(dynamicbox_h handler, enum dynamicbox_size_type type, dynamicbox_ret_cb cb, void *data); +extern int dynamicbox_resize(dynamicbox_h handler, dynamicbox_size_type_e type, dynamicbox_ret_cb cb, void *data); /** * @internal @@ -681,7 +715,7 @@ extern int dynamicbox_resize(dynamicbox_h handler, enum dynamicbox_size_type typ * @param[in] x Rational X of the content width * @param[in] y Rational Y of the content height * @privlevel public - * @privilege %http://tizen.org/privilege/dynamicbox.viewer + * @privilege %http://tizen.org/privilege/dynamicbox * @return int * @retval #DBOX_STATUS_ERROR_INVALID_PARAMETER Invalid argument * @retval #DBOX_STATUS_ERROR_FAULT Unrecoverable error occurred @@ -703,7 +737,7 @@ extern int dynamicbox_click(dynamicbox_h handler, double x, double y); * @param[in] cb Result callback for changing the cluster/category of a dynamicbox * @param[in] data User data for the result callback * @privlevel public - * @privilege %http://tizen.org/privilege/dynamicbox.viewer + * @privilege %http://tizen.org/privilege/dynamicbox * @return int * @retval #DBOX_STATUS_ERROR_NONE Request is successfully sent. the return callback will be called * @retval #DBOX_STATUS_ERROR_BUSY Previous request is not finished yet @@ -735,10 +769,12 @@ extern int dynamicbox_get_group(dynamicbox_h handler, const char **cluster, cons * @since_tizen 2.3 * @remarks If this function returns 0.0f, it means the dynamicbox has no update period or the handle is not valid. * This function only works after the return callback of dynamicbox_create fucntion is called. + * If this returns negative value, you can get the reason of failure using dynamicbox_last_status() * @param[in] handler Handler of a dynamicbox instance * @return double - * @retval Current update period of a dynamicbox - * @retval 0.0f This means the box has no update period or the handles is not valid + * @retval >0 Current update period of a dynamicbox + * @retval 0.0f The box has no update period + * @retval -1.0f Failed to get the period info */ extern double dynamicbox_period(dynamicbox_h handler); @@ -755,7 +791,7 @@ extern double dynamicbox_period(dynamicbox_h handler); * @param[in] cb Result callback of changing the update period of this dynamicbox * @param[in] data User data for the result callback * @privlevel public - * @privilege %http://tizen.org/privilege/dynamicbox.viewer + * @privilege %http://tizen.org/privilege/dynamicbox * @return int * @retval #DBOX_STATUS_ERROR_NONE Successfully done * @retval #DBOX_STATUS_ERROR_INVALID_PARAMETER Invalid argument @@ -769,6 +805,8 @@ extern int dynamicbox_set_period(dynamicbox_h handler, double period, dynamicbox /** * @internal * @brief Checks whether the given dynamicbox is a text type or not. + * @remarks + * If this returns DBOX_CONTENT_TYPE_INVALID, you can get the reason of failure using dynamicbox_last_status() * @since_tizen 2.3 * @param[in] handler Handler of a dynamicbox instance * @param[in] gbar 1 for Glance Bar or 0 @@ -781,11 +819,12 @@ extern int dynamicbox_set_period(dynamicbox_h handler, double period, dynamicbox * @retval #DBOX_CONTENT_TYPE_INVALID Invalid type * @see dynamicbox_type() */ -extern enum dynamicbox_type dynamicbox_type(dynamicbox_h handler, int gbar); +extern dynamicbox_type_e dynamicbox_type(dynamicbox_h handler, int gbar); /** * @internal * @brief Checks if the given dynamicbox is created by user or not. + * @remarks if this returns negative value, you can get the reason of failure using dynamicbox_last_status() * @since_tizen 2.3 * @details If the dynamicbox instance is created by a system this will return 0. * @param[in] handler Handler of a dynamicbox instance @@ -801,6 +840,7 @@ extern int dynamicbox_is_created_by_user(dynamicbox_h handler); /** * @internal * @brief Gets content information string of the given dynamicbox. + * @remarks if this returns @c NULL, you can get the reason of failure using dynamicbox_last_status() * @since_tizen 2.3 * @param[in] handler Handler of a dynamicbox instance * @return const char * @@ -819,6 +859,7 @@ extern const char *dynamicbox_content(dynamicbox_h handler); * @remarks The title returned by this API can be read by TTS. * But it is just recomendation for the homescreen. * So, to read it or not depends on its implementation. + * if this returns @c NULL, you can get the reason of failure using dynamicbox_last_status() * @param[in] handler Handler of a dynamicbox instance * @return const char * * @retval sub Cluster name @@ -830,6 +871,7 @@ extern const char *dynamicbox_title(dynamicbox_h handler); * @internal * @brief Gets the filename of the given dynamicbox, if it is an IMAGE type dynamicbox. * @details If the box is developed as an image format to represent its contents, the homescreen should know its image file name. + * @remarks if this returns @c NULL, you can get the reason of failure using dynamicbox_last_status() * @since_tizen 2.3 * @param[in] handler Handler of a dynamicbox instance * @return const char * @@ -841,6 +883,7 @@ extern const char *dynamicbox_filename(dynamicbox_h handler); /** * @internal * @brief Gets the package name of the given dynamicbox handler. + * @remarks if this returns @c NULL, you can get the reason of failure using dynamicbox_last_status() * @since_tizen 2.3 * @param[in] handler Handler of a dynamicbox instance * @return const char * @@ -852,6 +895,7 @@ extern const char *dynamicbox_pkgname(dynamicbox_h handler); /** * @internal * @brief Gets the priority of a current content. + * @remarks if this returns negative value, you can get the reason of failure using dynamicbox_last_status() * @since_tizen 2.3 * @param[in] handler Handler of a dynamicbox instance * @return double @@ -868,12 +912,12 @@ extern double dynamicbox_priority(dynamicbox_h handler); * @param[in] handler Handler of a dynamicbox instance * @param[in] gbar 1 for Glance Bar or 0 * @privlevel public - * @privilege %http://tizen.org/privilege/dynamicbox.viewer + * @privilege %http://tizen.org/privilege/dynamicbox * @return void * * @retval address Address of a Frame Buffer - * @retval @c NULL If it fails to get fb address + * @retval @c NULL If it fails to get buffer address */ -extern void *dynamicbox_acquire_fb(dynamicbox_h handler, int gbar); +extern void *dynamicbox_acquire_buffer(dynamicbox_h handler, int gbar); /** * @internal @@ -881,13 +925,13 @@ extern void *dynamicbox_acquire_fb(dynamicbox_h handler, int gbar); * @since_tizen 2.3 * @param[in] buffer Buffer * @privlevel public - * @privilege %http://tizen.org/privilege/dynamicbox.viewer + * @privilege %http://tizen.org/privilege/dynamicbox * @return int * @retval #DBOX_STATUS_ERROR_INVALID_PARAMETER Invalid argument * @retval #DBOX_STATUS_ERROR_NONE Successfully done - * @see dynamicbox_acquire_fb() + * @see dynamicbox_acquire_buffer() */ -extern int dynamicbox_release_fb(void *buffer); +extern int dynamicbox_release_buffer(void *buffer); /** * @internal @@ -899,26 +943,28 @@ extern int dynamicbox_release_fb(void *buffer); * @retval #DBOX_STATUS_ERROR_FAULT Unrecoverable error occurred * @retval refcnt Positive integer value including ZERO */ -extern int dynamicbox_fb_refcnt(void *buffer); +extern int dynamicbox_buffer_refcnt(void *buffer); /** * @internal * @brief Gets the size of the Dynamicbox. + * @remarks + * If this returns DBOX_SIZE_TYPE_UNKNOWN, you can get the reason of failure using dynamicbox_last_status() * @since_tizen 2.3 * @param[in] handler Handler of a dynamicbox instance - * @return enum dynamicbox_size_type + * @return dynamicbox_size_type_e * @retval #DBOX_SIZE_TYPE_NxM N by M size * @retval #DBOX_SIZE_TYPE_UNKNOWN Invalid handler or size type is not defined yet */ -extern enum dynamicbox_size_type dynamicbox_size(dynamicbox_h handler); +extern dynamicbox_size_type_e dynamicbox_size(dynamicbox_h handler); /** * @internal * @brief Gets the size of the Glance Bar. * @since_tizen 2.3 * @param[in] handler Handler of a dynamicbox instance - * @param[out] w - * @param[out] h + * @param[out] w Width of glance bar in pixels + * @param[out] h Height of glance bar in pixels * @return int type * @retval #DBOX_STATUS_ERROR_INVALID_PARAMETER Invalid parameters are used * @retval #DBOX_STATUS_ERROR_NONE Successfully done @@ -930,13 +976,15 @@ extern int dynamicbox_get_glance_bar_size(dynamicbox_h handler, int *w, int *h); * @brief Gets a list of the supported sizes of a given handler. * @since_tizen 2.3 * @param[in] handler Handler of a dynamicbox instance - * @param[out] cnt - * @param[out] size_list + * @param[in] size_list Array buffer for getting the size types + * @param[in] cnt size of array + * @param[out] cnt Count of returned size types + * @param[out] size_list Array of size types * @return int type * @retval #DBOX_STATUS_ERROR_INVALID_PARAMETER Invalid argument * @retval #DBOX_STATUS_ERROR_NONE Successfully done */ -extern int dynamicbox_get_supported_sizes(dynamicbox_h handler, int *cnt, int *size_list); +extern int dynamicbox_get_supported_sizes(dynamicbox_h handler, int *cnt, dynamicbox_size_type_e *size_list); /** * @internal @@ -948,7 +996,7 @@ extern int dynamicbox_get_supported_sizes(dynamicbox_h handler, int *cnt, int *s * @retval #DBOX_STATUS_ERROR_INVALID_PARAMETER Invalid argument * @retval size Size in bytes of the dynamicbox buffer */ -extern int dynamicbox_fb_buffer_size(dynamicbox_h handler, int gbar); +extern int dynamicbox_buffer_size(dynamicbox_h handler, int gbar); /** * @internal @@ -959,7 +1007,7 @@ extern int dynamicbox_fb_buffer_size(dynamicbox_h handler, int gbar); * @param[in] x Coordinates of X axis * @param[in] y Coordinates of Y axis * @privlevel public - * @privilege %http://tizen.org/privilege/dynamicbox.viewer + * @privilege %http://tizen.org/privilege/dynamicbox * @return int * @retval #DBOX_STATUS_ERROR_INVALID_PARAMETER Invalid argument * @retval #DBOX_STATUS_ERROR_BUSY Previous operation is not finished yet @@ -968,7 +1016,7 @@ extern int dynamicbox_fb_buffer_size(dynamicbox_h handler, int gbar); * @see dynamicbox_feed_access_event() * @see dynamicbox_feed_key_event() */ -extern int dynamicbox_feed_mouse_event(dynamicbox_h handler, enum dynamicbox_mouse_event_type type, dynamicbox_mouse_event_info_t info); +extern int dynamicbox_feed_mouse_event(dynamicbox_h handler, dynamicbox_mouse_event_type_e type, dynamicbox_mouse_event_info_t info); /** * @internal @@ -983,7 +1031,7 @@ extern int dynamicbox_feed_mouse_event(dynamicbox_h handler, enum dynamicbox_mou * @param[in] cb Result callback function * @param[in] data Callback data * @privlevel public - * @privilege %http://tizen.org/privilege/dynamicbox.viewer + * @privilege %http://tizen.org/privilege/dynamicbox * @return int * @retval #DBOX_STATUS_ERROR_INVALID_PARAMETER Invalid argument * @retval #DBOX_STATUS_ERROR_BUSY Previous operation is not finished yet @@ -992,7 +1040,7 @@ extern int dynamicbox_feed_mouse_event(dynamicbox_h handler, enum dynamicbox_mou * @see dynamicbox_feed_mouse_event() * @see dynamicbox_feed_key_event() */ -extern int dynamicbox_feed_access_event(dynamicbox_h handler, enum dynamicbox_access_event_type type, struct dynamicbox_access_event_info *info, dynamicbox_ret_cb cb, void *data); +extern int dynamicbox_feed_access_event(dynamicbox_h handler, dynamicbox_access_event_type_e type, dynamicbox_access_event_info_t info, dynamicbox_ret_cb cb, void *data); /** * @internal @@ -1006,7 +1054,7 @@ extern int dynamicbox_feed_access_event(dynamicbox_h handler, enum dynamicbox_ac * @param[in] cb Result callback * @param[in] data Callback data * @privlevel public - * @privilege %http://tizen.org/privilege/dynamicbox.viewer + * @privilege %http://tizen.org/privilege/dynamicbox * @return int * @retval #DBOX_STATUS_ERROR_INVALID_PARAMETER Invalid argument * @retval #DBOX_STATUS_ERROR_BUSY Previous operation is not finished yet @@ -1015,7 +1063,7 @@ extern int dynamicbox_feed_access_event(dynamicbox_h handler, enum dynamicbox_ac * @see dynamicbox_feed_mouse_event() * @see dynamicbox_feed_access_event() */ -extern int dynamicbox_feed_key_event(dynamicbox_h handler, enum dynamicbox_key_event_type type, dynamicbox_key_event_info_t info, dynamicbox_ret_cb cb, void *data); +extern int dynamicbox_feed_key_event(dynamicbox_h handler, dynamicbox_key_event_type_e type, dynamicbox_key_event_info_t info, dynamicbox_ret_cb cb, void *data); /** * @internal @@ -1032,7 +1080,7 @@ extern int dynamicbox_feed_key_event(dynamicbox_h handler, enum dynamicbox_key_e * @param[in] cb Result callback * @param[in] data Callback data * @privlevel public - * @privilege %http://tizen.org/privilege/dynamicbox.viewer + * @privilege %http://tizen.org/privilege/dynamicbox * @return int * @retval #DBOX_STATUS_ERROR_INVALID_PARAMETER Invalid parameters * @see dynamicbox_ret_cb @@ -1092,7 +1140,7 @@ extern int dynamicbox_has_glance_bar(dynamicbox_h handler); * @param[in] cb Result callback * @param[in] data Callback data * @privlevel public - * @privilege %http://tizen.org/privilege/dynamicbox.viewer + * @privilege %http://tizen.org/privilege/dynamicbox * @return int * @retval #DBOX_STATUS_ERROR_NONE Successfully done * @retval #DBOX_STATUS_ERROR_INVALID_PARAMETER Invalid argument @@ -1112,7 +1160,7 @@ extern int dynamicbox_create_glance_bar(dynamicbox_h handler, double x, double y * @param[in] x 0.0 ~ 1.0, 0.0 indicates the coordinate X of left of dynamicbox * @param[in] y 0.0 ~ 1.0, 0.0 indicates the coordinate Y of top of dynamicbox * @privlevel public - * @privilege %http://tizen.org/privilege/dynamicbox.viewer + * @privilege %http://tizen.org/privilege/dynamicbox * @return int * @retval #DBOX_STATUS_ERROR_NONE If sending a request for updating position of the Glance Bar has been done successfully * @retval #DBOX_STATUS_ERROR_FAULT Unrecoverable error occurred @@ -1130,7 +1178,7 @@ extern int dynamicbox_move_glance_bar(dynamicbox_h handler, double x, double y); * @param[in] cb Callback function * @param[in] data Callback data * @privlevel public - * @privilege %http://tizen.org/privilege/dynamicbox.viewer + * @privilege %http://tizen.org/privilege/dynamicbox * @return int * @retval #DBOX_STATUS_ERROR_INVALID_PARAMETER Invalid argument * @retval #DBOX_STATUS_ERROR_FAULT Unrecoverable error occurred @@ -1183,14 +1231,14 @@ extern int dynamicbox_set_text_handler(dynamicbox_h handler, int gbar, dynamicbo * @param[in] cb Result callback * @param[in] data Callback data * @privlevel public - * @privilege %http://tizen.org/privilege/dynamicbox.viewer + * @privilege %http://tizen.org/privilege/dynamicbox * @return int * @retval #DBOX_STATUS_ERROR_INVALID_PARAMETER Invalid parameters * @retval #DBOX_STATUS_ERROR_FAULT Unrecoverable error occurred * @retval #DBOX_STATUS_ERROR_NONE Successfully emitted * @see dynamicbox_ret_cb */ -extern int dynamicbox_emit_text_signal(dynamicbox_h handler, const char *emission, const char *source, double sx, double sy, double ex, double ey, dynamicbox_ret_cb cb, void *data); +extern int dynamicbox_emit_text_signal(dynamicbox_h handler, dynamicbox_text_event_t event_info, dynamicbox_ret_cb cb, void *data); /** * @internal @@ -1227,7 +1275,7 @@ extern void *dynamicbox_data(dynamicbox_h handler); * @param[in] cluster Cluster ("*" can be used for subscribe all cluster's dynamicboxes event; If you use the "*", value in the category will be ignored) * @param[in] category Category ("*" can be used for subscribe dynamicboxes events of all category(sub-cluster) in a given "cluster") * @privlevel public - * @privilege %http://tizen.org/privilege/dynamicbox.viewer + * @privilege %http://tizen.org/privilege/dynamicbox * @return int * @retval #DBOX_STATUS_ERROR_FAULT Unrecoverable error occurred * @retval #DBOX_STATUS_ERROR_NONE Successfully requested @@ -1242,7 +1290,7 @@ extern int dynamicbox_subscribe_group(const char *cluster, const char *category) * @param[in] cluster Cluster("*" can be used for subscribe all cluster's dynamicboxes event; If you use the "*", value in the category will be ignored) * @param[in] category Category ("*" can be used for subscribe all sub-cluster's dynamicboxes event in a given "cluster") * @privlevel public - * @privilege %http://tizen.org/privilege/dynamicbox.viewer + * @privilege %http://tizen.org/privilege/dynamicbox * @return int * @retval #DBOX_STATUS_ERROR_FAULT Unrecoverable error occurred * @retval #DBOX_STATUS_ERROR_NONE Successfully requested @@ -1261,7 +1309,7 @@ extern int dynamicbox_unsubscribe_group(const char *cluster, const char *categor * @param[in] category Sub-cluster ID * @param[in] force 1 if the boxes should be updated even if they are paused * @privlevel public - * @privilege %http://tizen.org/privilege/dynamicbox.viewer + * @privilege %http://tizen.org/privilege/dynamicbox * @return int * @retval #DBOX_STATUS_ERROR_INVALID_PARAMETER Invalid argument * @retval #DBOX_STATUS_ERROR_FAULT Unrecoverable error occurred @@ -1277,7 +1325,7 @@ extern int dynamicbox_refresh_group(const char *cluster, const char *category, i * @param[in] handler Handler of a dynamicbox instance * @param[in] force 1 if the box should be updated even if it is paused * @privlevel public - * @privilege %http://tizen.org/privilege/dynamicbox.viewer + * @privilege %http://tizen.org/privilege/dynamicbox * @return int * @retval #DBOX_STATUS_ERROR_INVALID_PARAMETER Invalid argument * @retval #DBOX_STATUS_ERROR_FAULT Unrecoverable error occurred @@ -1312,20 +1360,47 @@ extern unsigned int dynamicbox_resource_id(const dynamicbox_h handler, int gbar) * @since_tizen 2.3 * @param[in] handler Handler of a dynamicbox instance * @param[in] gbar 1 for Glance Bar or 0 - * @param[in] cb Callback function which will be called with result of acquiring lb resource id + * @param[in] cb Callback function which will be called with result of acquiring dbox resource id * @param[in] data Callback data * @privlevel public - * @privilege %http://tizen.org/privilege/dynamicbox.viewer + * @privilege %http://tizen.org/privilege/dynamicbox * @return int * @retval #DBOX_STATUS_ERROR_INVALID_PARAMETER Invalid argument * @retval #DBOX_STATUS_ERROR_FAULT Unrecoverable error occurred * @retval #DBOX_STATUS_ERROR_NONE Successfully requested * @pre Dynamicbox service system should support the ResourceId type buffer. - * The dynamicbox should be designed to use the buffer (script type). + * The dynamicbox should be designed to use the buffer (or script). * @see dynamicbox_release_resource_id() * @see dynamicbox_ret_cb */ -extern unsigned int dynamicbox_acquire_resource_id(dynamicbox_h handler, int gbar, dynamicbox_ret_cb cb, void *data); +extern int dynamicbox_acquire_resource_id(dynamicbox_h handler, int gbar, dynamicbox_ret_cb cb, void *data); + +/** + * @internal + * @brief Get the Resource Id of a dynamicbox for Extra buffer + * @details Even if a render process(provider) released the Resource Id, it will be kept while release it by viewer.\n + * This will prevent from unexpected resource releasing for viewer.\n + * You should release this using dynamicbox_release_resource_id() + * @remarks + * This is an ASYNCHRONOUS API. + * @since_tizen 2.3 + * @param[in] handler Handler of a dynamicbox instance + * @param[in] gbar 1 for Glance Bar or 0 + * @param[in] idx Index of extra buffer, it is limited to dynamicbox configuration + * @param[in] cb Callback function which will be called with result of acquiring dbox resource id + * @param[in] data Callback data + * @privlevel public + * @privilege %http://tizen.org/privilege/dynamicbox + * @return int + * @retval #DBOX_STATUS_ERROR_INVALID_PARAMETER Invalid argument + * @retval #DBOX_STATUS_ERROR_FAULT Unrecoverable error occurred + * @retval #DBOX_STATUS_ERROR_NONE Successfully requested + * @pre Dynamicbox service system should support the resource id type buffer. + * The dynamicbox should be designed to use the buffer (or script) + * @see dynamicbox_release_resource_id() + * @see dynamicbox_ret_cb + */ +extern int dynamicbox_acquire_extra_resource_id(dynamicbox_h handler, int gbar, int idx, dynamicbox_ret_cb cb, void *data); /** * @internal @@ -1337,7 +1412,7 @@ extern unsigned int dynamicbox_acquire_resource_id(dynamicbox_h handler, int gba * @param[in] gbar 1 for Glance Bar or 0 * @param[in] resource_id Resource Id of given dynamicbox handler * @privlevel public - * @privilege %http://tizen.org/privilege/dynamicbox.viewer + * @privilege %http://tizen.org/privilege/dynamicbox * @return int * @retval #DBOX_STATUS_ERROR_INVALID_PARAMETER Invalid argument * @retval #DBOX_STATUS_ERROR_FAULT Unrecoverable error occurred @@ -1354,7 +1429,7 @@ extern int dynamicbox_release_resource_id(dynamicbox_h handler, int gbar, unsign * @param[in] handler Handler of a dynamicbox instance * @param[in] state Configure the current visible state of a dynamicbox * @privlevel public - * @privilege %http://tizen.org/privilege/dynamicbox.viewer + * @privilege %http://tizen.org/privilege/dynamicbox * @return int * @retval #DBOX_STATUS_ERROR_INVALID_PARAMETER Invalid argument * @retval #DBOX_STATUS_ERROR_BUSY @@ -1363,12 +1438,13 @@ extern int dynamicbox_release_resource_id(dynamicbox_h handler, int gbar, unsign * @retval #DBOX_STATUS_ERROR_FAULT Unrecoverable error occurred * @retval #DBOX_STATUS_ERROR_NONE Successfully done */ -extern int dynamicbox_set_visibility(dynamicbox_h handler, enum dynamicbox_visible_state state); +extern int dynamicbox_set_visibility(dynamicbox_h handler, dynamicbox_visible_state_e state); /** * @internal - * @brief Updates a visible state of the dynamicbox. * @brief Gets the current visible state of a dynamicbox. + * @remarks + * If this returns DBOX_VISIBLE_ERROR, you can get the reason of failure using dynamicbox_last_status() * @since_tizen 2.3 * @param[in] handler Handler of a dynamicbox instance * @return dynamicbox_visible_state @@ -1377,7 +1453,7 @@ extern int dynamicbox_set_visibility(dynamicbox_h handler, enum dynamicbox_visib * @retval #DBOX_HIDE_WITH_PAUSE Dynamicbox is hidden, it will pause the update timer, but if a dynamicbox updates its contents, update event will occur * @retval #DBOX_VISIBLE_ERROR To enlarge the size of this enumeration type */ -extern enum dynamicbox_visible_state dynamicbox_visibility(dynamicbox_h handler); +extern dynamicbox_visible_state_e dynamicbox_visibility(dynamicbox_h handler); /** * @internal @@ -1395,7 +1471,7 @@ extern enum dynamicbox_visible_state dynamicbox_visibility(dynamicbox_h handler) * @param[in] cb Result callback function * @param[in] data Callback data * @privlevel public - * @privilege %http://tizen.org/privilege/dynamicbox.viewer + * @privilege %http://tizen.org/privilege/dynamicbox * @return int * @retval #DBOX_STATUS_ERROR_INVALID_PARAMETER Invalid argument * @retval #DBOX_STATUS_ERROR_BUSY @@ -1410,6 +1486,8 @@ extern int dynamicbox_set_update_mode(dynamicbox_h handler, int active_update, d /** * @internal * @brief Checks the active update mode of the given dynamicbox. + * @remarks + * If this returns negative value, you can get the reason of failure using dynamicbox_last_status() * @since_tizen 2.3 * @param[in] handler Handler of a dynamicbox instance * @return int @@ -1425,14 +1503,14 @@ extern int dynamicbox_is_active_update(dynamicbox_h handler); * @param[in] handler Handler of a dynamicbox instance * @param[in] gbar 1 for Glance Bar or 0 * @privlevel public - * @privilege %http://tizen.org/privilege/dynamicbox.viewer + * @privilege %http://tizen.org/privilege/dynamicbox * @return int * @retval #DBOX_STATUS_ERROR_NONE If success * @retval #DBOX_STATUS_ERROR_INVALID_PARAMETER Invalid handle * @see dynamicbox_set_manual_sync() * @see dynamicbox_manual_sync() */ -extern int dynamicbox_sync_fb(dynamicbox_h handler, int gbar); +extern int dynamicbox_sync_buffer(dynamicbox_h handler, int gbar); /** * @internal @@ -1451,6 +1529,8 @@ extern int dynamicbox_damage_region_get(dynamicbox_h handler, int gbar, const dy * @internal * @brief Gets an alternative icon of the given dynamicbox instance. * @details If the box should be represented as a shortcut icon, this function will get the alternative icon. + * @remarks + * If this returns @c NULL, you can get the reason of failure using dynamicbox_last_status() * @since_tizen 2.3 * @param[in] handler Handler of a dynamicbox instance * @return const char * @@ -1458,12 +1538,14 @@ extern int dynamicbox_damage_region_get(dynamicbox_h handler, int gbar, const dy * @retval @c NULL Dynamicbox has no alternative icon file * @see dynamicbox_alt_name() */ -extern const char *dynamicbox_alt_icon(dynamicbox_h handler); +extern const char *dynamicbox_alternative_icon(dynamicbox_h handler); /** * @internal * @brief Gets an alternative name of the given dynamicbox instance. * @details If the box should be represented as a shortcut name, this function will get the alternative name. + * @remarks + * If this returns @c NULL, you can get the reason of failure using dynamicbox_last_status() * @since_tizen 2.3 * @param[in] handler Handler of a dynamicbox instance * @return const char * @@ -1471,7 +1553,7 @@ extern const char *dynamicbox_alt_icon(dynamicbox_h handler); * @retval @c NULL Dynamicbox has no alternative name * @see dynamicbox_alt_icon() */ -extern const char *dynamicbox_alt_name(dynamicbox_h handler); +extern const char *dynamicbox_alternative_name(dynamicbox_h handler); /** * @internal @@ -1482,14 +1564,14 @@ extern const char *dynamicbox_alt_name(dynamicbox_h handler); * @param[in] handler Handler of a dynamicbox instance * @param[in] gbar 1 for Glance Bar or 0 * @privlevel public - * @privilege %http://tizen.org/privilege/dynamicbox.viewer + * @privilege %http://tizen.org/privilege/dynamicbox * @return int * @retval #DBOX_STATUS_ERROR_FAULT Unrecoverable error occurred * @retval #DBOX_STATUS_ERROR_INVALID_PARAMETER Invalid argument * @retval #DBOX_STATUS_ERROR_NONE Successfully done - * @see dynamicbox_release_fb_lock() + * @see dynamicbox_release_buffer_lock() */ -extern int dynamicbox_acquire_fb_lock(dynamicbox_h handler, int gbar); +extern int dynamicbox_acquire_buffer_lock(dynamicbox_h handler, int gbar); /** * @internal @@ -1499,31 +1581,31 @@ extern int dynamicbox_acquire_fb_lock(dynamicbox_h handler, int gbar); * @param[in] handler Handler of a dynamicbox instance * @param[in] gbar 1 for Glance Bar or 0 * @privlevel public - * @privilege %http://tizen.org/privilege/dynamicbox.viewer + * @privilege %http://tizen.org/privilege/dynamicbox * @return int * @retval #DBOX_STATUS_ERROR_FAULT Unrecoverable error occurred * @retval #DBOX_STATUS_ERROR_INVALID_PARAMETER Invalid argument * @retval #DBOX_STATUS_ERROR_NONE Successfully done - * @see dynamicbox_acquire_fb_lock() + * @see dynamicbox_acquire_buffer_lock() */ -extern int dynamicbox_release_fb_lock(dynamicbox_h handler, int gbar); +extern int dynamicbox_release_buffer_lock(dynamicbox_h handler, int gbar); /** * @internal * @brief Sets options for controlling a dynamicbox sub-system. * @details - * DBOX_OPTION_FRAME_DROP_FOR_RESIZE - * While resizing the box, viewer doesn't want to know the updated frames of an old size content anymore. - * In that case, turn this on, the provider will not send the updated event to the viewer about an old content. - * So the viewer can reduce its burden to update unnecessary frames. - * DBOX_OPTION_MANUAL_SYNC - * If you don't want to update frames automatically, or you want only reload the frames by your hands, (manually) - * Turn this on. - * After turnning it on, you should sync it using dynamicbox_sync_gbar_fb and dynamicbox_sync_dbox_pfb. - * DBOX_OPTION_SHARED_CONTENT - * If this option is turnned on, even though you create a new dynamicbox, - * if there are already added same instances that have same contents, the instance will not be created again. - * Instead of creating a new instance, a viewer will provide an old instance with a new handle. + * #DBOX_OPTION_FRAME_DROP_FOR_RESIZE + * While resizing the box, viewer doesn't want to know the updated frames of an old size content anymore. + * In that case, turn this on, the provider will not send the updated event to the viewer about an old content. + * So the viewer can reduce its burden to update unnecessary frames. + * #DBOX_OPTION_MANUAL_SYNC + * If you don't want to update frames automatically, or you want only reload the frames by your hands, (manually) + * Turn this on. + * After turnning it on, you should sync it using dynamicbox_sync_buffer(). + * #DBOX_OPTION_SHARED_CONTENT + * If this option is turnned on, even though you create a new dynamicbox, + * if there are already added same instances that have same contents, the instance will not be created again. + * Instead of creating a new instance, a viewer will provide an old instance with a new handle. * @since_tizen 2.3 * @param[in] option Option which will be affected by this call * @param[in] state New value for given option @@ -1532,13 +1614,15 @@ extern int dynamicbox_release_fb_lock(dynamicbox_h handler, int gbar); * @retval #DBOX_STATUS_ERROR_FAULT Failed to change the state of option * @retval #DBOX_STATUS_ERROR_NONE Successfully changed * @see dynamicbox_get_option() - * @see dynamicbox_sync_fb() + * @see dynamicbox_sync_buffer() */ -extern int dynamicbox_set_option(enum dynamicbox_option_type option, int state); +extern int dynamicbox_set_option(dynamicbox_option_type_e option, int state); /** * @internal * @brief Gets options of a dynamicbox sub-system. + * @remarks + * If this returns negative value, you can get the reason of failure using dynamicbox_last_status() * @since_tizen 2.3 * @param[in] option Type of option * @return int @@ -1547,7 +1631,7 @@ extern int dynamicbox_set_option(enum dynamicbox_option_type option, int state); * @retval >=0 Value of given option (must be >=0) * @see dynamicbox_set_option() */ -extern int dynamicbox_option(enum dynamicbox_option_type option); +extern int dynamicbox_option(dynamicbox_option_type_e option); /** * @internal @@ -1564,16 +1648,22 @@ extern int dynamicbox_set_auto_launch_handler(dynamicbox_auto_launch_handler_cb /** * @internal - * @brief get a damaged region from handler if a handler has buffer type dbox or gbar - * @since_tizen 2.3 - * @param[in] handler Handler of a dbox - * @param[in] gbar 1 if you want to get a damaged region of glance bar or 0 - * @param[out] region Region information, x, y, w, h - * @return int - * @retval #DBOX_STATUS_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #DBOX_STATUS_ERROR_NONE If sucess - */ -extern int dynamicbox_damage_region_get(dynamicbox_h handler, int gbar, const dynamicbox_damage_region_t *region); + * @brief Get the last extra buffer index and its id. + * @details + * If there is an event of #DBOX_EVENT_DBOX_EXTRA_BUFFER_CREATED or #DBOX_EVENT_GBAR_EXTRA_BUFFER_CREATED, + * #DBOX_EVENT_DBOX_EXTRA_BUFFER_DESTROYED or #DBOX_EVENT_GBAR_EXTRA_BUFFER_DESTROYED + * you can use this to get the last created buffer info + * @since_tizen 2.3 + * @param[in] handler Dynamicbox handler + * @param[in] gbar 1 if you want get the glance bar's info or 0 + * @param[out] idx Index of buffer + * @param[out] resource_id Resource Id + * @return status + * @retval #DBOX_STATUS_ERROR_NONE Successfully get + * @retval #DBOX_STATUS_ERROR_INVALID_PARAMETER Handler is not valid + * @retval #DBOX_STATUS_ERROR_NOT_EXIST There is no extra buffer + */ +extern int dynamicbox_get_affected_extra_buffer(dynamicbox_h handler, int gbar, int *idx, unsigned int *resource_id); /** * @} diff --git a/include/dynamicbox_internal.h b/include/dynamicbox_internal.h index 5b8825e..f4a6b7e 100644 --- a/include/dynamicbox_internal.h +++ b/include/dynamicbox_internal.h @@ -15,12 +15,12 @@ */ struct cb_info { - dynamicbox_ret_cb cb; - void *data; + dynamicbox_ret_cb cb; + void *data; }; -extern void dbox_invoke_event_handler(struct dynamicbox *handler, enum dynamicbox_event_type event); -extern void dbox_invoke_fault_handler(enum dynamicbox_fault_type type, const char *pkgname, const char *filename, const char *function); +extern void dbox_invoke_event_handler(struct dynamicbox *handler, dynamicbox_event_type_e event); +extern void dbox_invoke_fault_handler(dynamicbox_fault_type_e type, const char *pkgname, const char *filename, const char *function); extern struct dynamicbox_common *dbox_find_common_handle(const char *pkgname, const char *filename); extern struct dynamicbox *dbox_new_dynamicbox(const char *pkgname, const char *id, double timestamp, const char *cluster, const char *category); @@ -51,16 +51,12 @@ extern void dbox_set_update_mode(struct dynamicbox_common *handler, int active_m extern void dbox_set_filename(struct dynamicbox_common *handler, const char *filename); extern void dbox_set_alt_icon(struct dynamicbox_common *handler, const char *icon); extern void dbox_set_alt_name(struct dynamicbox_common *handle, const char *name); -extern int dbox_destroy_lock_file(struct dynamicbox_common *common, int is_gbar); -extern int dbox_create_lock_file(struct dynamicbox_common *common, int is_gbar); extern int dbox_destroy_common_handle(struct dynamicbox_common *common); extern struct dynamicbox_common *dbox_create_common_handle(struct dynamicbox *handle, const char *pkgname, const char *cluster, const char *category); extern int dbox_sync_gbar_fb(struct dynamicbox_common *common); extern int dbox_sync_dbox_fb(struct dynamicbox_common *common); extern int dbox_common_unref(struct dynamicbox_common *common, struct dynamicbox *handle); extern int dbox_common_ref(struct dynamicbox_common *common, struct dynamicbox *handle); -extern int dbox_fb_lock(int fd); -extern int dbox_fb_unlock(int fd); extern struct dynamicbox_common *dbox_find_sharable_common_handle(const char *pkgname, const char *content, int w, int h, const char *cluster, const char *category); extern struct dynamicbox *dbox_find_dbox_in_show(struct dynamicbox_common *common); extern struct dynamicbox *dbox_get_dbox_nth(struct dynamicbox_common *common, int nth); @@ -76,184 +72,198 @@ extern struct dynamicbox *dbox_unref(struct dynamicbox *handler, int destroy_com extern int dbox_send_delete(struct dynamicbox *handler, int type, dynamicbox_ret_cb cb, void *data); extern int dbox_delete_all(void); -enum dynamicbox_state { - DBOX_STATE_CREATE = 0xBEEFbeef, - DBOX_STATE_DELETE = 0xDEADdead, /* Delete only for this client */ - DBOX_STATE_DESTROYED = 0x00DEAD00 -}; +typedef enum dynamicbox_state { + DBOX_STATE_CREATE = 0xBEEFbeef, + DBOX_STATE_DELETE = 0xDEADdead, /* Delete only for this client */ + DBOX_STATE_DESTROYED = 0x00DEAD00 +} dynamicbox_state_e; struct dynamicbox_common { - enum dynamicbox_state state; - - struct dlist *dynamicbox_list; - int refcnt; - - char *cluster; - char *category; - - char *pkgname; - char *id; - - char *content; - char *title; - char *filename; - - double timestamp; - - struct alt_info { - char *icon; - char *name; - } alt; - - enum dynamicbox_delete_type delete_type; - - int is_user; - int is_gbar_created; - int is_pinned_up; - int is_active_update; - enum dynamicbox_visible_state visible; - - struct { - enum dynamicbox_dbox_type type; - struct fb_info *fb; - - int size_list; - - int width; - int height; - double priority; - - char *auto_launch; - double period; - int pinup_supported; - int mouse_event; - - /* For the filtering event */ - double x; - double y; - char *lock; - int lock_fd; - struct dynamicbox_damage_region last_damage; - } dbox; - - struct { - enum dynamicbox_gbar_type type; - struct fb_info *fb; - - int width; - int height; - - int default_width; - int default_height; - - /* For the filtering event */ - double x; - double y; - char *lock; - int lock_fd; - struct dynamicbox_damage_region last_damage; - } gbar; - - int nr_of_sizes; - - struct requested_flag { - unsigned int created:1; - unsigned int deleted:1; - unsigned int pinup:1; - unsigned int group_changed:1; - unsigned int period_changed:1; - unsigned int size_changed:1; - unsigned int gbar_created:1; - unsigned int gbar_destroyed:1; - unsigned int update_mode:1; - unsigned int access_event:1; - unsigned int key_event:1; - - /*! - * \note - * Reserved - */ - unsigned int reserved:21; - } request; + dynamicbox_state_e state; + + struct dlist *dynamicbox_list; + int refcnt; + + char *cluster; + char *category; + + char *pkgname; + char *id; + + char *content; + char *title; + char *filename; + + double timestamp; + + struct alt_info { + char *icon; + char *name; + } alt; + + dynamicbox_delete_type_e delete_type; + + int is_user; + int is_gbar_created; + int is_pinned_up; + int is_active_update; + dynamicbox_visible_state_e visible; + + struct { + dynamicbox_dbox_type_e type; + struct fb_info *fb; + + int size_list; + + int width; + int height; + double priority; + + char *auto_launch; + double period; + int pinup_supported; + int mouse_event; + + /* For the filtering event */ + double x; + double y; + + /* For the extra buffer */ + unsigned int *extra_buffer; + int last_extra_buffer_idx; + + /* Lock */ + dynamicbox_lock_info_t lock; + + /* For damaged region */ + struct dynamicbox_damage_region last_damage; + } dbox; + + struct { + dynamicbox_gbar_type_e type; + struct fb_info *fb; + + int width; + int height; + + int default_width; + int default_height; + + /* For the filtering event */ + double x; + double y; + + /* For the extra buffer */ + unsigned int *extra_buffer; + int last_extra_buffer_idx; + + /* Lock */ + dynamicbox_lock_info_t lock; + + /* For damaged region */ + struct dynamicbox_damage_region last_damage; + } gbar; + + int nr_of_sizes; + + struct requested_flag { + unsigned int created:1; + unsigned int deleted:1; + unsigned int pinup:1; + unsigned int group_changed:1; + unsigned int period_changed:1; + unsigned int size_changed:1; + unsigned int gbar_created:1; + unsigned int gbar_destroyed:1; + unsigned int update_mode:1; + unsigned int access_event:1; + unsigned int key_event:1; + + /*! + * \note + * Reserved + */ + unsigned int reserved:21; + } request; }; struct job_item { - struct dynamicbox *handle; - dynamicbox_ret_cb cb; - int ret; - void *data; + struct dynamicbox *handle; + dynamicbox_ret_cb cb; + int ret; + void *data; }; struct dynamicbox { - enum dynamicbox_state state; - - int refcnt; - int paused_updating; - - enum dynamicbox_visible_state visible; - struct dynamicbox_common *common; - - void *data; - - struct callback_table { - struct dynamicbox_script_operators dbox_ops; - struct dynamicbox_script_operators gbar_ops; - - struct created { - dynamicbox_ret_cb cb; - void *data; - } created; - - struct deleted { - dynamicbox_ret_cb cb; - void *data; - } deleted; - - struct pinup { - dynamicbox_ret_cb cb; - void *data; - } pinup; - - struct group_changed { - dynamicbox_ret_cb cb; - void *data; - } group_changed; - - struct period_changed { - dynamicbox_ret_cb cb; - void *data; - } period_changed; - - struct size_changed { - dynamicbox_ret_cb cb; - void *data; - } size_changed; - - struct gbar_created { - dynamicbox_ret_cb cb; - void *data; - } gbar_created; - - struct gbar_destroyed { - dynamicbox_ret_cb cb; - void *data; - } gbar_destroyed; - - struct update_mode { - dynamicbox_ret_cb cb; - void *data; - } update_mode; - - struct access_event { - dynamicbox_ret_cb cb; - void *data; - } access_event; - - struct key_event { - dynamicbox_ret_cb cb; - void *data; - } key_event; - } cbs; + dynamicbox_state_e state; + + int refcnt; + int paused_updating; + + dynamicbox_visible_state_e visible; + struct dynamicbox_common *common; + + void *data; + + struct callback_table { + struct dynamicbox_script_operators dbox_ops; + struct dynamicbox_script_operators gbar_ops; + + struct created { + dynamicbox_ret_cb cb; + void *data; + } created; + + struct deleted { + dynamicbox_ret_cb cb; + void *data; + } deleted; + + struct pinup { + dynamicbox_ret_cb cb; + void *data; + } pinup; + + struct group_changed { + dynamicbox_ret_cb cb; + void *data; + } group_changed; + + struct period_changed { + dynamicbox_ret_cb cb; + void *data; + } period_changed; + + struct size_changed { + dynamicbox_ret_cb cb; + void *data; + } size_changed; + + struct gbar_created { + dynamicbox_ret_cb cb; + void *data; + } gbar_created; + + struct gbar_destroyed { + dynamicbox_ret_cb cb; + void *data; + } gbar_destroyed; + + struct update_mode { + dynamicbox_ret_cb cb; + void *data; + } update_mode; + + struct access_event { + dynamicbox_ret_cb cb; + void *data; + } access_event; + + struct key_event { + dynamicbox_ret_cb cb; + void *data; + } key_event; + } cbs; }; /* End of a file */ diff --git a/include/util.h b/include/util.h index 071bc63..498a249 100644 --- a/include/util.h +++ b/include/util.h @@ -20,9 +20,9 @@ extern const char *util_basename(const char *name); extern const char *util_uri_to_path(const char *uri); extern int util_unlink(const char *filename); -#define SCHEMA_FILE "file://" -#define SCHEMA_PIXMAP "pixmap://" -#define SCHEMA_SHM "shm://" +#define SCHEMA_FILE "file://" +#define SCHEMA_PIXMAP "pixmap://" +#define SCHEMA_SHM "shm://" #define container_of(ptr, type, member) \ ({ const typeof( ((type *)0)->member ) *__mptr = (ptr); \ diff --git a/live.viewer/dbox.app-dbox.only/src/main.c b/live.viewer/dbox.app-dbox.only/src/main.c index 7399fe3..86c0686 100644 --- a/live.viewer/dbox.app-dbox.only/src/main.c +++ b/live.viewer/dbox.app-dbox.only/src/main.c @@ -68,7 +68,7 @@ static int dbox_resize(const char *id, int w, int h, void *data) return 0; } -static int dbox_destroy(const char *id, int reason, void *data) +static int dbox_destroy(const char *id, dynamicbox_destroy_type_e reason, void *data) { struct dynamicbox_data *dbox_data; diff --git a/live.viewer/dbox.video/src/player.c b/live.viewer/dbox.video/src/player.c index 6f90119..6c19c83 100644 --- a/live.viewer/dbox.video/src/player.c +++ b/live.viewer/dbox.video/src/player.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -49,7 +50,7 @@ int dynamicbox_player_updated(struct info *info) } snprintf(uri, len, "file://%s", info->id); - ret = dynamicbox_provider_send_updated("com.samsung.w-add-viewer.video", uri, ®ion); + ret = dynamicbox_provider_send_updated("com.samsung.w-add-viewer.video", uri, DBOX_PRIMARY_BUFFER, ®ion, 0, NULL); free(uri); LOGD("============== %s\n", info->id); diff --git a/live.viewer/packaging/com.samsung.w-add-viewer.spec b/live.viewer/packaging/com.samsung.w-add-viewer.spec index 3fd89fb..8ffbf31 100644 --- a/live.viewer/packaging/com.samsung.w-add-viewer.spec +++ b/live.viewer/packaging/com.samsung.w-add-viewer.spec @@ -35,6 +35,7 @@ BuildRequires: edje-bin BuildRequires: embryo-bin BuildRequires: gettext-devel BuildRequires: hash-signer +Requires(post): signing-client %description w-add-viewer @@ -64,12 +65,13 @@ make %{?jobs:-j%jobs} rm -rf %{buildroot} %define tizen_sign 1 %define tizen_sign_base /usr/apps/%{_package_name} -%define tizen_sign_level public +%define tizen_sign_level platform %define tizen_author_sign 1 %define tizen_dist_sign 1 %make_install %post +/usr/bin/signing-client/hash-signer-client.sh -a -d -p platform /usr/apps/${_package_name} %files %manifest %{_package_name}.manifest diff --git a/live.viewer/viewer/src/dynamicbox_evas.c b/live.viewer/viewer/src/dynamicbox_evas.c index 88f02a7..05104e6 100644 --- a/live.viewer/viewer/src/dynamicbox_evas.c +++ b/live.viewer/viewer/src/dynamicbox_evas.c @@ -112,6 +112,9 @@ #define DBOX_CLASS_NAME "dynamicbox" +#define DBOX_PRIMARY_BUFFER -1 +#define DBOX_KEEP_BUFFER -2 + int errno; /*! @@ -121,198 +124,206 @@ int errno; #define CLICK_REGION 22 static struct { - Evas_Smart_Class sc; - Evas_Smart *smart; - Eina_List *list; - struct { - Eina_List *delete_list; - Eina_List *create_list; - } raw_event; - int screen_width; - int screen_height; - - union _conf { - struct _field { - unsigned int user_view_port: 1; - unsigned int force_to_buffer: 1; - unsigned int support_gbar: 1; - unsigned int manual_pause_resume: 1; - unsigned int use_fixed_size: 1; - unsigned int easy_mode: 1; - unsigned int is_scroll_x: 1; - unsigned int is_scroll_y: 1; - unsigned int auto_feed: 1; - unsigned int delayed_pause_resume: 1; - unsigned int sensitive_move: 1; - unsigned int render_animator: 1; - unsigned int auto_render_selector: 1; - - unsigned int reserved: 19; - } field; - unsigned int mask; - } conf; - - Evas_Object *win; - Ecore_Animator *renderer; - Eina_List *dbox_dirty_objects; - Eina_List *gbar_dirty_objects; + Evas_Smart_Class sc; + Evas_Smart *smart; + Eina_List *list; + struct { + Eina_List *delete_list; + Eina_List *create_list; + } raw_event; + int screen_width; + int screen_height; + + union _conf { + struct _field { + unsigned int user_view_port: 1; + unsigned int force_to_buffer: 1; + unsigned int support_gbar: 1; + unsigned int manual_pause_resume: 1; + unsigned int use_fixed_size: 1; + unsigned int easy_mode: 1; + unsigned int is_scroll_x: 1; + unsigned int is_scroll_y: 1; + unsigned int auto_feed: 1; + unsigned int delayed_pause_resume: 1; + unsigned int sensitive_move: 1; + unsigned int render_animator: 1; + unsigned int auto_render_selector: 1; + + unsigned int reserved: 19; + } field; + unsigned int mask; + } conf; + + Evas_Object *win; + Ecore_Animator *renderer; + Eina_List *dbox_dirty_objects; + Eina_List *gbar_dirty_objects; } s_info = { - .sc = EVAS_SMART_CLASS_INIT_NAME_VERSION(DBOX_CLASS_NAME), - .smart = NULL, - .list = NULL, - .raw_event = { - .delete_list = NULL, - .create_list = NULL, - }, - .conf = { - .mask = 0, - }, - .screen_width = 720, - .screen_height = 1280, - .win = NULL, - .renderer = NULL, - .dbox_dirty_objects = NULL, - .gbar_dirty_objects = NULL, + .sc = EVAS_SMART_CLASS_INIT_NAME_VERSION(DBOX_CLASS_NAME), + .smart = NULL, + .list = NULL, + .raw_event = { + .delete_list = NULL, + .create_list = NULL, + }, + .conf = { + .mask = 0, + }, + .screen_width = 720, + .screen_height = 1280, + .win = NULL, + .renderer = NULL, + .dbox_dirty_objects = NULL, + .gbar_dirty_objects = NULL, }; struct access_ret_cb_data { - Evas_Object *obj; - void (*ret_cb)(Evas_Object *, int, void *); - void *data; + Evas_Object *obj; + void (*ret_cb)(Evas_Object *, int, void *); + void *data; }; struct acquire_data { - struct widget_data *data; - Evas_Object *content; - int w; - int h; + struct widget_data *data; + Evas_Object *content; + int w; + int h; }; enum CANCEL_CLICK { - CANCEL_DISABLED = 0x0, - CANCEL_USER = 0x01, - CANCEL_PROCESSED = 0x02 + CANCEL_DISABLED = 0x0, + CANCEL_USER = 0x01, + CANCEL_PROCESSED = 0x02 }; struct widget_data { - enum { - WIDGET_DATA_CREATED = 0x00beef00, - WIDGET_DATA_DELETED = 0x0d0e0a0d, - } state; - struct dynamicbox *handle; - Evas *e; - Evas_Object *stage; /*!< Do not resize thie directly, it should be resized via XX_update_geometry */ - Evas_Object *parent; - - Evas_Object *dbox_layout; /*!< Layout of Dynamicbox content part */ - Evas_Object *gbar_layout; /*!< Layout of GBAR content part */ - - Evas_Object *dynamicbox; /*!< Container object */ - - struct view_port { - int x; - int y; - int w; - int h; - } view_port; - - char *dbox_id; - char *content; - char *cluster; - char *category; - double period; - - void *dbox_fb; - void *gbar_fb; - - unsigned int gbar_pixmap; - unsigned int dbox_pixmap; - - struct down { - int x; - int y; - - struct { - int x; - int y; - int w; - int h; - } geo; - } down; + enum { + WIDGET_DATA_CREATED = 0x00beef00, + WIDGET_DATA_DELETED = 0x0d0e0a0d, + } state; + struct dynamicbox *handle; + Evas *e; + Evas_Object *stage; /*!< Do not resize thie directly, it should be resized via XX_update_geometry */ + Evas_Object *parent; + + Evas_Object *dbox_layout; /*!< Layout of Dynamicbox content part */ + Evas_Object *gbar_layout; /*!< Layout of GBAR content part */ + + Evas_Object *dynamicbox; /*!< Container object */ + + struct view_port { + int x; + int y; + int w; + int h; + } view_port; + + char *dbox_id; + char *content; + char *cluster; + char *category; + double period; + + void *dbox_fb; + void *gbar_fb; + + unsigned int gbar_pixmap; + unsigned int dbox_pixmap; + unsigned int *gbar_extra; + unsigned int *dbox_extra; + int gbar_extra_cnt; + int dbox_extra_cnt; + + int dbox_latest_idx; /* -1 = primary buffer, 0 ~ = extra buffer */ + int gbar_latest_idx; /* -1 = primary buffer, 0 ~ = extra buffer */ + + struct down { int x; int y; - int dbox_width; - int dbox_height; - int size_type; - - union { - struct { - unsigned int pressed: 1; /**< Mouse is pressed */ - unsigned int touch_effect: 1; /**< Requires to play touch effect */ - unsigned int mouse_event: 1; /**< Requires to feed mouse event */ - unsigned int scroll_x: 1; /**< */ - unsigned int scroll_y: 1; - unsigned int faulted: 1; - unsigned int flick_down: 1; - unsigned int gbar_created: 1; - - unsigned int created: 1; - unsigned int deleted: 1; - unsigned int dbox_pixmap_acquire_requested: 1; - unsigned int gbar_pixmap_acquire_requested: 1; - unsigned int cancel_scroll_x: 1; - unsigned int cancel_scroll_y: 1; - unsigned int cancel_click: 2; - unsigned int disable_preview: 1; - unsigned int disable_loading: 1; - unsigned int disable_text: 1; - unsigned int dbox_overlay_loaded: 1; - unsigned int gbar_overlay_loaded: 1; - - unsigned int freeze_visibility: 1; - - unsigned int dbox_dirty: 1; - unsigned int gbar_dirty: 1; - - unsigned int send_delete: 1; - unsigned int permanent_delete: 1; - - unsigned int reserved: 5; - } field; /* Do we really has performance loss? */ - - unsigned int flags; - } is; - - int refcnt; - int overlay_update_counter; - Ecore_Timer *overlay_timer; - int freezed_visibility; + struct { + int x; + int y; + int w; + int h; + } geo; + } down; + + int x; + int y; + + int dbox_width; + int dbox_height; + int size_type; + + union { + struct { + unsigned int pressed: 1; /**< Mouse is pressed */ + unsigned int touch_effect: 1; /**< Requires to play touch effect */ + unsigned int mouse_event: 1; /**< Requires to feed mouse event */ + unsigned int scroll_x: 1; /**< */ + unsigned int scroll_y: 1; + unsigned int faulted: 1; + unsigned int flick_down: 1; + unsigned int gbar_created: 1; + + unsigned int created: 1; + unsigned int deleted: 1; + unsigned int dbox_pixmap_acquire_requested: 1; + unsigned int gbar_pixmap_acquire_requested: 1; + unsigned int cancel_scroll_x: 1; + unsigned int cancel_scroll_y: 1; + unsigned int cancel_click: 2; + unsigned int disable_preview: 1; + unsigned int disable_loading: 1; + unsigned int disable_text: 1; + unsigned int dbox_overlay_loaded: 1; + unsigned int gbar_overlay_loaded: 1; + + unsigned int freeze_visibility: 1; + + unsigned int dbox_dirty: 1; + unsigned int gbar_dirty: 1; + + unsigned int send_delete: 1; + unsigned int permanent_delete: 1; + + unsigned int reserved: 5; + } field; /* Do we really has performance loss? */ + + unsigned int flags; + } is; + + int refcnt; + int overlay_update_counter; + Ecore_Timer *overlay_timer; + int freezed_visibility; }; enum EFFECT_MASK { - EFFECT_NONE = 0x0, - EFFECT_WIDTH = 0x01, - EFFECT_HEIGHT = 0x02, - EFFECT_BOTH = 0x03, - EFFECT_MOVE = 0x10 + EFFECT_NONE = 0x0, + EFFECT_WIDTH = 0x01, + EFFECT_HEIGHT = 0x02, + EFFECT_BOTH = 0x03, + EFFECT_MOVE = 0x10 }; struct animation_data { - Ecore_Timer *timer; - Evas_Object *obj; - - unsigned int effect_mask; - int w; - int h; - int x; - int y; + Ecore_Timer *timer; + Evas_Object *obj; + + unsigned int effect_mask; + int w; + int h; + int x; + int y; }; struct raw_event_cbdata { - void (*cb)(struct dynamicbox_evas_raw_event_info *info, void *data); - void *data; + void (*cb)(struct dynamicbox_evas_raw_event_info *info, void *data); + void *data; }; static int dynamicbox_fault_handler(enum dynamicbox_fault_type fault, const char *pkgname, const char *filename, const char *funcname, void *data); @@ -333,2129 +344,2193 @@ static void animator_del_cb(void *cbdata, Evas *e, Evas_Object *obj, void *event static void remove_dbox_dirty_object_list(struct widget_data *data); static void remove_gbar_dirty_object_list(struct widget_data *data); -static void append_dbox_dirty_object_list(struct widget_data *data); -static void append_gbar_dirty_object_list(struct widget_data *data); +static void append_dbox_dirty_object_list(struct widget_data *data, int idx); +static void append_gbar_dirty_object_list(struct widget_data *data, int idx); static void dynamicbox_event_dbox_updated(struct widget_data *data); static void dynamicbox_event_gbar_updated(struct widget_data *data); static struct widget_data *get_smart_data(Evas_Object *dynamicbox) { - if (dynamicbox && evas_object_smart_type_check(dynamicbox, DBOX_CLASS_NAME)) { - struct widget_data *data; + if (dynamicbox && evas_object_smart_type_check(dynamicbox, DBOX_CLASS_NAME)) { + struct widget_data *data; - data = evas_object_smart_data_get(dynamicbox); - if (data) { - if (data->state == WIDGET_DATA_CREATED) { - return data; - } + data = evas_object_smart_data_get(dynamicbox); + if (data) { + if (data->state == WIDGET_DATA_CREATED) { + return data; + } - ErrPrint("smart data is not valid\n"); - } else { - ErrPrint("smart data is not exists\n"); - } + ErrPrint("smart data is not valid\n"); + } else { + ErrPrint("smart data is not exists\n"); } + } - return NULL; + return NULL; } static inline void reset_scroller(struct widget_data *data) { - Evas_Object *scroller; + Evas_Object *scroller; - if (!data->dbox_layout) { - return; - } + if (!data->dbox_layout) { + return; + } - scroller = elm_object_part_content_get(data->dbox_layout, "scroller"); - if (!scroller) { - return; - } + scroller = elm_object_part_content_get(data->dbox_layout, "scroller"); + if (!scroller) { + return; + } - elm_scroller_region_show(scroller, 0, data->dbox_height >> 1, data->dbox_width, data->dbox_height); + elm_scroller_region_show(scroller, 0, data->dbox_height >> 1, data->dbox_width, data->dbox_height); } static void invoke_raw_event_callback(enum dynamicbox_evas_raw_event_type type, const char *pkgname, Evas_Object *dynamicbox, int error) { - struct dynamicbox_evas_raw_event_info info; - struct raw_event_cbdata *cbdata; - Eina_List *l; - Eina_List *n; + struct dynamicbox_evas_raw_event_info info; + struct raw_event_cbdata *cbdata; + Eina_List *l; + Eina_List *n; - info.pkgname = pkgname; - info.dynamicbox = dynamicbox; - info.error = error; - info.type = type; + info.pkgname = pkgname; + info.dynamicbox = dynamicbox; + info.error = error; + info.type = type; - switch (type) { + switch (type) { case DYNAMICBOX_EVAS_RAW_DELETE: - EINA_LIST_FOREACH_SAFE(s_info.raw_event.delete_list, l, n, cbdata) { - if (cbdata->cb) { - cbdata->cb(&info, cbdata->data); - } + EINA_LIST_FOREACH_SAFE(s_info.raw_event.delete_list, l, n, cbdata) { + if (cbdata->cb) { + cbdata->cb(&info, cbdata->data); } - break; + } + break; case DYNAMICBOX_EVAS_RAW_CREATE: - EINA_LIST_FOREACH_SAFE(s_info.raw_event.create_list, l, n, cbdata) { - if (cbdata->cb) { - cbdata->cb(&info, cbdata->data); - } + EINA_LIST_FOREACH_SAFE(s_info.raw_event.create_list, l, n, cbdata) { + if (cbdata->cb) { + cbdata->cb(&info, cbdata->data); } - break; + } + break; default: - break; - } + break; + } } static int find_size_type(struct widget_data *data, int w, int h) { - int cnt = DBOX_NR_OF_SIZE_LIST; - int i; - int _w[DBOX_NR_OF_SIZE_LIST]; - int _h[DBOX_NR_OF_SIZE_LIST]; - int type = DBOX_SIZE_TYPE_UNKNOWN; - int find; - int ret_type = DBOX_SIZE_TYPE_UNKNOWN; - int delta; - - if (dynamicbox_service_get_supported_sizes(data->dbox_id, &cnt, _w, _h) < 0) { - ErrPrint("No available sizes: %s\n", data->dbox_id); - return DBOX_SIZE_TYPE_UNKNOWN; + int cnt = DBOX_NR_OF_SIZE_LIST; + int i; + int _w[DBOX_NR_OF_SIZE_LIST]; + int _h[DBOX_NR_OF_SIZE_LIST]; + int type = DBOX_SIZE_TYPE_UNKNOWN; + int find; + int ret_type = DBOX_SIZE_TYPE_UNKNOWN; + int delta; + + if (dynamicbox_service_get_supported_sizes(data->dbox_id, &cnt, _w, _h) < 0) { + ErrPrint("No available sizes: %s\n", data->dbox_id); + return DBOX_SIZE_TYPE_UNKNOWN; + } + + find = 0x7FFFFFFF; + for (i = 0; i < cnt; i++) { + type = dynamicbox_service_size_type(_w[i], _h[i]); + + if (!s_info.conf.field.easy_mode) { + switch (type) { + case DBOX_SIZE_TYPE_EASY_1x1: + case DBOX_SIZE_TYPE_EASY_3x1: + case DBOX_SIZE_TYPE_EASY_3x3: + continue; + default: + break; + } + } else { + switch (type) { + case DBOX_SIZE_TYPE_EASY_1x1: + case DBOX_SIZE_TYPE_EASY_3x1: + case DBOX_SIZE_TYPE_EASY_3x3: + break; + default: + continue; + } } - find = 0x7FFFFFFF; - for (i = 0; i < cnt; i++) { - type = dynamicbox_service_size_type(_w[i], _h[i]); - - if (!s_info.conf.field.easy_mode) { - switch (type) { - case DBOX_SIZE_TYPE_EASY_1x1: - case DBOX_SIZE_TYPE_EASY_3x1: - case DBOX_SIZE_TYPE_EASY_3x3: - continue; - default: - break; - } - } else { - switch (type) { - case DBOX_SIZE_TYPE_EASY_1x1: - case DBOX_SIZE_TYPE_EASY_3x1: - case DBOX_SIZE_TYPE_EASY_3x3: - break; - default: - continue; - } - } - - delta = abs(_w[i] - w) + abs(_h[i] - h); - if (delta < find) { - find = delta; - ret_type = type; - } + delta = abs(_w[i] - w) + abs(_h[i] - h); + if (delta < find) { + find = delta; + ret_type = type; } + } - return ret_type; + return ret_type; } static Eina_Bool effect_animator_cb(void *_data) { - struct animation_data *data = _data; - int w; - int h; - int x; - int y; - int move_x = 0; - int move_y = 0; - - evas_object_geometry_get(data->obj, &x, &y, &w, &h); - if (data->w == w && data->h == h) { - evas_object_event_callback_del(data->obj, EVAS_CALLBACK_DEL, animator_del_cb); - evas_object_data_del(data->obj, "animation"); - free(data); - return ECORE_CALLBACK_CANCEL; - } - - if (data->effect_mask & EFFECT_WIDTH) { - if (w < data->w) { - if (data->w - w > 100) { - w += 20; - move_x = 20; - } else if (data->w - w > 10) { - w += 8; - move_x = 8; - } else { - w++; - move_x = 1; - } - } else if (w > data->w) { - if (w - data->w > 100) { - w -= 20; - move_x = -20; - } else if (w - data->w > 10) { - w -= 8; - move_x = -8; - } else { - w--; - move_x = -1; - } - } - } else { - w = data->w; - } - - if (data->effect_mask & EFFECT_HEIGHT) { - if (h < data->h) { - if (data->h - h > 100) { - h += 20; - move_y = 20; - } else if (data->h - h > 10) { - h += 8; - move_y = 8; - } else { - h++; - move_y = 1; - } - } else if (h > data->h) { - if (h - data->h > 100) { - h -= 20; - move_y = -20; - } else if (h - data->h > 10) { - h -= 8; - move_y = -8; - } else { - h--; - move_y = -1; - } - } - } else { - h = data->h; - } - - if (data->effect_mask & EFFECT_MOVE) { - if (move_x) { - x -= move_x; - } - if (move_y) { - y -= move_y; - } - evas_object_move(data->obj, x, y); - } - - evas_object_resize(data->obj, w, h); - return ECORE_CALLBACK_RENEW; + struct animation_data *data = _data; + int w; + int h; + int x; + int y; + int move_x = 0; + int move_y = 0; + + evas_object_geometry_get(data->obj, &x, &y, &w, &h); + if (data->w == w && data->h == h) { + evas_object_event_callback_del(data->obj, EVAS_CALLBACK_DEL, animator_del_cb); + evas_object_data_del(data->obj, "animation"); + free(data); + return ECORE_CALLBACK_CANCEL; + } + + if (data->effect_mask & EFFECT_WIDTH) { + if (w < data->w) { + if (data->w - w > 100) { + w += 20; + move_x = 20; + } else if (data->w - w > 10) { + w += 8; + move_x = 8; + } else { + w++; + move_x = 1; + } + } else if (w > data->w) { + if (w - data->w > 100) { + w -= 20; + move_x = -20; + } else if (w - data->w > 10) { + w -= 8; + move_x = -8; + } else { + w--; + move_x = -1; + } + } + } else { + w = data->w; + } + + if (data->effect_mask & EFFECT_HEIGHT) { + if (h < data->h) { + if (data->h - h > 100) { + h += 20; + move_y = 20; + } else if (data->h - h > 10) { + h += 8; + move_y = 8; + } else { + h++; + move_y = 1; + } + } else if (h > data->h) { + if (h - data->h > 100) { + h -= 20; + move_y = -20; + } else if (h - data->h > 10) { + h -= 8; + move_y = -8; + } else { + h--; + move_y = -1; + } + } + } else { + h = data->h; + } + + if (data->effect_mask & EFFECT_MOVE) { + if (move_x) { + x -= move_x; + } + if (move_y) { + y -= move_y; + } + evas_object_move(data->obj, x, y); + } + + evas_object_resize(data->obj, w, h); + return ECORE_CALLBACK_RENEW; } static void animator_del_cb(void *cbdata, Evas *e, Evas_Object *obj, void *event_info) { - struct animation_data *data; + struct animation_data *data; - data = evas_object_data_del(obj, "animation"); - if (data) { - ecore_timer_del(data->timer); - free(data); - } + data = evas_object_data_del(obj, "animation"); + if (data) { + ecore_timer_del(data->timer); + free(data); + } } static void effect_size_get(Evas_Object *obj, int *w, int *h) { - struct animation_data *data; + struct animation_data *data; - data = evas_object_data_get(obj, "animation"); - if (data) { - *w = data->w; - *h = data->h; - } else { - evas_object_geometry_get(obj, NULL, NULL, w, h); - } + data = evas_object_data_get(obj, "animation"); + if (data) { + *w = data->w; + *h = data->h; + } else { + evas_object_geometry_get(obj, NULL, NULL, w, h); + } } static void effect_resize(Evas_Object *obj, int w, int h, unsigned int effect_mask) { - struct animation_data *data; - int ow; - int oh; - int ox; - int oy; - - evas_object_geometry_get(obj, &ox, &oy, &ow, &oh); + struct animation_data *data; + int ow; + int oh; + int ox; + int oy; - data = evas_object_data_get(obj, "animation"); - if (data) { - if (ow == w && oh == h) { - evas_object_event_callback_del(obj, EVAS_CALLBACK_DEL, animator_del_cb); - evas_object_data_del(obj, "animation"); - free(data); - return; - } - /*! - * \note - * Update to new size - */ - data->w = w; - data->h = h; - return; - } else if (ow == w && oh == h) { - return; - } + evas_object_geometry_get(obj, &ox, &oy, &ow, &oh); - data = malloc(sizeof(*data)); - if (!data) { - ErrPrint("Heap: %s\n", strerror(errno)); - return; + data = evas_object_data_get(obj, "animation"); + if (data) { + if (ow == w && oh == h) { + evas_object_event_callback_del(obj, EVAS_CALLBACK_DEL, animator_del_cb); + evas_object_data_del(obj, "animation"); + free(data); + return; } - - data->obj = obj; + /*! + * \note + * Update to new size + */ data->w = w; data->h = h; - data->x = ox; - data->y = oy; - data->effect_mask = effect_mask; + return; + } else if (ow == w && oh == h) { + return; + } - data->timer = ecore_timer_add(1.0f/60.0f, effect_animator_cb, data); - if (!data->timer) { - free(data); - return; - } + data = malloc(sizeof(*data)); + if (!data) { + ErrPrint("Heap: %s\n", strerror(errno)); + return; + } + + data->obj = obj; + data->w = w; + data->h = h; + data->x = ox; + data->y = oy; + data->effect_mask = effect_mask; + + data->timer = ecore_timer_add(1.0f/60.0f, effect_animator_cb, data); + if (!data->timer) { + free(data); + return; + } - evas_object_data_set(obj, "animation", data); - evas_object_event_callback_add(obj, EVAS_CALLBACK_DEL, animator_del_cb, data); + evas_object_data_set(obj, "animation", data); + evas_object_event_callback_add(obj, EVAS_CALLBACK_DEL, animator_del_cb, data); } struct widget_data *widget_ref(struct widget_data *data) { - data->refcnt++; - return data; + data->refcnt++; + return data; } static void dump_handle_list(void) { - Eina_List *l = NULL; - Eina_List *n; - Evas_Object *dynamicbox; - struct widget_data *data; - - DbgPrint("============== DUMP ==============="); - EINA_LIST_FOREACH_SAFE(s_info.list, l, n, dynamicbox) { - data = evas_object_smart_data_get(dynamicbox); - if (!data) { - continue; - } + Eina_List *l = NULL; + Eina_List *n; + Evas_Object *dynamicbox; + struct widget_data *data; - DbgPrint("data[%p] %s (%s)\n", data, data->dbox_id, data->is.field.faulted ? "faulted" : "loaded"); + DbgPrint("============== DUMP ==============="); + EINA_LIST_FOREACH_SAFE(s_info.list, l, n, dynamicbox) { + data = evas_object_smart_data_get(dynamicbox); + if (!data) { + continue; } - DbgPrint("==================================="); + + DbgPrint("data[%p] %s (%s)\n", data, data->dbox_id, data->is.field.faulted ? "faulted" : "loaded"); + } + DbgPrint("==================================="); } struct widget_data *widget_unref(struct widget_data *data) { - data->refcnt--; - DbgPrint("refcnt: %d (%s)\n", data->refcnt, data->dbox_id); - if (data->refcnt != 0) { - return data; - } + data->refcnt--; + DbgPrint("refcnt: %d (%s)\n", data->refcnt, data->dbox_id); + if (data->refcnt != 0) { + return data; + } - DbgPrint("Destroy widget data %p(%s)\n", data, data->dbox_id); - free(data->content); - free(data->dbox_id); - free(data->cluster); - free(data->category); + DbgPrint("Destroy widget data %p(%s)\n", data, data->dbox_id); + free(data->content); + free(data->dbox_id); + free(data->cluster); + free(data->category); - if (data->overlay_timer) { - ecore_timer_del(data->overlay_timer); - data->overlay_timer = NULL; - } + if (data->overlay_timer) { + ecore_timer_del(data->overlay_timer); + data->overlay_timer = NULL; + } - if (data->stage) { - DbgPrint("Remove Stage\n"); - evas_object_del(data->stage); - } + if (data->stage) { + DbgPrint("Remove Stage\n"); + evas_object_del(data->stage); + } - if (data->dbox_layout) { - Evas_Object *content; + if (data->dbox_layout) { + Evas_Object *content; - content = elm_object_part_content_unset(data->dbox_layout, "dynamicbox,content"); - if (content) { - Evas_Object *front; + content = elm_object_part_content_unset(data->dbox_layout, "dynamicbox,content"); + if (content) { + Evas_Object *front; - front = elm_object_part_content_unset(content, "front,content"); - if (front) { - DbgPrint("Front image object is deleted\n"); - evas_object_del(front); - } + front = elm_object_part_content_unset(content, "front,content"); + if (front) { + DbgPrint("Front image object is deleted\n"); + evas_object_del(front); + } - DbgPrint("Content object deleted\n"); - evas_object_del(content); - } + DbgPrint("Content object deleted\n"); + evas_object_del(content); + } - content = elm_object_part_content_unset(data->dbox_layout, "overlay,content"); - if (content) { - DbgPrint("Overlay is deleted\n"); - evas_object_del(content); - } + content = elm_object_part_content_unset(data->dbox_layout, "overlay,content"); + if (content) { + DbgPrint("Overlay is deleted\n"); + evas_object_del(content); + } - DbgPrint("Remove DBOX Layout\n"); - evas_object_del(data->dbox_layout); - } + DbgPrint("Remove DBOX Layout\n"); + evas_object_del(data->dbox_layout); + } - if (data->gbar_layout) { - Evas_Object *content; - content = elm_object_part_content_get(data->gbar_layout, "gbar,content"); - if (content) { - Evas_Object *overlay; - overlay = elm_object_part_content_unset(content, "overlay,content"); - if (overlay) { - DbgPrint("Overlay is deleted\n"); - evas_object_del(overlay); - } - } - DbgPrint("Remove GBAR Layout\n"); - evas_object_del(data->gbar_layout); + if (data->gbar_layout) { + Evas_Object *content; + content = elm_object_part_content_get(data->gbar_layout, "gbar,content"); + if (content) { + Evas_Object *overlay; + overlay = elm_object_part_content_unset(content, "overlay,content"); + if (overlay) { + DbgPrint("Overlay is deleted\n"); + evas_object_del(overlay); + } } + DbgPrint("Remove GBAR Layout\n"); + evas_object_del(data->gbar_layout); + } - if (data->dbox_fb) { - dynamicbox_release_fb(data->dbox_fb); - data->dbox_fb = NULL; - } + if (data->dbox_fb) { + dynamicbox_release_buffer(data->dbox_fb); + data->dbox_fb = NULL; + } - if (data->gbar_fb) { - dynamicbox_release_fb(data->gbar_fb); - data->gbar_fb = NULL; - } + if (data->gbar_fb) { + dynamicbox_release_buffer(data->gbar_fb); + data->gbar_fb = NULL; + } - data->state = WIDGET_DATA_DELETED; - free(data); - dump_handle_list(); - return NULL; + data->state = WIDGET_DATA_DELETED; + free(data); + dump_handle_list(); + return NULL; } static void gbar_down_cb(void *cbdata, Evas *e, Evas_Object *obj, void *event_info) { - Evas_Event_Mouse_Down *down = event_info; - struct widget_data *data = cbdata; - struct dynamicbox_mouse_event_info minfo; - - if (data->state != WIDGET_DATA_CREATED) { - ErrPrint("Invalid widget data: %p\n", data); - return; - } - - evas_object_geometry_get(obj, &data->down.geo.x, &data->down.geo.y, &data->down.geo.w, &data->down.geo.h); - - data->x = data->down.x = down->canvas.x; - data->y = data->down.y = down->canvas.y; - data->is.field.pressed = 1; - if (s_info.conf.field.auto_render_selector) { - DbgPrint("Change to direct render\n"); - s_info.conf.field.render_animator = 0; - } + Evas_Event_Mouse_Down *down = event_info; + struct widget_data *data = cbdata; + struct dynamicbox_mouse_event_info minfo; - if (s_info.conf.field.auto_feed) { - minfo.x = (double)data->down.geo.x / (double)data->down.geo.w; - minfo.y = (double)data->down.geo.y / (double)data->down.geo.h; - dynamicbox_feed_mouse_event(data->handle, DBOX_GBAR_MOUSE_SET, &minfo); - } else { - minfo.x = (double)(down->canvas.x - data->down.geo.x) / (double)data->down.geo.w; - minfo.y = (double)(down->canvas.y - data->down.geo.y) / (double)data->down.geo.h; - dynamicbox_feed_mouse_event(data->handle, DBOX_GBAR_MOUSE_ENTER, &minfo); - dynamicbox_feed_mouse_event(data->handle, DBOX_GBAR_MOUSE_DOWN, &minfo); - } + if (data->state != WIDGET_DATA_CREATED) { + ErrPrint("Invalid widget data: %p\n", data); + return; + } + + evas_object_geometry_get(obj, &data->down.geo.x, &data->down.geo.y, &data->down.geo.w, &data->down.geo.h); + + data->x = data->down.x = down->canvas.x; + data->y = data->down.y = down->canvas.y; + data->is.field.pressed = 1; + if (s_info.conf.field.auto_render_selector) { + DbgPrint("Change to direct render\n"); + s_info.conf.field.render_animator = 0; + } + + if (s_info.conf.field.auto_feed) { + minfo.x = (double)data->down.geo.x; + minfo.y = (double)data->down.geo.y; + dynamicbox_feed_mouse_event(data->handle, DBOX_GBAR_MOUSE_SET, &minfo); + } else { + minfo.x = (double)(down->canvas.x - data->down.geo.x) / (double)data->down.geo.w; + minfo.y = (double)(down->canvas.y - data->down.geo.y) / (double)data->down.geo.h; + dynamicbox_feed_mouse_event(data->handle, DBOX_GBAR_MOUSE_ENTER, &minfo); + dynamicbox_feed_mouse_event(data->handle, DBOX_GBAR_MOUSE_DOWN, &minfo); + } } static void gbar_move_cb(void *cbdata, Evas *e, Evas_Object *obj, void *event_info) { - Evas_Event_Mouse_Move *move = event_info; - struct widget_data *data = cbdata; - Evas_Coord x, y, w, h; - struct dynamicbox_mouse_event_info minfo; + Evas_Event_Mouse_Move *move = event_info; + struct widget_data *data = cbdata; + Evas_Coord x, y, w, h; + struct dynamicbox_mouse_event_info minfo; - if (data->state != WIDGET_DATA_CREATED) { - ErrPrint("Invalid widget data: %p\n", data); - return; - } + if (data->state != WIDGET_DATA_CREATED) { + ErrPrint("Invalid widget data: %p\n", data); + return; + } - if (!data->is.field.pressed) { - return; - } + if (!data->is.field.pressed) { + return; + } - evas_object_geometry_get(obj, &x, &y, &w, &h); + evas_object_geometry_get(obj, &x, &y, &w, &h); - data->x = move->cur.canvas.x; - data->y = move->cur.canvas.y; + data->x = move->cur.canvas.x; + data->y = move->cur.canvas.y; - if (data->is.field.cancel_click != CANCEL_DISABLED || !s_info.conf.field.auto_feed) { - minfo.x = (double)(move->cur.canvas.x - x) / (double)w; - minfo.y = (double)(move->cur.canvas.y - y) / (double)h; + if (data->is.field.cancel_click != CANCEL_DISABLED || !s_info.conf.field.auto_feed) { + minfo.x = (double)(move->cur.canvas.x - x) / (double)w; + minfo.y = (double)(move->cur.canvas.y - y) / (double)h; - if (data->is.field.cancel_click == CANCEL_USER) { - dynamicbox_feed_mouse_event(data->handle, DBOX_GBAR_MOUSE_ON_HOLD, &minfo); - data->is.field.cancel_click = CANCEL_PROCESSED; - } + if (data->is.field.cancel_click == CANCEL_USER) { + dynamicbox_feed_mouse_event(data->handle, DBOX_GBAR_MOUSE_ON_HOLD, &minfo); + data->is.field.cancel_click = CANCEL_PROCESSED; + } - if (!s_info.conf.field.auto_feed) { - dynamicbox_feed_mouse_event(data->handle, DBOX_GBAR_MOUSE_MOVE, &minfo); - } + if (!s_info.conf.field.auto_feed) { + dynamicbox_feed_mouse_event(data->handle, DBOX_GBAR_MOUSE_MOVE, &minfo); + } - if (s_info.conf.field.auto_render_selector) { - DbgPrint("Change to direct render\n"); - s_info.conf.field.render_animator = 0; - } + if (s_info.conf.field.auto_render_selector) { + DbgPrint("Change to direct render\n"); + s_info.conf.field.render_animator = 0; } + } } static void dbox_pixmap_del_cb(void *cbdata, Evas *e, Evas_Object *obj, void *event_info) { - struct widget_data *data = cbdata; + struct widget_data *data = cbdata; + + if (data->dbox_pixmap) { + dynamicbox_release_resource_id(data->handle, 0, data->dbox_pixmap); + data->dbox_pixmap = 0; + } - if (data->dbox_pixmap) { - dynamicbox_release_resource_id(data->handle, 0, data->dbox_pixmap); - data->dbox_pixmap = 0; + if (data->dbox_extra) { + int idx; + + for (idx = 0; idx < dynamicbox_option(DBOX_OPTION_EXTRA_BUFFER_CNT); idx++) { + if (data->dbox_extra[idx] != 0u) { + if (dynamicbox_release_resource_id(data->handle, 0, data->dbox_extra[idx]) < 0) { + ErrPrint("Failed to release %u\n", data->dbox_extra[idx]); + } + data->dbox_extra[idx] = 0u; + } } + + free(data->dbox_extra); + data->dbox_extra = NULL; + } } static void gbar_pixmap_del_cb(void *cbdata, Evas *e, Evas_Object *obj, void *event_info) { - struct widget_data *data = cbdata; + struct widget_data *data = cbdata; + + if (data->gbar_pixmap) { + dynamicbox_release_resource_id(data->handle, 1, data->gbar_pixmap); + data->gbar_pixmap = 0; + } - if (data->gbar_pixmap) { - dynamicbox_release_resource_id(data->handle, 1, data->gbar_pixmap); - data->gbar_pixmap = 0; + if (data->gbar_extra) { + int idx; + + for (idx = 0; idx < dynamicbox_option(DBOX_OPTION_EXTRA_BUFFER_CNT); idx++) { + if (data->gbar_extra[idx] != 0u) { + if (dynamicbox_release_resource_id(data->handle, 0, data->gbar_extra[idx]) < 0) { + ErrPrint("Failed to release %u\n", data->gbar_extra[idx]); + } + data->gbar_extra[idx] = 0u; + } } + + free(data->gbar_extra); + data->gbar_extra = NULL; + } } static void gbar_up_cb(void *cbdata, Evas *e, Evas_Object *obj, void *event_info) { - Evas_Event_Mouse_Up *up = event_info; - struct widget_data *data = cbdata; - Evas_Coord x, y, w, h; - struct dynamicbox_mouse_event_info minfo; - - if (data->state != WIDGET_DATA_CREATED) { - ErrPrint("Invalid widget data: %p\n", data); - return; - } + Evas_Event_Mouse_Up *up = event_info; + struct widget_data *data = cbdata; + Evas_Coord x, y, w, h; + struct dynamicbox_mouse_event_info minfo; - if (!data->is.field.pressed) { - return; - } + if (data->state != WIDGET_DATA_CREATED) { + ErrPrint("Invalid widget data: %p\n", data); + return; + } - evas_object_geometry_get(obj, &x, &y, &w, &h); + if (!data->is.field.pressed) { + return; + } - if (s_info.conf.field.auto_feed) { - minfo.x = (double)x / (double)w; - minfo.y = (double)y / (double)h; - dynamicbox_feed_mouse_event(data->handle, DBOX_GBAR_MOUSE_UNSET, &minfo); - } else { - minfo.x = (double)(up->canvas.x - x) / (double)w; - minfo.y = (double)(up->canvas.y - y) / (double)h; + evas_object_geometry_get(obj, &x, &y, &w, &h); - if (data->down.geo.x != x || data->down.geo.y != y || data->is.field.cancel_click == CANCEL_USER) { - dynamicbox_feed_mouse_event(data->handle, DBOX_GBAR_MOUSE_ON_HOLD, &minfo); - data->is.field.cancel_click = CANCEL_PROCESSED; - } + if (s_info.conf.field.auto_feed) { + minfo.x = (double)x / (double)w; + minfo.y = (double)y / (double)h; + dynamicbox_feed_mouse_event(data->handle, DBOX_GBAR_MOUSE_UNSET, &minfo); + } else { + minfo.x = (double)(up->canvas.x - x) / (double)w; + minfo.y = (double)(up->canvas.y - y) / (double)h; - dynamicbox_feed_mouse_event(data->handle, DBOX_GBAR_MOUSE_UP, &minfo); - dynamicbox_feed_mouse_event(data->handle, DBOX_GBAR_MOUSE_LEAVE, &minfo); + if (data->down.geo.x != x || data->down.geo.y != y || data->is.field.cancel_click == CANCEL_USER) { + dynamicbox_feed_mouse_event(data->handle, DBOX_GBAR_MOUSE_ON_HOLD, &minfo); + data->is.field.cancel_click = CANCEL_PROCESSED; } - data->is.field.cancel_click = CANCEL_DISABLED; + dynamicbox_feed_mouse_event(data->handle, DBOX_GBAR_MOUSE_UP, &minfo); + dynamicbox_feed_mouse_event(data->handle, DBOX_GBAR_MOUSE_LEAVE, &minfo); + } + + data->is.field.cancel_click = CANCEL_DISABLED; } static void dbox_down_cb(void *cbdata, Evas *e, Evas_Object *obj, void *event_info) { - Evas_Event_Mouse_Down *down = event_info; - struct widget_data *data = cbdata; + Evas_Event_Mouse_Down *down = event_info; + struct widget_data *data = cbdata; - if (data->state != WIDGET_DATA_CREATED) { - ErrPrint("Invalid widget data: %p\n", data); - return; - } + if (data->state != WIDGET_DATA_CREATED) { + ErrPrint("Invalid widget data: %p\n", data); + return; + } - if (s_info.conf.field.support_gbar && !data->is.field.gbar_created) { - data->is.field.flick_down = 1; - } + if (s_info.conf.field.support_gbar && !data->is.field.gbar_created) { + data->is.field.flick_down = 1; + } - data->down.x = data->x = down->canvas.x; - data->down.y = data->y = down->canvas.y; - data->is.field.pressed = 1; - data->is.field.scroll_x = 0; - data->is.field.scroll_y = 0; - data->is.field.cancel_scroll_x = 0; - data->is.field.cancel_scroll_y = 0; + data->down.x = data->x = down->canvas.x; + data->down.y = data->y = down->canvas.y; + data->is.field.pressed = 1; + data->is.field.scroll_x = 0; + data->is.field.scroll_y = 0; + data->is.field.cancel_scroll_x = 0; + data->is.field.cancel_scroll_y = 0; - if (s_info.conf.field.auto_render_selector) { - DbgPrint("Change to direct render\n"); - s_info.conf.field.render_animator = 0; - } + if (s_info.conf.field.auto_render_selector) { + DbgPrint("Change to direct render\n"); + s_info.conf.field.render_animator = 0; + } - evas_object_geometry_get(obj, &data->down.geo.x, &data->down.geo.y, &data->down.geo.w, &data->down.geo.h); + evas_object_geometry_get(obj, &data->down.geo.x, &data->down.geo.y, &data->down.geo.w, &data->down.geo.h); - if (s_info.conf.field.sensitive_move && (data->down.geo.x != data->view_port.x || data->down.geo.y != data->view_port.y)) { - data->is.field.pressed = 0; - if (s_info.conf.field.auto_render_selector) { - DbgPrint("Change to render animator\n"); - s_info.conf.field.render_animator = 1; - } - return; + if (s_info.conf.field.sensitive_move && (data->down.geo.x != data->view_port.x || data->down.geo.y != data->view_port.y)) { + data->is.field.pressed = 0; + if (s_info.conf.field.auto_render_selector) { + DbgPrint("Change to render animator\n"); + s_info.conf.field.render_animator = 1; } + return; + } - if (data->handle && !data->is.field.faulted) { - struct dynamicbox_mouse_event_info minfo; + if (data->handle && !data->is.field.faulted) { + struct dynamicbox_mouse_event_info minfo; - if (s_info.conf.field.auto_feed && data->is.field.mouse_event) { - minfo.x = (double)data->down.geo.x / (double)data->down.geo.w; - minfo.y = (double)data->down.geo.y / (double)data->down.geo.h; - dynamicbox_feed_mouse_event(data->handle, DBOX_MOUSE_SET, &minfo); - } else { - minfo.x = (double)(data->x - data->down.geo.x) / (double)data->down.geo.w; - minfo.y = (double)(data->y - data->down.geo.y) / (double)data->down.geo.h; + if (s_info.conf.field.auto_feed && data->is.field.mouse_event) { + minfo.x = (double)data->down.geo.x; + minfo.y = (double)data->down.geo.y; + dynamicbox_feed_mouse_event(data->handle, DBOX_MOUSE_SET, &minfo); + } else { + minfo.x = (double)(data->x - data->down.geo.x) / (double)data->down.geo.w; + minfo.y = (double)(data->y - data->down.geo.y) / (double)data->down.geo.h; - dynamicbox_feed_mouse_event(data->handle, DBOX_MOUSE_ENTER, &minfo); - dynamicbox_feed_mouse_event(data->handle, DBOX_MOUSE_DOWN, &minfo); - dynamicbox_feed_mouse_event(data->handle, DBOX_MOUSE_MOVE, &minfo); - } + dynamicbox_feed_mouse_event(data->handle, DBOX_MOUSE_ENTER, &minfo); + dynamicbox_feed_mouse_event(data->handle, DBOX_MOUSE_DOWN, &minfo); + dynamicbox_feed_mouse_event(data->handle, DBOX_MOUSE_MOVE, &minfo); } + } } static void smart_callback_call(struct widget_data *data, const char *signal, void *cbdata) { - if (data->is.field.deleted || !data->dynamicbox) { - DbgPrint("Dynamicbox is deleted, ignore smart callback call\n"); - return; - } + if (data->is.field.deleted || !data->dynamicbox) { + DbgPrint("Dynamicbox is deleted, ignore smart callback call\n"); + return; + } - evas_object_smart_callback_call(data->dynamicbox, signal, cbdata); + evas_object_smart_callback_call(data->dynamicbox, signal, cbdata); } static void dbox_destroy_gbar_cb(struct dynamicbox *handle, int ret, void *cbdata) { - struct widget_data *data = cbdata; - Evas_Object *gbar_content; - struct dynamicbox_evas_event_info info; + struct widget_data *data = cbdata; + Evas_Object *gbar_content; + struct dynamicbox_evas_event_info info; - if (data->state != WIDGET_DATA_CREATED) { - ErrPrint("Invalid widget data: %p\n", data); - return; - } + if (data->state != WIDGET_DATA_CREATED) { + ErrPrint("Invalid widget data: %p\n", data); + return; + } - data->is.field.gbar_created = 0; + data->is.field.gbar_created = 0; - info.error = ret; - info.event = DBOX_EVENT_GBAR_DESTROYED; - info.pkgname = data->dbox_id; - smart_callback_call(data, DYNAMICBOX_SMART_SIGNAL_GBAR_DESTROYED, &info); - - DbgPrint("ret: %d\n", ret); - gbar_content = elm_object_part_content_unset(data->gbar_layout, "gbar,content"); - if (gbar_content) { - Evas_Native_Surface *surface; - unsigned int pixmap; - - switch (dynamicbox_type(data->handle, 1)) { - case DBOX_CONTENT_TYPE_RESOURCE_ID: - if (!s_info.conf.field.force_to_buffer) { - surface = evas_object_image_native_surface_get(gbar_content); - if (!surface) { - ErrPrint("surface is NULL\n"); - evas_object_del(gbar_content); - break; - } - - pixmap = surface->data.x11.pixmap; - evas_object_del(gbar_content); - - dynamicbox_release_resource_id(data->handle, 1, (int)pixmap); - if (pixmap == data->gbar_pixmap) { - data->gbar_pixmap = 0; - } - break; - } - case DBOX_CONTENT_TYPE_BUFFER: - if (data->gbar_fb) { - dynamicbox_release_fb(data->gbar_fb); - data->gbar_fb = NULL; - } + info.error = ret; + info.event = DBOX_EVENT_GBAR_DESTROYED; + info.pkgname = data->dbox_id; + smart_callback_call(data, DYNAMICBOX_SMART_SIGNAL_GBAR_DESTROYED, &info); + + DbgPrint("ret: %d\n", ret); + gbar_content = elm_object_part_content_unset(data->gbar_layout, "gbar,content"); + if (gbar_content) { + Evas_Native_Surface *surface; + unsigned int pixmap; + + switch (dynamicbox_type(data->handle, 1)) { + case DBOX_CONTENT_TYPE_RESOURCE_ID: + if (!s_info.conf.field.force_to_buffer) { + surface = evas_object_image_native_surface_get(gbar_content); + if (!surface) { + ErrPrint("surface is NULL\n"); evas_object_del(gbar_content); break; - case DBOX_CONTENT_TYPE_TEXT: - break; - case DBOX_CONTENT_TYPE_UIFW: - break; - case DBOX_CONTENT_TYPE_INVALID: - default: - break; + } + + pixmap = surface->data.x11.pixmap; + evas_object_del(gbar_content); + + dynamicbox_release_resource_id(data->handle, 1, (int)pixmap); + if (pixmap == data->gbar_pixmap) { + data->gbar_pixmap = 0; + } + break; + } + case DBOX_CONTENT_TYPE_BUFFER: + if (data->gbar_fb) { + dynamicbox_release_buffer(data->gbar_fb); + data->gbar_fb = NULL; } + evas_object_del(gbar_content); + break; + case DBOX_CONTENT_TYPE_TEXT: + break; + case DBOX_CONTENT_TYPE_UIFW: + break; + case DBOX_CONTENT_TYPE_INVALID: + default: + break; } + } - if (data->gbar_layout) { - evas_object_del(data->gbar_layout); - data->gbar_layout = NULL; - } + if (data->gbar_layout) { + evas_object_del(data->gbar_layout); + data->gbar_layout = NULL; + } - remove_gbar_dirty_object_list(data); - widget_unref(data); + remove_gbar_dirty_object_list(data); + widget_unref(data); } static void gbar_animation_done_cb(void *cbdata, Evas_Object *obj, const char *emission, const char *source) { - Evas_Object *rect; - struct widget_data *data = cbdata; + Evas_Object *rect; + struct widget_data *data = cbdata; - if (data->state != WIDGET_DATA_CREATED) { - ErrPrint("Invalid widget data: %p\n", data); - return; - } + if (data->state != WIDGET_DATA_CREATED) { + ErrPrint("Invalid widget data: %p\n", data); + return; + } - rect = elm_object_part_content_unset(obj, "overlay,content"); - if (rect) { - evas_object_del(rect); - } + rect = elm_object_part_content_unset(obj, "overlay,content"); + if (rect) { + evas_object_del(rect); + } } static void gbar_create_buffer_object(struct widget_data *data) { - Evas_Object *gbar_content; + Evas_Object *gbar_content; - gbar_content = evas_object_image_filled_add(data->e); - if (!gbar_content) { - ErrPrint("Failed to create an image object\n"); - } else { - evas_object_image_colorspace_set(gbar_content, EVAS_COLORSPACE_ARGB8888); - evas_object_image_alpha_set(gbar_content, EINA_TRUE); + gbar_content = evas_object_image_filled_add(data->e); + if (!gbar_content) { + ErrPrint("Failed to create an image object\n"); + } else { + evas_object_image_colorspace_set(gbar_content, EVAS_COLORSPACE_ARGB8888); + evas_object_image_alpha_set(gbar_content, EINA_TRUE); - elm_object_part_content_set(data->gbar_layout, "gbar,content", gbar_content); - } + elm_object_part_content_set(data->gbar_layout, "gbar,content", gbar_content); + } } static void gbar_create_text_object(struct widget_data *data) { - ErrPrint("Unsupported\n"); - /*! - * \todo - */ + ErrPrint("Unsupported\n"); + /*! + * \todo + */ } static void gbar_create_pixmap_object(struct widget_data *data) { - Evas_Object *gbar_content; + Evas_Object *gbar_content; - gbar_content = evas_object_image_filled_add(data->e); - if (!gbar_content) { - ErrPrint("Failed to create an image object\n"); - return; - } + gbar_content = evas_object_image_filled_add(data->e); + if (!gbar_content) { + ErrPrint("Failed to create an image object\n"); + return; + } - evas_object_image_colorspace_set(gbar_content, EVAS_COLORSPACE_ARGB8888); - evas_object_image_alpha_set(gbar_content, EINA_TRUE); - elm_object_part_content_set(data->gbar_layout, "gbar,content", gbar_content); + evas_object_image_colorspace_set(gbar_content, EVAS_COLORSPACE_ARGB8888); + evas_object_image_alpha_set(gbar_content, EINA_TRUE); + elm_object_part_content_set(data->gbar_layout, "gbar,content", gbar_content); - evas_object_event_callback_add(gbar_content, EVAS_CALLBACK_MOUSE_DOWN, gbar_down_cb, data); - evas_object_event_callback_add(gbar_content, EVAS_CALLBACK_MOUSE_MOVE, gbar_move_cb, data); - evas_object_event_callback_add(gbar_content, EVAS_CALLBACK_MOUSE_UP, gbar_up_cb, data); - evas_object_event_callback_add(gbar_content, EVAS_CALLBACK_DEL, gbar_pixmap_del_cb, data); + evas_object_event_callback_add(gbar_content, EVAS_CALLBACK_MOUSE_DOWN, gbar_down_cb, data); + evas_object_event_callback_add(gbar_content, EVAS_CALLBACK_MOUSE_MOVE, gbar_move_cb, data); + evas_object_event_callback_add(gbar_content, EVAS_CALLBACK_MOUSE_UP, gbar_up_cb, data); + evas_object_event_callback_add(gbar_content, EVAS_CALLBACK_DEL, gbar_pixmap_del_cb, data); } static void dbox_create_gbar_cb(struct dynamicbox *handle, int ret, void *cbdata) { - struct widget_data *data = cbdata; - struct dynamicbox_evas_event_info info; + struct widget_data *data = cbdata; + struct dynamicbox_evas_event_info info; - if (data->state != WIDGET_DATA_CREATED) { - ErrPrint("Invalid widget data: %p\n", data); - return; - } + if (data->state != WIDGET_DATA_CREATED) { + ErrPrint("Invalid widget data: %p\n", data); + return; + } - if (ret != DBOX_STATUS_ERROR_NONE) { - DbgPrint("Create GBAR: 0x%X\n", ret); - info.error = ret; - info.event = DBOX_EVENT_GBAR_CREATED; - info.pkgname = data->dbox_id; - smart_callback_call(data, DYNAMICBOX_SMART_SIGNAL_GBAR_ABORTED, &info); - widget_unref(data); - return; - } + if (ret != DBOX_STATUS_ERROR_NONE) { + DbgPrint("Create GBAR: 0x%X\n", ret); + info.error = ret; + info.event = DBOX_EVENT_GBAR_CREATED; + info.pkgname = data->dbox_id; + smart_callback_call(data, DYNAMICBOX_SMART_SIGNAL_GBAR_ABORTED, &info); + widget_unref(data); + return; + } - if (data->is.field.deleted) { - /** - * Evas Object is deleted. - * Do not proceed this process anymore and destroy GBAR too - */ - dynamicbox_destroy_glance_bar(data->handle, NULL, NULL); - return; - } + if (data->is.field.deleted) { + /** + * Evas Object is deleted. + * Do not proceed this process anymore and destroy GBAR too + */ + dynamicbox_destroy_glance_bar(data->handle, NULL, NULL); + return; + } - DbgPrint("GBAR is created\n"); + DbgPrint("GBAR is created\n"); + if (!data->gbar_layout) { + data->gbar_layout = elm_layout_add(data->parent); if (!data->gbar_layout) { - data->gbar_layout = elm_layout_add(data->parent); - if (!data->gbar_layout) { - ErrPrint("Failed to add an edje\n"); - info.error = DBOX_STATUS_ERROR_FAULT; - info.event = DBOX_EVENT_GBAR_CREATED; - info.pkgname = data->dbox_id; - smart_callback_call(data, DYNAMICBOX_SMART_SIGNAL_GBAR_ABORTED, &info); - - ret = dynamicbox_destroy_glance_bar(data->handle, dbox_destroy_gbar_cb, widget_ref(data)); - if (ret < 0) { - /*! - * \note - * PREVENT detect this. but it is FALSE POSITIVE - * - * widget_ref will increase the refcnt of data. - * and it is called when calling the dynamicbox_destroy_glance_bar function (via the last param) - * So this function call will not release the data. - */ - widget_unref(data); - } - - widget_unref(data); - return; - } + ErrPrint("Failed to add an edje\n"); + info.error = DBOX_STATUS_ERROR_FAULT; + info.event = DBOX_EVENT_GBAR_CREATED; + info.pkgname = data->dbox_id; + smart_callback_call(data, DYNAMICBOX_SMART_SIGNAL_GBAR_ABORTED, &info); + + ret = dynamicbox_destroy_glance_bar(data->handle, dbox_destroy_gbar_cb, widget_ref(data)); + if (ret < 0) { + /*! + * \note + * PREVENT detect this. but it is FALSE POSITIVE + * + * widget_ref will increase the refcnt of data. + * and it is called when calling the dynamicbox_destroy_glance_bar function (via the last param) + * So this function call will not release the data. + */ + widget_unref(data); + } - if (elm_layout_file_set(data->gbar_layout, DYNAMICBOX_EVAS_RESOURCE_EDJ, DYNAMICBOX_EVAS_RESOURCE_GBAR) == EINA_FALSE) { - ErrPrint("Failed to load edje object: %s(%s)\n", DYNAMICBOX_EVAS_RESOURCE_EDJ, DYNAMICBOX_EVAS_RESOURCE_GBAR); - evas_object_del(data->gbar_layout); - data->gbar_layout = NULL; - - info.error = DBOX_STATUS_ERROR_IO_ERROR; - info.event = DBOX_EVENT_GBAR_CREATED; - info.pkgname = data->dbox_id; - smart_callback_call(data, DYNAMICBOX_SMART_SIGNAL_GBAR_ABORTED, &info); - - ret = dynamicbox_destroy_glance_bar(data->handle, dbox_destroy_gbar_cb, widget_ref(data)); - if (ret < 0) { - /*! - * \note - * PREVENT detect this. but it is FALSE POSITIVE - * - * widget_ref will increase the refcnt of data. - * and it is called when calling the dynamicbox_destroy_glance_bar function (via the last param) - * So this function call will not release the data. - */ - widget_unref(data); - } - - widget_unref(data); - return; - } + widget_unref(data); + return; + } - evas_object_smart_member_add(data->gbar_layout, data->dynamicbox); - evas_object_clip_set(data->gbar_layout, data->stage); - elm_object_signal_callback_add(data->gbar_layout, "finished", "animation", gbar_animation_done_cb, data); - evas_object_show(data->gbar_layout); + if (elm_layout_file_set(data->gbar_layout, DYNAMICBOX_EVAS_RESOURCE_EDJ, DYNAMICBOX_EVAS_RESOURCE_GBAR) == EINA_FALSE) { + ErrPrint("Failed to load edje object: %s(%s)\n", DYNAMICBOX_EVAS_RESOURCE_EDJ, DYNAMICBOX_EVAS_RESOURCE_GBAR); + evas_object_del(data->gbar_layout); + data->gbar_layout = NULL; + + info.error = DBOX_STATUS_ERROR_IO_ERROR; + info.event = DBOX_EVENT_GBAR_CREATED; + info.pkgname = data->dbox_id; + smart_callback_call(data, DYNAMICBOX_SMART_SIGNAL_GBAR_ABORTED, &info); + + ret = dynamicbox_destroy_glance_bar(data->handle, dbox_destroy_gbar_cb, widget_ref(data)); + if (ret < 0) { + /*! + * \note + * PREVENT detect this. but it is FALSE POSITIVE + * + * widget_ref will increase the refcnt of data. + * and it is called when calling the dynamicbox_destroy_glance_bar function (via the last param) + * So this function call will not release the data. + */ + widget_unref(data); + } + + widget_unref(data); + return; } - gbar_overlay_loading(data); - switch (dynamicbox_type(data->handle, 1)) { + evas_object_smart_member_add(data->gbar_layout, data->dynamicbox); + evas_object_clip_set(data->gbar_layout, data->stage); + elm_object_signal_callback_add(data->gbar_layout, "finished", "animation", gbar_animation_done_cb, data); + evas_object_show(data->gbar_layout); + } + gbar_overlay_loading(data); + + switch (dynamicbox_type(data->handle, 1)) { case DBOX_CONTENT_TYPE_RESOURCE_ID: - if (!s_info.conf.field.force_to_buffer) { - gbar_create_pixmap_object(data); - break; - } - case DBOX_CONTENT_TYPE_BUFFER: - gbar_create_buffer_object(data); + if (!s_info.conf.field.force_to_buffer) { + gbar_create_pixmap_object(data); break; + } + case DBOX_CONTENT_TYPE_BUFFER: + gbar_create_buffer_object(data); + break; case DBOX_CONTENT_TYPE_TEXT: - gbar_create_text_object(data); - break; + gbar_create_text_object(data); + break; case DBOX_CONTENT_TYPE_UIFW: - break; + break; default: - info.error = DBOX_STATUS_ERROR_INVALID_PARAMETER; - info.event = DBOX_EVENT_GBAR_CREATED; - info.pkgname = data->dbox_id; - ret = dynamicbox_destroy_glance_bar(data->handle, dbox_destroy_gbar_cb, widget_ref(data)); - if (ret < 0) { - /*! - * \note - * PREVENT detect this. but it is FALSE POSITIVE - * - * widget_ref will increase the refcnt of data. - * and it is called when calling the dynamicbox_destroy_glance_bar function (via the last param) - * So this function call will not release the data. - */ - widget_unref(data); - } - ErrPrint("Failed to create a GBAR, unknown type\n"); - smart_callback_call(data, DYNAMICBOX_SMART_SIGNAL_GBAR_ABORTED, &info); + info.error = DBOX_STATUS_ERROR_INVALID_PARAMETER; + info.event = DBOX_EVENT_GBAR_CREATED; + info.pkgname = data->dbox_id; + ret = dynamicbox_destroy_glance_bar(data->handle, dbox_destroy_gbar_cb, widget_ref(data)); + if (ret < 0) { + /*! + * \note + * PREVENT detect this. but it is FALSE POSITIVE + * + * widget_ref will increase the refcnt of data. + * and it is called when calling the dynamicbox_destroy_glance_bar function (via the last param) + * So this function call will not release the data. + */ widget_unref(data); - return; - } + } + ErrPrint("Failed to create a GBAR, unknown type\n"); + smart_callback_call(data, DYNAMICBOX_SMART_SIGNAL_GBAR_ABORTED, &info); + widget_unref(data); + return; + } - data->is.field.gbar_created = 1; - info.error = DBOX_STATUS_ERROR_NONE; - info.event = DBOX_EVENT_GBAR_CREATED; - info.pkgname = data->dbox_id; - smart_callback_call(data, DYNAMICBOX_SMART_SIGNAL_GBAR_CREATED, &info); - widget_unref(data); + data->is.field.gbar_created = 1; + info.error = DBOX_STATUS_ERROR_NONE; + info.event = DBOX_EVENT_GBAR_CREATED; + info.pkgname = data->dbox_id; + smart_callback_call(data, DYNAMICBOX_SMART_SIGNAL_GBAR_CREATED, &info); + widget_unref(data); } static void update_scroll_flag(struct widget_data *data, int x, int y) { - if (s_info.conf.field.is_scroll_x && !s_info.conf.field.is_scroll_y) { - if (!data->is.field.scroll_x && abs(y - data->down.y) > CLICK_REGION && (abs(x - data->down.x) <= CLICK_REGION)) { - data->is.field.cancel_scroll_x = 1; - } + if (s_info.conf.field.is_scroll_x && !s_info.conf.field.is_scroll_y) { + if (!data->is.field.scroll_x && abs(y - data->down.y) > CLICK_REGION && (abs(x - data->down.x) <= CLICK_REGION)) { + data->is.field.cancel_scroll_x = 1; } + } - if (s_info.conf.field.is_scroll_y && !s_info.conf.field.is_scroll_x) { - if (!data->is.field.scroll_y && abs(x - data->down.x) > CLICK_REGION && (abs(y - data->down.y) <= CLICK_REGION)) { - data->is.field.cancel_scroll_y = 1; - } + if (s_info.conf.field.is_scroll_y && !s_info.conf.field.is_scroll_x) { + if (!data->is.field.scroll_y && abs(x - data->down.x) > CLICK_REGION && (abs(y - data->down.y) <= CLICK_REGION)) { + data->is.field.cancel_scroll_y = 1; } + } - data->is.field.scroll_x = s_info.conf.field.is_scroll_x && (!!(data->is.field.scroll_x || (abs(x - data->down.x) > CLICK_REGION))); - data->is.field.scroll_y = s_info.conf.field.is_scroll_y && (!!(data->is.field.scroll_y || (abs(y - data->down.y) > CLICK_REGION))); - data->is.field.scroll_x = !data->is.field.cancel_scroll_x && data->is.field.scroll_x; - data->is.field.scroll_y = !data->is.field.cancel_scroll_y && data->is.field.scroll_y; + data->is.field.scroll_x = s_info.conf.field.is_scroll_x && (!!(data->is.field.scroll_x || (abs(x - data->down.x) > CLICK_REGION))); + data->is.field.scroll_y = s_info.conf.field.is_scroll_y && (!!(data->is.field.scroll_y || (abs(y - data->down.y) > CLICK_REGION))); + data->is.field.scroll_x = !data->is.field.cancel_scroll_x && data->is.field.scroll_x; + data->is.field.scroll_y = !data->is.field.cancel_scroll_y && data->is.field.scroll_y; } static void dbox_up_cb(void *cbdata, Evas *e, Evas_Object *obj, void *event_info) { - Evas_Event_Mouse_Up *up = event_info; - struct dynamicbox_evas_event_info info; - struct widget_data *data = cbdata; - Evas_Coord x, y, w, h; - int ret = 0; + Evas_Event_Mouse_Up *up = event_info; + struct dynamicbox_evas_event_info info; + struct widget_data *data = cbdata; + Evas_Coord x, y, w, h; + int ret = 0; - if (data->state != WIDGET_DATA_CREATED) { - ErrPrint("Invalid widget data: %p\n", data); - return; - } + if (data->state != WIDGET_DATA_CREATED) { + ErrPrint("Invalid widget data: %p\n", data); + return; + } - if (!data->is.field.pressed) { - return; - } + if (!data->is.field.pressed) { + return; + } - update_scroll_flag(data, up->canvas.x, up->canvas.y); + update_scroll_flag(data, up->canvas.x, up->canvas.y); - data->x = up->canvas.x; - data->y = up->canvas.y; - data->is.field.pressed = 0; + data->x = up->canvas.x; + data->y = up->canvas.y; + data->is.field.pressed = 0; - if (s_info.conf.field.auto_render_selector) { - DbgPrint("Change to render animator\n"); - s_info.conf.field.render_animator = 1; - } + if (s_info.conf.field.auto_render_selector) { + DbgPrint("Change to render animator\n"); + s_info.conf.field.render_animator = 1; + } - info.pkgname = data->dbox_id; - info.event = DBOX_EVENT_GBAR_CREATED; + info.pkgname = data->dbox_id; + info.event = DBOX_EVENT_GBAR_CREATED; + + if (s_info.conf.field.support_gbar && data->is.field.flick_down && data->y - data->down.y < CLICK_REGION) { + DbgPrint("Flick down is canceled\n"); + data->is.field.flick_down = 0; + info.error = DBOX_STATUS_ERROR_CANCEL; + smart_callback_call(data, DYNAMICBOX_SMART_SIGNAL_FLICKDOWN_CANCELLED, &info); + } + + evas_object_geometry_get(data->dynamicbox, &x, &y, &w, &h); + + if (data->is.field.flick_down) { + data->is.field.flick_down = 0; + if (!data->handle || data->is.field.faulted || !dynamicbox_has_glance_bar(data->handle)) { + if (!data->is.field.gbar_created && s_info.conf.field.support_gbar) { + elm_object_signal_emit(data->dbox_layout, "tilt", "content"); + } + DbgPrint("Flick down is canceled\n"); + info.error = DBOX_STATUS_ERROR_CANCEL; + smart_callback_call(data, DYNAMICBOX_SMART_SIGNAL_FLICKDOWN_CANCELLED, &info); + } else if (s_info.conf.field.support_gbar && !data->is.field.gbar_created) { + double rx; + double ry; + int gbar_w; + int gbar_h; + + if (dynamicbox_get_glance_bar_size(data->handle, &gbar_w, &gbar_h) != DBOX_STATUS_ERROR_NONE) { + gbar_w = 0; + gbar_h = 0; + } + + elm_object_signal_emit(data->dbox_layout, "move,down", "content"); + + rx = ((double)x + (double)w / 2.0f) / (double)s_info.screen_width; + DbgPrint("x[%d], w[%d], rx[%lf]\n", x, w, rx); + // 0.0 0.125 0.25 0.375 0.5 0.625 0.75 0.875 1.0 + switch (dynamicbox_size(data->handle)) { + case DBOX_SIZE_TYPE_1x1: + if (rx < 0.25f) { + rx = 0.125f; + } else if (rx < 0.5f) { + rx = 0.375f; + } else if (rx < 0.75f) { + rx = 0.625f; + } else if (rx < 1.0f) { + rx = 0.875f; + } + break; + case DBOX_SIZE_TYPE_2x1: + case DBOX_SIZE_TYPE_2x2: + if (rx < 0.5f) { + rx = 0.25f; + } else if (rx < 0.625f) { + rx = 0.5f; + } else { + rx = 0.75f; + } + break; + default: + rx = 0.5f; + break; + } + + if (y + h + gbar_h <= s_info.screen_height) { + ry = 0.0f; + } else { + ry = 1.0f; + } - if (s_info.conf.field.support_gbar && data->is.field.flick_down && data->y - data->down.y < CLICK_REGION) { + DbgPrint("converted rx[%lf], ry[%lf]\n", rx, ry); + + ret = dynamicbox_create_glance_bar(data->handle, rx, ry, dbox_create_gbar_cb, widget_ref(data)); + if (ret < 0) { + widget_unref(data); DbgPrint("Flick down is canceled\n"); - data->is.field.flick_down = 0; info.error = DBOX_STATUS_ERROR_CANCEL; smart_callback_call(data, DYNAMICBOX_SMART_SIGNAL_FLICKDOWN_CANCELLED, &info); + } + DbgPrint("Create GBAR: %d (%lfx%lf)\n", ret, rx, ry); } + } - evas_object_geometry_get(data->dynamicbox, &x, &y, &w, &h); - - if (data->is.field.flick_down) { - data->is.field.flick_down = 0; - if (!data->handle || data->is.field.faulted || !dynamicbox_has_glance_bar(data->handle)) { - if (!data->is.field.gbar_created && s_info.conf.field.support_gbar) { - elm_object_signal_emit(data->dbox_layout, "tilt", "content"); - } - DbgPrint("Flick down is canceled\n"); - info.error = DBOX_STATUS_ERROR_CANCEL; - smart_callback_call(data, DYNAMICBOX_SMART_SIGNAL_FLICKDOWN_CANCELLED, &info); - } else if (s_info.conf.field.support_gbar && !data->is.field.gbar_created) { - double rx; - double ry; - int gbar_w; - int gbar_h; - - if (dynamicbox_get_glance_bar_size(data->handle, &gbar_w, &gbar_h) != DBOX_STATUS_ERROR_NONE) { - gbar_w = 0; - gbar_h = 0; - } - - elm_object_signal_emit(data->dbox_layout, "move,down", "content"); - - rx = ((double)x + (double)w / 2.0f) / (double)s_info.screen_width; - DbgPrint("x[%d], w[%d], rx[%lf]\n", x, w, rx); - // 0.0 0.125 0.25 0.375 0.5 0.625 0.75 0.875 1.0 - switch (dynamicbox_size(data->handle)) { - case DBOX_SIZE_TYPE_1x1: - if (rx < 0.25f) { - rx = 0.125f; - } else if (rx < 0.5f) { - rx = 0.375f; - } else if (rx < 0.75f) { - rx = 0.625f; - } else if (rx < 1.0f) { - rx = 0.875f; - } - break; - case DBOX_SIZE_TYPE_2x1: - case DBOX_SIZE_TYPE_2x2: - if (rx < 0.5f) { - rx = 0.25f; - } else if (rx < 0.625f) { - rx = 0.5f; - } else { - rx = 0.75f; - } - break; - default: - rx = 0.5f; - break; - } - - if (y + h + gbar_h <= s_info.screen_height) { - ry = 0.0f; - } else { - ry = 1.0f; - } - - DbgPrint("converted rx[%lf], ry[%lf]\n", rx, ry); - - ret = dynamicbox_create_glance_bar(data->handle, rx, ry, dbox_create_gbar_cb, widget_ref(data)); - if (ret < 0) { - widget_unref(data); - DbgPrint("Flick down is canceled\n"); - info.error = DBOX_STATUS_ERROR_CANCEL; - smart_callback_call(data, DYNAMICBOX_SMART_SIGNAL_FLICKDOWN_CANCELLED, &info); - } - DbgPrint("Create GBAR: %d (%lfx%lf)\n", ret, rx, ry); - } - } - - if (data->handle && !data->is.field.faulted) { - struct dynamicbox_mouse_event_info minfo; + if (data->handle && !data->is.field.faulted) { + struct dynamicbox_mouse_event_info minfo; - minfo.x = (double)(data->x - x) / (double)w; - minfo.y = (double)(data->y - y) / (double)h; + minfo.x = (double)(data->x - x) / (double)w; + minfo.y = (double)(data->y - y) / (double)h; - evas_object_geometry_get(obj, &x, &y, NULL, NULL); + evas_object_geometry_get(obj, &x, &y, NULL, NULL); - reset_scroller(data); + reset_scroller(data); - if (s_info.conf.field.auto_feed && data->is.field.mouse_event) { - struct dynamicbox_mouse_event_info _minfo; + if (s_info.conf.field.auto_feed && data->is.field.mouse_event) { + struct dynamicbox_mouse_event_info _minfo; - if (data->down.geo.x != x || data->down.geo.y != y || data->is.field.scroll_x || data->is.field.scroll_y || data->is.field.cancel_click == CANCEL_USER) { - dynamicbox_feed_mouse_event(data->handle, DBOX_MOUSE_ON_HOLD, &minfo); - data->is.field.cancel_click = CANCEL_PROCESSED; - } + if (data->down.geo.x != x || data->down.geo.y != y || data->is.field.scroll_x || data->is.field.scroll_y || data->is.field.cancel_click == CANCEL_USER) { + dynamicbox_feed_mouse_event(data->handle, DBOX_MOUSE_ON_HOLD, &minfo); + data->is.field.cancel_click = CANCEL_PROCESSED; + } - _minfo.x = (double)data->down.geo.x / (double)data->down.geo.w; - _minfo.y = (double)data->down.geo.y / (double)data->down.geo.h; - dynamicbox_feed_mouse_event(data->handle, DBOX_MOUSE_UNSET, &_minfo); - } else { - if (!data->is.field.mouse_event) { - /* We have to keep the first position of touch down */ - minfo.x = (double)(data->down.x - x) / (double)w; - minfo.y = (double)(data->down.y - y) / (double)h; - if (data->down.geo.x != x || data->down.geo.y != y || data->is.field.scroll_x || data->is.field.scroll_y || data->is.field.cancel_click == CANCEL_USER || abs(data->x - data->down.x) > CLICK_REGION || abs(data->y - data->down.y) > CLICK_REGION) { - dynamicbox_feed_mouse_event(data->handle, DBOX_MOUSE_ON_HOLD, &minfo); - data->is.field.cancel_click = CANCEL_PROCESSED; - } - } else { - if (data->down.geo.x != x || data->down.geo.y != y || data->is.field.scroll_x || data->is.field.scroll_y || data->is.field.cancel_click == CANCEL_USER) { - dynamicbox_feed_mouse_event(data->handle, DBOX_MOUSE_ON_HOLD, &minfo); - data->is.field.cancel_click = CANCEL_PROCESSED; - } - } - - dynamicbox_feed_mouse_event(data->handle, DBOX_MOUSE_UP, &minfo); - dynamicbox_feed_mouse_event(data->handle, DBOX_MOUSE_LEAVE, &minfo); + _minfo.x = (double)data->down.geo.x / (double)data->down.geo.w; + _minfo.y = (double)data->down.geo.y / (double)data->down.geo.h; + dynamicbox_feed_mouse_event(data->handle, DBOX_MOUSE_UNSET, &_minfo); + } else { + if (!data->is.field.mouse_event) { + /* We have to keep the first position of touch down */ + minfo.x = (double)(data->down.x - x) / (double)w; + minfo.y = (double)(data->down.y - y) / (double)h; + if (data->down.geo.x != x || data->down.geo.y != y || data->is.field.scroll_x || data->is.field.scroll_y || data->is.field.cancel_click == CANCEL_USER || abs(data->x - data->down.x) > CLICK_REGION || abs(data->y - data->down.y) > CLICK_REGION) { + dynamicbox_feed_mouse_event(data->handle, DBOX_MOUSE_ON_HOLD, &minfo); + data->is.field.cancel_click = CANCEL_PROCESSED; } - - if (!data->is.field.flick_down) { - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - if (data->is.field.gbar_created) { - ret = dynamicbox_destroy_glance_bar(data->handle, dbox_destroy_gbar_cb, widget_ref(data)); - if (ret < 0) { - widget_unref(data); - } - } else if (data->is.field.cancel_click == CANCEL_DISABLED) { - ret = dynamicbox_click(data->handle, minfo.x, minfo.y); - } + } else { + if (data->down.geo.x != x || data->down.geo.y != y || data->is.field.scroll_x || data->is.field.scroll_y || data->is.field.cancel_click == CANCEL_USER) { + dynamicbox_feed_mouse_event(data->handle, DBOX_MOUSE_ON_HOLD, &minfo); + data->is.field.cancel_click = CANCEL_PROCESSED; } + } + + dynamicbox_feed_mouse_event(data->handle, DBOX_MOUSE_UP, &minfo); + dynamicbox_feed_mouse_event(data->handle, DBOX_MOUSE_LEAVE, &minfo); + } - DbgPrint("Up: %lfx%lf [x:%d/%d/%d] [y:%d/%d/%d], ret: 0x%X, cancel: 0x%x\n", - minfo.x, minfo.y, - data->is.field.scroll_x, s_info.conf.field.is_scroll_x, data->is.field.cancel_scroll_x, - data->is.field.scroll_y, s_info.conf.field.is_scroll_y, data->is.field.cancel_scroll_y, - ret, data->is.field.cancel_click); - data->is.field.cancel_click = CANCEL_DISABLED; + if (!data->is.field.flick_down) { + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + if (data->is.field.gbar_created) { + ret = dynamicbox_destroy_glance_bar(data->handle, dbox_destroy_gbar_cb, widget_ref(data)); + if (ret < 0) { + widget_unref(data); + } + } else if (data->is.field.cancel_click == CANCEL_DISABLED) { + ret = dynamicbox_click(data->handle, minfo.x, minfo.y); + } } + + DbgPrint("Up: %lfx%lf [x:%d/%d/%d] [y:%d/%d/%d], ret: 0x%X, cancel: 0x%x\n", + minfo.x, minfo.y, + data->is.field.scroll_x, s_info.conf.field.is_scroll_x, data->is.field.cancel_scroll_x, + data->is.field.scroll_y, s_info.conf.field.is_scroll_y, data->is.field.cancel_scroll_y, + ret, data->is.field.cancel_click); + data->is.field.cancel_click = CANCEL_DISABLED; + } } static void dbox_move_cb(void *cbdata, Evas *e, Evas_Object *obj, void *event_info) { - Evas_Event_Mouse_Move *move = event_info; - struct widget_data *data = cbdata; + Evas_Event_Mouse_Move *move = event_info; + struct widget_data *data = cbdata; - if (data->state != WIDGET_DATA_CREATED) { - ErrPrint("Invalid widget data: %p\n", data); - return; - } + if (data->state != WIDGET_DATA_CREATED) { + ErrPrint("Invalid widget data: %p\n", data); + return; + } - if (!data->is.field.pressed) { - return; - } + if (!data->is.field.pressed) { + return; + } - if (s_info.conf.field.support_gbar && data->is.field.flick_down && data->y - move->cur.canvas.y > 0) { - struct dynamicbox_evas_event_info info; + if (s_info.conf.field.support_gbar && data->is.field.flick_down && data->y - move->cur.canvas.y > 0) { + struct dynamicbox_evas_event_info info; - DbgPrint("Flick down is canceled\n"); - data->is.field.flick_down = 0; - info.pkgname = data->dbox_id; - info.event = DBOX_EVENT_GBAR_CREATED; - info.error = DBOX_STATUS_ERROR_CANCEL; + DbgPrint("Flick down is canceled\n"); + data->is.field.flick_down = 0; + info.pkgname = data->dbox_id; + info.event = DBOX_EVENT_GBAR_CREATED; + info.error = DBOX_STATUS_ERROR_CANCEL; - smart_callback_call(data, DYNAMICBOX_SMART_SIGNAL_FLICKDOWN_CANCELLED, &info); - } + smart_callback_call(data, DYNAMICBOX_SMART_SIGNAL_FLICKDOWN_CANCELLED, &info); + } - update_scroll_flag(data, move->cur.canvas.x, move->cur.canvas.y); + update_scroll_flag(data, move->cur.canvas.x, move->cur.canvas.y); - data->x = move->cur.canvas.x; - data->y = move->cur.canvas.y; + data->x = move->cur.canvas.x; + data->y = move->cur.canvas.y; - if (data->handle && !data->is.field.faulted) { - if (data->is.field.cancel_click == CANCEL_USER) { - struct dynamicbox_mouse_event_info minfo; - Evas_Coord x, y, w, h; + if (data->handle && !data->is.field.faulted) { + if (data->is.field.cancel_click == CANCEL_USER) { + struct dynamicbox_mouse_event_info minfo; + Evas_Coord x, y, w, h; - evas_object_geometry_get(obj, &x, &y, &w, &h); + evas_object_geometry_get(obj, &x, &y, &w, &h); - minfo.x = (double)(data->x - x) / (double)w; - minfo.y = (double)(data->y - y) / (double)h; - dynamicbox_feed_mouse_event(data->handle, DBOX_MOUSE_ON_HOLD, &minfo); + minfo.x = (double)(data->x - x) / (double)w; + minfo.y = (double)(data->y - y) / (double)h; + dynamicbox_feed_mouse_event(data->handle, DBOX_MOUSE_ON_HOLD, &minfo); - /* - * Reset the clicked event - */ - data->is.field.cancel_click = CANCEL_PROCESSED; + /* + * Reset the clicked event + */ + data->is.field.cancel_click = CANCEL_PROCESSED; - if (s_info.conf.field.auto_render_selector) { - DbgPrint("Change to render animator\n"); - s_info.conf.field.render_animator = 1; - } + if (s_info.conf.field.auto_render_selector) { + DbgPrint("Change to render animator\n"); + s_info.conf.field.render_animator = 1; + } - } + } - if (!s_info.conf.field.auto_feed) { - struct dynamicbox_mouse_event_info minfo; - Evas_Coord x, y, w, h; + if (!s_info.conf.field.auto_feed) { + struct dynamicbox_mouse_event_info minfo; + Evas_Coord x, y, w, h; - evas_object_geometry_get(obj, &x, &y, &w, &h); + evas_object_geometry_get(obj, &x, &y, &w, &h); - minfo.x = (double)(data->x - x) / (double)w; - minfo.y = (double)(data->y - y) / (double)h; - dynamicbox_feed_mouse_event(data->handle, DBOX_MOUSE_MOVE, &minfo); - } + minfo.x = (double)(data->x - x) / (double)w; + minfo.y = (double)(data->y - y) / (double)h; + dynamicbox_feed_mouse_event(data->handle, DBOX_MOUSE_MOVE, &minfo); + } - if (s_info.conf.field.support_gbar && data->is.field.flick_down && abs(data->y - data->down.y) > CLICK_REGION) { - struct dynamicbox_evas_event_info info; - data->is.field.flick_down = 0; - info.pkgname = data->dbox_id; - info.event = DBOX_EVENT_GBAR_CREATED; - info.error = DBOX_STATUS_ERROR_CANCEL; - smart_callback_call(data, DYNAMICBOX_SMART_SIGNAL_FLICKDOWN_CANCELLED, &info); - DbgPrint("Flick down is canceled\n"); - } + if (s_info.conf.field.support_gbar && data->is.field.flick_down && abs(data->y - data->down.y) > CLICK_REGION) { + struct dynamicbox_evas_event_info info; + data->is.field.flick_down = 0; + info.pkgname = data->dbox_id; + info.event = DBOX_EVENT_GBAR_CREATED; + info.error = DBOX_STATUS_ERROR_CANCEL; + smart_callback_call(data, DYNAMICBOX_SMART_SIGNAL_FLICKDOWN_CANCELLED, &info); + DbgPrint("Flick down is canceled\n"); + } - } else { - if (s_info.conf.field.auto_render_selector) { - s_info.conf.field.render_animator = 1; - } + } else { + if (s_info.conf.field.auto_render_selector) { + s_info.conf.field.render_animator = 1; } + } } static char *get_package_icon(struct widget_data *data) { - char *icon; - char *uiapp; + char *icon; + char *uiapp; - if (data->size_type == DBOX_SIZE_TYPE_UNKNOWN) { - icon = dynamicbox_service_i18n_icon(data->dbox_id, NULL); - } else { - icon = dynamicbox_service_preview(data->dbox_id, data->size_type); - } + if (data->size_type == DBOX_SIZE_TYPE_UNKNOWN) { + icon = dynamicbox_service_i18n_icon(data->dbox_id, NULL); + } else { + icon = dynamicbox_service_preview(data->dbox_id, data->size_type); + } - if (icon && access(icon, R_OK) == 0) { - return icon; - } + if (icon && access(icon, R_OK) == 0) { + return icon; + } - if (icon) { - ErrPrint("Failed to access an icon file: [%s]\n", icon); - free(icon); - icon = NULL; - } + if (icon) { + ErrPrint("Failed to access an icon file: [%s]\n", icon); + free(icon); + icon = NULL; + } - uiapp = dynamicbox_service_mainappid(data->dbox_id); - if (uiapp) { - int ret; - ail_appinfo_h ai; - - ret = ail_get_appinfo(uiapp, &ai); - free(uiapp); - if (ret == AIL_ERROR_OK) { - char *uiapp_icon = NULL; - - ret = ail_appinfo_get_str(ai, AIL_PROP_ICON_STR, &uiapp_icon); - if (ret != AIL_ERROR_OK || !uiapp_icon || access(uiapp_icon, R_OK) != 0) { - ErrPrint("[%s] - %s\n", uiapp_icon, strerror(errno)); - } else { - DbgPrint("UI-App icon: [%s]\n", uiapp_icon); - icon = strdup(uiapp_icon); - if (!icon) { - ErrPrint("Heap: %s\n", strerror(errno)); - /*! - * \note - * icon will be specified to "unknown" icon file. (default) - */ - } - } - - ail_destroy_appinfo(ai); + uiapp = dynamicbox_service_mainappid(data->dbox_id); + if (uiapp) { + int ret; + ail_appinfo_h ai; + + ret = ail_get_appinfo(uiapp, &ai); + free(uiapp); + if (ret == AIL_ERROR_OK) { + char *uiapp_icon = NULL; + + ret = ail_appinfo_get_str(ai, AIL_PROP_ICON_STR, &uiapp_icon); + if (ret != AIL_ERROR_OK || !uiapp_icon || access(uiapp_icon, R_OK) != 0) { + ErrPrint("[%s] - %s\n", uiapp_icon, strerror(errno)); + } else { + DbgPrint("UI-App icon: [%s]\n", uiapp_icon); + icon = strdup(uiapp_icon); + if (!icon) { + ErrPrint("Heap: %s\n", strerror(errno)); + /*! + * \note + * icon will be specified to "unknown" icon file. (default) + */ } + } + + ail_destroy_appinfo(ai); } + } + if (!icon) { + icon = strdup(DYNAMICBOX_EVAS_UNKNOWN); if (!icon) { - icon = strdup(DYNAMICBOX_EVAS_UNKNOWN); - if (!icon) { - ErrPrint("Heap: %s\n", strerror(errno)); - } + ErrPrint("Heap: %s\n", strerror(errno)); } + } - return icon; + return icon; } static void activate_ret_cb(struct dynamicbox *handle, int ret, void *cbdata) { - struct widget_data *data = cbdata; - - if (data->state != WIDGET_DATA_CREATED) { - ErrPrint("Invalid widget data: %p\n", data); - return; - } + struct widget_data *data = cbdata; - data->overlay_update_counter = 0; - dbox_overlay_disable(data, 1); + if (data->state != WIDGET_DATA_CREATED) { + ErrPrint("Invalid widget data: %p\n", data); + return; + } - DbgPrint("Activated (%s): %d\n", data->dbox_id, ret); - if (!data->is.field.deleted && (ret == DBOX_STATUS_ERROR_NONE || ret == DBOX_STATUS_ERROR_INVALID_PARAMETER)) { - int type; - Evas_Coord w, h; - struct acquire_data acquire_data = { - .data = data, - }; + data->overlay_update_counter = 0; + dbox_overlay_disable(data, 1); - evas_object_geometry_get(data->dbox_layout, NULL, NULL, &w, &h); + DbgPrint("Activated (%s): %d\n", data->dbox_id, ret); + if (!data->is.field.deleted && (ret == DBOX_STATUS_ERROR_NONE || ret == DBOX_STATUS_ERROR_INVALID_PARAMETER)) { + int type; + Evas_Coord w, h; + struct acquire_data acquire_data = { + .data = data, + }; - type = find_size_type(data, w, h); - if (type == DBOX_SIZE_TYPE_UNKNOWN) { - ErrPrint("Failed to find a proper size type: %dx%d\n", w, h); - type = DBOX_SIZE_TYPE_1x1; - } + evas_object_geometry_get(data->dbox_layout, NULL, NULL, &w, &h); - data->is.field.faulted = 0; - data->is.field.created = 0; - data->is.field.send_delete = 1; - update_dbox_geometry(&acquire_data); - data->handle = dynamicbox_add(data->dbox_id, data->content, - data->cluster, data->category, - data->period, type, - dbox_created_cb, widget_ref(data)); - if (!data->handle) { - ErrPrint("Failed to send add request\n"); - widget_unref(data); - return; - } + type = find_size_type(data, w, h); + if (type == DBOX_SIZE_TYPE_UNKNOWN) { + ErrPrint("Failed to find a proper size type: %dx%d\n", w, h); + type = DBOX_SIZE_TYPE_1x1; + } - DbgPrint("Added Handle: (%p) %p\n", data->handle, data); - dynamicbox_set_data(data->handle, data->dynamicbox); - dbox_overlay_loading(data); + data->is.field.faulted = 0; + data->is.field.created = 0; + data->is.field.send_delete = 1; + update_dbox_geometry(&acquire_data); + data->handle = dynamicbox_add(data->dbox_id, data->content, + data->cluster, data->category, + data->period, type, + dbox_created_cb, widget_ref(data)); + if (!data->handle) { + ErrPrint("Failed to send add request\n"); + widget_unref(data); + return; } - data->is.field.deleted = 0; - widget_unref(data); + DbgPrint("Added Handle: (%p) %p\n", data->handle, data); + dynamicbox_set_data(data->handle, data->dynamicbox); + dbox_overlay_loading(data); + } + + data->is.field.deleted = 0; + widget_unref(data); } static void dbox_animation_done_cb(void *cbdata, Evas_Object *obj, const char *emission, const char *source) { - struct widget_data *data = cbdata; + struct widget_data *data = cbdata; - if (data->state != WIDGET_DATA_CREATED) { - ErrPrint("Invalid widget data: %p\n", data); - return; - } + if (data->state != WIDGET_DATA_CREATED) { + ErrPrint("Invalid widget data: %p\n", data); + return; + } - if (dynamicbox_has_glance_bar(data->handle)) { - } else { - DbgPrint("Animation finished\n"); - } + if (dynamicbox_has_glance_bar(data->handle)) { + } else { + DbgPrint("Animation finished\n"); + } } static void dbox_turn_done_cb(void *cbdata, Evas_Object *obj, const char *emission, const char *source) { - struct widget_data *data = cbdata; - Evas_Object *overlay; + struct widget_data *data = cbdata; + Evas_Object *overlay; - if (data->state != WIDGET_DATA_CREATED) { - ErrPrint("Invalid widget data: %p\n", data); - return; - } + if (data->state != WIDGET_DATA_CREATED) { + ErrPrint("Invalid widget data: %p\n", data); + return; + } - overlay = elm_object_part_content_unset(data->dbox_layout, "overlay,content"); - if (overlay) { - evas_object_del(overlay); - data->is.field.dbox_overlay_loaded = 0; - } + overlay = elm_object_part_content_unset(data->dbox_layout, "overlay,content"); + if (overlay) { + evas_object_del(overlay); + data->is.field.dbox_overlay_loaded = 0; + } } static void dbox_overlay_clicked_cb(void *cbdata, Evas_Object *obj, const char *emission, const char *source) { - struct widget_data *data = cbdata; + struct widget_data *data = cbdata; - if (data->state != WIDGET_DATA_CREATED) { - ErrPrint("Invalid widget data: %p\n", data); - return; - } + if (data->state != WIDGET_DATA_CREATED) { + ErrPrint("Invalid widget data: %p\n", data); + return; + } - DbgPrint("Overlay is clicked: (%s) (%s)\n", emission, source); - if (!data->is.field.faulted) { - /*! - * \todo - * Reload - */ - DbgPrint("Package [%s] is not faulted one\n", data->dbox_id); - } else { - DbgPrint("Activate: [%s]\n", data->dbox_id); - if (dynamicbox_activate(data->dbox_id, activate_ret_cb, widget_ref(data)) < 0) { - widget_unref(data); - ErrPrint("Failed to activate %s\n", data->dbox_id); - } + DbgPrint("Overlay is clicked: (%s) (%s)\n", emission, source); + if (!data->is.field.faulted) { + /*! + * \todo + * Reload + */ + DbgPrint("Package [%s] is not faulted one\n", data->dbox_id); + } else { + DbgPrint("Activate: [%s]\n", data->dbox_id); + if (dynamicbox_activate(data->dbox_id, activate_ret_cb, widget_ref(data)) < 0) { + widget_unref(data); + ErrPrint("Failed to activate %s\n", data->dbox_id); } + } } static void widget_data_setup(struct widget_data *data) { - data->e = evas_object_evas_get(data->dynamicbox); - if (!data->e) { - ErrPrint("Failed to get Evas object\n"); - data->state = WIDGET_DATA_DELETED; - free(data); - return; - } + data->e = evas_object_evas_get(data->dynamicbox); + if (!data->e) { + ErrPrint("Failed to get Evas object\n"); + data->state = WIDGET_DATA_DELETED; + free(data); + return; + } - data->stage = evas_object_rectangle_add(data->e); - if (!data->stage) { - ErrPrint("Failed to add stage object\n"); - data->state = WIDGET_DATA_DELETED; - free(data); - return; - } + data->stage = evas_object_rectangle_add(data->e); + if (!data->stage) { + ErrPrint("Failed to add stage object\n"); + data->state = WIDGET_DATA_DELETED; + free(data); + return; + } - evas_object_color_set(data->stage, 255, 255, 255, 255); + evas_object_color_set(data->stage, 255, 255, 255, 255); - data->dbox_layout = elm_layout_add(data->parent); - if (!data->dbox_layout) { - ErrPrint("Failed to add edje object\n"); - evas_object_del(data->stage); - data->state = WIDGET_DATA_DELETED; - free(data); - return; - } - - if (elm_layout_file_set(data->dbox_layout, DYNAMICBOX_EVAS_RESOURCE_EDJ, DYNAMICBOX_EVAS_RESOURCE_LB) == EINA_FALSE) { - ErrPrint("Failed to load edje object: %s(%s)\n", DYNAMICBOX_EVAS_RESOURCE_EDJ, DYNAMICBOX_EVAS_RESOURCE_LB); - evas_object_del(data->dbox_layout); - evas_object_del(data->stage); - data->state = WIDGET_DATA_DELETED; - free(data); - return; - } + data->dbox_layout = elm_layout_add(data->parent); + if (!data->dbox_layout) { + ErrPrint("Failed to add edje object\n"); + evas_object_del(data->stage); + data->state = WIDGET_DATA_DELETED; + free(data); + return; + } - Evas_Object *scroller; - scroller = elm_scroller_add(data->parent); - if (scroller) { - Evas_Object *box; + if (elm_layout_file_set(data->dbox_layout, DYNAMICBOX_EVAS_RESOURCE_EDJ, DYNAMICBOX_EVAS_RESOURCE_LB) == EINA_FALSE) { + ErrPrint("Failed to load edje object: %s(%s)\n", DYNAMICBOX_EVAS_RESOURCE_EDJ, DYNAMICBOX_EVAS_RESOURCE_LB); + evas_object_del(data->dbox_layout); + evas_object_del(data->stage); + data->state = WIDGET_DATA_DELETED; + free(data); + return; + } - elm_scroller_bounce_set(scroller, EINA_FALSE, EINA_FALSE); - elm_scroller_policy_set(scroller, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_OFF); - elm_scroller_single_direction_set(scroller, ELM_SCROLLER_SINGLE_DIRECTION_HARD); - //elm_object_scroll_lock_x_set(scroller, EINA_TRUE); + Evas_Object *scroller; + scroller = elm_scroller_add(data->parent); + if (scroller) { + Evas_Object *box; - box = evas_object_rectangle_add(data->e); - if (box) { - int height; + elm_scroller_bounce_set(scroller, EINA_FALSE, EINA_FALSE); + elm_scroller_policy_set(scroller, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_OFF); + elm_scroller_single_direction_set(scroller, ELM_SCROLLER_SINGLE_DIRECTION_HARD); + //elm_object_scroll_lock_x_set(scroller, EINA_TRUE); - height = s_info.screen_height << 1; + box = evas_object_rectangle_add(data->e); + if (box) { + int height; - evas_object_color_set(box, 0, 0, 0, 0); - evas_object_resize(box, s_info.screen_width, height); - evas_object_size_hint_min_set(box, s_info.screen_width, height); - evas_object_show(box); - } + height = s_info.screen_height << 1; - elm_object_content_set(scroller, box); - elm_object_part_content_set(data->dbox_layout, "scroller", scroller); - } else { - ErrPrint("Failed to create a scroller\n"); + evas_object_color_set(box, 0, 0, 0, 0); + evas_object_resize(box, s_info.screen_width, height); + evas_object_size_hint_min_set(box, s_info.screen_width, height); + evas_object_show(box); } - evas_object_show(data->dbox_layout); + elm_object_content_set(scroller, box); + elm_object_part_content_set(data->dbox_layout, "scroller", scroller); + } else { + ErrPrint("Failed to create a scroller\n"); + } + + evas_object_show(data->dbox_layout); - elm_object_signal_callback_add(data->dbox_layout, "mouse,clicked,1", "overlay,content", dbox_overlay_clicked_cb, data); - elm_object_signal_callback_add(data->dbox_layout, "done", "turn", dbox_turn_done_cb, data); - elm_object_signal_callback_add(data->dbox_layout, "finished", "animation", dbox_animation_done_cb, data); + elm_object_signal_callback_add(data->dbox_layout, "mouse,clicked,1", "overlay,content", dbox_overlay_clicked_cb, data); + elm_object_signal_callback_add(data->dbox_layout, "done", "turn", dbox_turn_done_cb, data); + elm_object_signal_callback_add(data->dbox_layout, "finished", "animation", dbox_animation_done_cb, data); - evas_object_event_callback_add(data->dbox_layout, EVAS_CALLBACK_MOUSE_DOWN, dbox_down_cb, data); - evas_object_event_callback_add(data->dbox_layout, EVAS_CALLBACK_MOUSE_MOVE, dbox_move_cb, data); - evas_object_event_callback_add(data->dbox_layout, EVAS_CALLBACK_MOUSE_UP, dbox_up_cb, data); + evas_object_event_callback_add(data->dbox_layout, EVAS_CALLBACK_MOUSE_DOWN, dbox_down_cb, data); + evas_object_event_callback_add(data->dbox_layout, EVAS_CALLBACK_MOUSE_MOVE, dbox_move_cb, data); + evas_object_event_callback_add(data->dbox_layout, EVAS_CALLBACK_MOUSE_UP, dbox_up_cb, data); - evas_object_smart_member_add(data->stage, data->dynamicbox); - evas_object_smart_member_add(data->dbox_layout, data->dynamicbox); - evas_object_clip_set(data->dbox_layout, data->stage); + evas_object_smart_member_add(data->stage, data->dynamicbox); + evas_object_smart_member_add(data->dbox_layout, data->dynamicbox); + evas_object_clip_set(data->dbox_layout, data->stage); } static Eina_Bool renderer_cb(void *_data) { - struct widget_data *data; + struct widget_data *data; - EINA_LIST_FREE(s_info.dbox_dirty_objects, data) { - dynamicbox_event_dbox_updated(data); - } + EINA_LIST_FREE(s_info.dbox_dirty_objects, data) { + dynamicbox_event_dbox_updated(data); + } - EINA_LIST_FREE(s_info.gbar_dirty_objects, data) { - dynamicbox_event_gbar_updated(data); - } + EINA_LIST_FREE(s_info.gbar_dirty_objects, data) { + dynamicbox_event_gbar_updated(data); + } - s_info.renderer = NULL; - return ECORE_CALLBACK_CANCEL; + s_info.renderer = NULL; + return ECORE_CALLBACK_CANCEL; } static void remove_dbox_dirty_object_list(struct widget_data *data) { - s_info.dbox_dirty_objects = eina_list_remove(s_info.dbox_dirty_objects, data); + s_info.dbox_dirty_objects = eina_list_remove(s_info.dbox_dirty_objects, data); } static void remove_gbar_dirty_object_list(struct widget_data *data) { - s_info.gbar_dirty_objects = eina_list_remove(s_info.gbar_dirty_objects, data); + s_info.gbar_dirty_objects = eina_list_remove(s_info.gbar_dirty_objects, data); } -static void append_dbox_dirty_object_list(struct widget_data *data) +static void append_dbox_dirty_object_list(struct widget_data *data, int idx) { - data->is.field.dbox_dirty = 1; + data->is.field.dbox_dirty = 1; - if (dynamicbox_visibility(data->handle) != DBOX_SHOW) { - return; - } + if (idx != DBOX_KEEP_BUFFER) { + data->dbox_latest_idx = idx; + } - if (s_info.conf.field.render_animator) { - if (eina_list_data_find(s_info.dbox_dirty_objects, data)) { - return; - } + if (dynamicbox_visibility(data->handle) != DBOX_SHOW) { + return; + } - if (!s_info.renderer) { - s_info.renderer = ecore_animator_add(renderer_cb, NULL); - if (!s_info.renderer) { - ErrPrint("Failed to create a renderer\n"); - } - } + if (s_info.conf.field.render_animator) { + if (eina_list_data_find(s_info.dbox_dirty_objects, data)) { + return; + } - s_info.dbox_dirty_objects = eina_list_append(s_info.dbox_dirty_objects, data); - } else { - if (s_info.renderer) { - ecore_animator_del(s_info.renderer); - s_info.renderer = NULL; - } + if (!s_info.renderer) { + s_info.renderer = ecore_animator_add(renderer_cb, NULL); + if (!s_info.renderer) { + ErrPrint("Failed to create a renderer\n"); + } + } - /* Need a choice - * Do we have to discard these all changes? or just flush them? - struct widget_data *item; - EINA_LIST_FREE(s_info.dbox_dirty_objects, item) { - dynamicbox_event_dbox_updated(item); - } - */ - eina_list_free(s_info.dbox_dirty_objects); - s_info.dbox_dirty_objects = NULL; - dynamicbox_event_dbox_updated(data); + s_info.dbox_dirty_objects = eina_list_append(s_info.dbox_dirty_objects, data); + } else { + if (s_info.renderer) { + ecore_animator_del(s_info.renderer); + s_info.renderer = NULL; } + + /* Need a choice + * Do we have to discard these all changes? or just flush them? + struct widget_data *item; + EINA_LIST_FREE(s_info.dbox_dirty_objects, item) { + dynamicbox_event_dbox_updated(item); + } + */ + eina_list_free(s_info.dbox_dirty_objects); + s_info.dbox_dirty_objects = NULL; + dynamicbox_event_dbox_updated(data); + } } -static void append_gbar_dirty_object_list(struct widget_data *data) +static void append_gbar_dirty_object_list(struct widget_data *data, int idx) { - data->is.field.gbar_dirty = 1; + data->is.field.gbar_dirty = 1; - if (dynamicbox_visibility(data->handle) != DBOX_SHOW) { - return; - } + if (idx != DBOX_KEEP_BUFFER) { + data->gbar_latest_idx = idx; + } - if (s_info.conf.field.render_animator) { - if (eina_list_data_find(s_info.gbar_dirty_objects, data)) { - return; - } + if (dynamicbox_visibility(data->handle) != DBOX_SHOW) { + return; + } - if (!s_info.renderer) { - s_info.renderer = ecore_animator_add(renderer_cb, NULL); - if (!s_info.renderer) { - ErrPrint("Failed to create a renderer\n"); - } - } + if (s_info.conf.field.render_animator) { + if (eina_list_data_find(s_info.gbar_dirty_objects, data)) { + return; + } - s_info.gbar_dirty_objects = eina_list_append(s_info.gbar_dirty_objects, data); - } else { - if (s_info.renderer) { - ecore_animator_del(s_info.renderer); - s_info.renderer = NULL; - } + if (!s_info.renderer) { + s_info.renderer = ecore_animator_add(renderer_cb, NULL); + if (!s_info.renderer) { + ErrPrint("Failed to create a renderer\n"); + } + } - /* Need a choice - * Do we have to discard these all changes? or just flush them? - struct widget_data *item; - EINA_LIST_FREE(s_info.gbar_dirty_objects, item) { - dynamicbox_event_gbar_updated(item); - } - */ - eina_list_free(s_info.gbar_dirty_objects); - s_info.gbar_dirty_objects = NULL; - dynamicbox_event_gbar_updated(data); + s_info.gbar_dirty_objects = eina_list_append(s_info.gbar_dirty_objects, data); + } else { + if (s_info.renderer) { + ecore_animator_del(s_info.renderer); + s_info.renderer = NULL; } + + /* Need a choice + * Do we have to discard these all changes? or just flush them? + struct widget_data *item; + EINA_LIST_FREE(s_info.gbar_dirty_objects, item) { + dynamicbox_event_gbar_updated(item); + } + */ + eina_list_free(s_info.gbar_dirty_objects); + s_info.gbar_dirty_objects = NULL; + dynamicbox_event_gbar_updated(data); + } } static void widget_add(Evas_Object *dynamicbox) { - struct widget_data *data; + struct widget_data *data; - data = calloc(1, sizeof(*data)); - if (!data) { - ErrPrint("Heap: %s\n", strerror(errno)); - return; - } + data = calloc(1, sizeof(*data)); + if (!data) { + ErrPrint("Heap: %s\n", strerror(errno)); + return; + } - data->state = WIDGET_DATA_CREATED; - data->dynamicbox = dynamicbox; - data->is.field.permanent_delete = 0; - evas_object_smart_data_set(data->dynamicbox, data); - widget_ref(data); + data->state = WIDGET_DATA_CREATED; + data->dynamicbox = dynamicbox; + data->is.field.permanent_delete = 0; + data->dbox_latest_idx = DBOX_PRIMARY_BUFFER; + data->gbar_latest_idx = DBOX_PRIMARY_BUFFER; + evas_object_smart_data_set(data->dynamicbox, data); + widget_ref(data); - s_info.list = eina_list_append(s_info.list, dynamicbox); - return; + s_info.list = eina_list_append(s_info.list, dynamicbox); + return; } static Evas_Object *create_image_object(struct widget_data *data) { - Evas_Object *img; + Evas_Object *img; - img = evas_object_image_filled_add(data->e); - if (!img) { - ErrPrint("Failed to create an image object\n"); - } else { - evas_object_image_colorspace_set(img, EVAS_COLORSPACE_ARGB8888); - evas_object_image_alpha_set(img, EINA_TRUE); - } + img = evas_object_image_filled_add(data->e); + if (!img) { + ErrPrint("Failed to create an image object\n"); + } else { + evas_object_image_colorspace_set(img, EVAS_COLORSPACE_ARGB8888); + evas_object_image_alpha_set(img, EINA_TRUE); + } - return img; + return img; } static void replace_dbox_pixmap_with_image(struct widget_data *data) { - Evas_Object *img; - Evas_Object *dbox_content; + Evas_Object *img; + Evas_Object *dbox_content; - dbox_content = elm_object_part_content_unset(data->dbox_layout, "dynamicbox,content"); - if (!dbox_content) { - ErrPrint("Failed to get content object\n"); - return; - } + dbox_content = elm_object_part_content_unset(data->dbox_layout, "dynamicbox,content"); + if (!dbox_content) { + ErrPrint("Failed to get content object\n"); + return; + } - img = create_image_object(data); - if (img) { - Evas_Coord w; - Evas_Coord h; - void *content; + img = create_image_object(data); + if (img) { + Evas_Coord w; + Evas_Coord h; + void *content; - evas_object_image_size_get(dbox_content, &w, &h); - evas_object_image_size_set(img, w, h); + evas_object_image_size_get(dbox_content, &w, &h); + evas_object_image_size_set(img, w, h); - content = evas_object_image_data_get(dbox_content, 0); - if (content) { - evas_object_image_data_copy_set(img, content); - } + content = evas_object_image_data_get(dbox_content, 0); + if (content) { + evas_object_image_data_copy_set(img, content); + } - evas_object_image_fill_set(img, 0, 0, w, h); - evas_object_image_pixels_dirty_set(img, EINA_TRUE); - evas_object_image_data_update_add(img, 0, 0, w, h); + evas_object_image_fill_set(img, 0, 0, w, h); + evas_object_image_pixels_dirty_set(img, EINA_TRUE); + evas_object_image_data_update_add(img, 0, 0, w, h); - elm_object_part_content_set(data->dbox_layout, "dynamicbox,content", img); - } else { - ErrPrint("Failed to create an image object\n"); - } + elm_object_part_content_set(data->dbox_layout, "dynamicbox,content", img); + } else { + ErrPrint("Failed to create an image object\n"); + } - evas_object_del(dbox_content); + evas_object_del(dbox_content); } static void replace_gbar_pixmap_with_image(struct widget_data *data) { - Evas_Object *img; - Evas_Object *gbar_content; + Evas_Object *img; + Evas_Object *gbar_content; - gbar_content = elm_object_part_content_unset(data->dbox_layout, "gbar,content"); - if (!gbar_content) { - ErrPrint("Failed to get content object\n"); - return; - } + gbar_content = elm_object_part_content_unset(data->dbox_layout, "gbar,content"); + if (!gbar_content) { + ErrPrint("Failed to get content object\n"); + return; + } - img = create_image_object(data); - if (img) { - Evas_Coord w; - Evas_Coord h; - void *content; + img = create_image_object(data); + if (img) { + Evas_Coord w; + Evas_Coord h; + void *content; - evas_object_image_size_get(gbar_content, &w, &h); - evas_object_image_size_set(img, w, h); + evas_object_image_size_get(gbar_content, &w, &h); + evas_object_image_size_set(img, w, h); - content = evas_object_image_data_get(gbar_content, 0); - if (content) { - evas_object_image_data_copy_set(img, content); - } + content = evas_object_image_data_get(gbar_content, 0); + if (content) { + evas_object_image_data_copy_set(img, content); + } - evas_object_image_fill_set(img, 0, 0, w, h); - evas_object_image_pixels_dirty_set(img, EINA_TRUE); - evas_object_image_data_update_add(img, 0, 0, w, h); + evas_object_image_fill_set(img, 0, 0, w, h); + evas_object_image_pixels_dirty_set(img, EINA_TRUE); + evas_object_image_data_update_add(img, 0, 0, w, h); - elm_object_part_content_set(data->dbox_layout, "gbar,content", img); - } else { - ErrPrint("Failed to create an image object\n"); - } + elm_object_part_content_set(data->dbox_layout, "gbar,content", img); + } else { + ErrPrint("Failed to create an image object\n"); + } - evas_object_del(gbar_content); + evas_object_del(gbar_content); } static void dbox_destroy_dbox_cb(struct dynamicbox *handle, int ret, void *_data) { - struct widget_data *data = _data; + struct widget_data *data = _data; - if (data->state != WIDGET_DATA_CREATED) { - ErrPrint("Invalid widget data: %p\n", data); - return; - } + if (data->state != WIDGET_DATA_CREATED) { + ErrPrint("Invalid widget data: %p\n", data); + return; + } - if (data->dbox_pixmap) { - replace_dbox_pixmap_with_image(data); - } + if (data->dbox_pixmap) { + replace_dbox_pixmap_with_image(data); + } - if (data->gbar_pixmap) { - replace_gbar_pixmap_with_image(data); - } + if (data->gbar_pixmap) { + replace_gbar_pixmap_with_image(data); + } - data->is.field.send_delete = 0; - DbgPrint("Invoke raw delete %s\n", data->dbox_id); - invoke_raw_event_callback(DYNAMICBOX_EVAS_RAW_DELETE, data->dbox_id, NULL, ret); - remove_dbox_dirty_object_list(data); - remove_gbar_dirty_object_list(data); /* for the safety */ - widget_unref(data); + data->is.field.send_delete = 0; + DbgPrint("Invoke raw delete %s\n", data->dbox_id); + invoke_raw_event_callback(DYNAMICBOX_EVAS_RAW_DELETE, data->dbox_id, NULL, ret); + remove_dbox_dirty_object_list(data); + remove_gbar_dirty_object_list(data); /* for the safety */ + widget_unref(data); } static void widget_del(Evas_Object *dynamicbox) { - struct widget_data *data; + struct widget_data *data; - data = evas_object_smart_data_get(dynamicbox); - if (!data) { - ErrPrint("Invalid object\n"); - return; - } + data = evas_object_smart_data_get(dynamicbox); + if (!data) { + ErrPrint("Invalid object\n"); + return; + } - if (data->state != WIDGET_DATA_CREATED) { - ErrPrint("Invalid widget data: %p\n", data); - return; - } + if (data->state != WIDGET_DATA_CREATED) { + ErrPrint("Invalid widget data: %p\n", data); + return; + } - if (data->is.field.deleted == 1) { - DbgPrint("Already deleted: %s\n", data->dbox_id); - return; - } + if (data->is.field.deleted == 1) { + DbgPrint("Already deleted: %s\n", data->dbox_id); + return; + } - data->is.field.deleted = 1; - - s_info.list = eina_list_remove(s_info.list, dynamicbox); - - if (data->handle) { - dynamicbox_set_data(data->handle, NULL); - - if (data->is.field.send_delete) { - int delete_type; - - if (data->is.field.permanent_delete) { - delete_type = DBOX_DELETE_PERMANENTLY; - } else { - delete_type = DBOX_DELETE_TEMPORARY; - } - DbgPrint("Send delete request (0x%X)\n", delete_type); - - if (data->is.field.created) { - if (dynamicbox_del(data->handle, delete_type, dbox_destroy_dbox_cb, widget_ref(data)) < 0) { - widget_unref(data); - } - } else { - DbgPrint("Not created yet. this will be canceld by created callback, ignore delete callback\n"); - if (dynamicbox_del(data->handle, delete_type, NULL, NULL) < 0) { - DbgPrint("Unref %p\n", data); - } - } - } else { - DbgPrint("Skip delete request\n"); + data->is.field.deleted = 1; + + s_info.list = eina_list_remove(s_info.list, dynamicbox); + + if (data->handle) { + dynamicbox_set_data(data->handle, NULL); + + if (data->is.field.send_delete) { + int delete_type; + + if (data->is.field.permanent_delete) { + delete_type = DBOX_DELETE_PERMANENTLY; + } else { + delete_type = DBOX_DELETE_TEMPORARY; + } + DbgPrint("Send delete request (0x%X)\n", delete_type); + + if (data->is.field.created) { + if (dynamicbox_del(data->handle, delete_type, dbox_destroy_dbox_cb, widget_ref(data)) < 0) { + widget_unref(data); } + } else { + DbgPrint("Not created yet. this will be canceld by created callback, ignore delete callback\n"); + if (dynamicbox_del(data->handle, delete_type, NULL, NULL) < 0) { + DbgPrint("Unref %p\n", data); + } + } } else { - DbgPrint("Handle is not created: %s\n", data->dbox_id); + DbgPrint("Skip delete request\n"); } + } else { + DbgPrint("Handle is not created: %s\n", data->dbox_id); + } - /** - * From now, the dynamicbox object is not valid - */ - data->dynamicbox = NULL; - widget_unref(data); + /** + * From now, the dynamicbox object is not valid + */ + data->dynamicbox = NULL; + widget_unref(data); } static void update_visibility(struct widget_data *data) { - int is_visible = 0; + int is_visible = 0; - if (!data->handle || !data->is.field.created) { - return; - } + if (!data->handle || !data->is.field.created) { + return; + } - if (data->is.field.freeze_visibility) { - DbgPrint("Freezed visibility: %X (%s)\n", data->freezed_visibility, dynamicbox_pkgname(data->handle)); - (void)dynamicbox_set_visibility(data->handle, data->freezed_visibility); - return; - } + if (data->is.field.freeze_visibility) { + DbgPrint("Freezed visibility: %X (%s)\n", data->freezed_visibility, dynamicbox_pkgname(data->handle)); + (void)dynamicbox_set_visibility(data->handle, data->freezed_visibility); + return; + } - is_visible = evas_object_visible_get(data->stage); + is_visible = evas_object_visible_get(data->stage); - if (is_visible) { - Evas_Coord x, y, w, h; + if (is_visible) { + Evas_Coord x, y, w, h; - evas_object_geometry_get(data->dbox_layout, &x, &y, &w, &h); + evas_object_geometry_get(data->dbox_layout, &x, &y, &w, &h); - if (!s_info.conf.field.user_view_port) { - Ecore_Evas *ee; + if (!s_info.conf.field.user_view_port) { + Ecore_Evas *ee; - ee = ecore_evas_ecore_evas_get(data->e); - if (ee) { - ecore_evas_geometry_get(ee, &data->view_port.x, &data->view_port.y, &data->view_port.w, &data->view_port.h); - } else { - data->view_port.x = 0; - data->view_port.y = 0; - ecore_x_window_size_get(0, &data->view_port.w, &data->view_port.h); - ErrPrint("Failed to get view port info (Fallback: %dx%d - %dx%d\n", - data->view_port.x, data->view_port.y, data->view_port.w, data->view_port.h); - } - } + ee = ecore_evas_ecore_evas_get(data->e); + if (ee) { + ecore_evas_geometry_get(ee, &data->view_port.x, &data->view_port.y, &data->view_port.w, &data->view_port.h); + } else { + data->view_port.x = 0; + data->view_port.y = 0; + ecore_x_window_size_get(0, &data->view_port.w, &data->view_port.h); + ErrPrint("Failed to get view port info (Fallback: %dx%d - %dx%d\n", + data->view_port.x, data->view_port.y, data->view_port.w, data->view_port.h); + } + } - if (x + w <= data->view_port.x || x >= data->view_port.x + data->view_port.w || y + h <= data->view_port.y || y >= data->view_port.y + data->view_port.h) { - is_visible = 0; - } else { - is_visible = 1; - } + if (x + w <= data->view_port.x || x >= data->view_port.x + data->view_port.w || y + h <= data->view_port.y || y >= data->view_port.y + data->view_port.h) { + is_visible = 0; + } else { + is_visible = 1; } + } - if (is_visible) { - (void)dynamicbox_set_visibility(data->handle, DBOX_SHOW); + if (is_visible) { + (void)dynamicbox_set_visibility(data->handle, DBOX_SHOW); - if (data->is.field.dbox_dirty) { - /** - * If the object has dirty flag, pumping it up again - * To updates its content - */ - append_dbox_dirty_object_list(data); - } - } else { - (void)dynamicbox_set_visibility(data->handle, DBOX_HIDE_WITH_PAUSE); + if (data->is.field.dbox_dirty) { + /** + * If the object has dirty flag, pumping it up again + * To updates its content + */ + append_dbox_dirty_object_list(data, DBOX_KEEP_BUFFER); } + } else { + (void)dynamicbox_set_visibility(data->handle, DBOX_HIDE_WITH_PAUSE); + } } static int do_force_mouse_up(struct widget_data *data) { - struct dynamicbox_mouse_event_info minfo; - Evas_Coord x, y, w, h; - struct dynamicbox_evas_event_info info; + struct dynamicbox_mouse_event_info minfo; + Evas_Coord x, y, w, h; + struct dynamicbox_evas_event_info info; - if (s_info.conf.field.auto_render_selector && s_info.conf.field.render_animator == 0) { - DbgPrint("Change to render animator\n"); - s_info.conf.field.render_animator = 1; - } + if (s_info.conf.field.auto_render_selector && s_info.conf.field.render_animator == 0) { + DbgPrint("Change to render animator\n"); + s_info.conf.field.render_animator = 1; + } - if (!data->is.field.pressed) { - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!data->is.field.pressed) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - evas_object_geometry_get(data->dynamicbox, &x, &y, &w, &h); + evas_object_geometry_get(data->dynamicbox, &x, &y, &w, &h); - minfo.x = (double)(data->x - x) / (double)w; - minfo.y = (double)(data->y - y) / (double)h; - - data->is.field.pressed = 0; - - reset_scroller(data); - - if (s_info.conf.field.auto_feed && data->is.field.mouse_event) { - DbgPrint("%x\n", data->is.field.cancel_click); - if (data->is.field.cancel_click != CANCEL_PROCESSED) { - DbgPrint("ON_HOLD send\n"); - dynamicbox_feed_mouse_event(data->handle, DBOX_MOUSE_ON_HOLD, &minfo); - data->is.field.cancel_click = CANCEL_PROCESSED; - } - - minfo.x = (double)data->down.geo.x / (double)data->down.geo.w; - minfo.y = (double)data->down.geo.y / (double)data->down.geo.h; + minfo.x = (double)(data->x - x) / (double)w; + minfo.y = (double)(data->y - y) / (double)h; - dynamicbox_feed_mouse_event(data->handle, DBOX_MOUSE_UNSET, &minfo); - } else { - if (!data->is.field.mouse_event) { - /* We have to keep the first position of touch down */ - minfo.x = (double)(data->down.x - x) / (double)w; - minfo.y = (double)(data->down.y - y) / (double)h; - } + data->is.field.pressed = 0; - DbgPrint("%x\n", data->is.field.cancel_click); - if (data->is.field.cancel_click != CANCEL_PROCESSED) { - DbgPrint("ON_HOLD send\n"); - dynamicbox_feed_mouse_event(data->handle, DBOX_MOUSE_ON_HOLD, &minfo); - data->is.field.cancel_click = CANCEL_PROCESSED; - } + reset_scroller(data); - dynamicbox_feed_mouse_event(data->handle, DBOX_MOUSE_UP, &minfo); - dynamicbox_feed_mouse_event(data->handle, DBOX_MOUSE_LEAVE, &minfo); + if (s_info.conf.field.auto_feed && data->is.field.mouse_event) { + DbgPrint("%x\n", data->is.field.cancel_click); + if (data->is.field.cancel_click != CANCEL_PROCESSED) { + DbgPrint("ON_HOLD send\n"); + dynamicbox_feed_mouse_event(data->handle, DBOX_MOUSE_ON_HOLD, &minfo); + data->is.field.cancel_click = CANCEL_PROCESSED; } - data->is.field.cancel_click = CANCEL_DISABLED; - data->is.field.flick_down = 0; - info.pkgname = data->dbox_id; - info.event = DBOX_EVENT_GBAR_CREATED; - info.error = DBOX_STATUS_ERROR_CANCEL; - smart_callback_call(data, DYNAMICBOX_SMART_SIGNAL_FLICKDOWN_CANCELLED, &info); - DbgPrint("Flick down is canceled\n"); - return DBOX_STATUS_ERROR_NONE; -} + minfo.x = (double)data->down.geo.x / (double)data->down.geo.w; + minfo.y = (double)data->down.geo.y / (double)data->down.geo.h; -static void widget_move(Evas_Object *dynamicbox, Evas_Coord x, Evas_Coord y) -{ - struct widget_data *data; - Evas_Coord w, h; - - data = evas_object_smart_data_get(dynamicbox); - if (!data) { - ErrPrint("Invalid object\n"); - return; + dynamicbox_feed_mouse_event(data->handle, DBOX_MOUSE_UNSET, &minfo); + } else { + if (!data->is.field.mouse_event) { + /* We have to keep the first position of touch down */ + minfo.x = (double)(data->down.x - x) / (double)w; + minfo.y = (double)(data->down.y - y) / (double)h; } - if (data->state != WIDGET_DATA_CREATED) { - ErrPrint("Invalid widget data: %p\n", data); - return; + DbgPrint("%x\n", data->is.field.cancel_click); + if (data->is.field.cancel_click != CANCEL_PROCESSED) { + DbgPrint("ON_HOLD send\n"); + dynamicbox_feed_mouse_event(data->handle, DBOX_MOUSE_ON_HOLD, &minfo); + data->is.field.cancel_click = CANCEL_PROCESSED; } - if (data->gbar_layout) { - Evas_Coord gbar_x, gbar_y, gbar_h; - Evas_Coord prev_x, prev_y; - Evas_Coord dbox_w, dbox_h; - double rx; - double ry; + dynamicbox_feed_mouse_event(data->handle, DBOX_MOUSE_UP, &minfo); + dynamicbox_feed_mouse_event(data->handle, DBOX_MOUSE_LEAVE, &minfo); + } - evas_object_geometry_get(data->dbox_layout, &prev_x, &prev_y, &dbox_w, &dbox_h); - evas_object_geometry_get(data->gbar_layout, &gbar_x, &gbar_y, NULL, &gbar_h); + data->is.field.cancel_click = CANCEL_DISABLED; + data->is.field.flick_down = 0; + info.pkgname = data->dbox_id; + info.event = DBOX_EVENT_GBAR_CREATED; + info.error = DBOX_STATUS_ERROR_CANCEL; + smart_callback_call(data, DYNAMICBOX_SMART_SIGNAL_FLICKDOWN_CANCELLED, &info); + DbgPrint("Flick down is canceled\n"); + return DBOX_STATUS_ERROR_NONE; +} - gbar_x += (x - prev_x); - gbar_y += (y - prev_y); +static void widget_move(Evas_Object *dynamicbox, Evas_Coord x, Evas_Coord y) +{ + struct widget_data *data; + Evas_Coord w, h; - evas_object_move(data->gbar_layout, gbar_x, gbar_y); + data = evas_object_smart_data_get(dynamicbox); + if (!data) { + ErrPrint("Invalid object\n"); + return; + } - rx = ((double)x + (double)dbox_w / 2.0f) / s_info.screen_width; - switch (find_size_type(data, dbox_w, dbox_h)) { - case DBOX_SIZE_TYPE_1x1: - if (rx < 0.25f) { - rx = 0.125f; - } else if (rx < 0.5f) { - rx = 0.375f; - } else if (rx < 0.75f) { - rx = 0.625f; - } else if (rx < 1.0f) { - rx = 0.875f; - } - break; - case DBOX_SIZE_TYPE_2x1: - case DBOX_SIZE_TYPE_2x2: - if (rx < 0.5f) { - rx = 0.25f; - } else if (rx < 0.75f) { - rx = 0.5f; - } else { - rx = 0.75f; - } - break; - default: - rx = 0.5f; - break; + if (data->state != WIDGET_DATA_CREATED) { + ErrPrint("Invalid widget data: %p\n", data); + return; + } + + if (data->gbar_layout) { + Evas_Coord gbar_x, gbar_y, gbar_h; + Evas_Coord prev_x, prev_y; + Evas_Coord dbox_w, dbox_h; + double rx; + double ry; + + evas_object_geometry_get(data->dbox_layout, &prev_x, &prev_y, &dbox_w, &dbox_h); + evas_object_geometry_get(data->gbar_layout, &gbar_x, &gbar_y, NULL, &gbar_h); + + gbar_x += (x - prev_x); + gbar_y += (y - prev_y); + + evas_object_move(data->gbar_layout, gbar_x, gbar_y); + + rx = ((double)x + (double)dbox_w / 2.0f) / s_info.screen_width; + switch (find_size_type(data, dbox_w, dbox_h)) { + case DBOX_SIZE_TYPE_1x1: + if (rx < 0.25f) { + rx = 0.125f; + } else if (rx < 0.5f) { + rx = 0.375f; + } else if (rx < 0.75f) { + rx = 0.625f; + } else if (rx < 1.0f) { + rx = 0.875f; } - if (prev_y + dbox_h + gbar_h > s_info.screen_height) { - ry = 1.0f; + break; + case DBOX_SIZE_TYPE_2x1: + case DBOX_SIZE_TYPE_2x2: + if (rx < 0.5f) { + rx = 0.25f; + } else if (rx < 0.75f) { + rx = 0.5f; } else { - ry = 0.0f; + rx = 0.75f; } + break; + default: + rx = 0.5f; + break; + } + if (prev_y + dbox_h + gbar_h > s_info.screen_height) { + ry = 1.0f; + } else { + ry = 0.0f; + } - if (data->is.field.gbar_created) { - dynamicbox_move_glance_bar(data->handle, rx, ry); - } + if (data->is.field.gbar_created) { + dynamicbox_move_glance_bar(data->handle, rx, ry); } + } - evas_object_move(data->stage, x, y); - evas_object_move(data->dbox_layout, x, y); - evas_object_geometry_get(data->dbox_layout, NULL, NULL, &w, &h); + evas_object_move(data->stage, x, y); + evas_object_move(data->dbox_layout, x, y); + evas_object_geometry_get(data->dbox_layout, NULL, NULL, &w, &h); - if (!s_info.conf.field.manual_pause_resume) { - update_visibility(data); - } + if (!s_info.conf.field.manual_pause_resume) { + update_visibility(data); + } - if (s_info.conf.field.sensitive_move) { - do_force_mouse_up(data); - } + if (s_info.conf.field.sensitive_move) { + do_force_mouse_up(data); + } } static int dbox_create_plug_object(struct widget_data *data) { - struct acquire_data acquire_data = { - .w = 0, - .h = 0, - .content = NULL, - .data = data, - }; + struct acquire_data acquire_data = { + .w = 0, + .h = 0, + .content = NULL, + .data = data, + }; - DbgPrint("Plug type created\n"); + DbgPrint("Plug type created\n"); - acquire_data.content = elm_object_part_content_unset(data->dbox_layout, "dynamicbox,content"); - if (acquire_data.content) { - DbgPrint("Dynamicbox Content is already prepared: %s\n", dynamicbox_filename(data->handle)); - evas_object_del(acquire_data.content); - } + acquire_data.content = elm_object_part_content_unset(data->dbox_layout, "dynamicbox,content"); + if (acquire_data.content) { + DbgPrint("Dynamicbox Content is already prepared: %s\n", dynamicbox_filename(data->handle)); + evas_object_del(acquire_data.content); + } - acquire_data.content = elm_plug_add(s_info.win); - if (!acquire_data.content) { - ErrPrint("Failed to add a plug object\n"); - return DBOX_STATUS_ERROR_FAULT; - } + acquire_data.content = elm_plug_add(s_info.win); + if (!acquire_data.content) { + ErrPrint("Failed to add a plug object\n"); + return DBOX_STATUS_ERROR_FAULT; + } - DbgPrint("Try to connect to %s\n", dynamicbox_filename(data->handle)); - if (!elm_plug_connect(acquire_data.content, dynamicbox_filename(data->handle), 0, EINA_TRUE)) { - ErrPrint("Cannot connect plug[%s]", dynamicbox_filename(data->handle)); - evas_object_del(acquire_data.content); - return DBOX_STATUS_ERROR_FAULT; - } + DbgPrint("Try to connect to %s\n", dynamicbox_filename(data->handle)); + if (!elm_plug_connect(acquire_data.content, dynamicbox_filename(data->handle), 0, EINA_TRUE)) { + ErrPrint("Cannot connect plug[%s]", dynamicbox_filename(data->handle)); + evas_object_del(acquire_data.content); + return DBOX_STATUS_ERROR_FAULT; + } - elm_object_part_content_set(data->dbox_layout, "dynamicbox,content", acquire_data.content); + elm_object_part_content_set(data->dbox_layout, "dynamicbox,content", acquire_data.content); - acquire_data.w = data->dbox_width; - acquire_data.h = data->dbox_height; - update_dbox_geometry(&acquire_data); - return DBOX_STATUS_ERROR_NONE; + acquire_data.w = data->dbox_width; + acquire_data.h = data->dbox_height; + update_dbox_geometry(&acquire_data); + return DBOX_STATUS_ERROR_NONE; } static int dbox_create_image_object(struct widget_data *data) { - Evas_Object *front_image; - struct acquire_data acquire_data = { - .w = 0, - .h = 0, - .content = NULL, - .data = data, - }; + Evas_Object *front_image; + struct acquire_data acquire_data = { + .w = 0, + .h = 0, + .content = NULL, + .data = data, + }; - DbgPrint("Image type created\n"); + DbgPrint("Image type created\n"); - acquire_data.content = elm_object_part_content_get(data->dbox_layout, "dynamicbox,content"); + acquire_data.content = elm_object_part_content_get(data->dbox_layout, "dynamicbox,content"); + if (!acquire_data.content) { + acquire_data.content = elm_layout_add(data->parent); if (!acquire_data.content) { - acquire_data.content = elm_layout_add(data->parent); - if (!acquire_data.content) { - ErrPrint("Failed to create an edje object\n"); - return DBOX_STATUS_ERROR_FAULT; - } + ErrPrint("Failed to create an edje object\n"); + return DBOX_STATUS_ERROR_FAULT; + } - if (elm_layout_file_set(acquire_data.content, DYNAMICBOX_EVAS_RESOURCE_EDJ, DYNAMICBOX_EVAS_RESOURCE_IMG) == EINA_FALSE) { - ErrPrint("Failed to load edje object: %s(%s)\n", DYNAMICBOX_EVAS_RESOURCE_EDJ, DYNAMICBOX_EVAS_RESOURCE_IMG); - evas_object_del(acquire_data.content); - return DBOX_STATUS_ERROR_IO_ERROR; - } + if (elm_layout_file_set(acquire_data.content, DYNAMICBOX_EVAS_RESOURCE_EDJ, DYNAMICBOX_EVAS_RESOURCE_IMG) == EINA_FALSE) { + ErrPrint("Failed to load edje object: %s(%s)\n", DYNAMICBOX_EVAS_RESOURCE_EDJ, DYNAMICBOX_EVAS_RESOURCE_IMG); + evas_object_del(acquire_data.content); + return DBOX_STATUS_ERROR_IO_ERROR; + } - front_image = elm_image_add(acquire_data.content); - if (!front_image) { - ErrPrint("Failed to add front_image object\n"); - evas_object_del(acquire_data.content); - return DBOX_STATUS_ERROR_FAULT; - } + front_image = elm_image_add(acquire_data.content); + if (!front_image) { + ErrPrint("Failed to add front_image object\n"); + evas_object_del(acquire_data.content); + return DBOX_STATUS_ERROR_FAULT; + } - DbgPrint("Default size %dx%d\n", data->dbox_width, data->dbox_height); + DbgPrint("Default size %dx%d\n", data->dbox_width, data->dbox_height); - elm_object_part_content_set(acquire_data.content, "front,content", front_image); - elm_object_part_content_set(data->dbox_layout, "dynamicbox,content", acquire_data.content); - } else { - front_image = elm_object_part_content_get(acquire_data.content, "front,content"); - if (!front_image) { - ErrPrint("Unable to get front,content object\n"); - front_image = elm_image_add(acquire_data.content); - if (!front_image) { - ErrPrint("Failed to add front_image object\n"); - return DBOX_STATUS_ERROR_FAULT; - } - - elm_object_part_content_set(acquire_data.content, "front,content", front_image); - } + elm_object_part_content_set(acquire_data.content, "front,content", front_image); + elm_object_part_content_set(data->dbox_layout, "dynamicbox,content", acquire_data.content); + } else { + front_image = elm_object_part_content_get(acquire_data.content, "front,content"); + if (!front_image) { + ErrPrint("Unable to get front,content object\n"); + front_image = elm_image_add(acquire_data.content); + if (!front_image) { + ErrPrint("Failed to add front_image object\n"); + return DBOX_STATUS_ERROR_FAULT; + } + + elm_object_part_content_set(acquire_data.content, "front,content", front_image); } + } - /* - evas_object_geometry_get(data->dynamicbox, NULL, NULL, &acquire_data.w, &acquire_data.h); - DbgPrint("Default size %dx%d\n", acquire_data.w, acquire_data.h); - DbgPrint("Image size: %dx%d\n", acquire_data.w, acquire_data.h); - */ - acquire_data.w = data->dbox_width; - acquire_data.h = data->dbox_height; - update_dbox_geometry(&acquire_data); - return DBOX_STATUS_ERROR_NONE; + /* + evas_object_geometry_get(data->dynamicbox, NULL, NULL, &acquire_data.w, &acquire_data.h); + DbgPrint("Default size %dx%d\n", acquire_data.w, acquire_data.h); + DbgPrint("Image size: %dx%d\n", acquire_data.w, acquire_data.h); + */ + acquire_data.w = data->dbox_width; + acquire_data.h = data->dbox_height; + update_dbox_geometry(&acquire_data); + return DBOX_STATUS_ERROR_NONE; } static int dbox_create_buffer_object(struct widget_data *data) { - Evas_Object *dbox_content; + Evas_Object *dbox_content; - dbox_content = elm_object_part_content_get(data->dbox_layout, "dynamicbox,content"); + dbox_content = elm_object_part_content_get(data->dbox_layout, "dynamicbox,content"); + if (!dbox_content) { + dbox_content = evas_object_image_filled_add(data->e); if (!dbox_content) { - dbox_content = evas_object_image_filled_add(data->e); - if (!dbox_content) { - ErrPrint("Failed to create an image object\n"); - return DBOX_STATUS_ERROR_FAULT; - } - - evas_object_image_colorspace_set(dbox_content, EVAS_COLORSPACE_ARGB8888); - evas_object_image_alpha_set(dbox_content, EINA_TRUE); - elm_object_part_content_set(data->dbox_layout, "dynamicbox,content", dbox_content); + ErrPrint("Failed to create an image object\n"); + return DBOX_STATUS_ERROR_FAULT; } - return DBOX_STATUS_ERROR_NONE; + evas_object_image_colorspace_set(dbox_content, EVAS_COLORSPACE_ARGB8888); + evas_object_image_alpha_set(dbox_content, EINA_TRUE); + elm_object_part_content_set(data->dbox_layout, "dynamicbox,content", dbox_content); + } + + return DBOX_STATUS_ERROR_NONE; } static int dbox_create_text_object(struct widget_data *data) { - ErrPrint("Unsupported\n"); + ErrPrint("Unsupported\n"); - /*! - * \todo - */ + /*! + * \todo + */ - return DBOX_STATUS_ERROR_NOT_IMPLEMENTED; + return DBOX_STATUS_ERROR_NOT_IMPLEMENTED; } static int dbox_create_pixmap_object(struct widget_data *data) { - Evas_Object *dbox_content; + Evas_Object *dbox_content; - dbox_content = elm_object_part_content_get(data->dbox_layout, "dynamicbox,content"); + dbox_content = elm_object_part_content_get(data->dbox_layout, "dynamicbox,content"); + if (!dbox_content) { + dbox_content = evas_object_image_filled_add(data->e); if (!dbox_content) { - dbox_content = evas_object_image_filled_add(data->e); - if (!dbox_content) { - ErrPrint("Failed to create an image object\n"); - return DBOX_STATUS_ERROR_FAULT; - } + ErrPrint("Failed to create an image object\n"); + return DBOX_STATUS_ERROR_FAULT; + } - evas_object_image_colorspace_set(dbox_content, EVAS_COLORSPACE_ARGB8888); - evas_object_image_alpha_set(dbox_content, EINA_TRUE); - evas_object_event_callback_add(dbox_content, EVAS_CALLBACK_DEL, dbox_pixmap_del_cb, data); + evas_object_image_colorspace_set(dbox_content, EVAS_COLORSPACE_ARGB8888); + evas_object_image_alpha_set(dbox_content, EINA_TRUE); + evas_object_event_callback_add(dbox_content, EVAS_CALLBACK_DEL, dbox_pixmap_del_cb, data); - elm_object_part_content_set(data->dbox_layout, "dynamicbox,content", dbox_content); - } + elm_object_part_content_set(data->dbox_layout, "dynamicbox,content", dbox_content); + } - return DBOX_STATUS_ERROR_NONE; + return DBOX_STATUS_ERROR_NONE; } static void dbox_resize_pixmap_object(struct widget_data *data) { - DbgPrint("Dynamicbox resize request is succssfully sent\n"); + DbgPrint("Dynamicbox resize request is succssfully sent\n"); } static void update_dbox_pixmap(Evas_Object *content, int w, int h) { - evas_object_image_pixels_dirty_set(content, EINA_TRUE); - evas_object_image_data_update_add(content, 0, 0, w, h); - evas_object_show(content); + evas_object_image_pixels_dirty_set(content, EINA_TRUE); + evas_object_image_data_update_add(content, 0, 0, w, h); + evas_object_show(content); } -static void acquire_dbox_pixmap_cb(struct dynamicbox *handle, int pixmap, void *cbdata) +static void acquire_dbox_extra_resource_cb(struct dynamicbox *handle, int pixmap, void *cbdata) { - struct acquire_data *acquire_data = cbdata; - struct widget_data *data = acquire_data->data; - Evas_Native_Surface *old_surface; - Evas_Native_Surface surface; - - data->is.field.dbox_pixmap_acquire_requested = 0; + DbgPrint("Acquired: %u\n", (unsigned int)pixmap); +} - if (pixmap == 0) { - DbgPrint("Pixmap gotten (0)\n"); - free(acquire_data); - widget_unref(data); - return; - } +static void acquire_gbar_extra_resource_cb(struct dynamicbox *handle, int pixmap, void *cbdata) +{ + DbgPrint("Acquired: %u\n", (unsigned int)pixmap); +} - evas_object_image_size_set(acquire_data->content, acquire_data->w, acquire_data->h); - evas_object_image_fill_set(acquire_data->content, 0, 0, acquire_data->w, acquire_data->h); - DbgPrint("fillset: %dx%d\n", acquire_data->w, acquire_data->h); +static void replace_pixmap(struct dynamicbox *handle, int gbar, Evas_Object *content, unsigned int pixmap) +{ + Evas_Native_Surface *old_surface; + Evas_Native_Surface surface; - surface.version = EVAS_NATIVE_SURFACE_VERSION; - surface.type = EVAS_NATIVE_SURFACE_X11; - surface.data.x11.pixmap = (unsigned int)pixmap; + surface.version = EVAS_NATIVE_SURFACE_VERSION; + surface.type = EVAS_NATIVE_SURFACE_X11; + surface.data.x11.pixmap = pixmap; - old_surface = evas_object_image_native_surface_get(acquire_data->content); - if (!old_surface) { - surface.data.x11.visual = ecore_x_default_visual_get(ecore_x_display_get(), ecore_x_default_screen_get()); + old_surface = evas_object_image_native_surface_get(content); + if (!old_surface) { + surface.data.x11.visual = ecore_x_default_visual_get(ecore_x_display_get(), ecore_x_default_screen_get()); - evas_object_image_native_surface_set(acquire_data->content, &surface); + evas_object_image_native_surface_set(content, &surface); - DbgPrint("Created: %u\n", surface.data.x11.pixmap); - } else { - unsigned int old_pixmap; + DbgPrint("Created: %u\n", surface.data.x11.pixmap); + } else { + unsigned int old_pixmap; - old_pixmap = old_surface->data.x11.pixmap; + old_pixmap = old_surface->data.x11.pixmap; - surface.data.x11.visual = old_surface->data.x11.visual; - evas_object_image_native_surface_set(acquire_data->content, &surface); + surface.data.x11.visual = old_surface->data.x11.visual; + evas_object_image_native_surface_set(content, &surface); - if (old_pixmap) { - dynamicbox_release_resource_id(data->handle, 0, old_pixmap); - } + if (old_pixmap && handle) { + dynamicbox_release_resource_id(handle, gbar, old_pixmap); } + } +} - data->dbox_pixmap = pixmap; +static void acquire_dbox_pixmap_cb(struct dynamicbox *handle, int pixmap, void *cbdata) +{ + struct acquire_data *acquire_data = cbdata; + struct widget_data *data = acquire_data->data; - append_dbox_dirty_object_list(data); - update_dbox_geometry(acquire_data); + data->is.field.dbox_pixmap_acquire_requested = 0; - widget_unref(data); + if (pixmap == 0) { + DbgPrint("Pixmap gotten (0)\n"); free(acquire_data); + widget_unref(data); + return; + } + + evas_object_image_size_set(acquire_data->content, acquire_data->w, acquire_data->h); + evas_object_image_fill_set(acquire_data->content, 0, 0, acquire_data->w, acquire_data->h); + DbgPrint("fillset: %dx%d\n", acquire_data->w, acquire_data->h); + + replace_pixmap(handle, 0, acquire_data->content, (unsigned int)pixmap); + + data->dbox_pixmap = pixmap; + + append_dbox_dirty_object_list(data, DBOX_KEEP_BUFFER); + update_dbox_geometry(acquire_data); + + widget_unref(data); + free(acquire_data); } static void dbox_update_pixmap_object(struct widget_data *data, Evas_Object *dbox_content, int w, int h) { - int ret; - struct acquire_data *acquire_data; + int ret; + struct acquire_data *acquire_data; + if (data->dbox_latest_idx == DBOX_PRIMARY_BUFFER) { if (data->dbox_pixmap == dynamicbox_resource_id(data->handle, 0)) { - update_dbox_pixmap(dbox_content, w, h); - return; + if (data->dbox_extra) { + /* Just replace the pixmap in this case, do not release old pixmap */ + replace_pixmap(NULL, 0, dbox_content, data->dbox_pixmap); + } + + update_dbox_pixmap(dbox_content, w, h); + return; } if (data->is.field.dbox_pixmap_acquire_requested) { - return; + return; } acquire_data = malloc(sizeof(*acquire_data)); if (!acquire_data) { - ErrPrint("malloc: %s\n", strerror(errno)); - return; + ErrPrint("malloc: %s\n", strerror(errno)); + return; } acquire_data->data = widget_ref(data); @@ -2465,590 +2540,599 @@ static void dbox_update_pixmap_object(struct widget_data *data, Evas_Object *dbo ret = dynamicbox_acquire_resource_id(data->handle, 0, acquire_dbox_pixmap_cb, acquire_data); if (ret != DBOX_STATUS_ERROR_NONE) { - widget_unref(data); - free(acquire_data); + widget_unref(data); + free(acquire_data); } else { - data->is.field.dbox_pixmap_acquire_requested = 1; + data->is.field.dbox_pixmap_acquire_requested = 1; + } + } else { + if (!data->dbox_extra) { + ErrPrint("Extra buffer is not prepared yet\n"); + return; } + + replace_pixmap(NULL, 0, dbox_content, data->dbox_extra[data->dbox_latest_idx]); + update_dbox_pixmap(dbox_content, w, h); + } } static void dbox_created_cb(struct dynamicbox *handle, int ret, void *cbdata) { - struct widget_data *data = cbdata; - struct dynamicbox_evas_event_info info; - - if (data->state != WIDGET_DATA_CREATED) { - ErrPrint("Invalid widget data: %p (%d), %s\n", data, ret, dynamicbox_pkgname(handle)); - return; - } + struct widget_data *data = cbdata; + struct dynamicbox_evas_event_info info; - if (ret != DBOX_STATUS_ERROR_NONE) { - DbgPrint("Failed to create: %X\n", ret); - data->handle = NULL; + if (data->state != WIDGET_DATA_CREATED) { + ErrPrint("Invalid widget data: %p (%d), %s\n", data, ret, dynamicbox_pkgname(handle)); + return; + } - if (!data->is.field.deleted) { - struct dynamicbox_evas_event_info fault_event; + if (ret != DBOX_STATUS_ERROR_NONE) { + DbgPrint("Failed to create: %X\n", ret); + data->handle = NULL; - fault_event.error = ret; - fault_event.pkgname = data->dbox_id; - fault_event.event = DBOX_EVENT_CREATED; + if (!data->is.field.deleted) { + struct dynamicbox_evas_event_info fault_event; - if (!data->is.field.faulted) { - data->is.field.faulted = 1; - dbox_overlay_faulted(data); - } + fault_event.error = ret; + fault_event.pkgname = data->dbox_id; + fault_event.event = DBOX_EVENT_CREATED; - DbgPrint("Display tap to load (%p) [%s]\n", data, data->dbox_id); - smart_callback_call(data, DYNAMICBOX_SMART_SIGNAL_DBOX_CREATE_ABORTED, &fault_event); + if (!data->is.field.faulted) { + data->is.field.faulted = 1; + dbox_overlay_faulted(data); + } - ret = DBOX_STATUS_ERROR_FAULT; - } else { - ret = DBOX_STATUS_ERROR_CANCEL; - } + DbgPrint("Display tap to load (%p) [%s]\n", data, data->dbox_id); + smart_callback_call(data, DYNAMICBOX_SMART_SIGNAL_DBOX_CREATE_ABORTED, &fault_event); - data->is.field.send_delete = 0; - DbgPrint("Invoke raw delete %s\n", data->dbox_id); - invoke_raw_event_callback(DYNAMICBOX_EVAS_RAW_DELETE, data->dbox_id, data->dynamicbox, ret); - widget_unref(data); - return; + ret = DBOX_STATUS_ERROR_FAULT; + } else { + ret = DBOX_STATUS_ERROR_CANCEL; } - switch (dynamicbox_type(handle, 0)) { + data->is.field.send_delete = 0; + DbgPrint("Invoke raw delete %s\n", data->dbox_id); + invoke_raw_event_callback(DYNAMICBOX_EVAS_RAW_DELETE, data->dbox_id, data->dynamicbox, ret); + widget_unref(data); + return; + } + + switch (dynamicbox_type(handle, 0)) { case DBOX_CONTENT_TYPE_IMAGE: - ret = dbox_create_image_object(data); - break; + ret = dbox_create_image_object(data); + break; case DBOX_CONTENT_TYPE_RESOURCE_ID: - if (!s_info.conf.field.force_to_buffer) { - ret = dbox_create_pixmap_object(data); - break; - } - case DBOX_CONTENT_TYPE_BUFFER: - ret = dbox_create_buffer_object(data); + if (!s_info.conf.field.force_to_buffer) { + ret = dbox_create_pixmap_object(data); break; + } + case DBOX_CONTENT_TYPE_BUFFER: + ret = dbox_create_buffer_object(data); + break; case DBOX_CONTENT_TYPE_TEXT: - ret = dbox_create_text_object(data); - break; + ret = dbox_create_text_object(data); + break; case DBOX_CONTENT_TYPE_UIFW: - ret = dbox_create_plug_object(data); - break; + ret = dbox_create_plug_object(data); + break; case DBOX_CONTENT_TYPE_INVALID: default: - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - break; - } + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + break; + } - if (ret == DBOX_STATUS_ERROR_NONE) { - info.error = DBOX_STATUS_ERROR_NONE; - info.pkgname = data->dbox_id; - info.event = DBOX_EVENT_CREATED; + if (ret == DBOX_STATUS_ERROR_NONE) { + info.error = DBOX_STATUS_ERROR_NONE; + info.pkgname = data->dbox_id; + info.event = DBOX_EVENT_CREATED; - data->is.field.created = 1; + data->is.field.created = 1; - update_visibility(data); - smart_callback_call(data, DYNAMICBOX_SMART_SIGNAL_DBOX_CREATED, &info); - DbgPrint("Invoke raw create %s\n", data->dbox_id); - invoke_raw_event_callback(DYNAMICBOX_EVAS_RAW_CREATE, data->dbox_id, data->dynamicbox, ret); + update_visibility(data); + smart_callback_call(data, DYNAMICBOX_SMART_SIGNAL_DBOX_CREATED, &info); + DbgPrint("Invoke raw create %s\n", data->dbox_id); + invoke_raw_event_callback(DYNAMICBOX_EVAS_RAW_CREATE, data->dbox_id, data->dynamicbox, ret); - /** - * In case of using the direct update path, - * sometimes the provider can send the updated event faster than created event. - * In that case, the viewer cannot recognize the updated content of a dbox. - * So for the safety, I added this to forcely update the dbox at the first time - * Right after creating its instance. - */ - append_dbox_dirty_object_list(data); - } else { - info.error = ret; - info.pkgname = data->dbox_id; - info.event = DBOX_EVENT_CREATED; - smart_callback_call(data, DYNAMICBOX_SMART_SIGNAL_DBOX_CREATE_ABORTED, &info); - data->is.field.send_delete = 0; - DbgPrint("Invoke raw delete %s\n", data->dbox_id); - invoke_raw_event_callback(DYNAMICBOX_EVAS_RAW_DELETE, data->dbox_id, data->dynamicbox, ret); - } + /** + * In case of using the direct update path, + * sometimes the provider can send the updated event faster than created event. + * In that case, the viewer cannot recognize the updated content of a dbox. + * So for the safety, I added this to forcely update the dbox at the first time + * Right after creating its instance. + */ + append_dbox_dirty_object_list(data, DBOX_KEEP_BUFFER); + } else { + info.error = ret; + info.pkgname = data->dbox_id; + info.event = DBOX_EVENT_CREATED; + smart_callback_call(data, DYNAMICBOX_SMART_SIGNAL_DBOX_CREATE_ABORTED, &info); + data->is.field.send_delete = 0; + DbgPrint("Invoke raw delete %s\n", data->dbox_id); + invoke_raw_event_callback(DYNAMICBOX_EVAS_RAW_DELETE, data->dbox_id, data->dynamicbox, ret); + } - widget_unref(data); + widget_unref(data); } static void dbox_resize_image_object(struct widget_data *data) { - DbgPrint("Dynamicbox resize request is succssfully sent\n"); + DbgPrint("Dynamicbox resize request is succssfully sent\n"); } static void dbox_resize_buffer_object(struct widget_data *data) { - DbgPrint("Dynamicbox resize request is succssfully sent\n"); + DbgPrint("Dynamicbox resize request is succssfully sent\n"); } static void dbox_resize_text_object(struct widget_data *data) { - DbgPrint("Dynamicbox resize request is succssfully sent\n"); + DbgPrint("Dynamicbox resize request is succssfully sent\n"); } static void dbox_resize_cb(struct dynamicbox *handle, int ret, void *cbdata) { - struct widget_data *data = cbdata; - struct dynamicbox_evas_event_info info; + struct widget_data *data = cbdata; + struct dynamicbox_evas_event_info info; - if (data->state != WIDGET_DATA_CREATED) { - ErrPrint("Invalid widget data: %p\n", data); - return; - } + if (data->state != WIDGET_DATA_CREATED) { + ErrPrint("Invalid widget data: %p\n", data); + return; + } - if (ret != DBOX_STATUS_ERROR_NONE) { - info.error = ret; - info.event = DBOX_EVENT_DBOX_SIZE_CHANGED; - info.pkgname = data->dbox_id; - smart_callback_call(data, DYNAMICBOX_SMART_SIGNAL_DBOX_RESIZE_ABORTED, &info); - widget_unref(data); - return; - } + if (ret != DBOX_STATUS_ERROR_NONE) { + info.error = ret; + info.event = DBOX_EVENT_DBOX_SIZE_CHANGED; + info.pkgname = data->dbox_id; + smart_callback_call(data, DYNAMICBOX_SMART_SIGNAL_DBOX_RESIZE_ABORTED, &info); + widget_unref(data); + return; + } - switch (dynamicbox_type(handle, 0)) { + switch (dynamicbox_type(handle, 0)) { case DBOX_CONTENT_TYPE_IMAGE: - dbox_resize_image_object(data); - break; + dbox_resize_image_object(data); + break; case DBOX_CONTENT_TYPE_RESOURCE_ID: - if (!s_info.conf.field.force_to_buffer) { - dbox_resize_pixmap_object(data); - break; - } - case DBOX_CONTENT_TYPE_BUFFER: - dbox_resize_buffer_object(data); + if (!s_info.conf.field.force_to_buffer) { + dbox_resize_pixmap_object(data); break; + } + case DBOX_CONTENT_TYPE_BUFFER: + dbox_resize_buffer_object(data); + break; case DBOX_CONTENT_TYPE_TEXT: - dbox_resize_text_object(data); - break; + dbox_resize_text_object(data); + break; case DBOX_CONTENT_TYPE_UIFW: - break; + break; case DBOX_CONTENT_TYPE_INVALID: - break; + break; default: - break; - } + break; + } - info.error = ret; - info.event = DBOX_EVENT_DBOX_SIZE_CHANGED; - info.pkgname = data->dbox_id; - smart_callback_call(data, DYNAMICBOX_SMART_SIGNAL_DBOX_RESIZED, &info); - widget_unref(data); + info.error = ret; + info.event = DBOX_EVENT_DBOX_SIZE_CHANGED; + info.pkgname = data->dbox_id; + smart_callback_call(data, DYNAMICBOX_SMART_SIGNAL_DBOX_RESIZED, &info); + widget_unref(data); } static void gbar_overlay_disable(struct widget_data *data) { - if (!data->gbar_layout) { - return; - } + if (!data->gbar_layout) { + return; + } - if (!data->is.field.gbar_overlay_loaded) { - return; - } + if (!data->is.field.gbar_overlay_loaded) { + return; + } - elm_object_signal_emit(data->gbar_layout, "disable", "overlay"); - data->is.field.gbar_overlay_loaded = 0; + elm_object_signal_emit(data->gbar_layout, "disable", "overlay"); + data->is.field.gbar_overlay_loaded = 0; } static void gbar_overlay_loading(struct widget_data *data) { - Evas_Object *rect; + Evas_Object *rect; - if (data->is.field.gbar_overlay_loaded) { - ErrPrint("Already loaded"); - return; - } + if (data->is.field.gbar_overlay_loaded) { + ErrPrint("Already loaded"); + return; + } - rect = elm_object_part_content_unset(data->gbar_layout, "overlay,content"); - if (rect) { - evas_object_del(rect); - } + rect = elm_object_part_content_unset(data->gbar_layout, "overlay,content"); + if (rect) { + evas_object_del(rect); + } - rect = evas_object_rectangle_add(data->e); - evas_object_color_set(rect, 0, 0, 0, 0); - evas_object_show(rect); - /*! - * \todo - * Overlay for loading a GBAR - */ + rect = evas_object_rectangle_add(data->e); + evas_object_color_set(rect, 0, 0, 0, 0); + evas_object_show(rect); + /*! + * \todo + * Overlay for loading a GBAR + */ - elm_object_part_content_set(data->gbar_layout, "overlay,content", rect); - elm_object_signal_emit(data->gbar_layout, "enable", "overlay"); + elm_object_part_content_set(data->gbar_layout, "overlay,content", rect); + elm_object_signal_emit(data->gbar_layout, "enable", "overlay"); - data->is.field.gbar_overlay_loaded = 1; + data->is.field.gbar_overlay_loaded = 1; } static Evas_Object *dbox_load_overlay_edje(struct widget_data *data) { - Evas_Object *overlay; + Evas_Object *overlay; - overlay = elm_layout_add(data->parent); - if (!overlay) { - ErrPrint("Failed to create a overlay\n"); - return NULL; - } + overlay = elm_layout_add(data->parent); + if (!overlay) { + ErrPrint("Failed to create a overlay\n"); + return NULL; + } - if (elm_layout_file_set(overlay, DYNAMICBOX_EVAS_RESOURCE_EDJ, DYNAMICBOX_EVAS_RESOURCE_OVERLAY_LOADING) == EINA_FALSE) { - ErrPrint("Failed to load overlay file\n"); - evas_object_del(overlay); - return NULL; - } + if (elm_layout_file_set(overlay, DYNAMICBOX_EVAS_RESOURCE_EDJ, DYNAMICBOX_EVAS_RESOURCE_OVERLAY_LOADING) == EINA_FALSE) { + ErrPrint("Failed to load overlay file\n"); + evas_object_del(overlay); + return NULL; + } - elm_object_part_content_set(data->dbox_layout, "overlay,content", overlay); - return overlay; + elm_object_part_content_set(data->dbox_layout, "overlay,content", overlay); + return overlay; } static Eina_Bool delayed_overlay_disable_cb(void *_data) { - struct widget_data *data = _data; + struct widget_data *data = _data; - elm_object_signal_emit(data->dbox_layout, "disable", "overlay"); + elm_object_signal_emit(data->dbox_layout, "disable", "overlay"); - data->is.field.dbox_overlay_loaded = 0; - data->overlay_update_counter = DEFAULT_OVERLAY_COUNTER; - data->overlay_timer = NULL; - return ECORE_CALLBACK_CANCEL; + data->is.field.dbox_overlay_loaded = 0; + data->overlay_update_counter = DEFAULT_OVERLAY_COUNTER; + data->overlay_timer = NULL; + return ECORE_CALLBACK_CANCEL; } static void dbox_overlay_disable(struct widget_data *data, int no_timer) { - if (!data->dbox_layout) { - return; - } + if (!data->dbox_layout) { + return; + } - if (!data->is.field.dbox_overlay_loaded) { - return; - } + if (!data->is.field.dbox_overlay_loaded) { + return; + } - data->overlay_update_counter--; - if (data->overlay_update_counter <= 0) { - if (no_timer) { - if (data->overlay_timer) { - ecore_timer_del(data->overlay_timer); - data->overlay_timer = NULL; - } - delayed_overlay_disable_cb(data); - } else { - if (data->overlay_timer) { - ecore_timer_del(data->overlay_timer); - data->overlay_timer = NULL; - delayed_overlay_disable_cb(data); - } else { - return; - } - } + data->overlay_update_counter--; + if (data->overlay_update_counter <= 0) { + if (no_timer) { + if (data->overlay_timer) { + ecore_timer_del(data->overlay_timer); + data->overlay_timer = NULL; + } + delayed_overlay_disable_cb(data); + } else { + if (data->overlay_timer) { + ecore_timer_del(data->overlay_timer); + data->overlay_timer = NULL; + delayed_overlay_disable_cb(data); + } else { + return; + } } + } - if (!no_timer && !data->overlay_timer) { - data->overlay_timer = ecore_timer_add(DEFAULT_OVERLAY_WAIT_TIME, delayed_overlay_disable_cb, data); - if (!data->overlay_timer) { - ErrPrint("Failed to create a timer\n"); - delayed_overlay_disable_cb(data); - } + if (!no_timer && !data->overlay_timer) { + data->overlay_timer = ecore_timer_add(DEFAULT_OVERLAY_WAIT_TIME, delayed_overlay_disable_cb, data); + if (!data->overlay_timer) { + ErrPrint("Failed to create a timer\n"); + delayed_overlay_disable_cb(data); } + } } static void dbox_overlay_loading(struct widget_data *data) { - struct acquire_data acquire_data; - Evas_Object *overlay; + struct acquire_data acquire_data; + Evas_Object *overlay; - if (data->is.field.disable_loading == 1) { - DbgPrint("Loading overlay is disabled"); - return; - } + if (data->is.field.disable_loading == 1) { + DbgPrint("Loading overlay is disabled"); + return; + } - if (data->is.field.dbox_overlay_loaded == 1) { - DbgPrint("Overlay is already loaded"); - return; - } + if (data->is.field.dbox_overlay_loaded == 1) { + DbgPrint("Overlay is already loaded"); + return; + } - overlay = elm_object_part_content_get(data->dbox_layout, "overlay,content"); + overlay = elm_object_part_content_get(data->dbox_layout, "overlay,content"); + if (!overlay) { + overlay = dbox_load_overlay_edje(data); if (!overlay) { - overlay = dbox_load_overlay_edje(data); - if (!overlay) { - return; - } + return; } + } - if (!data->is.field.disable_preview) { - char *icon; - - icon = get_package_icon(data); - if (icon) { - Evas_Object *preview; + if (!data->is.field.disable_preview) { + char *icon; - preview = elm_object_part_content_get(overlay, "preview"); - if (!preview) { - preview = elm_image_add(overlay); - } + icon = get_package_icon(data); + if (icon) { + Evas_Object *preview; - if (preview) { - elm_image_file_set(preview, icon, NULL); - elm_object_part_content_set(overlay, "preview", preview); - } + preview = elm_object_part_content_get(overlay, "preview"); + if (!preview) { + preview = elm_image_add(overlay); + } - free(icon); - } + if (preview) { + elm_image_file_set(preview, icon, NULL); + elm_object_part_content_set(overlay, "preview", preview); + } - DbgPrint("Set overlay loading (%p) %s\n", data, data->dbox_id); - } else { - DbgPrint("Overlay is disabled (%s)\n", data->dbox_id); + free(icon); } - elm_object_part_text_set(overlay, "text", _("IDS_IDLE_POP_LOADING_ING")); - if (data->is.field.disable_text) { - elm_object_signal_emit(overlay, "disable", "text"); - } + DbgPrint("Set overlay loading (%p) %s\n", data, data->dbox_id); + } else { + DbgPrint("Overlay is disabled (%s)\n", data->dbox_id); + } - elm_object_signal_emit(data->dbox_layout, "reset", "overlay"); - elm_object_signal_emit(data->dbox_layout, "enable", "overlay"); + elm_object_part_text_set(overlay, "text", _("IDS_IDLE_POP_LOADING_ING")); + if (data->is.field.disable_text) { + elm_object_signal_emit(overlay, "disable", "text"); + } - evas_object_geometry_get(data->dynamicbox, NULL, NULL, &acquire_data.w, &acquire_data.h); - acquire_data.content = NULL; - acquire_data.data = data; - update_dbox_geometry(&acquire_data); + elm_object_signal_emit(data->dbox_layout, "reset", "overlay"); + elm_object_signal_emit(data->dbox_layout, "enable", "overlay"); + + evas_object_geometry_get(data->dynamicbox, NULL, NULL, &acquire_data.w, &acquire_data.h); + acquire_data.content = NULL; + acquire_data.data = data; + update_dbox_geometry(&acquire_data); - data->is.field.dbox_overlay_loaded = 1; - data->overlay_update_counter = DEFAULT_OVERLAY_COUNTER; + data->is.field.dbox_overlay_loaded = 1; + data->overlay_update_counter = DEFAULT_OVERLAY_COUNTER; } static void dbox_overlay_faulted(struct widget_data *data) { - struct acquire_data acquire_data; - Evas_Object *overlay; + struct acquire_data acquire_data; + Evas_Object *overlay; - if (data->is.field.dbox_overlay_loaded) { - data->overlay_update_counter = 0; - dbox_overlay_disable(data, 1); - } + if (data->is.field.dbox_overlay_loaded) { + data->overlay_update_counter = 0; + dbox_overlay_disable(data, 1); + } - overlay = elm_object_part_content_get(data->dbox_layout, "overlay,content"); + overlay = elm_object_part_content_get(data->dbox_layout, "overlay,content"); + if (!overlay) { + overlay = dbox_load_overlay_edje(data); if (!overlay) { - overlay = dbox_load_overlay_edje(data); - if (!overlay) { - return; - } + return; } + } - if (dynamicbox_type(data->handle, 0) != DBOX_CONTENT_TYPE_IMAGE) { - Evas_Object *preview; + if (dynamicbox_type(data->handle, 0) != DBOX_CONTENT_TYPE_IMAGE) { + Evas_Object *preview; - preview = elm_object_part_content_get(overlay, "preview"); - if (!preview) { - char *icon; + preview = elm_object_part_content_get(overlay, "preview"); + if (!preview) { + char *icon; - icon = dynamicbox_service_preview(data->dbox_id, data->size_type); - if (icon) { - preview = elm_image_add(data->dbox_layout); - if (preview) { - elm_image_file_set(preview, icon, NULL); - elm_object_part_content_set(overlay, "preview", preview); - } - - free(icon); - } + icon = dynamicbox_service_preview(data->dbox_id, data->size_type); + if (icon) { + preview = elm_image_add(data->dbox_layout); + if (preview) { + elm_image_file_set(preview, icon, NULL); + elm_object_part_content_set(overlay, "preview", preview); } + + free(icon); + } } + } - DbgPrint("Set overlay fault (%p) %s\n", data, data->dbox_id); - elm_object_part_text_set(overlay, "text", _("IDS_HS_BODY_UNABLE_TO_LOAD_DATA_TAP_TO_RETRY")); - elm_object_signal_emit(overlay, "enable", "text"); - elm_object_signal_emit(data->dbox_layout, "reset", "overlay"); - elm_object_signal_emit(data->dbox_layout, "enable", "overlay"); + DbgPrint("Set overlay fault (%p) %s\n", data, data->dbox_id); + elm_object_part_text_set(overlay, "text", _("IDS_HS_BODY_UNABLE_TO_LOAD_DATA_TAP_TO_RETRY")); + elm_object_signal_emit(overlay, "enable", "text"); + elm_object_signal_emit(data->dbox_layout, "reset", "overlay"); + elm_object_signal_emit(data->dbox_layout, "enable", "overlay"); - evas_object_geometry_get(data->dynamicbox, NULL, NULL, &acquire_data.w, &acquire_data.h); - acquire_data.content = NULL; - acquire_data.data = data; - update_dbox_geometry(&acquire_data); - data->is.field.dbox_overlay_loaded = 1; + evas_object_geometry_get(data->dynamicbox, NULL, NULL, &acquire_data.w, &acquire_data.h); + acquire_data.content = NULL; + acquire_data.data = data; + update_dbox_geometry(&acquire_data); + data->is.field.dbox_overlay_loaded = 1; } static void widget_resize(Evas_Object *dynamicbox, Evas_Coord w, Evas_Coord h) { - struct widget_data *data; - int type; + struct widget_data *data; + int type; - data = evas_object_smart_data_get(dynamicbox); - if (!data) { - ErrPrint("Invalid object\n"); - return; - } + data = evas_object_smart_data_get(dynamicbox); + if (!data) { + ErrPrint("Invalid object\n"); + return; + } - if (data->state != WIDGET_DATA_CREATED) { - ErrPrint("Invalid widget data: %p\n", data); - return; - } + if (data->state != WIDGET_DATA_CREATED) { + ErrPrint("Invalid widget data: %p\n", data); + return; + } - type = find_size_type(data, w, h); - if (type == DBOX_SIZE_TYPE_UNKNOWN) { - ErrPrint("Invalid size: %dx%d\n", w, h); - //return; - } else if (s_info.conf.field.use_fixed_size) { - if (dynamicbox_service_get_size(type, &w, &h) < 0) { - ErrPrint("Failed to get box size\n"); - } + type = find_size_type(data, w, h); + if (type == DBOX_SIZE_TYPE_UNKNOWN) { + ErrPrint("Invalid size: %dx%d\n", w, h); + //return; + } else if (s_info.conf.field.use_fixed_size) { + if (dynamicbox_service_get_size(type, &w, &h) < 0) { + ErrPrint("Failed to get box size\n"); } + } - data->dbox_width = w; - data->dbox_height = h; - data->size_type = type; + data->dbox_width = w; + data->dbox_height = h; + data->size_type = type; - if (data->is.field.faulted) { - evas_object_resize(data->dbox_layout, data->dbox_width, data->dbox_height); - ErrPrint("Faulted DBox, skip resizing (%s)\n", data->dbox_id); - return; - } + if (data->is.field.faulted) { + evas_object_resize(data->dbox_layout, data->dbox_width, data->dbox_height); + ErrPrint("Faulted DBox, skip resizing (%s)\n", data->dbox_id); + return; + } - if (!data->handle) { - struct acquire_data acquire_data = { - .data = data, - }; - DbgPrint("Create new handle: %dx%d, (%s, %s), %s/%s\n", data->dbox_width, data->dbox_height, - data->dbox_id, data->content, - data->cluster, data->category); - if (dynamicbox_activate(data->dbox_id, NULL, NULL) < 0) { - ErrPrint("Activate: %s\n", data->dbox_id); - } - data->is.field.created = 0; - data->is.field.send_delete = 1; - update_dbox_geometry(&acquire_data); - - data->handle = dynamicbox_add(data->dbox_id, data->content, - data->cluster, data->category, - data->period, type, - dbox_created_cb, widget_ref(data)); - if (!data->handle) { - ErrPrint("Failed to send add request\n"); - DbgPrint("Unref %p %s\n", data, data->dbox_id); - widget_unref(data); - return; - } + if (!data->handle) { + struct acquire_data acquire_data = { + .data = data, + }; + DbgPrint("Create new handle: %dx%d, (%s, %s), %s/%s\n", data->dbox_width, data->dbox_height, + data->dbox_id, data->content, + data->cluster, data->category); + if (dynamicbox_activate(data->dbox_id, NULL, NULL) < 0) { + ErrPrint("Activate: %s\n", data->dbox_id); + } + data->is.field.created = 0; + data->is.field.send_delete = 1; + update_dbox_geometry(&acquire_data); - DbgPrint("Added handle: %p (%p)\n", data->handle, data); - dynamicbox_set_data(data->handle, dynamicbox); - dbox_overlay_loading(data); - data->is.field.touch_effect = dynamicbox_service_touch_effect(data->dbox_id, type); - data->is.field.mouse_event = dynamicbox_service_mouse_event(data->dbox_id, type); - } else { - int ret; + data->handle = dynamicbox_add(data->dbox_id, data->content, + data->cluster, data->category, + data->period, type, + dbox_created_cb, widget_ref(data)); + if (!data->handle) { + ErrPrint("Failed to send add request\n"); + DbgPrint("Unref %p %s\n", data, data->dbox_id); + widget_unref(data); + return; + } + + DbgPrint("Added handle: %p (%p)\n", data->handle, data); + dynamicbox_set_data(data->handle, dynamicbox); + dbox_overlay_loading(data); + data->is.field.touch_effect = dynamicbox_service_touch_effect(data->dbox_id, type); + data->is.field.mouse_event = dynamicbox_service_mouse_event(data->dbox_id, type); + } else { + int ret; - DbgPrint("Resize to %dx%d\n", w, h); + DbgPrint("Resize to %dx%d\n", w, h); - if (type > 0 && type != DBOX_SIZE_TYPE_UNKNOWN) { - ret = dynamicbox_resize(data->handle, type, dbox_resize_cb, widget_ref(data)); - } else { - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - /* This will be decreased soon ... */ - widget_ref(data); - } + if (type > 0 && type != DBOX_SIZE_TYPE_UNKNOWN) { + ret = dynamicbox_resize(data->handle, type, dbox_resize_cb, widget_ref(data)); + } else { + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + /* This will be decreased soon ... */ + widget_ref(data); + } - evas_object_resize(data->dbox_layout, data->dbox_width, data->dbox_height); - if (ret == DBOX_STATUS_ERROR_ALREADY) { - DbgPrint("Same size\n"); - widget_unref(data); - } else if (ret == DBOX_STATUS_ERROR_NONE) { - DbgPrint("Resize request is successfully sent\n"); - data->is.field.touch_effect = dynamicbox_service_touch_effect(data->dbox_id, type); - data->is.field.mouse_event = dynamicbox_service_mouse_event(data->dbox_id, type); - } else { - widget_unref(data); - } + evas_object_resize(data->dbox_layout, data->dbox_width, data->dbox_height); + if (ret == DBOX_STATUS_ERROR_ALREADY) { + DbgPrint("Same size\n"); + widget_unref(data); + } else if (ret == DBOX_STATUS_ERROR_NONE) { + DbgPrint("Resize request is successfully sent\n"); + data->is.field.touch_effect = dynamicbox_service_touch_effect(data->dbox_id, type); + data->is.field.mouse_event = dynamicbox_service_mouse_event(data->dbox_id, type); + } else { + widget_unref(data); } + } } static void widget_show(Evas_Object *dynamicbox) { - struct widget_data *data; + struct widget_data *data; - data = evas_object_smart_data_get(dynamicbox); - if (!data) { - ErrPrint("Invalid object\n"); - return; - } + data = evas_object_smart_data_get(dynamicbox); + if (!data) { + ErrPrint("Invalid object\n"); + return; + } - if (data->state != WIDGET_DATA_CREATED) { - ErrPrint("Invalid widget data: %p\n", data); - return; - } + if (data->state != WIDGET_DATA_CREATED) { + ErrPrint("Invalid widget data: %p\n", data); + return; + } - evas_object_show(data->stage); - evas_object_show(data->dbox_layout); + evas_object_show(data->stage); + evas_object_show(data->dbox_layout); - update_visibility(data); + update_visibility(data); } static void widget_hide(Evas_Object *dynamicbox) { - struct widget_data *data; + struct widget_data *data; - data = evas_object_smart_data_get(dynamicbox); - if (!data) { - ErrPrint("Invalid object\n"); - return; - } + data = evas_object_smart_data_get(dynamicbox); + if (!data) { + ErrPrint("Invalid object\n"); + return; + } - if (data->state != WIDGET_DATA_CREATED) { - ErrPrint("Invalid widget data: %p\n", data); - return; - } + if (data->state != WIDGET_DATA_CREATED) { + ErrPrint("Invalid widget data: %p\n", data); + return; + } - evas_object_hide(data->stage); - evas_object_hide(data->dbox_layout); + evas_object_hide(data->stage); + evas_object_hide(data->dbox_layout); - update_visibility(data); + update_visibility(data); } static void widget_color_set(Evas_Object *dynamicbox, int r, int g, int b, int a) { - struct widget_data *data; + struct widget_data *data; - data = evas_object_smart_data_get(dynamicbox); - if (!data) { - ErrPrint("Invalid object\n"); - return; - } + data = evas_object_smart_data_get(dynamicbox); + if (!data) { + ErrPrint("Invalid object\n"); + return; + } - if (data->state != WIDGET_DATA_CREATED) { - ErrPrint("Invalid widget data: %p\n", data); - return; - } + if (data->state != WIDGET_DATA_CREATED) { + ErrPrint("Invalid widget data: %p\n", data); + return; + } - evas_object_color_set(data->stage, r, g, b, a); + evas_object_color_set(data->stage, r, g, b, a); } static void widget_clip_set(Evas_Object *dynamicbox, Evas_Object *clip) { - struct widget_data *data; + struct widget_data *data; - data = evas_object_smart_data_get(dynamicbox); - if (!data) { - ErrPrint("Invalid object\n"); - return; - } + data = evas_object_smart_data_get(dynamicbox); + if (!data) { + ErrPrint("Invalid object\n"); + return; + } - if (data->state != WIDGET_DATA_CREATED) { - ErrPrint("Invalid widget data: %p\n", data); - return; - } + if (data->state != WIDGET_DATA_CREATED) { + ErrPrint("Invalid widget data: %p\n", data); + return; + } - evas_object_clip_set(data->stage, clip); + evas_object_clip_set(data->stage, clip); } static void widget_clip_unset(Evas_Object *dynamicbox) { - struct widget_data *data; + struct widget_data *data; - data = evas_object_smart_data_get(dynamicbox); - if (!data) { - ErrPrint("Invalid object\n"); - return; - } + data = evas_object_smart_data_get(dynamicbox); + if (!data) { + ErrPrint("Invalid object\n"); + return; + } - if (data->state != WIDGET_DATA_CREATED) { - ErrPrint("Invalid widget data: %p\n", data); - return; - } + if (data->state != WIDGET_DATA_CREATED) { + ErrPrint("Invalid widget data: %p\n", data); + return; + } - evas_object_clip_unset(data->stage); + evas_object_clip_unset(data->stage); } /*! @@ -3056,192 +3140,192 @@ static void widget_clip_unset(Evas_Object *dynamicbox) */ static void update_stage_geometry(struct acquire_data *acquire_data) { - Evas_Coord dbox_x, dbox_y, dbox_w, dbox_h; - Evas_Coord stage_w, stage_h; + Evas_Coord dbox_x, dbox_y, dbox_w, dbox_h; + Evas_Coord stage_w, stage_h; - evas_object_geometry_get(acquire_data->data->dbox_layout, &dbox_x, &dbox_y, &dbox_w, &dbox_h); + evas_object_geometry_get(acquire_data->data->dbox_layout, &dbox_x, &dbox_y, &dbox_w, &dbox_h); - const int delta_y_top = (acquire_data->h - dbox_y); - const int delta_y_bottom = (acquire_data->h - (s_info.screen_height - dbox_y - dbox_h)); + const int delta_y_top = (acquire_data->h - dbox_y); + const int delta_y_bottom = (acquire_data->h - (s_info.screen_height - dbox_y - dbox_h)); - stage_w = dbox_w > acquire_data->w ? dbox_w : acquire_data->w; - stage_h = dbox_h + acquire_data->h;// - delta_y_top; + stage_w = dbox_w > acquire_data->w ? dbox_w : acquire_data->w; + stage_h = dbox_h + acquire_data->h;// - delta_y_top; - if(delta_y_top >= delta_y_bottom) - { - evas_object_move(acquire_data->data->stage, 0, dbox_y); - } - else - { - evas_object_move(acquire_data->data->stage, 0, dbox_y - acquire_data->h); - } + if(delta_y_top >= delta_y_bottom) + { + evas_object_move(acquire_data->data->stage, 0, dbox_y); + } + else + { + evas_object_move(acquire_data->data->stage, 0, dbox_y - acquire_data->h); + } - evas_object_resize(acquire_data->data->stage, stage_w, stage_h); + evas_object_resize(acquire_data->data->stage, stage_w, stage_h); } static void update_gbar_geometry(struct acquire_data *acquire_data) { - Evas_Coord dbox_x, dbox_y, dbox_w, dbox_h; + Evas_Coord dbox_x, dbox_y, dbox_w, dbox_h; - evas_object_geometry_get(acquire_data->data->dbox_layout, &dbox_x, &dbox_y, &dbox_w, &dbox_h); + evas_object_geometry_get(acquire_data->data->dbox_layout, &dbox_x, &dbox_y, &dbox_w, &dbox_h); - //How much of the GBAR is outside the screen - const int delta_y_top = (acquire_data->h - dbox_y) < 0 ? 0 : acquire_data->h - dbox_y; - const int delta_y_bottom = (acquire_data->h - (s_info.screen_height - dbox_y - dbox_h)) < 0 ? 0 : (acquire_data->h - (s_info.screen_height - dbox_y - dbox_h)); + //How much of the GBAR is outside the screen + const int delta_y_top = (acquire_data->h - dbox_y) < 0 ? 0 : acquire_data->h - dbox_y; + const int delta_y_bottom = (acquire_data->h - (s_info.screen_height - dbox_y - dbox_h)) < 0 ? 0 : (acquire_data->h - (s_info.screen_height - dbox_y - dbox_h)); - //If more of the GBAR is outside the top side draw at the bottom, otherwise draw at the top - if(delta_y_top >= delta_y_bottom) - { - evas_object_move(acquire_data->data->gbar_layout, 0, dbox_y + dbox_h - delta_y_bottom); - effect_resize(acquire_data->data->gbar_layout, acquire_data->w, acquire_data->h, EFFECT_HEIGHT); - } - else - { - evas_object_move(acquire_data->data->gbar_layout, 0, dbox_y + delta_y_top); - effect_resize(acquire_data->data->gbar_layout, acquire_data->w, acquire_data->h, EFFECT_HEIGHT|EFFECT_MOVE); - } + //If more of the GBAR is outside the top side draw at the bottom, otherwise draw at the top + if(delta_y_top >= delta_y_bottom) + { + evas_object_move(acquire_data->data->gbar_layout, 0, dbox_y + dbox_h - delta_y_bottom); + effect_resize(acquire_data->data->gbar_layout, acquire_data->w, acquire_data->h, EFFECT_HEIGHT); + } + else + { + evas_object_move(acquire_data->data->gbar_layout, 0, dbox_y + delta_y_top); + effect_resize(acquire_data->data->gbar_layout, acquire_data->w, acquire_data->h, EFFECT_HEIGHT|EFFECT_MOVE); + } } static void update_dbox_geometry(struct acquire_data *acquire_data) { - Evas_Coord dbox_x, dbox_y, dbox_w, dbox_h; - Evas_Coord stage_w, stage_h; - struct widget_data *data = acquire_data->data; + Evas_Coord dbox_x, dbox_y, dbox_w, dbox_h; + Evas_Coord stage_w, stage_h; + struct widget_data *data = acquire_data->data; - evas_object_resize(data->dbox_layout, data->dbox_width, data->dbox_height); - evas_object_geometry_get(data->dbox_layout, &dbox_x, &dbox_y, &dbox_w, &dbox_h); - - if (data->gbar_layout) { - Evas_Coord gbar_x, gbar_y, gbar_w, gbar_h; + evas_object_resize(data->dbox_layout, data->dbox_width, data->dbox_height); + evas_object_geometry_get(data->dbox_layout, &dbox_x, &dbox_y, &dbox_w, &dbox_h); - evas_object_geometry_get(data->gbar_layout, &gbar_x, &gbar_y, &gbar_w, &gbar_h); - if (dbox_y + dbox_h + gbar_h > s_info.screen_height) { - evas_object_move(data->gbar_layout, 0, dbox_y - gbar_h); - evas_object_move(data->stage, 0, dbox_y - gbar_h); - } else { - evas_object_move(data->gbar_layout, 0, dbox_y + dbox_h); - evas_object_move(data->stage, 0, dbox_y); - } + if (data->gbar_layout) { + Evas_Coord gbar_x, gbar_y, gbar_w, gbar_h; - stage_w = gbar_w > dbox_w ? gbar_w : dbox_w; - stage_h = dbox_h + gbar_h; + evas_object_geometry_get(data->gbar_layout, &gbar_x, &gbar_y, &gbar_w, &gbar_h); + if (dbox_y + dbox_h + gbar_h > s_info.screen_height) { + evas_object_move(data->gbar_layout, 0, dbox_y - gbar_h); + evas_object_move(data->stage, 0, dbox_y - gbar_h); } else { - stage_w = dbox_w; - if (s_info.conf.field.support_gbar) { - stage_h = dbox_h + 100; /* Reserve 100 px for effect */ - } else { - stage_h = dbox_h; - } + evas_object_move(data->gbar_layout, 0, dbox_y + dbox_h); + evas_object_move(data->stage, 0, dbox_y); + } - evas_object_move(data->stage, dbox_x, dbox_y); + stage_w = gbar_w > dbox_w ? gbar_w : dbox_w; + stage_h = dbox_h + gbar_h; + } else { + stage_w = dbox_w; + if (s_info.conf.field.support_gbar) { + stage_h = dbox_h + 100; /* Reserve 100 px for effect */ + } else { + stage_h = dbox_h; } - evas_object_resize(data->stage, stage_w, stage_h); + evas_object_move(data->stage, dbox_x, dbox_y); + } + + evas_object_resize(data->stage, stage_w, stage_h); } static void dbox_update_image_object(struct widget_data *data, Evas_Object *dbox_content, int w, int h) { - Evas_Object *front_image; + Evas_Object *front_image; - front_image = elm_object_part_content_get(dbox_content, "front,content"); - if (front_image) { - elm_image_file_set(front_image, dynamicbox_filename(data->handle), NULL); - } else { - ErrPrint("Image object not found\n"); - } + front_image = elm_object_part_content_get(dbox_content, "front,content"); + if (front_image) { + elm_image_file_set(front_image, dynamicbox_filename(data->handle), NULL); + } else { + ErrPrint("Image object not found\n"); + } } static void dbox_update_buffer_object(struct widget_data *data, Evas_Object *dbox_content, int w, int h) { - struct acquire_data acquire_data = { - .w = w, - .h = h, - .content = dbox_content, - .data = data, - }; - - if (data->dbox_fb) { - dynamicbox_release_fb(data->dbox_fb); - data->dbox_fb = NULL; - } - - data->dbox_fb = dynamicbox_acquire_fb(data->handle, 0); - if (!data->dbox_fb) { - ErrPrint("Failed to get fb\n"); - return; - } + struct acquire_data acquire_data = { + .w = w, + .h = h, + .content = dbox_content, + .data = data, + }; + + if (data->dbox_fb) { + dynamicbox_release_buffer(data->dbox_fb); + data->dbox_fb = NULL; + } + + data->dbox_fb = dynamicbox_acquire_buffer(data->handle, 0); + if (!data->dbox_fb) { + ErrPrint("Failed to get fb\n"); + return; + } - evas_object_image_size_set(dbox_content, w, h); + evas_object_image_size_set(dbox_content, w, h); - if (dynamicbox_acquire_fb_lock(data->handle, 0) < 0) { - ErrPrint("Failed to acquire lock\n"); - } - evas_object_image_data_copy_set(dbox_content, data->dbox_fb); - if (dynamicbox_release_fb_lock(data->handle, 0) < 0) { - ErrPrint("Failed to release lock\n"); - } + if (dynamicbox_acquire_buffer_lock(data->handle, 0) < 0) { + ErrPrint("Failed to acquire lock\n"); + } + evas_object_image_data_copy_set(dbox_content, data->dbox_fb); + if (dynamicbox_release_buffer_lock(data->handle, 0) < 0) { + ErrPrint("Failed to release lock\n"); + } - evas_object_image_fill_set(dbox_content, 0, 0, w, h); - evas_object_image_pixels_dirty_set(dbox_content, EINA_TRUE); - evas_object_image_data_update_add(dbox_content, 0, 0, w, h); - update_dbox_geometry(&acquire_data); + evas_object_image_fill_set(dbox_content, 0, 0, w, h); + evas_object_image_pixels_dirty_set(dbox_content, EINA_TRUE); + evas_object_image_data_update_add(dbox_content, 0, 0, w, h); + update_dbox_geometry(&acquire_data); } static void dbox_update_text_object(struct widget_data *data, Evas_Object *dbox_content, int w, int h) { - struct acquire_data acquire_data = { - .w = w, - .h = h, - .content = dbox_content, - .data = data, - }; + struct acquire_data acquire_data = { + .w = w, + .h = h, + .content = dbox_content, + .data = data, + }; - update_dbox_geometry(&acquire_data); + update_dbox_geometry(&acquire_data); } static void dynamicbox_event_extra_info_updated(struct widget_data *data) { - struct dynamicbox_evas_event_info info; - const char *content_info; - char *tmp; + struct dynamicbox_evas_event_info info; + const char *content_info; + char *tmp; - if (data->is.field.deleted) { - DbgPrint("Box is %s, ignore update\n", data->is.field.deleted ? "deleted" : "faulted"); - return; - } + if (data->is.field.deleted) { + DbgPrint("Box is %s, ignore update\n", data->is.field.deleted ? "deleted" : "faulted"); + return; + } - content_info = dynamicbox_content(data->handle); - if (content_info && data->content) { - if (!strcmp(content_info, data->content)) { - /* Nothing chnaged */ - } else { - tmp = strdup(content_info); - if (!tmp) { - ErrPrint("Heap: %s\n", strerror(errno)); - return; - } - - free(data->content); - data->content = tmp; - } - } else if (content_info) { - tmp = strdup(content_info); - if (!tmp) { - ErrPrint("Heap: %s\n", strerror(errno)); - return; - } - data->content = tmp; - } else if (data->content) { - free(data->content); - data->content = NULL; + content_info = dynamicbox_content(data->handle); + if (content_info && data->content) { + if (!strcmp(content_info, data->content)) { + /* Nothing chnaged */ } else { - /* Nothing changed */ + tmp = strdup(content_info); + if (!tmp) { + ErrPrint("Heap: %s\n", strerror(errno)); + return; + } + + free(data->content); + data->content = tmp; + } + } else if (content_info) { + tmp = strdup(content_info); + if (!tmp) { + ErrPrint("Heap: %s\n", strerror(errno)); + return; } + data->content = tmp; + } else if (data->content) { + free(data->content); + data->content = NULL; + } else { + /* Nothing changed */ + } - info.pkgname = data->dbox_id; - info.event = DBOX_EVENT_EXTRA_INFO_UPDATED; - info.error = DBOX_STATUS_ERROR_NONE; - smart_callback_call(data, DYNAMICBOX_SMART_SIGNAL_EXTRA_INFO_UPDATED, &info); + info.pkgname = data->dbox_id; + info.event = DBOX_EVENT_EXTRA_INFO_UPDATED; + info.error = DBOX_STATUS_ERROR_NONE; + smart_callback_call(data, DYNAMICBOX_SMART_SIGNAL_EXTRA_INFO_UPDATED, &info); } /*! @@ -3249,212 +3333,216 @@ static void dynamicbox_event_extra_info_updated(struct widget_data *data) */ static void dynamicbox_event_dbox_updated(struct widget_data *data) { - Evas_Object *dbox_content; - int type; - int w, h; - struct dynamicbox_evas_event_info info; + Evas_Object *dbox_content; + int type; + int w, h; + struct dynamicbox_evas_event_info info; - data->is.field.dbox_dirty = 0; + data->is.field.dbox_dirty = 0; - if (data->is.field.deleted) { - DbgPrint("Box is %s, ignore update\n", data->is.field.deleted ? "deleted" : "faulted"); - return; - } + if (data->is.field.deleted) { + DbgPrint("Box is %s, ignore update\n", data->is.field.deleted ? "deleted" : "faulted"); + return; + } - dbox_content = elm_object_part_content_get(data->dbox_layout, "dynamicbox,content"); - if (!dbox_content) { - ErrPrint("Failed to get content object\n"); - return; - } + dbox_content = elm_object_part_content_get(data->dbox_layout, "dynamicbox,content"); + if (!dbox_content) { + ErrPrint("Failed to get content object\n"); + return; + } - type = dynamicbox_size(data->handle); - if (type < 0 || type == DBOX_SIZE_TYPE_UNKNOWN) { - ErrPrint("Size is not valid %X\n", type); - return; - } + type = dynamicbox_size(data->handle); + if (type < 0 || type == DBOX_SIZE_TYPE_UNKNOWN) { + ErrPrint("Size is not valid %X\n", type); + return; + } - w = data->dbox_width; - h = data->dbox_height; + w = data->dbox_width; + h = data->dbox_height; - switch (dynamicbox_type(data->handle, 0)) { + switch (dynamicbox_type(data->handle, 0)) { case DBOX_CONTENT_TYPE_IMAGE: - dbox_update_image_object(data, dbox_content, w, h); - break; + dbox_update_image_object(data, dbox_content, w, h); + break; case DBOX_CONTENT_TYPE_RESOURCE_ID: - if (!s_info.conf.field.force_to_buffer) { - dbox_update_pixmap_object(data, dbox_content, w, h); - break; - } - case DBOX_CONTENT_TYPE_BUFFER: - dbox_update_buffer_object(data, dbox_content, w, h); + if (!s_info.conf.field.force_to_buffer) { + dbox_update_pixmap_object(data, dbox_content, w, h); break; + } + case DBOX_CONTENT_TYPE_BUFFER: + dbox_update_buffer_object(data, dbox_content, w, h); + break; case DBOX_CONTENT_TYPE_TEXT: - dbox_update_text_object(data, dbox_content, w, h); - break; + dbox_update_text_object(data, dbox_content, w, h); + break; case DBOX_CONTENT_TYPE_UIFW: - break; + break; case DBOX_CONTENT_TYPE_INVALID: default: - break; - } + break; + } - dbox_overlay_disable(data, 0); + dbox_overlay_disable(data, 0); - info.pkgname = data->dbox_id; - info.event = DBOX_EVENT_DBOX_UPDATED; - info.error = DBOX_STATUS_ERROR_NONE; - smart_callback_call(data, DYNAMICBOX_SMART_SIGNAL_UPDATED, &info); + info.pkgname = data->dbox_id; + info.event = DBOX_EVENT_DBOX_UPDATED; + info.error = DBOX_STATUS_ERROR_NONE; + smart_callback_call(data, DYNAMICBOX_SMART_SIGNAL_UPDATED, &info); } static void gbar_update_buffer_object(struct widget_data *data, Evas_Object *gbar_content, int w, int h) { - struct acquire_data acquire_data = { - .data = data, - .content = gbar_content, - .w = w, - .h = h, - }; - - if (data->gbar_fb) { - dynamicbox_release_fb(data->gbar_fb); - data->gbar_fb = NULL; - } else { - // This is first time - gbar_overlay_disable(data); - } + struct acquire_data acquire_data = { + .data = data, + .content = gbar_content, + .w = w, + .h = h, + }; + + if (data->gbar_fb) { + dynamicbox_release_buffer(data->gbar_fb); + data->gbar_fb = NULL; + } else { + // This is first time + gbar_overlay_disable(data); + } - data->gbar_fb = dynamicbox_acquire_fb(data->handle, 1); - if (!data->gbar_fb) { - ErrPrint("Failed to get fb\n"); - return; - } + data->gbar_fb = dynamicbox_acquire_buffer(data->handle, 1); + if (!data->gbar_fb) { + ErrPrint("Failed to get fb\n"); + return; + } - evas_object_image_size_set(gbar_content, w, h); + evas_object_image_size_set(gbar_content, w, h); - if (dynamicbox_acquire_fb_lock(data->handle, 1) < 0) { - ErrPrint("Failed to acquire lock\n"); - } - evas_object_image_data_copy_set(gbar_content, data->gbar_fb); - if (dynamicbox_release_fb_lock(data->handle, 1) < 0) { - ErrPrint("Failed to release lock\n"); - } + if (dynamicbox_acquire_buffer_lock(data->handle, 1) < 0) { + ErrPrint("Failed to acquire lock\n"); + } + evas_object_image_data_copy_set(gbar_content, data->gbar_fb); + if (dynamicbox_release_buffer_lock(data->handle, 1) < 0) { + ErrPrint("Failed to release lock\n"); + } - evas_object_image_fill_set(gbar_content, 0, 0, w, h); - evas_object_image_pixels_dirty_set(gbar_content, EINA_TRUE); - evas_object_image_data_update_add(gbar_content, 0, 0, w, h); + evas_object_image_fill_set(gbar_content, 0, 0, w, h); + evas_object_image_pixels_dirty_set(gbar_content, EINA_TRUE); + evas_object_image_data_update_add(gbar_content, 0, 0, w, h); - update_stage_geometry(&acquire_data); - update_gbar_geometry(&acquire_data); + update_stage_geometry(&acquire_data); + update_gbar_geometry(&acquire_data); } static void gbar_update_text_object(struct widget_data *data, Evas_Object *gbar_content, int w, int h) { - struct acquire_data acquire_data = { - .data = data, - .content = gbar_content, - .w = w, - .h = h, - }; + struct acquire_data acquire_data = { + .data = data, + .content = gbar_content, + .w = w, + .h = h, + }; - ErrPrint("Text type is updated\n"); - gbar_overlay_disable(data); + ErrPrint("Text type is updated\n"); + gbar_overlay_disable(data); - update_stage_geometry(&acquire_data); - update_gbar_geometry(&acquire_data); + update_stage_geometry(&acquire_data); + update_gbar_geometry(&acquire_data); } static void update_gbar_pixmap(Evas_Object *content, int w, int h) { - evas_object_image_pixels_dirty_set(content, EINA_TRUE); - evas_object_image_data_update_add(content, 0, 0, w, h); - evas_object_show(content); + evas_object_image_pixels_dirty_set(content, EINA_TRUE); + evas_object_image_data_update_add(content, 0, 0, w, h); + evas_object_show(content); } static void acquire_gbar_pixmap_cb(struct dynamicbox *handle, int pixmap, void *cbdata) { - struct acquire_data *acquire_data = cbdata; - struct widget_data *data = acquire_data->data; - Evas_Native_Surface *old_surface; - Evas_Native_Surface surface; + struct acquire_data *acquire_data = cbdata; + struct widget_data *data = acquire_data->data; + Evas_Native_Surface *old_surface; + Evas_Native_Surface surface; - data->is.field.gbar_pixmap_acquire_requested = 0; + data->is.field.gbar_pixmap_acquire_requested = 0; - if (pixmap == 0) { - ErrPrint("Failed to acquire pixmap\n"); - DbgPrint("Unref %p %s\n", data, data->dbox_id); - widget_unref(data); - free(acquire_data); - return; - } + if (pixmap == 0) { + ErrPrint("Failed to acquire pixmap\n"); + DbgPrint("Unref %p %s\n", data, data->dbox_id); + widget_unref(data); + free(acquire_data); + return; + } - evas_object_image_size_set(acquire_data->content, acquire_data->w, acquire_data->h); - evas_object_image_fill_set(acquire_data->content, 0, 0, acquire_data->w, acquire_data->h); + evas_object_image_size_set(acquire_data->content, acquire_data->w, acquire_data->h); + evas_object_image_fill_set(acquire_data->content, 0, 0, acquire_data->w, acquire_data->h); - surface.version = EVAS_NATIVE_SURFACE_VERSION; - surface.type = EVAS_NATIVE_SURFACE_X11; - surface.data.x11.pixmap = (unsigned int)pixmap; + surface.version = EVAS_NATIVE_SURFACE_VERSION; + surface.type = EVAS_NATIVE_SURFACE_X11; + surface.data.x11.pixmap = (unsigned int)pixmap; - old_surface = evas_object_image_native_surface_get(acquire_data->content); - if (!old_surface) { - gbar_overlay_disable(data); - surface.data.x11.visual = ecore_x_default_visual_get(ecore_x_display_get(), ecore_x_default_screen_get()); - evas_object_image_native_surface_set(acquire_data->content, &surface); - } else { - unsigned int old_pixmap = 0u; - old_pixmap = old_surface->data.x11.pixmap; - surface.data.x11.visual = old_surface->data.x11.visual; - evas_object_image_native_surface_set(acquire_data->content, &surface); + old_surface = evas_object_image_native_surface_get(acquire_data->content); + if (!old_surface) { + gbar_overlay_disable(data); + surface.data.x11.visual = ecore_x_default_visual_get(ecore_x_display_get(), ecore_x_default_screen_get()); + evas_object_image_native_surface_set(acquire_data->content, &surface); + } else { + unsigned int old_pixmap = 0u; + old_pixmap = old_surface->data.x11.pixmap; + surface.data.x11.visual = old_surface->data.x11.visual; + evas_object_image_native_surface_set(acquire_data->content, &surface); - if (old_pixmap) { - dynamicbox_release_resource_id(data->handle, 1, old_pixmap); - } + if (old_pixmap) { + dynamicbox_release_resource_id(data->handle, 1, old_pixmap); } + } - data->gbar_pixmap = (unsigned int)pixmap; + data->gbar_pixmap = (unsigned int)pixmap; - append_gbar_dirty_object_list(data); - update_stage_geometry(acquire_data); - update_gbar_geometry(acquire_data); + append_gbar_dirty_object_list(data, DBOX_KEEP_BUFFER); + update_stage_geometry(acquire_data); + update_gbar_geometry(acquire_data); - free(acquire_data); - DbgPrint("Unref %p %s\n", data, data->dbox_id); - widget_unref(data); + free(acquire_data); + DbgPrint("Unref %p %s\n", data, data->dbox_id); + widget_unref(data); } static void gbar_update_pixmap_object(struct widget_data *data, Evas_Object *gbar_content, int w, int h) { - struct acquire_data *acquire_data; - int ret; + struct acquire_data *acquire_data; + int ret; + if (data->gbar_latest_idx == DBOX_PRIMARY_BUFFER) { if (data->gbar_pixmap == dynamicbox_resource_id(data->handle, 1)) { - int ow; - int oh; - - effect_size_get(gbar_content, &ow, &oh); - - update_gbar_pixmap(gbar_content, w, h); - - if (ow != w || oh != h) { - struct acquire_data adata = { - .data = data, - .content = gbar_content, - .w = w, - .h = h, - }; + int ow; + int oh; + + effect_size_get(gbar_content, &ow, &oh); + + if (data->gbar_extra) { + replace_pixmap(NULL, 1, gbar_content, data->gbar_pixmap); + } + update_gbar_pixmap(gbar_content, w, h); + + if (ow != w || oh != h) { + struct acquire_data adata = { + .data = data, + .content = gbar_content, + .w = w, + .h = h, + }; - update_stage_geometry(&adata); - } - return; + update_stage_geometry(&adata); + } + return; } if (data->is.field.gbar_pixmap_acquire_requested) { - return; + return; } acquire_data = malloc(sizeof(*acquire_data)); if (!acquire_data) { - ErrPrint("Heap: %s\n", strerror(errno)); - return; + ErrPrint("Heap: %s\n", strerror(errno)); + return; } acquire_data->content = gbar_content; @@ -3464,1275 +3552,1395 @@ static void gbar_update_pixmap_object(struct widget_data *data, Evas_Object *gba ret = dynamicbox_acquire_resource_id(data->handle, 1, acquire_gbar_pixmap_cb, acquire_data); if (ret != DBOX_STATUS_ERROR_NONE) { - ErrPrint("Failed to acquire gbar resource id\n"); - free(acquire_data); - DbgPrint("Unref %p %s\n", data, data->dbox_id); - widget_unref(data); + ErrPrint("Failed to acquire gbar resource id\n"); + free(acquire_data); + DbgPrint("Unref %p %s\n", data, data->dbox_id); + widget_unref(data); } else { - data->is.field.gbar_pixmap_acquire_requested = 1; + data->is.field.gbar_pixmap_acquire_requested = 1; + } + } else { + int ow; + int oh; + + if (!data->gbar_extra) { + DbgPrint("Extra GBar is not prepared yet\n"); + return; + } + + effect_size_get(gbar_content, &ow, &oh); + + replace_pixmap(NULL, 1, gbar_content, data->gbar_extra[data->gbar_latest_idx]); + update_gbar_pixmap(gbar_content, w, h); + + if (ow != w || oh != h) { + struct acquire_data adata = { + .data = data, + .content = gbar_content, + .w = w, + .h = h, + }; + + update_stage_geometry(&adata); } + } } static void dynamicbox_event_gbar_updated(struct widget_data *data) { - Evas_Object *gbar_content; - int w, h; + Evas_Object *gbar_content; + int w, h; - data->is.field.gbar_dirty = 0; + data->is.field.gbar_dirty = 0; - if (data->is.field.deleted) { - DbgPrint("Box is deleted, ignore update\n"); - return; - } + if (data->is.field.deleted) { + DbgPrint("Box is deleted, ignore update\n"); + return; + } - gbar_content = elm_object_part_content_get(data->gbar_layout, "gbar,content"); - if (!gbar_content) { - ErrPrint("Failed to get content object\n"); - return; - } + gbar_content = elm_object_part_content_get(data->gbar_layout, "gbar,content"); + if (!gbar_content) { + ErrPrint("Failed to get content object\n"); + return; + } - if (dynamicbox_get_glance_bar_size(data->handle, &w, &h) != DBOX_STATUS_ERROR_NONE) { - ErrPrint("Failed to get gbar_size\n"); - w = 0; - h = 0; - } + if (dynamicbox_get_glance_bar_size(data->handle, &w, &h) != DBOX_STATUS_ERROR_NONE) { + ErrPrint("Failed to get gbar_size\n"); + w = 0; + h = 0; + } - switch (dynamicbox_type(data->handle, 1)) { + switch (dynamicbox_type(data->handle, 1)) { case DBOX_CONTENT_TYPE_RESOURCE_ID: - if (!s_info.conf.field.force_to_buffer) { - gbar_update_pixmap_object(data, gbar_content, w, h); - break; - } - case DBOX_CONTENT_TYPE_BUFFER: - gbar_update_buffer_object(data, gbar_content, w, h); + if (!s_info.conf.field.force_to_buffer) { + gbar_update_pixmap_object(data, gbar_content, w, h); break; + } + case DBOX_CONTENT_TYPE_BUFFER: + gbar_update_buffer_object(data, gbar_content, w, h); + break; case DBOX_CONTENT_TYPE_TEXT: - gbar_update_text_object(data, gbar_content, w, h); - break; + gbar_update_text_object(data, gbar_content, w, h); + break; case DBOX_CONTENT_TYPE_UIFW: - break; + break; case DBOX_CONTENT_TYPE_INVALID: default: - ErrPrint("Invalid pd type\n"); - break; - } + ErrPrint("Invalid pd type\n"); + break; + } } static void dynamicbox_event_deleted(struct widget_data *data) { - struct dynamicbox_evas_event_info info; + struct dynamicbox_evas_event_info info; - if (data->dbox_fb) { - dynamicbox_release_fb(data->dbox_fb); - data->dbox_fb = NULL; - } + if (data->dbox_fb) { + dynamicbox_release_buffer(data->dbox_fb); + data->dbox_fb = NULL; + } - if (data->gbar_fb) { - dynamicbox_release_fb(data->gbar_fb); - data->gbar_fb = NULL; - } + if (data->gbar_fb) { + dynamicbox_release_buffer(data->gbar_fb); + data->gbar_fb = NULL; + } - if (data->dbox_pixmap) { - replace_dbox_pixmap_with_image(data); - } + if (data->dbox_pixmap) { + replace_dbox_pixmap_with_image(data); + } - if (data->gbar_pixmap) { - replace_gbar_pixmap_with_image(data); - } + if (data->gbar_pixmap) { + replace_gbar_pixmap_with_image(data); + } - DbgPrint("Dynamicbox is deleted: %p (emit signal)\n", data); - data->is.field.send_delete = 0; - info.pkgname = data->dbox_id; - info.event = DBOX_EVENT_DELETED; - info.error = data->is.field.faulted ? DBOX_STATUS_ERROR_FAULT : DBOX_STATUS_ERROR_NONE; + DbgPrint("Dynamicbox is deleted: %p (emit signal)\n", data); + data->is.field.send_delete = 0; + info.pkgname = data->dbox_id; + info.event = DBOX_EVENT_DELETED; + info.error = data->is.field.faulted ? DBOX_STATUS_ERROR_FAULT : DBOX_STATUS_ERROR_NONE; - /** - * Even if the dynamicbox object tries to be deleted from DBOX_DELETED event callback, - * widget data should not be released while processing RAW_DELETE event handling - */ - widget_ref(data); + /** + * Even if the dynamicbox object tries to be deleted from DBOX_DELETED event callback, + * widget data should not be released while processing RAW_DELETE event handling + */ + widget_ref(data); - smart_callback_call(data, DYNAMICBOX_SMART_SIGNAL_DBOX_DELETED, &info); - DbgPrint("Invoke raw delete %s\n", data->dbox_id); - invoke_raw_event_callback(DYNAMICBOX_EVAS_RAW_DELETE, data->dbox_id, data->dynamicbox, info.error); + smart_callback_call(data, DYNAMICBOX_SMART_SIGNAL_DBOX_DELETED, &info); + DbgPrint("Invoke raw delete %s\n", data->dbox_id); + invoke_raw_event_callback(DYNAMICBOX_EVAS_RAW_DELETE, data->dbox_id, data->dynamicbox, info.error); - remove_dbox_dirty_object_list(data); - remove_gbar_dirty_object_list(data); /* For the safety */ + remove_dbox_dirty_object_list(data); + remove_gbar_dirty_object_list(data); /* For the safety */ - data->handle = NULL; + data->handle = NULL; - /** - * All event handler is handled correctly, - * Then decrease the refcnt of it. - */ - widget_unref(data); + /** + * All event handler is handled correctly, + * Then decrease the refcnt of it. + */ + widget_unref(data); } static void dynamicbox_event_request_close_gbar(struct widget_data *data) { - int ret; + int ret; - ret = dynamicbox_destroy_glance_bar(data->handle, dbox_destroy_gbar_cb, widget_ref(data)); - if (ret < 0) { - ErrPrint("Failed to close a GBAR: %x\n", ret); - DbgPrint("Unref %p %s\n", data, data->dbox_id); - widget_unref(data); - } + ret = dynamicbox_destroy_glance_bar(data->handle, dbox_destroy_gbar_cb, widget_ref(data)); + if (ret < 0) { + ErrPrint("Failed to close a GBAR: %x\n", ret); + DbgPrint("Unref %p %s\n", data, data->dbox_id); + widget_unref(data); + } } static void dynamicbox_event_group_changed(struct widget_data *data) { - DbgPrint("Group is changed\n"); + DbgPrint("Group is changed\n"); } static void dynamicbox_event_pinup_changed(struct widget_data *data) { - DbgPrint("Pinup is changed\n"); + DbgPrint("Pinup is changed\n"); } static void dynamicbox_event_period_changed(struct widget_data *data) { - struct dynamicbox_evas_event_info info; + struct dynamicbox_evas_event_info info; - data->period = dynamicbox_period(data->handle); - DbgPrint("Update period is changed to (%lf)\n", data->period); + data->period = dynamicbox_period(data->handle); + DbgPrint("Update period is changed to (%lf)\n", data->period); - info.pkgname = data->dbox_id; - info.event = DBOX_EVENT_PERIOD_CHANGED; - info.error = DBOX_STATUS_ERROR_NONE; - smart_callback_call(data, DYNAMICBOX_SMART_SIGNAL_PERIOD_CHANGED, &info); + info.pkgname = data->dbox_id; + info.event = DBOX_EVENT_PERIOD_CHANGED; + info.error = DBOX_STATUS_ERROR_NONE; + smart_callback_call(data, DYNAMICBOX_SMART_SIGNAL_PERIOD_CHANGED, &info); } static void dynamicbox_event_dbox_size_changed(struct widget_data *data) { - DbgPrint("Dynamicbox LB size is changed\n"); + DbgPrint("Dynamicbox LB size is changed\n"); } static void dynamicbox_event_gbar_size_changed(struct widget_data *data) { - DbgPrint("Dynamicbox GBAR size is changed\n"); + DbgPrint("Dynamicbox GBAR size is changed\n"); } static void dynamicbox_event_gbar_created(struct widget_data *data) { - DbgPrint("Dynamicbox GBAR is created\n"); + DbgPrint("Dynamicbox GBAR is created\n"); } static void dynamicbox_event_gbar_destroyed(struct widget_data *data) { - DbgPrint("Dynamicbox GBAR is destroyed\n"); - remove_gbar_dirty_object_list(data); + DbgPrint("Dynamicbox GBAR is destroyed\n"); + remove_gbar_dirty_object_list(data); } static void dynamicbox_event_hold_scroll(struct widget_data *data) { - struct dynamicbox_evas_event_info info; - DbgPrint("Dynamicbox hold scroll\n"); + struct dynamicbox_evas_event_info info; + DbgPrint("Dynamicbox hold scroll\n"); - info.pkgname = data->dbox_id; - info.event = DBOX_EVENT_HOLD_SCROLL; - info.error = DBOX_STATUS_ERROR_NONE; - smart_callback_call(data, DYNAMICBOX_SMART_SIGNAL_CONTROL_SCROLLER, &info); + info.pkgname = data->dbox_id; + info.event = DBOX_EVENT_HOLD_SCROLL; + info.error = DBOX_STATUS_ERROR_NONE; + smart_callback_call(data, DYNAMICBOX_SMART_SIGNAL_CONTROL_SCROLLER, &info); } static void dynamicbox_event_release_scroll(struct widget_data *data) { - struct dynamicbox_evas_event_info info; - DbgPrint("Dynamicbox release scroll\n"); + struct dynamicbox_evas_event_info info; + DbgPrint("Dynamicbox release scroll\n"); - info.pkgname = data->dbox_id; - info.event = DBOX_EVENT_RELEASE_SCROLL; - info.error = DBOX_STATUS_ERROR_NONE; - smart_callback_call(data, DYNAMICBOX_SMART_SIGNAL_CONTROL_SCROLLER, &info); + info.pkgname = data->dbox_id; + info.event = DBOX_EVENT_RELEASE_SCROLL; + info.error = DBOX_STATUS_ERROR_NONE; + smart_callback_call(data, DYNAMICBOX_SMART_SIGNAL_CONTROL_SCROLLER, &info); } static void dynamicbox_event_dbox_update_begin(struct widget_data *data) { - DbgPrint("DBOX Update Begin\n"); + DbgPrint("DBOX Update Begin\n"); } static void dynamicbox_event_dbox_update_end(struct widget_data *data) { - DbgPrint("DBOX Update End\n"); + DbgPrint("DBOX Update End\n"); } static void dynamicbox_event_gbar_update_begin(struct widget_data *data) { - DbgPrint("GBAR Update Begin\n"); + DbgPrint("GBAR Update Begin\n"); } static void dynamicbox_event_gbar_update_end(struct widget_data *data) { - DbgPrint("GBAR Update End\n"); + DbgPrint("GBAR Update End\n"); } static void dynamicbox_event_update_mode_changed(struct widget_data *data) { - DbgPrint("Update mode changed\n"); + DbgPrint("Update mode changed\n"); } static void dynamicbox_event_ignored(struct widget_data *data) { - DbgPrint("Request is ignored\n"); + DbgPrint("Request is ignored\n"); } static int dynamicbox_event_handler(struct dynamicbox *handle, enum dynamicbox_event_type event, void *cbdata) { - Evas_Object *dynamicbox; - struct widget_data *data; + Evas_Object *dynamicbox; + struct widget_data *data; + int idx; + unsigned int resource_id; - dynamicbox = dynamicbox_data(handle); - if (!dynamicbox) { - ErrPrint("dynamicbox object is not exists\n"); - return 0; - } + dynamicbox = dynamicbox_data(handle); + if (!dynamicbox) { + ErrPrint("dynamicbox object is not exists\n"); + return 0; + } - data = get_smart_data(dynamicbox); - if (!data || data->is.field.deleted) { - ErrPrint("Failed to get smart data\n"); - dynamicbox_set_data(handle, NULL); - if (event == DBOX_EVENT_CREATED) { - DbgPrint("System created dynamicbox is not supported\n"); - (void)dynamicbox_del(handle, DBOX_DELETE_PERMANENTLY, NULL, NULL); - } - return 0; + data = get_smart_data(dynamicbox); + if (!data || data->is.field.deleted) { + ErrPrint("Failed to get smart data\n"); + dynamicbox_set_data(handle, NULL); + if (event == DBOX_EVENT_CREATED) { + DbgPrint("System created dynamicbox is not supported\n"); + (void)dynamicbox_del(handle, DBOX_DELETE_PERMANENTLY, NULL, NULL); } - - switch (event) { + return 0; + } + + switch (event) { + case DBOX_EVENT_DBOX_EXTRA_BUFFER_CREATED: + dynamicbox_get_affected_extra_buffer(handle, 0, &idx, &resource_id); + DbgPrint("Extra buffer created for DBOX: %d (%u)\n", idx, resource_id); + if (!data->dbox_extra) { + data->dbox_extra = calloc(dynamicbox_option(DBOX_OPTION_EXTRA_BUFFER_CNT), sizeof(*data->dbox_extra)); + if (!data->dbox_extra) { + ErrPrint("calloc: %s\n", strerror(errno)); + } + } + + data->dbox_extra[idx] = resource_id; + data->dbox_extra_cnt++; + + if (dynamicbox_acquire_extra_resource_id(handle, 0, idx, acquire_dbox_extra_resource_cb, data) < 0) { + ErrPrint("Failed to acquire resource: %u\n", resource_id); + } + break; + case DBOX_EVENT_DBOX_EXTRA_BUFFER_DESTROYED: + dynamicbox_get_affected_extra_buffer(handle, 0, &idx, &resource_id); + DbgPrint("Extra buffer destroyed for DBOX: %d (%u)\n", idx, resource_id); + if (data->dbox_extra[idx] != resource_id) { + DbgPrint("Resource Id mismatched\n"); + } + data->dbox_extra[idx] = 0u; + data->dbox_extra_cnt--; + if (!data->dbox_extra_cnt) { + DbgPrint("Release dbox array\n"); + free(data->dbox_extra); + data->dbox_extra = NULL; + } + + if (dynamicbox_release_resource_id(handle, 0, resource_id) < 0) { + ErrPrint("Failed to release resource: %u\n", resource_id); + } + break; + case DBOX_EVENT_GBAR_EXTRA_BUFFER_CREATED: + dynamicbox_get_affected_extra_buffer(handle, 1, &idx, &resource_id); + DbgPrint("Extra buffer destroyed for GBAR: %d (%u)\n", idx, resource_id); + if (!data->gbar_extra) { + data->gbar_extra = calloc(dynamicbox_option(DBOX_OPTION_EXTRA_BUFFER_CNT), sizeof(*data->gbar_extra)); + if (!data->gbar_extra) { + ErrPrint("calloc: %s\n", strerror(errno)); + } + } + data->gbar_extra[idx] = resource_id; + data->gbar_extra_cnt++; + + if (dynamicbox_acquire_extra_resource_id(handle, 1, idx, acquire_gbar_extra_resource_cb, data) < 0) { + ErrPrint("Failed to acquire resource: %u\n", resource_id); + } + break; + case DBOX_EVENT_GBAR_EXTRA_BUFFER_DESTROYED: + dynamicbox_get_affected_extra_buffer(handle, 1, &idx, &resource_id); + DbgPrint("Extra buffer destroyed for GBAR: %d (%u)\n", idx, resource_id); + if (data->gbar_extra[idx] != resource_id) { + DbgPrint("Resource Id mismatched\n"); + } + data->gbar_extra[idx] = 0u; + data->gbar_extra_cnt--; + if (!data->gbar_extra_cnt) { + DbgPrint("Release gbar array\n"); + free(data->gbar_extra); + data->gbar_extra = NULL; + } + + if (dynamicbox_release_resource_id(handle, 1, resource_id) < 0) { + ErrPrint("Failed to release resource: %u\n", resource_id); + } + break; + case DBOX_EVENT_DBOX_EXTRA_UPDATED: + dynamicbox_get_affected_extra_buffer(handle, 0, &idx, &resource_id); + DbgPrint("Extra buffer updated for DBOX: %d (%u)\n", idx, resource_id); + if (!data->dbox_extra) { + ErrPrint("Extra buffer is not prepared yet\n"); + } else { + if (data->dbox_extra[idx] != resource_id) { + ErrPrint("Resource ID mismatched\n"); + } + append_dbox_dirty_object_list(data, idx); + } + break; + case DBOX_EVENT_GBAR_EXTRA_UPDATED: + dynamicbox_get_affected_extra_buffer(handle, 1, &idx, &resource_id); + DbgPrint("Extra buffer updated for GBAR: %d (%u)\n", idx, resource_id); + if (!data->gbar_extra) { + ErrPrint("Extra buffer is not prepared yet\n"); + } else { + if (data->gbar_extra[idx] != resource_id) { + ErrPrint("Resource ID mismatched\n"); + } + append_gbar_dirty_object_list(data, idx); + } + break; case DBOX_EVENT_DBOX_UPDATED: - append_dbox_dirty_object_list(data); - break; + append_dbox_dirty_object_list(data, DBOX_PRIMARY_BUFFER); + break; case DBOX_EVENT_GBAR_UPDATED: - append_gbar_dirty_object_list(data); - break; + append_gbar_dirty_object_list(data, DBOX_PRIMARY_BUFFER); + break; case DBOX_EVENT_EXTRA_INFO_UPDATED: - dynamicbox_event_extra_info_updated(data); - break; + dynamicbox_event_extra_info_updated(data); + break; case DBOX_EVENT_DELETED: - dynamicbox_event_deleted(data); - break; + dynamicbox_event_deleted(data); + break; case DBOX_EVENT_GROUP_CHANGED: - dynamicbox_event_group_changed(data); - break; + dynamicbox_event_group_changed(data); + break; case DBOX_EVENT_PINUP_CHANGED: - dynamicbox_event_pinup_changed(data); - break; + dynamicbox_event_pinup_changed(data); + break; case DBOX_EVENT_PERIOD_CHANGED: - dynamicbox_event_period_changed(data); - break; + dynamicbox_event_period_changed(data); + break; case DBOX_EVENT_DBOX_SIZE_CHANGED: - dynamicbox_event_dbox_size_changed(data); - break; + dynamicbox_event_dbox_size_changed(data); + break; case DBOX_EVENT_GBAR_SIZE_CHANGED: - dynamicbox_event_gbar_size_changed(data); - break; + dynamicbox_event_gbar_size_changed(data); + break; case DBOX_EVENT_GBAR_CREATED: - dynamicbox_event_gbar_created(data); - break; + dynamicbox_event_gbar_created(data); + break; case DBOX_EVENT_GBAR_DESTROYED: - dynamicbox_event_gbar_destroyed(data); - break; + dynamicbox_event_gbar_destroyed(data); + break; case DBOX_EVENT_HOLD_SCROLL: - dynamicbox_event_hold_scroll(data); - break; + dynamicbox_event_hold_scroll(data); + break; case DBOX_EVENT_RELEASE_SCROLL: - dynamicbox_event_release_scroll(data); - break; + dynamicbox_event_release_scroll(data); + break; case DBOX_EVENT_DBOX_UPDATE_BEGIN: - dynamicbox_event_dbox_update_begin(data); - break; + dynamicbox_event_dbox_update_begin(data); + break; case DBOX_EVENT_DBOX_UPDATE_END: - dynamicbox_event_dbox_update_end(data); - break; + dynamicbox_event_dbox_update_end(data); + break; case DBOX_EVENT_GBAR_UPDATE_BEGIN: - dynamicbox_event_gbar_update_begin(data); - break; + dynamicbox_event_gbar_update_begin(data); + break; case DBOX_EVENT_GBAR_UPDATE_END: - dynamicbox_event_gbar_update_end(data); - break; + dynamicbox_event_gbar_update_end(data); + break; case DBOX_EVENT_UPDATE_MODE_CHANGED: - dynamicbox_event_update_mode_changed(data); - break; + dynamicbox_event_update_mode_changed(data); + break; case DBOX_EVENT_REQUEST_CLOSE_GBAR: - dynamicbox_event_request_close_gbar(data); - break; + dynamicbox_event_request_close_gbar(data); + break; case DBOX_EVENT_IGNORED: - dynamicbox_event_ignored(data); - break; + dynamicbox_event_ignored(data); + break; default: - break; - } + break; + } - return 0; + return 0; } static int dynamicbox_fault_handler(enum dynamicbox_fault_type fault, const char *pkgname, const char *filename, const char *funcname, void *cbdata) { - Eina_List *l = NULL; - Evas_Object *dynamicbox; - struct widget_data *data; - struct dynamicbox_evas_event_info info; + Eina_List *l = NULL; + Evas_Object *dynamicbox; + struct widget_data *data; + struct dynamicbox_evas_event_info info; - switch (fault) { + switch (fault) { case DBOX_FAULT_DEACTIVATED: - EINA_LIST_FOREACH(s_info.list, l, dynamicbox) { - data = get_smart_data(dynamicbox); - if (!data) { - continue; - } - - if (!strcmp(data->dbox_id, pkgname)) { - DbgPrint("Faulted: %s (%p)\n", pkgname, data); - data->is.field.faulted = 1; - dbox_overlay_faulted(data); - info.error = DBOX_STATUS_ERROR_FAULT; - info.pkgname = data->dbox_id; - info.event = DBOX_FAULT_DEACTIVATED; - smart_callback_call(data, DYNAMICBOX_SMART_SIGNAL_DBOX_FAULTED, &info); - } + EINA_LIST_FOREACH(s_info.list, l, dynamicbox) { + data = get_smart_data(dynamicbox); + if (!data) { + continue; } - break; + + if (!strcmp(data->dbox_id, pkgname)) { + DbgPrint("Faulted: %s (%p)\n", pkgname, data); + data->is.field.faulted = 1; + dbox_overlay_faulted(data); + info.error = DBOX_STATUS_ERROR_FAULT; + info.pkgname = data->dbox_id; + info.event = DBOX_FAULT_DEACTIVATED; + smart_callback_call(data, DYNAMICBOX_SMART_SIGNAL_DBOX_FAULTED, &info); + } + } + break; case DBOX_FAULT_PROVIDER_DISCONNECTED: - EINA_LIST_FOREACH(s_info.list, l, dynamicbox) { - data = get_smart_data(dynamicbox); - if (!data) { - continue; - } - - if (!strcmp(data->dbox_id, pkgname)) { - DbgPrint("Disconnected: %s (%p)\n", pkgname, data); - data->is.field.faulted = 1; - dbox_overlay_faulted(data); - info.error = DBOX_STATUS_ERROR_FAULT; - info.pkgname = data->dbox_id; - info.event = DBOX_FAULT_PROVIDER_DISCONNECTED; - smart_callback_call(data, DYNAMICBOX_SMART_SIGNAL_PROVIDER_DISCONNECTED, &info); - } + EINA_LIST_FOREACH(s_info.list, l, dynamicbox) { + data = get_smart_data(dynamicbox); + if (!data) { + continue; } - break; + + if (!strcmp(data->dbox_id, pkgname)) { + DbgPrint("Disconnected: %s (%p)\n", pkgname, data); + data->is.field.faulted = 1; + dbox_overlay_faulted(data); + info.error = DBOX_STATUS_ERROR_FAULT; + info.pkgname = data->dbox_id; + info.event = DBOX_FAULT_PROVIDER_DISCONNECTED; + smart_callback_call(data, DYNAMICBOX_SMART_SIGNAL_PROVIDER_DISCONNECTED, &info); + } + } + break; default: - break; - } - return 0; + break; + } + return 0; } EAPI int evas_object_dynamicbox_init(Evas_Object *win, int force_to_buffer) { - int ret; + int ret; - ecore_x_window_size_get(0, &s_info.screen_width, &s_info.screen_height); + ecore_x_window_size_get(0, &s_info.screen_width, &s_info.screen_height); - dynamicbox_set_option(DBOX_OPTION_DIRECT_UPDATE, 1); - s_info.conf.field.render_animator = 1; // By default, use render animator for updating + dynamicbox_set_option(DBOX_OPTION_DIRECT_UPDATE, 1); + s_info.conf.field.render_animator = 1; // By default, use render animator for updating - ret = dynamicbox_init(ecore_x_display_get(), 1, 0.001f, 1); - if (ret < 0) { - return ret; - } + ret = dynamicbox_init(ecore_x_display_get(), 1, 0.001f, 1); + if (ret < 0) { + return ret; + } - ret = dynamicbox_set_event_handler(dynamicbox_event_handler, NULL); + ret = dynamicbox_add_event_handler(dynamicbox_event_handler, NULL); + if (ret != DBOX_STATUS_ERROR_NONE) { + ErrPrint("Failed to set handler\n"); + dynamicbox_fini(); + } else { + DbgPrint("Event handler registered\n"); + ret = dynamicbox_add_fault_handler(dynamicbox_fault_handler, NULL); if (ret != DBOX_STATUS_ERROR_NONE) { - ErrPrint("Failed to set handler\n"); - dynamicbox_fini(); + ErrPrint("Failed to set fault handler\n"); + dynamicbox_remove_event_handler(dynamicbox_event_handler); + dynamicbox_fini(); } else { - DbgPrint("Event handler registered\n"); - ret = dynamicbox_set_fault_handler(dynamicbox_fault_handler, NULL); - if (ret != DBOX_STATUS_ERROR_NONE) { - ErrPrint("Failed to set fault handler\n"); - dynamicbox_unset_event_handler(dynamicbox_event_handler); - dynamicbox_fini(); - } else { - DbgPrint("Fault handler is registered\n"); - } + DbgPrint("Fault handler is registered\n"); } + } - s_info.conf.field.force_to_buffer = force_to_buffer; - s_info.win = win; + s_info.conf.field.force_to_buffer = force_to_buffer; + s_info.win = win; - return ret; + return ret; } EAPI int evas_object_dynamicbox_fini(void) { - dynamicbox_unset_event_handler(dynamicbox_event_handler); - dynamicbox_unset_fault_handler(dynamicbox_fault_handler); - dynamicbox_fini(); - return 0; + dynamicbox_remove_event_handler(dynamicbox_event_handler); + dynamicbox_remove_fault_handler(dynamicbox_fault_handler); + dynamicbox_fini(); + return 0; } EAPI int evas_object_dynamicbox_resumed(void) { - return dynamicbox_viewer_set_resumed(); + return dynamicbox_viewer_set_resumed(); } EAPI int evas_object_dynamicbox_paused(void) { - return dynamicbox_viewer_set_paused(); + return dynamicbox_viewer_set_paused(); } EAPI Evas_Object *evas_object_dynamicbox_add(Evas_Object *parent, const char *dbox_id, const char *content_info, const char *cluster, const char *category, double period) { - struct widget_data *data; - Evas_Object *dynamicbox; - char *_dbox_id; - char *_content_info; - char *_cluster; - char *_category; - - if (!parent || !dbox_id) { - return NULL; - } - - if (!cluster) { - cluster = "user,created"; - } + struct widget_data *data; + Evas_Object *dynamicbox; + char *_dbox_id; + char *_content_info; + char *_cluster; + char *_category; - if (!category) { - category = "default"; - } - - _cluster = strdup(cluster); - if (!_cluster) { - ErrPrint("Heap: %s\n", strerror(errno)); - return NULL; - } - - _category = strdup(category); - if (!_category) { - ErrPrint("Heap: %s\n", strerror(errno)); - free(_cluster); - return NULL; - } - - _dbox_id = strdup(dbox_id); - if (!_dbox_id) { - ErrPrint("Heap: %s\n", strerror(errno)); - free(_category); - free(_cluster); - return NULL; - } + if (!parent || !dbox_id) { + return NULL; + } - if (content_info) { - _content_info = strdup(content_info); - if (!_content_info) { - ErrPrint("Heap: %s\n", strerror(errno)); - free(_dbox_id); - free(_category); - free(_cluster); - return NULL; - } - } else { - _content_info = NULL; - } + if (!cluster) { + cluster = "user,created"; + } - if (!s_info.smart) { - s_info.sc.add = widget_add; - s_info.sc.del = widget_del; - s_info.sc.move = widget_move; - s_info.sc.resize = widget_resize; - s_info.sc.show = widget_show; - s_info.sc.hide = widget_hide; - s_info.sc.color_set = widget_color_set; - s_info.sc.clip_set = widget_clip_set; - s_info.sc.clip_unset = widget_clip_unset; - - s_info.smart = evas_smart_class_new(&s_info.sc); - } + if (!category) { + category = "default"; + } - dynamicbox = evas_object_smart_add(evas_object_evas_get(parent), s_info.smart); + _cluster = strdup(cluster); + if (!_cluster) { + ErrPrint("Heap: %s\n", strerror(errno)); + return NULL; + } - data = evas_object_smart_data_get(dynamicbox); - if (data) { - data->parent = parent; - data->dbox_id = _dbox_id; - data->content = _content_info; - data->cluster = _cluster; - data->category = _category; - data->is.field.mouse_event = 0; - data->period = period; - - widget_data_setup(data); - } else { - ErrPrint("Failed to get smart data\n"); - free(_dbox_id); - free(_content_info); - free(_cluster); - free(_category); - } + _category = strdup(category); + if (!_category) { + ErrPrint("Heap: %s\n", strerror(errno)); + free(_cluster); + return NULL; + } - return dynamicbox; + _dbox_id = strdup(dbox_id); + if (!_dbox_id) { + ErrPrint("Heap: %s\n", strerror(errno)); + free(_category); + free(_cluster); + return NULL; + } + + if (content_info) { + _content_info = strdup(content_info); + if (!_content_info) { + ErrPrint("Heap: %s\n", strerror(errno)); + free(_dbox_id); + free(_category); + free(_cluster); + return NULL; + } + } else { + _content_info = NULL; + } + + if (!s_info.smart) { + s_info.sc.add = widget_add; + s_info.sc.del = widget_del; + s_info.sc.move = widget_move; + s_info.sc.resize = widget_resize; + s_info.sc.show = widget_show; + s_info.sc.hide = widget_hide; + s_info.sc.color_set = widget_color_set; + s_info.sc.clip_set = widget_clip_set; + s_info.sc.clip_unset = widget_clip_unset; + + s_info.smart = evas_smart_class_new(&s_info.sc); + } + + dynamicbox = evas_object_smart_add(evas_object_evas_get(parent), s_info.smart); + + data = evas_object_smart_data_get(dynamicbox); + if (data) { + data->parent = parent; + data->dbox_id = _dbox_id; + data->content = _content_info; + data->cluster = _cluster; + data->category = _category; + data->is.field.mouse_event = 0; + data->period = period; + + widget_data_setup(data); + } else { + ErrPrint("Failed to get smart data\n"); + free(_dbox_id); + free(_content_info); + free(_cluster); + free(_category); + } + + return dynamicbox; } EAPI int evas_object_dynamicbox_view_port_set(Evas_Object *dynamicbox, int x, int y, int w, int h) { - struct widget_data *data; + struct widget_data *data; - data = get_smart_data(dynamicbox); - if (!data) { - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + data = get_smart_data(dynamicbox); + if (!data) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - data->view_port.x = x; - data->view_port.y = y; - data->view_port.w = w; - data->view_port.h = h; - s_info.conf.field.user_view_port = 1; - return DBOX_STATUS_ERROR_NONE; + data->view_port.x = x; + data->view_port.y = y; + data->view_port.w = w; + data->view_port.h = h; + s_info.conf.field.user_view_port = 1; + return DBOX_STATUS_ERROR_NONE; } EAPI int evas_object_dynamicbox_view_port_get(Evas_Object *dynamicbox, int *x, int *y, int *w, int *h) { - struct widget_data *data; + struct widget_data *data; - data = get_smart_data(dynamicbox); - if (!data) { - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + data = get_smart_data(dynamicbox); + if (!data) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (x) { - *x = data->view_port.x; - } + if (x) { + *x = data->view_port.x; + } - if (y) { - *y = data->view_port.y; - } + if (y) { + *y = data->view_port.y; + } - if (w) { - *w = data->view_port.w; - } + if (w) { + *w = data->view_port.w; + } - if (h) { - *h = data->view_port.h; - } + if (h) { + *h = data->view_port.h; + } - return DBOX_STATUS_ERROR_NONE; + return DBOX_STATUS_ERROR_NONE; } EAPI int evas_object_dynamicbox_conf_set(enum dynamicbox_evas_conf type, int value) { - switch (type) { + switch (type) { case DYNAMICBOX_EVAS_SENSITIVE_MOVE: - s_info.conf.field.sensitive_move = value; - break; + s_info.conf.field.sensitive_move = value; + break; case DYNAMICBOX_EVAS_EVENT_AUTO_FEED: - s_info.conf.field.auto_feed = value; - break; + s_info.conf.field.auto_feed = value; + break; case DYNAMICBOX_EVAS_EASY_MODE: - s_info.conf.field.easy_mode = value; - break; + s_info.conf.field.easy_mode = value; + break; case DYNAMICBOX_EVAS_USE_FIXED_SIZE: - s_info.conf.field.use_fixed_size = value; - break; + s_info.conf.field.use_fixed_size = value; + break; case DYNAMICBOX_EVAS_MANUAL_PAUSE_RESUME: - s_info.conf.field.manual_pause_resume = value; - break; + s_info.conf.field.manual_pause_resume = value; + break; case DYNAMICBOX_EVAS_SHARED_CONTENT: - (void)dynamicbox_set_option(DBOX_OPTION_SHARED_CONTENT, value); - break; + (void)dynamicbox_set_option(DBOX_OPTION_SHARED_CONTENT, value); + break; case DYNAMICBOX_EVAS_SUPPORT_GBAR: - s_info.conf.field.support_gbar = value; - break; + s_info.conf.field.support_gbar = value; + break; case DYNAMICBOX_EVAS_SCROLL_X: - s_info.conf.field.is_scroll_x = value; - break; + s_info.conf.field.is_scroll_x = value; + break; case DYNAMICBOX_EVAS_SCROLL_Y: - s_info.conf.field.is_scroll_y = value; - break; + s_info.conf.field.is_scroll_y = value; + break; case DYNAMICBOX_EVAS_DELAYED_PAUSE_RESUME: - s_info.conf.field.delayed_pause_resume = value; - break; + s_info.conf.field.delayed_pause_resume = value; + break; case DYNAMICBOX_EVAS_AUTO_RENDER_SELECTION: - s_info.conf.field.auto_render_selector = value; - break; + s_info.conf.field.auto_render_selector = value; + break; default: - break; - } + break; + } - return DBOX_STATUS_ERROR_NONE; + return DBOX_STATUS_ERROR_NONE; } EAPI int evas_object_dynamicbox_pause(Evas_Object *dynamicbox) { - struct widget_data *data; + struct widget_data *data; - data = get_smart_data(dynamicbox); - if (!data || !data->is.field.created || !data->handle) { - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + data = get_smart_data(dynamicbox); + if (!data || !data->is.field.created || !data->handle) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - return dynamicbox_set_visibility(data->handle, DBOX_HIDE_WITH_PAUSE); + return dynamicbox_set_visibility(data->handle, DBOX_HIDE_WITH_PAUSE); } EAPI int evas_object_dynamicbox_resume(Evas_Object *dynamicbox) { - struct widget_data *data; + struct widget_data *data; - data = get_smart_data(dynamicbox); - if (!data || !data->is.field.created || !data->handle) { - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + data = get_smart_data(dynamicbox); + if (!data || !data->is.field.created || !data->handle) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - return dynamicbox_set_visibility(data->handle, DBOX_SHOW); + return dynamicbox_set_visibility(data->handle, DBOX_SHOW); } EAPI int evas_object_dynamicbox_destroy_gbar(Evas_Object *dynamicbox) { - struct widget_data *data; - int ret; + struct widget_data *data; + int ret; - data = get_smart_data(dynamicbox); - if (!data || data->state != WIDGET_DATA_CREATED || !data->is.field.created || !data->handle || !data->is.field.gbar_created) { - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + data = get_smart_data(dynamicbox); + if (!data || data->state != WIDGET_DATA_CREATED || !data->is.field.created || !data->handle || !data->is.field.gbar_created) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - ret = dynamicbox_destroy_glance_bar(data->handle, dbox_destroy_gbar_cb, widget_ref(data)); - if (ret < 0) { - widget_unref(data); - } + ret = dynamicbox_destroy_glance_bar(data->handle, dbox_destroy_gbar_cb, widget_ref(data)); + if (ret < 0) { + widget_unref(data); + } - return ret; + return ret; } EAPI const char *evas_object_dynamicbox_content(Evas_Object *dynamicbox) { - struct widget_data *data; + struct widget_data *data; - data = get_smart_data(dynamicbox); - if (!data || !data->is.field.created || !data->handle) { - return NULL; - } + data = get_smart_data(dynamicbox); + if (!data || !data->is.field.created || !data->handle) { + return NULL; + } - return dynamicbox_content(data->handle); + return dynamicbox_content(data->handle); } EAPI const char *evas_object_dynamicbox_title(Evas_Object *dynamicbox) { - struct widget_data *data; + struct widget_data *data; - data = get_smart_data(dynamicbox); - if (!data || !data->is.field.created || !data->handle) { - return NULL; - } + data = get_smart_data(dynamicbox); + if (!data || !data->is.field.created || !data->handle) { + return NULL; + } - return dynamicbox_title(data->handle); + return dynamicbox_title(data->handle); } EAPI const char *evas_object_dynamicbox_dbox_id(Evas_Object *dynamicbox) { - struct widget_data *data; + struct widget_data *data; - data = get_smart_data(dynamicbox); - if (!data || data->state != WIDGET_DATA_CREATED) { - return NULL; - } + data = get_smart_data(dynamicbox); + if (!data || data->state != WIDGET_DATA_CREATED) { + return NULL; + } - return data->dbox_id; + return data->dbox_id; } EAPI double evas_object_dynamicbox_period(Evas_Object *dynamicbox) { - struct widget_data *data; + struct widget_data *data; - data = get_smart_data(dynamicbox); - if (!data || !data->is.field.created || !data->handle) { - return 0.0f; - } + data = get_smart_data(dynamicbox); + if (!data || !data->is.field.created || !data->handle) { + return 0.0f; + } - return data->period; + return data->period; } EAPI void evas_object_dynamicbox_cancel_click(Evas_Object *dynamicbox) { - struct widget_data *data; + struct widget_data *data; - data = get_smart_data(dynamicbox); - if (!data || !data->is.field.created || !data->handle) { - return; - } + data = get_smart_data(dynamicbox); + if (!data || !data->is.field.created || !data->handle) { + return; + } - if (data->is.field.cancel_click == CANCEL_DISABLED) { - data->is.field.cancel_click = CANCEL_USER; - } + if (data->is.field.cancel_click == CANCEL_DISABLED) { + data->is.field.cancel_click = CANCEL_USER; + } } static void access_ret_cb(struct dynamicbox *handle, int ret, void *data) { - struct access_ret_cb_data *cb_data = data; + struct access_ret_cb_data *cb_data = data; - switch (ret) { + switch (ret) { case DBOX_ACCESS_STATUS_ERROR: - ret = DYNAMICBOX_ACCESS_ERROR; - break; + ret = DYNAMICBOX_ACCESS_ERROR; + break; case DBOX_ACCESS_STATUS_DONE: - ret = DYNAMICBOX_ACCESS_DONE; - break; + ret = DYNAMICBOX_ACCESS_DONE; + break; case DBOX_ACCESS_STATUS_FIRST: - ret = DYNAMICBOX_ACCESS_FIRST; - break; + ret = DYNAMICBOX_ACCESS_FIRST; + break; case DBOX_ACCESS_STATUS_LAST: - ret = DYNAMICBOX_ACCESS_LAST; - break; + ret = DYNAMICBOX_ACCESS_LAST; + break; case DBOX_ACCESS_STATUS_READ: - ret = DYNAMICBOX_ACCESS_READ; - break; + ret = DYNAMICBOX_ACCESS_READ; + break; default: - ret = DYNAMICBOX_ACCESS_UNKNOWN; - break; - } + ret = DYNAMICBOX_ACCESS_UNKNOWN; + break; + } - if (cb_data->ret_cb) { - cb_data->ret_cb(cb_data->obj, ret, cb_data->data); - } + if (cb_data->ret_cb) { + cb_data->ret_cb(cb_data->obj, ret, cb_data->data); + } - free(cb_data); + free(cb_data); } EAPI int evas_object_dynamicbox_force_mouse_up(Evas_Object *dynamicbox) { - struct widget_data *data; + struct widget_data *data; - data = get_smart_data(dynamicbox); - if (!data || !data->is.field.created || !data->handle) { - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + data = get_smart_data(dynamicbox); + if (!data || !data->is.field.created || !data->handle) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - return do_force_mouse_up(data); + return do_force_mouse_up(data); } EAPI int evas_object_dynamicbox_access_action(Evas_Object *dynamicbox, int type, void *_info, void (*ret_cb)(Evas_Object *obj, int ret, void *data), void *cbdata) { - struct widget_data *data; - Elm_Access_Action_Info *info = _info; - int w; - int h; - struct access_ret_cb_data *cb_data; - int ret; - struct dynamicbox_access_event_info ainfo; - - data = get_smart_data(dynamicbox); - if (!data || !data->is.field.created || !data->handle) { - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - evas_object_geometry_get(data->dbox_layout, NULL, NULL, &w, &h); - ainfo.x = (double)info->x / (double)w; - ainfo.y = (double)info->y / (double)h; - ainfo.info = 0; - - switch (type) { + struct widget_data *data; + Elm_Access_Action_Info *info = _info; + int w; + int h; + struct access_ret_cb_data *cb_data; + int ret; + struct dynamicbox_access_event_info ainfo; + + data = get_smart_data(dynamicbox); + if (!data || !data->is.field.created || !data->handle) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + evas_object_geometry_get(data->dbox_layout, NULL, NULL, &w, &h); + ainfo.x = (double)info->x / (double)w; + ainfo.y = (double)info->y / (double)h; + ainfo.info = 0; + + switch (type) { case ELM_ACCESS_ACTION_HIGHLIGHT: /* highlight an object */ - DbgPrint("Highlight %dx%d ignored\n", info->x, info->y); - break; + DbgPrint("Highlight %dx%d ignored\n", info->x, info->y); + break; case ELM_ACCESS_ACTION_READ: - cb_data = calloc(1, sizeof(*cb_data)); - if (!cb_data) { - ErrPrint("Heap: %s\n", strerror(errno)); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } - - cb_data->ret_cb = ret_cb; - cb_data->data = cbdata; - cb_data->obj = dynamicbox; - - ainfo.type = DBOX_ACCESS_TYPE_HIGHLIGHT; - ret = dynamicbox_feed_access_event(data->handle, DBOX_ACCESS_HIGHLIGHT, &ainfo, access_ret_cb, cb_data); - if (ret != DBOX_STATUS_ERROR_NONE) { - free(cb_data); - } - break; + cb_data = calloc(1, sizeof(*cb_data)); + if (!cb_data) { + ErrPrint("Heap: %s\n", strerror(errno)); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } + + cb_data->ret_cb = ret_cb; + cb_data->data = cbdata; + cb_data->obj = dynamicbox; + + ainfo.type = DBOX_ACCESS_TYPE_HIGHLIGHT; + ret = dynamicbox_feed_access_event(data->handle, DBOX_ACCESS_HIGHLIGHT, &ainfo, access_ret_cb, cb_data); + if (ret != DBOX_STATUS_ERROR_NONE) { + free(cb_data); + } + break; case ELM_ACCESS_ACTION_UNHIGHLIGHT: /* unhighlight an object */ - cb_data = calloc(1, sizeof(*cb_data)); - if (!cb_data) { - ErrPrint("Heap: %s\n", strerror(errno)); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } - - cb_data->ret_cb = ret_cb; - cb_data->data = cbdata; - cb_data->obj = dynamicbox; - - ainfo.type = DBOX_ACCESS_TYPE_UNHIGHLIGHT; - ret = dynamicbox_feed_access_event(data->handle, DBOX_ACCESS_HIGHLIGHT, &ainfo, access_ret_cb, cb_data); - if (ret != DBOX_STATUS_ERROR_NONE) { - free(cb_data); - } - break; + cb_data = calloc(1, sizeof(*cb_data)); + if (!cb_data) { + ErrPrint("Heap: %s\n", strerror(errno)); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } + + cb_data->ret_cb = ret_cb; + cb_data->data = cbdata; + cb_data->obj = dynamicbox; + + ainfo.type = DBOX_ACCESS_TYPE_UNHIGHLIGHT; + ret = dynamicbox_feed_access_event(data->handle, DBOX_ACCESS_HIGHLIGHT, &ainfo, access_ret_cb, cb_data); + if (ret != DBOX_STATUS_ERROR_NONE) { + free(cb_data); + } + break; case ELM_ACCESS_ACTION_HIGHLIGHT_NEXT: /* set highlight to next object */ - cb_data = calloc(1, sizeof(*cb_data)); - if (!cb_data) { - ErrPrint("Heap: %s\n", strerror(errno)); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } - - cb_data->ret_cb = ret_cb; - cb_data->data = cbdata; - cb_data->obj = dynamicbox; - - ainfo.type = DBOX_ACCESS_TYPE_HIGHLIGHT_NEXT; - ret = dynamicbox_feed_access_event(data->handle, DBOX_ACCESS_HIGHLIGHT, &ainfo, access_ret_cb, cb_data); - if (ret != DBOX_STATUS_ERROR_NONE) { - free(cb_data); - } - break; + cb_data = calloc(1, sizeof(*cb_data)); + if (!cb_data) { + ErrPrint("Heap: %s\n", strerror(errno)); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } + + cb_data->ret_cb = ret_cb; + cb_data->data = cbdata; + cb_data->obj = dynamicbox; + + ainfo.type = DBOX_ACCESS_TYPE_HIGHLIGHT_NEXT; + ret = dynamicbox_feed_access_event(data->handle, DBOX_ACCESS_HIGHLIGHT, &ainfo, access_ret_cb, cb_data); + if (ret != DBOX_STATUS_ERROR_NONE) { + free(cb_data); + } + break; case ELM_ACCESS_ACTION_HIGHLIGHT_PREV: /* set highlight to previous object */ - cb_data = calloc(1, sizeof(*cb_data)); - if (!cb_data) { - ErrPrint("Heap: %s\n", strerror(errno)); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } - - cb_data->ret_cb = ret_cb; - cb_data->data = cbdata; - cb_data->obj = dynamicbox; - - ainfo.type = DBOX_ACCESS_TYPE_HIGHLIGHT_NEXT; - ret = dynamicbox_feed_access_event(data->handle, DBOX_ACCESS_HIGHLIGHT, &ainfo, access_ret_cb, cb_data); - if (ret != DBOX_STATUS_ERROR_NONE) { - free(cb_data); - } - break; + cb_data = calloc(1, sizeof(*cb_data)); + if (!cb_data) { + ErrPrint("Heap: %s\n", strerror(errno)); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } + + cb_data->ret_cb = ret_cb; + cb_data->data = cbdata; + cb_data->obj = dynamicbox; + + ainfo.type = DBOX_ACCESS_TYPE_HIGHLIGHT_NEXT; + ret = dynamicbox_feed_access_event(data->handle, DBOX_ACCESS_HIGHLIGHT, &ainfo, access_ret_cb, cb_data); + if (ret != DBOX_STATUS_ERROR_NONE) { + free(cb_data); + } + break; case ELM_ACCESS_ACTION_ACTIVATE: /* activate a highlight object */ - cb_data = calloc(1, sizeof(*cb_data)); - if (!cb_data) { - ErrPrint("Heap: %s\n", strerror(errno)); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } - - cb_data->ret_cb = ret_cb; - cb_data->data = cbdata; - cb_data->obj = dynamicbox; - - ainfo.type = DBOX_ACCESS_TYPE_NONE; /* meaningless */ - ret = dynamicbox_feed_access_event(data->handle, DBOX_ACCESS_ACTIVATE, &ainfo, access_ret_cb, cb_data); - if (ret != DBOX_STATUS_ERROR_NONE) { - free(cb_data); - } - break; + cb_data = calloc(1, sizeof(*cb_data)); + if (!cb_data) { + ErrPrint("Heap: %s\n", strerror(errno)); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } + + cb_data->ret_cb = ret_cb; + cb_data->data = cbdata; + cb_data->obj = dynamicbox; + + ainfo.type = DBOX_ACCESS_TYPE_NONE; /* meaningless */ + ret = dynamicbox_feed_access_event(data->handle, DBOX_ACCESS_ACTIVATE, &ainfo, access_ret_cb, cb_data); + if (ret != DBOX_STATUS_ERROR_NONE) { + free(cb_data); + } + break; case ELM_ACCESS_ACTION_SCROLL: /* scroll if one of highlight object parents * is scrollable */ - cb_data = calloc(1, sizeof(*cb_data)); - if (!cb_data) { - ErrPrint("Heap: %s\n", strerror(errno)); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } + cb_data = calloc(1, sizeof(*cb_data)); + if (!cb_data) { + ErrPrint("Heap: %s\n", strerror(errno)); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } - cb_data->ret_cb = ret_cb; - cb_data->data = cbdata; - cb_data->obj = dynamicbox; + cb_data->ret_cb = ret_cb; + cb_data->data = cbdata; + cb_data->obj = dynamicbox; - switch (info->mouse_type) { + switch (info->mouse_type) { case 0: - ainfo.type = DBOX_ACCESS_TYPE_DOWN; - ret = dynamicbox_feed_access_event(data->handle, DBOX_ACCESS_SCROLL, &ainfo, access_ret_cb, cb_data); - if (ret != DBOX_STATUS_ERROR_NONE) { - free(cb_data); - } - break; + ainfo.type = DBOX_ACCESS_TYPE_DOWN; + ret = dynamicbox_feed_access_event(data->handle, DBOX_ACCESS_SCROLL, &ainfo, access_ret_cb, cb_data); + if (ret != DBOX_STATUS_ERROR_NONE) { + free(cb_data); + } + break; case 1: - ainfo.type = DBOX_ACCESS_TYPE_MOVE; - ret = dynamicbox_feed_access_event(data->handle, DBOX_ACCESS_SCROLL, &ainfo, access_ret_cb, cb_data); - if (ret != DBOX_STATUS_ERROR_NONE) { - free(cb_data); - } - break; + ainfo.type = DBOX_ACCESS_TYPE_MOVE; + ret = dynamicbox_feed_access_event(data->handle, DBOX_ACCESS_SCROLL, &ainfo, access_ret_cb, cb_data); + if (ret != DBOX_STATUS_ERROR_NONE) { + free(cb_data); + } + break; case 2: - ainfo.type = DBOX_ACCESS_TYPE_UP; - ret = dynamicbox_feed_access_event(data->handle, DBOX_ACCESS_SCROLL, &ainfo, access_ret_cb, cb_data); - if (ret != DBOX_STATUS_ERROR_NONE) { - free(cb_data); - } - break; - default: - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + ainfo.type = DBOX_ACCESS_TYPE_UP; + ret = dynamicbox_feed_access_event(data->handle, DBOX_ACCESS_SCROLL, &ainfo, access_ret_cb, cb_data); + if (ret != DBOX_STATUS_ERROR_NONE) { free(cb_data); - break; - } - break; + } + break; + default: + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + free(cb_data); + break; + } + break; case ELM_ACCESS_ACTION_MOUSE: /* give mouse event to highlight object */ - cb_data = calloc(1, sizeof(*cb_data)); - if (!cb_data) { - ErrPrint("Heap: %s\n", strerror(errno)); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } - - cb_data->ret_cb = ret_cb; - cb_data->data = cbdata; - cb_data->obj = dynamicbox; - ainfo.type = DBOX_ACCESS_TYPE_NONE; - ret = dynamicbox_feed_access_event(data->handle, DBOX_ACCESS_MOUSE, &ainfo, access_ret_cb, cb_data); - if (ret != DBOX_STATUS_ERROR_NONE) { - free(cb_data); - } - break; + cb_data = calloc(1, sizeof(*cb_data)); + if (!cb_data) { + ErrPrint("Heap: %s\n", strerror(errno)); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } + + cb_data->ret_cb = ret_cb; + cb_data->data = cbdata; + cb_data->obj = dynamicbox; + ainfo.type = DBOX_ACCESS_TYPE_NONE; + ret = dynamicbox_feed_access_event(data->handle, DBOX_ACCESS_MOUSE, &ainfo, access_ret_cb, cb_data); + if (ret != DBOX_STATUS_ERROR_NONE) { + free(cb_data); + } + break; case ELM_ACCESS_ACTION_UP: /* change value up of highlight object */ - cb_data = calloc(1, sizeof(*cb_data)); - if (!cb_data) { - ErrPrint("Heap: %s\n", strerror(errno)); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } - - cb_data->ret_cb = ret_cb; - cb_data->data = cbdata; - cb_data->obj = dynamicbox; - ainfo.type = DBOX_ACCESS_TYPE_UP; - ret = dynamicbox_feed_access_event(data->handle, DBOX_ACCESS_ACTION, &ainfo, access_ret_cb, cb_data); - if (ret != DBOX_STATUS_ERROR_NONE) { - free(cb_data); - } - break; + cb_data = calloc(1, sizeof(*cb_data)); + if (!cb_data) { + ErrPrint("Heap: %s\n", strerror(errno)); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } + + cb_data->ret_cb = ret_cb; + cb_data->data = cbdata; + cb_data->obj = dynamicbox; + ainfo.type = DBOX_ACCESS_TYPE_UP; + ret = dynamicbox_feed_access_event(data->handle, DBOX_ACCESS_ACTION, &ainfo, access_ret_cb, cb_data); + if (ret != DBOX_STATUS_ERROR_NONE) { + free(cb_data); + } + break; case ELM_ACCESS_ACTION_DOWN: /* change value down of highlight object */ - cb_data = calloc(1, sizeof(*cb_data)); - if (!cb_data) { - ErrPrint("Heap: %s\n", strerror(errno)); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } - - cb_data->ret_cb = ret_cb; - cb_data->data = cbdata; - cb_data->obj = dynamicbox; - - ainfo.type = DBOX_ACCESS_TYPE_DOWN; - ret = dynamicbox_feed_access_event(data->handle, DBOX_ACCESS_ACTION, &ainfo, access_ret_cb, cb_data); - if (ret != DBOX_STATUS_ERROR_NONE) { - free(cb_data); - } - break; + cb_data = calloc(1, sizeof(*cb_data)); + if (!cb_data) { + ErrPrint("Heap: %s\n", strerror(errno)); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } + + cb_data->ret_cb = ret_cb; + cb_data->data = cbdata; + cb_data->obj = dynamicbox; + + ainfo.type = DBOX_ACCESS_TYPE_DOWN; + ret = dynamicbox_feed_access_event(data->handle, DBOX_ACCESS_ACTION, &ainfo, access_ret_cb, cb_data); + if (ret != DBOX_STATUS_ERROR_NONE) { + free(cb_data); + } + break; case ELM_ACCESS_ACTION_VALUE_CHANGE: /* TODO: deprecate this */ - cb_data = calloc(1, sizeof(*cb_data)); - if (!cb_data) { - ErrPrint("Heap: %s\n", strerror(errno)); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } - - cb_data->ret_cb = ret_cb; - cb_data->data = cbdata; - cb_data->obj = dynamicbox; - - ainfo.type = DBOX_ACCESS_TYPE_NONE; - ret = dynamicbox_feed_access_event(data->handle, DBOX_ACCESS_VALUE_CHANGE, &ainfo, access_ret_cb, cb_data); - if (ret != DBOX_STATUS_ERROR_NONE) { - free(cb_data); - } - break; + cb_data = calloc(1, sizeof(*cb_data)); + if (!cb_data) { + ErrPrint("Heap: %s\n", strerror(errno)); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } + + cb_data->ret_cb = ret_cb; + cb_data->data = cbdata; + cb_data->obj = dynamicbox; + + ainfo.type = DBOX_ACCESS_TYPE_NONE; + ret = dynamicbox_feed_access_event(data->handle, DBOX_ACCESS_VALUE_CHANGE, &ainfo, access_ret_cb, cb_data); + if (ret != DBOX_STATUS_ERROR_NONE) { + free(cb_data); + } + break; case ELM_ACCESS_ACTION_BACK: /* go back to a previous view ex: pop naviframe item */ - cb_data = calloc(1, sizeof(*cb_data)); - if (!cb_data) { - ErrPrint("Heap: %s\n", strerror(errno)); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } - - cb_data->ret_cb = ret_cb; - cb_data->data = cbdata; - cb_data->obj = dynamicbox; - - ainfo.type = DBOX_ACCESS_TYPE_NONE; - ret = dynamicbox_feed_access_event(data->handle, DBOX_ACCESS_BACK, &ainfo, access_ret_cb, cb_data); - if (ret != DBOX_STATUS_ERROR_NONE) { - free(cb_data); - } - break; + cb_data = calloc(1, sizeof(*cb_data)); + if (!cb_data) { + ErrPrint("Heap: %s\n", strerror(errno)); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } + + cb_data->ret_cb = ret_cb; + cb_data->data = cbdata; + cb_data->obj = dynamicbox; + + ainfo.type = DBOX_ACCESS_TYPE_NONE; + ret = dynamicbox_feed_access_event(data->handle, DBOX_ACCESS_BACK, &ainfo, access_ret_cb, cb_data); + if (ret != DBOX_STATUS_ERROR_NONE) { + free(cb_data); + } + break; case ELM_ACCESS_ACTION_OVER: /* mouse over an object */ - cb_data = calloc(1, sizeof(*cb_data)); - if (!cb_data) { - ErrPrint("Heap: %s\n", strerror(errno)); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } - - cb_data->ret_cb = ret_cb; - cb_data->data = cbdata; - cb_data->obj = dynamicbox; - - ainfo.type = DBOX_ACCESS_TYPE_NONE; - ret = dynamicbox_feed_access_event(data->handle, DBOX_ACCESS_OVER, &ainfo, access_ret_cb, cb_data); - if (ret != DBOX_STATUS_ERROR_NONE) { - free(cb_data); - } - break; + cb_data = calloc(1, sizeof(*cb_data)); + if (!cb_data) { + ErrPrint("Heap: %s\n", strerror(errno)); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } + + cb_data->ret_cb = ret_cb; + cb_data->data = cbdata; + cb_data->obj = dynamicbox; + + ainfo.type = DBOX_ACCESS_TYPE_NONE; + ret = dynamicbox_feed_access_event(data->handle, DBOX_ACCESS_OVER, &ainfo, access_ret_cb, cb_data); + if (ret != DBOX_STATUS_ERROR_NONE) { + free(cb_data); + } + break; case ELM_ACCESS_ACTION_ENABLE: /* enable highlight and read ability */ - cb_data = calloc(1, sizeof(*cb_data)); - if (!cb_data) { - ErrPrint("Heap: %s\n", strerror(errno)); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } - - cb_data->ret_cb = ret_cb; - cb_data->data = cbdata; - cb_data->obj = dynamicbox; - - ainfo.type = DBOX_ACCESS_TYPE_ENABLE; - ret = dynamicbox_feed_access_event(data->handle, DBOX_ACCESS_ENABLE, &ainfo, access_ret_cb, cb_data); - if (ret != DBOX_STATUS_ERROR_NONE) { - free(cb_data); - } - break; + cb_data = calloc(1, sizeof(*cb_data)); + if (!cb_data) { + ErrPrint("Heap: %s\n", strerror(errno)); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } + + cb_data->ret_cb = ret_cb; + cb_data->data = cbdata; + cb_data->obj = dynamicbox; + + ainfo.type = DBOX_ACCESS_TYPE_ENABLE; + ret = dynamicbox_feed_access_event(data->handle, DBOX_ACCESS_ENABLE, &ainfo, access_ret_cb, cb_data); + if (ret != DBOX_STATUS_ERROR_NONE) { + free(cb_data); + } + break; case ELM_ACCESS_ACTION_DISABLE: /* disable highlight and read ability */ - cb_data = calloc(1, sizeof(*cb_data)); - if (!cb_data) { - ErrPrint("Heap: %s\n", strerror(errno)); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } - - cb_data->ret_cb = ret_cb; - cb_data->data = cbdata; - cb_data->obj = dynamicbox; - - ainfo.type = DBOX_ACCESS_TYPE_DISABLE; - ret = dynamicbox_feed_access_event(data->handle, DBOX_ACCESS_ENABLE, &ainfo, access_ret_cb, cb_data); - if (ret != DBOX_STATUS_ERROR_NONE) { - free(cb_data); - } - break; + cb_data = calloc(1, sizeof(*cb_data)); + if (!cb_data) { + ErrPrint("Heap: %s\n", strerror(errno)); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } + + cb_data->ret_cb = ret_cb; + cb_data->data = cbdata; + cb_data->obj = dynamicbox; + + ainfo.type = DBOX_ACCESS_TYPE_DISABLE; + ret = dynamicbox_feed_access_event(data->handle, DBOX_ACCESS_ENABLE, &ainfo, access_ret_cb, cb_data); + if (ret != DBOX_STATUS_ERROR_NONE) { + free(cb_data); + } + break; default: - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - break; - } + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + break; + } - return ret; + return ret; } EAPI void evas_object_dynamicbox_disable_preview(Evas_Object *dynamicbox) { - struct widget_data *data; + struct widget_data *data; - data = get_smart_data(dynamicbox); - if (!data) { - ErrPrint("Invalid object\n"); - return; - } + data = get_smart_data(dynamicbox); + if (!data) { + ErrPrint("Invalid object\n"); + return; + } - data->is.field.disable_preview = 1; + data->is.field.disable_preview = 1; } EAPI void evas_object_dynamicbox_disable_overlay_text(Evas_Object *dynamicbox) { - struct widget_data *data; + struct widget_data *data; - data = get_smart_data(dynamicbox); - if (!data) { - ErrPrint("Invalid object\n"); - return; - } + data = get_smart_data(dynamicbox); + if (!data) { + ErrPrint("Invalid object\n"); + return; + } - data->is.field.disable_text = 1; + data->is.field.disable_text = 1; } EAPI void evas_object_dynamicbox_disable_loading(Evas_Object *dynamicbox) { - struct widget_data *data; + struct widget_data *data; - data = get_smart_data(dynamicbox); - if (!data) { - ErrPrint("Invalid object\n"); - return; - } + data = get_smart_data(dynamicbox); + if (!data) { + ErrPrint("Invalid object\n"); + return; + } - data->is.field.disable_loading = 1; + data->is.field.disable_loading = 1; } EAPI void evas_object_dynamicbox_activate(Evas_Object *dynamicbox) { - struct widget_data *data; + struct widget_data *data; - data = get_smart_data(dynamicbox); - if (!data) { - ErrPrint("Invalid object\n"); - return; - } + data = get_smart_data(dynamicbox); + if (!data) { + ErrPrint("Invalid object\n"); + return; + } - if (data->is.field.faulted) { - elm_object_signal_emit(data->dbox_layout, "mouse,clicked,1", "overlay,content"); - } else { - DbgPrint("Dynamicbox is not faulted\n"); - } + if (data->is.field.faulted) { + elm_object_signal_emit(data->dbox_layout, "mouse,clicked,1", "overlay,content"); + } else { + DbgPrint("Dynamicbox is not faulted\n"); + } } EAPI int evas_object_dynamicbox_is_faulted(Evas_Object *dynamicbox) { - struct widget_data *data; + struct widget_data *data; - data = get_smart_data(dynamicbox); - if (!data) { - ErrPrint("Invalid object\n"); - return 0; - } + data = get_smart_data(dynamicbox); + if (!data) { + ErrPrint("Invalid object\n"); + return 0; + } - return data->is.field.faulted; + return data->is.field.faulted; } EAPI int evas_object_dynamicbox_set_raw_event_callback(enum dynamicbox_evas_raw_event_type type, void (*cb)(struct dynamicbox_evas_raw_event_info *info, void *data), void *data) { - struct raw_event_cbdata *cbdata; + struct raw_event_cbdata *cbdata; - cbdata = calloc(1, sizeof(*cbdata)); - if (!cbdata) { - ErrPrint("calloc: %s\n", strerror(errno)); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } + cbdata = calloc(1, sizeof(*cbdata)); + if (!cbdata) { + ErrPrint("calloc: %s\n", strerror(errno)); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } - cbdata->cb = cb; - cbdata->data = data; + cbdata->cb = cb; + cbdata->data = data; - switch (type) { + switch (type) { case DYNAMICBOX_EVAS_RAW_DELETE: - s_info.raw_event.delete_list = eina_list_append(s_info.raw_event.delete_list, cbdata); - break; + s_info.raw_event.delete_list = eina_list_append(s_info.raw_event.delete_list, cbdata); + break; case DYNAMICBOX_EVAS_RAW_CREATE: - s_info.raw_event.create_list = eina_list_append(s_info.raw_event.create_list, cbdata); - break; + s_info.raw_event.create_list = eina_list_append(s_info.raw_event.create_list, cbdata); + break; default: - break; - } + break; + } - return DBOX_STATUS_ERROR_NONE; + return DBOX_STATUS_ERROR_NONE; } EAPI int evas_object_dynamicbox_unset_raw_event_callback(enum dynamicbox_evas_raw_event_type type, void (*cb)(struct dynamicbox_evas_raw_event_info *info, void *data), void *data) { - Eina_List *l; - Eina_List *n; - struct raw_event_cbdata *cbdata; + Eina_List *l; + Eina_List *n; + struct raw_event_cbdata *cbdata; - switch (type) { + switch (type) { case DYNAMICBOX_EVAS_RAW_DELETE: - EINA_LIST_FOREACH_SAFE(s_info.raw_event.delete_list, l, n, cbdata) { - if (cbdata->cb == cb && cbdata->data == data) { - s_info.raw_event.delete_list = eina_list_remove(s_info.raw_event.delete_list, cbdata); - break; - } + EINA_LIST_FOREACH_SAFE(s_info.raw_event.delete_list, l, n, cbdata) { + if (cbdata->cb == cb && cbdata->data == data) { + s_info.raw_event.delete_list = eina_list_remove(s_info.raw_event.delete_list, cbdata); + break; } - break; + } + break; case DYNAMICBOX_EVAS_RAW_CREATE: - EINA_LIST_FOREACH_SAFE(s_info.raw_event.create_list, l, n, cbdata) { - if (cbdata->cb == cb && cbdata->data == data) { - s_info.raw_event.create_list = eina_list_remove(s_info.raw_event.create_list, cbdata); - break; - } + EINA_LIST_FOREACH_SAFE(s_info.raw_event.create_list, l, n, cbdata) { + if (cbdata->cb == cb && cbdata->data == data) { + s_info.raw_event.create_list = eina_list_remove(s_info.raw_event.create_list, cbdata); + break; } - break; + } + break; default: - break; - } + break; + } - return DBOX_STATUS_ERROR_NONE; + return DBOX_STATUS_ERROR_NONE; } EAPI int evas_object_dynamicbox_freeze_visibility(Evas_Object *dynamicbox, int status) { - struct widget_data *data; + struct widget_data *data; - data = get_smart_data(dynamicbox); - if (!data) { - ErrPrint("Invalid object\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + data = get_smart_data(dynamicbox); + if (!data) { + ErrPrint("Invalid object\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - data->is.field.freeze_visibility = 1; - data->freezed_visibility = status; - return DBOX_STATUS_ERROR_NONE; + data->is.field.freeze_visibility = 1; + data->freezed_visibility = status; + return DBOX_STATUS_ERROR_NONE; } EAPI int evas_object_dynamicbox_thaw_visibility(Evas_Object *dynamicbox) { - struct widget_data *data; + struct widget_data *data; - data = get_smart_data(dynamicbox); - if (!data) { - ErrPrint("Invalid object\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + data = get_smart_data(dynamicbox); + if (!data) { + ErrPrint("Invalid object\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - data->is.field.freeze_visibility = 0; + data->is.field.freeze_visibility = 0; - return DBOX_STATUS_ERROR_NONE; + return DBOX_STATUS_ERROR_NONE; } EAPI int evas_object_dynamicbox_visibility_is_freezed(Evas_Object *dynamicbox) { - struct widget_data *data; + struct widget_data *data; - data = get_smart_data(dynamicbox); - if (!data) { - ErrPrint("Invalid object\n"); - return 0; - } + data = get_smart_data(dynamicbox); + if (!data) { + ErrPrint("Invalid object\n"); + return 0; + } - return data->is.field.freeze_visibility; + return data->is.field.freeze_visibility; } EAPI int evas_object_dynamicbox_dump(Evas_Object *dynamicbox, const char *filename) { - struct widget_data *data; - FILE *fp; + struct widget_data *data; + FILE *fp; - data = get_smart_data(dynamicbox); - if (!data) { - ErrPrint("Invalid object\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + data = get_smart_data(dynamicbox); + if (!data) { + ErrPrint("Invalid object\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - fp = fopen(filename, "w+"); - if (fp) { - Evas_Object *image; - image = elm_object_part_content_get(data->dbox_layout, "dynamicbox,content"); - if (image) { - void *data; - Evas_Coord w, h; - evas_object_geometry_get(image, NULL, NULL, &w, &h); - - data = evas_object_image_data_get(image, 0); - if (data) { - fwrite(data, w * h, sizeof(int), fp); - } - } - fclose(fp); + fp = fopen(filename, "w+"); + if (fp) { + Evas_Object *image; + image = elm_object_part_content_get(data->dbox_layout, "dynamicbox,content"); + if (image) { + void *data; + Evas_Coord w, h; + evas_object_geometry_get(image, NULL, NULL, &w, &h); + + data = evas_object_image_data_get(image, 0); + if (data) { + fwrite(data, w * h, sizeof(int), fp); + } } + fclose(fp); + } - return DBOX_STATUS_ERROR_NONE; + return DBOX_STATUS_ERROR_NONE; } int evas_object_dynamicbox_is_dynamicbox(Evas_Object *dynamicbox) { - struct widget_data *data; + struct widget_data *data; - data = get_smart_data(dynamicbox); - if (!data) { - ErrPrint("Invalid object\n"); - return 0; - } + data = get_smart_data(dynamicbox); + if (!data) { + ErrPrint("Invalid object\n"); + return 0; + } - return 1; + return 1; } void evas_object_dynamicbox_use_render_animator(int flag) { - if (s_info.conf.field.auto_render_selector) { - DbgPrint("Auto selector enabled, this flag will be changed automatically\n"); - } + if (s_info.conf.field.auto_render_selector) { + DbgPrint("Auto selector enabled, this flag will be changed automatically\n"); + } - s_info.conf.field.render_animator = !!flag; - DbgPrint("Turn %s render animator\n", s_info.conf.field.render_animator ? "on" : "off"); + s_info.conf.field.render_animator = !!flag; + DbgPrint("Turn %s render animator\n", s_info.conf.field.render_animator ? "on" : "off"); } void evas_object_dynamicbox_set_permanent_delete(Evas_Object *dynamicbox, int flag) { - struct widget_data *data; + struct widget_data *data; - data = get_smart_data(dynamicbox); - if (!data) { - ErrPrint("Invalid object\n"); - return; - } + data = get_smart_data(dynamicbox); + if (!data) { + ErrPrint("Invalid object\n"); + return; + } - data->is.field.permanent_delete = !!flag; + data->is.field.permanent_delete = !!flag; } /* End of a file */ diff --git a/src/client.c b/src/client.c index a6e4ae8..eca3c17 100644 --- a/src/client.c +++ b/src/client.c @@ -54,1859 +54,2232 @@ int errno; #define MAX_DIRECT_ADDR 256 static struct info { - int fd; - int direct_fd; - guint timer_id; - char *client_addr; - char *direct_addr; + int fd; + int direct_fd; + guint timer_id; + char *client_addr; + char *direct_addr; } s_info = { - .fd = -1, - .direct_fd = -1, - .timer_id = 0, - .client_addr = NULL, - .direct_addr = NULL, + .fd = -1, + .direct_fd = -1, + .timer_id = 0, + .client_addr = NULL, + .direct_addr = NULL, }; static struct packet *master_fault_package(pid_t pid, int handle, const struct packet *packet) { - const char *pkgname; - const char *id; - const char *function; - - if (packet_get(packet, "sss", &pkgname, &id, &function) != 3) { - ErrPrint("Invalid arguments\n"); - return NULL; - } - - DbgPrint("[%s]\n", pkgname); - master_rpc_clear_fault_package(pkgname); - dbox_invoke_fault_handler(DBOX_FAULT_DEACTIVATED, pkgname, id, function); - return NULL; + const char *pkgname; + const char *id; + const char *function; + + if (packet_get(packet, "sss", &pkgname, &id, &function) != 3) { + ErrPrint("Invalid arguments\n"); + return NULL; + } + + DbgPrint("[%s]\n", pkgname); + master_rpc_clear_fault_package(pkgname); + dbox_invoke_fault_handler(DBOX_FAULT_DEACTIVATED, pkgname, id, function); + return NULL; } static struct packet *master_hold_scroll(pid_t pid, int handle, const struct packet *packet) { - struct dynamicbox_common *common; - dynamicbox_h dynamicbox; - const char *pkgname; - const char *id; - int seize; - int ret; - struct dlist *l; - - ret = packet_get(packet, "ssi", &pkgname, &id, &seize); - if (ret != 3) { - ErrPrint("Invalid argument\n"); - goto out; - } - - common = dbox_find_common_handle(pkgname, id); - if (!common) { - ErrPrint("Instance(%s) is not exists\n", id); - goto out; - } - - DbgPrint("HOLD: [%s] seize(%d)\n", id, seize); - seize = seize ? DBOX_EVENT_HOLD_SCROLL : DBOX_EVENT_RELEASE_SCROLL; - dlist_foreach(common->dynamicbox_list, l, dynamicbox) { - dbox_invoke_event_handler(dynamicbox, seize); - } + struct dynamicbox_common *common; + dynamicbox_h dynamicbox; + const char *pkgname; + const char *id; + int seize; + int ret; + struct dlist *l; + + ret = packet_get(packet, "ssi", &pkgname, &id, &seize); + if (ret != 3) { + ErrPrint("Invalid argument\n"); + goto out; + } + + common = dbox_find_common_handle(pkgname, id); + if (!common) { + ErrPrint("Instance(%s) is not exists\n", id); + goto out; + } + + DbgPrint("HOLD: [%s] seize(%d)\n", id, seize); + seize = seize ? DBOX_EVENT_HOLD_SCROLL : DBOX_EVENT_RELEASE_SCROLL; + dlist_foreach(common->dynamicbox_list, l, dynamicbox) { + dbox_invoke_event_handler(dynamicbox, seize); + } out: - return NULL; + return NULL; } static struct packet *master_pinup(pid_t pid, int handle, const struct packet *packet) { - const char *pkgname; - const char *id; - const char *content; - dynamicbox_h handler; - struct dlist *l; - struct dlist *n; - struct dynamicbox_common *common; - char *new_content; - int ret; - int status; - int pinup; - - ret = packet_get(packet, "iisss", &status, &pinup, &pkgname, &id, &content); - if (ret != 5) { - ErrPrint("Invalid argument\n"); - goto out; - } - - common = dbox_find_common_handle(pkgname, id); - if (!common) { - ErrPrint("Instance (%s) is not exists\n", id); - goto out; - } - - if (status == (int)DBOX_STATUS_ERROR_NONE) { - new_content = strdup(content); - if (new_content) { - free(common->content); - common->content = new_content; - common->is_pinned_up = pinup; - } else { - ErrPrint("Heap: %s\n", strerror(errno)); - status = DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } - } - - common->request.pinup = 0; - - dlist_foreach_safe(common->dynamicbox_list, l, n, handler) { - if (handler->cbs.pinup.cb) { - dynamicbox_ret_cb cb; - void *cbdata; - - /* Make sure that user can call pinup API in its result callback */ - cb = handler->cbs.pinup.cb; - cbdata = handler->cbs.pinup.data; - - handler->cbs.pinup.cb = NULL; - handler->cbs.pinup.data = NULL; - - cb(handler, status, cbdata); - } else if (status == (int)DBOX_STATUS_ERROR_NONE) { - dbox_invoke_event_handler(handler, DBOX_EVENT_PINUP_CHANGED); - } - } + const char *pkgname; + const char *id; + const char *content; + dynamicbox_h handler; + struct dlist *l; + struct dlist *n; + struct dynamicbox_common *common; + char *new_content; + int ret; + int status; + int pinup; + + ret = packet_get(packet, "iisss", &status, &pinup, &pkgname, &id, &content); + if (ret != 5) { + ErrPrint("Invalid argument\n"); + goto out; + } + + common = dbox_find_common_handle(pkgname, id); + if (!common) { + ErrPrint("Instance (%s) is not exists\n", id); + goto out; + } + + if (status == (int)DBOX_STATUS_ERROR_NONE) { + new_content = strdup(content); + if (new_content) { + free(common->content); + common->content = new_content; + common->is_pinned_up = pinup; + } else { + ErrPrint("Heap: %s\n", strerror(errno)); + status = DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } + } + + common->request.pinup = 0; + + dlist_foreach_safe(common->dynamicbox_list, l, n, handler) { + if (handler->cbs.pinup.cb) { + dynamicbox_ret_cb cb; + void *cbdata; + + /* Make sure that user can call pinup API in its result callback */ + cb = handler->cbs.pinup.cb; + cbdata = handler->cbs.pinup.data; + + handler->cbs.pinup.cb = NULL; + handler->cbs.pinup.data = NULL; + + cb(handler, status, cbdata); + } else if (status == (int)DBOX_STATUS_ERROR_NONE) { + dbox_invoke_event_handler(handler, DBOX_EVENT_PINUP_CHANGED); + } + } out: - return NULL; + return NULL; } static struct packet *master_deleted(pid_t pid, int handle, const struct packet *packet) { - const char *pkgname; - const char *id; - double timestamp; - dynamicbox_h handler; - struct dynamicbox_common *common; - struct dlist *l; - struct dlist *n; - int reason; - - if (packet_get(packet, "ssdi", &pkgname, &id, ×tamp, &reason) != 4) { - ErrPrint("Invalid arguemnt\n"); - goto out; - } - - DbgPrint("[%s]\n", pkgname); - common = dbox_find_common_handle_by_timestamp(timestamp); - if (!common) { - /*! - * \note - * This can be happens only if the user delete a dynamicbox - * right after create it before receive created event. - */ - goto out; - } - - /*!< Check validity of this "handler" */ - if (common->state != DBOX_STATE_CREATE) { - if (common->state != DBOX_STATE_DELETE) { - /*! - * \note - * This is not possible - */ - ErrPrint("Already deleted handler (%s - %s)\n", pkgname, id); - return NULL; - } - } - - common->request.deleted = 0; - /*! - * We should change the state of "common handler' before handling the callbacks. - * Because if user tries to create a new handle in the callbacks, - * find_sharable_common_handle will returns destroying object. - * Then we will get panic. - * To prevent it, we should change its state first. - */ - common->state = DBOX_STATE_DELETE; - - dlist_foreach_safe(common->dynamicbox_list, l, n, handler) { - if (handler->cbs.created.cb) { - dynamicbox_ret_cb cb; - void *cbdata; - /*! - * \note - * - * "if (handler->id == NULL) {" - * - * The instance is not created yet. - * But the master forcely destroy it and send destroyed event to this - * without the created event. - * - * It could be destroyed when a slave has critical error(fault) - * before creating an instance successfully. - */ - if (handler->cbs.created.cb == handler->cbs.deleted.cb) { - if (handler->cbs.created.data != handler->cbs.deleted.data) { - DbgPrint("cb is same but cbdata is different (%s - %s)\n", pkgname, id); - } - - handler->cbs.deleted.cb = NULL; - handler->cbs.deleted.data = NULL; - } - - cb = handler->cbs.created.cb; - cbdata = handler->cbs.created.data; - - handler->cbs.created.cb = NULL; - handler->cbs.created.data = NULL; - - if (reason == (int)DBOX_STATUS_ERROR_NONE) { - reason = DBOX_STATUS_ERROR_CANCEL; - } - - cb(handler, reason, cbdata); - } else if (common->id) { - if (handler->cbs.deleted.cb) { - dynamicbox_ret_cb cb; - void *cbdata; - - cb = handler->cbs.deleted.cb; - cbdata = handler->cbs.deleted.data; - - handler->cbs.deleted.cb = NULL; - handler->cbs.deleted.data = NULL; - - cb(handler, reason, cbdata); - } else { - dbox_invoke_event_handler(handler, DBOX_EVENT_DELETED); - } - } - - /* Just try to delete it, if a user didn't remove it from the live box list */ - dbox_unref(handler, 1); - } + const char *pkgname; + const char *id; + double timestamp; + dynamicbox_h handler; + struct dynamicbox_common *common; + struct dlist *l; + struct dlist *n; + int reason; + + if (packet_get(packet, "ssdi", &pkgname, &id, ×tamp, &reason) != 4) { + ErrPrint("Invalid arguemnt\n"); + goto out; + } + + DbgPrint("[%s]\n", pkgname); + common = dbox_find_common_handle_by_timestamp(timestamp); + if (!common) { + /*! + * \note + * This can be happens only if the user delete a dynamicbox + * right after create it before receive created event. + */ + goto out; + } + + /*!< Check validity of this "handler" */ + if (common->state != DBOX_STATE_CREATE) { + if (common->state != DBOX_STATE_DELETE) { + /*! + * \note + * This is not possible + */ + ErrPrint("Already deleted handler (%s - %s)\n", pkgname, id); + return NULL; + } + } + + common->request.deleted = 0; + /*! + * We should change the state of "common handler' before handling the callbacks. + * Because if user tries to create a new handle in the callbacks, + * find_sharable_common_handle will returns destroying object. + * Then we will get panic. + * To prevent it, we should change its state first. + */ + common->state = DBOX_STATE_DELETE; + + dlist_foreach_safe(common->dynamicbox_list, l, n, handler) { + if (handler->cbs.created.cb) { + dynamicbox_ret_cb cb; + void *cbdata; + /*! + * \note + * + * "if (handler->id == NULL) {" + * + * The instance is not created yet. + * But the master forcely destroy it and send destroyed event to this + * without the created event. + * + * It could be destroyed when a slave has critical error(fault) + * before creating an instance successfully. + */ + if (handler->cbs.created.cb == handler->cbs.deleted.cb) { + if (handler->cbs.created.data != handler->cbs.deleted.data) { + DbgPrint("cb is same but cbdata is different (%s - %s)\n", pkgname, id); + } + + handler->cbs.deleted.cb = NULL; + handler->cbs.deleted.data = NULL; + } + + cb = handler->cbs.created.cb; + cbdata = handler->cbs.created.data; + + handler->cbs.created.cb = NULL; + handler->cbs.created.data = NULL; + + if (reason == (int)DBOX_STATUS_ERROR_NONE) { + reason = DBOX_STATUS_ERROR_CANCEL; + } + + cb(handler, reason, cbdata); + } else if (common->id) { + if (handler->cbs.deleted.cb) { + dynamicbox_ret_cb cb; + void *cbdata; + + cb = handler->cbs.deleted.cb; + cbdata = handler->cbs.deleted.data; + + handler->cbs.deleted.cb = NULL; + handler->cbs.deleted.data = NULL; + + cb(handler, reason, cbdata); + } else { + dbox_invoke_event_handler(handler, DBOX_EVENT_DELETED); + } + } + + /* Just try to delete it, if a user didn't remove it from the live box list */ + dbox_unref(handler, 1); + } out: - return NULL; + return NULL; } static struct packet *master_dbox_update_begin(pid_t pid, int handle, const struct packet *packet) { - dynamicbox_h handler; - struct dynamicbox_common *common; - const char *pkgname; - const char *id; - const char *content; - const char *title; - const char *fbfile; - double priority; - int ret; - - ret = packet_get(packet, "ssdsss", &pkgname, &id, &priority, &content, &title, &fbfile); - if (ret != 6) { - ErrPrint("Invalid argument\n"); - goto out; - } - - common = dbox_find_common_handle(pkgname, id); - if (!common) { - ErrPrint("Instance[%s] is not exists\n", id); - goto out; - } - - if (common->state != DBOX_STATE_CREATE) { - ErrPrint("(%s) is not created\n", id); - goto out; - } - - dbox_set_priority(common, priority); - dbox_set_content(common, content); - dbox_set_title(common, title); - - /*! - * \NOTE - * Width & Height is not changed in this case. - * If the active update is began, the size should not be changed, - * And if the size is changed, the provider should finish the updating first. - * And then begin updating again after change its size. - */ - if (dbox_get_dbox_fb(common)) { - (void)dbox_set_dbox_fb(common, fbfile); - - ret = dbox_sync_dbox_fb(common); - - if (ret != (int)DBOX_STATUS_ERROR_NONE) { - ErrPrint("Failed to do sync FB (%s - %s) (%d)\n", pkgname, fbfile, ret); - } else { - struct dlist *l; - dlist_foreach(common->dynamicbox_list, l, handler) { - dbox_invoke_event_handler(handler, DBOX_EVENT_DBOX_UPDATE_BEGIN); - } - } - } else { - ErrPrint("Invalid request[%s], %s\n", id, fbfile); - } + dynamicbox_h handler; + struct dynamicbox_common *common; + const char *pkgname; + const char *id; + const char *content; + const char *title; + const char *fbfile; + double priority; + int ret; + + ret = packet_get(packet, "ssdsss", &pkgname, &id, &priority, &content, &title, &fbfile); + if (ret != 6) { + ErrPrint("Invalid argument\n"); + goto out; + } + + common = dbox_find_common_handle(pkgname, id); + if (!common) { + ErrPrint("Instance[%s] is not exists\n", id); + goto out; + } + + if (common->state != DBOX_STATE_CREATE) { + ErrPrint("(%s) is not created\n", id); + goto out; + } + + dbox_set_priority(common, priority); + dbox_set_content(common, content); + dbox_set_title(common, title); + + /*! + * \NOTE + * Width & Height is not changed in this case. + * If the active update is began, the size should not be changed, + * And if the size is changed, the provider should finish the updating first. + * And then begin updating again after change its size. + */ + if (dbox_get_dbox_fb(common)) { + (void)dbox_set_dbox_fb(common, fbfile); + + ret = dbox_sync_dbox_fb(common); + + if (ret != (int)DBOX_STATUS_ERROR_NONE) { + ErrPrint("Failed to do sync FB (%s - %s) (%d)\n", pkgname, fbfile, ret); + } else { + struct dlist *l; + dlist_foreach(common->dynamicbox_list, l, handler) { + dbox_invoke_event_handler(handler, DBOX_EVENT_DBOX_UPDATE_BEGIN); + } + } + } else { + ErrPrint("Invalid request[%s], %s\n", id, fbfile); + } out: - return NULL; + return NULL; } static struct packet *master_gbar_update_begin(pid_t pid, int handle, const struct packet *packet) { - dynamicbox_h handler; - struct dynamicbox_common *common; - const char *pkgname; - const char *id; - const char *fbfile; - int ret; - - ret = packet_get(packet, "sss", &pkgname, &id, &fbfile); - if (ret != 2) { - ErrPrint("Invalid argument\n"); - goto out; - } - - common = dbox_find_common_handle(pkgname, id); - if (!common) { - ErrPrint("Instance[%s] is not exists\n", id); - goto out; - } - - if (common->state != DBOX_STATE_CREATE) { - ErrPrint("[%s] is not created\n", id); - goto out; - } - - if (dbox_get_gbar_fb(common)) { - (void)dbox_set_gbar_fb(common, fbfile); - - ret = dbox_sync_gbar_fb(common); - if (ret != (int)DBOX_STATUS_ERROR_NONE) { - ErrPrint("Failed to do sync FB (%s - %s) (%d)\n", pkgname, fbfile, ret); - } else { - struct dlist *l; - dlist_foreach(common->dynamicbox_list, l, handler) { - dbox_invoke_event_handler(handler, DBOX_EVENT_GBAR_UPDATE_BEGIN); - } - } - } else { - ErrPrint("Invalid request[%s], %s\n", id, fbfile); - } + dynamicbox_h handler; + struct dynamicbox_common *common; + const char *pkgname; + const char *id; + const char *fbfile; + int ret; + + ret = packet_get(packet, "sss", &pkgname, &id, &fbfile); + if (ret != 2) { + ErrPrint("Invalid argument\n"); + goto out; + } + + common = dbox_find_common_handle(pkgname, id); + if (!common) { + ErrPrint("Instance[%s] is not exists\n", id); + goto out; + } + + if (common->state != DBOX_STATE_CREATE) { + ErrPrint("[%s] is not created\n", id); + goto out; + } + + if (dbox_get_gbar_fb(common)) { + (void)dbox_set_gbar_fb(common, fbfile); + + ret = dbox_sync_gbar_fb(common); + if (ret != (int)DBOX_STATUS_ERROR_NONE) { + ErrPrint("Failed to do sync FB (%s - %s) (%d)\n", pkgname, fbfile, ret); + } else { + struct dlist *l; + dlist_foreach(common->dynamicbox_list, l, handler) { + dbox_invoke_event_handler(handler, DBOX_EVENT_GBAR_UPDATE_BEGIN); + } + } + } else { + ErrPrint("Invalid request[%s], %s\n", id, fbfile); + } out: - return NULL; + return NULL; } static struct packet *master_dbox_update_end(pid_t pid, int handle, const struct packet *packet) { - dynamicbox_h handler; - struct dynamicbox_common *common; - const char *pkgname; - const char *id; - int ret; - - ret = packet_get(packet, "ss", &pkgname, &id); - if (ret != 2) { - ErrPrint("Invalid argument\n"); - goto out; - } - - common = dbox_find_common_handle(pkgname, id); - if (!common) { - ErrPrint("Instance[%s] is not exists\n", id); - goto out; - } - - if (common->state != DBOX_STATE_CREATE) { - ErrPrint("[%s] is not created\n", id); - goto out; - } - - if (dbox_get_dbox_fb(common)) { - struct dlist *l; - dlist_foreach(common->dynamicbox_list, l, handler) { - dbox_invoke_event_handler(handler, DBOX_EVENT_DBOX_UPDATE_END); - } - } else { - ErrPrint("Invalid request[%s]\n", id); - } + dynamicbox_h handler; + struct dynamicbox_common *common; + const char *pkgname; + const char *id; + int ret; + + ret = packet_get(packet, "ss", &pkgname, &id); + if (ret != 2) { + ErrPrint("Invalid argument\n"); + goto out; + } + + common = dbox_find_common_handle(pkgname, id); + if (!common) { + ErrPrint("Instance[%s] is not exists\n", id); + goto out; + } + + if (common->state != DBOX_STATE_CREATE) { + ErrPrint("[%s] is not created\n", id); + goto out; + } + + if (dbox_get_dbox_fb(common)) { + struct dlist *l; + dlist_foreach(common->dynamicbox_list, l, handler) { + dbox_invoke_event_handler(handler, DBOX_EVENT_DBOX_UPDATE_END); + } + } else { + ErrPrint("Invalid request[%s]\n", id); + } out: - return NULL; + return NULL; } static struct packet *master_key_status(pid_t pid, int handle, const struct packet *packet) { - dynamicbox_h handler; - struct dynamicbox_common *common; - struct dlist *l; - const char *pkgname; - const char *id; - int ret; - int status; - - ret = packet_get(packet, "ssi", &pkgname, &id, &status); - if (ret != 3) { - ErrPrint("Invalid argument\n"); - goto out; - } - - common = dbox_find_common_handle(pkgname, id); - if (!common) { - ErrPrint("Instance[%s] is not exists\n", id); - goto out; - } - - if (common->state != DBOX_STATE_CREATE) { - ErrPrint("[%s] is not created\n", id); - goto out; - } - - common->request.key_event = 0; - dlist_foreach(common->dynamicbox_list, l, handler) { - if (handler->cbs.key_event.cb) { - dynamicbox_ret_cb cb; - void *cbdata; - - cb = handler->cbs.key_event.cb; - cbdata = handler->cbs.key_event.data; - - handler->cbs.key_event.cb = NULL; - handler->cbs.key_event.data = NULL; - - cb(handler, status, cbdata); - } else { - ErrPrint("Invalid event[%s]\n", id); - } - } + dynamicbox_h handler; + struct dynamicbox_common *common; + struct dlist *l; + const char *pkgname; + const char *id; + int ret; + int status; + + ret = packet_get(packet, "ssi", &pkgname, &id, &status); + if (ret != 3) { + ErrPrint("Invalid argument\n"); + goto out; + } + + common = dbox_find_common_handle(pkgname, id); + if (!common) { + ErrPrint("Instance[%s] is not exists\n", id); + goto out; + } + + if (common->state != DBOX_STATE_CREATE) { + ErrPrint("[%s] is not created\n", id); + goto out; + } + + common->request.key_event = 0; + dlist_foreach(common->dynamicbox_list, l, handler) { + if (handler->cbs.key_event.cb) { + dynamicbox_ret_cb cb; + void *cbdata; + + cb = handler->cbs.key_event.cb; + cbdata = handler->cbs.key_event.data; + + handler->cbs.key_event.cb = NULL; + handler->cbs.key_event.data = NULL; + + cb(handler, status, cbdata); + } else { + ErrPrint("Invalid event[%s]\n", id); + } + } out: - return NULL; + return NULL; } static struct packet *master_request_close_gbar(pid_t pid, int handle, const struct packet *packet) { - dynamicbox_h handler; - struct dynamicbox_common *common; - struct dlist *l; - const char *pkgname; - const char *id; - int ret; - int reason; - - ret = packet_get(packet, "ssi", &pkgname, &id, &reason); - if (ret != 3) { - ErrPrint("Invalid argument\n"); - goto out; - } - - common = dbox_find_common_handle(pkgname, id); - if (!common) { - ErrPrint("Instance[%s] is not exists\n", id); - goto out; - } - - if (common->state != DBOX_STATE_CREATE) { - ErrPrint("[%s] is not created\n", id); - goto out; - } - - if (!common->is_gbar_created) { - DbgPrint("GBAR is not created, closing what?(%s)\n", id); - goto out; - } - - DbgPrint("Reason: %d\n", reason); - - dlist_foreach(common->dynamicbox_list, l, handler) { - dbox_invoke_event_handler(handler, DBOX_EVENT_REQUEST_CLOSE_GBAR); - } + dynamicbox_h handler; + struct dynamicbox_common *common; + struct dlist *l; + const char *pkgname; + const char *id; + int ret; + int reason; + + ret = packet_get(packet, "ssi", &pkgname, &id, &reason); + if (ret != 3) { + ErrPrint("Invalid argument\n"); + goto out; + } + + common = dbox_find_common_handle(pkgname, id); + if (!common) { + ErrPrint("Instance[%s] is not exists\n", id); + goto out; + } + + if (common->state != DBOX_STATE_CREATE) { + ErrPrint("[%s] is not created\n", id); + goto out; + } + + if (!common->is_gbar_created) { + DbgPrint("GBAR is not created, closing what?(%s)\n", id); + goto out; + } + + DbgPrint("Reason: %d\n", reason); + + dlist_foreach(common->dynamicbox_list, l, handler) { + dbox_invoke_event_handler(handler, DBOX_EVENT_REQUEST_CLOSE_GBAR); + } out: - return NULL; + return NULL; } static struct packet *master_access_status(pid_t pid, int handle, const struct packet *packet) { - dynamicbox_h handler; - struct dynamicbox_common *common; - struct dlist *l; - const char *pkgname; - const char *id; - int ret; - int status; - - ret = packet_get(packet, "ssi", &pkgname, &id, &status); - if (ret != 3) { - ErrPrint("Invalid argument\n"); - goto out; - } - - common = dbox_find_common_handle(pkgname, id); - if (!common) { - ErrPrint("Instance[%s] is not exists\n", id); - goto out; - } - - if (common->state != DBOX_STATE_CREATE) { - ErrPrint("[%s] is not created\n", id); - goto out; - } - - common->request.access_event = 0; - dlist_foreach(common->dynamicbox_list, l, handler) { - if (handler->cbs.access_event.cb) { - dynamicbox_ret_cb cb; - void *cbdata; - - cb = handler->cbs.access_event.cb; - cbdata = handler->cbs.access_event.data; - - handler->cbs.access_event.cb = NULL; - handler->cbs.access_event.data = NULL; - - cb(handler, status, cbdata); - } - } + dynamicbox_h handler; + struct dynamicbox_common *common; + struct dlist *l; + const char *pkgname; + const char *id; + int ret; + int status; + + ret = packet_get(packet, "ssi", &pkgname, &id, &status); + if (ret != 3) { + ErrPrint("Invalid argument\n"); + goto out; + } + + common = dbox_find_common_handle(pkgname, id); + if (!common) { + ErrPrint("Instance[%s] is not exists\n", id); + goto out; + } + + if (common->state != DBOX_STATE_CREATE) { + ErrPrint("[%s] is not created\n", id); + goto out; + } + + common->request.access_event = 0; + dlist_foreach(common->dynamicbox_list, l, handler) { + if (handler->cbs.access_event.cb) { + dynamicbox_ret_cb cb; + void *cbdata; + + cb = handler->cbs.access_event.cb; + cbdata = handler->cbs.access_event.data; + + handler->cbs.access_event.cb = NULL; + handler->cbs.access_event.data = NULL; + + cb(handler, status, cbdata); + } + } out: - return NULL; + return NULL; } static struct packet *master_gbar_update_end(pid_t pid, int handle, const struct packet *packet) { - dynamicbox_h handler; - struct dynamicbox_common *common; - const char *pkgname; - const char *id; - int ret; - - ret = packet_get(packet, "ss", &pkgname, &id); - if (ret != 2) { - ErrPrint("Invalid argument\n"); - goto out; - } - - common = dbox_find_common_handle(pkgname, id); - if (!common) { - ErrPrint("Instance[%s] is not exists\n", id); - goto out; - } - - if (common->state != DBOX_STATE_CREATE) { - ErrPrint("[%s] is not created\n", id); - goto out; - } - - if (dbox_get_dbox_fb(common)) { - struct dlist *l; - - dlist_foreach(common->dynamicbox_list, l, handler) { - dbox_invoke_event_handler(handler, DBOX_EVENT_GBAR_UPDATE_END); - } - } else { - ErrPrint("Invalid request[%s]", id); - } + dynamicbox_h handler; + struct dynamicbox_common *common; + const char *pkgname; + const char *id; + int ret; + + ret = packet_get(packet, "ss", &pkgname, &id); + if (ret != 2) { + ErrPrint("Invalid argument\n"); + goto out; + } + + common = dbox_find_common_handle(pkgname, id); + if (!common) { + ErrPrint("Instance[%s] is not exists\n", id); + goto out; + } + + if (common->state != DBOX_STATE_CREATE) { + ErrPrint("[%s] is not created\n", id); + goto out; + } + + if (dbox_get_dbox_fb(common)) { + struct dlist *l; + + dlist_foreach(common->dynamicbox_list, l, handler) { + dbox_invoke_event_handler(handler, DBOX_EVENT_GBAR_UPDATE_END); + } + } else { + ErrPrint("Invalid request[%s]", id); + } out: - return NULL; + return NULL; } static struct packet *master_extra_info(pid_t pid, int handle, const struct packet *packet) { - const char *pkgname; - const char *id; - const char *content; - const char *title; - const char *icon; - const char *name; - double priority; - int ret; - dynamicbox_h handler; - struct dynamicbox_common *common; - struct dlist *l; - struct dlist *n; - - ret = packet_get(packet, "ssssssd", &pkgname, &id, - &content, &title, - &icon, &name, - &priority); - if (ret != 7) { - ErrPrint("Invalid parameters\n"); - goto out; - } - - common = dbox_find_common_handle(pkgname, id); - if (!common) { - ErrPrint("instance(%s) is not exists\n", id); - goto out; - } - - if (common->state != DBOX_STATE_CREATE) { - /*! - * \note - * Already deleted by the user. - * Don't try to notice anything with this, Just ignore all events - * Beacuse the user doesn't wants know about this anymore - */ - ErrPrint("(%s) is not exists, but updated\n", id); - goto out; - } - - dbox_set_priority(common, priority); - dbox_set_content(common, content); - dbox_set_title(common, title); - dbox_set_alt_icon(common, icon); - dbox_set_alt_name(common, name); - - dlist_foreach_safe(common->dynamicbox_list, l, n, handler) { - dbox_invoke_event_handler(handler, DBOX_EVENT_EXTRA_INFO_UPDATED); - } + const char *pkgname; + const char *id; + const char *content; + const char *title; + const char *icon; + const char *name; + double priority; + int ret; + dynamicbox_h handler; + struct dynamicbox_common *common; + struct dlist *l; + struct dlist *n; + + ret = packet_get(packet, "ssssssd", &pkgname, &id, + &content, &title, + &icon, &name, + &priority); + if (ret != 7) { + ErrPrint("Invalid parameters\n"); + goto out; + } + + common = dbox_find_common_handle(pkgname, id); + if (!common) { + ErrPrint("instance(%s) is not exists\n", id); + goto out; + } + + if (common->state != DBOX_STATE_CREATE) { + /*! + * \note + * Already deleted by the user. + * Don't try to notice anything with this, Just ignore all events + * Beacuse the user doesn't wants know about this anymore + */ + ErrPrint("(%s) is not exists, but updated\n", id); + goto out; + } + + dbox_set_priority(common, priority); + dbox_set_content(common, content); + dbox_set_title(common, title); + dbox_set_alt_icon(common, icon); + dbox_set_alt_name(common, name); + + dlist_foreach_safe(common->dynamicbox_list, l, n, handler) { + dbox_invoke_event_handler(handler, DBOX_EVENT_EXTRA_INFO_UPDATED); + } out: - return NULL; + return NULL; +} + +static struct packet *master_extra_updated(pid_t pid, int handle, const struct packet *packet) +{ + const char *pkgname; + const char *id; + dynamicbox_h handler; + struct dynamicbox_common *common; + int ret; + int x; + int y; + int w; + int h; + int is_gbar; + int event_type; + int idx; + + ret = packet_get(packet, "ssiiiiii", &pkgname, &id, &is_gbar, &idx, &x, &y, &w, &h); + if (ret != 8) { + ErrPrint("Invalid argument\n"); + goto out; + } + + common = dbox_find_common_handle(pkgname, id); + if (!common) { + ErrPrint("instance(%s) is not exists\n", id); + goto out; + } + + if (common->state != DBOX_STATE_CREATE) { + /*! + * \note + * Already deleted by the user. + * Don't try to notice anything with this, Just ignore all events + * Beacuse the user doesn't wants know about this anymore + */ + ErrPrint("(%s) is not exists, but updated\n", id); + goto out; + } + + if (common->request.created) { + DbgPrint("Creation is not done yet. waiting create event(%s)\n", id); + goto out; + } + + if (is_gbar) { + common->gbar.last_damage.x = x; + common->gbar.last_damage.y = y; + common->gbar.last_damage.w = w; + common->gbar.last_damage.h = h; + event_type = DBOX_EVENT_GBAR_EXTRA_UPDATED; + common->gbar.last_extra_buffer_idx = idx; + } else { + common->dbox.last_damage.x = x; + common->dbox.last_damage.y = y; + common->dbox.last_damage.w = w; + common->dbox.last_damage.h = h; + event_type = DBOX_EVENT_DBOX_EXTRA_UPDATED; + common->dbox.last_extra_buffer_idx = idx; + + if (conf_frame_drop_for_resizing() && common->request.size_changed) { + /* Just for skipping the update event callback call, After request to resize buffer, update event will be discarded */ + DbgPrint("Discards obsoloted update event\n"); + ret = DBOX_STATUS_ERROR_BUSY; + } else { + if (!conf_manual_sync()) { + ret = dbox_sync_dbox_fb(common); + if (ret != (int)DBOX_STATUS_ERROR_NONE) { + ErrPrint("Failed to do sync FB (%s - %s) (%d)\n", pkgname, util_basename(util_uri_to_path(id)), ret); + } + } else { + ret = DBOX_STATUS_ERROR_NONE; + } + } + } + + if (ret == (int)DBOX_STATUS_ERROR_NONE) { + struct dlist *l; + struct dlist *n; + + dlist_foreach_safe(common->dynamicbox_list, l, n, handler) { + dbox_invoke_event_handler(handler, event_type); + } + } + +out: + return NULL; } static struct packet *master_dbox_updated(pid_t pid, int handle, const struct packet *packet) { - const char *pkgname; - const char *id; - const char *fbfile; - const char *safe_file; - dynamicbox_h handler; - struct dynamicbox_common *common; - int ret; - int x; - int y; - int w; - int h; - - DbgPrint("Updated: %X (%d)\n", *((unsigned int *)packet_command(packet)), pid); - - ret = packet_get(packet, "ssssiiii", &pkgname, &id, &fbfile, &safe_file, &x, &y, &w, &h); - if (ret != 8) { - ErrPrint("Invalid argument\n"); - goto out; - } - - common = dbox_find_common_handle(pkgname, id); - if (!common) { - ErrPrint("instance(%s) is not exists\n", id); - goto out; - } - - common->dbox.last_damage.x = x; - common->dbox.last_damage.y = y; - common->dbox.last_damage.w = w; - common->dbox.last_damage.h = h; - - if (common->state != DBOX_STATE_CREATE) { - /*! - * \note - * Already deleted by the user. - * Don't try to notice anything with this, Just ignore all events - * Beacuse the user doesn't wants know about this anymore - */ - ErrPrint("(%s) is not exists, but updated\n", id); - goto out; - } - - dbox_set_filename(common, safe_file); - - if (dbox_text_dbox(common)) { - const char *common_filename; - - common_filename = common->filename ? common->filename : util_uri_to_path(common->id); - - (void)parse_desc(common, common_filename, 0); - /*! - * \note - * DESC parser will call the "text event callback". - * Don't need to call global event callback in this case. - */ - goto out; - } else if (dbox_get_dbox_fb(common)) { - /*! - * \todo - * replace this with "flag" instead of "callback address" - */ - if (conf_frame_drop_for_resizing() && common->request.size_changed) { - /* Just for skipping the update event callback call, After request to resize buffer, update event will be discarded */ - DbgPrint("Discards obsoloted update event\n"); - ret = DBOX_STATUS_ERROR_BUSY; - } else { - (void)dbox_set_dbox_fb(common, fbfile); - - if (!conf_manual_sync()) { - ret = dbox_sync_dbox_fb(common); - if (ret != (int)DBOX_STATUS_ERROR_NONE) { - ErrPrint("Failed to do sync FB (%s - %s) (%d)\n", pkgname, util_basename(util_uri_to_path(id)), ret); - } - } else { - ret = DBOX_STATUS_ERROR_NONE; - } - } - } else { - ret = DBOX_STATUS_ERROR_NONE; - } - - if (ret == (int)DBOX_STATUS_ERROR_NONE) { - struct dlist *l; - struct dlist *n; - - dlist_foreach_safe(common->dynamicbox_list, l, n, handler) { - dbox_invoke_event_handler(handler, DBOX_EVENT_DBOX_UPDATED); - } - } + const char *pkgname; + const char *id; + const char *fbfile; + const char *safe_file; + dynamicbox_h handler; + struct dynamicbox_common *common; + int ret; + int x; + int y; + int w; + int h; + + ret = packet_get(packet, "ssssiiii", &pkgname, &id, &fbfile, &safe_file, &x, &y, &w, &h); + if (ret != 8) { + ErrPrint("Invalid argument\n"); + goto out; + } + + common = dbox_find_common_handle(pkgname, id); + if (!common) { + ErrPrint("instance(%s) is not exists\n", id); + goto out; + } + + if (common->state != DBOX_STATE_CREATE) { + /*! + * \note + * Already deleted by the user. + * Don't try to notice anything with this, Just ignore all events + * Beacuse the user doesn't wants know about this anymore + */ + ErrPrint("(%s) is not exists, but updated\n", id); + goto out; + } + + if (common->request.created) { + DbgPrint("Creation is not done yet. waiting create event(%s)\n", id); + goto out; + } + + common->dbox.last_damage.x = x; + common->dbox.last_damage.y = y; + common->dbox.last_damage.w = w; + common->dbox.last_damage.h = h; + + dbox_set_filename(common, safe_file); + + if (dbox_text_dbox(common)) { + const char *common_filename; + + common_filename = common->filename ? common->filename : util_uri_to_path(common->id); + + (void)parse_desc(common, common_filename, 0); + /*! + * \note + * DESC parser will call the "text event callback". + * Don't need to call global event callback in this case. + */ + goto out; + } else if (dbox_get_dbox_fb(common)) { + /*! + * \todo + * replace this with "flag" instead of "callback address" + */ + if (conf_frame_drop_for_resizing() && common->request.size_changed) { + /* Just for skipping the update event callback call, After request to resize buffer, update event will be discarded */ + DbgPrint("Discards obsoloted update event\n"); + ret = DBOX_STATUS_ERROR_BUSY; + } else { + (void)dbox_set_dbox_fb(common, fbfile); + + if (!conf_manual_sync()) { + ret = dbox_sync_dbox_fb(common); + if (ret != (int)DBOX_STATUS_ERROR_NONE) { + ErrPrint("Failed to do sync FB (%s - %s) (%d)\n", pkgname, util_basename(util_uri_to_path(id)), ret); + } + } else { + ret = DBOX_STATUS_ERROR_NONE; + } + } + } else { + ret = DBOX_STATUS_ERROR_NONE; + } + + if (ret == (int)DBOX_STATUS_ERROR_NONE) { + struct dlist *l; + struct dlist *n; + + dlist_foreach_safe(common->dynamicbox_list, l, n, handler) { + dbox_invoke_event_handler(handler, DBOX_EVENT_DBOX_UPDATED); + } + } out: - return NULL; + return NULL; } static struct packet *master_gbar_created(pid_t pid, int handle, const struct packet *packet) { - dynamicbox_h handler; - struct dynamicbox_common *common; - const char *pkgname; - const char *id; - const char *buf_id; - struct dlist *l; - struct dlist *n; - int width; - int height; - int ret; - int status; - - ret = packet_get(packet, "sssiii", &pkgname, &id, &buf_id, &width, &height, &status); - if (ret != 6) { - ErrPrint("Invalid argument\n"); - goto out; - } - - DbgPrint("[%s]\n", pkgname); - common = dbox_find_common_handle(pkgname, id); - if (!common) { - ErrPrint("Instance(%s) is not exists\n", id); - goto out; - } - - if (common->state != DBOX_STATE_CREATE) { - ErrPrint("Instance(%s) is not created\n", id); - goto out; - } - - if (!common->request.gbar_created) { - ErrPrint("GBAR create request is canceled\n"); - goto out; - } - - common->is_gbar_created = (status == (int)DBOX_STATUS_ERROR_NONE); - common->request.gbar_created = 0; - - if (common->is_gbar_created) { - dbox_set_gbarsize(common, width, height); - if (dbox_text_gbar(common)) { - DbgPrint("Text TYPE does not need to handle this\n"); - } else { - (void)dbox_set_gbar_fb(common, buf_id); - - switch (common->gbar.type) { - case GBAR_TYPE_SCRIPT: - case GBAR_TYPE_BUFFER: - switch (fb_type(dbox_get_gbar_fb(common))) { - case DBOX_FB_TYPE_FILE: - case DBOX_FB_TYPE_SHM: - dbox_create_lock_file(common, 1); - break; - case DBOX_FB_TYPE_PIXMAP: - case DBOX_FB_TYPE_ERROR: - default: - break; - } - break; - case GBAR_TYPE_UIFW: - case GBAR_TYPE_TEXT: - default: - break; - } - - ret = dbox_sync_gbar_fb(common); - if (ret < 0) { - ErrPrint("Failed to do sync FB (%s - %s)\n", pkgname, util_basename(util_uri_to_path(id))); - } - } - } - - DbgPrint("PERF_DBOX\n"); - dlist_foreach_safe(common->dynamicbox_list, l, n, handler) { - if (handler->cbs.gbar_created.cb) { - dynamicbox_ret_cb cb; - void *cbdata; - - cb = handler->cbs.gbar_created.cb; - cbdata = handler->cbs.gbar_created.data; - - handler->cbs.gbar_created.cb = NULL; - handler->cbs.gbar_created.data = NULL; - - /*! - * Before call the Callback function, - * gbar_create_cb must be reset. - * Because, in the create callback, user can call create_gbar function again. - */ - cb(handler, status, cbdata); - } else if (status == (int)DBOX_STATUS_ERROR_NONE) { - dbox_invoke_event_handler(handler, DBOX_EVENT_GBAR_CREATED); - } - } + dynamicbox_h handler; + struct dynamicbox_common *common; + const char *pkgname; + const char *id; + const char *buf_id; + struct dlist *l; + struct dlist *n; + int width; + int height; + int ret; + int status; + + ret = packet_get(packet, "sssiii", &pkgname, &id, &buf_id, &width, &height, &status); + if (ret != 6) { + ErrPrint("Invalid argument\n"); + goto out; + } + + DbgPrint("[%s]\n", pkgname); + common = dbox_find_common_handle(pkgname, id); + if (!common) { + ErrPrint("Instance(%s) is not exists\n", id); + goto out; + } + + if (common->state != DBOX_STATE_CREATE) { + ErrPrint("Instance(%s) is not created\n", id); + goto out; + } + + if (!common->request.gbar_created) { + ErrPrint("GBAR create request is canceled\n"); + goto out; + } + + common->is_gbar_created = (status == (int)DBOX_STATUS_ERROR_NONE); + common->request.gbar_created = 0; + + if (common->is_gbar_created) { + dbox_set_gbarsize(common, width, height); + if (dbox_text_gbar(common)) { + DbgPrint("Text TYPE does not need to handle this\n"); + } else { + (void)dbox_set_gbar_fb(common, buf_id); + + switch (common->gbar.type) { + case GBAR_TYPE_SCRIPT: + case GBAR_TYPE_BUFFER: + switch (fb_type(dbox_get_gbar_fb(common))) { + case DBOX_FB_TYPE_FILE: + case DBOX_FB_TYPE_SHM: + common->gbar.lock = dynamicbox_service_create_lock(common->id, DBOX_TYPE_GBAR, DBOX_LOCK_READ); + break; + case DBOX_FB_TYPE_PIXMAP: + case DBOX_FB_TYPE_ERROR: + default: + break; + } + break; + case GBAR_TYPE_UIFW: + case GBAR_TYPE_TEXT: + default: + break; + } + + ret = dbox_sync_gbar_fb(common); + if (ret < 0) { + ErrPrint("Failed to do sync FB (%s - %s)\n", pkgname, util_basename(util_uri_to_path(id))); + } + } + } + + DbgPrint("PERF_DBOX\n"); + dlist_foreach_safe(common->dynamicbox_list, l, n, handler) { + if (handler->cbs.gbar_created.cb) { + dynamicbox_ret_cb cb; + void *cbdata; + + cb = handler->cbs.gbar_created.cb; + cbdata = handler->cbs.gbar_created.data; + + handler->cbs.gbar_created.cb = NULL; + handler->cbs.gbar_created.data = NULL; + + /*! + * Before call the Callback function, + * gbar_create_cb must be reset. + * Because, in the create callback, user can call create_gbar function again. + */ + cb(handler, status, cbdata); + } else if (status == (int)DBOX_STATUS_ERROR_NONE) { + dbox_invoke_event_handler(handler, DBOX_EVENT_GBAR_CREATED); + } + } out: - return NULL; + return NULL; } static struct packet *master_gbar_destroyed(pid_t pid, int handle, const struct packet *packet) { - dynamicbox_h handler; - struct dlist *l; - struct dynamicbox_common *common; - const char *pkgname; - const char *id; - int ret; - int status; - - ret = packet_get(packet, "ssi", &pkgname, &id, &status); - if (ret != 3) { - ErrPrint("Invalid argument\n"); - goto out; - } - - DbgPrint("[%s]\n", pkgname); - common = dbox_find_common_handle(pkgname, id); - if (!common) { - ErrPrint("Instance(%s) is not exists\n", id); - goto out; - } - - if (common->state != DBOX_STATE_CREATE) { - ErrPrint("Instance(%s) is not created\n", id); - goto out; - } - - if (common->is_gbar_created == 0) { - ErrPrint("GBAR is not created, event is ignored\n"); - goto out; - } - - common->is_gbar_created = 0; - common->request.gbar_destroyed = 0; - - dlist_foreach(common->dynamicbox_list, l, handler) { - if (handler->cbs.gbar_destroyed.cb) { - dynamicbox_ret_cb cb; - void *cbdata; - - cb = handler->cbs.gbar_destroyed.cb; - cbdata = handler->cbs.gbar_destroyed.data; - - handler->cbs.gbar_destroyed.cb = NULL; - handler->cbs.gbar_destroyed.data = NULL; - - /*! - * Before call the Callback function, - * gbar_destroyed_cb must be reset. - * Because, in the create callback, user can call destroy_gbar function again. - */ - cb(handler, status, cbdata); - } else if (status == (int)DBOX_STATUS_ERROR_NONE) { - dbox_invoke_event_handler(handler, DBOX_EVENT_GBAR_DESTROYED); - } - } - - /*! - * \note - * Lock file should be deleted after all callbacks are processed. - */ - switch (common->gbar.type) { - case GBAR_TYPE_SCRIPT: - case GBAR_TYPE_BUFFER: - switch (fb_type(dbox_get_gbar_fb(common))) { - case DBOX_FB_TYPE_FILE: - case DBOX_FB_TYPE_SHM: - dbox_destroy_lock_file(common, 1); - break; - case DBOX_FB_TYPE_PIXMAP: - case DBOX_FB_TYPE_ERROR: - default: - break; - } - break; - case GBAR_TYPE_UIFW: - case GBAR_TYPE_TEXT: - default: - break; - } + dynamicbox_h handler; + struct dlist *l; + struct dynamicbox_common *common; + const char *pkgname; + const char *id; + int ret; + int status; + + ret = packet_get(packet, "ssi", &pkgname, &id, &status); + if (ret != 3) { + ErrPrint("Invalid argument\n"); + goto out; + } + + DbgPrint("[%s]\n", pkgname); + common = dbox_find_common_handle(pkgname, id); + if (!common) { + ErrPrint("Instance(%s) is not exists\n", id); + goto out; + } + + if (common->state != DBOX_STATE_CREATE) { + ErrPrint("Instance(%s) is not created\n", id); + goto out; + } + + if (common->is_gbar_created == 0) { + ErrPrint("GBAR is not created, event is ignored\n"); + goto out; + } + + common->is_gbar_created = 0; + common->request.gbar_destroyed = 0; + + dlist_foreach(common->dynamicbox_list, l, handler) { + if (handler->cbs.gbar_destroyed.cb) { + dynamicbox_ret_cb cb; + void *cbdata; + + cb = handler->cbs.gbar_destroyed.cb; + cbdata = handler->cbs.gbar_destroyed.data; + + handler->cbs.gbar_destroyed.cb = NULL; + handler->cbs.gbar_destroyed.data = NULL; + + /*! + * Before call the Callback function, + * gbar_destroyed_cb must be reset. + * Because, in the create callback, user can call destroy_gbar function again. + */ + cb(handler, status, cbdata); + } else if (status == (int)DBOX_STATUS_ERROR_NONE) { + dbox_invoke_event_handler(handler, DBOX_EVENT_GBAR_DESTROYED); + } + } + + /*! + * \note + * Lock file should be deleted after all callbacks are processed. + */ + switch (common->gbar.type) { + case GBAR_TYPE_SCRIPT: + case GBAR_TYPE_BUFFER: + switch (fb_type(dbox_get_gbar_fb(common))) { + case DBOX_FB_TYPE_FILE: + case DBOX_FB_TYPE_SHM: + dynamicbox_service_destroy_lock(common->gbar.lock); + common->gbar.lock = NULL; + break; + case DBOX_FB_TYPE_PIXMAP: + case DBOX_FB_TYPE_ERROR: + default: + break; + } + break; + case GBAR_TYPE_UIFW: + case GBAR_TYPE_TEXT: + default: + break; + } out: - return NULL; + return NULL; } static struct packet *master_gbar_updated(pid_t pid, int handle, const struct packet *packet) { - const char *pkgname; - const char *id; - const char *descfile; - const char *fbfile; - int ret; - dynamicbox_h handler; - struct dynamicbox_common *common; - struct dlist *l; - int x; - int y; - int w; - int h; - - ret = packet_get(packet, "ssssiiii", - &pkgname, &id, - &descfile, &fbfile, - &x, &y, - &w, &h); - if (ret != 8) { - ErrPrint("Invalid argument\n"); - goto out; - } - - common = dbox_find_common_handle(pkgname, id); - if (!common) { - ErrPrint("Instance(%s) is not exists\n", id); - goto out; - } - - common->gbar.last_damage.x = x; - common->gbar.last_damage.y = y; - common->gbar.last_damage.w = w; - common->gbar.last_damage.h = h; - - if (common->state != DBOX_STATE_CREATE) { - /*! - * \note - * This handler is already deleted by the user. - * So don't try to notice anything about this anymore. - * Just ignore all events. - */ - ErrPrint("Instance(%s) is not created\n", id); - goto out; - } - - if (dbox_text_gbar(common)) { - (void)parse_desc(common, descfile, 1); - } else { - if (conf_frame_drop_for_resizing() && common->request.size_changed) { - /* Just for skipping the update event callback call, After request to resize buffer, update event will be discarded */ - DbgPrint("Discards obsoloted update event\n"); - } else { - (void)dbox_set_gbar_fb(common, fbfile); - - if (!conf_manual_sync()) { - ret = dbox_sync_gbar_fb(common); - if (ret < 0) { - ErrPrint("Failed to do sync FB (%s - %s), %d\n", pkgname, util_basename(util_uri_to_path(id)), ret); - } else { - dlist_foreach(common->dynamicbox_list, l, handler) { - dbox_invoke_event_handler(handler, DBOX_EVENT_GBAR_UPDATED); - } - } - } else { - dlist_foreach(common->dynamicbox_list, l, handler) { - dbox_invoke_event_handler(handler, DBOX_EVENT_GBAR_UPDATED); - } - } - } - } + const char *pkgname; + const char *id; + const char *descfile; + const char *fbfile; + int ret; + dynamicbox_h handler; + struct dynamicbox_common *common; + struct dlist *l; + int x; + int y; + int w; + int h; + + ret = packet_get(packet, "ssssiiii", &pkgname, &id, &fbfile, &descfile, &x, &y, &w, &h); + if (ret != 8) { + ErrPrint("Invalid argument\n"); + goto out; + } + + common = dbox_find_common_handle(pkgname, id); + if (!common) { + ErrPrint("Instance(%s) is not exists\n", id); + goto out; + } + + common->gbar.last_damage.x = x; + common->gbar.last_damage.y = y; + common->gbar.last_damage.w = w; + common->gbar.last_damage.h = h; + + if (common->state != DBOX_STATE_CREATE) { + /*! + * \note + * This handler is already deleted by the user. + * So don't try to notice anything about this anymore. + * Just ignore all events. + */ + ErrPrint("Instance(%s) is not created\n", id); + goto out; + } + + if (dbox_text_gbar(common)) { + (void)parse_desc(common, descfile, 1); + } else { + if (conf_frame_drop_for_resizing() && common->request.size_changed) { + /* Just for skipping the update event callback call, After request to resize buffer, update event will be discarded */ + DbgPrint("Discards obsoloted update event\n"); + } else { + (void)dbox_set_gbar_fb(common, fbfile); + + if (!conf_manual_sync()) { + ret = dbox_sync_gbar_fb(common); + if (ret < 0) { + ErrPrint("Failed to do sync FB (%s - %s), %d\n", pkgname, util_basename(util_uri_to_path(id)), ret); + } else { + dlist_foreach(common->dynamicbox_list, l, handler) { + dbox_invoke_event_handler(handler, DBOX_EVENT_GBAR_UPDATED); + } + } + } else { + dlist_foreach(common->dynamicbox_list, l, handler) { + dbox_invoke_event_handler(handler, DBOX_EVENT_GBAR_UPDATED); + } + } + } + } + +out: + return NULL; +} + +static struct packet *master_gbar_extra_buffer_destroyed(pid_t pid, int handle, const struct packet *packet) +{ + dynamicbox_h handler; + struct dynamicbox_common *common; + const char *pkgname; + struct dlist *l; + struct dlist *n; + const char *id; + int pixmap; + int idx; + int ret; + + if (!packet) { + ErrPrint("Invalid packet\n"); + goto out; + } + + ret = packet_get(packet, "ssii", &pkgname, &id, &pixmap, &idx); + if (ret != 4) { + ErrPrint("Invalid argument\n"); + goto out; + } + + if (idx < 0 || idx >= conf_extra_buffer_count()) { + ErrPrint("Extra buffer count is not matched\n"); + goto out; + } + + common = dbox_find_common_handle(pkgname, id); + if (!common) { + ErrPrint("DBOX(%s) is not found\n", id); + goto out; + } + + if (common->state != DBOX_STATE_CREATE) { + ErrPrint("DBOX(%s) is not created yet\n", id); + goto out; + } + + if (!common->gbar.extra_buffer && conf_extra_buffer_count()) { + common->gbar.extra_buffer = calloc(conf_extra_buffer_count(), sizeof(*common->gbar.extra_buffer)); + if (!common->gbar.extra_buffer) { + ErrPrint("DBOX(%s) calloc: %s\n", id, strerror(errno)); + } + } + + common->gbar.last_extra_buffer_idx = idx; + if (common->gbar.extra_buffer[idx] != pixmap) { + DbgPrint("Extra buffer Pixmap is not matched %u <> %u\n", common->dbox.extra_buffer[idx], pixmap); + } + + dlist_foreach_safe(common->dynamicbox_list, l, n, handler) { + dbox_invoke_event_handler(handler, DBOX_EVENT_GBAR_EXTRA_BUFFER_DESTROYED); + } +out: + return NULL; +} + +static struct packet *master_dbox_extra_buffer_destroyed(pid_t pid, int handle, const struct packet *packet) +{ + dynamicbox_h handler; + struct dynamicbox_common *common; + const char *pkgname; + struct dlist *l; + struct dlist *n; + const char *id; + int idx; + int pixmap; + int ret; + + if (!packet) { + ErrPrint("Invalid packet\n"); + goto out; + } + + ret = packet_get(packet, "ssii", &pkgname, &id, &pixmap, &idx); + if (ret != 4) { + ErrPrint("Invalid argument\n"); + goto out; + } + + if (idx < 0 || idx >= conf_extra_buffer_count()) { + ErrPrint("Extra buffer count is not matched\n"); + goto out; + } + + common = dbox_find_common_handle(pkgname, id); + if (!common) { + ErrPrint("DBOX(%s) is not found\n", id); + goto out; + } + + if (common->state != DBOX_STATE_CREATE) { + ErrPrint("DBOX(%s) is not created yet\n", id); + goto out; + } + + if (!common->dbox.extra_buffer && conf_extra_buffer_count()) { + common->dbox.extra_buffer = calloc(conf_extra_buffer_count(), sizeof(*common->dbox.extra_buffer)); + if (!common->dbox.extra_buffer) { + ErrPrint("DBOX(%s) calloc: %s\n", id, strerror(errno)); + } + } + + common->dbox.last_extra_buffer_idx = idx; + if (common->dbox.extra_buffer[idx] != pixmap) { + DbgPrint("Extra buffer Pixmap is not matched %u <> %u\n", common->dbox.extra_buffer[idx], pixmap); + } + + dlist_foreach_safe(common->dynamicbox_list, l, n, handler) { + dbox_invoke_event_handler(handler, DBOX_EVENT_DBOX_EXTRA_BUFFER_DESTROYED); + } +out: + return NULL; +} + +static struct packet *master_dbox_extra_buffer_created(pid_t pid, int handle, const struct packet *packet) +{ + dynamicbox_h handler; + struct dynamicbox_common *common; + const char *pkgname; + struct dlist *l; + struct dlist *n; + const char *id; + int idx; + int pixmap; + int ret; + + if (!packet) { + ErrPrint("Invalid packet\n"); + goto out; + } + + ret = packet_get(packet, "ssii", &pkgname, &id, &pixmap, &idx); + if (ret != 4) { + ErrPrint("Invalid argument\n"); + goto out; + } + + if (idx < 0 || idx >= conf_extra_buffer_count()) { + ErrPrint("Extra buffer count is not matched\n"); + goto out; + } + + common = dbox_find_common_handle(pkgname, id); + if (!common) { + ErrPrint("DBOX(%s) is not found\n", id); + goto out; + } + + if (common->state != DBOX_STATE_CREATE) { + ErrPrint("DBOX(%s) is not created yet\n", id); + goto out; + } + + if (!common->dbox.extra_buffer && conf_extra_buffer_count()) { + common->dbox.extra_buffer = calloc(conf_extra_buffer_count(), sizeof(*common->dbox.extra_buffer)); + if (!common->dbox.extra_buffer) { + ErrPrint("DBOX(%s) calloc: %s\n", id, strerror(errno)); + } + } + + common->dbox.last_extra_buffer_idx = idx; + common->dbox.extra_buffer[idx] = pixmap; + + dlist_foreach_safe(common->dynamicbox_list, l, n, handler) { + dbox_invoke_event_handler(handler, DBOX_EVENT_DBOX_EXTRA_BUFFER_CREATED); + } +out: + return NULL; +} +static struct packet *master_gbar_extra_buffer_created(pid_t pid, int handle, const struct packet *packet) +{ + dynamicbox_h handler; + struct dynamicbox_common *common; + const char *pkgname; + struct dlist *l; + struct dlist *n; + const char *id; + int pixmap; + int idx; + int ret; + + if (!packet) { + ErrPrint("Invalid packet\n"); + goto out; + } + + ret = packet_get(packet, "ssii", &pkgname, &id, &pixmap, &idx); + if (ret != 4) { + ErrPrint("Invalid argument\n"); + goto out; + } + + if (idx < 0 || idx >= conf_extra_buffer_count()) { + ErrPrint("Extra buffer count is not matched\n"); + goto out; + } + + common = dbox_find_common_handle(pkgname, id); + if (!common) { + ErrPrint("DBOX(%s) is not found\n", id); + goto out; + } + + if (common->state != DBOX_STATE_CREATE) { + ErrPrint("DBOX(%s) is not created yet\n", id); + goto out; + } + + if (!common->gbar.extra_buffer && conf_extra_buffer_count()) { + common->gbar.extra_buffer = calloc(conf_extra_buffer_count(), sizeof(*common->gbar.extra_buffer)); + if (!common->gbar.extra_buffer) { + ErrPrint("DBOX(%s) calloc: %s\n", id, strerror(errno)); + } + } + + common->gbar.last_extra_buffer_idx = idx; + common->gbar.extra_buffer[idx] = pixmap; + + dlist_foreach_safe(common->dynamicbox_list, l, n, handler) { + dbox_invoke_event_handler(handler, DBOX_EVENT_GBAR_EXTRA_BUFFER_CREATED); + } out: - return NULL; + return NULL; } static struct packet *master_update_mode(pid_t pid, int handle, const struct packet *packet) { - dynamicbox_h handler; - struct dynamicbox_common *common; - struct dlist *l; - struct dlist *n; - const char *pkgname; - const char *id; - int active_mode; - int status; - int ret; - - if (!packet) { - ErrPrint("Invalid packet\n"); - goto out; - } - - ret = packet_get(packet, "ssii", &pkgname, &id, &status, &active_mode); - if (ret != 4) { - ErrPrint("Invalid argument\n"); - goto out; - } - - common = dbox_find_common_handle(pkgname, id); - if (!common) { - ErrPrint("Livebox(%s) is not found\n", id); - goto out; - } - - if (common->state != DBOX_STATE_CREATE) { - ErrPrint("Livebox(%s) is not created yet\n", id); - goto out; - } - - if (status == (int)DBOX_STATUS_ERROR_NONE) { - dbox_set_update_mode(common, active_mode); - } - - common->request.update_mode = 0; - dlist_foreach_safe(common->dynamicbox_list, l, n, handler) { - if (handler->cbs.update_mode.cb) { - dynamicbox_ret_cb cb; - void *cbdata; - - cb = handler->cbs.update_mode.cb; - cbdata = handler->cbs.update_mode.data; - - handler->cbs.update_mode.cb = NULL; - handler->cbs.update_mode.data = NULL; - - cb(handler, status, cbdata); - } else if (status == (int)DBOX_STATUS_ERROR_NONE) { - dbox_invoke_event_handler(handler, DBOX_EVENT_UPDATE_MODE_CHANGED); - } - } + dynamicbox_h handler; + struct dynamicbox_common *common; + struct dlist *l; + struct dlist *n; + const char *pkgname; + const char *id; + int active_mode; + int status; + int ret; + + if (!packet) { + ErrPrint("Invalid packet\n"); + goto out; + } + + ret = packet_get(packet, "ssii", &pkgname, &id, &status, &active_mode); + if (ret != 4) { + ErrPrint("Invalid argument\n"); + goto out; + } + + common = dbox_find_common_handle(pkgname, id); + if (!common) { + ErrPrint("DBOX(%s) is not found\n", id); + goto out; + } + + if (common->state != DBOX_STATE_CREATE) { + ErrPrint("DBOX(%s) is not created yet\n", id); + goto out; + } + + if (status == (int)DBOX_STATUS_ERROR_NONE) { + dbox_set_update_mode(common, active_mode); + } + + common->request.update_mode = 0; + dlist_foreach_safe(common->dynamicbox_list, l, n, handler) { + if (handler->cbs.update_mode.cb) { + dynamicbox_ret_cb cb; + void *cbdata; + + cb = handler->cbs.update_mode.cb; + cbdata = handler->cbs.update_mode.data; + + handler->cbs.update_mode.cb = NULL; + handler->cbs.update_mode.data = NULL; + + cb(handler, status, cbdata); + } else if (status == (int)DBOX_STATUS_ERROR_NONE) { + dbox_invoke_event_handler(handler, DBOX_EVENT_UPDATE_MODE_CHANGED); + } + } out: - return NULL; + return NULL; } static struct packet *master_size_changed(pid_t pid, int handle, const struct packet *packet) { - dynamicbox_h handler; - struct dynamicbox_common *common; - const char *pkgname; - const char *id; - const char *fbfile; - int status; - int ret; - int w; - int h; - int is_gbar; - - if (!packet) { - ErrPrint("Invalid packet\n"); - goto out; - } - - ret = packet_get(packet, "sssiiii", &pkgname, &id, &fbfile, &is_gbar, &w, &h, &status); - if (ret != 7) { - ErrPrint("Invalid argument\n"); - goto out; - } - - common = dbox_find_common_handle(pkgname, id); - if (!common) { - ErrPrint("Livebox(%s) is not found\n", id); - goto out; - } - - if (common->state != DBOX_STATE_CREATE) { - ErrPrint("Livebox(%s) is not created yet\n", id); - goto out; - } - - common->request.size_changed = 0; - if (is_gbar) { - /*! - * \NOTE - * GBAR is not able to resized by the client. - * GBAR is only can be managed by the provider. - * So the GBAR has no private resized event handler. - * Notify it via global event handler only. - */ - if (status == (int)DBOX_STATUS_ERROR_NONE) { - struct dlist *l; - - dbox_set_gbarsize(common, w, h); - dlist_foreach(common->dynamicbox_list, l, handler) { - dbox_invoke_event_handler(handler, DBOX_EVENT_GBAR_SIZE_CHANGED); - } - } else { - ErrPrint("This is not possible. GBAR Size is changed but the return value is not ZERO (%d)\n", status); - } - } else { - struct dlist *l; - struct dlist *n; - - if (status == (int)DBOX_STATUS_ERROR_NONE) { - dbox_set_size(common, w, h); - - /*! - * \NOTE - * If there is a created DBOX FB, - * Update it too. - */ - if (dbox_get_dbox_fb(common)) { - (void)dbox_set_dbox_fb(common, fbfile); - - ret = dbox_sync_dbox_fb(common); - if (ret < 0) { - ErrPrint("Failed to do sync FB (%s - %s)\n", pkgname, util_basename(util_uri_to_path(id))); - } - - /* Just update the size info only. */ - } - } - - /*! - * \NOTE - * I cannot believe client. - * So I added some log before & after call the user callback. - */ - dlist_foreach_safe(common->dynamicbox_list, l, n, handler) { - if (handler->cbs.size_changed.cb) { - dynamicbox_ret_cb cb; - void *cbdata; - - cb = handler->cbs.size_changed.cb; - cbdata = handler->cbs.size_changed.data; - - handler->cbs.size_changed.cb = NULL; - handler->cbs.size_changed.data = NULL; - - cb(handler, status, cbdata); - } else if (status == (int)DBOX_STATUS_ERROR_NONE) { - dbox_invoke_event_handler(handler, DBOX_EVENT_DBOX_SIZE_CHANGED); - } - } - } + dynamicbox_h handler; + struct dynamicbox_common *common; + const char *pkgname; + const char *id; + const char *fbfile; + int status; + int ret; + int w; + int h; + int is_gbar; + + if (!packet) { + ErrPrint("Invalid packet\n"); + goto out; + } + + ret = packet_get(packet, "sssiiii", &pkgname, &id, &fbfile, &is_gbar, &w, &h, &status); + if (ret != 7) { + ErrPrint("Invalid argument\n"); + goto out; + } + + common = dbox_find_common_handle(pkgname, id); + if (!common) { + ErrPrint("DBOX(%s) is not found\n", id); + goto out; + } + + if (common->state != DBOX_STATE_CREATE) { + ErrPrint("DBOX(%s) is not created yet\n", id); + goto out; + } + + common->request.size_changed = 0; + if (is_gbar) { + /*! + * \NOTE + * GBAR is not able to resized by the client. + * GBAR is only can be managed by the provider. + * So the GBAR has no private resized event handler. + * Notify it via global event handler only. + */ + if (status == (int)DBOX_STATUS_ERROR_NONE) { + struct dlist *l; + + dbox_set_gbarsize(common, w, h); + dlist_foreach(common->dynamicbox_list, l, handler) { + dbox_invoke_event_handler(handler, DBOX_EVENT_GBAR_SIZE_CHANGED); + } + } else { + ErrPrint("This is not possible. GBAR Size is changed but the return value is not ZERO (%d)\n", status); + } + } else { + struct dlist *l; + struct dlist *n; + + if (status == (int)DBOX_STATUS_ERROR_NONE) { + dbox_set_size(common, w, h); + + /*! + * \NOTE + * If there is a created DBOX FB, + * Update it too. + */ + if (dbox_get_dbox_fb(common)) { + (void)dbox_set_dbox_fb(common, fbfile); + + ret = dbox_sync_dbox_fb(common); + if (ret < 0) { + ErrPrint("Failed to do sync FB (%s - %s)\n", pkgname, util_basename(util_uri_to_path(id))); + } + + /* Just update the size info only. */ + } + } + + /*! + * \NOTE + * I cannot believe client. + * So I added some log before & after call the user callback. + */ + dlist_foreach_safe(common->dynamicbox_list, l, n, handler) { + if (handler->cbs.size_changed.cb) { + dynamicbox_ret_cb cb; + void *cbdata; + + cb = handler->cbs.size_changed.cb; + cbdata = handler->cbs.size_changed.data; + + handler->cbs.size_changed.cb = NULL; + handler->cbs.size_changed.data = NULL; + + cb(handler, status, cbdata); + } else if (status == (int)DBOX_STATUS_ERROR_NONE) { + dbox_invoke_event_handler(handler, DBOX_EVENT_DBOX_SIZE_CHANGED); + } + } + } out: - return NULL; + return NULL; } static struct packet *master_period_changed(pid_t pid, int handle, const struct packet *packet) { - dynamicbox_h handler; - struct dynamicbox_common *common; - struct dlist *l; - struct dlist *n; - const char *pkgname; - const char *id; - int ret; - double period; - int status; - - ret = packet_get(packet, "idss", &status, &period, &pkgname, &id); - if (ret != 4) { - ErrPrint("Invalid argument\n"); - goto out; - } - - common = dbox_find_common_handle(pkgname, id); - if (!common) { - ErrPrint("Livebox(%s) is not found\n", id); - goto out; - } - - if (common->state != DBOX_STATE_CREATE) { - ErrPrint("Livebox(%s) is not created\n", id); - goto out; - } - - if (status == (int)DBOX_STATUS_ERROR_NONE) { - dbox_set_period(common, period); - } - - common->request.period_changed = 0; - - dlist_foreach_safe(common->dynamicbox_list, l, n, handler) { - if (handler->cbs.period_changed.cb) { - dynamicbox_ret_cb cb; - void *cbdata; - - cb = handler->cbs.period_changed.cb; - cbdata = handler->cbs.period_changed.data; - - handler->cbs.period_changed.cb = NULL; - handler->cbs.period_changed.data = NULL; - - cb(handler, status, cbdata); - } else if (status == (int)DBOX_STATUS_ERROR_NONE) { - dbox_invoke_event_handler(handler, DBOX_EVENT_PERIOD_CHANGED); - } - } + dynamicbox_h handler; + struct dynamicbox_common *common; + struct dlist *l; + struct dlist *n; + const char *pkgname; + const char *id; + int ret; + double period; + int status; + + ret = packet_get(packet, "idss", &status, &period, &pkgname, &id); + if (ret != 4) { + ErrPrint("Invalid argument\n"); + goto out; + } + + common = dbox_find_common_handle(pkgname, id); + if (!common) { + ErrPrint("DBOX(%s) is not found\n", id); + goto out; + } + + if (common->state != DBOX_STATE_CREATE) { + ErrPrint("DBOX(%s) is not created\n", id); + goto out; + } + + if (status == (int)DBOX_STATUS_ERROR_NONE) { + dbox_set_period(common, period); + } + + common->request.period_changed = 0; + + dlist_foreach_safe(common->dynamicbox_list, l, n, handler) { + if (handler->cbs.period_changed.cb) { + dynamicbox_ret_cb cb; + void *cbdata; + + cb = handler->cbs.period_changed.cb; + cbdata = handler->cbs.period_changed.data; + + handler->cbs.period_changed.cb = NULL; + handler->cbs.period_changed.data = NULL; + + cb(handler, status, cbdata); + } else if (status == (int)DBOX_STATUS_ERROR_NONE) { + dbox_invoke_event_handler(handler, DBOX_EVENT_PERIOD_CHANGED); + } + } out: - return NULL; + return NULL; } static struct packet *master_group_changed(pid_t pid, int handle, const struct packet *packet) { - dynamicbox_h handler; - struct dynamicbox_common *common; - struct dlist *l; - struct dlist *n; - const char *pkgname; - const char *id; - int ret; - const char *cluster; - const char *category; - int status; - - ret = packet_get(packet, "ssiss", &pkgname, &id, &status, &cluster, &category); - if (ret != 5) { - ErrPrint("Invalid argument\n"); - goto out; - } - - common = dbox_find_common_handle(pkgname, id); - if (!common) { - ErrPrint("Livebox(%s) is not exists\n", id); - goto out; - } - - if (common->state != DBOX_STATE_CREATE) { - /*! - * \note - * Do no access this handler, - * You cannot believe this handler anymore. - */ - ErrPrint("Livebox(%s) is not created\n", id); - goto out; - } - - if (status == (int)DBOX_STATUS_ERROR_NONE) { - (void)dbox_set_group(common, cluster, category); - } - - common->request.group_changed = 0; - - dlist_foreach_safe(common->dynamicbox_list, l, n, handler) { - if (handler->cbs.group_changed.cb) { - dynamicbox_ret_cb cb; - void *cbdata; - - cb = handler->cbs.group_changed.cb; - cbdata = handler->cbs.group_changed.data; - - handler->cbs.group_changed.cb = NULL; - handler->cbs.group_changed.data = NULL; - - cb(handler, status, cbdata); - } else if (status == (int)DBOX_STATUS_ERROR_NONE) { - dbox_invoke_event_handler(handler, DBOX_EVENT_GROUP_CHANGED); - } - } + dynamicbox_h handler; + struct dynamicbox_common *common; + struct dlist *l; + struct dlist *n; + const char *pkgname; + const char *id; + int ret; + const char *cluster; + const char *category; + int status; + + ret = packet_get(packet, "ssiss", &pkgname, &id, &status, &cluster, &category); + if (ret != 5) { + ErrPrint("Invalid argument\n"); + goto out; + } + + common = dbox_find_common_handle(pkgname, id); + if (!common) { + ErrPrint("DBOX(%s) is not exists\n", id); + goto out; + } + + if (common->state != DBOX_STATE_CREATE) { + /*! + * \note + * Do no access this handler, + * You cannot believe this handler anymore. + */ + ErrPrint("DBOX(%s) is not created\n", id); + goto out; + } + + if (status == (int)DBOX_STATUS_ERROR_NONE) { + (void)dbox_set_group(common, cluster, category); + } + + common->request.group_changed = 0; + + dlist_foreach_safe(common->dynamicbox_list, l, n, handler) { + if (handler->cbs.group_changed.cb) { + dynamicbox_ret_cb cb; + void *cbdata; + + cb = handler->cbs.group_changed.cb; + cbdata = handler->cbs.group_changed.data; + + handler->cbs.group_changed.cb = NULL; + handler->cbs.group_changed.data = NULL; + + cb(handler, status, cbdata); + } else if (status == (int)DBOX_STATUS_ERROR_NONE) { + dbox_invoke_event_handler(handler, DBOX_EVENT_GROUP_CHANGED); + } + } out: - return NULL; + return NULL; +} + +static struct packet *master_update_id(pid_t pid, int handle, const struct packet *packet) +{ + int ret; + double timestamp; + const char *id; + struct dynamicbox_common *common; + + if (!packet) { + ErrPrint("Invalid packet\n"); + return NULL; + } + + ret = packet_get(packet, "ds", ×tamp, &id); + if (ret != 2) { + ErrPrint("Invalid paramter\n"); + return NULL; + } + + common = dbox_find_common_handle_by_timestamp(timestamp); + if (!common) { + ErrPrint("Handle is not found for %d\n", timestamp); + return NULL; + } + + dbox_set_id(common, id); + DbgPrint("Update ID(%s) for %lf\n", id, timestamp); + return NULL; } static struct packet *master_created(pid_t pid, int handle, const struct packet *packet) { - dynamicbox_h handler; - struct dynamicbox_common *common; - struct dlist *l; - - int dbox_w; - int dbox_h; - int gbar_w; - int gbar_h; - const char *pkgname; - const char *id; - - const char *content; - const char *cluster; - const char *category; - const char *dbox_fname; - const char *gbar_fname; - const char *title; - - double timestamp; - const char *auto_launch; - double priority; - int size_list; - int user; - int pinup_supported; - enum dynamicbox_dbox_type dbox_type; - enum dynamicbox_gbar_type gbar_type; - double period; - int is_pinned_up; - - int old_state = DBOX_STATE_DESTROYED; - - int ret; - - ret = packet_get(packet, "dsssiiiisssssdiiiiidsi", - ×tamp, - &pkgname, &id, &content, - &dbox_w, &dbox_h, &gbar_w, &gbar_h, - &cluster, &category, &dbox_fname, &gbar_fname, - &auto_launch, &priority, &size_list, &user, &pinup_supported, - &dbox_type, &gbar_type, &period, &title, &is_pinned_up); - if (ret != 22) { - ErrPrint("Invalid argument\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } - - ErrPrint("[%lf] pkgname: %s, id: %s, content: %s, " - "gbar_w: %d, gbar_h: %d, dbox_w: %d, dbox_h: %d, " - "cluster: %s, category: %s, dbox_fname: \"%s\", gbar_fname: \"%s\", " - "auto_launch: %s, priority: %lf, size_list: %d, user: %d, pinup: %d, " - "dbox_type: %d, gbar_type: %d, period: %lf, title: [%s], is_pinned_up: %d\n", - timestamp, pkgname, id, content, - gbar_w, gbar_h, dbox_w, dbox_h, - cluster, category, dbox_fname, gbar_fname, - auto_launch, priority, size_list, user, pinup_supported, - dbox_type, gbar_type, period, title, is_pinned_up); - - common = dbox_find_common_handle_by_timestamp(timestamp); - if (!common) { - handler = dbox_new_dynamicbox(pkgname, id, timestamp, cluster, category); - if (!handler) { - ErrPrint("Failed to create a new dynamicbox\n"); - ret = DBOX_STATUS_ERROR_FAULT; - goto out; - } - common = handler->common; - old_state = common->state; - } else { - if (common->state != DBOX_STATE_CREATE) { - if (common->state != DBOX_STATE_DELETE) { - /*! - * \note - * This is not possible!!! - */ - ErrPrint("Invalid handler\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto out; - } - - /*! - * \note - * After get the delete states, - * call the create callback with deleted result. - */ - } - - old_state = common->state; - - if (common->id) { - ErrPrint("Already created: timestamp[%lf] " - "pkgname[%s], id[%s] content[%s] " - "cluster[%s] category[%s] dbox_fname[%s] gbar_fname[%s]\n", - timestamp, pkgname, id, - content, cluster, category, - dbox_fname, gbar_fname); - - ret = DBOX_STATUS_ERROR_ALREADY; - goto out; - } - - dbox_set_id(common, id); - } - - common->request.created = 0; - dbox_set_size(common, dbox_w, dbox_h); - common->dbox.type = dbox_type; - common->is_pinned_up = is_pinned_up; - - switch (dbox_type) { - case DBOX_TYPE_UIFW: - case DBOX_TYPE_FILE: - break; - case DBOX_TYPE_SCRIPT: - case DBOX_TYPE_BUFFER: - if (!strlen(dbox_fname)) { - break; - } - (void)dbox_set_dbox_fb(common, dbox_fname); - - /*! - * \note - * Livebox should create the lock file from here. - * Even if the old_state == DBOX_STATE_DELETE, - * the lock file will be deleted from deleted event callback. - */ - switch (fb_type(dbox_get_dbox_fb(common))) { - case DBOX_FB_TYPE_FILE: - case DBOX_FB_TYPE_SHM: - dbox_create_lock_file(common, 0); - break; - case DBOX_FB_TYPE_PIXMAP: - case DBOX_FB_TYPE_ERROR: - default: - break; - } - - ret = dbox_sync_dbox_fb(common); - if (ret < 0) { - ErrPrint("Failed to do sync FB (%s - %s)\n", pkgname, util_basename(util_uri_to_path(id))); - } - break; - case DBOX_TYPE_TEXT: - dbox_set_text_dbox(common); - break; - default: - break; - } - - common->gbar.type = gbar_type; - dbox_set_gbarsize(common, gbar_w, gbar_h); - dbox_set_default_gbarsize(common, gbar_w, gbar_h); - switch (gbar_type) { - case GBAR_TYPE_SCRIPT: - case GBAR_TYPE_BUFFER: - if (!strlen(gbar_fname)) { - break; - } - - dbox_set_gbar_fb(common, gbar_fname); - - ret = dbox_sync_gbar_fb(common); - if (ret < 0) { - ErrPrint("Failed to do sync FB (%s - %s)\n", pkgname, util_basename(util_uri_to_path(id))); - } - - /*! - * \brief - * GBAR doesn't need to create the lock file from here. - * Just create it from GBAR_CREATED event. - */ - - break; - case GBAR_TYPE_TEXT: - dbox_set_text_gbar(common); - break; - case GBAR_TYPE_UIFW: - default: - break; - } - - dbox_set_priority(common, priority); - - dbox_set_size_list(common, size_list); - dbox_set_group(common, cluster, category); - - dbox_set_content(common, content); - dbox_set_title(common, title); - - dbox_set_user(common, user); - - dbox_set_auto_launch(common, auto_launch); - dbox_set_pinup(common, pinup_supported); - - dbox_set_period(common, period); - - ret = 0; - - if (common->state == DBOX_STATE_CREATE) { - dlist_foreach(common->dynamicbox_list, l, handler) { - /*! - * \note - * These callback can change the handler->state. - * So we have to use the "old_state" which stored state before call these callbacks - */ - - if (handler->cbs.created.cb) { - dynamicbox_ret_cb cb; - void *cbdata; - - cb = handler->cbs.created.cb; - cbdata = handler->cbs.created.data; - - handler->cbs.created.cb = NULL; - handler->cbs.created.data = NULL; - - cb(handler, ret, cbdata); - } else { - dbox_invoke_event_handler(handler, DBOX_EVENT_CREATED); - } - } - } + dynamicbox_h handler; + struct dynamicbox_common *common; + struct dlist *l; + + int dbox_w; + int dbox_h; + int gbar_w; + int gbar_h; + const char *pkgname; + const char *id; + + const char *content; + const char *cluster; + const char *category; + const char *dbox_fname; + const char *gbar_fname; + const char *title; + + double timestamp; + const char *auto_launch; + double priority; + int size_list; + int user; + int pinup_supported; + dynamicbox_dbox_type_e dbox_type; + dynamicbox_gbar_type_e gbar_type; + double period; + int is_pinned_up; + + int old_state = DBOX_STATE_DESTROYED; + + int ret; + + ret = packet_get(packet, "dsssiiiisssssdiiiiidsi", + ×tamp, + &pkgname, &id, &content, + &dbox_w, &dbox_h, &gbar_w, &gbar_h, + &cluster, &category, &dbox_fname, &gbar_fname, + &auto_launch, &priority, &size_list, &user, &pinup_supported, + &dbox_type, &gbar_type, &period, &title, &is_pinned_up); + if (ret != 22) { + ErrPrint("Invalid argument\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } + + ErrPrint("[%lf] pkgname: %s, id: %s, content: %s, " + "gbar_w: %d, gbar_h: %d, dbox_w: %d, dbox_h: %d, " + "cluster: %s, category: %s, dbox_fname: \"%s\", gbar_fname: \"%s\", " + "auto_launch: %s, priority: %lf, size_list: %d, user: %d, pinup: %d, " + "dbox_type: %d, gbar_type: %d, period: %lf, title: [%s], is_pinned_up: %d\n", + timestamp, pkgname, id, content, + gbar_w, gbar_h, dbox_w, dbox_h, + cluster, category, dbox_fname, gbar_fname, + auto_launch, priority, size_list, user, pinup_supported, + dbox_type, gbar_type, period, title, is_pinned_up); + + common = dbox_find_common_handle_by_timestamp(timestamp); + if (!common) { + handler = dbox_new_dynamicbox(pkgname, id, timestamp, cluster, category); + if (!handler) { + ErrPrint("Failed to create a new dynamicbox\n"); + ret = DBOX_STATUS_ERROR_FAULT; + goto out; + } + common = handler->common; + old_state = common->state; + } else { + if (common->state != DBOX_STATE_CREATE) { + if (common->state != DBOX_STATE_DELETE) { + /*! + * \note + * This is not possible!!! + */ + ErrPrint("Invalid handler\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto out; + } + + /*! + * \note + * After get the delete states, + * call the create callback with deleted result. + */ + } + + old_state = common->state; + + if (common->id && common->request.created == 0) { + ErrPrint("Already created: timestamp[%lf] " + "pkgname[%s], id[%s] content[%s] " + "cluster[%s] category[%s] dbox_fname[%s] gbar_fname[%s]\n", + timestamp, pkgname, id, + content, cluster, category, + dbox_fname, gbar_fname); + + ret = DBOX_STATUS_ERROR_ALREADY; + goto out; + } + + dbox_set_id(common, id); + } + + common->request.created = 0; + dbox_set_size(common, dbox_w, dbox_h); + common->dbox.type = dbox_type; + common->is_pinned_up = is_pinned_up; + + switch (dbox_type) { + case DBOX_TYPE_UIFW: + case DBOX_TYPE_FILE: + break; + case DBOX_TYPE_SCRIPT: + case DBOX_TYPE_BUFFER: + if (!strlen(dbox_fname)) { + break; + } + (void)dbox_set_dbox_fb(common, dbox_fname); + + /*! + * \note + * DBOX should create the lock file from here. + * Even if the old_state == DBOX_STATE_DELETE, + * the lock file will be deleted from deleted event callback. + */ + switch (fb_type(dbox_get_dbox_fb(common))) { + case DBOX_FB_TYPE_FILE: + case DBOX_FB_TYPE_SHM: + common->dbox.lock = dynamicbox_service_create_lock(common->id, DBOX_TYPE_DBOX, DBOX_LOCK_READ); + break; + case DBOX_FB_TYPE_PIXMAP: + case DBOX_FB_TYPE_ERROR: + default: + break; + } + + ret = dbox_sync_dbox_fb(common); + if (ret < 0) { + ErrPrint("Failed to do sync FB (%s - %s)\n", pkgname, util_basename(util_uri_to_path(id))); + } + break; + case DBOX_TYPE_TEXT: + dbox_set_text_dbox(common); + break; + default: + break; + } + + common->gbar.type = gbar_type; + dbox_set_gbarsize(common, gbar_w, gbar_h); + dbox_set_default_gbarsize(common, gbar_w, gbar_h); + switch (gbar_type) { + case GBAR_TYPE_SCRIPT: + case GBAR_TYPE_BUFFER: + if (!strlen(gbar_fname)) { + break; + } + + dbox_set_gbar_fb(common, gbar_fname); + + ret = dbox_sync_gbar_fb(common); + if (ret < 0) { + ErrPrint("Failed to do sync FB (%s - %s)\n", pkgname, util_basename(util_uri_to_path(id))); + } + + /*! + * \brief + * GBAR doesn't need to create the lock file from here. + * Just create it from GBAR_CREATED event. + */ + + break; + case GBAR_TYPE_TEXT: + dbox_set_text_gbar(common); + break; + case GBAR_TYPE_UIFW: + default: + break; + } + + dbox_set_priority(common, priority); + + dbox_set_size_list(common, size_list); + dbox_set_group(common, cluster, category); + + dbox_set_content(common, content); + dbox_set_title(common, title); + + dbox_set_user(common, user); + + dbox_set_auto_launch(common, auto_launch); + dbox_set_pinup(common, pinup_supported); + + dbox_set_period(common, period); + + ret = 0; + + if (common->state == DBOX_STATE_CREATE) { + dlist_foreach(common->dynamicbox_list, l, handler) { + /*! + * \note + * These callback can change the handler->state. + * So we have to use the "old_state" which stored state before call these callbacks + */ + + if (handler->cbs.created.cb) { + dynamicbox_ret_cb cb; + void *cbdata; + + cb = handler->cbs.created.cb; + cbdata = handler->cbs.created.data; + + handler->cbs.created.cb = NULL; + handler->cbs.created.data = NULL; + + cb(handler, ret, cbdata); + } else { + dbox_invoke_event_handler(handler, DBOX_EVENT_CREATED); + } + } + } out: - if (ret == 0 && old_state == DBOX_STATE_DELETE) { - struct dlist *n; - - DbgPrint("Take place an unexpected case [%d]\n", common->refcnt); - dlist_foreach_safe(common->dynamicbox_list, l, n, handler) { - if (handler->cbs.created.cb) { - if (!handler->common->request.deleted) { - if (dbox_send_delete(handler, common->delete_type, handler->cbs.created.cb, handler->cbs.created.data) < 0) { - /*! - * \note - * Already sent or something else happens. - * Callback will be called in any cases - */ - } - } else if (handler->state != DBOX_STATE_DELETE) { - handler->cbs.created.cb(handler, DBOX_STATUS_ERROR_CANCEL, handler->cbs.created.data); - dbox_unref(handler, 1); - } - } else { - dbox_invoke_event_handler(handler, DBOX_EVENT_DELETED); - dbox_unref(handler, 1); - } - } - - /*! - * \note - * handler->cbs.created.cb = NULL; - * handler->cbs.created.data = NULL; - * - * Do not clear this to use this from the deleted event callback. - * if this value is not cleared when the deleted event callback check it, - * it means that the created function is not called yet. - * Then the call the deleted event callback with DBOX_STATUS_ERROR_CANCEL errno. - */ - } - - return NULL; + if (ret == 0 && old_state == DBOX_STATE_DELETE) { + struct dlist *n; + + DbgPrint("Take place an unexpected case [%d]\n", common->refcnt); + dlist_foreach_safe(common->dynamicbox_list, l, n, handler) { + if (handler->cbs.created.cb) { + if (!handler->common->request.deleted) { + if (dbox_send_delete(handler, common->delete_type, handler->cbs.created.cb, handler->cbs.created.data) < 0) { + /*! + * \note + * Already sent or something else happens. + * Callback will be called in any cases + */ + } + } else if (handler->state != DBOX_STATE_DELETE) { + handler->cbs.created.cb(handler, DBOX_STATUS_ERROR_CANCEL, handler->cbs.created.data); + dbox_unref(handler, 1); + } + } else { + dbox_invoke_event_handler(handler, DBOX_EVENT_DELETED); + dbox_unref(handler, 1); + } + } + + /*! + * \note + * handler->cbs.created.cb = NULL; + * handler->cbs.created.data = NULL; + * + * Do not clear this to use this from the deleted event callback. + * if this value is not cleared when the deleted event callback check it, + * it means that the created function is not called yet. + * Then the call the deleted event callback with DBOX_STATUS_ERROR_CANCEL errno. + */ + } + + return NULL; } static struct method s_table[] = { - { - .cmd = CMD_STR_DBOX_UPDATED, /* pkgname, id, dbox_w, dbox_h, priority, ret */ - .handler = master_dbox_updated, - }, - { - .cmd = CMD_STR_GBAR_UPDATED, /* pkgname, id, descfile, pd_w, pd_h, ret */ - .handler = master_gbar_updated, - }, - { - .cmd = CMD_STR_EXTRA_INFO, - .handler = master_extra_info, - }, - { - .cmd = CMD_STR_DELETED, /* pkgname, id, timestamp, ret */ - .handler = master_deleted, - }, - { - .cmd = CMD_STR_FAULT_PACKAGE, /* pkgname, id, function, ret */ - .handler = master_fault_package, - }, - { - .cmd = CMD_STR_SCROLL, - .handler = master_hold_scroll, - }, - { - .cmd = CMD_STR_DBOX_UPDATE_BEGIN, - .handler = master_dbox_update_begin, - }, - { - .cmd = CMD_STR_DBOX_UPDATE_END, - .handler = master_dbox_update_end, - }, - { - .cmd = CMD_STR_GBAR_UPDATE_BEGIN, - .handler = master_gbar_update_begin, - }, - { - .cmd = CMD_STR_GBAR_UPDATE_END, - .handler = master_gbar_update_end, - }, - { - .cmd = CMD_STR_ACCESS_STATUS, - .handler = master_access_status, - }, - { - .cmd = CMD_STR_KEY_STATUS, - .handler = master_key_status, - }, - { - .cmd = CMD_STR_CLOSE_GBAR, - .handler = master_request_close_gbar, - }, - { - .cmd = CMD_STR_GBAR_CREATED, - .handler = master_gbar_created, - }, - { - .cmd = CMD_STR_GBAR_DESTROYED, - .handler = master_gbar_destroyed, - }, - { - .cmd = CMD_STR_CREATED, /* timestamp, pkgname, id, content, dbox_w, dbox_h, gbar_w, gbar_h, cluster, category, dbox_file, gbar_file, auto_launch, priority, size_list, is_user, pinup_supported, text_dbox, text_gbar, period, ret */ - .handler = master_created, - }, - { - .cmd = CMD_STR_GROUP_CHANGED, - .handler = master_group_changed, - }, - { - .cmd = CMD_STR_PERIOD_CHANGED, - .handler = master_period_changed, - }, - { - .cmd = CMD_STR_SIZE_CHANGED, - .handler = master_size_changed, - }, - { - .cmd = CMD_STR_PINUP, - .handler = master_pinup, - }, - - { - .cmd = CMD_STR_UPDATE_MODE, - .handler = master_update_mode, - }, - { - .cmd = NULL, - .handler = NULL, - }, + { /* DBOX_UPDATED */ + .cmd = CMD_STR_DBOX_UPDATED, /* pkgname, id, dbox_w, dbox_h, priority, ret */ + .handler = master_dbox_updated, + }, + { /* GBAR_UPDATED */ + .cmd = CMD_STR_GBAR_UPDATED, /* pkgname, id, descfile, pd_w, pd_h, ret */ + .handler = master_gbar_updated, + }, + { /* EXTRA_UPDATED */ + .cmd = CMD_STR_EXTRA_UPDATED, + .handler = master_extra_updated, + }, + { /* EXTRA_INFO */ + .cmd = CMD_STR_EXTRA_INFO, + .handler = master_extra_info, + }, + { /* DELETED */ + .cmd = CMD_STR_DELETED, /* pkgname, id, timestamp, ret */ + .handler = master_deleted, + }, + { /* FAULTED */ + .cmd = CMD_STR_FAULT_PACKAGE, /* pkgname, id, function, ret */ + .handler = master_fault_package, + }, + { /* SCROLL */ + .cmd = CMD_STR_SCROLL, + .handler = master_hold_scroll, + }, + { /* DBOX_UPDATE_BEGIN */ + .cmd = CMD_STR_DBOX_UPDATE_BEGIN, + .handler = master_dbox_update_begin, + }, + { /* DBOX_UPDATE_END */ + .cmd = CMD_STR_DBOX_UPDATE_END, + .handler = master_dbox_update_end, + }, + { /* GBAR_UPDATE_BEGIN */ + .cmd = CMD_STR_GBAR_UPDATE_BEGIN, + .handler = master_gbar_update_begin, + }, + { /* GBAR_UPDATE_END */ + .cmd = CMD_STR_GBAR_UPDATE_END, + .handler = master_gbar_update_end, + }, + { /* ACCESS_STATUS */ + .cmd = CMD_STR_ACCESS_STATUS, + .handler = master_access_status, + }, + { /* KEY_STATUS */ + .cmd = CMD_STR_KEY_STATUS, + .handler = master_key_status, + }, + { /* CLOSE_GBAR */ + .cmd = CMD_STR_CLOSE_GBAR, + .handler = master_request_close_gbar, + }, + { /* GBAR_CREATED */ + .cmd = CMD_STR_GBAR_CREATED, + .handler = master_gbar_created, + }, + { /* GBAR_DESTROYED */ + .cmd = CMD_STR_GBAR_DESTROYED, + .handler = master_gbar_destroyed, + }, + { /* CREATED */ + .cmd = CMD_STR_CREATED, + .handler = master_created, + }, + { /* GROUP_CHANGED */ + .cmd = CMD_STR_GROUP_CHANGED, + .handler = master_group_changed, + }, + { /* PERIOD_CHANGED */ + .cmd = CMD_STR_PERIOD_CHANGED, + .handler = master_period_changed, + }, + { /* SIZE_CHANGED */ + .cmd = CMD_STR_SIZE_CHANGED, + .handler = master_size_changed, + }, + { /* PINUP */ + .cmd = CMD_STR_PINUP, + .handler = master_pinup, + }, + { /* UPDATE_MODE */ + .cmd = CMD_STR_UPDATE_MODE, + .handler = master_update_mode, + }, + { /* DBOX_CREATE_XBUF */ + .cmd = CMD_STR_DBOX_CREATE_XBUF, + .handler = master_dbox_extra_buffer_created, + }, + { /* GBAR_CREATE_XBUF */ + .cmd = CMD_STR_GBAR_CREATE_XBUF, + .handler = master_gbar_extra_buffer_created, + }, + { /* DBOX_DESTROY_XBUF */ + .cmd = CMD_STR_DBOX_DESTROY_XBUF, + .handler = master_dbox_extra_buffer_destroyed, + }, + { /* GBAR_DESTROY_XBUF */ + .cmd = CMD_STR_GBAR_DESTROY_XBUF, + .handler = master_gbar_extra_buffer_destroyed, + }, + { /* UPDATE_ID */ + .cmd = CMD_STR_UPDATE_ID, + .handler = master_update_id, + }, + { + .cmd = NULL, + .handler = NULL, + }, }; static void acquire_cb(dynamicbox_h handler, const struct packet *result, void *data) { - if (!result) { - DbgPrint("Result packet is not valid\n"); - } else { - int ret; - - if (packet_get(result, "i", &ret) != 1) { - ErrPrint("Invalid argument\n"); - } else { - DbgPrint("Acquire returns: %d\n", ret); - } - } - - return; + if (!result) { + DbgPrint("Result packet is not valid\n"); + } else { + int ret; + int extra_buffer_count; + + if (packet_get(result, "ii", &ret, &extra_buffer_count) != 2) { + ErrPrint("Invalid argument\n"); + } else { + DbgPrint("Acquire returns: %d (%d)\n", ret, extra_buffer_count); + conf_set_extra_buffer_count(extra_buffer_count); + } + } + + return; } static inline int make_connection(void) { - struct packet *packet; - unsigned int cmd = CMD_ACQUIRE; - int ret; - - DbgPrint("Let's making connection!\n"); - - s_info.fd = com_core_packet_client_init(client_addr(), 0, s_table); - if (s_info.fd < 0) { - ErrPrint("Try this again later\n"); - return DBOX_STATUS_ERROR_IO_ERROR; - } - - packet = packet_create((const char *)&cmd, "ds", util_timestamp(), client_direct_addr()); - if (!packet) { - com_core_packet_client_fini(s_info.fd); - s_info.fd = -1; - return DBOX_STATUS_ERROR_FAULT; - } - - ret = master_rpc_async_request(NULL, packet, 1, acquire_cb, NULL); - if (ret < 0) { - ErrPrint("Master RPC returns %d\n", ret); - com_core_packet_client_fini(s_info.fd); - s_info.fd = -1; - return DBOX_STATUS_ERROR_IO_ERROR; - } - - return DBOX_STATUS_ERROR_NONE; + struct packet *packet; + unsigned int cmd = CMD_ACQUIRE; + int ret; + + DbgPrint("Let's making connection!\n"); + + s_info.fd = com_core_packet_client_init(client_addr(), 0, s_table); + if (s_info.fd < 0) { + ErrPrint("Try this again later\n"); + return DBOX_STATUS_ERROR_IO_ERROR; + } + + packet = packet_create((const char *)&cmd, "ds", util_timestamp(), client_direct_addr()); + if (!packet) { + com_core_packet_client_fini(s_info.fd); + s_info.fd = -1; + return DBOX_STATUS_ERROR_FAULT; + } + + ret = master_rpc_async_request(NULL, packet, 1, acquire_cb, NULL); + if (ret < 0) { + ErrPrint("Master RPC returns %d\n", ret); + com_core_packet_client_fini(s_info.fd); + s_info.fd = -1; + return DBOX_STATUS_ERROR_IO_ERROR; + } + + return DBOX_STATUS_ERROR_NONE; } static int connected_cb(int handle, void *data) { - master_rpc_check_and_fire_consumer(); - return 0; + master_rpc_check_and_fire_consumer(); + return 0; } static void master_started_cb(keynode_t *node, void *data) { - int state = 0; - - if (vconf_get_bool(VCONFKEY_MASTER_STARTED, &state) < 0) { - ErrPrint("Unable to get [%s]\n", VCONFKEY_MASTER_STARTED); - } - - DbgPrint("Master state: %d\n", state); - if (state == 1 && make_connection() == (int)DBOX_STATUS_ERROR_NONE) { - int ret; - ret = vconf_ignore_key_changed(VCONFKEY_MASTER_STARTED, master_started_cb); - if (ret < 0) { - DbgPrint("master_started vconf key de-registered [%d]\n", ret); - } - } + int state = 0; + + if (vconf_get_bool(VCONFKEY_MASTER_STARTED, &state) < 0) { + ErrPrint("Unable to get [%s]\n", VCONFKEY_MASTER_STARTED); + } + + DbgPrint("Master state: %d\n", state); + if (state == 1 && make_connection() == (int)DBOX_STATUS_ERROR_NONE) { + int ret; + ret = vconf_ignore_key_changed(VCONFKEY_MASTER_STARTED, master_started_cb); + if (ret < 0) { + DbgPrint("master_started vconf key de-registered [%d]\n", ret); + } + } } static gboolean timeout_cb(gpointer data) { - if (vconf_notify_key_changed(VCONFKEY_MASTER_STARTED, master_started_cb, NULL) < 0) { - ErrPrint("Failed to add vconf for monitoring service state\n"); - } else { - DbgPrint("vconf event callback is registered\n"); - } + if (vconf_notify_key_changed(VCONFKEY_MASTER_STARTED, master_started_cb, NULL) < 0) { + ErrPrint("Failed to add vconf for monitoring service state\n"); + } else { + DbgPrint("vconf event callback is registered\n"); + } - master_started_cb(NULL, NULL); + master_started_cb(NULL, NULL); - s_info.timer_id = 0; - return FALSE; + s_info.timer_id = 0; + return FALSE; } static int disconnected_cb(int handle, void *data) { - if (s_info.fd != handle) { - /*!< This handle is not my favor */ - return 0; - } - - s_info.fd = -1; /*!< Disconnected */ - - master_rpc_clear_all_request(); - dbox_invoke_fault_handler(DBOX_FAULT_PROVIDER_DISCONNECTED, MASTER_PKGNAME, "default", "disconnected"); - - dbox_delete_all(); - - /* Try to reconnect after 1 sec later */ - if (!s_info.timer_id) { - DbgPrint("Reconnecting timer is added\n"); - s_info.timer_id = g_timeout_add(1000, timeout_cb, NULL); - if (s_info.timer_id == 0) { - ErrPrint("Unable to add reconnecting timer\n"); - return 0; - } - } else { - ErrPrint("Reconnecting timer is already exists\n"); - } - - return 0; + if (s_info.fd != handle) { + /*!< This handle is not my favor */ + return 0; + } + + s_info.fd = -1; /*!< Disconnected */ + + master_rpc_clear_all_request(); + dbox_invoke_fault_handler(DBOX_FAULT_PROVIDER_DISCONNECTED, MASTER_PKGNAME, "default", "disconnected"); + + dbox_delete_all(); + + /* Try to reconnect after 1 sec later */ + if (!s_info.timer_id) { + DbgPrint("Reconnecting timer is added\n"); + s_info.timer_id = g_timeout_add(1000, timeout_cb, NULL); + if (s_info.timer_id == 0) { + ErrPrint("Unable to add reconnecting timer\n"); + return 0; + } + } else { + ErrPrint("Reconnecting timer is already exists\n"); + } + + return 0; } static struct method s_direct_table[] = { - { - .cmd = CMD_STR_DBOX_UPDATED, /* pkgname, id, lb_w, lb_h, priority, ret */ - .handler = master_dbox_updated, - }, - { - .cmd = CMD_STR_GBAR_UPDATED, /* pkgname, id, descfile, pd_w, pd_h, ret */ - .handler = master_gbar_updated, - }, - { - .cmd = NULL, - .handler = NULL, - }, + { + .cmd = CMD_STR_DBOX_UPDATED, /* pkgname, id, lb_w, lb_h, priority, ret */ + .handler = master_dbox_updated, + }, + { + .cmd = CMD_STR_GBAR_UPDATED, /* pkgname, id, descfile, pd_w, pd_h, ret */ + .handler = master_gbar_updated, + }, + { + .cmd = CMD_STR_EXTRA_UPDATED, + .handler = master_extra_updated, + }, + { + .cmd = NULL, + .handler = NULL, + }, }; static void prepare_direct_update(void) { - char path[MAX_DIRECT_ADDR]; + char path[MAX_DIRECT_ADDR]; - if (!conf_direct_update()) { - return; - } + if (!conf_direct_update()) { + return; + } - if (!strncmp(s_info.client_addr, COM_CORE_REMOTE_SCHEME, strlen(COM_CORE_REMOTE_SCHEME))) { - ErrPrint("Remote model is not support this\n"); - return; - } + if (!strncmp(s_info.client_addr, COM_CORE_REMOTE_SCHEME, strlen(COM_CORE_REMOTE_SCHEME))) { + ErrPrint("Remote model is not support this\n"); + return; + } - snprintf(path, sizeof(path) - 1, "/tmp/.%d.%lf.dbox.viewer", getpid(), util_timestamp()); + snprintf(path, sizeof(path) - 1, "/tmp/.%d.%lf.dbox.viewer", getpid(), util_timestamp()); - s_info.direct_addr = strdup(path); - if (!s_info.direct_addr) { - ErrPrint("strdup: %s\n", strerror(errno)); - return; - } + s_info.direct_addr = strdup(path); + if (!s_info.direct_addr) { + ErrPrint("strdup: %s\n", strerror(errno)); + return; + } - s_info.direct_fd = com_core_packet_server_init(client_direct_addr(), s_direct_table); - if (s_info.direct_fd < 0) { - ErrPrint("Failed to prepare server: %s\n", client_direct_addr()); - return; - } + s_info.direct_fd = com_core_packet_server_init(client_direct_addr(), s_direct_table); + if (s_info.direct_fd < 0) { + ErrPrint("Failed to prepare server: %s\n", client_direct_addr()); + return; + } - DbgPrint("Direct update is prepared: %s - %d\n", client_direct_addr(), client_direct_fd()); + DbgPrint("Direct update is prepared: %s - %d\n", client_direct_addr(), client_direct_fd()); } int client_init(int use_thread) { - com_core_packet_use_thread(use_thread); - - s_info.client_addr = vconf_get_str(VCONFKEY_MASTER_CLIENT_ADDR); - if (!s_info.client_addr) { - s_info.client_addr = strdup(CLIENT_SOCKET); - if (!s_info.client_addr) { - ErrPrint("Heap: %s\n", strerror(errno)); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } - } - - (void)file_service_init(); - - DbgPrint("Server Address: %s\n", s_info.client_addr); - - com_core_add_event_callback(CONNECTOR_DISCONNECTED, disconnected_cb, NULL); - com_core_add_event_callback(CONNECTOR_CONNECTED, connected_cb, NULL); - - /** - * @note - * Before creating a connection with master, - * Initiate the private channel for getting the updated event from providers - * How could we propagates the our address to every providers? - */ - prepare_direct_update(); - - if (vconf_notify_key_changed(VCONFKEY_MASTER_STARTED, master_started_cb, NULL) < 0) { - ErrPrint("Failed to add vconf for service state\n"); - } else { - DbgPrint("vconf event callback is registered\n"); - } - - master_started_cb(NULL, NULL); - return DBOX_STATUS_ERROR_NONE; + com_core_packet_use_thread(use_thread); + + s_info.client_addr = vconf_get_str(VCONFKEY_MASTER_CLIENT_ADDR); + if (!s_info.client_addr) { + s_info.client_addr = strdup(CLIENT_SOCKET); + if (!s_info.client_addr) { + ErrPrint("Heap: %s\n", strerror(errno)); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } + } + + (void)file_service_init(); + + DbgPrint("Server Address: %s\n", s_info.client_addr); + + com_core_add_event_callback(CONNECTOR_DISCONNECTED, disconnected_cb, NULL); + com_core_add_event_callback(CONNECTOR_CONNECTED, connected_cb, NULL); + + /** + * @note + * Before creating a connection with master, + * Initiate the private channel for getting the updated event from providers + * How could we propagates the our address to every providers? + */ + prepare_direct_update(); + + if (vconf_notify_key_changed(VCONFKEY_MASTER_STARTED, master_started_cb, NULL) < 0) { + ErrPrint("Failed to add vconf for service state\n"); + } else { + DbgPrint("vconf event callback is registered\n"); + } + + master_started_cb(NULL, NULL); + return DBOX_STATUS_ERROR_NONE; } int client_fd(void) { - return s_info.fd; + return s_info.fd; } const char *client_addr(void) { - return s_info.client_addr; + return s_info.client_addr; } const char *client_direct_addr(void) { - return s_info.direct_addr; + return s_info.direct_addr; } int client_direct_fd(void) { - return s_info.direct_fd; + return s_info.direct_fd; } int client_fini(void) { - int ret; + int ret; - (void)file_service_fini(); + (void)file_service_fini(); - ret = vconf_ignore_key_changed(VCONFKEY_MASTER_STARTED, master_started_cb); - if (ret < 0) { - DbgPrint("Ignore vconf key: %d\n", ret); - } + ret = vconf_ignore_key_changed(VCONFKEY_MASTER_STARTED, master_started_cb); + if (ret < 0) { + DbgPrint("Ignore vconf key: %d\n", ret); + } - com_core_del_event_callback(CONNECTOR_DISCONNECTED, disconnected_cb, NULL); - com_core_del_event_callback(CONNECTOR_CONNECTED, connected_cb, NULL); - com_core_packet_client_fini(s_info.fd); - s_info.fd = -1; + com_core_del_event_callback(CONNECTOR_DISCONNECTED, disconnected_cb, NULL); + com_core_del_event_callback(CONNECTOR_CONNECTED, connected_cb, NULL); + com_core_packet_client_fini(s_info.fd); + s_info.fd = -1; - if (s_info.direct_fd >= 0) { - com_core_packet_server_fini(s_info.direct_fd); - s_info.direct_fd = -1; - } + if (s_info.direct_fd >= 0) { + com_core_packet_server_fini(s_info.direct_fd); + s_info.direct_fd = -1; + } - free(s_info.client_addr); - s_info.client_addr = NULL; + free(s_info.client_addr); + s_info.client_addr = NULL; - free(s_info.direct_addr); - s_info.direct_addr = NULL; - return DBOX_STATUS_ERROR_NONE; + free(s_info.direct_addr); + s_info.direct_addr = NULL; + return DBOX_STATUS_ERROR_NONE; } /* End of a file */ diff --git a/src/conf.c b/src/conf.c index e2c2a1c..fe0a448 100644 --- a/src/conf.c +++ b/src/conf.c @@ -1,69 +1,82 @@ #include +#include static struct info { - int manual_sync; - int frame_drop_for_resizing; - int shared_content; - int direct_update; + int manual_sync; + int frame_drop_for_resizing; + int shared_content; + int direct_update; + int extra_buffer_count; - double event_filter; + double event_filter; } s_info = { - .manual_sync = 0, - .frame_drop_for_resizing = 1, - .shared_content = 0, - .direct_update = 0, + .manual_sync = 0, + .frame_drop_for_resizing = 1, + .shared_content = 0, + .direct_update = 0, + .extra_buffer_count = 0, - .event_filter = 0.01f, + .event_filter = 0.01f, }; void conf_set_direct_update(int flag) { - s_info.direct_update = flag; + s_info.direct_update = flag; } int conf_direct_update(void) { - return s_info.direct_update; + return s_info.direct_update; } void conf_set_manual_sync(int flag) { - s_info.manual_sync = flag; + s_info.manual_sync = flag; } int conf_manual_sync(void) { - return s_info.manual_sync; + return s_info.manual_sync; } void conf_set_frame_drop_for_resizing(int flag) { - s_info.frame_drop_for_resizing = flag; + s_info.frame_drop_for_resizing = flag; } int conf_frame_drop_for_resizing(void) { - return s_info.frame_drop_for_resizing; + return s_info.frame_drop_for_resizing; } void conf_set_shared_content(int flag) { - s_info.shared_content = flag; + s_info.shared_content = flag; } int conf_shared_content(void) { - return s_info.shared_content; + return s_info.shared_content; } double conf_event_filter(void) { - return s_info.event_filter; + return s_info.event_filter; } void conf_set_event_filter(double filter) { - s_info.event_filter = filter; + s_info.event_filter = filter; +} + +void conf_set_extra_buffer_count(int buffer_count) +{ + s_info.extra_buffer_count = buffer_count; +} + +int conf_extra_buffer_count(void) +{ + return s_info.extra_buffer_count; } /* End of a file */ diff --git a/src/desc_parser.c b/src/desc_parser.c index d0be33d..63b6036 100644 --- a/src/desc_parser.c +++ b/src/desc_parser.c @@ -28,6 +28,7 @@ #include #include #include +#include #include "debug.h" #include "dynamicbox.h" @@ -40,658 +41,658 @@ #define INFO_CATEGORY "category" static const char *type_list[] = { - "access", - "access,operation", - "color", - "drag", - "image", - "info", - "script", - "signal", - "text", - NULL + "access", + "access,operation", + "color", + "drag", + "image", + "info", + "script", + "signal", + "text", + NULL }; static const char *field_list[] = { - "type", - "part", - "data", - "option", - "id", - "target", - "file", - NULL + "type", + "part", + "data", + "option", + "id", + "target", + "file", + NULL }; enum block_type { - TYPE_ACCESS, - TYPE_ACCESS_OP, - TYPE_COLOR, - TYPE_DRAG, - TYPE_IMAGE, - TYPE_INFO, - TYPE_SCRIPT, - TYPE_SIGNAL, - TYPE_TEXT, - TYPE_MAX + TYPE_ACCESS, + TYPE_ACCESS_OP, + TYPE_COLOR, + TYPE_DRAG, + TYPE_IMAGE, + TYPE_INFO, + TYPE_SCRIPT, + TYPE_SIGNAL, + TYPE_TEXT, + TYPE_MAX }; enum field_type { - FIELD_TYPE, - FIELD_PART, - FIELD_DATA, - FIELD_OPTION, - FIELD_ID, - FIELD_TARGET, - FIELD_FILE + FIELD_TYPE, + FIELD_PART, + FIELD_DATA, + FIELD_OPTION, + FIELD_ID, + FIELD_TARGET, + FIELD_FILE }; struct block { - enum block_type type; - char *part; - char *data; - char *option; - char *id; - char *target; - char *file; - - /* Should be released */ - char *filebuf; - const char *filename; + enum block_type type; + char *part; + char *data; + char *option; + char *id; + char *target; + char *file; + + /* Should be released */ + char *filebuf; + const char *filename; }; static int update_text(dynamicbox_h handle, struct block *block, int is_gbar) { - struct dynamicbox_script_operators *ops; + struct dynamicbox_script_operators *ops; - if (!block || !block->part || !block->data) { - ErrPrint("Invalid argument\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!block || !block->part || !block->data) { + ErrPrint("Invalid argument\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - ops = is_gbar ? &handle->cbs.gbar_ops : &handle->cbs.dbox_ops; - if (ops->update_text) { - ops->update_text(handle, (const char *)block->id, (const char *)block->part, (const char *)block->data); - } + ops = is_gbar ? &handle->cbs.gbar_ops : &handle->cbs.dbox_ops; + if (ops->update_text) { + ops->update_text(handle, (const char *)block->id, (const char *)block->part, (const char *)block->data); + } - return 0; + return 0; } static int update_image(dynamicbox_h handle, struct block *block, int is_gbar) { - struct dynamicbox_script_operators *ops; + struct dynamicbox_script_operators *ops; - if (!block || !block->part) { - ErrPrint("Invalid argument\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!block || !block->part) { + ErrPrint("Invalid argument\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - ops = is_gbar ? &handle->cbs.gbar_ops : &handle->cbs.dbox_ops; - if (ops->update_image) { - ops->update_image(handle, block->id, block->part, block->data, block->option); - } + ops = is_gbar ? &handle->cbs.gbar_ops : &handle->cbs.dbox_ops; + if (ops->update_image) { + ops->update_image(handle, block->id, block->part, block->data, block->option); + } - return 0; + return 0; } static int update_script(dynamicbox_h handle, struct block *block, int is_gbar) { - struct dynamicbox_script_operators *ops; + struct dynamicbox_script_operators *ops; - if (!block || !block->part) { - ErrPrint("Invalid argument\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!block || !block->part) { + ErrPrint("Invalid argument\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - ops = is_gbar ? &handle->cbs.gbar_ops : &handle->cbs.dbox_ops; - if (ops->update_script) { - ops->update_script(handle, block->id, block->target, block->part, block->data, block->option); - } + ops = is_gbar ? &handle->cbs.gbar_ops : &handle->cbs.dbox_ops; + if (ops->update_script) { + ops->update_script(handle, block->id, block->target, block->part, block->data, block->option); + } - return 0; + return 0; } static int update_signal(dynamicbox_h handle, struct block *block, int is_gbar) { - struct dynamicbox_script_operators *ops; + struct dynamicbox_script_operators *ops; - if (!block) { - ErrPrint("Invalid argument\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!block) { + ErrPrint("Invalid argument\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - ops = is_gbar ? &handle->cbs.gbar_ops : &handle->cbs.dbox_ops; - if (ops->update_signal) { - ops->update_signal(handle, block->id, block->data, block->part); - } + ops = is_gbar ? &handle->cbs.gbar_ops : &handle->cbs.dbox_ops; + if (ops->update_signal) { + ops->update_signal(handle, block->id, block->data, block->part); + } - return 0; + return 0; } static int update_drag(dynamicbox_h handle, struct block *block, int is_gbar) { - double dx, dy; - struct dynamicbox_script_operators *ops; + double dx, dy; + struct dynamicbox_script_operators *ops; - if (!block || !block->data || !block->part) { - ErrPrint("Invalid argument\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!block || !block->data || !block->part) { + ErrPrint("Invalid argument\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (sscanf(block->data, "%lfx%lf", &dx, &dy) != 2) { - ErrPrint("Invalid format of data\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (sscanf(block->data, "%lfx%lf", &dx, &dy) != 2) { + ErrPrint("Invalid format of data\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - ops = is_gbar ? &handle->cbs.gbar_ops : &handle->cbs.dbox_ops; - if (ops->update_drag) { - ops->update_drag(handle, block->id, block->part, dx, dy); - } + ops = is_gbar ? &handle->cbs.gbar_ops : &handle->cbs.dbox_ops; + if (ops->update_drag) { + ops->update_drag(handle, block->id, block->part, dx, dy); + } - return 0; + return 0; } static int update_info(dynamicbox_h handle, struct block *block, int is_gbar) { - struct dynamicbox_script_operators *ops; - - if (!block || !block->part || !block->data) { - ErrPrint("Invalid argument\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - ops = is_gbar ? &handle->cbs.gbar_ops : &handle->cbs.dbox_ops; - if (!strcasecmp(block->part, INFO_SIZE)) { - int w, h; - - if (sscanf(block->data, "%dx%d", &w, &h) != 2) { - ErrPrint("Invalid format (%s)\n", block->data); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - if (ops->update_info_size) { - ops->update_info_size(handle, block->id, w, h); - } - } else if (!strcasecmp(block->part, INFO_CATEGORY)) { - if (ops->update_info_category) { - ops->update_info_category(handle, block->id, block->data); - } - } - - return 0; + struct dynamicbox_script_operators *ops; + + if (!block || !block->part || !block->data) { + ErrPrint("Invalid argument\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + ops = is_gbar ? &handle->cbs.gbar_ops : &handle->cbs.dbox_ops; + if (!strcasecmp(block->part, INFO_SIZE)) { + int w, h; + + if (sscanf(block->data, "%dx%d", &w, &h) != 2) { + ErrPrint("Invalid format (%s)\n", block->data); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + if (ops->update_info_size) { + ops->update_info_size(handle, block->id, w, h); + } + } else if (!strcasecmp(block->part, INFO_CATEGORY)) { + if (ops->update_info_category) { + ops->update_info_category(handle, block->id, block->data); + } + } + + return 0; } static int update_access(dynamicbox_h handle, struct block *block, int is_gbar) { - struct dynamicbox_script_operators *ops; + struct dynamicbox_script_operators *ops; - if (!block) { - ErrPrint("Invalid argument\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!block) { + ErrPrint("Invalid argument\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - ops = is_gbar ? &handle->cbs.gbar_ops : &handle->cbs.dbox_ops; - if (ops->update_access) { - ops->update_access(handle, block->id, block->part, block->data, block->option); - } + ops = is_gbar ? &handle->cbs.gbar_ops : &handle->cbs.dbox_ops; + if (ops->update_access) { + ops->update_access(handle, block->id, block->part, block->data, block->option); + } - return 0; + return 0; } static int operate_access(dynamicbox_h handle, struct block *block, int is_gbar) { - struct dynamicbox_script_operators *ops; + struct dynamicbox_script_operators *ops; - if (!block) { - ErrPrint("Invalid argument\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!block) { + ErrPrint("Invalid argument\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - ops = is_gbar ? &handle->cbs.gbar_ops : &handle->cbs.dbox_ops; - if (ops->operate_access) { - ops->operate_access(handle, block->id, block->part, block->data, block->option); - } + ops = is_gbar ? &handle->cbs.gbar_ops : &handle->cbs.dbox_ops; + if (ops->operate_access) { + ops->operate_access(handle, block->id, block->part, block->data, block->option); + } - return 0; + return 0; } static int update_color(dynamicbox_h handle, struct block *block, int is_gbar) { - struct dynamicbox_script_operators *ops; + struct dynamicbox_script_operators *ops; - if (!block) { - ErrPrint("Invalid argument\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!block) { + ErrPrint("Invalid argument\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - ops = is_gbar ? &handle->cbs.gbar_ops : &handle->cbs.dbox_ops; - if (ops->update_color) { - ops->update_color(handle, block->id, block->part, block->data); - } + ops = is_gbar ? &handle->cbs.gbar_ops : &handle->cbs.dbox_ops; + if (ops->update_color) { + ops->update_color(handle, block->id, block->part, block->data); + } - return 0; + return 0; } static inline int update_begin(dynamicbox_h handle, int is_gbar) { - struct dynamicbox_script_operators *ops; + struct dynamicbox_script_operators *ops; - ops = is_gbar ? &handle->cbs.gbar_ops : &handle->cbs.dbox_ops; - if (ops->update_begin) { - ops->update_begin(handle); - } + ops = is_gbar ? &handle->cbs.gbar_ops : &handle->cbs.dbox_ops; + if (ops->update_begin) { + ops->update_begin(handle); + } - return 0; + return 0; } static inline int update_end(dynamicbox_h handle, int is_gbar) { - struct dynamicbox_script_operators *ops; + struct dynamicbox_script_operators *ops; - ops = is_gbar ? &handle->cbs.gbar_ops : &handle->cbs.dbox_ops; - if (ops->update_end) { - ops->update_end(handle); - } + ops = is_gbar ? &handle->cbs.gbar_ops : &handle->cbs.dbox_ops; + if (ops->update_end) { + ops->update_end(handle); + } - return 0; + return 0; } static inline void delete_block(struct block *block) { - free(block->filebuf); - free(block); + free(block->filebuf); + free(block); } static inline void consuming_parsed_block(dynamicbox_h handle, int is_gbar, struct block *block) { - typedef int (*update_function_t)(dynamicbox_h handle, struct block *block, int is_gbar); - static update_function_t updators[] = { - update_access, - operate_access, - update_color, - update_drag, - update_image, - update_info, - update_script, - update_signal, - update_text, - NULL - }; - - if (block->type >= 0 || block->type < TYPE_MAX) { - (void)updators[block->type](handle, block, is_gbar); - } else { - ErrPrint("Block type[%d] is not valid\n", block->type); - } + typedef int (*update_function_t)(dynamicbox_h handle, struct block *block, int is_gbar); + static update_function_t updators[] = { + update_access, + operate_access, + update_color, + update_drag, + update_image, + update_info, + update_script, + update_signal, + update_text, + NULL + }; + + if (block->type >= 0 || block->type < TYPE_MAX) { + (void)updators[block->type](handle, block, is_gbar); + } else { + ErrPrint("Block type[%d] is not valid\n", block->type); + } } static inline char *load_file(const char *filename) { - char *filebuf = NULL; - int fd; - off_t filesize; - int ret; - size_t readsize = 0; - - fd = open(filename, O_RDONLY); - if (fd < 0) { - ErrPrint("open: %s\n", strerror(errno)); - return NULL; - } - - filesize = lseek(fd, 0L, SEEK_END); - if (filesize == (off_t)-1) { - ErrPrint("lseek: %s\n", strerror(errno)); - goto errout; - } - - if (lseek(fd, 0L, SEEK_SET) < 0) { - ErrPrint("lseek: %s\n", strerror(errno)); - goto errout; - } - - filebuf = malloc(filesize + 1); - if (!filebuf) { - ErrPrint("malloc: %s\n", strerror(errno)); - goto errout; - } - - while (readsize < filesize) { - ret = read(fd, filebuf + readsize, (size_t)filesize - readsize); - if (ret < 0) { - if (errno == EINTR) { - DbgPrint("Read is interrupted\n"); - continue; - } - - ErrPrint("read: %s\n", strerror(errno)); - free(filebuf); - filebuf = NULL; - break; - } - - readsize += ret; - } - - if (filebuf) { - filebuf[readsize] = '\0'; - } - - /*! - * \note - * Now, we are ready to parse the filebuf. - */ + char *filebuf = NULL; + int fd; + off_t filesize; + int ret; + size_t readsize = 0; + + fd = open(filename, O_RDONLY); + if (fd < 0) { + ErrPrint("open: %s\n", strerror(errno)); + return NULL; + } + + filesize = lseek(fd, 0L, SEEK_END); + if (filesize == (off_t)-1) { + ErrPrint("lseek: %s\n", strerror(errno)); + goto errout; + } + + if (lseek(fd, 0L, SEEK_SET) < 0) { + ErrPrint("lseek: %s\n", strerror(errno)); + goto errout; + } + + filebuf = malloc(filesize + 1); + if (!filebuf) { + ErrPrint("malloc: %s\n", strerror(errno)); + goto errout; + } + + while (readsize < filesize) { + ret = read(fd, filebuf + readsize, (size_t)filesize - readsize); + if (ret < 0) { + if (errno == EINTR) { + DbgPrint("Read is interrupted\n"); + continue; + } + + ErrPrint("read: %s\n", strerror(errno)); + free(filebuf); + filebuf = NULL; + break; + } + + readsize += ret; + } + + if (filebuf) { + filebuf[readsize] = '\0'; + } + + /*! + * \note + * Now, we are ready to parse the filebuf. + */ errout: - if (close(fd) < 0) { - ErrPrint("close: %s\n", strerror(errno)); - } + if (close(fd) < 0) { + ErrPrint("close: %s\n", strerror(errno)); + } - return filebuf; + return filebuf; } int parse_desc(struct dynamicbox_common *common, const char *filename, int is_gbar) { - int type_idx = 0; - int type_len = 0; - int field_idx = 0; - int field_len = 0; - char *filebuf; - char *fileptr; - char *ptr = NULL; - struct block *block = NULL; - struct dlist *block_list = NULL; - struct dlist *l; - struct dlist *n; - struct dlist *handle_iterator; - dynamicbox_h handler; - enum state { - BEGIN, - FIELD, - DATA, - END, - DONE, - ERROR, - } state; - - filebuf = load_file(filename); - if (!filebuf) { - return DBOX_STATUS_ERROR_IO_ERROR; - } - - fileptr = filebuf; - - state = BEGIN; - while (*fileptr && state != ERROR) { - switch (state) { - case BEGIN: - if (*fileptr == '{') { - block = calloc(1, sizeof(*block)); - if (!block) { - ErrPrint("calloc: %s\n", strerror(errno)); - state = ERROR; - continue; - } - state = FIELD; - ptr = NULL; - } - break; - case FIELD: - if (isspace(*fileptr)) { - if (ptr != NULL) { - *fileptr = '\0'; - } - } else if (*fileptr == '=') { - *fileptr = '\0'; - ptr = NULL; - state = DATA; - } else if (ptr == NULL) { - ptr = fileptr; - field_idx = 0; - field_len = 0; - - while (field_list[field_idx]) { - if (field_list[field_idx][field_len] == *fileptr) { - break; - } - field_idx++; - } - - if (!field_list[field_idx]) { - ErrPrint("Invalid field\n"); - state = ERROR; - continue; - } - - field_len++; - } else { - if (field_list[field_idx][field_len] != *fileptr) { - field_idx++; - while (field_list[field_idx]) { - if (!strncmp(field_list[field_idx], fileptr - field_len, field_len)) { - break; - } else { - field_idx++; - } - } - - if (!field_list[field_idx]) { - state = ERROR; - ErrPrint("field is not valid\n"); - continue; - } - } - - field_len++; - } - break; - case DATA: - switch (field_idx) { - case FIELD_TYPE: - if (ptr == NULL) { - if (isspace(*fileptr)) { - break; - } - - if (*fileptr == '\0') { - state = ERROR; - ErrPrint("Type is not valid\n"); - continue; - } - - ptr = fileptr; - type_idx = 0; - type_len = 0; - } - - if (*fileptr && (*fileptr == '\n' || *fileptr == '\r' || *fileptr == '\f')) { - *fileptr = '\0'; - } - - if (type_list[type_idx][type_len] != *fileptr) { - type_idx++; - while (type_list[type_idx]) { - if (!strncmp(type_list[type_idx], fileptr - type_len, type_len)) { - break; - } else { - type_idx++; - } - } - - if (!type_list[type_idx]) { - state = ERROR; - ErrPrint("type is not valid (%s)\n", fileptr - type_len); - continue; - } - } - - if (!*fileptr) { - block->type = type_idx; - state = DONE; - ptr = NULL; - } - - type_len++; - break; - case FIELD_PART: - if (ptr == NULL) { - ptr = fileptr; - } - - if (*fileptr && (*fileptr == '\n' || *fileptr == '\r' || *fileptr == '\f')) { - *fileptr = '\0'; - } - - if (!*fileptr) { - block->part = ptr; - state = DONE; - ptr = NULL; - } - break; - case FIELD_DATA: - if (ptr == NULL) { - ptr = fileptr; - } - - if (*fileptr && (*fileptr == '\n' || *fileptr == '\r' || *fileptr == '\f')) { - *fileptr = '\0'; - } - - if (!*fileptr) { - block->data = ptr; - state = DONE; - ptr = NULL; - } - break; - case FIELD_OPTION: - if (ptr == NULL) { - ptr = fileptr; - } - - if (*fileptr && (*fileptr == '\n' || *fileptr == '\r' || *fileptr == '\f')) { - *fileptr = '\0'; - } - - if (!*fileptr) { - block->option = ptr; - state = DONE; - ptr = NULL; - } - break; - case FIELD_ID: - if (ptr == NULL) { - ptr = fileptr; - } - - if (*fileptr && (*fileptr == '\n' || *fileptr == '\r' || *fileptr == '\f')) { - *fileptr = '\0'; - } - - if (!*fileptr) { - block->id = ptr; - state = DONE; - ptr = NULL; - } - break; - case FIELD_TARGET: - if (ptr == NULL) { - ptr = fileptr; - } - - if (*fileptr && (*fileptr == '\n' || *fileptr == '\r' || *fileptr == '\f')) { - *fileptr = '\0'; - } - - if (!*fileptr) { - block->target = ptr; - state = DONE; - ptr = NULL; - } - break; - case FIELD_FILE: - if (ptr == NULL) { - ptr = fileptr; - } - - if (*fileptr && (*fileptr == '\n' || *fileptr == '\r' || *fileptr == '\f')) { - *fileptr = '\0'; - } - - if (!*fileptr) { - block->target = ptr; - state = DONE; - ptr = NULL; - } - default: - break; - } - - break; - case DONE: - if (isspace(*fileptr)) { - } else if (*fileptr == '}') { - state = BEGIN; - block->filename = filename; - block_list = dlist_append(block_list, block); - block = NULL; - } else { - state = FIELD; - continue; - } - break; - case END: - default: - break; - } - - fileptr++; - } - - if (state != BEGIN) { - struct dlist *l; - struct dlist *n; - ErrPrint("State %d\n", state); - - free(filebuf); - free(block); - - dlist_foreach_safe(block_list, l, n, block) { - free(block); - block_list = dlist_remove(block_list, l); - } - - return DBOX_STATUS_ERROR_FAULT; - } - - - block = dlist_data(dlist_prev(block_list)); - if (block) { - block->filebuf = filebuf; - } else { - ErrPrint("Last block is not exists (There is no parsed block)\n"); - free(filebuf); - } - - ErrPrint("Begin: Set content for object\n"); - dlist_foreach(common->dynamicbox_list, l, handler) { - update_begin(handler, is_gbar); - } - - dlist_foreach_safe(block_list, l, n, block) { - dlist_foreach(common->dynamicbox_list, handle_iterator, handler) { - consuming_parsed_block(handler, is_gbar, block); - } - - block_list = dlist_remove(block_list, l); - delete_block(block); - } - - dlist_foreach(common->dynamicbox_list, l, handler) { - update_end(handler, is_gbar); - } - ErrPrint("End: Set content for object\n"); - - return DBOX_STATUS_ERROR_NONE; + int type_idx = 0; + int type_len = 0; + int field_idx = 0; + int field_len = 0; + char *filebuf; + char *fileptr; + char *ptr = NULL; + struct block *block = NULL; + struct dlist *block_list = NULL; + struct dlist *l; + struct dlist *n; + struct dlist *handle_iterator; + dynamicbox_h handler; + enum state { + BEGIN, + FIELD, + DATA, + END, + DONE, + ERROR, + } state; + + filebuf = load_file(filename); + if (!filebuf) { + return DBOX_STATUS_ERROR_IO_ERROR; + } + + fileptr = filebuf; + + state = BEGIN; + while (*fileptr && state != ERROR) { + switch (state) { + case BEGIN: + if (*fileptr == '{') { + block = calloc(1, sizeof(*block)); + if (!block) { + ErrPrint("calloc: %s\n", strerror(errno)); + state = ERROR; + continue; + } + state = FIELD; + ptr = NULL; + } + break; + case FIELD: + if (isspace(*fileptr)) { + if (ptr != NULL) { + *fileptr = '\0'; + } + } else if (*fileptr == '=') { + *fileptr = '\0'; + ptr = NULL; + state = DATA; + } else if (ptr == NULL) { + ptr = fileptr; + field_idx = 0; + field_len = 0; + + while (field_list[field_idx]) { + if (field_list[field_idx][field_len] == *fileptr) { + break; + } + field_idx++; + } + + if (!field_list[field_idx]) { + ErrPrint("Invalid field\n"); + state = ERROR; + continue; + } + + field_len++; + } else { + if (field_list[field_idx][field_len] != *fileptr) { + field_idx++; + while (field_list[field_idx]) { + if (!strncmp(field_list[field_idx], fileptr - field_len, field_len)) { + break; + } else { + field_idx++; + } + } + + if (!field_list[field_idx]) { + state = ERROR; + ErrPrint("field is not valid\n"); + continue; + } + } + + field_len++; + } + break; + case DATA: + switch (field_idx) { + case FIELD_TYPE: + if (ptr == NULL) { + if (isspace(*fileptr)) { + break; + } + + if (*fileptr == '\0') { + state = ERROR; + ErrPrint("Type is not valid\n"); + continue; + } + + ptr = fileptr; + type_idx = 0; + type_len = 0; + } + + if (*fileptr && (*fileptr == '\n' || *fileptr == '\r' || *fileptr == '\f')) { + *fileptr = '\0'; + } + + if (type_list[type_idx][type_len] != *fileptr) { + type_idx++; + while (type_list[type_idx]) { + if (!strncmp(type_list[type_idx], fileptr - type_len, type_len)) { + break; + } else { + type_idx++; + } + } + + if (!type_list[type_idx]) { + state = ERROR; + ErrPrint("type is not valid (%s)\n", fileptr - type_len); + continue; + } + } + + if (!*fileptr) { + block->type = type_idx; + state = DONE; + ptr = NULL; + } + + type_len++; + break; + case FIELD_PART: + if (ptr == NULL) { + ptr = fileptr; + } + + if (*fileptr && (*fileptr == '\n' || *fileptr == '\r' || *fileptr == '\f')) { + *fileptr = '\0'; + } + + if (!*fileptr) { + block->part = ptr; + state = DONE; + ptr = NULL; + } + break; + case FIELD_DATA: + if (ptr == NULL) { + ptr = fileptr; + } + + if (*fileptr && (*fileptr == '\n' || *fileptr == '\r' || *fileptr == '\f')) { + *fileptr = '\0'; + } + + if (!*fileptr) { + block->data = ptr; + state = DONE; + ptr = NULL; + } + break; + case FIELD_OPTION: + if (ptr == NULL) { + ptr = fileptr; + } + + if (*fileptr && (*fileptr == '\n' || *fileptr == '\r' || *fileptr == '\f')) { + *fileptr = '\0'; + } + + if (!*fileptr) { + block->option = ptr; + state = DONE; + ptr = NULL; + } + break; + case FIELD_ID: + if (ptr == NULL) { + ptr = fileptr; + } + + if (*fileptr && (*fileptr == '\n' || *fileptr == '\r' || *fileptr == '\f')) { + *fileptr = '\0'; + } + + if (!*fileptr) { + block->id = ptr; + state = DONE; + ptr = NULL; + } + break; + case FIELD_TARGET: + if (ptr == NULL) { + ptr = fileptr; + } + + if (*fileptr && (*fileptr == '\n' || *fileptr == '\r' || *fileptr == '\f')) { + *fileptr = '\0'; + } + + if (!*fileptr) { + block->target = ptr; + state = DONE; + ptr = NULL; + } + break; + case FIELD_FILE: + if (ptr == NULL) { + ptr = fileptr; + } + + if (*fileptr && (*fileptr == '\n' || *fileptr == '\r' || *fileptr == '\f')) { + *fileptr = '\0'; + } + + if (!*fileptr) { + block->target = ptr; + state = DONE; + ptr = NULL; + } + default: + break; + } + + break; + case DONE: + if (isspace(*fileptr)) { + } else if (*fileptr == '}') { + state = BEGIN; + block->filename = filename; + block_list = dlist_append(block_list, block); + block = NULL; + } else { + state = FIELD; + continue; + } + break; + case END: + default: + break; + } + + fileptr++; + } + + if (state != BEGIN) { + struct dlist *l; + struct dlist *n; + ErrPrint("State %d\n", state); + + free(filebuf); + free(block); + + dlist_foreach_safe(block_list, l, n, block) { + free(block); + block_list = dlist_remove(block_list, l); + } + + return DBOX_STATUS_ERROR_FAULT; + } + + + block = dlist_data(dlist_prev(block_list)); + if (block) { + block->filebuf = filebuf; + } else { + ErrPrint("Last block is not exists (There is no parsed block)\n"); + free(filebuf); + } + + ErrPrint("Begin: Set content for object\n"); + dlist_foreach(common->dynamicbox_list, l, handler) { + update_begin(handler, is_gbar); + } + + dlist_foreach_safe(block_list, l, n, block) { + dlist_foreach(common->dynamicbox_list, handle_iterator, handler) { + consuming_parsed_block(handler, is_gbar, block); + } + + block_list = dlist_remove(block_list, l); + delete_block(block); + } + + dlist_foreach(common->dynamicbox_list, l, handler) { + update_end(handler, is_gbar); + } + ErrPrint("End: Set content for object\n"); + + return DBOX_STATUS_ERROR_NONE; } /* End of a file */ diff --git a/src/dlist.c b/src/dlist.c index 3ae571b..5f09555 100644 --- a/src/dlist.c +++ b/src/dlist.c @@ -35,155 +35,155 @@ */ struct dlist { - struct dlist *next; - struct dlist *prev; - void *data; + struct dlist *next; + struct dlist *prev; + void *data; }; struct dlist *dlist_append(struct dlist *list, void *data) { - struct dlist *item; + struct dlist *item; - item = malloc(sizeof(*item)); - if (!item) { - return NULL; - } + item = malloc(sizeof(*item)); + if (!item) { + return NULL; + } - item->next = NULL; - item->data = data; + item->next = NULL; + item->data = data; - if (!list) { - item->prev = item; + if (!list) { + item->prev = item; - list = item; - } else { - item->prev = list->prev; - item->prev->next = item; - list->prev = item; - } + list = item; + } else { + item->prev = list->prev; + item->prev->next = item; + list->prev = item; + } - assert(!list->prev->next && "item NEXT"); + assert(!list->prev->next && "item NEXT"); - return list; + return list; } struct dlist *dlist_prepend(struct dlist *list, void *data) { - struct dlist *item; + struct dlist *item; - item = malloc(sizeof(*item)); - if (!item) { - return NULL; - } + item = malloc(sizeof(*item)); + if (!item) { + return NULL; + } - item->data = data; + item->data = data; - if (!list) { - item->prev = item; - item->next = NULL; - } else { - if (list->prev->next) { - list->prev->next = item; - } + if (!list) { + item->prev = item; + item->next = NULL; + } else { + if (list->prev->next) { + list->prev->next = item; + } - item->prev = list->prev; - item->next = list; + item->prev = list->prev; + item->next = list; - list->prev = item; + list->prev = item; - } + } - return item; + return item; } struct dlist *dlist_remove(struct dlist *list, struct dlist *l) { - if (!list || !l) { - return NULL; - } - - if (l == list) { - list = l->next; - } else { - l->prev->next = l->next; - } - - if (l->next) { - l->next->prev = l->prev; - } - /*! - * \note - * If the removed entry 'l' has no next element, it is the last element. - * In this case, check the existence of the list first, - * and if the list is not empty, update the 'prev' of the list (which is a head element of the list) - * - * If we didn't care about this, the head element(list) can indicates the invalid element. - */ - else if (list) { - list->prev = l->prev; - } - - free(l); - return list; + if (!list || !l) { + return NULL; + } + + if (l == list) { + list = l->next; + } else { + l->prev->next = l->next; + } + + if (l->next) { + l->next->prev = l->prev; + } + /*! + * \note + * If the removed entry 'l' has no next element, it is the last element. + * In this case, check the existence of the list first, + * and if the list is not empty, update the 'prev' of the list (which is a head element of the list) + * + * If we didn't care about this, the head element(list) can indicates the invalid element. + */ + else if (list) { + list->prev = l->prev; + } + + free(l); + return list; } struct dlist *dlist_find_data(struct dlist *list, void *data) { - struct dlist *l; - void *_data; + struct dlist *l; + void *_data; - dlist_foreach(list, l, _data) { - if (data == _data) { - return l; - } - } + dlist_foreach(list, l, _data) { + if (data == _data) { + return l; + } + } - return NULL; + return NULL; } void *dlist_data(struct dlist *l) { - return l ? l->data : NULL; + return l ? l->data : NULL; } struct dlist *dlist_next(struct dlist *l) { - return l ? l->next : NULL; + return l ? l->next : NULL; } struct dlist *dlist_prev(struct dlist *l) { - return l ? l->prev : NULL; + return l ? l->prev : NULL; } int dlist_count(struct dlist *l) { - register int i; - struct dlist *n; - void *data; + register int i; + struct dlist *n; + void *data; - i = 0; - dlist_foreach(l, n, data) { - i++; - } + i = 0; + dlist_foreach(l, n, data) { + i++; + } - return i; + return i; } struct dlist *dlist_nth(struct dlist *l, int nth) { - register int i; - struct dlist *n; - - i = 0; - for (n = l; n; n = n->next) { - if (i == nth) { - return n; - } - i++; - } - - return NULL; + register int i; + struct dlist *n; + + i = 0; + for (n = l; n; n = n->next) { + if (i == nth) { + return n; + } + i++; + } + + return NULL; } /* End of a file */ diff --git a/src/dynamicbox.c b/src/dynamicbox.c index 7dc2bd6..a0cd054 100644 --- a/src/dynamicbox.c +++ b/src/dynamicbox.c @@ -56,965 +56,1116 @@ FILE *__file_log_fp; static int default_launch_handler(dynamicbox_h handler, const char *appid, void *data); static struct info { - int init_count; - int prevent_overwrite; - guint job_timer; - struct dlist *job_list; - - struct launch { - int (*handler)(dynamicbox_h handler, const char *appid, void *data); - void *data; - } launch; + int init_count; + int prevent_overwrite; + guint job_timer; + struct dlist *job_list; + + struct launch { + int (*handler)(dynamicbox_h handler, const char *appid, void *data); + void *data; + } launch; } s_info = { - .init_count = 0, - .prevent_overwrite = 0, - .job_timer = 0, - .job_list = NULL, - .launch = { - .handler = default_launch_handler, - .data = NULL, - }, + .init_count = 0, + .prevent_overwrite = 0, + .job_timer = 0, + .job_list = NULL, + .launch = { + .handler = default_launch_handler, + .data = NULL, + }, }; static void dbox_pixmap_acquired_cb(dynamicbox_h handler, const struct packet *result, void *data); static void gbar_pixmap_acquired_cb(dynamicbox_h handler, const struct packet *result, void *data); +static void gbar_xpixmap_acquired_cb(dynamicbox_h handler, const struct packet *result, void *data); +static void dbox_xpixmap_acquired_cb(dynamicbox_h handler, const struct packet *result, void *data); static int default_launch_handler(dynamicbox_h handler, const char *appid, void *data) { - int ret; + int ret; - ret = aul_launch_app(appid, NULL); - if (ret <= 0) { - ErrPrint("Failed to launch an app %s (%d)\n", appid, ret); - } + ret = aul_launch_app(appid, NULL); + if (ret <= 0) { + ErrPrint("Failed to launch an app %s (%d)\n", appid, ret); + } -/* - app_control_h service; + /* + app_control_h service; - DbgPrint("AUTO_LAUNCH [%s]\n", handler->common->dbox.auto_launch); + DbgPrint("AUTO_LAUNCH [%s]\n", handler->common->dbox.auto_launch); - ret = app_control_create(&service); - if (ret == APP_CONTROL_ERROR_NONE) { - app_control_set_package(service, handler->common->dbox.auto_launch); - app_control_send_launch_request(service, NULL, NULL); - app_control_destroy(service); - } else { - ErrPrint("Failed to launch an app %s (%d)\n", handler->common->dbox.auto_launch, ret); - } -*/ + ret = app_control_create(&service); + if (ret == APP_CONTROL_ERROR_NONE) { + app_control_set_package(service, handler->common->dbox.auto_launch); + app_control_send_launch_request(service, NULL, NULL); + app_control_destroy(service); + } else { + ErrPrint("Failed to launch an app %s (%d)\n", handler->common->dbox.auto_launch, ret); + } + */ - return ret > 0 ? DBOX_STATUS_ERROR_NONE : DBOX_STATUS_ERROR_FAULT; + return ret > 0 ? DBOX_STATUS_ERROR_NONE : DBOX_STATUS_ERROR_FAULT; } static inline void default_create_cb(dynamicbox_h handler, int ret, void *data) { - DbgPrint("Default created event handler: %d\n", ret); + DbgPrint("Default created event handler: %d\n", ret); } static inline void default_pinup_cb(dynamicbox_h handler, int ret, void *data) { - DbgPrint("Default pinup event handler: %d\n", ret); + DbgPrint("Default pinup event handler: %d\n", ret); } static inline void default_group_changed_cb(dynamicbox_h handler, int ret, void *data) { - DbgPrint("Default group changed event handler: %d\n", ret); + DbgPrint("Default group changed event handler: %d\n", ret); } static inline void default_period_changed_cb(dynamicbox_h handler, int ret, void *data) { - DbgPrint("Default period changed event handler: %d\n", ret); + DbgPrint("Default period changed event handler: %d\n", ret); } static inline void default_gbar_created_cb(dynamicbox_h handler, int ret, void *data) { - DbgPrint("Default GBAR created event handler: %d\n", ret); + DbgPrint("Default GBAR created event handler: %d\n", ret); } static inline void default_gbar_destroyed_cb(dynamicbox_h handler, int ret, void *data) { - DbgPrint("Default GBAR destroyed event handler: %d\n", ret); + DbgPrint("Default GBAR destroyed event handler: %d\n", ret); } static inline void default_dbox_size_changed_cb(dynamicbox_h handler, int ret, void *data) { - DbgPrint("Default DBOX size changed event handler: %d\n", ret); + DbgPrint("Default DBOX size changed event handler: %d\n", ret); } static inline void default_update_mode_cb(dynamicbox_h handler, int ret, void *data) { - DbgPrint("Default update mode set event handler: %d\n", ret); + DbgPrint("Default update mode set event handler: %d\n", ret); } static inline void default_access_event_cb(dynamicbox_h handler, int ret, void *data) { - DbgPrint("Default access event handler: %d\n", ret); + DbgPrint("Default access event handler: %d\n", ret); } static inline void default_key_event_cb(dynamicbox_h handler, int ret, void *data) { - DbgPrint("Default key event handler: %d\n", ret); + DbgPrint("Default key event handler: %d\n", ret); } static void update_mode_cb(dynamicbox_h handler, const struct packet *result, void *data) { - int ret; + int ret; - if (!result) { - ret = DBOX_STATUS_ERROR_FAULT; - goto errout; - } else if (packet_get(result, "i", &ret) != 1) { - ErrPrint("Invalid argument\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto errout; - } + if (!result) { + ret = DBOX_STATUS_ERROR_FAULT; + goto errout; + } else if (packet_get(result, "i", &ret) != 1) { + ErrPrint("Invalid argument\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto errout; + } - if (ret < 0) { - ErrPrint("Resize request is failed: %d\n", ret); - goto errout; - } + if (ret < 0) { + ErrPrint("Resize request is failed: %d\n", ret); + goto errout; + } - return; + return; errout: - handler->cbs.update_mode.cb(handler, ret, handler->cbs.update_mode.data); - handler->cbs.update_mode.cb = NULL; - handler->cbs.update_mode.data = NULL; - handler->common->request.update_mode = 0; + handler->cbs.update_mode.cb(handler, ret, handler->cbs.update_mode.data); + handler->cbs.update_mode.cb = NULL; + handler->cbs.update_mode.data = NULL; + handler->common->request.update_mode = 0; - if (ret == (int)DBOX_STATUS_ERROR_NOT_EXIST && handler->refcnt == 2) { - dbox_invoke_event_handler(handler, DBOX_EVENT_DELETED); - dbox_unref(handler, 1); - } + if (handler->common->state != DBOX_STATE_DELETE) { + if (ret == (int)DBOX_STATUS_ERROR_NOT_EXIST && handler->refcnt == 2) { + dbox_invoke_event_handler(handler, DBOX_EVENT_DELETED); + dbox_unref(handler, 1); + } + } } static void resize_cb(dynamicbox_h handler, const struct packet *result, void *data) { - int ret; - - if (!result) { - ret = DBOX_STATUS_ERROR_FAULT; - goto errout; - } else if (packet_get(result, "i", &ret) != 1) { - ErrPrint("Invalid argument\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto errout; - } - - /*! - * \note - * In case of resize request, - * The dynamicbox handler will not have resized value right after this callback, - * It can only get the new size when it makes updates. - * - * So the user can only get the resized value(result) from the first update event - * after this request. - */ - if (ret < 0) { - ErrPrint("Resize request is failed: %d\n", ret); - goto errout; - } - - return; + int ret; + + if (!result) { + ret = DBOX_STATUS_ERROR_FAULT; + goto errout; + } else if (packet_get(result, "i", &ret) != 1) { + ErrPrint("Invalid argument\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto errout; + } + + /*! + * \note + * In case of resize request, + * The dynamicbox handler will not have resized value right after this callback, + * It can only get the new size when it makes updates. + * + * So the user can only get the resized value(result) from the first update event + * after this request. + */ + if (ret < 0) { + ErrPrint("Resize request is failed: %d\n", ret); + goto errout; + } + + return; errout: - handler->cbs.size_changed.cb(handler, ret, handler->cbs.size_changed.data); - handler->cbs.size_changed.cb = NULL; - handler->cbs.size_changed.data = NULL; - handler->common->request.size_changed = 0; + handler->cbs.size_changed.cb(handler, ret, handler->cbs.size_changed.data); + handler->cbs.size_changed.cb = NULL; + handler->cbs.size_changed.data = NULL; + handler->common->request.size_changed = 0; - if (ret == (int)DBOX_STATUS_ERROR_NOT_EXIST && handler->refcnt == 2) { - dbox_invoke_event_handler(handler, DBOX_EVENT_DELETED); - dbox_unref(handler, 1); - } + if (handler->common->state != DBOX_STATE_DELETE) { + if (ret == (int)DBOX_STATUS_ERROR_NOT_EXIST && handler->refcnt == 2) { + dbox_invoke_event_handler(handler, DBOX_EVENT_DELETED); + dbox_unref(handler, 1); + } + } } static void text_signal_cb(dynamicbox_h handler, const struct packet *result, void *data) { - int ret; - void *cbdata; - struct cb_info *info = data; - dynamicbox_ret_cb cb; + int ret; + void *cbdata; + struct cb_info *info = data; + dynamicbox_ret_cb cb; - cbdata = info->data; - cb = info->cb; - dbox_destroy_cb_info(info); + cbdata = info->data; + cb = info->cb; + dbox_destroy_cb_info(info); - if (!result) { - ret = DBOX_STATUS_ERROR_FAULT; - } else if (packet_get(result, "i", &ret) != 1) { - ErrPrint("Invalid argument\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!result) { + ret = DBOX_STATUS_ERROR_FAULT; + } else if (packet_get(result, "i", &ret) != 1) { + ErrPrint("Invalid argument\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (cb) { - cb(handler, ret, cbdata); - } - return; + if (cb) { + cb(handler, ret, cbdata); + } + return; } static void set_group_ret_cb(dynamicbox_h handler, const struct packet *result, void *data) { - int ret; + int ret; - if (!result) { - ret = DBOX_STATUS_ERROR_FAULT; - goto errout; - } else if (packet_get(result, "i", &ret) != 1) { - ErrPrint("Invalid argument\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto errout; - } + if (!result) { + ret = DBOX_STATUS_ERROR_FAULT; + goto errout; + } else if (packet_get(result, "i", &ret) != 1) { + ErrPrint("Invalid argument\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto errout; + } - if (ret < 0) { - goto errout; - } + if (ret < 0) { + goto errout; + } - return; + return; errout: - handler->cbs.group_changed.cb(handler, ret, handler->cbs.group_changed.data); - handler->cbs.group_changed.cb = NULL; - handler->cbs.group_changed.data = NULL; - handler->common->request.group_changed = 0; + handler->cbs.group_changed.cb(handler, ret, handler->cbs.group_changed.data); + handler->cbs.group_changed.cb = NULL; + handler->cbs.group_changed.data = NULL; + handler->common->request.group_changed = 0; - if (ret == (int)DBOX_STATUS_ERROR_NOT_EXIST && handler->refcnt == 2) { - dbox_invoke_event_handler(handler, DBOX_EVENT_DELETED); - dbox_unref(handler, 1); - } + if (handler->common->state != DBOX_STATE_DELETE) { + if (ret == (int)DBOX_STATUS_ERROR_NOT_EXIST && handler->refcnt == 2) { + dbox_invoke_event_handler(handler, DBOX_EVENT_DELETED); + dbox_unref(handler, 1); + } + } } static void period_ret_cb(dynamicbox_h handler, const struct packet *result, void *data) { - int ret; + int ret; - if (!result) { - ret = DBOX_STATUS_ERROR_FAULT; - goto errout; - } else if (packet_get(result, "i", &ret) != 1) { - ErrPrint("Invalid argument\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto errout; - } + if (!result) { + ret = DBOX_STATUS_ERROR_FAULT; + goto errout; + } else if (packet_get(result, "i", &ret) != 1) { + ErrPrint("Invalid argument\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto errout; + } - if (ret < 0) { - goto errout; - } + if (ret < 0) { + goto errout; + } - return; + return; errout: - handler->cbs.period_changed.cb(handler, ret, handler->cbs.period_changed.data); - handler->cbs.period_changed.cb = NULL; - handler->cbs.period_changed.data = NULL; - handler->common->request.period_changed = 0; + handler->cbs.period_changed.cb(handler, ret, handler->cbs.period_changed.data); + handler->cbs.period_changed.cb = NULL; + handler->cbs.period_changed.data = NULL; + handler->common->request.period_changed = 0; - if (ret == (int)DBOX_STATUS_ERROR_NOT_EXIST && handler->refcnt == 2) { - dbox_invoke_event_handler(handler, DBOX_EVENT_DELETED); - dbox_unref(handler, 1); - } + if (handler->common->state != DBOX_STATE_DELETE) { + if (ret == (int)DBOX_STATUS_ERROR_NOT_EXIST && handler->refcnt == 2) { + dbox_invoke_event_handler(handler, DBOX_EVENT_DELETED); + dbox_unref(handler, 1); + } + } } static void gbar_create_cb(dynamicbox_h handler, const struct packet *result, void *data) { - int ret; + int ret; - if (!result) { - ret = DBOX_STATUS_ERROR_FAULT; - goto errout; - } else if (packet_get(result, "i", &ret) != 1) { - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - goto errout; - } + if (!result) { + ret = DBOX_STATUS_ERROR_FAULT; + goto errout; + } else if (packet_get(result, "i", &ret) != 1) { + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + goto errout; + } - if (ret < 0) { - ErrPrint("Failed to create a GBAR[%d]\n", ret); - goto errout; - } + if (ret < 0) { + ErrPrint("Failed to create a GBAR[%d]\n", ret); + goto errout; + } - return; + return; errout: - handler->cbs.gbar_created.cb(handler, ret, handler->cbs.gbar_created.data); - handler->cbs.gbar_created.cb = NULL; - handler->cbs.gbar_created.data = NULL; - handler->common->request.gbar_created = 0; + handler->cbs.gbar_created.cb(handler, ret, handler->cbs.gbar_created.data); + handler->cbs.gbar_created.cb = NULL; + handler->cbs.gbar_created.data = NULL; + handler->common->request.gbar_created = 0; - if (ret == (int)DBOX_STATUS_ERROR_NOT_EXIST && handler->refcnt == 2) { - dbox_invoke_event_handler(handler, DBOX_EVENT_DELETED); - dbox_unref(handler, 1); - } + if (handler->common->state != DBOX_STATE_DELETE) { + if (ret == (int)DBOX_STATUS_ERROR_NOT_EXIST && handler->refcnt == 2) { + dbox_invoke_event_handler(handler, DBOX_EVENT_DELETED); + dbox_unref(handler, 1); + } + } } static void activated_cb(dynamicbox_h handler, const struct packet *result, void *data) { - int ret; - struct cb_info *info = data; - void *cbdata; - dynamicbox_ret_cb cb; - const char *pkgname = ""; + int ret; + struct cb_info *info = data; + void *cbdata; + dynamicbox_ret_cb cb; + const char *pkgname = ""; - cbdata = info->data; - cb = info->cb; - dbox_destroy_cb_info(info); + cbdata = info->data; + cb = info->cb; + dbox_destroy_cb_info(info); - if (!result) { - ret = DBOX_STATUS_ERROR_FAULT; - } else if (packet_get(result, "is", &ret, &pkgname) != 2) { - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!result) { + ret = DBOX_STATUS_ERROR_FAULT; + } else if (packet_get(result, "is", &ret, &pkgname) != 2) { + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (cb) { - cb(handler, ret, cbdata); - } + if (cb) { + cb(handler, ret, cbdata); + } } static void gbar_destroy_cb(dynamicbox_h handler, const struct packet *result, void *data) { - int ret; - dynamicbox_ret_cb cb; - void *cbdata; - struct cb_info *info = data; + int ret; + dynamicbox_ret_cb cb; + void *cbdata; + struct cb_info *info = data; - cbdata = info->data; - cb = info->cb; - dbox_destroy_cb_info(info); + cbdata = info->data; + cb = info->cb; + dbox_destroy_cb_info(info); - if (!result) { - ErrPrint("Result is NIL (may connection lost)\n"); - ret = DBOX_STATUS_ERROR_FAULT; - } else if (packet_get(result, "i", &ret) != 1) { - ErrPrint("Invalid parameter\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!result) { + ErrPrint("Result is NIL (may connection lost)\n"); + ret = DBOX_STATUS_ERROR_FAULT; + } else if (packet_get(result, "i", &ret) != 1) { + ErrPrint("Invalid parameter\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (ret == (int)DBOX_STATUS_ERROR_NONE) { - handler->cbs.gbar_destroyed.cb = cb; - handler->cbs.gbar_destroyed.data = cbdata; - } else { - handler->common->is_gbar_created = 0; - handler->common->request.gbar_destroyed = 0; + if (ret == (int)DBOX_STATUS_ERROR_NONE) { + handler->cbs.gbar_destroyed.cb = cb; + handler->cbs.gbar_destroyed.data = cbdata; + } else { + handler->common->is_gbar_created = 0; + handler->common->request.gbar_destroyed = 0; - if (cb) { - cb(handler, ret, cbdata); - } - } + if (cb) { + cb(handler, ret, cbdata); + } + } } static void delete_cluster_cb(dynamicbox_h handler, const struct packet *result, void *data) { - struct cb_info *info = data; - int ret; - dynamicbox_ret_cb cb; - void *cbdata; + struct cb_info *info = data; + int ret; + dynamicbox_ret_cb cb; + void *cbdata; - cb = info->cb; - cbdata = info->data; - dbox_destroy_cb_info(info); + cb = info->cb; + cbdata = info->data; + dbox_destroy_cb_info(info); - if (!result) { - ret = DBOX_STATUS_ERROR_FAULT; - } else if (packet_get(result, "i", &ret) != 1) { - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!result) { + ret = DBOX_STATUS_ERROR_FAULT; + } else if (packet_get(result, "i", &ret) != 1) { + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (cb) { - cb(handler, ret, cbdata); - } + if (cb) { + cb(handler, ret, cbdata); + } } static void delete_category_cb(dynamicbox_h handler, const struct packet *result, void *data) { - struct cb_info *info = data; - int ret; - dynamicbox_ret_cb cb; - void *cbdata; + struct cb_info *info = data; + int ret; + dynamicbox_ret_cb cb; + void *cbdata; - cb = info->cb; - cbdata = info->data; - dbox_destroy_cb_info(info); + cb = info->cb; + cbdata = info->data; + dbox_destroy_cb_info(info); - if (!result) { - ret = DBOX_STATUS_ERROR_FAULT; - } else if (packet_get(result, "i", &ret) != 1) { - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!result) { + ret = DBOX_STATUS_ERROR_FAULT; + } else if (packet_get(result, "i", &ret) != 1) { + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (cb) { - cb(handler, ret, cbdata); - } + if (cb) { + cb(handler, ret, cbdata); + } } static int dbox_acquire_dbox_pixmap(dynamicbox_h handler, dynamicbox_ret_cb cb, void *data) { - struct packet *packet; - struct cb_info *cbinfo; - const char *id; - unsigned int cmd = CMD_DBOX_ACQUIRE_PIXMAP; - int ret; + struct packet *packet; + struct cb_info *cbinfo; + const char *id; + unsigned int cmd = CMD_DBOX_ACQUIRE_PIXMAP; + int ret; - id = fb_id(handler->common->dbox.fb); - if (!id || strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP))) { - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + id = fb_id(handler->common->dbox.fb); + if (!id || strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP))) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - packet = packet_create((const char *)&cmd, "ss", handler->common->pkgname, handler->common->id); - if (!packet) { - ErrPrint("Failed to build a param\n"); - return DBOX_STATUS_ERROR_FAULT; - } + packet = packet_create((const char *)&cmd, "ss", handler->common->pkgname, handler->common->id); + if (!packet) { + ErrPrint("Failed to build a param\n"); + return DBOX_STATUS_ERROR_FAULT; + } - cbinfo = dbox_create_cb_info(cb, data); - if (!cbinfo) { - packet_destroy(packet); - return DBOX_STATUS_ERROR_FAULT; - } + cbinfo = dbox_create_cb_info(cb, data); + if (!cbinfo) { + packet_destroy(packet); + return DBOX_STATUS_ERROR_FAULT; + } - ret = master_rpc_async_request(handler, packet, 0, dbox_pixmap_acquired_cb, cbinfo); - if (ret < 0) { - dbox_destroy_cb_info(cbinfo); - } + ret = master_rpc_async_request(handler, packet, 0, dbox_pixmap_acquired_cb, cbinfo); + if (ret < 0) { + dbox_destroy_cb_info(cbinfo); + } - return ret; + return ret; } static void dbox_pixmap_acquired_cb(dynamicbox_h handler, const struct packet *result, void *data) { - int pixmap; - int ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - dynamicbox_ret_cb cb; - void *cbdata; - struct cb_info *info = data; - - cb = info->cb; - cbdata = info->data; - dbox_destroy_cb_info(info); - - if (!result) { - pixmap = 0; /* PIXMAP 0 means error */ - } else if (packet_get(result, "ii", &pixmap, &ret) != 2) { - pixmap = 0; - } - - if (ret == (int)DBOX_STATUS_ERROR_BUSY) { - ret = dbox_acquire_dbox_pixmap(handler, cb, cbdata); - DbgPrint("Busy, Try again: %d\n", ret); - /* Try again */ - } else if (ret == (int)DBOX_STATUS_ERROR_NOT_EXIST && handler->refcnt == 2) { - if (cb) { - cb(handler, pixmap, cbdata); - } - - dbox_invoke_event_handler(handler, DBOX_EVENT_DELETED); - dbox_unref(handler, 1); - } else { - if (cb) { - cb(handler, pixmap, cbdata); - } - } + int pixmap; + int ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + dynamicbox_ret_cb cb; + void *cbdata; + struct cb_info *info = data; + + cb = info->cb; + cbdata = info->data; + dbox_destroy_cb_info(info); + + if (!result) { + pixmap = 0; /* PIXMAP 0 means error */ + } else if (packet_get(result, "ii", &pixmap, &ret) != 2) { + pixmap = 0; + } + + if (ret == (int)DBOX_STATUS_ERROR_BUSY) { + ret = dbox_acquire_dbox_pixmap(handler, cb, cbdata); + DbgPrint("Busy, Try again: %d\n", ret); + /* Try again */ + } else if (ret == (int)DBOX_STATUS_ERROR_NOT_EXIST && handler->refcnt == 2) { + if (cb) { + cb(handler, pixmap, cbdata); + } + + if (handler->common->state != DBOX_STATE_DELETE) { + dbox_invoke_event_handler(handler, DBOX_EVENT_DELETED); + dbox_unref(handler, 1); + } + } else { + if (cb) { + cb(handler, pixmap, cbdata); + } + } +} + +static void dbox_xpixmap_acquired_cb(dynamicbox_h handler, const struct packet *result, void *data) +{ + int pixmap; + int ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + dynamicbox_ret_cb cb; + void *cbdata; + struct cb_info *info = data; + + cb = info->cb; + cbdata = info->data; + dbox_destroy_cb_info(info); + + if (!result) { + pixmap = 0; + } else if (packet_get(result, "ii", &pixmap, &ret) != 2) { + pixmap = 0; + } + + if (cb) { + cb(handler, pixmap, cbdata); + } + + if (handler->common->state != DBOX_STATE_DELETE) { + if (ret == (int)DBOX_STATUS_ERROR_NOT_EXIST && handler->refcnt == 2) { + dbox_invoke_event_handler(handler, DBOX_EVENT_DELETED); + dbox_unref(handler, 1); + } + } +} + +static int dbox_acquire_gbar_extra_pixmap(dynamicbox_h handler, int idx, dynamicbox_ret_cb cb, void *data) +{ + struct packet *packet; + struct cb_info *cbinfo; + unsigned int cmd = CMD_GBAR_ACQUIRE_XPIXMAP; + int ret; + + packet = packet_create((const char *)&cmd, "ssi", handler->common->pkgname, handler->common->id, idx); + if (!packet) { + ErrPrint("Failed to build a param\n"); + return DBOX_STATUS_ERROR_FAULT; + } + + cbinfo = dbox_create_cb_info(cb, data); + if (!cbinfo) { + packet_destroy(packet); + return DBOX_STATUS_ERROR_FAULT; + } + + ret = master_rpc_async_request(handler, packet, 0, gbar_xpixmap_acquired_cb, cbinfo); + if (ret < 0) { + /*! + * \note + * Packet will be destroyed by master_rpc_async_request + */ + dbox_destroy_cb_info(cbinfo); + } + + return ret; +} + +static int dbox_acquire_dbox_extra_pixmap(dynamicbox_h handler, int idx, dynamicbox_ret_cb cb, void *data) +{ + struct packet *packet; + struct cb_info *cbinfo; + unsigned int cmd = CMD_DBOX_ACQUIRE_XPIXMAP; + int ret; + + packet = packet_create((const char *)&cmd, "ssi", handler->common->pkgname, handler->common->id, idx); + if (!packet) { + ErrPrint("Failed to build a param\n"); + return DBOX_STATUS_ERROR_FAULT; + } + + cbinfo = dbox_create_cb_info(cb, data); + if (!cbinfo) { + packet_destroy(packet); + return DBOX_STATUS_ERROR_FAULT; + } + + ret = master_rpc_async_request(handler, packet, 0, dbox_xpixmap_acquired_cb, cbinfo); + if (ret < 0) { + /*! + * \note + * Packet will be destroyed by master_rpc_async_request + */ + dbox_destroy_cb_info(cbinfo); + } + + return ret; } static int dbox_acquire_gbar_pixmap(dynamicbox_h handler, dynamicbox_ret_cb cb, void *data) { - struct packet *packet; - struct cb_info *cbinfo; - unsigned int cmd = CMD_GBAR_ACQUIRE_PIXMAP; - const char *id; - int ret; - - id = fb_id(handler->common->gbar.fb); - if (!id || strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP))) { - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - packet = packet_create((const char *)&cmd, "ss", handler->common->pkgname, handler->common->id); - if (!packet) { - ErrPrint("Failed to build a param\n"); - return DBOX_STATUS_ERROR_FAULT; - } - - cbinfo = dbox_create_cb_info(cb, data); - if (!cbinfo) { - packet_destroy(packet); - return DBOX_STATUS_ERROR_FAULT; - } - - ret = master_rpc_async_request(handler, packet, 0, gbar_pixmap_acquired_cb, cbinfo); - if (ret < 0) { - /*! - * \note - * Packet will be destroyed by master_rpc_async_request - */ - dbox_destroy_cb_info(cbinfo); - } - - return ret; + struct packet *packet; + struct cb_info *cbinfo; + unsigned int cmd = CMD_GBAR_ACQUIRE_PIXMAP; + const char *id; + int ret; + + id = fb_id(handler->common->gbar.fb); + if (!id || strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP))) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + packet = packet_create((const char *)&cmd, "ss", handler->common->pkgname, handler->common->id); + if (!packet) { + ErrPrint("Failed to build a param\n"); + return DBOX_STATUS_ERROR_FAULT; + } + + cbinfo = dbox_create_cb_info(cb, data); + if (!cbinfo) { + packet_destroy(packet); + return DBOX_STATUS_ERROR_FAULT; + } + + ret = master_rpc_async_request(handler, packet, 0, gbar_pixmap_acquired_cb, cbinfo); + if (ret < 0) { + /*! + * \note + * Packet will be destroyed by master_rpc_async_request + */ + dbox_destroy_cb_info(cbinfo); + } + + return ret; +} + +static void gbar_xpixmap_acquired_cb(dynamicbox_h handler, const struct packet *result, void *data) +{ + int pixmap; + int ret; + dynamicbox_ret_cb cb; + void *cbdata; + struct cb_info *info = data; + + cb = info->cb; + cbdata = info->data; + dbox_destroy_cb_info(info); + + if (!result) { + pixmap = 0; /* PIXMAP 0 means error */ + ret = DBOX_STATUS_ERROR_FAULT; + } else if (packet_get(result, "ii", &pixmap, &ret) != 2) { + pixmap = 0; + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + if (cb) { + DbgPrint("ret: %x, pixmap: %d\n", ret, pixmap); + cb(handler, pixmap, cbdata); + } + + if (handler->common->state != DBOX_STATE_DELETE) { + if (ret == (int)DBOX_STATUS_ERROR_NOT_EXIST && handler->refcnt == 2) { + dbox_invoke_event_handler(handler, DBOX_EVENT_DELETED); + dbox_unref(handler, 1); + } + } } static void gbar_pixmap_acquired_cb(dynamicbox_h handler, const struct packet *result, void *data) { - int pixmap; - int ret; - dynamicbox_ret_cb cb; - void *cbdata; - struct cb_info *info = data; - - cb = info->cb; - cbdata = info->data; - dbox_destroy_cb_info(info); - - if (!result) { - pixmap = 0; /* PIXMAP 0 means error */ - ret = DBOX_STATUS_ERROR_FAULT; - } else if (packet_get(result, "ii", &pixmap, &ret) != 2) { - pixmap = 0; - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - if (ret == (int)DBOX_STATUS_ERROR_BUSY) { - ret = dbox_acquire_gbar_pixmap(handler, cb, cbdata); - DbgPrint("Busy, Try again: %d\n", ret); - /* Try again */ - } else if (ret == (int)DBOX_STATUS_ERROR_NOT_EXIST && handler->refcnt == 2) { - if (cb) { - cb(handler, pixmap, cbdata); - } - dbox_invoke_event_handler(handler, DBOX_EVENT_DELETED); - dbox_unref(handler, 1); - } else { - if (cb) { - DbgPrint("ret: %d, pixmap: %d\n", ret, pixmap); - cb(handler, pixmap, cbdata); - } - } + int pixmap; + int ret; + dynamicbox_ret_cb cb; + void *cbdata; + struct cb_info *info = data; + + cb = info->cb; + cbdata = info->data; + dbox_destroy_cb_info(info); + + if (!result) { + pixmap = 0; /* PIXMAP 0 means error */ + ret = DBOX_STATUS_ERROR_FAULT; + } else if (packet_get(result, "ii", &pixmap, &ret) != 2) { + pixmap = 0; + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + if (ret == (int)DBOX_STATUS_ERROR_BUSY) { + ret = dbox_acquire_gbar_pixmap(handler, cb, cbdata); + DbgPrint("Busy, Try again: %d\n", ret); + /* Try again */ + } else if (ret == (int)DBOX_STATUS_ERROR_NOT_EXIST && handler->refcnt == 2) { + if (cb) { + cb(handler, pixmap, cbdata); + } + + if (handler->common->state != DBOX_STATE_DELETE) { + dbox_invoke_event_handler(handler, DBOX_EVENT_DELETED); + dbox_unref(handler, 1); + } + } else { + if (cb) { + DbgPrint("ret: %d, pixmap: %d\n", ret, pixmap); + cb(handler, pixmap, cbdata); + } + } } static void pinup_done_cb(dynamicbox_h handler, const struct packet *result, void *data) { - int ret; + int ret; - if (!result) { - ret = DBOX_STATUS_ERROR_FAULT; - goto errout; - } else if (packet_get(result, "i", &ret) != 1) { - goto errout; - } + if (!result) { + ret = DBOX_STATUS_ERROR_FAULT; + goto errout; + } else if (packet_get(result, "i", &ret) != 1) { + goto errout; + } - if (ret < 0) { - goto errout; - } + if (ret < 0) { + goto errout; + } - return; + return; errout: - handler->cbs.pinup.cb(handler, ret, handler->cbs.pinup.data); - handler->cbs.pinup.cb = NULL; - handler->cbs.pinup.data = NULL; - handler->common->request.pinup = 0; + handler->cbs.pinup.cb(handler, ret, handler->cbs.pinup.data); + handler->cbs.pinup.cb = NULL; + handler->cbs.pinup.data = NULL; + handler->common->request.pinup = 0; - if (ret == (int)DBOX_STATUS_ERROR_NOT_EXIST && handler->refcnt == 2) { - dbox_invoke_event_handler(handler, DBOX_EVENT_DELETED); - dbox_unref(handler, 1); - } + if (handler->common->state != DBOX_STATE_DELETE) { + if (ret == (int)DBOX_STATUS_ERROR_NOT_EXIST && handler->refcnt == 2) { + dbox_invoke_event_handler(handler, DBOX_EVENT_DELETED); + dbox_unref(handler, 1); + } + } } static void key_ret_cb(dynamicbox_h handler, const struct packet *result, void *data) { - int ret; + int ret; - if (!result) { - ret = DBOX_STATUS_ERROR_FAULT; - return; - } + if (!result) { + ret = DBOX_STATUS_ERROR_FAULT; + return; + } - if (packet_get(result, "i", &ret) != 1) { - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - return; - } + if (packet_get(result, "i", &ret) != 1) { + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + return; + } - if (ret != DBOX_STATUS_ERROR_NONE) { - goto errout; - } + if (ret != DBOX_STATUS_ERROR_NONE) { + goto errout; + } - return; + return; errout: - handler->cbs.key_event.cb(handler, ret, handler->cbs.key_event.data); - handler->cbs.key_event.cb = NULL; - handler->cbs.key_event.data = NULL; - handler->common->request.key_event = 0; + handler->cbs.key_event.cb(handler, ret, handler->cbs.key_event.data); + handler->cbs.key_event.cb = NULL; + handler->cbs.key_event.data = NULL; + handler->common->request.key_event = 0; - if (ret == (int)DBOX_STATUS_ERROR_NOT_EXIST && handler->refcnt == 2) { - dbox_invoke_event_handler(handler, DBOX_EVENT_DELETED); - dbox_unref(handler, 1); - } + if (handler->common->state != DBOX_STATE_DELETE) { + if (ret == (int)DBOX_STATUS_ERROR_NOT_EXIST && handler->refcnt == 2) { + dbox_invoke_event_handler(handler, DBOX_EVENT_DELETED); + dbox_unref(handler, 1); + } + } } static void access_ret_cb(dynamicbox_h handler, const struct packet *result, void *data) { - int ret; + int ret; - if (!result) { - ret = DBOX_STATUS_ERROR_FAULT; - return; - } + if (!result) { + ret = DBOX_STATUS_ERROR_FAULT; + return; + } - if (packet_get(result, "i", &ret) != 1) { - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - return; - } + if (packet_get(result, "i", &ret) != 1) { + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + return; + } - if (ret != DBOX_STATUS_ERROR_NONE) { - goto errout; - } + if (ret != DBOX_STATUS_ERROR_NONE) { + goto errout; + } - return; + return; errout: - handler->cbs.access_event.cb(handler, ret, handler->cbs.access_event.data); - handler->cbs.access_event.cb = NULL; - handler->cbs.access_event.data = NULL; - handler->common->request.access_event = 0; + handler->cbs.access_event.cb(handler, ret, handler->cbs.access_event.data); + handler->cbs.access_event.cb = NULL; + handler->cbs.access_event.data = NULL; + handler->common->request.access_event = 0; - if (ret == (int)DBOX_STATUS_ERROR_NOT_EXIST && handler->refcnt == 2) { - dbox_invoke_event_handler(handler, DBOX_EVENT_DELETED); - dbox_unref(handler, 1); - } + if (handler->common->state != DBOX_STATE_DELETE) { + if (ret == (int)DBOX_STATUS_ERROR_NOT_EXIST && handler->refcnt == 2) { + dbox_invoke_event_handler(handler, DBOX_EVENT_DELETED); + dbox_unref(handler, 1); + } + } } static int send_access_event(dynamicbox_h handler, const char *event, int x, int y, int type) { - struct packet *packet; - double timestamp; + struct packet *packet; + double timestamp; - timestamp = util_timestamp(); + timestamp = util_timestamp(); - packet = packet_create(event, "ssdiii", handler->common->pkgname, handler->common->id, timestamp, x, y, type); - if (!packet) { - ErrPrint("Failed to build packet\n"); - return DBOX_STATUS_ERROR_FAULT; - } + packet = packet_create(event, "ssdiii", handler->common->pkgname, handler->common->id, timestamp, x, y, type); + if (!packet) { + ErrPrint("Failed to build packet\n"); + return DBOX_STATUS_ERROR_FAULT; + } - return master_rpc_async_request(handler, packet, 0, access_ret_cb, NULL); + return master_rpc_async_request(handler, packet, 0, access_ret_cb, NULL); } static int send_key_event(dynamicbox_h handler, const char *event, unsigned int keycode) { - struct packet *packet; - double timestamp; + struct packet *packet; + double timestamp; - timestamp = util_timestamp(); - packet = packet_create(event, "ssdi", handler->common->pkgname, handler->common->id, timestamp, keycode); - if (!packet) { - ErrPrint("Failed to build packet\n"); - return DBOX_STATUS_ERROR_FAULT; - } + timestamp = util_timestamp(); + packet = packet_create(event, "ssdi", handler->common->pkgname, handler->common->id, timestamp, keycode); + if (!packet) { + ErrPrint("Failed to build packet\n"); + return DBOX_STATUS_ERROR_FAULT; + } - return master_rpc_async_request(handler, packet, 0, key_ret_cb, NULL); + return master_rpc_async_request(handler, packet, 0, key_ret_cb, NULL); } static int send_mouse_event(dynamicbox_h handler, const char *event, int x, int y) { - struct packet *packet; - double timestamp; + struct packet *packet; + double timestamp; - timestamp = util_timestamp(); - packet = packet_create_noack(event, "ssdii", handler->common->pkgname, handler->common->id, timestamp, x, y); - if (!packet) { - ErrPrint("Failed to build param\n"); - return DBOX_STATUS_ERROR_FAULT; - } + timestamp = util_timestamp(); + packet = packet_create_noack(event, "ssdii", handler->common->pkgname, handler->common->id, timestamp, x, y); + if (!packet) { + ErrPrint("Failed to build param\n"); + return DBOX_STATUS_ERROR_FAULT; + } - return master_rpc_request_only(handler, packet); + return master_rpc_request_only(handler, packet); } static int initialize_dynamicbox(void *disp, int use_thread) { - int ret; + int ret; #if defined(FLOG) - char filename[BUFSIZ]; - snprintf(filename, sizeof(filename), "/tmp/%d.box.log", getpid()); - __file_log_fp = fopen(filename, "w+t"); - if (!__file_log_fp) { - __file_log_fp = fdopen(1, "w+t"); - } + char filename[BUFSIZ]; + snprintf(filename, sizeof(filename), "/tmp/%d.box.log", getpid()); + __file_log_fp = fopen(filename, "w+t"); + if (!__file_log_fp) { + __file_log_fp = fdopen(1, "w+t"); + } #endif - ret = dynamicbox_service_init(); - if (ret != DBOX_STATUS_ERROR_NONE) { - return ret; - } + ret = dynamicbox_service_init(); + if (ret != DBOX_STATUS_ERROR_NONE) { + return ret; + } - ret = fb_init(disp); - if (ret != DBOX_STATUS_ERROR_NONE) { - dynamicbox_service_fini(); - return ret; - } + ret = fb_init(disp); + if (ret != DBOX_STATUS_ERROR_NONE) { + dynamicbox_service_fini(); + return ret; + } - ret = client_init(use_thread); - if (ret != DBOX_STATUS_ERROR_NONE) { - fb_fini(); - dynamicbox_service_fini(); - return ret; - } + ret = client_init(use_thread); + if (ret != DBOX_STATUS_ERROR_NONE) { + fb_fini(); + dynamicbox_service_fini(); + return ret; + } - s_info.init_count++; - return ret; + s_info.init_count++; + return ret; } static inline char *dbox_pkgname(const char *pkgname) { - char *dbox; + char *dbox; - dbox = dynamicbox_service_dbox_id(pkgname); - if (!dbox) { - dbox = strdup(pkgname); - } + dbox = dynamicbox_service_dbox_id(pkgname); + if (!dbox) { + dbox = strdup(pkgname); + } - return dbox; + return dbox; } static gboolean job_execute_cb(void *data) { - struct job_item *item; - struct dlist *l; + struct job_item *item; + struct dlist *l; - l = dlist_nth(s_info.job_list, 0); - if (!l) { - s_info.job_timer = 0; - return FALSE; - } + l = dlist_nth(s_info.job_list, 0); + if (!l) { + s_info.job_timer = 0; + return FALSE; + } - item = dlist_data(l); - s_info.job_list = dlist_remove(s_info.job_list, l); + item = dlist_data(l); + s_info.job_list = dlist_remove(s_info.job_list, l); - if (item) { - item->cb(item->handle, item->ret, item->data); - dbox_unref(item->handle, 1); - free(item); - } + if (item) { + item->cb(item->handle, item->ret, item->data); + dbox_unref(item->handle, 1); + free(item); + } - return TRUE; + return TRUE; } static int job_add(dynamicbox_h handle, dynamicbox_ret_cb job_cb, int ret, void *data) { - struct job_item *item; + struct job_item *item; - if (!job_cb) { - ErrPrint("Invalid argument\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!job_cb) { + ErrPrint("Invalid argument\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - item = malloc(sizeof(*item)); - if (!item) { - ErrPrint("Heap: %s\n", strerror(errno)); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } + item = malloc(sizeof(*item)); + if (!item) { + ErrPrint("Heap: %s\n", strerror(errno)); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } - item->handle = dbox_ref(handle); - item->cb = job_cb; - item->data = data; - item->ret = ret; + item->handle = dbox_ref(handle); + item->cb = job_cb; + item->data = data; + item->ret = ret; - s_info.job_list = dlist_append(s_info.job_list, item); + s_info.job_list = dlist_append(s_info.job_list, item); - if (!s_info.job_timer) { - s_info.job_timer = g_timeout_add(1, job_execute_cb, NULL); - if (!s_info.job_timer) { - ErrPrint("Failed to create a job timer\n"); - } - } + if (!s_info.job_timer) { + s_info.job_timer = g_timeout_add(1, job_execute_cb, NULL); + if (!s_info.job_timer) { + ErrPrint("Failed to create a job timer\n"); + } + } - return DBOX_STATUS_ERROR_NONE; + return DBOX_STATUS_ERROR_NONE; } static void new_ret_cb(dynamicbox_h handler, const struct packet *result, void *data) { - int ret; - struct cb_info *info = data; - dynamicbox_ret_cb cb; - void *cbdata; - - cb = info->cb; - cbdata = info->data; - dbox_destroy_cb_info(info); - - if (!result) { - ret = DBOX_STATUS_ERROR_FAULT; - } else if (packet_get(result, "i", &ret) != 1) { - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - if (ret >= 0) { - handler->cbs.created.cb = cb; - handler->cbs.created.data = cbdata; - - /*! - * \note - * Don't go anymore ;) - */ - return; - } else if (cb) { - /*! - * \note - * It means the current instance is not created, - * so user has to know about this. - * notice it to user using "deleted" event. - */ - cb(handler, ret, cbdata); - } - - dbox_unref(handler, 1); + int ret; + struct cb_info *info = data; + dynamicbox_ret_cb cb; + void *cbdata; + + cb = info->cb; + cbdata = info->data; + dbox_destroy_cb_info(info); + + if (!result) { + ret = DBOX_STATUS_ERROR_FAULT; + } else if (packet_get(result, "i", &ret) != 1) { + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + if (ret >= 0) { + handler->cbs.created.cb = cb; + handler->cbs.created.data = cbdata; + + /*! + * \note + * Don't go anymore ;) + */ + return; + } else if (cb) { + /*! + * \note + * It means the current instance is not created, + * so user has to know about this. + * notice it to user using "deleted" event. + */ + cb(handler, ret, cbdata); + } + + dbox_unref(handler, 1); } static int create_real_instance(dynamicbox_h handler, dynamicbox_ret_cb cb, void *data) { - struct cb_info *cbinfo; - struct packet *packet; - struct dynamicbox_common *common; - unsigned int cmd = CMD_NEW; - int ret; - - common = handler->common; - - packet = packet_create((const char *)&cmd, "dssssdii", - common->timestamp, common->pkgname, common->content, - common->cluster, common->category, - common->dbox.period, common->dbox.width, common->dbox.height); - if (!packet) { - ErrPrint("Failed to create a new packet\n"); - return DBOX_STATUS_ERROR_FAULT; - } - - cbinfo = dbox_create_cb_info(cb, data); - if (!cbinfo) { - ErrPrint("Failed to create a cbinfo\n"); - packet_destroy(packet); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } - - /*! - * \note - * master_rpc_async_request will destroy the packet (decrease the refcnt) - * So be aware the packet object after return from master_rpc_async_request. - */ - ret = master_rpc_async_request(handler, packet, 0, new_ret_cb, cbinfo); - if (ret < 0) { - ErrPrint("Failed to send a new packet\n"); - dbox_destroy_cb_info(cbinfo); - return DBOX_STATUS_ERROR_FAULT; - } - handler->common->request.created = 1; - return DBOX_STATUS_ERROR_NONE; + struct cb_info *cbinfo; + struct packet *packet; + struct dynamicbox_common *common; + unsigned int cmd = CMD_NEW; + int ret; + + common = handler->common; + + packet = packet_create((const char *)&cmd, "dssssdii", + common->timestamp, common->pkgname, common->content, + common->cluster, common->category, + common->dbox.period, common->dbox.width, common->dbox.height); + if (!packet) { + ErrPrint("Failed to create a new packet\n"); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_FAULT); + return DBOX_STATUS_ERROR_FAULT; + } + + cbinfo = dbox_create_cb_info(cb, data); + if (!cbinfo) { + ErrPrint("Failed to create a cbinfo\n"); + packet_destroy(packet); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_OUT_OF_MEMORY); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } + + /*! + * \note + * master_rpc_async_request will destroy the packet (decrease the refcnt) + * So be aware the packet object after return from master_rpc_async_request. + */ + ret = master_rpc_async_request(handler, packet, 0, new_ret_cb, cbinfo); + if (ret < 0) { + ErrPrint("Failed to send a new packet\n"); + dbox_destroy_cb_info(cbinfo); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_FAULT); + return DBOX_STATUS_ERROR_FAULT; + } + handler->common->request.created = 1; + return DBOX_STATUS_ERROR_NONE; } static void create_cb(dynamicbox_h handle, int ret, void *data) { - struct cb_info *cbinfo = data; + struct cb_info *cbinfo = data; - if (cbinfo->cb) { - cbinfo->cb(handle, ret, cbinfo->data); - } + if (cbinfo->cb) { + cbinfo->cb(handle, ret, cbinfo->data); + } - dbox_destroy_cb_info(cbinfo); + dbox_destroy_cb_info(cbinfo); - /*! - * \note - * Forcely generate "updated" event - */ - dbox_invoke_event_handler(handle, DBOX_EVENT_DBOX_UPDATED); + /*! + * \note + * Forcely generate "updated" event + */ + dbox_invoke_event_handler(handle, DBOX_EVENT_DBOX_UPDATED); } static int create_fake_instance(dynamicbox_h handler, dynamicbox_ret_cb cb, void *data) { - struct cb_info *cbinfo; + struct cb_info *cbinfo; - cbinfo = dbox_create_cb_info(cb, data); - if (!cbinfo) { - ErrPrint("Failed to create a cbinfo\n"); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } + cbinfo = dbox_create_cb_info(cb, data); + if (!cbinfo) { + ErrPrint("Failed to create a cbinfo\n"); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } - if (job_add(handler, create_cb, DBOX_STATUS_ERROR_NONE, cbinfo) != DBOX_STATUS_ERROR_NONE) { - dbox_destroy_cb_info(cbinfo); - } + if (job_add(handler, create_cb, DBOX_STATUS_ERROR_NONE, cbinfo) != DBOX_STATUS_ERROR_NONE) { + dbox_destroy_cb_info(cbinfo); + } - return DBOX_STATUS_ERROR_NONE; + return DBOX_STATUS_ERROR_NONE; } static void refresh_for_paused_updating_cb(dynamicbox_h handle, int ret, void *data) { - if (handle->paused_updating == 0) { - DbgPrint("Paused updates are cleared\n"); - return; - } - - DbgPrint("Pending updates are found\n"); - dbox_invoke_event_handler(handle, DBOX_EVENT_DBOX_UPDATED); -} - -static int dbox_set_visibility(dynamicbox_h handler, enum dynamicbox_visible_state state) -{ - struct packet *packet; - int need_to_add_job = 0; - unsigned int cmd = CMD_CHANGE_VISIBILITY; - int ret; - - if (handler->common->visible != DBOX_SHOW && state == DBOX_SHOW) { - need_to_add_job = !!handler->paused_updating; - } else if (handler->common->visible == DBOX_SHOW && state != DBOX_SHOW) { - if (!!dbox_find_dbox_in_show(handler->common)) { - return DBOX_STATUS_ERROR_NONE; - } - } else if (handler->common->visible == DBOX_SHOW && state == DBOX_SHOW && handler->paused_updating) { - if (job_add(handler, refresh_for_paused_updating_cb, DBOX_STATUS_ERROR_NONE, NULL) < 0) { - ErrPrint("Unable to add a new job for refreshing box\n"); - } - - return DBOX_STATUS_ERROR_NONE; - } else { - /*! - * \brief - * No need to send this to the master - */ - return DBOX_STATUS_ERROR_NONE; - } - - packet = packet_create_noack((const char *)&cmd, "ssi", handler->common->pkgname, handler->common->id, (int)state); - if (!packet) { - ErrPrint("Failed to create a packet\n"); - return DBOX_STATUS_ERROR_FAULT; - } - - ret = master_rpc_request_only(handler, packet); - if (ret == (int)DBOX_STATUS_ERROR_NONE) { - DbgPrint("[%s] visibility is changed 0x[%x]\n", handler->common->pkgname, state); - handler->common->visible = state; - - if (need_to_add_job) { - if (job_add(handler, refresh_for_paused_updating_cb, DBOX_STATUS_ERROR_NONE, NULL) < 0) { - ErrPrint("Unable to add a new job for refreshing box\n"); - } - } - } - - return ret; + if (handle->paused_updating == 0) { + DbgPrint("Paused updates are cleared\n"); + return; + } + + DbgPrint("Pending updates are found\n"); + dbox_invoke_event_handler(handle, DBOX_EVENT_DBOX_UPDATED); +} + +static int dbox_set_visibility(dynamicbox_h handler, dynamicbox_visible_state_e state) +{ + struct packet *packet; + int need_to_add_job = 0; + unsigned int cmd = CMD_CHANGE_VISIBILITY; + int ret; + + if (handler->common->visible != DBOX_SHOW && state == DBOX_SHOW) { + need_to_add_job = !!handler->paused_updating; + } else if (handler->common->visible == DBOX_SHOW && state != DBOX_SHOW) { + if (!!dbox_find_dbox_in_show(handler->common)) { + return DBOX_STATUS_ERROR_NONE; + } + } else if (handler->common->visible == DBOX_SHOW && state == DBOX_SHOW && handler->paused_updating) { + if (job_add(handler, refresh_for_paused_updating_cb, DBOX_STATUS_ERROR_NONE, NULL) < 0) { + ErrPrint("Unable to add a new job for refreshing box\n"); + } + + return DBOX_STATUS_ERROR_NONE; + } else { + /*! + * \brief + * No need to send this to the master + */ + return DBOX_STATUS_ERROR_NONE; + } + + packet = packet_create_noack((const char *)&cmd, "ssi", handler->common->pkgname, handler->common->id, (int)state); + if (!packet) { + ErrPrint("Failed to create a packet\n"); + return DBOX_STATUS_ERROR_FAULT; + } + + ret = master_rpc_request_only(handler, packet); + if (ret == (int)DBOX_STATUS_ERROR_NONE) { + DbgPrint("[%s] visibility is changed 0x[%x]\n", handler->common->pkgname, state); + handler->common->visible = state; + + if (need_to_add_job) { + if (job_add(handler, refresh_for_paused_updating_cb, DBOX_STATUS_ERROR_NONE, NULL) < 0) { + ErrPrint("Unable to add a new job for refreshing box\n"); + } + } + } + + return ret; } static void dbox_update_visibility(struct dynamicbox_common *old_common) { - dynamicbox_h item; + dynamicbox_h item; - item = dbox_find_dbox_in_show(old_common); - if (!item) { - item = dbox_get_dbox_nth(old_common, 0); - if (item) { - dbox_set_visibility(item, DBOX_HIDE_WITH_PAUSE); - } else { - ErrPrint("Unable to get the valid handle from common handler\n"); - } - } else { - dbox_set_visibility(item, DBOX_SHOW); - } + item = dbox_find_dbox_in_show(old_common); + if (!item) { + item = dbox_get_dbox_nth(old_common, 0); + if (item) { + dbox_set_visibility(item, DBOX_HIDE_WITH_PAUSE); + } else { + ErrPrint("Unable to get the valid handle from common handler\n"); + } + } else { + dbox_set_visibility(item, DBOX_SHOW); + } } /*! @@ -1024,2755 +1175,2917 @@ static void dbox_update_visibility(struct dynamicbox_common *old_common) */ static void job_del_cb(dynamicbox_h handle, int type, void *data) { - struct cb_info *cbinfo = data; - dynamicbox_ret_cb cb; - - if (handle->visible == DBOX_SHOW) { - dbox_update_visibility(handle->common); - } - - cb = cbinfo->cb; - data = cbinfo->data; - dbox_destroy_cb_info(cbinfo); - - if (handle->common->state != DBOX_STATE_CREATE) { - DbgPrint("[%s] %d\n", handle->common->pkgname, handle->refcnt); - if (cb) { - cb(handle, DBOX_STATUS_ERROR_NONE, data); - } - - return; - } - - if (handle->common->refcnt == 1) { - handle->common->delete_type = type; - handle->common->state = DBOX_STATE_DELETE; - - if (!handle->common->id) { - /*! - * \note - * The id is not determined yet. - * It means a user didn't receive created event yet. - * Then just stop to delete procedure from here. - * Because the "created" event handle will release this. - * By the way, if the user adds any callback for getting return status of this, - * call it at here. - */ - if (cb) { - cb(handle, DBOX_STATUS_ERROR_NONE, data); - } - } - - DbgPrint("Send delete request\n"); - dbox_send_delete(handle, type, cb, data); - } else { - if (cb) { - cb(handle, DBOX_STATUS_ERROR_NONE, data); - } - - DbgPrint("Before unref: %d\n", handle->common->refcnt); - dbox_unref(handle, 1); - } + struct cb_info *cbinfo = data; + dynamicbox_ret_cb cb; + + if (handle->visible == DBOX_SHOW) { + dbox_update_visibility(handle->common); + } + + cb = cbinfo->cb; + data = cbinfo->data; + dbox_destroy_cb_info(cbinfo); + + if (handle->common->state != DBOX_STATE_CREATE) { + DbgPrint("[%s] %d\n", handle->common->pkgname, handle->refcnt); + if (cb) { + cb(handle, DBOX_STATUS_ERROR_NONE, data); + } + + return; + } + + if (handle->common->refcnt == 1) { + handle->common->delete_type = type; + handle->common->state = DBOX_STATE_DELETE; + + if (!handle->common->id) { + /*! + * \note + * The id is not determined yet. + * It means a user didn't receive created event yet. + * Then just stop to delete procedure from here. + * Because the "created" event handle will release this. + * By the way, if the user adds any callback for getting return status of this, + * call it at here. + */ + if (cb) { + cb(handle, DBOX_STATUS_ERROR_NONE, data); + } + } + + DbgPrint("Send delete request\n"); + dbox_send_delete(handle, type, cb, data); + } else { + if (cb) { + cb(handle, DBOX_STATUS_ERROR_NONE, data); + } + + DbgPrint("Before unref: %d\n", handle->common->refcnt); + dbox_unref(handle, 1); + } } static void resize_job_cb(dynamicbox_h handler, int ret, void *data) { - struct cb_info *info = data; + struct cb_info *info = data; - if (info->cb) { - info->cb(handler, ret, info->data); - } + if (info->cb) { + info->cb(handler, ret, info->data); + } - free(info); + free(info); - /*! - * \note - * Forcely update the box - */ - dbox_invoke_event_handler(handler, DBOX_EVENT_DBOX_UPDATED); + /*! + * \note + * Forcely update the box + */ + dbox_invoke_event_handler(handler, DBOX_EVENT_DBOX_UPDATED); } static void turn_off_gbar_destroyed_flag_cb(dynamicbox_h handler, int ret, void *data) { - if (handler->common->request.gbar_destroyed) { - dynamicbox_ret_cb cb; - void *data; + if (handler->common->request.gbar_destroyed) { + dynamicbox_ret_cb cb; + void *data; - DbgPrint("gbar_destroyed request is canceled\n"); - handler->common->request.gbar_destroyed = 0; - cb = handler->cbs.gbar_destroyed.cb; - data = handler->cbs.gbar_destroyed.data; - handler->cbs.gbar_destroyed.cb = NULL; - handler->cbs.gbar_destroyed.data = NULL; + DbgPrint("gbar_destroyed request is canceled\n"); + handler->common->request.gbar_destroyed = 0; + cb = handler->cbs.gbar_destroyed.cb; + data = handler->cbs.gbar_destroyed.data; + handler->cbs.gbar_destroyed.cb = NULL; + handler->cbs.gbar_destroyed.data = NULL; - if (cb) { - cb(handler, ret, data); - } - } + if (cb) { + cb(handler, ret, data); + } + } } static void turn_off_gbar_created_flag_cb(dynamicbox_h handler, int ret, void *data) { - if (handler->common->request.gbar_created) { - dynamicbox_ret_cb cb; - void *data; + if (handler->common->request.gbar_created) { + dynamicbox_ret_cb cb; + void *data; - DbgPrint("gbar_created request is canceled\n"); - handler->common->request.gbar_created = 0; - cb = handler->cbs.gbar_created.cb; - data = handler->cbs.gbar_created.data; - handler->cbs.gbar_created.cb = NULL; - handler->cbs.gbar_created.data = NULL; + DbgPrint("gbar_created request is canceled\n"); + handler->common->request.gbar_created = 0; + cb = handler->cbs.gbar_created.cb; + data = handler->cbs.gbar_created.data; + handler->cbs.gbar_created.cb = NULL; + handler->cbs.gbar_created.data = NULL; - if (cb) { - cb(handler, ret, data); - } - } + if (cb) { + cb(handler, ret, data); + } + } } EAPI int dynamicbox_init(void *disp, int prevent_overwrite, double event_filter, int use_thread) { - if (s_info.init_count > 0) { - s_info.init_count++; - return DBOX_STATUS_ERROR_NONE; - } + if (s_info.init_count > 0) { + s_info.init_count++; + return DBOX_STATUS_ERROR_NONE; + } - /*! - * \note - * Some application doesn't want to use the environment value. - * So set them using arguments. - */ - s_info.prevent_overwrite = prevent_overwrite; - conf_set_event_filter(event_filter); + /*! + * \note + * Some application doesn't want to use the environment value. + * So set them using arguments. + */ + s_info.prevent_overwrite = prevent_overwrite; + conf_set_event_filter(event_filter); - return initialize_dynamicbox(disp, use_thread); + return initialize_dynamicbox(disp, use_thread); } EAPI int dynamicbox_fini(void) { - if (s_info.init_count <= 0) { - ErrPrint("Doesn't initialized\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - s_info.init_count--; - if (s_info.init_count > 0) { - ErrPrint("init count : %d\n", s_info.init_count); - return DBOX_STATUS_ERROR_NONE; - } - - client_fini(); - fb_fini(); - dynamicbox_service_fini(); - return DBOX_STATUS_ERROR_NONE; -} - -EAPI dynamicbox_h dynamicbox_add(const char *pkgname, const char *content, const char *cluster, const char *category, double period, enum dynamicbox_size_type type, dynamicbox_ret_cb cb, void *data) -{ - char *dboxid; - dynamicbox_h handler; - int w = 0; - int h = 0; - - if (!pkgname || !cluster || !category) { - ErrPrint("Invalid arguments: pkgname[%p], cluster[%p], category[%p]\n", - pkgname, cluster, category); - return NULL; - } - - dboxid = dbox_pkgname(pkgname); - if (!dboxid) { - ErrPrint("Invalid package: %s\n", pkgname); - return NULL; - } - - if (dynamicbox_service_is_enabled(dboxid) == 0) { - DbgPrint("Livebox [%s](%s) is disabled package\n", dboxid, pkgname); - free(dboxid); - return NULL; - } - - if (type != DBOX_SIZE_TYPE_UNKNOWN) { - (void)dynamicbox_service_get_size(type, &w, &h); - } - - handler = calloc(1, sizeof(*handler)); - if (!handler) { - ErrPrint("Error: %s\n", strerror(errno)); - free(dboxid); - return NULL; - } - - if (!cb) { - cb = default_create_cb; - } - - handler->common = dbox_find_sharable_common_handle(dboxid, content, w, h, cluster, category); - if (!handler->common) { - handler->common = dbox_create_common_handle(handler, dboxid, cluster, category); - free(dboxid); - if (!handler->common) { - ErrPrint("Failed to find common handle\n"); - free(handler); - return NULL; - } - - if (!content || !strlen(content)) { - char *pc; - /*! - * \note - * I know the content should not be modified. use it temporarly without "const" - */ - pc = dynamicbox_service_content(handler->common->pkgname); - dbox_set_content(handler->common, pc); - free(pc); - } else { - dbox_set_content(handler->common, content); - } - - dbox_set_period(handler->common, period); - dbox_set_size(handler->common, w, h); - dbox_common_ref(handler->common, handler); - - if (create_real_instance(handler, cb, data) < 0) { - if (dbox_common_unref(handler->common, handler) == 0) { - /*! - * Delete common - */ - dbox_destroy_common_handle(handler->common); - handler->common = NULL; - } - free(handler); - return NULL; - } - } else { - free(dboxid); - - dbox_common_ref(handler->common, handler); - - if (handler->common->request.created) { - /*! - * If a box is in creating, wait its result too - */ - handler->cbs.created.cb = cb; - handler->cbs.created.data = data; - } else { - /*! - * or fire the fake created_event - */ - if (create_fake_instance(handler, cb, data) < 0) { - if (dbox_common_unref(handler->common, handler) == 0) { - /*! - * Delete common - */ - dbox_destroy_common_handle(handler->common); - } - free(handler); - return NULL; - } - } - } - - handler->visible = DBOX_SHOW; - handler->state = DBOX_STATE_CREATE; - handler = dbox_ref(handler); - - if (handler->common->visible != DBOX_SHOW) { - dbox_set_visibility(handler, DBOX_SHOW); - } - - return handler; + if (s_info.init_count <= 0) { + ErrPrint("Doesn't initialized\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + s_info.init_count--; + if (s_info.init_count > 0) { + ErrPrint("init count : %d\n", s_info.init_count); + return DBOX_STATUS_ERROR_NONE; + } + + client_fini(); + fb_fini(); + dynamicbox_service_fini(); + return DBOX_STATUS_ERROR_NONE; +} + +EAPI dynamicbox_h dynamicbox_add(const char *pkgname, const char *content, const char *cluster, const char *category, double period, dynamicbox_size_type_e type, dynamicbox_ret_cb cb, void *data) +{ + char *dboxid; + dynamicbox_h handler; + int w = 0; + int h = 0; + + if (!pkgname || !cluster || !category) { + ErrPrint("Invalid arguments: pkgname[%p], cluster[%p], category[%p]\n", + pkgname, cluster, category); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return NULL; + } + + dboxid = dbox_pkgname(pkgname); + if (!dboxid) { + ErrPrint("Invalid package: %s\n", pkgname); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return NULL; + } + + if (dynamicbox_service_is_enabled(dboxid) == 0) { + DbgPrint("Livebox [%s](%s) is disabled package\n", dboxid, pkgname); + free(dboxid); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_DISABLED); + return NULL; + } + + if (type != DBOX_SIZE_TYPE_UNKNOWN) { + (void)dynamicbox_service_get_size(type, &w, &h); + } + + handler = calloc(1, sizeof(*handler)); + if (!handler) { + ErrPrint("Error: %s\n", strerror(errno)); + free(dboxid); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_OUT_OF_MEMORY); + return NULL; + } + + if (!cb) { + cb = default_create_cb; + } + + handler->common = dbox_find_sharable_common_handle(dboxid, content, w, h, cluster, category); + if (!handler->common) { + handler->common = dbox_create_common_handle(handler, dboxid, cluster, category); + free(dboxid); + if (!handler->common) { + ErrPrint("Failed to find common handle\n"); + free(handler); + return NULL; + } + + if (!content || !strlen(content)) { + char *pc; + /** + * @note + * I know the content should not be modified. use it temporarly without "const" + */ + pc = dynamicbox_service_content(handler->common->pkgname); + dbox_set_content(handler->common, pc); + free(pc); + } else { + dbox_set_content(handler->common, content); + } + + dbox_set_period(handler->common, period); + dbox_set_size(handler->common, w, h); + dbox_common_ref(handler->common, handler); + + if (create_real_instance(handler, cb, data) < 0) { + if (dbox_common_unref(handler->common, handler) == 0) { + /*! + * Delete common + */ + dbox_destroy_common_handle(handler->common); + handler->common = NULL; + } + free(handler); + return NULL; + } + } else { + free(dboxid); + + dbox_common_ref(handler->common, handler); + + if (handler->common->request.created) { + /*! + * If a box is in creating, wait its result too + */ + handler->cbs.created.cb = cb; + handler->cbs.created.data = data; + } else { + /*! + * or fire the fake created_event + */ + if (create_fake_instance(handler, cb, data) < 0) { + if (dbox_common_unref(handler->common, handler) == 0) { + /*! + * Delete common + */ + dbox_destroy_common_handle(handler->common); + } + free(handler); + return NULL; + } + } + } + + handler->visible = DBOX_SHOW; + handler->state = DBOX_STATE_CREATE; + handler = dbox_ref(handler); + + if (handler->common->visible != DBOX_SHOW) { + dbox_set_visibility(handler, DBOX_SHOW); + } + + return handler; } EAPI double dynamicbox_period(dynamicbox_h handler) { - if (!handler || handler->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is not valid\n"); - return 0.0f; - } + if (!handler || handler->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is not valid\n"); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return -1.0f; + } - if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { - ErrPrint("Invalid handle\n"); - return 0.0f; - } + if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { + ErrPrint("Invalid handle\n"); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return -1.0f; + } - if (!handler->common->id) { - ErrPrint("Hnalder is not valid\n"); - return 0.0f; - } + if (!handler->common->id) { + ErrPrint("Hnalder is not valid\n"); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return -1.0f; + } - return handler->common->dbox.period; + return handler->common->dbox.period; } EAPI int dynamicbox_set_period(dynamicbox_h handler, double period, dynamicbox_ret_cb cb, void *data) { - struct packet *packet; - unsigned int cmd = CMD_SET_PERIOD; - int ret; + struct packet *packet; + unsigned int cmd = CMD_SET_PERIOD; + int ret; - if (!handler || handler->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is not valid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!handler || handler->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is not valid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { - ErrPrint("Invalid handle\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { + ErrPrint("Invalid handle\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (!handler->common->id) { - ErrPrint("Handler is not valid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!handler->common->id) { + ErrPrint("Handler is not valid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (handler->common->request.period_changed) { - ErrPrint("Previous request for changing period is not finished\n"); - return DBOX_STATUS_ERROR_BUSY; - } + if (handler->common->request.period_changed) { + ErrPrint("Previous request for changing period is not finished\n"); + return DBOX_STATUS_ERROR_BUSY; + } - if (!handler->common->is_user) { - ErrPrint("CA Livebox is not able to change the period\n"); - return DBOX_STATUS_ERROR_PERMISSION_DENIED; - } + if (!handler->common->is_user) { + ErrPrint("CA Livebox is not able to change the period\n"); + return DBOX_STATUS_ERROR_PERMISSION_DENIED; + } - if (handler->common->dbox.period == period) { - DbgPrint("No changes\n"); - return DBOX_STATUS_ERROR_ALREADY; - } + if (handler->common->dbox.period == period) { + DbgPrint("No changes\n"); + return DBOX_STATUS_ERROR_ALREADY; + } - packet = packet_create((const char *)&cmd, "ssd", handler->common->pkgname, handler->common->id, period); - if (!packet) { - ErrPrint("Failed to build a packet %s\n", handler->common->pkgname); - return DBOX_STATUS_ERROR_FAULT; - } + packet = packet_create((const char *)&cmd, "ssd", handler->common->pkgname, handler->common->id, period); + if (!packet) { + ErrPrint("Failed to build a packet %s\n", handler->common->pkgname); + return DBOX_STATUS_ERROR_FAULT; + } - if (!cb) { - cb = default_period_changed_cb; - } + if (!cb) { + cb = default_period_changed_cb; + } - ret = master_rpc_async_request(handler, packet, 0, period_ret_cb, NULL); - if (ret == (int)DBOX_STATUS_ERROR_NONE) { - handler->cbs.period_changed.cb = cb; - handler->cbs.period_changed.data = data; - handler->common->request.period_changed = 1; - } + ret = master_rpc_async_request(handler, packet, 0, period_ret_cb, NULL); + if (ret == (int)DBOX_STATUS_ERROR_NONE) { + handler->cbs.period_changed.cb = cb; + handler->cbs.period_changed.data = data; + handler->common->request.period_changed = 1; + } - return ret; + return ret; } -EAPI int dynamicbox_del(dynamicbox_h handler, enum dynamicbox_delete_type type, dynamicbox_ret_cb cb, void *data) +EAPI int dynamicbox_del(dynamicbox_h handler, dynamicbox_delete_type_e type, dynamicbox_ret_cb cb, void *data) { - struct cb_info *cbinfo; + struct cb_info *cbinfo; - if (!handler) { - ErrPrint("Handler is NIL\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!handler) { + ErrPrint("Handler is NIL\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (handler->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is already deleted\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (handler->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is already deleted\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - handler->state = DBOX_STATE_DELETE; + handler->state = DBOX_STATE_DELETE; - cbinfo = dbox_create_cb_info(cb, data); - if (!cbinfo) { - ErrPrint("Failed to create a cbinfo\n"); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } + cbinfo = dbox_create_cb_info(cb, data); + if (!cbinfo) { + ErrPrint("Failed to create a cbinfo\n"); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } - if (job_add(handler, job_del_cb, type, cbinfo) != DBOX_STATUS_ERROR_NONE) { - ErrPrint("Failed to add a new job\n"); - dbox_destroy_cb_info(cbinfo); - return DBOX_STATUS_ERROR_FAULT; - } + if (job_add(handler, job_del_cb, type, cbinfo) != DBOX_STATUS_ERROR_NONE) { + ErrPrint("Failed to add a new job\n"); + dbox_destroy_cb_info(cbinfo); + return DBOX_STATUS_ERROR_FAULT; + } - return DBOX_STATUS_ERROR_NONE; + return DBOX_STATUS_ERROR_NONE; } -EAPI int dynamicbox_set_fault_handler(dynamicbox_fault_handler_cb dbox_cb, void *data) +EAPI int dynamicbox_add_fault_handler(dynamicbox_fault_handler_cb dbox_cb, void *data) { - if (!dbox_cb) { - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!dbox_cb) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - return dbox_add_fault_handler(dbox_cb, data); + return dbox_add_fault_handler(dbox_cb, data); } -EAPI void *dynamicbox_unset_fault_handler(dynamicbox_fault_handler_cb dbox_cb) +EAPI void *dynamicbox_remove_fault_handler(dynamicbox_fault_handler_cb dbox_cb) { - if (!dbox_cb) { - return NULL; - } + if (!dbox_cb) { + return NULL; + } - return dbox_remove_fault_handler(dbox_cb); + return dbox_remove_fault_handler(dbox_cb); } -EAPI int dynamicbox_set_event_handler(dynamicbox_event_handler_cb dbox_cb, void *data) +EAPI int dynamicbox_add_event_handler(dynamicbox_event_handler_cb dbox_cb, void *data) { - if (!dbox_cb) { - ErrPrint("Invalid argument dbox_cb is nil\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!dbox_cb) { + ErrPrint("Invalid argument dbox_cb is nil\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - return dbox_add_event_handler(dbox_cb, data); + return dbox_add_event_handler(dbox_cb, data); } -EAPI void *dynamicbox_unset_event_handler(dynamicbox_event_handler_cb dbox_cb) +EAPI void *dynamicbox_remove_event_handler(dynamicbox_event_handler_cb dbox_cb) { - if (!dbox_cb) { - return NULL; - } + if (!dbox_cb) { + return NULL; + } - return dbox_remove_event_handler(dbox_cb); + return dbox_remove_event_handler(dbox_cb); } EAPI int dynamicbox_set_update_mode(dynamicbox_h handler, int active_update, dynamicbox_ret_cb cb, void *data) { - struct packet *packet; - unsigned int cmd = CMD_UPDATE_MODE; - int ret; + struct packet *packet; + unsigned int cmd = CMD_UPDATE_MODE; + int ret; - if (!handler || handler->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is Invalid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!handler || handler->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is Invalid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is Invalid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is Invalid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (!handler->common->id) { - ErrPrint("Handler is Invalid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!handler->common->id) { + ErrPrint("Handler is Invalid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (handler->common->request.update_mode) { - ErrPrint("Previous update_mode cb is not finished yet\n"); - return DBOX_STATUS_ERROR_BUSY; - } + if (handler->common->request.update_mode) { + ErrPrint("Previous update_mode cb is not finished yet\n"); + return DBOX_STATUS_ERROR_BUSY; + } - if (handler->common->is_active_update == active_update) { - return DBOX_STATUS_ERROR_ALREADY; - } + if (handler->common->is_active_update == active_update) { + return DBOX_STATUS_ERROR_ALREADY; + } - if (!handler->common->is_user) { - return DBOX_STATUS_ERROR_PERMISSION_DENIED; - } + if (!handler->common->is_user) { + return DBOX_STATUS_ERROR_PERMISSION_DENIED; + } - packet = packet_create((const char *)&cmd, "ssi", handler->common->pkgname, handler->common->id, active_update); - if (!packet) { - return DBOX_STATUS_ERROR_FAULT; - } + packet = packet_create((const char *)&cmd, "ssi", handler->common->pkgname, handler->common->id, active_update); + if (!packet) { + return DBOX_STATUS_ERROR_FAULT; + } - if (!cb) { - cb = default_update_mode_cb; - } + if (!cb) { + cb = default_update_mode_cb; + } - ret = master_rpc_async_request(handler, packet, 0, update_mode_cb, NULL); - if (ret == (int)DBOX_STATUS_ERROR_NONE) { - handler->cbs.update_mode.cb = cb; - handler->cbs.update_mode.data = data; - handler->common->request.update_mode = 1; - } + ret = master_rpc_async_request(handler, packet, 0, update_mode_cb, NULL); + if (ret == (int)DBOX_STATUS_ERROR_NONE) { + handler->cbs.update_mode.cb = cb; + handler->cbs.update_mode.data = data; + handler->common->request.update_mode = 1; + } - return ret; + return ret; } EAPI int dynamicbox_is_active_update(dynamicbox_h handler) { - if (!handler || handler->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is Invalid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is Invalid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - if (!handler->common->id) { - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - return handler->common->is_active_update; -} - -EAPI int dynamicbox_resize(dynamicbox_h handler, enum dynamicbox_size_type type, dynamicbox_ret_cb cb, void *data) -{ - struct dynamicbox_common *common; - int w; - int h; - int ret; - - /*! - * \TODO - * If this handle is host instance or link instance, - * Create a new instance or find another linkable instance. - */ - - if (!handler || handler->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is not valid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { - ErrPrint("Invalid handle\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - if (!handler->common->id) { - ErrPrint("Handler is not valid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - /*! - * \note - * resize operation should be separated by each handler. - * If a handler is resizing, the other handler can request resize too. - * So we should not use the common->request.size_changed flag. - */ - if (handler->cbs.size_changed.cb) { - ErrPrint("Previous resize request is not finished yet\n"); - return DBOX_STATUS_ERROR_BUSY; - } - - if (dynamicbox_service_get_size(type, &w, &h) != 0) { - ErrPrint("Invalid size type\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - if (handler->common->dbox.width == w && handler->common->dbox.height == h) { - DbgPrint("No changes\n"); - return DBOX_STATUS_ERROR_ALREADY; - } - - if (!handler->common->is_user) { - ErrPrint("CA Livebox is not able to be resized\n"); - return DBOX_STATUS_ERROR_PERMISSION_DENIED; - } - - if (handler->common->refcnt <= 1) { - struct packet *packet; - unsigned int cmd = CMD_RESIZE; - - /* Only 1 instance */ - packet = packet_create((const char *)&cmd, "ssii", handler->common->pkgname, handler->common->id, w, h); - if (!packet) { - ErrPrint("Failed to build param\n"); - return DBOX_STATUS_ERROR_FAULT; - } - - if (!cb) { - cb = default_dbox_size_changed_cb; - } - - ret = master_rpc_async_request(handler, packet, 0, resize_cb, NULL); - if (ret == (int)DBOX_STATUS_ERROR_NONE) { - handler->cbs.size_changed.cb = cb; - handler->cbs.size_changed.data = data; - handler->common->request.size_changed = 1; - } - } else { - common = dbox_find_sharable_common_handle(handler->common->pkgname, handler->common->content, w, h, handler->common->cluster, handler->common->category); - if (!common) { - struct dynamicbox_common *old_common; - /*! - * \note - * If the common handler is in resizing, - * if user tries to resize a hander, then simply create new one even if the requested size is same with this. - - if (handler->common->request.size_changed) { - } - - */ - - old_common = handler->common; - - common = dbox_create_common_handle(handler, old_common->pkgname, old_common->cluster, old_common->category); - if (!common) { - ErrPrint("Failed to create common handle\n"); - return DBOX_STATUS_ERROR_FAULT; - } - - dbox_set_size(common, w, h); - dbox_set_content(common, old_common->content); - dbox_set_period(common, old_common->dbox.period); - - /*! - * \note - * Disconnecting from old one. - */ - if (dbox_common_unref(old_common, handler) == 0) { - /*! - * \note - * Impossible - */ - ErrPrint("Common has no associated handler\n"); - } - - dbox_common_ref(common, handler); - - /*! - * Connect to a new one - */ - handler->common = common; - - /*! - * \TODO - * Need to care, if it fails to create a common handle, - * the resize operation will be failed. - * in that case, we should reuse the old common handle - */ - ret = create_real_instance(handler, cb, data); - if (ret < 0) { - dbox_common_unref(common, handler); - dbox_destroy_common_handle(common); - - dbox_common_ref(old_common, handler); - handler->common = old_common; - } else { - /*! - * In this case, we should update visibility of old_common's dynamicboxes - */ - if (handler->visible == DBOX_SHOW) { - dbox_update_visibility(old_common); - } - } - } else { - struct cb_info *cbinfo; - - cbinfo = dbox_create_cb_info(cb, data); - if (!cbinfo) { - ErrPrint("Failed to create a cbinfo\n"); - ret = DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } else { - ret = job_add(handler, resize_job_cb, DBOX_STATUS_ERROR_NONE, cbinfo); - if (ret == (int)DBOX_STATUS_ERROR_NONE) { - struct dynamicbox_common *old_common; - - old_common = handler->common; - - if (dbox_common_unref(handler->common, handler) == 0) { - ErrPrint("Old common has no associated handler\n"); - } - - dbox_common_ref(common, handler); - handler->common = common; - - if (handler->visible == DBOX_SHOW) { - dbox_update_visibility(old_common); /* To update visibility: Show --> Paused */ - dbox_update_visibility(common); /* To update visibility: Paused --> Show */ - } - } else { - dbox_destroy_cb_info(cbinfo); - } - } - } - } - - return ret; + if (!handler || handler->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is Invalid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is Invalid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + if (!handler->common->id) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + return handler->common->is_active_update; +} + +EAPI int dynamicbox_resize(dynamicbox_h handler, dynamicbox_size_type_e type, dynamicbox_ret_cb cb, void *data) +{ + struct dynamicbox_common *common; + int w; + int h; + int ret; + + /*! + * \TODO + * If this handle is host instance or link instance, + * Create a new instance or find another linkable instance. + */ + + if (!handler || handler->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is not valid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { + ErrPrint("Invalid handle\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + if (!handler->common->id) { + ErrPrint("Handler is not valid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + /*! + * \note + * resize operation should be separated by each handler. + * If a handler is resizing, the other handler can request resize too. + * So we should not use the common->request.size_changed flag. + */ + if (handler->cbs.size_changed.cb) { + ErrPrint("Previous resize request is not finished yet\n"); + return DBOX_STATUS_ERROR_BUSY; + } + + if (dynamicbox_service_get_size(type, &w, &h) != 0) { + ErrPrint("Invalid size type\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + if (handler->common->dbox.width == w && handler->common->dbox.height == h) { + DbgPrint("No changes\n"); + return DBOX_STATUS_ERROR_ALREADY; + } + + if (!handler->common->is_user) { + ErrPrint("CA Livebox is not able to be resized\n"); + return DBOX_STATUS_ERROR_PERMISSION_DENIED; + } + + if (handler->common->refcnt <= 1) { + struct packet *packet; + unsigned int cmd = CMD_RESIZE; + + /* Only 1 instance */ + packet = packet_create((const char *)&cmd, "ssii", handler->common->pkgname, handler->common->id, w, h); + if (!packet) { + ErrPrint("Failed to build param\n"); + return DBOX_STATUS_ERROR_FAULT; + } + + if (!cb) { + cb = default_dbox_size_changed_cb; + } + + ret = master_rpc_async_request(handler, packet, 0, resize_cb, NULL); + if (ret == (int)DBOX_STATUS_ERROR_NONE) { + handler->cbs.size_changed.cb = cb; + handler->cbs.size_changed.data = data; + handler->common->request.size_changed = 1; + } + } else { + common = dbox_find_sharable_common_handle(handler->common->pkgname, handler->common->content, w, h, handler->common->cluster, handler->common->category); + if (!common) { + struct dynamicbox_common *old_common; + /*! + * \note + * If the common handler is in resizing, + * if user tries to resize a hander, then simply create new one even if the requested size is same with this. + + if (handler->common->request.size_changed) { + } + + */ + + old_common = handler->common; + + common = dbox_create_common_handle(handler, old_common->pkgname, old_common->cluster, old_common->category); + if (!common) { + ErrPrint("Failed to create common handle\n"); + return DBOX_STATUS_ERROR_FAULT; + } + + dbox_set_size(common, w, h); + dbox_set_content(common, old_common->content); + dbox_set_period(common, old_common->dbox.period); + + /*! + * \note + * Disconnecting from old one. + */ + if (dbox_common_unref(old_common, handler) == 0) { + /*! + * \note + * Impossible + */ + ErrPrint("Common has no associated handler\n"); + } + + dbox_common_ref(common, handler); + + /*! + * Connect to a new one + */ + handler->common = common; + + /*! + * \TODO + * Need to care, if it fails to create a common handle, + * the resize operation will be failed. + * in that case, we should reuse the old common handle + */ + ret = create_real_instance(handler, cb, data); + if (ret < 0) { + dbox_common_unref(common, handler); + dbox_destroy_common_handle(common); + + dbox_common_ref(old_common, handler); + handler->common = old_common; + } else { + /*! + * In this case, we should update visibility of old_common's dynamicboxes + */ + if (handler->visible == DBOX_SHOW) { + dbox_update_visibility(old_common); + } + } + } else { + struct cb_info *cbinfo; + + cbinfo = dbox_create_cb_info(cb, data); + if (!cbinfo) { + ErrPrint("Failed to create a cbinfo\n"); + ret = DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } else { + ret = job_add(handler, resize_job_cb, DBOX_STATUS_ERROR_NONE, cbinfo); + if (ret == (int)DBOX_STATUS_ERROR_NONE) { + struct dynamicbox_common *old_common; + + old_common = handler->common; + + if (dbox_common_unref(handler->common, handler) == 0) { + ErrPrint("Old common has no associated handler\n"); + } + + dbox_common_ref(common, handler); + handler->common = common; + + if (handler->visible == DBOX_SHOW) { + dbox_update_visibility(old_common); /* To update visibility: Show --> Paused */ + dbox_update_visibility(common); /* To update visibility: Paused --> Show */ + } + } else { + dbox_destroy_cb_info(cbinfo); + } + } + } + } + + return ret; } EAPI int dynamicbox_click(dynamicbox_h handler, double x, double y) { - struct packet *packet; - double timestamp; - unsigned int cmd = CMD_CLICKED; - int ret; + struct packet *packet; + double timestamp; + unsigned int cmd = CMD_CLICKED; + int ret; - if (!handler || handler->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is invalid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!handler || handler->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is invalid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is invalid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is invalid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (!handler->common->id) { - ErrPrint("Handler is not valid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!handler->common->id) { + ErrPrint("Handler is not valid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (handler->common->dbox.auto_launch) { - if (s_info.launch.handler) { - ret = s_info.launch.handler(handler, handler->common->dbox.auto_launch, s_info.launch.data); - if (ret < 0) { - ErrPrint("launch handler app %s (%d)\n", handler->common->dbox.auto_launch, ret); - } - } - } + if (handler->common->dbox.auto_launch) { + if (s_info.launch.handler) { + ret = s_info.launch.handler(handler, handler->common->dbox.auto_launch, s_info.launch.data); + if (ret < 0) { + ErrPrint("launch handler app %s (%d)\n", handler->common->dbox.auto_launch, ret); + } + } + } - timestamp = util_timestamp(); - DbgPrint("CLICKED: %lf\n", timestamp); + timestamp = util_timestamp(); + DbgPrint("CLICKED: %lf\n", timestamp); - packet = packet_create_noack((const char *)&cmd, "sssddd", handler->common->pkgname, handler->common->id, "clicked", timestamp, x, y); - if (!packet) { - ErrPrint("Failed to build param\n"); - return DBOX_STATUS_ERROR_FAULT; - } + packet = packet_create_noack((const char *)&cmd, "sssddd", handler->common->pkgname, handler->common->id, "clicked", timestamp, x, y); + if (!packet) { + ErrPrint("Failed to build param\n"); + return DBOX_STATUS_ERROR_FAULT; + } - ret = master_rpc_request_only(handler, packet); - return ret; + ret = master_rpc_request_only(handler, packet); + return ret; } EAPI int dynamicbox_has_glance_bar(dynamicbox_h handler) { - if (!handler || handler->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is invalid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!handler || handler->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is invalid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is invalid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is invalid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (!handler->common->id) { - ErrPrint("Handler is not valid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!handler->common->id) { + ErrPrint("Handler is not valid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - return !!handler->common->gbar.fb; + return !!handler->common->gbar.fb; } EAPI int dynamicbox_glance_bar_is_created(dynamicbox_h handler) { - if (!handler || handler->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is invalid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!handler || handler->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is invalid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is invalid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is invalid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (!handler->common->gbar.fb || !handler->common->id) { - ErrPrint("Handler is not valid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!handler->common->gbar.fb || !handler->common->id) { + ErrPrint("Handler is not valid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - return handler->common->is_gbar_created; + return handler->common->is_gbar_created; } EAPI int dynamicbox_create_glance_bar(dynamicbox_h handler, double x, double y, dynamicbox_ret_cb cb, void *data) { - struct packet *packet; - unsigned int cmd = CMD_CREATE_GBAR; - int ret; - - if (!handler || handler->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is invalid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is invalid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - if (!handler->common->gbar.fb || !handler->common->id) { - ErrPrint("Handler is not valid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - /*! - * \note - * Only one handler can have a GBAR - */ - if (handler->common->is_gbar_created) { - DbgPrint("GBAR is already created\n"); - return DBOX_STATUS_ERROR_NONE; - } - - if (handler->common->request.gbar_created) { - ErrPrint("Previous request is not completed yet\n"); - return DBOX_STATUS_ERROR_BUSY; - } - - /*! - * \note - * Turn off the gbar_destroyed request flag - */ - if (handler->common->request.gbar_destroyed) { - if (job_add(handler, turn_off_gbar_destroyed_flag_cb, DBOX_STATUS_ERROR_CANCEL, NULL) < 0) { - ErrPrint("Failed to add gbar_destroyed job\n"); - } - } - - packet = packet_create((const char *)&cmd, "ssdd", handler->common->pkgname, handler->common->id, x, y); - if (!packet) { - ErrPrint("Failed to build param\n"); - return DBOX_STATUS_ERROR_FAULT; - } - - if (!cb) { - cb = default_gbar_created_cb; - } - - DbgPrint("PERF_DBOX\n"); - ret = master_rpc_async_request(handler, packet, 0, gbar_create_cb, NULL); - if (ret == (int)DBOX_STATUS_ERROR_NONE) { - handler->cbs.gbar_created.cb = cb; - handler->cbs.gbar_created.data = data; - handler->common->request.gbar_created = 1; - } - - return ret; + struct packet *packet; + unsigned int cmd = CMD_CREATE_GBAR; + int ret; + + if (!handler || handler->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is invalid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is invalid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + if (!handler->common->gbar.fb || !handler->common->id) { + ErrPrint("Handler is not valid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + /*! + * \note + * Only one handler can have a GBAR + */ + if (handler->common->is_gbar_created) { + DbgPrint("GBAR is already created\n"); + return DBOX_STATUS_ERROR_NONE; + } + + if (handler->common->request.gbar_created) { + ErrPrint("Previous request is not completed yet\n"); + return DBOX_STATUS_ERROR_BUSY; + } + + /*! + * \note + * Turn off the gbar_destroyed request flag + */ + if (handler->common->request.gbar_destroyed) { + if (job_add(handler, turn_off_gbar_destroyed_flag_cb, DBOX_STATUS_ERROR_CANCEL, NULL) < 0) { + ErrPrint("Failed to add gbar_destroyed job\n"); + } + } + + packet = packet_create((const char *)&cmd, "ssdd", handler->common->pkgname, handler->common->id, x, y); + if (!packet) { + ErrPrint("Failed to build param\n"); + return DBOX_STATUS_ERROR_FAULT; + } + + if (!cb) { + cb = default_gbar_created_cb; + } + + DbgPrint("PERF_DBOX\n"); + ret = master_rpc_async_request(handler, packet, 0, gbar_create_cb, NULL); + if (ret == (int)DBOX_STATUS_ERROR_NONE) { + handler->cbs.gbar_created.cb = cb; + handler->cbs.gbar_created.data = data; + handler->common->request.gbar_created = 1; + } + + return ret; } EAPI int dynamicbox_move_glance_bar(dynamicbox_h handler, double x, double y) { - struct packet *packet; - unsigned int cmd = CMD_GBAR_MOVE; + struct packet *packet; + unsigned int cmd = CMD_GBAR_MOVE; - if (!handler || handler->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is invalid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!handler || handler->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is invalid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is invalid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is invalid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (!handler->common->gbar.fb || !handler->common->id) { - ErrPrint("Handler is not valid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!handler->common->gbar.fb || !handler->common->id) { + ErrPrint("Handler is not valid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (!handler->common->is_gbar_created) { - ErrPrint("GBAR is not created\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!handler->common->is_gbar_created) { + ErrPrint("GBAR is not created\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - packet = packet_create_noack((const char *)&cmd, "ssdd", handler->common->pkgname, handler->common->id, x, y); - if (!packet) { - ErrPrint("Failed to build param\n"); - return DBOX_STATUS_ERROR_FAULT; - } + packet = packet_create_noack((const char *)&cmd, "ssdd", handler->common->pkgname, handler->common->id, x, y); + if (!packet) { + ErrPrint("Failed to build param\n"); + return DBOX_STATUS_ERROR_FAULT; + } - return master_rpc_request_only(handler, packet); + return master_rpc_request_only(handler, packet); } EAPI int dynamicbox_activate(const char *pkgname, dynamicbox_ret_cb cb, void *data) { - struct packet *packet; - struct cb_info *cbinfo; - unsigned int cmd = CMD_ACTIVATE_PACKAGE; - int ret; + struct packet *packet; + struct cb_info *cbinfo; + unsigned int cmd = CMD_ACTIVATE_PACKAGE; + int ret; - if (!pkgname) { - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!pkgname) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - packet = packet_create((const char *)&cmd, "s", pkgname); - if (!packet) { - ErrPrint("Failed to build a param\n"); - return DBOX_STATUS_ERROR_FAULT; - } + packet = packet_create((const char *)&cmd, "s", pkgname); + if (!packet) { + ErrPrint("Failed to build a param\n"); + return DBOX_STATUS_ERROR_FAULT; + } - cbinfo = dbox_create_cb_info(cb, data); - if (!cbinfo) { - ErrPrint("Unable to create cbinfo\n"); - packet_destroy(packet); - return DBOX_STATUS_ERROR_FAULT; - } + cbinfo = dbox_create_cb_info(cb, data); + if (!cbinfo) { + ErrPrint("Unable to create cbinfo\n"); + packet_destroy(packet); + return DBOX_STATUS_ERROR_FAULT; + } - ret = master_rpc_async_request(NULL, packet, 0, activated_cb, cbinfo); - if (ret < 0) { - dbox_destroy_cb_info(cbinfo); - } + ret = master_rpc_async_request(NULL, packet, 0, activated_cb, cbinfo); + if (ret < 0) { + dbox_destroy_cb_info(cbinfo); + } - return ret; + return ret; } EAPI int dynamicbox_destroy_glance_bar(dynamicbox_h handler, dynamicbox_ret_cb cb, void *data) { - struct packet *packet; - struct cb_info *cbinfo; - unsigned int cmd = CMD_DESTROY_GBAR; - int ret; - - if (!handler || handler->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is invalid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is invalid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - if (!handler->common->gbar.fb || !handler->common->id) { - ErrPrint("Handler is not valid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - /*! - * \FIXME - * Replace the callback check code. - * Use the flag instead of callback. - * the flag should be in the ADT "common" - */ - if (!handler->common->is_gbar_created && !handler->common->request.gbar_created) { - ErrPrint("GBAR is not created\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - if (handler->common->request.gbar_destroyed) { - ErrPrint("GBAR destroy request is already sent\n"); - return DBOX_STATUS_ERROR_ALREADY; - } - - /*! - * \note - * Disable the gbar_created request flag - */ - if (handler->common->request.gbar_created) { - if (job_add(handler, turn_off_gbar_created_flag_cb, DBOX_STATUS_ERROR_CANCEL, NULL) < 0) { - ErrPrint("Failed to add a new job\n"); - } - } - - DbgPrint("[%s]\n", handler->common->pkgname); - - packet = packet_create((const char *)&cmd, "ss", handler->common->pkgname, handler->common->id); - if (!packet) { - ErrPrint("Failed to build a param\n"); - return DBOX_STATUS_ERROR_FAULT; - } - - if (!cb) { - cb = default_gbar_destroyed_cb; - } - - cbinfo = dbox_create_cb_info(cb, data); - if (!cbinfo) { - packet_destroy(packet); - return DBOX_STATUS_ERROR_FAULT; - } - - ret = master_rpc_async_request(handler, packet, 0, gbar_destroy_cb, cbinfo); - if (ret < 0) { - dbox_destroy_cb_info(cbinfo); - } else { - handler->common->request.gbar_destroyed = 1; - } - - return ret; -} - -EAPI int dynamicbox_feed_access_event(dynamicbox_h handler, enum dynamicbox_access_event_type type, struct dynamicbox_access_event_info *info, dynamicbox_ret_cb cb, void *data) -{ - int w = 1; - int h = 1; - unsigned int cmd; - int ret = 0; /* re-used for sending event type */ - - if (!handler || handler->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is invalid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is invalid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - if (!handler->common->id) { - ErrPrint("Handler is not valid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - if (handler->common->request.access_event) { - ErrPrint("Previous access event is not yet done\n"); - return DBOX_STATUS_ERROR_BUSY; - } - - if (type & DBOX_ACCESS_EVENT_GBAR_MASK) { - if (!handler->common->is_gbar_created) { - ErrPrint("GBAR is not created\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - w = handler->common->gbar.width; - h = handler->common->gbar.height; - - switch (type & ~(DBOX_ACCESS_EVENT_GBAR_MASK | DBOX_ACCESS_EVENT_DBOX_MASK)) { - case DBOX_ACCESS_EVENT_HIGHLIGHT: - cmd = CMD_GBAR_ACCESS_HL; - ret = (int)info->type; - break; - case DBOX_ACCESS_EVENT_ACTIVATE: - cmd = CMD_GBAR_ACCESS_ACTIVATE; - break; - case DBOX_ACCESS_EVENT_ACTION: - cmd = CMD_GBAR_ACCESS_ACTION; - ret = (int)info->type; - break; - case DBOX_ACCESS_EVENT_SCROLL: - cmd = CMD_GBAR_ACCESS_SCROLL; - ret = (int)info->type; - break; - case DBOX_ACCESS_EVENT_VALUE_CHANGE: - cmd = CMD_GBAR_ACCESS_VALUE_CHANGE; - break; - case DBOX_ACCESS_EVENT_MOUSE: - cmd = CMD_GBAR_ACCESS_MOUSE; - ret = (int)info->type; - break; - case DBOX_ACCESS_EVENT_BACK: - cmd = CMD_GBAR_ACCESS_BACK; - break; - case DBOX_ACCESS_EVENT_OVER: - cmd = CMD_GBAR_ACCESS_OVER; - break; - case DBOX_ACCESS_EVENT_READ: - cmd = CMD_GBAR_ACCESS_READ; - break; - case DBOX_ACCESS_EVENT_ENABLE: - cmd = CMD_GBAR_ACCESS_ENABLE; - ret = info->type; - break; - default: - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - } else if (type & DBOX_ACCESS_EVENT_DBOX_MASK) { - w = handler->common->dbox.width; - h = handler->common->dbox.height; - switch (type & ~(DBOX_ACCESS_EVENT_GBAR_MASK | DBOX_ACCESS_EVENT_DBOX_MASK)) { - case DBOX_ACCESS_EVENT_HIGHLIGHT: - cmd = CMD_DBOX_ACCESS_HL; - ret = (int)info->type; - break; - case DBOX_ACCESS_EVENT_ACTIVATE: - cmd = CMD_DBOX_ACCESS_ACTIVATE; - break; - case DBOX_ACCESS_EVENT_ACTION: - cmd = CMD_DBOX_ACCESS_ACTION; - ret = (int)info->type; - break; - case DBOX_ACCESS_EVENT_SCROLL: - cmd = CMD_DBOX_ACCESS_SCROLL; - ret = (int)info->type; - break; - case DBOX_ACCESS_EVENT_VALUE_CHANGE: - cmd = CMD_DBOX_ACCESS_VALUE_CHANGE; - break; - case DBOX_ACCESS_EVENT_MOUSE: - cmd = CMD_DBOX_ACCESS_MOUSE; - ret = (int)info->type; - break; - case DBOX_ACCESS_EVENT_BACK: - cmd = CMD_DBOX_ACCESS_BACK; - break; - case DBOX_ACCESS_EVENT_OVER: - cmd = CMD_DBOX_ACCESS_OVER; - break; - case DBOX_ACCESS_EVENT_READ: - cmd = CMD_DBOX_ACCESS_READ; - break; - case DBOX_ACCESS_EVENT_ENABLE: - cmd = CMD_DBOX_ACCESS_ENABLE; - ret = info->type; - break; - default: - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - } else { - ErrPrint("Invalid event type\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - if (!cb) { - cb = default_access_event_cb; - } - - ret = send_access_event(handler, (const char *)&cmd, info->x * w, info->y * h, ret); - if (ret == (int)DBOX_STATUS_ERROR_NONE) { - handler->cbs.access_event.cb = cb; - handler->cbs.access_event.data = data; - handler->common->request.access_event = 1; - } - - return ret; -} - -EAPI int dynamicbox_feed_mouse_event(dynamicbox_h handler, enum dynamicbox_mouse_event_type type, struct dynamicbox_mouse_event_info *info) -{ - int w = 1; - int h = 1; - unsigned int cmd; - - if (!handler || handler->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is invalid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is invalid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - if (!handler->common->id) { - ErrPrint("Handler is not valid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - if (!(type & DBOX_MOUSE_EVENT_MASK)) { - ErrPrint("Invalid content event is used\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - if (type & DBOX_MOUSE_EVENT_GBAR_MASK) { - int flag = 1; - - if (!handler->common->is_gbar_created) { - ErrPrint("GBAR is not created\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - if (!handler->common->gbar.fb) { - ErrPrint("Handler is not valid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - if (type & DBOX_MOUSE_EVENT_MOVE) { - if (fabs(info->x - handler->common->gbar.x) < conf_event_filter() && fabs(info->y - handler->common->gbar.y) < conf_event_filter()) { - return DBOX_STATUS_ERROR_BUSY; - } - } else if (type & DBOX_MOUSE_EVENT_SET) { - flag = 0; - } - - w = handler->common->gbar.width; - h = handler->common->gbar.height; - if (flag) { - handler->common->gbar.x = info->x; - handler->common->gbar.y = info->y; - } - - switch ((type & ~(DBOX_MOUSE_EVENT_GBAR_MASK | DBOX_MOUSE_EVENT_DBOX_MASK))) { - case DBOX_MOUSE_EVENT_ENTER | DBOX_MOUSE_EVENT_MASK: - cmd = CMD_GBAR_MOUSE_ENTER; - break; - case DBOX_MOUSE_EVENT_LEAVE | DBOX_MOUSE_EVENT_MASK: - cmd = CMD_GBAR_MOUSE_LEAVE; - break; - case DBOX_MOUSE_EVENT_UP | DBOX_MOUSE_EVENT_MASK: - cmd = CMD_GBAR_MOUSE_UP; - break; - case DBOX_MOUSE_EVENT_DOWN | DBOX_MOUSE_EVENT_MASK: - cmd = CMD_GBAR_MOUSE_DOWN; - break; - case DBOX_MOUSE_EVENT_MOVE | DBOX_MOUSE_EVENT_MASK: - cmd = CMD_GBAR_MOUSE_MOVE; - break; - case DBOX_MOUSE_EVENT_SET | DBOX_MOUSE_EVENT_MASK: - cmd = CMD_GBAR_MOUSE_SET; - break; - case DBOX_MOUSE_EVENT_UNSET | DBOX_MOUSE_EVENT_MASK: - cmd = CMD_GBAR_MOUSE_UNSET; - break; - case DBOX_MOUSE_EVENT_ON_SCROLL | DBOX_MOUSE_EVENT_MASK: - cmd = CMD_GBAR_MOUSE_ON_SCROLL; - break; - case DBOX_MOUSE_EVENT_ON_HOLD | DBOX_MOUSE_EVENT_MASK: - cmd = CMD_GBAR_MOUSE_ON_HOLD; - break; - case DBOX_MOUSE_EVENT_OFF_SCROLL | DBOX_MOUSE_EVENT_MASK: - cmd = CMD_GBAR_MOUSE_OFF_SCROLL; - break; - case DBOX_MOUSE_EVENT_OFF_HOLD | DBOX_MOUSE_EVENT_MASK: - cmd = CMD_GBAR_MOUSE_OFF_HOLD; - break; - default: - ErrPrint("Invalid event type\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - } else if (type & DBOX_MOUSE_EVENT_DBOX_MASK) { - int flag = 1; - - if (!handler->common->dbox.fb) { - ErrPrint("Handler is not valid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - if (type & DBOX_MOUSE_EVENT_MOVE) { - if (fabs(info->x - handler->common->dbox.x) < conf_event_filter() && fabs(info->y - handler->common->dbox.y) < conf_event_filter()) { - return DBOX_STATUS_ERROR_BUSY; - } - } else if (type & DBOX_MOUSE_EVENT_SET) { - flag = 0; - } - - w = handler->common->dbox.width; - h = handler->common->dbox.height; - if (flag) { - handler->common->dbox.x = info->x; - handler->common->dbox.y = info->y; - } - - switch ((type & ~(DBOX_MOUSE_EVENT_GBAR_MASK | DBOX_MOUSE_EVENT_DBOX_MASK))) { - case DBOX_MOUSE_EVENT_ENTER | DBOX_MOUSE_EVENT_MASK: - cmd = CMD_DBOX_MOUSE_ENTER; - break; - case DBOX_MOUSE_EVENT_LEAVE | DBOX_MOUSE_EVENT_MASK: - cmd = CMD_DBOX_MOUSE_LEAVE; - break; - case DBOX_MOUSE_EVENT_UP | DBOX_MOUSE_EVENT_MASK: - cmd = CMD_DBOX_MOUSE_UP; - break; - case DBOX_MOUSE_EVENT_DOWN | DBOX_MOUSE_EVENT_MASK: - cmd = CMD_DBOX_MOUSE_DOWN; - break; - case DBOX_MOUSE_EVENT_MOVE | DBOX_MOUSE_EVENT_MASK: - if (!handler->common->dbox.mouse_event) { - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - cmd = CMD_DBOX_MOUSE_MOVE; - break; - case DBOX_MOUSE_EVENT_SET | DBOX_MOUSE_EVENT_MASK: - if (!handler->common->dbox.mouse_event) { - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - cmd = CMD_DBOX_MOUSE_SET; - break; - case DBOX_MOUSE_EVENT_UNSET | DBOX_MOUSE_EVENT_MASK: - if (!handler->common->dbox.mouse_event) { - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - cmd = CMD_DBOX_MOUSE_UNSET; - break; - case DBOX_MOUSE_EVENT_ON_SCROLL | DBOX_MOUSE_EVENT_MASK: - cmd = CMD_DBOX_MOUSE_ON_SCROLL; - break; - case DBOX_MOUSE_EVENT_ON_HOLD | DBOX_MOUSE_EVENT_MASK: - cmd = CMD_DBOX_MOUSE_ON_HOLD; - break; - case DBOX_MOUSE_EVENT_OFF_SCROLL | DBOX_MOUSE_EVENT_MASK: - cmd = CMD_DBOX_MOUSE_OFF_SCROLL; - break; - case DBOX_MOUSE_EVENT_OFF_HOLD | DBOX_MOUSE_EVENT_MASK: - cmd = CMD_DBOX_MOUSE_OFF_HOLD; - break; - default: - ErrPrint("Invalid event type\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - } else { - ErrPrint("Invalid event type\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - return send_mouse_event(handler, (const char *)&cmd, info->x * w, info->y * h); -} - -EAPI int dynamicbox_feed_key_event(dynamicbox_h handler, enum dynamicbox_key_event_type type, struct dynamicbox_key_event_info *info, dynamicbox_ret_cb cb, void *data) -{ - int ret; - unsigned int cmd; - - if (!handler || handler->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is invalid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is invalid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - if (!handler->common->id) { - ErrPrint("Handler is not valid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - if (!(type & DBOX_KEY_EVENT_MASK)) { - ErrPrint("Invalid key event is used\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - if (handler->common->request.key_event) { - ErrPrint("Previous key event is not completed yet\n"); - return DBOX_STATUS_ERROR_BUSY; - } - - if (type & DBOX_MOUSE_EVENT_GBAR_MASK) { - if (!handler->common->is_gbar_created) { - ErrPrint("GBAR is not created\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - if (!handler->common->gbar.fb) { - ErrPrint("Handler is not valid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - if (type & DBOX_KEY_EVENT_DOWN) { - /*! - * \TODO - * filtering the reproduced events if it is too fast - */ - } else if (type & DBOX_KEY_EVENT_SET) { - /*! - * \TODO - * What can I do for this case? - */ - } - - /*! - * Must be short than 29 bytes. - */ - switch ((type & ~(DBOX_MOUSE_EVENT_GBAR_MASK | DBOX_MOUSE_EVENT_DBOX_MASK))) { - case DBOX_KEY_EVENT_FOCUS_IN | DBOX_KEY_EVENT_MASK: - cmd = CMD_GBAR_KEY_FOCUS_IN; - break; - case DBOX_KEY_EVENT_FOCUS_OUT | DBOX_KEY_EVENT_MASK: - cmd = CMD_GBAR_KEY_FOCUS_OUT; - break; - case DBOX_KEY_EVENT_UP | DBOX_KEY_EVENT_MASK: - cmd = CMD_GBAR_KEY_UP; - break; - case DBOX_KEY_EVENT_DOWN | DBOX_KEY_EVENT_MASK: - cmd = CMD_GBAR_KEY_DOWN; - break; - case DBOX_KEY_EVENT_SET | DBOX_KEY_EVENT_MASK: - cmd = CMD_GBAR_KEY_SET; - break; - case DBOX_KEY_EVENT_UNSET | DBOX_KEY_EVENT_MASK: - cmd = CMD_GBAR_KEY_UNSET; - break; - default: - ErrPrint("Invalid event type\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - } else if (type & DBOX_MOUSE_EVENT_DBOX_MASK) { - if (!handler->common->dbox.fb) { - ErrPrint("Handler is not valid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - if (type & DBOX_KEY_EVENT_DOWN) { - /*! - * \TODO - * filtering the reproduced events if it is too fast - */ - } else if (type & DBOX_KEY_EVENT_SET) { - /*! - * What can I do for this case? - */ - } - - switch ((type & ~(DBOX_MOUSE_EVENT_GBAR_MASK | DBOX_MOUSE_EVENT_DBOX_MASK))) { - case DBOX_KEY_EVENT_FOCUS_IN | DBOX_KEY_EVENT_MASK: - cmd = CMD_DBOX_KEY_FOCUS_IN; - break; - case DBOX_KEY_EVENT_FOCUS_OUT | DBOX_KEY_EVENT_MASK: - cmd = CMD_DBOX_KEY_FOCUS_OUT; - break; - case DBOX_KEY_EVENT_UP | DBOX_KEY_EVENT_MASK: - cmd = CMD_DBOX_KEY_UP; - break; - case DBOX_KEY_EVENT_DOWN | DBOX_KEY_EVENT_MASK: - cmd = CMD_DBOX_KEY_DOWN; - break; - case DBOX_KEY_EVENT_SET | DBOX_KEY_EVENT_MASK: - cmd = CMD_DBOX_KEY_SET; - break; - case DBOX_KEY_EVENT_UNSET | DBOX_KEY_EVENT_MASK: - cmd = CMD_DBOX_KEY_UNSET; - break; - default: - ErrPrint("Invalid event type\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - } else { - ErrPrint("Invalid event type\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - if (!cb) { - cb = default_key_event_cb; - } - - ret = send_key_event(handler, (const char *)&cmd, info->keycode); - if (ret == (int)DBOX_STATUS_ERROR_NONE) { - handler->cbs.key_event.cb = cb; - handler->cbs.key_event.data = data; - handler->common->request.key_event = 1; - } - - return ret; + struct packet *packet; + struct cb_info *cbinfo; + unsigned int cmd = CMD_DESTROY_GBAR; + int ret; + + if (!handler || handler->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is invalid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is invalid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + if (!handler->common->gbar.fb || !handler->common->id) { + ErrPrint("Handler is not valid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + /*! + * \FIXME + * Replace the callback check code. + * Use the flag instead of callback. + * the flag should be in the ADT "common" + */ + if (!handler->common->is_gbar_created && !handler->common->request.gbar_created) { + ErrPrint("GBAR is not created\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + if (handler->common->request.gbar_destroyed) { + ErrPrint("GBAR destroy request is already sent\n"); + return DBOX_STATUS_ERROR_ALREADY; + } + + /*! + * \note + * Disable the gbar_created request flag + */ + if (handler->common->request.gbar_created) { + if (job_add(handler, turn_off_gbar_created_flag_cb, DBOX_STATUS_ERROR_CANCEL, NULL) < 0) { + ErrPrint("Failed to add a new job\n"); + } + } + + DbgPrint("[%s]\n", handler->common->pkgname); + + packet = packet_create((const char *)&cmd, "ss", handler->common->pkgname, handler->common->id); + if (!packet) { + ErrPrint("Failed to build a param\n"); + return DBOX_STATUS_ERROR_FAULT; + } + + if (!cb) { + cb = default_gbar_destroyed_cb; + } + + cbinfo = dbox_create_cb_info(cb, data); + if (!cbinfo) { + packet_destroy(packet); + return DBOX_STATUS_ERROR_FAULT; + } + + ret = master_rpc_async_request(handler, packet, 0, gbar_destroy_cb, cbinfo); + if (ret < 0) { + dbox_destroy_cb_info(cbinfo); + } else { + handler->common->request.gbar_destroyed = 1; + } + + return ret; +} + +EAPI int dynamicbox_feed_access_event(dynamicbox_h handler, dynamicbox_access_event_type_e type, dynamicbox_access_event_info_t info, dynamicbox_ret_cb cb, void *data) +{ + int w = 1; + int h = 1; + unsigned int cmd; + int ret = 0; /* re-used for sending event type */ + + if (!handler || handler->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is invalid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is invalid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + if (!handler->common->id) { + ErrPrint("Handler is not valid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + if (handler->common->request.access_event) { + ErrPrint("Previous access event is not yet done\n"); + return DBOX_STATUS_ERROR_BUSY; + } + + if (type & DBOX_ACCESS_EVENT_GBAR_MASK) { + if (!handler->common->is_gbar_created) { + ErrPrint("GBAR is not created\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + w = handler->common->gbar.width; + h = handler->common->gbar.height; + + switch (type & ~(DBOX_ACCESS_EVENT_GBAR_MASK | DBOX_ACCESS_EVENT_DBOX_MASK)) { + case DBOX_ACCESS_EVENT_HIGHLIGHT: + cmd = CMD_GBAR_ACCESS_HL; + ret = (int)info->type; + break; + case DBOX_ACCESS_EVENT_ACTIVATE: + cmd = CMD_GBAR_ACCESS_ACTIVATE; + break; + case DBOX_ACCESS_EVENT_ACTION: + cmd = CMD_GBAR_ACCESS_ACTION; + ret = (int)info->type; + break; + case DBOX_ACCESS_EVENT_SCROLL: + cmd = CMD_GBAR_ACCESS_SCROLL; + ret = (int)info->type; + break; + case DBOX_ACCESS_EVENT_VALUE_CHANGE: + cmd = CMD_GBAR_ACCESS_VALUE_CHANGE; + break; + case DBOX_ACCESS_EVENT_MOUSE: + cmd = CMD_GBAR_ACCESS_MOUSE; + ret = (int)info->type; + break; + case DBOX_ACCESS_EVENT_BACK: + cmd = CMD_GBAR_ACCESS_BACK; + break; + case DBOX_ACCESS_EVENT_OVER: + cmd = CMD_GBAR_ACCESS_OVER; + break; + case DBOX_ACCESS_EVENT_READ: + cmd = CMD_GBAR_ACCESS_READ; + break; + case DBOX_ACCESS_EVENT_ENABLE: + cmd = CMD_GBAR_ACCESS_ENABLE; + ret = info->type; + break; + default: + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + } else if (type & DBOX_ACCESS_EVENT_DBOX_MASK) { + w = handler->common->dbox.width; + h = handler->common->dbox.height; + switch (type & ~(DBOX_ACCESS_EVENT_GBAR_MASK | DBOX_ACCESS_EVENT_DBOX_MASK)) { + case DBOX_ACCESS_EVENT_HIGHLIGHT: + cmd = CMD_DBOX_ACCESS_HL; + ret = (int)info->type; + break; + case DBOX_ACCESS_EVENT_ACTIVATE: + cmd = CMD_DBOX_ACCESS_ACTIVATE; + break; + case DBOX_ACCESS_EVENT_ACTION: + cmd = CMD_DBOX_ACCESS_ACTION; + ret = (int)info->type; + break; + case DBOX_ACCESS_EVENT_SCROLL: + cmd = CMD_DBOX_ACCESS_SCROLL; + ret = (int)info->type; + break; + case DBOX_ACCESS_EVENT_VALUE_CHANGE: + cmd = CMD_DBOX_ACCESS_VALUE_CHANGE; + break; + case DBOX_ACCESS_EVENT_MOUSE: + cmd = CMD_DBOX_ACCESS_MOUSE; + ret = (int)info->type; + break; + case DBOX_ACCESS_EVENT_BACK: + cmd = CMD_DBOX_ACCESS_BACK; + break; + case DBOX_ACCESS_EVENT_OVER: + cmd = CMD_DBOX_ACCESS_OVER; + break; + case DBOX_ACCESS_EVENT_READ: + cmd = CMD_DBOX_ACCESS_READ; + break; + case DBOX_ACCESS_EVENT_ENABLE: + cmd = CMD_DBOX_ACCESS_ENABLE; + ret = info->type; + break; + default: + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + } else { + ErrPrint("Invalid event type\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + if (!cb) { + cb = default_access_event_cb; + } + + ret = send_access_event(handler, (const char *)&cmd, info->x * w, info->y * h, ret); + if (ret == (int)DBOX_STATUS_ERROR_NONE) { + handler->cbs.access_event.cb = cb; + handler->cbs.access_event.data = data; + handler->common->request.access_event = 1; + } + + return ret; +} + +EAPI int dynamicbox_feed_mouse_event(dynamicbox_h handler, dynamicbox_mouse_event_type_e type, dynamicbox_mouse_event_info_t info) +{ + int w = 1; + int h = 1; + unsigned int cmd; + + if (!handler || handler->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is invalid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is invalid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + if (!handler->common->id) { + ErrPrint("Handler is not valid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + if (!(type & DBOX_MOUSE_EVENT_MASK)) { + ErrPrint("Invalid content event is used\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + if (type & DBOX_MOUSE_EVENT_GBAR_MASK) { + int flag = 1; + + if (!handler->common->is_gbar_created) { + ErrPrint("GBAR is not created\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + if (!handler->common->gbar.fb) { + ErrPrint("Handler is not valid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + if (type & DBOX_MOUSE_EVENT_MOVE) { + if (fabs(info->x - handler->common->gbar.x) < conf_event_filter() && fabs(info->y - handler->common->gbar.y) < conf_event_filter()) { + return DBOX_STATUS_ERROR_BUSY; + } + } else if (type & DBOX_MOUSE_EVENT_SET) { + flag = 0; + } + + if (flag) { + handler->common->gbar.x = info->x; + handler->common->gbar.y = info->y; + w = handler->common->gbar.width; + h = handler->common->gbar.height; + } + + switch ((type & ~(DBOX_MOUSE_EVENT_GBAR_MASK | DBOX_MOUSE_EVENT_DBOX_MASK))) { + case DBOX_MOUSE_EVENT_ENTER | DBOX_MOUSE_EVENT_MASK: + cmd = CMD_GBAR_MOUSE_ENTER; + break; + case DBOX_MOUSE_EVENT_LEAVE | DBOX_MOUSE_EVENT_MASK: + cmd = CMD_GBAR_MOUSE_LEAVE; + break; + case DBOX_MOUSE_EVENT_UP | DBOX_MOUSE_EVENT_MASK: + cmd = CMD_GBAR_MOUSE_UP; + break; + case DBOX_MOUSE_EVENT_DOWN | DBOX_MOUSE_EVENT_MASK: + cmd = CMD_GBAR_MOUSE_DOWN; + break; + case DBOX_MOUSE_EVENT_MOVE | DBOX_MOUSE_EVENT_MASK: + cmd = CMD_GBAR_MOUSE_MOVE; + break; + case DBOX_MOUSE_EVENT_SET | DBOX_MOUSE_EVENT_MASK: + cmd = CMD_GBAR_MOUSE_SET; + break; + case DBOX_MOUSE_EVENT_UNSET | DBOX_MOUSE_EVENT_MASK: + cmd = CMD_GBAR_MOUSE_UNSET; + break; + case DBOX_MOUSE_EVENT_ON_SCROLL | DBOX_MOUSE_EVENT_MASK: + cmd = CMD_GBAR_MOUSE_ON_SCROLL; + break; + case DBOX_MOUSE_EVENT_ON_HOLD | DBOX_MOUSE_EVENT_MASK: + cmd = CMD_GBAR_MOUSE_ON_HOLD; + break; + case DBOX_MOUSE_EVENT_OFF_SCROLL | DBOX_MOUSE_EVENT_MASK: + cmd = CMD_GBAR_MOUSE_OFF_SCROLL; + break; + case DBOX_MOUSE_EVENT_OFF_HOLD | DBOX_MOUSE_EVENT_MASK: + cmd = CMD_GBAR_MOUSE_OFF_HOLD; + break; + default: + ErrPrint("Invalid event type\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + } else if (type & DBOX_MOUSE_EVENT_DBOX_MASK) { + int flag = 1; + + if (!handler->common->dbox.fb) { + ErrPrint("Handler is not valid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + if (type & DBOX_MOUSE_EVENT_MOVE) { + if (fabs(info->x - handler->common->dbox.x) < conf_event_filter() && fabs(info->y - handler->common->dbox.y) < conf_event_filter()) { + return DBOX_STATUS_ERROR_BUSY; + } + } else if (type & DBOX_MOUSE_EVENT_SET) { + flag = 0; + } + + if (flag) { + handler->common->dbox.x = info->x; + handler->common->dbox.y = info->y; + w = handler->common->dbox.width; + h = handler->common->dbox.height; + } + + switch ((type & ~(DBOX_MOUSE_EVENT_GBAR_MASK | DBOX_MOUSE_EVENT_DBOX_MASK))) { + case DBOX_MOUSE_EVENT_ENTER | DBOX_MOUSE_EVENT_MASK: + cmd = CMD_DBOX_MOUSE_ENTER; + break; + case DBOX_MOUSE_EVENT_LEAVE | DBOX_MOUSE_EVENT_MASK: + cmd = CMD_DBOX_MOUSE_LEAVE; + break; + case DBOX_MOUSE_EVENT_UP | DBOX_MOUSE_EVENT_MASK: + cmd = CMD_DBOX_MOUSE_UP; + break; + case DBOX_MOUSE_EVENT_DOWN | DBOX_MOUSE_EVENT_MASK: + cmd = CMD_DBOX_MOUSE_DOWN; + break; + case DBOX_MOUSE_EVENT_MOVE | DBOX_MOUSE_EVENT_MASK: + if (!handler->common->dbox.mouse_event) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + cmd = CMD_DBOX_MOUSE_MOVE; + break; + case DBOX_MOUSE_EVENT_SET | DBOX_MOUSE_EVENT_MASK: + if (!handler->common->dbox.mouse_event) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + cmd = CMD_DBOX_MOUSE_SET; + break; + case DBOX_MOUSE_EVENT_UNSET | DBOX_MOUSE_EVENT_MASK: + if (!handler->common->dbox.mouse_event) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + cmd = CMD_DBOX_MOUSE_UNSET; + break; + case DBOX_MOUSE_EVENT_ON_SCROLL | DBOX_MOUSE_EVENT_MASK: + cmd = CMD_DBOX_MOUSE_ON_SCROLL; + break; + case DBOX_MOUSE_EVENT_ON_HOLD | DBOX_MOUSE_EVENT_MASK: + cmd = CMD_DBOX_MOUSE_ON_HOLD; + break; + case DBOX_MOUSE_EVENT_OFF_SCROLL | DBOX_MOUSE_EVENT_MASK: + cmd = CMD_DBOX_MOUSE_OFF_SCROLL; + break; + case DBOX_MOUSE_EVENT_OFF_HOLD | DBOX_MOUSE_EVENT_MASK: + cmd = CMD_DBOX_MOUSE_OFF_HOLD; + break; + default: + ErrPrint("Invalid event type\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + } else { + ErrPrint("Invalid event type\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + return send_mouse_event(handler, (const char *)&cmd, info->x * w, info->y * h); +} + +EAPI int dynamicbox_feed_key_event(dynamicbox_h handler, dynamicbox_key_event_type_e type, dynamicbox_key_event_info_t info, dynamicbox_ret_cb cb, void *data) +{ + int ret; + unsigned int cmd; + + if (!handler || handler->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is invalid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is invalid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + if (!handler->common->id) { + ErrPrint("Handler is not valid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + if (!(type & DBOX_KEY_EVENT_MASK)) { + ErrPrint("Invalid key event is used\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + if (handler->common->request.key_event) { + ErrPrint("Previous key event is not completed yet\n"); + return DBOX_STATUS_ERROR_BUSY; + } + + if (type & DBOX_MOUSE_EVENT_GBAR_MASK) { + if (!handler->common->is_gbar_created) { + ErrPrint("GBAR is not created\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + if (!handler->common->gbar.fb) { + ErrPrint("Handler is not valid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + if (type & DBOX_KEY_EVENT_DOWN) { + /*! + * \TODO + * filtering the reproduced events if it is too fast + */ + } else if (type & DBOX_KEY_EVENT_SET) { + /*! + * \TODO + * What can I do for this case? + */ + } + + /*! + * Must be short than 29 bytes. + */ + switch ((type & ~(DBOX_MOUSE_EVENT_GBAR_MASK | DBOX_MOUSE_EVENT_DBOX_MASK))) { + case DBOX_KEY_EVENT_FOCUS_IN | DBOX_KEY_EVENT_MASK: + cmd = CMD_GBAR_KEY_FOCUS_IN; + break; + case DBOX_KEY_EVENT_FOCUS_OUT | DBOX_KEY_EVENT_MASK: + cmd = CMD_GBAR_KEY_FOCUS_OUT; + break; + case DBOX_KEY_EVENT_UP | DBOX_KEY_EVENT_MASK: + cmd = CMD_GBAR_KEY_UP; + break; + case DBOX_KEY_EVENT_DOWN | DBOX_KEY_EVENT_MASK: + cmd = CMD_GBAR_KEY_DOWN; + break; + case DBOX_KEY_EVENT_SET | DBOX_KEY_EVENT_MASK: + cmd = CMD_GBAR_KEY_SET; + break; + case DBOX_KEY_EVENT_UNSET | DBOX_KEY_EVENT_MASK: + cmd = CMD_GBAR_KEY_UNSET; + break; + default: + ErrPrint("Invalid event type\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + } else if (type & DBOX_MOUSE_EVENT_DBOX_MASK) { + if (!handler->common->dbox.fb) { + ErrPrint("Handler is not valid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + if (type & DBOX_KEY_EVENT_DOWN) { + /*! + * \TODO + * filtering the reproduced events if it is too fast + */ + } else if (type & DBOX_KEY_EVENT_SET) { + /*! + * What can I do for this case? + */ + } + + switch ((type & ~(DBOX_MOUSE_EVENT_GBAR_MASK | DBOX_MOUSE_EVENT_DBOX_MASK))) { + case DBOX_KEY_EVENT_FOCUS_IN | DBOX_KEY_EVENT_MASK: + cmd = CMD_DBOX_KEY_FOCUS_IN; + break; + case DBOX_KEY_EVENT_FOCUS_OUT | DBOX_KEY_EVENT_MASK: + cmd = CMD_DBOX_KEY_FOCUS_OUT; + break; + case DBOX_KEY_EVENT_UP | DBOX_KEY_EVENT_MASK: + cmd = CMD_DBOX_KEY_UP; + break; + case DBOX_KEY_EVENT_DOWN | DBOX_KEY_EVENT_MASK: + cmd = CMD_DBOX_KEY_DOWN; + break; + case DBOX_KEY_EVENT_SET | DBOX_KEY_EVENT_MASK: + cmd = CMD_DBOX_KEY_SET; + break; + case DBOX_KEY_EVENT_UNSET | DBOX_KEY_EVENT_MASK: + cmd = CMD_DBOX_KEY_UNSET; + break; + default: + ErrPrint("Invalid event type\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + } else { + ErrPrint("Invalid event type\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + if (!cb) { + cb = default_key_event_cb; + } + + ret = send_key_event(handler, (const char *)&cmd, info->keycode); + if (ret == (int)DBOX_STATUS_ERROR_NONE) { + handler->cbs.key_event.cb = cb; + handler->cbs.key_event.data = data; + handler->common->request.key_event = 1; + } + + return ret; } EAPI const char *dynamicbox_filename(dynamicbox_h handler) { - if (!handler || handler->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is invalid\n"); - return NULL; - } + if (!handler || handler->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is invalid\n"); + return NULL; + } - if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is invalid\n"); - return NULL; - } + if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is invalid\n"); + return NULL; + } - if (!handler->common->id) { - ErrPrint("Handler is not valid\n"); - return NULL; - } + if (!handler->common->id) { + ErrPrint("Handler is not valid\n"); + return NULL; + } - if (handler->common->filename) { - return handler->common->filename; - } + if (handler->common->filename) { + return handler->common->filename; + } - /* Oooops */ - return util_uri_to_path(handler->common->id); + /* Oooops */ + dynamicbox_set_last_status(DBOX_STATUS_ERROR_NONE); + return util_uri_to_path(handler->common->id); } EAPI int dynamicbox_get_glance_bar_size(dynamicbox_h handler, int *w, int *h) { - int _w; - int _h; - - if (!handler || handler->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is invalid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is invalid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - if (!handler->common->id) { - ErrPrint("Handler is not valid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - if (!w) { - w = &_w; - } - if (!h) { - h = &_h; - } - - if (!handler->common->is_gbar_created) { - *w = handler->common->gbar.default_width; - *h = handler->common->gbar.default_height; - } else { - *w = handler->common->gbar.width; - *h = handler->common->gbar.height; - } - - return DBOX_STATUS_ERROR_NONE; -} - -EAPI enum dynamicbox_size_type dynamicbox_size(dynamicbox_h handler) -{ - int w; - int h; - - if (!handler || handler->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is invalid\n"); - return DBOX_SIZE_TYPE_UNKNOWN; - } - - if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is invalid\n"); - return DBOX_SIZE_TYPE_UNKNOWN; - } - - if (!handler->common->id) { - ErrPrint("Handler is not valid\n"); - return DBOX_SIZE_TYPE_UNKNOWN; - } - - w = handler->common->dbox.width; - h = handler->common->dbox.height; - - switch (handler->common->dbox.type) { - case DBOX_TYPE_BUFFER: - case DBOX_TYPE_SCRIPT: - if (!fb_is_created(handler->common->dbox.fb)) { - w = 0; - h = 0; - } - break; - default: - break; - } - - return dynamicbox_service_size_type(w, h); + int _w; + int _h; + + if (!handler || handler->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is invalid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is invalid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + if (!handler->common->id) { + ErrPrint("Handler is not valid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + if (!w) { + w = &_w; + } + if (!h) { + h = &_h; + } + + if (!handler->common->is_gbar_created) { + *w = handler->common->gbar.default_width; + *h = handler->common->gbar.default_height; + } else { + *w = handler->common->gbar.width; + *h = handler->common->gbar.height; + } + + return DBOX_STATUS_ERROR_NONE; +} + +EAPI dynamicbox_size_type_e dynamicbox_size(dynamicbox_h handler) +{ + int w; + int h; + + if (!handler || handler->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is invalid\n"); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return DBOX_SIZE_TYPE_UNKNOWN; + } + + if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is invalid\n"); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return DBOX_SIZE_TYPE_UNKNOWN; + } + + if (!handler->common->id) { + ErrPrint("Handler is not valid\n"); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return DBOX_SIZE_TYPE_UNKNOWN; + } + + w = handler->common->dbox.width; + h = handler->common->dbox.height; + + switch (handler->common->dbox.type) { + case DBOX_TYPE_BUFFER: + case DBOX_TYPE_SCRIPT: + if (!fb_is_created(handler->common->dbox.fb)) { + w = 0; + h = 0; + dynamicbox_set_last_status(DBOX_STATUS_ERROR_NOT_EXIST); + } + break; + default: + break; + } + + return dynamicbox_service_size_type(w, h); } EAPI int dynamicbox_set_group(dynamicbox_h handler, const char *cluster, const char *category, dynamicbox_ret_cb cb, void *data) { - struct packet *packet; - unsigned int cmd = CMD_CHANGE_GROUP; - int ret; - - if (!handler) { - ErrPrint("Handler is NIL\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - if (!cluster || !category || handler->state != DBOX_STATE_CREATE) { - ErrPrint("Invalid argument\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { - ErrPrint("Invalid argument\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - if (!handler->common->id) { - ErrPrint("Invalid argument\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - if (handler->common->request.group_changed) { - ErrPrint("Previous group changing request is not finished yet\n"); - return DBOX_STATUS_ERROR_BUSY; - } - - if (!handler->common->is_user) { - ErrPrint("CA Livebox is not able to change the group\n"); - return DBOX_STATUS_ERROR_PERMISSION_DENIED; - } - - if (!strcmp(handler->common->cluster, cluster) && !strcmp(handler->common->category, category)) { - DbgPrint("No changes\n"); - return DBOX_STATUS_ERROR_ALREADY; - } - - packet = packet_create((const char *)&cmd, "ssss", handler->common->pkgname, handler->common->id, cluster, category); - if (!packet) { - ErrPrint("Failed to build a param\n"); - return DBOX_STATUS_ERROR_FAULT; - } - - if (!cb) { - cb = default_group_changed_cb; - } - - ret = master_rpc_async_request(handler, packet, 0, set_group_ret_cb, NULL); - if (ret == (int)DBOX_STATUS_ERROR_NONE) { - handler->cbs.group_changed.cb = cb; - handler->cbs.group_changed.data = data; - handler->common->request.group_changed = 1; - } - - return ret; + struct packet *packet; + unsigned int cmd = CMD_CHANGE_GROUP; + int ret; + + if (!handler) { + ErrPrint("Handler is NIL\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + if (!cluster || !category || handler->state != DBOX_STATE_CREATE) { + ErrPrint("Invalid argument\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { + ErrPrint("Invalid argument\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + if (!handler->common->id) { + ErrPrint("Invalid argument\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + if (handler->common->request.group_changed) { + ErrPrint("Previous group changing request is not finished yet\n"); + return DBOX_STATUS_ERROR_BUSY; + } + + if (!handler->common->is_user) { + ErrPrint("CA Livebox is not able to change the group\n"); + return DBOX_STATUS_ERROR_PERMISSION_DENIED; + } + + if (!strcmp(handler->common->cluster, cluster) && !strcmp(handler->common->category, category)) { + DbgPrint("No changes\n"); + return DBOX_STATUS_ERROR_ALREADY; + } + + packet = packet_create((const char *)&cmd, "ssss", handler->common->pkgname, handler->common->id, cluster, category); + if (!packet) { + ErrPrint("Failed to build a param\n"); + return DBOX_STATUS_ERROR_FAULT; + } + + if (!cb) { + cb = default_group_changed_cb; + } + + ret = master_rpc_async_request(handler, packet, 0, set_group_ret_cb, NULL); + if (ret == (int)DBOX_STATUS_ERROR_NONE) { + handler->cbs.group_changed.cb = cb; + handler->cbs.group_changed.data = data; + handler->common->request.group_changed = 1; + } + + return ret; } EAPI int dynamicbox_get_group(dynamicbox_h handler, const char **cluster, const char **category) { - if (!handler) { - ErrPrint("Handler is NIL\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!handler) { + ErrPrint("Handler is NIL\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (!cluster || !category || handler->state != DBOX_STATE_CREATE) { - ErrPrint("Invalid argument\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!cluster || !category || handler->state != DBOX_STATE_CREATE) { + ErrPrint("Invalid argument\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { - ErrPrint("Invalid argument\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { + ErrPrint("Invalid argument\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (!handler->common->id) { - ErrPrint("Invalid argument\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!handler->common->id) { + ErrPrint("Invalid argument\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - *cluster = handler->common->cluster; - *category = handler->common->category; - return DBOX_STATUS_ERROR_NONE; + *cluster = handler->common->cluster; + *category = handler->common->category; + return DBOX_STATUS_ERROR_NONE; } -EAPI int dynamicbox_get_supported_sizes(dynamicbox_h handler, int *cnt, int *size_list) +EAPI int dynamicbox_get_supported_sizes(dynamicbox_h handler, int *cnt, dynamicbox_size_type_e *size_list) { - register int i; - register int j; + register int i; + register int j; - if (!handler || !size_list) { - ErrPrint("Invalid argument, handler(%p), size_list(%p)\n", handler, size_list); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!handler || !size_list) { + ErrPrint("Invalid argument, handler(%p), size_list(%p)\n", handler, size_list); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (!cnt || handler->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is not valid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!cnt || handler->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is not valid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is not valid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is not valid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (!handler->common->id) { - ErrPrint("Handler is not valid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!handler->common->id) { + ErrPrint("Handler is not valid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - for (j = i = 0; i < DBOX_NR_OF_SIZE_LIST; i++) { - if (handler->common->dbox.size_list & (0x01 << i)) { - if (j == *cnt) { - break; - } + for (j = i = 0; i < DBOX_NR_OF_SIZE_LIST; i++) { + if (handler->common->dbox.size_list & (0x01 << i)) { + if (j == *cnt) { + break; + } - size_list[j++] = (0x01 << i); - } - } + size_list[j++] = (dynamicbox_size_type_e)(0x01 << i); + } + } - *cnt = j; - return DBOX_STATUS_ERROR_NONE; + *cnt = j; + return DBOX_STATUS_ERROR_NONE; } EAPI const char *dynamicbox_pkgname(dynamicbox_h handler) { - if (!handler) { - ErrPrint("Handler is NIL\n"); - return NULL; - } + if (!handler) { + ErrPrint("Handler is NIL\n"); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return NULL; + } - if (handler->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is not valid\n"); - return NULL; - } + if (handler->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is not valid\n"); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return NULL; + } - if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is not valid\n"); - return NULL; - } + if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is not valid\n"); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return NULL; + } - return handler->common->pkgname; + dynamicbox_set_last_status(DBOX_STATUS_ERROR_NONE); + return handler->common->pkgname; } EAPI double dynamicbox_priority(dynamicbox_h handler) { - if (!handler || handler->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is invalid\n"); - return -1.0f; - } + if (!handler || handler->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is invalid\n"); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return -1.0f; + } - if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is invalid\n"); - return -1.0f; - } + if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is invalid\n"); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return -1.0f; + } - if (!handler->common->id) { - ErrPrint("Handler is not valid (%p)\n", handler); - return -1.0f; - } + if (!handler->common->id) { + ErrPrint("Handler is not valid (%p)\n", handler); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return -1.0f; + } - return handler->common->dbox.priority; + return handler->common->dbox.priority; } EAPI int dynamicbox_delete_cluster(const char *cluster, dynamicbox_ret_cb cb, void *data) { - struct packet *packet; - struct cb_info *cbinfo; - unsigned int cmd = CMD_DELETE_CLUSTER; - int ret; + struct packet *packet; + struct cb_info *cbinfo; + unsigned int cmd = CMD_DELETE_CLUSTER; + int ret; - packet = packet_create((const char *)&cmd, "s", cluster); - if (!packet) { - ErrPrint("Failed to build a param\n"); - return DBOX_STATUS_ERROR_FAULT; - } + packet = packet_create((const char *)&cmd, "s", cluster); + if (!packet) { + ErrPrint("Failed to build a param\n"); + return DBOX_STATUS_ERROR_FAULT; + } - cbinfo = dbox_create_cb_info(cb, data); - if (!cbinfo) { - packet_destroy(packet); - return DBOX_STATUS_ERROR_FAULT; - } + cbinfo = dbox_create_cb_info(cb, data); + if (!cbinfo) { + packet_destroy(packet); + return DBOX_STATUS_ERROR_FAULT; + } - ret = master_rpc_async_request(NULL, packet, 0, delete_cluster_cb, cbinfo); - if (ret < 0) { - dbox_destroy_cb_info(cbinfo); - } + ret = master_rpc_async_request(NULL, packet, 0, delete_cluster_cb, cbinfo); + if (ret < 0) { + dbox_destroy_cb_info(cbinfo); + } - return ret; + return ret; } EAPI int dynamicbox_delete_category(const char *cluster, const char *category, dynamicbox_ret_cb cb, void *data) { - struct packet *packet; - struct cb_info *cbinfo; - unsigned int cmd = CMD_DELETE_CATEGORY; - int ret; - - packet = packet_create((const char *)&cmd, "ss", cluster, category); - if (!packet) { - ErrPrint("Failed to build a param\n"); - return DBOX_STATUS_ERROR_FAULT; - } - - cbinfo = dbox_create_cb_info(cb, data); - if (!cbinfo) { - packet_destroy(packet); - return DBOX_STATUS_ERROR_FAULT; - } - - ret = master_rpc_async_request(NULL, packet, 0, delete_category_cb, cbinfo); - if (ret < 0) { - dbox_destroy_cb_info(cbinfo); - } - - return ret; -} - -EAPI enum dynamicbox_type dynamicbox_type(dynamicbox_h handler, int gbar) -{ - enum dynamicbox_type type; - - if (!handler || handler->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is invalid\n"); - return DBOX_CONTENT_TYPE_INVALID; - } - - if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is invalid\n"); - return DBOX_CONTENT_TYPE_INVALID; - } - - if (!handler->common->id) { - ErrPrint("Handler is not valid\n"); - return DBOX_CONTENT_TYPE_INVALID; - } - - if (gbar) { - switch (handler->common->gbar.type) { - case GBAR_TYPE_TEXT: - return DBOX_CONTENT_TYPE_TEXT; - case GBAR_TYPE_BUFFER: - case GBAR_TYPE_SCRIPT: - { - const char *id; - id = fb_id(handler->common->gbar.fb); - if (id && !strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP))) { - return DBOX_CONTENT_TYPE_RESOURCE_ID; - } - } - return DBOX_CONTENT_TYPE_BUFFER; - case GBAR_TYPE_UIFW: - return DBOX_CONTENT_TYPE_UIFW; - default: - break; - } - - return DBOX_CONTENT_TYPE_INVALID; - } else { - switch (handler->common->dbox.type) { - case DBOX_TYPE_FILE: - return DBOX_CONTENT_TYPE_IMAGE; - case DBOX_TYPE_BUFFER: - case DBOX_TYPE_SCRIPT: - { - const char *id; - id = fb_id(handler->common->dbox.fb); - if (id && !strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP))) { - return DBOX_CONTENT_TYPE_RESOURCE_ID; - } - } - return DBOX_CONTENT_TYPE_BUFFER; - case DBOX_TYPE_TEXT: - return DBOX_CONTENT_TYPE_TEXT; - case DBOX_TYPE_UIFW: - return DBOX_CONTENT_TYPE_UIFW; - default: - break; - } - - return DBOX_CONTENT_TYPE_INVALID; - } - - return type; + struct packet *packet; + struct cb_info *cbinfo; + unsigned int cmd = CMD_DELETE_CATEGORY; + int ret; + + packet = packet_create((const char *)&cmd, "ss", cluster, category); + if (!packet) { + ErrPrint("Failed to build a param\n"); + return DBOX_STATUS_ERROR_FAULT; + } + + cbinfo = dbox_create_cb_info(cb, data); + if (!cbinfo) { + packet_destroy(packet); + return DBOX_STATUS_ERROR_FAULT; + } + + ret = master_rpc_async_request(NULL, packet, 0, delete_category_cb, cbinfo); + if (ret < 0) { + dbox_destroy_cb_info(cbinfo); + } + + return ret; +} + +EAPI dynamicbox_type_e dynamicbox_type(dynamicbox_h handler, int gbar) +{ + if (!handler || handler->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is invalid\n"); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return DBOX_CONTENT_TYPE_INVALID; + } + + if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is invalid\n"); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return DBOX_CONTENT_TYPE_INVALID; + } + + if (!handler->common->id) { + ErrPrint("Handler is not valid\n"); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return DBOX_CONTENT_TYPE_INVALID; + } + + if (gbar) { + switch (handler->common->gbar.type) { + case GBAR_TYPE_TEXT: + return DBOX_CONTENT_TYPE_TEXT; + case GBAR_TYPE_BUFFER: + case GBAR_TYPE_SCRIPT: + { + const char *id; + id = fb_id(handler->common->gbar.fb); + if (id && !strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP))) { + return DBOX_CONTENT_TYPE_RESOURCE_ID; + } + } + return DBOX_CONTENT_TYPE_BUFFER; + case GBAR_TYPE_UIFW: + return DBOX_CONTENT_TYPE_UIFW; + default: + break; + } + } else { + switch (handler->common->dbox.type) { + case DBOX_TYPE_FILE: + return DBOX_CONTENT_TYPE_IMAGE; + case DBOX_TYPE_BUFFER: + case DBOX_TYPE_SCRIPT: + { + const char *id; + id = fb_id(handler->common->dbox.fb); + if (id && !strncasecmp(id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP))) { + return DBOX_CONTENT_TYPE_RESOURCE_ID; + } + } + return DBOX_CONTENT_TYPE_BUFFER; + case DBOX_TYPE_TEXT: + return DBOX_CONTENT_TYPE_TEXT; + case DBOX_TYPE_UIFW: + return DBOX_CONTENT_TYPE_UIFW; + default: + break; + } + } + + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return DBOX_CONTENT_TYPE_INVALID; } EAPI int dynamicbox_set_text_handler(dynamicbox_h handler, int gbar, struct dynamicbox_script_operators *ops) { - if (!handler) { - ErrPrint("Handler is NIL\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - if (handler->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is not valid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!handler) { + ErrPrint("Handler is NIL\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + if (handler->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is not valid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (gbar) { - memcpy(&handler->cbs.gbar_ops, ops, sizeof(*ops)); - } else { - memcpy(&handler->cbs.dbox_ops, ops, sizeof(*ops)); - } + if (gbar) { + memcpy(&handler->cbs.gbar_ops, ops, sizeof(*ops)); + } else { + memcpy(&handler->cbs.dbox_ops, ops, sizeof(*ops)); + } - return DBOX_STATUS_ERROR_NONE; + return DBOX_STATUS_ERROR_NONE; } -EAPI unsigned int dynamicbox_acquire_resource_id(dynamicbox_h handler, int gbar, dynamicbox_ret_cb cb, void *data) +EAPI int dynamicbox_acquire_extra_resource_id(dynamicbox_h handler, int gbar, int idx, dynamicbox_ret_cb cb, void *data) { - if (gbar) { - if (!handler || handler->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is invalid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (idx < 0) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is invalid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!handler || handler->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is invalid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (!handler->common->id) { - ErrPrint("Invalid handle\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is invalid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (handler->common->gbar.type != GBAR_TYPE_SCRIPT && handler->common->gbar.type != GBAR_TYPE_BUFFER) { - ErrPrint("Handler is not valid type\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!handler->common->id) { + ErrPrint("Invalid handle\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - return dbox_acquire_gbar_pixmap(handler, cb, data); - } else { - if (!handler || handler->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is invalid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (gbar) { + if (handler->common->gbar.type != GBAR_TYPE_SCRIPT && handler->common->gbar.type != GBAR_TYPE_BUFFER) { + ErrPrint("Invalid handler\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is invalid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!handler->common->gbar.extra_buffer) { + return DBOX_STATUS_ERROR_NOT_EXIST; + } - if (!handler->common->id) { - ErrPrint("Invalid handle\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (idx >= conf_extra_buffer_count()) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (handler->common->dbox.type != DBOX_TYPE_SCRIPT && handler->common->dbox.type != DBOX_TYPE_BUFFER) { - ErrPrint("Handler is not valid type\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + return dbox_acquire_gbar_extra_pixmap(handler, idx, cb, data); + } else { + if (handler->common->dbox.type != DBOX_TYPE_SCRIPT && handler->common->dbox.type != DBOX_TYPE_BUFFER) { + ErrPrint("Handler is not valid type\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - return dbox_acquire_dbox_pixmap(handler, cb, data); - } -} + if (!handler->common->dbox.extra_buffer) { + return DBOX_STATUS_ERROR_NOT_EXIST; + } -/*! - * \note - * Do not check the state of handler and common-handler. - * If this function is used in the deleted callback, - * the handler and common-handler's state would be DELETE - * if this function check the state of handles, - * user cannot release the pixmap. - */ -EAPI int dynamicbox_release_resource_id(dynamicbox_h handler, int gbar, unsigned int resource_id) -{ - struct packet *packet; - const char *pkgname; - const char *id; - unsigned int cmd; - - if (resource_id == 0 /* || handler->state != DBOX_STATE_CREATE */) { - ErrPrint("Pixmap is invalid [%d]\n", resource_id); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - if (gbar) { - if (!handler) { - /*! - * \note - * Even though the handler is NULL, we should send the release request to the master. - * Because the resource_id resource can be released after the handler is destroyed. - * Pixmap resource is used by client. and it cannot be guaranteed to release resource_id. - * In some cases, the resource_id can be released after the handler is deleted. - * - * Its implementation is up to the viewer app. - * But we cannot force it to use only with valid handler. - */ - DbgPrint("Using NULL handler\n"); - pkgname = NULL; - id = NULL; - /*! - * \note - * Master will try to find the buffer handler using given resource_id. if the pkgname and id is not valid. - */ - } else { - if (!handler->common /* || handler-common->state != DBOX_STATE_CREATE */) { - ErrPrint("Handler is invalid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - if (!handler->common->id) { - ErrPrint("Invalid handle\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - if (handler->common->gbar.type != GBAR_TYPE_SCRIPT && handler->common->gbar.type != GBAR_TYPE_BUFFER) { - ErrPrint("Handler is not valid type\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - pkgname = handler->common->pkgname; - id = handler->common->id; - } - - cmd = CMD_GBAR_RELEASE_PIXMAP; - } else { - if (!handler) { - /*! - * \note - * Even though the handler is NULL, we should send the release request to the master. - * Because the resource_id resource can be released after the handler is destroyed. - * Pixmap resource is used by client. and it cannot be guaranteed to release resource_id. - * In some cases, the resource_id can be released after the handler is deleted. - * - * Its implementation is up to the viewer app. - * But we cannot force it to use only with valid handler. - */ - DbgPrint("Using NULL handler\n"); - pkgname = NULL; - id = NULL; - /*! - * \note - * Master will try to find the buffer handler using given resource_id. if the pkgname and id is not valid. - */ - } else { - if (!handler->common /* || handler->common->state != DBOX_STATE_CREATE */) { - ErrPrint("Handler is invalid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - if (!handler->common->id) { - ErrPrint("Invalid handle\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - if (handler->common->dbox.type != DBOX_TYPE_SCRIPT && handler->common->dbox.type != DBOX_TYPE_BUFFER) { - ErrPrint("Handler is not valid type\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - pkgname = handler->common->pkgname; - id = handler->common->id; - } - - cmd = CMD_DBOX_RELEASE_PIXMAP; - } - - packet = packet_create_noack((const char *)&cmd, "ssi", pkgname, id, resource_id); - if (!packet) { - ErrPrint("Failed to build a param\n"); - return DBOX_STATUS_ERROR_FAULT; - } - - return master_rpc_request_only(handler, packet); -} - -EAPI unsigned int dynamicbox_resource_id(const dynamicbox_h handler, int gbar) -{ - const char *id; - int pixmap = 0; - - if (gbar) { - if (!handler || handler->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is invalid\n"); - return 0; - } - - if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is invalid\n"); - return 0; - } - - if (!handler->common->id) { - ErrPrint("Invalid handler\n"); - return 0; - } - - if (handler->common->gbar.type != GBAR_TYPE_SCRIPT && handler->common->gbar.type != GBAR_TYPE_BUFFER) { - ErrPrint("Invalid handler\n"); - return 0; - } - - id = fb_id(handler->common->gbar.fb); - if (id && sscanf(id, SCHEMA_PIXMAP "%u", (unsigned int *)&pixmap) != 1) { - ErrPrint("PIXMAP Id is not valid\n"); - return 0; - } - } else { - if (!handler || handler->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is invalid\n"); - return 0; - } - - if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is invalid\n"); - return 0; - } - - if (!handler->common->id) { - ErrPrint("Invalid handler\n"); - return 0; - } + if (idx >= conf_extra_buffer_count()) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (handler->common->dbox.type != DBOX_TYPE_SCRIPT && handler->common->dbox.type != DBOX_TYPE_BUFFER) { - ErrPrint("Invalid handler\n"); - return 0; - } - - id = fb_id(handler->common->dbox.fb); - if (id && sscanf(id, SCHEMA_PIXMAP "%u", (unsigned int *)&pixmap) != 1) { - ErrPrint("PIXMAP Id is not valid\n"); - return 0; - } - - } - - return pixmap; + return dbox_acquire_dbox_extra_pixmap(handler, idx, cb, data); + } } -EAPI void *dynamicbox_acquire_fb(dynamicbox_h handler, int gbar) +EAPI int dynamicbox_acquire_resource_id(dynamicbox_h handler, int gbar, dynamicbox_ret_cb cb, void *data) { - if (gbar) { - if (!handler || handler->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is invalid\n"); - return NULL; - } - - if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is invalid\n"); - return NULL; - } - - if (!handler->common->id) { - ErrPrint("Invalid handler\n"); - return NULL; - } - - if (handler->common->gbar.type != GBAR_TYPE_SCRIPT && handler->common->gbar.type != GBAR_TYPE_BUFFER) { - ErrPrint("Handler is not valid type\n"); - return NULL; - } + if (!handler || handler->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is invalid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - return fb_acquire_buffer(handler->common->gbar.fb); - } else { - if (!handler || handler->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is invalid\n"); - return NULL; - } + if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is invalid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is invalid\n"); - return NULL; - } + if (!handler->common->id) { + ErrPrint("Invalid handle\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (!handler->common->id) { - ErrPrint("Invalid handle\n"); - return NULL; - } + if (gbar) { + if (handler->common->gbar.type != GBAR_TYPE_SCRIPT && handler->common->gbar.type != GBAR_TYPE_BUFFER) { + ErrPrint("Handler is not valid type\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (handler->common->dbox.type != DBOX_TYPE_SCRIPT && handler->common->dbox.type != DBOX_TYPE_BUFFER) { - ErrPrint("Handler is not valid type\n"); - return NULL; - } + return dbox_acquire_gbar_pixmap(handler, cb, data); + } else { + if (handler->common->dbox.type != DBOX_TYPE_SCRIPT && handler->common->dbox.type != DBOX_TYPE_BUFFER) { + ErrPrint("Handler is not valid type\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - return fb_acquire_buffer(handler->common->dbox.fb); - } + return dbox_acquire_dbox_pixmap(handler, cb, data); + } } -EAPI int dynamicbox_release_fb(void *buffer) -{ - return fb_release_buffer(buffer); -} - -EAPI int dynamicbox_fb_refcnt(void *buffer) +/*! + * \note + * Do not check the state of handler and common-handler. + * If this function is used in the deleted callback, + * the handler and common-handler's state would be DELETE + * if this function check the state of handles, + * user cannot release the pixmap. + */ +EAPI int dynamicbox_release_resource_id(dynamicbox_h handler, int gbar, unsigned int resource_id) { - return fb_refcnt(buffer); + struct packet *packet; + const char *pkgname; + const char *id; + unsigned int cmd; + + if (resource_id == 0 /* || handler->state != DBOX_STATE_CREATE */) { + ErrPrint("Pixmap is invalid [%d]\n", resource_id); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + if (gbar) { + if (!handler) { + /*! + * \note + * Even though the handler is NULL, we should send the release request to the master. + * Because the resource_id resource can be released after the handler is destroyed. + * Pixmap resource is used by client. and it cannot be guaranteed to release resource_id. + * In some cases, the resource_id can be released after the handler is deleted. + * + * Its implementation is up to the viewer app. + * But we cannot force it to use only with valid handler. + */ + DbgPrint("Using NULL handler\n"); + pkgname = NULL; + id = NULL; + /*! + * \note + * Master will try to find the buffer handler using given resource_id. if the pkgname and id is not valid. + */ + } else { + if (!handler->common /* || handler-common->state != DBOX_STATE_CREATE */) { + ErrPrint("Handler is invalid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + if (!handler->common->id) { + ErrPrint("Invalid handle\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + if (handler->common->gbar.type != GBAR_TYPE_SCRIPT && handler->common->gbar.type != GBAR_TYPE_BUFFER) { + ErrPrint("Handler is not valid type\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + pkgname = handler->common->pkgname; + id = handler->common->id; + } + + cmd = CMD_GBAR_RELEASE_PIXMAP; + } else { + if (!handler) { + /*! + * \note + * Even though the handler is NULL, we should send the release request to the master. + * Because the resource_id resource can be released after the handler is destroyed. + * Pixmap resource is used by client. and it cannot be guaranteed to release resource_id. + * In some cases, the resource_id can be released after the handler is deleted. + * + * Its implementation is up to the viewer app. + * But we cannot force it to use only with valid handler. + */ + DbgPrint("Using NULL handler\n"); + pkgname = NULL; + id = NULL; + /*! + * \note + * Master will try to find the buffer handler using given resource_id. if the pkgname and id is not valid. + */ + } else { + if (!handler->common /* || handler->common->state != DBOX_STATE_CREATE */) { + ErrPrint("Handler is invalid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + if (!handler->common->id) { + ErrPrint("Invalid handle\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + if (handler->common->dbox.type != DBOX_TYPE_SCRIPT && handler->common->dbox.type != DBOX_TYPE_BUFFER) { + ErrPrint("Handler is not valid type\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + pkgname = handler->common->pkgname; + id = handler->common->id; + } + + cmd = CMD_DBOX_RELEASE_PIXMAP; + } + + packet = packet_create_noack((const char *)&cmd, "ssi", pkgname, id, resource_id); + if (!packet) { + ErrPrint("Failed to build a param\n"); + return DBOX_STATUS_ERROR_FAULT; + } + + return master_rpc_request_only(handler, packet); +} + +EAPI unsigned int dynamicbox_extra_resource_id(const dynamicbox_h handler, int gbar, int idx) +{ + if (idx < 0) { + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return 0u; + } + + if (!handler || handler->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is invalid\n"); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return 0u; + } + + if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is invalid\n"); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return 0u; + } + + if (!handler->common->id) { + ErrPrint("Invalid handler\n"); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return 0u; + } + + if (gbar) { + if (handler->common->gbar.type != GBAR_TYPE_SCRIPT && handler->common->gbar.type != GBAR_TYPE_BUFFER) { + ErrPrint("Invalid handler\n"); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return 0u; + } + + if (!handler->common->gbar.extra_buffer || handler->common->gbar.last_extra_buffer_idx < 0) { + dynamicbox_set_last_status(DBOX_STATUS_ERROR_NOT_EXIST); + return 0u; + } + + return handler->common->gbar.extra_buffer[handler->common->gbar.last_extra_buffer_idx]; + } else { + if (handler->common->dbox.type != DBOX_TYPE_SCRIPT && handler->common->dbox.type != DBOX_TYPE_BUFFER) { + ErrPrint("Invalid handler\n"); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return 0u; + } + + if (!handler->common->dbox.extra_buffer || handler->common->dbox.last_extra_buffer_idx < 0) { + dynamicbox_set_last_status(DBOX_STATUS_ERROR_NOT_EXIST); + return 0u; + } + + return handler->common->dbox.extra_buffer[handler->common->dbox.last_extra_buffer_idx]; + } } -EAPI int dynamicbox_fb_buffer_size(dynamicbox_h handler, int gbar) +EAPI unsigned int dynamicbox_resource_id(const dynamicbox_h handler, int gbar) { - if (!handler || handler->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is invalid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is invalid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + const char *id; + unsigned int pixmap = 0u; + + if (!handler || handler->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is invalid\n"); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return 0u; + } + + if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is invalid\n"); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return 0u; + } + + if (!handler->common->id) { + ErrPrint("Invalid handler\n"); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return 0u; + } + + if (gbar) { + if (handler->common->gbar.type != GBAR_TYPE_SCRIPT && handler->common->gbar.type != GBAR_TYPE_BUFFER) { + ErrPrint("Invalid handler\n"); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return 0u; + } + + id = fb_id(handler->common->gbar.fb); + if (id && sscanf(id, SCHEMA_PIXMAP "%u", &pixmap) != 1) { + ErrPrint("PIXMAP Id is not valid\n"); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return 0u; + } + } else { + if (handler->common->dbox.type != DBOX_TYPE_SCRIPT && handler->common->dbox.type != DBOX_TYPE_BUFFER) { + ErrPrint("Invalid handler\n"); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return 0u; + } + + id = fb_id(handler->common->dbox.fb); + if (id && sscanf(id, SCHEMA_PIXMAP "%u", &pixmap) != 1) { + ErrPrint("PIXMAP Id is not valid\n"); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return 0u; + } + } + + return pixmap; +} + +EAPI void *dynamicbox_acquire_buffer(dynamicbox_h handler, int gbar) +{ + if (gbar) { + if (!handler || handler->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is invalid\n"); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return NULL; + } + + if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is invalid\n"); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return NULL; + } + + if (!handler->common->id) { + ErrPrint("Invalid handler\n"); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return NULL; + } + + if (handler->common->gbar.type != GBAR_TYPE_SCRIPT && handler->common->gbar.type != GBAR_TYPE_BUFFER) { + ErrPrint("Handler is not valid type\n"); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return NULL; + } + + return fb_acquire_buffer(handler->common->gbar.fb); + } else { + if (!handler || handler->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is invalid\n"); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return NULL; + } + + if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is invalid\n"); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return NULL; + } + + if (!handler->common->id) { + ErrPrint("Invalid handle\n"); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return NULL; + } + + if (handler->common->dbox.type != DBOX_TYPE_SCRIPT && handler->common->dbox.type != DBOX_TYPE_BUFFER) { + ErrPrint("Handler is not valid type\n"); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return NULL; + } + + return fb_acquire_buffer(handler->common->dbox.fb); + } +} + +EAPI int dynamicbox_release_buffer(void *buffer) +{ + return fb_release_buffer(buffer); +} + +EAPI int dynamicbox_buffer_refcnt(void *buffer) +{ + return fb_refcnt(buffer); +} + +EAPI int dynamicbox_buffer_size(dynamicbox_h handler, int gbar) +{ + if (!handler || handler->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is invalid\n"); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is invalid\n"); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + if (!handler->common->id) { + ErrPrint("Invalid handler\n"); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (!handler->common->id) { - ErrPrint("Invalid handler\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - if (gbar) { - return fb_size(handler->common->gbar.fb); - } else { - return fb_size(handler->common->dbox.fb); - } + if (gbar) { + return fb_size(handler->common->gbar.fb); + } else { + return fb_size(handler->common->dbox.fb); + } } EAPI int dynamicbox_is_created_by_user(dynamicbox_h handler) { - if (!handler || handler->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is invalid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!handler || handler->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is invalid\n"); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is invalid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is invalid\n"); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (!handler->common->id) { - ErrPrint("Invalid handler\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!handler->common->id) { + ErrPrint("Invalid handler\n"); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - return handler->common->is_user; + return handler->common->is_user; } EAPI int dynamicbox_set_pinup(dynamicbox_h handler, int flag, dynamicbox_ret_cb cb, void *data) { - struct packet *packet; - unsigned int cmd = CMD_PINUP_CHANGED; - int ret; + struct packet *packet; + unsigned int cmd = CMD_PINUP_CHANGED; + int ret; - if (!handler || handler->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is invalid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!handler || handler->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is invalid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is invalid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is invalid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (!handler->common->id) { - ErrPrint("Invalid handler\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!handler->common->id) { + ErrPrint("Invalid handler\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (handler->common->request.pinup) { - ErrPrint("Previous pinup request is not finished\n"); - return DBOX_STATUS_ERROR_BUSY; - } + if (handler->common->request.pinup) { + ErrPrint("Previous pinup request is not finished\n"); + return DBOX_STATUS_ERROR_BUSY; + } - if (handler->common->is_pinned_up == flag) { - DbgPrint("No changes\n"); - return DBOX_STATUS_ERROR_ALREADY; - } + if (handler->common->is_pinned_up == flag) { + DbgPrint("No changes\n"); + return DBOX_STATUS_ERROR_ALREADY; + } - packet = packet_create((const char *)&cmd, "ssi", handler->common->pkgname, handler->common->id, flag); - if (!packet) { - ErrPrint("Failed to build a param\n"); - return DBOX_STATUS_ERROR_FAULT; - } + packet = packet_create((const char *)&cmd, "ssi", handler->common->pkgname, handler->common->id, flag); + if (!packet) { + ErrPrint("Failed to build a param\n"); + return DBOX_STATUS_ERROR_FAULT; + } - if (!cb) { - cb = default_pinup_cb; - } + if (!cb) { + cb = default_pinup_cb; + } - ret = master_rpc_async_request(handler, packet, 0, pinup_done_cb, NULL); - if (ret == (int)DBOX_STATUS_ERROR_NONE) { - handler->cbs.pinup.cb = cb; - handler->cbs.pinup.data = data; - handler->common->request.pinup = 1; - } + ret = master_rpc_async_request(handler, packet, 0, pinup_done_cb, NULL); + if (ret == (int)DBOX_STATUS_ERROR_NONE) { + handler->cbs.pinup.cb = cb; + handler->cbs.pinup.data = data; + handler->common->request.pinup = 1; + } - return ret; + return ret; } EAPI int dynamicbox_is_pinned_up(dynamicbox_h handler) { - if (!handler || handler->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is invalid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!handler || handler->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is invalid\n"); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is invalid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is invalid\n"); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (!handler->common->id) { - ErrPrint("Invalid handler\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!handler->common->id) { + ErrPrint("Invalid handler\n"); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - return handler->common->is_pinned_up; + return handler->common->is_pinned_up; } EAPI int dynamicbox_has_pinup(dynamicbox_h handler) { - if (!handler || handler->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is invalid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!handler || handler->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is invalid\n"); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is invalid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is invalid\n"); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (!handler->common->id) { - ErrPrint("Invalid handler\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!handler->common->id) { + ErrPrint("Invalid handler\n"); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - return handler->common->dbox.pinup_supported; + return handler->common->dbox.pinup_supported; } EAPI int dynamicbox_set_data(dynamicbox_h handler, void *data) { - if (!handler) { - ErrPrint("Handler is NIL\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!handler) { + ErrPrint("Handler is NIL\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (handler->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is invalid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (handler->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is invalid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - handler->data = data; - return DBOX_STATUS_ERROR_NONE; + handler->data = data; + return DBOX_STATUS_ERROR_NONE; } EAPI void *dynamicbox_data(dynamicbox_h handler) { - if (!handler) { - ErrPrint("Handler is NIL\n"); - return NULL; - } + if (!handler) { + ErrPrint("Handler is NIL\n"); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return NULL; + } - if (handler->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is invalid\n"); - return NULL; - } + if (handler->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is invalid\n"); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return NULL; + } - return handler->data; + return handler->data; } EAPI const char *dynamicbox_content(dynamicbox_h handler) { - if (!handler || handler->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is invalid\n"); - return NULL; - } + if (!handler || handler->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is invalid\n"); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return NULL; + } - if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { - ErrPrint("Invalid handle\n"); - return NULL; - } + if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { + ErrPrint("Invalid handle\n"); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return NULL; + } - return handler->common->content; + dynamicbox_set_last_status(DBOX_STATUS_ERROR_NONE); + return handler->common->content; } EAPI const char *dynamicbox_title(dynamicbox_h handler) { - if (!handler || handler->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is invalid\n"); - return NULL; - } - - if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { - ErrPrint("Invalid handle\n"); - return NULL; - } - - return handler->common->title; -} - -EAPI int dynamicbox_emit_text_signal(dynamicbox_h handler, const char *emission, const char *source, double sx, double sy, double ex, double ey, dynamicbox_ret_cb cb, void *data) -{ - struct packet *packet; - struct cb_info *cbinfo; - unsigned int cmd = CMD_TEXT_SIGNAL; - int ret; - - if (!handler || handler->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is invalid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is invalid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - if ((handler->common->dbox.type != DBOX_TYPE_TEXT && handler->common->gbar.type != GBAR_TYPE_TEXT) || !handler->common->id) { - ErrPrint("Handler is not valid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - if (!emission) { - emission = ""; - } - - if (!source) { - source = ""; - } - - packet = packet_create((const char *)&cmd, "ssssdddd", - handler->common->pkgname, handler->common->id, emission, source, sx, sy, ex, ey); - if (!packet) { - ErrPrint("Failed to build a param\n"); - return DBOX_STATUS_ERROR_FAULT; - } - - cbinfo = dbox_create_cb_info(cb, data); - if (!cbinfo) { - packet_destroy(packet); - return DBOX_STATUS_ERROR_FAULT; - } - - ret = master_rpc_async_request(handler, packet, 0, text_signal_cb, cbinfo); - if (ret < 0) { - dbox_destroy_cb_info(cbinfo); - } - - return ret; + if (!handler || handler->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is invalid\n"); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return NULL; + } + + if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { + ErrPrint("Invalid handle\n"); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return NULL; + } + + dynamicbox_set_last_status(DBOX_STATUS_ERROR_NONE); + return handler->common->title; +} + +EAPI int dynamicbox_emit_text_signal(dynamicbox_h handler, dynamicbox_text_event_t event_info, dynamicbox_ret_cb cb, void *data) +{ + struct packet *packet; + struct cb_info *cbinfo; + unsigned int cmd = CMD_TEXT_SIGNAL; + int ret; + const char *emission; + const char *source; + + if (!handler || handler->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is invalid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is invalid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + if ((handler->common->dbox.type != DBOX_TYPE_TEXT && handler->common->gbar.type != GBAR_TYPE_TEXT) || !handler->common->id) { + ErrPrint("Handler is not valid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + if (!event_info) { + ErrPrint("Invalid event info\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + emission = event_info->emission; + if (!emission) { + emission = ""; + } + + source = event_info->source; + if (!source) { + source = ""; + } + + packet = packet_create((const char *)&cmd, "ssssdddd", + handler->common->pkgname, handler->common->id, + emission, source, + event_info->geometry.sx, event_info->geometry.sy, + event_info->geometry.ex, event_info->geometry.ey); + if (!packet) { + ErrPrint("Failed to build a param\n"); + return DBOX_STATUS_ERROR_FAULT; + } + + cbinfo = dbox_create_cb_info(cb, data); + if (!cbinfo) { + packet_destroy(packet); + return DBOX_STATUS_ERROR_FAULT; + } + + ret = master_rpc_async_request(handler, packet, 0, text_signal_cb, cbinfo); + if (ret < 0) { + dbox_destroy_cb_info(cbinfo); + } + + return ret; } EAPI int dynamicbox_subscribe_group(const char *cluster, const char *category) { - struct packet *packet; - unsigned int cmd = CMD_SUBSCRIBE; + struct packet *packet; + unsigned int cmd = CMD_SUBSCRIBE; - /*! - * \todo - * Validate the group info using DB - * If the group info is not valid, do not send this request - */ + /*! + * \todo + * Validate the group info using DB + * If the group info is not valid, do not send this request + */ - packet = packet_create_noack((const char *)&cmd, "ss", cluster ? cluster : "", category ? category : ""); - if (!packet) { - ErrPrint("Failed to create a packet\n"); - return DBOX_STATUS_ERROR_FAULT; - } + packet = packet_create_noack((const char *)&cmd, "ss", cluster ? cluster : "", category ? category : ""); + if (!packet) { + ErrPrint("Failed to create a packet\n"); + return DBOX_STATUS_ERROR_FAULT; + } - return master_rpc_request_only(NULL, packet); + return master_rpc_request_only(NULL, packet); } EAPI int dynamicbox_unsubscribe_group(const char *cluster, const char *category) { - struct packet *packet; - unsigned int cmd = CMD_UNSUBSCRIBE; + struct packet *packet; + unsigned int cmd = CMD_UNSUBSCRIBE; - /*! - * \todo - * Validate the group info using DB - * If the group info is not valid, do not send this request - * AND Check the subscribed or not too - */ + /*! + * \todo + * Validate the group info using DB + * If the group info is not valid, do not send this request + * AND Check the subscribed or not too + */ - packet = packet_create_noack((const char *)&cmd, "ss", cluster ? cluster : "", category ? category : ""); - if (!packet) { - ErrPrint("Failed to create a packet\n"); - return DBOX_STATUS_ERROR_FAULT; - } + packet = packet_create_noack((const char *)&cmd, "ss", cluster ? cluster : "", category ? category : ""); + if (!packet) { + ErrPrint("Failed to create a packet\n"); + return DBOX_STATUS_ERROR_FAULT; + } - return master_rpc_request_only(NULL, packet); + return master_rpc_request_only(NULL, packet); } EAPI int dynamicbox_refresh(dynamicbox_h handler, int force) { - struct packet *packet; - unsigned int cmd = CMD_UPDATE; + struct packet *packet; + unsigned int cmd = CMD_UPDATE; - if (!handler || handler->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is invalid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!handler || handler->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is invalid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is not valid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is not valid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (!handler->common->id) { - ErrPrint("Handler is not valid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!handler->common->id) { + ErrPrint("Handler is not valid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - packet = packet_create_noack((const char *)&cmd, "ssi", handler->common->pkgname, handler->common->id, force); - if (!packet) { - ErrPrint("Failed to create a packet\n"); - return DBOX_STATUS_ERROR_FAULT; - } + packet = packet_create_noack((const char *)&cmd, "ssi", handler->common->pkgname, handler->common->id, force); + if (!packet) { + ErrPrint("Failed to create a packet\n"); + return DBOX_STATUS_ERROR_FAULT; + } - return master_rpc_request_only(handler, packet); + return master_rpc_request_only(handler, packet); } EAPI int dynamicbox_refresh_group(const char *cluster, const char *category, int force) { - struct packet *packet; - unsigned int cmd = CMD_REFRESH_GROUP; + struct packet *packet; + unsigned int cmd = CMD_REFRESH_GROUP; - if (!cluster || !category) { - ErrPrint("Invalid argument\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!cluster || !category) { + ErrPrint("Invalid argument\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - packet = packet_create_noack((const char *)&cmd, "ssi", cluster, category, force); - if (!packet) { - ErrPrint("Failed to create a packet\n"); - return DBOX_STATUS_ERROR_FAULT; - } + packet = packet_create_noack((const char *)&cmd, "ssi", cluster, category, force); + if (!packet) { + ErrPrint("Failed to create a packet\n"); + return DBOX_STATUS_ERROR_FAULT; + } - return master_rpc_request_only(NULL, packet); + return master_rpc_request_only(NULL, packet); } -EAPI int dynamicbox_set_visibility(dynamicbox_h handler, enum dynamicbox_visible_state state) +EAPI int dynamicbox_set_visibility(dynamicbox_h handler, dynamicbox_visible_state_e state) { - int old_state; - int ret; + int old_state; + int ret; - if (!handler || handler->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is invalid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!handler || handler->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is invalid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is not valid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is not valid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (!handler->common->id) { - ErrPrint("Handler is not valid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!handler->common->id) { + ErrPrint("Handler is not valid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (!handler->common->is_user) { - /* System cluster dynamicbox cannot be changed its visible states */ - if (state == DBOX_HIDE_WITH_PAUSE) { - ErrPrint("CA Livebox is not able to change the visibility\n"); - return DBOX_STATUS_ERROR_PERMISSION_DENIED; - } - } + if (!handler->common->is_user) { + /* System cluster dynamicbox cannot be changed its visible states */ + if (state == DBOX_HIDE_WITH_PAUSE) { + ErrPrint("CA Livebox is not able to change the visibility\n"); + return DBOX_STATUS_ERROR_PERMISSION_DENIED; + } + } - if (handler->visible == state) { - DbgPrint("%s has no changes\n", handler->common->pkgname); - return DBOX_STATUS_ERROR_ALREADY; - } + if (handler->visible == state) { + DbgPrint("%s has no changes\n", handler->common->pkgname); + return DBOX_STATUS_ERROR_ALREADY; + } - old_state = handler->visible; - handler->visible = state; + old_state = handler->visible; + handler->visible = state; - ret = dbox_set_visibility(handler, state); - if (ret < 0) { - handler->visible = old_state; - } + ret = dbox_set_visibility(handler, state); + if (ret < 0) { + handler->visible = old_state; + } - return ret; + return ret; } -EAPI enum dynamicbox_visible_state dynamicbox_visibility(dynamicbox_h handler) +EAPI dynamicbox_visible_state_e dynamicbox_visibility(dynamicbox_h handler) { - if (!handler || handler->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is invalid\n"); - return DBOX_VISIBLE_ERROR; - } + if (!handler || handler->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is invalid\n"); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return DBOX_VISIBLE_ERROR; + } - if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is not valid\n"); - return DBOX_VISIBLE_ERROR; - } + if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is not valid\n"); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return DBOX_VISIBLE_ERROR; + } - if (!handler->common->id) { - ErrPrint("Handler is not valid\n"); - return DBOX_VISIBLE_ERROR; - } + if (!handler->common->id) { + ErrPrint("Handler is not valid\n"); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return DBOX_VISIBLE_ERROR; + } - return handler->visible; + return handler->visible; } EAPI int dynamicbox_viewer_set_paused(void) { - struct packet *packet; - unsigned int cmd = CMD_CLIENT_PAUSED; + struct packet *packet; + unsigned int cmd = CMD_CLIENT_PAUSED; - packet = packet_create_noack((const char *)&cmd, "d", util_timestamp()); - if (!packet) { - ErrPrint("Failed to create a pause packet\n"); - return DBOX_STATUS_ERROR_FAULT; - } + packet = packet_create_noack((const char *)&cmd, "d", util_timestamp()); + if (!packet) { + ErrPrint("Failed to create a pause packet\n"); + return DBOX_STATUS_ERROR_FAULT; + } - return master_rpc_request_only(NULL, packet); + return master_rpc_request_only(NULL, packet); } EAPI int dynamicbox_viewer_set_resumed(void) { - struct packet *packet; - unsigned int cmd = CMD_CLIENT_RESUMED; + struct packet *packet; + unsigned int cmd = CMD_CLIENT_RESUMED; - packet = packet_create_noack((const char *)&cmd, "d", util_timestamp()); - if (!packet) { - ErrPrint("Failed to create a resume packet\n"); - return DBOX_STATUS_ERROR_FAULT; - } + packet = packet_create_noack((const char *)&cmd, "d", util_timestamp()); + if (!packet) { + ErrPrint("Failed to create a resume packet\n"); + return DBOX_STATUS_ERROR_FAULT; + } - return master_rpc_request_only(NULL, packet); + return master_rpc_request_only(NULL, packet); } -EAPI int dynamicbox_sync_fb(dynamicbox_h handler, int gbar) +EAPI int dynamicbox_sync_buffer(dynamicbox_h handler, int gbar) { - if (!handler || handler->state != DBOX_STATE_CREATE) { - ErrPrint("Invalid handle\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!handler || handler->state != DBOX_STATE_CREATE) { + ErrPrint("Invalid handle\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { - ErrPrint("Invalid handle\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { + ErrPrint("Invalid handle\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (!handler->common->id) { - ErrPrint("Invalid handle\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!handler->common->id) { + ErrPrint("Invalid handle\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (gbar) { - return dbox_sync_gbar_fb(handler->common); - } else { - return dbox_sync_dbox_fb(handler->common); - } + if (gbar) { + return dbox_sync_gbar_fb(handler->common); + } else { + return dbox_sync_dbox_fb(handler->common); + } } -EAPI const char *dynamicbox_alt_icon(dynamicbox_h handler) +EAPI const char *dynamicbox_alternative_icon(dynamicbox_h handler) { - if (!handler || handler->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is not valid[%p]\n", handler); - return NULL; - } + if (!handler || handler->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is not valid[%p]\n", handler); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return NULL; + } - if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is not valid\n"); - return NULL; - } + if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is not valid\n"); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return NULL; + } - return handler->common->alt.icon; + return handler->common->alt.icon; } -EAPI const char *dynamicbox_alt_name(dynamicbox_h handler) +EAPI const char *dynamicbox_alternative_name(dynamicbox_h handler) { - if (!handler || handler->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is not valid[%p]\n", handler); - return NULL; - } + if (!handler || handler->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is not valid[%p]\n", handler); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return NULL; + } - if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is not valid\n"); - return NULL; - } + if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is not valid\n"); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return NULL; + } - return handler->common->alt.name; + return handler->common->alt.name; } -EAPI int dynamicbox_acquire_fb_lock(dynamicbox_h handler, int is_gbar) +EAPI int dynamicbox_acquire_buffer_lock(dynamicbox_h handler, int is_gbar) { - int ret = DBOX_STATUS_ERROR_NONE; - int fd; + int ret = DBOX_STATUS_ERROR_NONE; - if (!handler || handler->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is not valid[%p]\n", handler); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!handler || handler->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is not valid[%p]\n", handler); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { + ErrPrint("Handler is not valid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + if (!handler->common->id) { + ErrPrint("Handler is not valid[%p]\n", handler); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { - ErrPrint("Handler is not valid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (is_gbar) { + ret = dynamicbox_service_acquire_lock(handler->common->gbar.lock); + } else { + ret = dynamicbox_service_acquire_lock(handler->common->dbox.lock); + } - if (!handler->common->id) { - ErrPrint("Handler is not valid[%p]\n", handler); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - if (is_gbar) { - if (!handler->common->gbar.lock || handler->common->gbar.lock_fd < 0) { - DbgPrint("Lock: %s (%d)\n", handler->common->gbar.lock, handler->common->gbar.lock_fd); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - if (fb_type(dbox_get_gbar_fb(handler->common)) == DBOX_FB_TYPE_FILE) { - return DBOX_STATUS_ERROR_NONE; - } - - fd = handler->common->gbar.lock_fd; - } else { - if (!handler->common->dbox.lock || handler->common->dbox.lock_fd < 0) { - DbgPrint("Lock: %s (%d)\n", handler->common->dbox.lock, handler->common->dbox.lock_fd); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - if (fb_type(dbox_get_dbox_fb(handler->common)) == DBOX_FB_TYPE_FILE) { - return DBOX_STATUS_ERROR_NONE; - } - - fd = handler->common->dbox.lock_fd; - } - - ret = dbox_fb_lock(fd); - - return ret == 0 ? DBOX_STATUS_ERROR_NONE : DBOX_STATUS_ERROR_FAULT; + return ret == 0 ? DBOX_STATUS_ERROR_NONE : DBOX_STATUS_ERROR_FAULT; } -EAPI int dynamicbox_release_fb_lock(dynamicbox_h handler, int is_gbar) -{ - int ret = DBOX_STATUS_ERROR_NONE; - int fd; - - if (!handler || handler->state != DBOX_STATE_CREATE) { - ErrPrint("Invalid handle\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } +EAPI int dynamicbox_release_buffer_lock(dynamicbox_h handler, int is_gbar) +{ + int ret = DBOX_STATUS_ERROR_NONE; - if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { - ErrPrint("Invalid handle\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!handler || handler->state != DBOX_STATE_CREATE) { + ErrPrint("Invalid handle\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (!handler->common->id) { - ErrPrint("Handler is not valid[%p]\n", handler); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { + ErrPrint("Invalid handle\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + if (!handler->common->id) { + ErrPrint("Handler is not valid[%p]\n", handler); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + if (is_gbar) { + ret = dynamicbox_service_release_lock(handler->common->gbar.lock); + } else { + ret = dynamicbox_service_release_lock(handler->common->dbox.lock); + } + + return ret == 0 ? DBOX_STATUS_ERROR_NONE : DBOX_STATUS_ERROR_FAULT; +} + +EAPI int dynamicbox_set_option(dynamicbox_option_type_e option, int state) +{ + int ret = DBOX_STATUS_ERROR_NONE; + + switch (option) { + case DBOX_OPTION_MANUAL_SYNC: + conf_set_manual_sync(state); + break; + case DBOX_OPTION_FRAME_DROP_FOR_RESIZE: + conf_set_frame_drop_for_resizing(state); + break; + case DBOX_OPTION_SHARED_CONTENT: + conf_set_shared_content(state); + break; + case DBOX_OPTION_DIRECT_UPDATE: + if (s_info.init_count) { + DbgPrint("Already intialized, this option is not applied\n"); + } + conf_set_direct_update(state); + break; + case DBOX_OPTION_EXTRA_BUFFER_CNT: + ErrPrint("Permission denied\n"); + ret = DBOX_STATUS_ERROR_PERMISSION_DENIED; + break; + default: + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + break; + } + + return ret; +} + +EAPI int dynamicbox_option(dynamicbox_option_type_e option) +{ + int ret; + + dynamicbox_set_last_status(DBOX_STATUS_ERROR_NONE); + switch (option) { + case DBOX_OPTION_MANUAL_SYNC: + ret = conf_manual_sync(); + break; + case DBOX_OPTION_FRAME_DROP_FOR_RESIZE: + ret = conf_frame_drop_for_resizing(); + break; + case DBOX_OPTION_SHARED_CONTENT: + ret = conf_shared_content(); + break; + case DBOX_OPTION_DIRECT_UPDATE: + ret = conf_direct_update(); + break; + case DBOX_OPTION_EXTRA_BUFFER_CNT: + ret = conf_extra_buffer_count(); + break; + default: + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + break; + } + + return ret; +} - if (is_gbar) { - if (!handler->common->gbar.lock || handler->common->gbar.lock_fd < 0) { - DbgPrint("Unlock: %s (%d)\n", handler->common->gbar.lock, handler->common->gbar.lock_fd); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } +EAPI int dynamicbox_set_auto_launch_handler(dynamicbox_auto_launch_handler_cb dbox_launch_handler, void *data) +{ + s_info.launch.handler = dbox_launch_handler; + s_info.launch.data = data; - if (fb_type(dbox_get_gbar_fb(handler->common)) == DBOX_FB_TYPE_FILE) { - return DBOX_STATUS_ERROR_NONE; - } + return DBOX_STATUS_ERROR_NONE; +} - fd = handler->common->gbar.lock_fd; - } else { - if (!handler->common->dbox.lock || handler->common->dbox.lock_fd < 0) { - DbgPrint("Unlock: %s (%d)\n", handler->common->dbox.lock, handler->common->dbox.lock_fd); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } +EAPI int dynamicbox_damage_region_get(dynamicbox_h handler, int gbar, const dynamicbox_damage_region_t *region) +{ + if (!handler || handler->state != DBOX_STATE_CREATE) { + ErrPrint("Invalid handle\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (fb_type(dbox_get_dbox_fb(handler->common)) == DBOX_FB_TYPE_FILE) { - return DBOX_STATUS_ERROR_NONE; - } + if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { + ErrPrint("Invalid handle\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - fd = handler->common->dbox.lock_fd; - } + if (!handler->common->id) { + ErrPrint("Handler is not valid[%p]\n", handler); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - ret = dbox_fb_unlock(fd); + if (gbar) { + region = &handler->common->dbox.last_damage; + } else { + region = &handler->common->gbar.last_damage; + } - return ret == 0 ? DBOX_STATUS_ERROR_NONE : DBOX_STATUS_ERROR_FAULT; + return DBOX_STATUS_ERROR_NONE; } -EAPI int dynamicbox_set_option(enum dynamicbox_option_type option, int state) -{ - int ret = DBOX_STATUS_ERROR_NONE; - - switch (option) { - case DBOX_OPTION_MANUAL_SYNC: - conf_set_manual_sync(state); - break; - case DBOX_OPTION_FRAME_DROP_FOR_RESIZE: - conf_set_frame_drop_for_resizing(state); - break; - case DBOX_OPTION_SHARED_CONTENT: - conf_set_shared_content(state); - break; - case DBOX_OPTION_DIRECT_UPDATE: - if (s_info.init_count) { - DbgPrint("Already intialized, this option is not applied\n"); - } - conf_set_direct_update(state); - break; - default: - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - break; - } - - return ret; -} +EAPI int dynamicbox_get_affected_extra_buffer(dynamicbox_h handler, int gbar, int *idx, unsigned int *resource_id) +{ + int _idx; + unsigned int _resource_id; -EAPI int dynamicbox_option(enum dynamicbox_option_type option) -{ - int ret; + if (!handler || handler->state != DBOX_STATE_CREATE) { + ErrPrint("Invalid handle\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - switch (option) { - case DBOX_OPTION_MANUAL_SYNC: - ret = conf_manual_sync(); - break; - case DBOX_OPTION_FRAME_DROP_FOR_RESIZE: - ret = conf_frame_drop_for_resizing(); - break; - case DBOX_OPTION_SHARED_CONTENT: - ret = conf_shared_content(); - break; - case DBOX_OPTION_DIRECT_UPDATE: - ret = conf_direct_update(); - break; - default: - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - break; - } - - return ret; -} + if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { + ErrPrint("Invalid handle\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } -EAPI int dynamicbox_set_auto_launch_handler(dynamicbox_auto_launch_handler_cb dbox_launch_handler, void *data) -{ - s_info.launch.handler = dbox_launch_handler; - s_info.launch.data = data; + if (!handler->common->id) { + ErrPrint("Handler is not valid[%p]\n", handler); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - return DBOX_STATUS_ERROR_NONE; -} + if (!idx) { + idx = &_idx; + } -EAPI int dynamicbox_damage_region_get(dynamicbox_h handler, int gbar, const dynamicbox_damage_region_t *region) -{ - if (!handler || handler->state != DBOX_STATE_CREATE) { - ErrPrint("Invalid handle\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!resource_id) { + resource_id = &_resource_id; + } - if (!handler->common || handler->common->state != DBOX_STATE_CREATE) { - ErrPrint("Invalid handle\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (gbar) { + if (!handler->common->gbar.extra_buffer || handler->common->gbar.last_extra_buffer_idx < 0) { + return DBOX_STATUS_ERROR_NOT_EXIST; + } - if (!handler->common->id) { - ErrPrint("Handler is not valid[%p]\n", handler); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + *idx = handler->common->gbar.last_extra_buffer_idx; + *resource_id = handler->common->gbar.extra_buffer[*idx]; + } else { + if (!handler->common->dbox.extra_buffer || handler->common->dbox.last_extra_buffer_idx < 0) { + return DBOX_STATUS_ERROR_NOT_EXIST; + } - if (gbar) { - region = &handler->common->dbox.last_damage; - } else { - region = &handler->common->gbar.last_damage; - } + *idx = handler->common->dbox.last_extra_buffer_idx; + *resource_id = handler->common->dbox.extra_buffer[*idx]; + } - return DBOX_STATUS_ERROR_NONE; + return DBOX_STATUS_ERROR_NONE; } /* End of a file */ diff --git a/src/dynamicbox_internal.c b/src/dynamicbox_internal.c index e4b2c34..ef91134 100644 --- a/src/dynamicbox_internal.c +++ b/src/dynamicbox_internal.c @@ -24,1145 +24,1032 @@ int errno; -enum event_state { - INFO_STATE_CALLBACK_IN_IDLE = 0x00, - INFO_STATE_CALLBACK_IN_PROCESSING = 0x01 -}; +typedef enum event_state { + INFO_STATE_CALLBACK_IN_IDLE = 0x00, + INFO_STATE_CALLBACK_IN_PROCESSING = 0x01 +} event_state_e; struct event_info { - int is_deleted; - int (*handler)(dynamicbox_h handler, enum dynamicbox_event_type event, void *data); - void *user_data; + int is_deleted; + int (*handler)(dynamicbox_h handler, dynamicbox_event_type_e event, void *data); + void *user_data; }; struct fault_info { - int is_deleted; - int (*handler)(enum dynamicbox_fault_type event, const char *pkgname, const char *filename, const char *func, void *data); - void *user_data; + int is_deleted; + int (*handler)(dynamicbox_fault_type_e event, const char *pkgname, const char *filename, const char *func, void *data); + void *user_data; }; static struct info { - struct dlist *dynamicbox_common_list; - struct dlist *dynamicbox_list; - struct dlist *event_list; - struct dlist *fault_list; - enum event_state event_state; - enum event_state fault_state; + struct dlist *dynamicbox_common_list; + struct dlist *dynamicbox_list; + struct dlist *event_list; + struct dlist *fault_list; + event_state_e event_state; + event_state_e fault_state; } s_info = { - .dynamicbox_common_list = NULL, - .dynamicbox_list = NULL, - .event_list = NULL, - .fault_list = NULL, - .event_state = INFO_STATE_CALLBACK_IN_IDLE, - .fault_state = INFO_STATE_CALLBACK_IN_IDLE, + .dynamicbox_common_list = NULL, + .dynamicbox_list = NULL, + .event_list = NULL, + .fault_list = NULL, + .event_state = INFO_STATE_CALLBACK_IN_IDLE, + .fault_state = INFO_STATE_CALLBACK_IN_IDLE, }; static inline void default_delete_cb(dynamicbox_h handler, int ret, void *data) { - DbgPrint("Default deleted event handler: %d\n", ret); + DbgPrint("Default deleted event handler: %d\n", ret); } static void del_ret_cb(dynamicbox_h handler, const struct packet *result, void *data) { - struct cb_info *info = data; - int ret; - dynamicbox_ret_cb cb; - void *cbdata; - - cb = info->cb; - cbdata = info->data; - dbox_destroy_cb_info(info); - - if (!result) { - ErrPrint("Connection lost?\n"); - ret = DBOX_STATUS_ERROR_FAULT; - } else if (packet_get(result, "i", &ret) != 1) { - ErrPrint("Invalid argument\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - if (ret == 0) { - handler->cbs.deleted.cb = cb; - handler->cbs.deleted.data = cbdata; - } else if (cb) { - cb(handler, ret, cbdata); - } - - /*! - * \note - * Do not call the deleted callback from here. - * master will send the "deleted" event. - * Then invoke this callback. - * - * if (handler->cbs.deleted.cb) - * handler->cbs.deleted.cb(handler, ret, handler->cbs.deleted.data); - */ -} - -int dbox_destroy_lock_file(struct dynamicbox_common *common, int is_gbar) -{ - if (is_gbar) { - if (!common->gbar.lock) { - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - if (close(common->gbar.lock_fd) < 0) { - ErrPrint("close: %s\n", strerror(errno)); - } - common->gbar.lock_fd = -1; - - if (unlink(common->gbar.lock) < 0) { - ErrPrint("unlink: %s\n", strerror(errno)); - } - - free(common->gbar.lock); - common->gbar.lock = NULL; - } else { - if (!common->dbox.lock) { - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - if (close(common->dbox.lock_fd) < 0) { - ErrPrint("close: %s\n", strerror(errno)); - } - common->dbox.lock_fd = -1; - - if (unlink(common->dbox.lock) < 0) { - ErrPrint("unlink: %s\n", strerror(errno)); - } - - free(common->dbox.lock); - common->dbox.lock = NULL; - } - - return DBOX_STATUS_ERROR_NONE; -} - -int dbox_create_lock_file(struct dynamicbox_common *common, int is_gbar) -{ - int len; - char *file; - - len = strlen(common->id); - file = malloc(len + 20); - if (!file) { - ErrPrint("Heap: %s\n", strerror(errno)); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } - - snprintf(file, len + 20, "%s.%s.lck", util_uri_to_path(common->id), is_gbar ? "pd" : "lb"); - - if (is_gbar) { - common->gbar.lock_fd = open(file, O_RDONLY); - if (common->gbar.lock_fd < 0) { - ErrPrint("open: %s\n", strerror(errno)); - free(file); - return DBOX_STATUS_ERROR_IO_ERROR; - } - - common->gbar.lock = file; - } else { - common->dbox.lock_fd = open(file, O_RDONLY); - if (common->dbox.lock_fd < 0) { - ErrPrint("open: %s\n", strerror(errno)); - free(file); - return DBOX_STATUS_ERROR_IO_ERROR; - } - - common->dbox.lock = file; - } - - return DBOX_STATUS_ERROR_NONE; + struct cb_info *info = data; + int ret; + dynamicbox_ret_cb cb; + void *cbdata; + + cb = info->cb; + cbdata = info->data; + dbox_destroy_cb_info(info); + + if (!result) { + ErrPrint("Connection lost?\n"); + ret = DBOX_STATUS_ERROR_FAULT; + } else if (packet_get(result, "i", &ret) != 1) { + ErrPrint("Invalid argument\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + if (ret == 0) { + handler->cbs.deleted.cb = cb; + handler->cbs.deleted.data = cbdata; + } else if (cb) { + cb(handler, ret, cbdata); + } + + /*! + * \note + * Do not call the deleted callback from here. + * master will send the "deleted" event. + * Then invoke this callback. + * + * if (handler->cbs.deleted.cb) + * handler->cbs.deleted.cb(handler, ret, handler->cbs.deleted.data); + */ } struct dynamicbox_common *dbox_create_common_handle(dynamicbox_h handle, const char *pkgname, const char *cluster, const char *category) { - struct dynamicbox_common *common; - - common = calloc(1, sizeof(*common)); - if (!common) { - ErrPrint("Heap: %s\n", strerror(errno)); - return NULL; - } - - common->pkgname = strdup(pkgname); - if (!common->pkgname) { - free(common); - return NULL; - } - - common->cluster = strdup(cluster); - if (!common->cluster) { - ErrPrint("Error: %s\n", strerror(errno)); - free(common->pkgname); - free(common); - return NULL; - } - - common->category = strdup(category); - if (!common->category) { - ErrPrint("Error: %s\n", strerror(errno)); - free(common->cluster); - free(common->pkgname); - free(common); - return NULL; - } - - /* Data provider will set this */ - common->dbox.type = DBOX_TYPE_FILE; - common->gbar.type = GBAR_TYPE_SCRIPT; - - /* Used for handling the mouse event on a box */ - common->dbox.mouse_event = 0; - - /* Cluster infomration is not determined yet */ - common->nr_of_sizes = 0x01; - - common->timestamp = util_timestamp(); - common->is_user = 1; - common->delete_type = DBOX_DELETE_PERMANENTLY; - common->gbar.lock = NULL; - common->gbar.lock_fd = -1; - common->dbox.lock = NULL; - common->dbox.lock_fd = -1; - - common->state = DBOX_STATE_CREATE; - common->visible = DBOX_SHOW; - - s_info.dynamicbox_common_list = dlist_append(s_info.dynamicbox_common_list, common); - return common; + struct dynamicbox_common *common; + + common = calloc(1, sizeof(*common)); + if (!common) { + ErrPrint("Heap: %s\n", strerror(errno)); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_OUT_OF_MEMORY); + return NULL; + } + + common->pkgname = strdup(pkgname); + if (!common->pkgname) { + free(common); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_OUT_OF_MEMORY); + return NULL; + } + + common->cluster = strdup(cluster); + if (!common->cluster) { + ErrPrint("Error: %s\n", strerror(errno)); + free(common->pkgname); + free(common); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_OUT_OF_MEMORY); + return NULL; + } + + common->category = strdup(category); + if (!common->category) { + ErrPrint("Error: %s\n", strerror(errno)); + free(common->cluster); + free(common->pkgname); + free(common); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_OUT_OF_MEMORY); + return NULL; + } + + /* Data provider will set this */ + common->dbox.type = DBOX_TYPE_FILE; + common->gbar.type = GBAR_TYPE_SCRIPT; + + /* Used for handling the mouse event on a box */ + common->dbox.mouse_event = 0; + + /* Cluster infomration is not determined yet */ + common->nr_of_sizes = 0x01; + + common->timestamp = util_timestamp(); + common->is_user = 1; + common->delete_type = DBOX_DELETE_PERMANENTLY; + + common->gbar.lock = NULL; + common->gbar.last_extra_buffer_idx = -1; + + common->dbox.lock = NULL; + common->dbox.last_extra_buffer_idx = -1; + + common->state = DBOX_STATE_CREATE; + common->visible = DBOX_SHOW; + + s_info.dynamicbox_common_list = dlist_append(s_info.dynamicbox_common_list, common); + return common; } int dbox_destroy_common_handle(struct dynamicbox_common *common) { - dlist_remove_data(s_info.dynamicbox_common_list, common); - - common->state = DBOX_STATE_DESTROYED; - - if (common->filename) { - (void)util_unlink(common->filename); - } - - free(common->cluster); - free(common->category); - free(common->id); - free(common->pkgname); - free(common->filename); - free(common->dbox.auto_launch); - free(common->alt.icon); - free(common->alt.name); - - if (common->dbox.fb) { - fb_destroy(common->dbox.fb); - common->dbox.fb = NULL; - } - - if (common->gbar.fb) { - fb_destroy(common->gbar.fb); - common->gbar.fb = NULL; - } - - return 0; + dlist_remove_data(s_info.dynamicbox_common_list, common); + + common->state = DBOX_STATE_DESTROYED; + + if (common->filename) { + (void)util_unlink(common->filename); + } + + free(common->cluster); + free(common->category); + free(common->id); + free(common->pkgname); + free(common->filename); + free(common->dbox.auto_launch); + free(common->alt.icon); + free(common->alt.name); + + if (common->dbox.fb) { + fb_destroy(common->dbox.fb); + common->dbox.fb = NULL; + } + + if (common->gbar.fb) { + fb_destroy(common->gbar.fb); + common->gbar.fb = NULL; + } + + return 0; } int dbox_common_ref(struct dynamicbox_common *common, dynamicbox_h handle) { - common->dynamicbox_list = dlist_append(common->dynamicbox_list, handle); - common->refcnt++; + common->dynamicbox_list = dlist_append(common->dynamicbox_list, handle); + common->refcnt++; - return common->refcnt; + return common->refcnt; } int dbox_common_unref(struct dynamicbox_common *common, dynamicbox_h handle) { - int refcnt; - dlist_remove_data(common->dynamicbox_list, handle); - refcnt = --common->refcnt; + int refcnt; + dlist_remove_data(common->dynamicbox_list, handle); + refcnt = --common->refcnt; - return refcnt; + return refcnt; } int dbox_set_group(struct dynamicbox_common *common, const char *cluster, const char *category) { - void *pc = NULL; - void *ps = NULL; - - if (cluster) { - pc = strdup(cluster); - if (!pc) { - ErrPrint("Heap: %s (cluster: %s)\n", strerror(errno), cluster); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } - } - - if (category) { - ps = strdup(category); - if (!ps) { - ErrPrint("Heap: %s (category: %s)\n", strerror(errno), category); - free(pc); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } - } - - if (common->cluster) { - free(common->cluster); - } - - if (common->category) { - free(common->category); - } - - common->cluster = pc; - common->category = ps; - - return DBOX_STATUS_ERROR_NONE; + void *pc = NULL; + void *ps = NULL; + + if (cluster) { + pc = strdup(cluster); + if (!pc) { + ErrPrint("Heap: %s (cluster: %s)\n", strerror(errno), cluster); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } + } + + if (category) { + ps = strdup(category); + if (!ps) { + ErrPrint("Heap: %s (category: %s)\n", strerror(errno), category); + free(pc); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } + } + + if (common->cluster) { + free(common->cluster); + } + + if (common->category) { + free(common->category); + } + + common->cluster = pc; + common->category = ps; + + return DBOX_STATUS_ERROR_NONE; } void dbox_set_size(struct dynamicbox_common *common, int w, int h) { - int size_type; + int size_type; - common->dbox.width = w; - common->dbox.height = h; + common->dbox.width = w; + common->dbox.height = h; - size_type = dynamicbox_service_size_type(w, h); - if (size_type != DBOX_SIZE_TYPE_UNKNOWN) { - common->dbox.mouse_event = dynamicbox_service_mouse_event(common->pkgname, size_type); - } + size_type = dynamicbox_service_size_type(w, h); + if (size_type != DBOX_SIZE_TYPE_UNKNOWN) { + common->dbox.mouse_event = dynamicbox_service_mouse_event(common->pkgname, size_type); + } } void dbox_set_update_mode(struct dynamicbox_common *common, int active_mode) { - common->is_active_update = active_mode; + common->is_active_update = active_mode; } void dbox_set_gbarsize(struct dynamicbox_common *common, int w, int h) { - common->gbar.width = w; - common->gbar.height = h; + common->gbar.width = w; + common->gbar.height = h; } void dbox_set_default_gbarsize(struct dynamicbox_common *common, int w, int h) { - common->gbar.default_width = w; - common->gbar.default_height = h; + common->gbar.default_width = w; + common->gbar.default_height = h; } -void dbox_invoke_fault_handler(enum dynamicbox_fault_type event, const char *pkgname, const char *file, const char *func) +void dbox_invoke_fault_handler(dynamicbox_fault_type_e event, const char *pkgname, const char *file, const char *func) { - struct dlist *l; - struct dlist *n; - struct fault_info *info; + struct dlist *l; + struct dlist *n; + struct fault_info *info; - s_info.fault_state = INFO_STATE_CALLBACK_IN_PROCESSING; + s_info.fault_state = INFO_STATE_CALLBACK_IN_PROCESSING; - dlist_foreach_safe(s_info.fault_list, l, n, info) { - if (!info->is_deleted && info->handler(event, pkgname, file, func, info->user_data) == EXIT_FAILURE) { - info->is_deleted = 1; - } + dlist_foreach_safe(s_info.fault_list, l, n, info) { + if (!info->is_deleted && info->handler(event, pkgname, file, func, info->user_data) == EXIT_FAILURE) { + info->is_deleted = 1; + } - if (info->is_deleted) { - s_info.fault_list = dlist_remove(s_info.fault_list, l); - free(info); - } - } + if (info->is_deleted) { + s_info.fault_list = dlist_remove(s_info.fault_list, l); + free(info); + } + } - s_info.fault_state &= ~INFO_STATE_CALLBACK_IN_PROCESSING; + s_info.fault_state &= ~INFO_STATE_CALLBACK_IN_PROCESSING; } -void dbox_invoke_event_handler(dynamicbox_h handler, enum dynamicbox_event_type event) +void dbox_invoke_event_handler(dynamicbox_h handler, dynamicbox_event_type_e event) { - struct dlist *l; - struct dlist *n; - struct event_info *info; - - if (event == DBOX_EVENT_DBOX_UPDATED && handler->common->refcnt > 1) { - if (handler->visible != DBOX_SHOW) { - DbgPrint("Update requested(pending) - %s\n", handler->common->pkgname); - handler->paused_updating++; - return; - } else { - handler->paused_updating = 0; - } - } - - s_info.event_state = INFO_STATE_CALLBACK_IN_PROCESSING; - - dlist_foreach_safe(s_info.event_list, l, n, info) { - if (!info->is_deleted && info->handler(handler, event, info->user_data) == EXIT_FAILURE) { - DbgPrint("Event handler returns EXIT_FAILURE\n"); - info->is_deleted = 1; - } - - if (info->is_deleted) { - s_info.event_list = dlist_remove(s_info.event_list, l); - free(info); - } - } - - s_info.event_state &= ~INFO_STATE_CALLBACK_IN_PROCESSING; + struct dlist *l; + struct dlist *n; + struct event_info *info; + + if (event == DBOX_EVENT_DBOX_UPDATED && handler->common->refcnt > 1) { + if (handler->visible != DBOX_SHOW) { + DbgPrint("Update requested(pending) - %s\n", handler->common->pkgname); + handler->paused_updating++; + return; + } else { + handler->paused_updating = 0; + } + } + + s_info.event_state = INFO_STATE_CALLBACK_IN_PROCESSING; + + dlist_foreach_safe(s_info.event_list, l, n, info) { + if (!info->is_deleted && info->handler(handler, event, info->user_data) == EXIT_FAILURE) { + DbgPrint("Event handler returns EXIT_FAILURE\n"); + info->is_deleted = 1; + } + + if (info->is_deleted) { + s_info.event_list = dlist_remove(s_info.event_list, l); + free(info); + } + } + + s_info.event_state &= ~INFO_STATE_CALLBACK_IN_PROCESSING; } struct dynamicbox_common *dbox_find_common_handle(const char *pkgname, const char *id) { - struct dlist *l; - struct dynamicbox_common *common; + struct dlist *l; + struct dynamicbox_common *common; - dlist_foreach(s_info.dynamicbox_common_list, l, common) { - if (!common->id) { - continue; - } + dlist_foreach(s_info.dynamicbox_common_list, l, common) { + if (!common->id) { + continue; + } - if (!strcmp(common->pkgname, pkgname) && !strcmp(common->id, id)) { - return common; - } - } + if (!strcmp(common->pkgname, pkgname) && !strcmp(common->id, id)) { + return common; + } + } - return NULL; + return NULL; } struct dynamicbox_common *dbox_find_common_handle_by_timestamp(double timestamp) { - struct dlist *l; - struct dynamicbox_common *common; + struct dlist *l; + struct dynamicbox_common *common; - dlist_foreach(s_info.dynamicbox_common_list, l, common) { - if (common->timestamp == timestamp) { - return common; - } - } + dlist_foreach(s_info.dynamicbox_common_list, l, common) { + if (common->timestamp == timestamp) { + return common; + } + } - return NULL; + return NULL; } dynamicbox_h dbox_new_dynamicbox(const char *pkgname, const char *id, double timestamp, const char *cluster, const char *category) { - dynamicbox_h handler; - - handler = calloc(1, sizeof(*handler)); - if (!handler) { - ErrPrint("Failed to create a new dynamicbox\n"); - return NULL; - } - - handler->common = dbox_create_common_handle(handler, pkgname, cluster, category); - if (!handler->common) { - ErrPrint("Heap: %s\n", strerror(errno)); - free(handler); - return NULL; - } - - dbox_common_ref(handler->common, handler); - dbox_set_id(handler->common, id); - handler->common->timestamp = timestamp; - handler->common->state = DBOX_STATE_CREATE; - handler->visible = DBOX_SHOW; - s_info.dynamicbox_list = dlist_append(s_info.dynamicbox_list, handler); - - return dbox_ref(handler); + dynamicbox_h handler; + + handler = calloc(1, sizeof(*handler)); + if (!handler) { + ErrPrint("Failed to create a new dynamicbox\n"); + return NULL; + } + + handler->common = dbox_create_common_handle(handler, pkgname, cluster, category); + if (!handler->common) { + ErrPrint("Heap: %s\n", strerror(errno)); + free(handler); + return NULL; + } + + dbox_common_ref(handler->common, handler); + dbox_set_id(handler->common, id); + handler->common->timestamp = timestamp; + handler->common->state = DBOX_STATE_CREATE; + handler->visible = DBOX_SHOW; + s_info.dynamicbox_list = dlist_append(s_info.dynamicbox_list, handler); + + return dbox_ref(handler); } int dbox_delete_all(void) { - struct dlist *l; - struct dlist *n; - dynamicbox_h handler; + struct dlist *l; + struct dlist *n; + dynamicbox_h handler; - dlist_foreach_safe(s_info.dynamicbox_list, l, n, handler) { - dbox_invoke_event_handler(handler, DBOX_EVENT_DELETED); - dbox_unref(handler, 1); - } + dlist_foreach_safe(s_info.dynamicbox_list, l, n, handler) { + dbox_invoke_event_handler(handler, DBOX_EVENT_DELETED); + dbox_unref(handler, 1); + } - return DBOX_STATUS_ERROR_NONE; + return DBOX_STATUS_ERROR_NONE; } int dbox_set_content(struct dynamicbox_common *common, const char *content) { - char *pc = NULL; - - if (content) { - pc = strdup(content); - if (!pc) { - ErrPrint("heap: %s [%s]\n", strerror(errno), content); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } - } - - free(common->content); - common->content = pc; - return DBOX_STATUS_ERROR_NONE; + char *pc = NULL; + + if (content) { + pc = strdup(content); + if (!pc) { + ErrPrint("heap: %s [%s]\n", strerror(errno), content); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } + } + + free(common->content); + common->content = pc; + return DBOX_STATUS_ERROR_NONE; } int dbox_set_title(struct dynamicbox_common *common, const char *title) { - char *pt = NULL; - - if (title) { - pt = strdup(title); - if (!pt) { - ErrPrint("heap: %s [%s]\n", strerror(errno), title); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } - } - - free(common->title); - common->title = pt; - return DBOX_STATUS_ERROR_NONE; + char *pt = NULL; + + if (title) { + pt = strdup(title); + if (!pt) { + ErrPrint("heap: %s [%s]\n", strerror(errno), title); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } + } + + free(common->title); + common->title = pt; + return DBOX_STATUS_ERROR_NONE; } void dbox_set_size_list(struct dynamicbox_common *common, int size_list) { - common->dbox.size_list = size_list; + common->dbox.size_list = size_list; } void dbox_set_auto_launch(struct dynamicbox_common *common, const char *auto_launch) { - char *pa = NULL; + char *pa = NULL; - if (!auto_launch || !strlen(auto_launch)) { - return; - } + if (!auto_launch || !strlen(auto_launch)) { + return; + } - pa = strdup(auto_launch); - if (!pa) { - ErrPrint("heap: %s, [%s]\n", strerror(errno), auto_launch); - return; - } + pa = strdup(auto_launch); + if (!pa) { + ErrPrint("heap: %s, [%s]\n", strerror(errno), auto_launch); + return; + } - free(common->dbox.auto_launch); - common->dbox.auto_launch = pa; + free(common->dbox.auto_launch); + common->dbox.auto_launch = pa; } void dbox_set_priority(struct dynamicbox_common *common, double priority) { - common->dbox.priority = priority; + common->dbox.priority = priority; } void dbox_set_id(struct dynamicbox_common *common, const char *id) { - char *pi = NULL; - - if (id) { - pi = strdup(id); - if (!pi) { - ErrPrint("heap: %s [%s]\n", strerror(errno), pi); - return; - } - } - - free(common->id); - common->id = pi; + char *pi = NULL; + + if (id) { + pi = strdup(id); + if (!pi) { + ErrPrint("heap: %s [%s]\n", strerror(errno), pi); + return; + } + } + + free(common->id); + common->id = pi; } void dbox_set_filename(struct dynamicbox_common *common, const char *filename) { - if (common->filename) { - if (common->dbox.type == DBOX_TYPE_FILE || common->dbox.type == DBOX_TYPE_TEXT) { - if (common->filename[0] && unlink(common->filename) < 0) { - ErrPrint("unlink: %s (%s)\n", strerror(errno), common->filename); - } - } - - free(common->filename); - } - - common->filename = strdup(filename); - if (!common->filename) { - ErrPrint("Heap: %s\n", strerror(errno)); - } + if (common->filename) { + if (common->dbox.type == DBOX_TYPE_FILE || common->dbox.type == DBOX_TYPE_TEXT) { + if (common->filename[0] && unlink(common->filename) < 0) { + ErrPrint("unlink: %s (%s)\n", strerror(errno), common->filename); + } + } + + free(common->filename); + } + + common->filename = strdup(filename); + if (!common->filename) { + ErrPrint("Heap: %s\n", strerror(errno)); + } } void dbox_set_alt_icon(struct dynamicbox_common *common, const char *icon) { - char *_icon = NULL; + char *_icon = NULL; - if (icon && strlen(icon)) { - _icon = strdup(icon); - if (!_icon) { - ErrPrint("Heap: %s\n", strerror(errno)); - } - } + if (icon && strlen(icon)) { + _icon = strdup(icon); + if (!_icon) { + ErrPrint("Heap: %s\n", strerror(errno)); + } + } - free(common->alt.icon); - common->alt.icon = _icon; + free(common->alt.icon); + common->alt.icon = _icon; } void dbox_set_alt_name(struct dynamicbox_common *common, const char *name) { - char *_name = NULL; + char *_name = NULL; - if (name && strlen(name)) { - _name = strdup(name); - if (!_name) { - ErrPrint("Heap: %s\n", strerror(errno)); - } - } + if (name && strlen(name)) { + _name = strdup(name); + if (!_name) { + ErrPrint("Heap: %s\n", strerror(errno)); + } + } - free(common->alt.name); - common->alt.name = _name; + free(common->alt.name); + common->alt.name = _name; } int dbox_set_dbox_fb(struct dynamicbox_common *common, const char *filename) { - struct fb_info *fb; - - if (!common) { - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - fb = common->dbox.fb; - if (fb && !strcmp(fb_id(fb), filename)) { /*!< BUFFER is not changed, */ - return DBOX_STATUS_ERROR_NONE; - } - - common->dbox.fb = NULL; - - if (!filename || filename[0] == '\0') { - if (fb) { - fb_destroy(fb); - } - return DBOX_STATUS_ERROR_NONE; - } - - common->dbox.fb = fb_create(filename, common->dbox.width, common->dbox.height); - if (!common->dbox.fb) { - ErrPrint("Faield to create a FB\n"); - if (fb) { - fb_destroy(fb); - } - return DBOX_STATUS_ERROR_FAULT; - } - - if (fb) { - fb_destroy(fb); - } - - return DBOX_STATUS_ERROR_NONE; + struct fb_info *fb; + + if (!common) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + fb = common->dbox.fb; + if (fb && !strcmp(fb_id(fb), filename)) { /*!< BUFFER is not changed, */ + return DBOX_STATUS_ERROR_NONE; + } + + common->dbox.fb = NULL; + + if (!filename || filename[0] == '\0') { + if (fb) { + fb_destroy(fb); + } + return DBOX_STATUS_ERROR_NONE; + } + + common->dbox.fb = fb_create(filename, common->dbox.width, common->dbox.height); + if (!common->dbox.fb) { + ErrPrint("Faield to create a FB\n"); + if (fb) { + fb_destroy(fb); + } + return DBOX_STATUS_ERROR_FAULT; + } + + if (fb) { + fb_destroy(fb); + } + + return DBOX_STATUS_ERROR_NONE; } int dbox_set_gbar_fb(struct dynamicbox_common *common, const char *filename) { - struct fb_info *fb; - - if (!common || common->state != DBOX_STATE_CREATE) { - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - fb = common->gbar.fb; - if (fb && !strcmp(fb_id(fb), filename)) { - /* BUFFER is not changed, just update the content */ - return DBOX_STATUS_ERROR_EXIST; - } - common->gbar.fb = NULL; - - if (!filename || filename[0] == '\0') { - if (fb) { - fb_destroy(fb); - } - return DBOX_STATUS_ERROR_NONE; - } - - common->gbar.fb = fb_create(filename, common->gbar.width, common->gbar.height); - if (!common->gbar.fb) { - ErrPrint("Failed to create a FB\n"); - if (fb) { - fb_destroy(fb); - } - return DBOX_STATUS_ERROR_FAULT; - } - - if (fb) { - fb_destroy(fb); - } - return DBOX_STATUS_ERROR_NONE; + struct fb_info *fb; + + if (!common || common->state != DBOX_STATE_CREATE) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + fb = common->gbar.fb; + if (fb && !strcmp(fb_id(fb), filename)) { + /* BUFFER is not changed, just update the content */ + return DBOX_STATUS_ERROR_EXIST; + } + common->gbar.fb = NULL; + + if (!filename || filename[0] == '\0') { + if (fb) { + fb_destroy(fb); + } + return DBOX_STATUS_ERROR_NONE; + } + + common->gbar.fb = fb_create(filename, common->gbar.width, common->gbar.height); + if (!common->gbar.fb) { + ErrPrint("Failed to create a FB\n"); + if (fb) { + fb_destroy(fb); + } + return DBOX_STATUS_ERROR_FAULT; + } + + if (fb) { + fb_destroy(fb); + } + return DBOX_STATUS_ERROR_NONE; } struct fb_info *dbox_get_dbox_fb(struct dynamicbox_common *common) { - return common->dbox.fb; + return common->dbox.fb; } struct fb_info *dbox_get_gbar_fb(struct dynamicbox_common *common) { - return common->gbar.fb; + return common->gbar.fb; } void dbox_set_user(struct dynamicbox_common *common, int user) { - common->is_user = user; + common->is_user = user; } void dbox_set_pinup(struct dynamicbox_common *common, int pinup_supported) { - common->dbox.pinup_supported = pinup_supported; + common->dbox.pinup_supported = pinup_supported; } void dbox_set_text_dbox(struct dynamicbox_common *common) { - common->dbox.type = DBOX_TYPE_TEXT; + common->dbox.type = DBOX_TYPE_TEXT; } void dbox_set_text_gbar(struct dynamicbox_common *common) { - common->gbar.type = GBAR_TYPE_TEXT; + common->gbar.type = GBAR_TYPE_TEXT; } int dbox_text_dbox(struct dynamicbox_common *common) { - return common->dbox.type == DBOX_TYPE_TEXT; + return common->dbox.type == DBOX_TYPE_TEXT; } int dbox_text_gbar(struct dynamicbox_common *common) { - return common->gbar.type == GBAR_TYPE_TEXT; + return common->gbar.type == GBAR_TYPE_TEXT; } void dbox_set_period(struct dynamicbox_common *common, double period) { - common->dbox.period = period; + common->dbox.period = period; } dynamicbox_h dbox_ref(dynamicbox_h handler) { - if (!handler) { - return NULL; - } + if (!handler) { + return NULL; + } - handler->refcnt++; - return handler; + handler->refcnt++; + return handler; } dynamicbox_h dbox_unref(dynamicbox_h handler, int destroy_common) { - if (!handler) { - return NULL; - } - - handler->refcnt--; - if (handler->refcnt > 0) { - return handler; - } - - if (handler->cbs.created.cb) { - handler->cbs.created.cb(handler, DBOX_STATUS_ERROR_FAULT, handler->cbs.created.data); - handler->cbs.created.cb = NULL; - handler->cbs.created.data = NULL; - } - - if (handler->cbs.deleted.cb) { - handler->cbs.deleted.cb(handler, DBOX_STATUS_ERROR_FAULT, handler->cbs.deleted.data); - handler->cbs.deleted.cb = NULL; - handler->cbs.deleted.data = NULL; - } - - if (handler->cbs.pinup.cb) { - handler->cbs.pinup.cb(handler, DBOX_STATUS_ERROR_FAULT, handler->cbs.pinup.data); - handler->cbs.pinup.cb = NULL; - handler->cbs.pinup.data = NULL; - } - - if (handler->cbs.group_changed.cb) { - handler->cbs.group_changed.cb(handler, DBOX_STATUS_ERROR_FAULT, handler->cbs.group_changed.data); - handler->cbs.group_changed.cb = NULL; - handler->cbs.group_changed.data = NULL; - } - - if (handler->cbs.period_changed.cb) { - handler->cbs.period_changed.cb(handler, DBOX_STATUS_ERROR_FAULT, handler->cbs.period_changed.data); - handler->cbs.period_changed.cb = NULL; - handler->cbs.period_changed.data = NULL; - } - - if (handler->cbs.size_changed.cb) { - handler->cbs.size_changed.cb(handler, DBOX_STATUS_ERROR_FAULT, handler->cbs.size_changed.data); - handler->cbs.size_changed.cb = NULL; - handler->cbs.size_changed.data = NULL; - } - - if (handler->cbs.gbar_created.cb) { - handler->cbs.gbar_created.cb(handler, DBOX_STATUS_ERROR_FAULT, handler->cbs.gbar_created.data); - handler->cbs.gbar_created.cb = NULL; - handler->cbs.gbar_created.data = NULL; - } - - if (handler->cbs.gbar_destroyed.cb) { - handler->cbs.gbar_destroyed.cb(handler, DBOX_STATUS_ERROR_FAULT, handler->cbs.gbar_destroyed.data); - handler->cbs.gbar_destroyed.cb = NULL; - handler->cbs.gbar_destroyed.data = NULL; - } - - if (handler->cbs.update_mode.cb) { - handler->cbs.update_mode.cb(handler, DBOX_STATUS_ERROR_FAULT, handler->cbs.update_mode.data); - handler->cbs.update_mode.cb = NULL; - handler->cbs.update_mode.data = NULL; - } - - if (handler->cbs.access_event.cb) { - handler->cbs.access_event.cb(handler, DBOX_ACCESS_STATUS_ERROR, handler->cbs.access_event.data); - handler->cbs.access_event.cb = NULL; - handler->cbs.access_event.data = NULL; - } - - if (handler->cbs.key_event.cb) { - handler->cbs.key_event.cb(handler, DBOX_KEY_STATUS_ERROR, handler->cbs.key_event.data); - handler->cbs.key_event.cb = NULL; - handler->cbs.key_event.data = NULL; - } - - dlist_remove_data(s_info.dynamicbox_list, handler); - - handler->state = DBOX_STATE_DESTROYED; - if (dbox_common_unref(handler->common, handler) == 0) { - if (destroy_common) { - /*! - * \note - * Lock file should be deleted after all callbacks are processed. - */ - dbox_destroy_lock_file(handler->common, 0); - dbox_destroy_common_handle(handler->common); - } - } - free(handler); - DbgPrint("Handler is released\n"); - return NULL; + if (!handler) { + return NULL; + } + + handler->refcnt--; + if (handler->refcnt > 0) { + return handler; + } + + if (handler->cbs.created.cb) { + handler->cbs.created.cb(handler, DBOX_STATUS_ERROR_FAULT, handler->cbs.created.data); + handler->cbs.created.cb = NULL; + handler->cbs.created.data = NULL; + } + + if (handler->cbs.deleted.cb) { + handler->cbs.deleted.cb(handler, DBOX_STATUS_ERROR_FAULT, handler->cbs.deleted.data); + handler->cbs.deleted.cb = NULL; + handler->cbs.deleted.data = NULL; + } + + if (handler->cbs.pinup.cb) { + handler->cbs.pinup.cb(handler, DBOX_STATUS_ERROR_FAULT, handler->cbs.pinup.data); + handler->cbs.pinup.cb = NULL; + handler->cbs.pinup.data = NULL; + } + + if (handler->cbs.group_changed.cb) { + handler->cbs.group_changed.cb(handler, DBOX_STATUS_ERROR_FAULT, handler->cbs.group_changed.data); + handler->cbs.group_changed.cb = NULL; + handler->cbs.group_changed.data = NULL; + } + + if (handler->cbs.period_changed.cb) { + handler->cbs.period_changed.cb(handler, DBOX_STATUS_ERROR_FAULT, handler->cbs.period_changed.data); + handler->cbs.period_changed.cb = NULL; + handler->cbs.period_changed.data = NULL; + } + + if (handler->cbs.size_changed.cb) { + handler->cbs.size_changed.cb(handler, DBOX_STATUS_ERROR_FAULT, handler->cbs.size_changed.data); + handler->cbs.size_changed.cb = NULL; + handler->cbs.size_changed.data = NULL; + } + + if (handler->cbs.gbar_created.cb) { + handler->cbs.gbar_created.cb(handler, DBOX_STATUS_ERROR_FAULT, handler->cbs.gbar_created.data); + handler->cbs.gbar_created.cb = NULL; + handler->cbs.gbar_created.data = NULL; + } + + if (handler->cbs.gbar_destroyed.cb) { + handler->cbs.gbar_destroyed.cb(handler, DBOX_STATUS_ERROR_FAULT, handler->cbs.gbar_destroyed.data); + handler->cbs.gbar_destroyed.cb = NULL; + handler->cbs.gbar_destroyed.data = NULL; + } + + if (handler->cbs.update_mode.cb) { + handler->cbs.update_mode.cb(handler, DBOX_STATUS_ERROR_FAULT, handler->cbs.update_mode.data); + handler->cbs.update_mode.cb = NULL; + handler->cbs.update_mode.data = NULL; + } + + if (handler->cbs.access_event.cb) { + handler->cbs.access_event.cb(handler, DBOX_ACCESS_STATUS_ERROR, handler->cbs.access_event.data); + handler->cbs.access_event.cb = NULL; + handler->cbs.access_event.data = NULL; + } + + if (handler->cbs.key_event.cb) { + handler->cbs.key_event.cb(handler, DBOX_KEY_STATUS_ERROR, handler->cbs.key_event.data); + handler->cbs.key_event.cb = NULL; + handler->cbs.key_event.data = NULL; + } + + dlist_remove_data(s_info.dynamicbox_list, handler); + + handler->state = DBOX_STATE_DESTROYED; + if (dbox_common_unref(handler->common, handler) == 0) { + if (destroy_common) { + /*! + * \note + * Lock file should be deleted after all callbacks are processed. + */ + (void)dynamicbox_service_destroy_lock(handler->common->dbox.lock); + handler->common->dbox.lock = NULL; + dbox_destroy_common_handle(handler->common); + } + } + free(handler); + DbgPrint("Handler is released\n"); + return NULL; } int dbox_send_delete(dynamicbox_h handler, int type, dynamicbox_ret_cb cb, void *data) { - struct packet *packet; - struct cb_info *cbinfo; - int ret; - - if (handler->common->request.deleted) { - ErrPrint("Already in-progress\n"); - if (cb) { - cb(handler, DBOX_STATUS_ERROR_NONE, data); - } - return DBOX_STATUS_ERROR_BUSY; - } - - if (!cb) { - cb = default_delete_cb; - } - - packet = packet_create("delete", "ssid", handler->common->pkgname, handler->common->id, type, handler->common->timestamp); - if (!packet) { - ErrPrint("Failed to build a param\n"); - if (cb) { - cb(handler, DBOX_STATUS_ERROR_FAULT, data); - } - - return DBOX_STATUS_ERROR_FAULT; - } - - cbinfo = dbox_create_cb_info(cb, data); - if (!cbinfo) { - packet_destroy(packet); - ErrPrint("Failed to create cbinfo\n"); - if (cb) { - cb(handler, DBOX_STATUS_ERROR_FAULT, data); - } - - return DBOX_STATUS_ERROR_FAULT; - } - - ret = master_rpc_async_request(handler, packet, 0, del_ret_cb, cbinfo); - if (ret < 0) { - /*! - * Packet is destroyed by master_rpc_async_request. - */ - dbox_destroy_cb_info(cbinfo); - - if (cb) { - cb(handler, DBOX_STATUS_ERROR_FAULT, data); - } - } else { - handler->common->request.deleted = 1; - } - - return ret; + struct packet *packet; + struct cb_info *cbinfo; + int ret; + + if (handler->common->request.deleted) { + ErrPrint("Already in-progress\n"); + if (cb) { + cb(handler, DBOX_STATUS_ERROR_NONE, data); + } + return DBOX_STATUS_ERROR_BUSY; + } + + if (!cb) { + cb = default_delete_cb; + } + + packet = packet_create("delete", "ssid", handler->common->pkgname, handler->common->id, type, handler->common->timestamp); + if (!packet) { + ErrPrint("Failed to build a param\n"); + if (cb) { + cb(handler, DBOX_STATUS_ERROR_FAULT, data); + } + + return DBOX_STATUS_ERROR_FAULT; + } + + cbinfo = dbox_create_cb_info(cb, data); + if (!cbinfo) { + packet_destroy(packet); + ErrPrint("Failed to create cbinfo\n"); + if (cb) { + cb(handler, DBOX_STATUS_ERROR_FAULT, data); + } + + return DBOX_STATUS_ERROR_FAULT; + } + + ret = master_rpc_async_request(handler, packet, 0, del_ret_cb, cbinfo); + if (ret < 0) { + /*! + * Packet is destroyed by master_rpc_async_request. + */ + dbox_destroy_cb_info(cbinfo); + + if (cb) { + cb(handler, DBOX_STATUS_ERROR_FAULT, data); + } + } else { + handler->common->request.deleted = 1; + } + + return ret; } int dbox_sync_dbox_fb(struct dynamicbox_common *common) { - int ret; + int ret; - if (fb_type(dbox_get_dbox_fb(common)) == DBOX_FB_TYPE_FILE && common->dbox.lock_fd >= 0) { - (void)dbox_fb_lock(common->dbox.lock_fd); - ret = fb_sync(dbox_get_dbox_fb(common), common->dbox.last_damage.x, common->dbox.last_damage.y, common->dbox.last_damage.w, common->dbox.last_damage.h); - (void)dbox_fb_unlock(common->dbox.lock_fd); - } else { - ret = fb_sync(dbox_get_dbox_fb(common), common->dbox.last_damage.x, common->dbox.last_damage.y, common->dbox.last_damage.w, common->dbox.last_damage.h); - } + if (fb_type(dbox_get_dbox_fb(common)) == DBOX_FB_TYPE_FILE) { + (void)dynamicbox_service_acquire_lock(common->dbox.lock); + ret = fb_sync(dbox_get_dbox_fb(common), common->dbox.last_damage.x, common->dbox.last_damage.y, common->dbox.last_damage.w, common->dbox.last_damage.h); + (void)dynamicbox_service_release_lock(common->dbox.lock); + } else { + ret = fb_sync(dbox_get_dbox_fb(common), common->dbox.last_damage.x, common->dbox.last_damage.y, common->dbox.last_damage.w, common->dbox.last_damage.h); + } - return ret; + return ret; } int dbox_sync_gbar_fb(struct dynamicbox_common *common) { - int ret; + int ret; - if (fb_type(dbox_get_gbar_fb(common)) == DBOX_FB_TYPE_FILE && common->gbar.lock_fd >= 0) { - (void)dbox_fb_lock(common->gbar.lock_fd); - ret = fb_sync(dbox_get_gbar_fb(common), common->gbar.last_damage.x, common->gbar.last_damage.y, common->gbar.last_damage.w, common->gbar.last_damage.h); - (void)dbox_fb_unlock(common->gbar.lock_fd); - } else { - ret = fb_sync(dbox_get_gbar_fb(common), common->gbar.last_damage.x, common->gbar.last_damage.y, common->gbar.last_damage.w, common->gbar.last_damage.h); - } + if (fb_type(dbox_get_gbar_fb(common)) == DBOX_FB_TYPE_FILE) { + (void)dynamicbox_service_acquire_lock(common->gbar.lock); + ret = fb_sync(dbox_get_gbar_fb(common), common->gbar.last_damage.x, common->gbar.last_damage.y, common->gbar.last_damage.w, common->gbar.last_damage.h); + (void)dynamicbox_service_release_lock(common->gbar.lock); + } else { + ret = fb_sync(dbox_get_gbar_fb(common), common->gbar.last_damage.x, common->gbar.last_damage.y, common->gbar.last_damage.w, common->gbar.last_damage.h); + } - return ret; -} - -int dbox_fb_lock(int fd) -{ - struct flock flock; - int ret; - - flock.l_type = F_RDLCK; - flock.l_whence = SEEK_SET; - flock.l_start = 0; - flock.l_len = 0; - flock.l_pid = getpid(); - - do { - ret = fcntl(fd, F_SETLKW, &flock); - if (ret < 0) { - ret = errno; - ErrPrint("fcntl: %s\n", strerror(errno)); - } - } while (ret == EINTR); - - return ret; -} - -int dbox_fb_unlock(int fd) -{ - struct flock flock; - int ret; - - flock.l_type = F_UNLCK; - flock.l_whence = SEEK_SET; - flock.l_start = 0; - flock.l_len = 0; - flock.l_pid = getpid(); - - do { - ret = fcntl(fd, F_SETLKW, &flock); - if (ret < 0) { - ret = errno; - ErrPrint("fcntl: %s\n", strerror(errno)); - } - } while (ret == EINTR); - - return ret; + return ret; } struct dynamicbox_common *dbox_find_sharable_common_handle(const char *pkgname, const char *content, int w, int h, const char *cluster, const char *category) { - struct dlist *l; - struct dynamicbox_common *common; - - if (!conf_shared_content()) { - /*! - * Shared content option is turnned off. - */ - return NULL; - } - - dlist_foreach(s_info.dynamicbox_common_list, l, common) { - if (common->state != DBOX_STATE_CREATE) { - continue; - } - - if (strcmp(common->pkgname, pkgname)) { - continue; - } - - if (strcmp(common->cluster, cluster)) { - DbgPrint("Cluster mismatched\n"); - continue; - } - - if (strcmp(common->category, category)) { - DbgPrint("Category mismatched\n"); - continue; - } - - if (common->content && content) { - if (strcmp(common->content, content)) { - DbgPrint("%s Content ([%s] <> [%s])\n", common->pkgname, common->content, content); - continue; - } - } else { - int c1_len; - int c2_len; - - /*! - * \note - * We assumes "" (ZERO length string) to NULL - */ - c1_len = common->content ? strlen(common->content) : 0; - c2_len = content ? strlen(content) : 0; - if (c1_len != c2_len) { - DbgPrint("%s Content %p <> %p\n", common->pkgname, common->content, content); - continue; - } - } - - if (common->request.size_changed) { - DbgPrint("Changing size\n"); - /*! - * \note - * Do not re-use resizing instance. - * We will not use predicted size. - */ - continue; - } - - if (common->request.created) { - DbgPrint("Creating now but re-use it (%s)\n", common->pkgname); - } - - if (common->dbox.width != w || common->dbox.height != h) { - DbgPrint("Size mismatched\n"); - continue; - } - - DbgPrint("common handle is found: %p\n", common); - return common; - } - - return NULL; + struct dlist *l; + struct dynamicbox_common *common; + + if (!conf_shared_content()) { + /*! + * Shared content option is turnned off. + */ + return NULL; + } + + dlist_foreach(s_info.dynamicbox_common_list, l, common) { + if (common->state != DBOX_STATE_CREATE) { + continue; + } + + if (strcmp(common->pkgname, pkgname)) { + continue; + } + + if (strcmp(common->cluster, cluster)) { + DbgPrint("Cluster mismatched\n"); + continue; + } + + if (strcmp(common->category, category)) { + DbgPrint("Category mismatched\n"); + continue; + } + + if (common->content && content) { + if (strcmp(common->content, content)) { + DbgPrint("%s Content ([%s] <> [%s])\n", common->pkgname, common->content, content); + continue; + } + } else { + int c1_len; + int c2_len; + + /*! + * \note + * We assumes "" (ZERO length string) to NULL + */ + c1_len = common->content ? strlen(common->content) : 0; + c2_len = content ? strlen(content) : 0; + if (c1_len != c2_len) { + DbgPrint("%s Content %p <> %p\n", common->pkgname, common->content, content); + continue; + } + } + + if (common->request.size_changed) { + DbgPrint("Changing size\n"); + /*! + * \note + * Do not re-use resizing instance. + * We will not use predicted size. + */ + continue; + } + + if (common->request.created) { + DbgPrint("Creating now but re-use it (%s)\n", common->pkgname); + } + + if (common->dbox.width != w || common->dbox.height != h) { + DbgPrint("Size mismatched\n"); + continue; + } + + DbgPrint("common handle is found: %p\n", common); + return common; + } + + return NULL; } dynamicbox_h dbox_find_dbox_in_show(struct dynamicbox_common *common) { - struct dlist *l; - dynamicbox_h item; + struct dlist *l; + dynamicbox_h item; - dlist_foreach(common->dynamicbox_list, l, item) { - if (item->visible == DBOX_SHOW) { - DbgPrint("%s visibility is not changed\n", common->pkgname); - return item; - } - } + dlist_foreach(common->dynamicbox_list, l, item) { + if (item->visible == DBOX_SHOW) { + DbgPrint("%s visibility is not changed\n", common->pkgname); + return item; + } + } - return NULL; + return NULL; } dynamicbox_h dbox_get_dbox_nth(struct dynamicbox_common *common, int nth) { - dynamicbox_h item; - struct dlist *l; + dynamicbox_h item; + struct dlist *l; - l = dlist_nth(common->dynamicbox_list, nth); - item = dlist_data(l); + l = dlist_nth(common->dynamicbox_list, nth); + item = dlist_data(l); - return item; + return item; } int dbox_add_event_handler(dynamicbox_event_handler_cb dbox_cb, void *data) { - struct event_info *info; - info = malloc(sizeof(*info)); - if (!info) { - ErrPrint("Heap: %s\n", strerror(errno)); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } - - info->handler = dbox_cb; - info->user_data = data; - info->is_deleted = 0; - - s_info.event_list = dlist_append(s_info.event_list, info); - return DBOX_STATUS_ERROR_NONE; + struct event_info *info; + info = malloc(sizeof(*info)); + if (!info) { + ErrPrint("Heap: %s\n", strerror(errno)); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } + + info->handler = dbox_cb; + info->user_data = data; + info->is_deleted = 0; + + s_info.event_list = dlist_append(s_info.event_list, info); + return DBOX_STATUS_ERROR_NONE; } void *dbox_remove_event_handler(dynamicbox_event_handler_cb dbox_cb) { - struct event_info *info; - struct dlist *l; + struct event_info *info; + struct dlist *l; - dlist_foreach(s_info.event_list, l, info) { - if (info->handler == dbox_cb) { - void *data; + dlist_foreach(s_info.event_list, l, info) { + if (info->handler == dbox_cb) { + void *data; - data = info->user_data; + data = info->user_data; - if (s_info.event_state == INFO_STATE_CALLBACK_IN_PROCESSING) { - info->is_deleted = 1; - } else { - s_info.event_list = dlist_remove(s_info.event_list, l); - free(info); - } + if (s_info.event_state == INFO_STATE_CALLBACK_IN_PROCESSING) { + info->is_deleted = 1; + } else { + s_info.event_list = dlist_remove(s_info.event_list, l); + free(info); + } - return data; - } - } + return data; + } + } - return NULL; + return NULL; } int dbox_add_fault_handler(dynamicbox_fault_handler_cb dbox_cb, void *data) { - struct fault_info *info; - info = malloc(sizeof(*info)); - if (!info) { - ErrPrint("Heap: %s\n", strerror(errno)); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } - - info->handler = dbox_cb; - info->user_data = data; - info->is_deleted = 0; - - s_info.fault_list = dlist_append(s_info.fault_list, info); - return DBOX_STATUS_ERROR_NONE; + struct fault_info *info; + info = malloc(sizeof(*info)); + if (!info) { + ErrPrint("Heap: %s\n", strerror(errno)); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } + + info->handler = dbox_cb; + info->user_data = data; + info->is_deleted = 0; + + s_info.fault_list = dlist_append(s_info.fault_list, info); + return DBOX_STATUS_ERROR_NONE; } void *dbox_remove_fault_handler(dynamicbox_fault_handler_cb dbox_cb) { - struct fault_info *info; - struct dlist *l; + struct fault_info *info; + struct dlist *l; - dlist_foreach(s_info.fault_list, l, info) { - if (info->handler == dbox_cb) { - void *data; + dlist_foreach(s_info.fault_list, l, info) { + if (info->handler == dbox_cb) { + void *data; - data = info->user_data; + data = info->user_data; - if (s_info.fault_state == INFO_STATE_CALLBACK_IN_PROCESSING) { - info->is_deleted = 1; - } else { - s_info.fault_list = dlist_remove(s_info.fault_list, l); - free(info); - } + if (s_info.fault_state == INFO_STATE_CALLBACK_IN_PROCESSING) { + info->is_deleted = 1; + } else { + s_info.fault_list = dlist_remove(s_info.fault_list, l); + free(info); + } - return data; - } - } + return data; + } + } - return NULL; + return NULL; } struct cb_info *dbox_create_cb_info(dynamicbox_ret_cb cb, void *data) { - struct cb_info *info; + struct cb_info *info; - info = malloc(sizeof(*info)); - if (!info) { - ErrPrint("Heap: %s\n", strerror(errno)); - return NULL; - } + info = malloc(sizeof(*info)); + if (!info) { + ErrPrint("Heap: %s\n", strerror(errno)); + return NULL; + } - info->cb = cb; - info->data = data; - return info; + info->cb = cb; + info->data = data; + return info; } void dbox_destroy_cb_info(struct cb_info *info) { - free(info); + free(info); } /* End of a file */ diff --git a/src/fb.c b/src/fb.c index 041bf09..6f79ebf 100644 --- a/src/fb.c +++ b/src/fb.c @@ -41,629 +41,632 @@ int errno; -struct fb_info { - char *id; - int w; - int h; - int bufsz; - void *buffer; - - int pixels; - int handle; -}; - static struct { - Display *disp; - int screen; - Visual *visual; - int disp_is_opened; + Display *disp; + int screen; + Visual *visual; + int disp_is_opened; } s_info = { - .disp = NULL, - .disp_is_opened = 0, - .screen = -1, - .visual = NULL, + .disp = NULL, + .disp_is_opened = 0, + .screen = -1, + .visual = NULL, }; int fb_init(void *disp) { - s_info.disp = disp; - if (s_info.disp) { - Screen *screen; + s_info.disp = disp; + if (s_info.disp) { + Screen *screen; - screen = DefaultScreenOfDisplay(s_info.disp); + screen = DefaultScreenOfDisplay(s_info.disp); - s_info.screen = DefaultScreen(s_info.disp); - s_info.visual = DefaultVisualOfScreen(screen); - } + s_info.screen = DefaultScreen(s_info.disp); + s_info.visual = DefaultVisualOfScreen(screen); + } - return DBOX_STATUS_ERROR_NONE; + return DBOX_STATUS_ERROR_NONE; } int fb_fini(void) { - if (s_info.disp_is_opened && s_info.disp) { - XCloseDisplay(s_info.disp); - } - - s_info.disp = NULL; - s_info.disp_is_opened = 0; - s_info.visual = NULL; - s_info.screen = -1; - return 0; + if (s_info.disp_is_opened && s_info.disp) { + XCloseDisplay(s_info.disp); + } + + s_info.disp = NULL; + s_info.disp_is_opened = 0; + s_info.visual = NULL; + s_info.screen = -1; + return 0; } static inline void update_fb_size(struct fb_info *info) { - info->bufsz = info->w * info->h * info->pixels; + info->bufsz = info->w * info->h * info->pixels; } static int sync_for_file(struct fb_info *info, int x, int y, int w, int h) { - int fd; - dynamicbox_fb_t buffer; - - buffer = info->buffer; - - if (!buffer) { /* Ignore this sync request */ - return DBOX_STATUS_ERROR_NONE; - } - - if (buffer->state != DBOX_FB_STATE_CREATED) { - ErrPrint("Invalid state of a FB\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - if (buffer->type != DBOX_FB_TYPE_FILE) { - ErrPrint("Invalid buffer\n"); - return DBOX_STATUS_ERROR_NONE; - } - - fd = open(util_uri_to_path(info->id), O_RDONLY); - if (fd < 0) { - ErrPrint("Failed to open a file (%s) because of (%s)\n", - util_uri_to_path(info->id), strerror(errno)); - - /** - * @note - * But return ZERO, even if we couldn't get a buffer file, - * the viewer can draw empty screen. - * - * and then update it after it gots update events - */ - return DBOX_STATUS_ERROR_NONE; - } - - /** - * @note - * Could we get some advantage if we load a part of file instead of loading all of them? - */ - if (x != 0 || y != 0 || info->w != w || info->h != h) { - int iy; - register int index; - register int width; - - for (iy = y; iy < h; iy++) { - index = iy * info->w + x; - width = w * info->pixels; - - if (lseek(fd, index * info->pixels, SEEK_SET) != index * info->pixels) { - ErrPrint("lseek: %s\n", strerror(errno)); - if (close(fd) < 0) { - ErrPrint("close: %s\n", strerror(errno)); - } - /** - * @note - * But return ZERO, even if we couldn't get a buffer file, - * the viewer can draw empty screen. - * - * and then update it after it gots update events - */ - return DBOX_STATUS_ERROR_NONE; - } - - if (read(fd, ((unsigned int *)buffer->data) + index, width) != width) { - if (close(fd) < 0) { - ErrPrint("close: %s\n", strerror(errno)); - } - /** - * @note - * But return ZERO, even if we couldn't get a buffer file, - * the viewer can draw empty screen. - * - * and then update it after it gots update events - */ - return DBOX_STATUS_ERROR_NONE; - } - } - } else { - if (read(fd, buffer->data, info->bufsz) != info->bufsz) { - ErrPrint("read: %s\n", strerror(errno)); - if (close(fd) < 0) { - ErrPrint("close: %s\n", strerror(errno)); - } - - /** - * @note - * But return ZERO, even if we couldn't get a buffer file, - * the viewer can draw empty screen. - * - * and then update it after it gots update events - */ - return DBOX_STATUS_ERROR_NONE; - } - } - - if (close(fd) < 0) { - ErrPrint("close: %s\n", strerror(errno)); - } - return DBOX_STATUS_ERROR_NONE; + int fd; + dynamicbox_fb_t buffer; + + buffer = info->buffer; + + if (!buffer) { /* Ignore this sync request */ + return DBOX_STATUS_ERROR_NONE; + } + + if (buffer->state != DBOX_FB_STATE_CREATED) { + ErrPrint("Invalid state of a FB\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + if (buffer->type != DBOX_FB_TYPE_FILE) { + ErrPrint("Invalid buffer\n"); + return DBOX_STATUS_ERROR_NONE; + } + + fd = open(util_uri_to_path(info->id), O_RDONLY); + if (fd < 0) { + ErrPrint("Failed to open a file (%s) because of (%s)\n", + util_uri_to_path(info->id), strerror(errno)); + + /** + * @note + * But return ZERO, even if we couldn't get a buffer file, + * the viewer can draw empty screen. + * + * and then update it after it gots update events + */ + return DBOX_STATUS_ERROR_NONE; + } + + /** + * @note + * Could we get some advantage if we load a part of file instead of loading all of them? + */ + if (x != 0 || y != 0 || info->w != w || info->h != h) { + int iy; + register int index; + register int width; + + for (iy = y; iy < h; iy++) { + index = iy * info->w + x; + width = w * info->pixels; + + if (lseek(fd, index * info->pixels, SEEK_SET) != index * info->pixels) { + ErrPrint("lseek: %s\n", strerror(errno)); + if (close(fd) < 0) { + ErrPrint("close: %s\n", strerror(errno)); + } + /** + * @note + * But return ZERO, even if we couldn't get a buffer file, + * the viewer can draw empty screen. + * + * and then update it after it gots update events + */ + return DBOX_STATUS_ERROR_NONE; + } + + if (read(fd, ((unsigned int *)buffer->data) + index, width) != width) { + if (close(fd) < 0) { + ErrPrint("close: %s\n", strerror(errno)); + } + /** + * @note + * But return ZERO, even if we couldn't get a buffer file, + * the viewer can draw empty screen. + * + * and then update it after it gots update events + */ + return DBOX_STATUS_ERROR_NONE; + } + } + } else { + if (read(fd, buffer->data, info->bufsz) != info->bufsz) { + ErrPrint("read: %s\n", strerror(errno)); + if (close(fd) < 0) { + ErrPrint("close: %s\n", strerror(errno)); + } + + /** + * @note + * But return ZERO, even if we couldn't get a buffer file, + * the viewer can draw empty screen. + * + * and then update it after it gots update events + */ + return DBOX_STATUS_ERROR_NONE; + } + } + + if (close(fd) < 0) { + ErrPrint("close: %s\n", strerror(errno)); + } + return DBOX_STATUS_ERROR_NONE; } static int sync_for_pixmap(struct fb_info *info, int x, int y, int w, int h) { - dynamicbox_fb_t buffer; - XShmSegmentInfo si; - XImage *xim; - - buffer = info->buffer; - if (!buffer) { /*!< Ignore this sync request */ - return DBOX_STATUS_ERROR_NONE; - } - - if (buffer->state != DBOX_FB_STATE_CREATED) { - ErrPrint("Invalid state of a FB\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - if (buffer->type != DBOX_FB_TYPE_PIXMAP) { - ErrPrint("Invalid buffer\n"); - return DBOX_STATUS_ERROR_NONE; - } - - if (!s_info.disp) { - s_info.disp = XOpenDisplay(NULL); - if (s_info.disp) { - Screen *screen; - - s_info.disp_is_opened = 1; - - screen = DefaultScreenOfDisplay(s_info.disp); - - s_info.screen = DefaultScreen(s_info.disp); - s_info.visual = DefaultVisualOfScreen(screen); - } else { - ErrPrint("Failed to open a display\n"); - return DBOX_STATUS_ERROR_FAULT; - } - } - - if (info->handle == 0) { - ErrPrint("Pixmap ID is not valid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - if (info->bufsz == 0) { - /*! - * If the client does not acquire the buffer, - * This function will do nothing. - * It will work only if the buffer is acquired. - * To sync its contents. - */ - DbgPrint("Nothing can be sync\n"); - return DBOX_STATUS_ERROR_NONE; - } - - si.shmid = shmget(IPC_PRIVATE, info->bufsz, IPC_CREAT | 0666); - if (si.shmid < 0) { - ErrPrint("shmget: %s\n", strerror(errno)); - return DBOX_STATUS_ERROR_FAULT; - } - - si.readOnly = False; - si.shmaddr = shmat(si.shmid, NULL, 0); - if (si.shmaddr == (void *)-1) { - if (shmctl(si.shmid, IPC_RMID, 0) < 0) { - ErrPrint("shmctl: %s\n", strerror(errno)); - } - - return DBOX_STATUS_ERROR_FAULT; - } - - /*! - * \NOTE - * Use the 24 bits Pixmap for Video player - */ - xim = XShmCreateImage(s_info.disp, s_info.visual, - (info->pixels << 3), ZPixmap, NULL, - &si, - info->w, info->h); - if (xim == NULL) { - if (shmdt(si.shmaddr) < 0) { - ErrPrint("shmdt: %s\n", strerror(errno)); - } - - if (shmctl(si.shmid, IPC_RMID, 0) < 0) { - ErrPrint("shmctl: %s\n", strerror(errno)); - } - - return DBOX_STATUS_ERROR_FAULT; - } - - xim->data = si.shmaddr; - XShmAttach(s_info.disp, &si); - - XShmGetImage(s_info.disp, info->handle, xim, 0, 0, 0xFFFFFFFF); - XSync(s_info.disp, False); - - if (x != 0 || y != 0 || info->w != w || info->h != h) { - int ix; - int iy; - register int index; - - for (iy = y; iy < h; iy++) { - for (ix = x; ix < w; ix++) { - index = iy * info->w + x; - *(((unsigned int *)buffer->data) + index) = *(((unsigned int *)xim->data) + index); - } - } - } else { - memcpy(buffer->data, xim->data, info->bufsz); - } - - XShmDetach(s_info.disp, &si); - XDestroyImage(xim); - - if (shmdt(si.shmaddr) < 0) { - ErrPrint("shmdt: %s\n", strerror(errno)); - } - - if (shmctl(si.shmid, IPC_RMID, 0) < 0) { - ErrPrint("shmctl: %s\n", strerror(errno)); - } - - return DBOX_STATUS_ERROR_NONE; + dynamicbox_fb_t buffer; + XShmSegmentInfo si; + XImage *xim; + + buffer = info->buffer; + if (!buffer) { /*!< Ignore this sync request */ + return DBOX_STATUS_ERROR_NONE; + } + + if (buffer->state != DBOX_FB_STATE_CREATED) { + ErrPrint("Invalid state of a FB\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + if (buffer->type != DBOX_FB_TYPE_PIXMAP) { + ErrPrint("Invalid buffer\n"); + return DBOX_STATUS_ERROR_NONE; + } + + if (!s_info.disp) { + s_info.disp = XOpenDisplay(NULL); + if (s_info.disp) { + Screen *screen; + + s_info.disp_is_opened = 1; + + screen = DefaultScreenOfDisplay(s_info.disp); + + s_info.screen = DefaultScreen(s_info.disp); + s_info.visual = DefaultVisualOfScreen(screen); + } else { + ErrPrint("Failed to open a display\n"); + return DBOX_STATUS_ERROR_FAULT; + } + } + + if (info->handle == 0) { + ErrPrint("Pixmap ID is not valid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + if (info->bufsz == 0) { + /*! + * If the client does not acquire the buffer, + * This function will do nothing. + * It will work only if the buffer is acquired. + * To sync its contents. + */ + DbgPrint("Nothing can be sync\n"); + return DBOX_STATUS_ERROR_NONE; + } + + si.shmid = shmget(IPC_PRIVATE, info->bufsz, IPC_CREAT | 0666); + if (si.shmid < 0) { + ErrPrint("shmget: %s\n", strerror(errno)); + return DBOX_STATUS_ERROR_FAULT; + } + + si.readOnly = False; + si.shmaddr = shmat(si.shmid, NULL, 0); + if (si.shmaddr == (void *)-1) { + if (shmctl(si.shmid, IPC_RMID, 0) < 0) { + ErrPrint("shmctl: %s\n", strerror(errno)); + } + + return DBOX_STATUS_ERROR_FAULT; + } + + /*! + * \NOTE + * Use the 24 bits Pixmap for Video player + */ + xim = XShmCreateImage(s_info.disp, s_info.visual, + (info->pixels << 3), ZPixmap, NULL, + &si, + info->w, info->h); + if (xim == NULL) { + if (shmdt(si.shmaddr) < 0) { + ErrPrint("shmdt: %s\n", strerror(errno)); + } + + if (shmctl(si.shmid, IPC_RMID, 0) < 0) { + ErrPrint("shmctl: %s\n", strerror(errno)); + } + + return DBOX_STATUS_ERROR_FAULT; + } + + xim->data = si.shmaddr; + XShmAttach(s_info.disp, &si); + + XShmGetImage(s_info.disp, info->handle, xim, 0, 0, 0xFFFFFFFF); + XSync(s_info.disp, False); + + if (x != 0 || y != 0 || info->w != w || info->h != h) { + int ix; + int iy; + register int index; + + for (iy = y; iy < h; iy++) { + for (ix = x; ix < w; ix++) { + index = iy * info->w + x; + *(((unsigned int *)buffer->data) + index) = *(((unsigned int *)xim->data) + index); + } + } + } else { + memcpy(buffer->data, xim->data, info->bufsz); + } + + XShmDetach(s_info.disp, &si); + XDestroyImage(xim); + + if (shmdt(si.shmaddr) < 0) { + ErrPrint("shmdt: %s\n", strerror(errno)); + } + + if (shmctl(si.shmid, IPC_RMID, 0) < 0) { + ErrPrint("shmctl: %s\n", strerror(errno)); + } + + return DBOX_STATUS_ERROR_NONE; } int fb_sync(struct fb_info *info, int x, int y, int w, int h) { - if (!info) { - ErrPrint("FB Handle is not valid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - if (!info->id || info->id[0] == '\0') { - DbgPrint("Ingore sync\n"); - return DBOX_STATUS_ERROR_NONE; - } - - if (!strncasecmp(info->id, SCHEMA_FILE, strlen(SCHEMA_FILE))) { - return sync_for_file(info, x, y, w, h); - } else if (!strncasecmp(info->id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP))) { - return sync_for_pixmap(info, x, y, w, h); - } else if (!strncasecmp(info->id, SCHEMA_SHM, strlen(SCHEMA_SHM))) { - /* No need to do sync */ - return DBOX_STATUS_ERROR_NONE; - } - - return DBOX_STATUS_ERROR_INVALID_PARAMETER; + if (!info) { + ErrPrint("FB Handle is not valid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + if (!info->id || info->id[0] == '\0') { + DbgPrint("Ingore sync\n"); + return DBOX_STATUS_ERROR_NONE; + } + + if (!strncasecmp(info->id, SCHEMA_FILE, strlen(SCHEMA_FILE))) { + return sync_for_file(info, x, y, w, h); + } else if (!strncasecmp(info->id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP))) { + return sync_for_pixmap(info, x, y, w, h); + } else if (!strncasecmp(info->id, SCHEMA_SHM, strlen(SCHEMA_SHM))) { + /* No need to do sync */ + return DBOX_STATUS_ERROR_NONE; + } + + return DBOX_STATUS_ERROR_INVALID_PARAMETER; } struct fb_info *fb_create(const char *id, int w, int h) { - struct fb_info *info; - - if (!id || id[0] == '\0') { - ErrPrint("Invalid ID\n"); - return NULL; - } - - info = calloc(1, sizeof(*info)); - if (!info) { - ErrPrint("Heap: %s\n", strerror(errno)); - return NULL; - } - - info->id = strdup(id); - if (!info->id) { - ErrPrint("Heap: %s\n", strerror(errno)); - free(info); - return NULL; - } - - info->pixels = sizeof(int); /* Use the default pixels(depth) */ - - if (sscanf(info->id, SCHEMA_SHM "%d", &info->handle) == 1) { - DbgPrint("SHMID: %d is gotten\n", info->handle); - } else if (sscanf(info->id, SCHEMA_PIXMAP "%d:%d", &info->handle, &info->pixels) == 2) { - DbgPrint("PIXMAP-SHMID: %d is gotten (%d)\n", info->handle, info->pixels); - } else { - info->handle = DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - info->bufsz = 0; - info->buffer = NULL; - info->w = w; - info->h = h; - - return info; + struct fb_info *info; + + if (!id || id[0] == '\0') { + ErrPrint("Invalid ID\n"); + return NULL; + } + + info = calloc(1, sizeof(*info)); + if (!info) { + ErrPrint("Heap: %s\n", strerror(errno)); + return NULL; + } + + info->id = strdup(id); + if (!info->id) { + ErrPrint("Heap: %s\n", strerror(errno)); + free(info); + return NULL; + } + + info->pixels = sizeof(int); /* Use the default pixels(depth) */ + + if (sscanf(info->id, SCHEMA_SHM "%d", &info->handle) == 1) { + DbgPrint("SHMID: %d is gotten\n", info->handle); + } else if (sscanf(info->id, SCHEMA_PIXMAP "%d:%d", &info->handle, &info->pixels) == 2) { + DbgPrint("PIXMAP-SHMID: %d is gotten (%d)\n", info->handle, info->pixels); + } else { + info->handle = DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + info->bufsz = 0; + info->buffer = NULL; + info->w = w; + info->h = h; + + return info; } int fb_destroy(struct fb_info *info) { - if (!info) { - ErrPrint("Handle is not valid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!info) { + ErrPrint("Handle is not valid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (info->buffer) { - dynamicbox_fb_t buffer; - buffer = info->buffer; + if (info->buffer) { + dynamicbox_fb_t buffer; + buffer = info->buffer; - buffer->info = NULL; - } + buffer->info = NULL; + } - free(info->id); - free(info); - return DBOX_STATUS_ERROR_NONE; + free(info->id); + free(info); + return DBOX_STATUS_ERROR_NONE; } int fb_is_created(struct fb_info *info) { - if (!info) { - ErrPrint("Handle is not valid\n"); - return 0; - } - - if (!strncasecmp(info->id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP)) && info->handle != 0) { - return 1; - } else if (!strncasecmp(info->id, SCHEMA_SHM, strlen(SCHEMA_SHM)) && info->handle > 0) { - return 1; - } else { - const char *path; - path = util_uri_to_path(info->id); - if (path && access(path, F_OK | R_OK) == 0) { - return 1; - } else { - ErrPrint("access: %s (%s)\n", strerror(errno), path); - } - } - - return 0; + if (!info) { + ErrPrint("Handle is not valid\n"); + return 0; + } + + if (!strncasecmp(info->id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP)) && info->handle != 0) { + return 1; + } else if (!strncasecmp(info->id, SCHEMA_SHM, strlen(SCHEMA_SHM)) && info->handle > 0) { + return 1; + } else { + const char *path; + path = util_uri_to_path(info->id); + if (path && access(path, F_OK | R_OK) == 0) { + return 1; + } else { + ErrPrint("access: %s (%s)\n", strerror(errno), path); + } + } + + return 0; } void *fb_acquire_buffer(struct fb_info *info) { - dynamicbox_fb_t buffer; - - if (!info) { - ErrPrint("info == NIL\n"); - return NULL; - } - - if (!info->buffer) { - if (!strncasecmp(info->id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP))) { - update_fb_size(info); - - buffer = calloc(1, sizeof(*buffer) + info->bufsz); - if (!buffer) { - ErrPrint("Heap: %s\n", strerror(errno)); - info->bufsz = 0; - return NULL; - } - - buffer->type = DBOX_FB_TYPE_PIXMAP; - buffer->refcnt = 0; - buffer->state = DBOX_FB_STATE_CREATED; - buffer->info = info; - info->buffer = buffer; - - /*! - * \note - * Just update from here. - */ - sync_for_pixmap(info, 0, 0, info->w, info->h); - } else if (!strncasecmp(info->id, SCHEMA_FILE, strlen(SCHEMA_FILE))) { - update_fb_size(info); - - buffer = calloc(1, sizeof(*buffer) + info->bufsz); - if (!buffer) { - ErrPrint("Heap: %s\n", strerror(errno)); - info->bufsz = 0; - return NULL; - } - - buffer->type = DBOX_FB_TYPE_FILE; - buffer->refcnt = 0; - buffer->state = DBOX_FB_STATE_CREATED; - buffer->info = info; - info->buffer = buffer; - - sync_for_file(info, 0, 0, info->w, info->h); - } else if (!strncasecmp(info->id, SCHEMA_SHM, strlen(SCHEMA_SHM))) { - buffer = shmat(info->handle, NULL, 0); - if (buffer == (void *)-1) { - ErrPrint("shmat: %s (%d)\n", strerror(errno), info->handle); - return NULL; - } - - return buffer->data; - } else { - ErrPrint("Buffer is not created (%s)\n", info->id); - return NULL; - } - } - - buffer = info->buffer; - - switch (buffer->type) { - case DBOX_FB_TYPE_PIXMAP: - buffer->refcnt++; - break; - case DBOX_FB_TYPE_FILE: - buffer->refcnt++; - break; - default: - DbgPrint("Unknwon FP: %d\n", buffer->type); - break; - } - - return buffer->data; + dynamicbox_fb_t buffer; + + if (!info) { + ErrPrint("info == NIL\n"); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return NULL; + } + + if (!info->buffer) { + if (!strncasecmp(info->id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP))) { + update_fb_size(info); + + buffer = calloc(1, sizeof(*buffer) + info->bufsz); + if (!buffer) { + ErrPrint("Heap: %s\n", strerror(errno)); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_OUT_OF_MEMORY); + info->bufsz = 0; + return NULL; + } + + buffer->type = DBOX_FB_TYPE_PIXMAP; + buffer->refcnt = 0; + buffer->state = DBOX_FB_STATE_CREATED; + buffer->info = info; + info->buffer = buffer; + + /*! + * \note + * Just update from here. + */ + sync_for_pixmap(info, 0, 0, info->w, info->h); + } else if (!strncasecmp(info->id, SCHEMA_FILE, strlen(SCHEMA_FILE))) { + update_fb_size(info); + + buffer = calloc(1, sizeof(*buffer) + info->bufsz); + if (!buffer) { + ErrPrint("Heap: %s\n", strerror(errno)); + info->bufsz = 0; + dynamicbox_set_last_status(DBOX_STATUS_ERROR_OUT_OF_MEMORY); + return NULL; + } + + buffer->type = DBOX_FB_TYPE_FILE; + buffer->refcnt = 0; + buffer->state = DBOX_FB_STATE_CREATED; + buffer->info = info; + info->buffer = buffer; + + sync_for_file(info, 0, 0, info->w, info->h); + } else if (!strncasecmp(info->id, SCHEMA_SHM, strlen(SCHEMA_SHM))) { + buffer = shmat(info->handle, NULL, 0); + if (buffer == (void *)-1) { + ErrPrint("shmat: %s (%d)\n", strerror(errno), info->handle); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_FAULT); + return NULL; + } + + return buffer->data; + } else { + ErrPrint("Buffer is not created (%s)\n", info->id); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return NULL; + } + } + + buffer = info->buffer; + + switch (buffer->type) { + case DBOX_FB_TYPE_PIXMAP: + buffer->refcnt++; + break; + case DBOX_FB_TYPE_FILE: + buffer->refcnt++; + break; + default: + DbgPrint("Unknwon FP: %d\n", buffer->type); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + break; + } + + return buffer->data; } int fb_release_buffer(void *data) { - dynamicbox_fb_t buffer; - - if (!data) { - ErrPrint("buffer data == NIL\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - buffer = container_of(data, struct dynamicbox_fb, data); - - if (buffer->state != DBOX_FB_STATE_CREATED) { - ErrPrint("Invalid handle\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - switch (buffer->type) { - case DBOX_FB_TYPE_SHM: - if (shmdt(buffer) < 0) { - ErrPrint("shmdt: %s\n", strerror(errno)); - } - break; - case DBOX_FB_TYPE_PIXMAP: - buffer->refcnt--; - if (buffer->refcnt == 0) { - struct fb_info *info; - info = buffer->info; - - buffer->state = DBOX_FB_STATE_DESTROYED; - free(buffer); - - if (info && info->buffer == buffer) { - info->buffer = NULL; - } - } - break; - case DBOX_FB_TYPE_FILE: - buffer->refcnt--; - if (buffer->refcnt == 0) { - struct fb_info *info; - info = buffer->info; - - buffer->state = DBOX_FB_STATE_DESTROYED; - free(buffer); - - if (info && info->buffer == buffer) { - info->buffer = NULL; - } - } - break; - default: - ErrPrint("Unknwon buffer type\n"); - break; - } - - return DBOX_STATUS_ERROR_NONE; + dynamicbox_fb_t buffer; + + if (!data) { + ErrPrint("buffer data == NIL\n"); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + buffer = container_of(data, struct dynamicbox_fb, data); + + if (buffer->state != DBOX_FB_STATE_CREATED) { + ErrPrint("Invalid handle\n"); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + switch (buffer->type) { + case DBOX_FB_TYPE_SHM: + if (shmdt(buffer) < 0) { + ErrPrint("shmdt: %s\n", strerror(errno)); + } + break; + case DBOX_FB_TYPE_PIXMAP: + buffer->refcnt--; + if (buffer->refcnt == 0) { + struct fb_info *info; + info = buffer->info; + + buffer->state = DBOX_FB_STATE_DESTROYED; + free(buffer); + + if (info && info->buffer == buffer) { + info->buffer = NULL; + } + } + break; + case DBOX_FB_TYPE_FILE: + buffer->refcnt--; + if (buffer->refcnt == 0) { + struct fb_info *info; + info = buffer->info; + + buffer->state = DBOX_FB_STATE_DESTROYED; + free(buffer); + + if (info && info->buffer == buffer) { + info->buffer = NULL; + } + } + break; + default: + ErrPrint("Unknwon buffer type\n"); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + break; + } + + return DBOX_STATUS_ERROR_NONE; } int fb_refcnt(void *data) { - dynamicbox_fb_t buffer; - struct shmid_ds buf; - int ret; - - if (!data) { - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - buffer = container_of(data, struct dynamicbox_fb, data); - - if (buffer->state != DBOX_FB_STATE_CREATED) { - ErrPrint("Invalid handle\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - switch (buffer->type) { - case DBOX_FB_TYPE_SHM: - if (shmctl(buffer->refcnt, IPC_STAT, &buf) < 0) { - ErrPrint("Error: %s\n", strerror(errno)); - return DBOX_STATUS_ERROR_FAULT; - } - - ret = buf.shm_nattch; - break; - case DBOX_FB_TYPE_PIXMAP: - ret = buffer->refcnt; - break; - case DBOX_FB_TYPE_FILE: - ret = buffer->refcnt; - break; - default: - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - break; - } - - return ret; + dynamicbox_fb_t buffer; + struct shmid_ds buf; + int ret; + + if (!data) { + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + buffer = container_of(data, struct dynamicbox_fb, data); + + if (buffer->state != DBOX_FB_STATE_CREATED) { + ErrPrint("Invalid handle\n"); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + switch (buffer->type) { + case DBOX_FB_TYPE_SHM: + if (shmctl(buffer->refcnt, IPC_STAT, &buf) < 0) { + ErrPrint("Error: %s\n", strerror(errno)); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_FAULT); + return DBOX_STATUS_ERROR_FAULT; + } + + ret = buf.shm_nattch; + break; + case DBOX_FB_TYPE_PIXMAP: + ret = buffer->refcnt; + break; + case DBOX_FB_TYPE_FILE: + ret = buffer->refcnt; + break; + default: + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + break; + } + + return ret; } const char *fb_id(struct fb_info *info) { - return info ? info->id : NULL; + return info ? info->id : NULL; } int fb_get_size(struct fb_info *info, int *w, int *h) { - if (!info) { - ErrPrint("Handle is not valid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - *w = info->w; - *h = info->h; - return DBOX_STATUS_ERROR_NONE; + if (!info) { + ErrPrint("Handle is not valid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + *w = info->w; + *h = info->h; + return DBOX_STATUS_ERROR_NONE; } int fb_size(struct fb_info *info) { - if (!info) { - return 0; - } + if (!info) { + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return 0; + } - update_fb_size(info); + update_fb_size(info); - return info->bufsz; + return info->bufsz; } int fb_type(struct fb_info *info) { - dynamicbox_fb_t buffer; - - if (!info) { - return DBOX_FB_TYPE_ERROR; - } - - buffer = info->buffer; - if (!buffer) { - int type = DBOX_FB_TYPE_ERROR; - /*! - * \note - * Try to get this from SCHEMA - */ - if (info->id) { - if (!strncasecmp(info->id, SCHEMA_FILE, strlen(SCHEMA_FILE))) { - type = DBOX_FB_TYPE_FILE; - } else if (!strncasecmp(info->id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP))) { - type = DBOX_FB_TYPE_PIXMAP; - } else if (!strncasecmp(info->id, SCHEMA_SHM, strlen(SCHEMA_SHM))) { - type = DBOX_FB_TYPE_SHM; - } - } - - return type; - } - - return buffer->type; + dynamicbox_fb_t buffer; + + if (!info) { + return DBOX_FB_TYPE_ERROR; + } + + buffer = info->buffer; + if (!buffer) { + int type = DBOX_FB_TYPE_ERROR; + /*! + * \note + * Try to get this from SCHEMA + */ + if (info->id) { + if (!strncasecmp(info->id, SCHEMA_FILE, strlen(SCHEMA_FILE))) { + type = DBOX_FB_TYPE_FILE; + } else if (!strncasecmp(info->id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP))) { + type = DBOX_FB_TYPE_PIXMAP; + } else if (!strncasecmp(info->id, SCHEMA_SHM, strlen(SCHEMA_SHM))) { + type = DBOX_FB_TYPE_SHM; + } + } + + return type; + } + + return buffer->type; } /* End of a file */ diff --git a/src/fb_wayland.c b/src/fb_wayland.c index e90f769..c5605b4 100644 --- a/src/fb_wayland.c +++ b/src/fb_wayland.c @@ -38,14 +38,14 @@ int errno; struct fb_info { - char *id; - int w; - int h; - int bufsz; - void *buffer; - - int pixels; - int handle; + char *id; + int w; + int h; + int bufsz; + void *buffer; + + int pixels; + int handle; }; static struct { @@ -54,384 +54,398 @@ static struct { int fb_init(void *disp) { - return 0; + return 0; } int fb_fini(void) { - return 0; + return 0; } static inline void update_fb_size(struct fb_info *info) { - info->bufsz = info->w * info->h * info->pixels; + info->bufsz = info->w * info->h * info->pixels; } static inline int sync_for_file(struct fb_info *info) { - int fd; - struct buffer *buffer; - - buffer = info->buffer; - - if (!buffer) { /* Ignore this sync request */ - return DBOX_STATUS_ERROR_NONE; - } - - if (buffer->state != CREATED) { - ErrPrint("Invalid state of a FB\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - if (buffer->type != DBOX_BUFFER_TYPE_FILE) { - ErrPrint("Invalid buffer\n"); - return DBOX_STATUS_ERROR_NONE; - } - - fd = open(util_uri_to_path(info->id), O_RDONLY); - if (fd < 0) { - ErrPrint("Failed to open a file (%s) because of (%s)\n", - util_uri_to_path(info->id), strerror(errno)); - - /*! - * \note - * But return ZERO, even if we couldn't get a buffer file, - * the viewer can draw empty screen. - * - * and then update it after it gots update events - */ - return DBOX_STATUS_ERROR_NONE; - } - - if (read(fd, buffer->data, info->bufsz) != info->bufsz) { - ErrPrint("read: %s\n", strerror(errno)); - if (close(fd) < 0) { - ErrPrint("close: %s\n", strerror(errno)); - } - - /*! - * \note - * But return ZERO, even if we couldn't get a buffer file, - * the viewer can draw empty screen. - * - * and then update it after it gots update events - */ - return DBOX_STATUS_ERROR_NONE; - } - - if (close(fd) < 0) { - ErrPrint("close: %s\n", strerror(errno)); - } - return DBOX_STATUS_ERROR_NONE; + int fd; + struct buffer *buffer; + + buffer = info->buffer; + + if (!buffer) { /* Ignore this sync request */ + return DBOX_STATUS_ERROR_NONE; + } + + if (buffer->state != CREATED) { + ErrPrint("Invalid state of a FB\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + if (buffer->type != DBOX_BUFFER_TYPE_FILE) { + ErrPrint("Invalid buffer\n"); + return DBOX_STATUS_ERROR_NONE; + } + + fd = open(util_uri_to_path(info->id), O_RDONLY); + if (fd < 0) { + ErrPrint("Failed to open a file (%s) because of (%s)\n", + util_uri_to_path(info->id), strerror(errno)); + + /*! + * \note + * But return ZERO, even if we couldn't get a buffer file, + * the viewer can draw empty screen. + * + * and then update it after it gots update events + */ + return DBOX_STATUS_ERROR_NONE; + } + + if (read(fd, buffer->data, info->bufsz) != info->bufsz) { + ErrPrint("read: %s\n", strerror(errno)); + if (close(fd) < 0) { + ErrPrint("close: %s\n", strerror(errno)); + } + + /*! + * \note + * But return ZERO, even if we couldn't get a buffer file, + * the viewer can draw empty screen. + * + * and then update it after it gots update events + */ + return DBOX_STATUS_ERROR_NONE; + } + + if (close(fd) < 0) { + ErrPrint("close: %s\n", strerror(errno)); + } + return DBOX_STATUS_ERROR_NONE; } int fb_sync(struct fb_info *info, int x, int y, int w, int h) { - if (!info) { - ErrPrint("FB Handle is not valid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - if (!info->id || info->id[0] == '\0') { - DbgPrint("Ingore sync\n"); - return DBOX_STATUS_ERROR_NONE; - } - - if (!strncasecmp(info->id, SCHEMA_FILE, strlen(SCHEMA_FILE))) { - return sync_for_file(info); - } else if (!strncasecmp(info->id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP))) { - } else if (!strncasecmp(info->id, SCHEMA_SHM, strlen(SCHEMA_SHM))) { - /* No need to do sync */ - return DBOX_STATUS_ERROR_NONE; - } - - return DBOX_STATUS_ERROR_INVALID_PARAMETER; + if (!info) { + ErrPrint("FB Handle is not valid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + if (!info->id || info->id[0] == '\0') { + DbgPrint("Ingore sync\n"); + return DBOX_STATUS_ERROR_NONE; + } + + if (!strncasecmp(info->id, SCHEMA_FILE, strlen(SCHEMA_FILE))) { + return sync_for_file(info); + } else if (!strncasecmp(info->id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP))) { + } else if (!strncasecmp(info->id, SCHEMA_SHM, strlen(SCHEMA_SHM))) { + /* No need to do sync */ + return DBOX_STATUS_ERROR_NONE; + } + + return DBOX_STATUS_ERROR_INVALID_PARAMETER; } struct fb_info *fb_create(const char *id, int w, int h) { - struct fb_info *info; - - if (!id || id[0] == '\0') { - ErrPrint("Invalid ID\n"); - return NULL; - } - - info = calloc(1, sizeof(*info)); - if (!info) { - ErrPrint("Heap: %s\n", strerror(errno)); - return NULL; - } - - info->id = strdup(id); - if (!info->id) { - ErrPrint("Heap: %s\n", strerror(errno)); - free(info); - return NULL; - } - - info->pixels = sizeof(int); /* Use the default pixels(depth) */ - - if (sscanf(info->id, SCHEMA_SHM "%d", &info->handle) == 1) { - DbgPrint("SHMID: %d is gotten\n", info->handle); - } else if (sscanf(info->id, SCHEMA_PIXMAP "%d:%d", &info->handle, &info->pixels) == 2) { - DbgPrint("PIXMAP-SHMID: %d is gotten (%d)\n", info->handle, info->pixels); - ErrPrint("Unsupported\n"); - free(info); - return NULL; - } else { - info->handle = DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - info->bufsz = 0; - info->buffer = NULL; - info->w = w; - info->h = h; - - return info; + struct fb_info *info; + + if (!id || id[0] == '\0') { + ErrPrint("Invalid ID\n"); + return NULL; + } + + info = calloc(1, sizeof(*info)); + if (!info) { + ErrPrint("Heap: %s\n", strerror(errno)); + return NULL; + } + + info->id = strdup(id); + if (!info->id) { + ErrPrint("Heap: %s\n", strerror(errno)); + free(info); + return NULL; + } + + info->pixels = sizeof(int); /* Use the default pixels(depth) */ + + if (sscanf(info->id, SCHEMA_SHM "%d", &info->handle) == 1) { + DbgPrint("SHMID: %d is gotten\n", info->handle); + } else if (sscanf(info->id, SCHEMA_PIXMAP "%d:%d", &info->handle, &info->pixels) == 2) { + DbgPrint("PIXMAP-SHMID: %d is gotten (%d)\n", info->handle, info->pixels); + ErrPrint("Unsupported\n"); + free(info); + return NULL; + } else { + info->handle = DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + info->bufsz = 0; + info->buffer = NULL; + info->w = w; + info->h = h; + + return info; } int fb_destroy(struct fb_info *info) { - if (!info) { - ErrPrint("Handle is not valid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + if (!info) { + ErrPrint("Handle is not valid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - if (info->buffer) { - struct buffer *buffer; - buffer = info->buffer; + if (info->buffer) { + struct buffer *buffer; + buffer = info->buffer; - buffer->info = NULL; - } + buffer->info = NULL; + } - free(info->id); - free(info); - return DBOX_STATUS_ERROR_NONE; + free(info->id); + free(info); + return DBOX_STATUS_ERROR_NONE; } int fb_is_created(struct fb_info *info) { - if (!info) { - ErrPrint("Handle is not valid\n"); - return 0; - } - - if (!strncasecmp(info->id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP)) && info->handle != 0) { - return 1; - } else if (!strncasecmp(info->id, SCHEMA_SHM, strlen(SCHEMA_SHM)) && info->handle > 0) { - return 1; - } else { - const char *path; - path = util_uri_to_path(info->id); - if (path && access(path, F_OK | R_OK) == 0) { - return 1; - } else { - ErrPrint("access: %s (%s)\n", strerror(errno), path); - } - } - - return 0; + if (!info) { + ErrPrint("Handle is not valid\n"); + return 0; + } + + if (!strncasecmp(info->id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP)) && info->handle != 0) { + return 1; + } else if (!strncasecmp(info->id, SCHEMA_SHM, strlen(SCHEMA_SHM)) && info->handle > 0) { + return 1; + } else { + const char *path; + path = util_uri_to_path(info->id); + if (path && access(path, F_OK | R_OK) == 0) { + return 1; + } else { + ErrPrint("access: %s (%s)\n", strerror(errno), path); + } + } + + return 0; } void *fb_acquire_buffer(struct fb_info *info) { - struct buffer *buffer; - - if (!info) { - ErrPrint("info == NIL\n"); - return NULL; - } - - if (!info->buffer) { - if (!strncasecmp(info->id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP))) { - ErrPrint("Unsupported Type\n"); - return NULL; - } else if (!strncasecmp(info->id, SCHEMA_FILE, strlen(SCHEMA_FILE))) { - update_fb_size(info); - - buffer = calloc(1, sizeof(*buffer) + info->bufsz); - if (!buffer) { - ErrPrint("Heap: %s\n", strerror(errno)); - info->bufsz = 0; - return NULL; - } - - buffer->type = DBOX_BUFFER_TYPE_FILE; - buffer->refcnt = 0; - buffer->state = CREATED; - buffer->info = info; - info->buffer = buffer; - - sync_for_file(info); - } else if (!strncasecmp(info->id, SCHEMA_SHM, strlen(SCHEMA_SHM))) { - buffer = shmat(info->handle, NULL, 0); - if (buffer == (void *)-1) { - ErrPrint("shmat: %s (%d)\n", strerror(errno), info->handle); - return NULL; - } - - return buffer->data; - } else { - ErrPrint("Buffer is not created (%s)\n", info->id); - return NULL; - } - } - - buffer = info->buffer; - - switch (buffer->type) { - case DBOX_BUFFER_TYPE_FILE: - buffer->refcnt++; - break; - case DBOX_BUFFER_TYPE_PIXMAP: - default: - DbgPrint("Unknwon FP: %d\n", buffer->type); - break; - } - - return buffer->data; + struct buffer *buffer; + + if (!info) { + ErrPrint("info == NIL\n"); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return NULL; + } + + if (!info->buffer) { + if (!strncasecmp(info->id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP))) { + ErrPrint("Unsupported Type\n"); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return NULL; + } else if (!strncasecmp(info->id, SCHEMA_FILE, strlen(SCHEMA_FILE))) { + update_fb_size(info); + + buffer = calloc(1, sizeof(*buffer) + info->bufsz); + if (!buffer) { + ErrPrint("Heap: %s\n", strerror(errno)); + info->bufsz = 0; + dynamicbox_set_last_status(DBOX_STATUS_ERROR_OUT_OF_MEMORY); + return NULL; + } + + buffer->type = DBOX_BUFFER_TYPE_FILE; + buffer->refcnt = 0; + buffer->state = CREATED; + buffer->info = info; + info->buffer = buffer; + + sync_for_file(info); + } else if (!strncasecmp(info->id, SCHEMA_SHM, strlen(SCHEMA_SHM))) { + buffer = shmat(info->handle, NULL, 0); + if (buffer == (void *)-1) { + ErrPrint("shmat: %s (%d)\n", strerror(errno), info->handle); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_FAULT); + return NULL; + } + + return buffer->data; + } else { + ErrPrint("Buffer is not created (%s)\n", info->id); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return NULL; + } + } + + buffer = info->buffer; + + switch (buffer->type) { + case DBOX_BUFFER_TYPE_FILE: + buffer->refcnt++; + break; + case DBOX_BUFFER_TYPE_PIXMAP: + default: + DbgPrint("Unknwon FP: %d\n", buffer->type); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + break; + } + + return buffer->data; } int fb_release_buffer(void *data) { - struct buffer *buffer; - - if (!data) { - ErrPrint("buffer data == NIL\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - buffer = container_of(data, struct buffer, data); - - if (buffer->state != CREATED) { - ErrPrint("Invalid handle\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - switch (buffer->type) { - case DBOX_BUFFER_TYPE_SHM: - if (shmdt(buffer) < 0) { - ErrPrint("shmdt: %s\n", strerror(errno)); - } - break; - case DBOX_BUFFER_TYPE_FILE: - buffer->refcnt--; - if (buffer->refcnt == 0) { - struct fb_info *info; - info = buffer->info; - - buffer->state = DBOX_FB_STATE_DESTROYED; - free(buffer); - - if (info && info->buffer == buffer) { - info->buffer = NULL; - } - } - break; - case DBOX_BUFFER_TYPE_PIXMAP: - default: - ErrPrint("Unknwon buffer type\n"); - break; - } - - return DBOX_STATUS_ERROR_NONE; + struct buffer *buffer; + + if (!data) { + ErrPrint("buffer data == NIL\n"); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + buffer = container_of(data, struct buffer, data); + + if (buffer->state != CREATED) { + ErrPrint("Invalid handle\n"); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + switch (buffer->type) { + case DBOX_BUFFER_TYPE_SHM: + if (shmdt(buffer) < 0) { + ErrPrint("shmdt: %s\n", strerror(errno)); + } + break; + case DBOX_BUFFER_TYPE_FILE: + buffer->refcnt--; + if (buffer->refcnt == 0) { + struct fb_info *info; + info = buffer->info; + + buffer->state = DBOX_FB_STATE_DESTROYED; + free(buffer); + + if (info && info->buffer == buffer) { + info->buffer = NULL; + } + } + break; + case DBOX_BUFFER_TYPE_PIXMAP: + default: + ErrPrint("Unknwon buffer type\n"); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + break; + } + + return DBOX_STATUS_ERROR_NONE; } int fb_refcnt(void *data) { - struct buffer *buffer; - struct shmid_ds buf; - int ret; - - if (!data) { - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - buffer = container_of(data, struct buffer, data); - - if (buffer->state != CREATED) { - ErrPrint("Invalid handle\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - switch (buffer->type) { - case DBOX_BUFFER_TYPE_SHM: - if (shmctl(buffer->refcnt, IPC_STAT, &buf) < 0) { - ErrPrint("Error: %s\n", strerror(errno)); - return DBOX_STATUS_ERROR_FAULT; - } - - ret = buf.shm_nattch; - break; - case DBOX_BUFFER_TYPE_FILE: - ret = buffer->refcnt; - break; - case DBOX_BUFFER_TYPE_PIXMAP: - default: - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - break; - } - - return ret; + struct buffer *buffer; + struct shmid_ds buf; + int ret; + + if (!data) { + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + buffer = container_of(data, struct buffer, data); + + if (buffer->state != CREATED) { + ErrPrint("Invalid handle\n"); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + switch (buffer->type) { + case DBOX_BUFFER_TYPE_SHM: + if (shmctl(buffer->refcnt, IPC_STAT, &buf) < 0) { + ErrPrint("Error: %s\n", strerror(errno)); + dynamicbox_set_last_status(DBOX_STATUS_ERROR_FAULT); + return DBOX_STATUS_ERROR_FAULT; + } + + ret = buf.shm_nattch; + break; + case DBOX_BUFFER_TYPE_FILE: + ret = buffer->refcnt; + break; + case DBOX_BUFFER_TYPE_PIXMAP: + default: + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + break; + } + + return ret; } const char *fb_id(struct fb_info *info) { - return info ? info->id : NULL; + return info ? info->id : NULL; } int fb_get_size(struct fb_info *info, int *w, int *h) { - if (!info) { - ErrPrint("Handle is not valid\n"); - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - *w = info->w; - *h = info->h; - return DBOX_STATUS_ERROR_NONE; + if (!info) { + ErrPrint("Handle is not valid\n"); + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + *w = info->w; + *h = info->h; + return DBOX_STATUS_ERROR_NONE; } int fb_size(struct fb_info *info) { - if (!info) { - return 0; - } + if (!info) { + dynamicbox_set_last_status(DBOX_STATUS_ERROR_INVALID_PARAMETER); + return 0; + } - update_fb_size(info); + update_fb_size(info); - return info->bufsz; + return info->bufsz; } int fb_type(struct fb_info *info) { - struct buffer *buffer; - - if (!info) { - return DBOX_BUFFER_TYPE_ERROR; - } - - buffer = info->buffer; - if (!buffer) { - int type = DBOX_BUFFER_TYPE_ERROR; - /*! - * \note - * Try to get this from SCHEMA - */ - if (info->id) { - if (!strncasecmp(info->id, SCHEMA_FILE, strlen(SCHEMA_FILE))) { - type = DBOX_BUFFER_TYPE_FILE; - } else if (!strncasecmp(info->id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP))) { - /* Unsupported type */ - } else if (!strncasecmp(info->id, SCHEMA_SHM, strlen(SCHEMA_SHM))) { - type = DBOX_BUFFER_TYPE_SHM; - } - } - - return type; - } - - return buffer->type; + struct buffer *buffer; + + if (!info) { + return DBOX_BUFFER_TYPE_ERROR; + } + + buffer = info->buffer; + if (!buffer) { + int type = DBOX_BUFFER_TYPE_ERROR; + /*! + * \note + * Try to get this from SCHEMA + */ + if (info->id) { + if (!strncasecmp(info->id, SCHEMA_FILE, strlen(SCHEMA_FILE))) { + type = DBOX_BUFFER_TYPE_FILE; + } else if (!strncasecmp(info->id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP))) { + /* Unsupported type */ + } else if (!strncasecmp(info->id, SCHEMA_SHM, strlen(SCHEMA_SHM))) { + type = DBOX_BUFFER_TYPE_SHM; + } + } + + return type; + } + + return buffer->type; } /* End of a file */ diff --git a/src/file_service.c b/src/file_service.c index 04d75da..1219ce3 100644 --- a/src/file_service.c +++ b/src/file_service.c @@ -37,81 +37,81 @@ #include "debug.h" #include "dlist.h" -#define FILE_SERVICE_PORT 8209 +#define FILE_SERVICE_PORT 8209 #define CRITICAL_SECTION_BEGIN(handle) \ do { \ - int ret; \ - ret = pthread_mutex_lock(handle); \ - if (ret != 0) { \ - ErrPrint("Failed to lock: %s\n", strerror(ret)); \ - } \ + int ret; \ + ret = pthread_mutex_lock(handle); \ + if (ret != 0) { \ + ErrPrint("Failed to lock: %s\n", strerror(ret)); \ + } \ } while (0) #define CRITICAL_SECTION_END(handle) \ do { \ - int ret; \ - ret = pthread_mutex_unlock(handle); \ - if (ret != 0) { \ - ErrPrint("Failed to unlock: %s\n", strerror(ret)); \ - } \ + int ret; \ + ret = pthread_mutex_unlock(handle); \ + if (ret != 0) { \ + ErrPrint("Failed to unlock: %s\n", strerror(ret)); \ + } \ } while (0) #define CANCEL_SECTION_BEGIN() do { \ - int ret; \ - ret = pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); \ - if (ret != 0) { \ - ErrPrint("Unable to set cancelate state: %s\n", strerror(ret)); \ - } \ + int ret; \ + ret = pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); \ + if (ret != 0) { \ + ErrPrint("Unable to set cancelate state: %s\n", strerror(ret)); \ + } \ } while (0) #define CANCEL_SECTION_END() do { \ - int ret; \ - ret = pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL); \ - if (ret != 0) { \ - ErrPrint("Unable to set cancelate state: %s\n", strerror(ret)); \ - } \ + int ret; \ + ret = pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL); \ + if (ret != 0) { \ + ErrPrint("Unable to set cancelate state: %s\n", strerror(ret)); \ + } \ } while (0) -#define CLOSE_PIPE(p) do { \ - int status; \ - status = close(p[PIPE_READ]); \ - if (status < 0) { \ - ErrPrint("close: %s\n", strerror(errno)); \ - } \ - status = close(p[PIPE_WRITE]); \ - if (status < 0) { \ - ErrPrint("close: %s\n", strerror(errno)); \ - } \ +#define CLOSE_PIPE(p) do { \ + int status; \ + status = close(p[PIPE_READ]); \ + if (status < 0) { \ + ErrPrint("close: %s\n", strerror(errno)); \ + } \ + status = close(p[PIPE_WRITE]); \ + if (status < 0) { \ + ErrPrint("close: %s\n", strerror(errno)); \ + } \ } while (0) #define PIPE_READ 0 #define PIPE_WRITE 1 #define PIPE_MAX 2 -#define EVT_END_CH 'c' -#define EVT_CH 'e' +#define EVT_END_CH 'c' +#define EVT_CH 'e' static struct { - pthread_t file_svc_thid; - pthread_mutex_t file_svc_lock; - int ctrl_pipe[PIPE_MAX]; - int evt_pipe[PIPE_MAX]; - struct dlist *request_list; - int file_service_fd; + pthread_t file_svc_thid; + pthread_mutex_t file_svc_lock; + int ctrl_pipe[PIPE_MAX]; + int evt_pipe[PIPE_MAX]; + struct dlist *request_list; + int file_service_fd; } s_info = { - .ctrl_pipe = { -1, -1 }, - .evt_pipe = { -1, -1 }, - .request_list = NULL, - .file_service_fd = -1, + .ctrl_pipe = { -1, -1 }, + .evt_pipe = { -1, -1 }, + .request_list = NULL, + .file_service_fd = -1, }; struct request_item { - char *filename; - char *save_to; - void (*result_cb)(const char *filename, const char *save_to, int ret, void *data); - void *data; - int ret; + char *filename; + char *save_to; + void (*result_cb)(const char *filename, const char *save_to, int ret, void *data); + void *data; + int ret; }; /*! @@ -119,87 +119,87 @@ struct request_item { * This must should be shared with client. */ struct burst_head { - off_t size; - int flen; - char fname[]; + off_t size; + int flen; + char fname[]; }; struct burst_data { - int size; - char data[]; + int size; + char data[]; }; static inline int put_event_ch(int fd, char ch) { - int ret; + int ret; - ret = write(fd, &ch, sizeof(ch)); - if (ret != sizeof(ch)) { - ErrPrint("write: %s\n", strerror(errno)); - return ret; - } + ret = write(fd, &ch, sizeof(ch)); + if (ret != sizeof(ch)) { + ErrPrint("write: %s\n", strerror(errno)); + return ret; + } - return 0; + return 0; } static inline int get_event_ch(int fd) { - int ret; - char ch; + int ret; + char ch; - ret = read(fd, &ch, sizeof(ch)); - if (ret != sizeof(ch)) { - ErrPrint("read: %s\n", strerror(errno)); - return ret; - } + ret = read(fd, &ch, sizeof(ch)); + if (ret != sizeof(ch)) { + ErrPrint("read: %s\n", strerror(errno)); + return ret; + } - ret = (int)((unsigned int)ch); - return ret; + ret = (int)((unsigned int)ch); + return ret; } static inline int file_service_close(int fd) { - return secure_socket_destroy_handle(fd); + return secure_socket_destroy_handle(fd); } static inline int file_service_open(void) { - char *addr; - int port; - char *file_addr; - int len; - int fd; - - addr = malloc(strlen(client_addr()) + 1); - if (!addr) { - ErrPrint("Heap: %s\n", strerror(errno)); - return -ENOMEM; - } - - if (sscanf(client_addr(), COM_CORE_REMOTE_SCHEME"%[^:]:%d", addr, &port) != 2) { - ErrPrint("Invalid URL\n"); - free(addr); - return -EINVAL; - } - - len = strlen(COM_CORE_REMOTE_SCHEME); - len+= strlen(addr); - len+= 6; /* Port length? */ - - file_addr = malloc(len); - if (!file_addr) { - ErrPrint("Heap: %s\n", strerror(errno)); - free(addr); - return -ENOMEM; - } - - snprintf(file_addr, len, COM_CORE_REMOTE_SCHEME"%s:%d", addr, FILE_SERVICE_PORT); - DbgPrint("File service: %s\n", file_addr); - fd = secure_socket_create_client(file_addr); - free(file_addr); - free(addr); - - return fd; + char *addr; + int port; + char *file_addr; + int len; + int fd; + + addr = malloc(strlen(client_addr()) + 1); + if (!addr) { + ErrPrint("Heap: %s\n", strerror(errno)); + return -ENOMEM; + } + + if (sscanf(client_addr(), COM_CORE_REMOTE_SCHEME"%[^:]:%d", addr, &port) != 2) { + ErrPrint("Invalid URL\n"); + free(addr); + return -EINVAL; + } + + len = strlen(COM_CORE_REMOTE_SCHEME); + len+= strlen(addr); + len+= 6; /* Port length? */ + + file_addr = malloc(len); + if (!file_addr) { + ErrPrint("Heap: %s\n", strerror(errno)); + free(addr); + return -ENOMEM; + } + + snprintf(file_addr, len, COM_CORE_REMOTE_SCHEME"%s:%d", addr, FILE_SERVICE_PORT); + DbgPrint("File service: %s\n", file_addr); + fd = secure_socket_create_client(file_addr); + free(file_addr); + free(addr); + + return fd; } /*! @@ -207,14 +207,14 @@ static inline int file_service_open(void) */ static void write_item_to_pipe(struct request_item *item, int ret) { - item->ret = DBOX_STATUS_ERROR_FAULT; - if (write(s_info.evt_pipe[PIPE_WRITE], &item, sizeof(item)) != sizeof(item)) { - ErrPrint("write: %s\n", strerror(errno)); - free(item->filename); - free(item->save_to); - free(item); - item = NULL; - } + item->ret = DBOX_STATUS_ERROR_FAULT; + if (write(s_info.evt_pipe[PIPE_WRITE], &item, sizeof(item)) != sizeof(item)) { + ErrPrint("write: %s\n", strerror(errno)); + free(item->filename); + free(item->save_to); + free(item); + item = NULL; + } } /*! @@ -222,494 +222,494 @@ static void write_item_to_pipe(struct request_item *item, int ret) */ static void *file_service_main(void *data) { - int ret = 0; - int select_fd; - struct timeval tv; - fd_set set; - int offset; - enum { - RECV_INIT, - RECV_HEADER, - RECV_DATA, - } recv_state; - struct burst_head *head; - struct burst_data *body; - int recvsz; - struct request_item *item; - int file_offset; - int file_fd; - - head = NULL; - item = NULL; - recv_state = RECV_INIT; - select_fd = (s_info.file_service_fd > s_info.ctrl_pipe[PIPE_READ] ? s_info.file_service_fd : s_info.ctrl_pipe[PIPE_READ]) + 1; - while (ret == 0) { - FD_ZERO(&set); - FD_SET(s_info.file_service_fd, &set); - FD_SET(s_info.ctrl_pipe[PIPE_READ], &set); - - tv.tv_sec = 3; - tv.tv_usec = 0; - ret = select(select_fd , &set, NULL, NULL, &tv); - if (ret < 0) { - ret = -errno; - if (errno == EINTR) { - ErrPrint("INTERRUPTED\n"); - ret = 0; - continue; - } - ErrPrint("Error: %s\n", strerror(errno)); - break; - } else if (ret == 0) { - ErrPrint("Timeout\n"); - ret = -ETIMEDOUT; - break; - } - - if (item && FD_ISSET(s_info.file_service_fd, &set)) { - switch (recv_state) { - case RECV_INIT: - if (head == NULL) { - recvsz = sizeof(*head); - - head = malloc(recvsz); - if (!head) { - ErrPrint("Heap: %s\n", strerror(errno)); - ret = DBOX_STATUS_ERROR_OUT_OF_MEMORY; - write_item_to_pipe(item, ret); - item = NULL; - break; - } - - offset = 0; - recv_state = RECV_HEADER; - } - case RECV_HEADER: - if (offset < recvsz) { - ret = secure_socket_recv(s_info.file_service_fd, (char *)head + offset, recvsz - offset, NULL); - if (ret > 0) { - offset += ret; - } else { - free(head); - head = NULL; - recv_state = RECV_INIT; - ret = DBOX_STATUS_ERROR_FAULT; - write_item_to_pipe(item, ret); - item = NULL; - break; - } - } - - if (offset == sizeof(*head)) { - void *tmp; - - recvsz += head->flen; - - tmp = realloc(head, recvsz); - if (!tmp) { - ErrPrint("Heap: %s\n", strerror(errno)); - - free(head); - head = NULL; - recv_state = RECV_INIT; - - ret = DBOX_STATUS_ERROR_OUT_OF_MEMORY; - write_item_to_pipe(item, ret); - item = NULL; - break; - } - - head = tmp; - } else if (offset == recvsz) { - DbgPrint("Filesize: %d, name[%s]\n", head->size, head->fname); - if (strcmp(item->filename, head->fname)) { - ErrPrint("Invalid data sequence (%s <> %s)\n", item->filename, head->fname); - - free(head); - head = NULL; - recv_state = RECV_INIT; - ret = DBOX_STATUS_ERROR_FAULT; - write_item_to_pipe(item, ret); - item = NULL; - break; - } - - file_fd = open(item->save_to, O_WRONLY|O_CREAT, 0644); - if (file_fd < 0) { - ErrPrint("open: %s\n", strerror(errno)); - free(head); - head = NULL; - recv_state = RECV_INIT; - - ret = DBOX_STATUS_ERROR_IO_ERROR; - write_item_to_pipe(item, ret); - item = NULL; - break; - } - - recv_state = RECV_DATA; - body = NULL; - - } else { - ErrPrint("Invalid state\n"); - free(head); - head = NULL; - recv_state = RECV_INIT; - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - write_item_to_pipe(item, ret); - item = NULL; - } - break; - case RECV_DATA: - if (!body) { - body = malloc(sizeof(*body)); - if (!body) { - free(head); - head = NULL; - recv_state = RECV_INIT; - ret = DBOX_STATUS_ERROR_OUT_OF_MEMORY; - write_item_to_pipe(item, ret); - item = NULL; - break; - } - - recvsz = sizeof(*body); - offset = 0; - } - - ret = secure_socket_recv(s_info.file_service_fd, (char *)body + offset, recvsz - offset, NULL); - if (ret > 0) { - offset += ret; - } else { - free(head); - head = NULL; - free(body); - body = NULL; - recv_state = RECV_INIT; - ret = DBOX_STATUS_ERROR_FAULT; - write_item_to_pipe(item, ret); - item = NULL; - break; - } - - if (offset == sizeof(*body)) { - void *tmp; - - if (body->size < 0) { - ErrPrint("body->size: %d\n", body->size); - free(head); - head = NULL; - free(body); - body = NULL; - recv_state = RECV_INIT; - ret = DBOX_STATUS_ERROR_FAULT; - write_item_to_pipe(item, ret); - item = NULL; - break; - } - - recvsz += body->size; - - tmp = realloc(body, recvsz); - if (!tmp) { - ErrPrint("Heap: %s\n", strerror(errno)); - free(head); - head = NULL; - - free(body); - body = NULL; - recv_state = RECV_INIT; - - ret = DBOX_STATUS_ERROR_OUT_OF_MEMORY; - write_item_to_pipe(item, ret); - item = NULL; - break; - } - } else if (offset == recvsz) { - /* Flush this to the file */ - ret = write(file_fd, body->data, body->size); - if (ret < 0) { - ErrPrint("write: %s\n", strerror(errno)); - free(head); - head = NULL; - - free(body); - body = NULL; - recv_state = RECV_INIT; - - ret = DBOX_STATUS_ERROR_IO_ERROR; - write_item_to_pipe(item, ret); - item = NULL; - break; - } else { - if (body->size != ret) { - DbgPrint("Body is not flushed correctly: %d, %d\n", ret, body->size); - ret = body->size; - } - - file_offset += ret; - if (file_offset == head->size) { - if (close(file_fd) < 0) { - ErrPrint("close: %s\n", strerror(errno)); - } - ret = DBOX_STATUS_ERROR_NONE; - write_item_to_pipe(item, ret); - item = NULL; - } - } - - free(body); - body = NULL; - - free(head); - head = NULL; - - recv_state = RECV_INIT; - } else { - ErrPrint("Invalid state\n"); - - ret = -EFAULT; - free(body); - body = NULL; - free(head); - head = NULL; - recv_state = RECV_INIT; - - ret = DBOX_STATUS_ERROR_FAULT; - write_item_to_pipe(item, ret); - item = NULL; - } - break; - default: - ErrPrint("Unknown event: %d\n", recv_state); - ret = DBOX_STATUS_ERROR_FAULT; - write_item_to_pipe(item, ret); - item = NULL; - break; - } - } else if (item == NULL && recv_state == RECV_INIT && FD_ISSET(s_info.ctrl_pipe[PIPE_READ], &set)) { - int ch; - struct dlist *l; - - /* Only if the recv state is not changed, we can get next request item */ - ch = get_event_ch(s_info.ctrl_pipe[PIPE_READ]); - if (ch == EVT_END_CH) { - DbgPrint("Service thread is canceled\n"); - break; - } - - CRITICAL_SECTION_BEGIN(&s_info.file_svc_lock); - l = dlist_nth(s_info.request_list, 0); - item = dlist_data(l); - s_info.request_list = dlist_remove(s_info.request_list, l); - CRITICAL_SECTION_END(&s_info.file_svc_lock); - } - } - - return (void *)ret; + int ret = 0; + int select_fd; + struct timeval tv; + fd_set set; + int offset; + enum { + RECV_INIT, + RECV_HEADER, + RECV_DATA, + } recv_state; + struct burst_head *head; + struct burst_data *body; + int recvsz; + struct request_item *item; + int file_offset; + int file_fd; + + head = NULL; + item = NULL; + recv_state = RECV_INIT; + select_fd = (s_info.file_service_fd > s_info.ctrl_pipe[PIPE_READ] ? s_info.file_service_fd : s_info.ctrl_pipe[PIPE_READ]) + 1; + while (ret == 0) { + FD_ZERO(&set); + FD_SET(s_info.file_service_fd, &set); + FD_SET(s_info.ctrl_pipe[PIPE_READ], &set); + + tv.tv_sec = 3; + tv.tv_usec = 0; + ret = select(select_fd , &set, NULL, NULL, &tv); + if (ret < 0) { + ret = -errno; + if (errno == EINTR) { + ErrPrint("INTERRUPTED\n"); + ret = 0; + continue; + } + ErrPrint("Error: %s\n", strerror(errno)); + break; + } else if (ret == 0) { + ErrPrint("Timeout\n"); + ret = -ETIMEDOUT; + break; + } + + if (item && FD_ISSET(s_info.file_service_fd, &set)) { + switch (recv_state) { + case RECV_INIT: + if (head == NULL) { + recvsz = sizeof(*head); + + head = malloc(recvsz); + if (!head) { + ErrPrint("Heap: %s\n", strerror(errno)); + ret = DBOX_STATUS_ERROR_OUT_OF_MEMORY; + write_item_to_pipe(item, ret); + item = NULL; + break; + } + + offset = 0; + recv_state = RECV_HEADER; + } + case RECV_HEADER: + if (offset < recvsz) { + ret = secure_socket_recv(s_info.file_service_fd, (char *)head + offset, recvsz - offset, NULL); + if (ret > 0) { + offset += ret; + } else { + free(head); + head = NULL; + recv_state = RECV_INIT; + ret = DBOX_STATUS_ERROR_FAULT; + write_item_to_pipe(item, ret); + item = NULL; + break; + } + } + + if (offset == sizeof(*head)) { + void *tmp; + + recvsz += head->flen; + + tmp = realloc(head, recvsz); + if (!tmp) { + ErrPrint("Heap: %s\n", strerror(errno)); + + free(head); + head = NULL; + recv_state = RECV_INIT; + + ret = DBOX_STATUS_ERROR_OUT_OF_MEMORY; + write_item_to_pipe(item, ret); + item = NULL; + break; + } + + head = tmp; + } else if (offset == recvsz) { + DbgPrint("Filesize: %d, name[%s]\n", head->size, head->fname); + if (strcmp(item->filename, head->fname)) { + ErrPrint("Invalid data sequence (%s <> %s)\n", item->filename, head->fname); + + free(head); + head = NULL; + recv_state = RECV_INIT; + ret = DBOX_STATUS_ERROR_FAULT; + write_item_to_pipe(item, ret); + item = NULL; + break; + } + + file_fd = open(item->save_to, O_WRONLY|O_CREAT, 0644); + if (file_fd < 0) { + ErrPrint("open: %s\n", strerror(errno)); + free(head); + head = NULL; + recv_state = RECV_INIT; + + ret = DBOX_STATUS_ERROR_IO_ERROR; + write_item_to_pipe(item, ret); + item = NULL; + break; + } + + recv_state = RECV_DATA; + body = NULL; + + } else { + ErrPrint("Invalid state\n"); + free(head); + head = NULL; + recv_state = RECV_INIT; + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + write_item_to_pipe(item, ret); + item = NULL; + } + break; + case RECV_DATA: + if (!body) { + body = malloc(sizeof(*body)); + if (!body) { + free(head); + head = NULL; + recv_state = RECV_INIT; + ret = DBOX_STATUS_ERROR_OUT_OF_MEMORY; + write_item_to_pipe(item, ret); + item = NULL; + break; + } + + recvsz = sizeof(*body); + offset = 0; + } + + ret = secure_socket_recv(s_info.file_service_fd, (char *)body + offset, recvsz - offset, NULL); + if (ret > 0) { + offset += ret; + } else { + free(head); + head = NULL; + free(body); + body = NULL; + recv_state = RECV_INIT; + ret = DBOX_STATUS_ERROR_FAULT; + write_item_to_pipe(item, ret); + item = NULL; + break; + } + + if (offset == sizeof(*body)) { + void *tmp; + + if (body->size < 0) { + ErrPrint("body->size: %d\n", body->size); + free(head); + head = NULL; + free(body); + body = NULL; + recv_state = RECV_INIT; + ret = DBOX_STATUS_ERROR_FAULT; + write_item_to_pipe(item, ret); + item = NULL; + break; + } + + recvsz += body->size; + + tmp = realloc(body, recvsz); + if (!tmp) { + ErrPrint("Heap: %s\n", strerror(errno)); + free(head); + head = NULL; + + free(body); + body = NULL; + recv_state = RECV_INIT; + + ret = DBOX_STATUS_ERROR_OUT_OF_MEMORY; + write_item_to_pipe(item, ret); + item = NULL; + break; + } + } else if (offset == recvsz) { + /* Flush this to the file */ + ret = write(file_fd, body->data, body->size); + if (ret < 0) { + ErrPrint("write: %s\n", strerror(errno)); + free(head); + head = NULL; + + free(body); + body = NULL; + recv_state = RECV_INIT; + + ret = DBOX_STATUS_ERROR_IO_ERROR; + write_item_to_pipe(item, ret); + item = NULL; + break; + } else { + if (body->size != ret) { + DbgPrint("Body is not flushed correctly: %d, %d\n", ret, body->size); + ret = body->size; + } + + file_offset += ret; + if (file_offset == head->size) { + if (close(file_fd) < 0) { + ErrPrint("close: %s\n", strerror(errno)); + } + ret = DBOX_STATUS_ERROR_NONE; + write_item_to_pipe(item, ret); + item = NULL; + } + } + + free(body); + body = NULL; + + free(head); + head = NULL; + + recv_state = RECV_INIT; + } else { + ErrPrint("Invalid state\n"); + + ret = -EFAULT; + free(body); + body = NULL; + free(head); + head = NULL; + recv_state = RECV_INIT; + + ret = DBOX_STATUS_ERROR_FAULT; + write_item_to_pipe(item, ret); + item = NULL; + } + break; + default: + ErrPrint("Unknown event: %d\n", recv_state); + ret = DBOX_STATUS_ERROR_FAULT; + write_item_to_pipe(item, ret); + item = NULL; + break; + } + } else if (item == NULL && recv_state == RECV_INIT && FD_ISSET(s_info.ctrl_pipe[PIPE_READ], &set)) { + int ch; + struct dlist *l; + + /* Only if the recv state is not changed, we can get next request item */ + ch = get_event_ch(s_info.ctrl_pipe[PIPE_READ]); + if (ch == EVT_END_CH) { + DbgPrint("Service thread is canceled\n"); + break; + } + + CRITICAL_SECTION_BEGIN(&s_info.file_svc_lock); + l = dlist_nth(s_info.request_list, 0); + item = dlist_data(l); + s_info.request_list = dlist_remove(s_info.request_list, l); + CRITICAL_SECTION_END(&s_info.file_svc_lock); + } + } + + return (void *)ret; } /* Master */ static gboolean evt_cb(GIOChannel *src, GIOCondition cond, gpointer data) { - int fd; - struct request_item *item; - - fd = g_io_channel_unix_get_fd(src); - - if (!(cond & G_IO_IN)) { - DbgPrint("Client is disconencted\n"); - return FALSE; - } - - if ((cond & G_IO_ERR) || (cond & G_IO_HUP) || (cond & G_IO_NVAL)) { - DbgPrint("Client connection is lost\n"); - return FALSE; - } - - if (read(fd, &item, sizeof(item)) != sizeof(item)) { - ErrPrint("read: %s\n", strerror(errno)); - } else { - if (item->result_cb) { - item->result_cb(item->filename, item->save_to, item->ret, item->data); - } - - free(item->filename); - free(item->save_to); - free(item); - } - - return TRUE; + int fd; + struct request_item *item; + + fd = g_io_channel_unix_get_fd(src); + + if (!(cond & G_IO_IN)) { + DbgPrint("Client is disconencted\n"); + return FALSE; + } + + if ((cond & G_IO_ERR) || (cond & G_IO_HUP) || (cond & G_IO_NVAL)) { + DbgPrint("Client connection is lost\n"); + return FALSE; + } + + if (read(fd, &item, sizeof(item)) != sizeof(item)) { + ErrPrint("read: %s\n", strerror(errno)); + } else { + if (item->result_cb) { + item->result_cb(item->filename, item->save_to, item->ret, item->data); + } + + free(item->filename); + free(item->save_to); + free(item); + } + + return TRUE; } int file_service_send_request(const char *filename, const char *save_to, void (*result_cb)(const char *filename, const char *save_to, int ret, void *data), void *data) { - struct request_item *item; - - item = malloc(sizeof(*item)); - if (!item) { - ErrPrint("Heap: %s\n", strerror(errno)); - return -ENOMEM; - } - - item->filename = strdup(filename); - if (!item->filename) { - ErrPrint("Heap: %s\n", strerror(errno)); - free(item); - return -ENOMEM; - } - - item->save_to = strdup(save_to); - if (!item->save_to) { - ErrPrint("Heap: %s\n", strerror(errno)); - free(item->filename); - free(item); - return -ENOMEM; - } - - item->result_cb = result_cb; - item->data = data; - - CRITICAL_SECTION_BEGIN(&s_info.file_svc_lock); - s_info.request_list = dlist_append(s_info.request_list, item); - CRITICAL_SECTION_END(&s_info.file_svc_lock); - return 0; + struct request_item *item; + + item = malloc(sizeof(*item)); + if (!item) { + ErrPrint("Heap: %s\n", strerror(errno)); + return -ENOMEM; + } + + item->filename = strdup(filename); + if (!item->filename) { + ErrPrint("Heap: %s\n", strerror(errno)); + free(item); + return -ENOMEM; + } + + item->save_to = strdup(save_to); + if (!item->save_to) { + ErrPrint("Heap: %s\n", strerror(errno)); + free(item->filename); + free(item); + return -ENOMEM; + } + + item->result_cb = result_cb; + item->data = data; + + CRITICAL_SECTION_BEGIN(&s_info.file_svc_lock); + s_info.request_list = dlist_append(s_info.request_list, item); + CRITICAL_SECTION_END(&s_info.file_svc_lock); + return 0; } int file_service_init(void) { - int status; - GIOChannel *gio; - guint id; - - if (strncmp(client_addr(), COM_CORE_REMOTE_SCHEME, strlen(COM_CORE_REMOTE_SCHEME))) { - return 0; - } - - s_info.file_service_fd = file_service_open(); - if (s_info.file_service_fd < 0) { - return -EFAULT; - } - - if (pipe2(s_info.ctrl_pipe, O_NONBLOCK | O_CLOEXEC) < 0) { - ErrPrint("file service: %s\n", strerror(errno)); - file_service_close(s_info.file_service_fd); - s_info.file_service_fd = -1; - return -EFAULT; - } - - if (pipe2(s_info.evt_pipe, O_NONBLOCK | O_CLOEXEC) < 0) { - ErrPrint("file service: %s\n", strerror(errno)); - CLOSE_PIPE(s_info.ctrl_pipe); - file_service_close(s_info.file_service_fd); - s_info.file_service_fd = -1; - return -EFAULT; - } - - status = pthread_mutex_init(&s_info.file_svc_lock, NULL); - if (status != 0) { - ErrPrint("Mutex: %s\n", strerror(status)); - CLOSE_PIPE(s_info.ctrl_pipe); - CLOSE_PIPE(s_info.evt_pipe); - file_service_close(s_info.file_service_fd); - s_info.file_service_fd = -1; - return -EFAULT; - } - - gio = g_io_channel_unix_new(s_info.evt_pipe[PIPE_READ]); - if (!gio) { - ErrPrint("io channel new\n"); - status = pthread_mutex_destroy(&s_info.file_svc_lock); - if (status != 0) { - ErrPrint("destroy: %s\n", strerror(status)); - } - CLOSE_PIPE(s_info.ctrl_pipe); - CLOSE_PIPE(s_info.evt_pipe); - file_service_close(s_info.file_service_fd); - s_info.file_service_fd = -1; - return -EFAULT; - } - - g_io_channel_set_close_on_unref(gio, FALSE); - - id = g_io_add_watch(gio, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL, (GIOFunc)evt_cb, NULL); - if (id <= 0) { - GError *err = NULL; - ErrPrint("Failed to add IO watch\n"); - g_io_channel_shutdown(gio, TRUE, &err); - if (err) { - ErrPrint("Shutdown: %s\n", err->message); - g_error_free(err); - } - g_io_channel_unref(gio); - - status = pthread_mutex_destroy(&s_info.file_svc_lock); - if (status != 0) { - ErrPrint("destroy: %s\n", strerror(status)); - } - CLOSE_PIPE(s_info.ctrl_pipe); - CLOSE_PIPE(s_info.evt_pipe); - file_service_close(s_info.file_service_fd); - s_info.file_service_fd = -1; - return -EIO; - } - - status = pthread_create(&s_info.file_svc_thid, NULL, file_service_main, NULL); - if (status != 0) { - GError *err = NULL; - ErrPrint("Failed to add IO watch\n"); - g_io_channel_shutdown(gio, TRUE, &err); - if (err) { - ErrPrint("Shutdown: %s\n", err->message); - g_error_free(err); - } - g_io_channel_unref(gio); - - ErrPrint("file service: %s\n", strerror(status)); - CLOSE_PIPE(s_info.ctrl_pipe); - CLOSE_PIPE(s_info.evt_pipe); - file_service_close(s_info.file_service_fd); - s_info.file_service_fd = -1; - - status = pthread_mutex_destroy(&s_info.file_svc_lock); - if (status != 0) { - ErrPrint("destroy: %s\n", strerror(status)); - } - - return -EFAULT; - } - - g_io_channel_unref(gio); - return 0; + int status; + GIOChannel *gio; + guint id; + + if (strncmp(client_addr(), COM_CORE_REMOTE_SCHEME, strlen(COM_CORE_REMOTE_SCHEME))) { + return 0; + } + + s_info.file_service_fd = file_service_open(); + if (s_info.file_service_fd < 0) { + return -EFAULT; + } + + if (pipe2(s_info.ctrl_pipe, O_NONBLOCK | O_CLOEXEC) < 0) { + ErrPrint("file service: %s\n", strerror(errno)); + file_service_close(s_info.file_service_fd); + s_info.file_service_fd = -1; + return -EFAULT; + } + + if (pipe2(s_info.evt_pipe, O_NONBLOCK | O_CLOEXEC) < 0) { + ErrPrint("file service: %s\n", strerror(errno)); + CLOSE_PIPE(s_info.ctrl_pipe); + file_service_close(s_info.file_service_fd); + s_info.file_service_fd = -1; + return -EFAULT; + } + + status = pthread_mutex_init(&s_info.file_svc_lock, NULL); + if (status != 0) { + ErrPrint("Mutex: %s\n", strerror(status)); + CLOSE_PIPE(s_info.ctrl_pipe); + CLOSE_PIPE(s_info.evt_pipe); + file_service_close(s_info.file_service_fd); + s_info.file_service_fd = -1; + return -EFAULT; + } + + gio = g_io_channel_unix_new(s_info.evt_pipe[PIPE_READ]); + if (!gio) { + ErrPrint("io channel new\n"); + status = pthread_mutex_destroy(&s_info.file_svc_lock); + if (status != 0) { + ErrPrint("destroy: %s\n", strerror(status)); + } + CLOSE_PIPE(s_info.ctrl_pipe); + CLOSE_PIPE(s_info.evt_pipe); + file_service_close(s_info.file_service_fd); + s_info.file_service_fd = -1; + return -EFAULT; + } + + g_io_channel_set_close_on_unref(gio, FALSE); + + id = g_io_add_watch(gio, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL, (GIOFunc)evt_cb, NULL); + if (id <= 0) { + GError *err = NULL; + ErrPrint("Failed to add IO watch\n"); + g_io_channel_shutdown(gio, TRUE, &err); + if (err) { + ErrPrint("Shutdown: %s\n", err->message); + g_error_free(err); + } + g_io_channel_unref(gio); + + status = pthread_mutex_destroy(&s_info.file_svc_lock); + if (status != 0) { + ErrPrint("destroy: %s\n", strerror(status)); + } + CLOSE_PIPE(s_info.ctrl_pipe); + CLOSE_PIPE(s_info.evt_pipe); + file_service_close(s_info.file_service_fd); + s_info.file_service_fd = -1; + return -EIO; + } + + status = pthread_create(&s_info.file_svc_thid, NULL, file_service_main, NULL); + if (status != 0) { + GError *err = NULL; + ErrPrint("Failed to add IO watch\n"); + g_io_channel_shutdown(gio, TRUE, &err); + if (err) { + ErrPrint("Shutdown: %s\n", err->message); + g_error_free(err); + } + g_io_channel_unref(gio); + + ErrPrint("file service: %s\n", strerror(status)); + CLOSE_PIPE(s_info.ctrl_pipe); + CLOSE_PIPE(s_info.evt_pipe); + file_service_close(s_info.file_service_fd); + s_info.file_service_fd = -1; + + status = pthread_mutex_destroy(&s_info.file_svc_lock); + if (status != 0) { + ErrPrint("destroy: %s\n", strerror(status)); + } + + return -EFAULT; + } + + g_io_channel_unref(gio); + return 0; } int file_service_fini(void) { - void *svc_ret; - int ret; + void *svc_ret; + int ret; - if (strncmp(client_addr(), COM_CORE_REMOTE_SCHEME, strlen(COM_CORE_REMOTE_SCHEME))) { - return 0; - } + if (strncmp(client_addr(), COM_CORE_REMOTE_SCHEME, strlen(COM_CORE_REMOTE_SCHEME))) { + return 0; + } - (void)put_event_ch(s_info.ctrl_pipe[PIPE_WRITE], EVT_END_CH); + (void)put_event_ch(s_info.ctrl_pipe[PIPE_WRITE], EVT_END_CH); - ret = pthread_join(s_info.file_svc_thid, &svc_ret); - if (ret != 0) { - ErrPrint("join: %s\n", strerror(ret)); - } else { - DbgPrint("file svc returns: %d\n", (int)svc_ret); - } + ret = pthread_join(s_info.file_svc_thid, &svc_ret); + if (ret != 0) { + ErrPrint("join: %s\n", strerror(ret)); + } else { + DbgPrint("file svc returns: %d\n", (int)svc_ret); + } - ret = pthread_mutex_destroy(&s_info.file_svc_lock); - if (ret != 0) { - ErrPrint("destroy: %s\n", strerror(ret)); - } + ret = pthread_mutex_destroy(&s_info.file_svc_lock); + if (ret != 0) { + ErrPrint("destroy: %s\n", strerror(ret)); + } - CLOSE_PIPE(s_info.evt_pipe); - CLOSE_PIPE(s_info.ctrl_pipe); + CLOSE_PIPE(s_info.evt_pipe); + CLOSE_PIPE(s_info.ctrl_pipe); - return 0; + return 0; } /* End of a file */ diff --git a/src/master_rpc.c b/src/master_rpc.c index 5e182a0..2a73743 100644 --- a/src/master_rpc.c +++ b/src/master_rpc.c @@ -26,6 +26,7 @@ #include #include #include +#include #include "debug.h" #include "dlist.h" @@ -39,159 +40,159 @@ #define REQUEST_DELAY 10 struct command { - int ttl; - struct packet *packet; - dynamicbox_h handler; - void (*ret_cb)(dynamicbox_h handler, const struct packet *result, void *data); - void *data; - enum { - TYPE_ACK, - TYPE_NOACK - } type; + int ttl; + struct packet *packet; + dynamicbox_h handler; + void (*ret_cb)(dynamicbox_h handler, const struct packet *result, void *data); + void *data; + enum { + TYPE_ACK, + TYPE_NOACK + } type; }; int errno; static struct { - guint cmd_timer; - struct dlist *cmd_list; + guint cmd_timer; + struct dlist *cmd_list; } s_info = { - .cmd_timer = 0, - .cmd_list = NULL, + .cmd_timer = 0, + .cmd_list = NULL, }; static int done_cb(pid_t pid, int handle, const struct packet *packet, void *data); static inline struct command *pop_command(void) { - struct dlist *l; - struct command *command; + struct dlist *l; + struct command *command; - l = dlist_nth(s_info.cmd_list, 0); - if (!l) { - return NULL; - } + l = dlist_nth(s_info.cmd_list, 0); + if (!l) { + return NULL; + } - command = dlist_data(l); - s_info.cmd_list = dlist_remove(s_info.cmd_list, l); - return command; + command = dlist_data(l); + s_info.cmd_list = dlist_remove(s_info.cmd_list, l); + return command; } static inline struct command *create_command(dynamicbox_h handler, struct packet *packet) { - struct command *command; + struct command *command; - command = malloc(sizeof(*command)); - if (!command) { - ErrPrint("Failed to allocate mem for command\n"); - return NULL; - } + command = malloc(sizeof(*command)); + if (!command) { + ErrPrint("Failed to allocate mem for command\n"); + return NULL; + } - command->handler = dbox_ref(handler); - command->packet = packet_ref(packet); - return command; + command->handler = dbox_ref(handler); + command->packet = packet_ref(packet); + return command; } static inline void destroy_command(struct command *command) { - packet_unref(command->packet); - dbox_unref(command->handler, 1); - free(command); + packet_unref(command->packet); + dbox_unref(command->handler, 1); + free(command); } static gboolean cmd_consumer(gpointer user_data) { - struct command *command; - - command = pop_command(); - if (!command) { - s_info.cmd_timer = 0; - return FALSE; - } - - /*! - * \NOTE: - * Item will be deleted in the "done_cb" - * - * item->param be release by the g_dbus_proxy_call - * so to use it again from the done_cb function, - * increate the reference counter of the item->param - */ - if (command->type == TYPE_NOACK) { - if (com_core_packet_send_only(client_fd(), command->packet) < 0) { - ErrPrint("Failed to send a packet to master\n"); - } - - destroy_command(command); - } else { - if (com_core_packet_async_send(client_fd(), command->packet, 0u, done_cb, command) < 0) { - ErrPrint("Failed to send a packet to master\n"); - if (command->ret_cb) { - command->ret_cb(command->handler, NULL, command->data); - } - destroy_command(command); - } - } - return TRUE; + struct command *command; + + command = pop_command(); + if (!command) { + s_info.cmd_timer = 0; + return FALSE; + } + + /*! + * \NOTE: + * Item will be deleted in the "done_cb" + * + * item->param be release by the g_dbus_proxy_call + * so to use it again from the done_cb function, + * increate the reference counter of the item->param + */ + if (command->type == TYPE_NOACK) { + if (com_core_packet_send_only(client_fd(), command->packet) < 0) { + ErrPrint("Failed to send a packet to master\n"); + } + + destroy_command(command); + } else { + if (com_core_packet_async_send(client_fd(), command->packet, 0u, done_cb, command) < 0) { + ErrPrint("Failed to send a packet to master\n"); + if (command->ret_cb) { + command->ret_cb(command->handler, NULL, command->data); + } + destroy_command(command); + } + } + return TRUE; } static inline void prepend_command(struct command *command) { - s_info.cmd_list = dlist_prepend(s_info.cmd_list, command); - master_rpc_check_and_fire_consumer(); + s_info.cmd_list = dlist_prepend(s_info.cmd_list, command); + master_rpc_check_and_fire_consumer(); } void master_rpc_check_and_fire_consumer(void) { - if (!s_info.cmd_list || s_info.cmd_timer || client_fd() < 0) { - return; - } - - s_info.cmd_timer = g_timeout_add(REQUEST_DELAY, cmd_consumer, NULL); - if (!s_info.cmd_timer) { - ErrPrint("Failed to add timer\n"); - } + if (!s_info.cmd_list || s_info.cmd_timer || client_fd() < 0) { + return; + } + + s_info.cmd_timer = g_timeout_add(REQUEST_DELAY, cmd_consumer, NULL); + if (!s_info.cmd_timer) { + ErrPrint("Failed to add timer\n"); + } } static int done_cb(pid_t pid, int handle, const struct packet *packet, void *data) { - struct command *command; - int ret; - - command = data; - - if (!packet) { - /*! \NOTE: - * Release resource even if - * we failed to finish the method call - */ - command->ttl--; - if (command->ttl > 0) { - prepend_command(command); - return 0; - } - - goto out; - } - - if (packet_get(packet, "i", &ret) != 1) { - ErrPrint("Invalid result packet\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + struct command *command; + int ret; + + command = data; + + if (!packet) { + /*! \NOTE: + * Release resource even if + * we failed to finish the method call + */ + command->ttl--; + if (command->ttl > 0) { + prepend_command(command); + return 0; + } + + goto out; + } + + if (packet_get(packet, "i", &ret) != 1) { + ErrPrint("Invalid result packet\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + } out: - if (command->ret_cb) { - command->ret_cb(command->handler, packet, command->data); - } + if (command->ret_cb) { + command->ret_cb(command->handler, packet, command->data); + } - destroy_command(command); - return 0; + destroy_command(command); + return 0; } static inline void push_command(struct command *command) { - s_info.cmd_list = dlist_append(s_info.cmd_list, command); - master_rpc_check_and_fire_consumer(); + s_info.cmd_list = dlist_append(s_info.cmd_list, command); + master_rpc_check_and_fire_consumer(); } /*! @@ -200,118 +201,118 @@ static inline void push_command(struct command *command) */ int master_rpc_async_request(dynamicbox_h handler, struct packet *packet, int urgent, void (*ret_cb)(dynamicbox_h handler, const struct packet *result, void *data), void *data) { - struct command *command; - - command = create_command(handler, packet); - if (!command) { - ErrPrint("Failed to create a command\n"); - packet_unref(packet); - return DBOX_STATUS_ERROR_FAULT; - } - - command->ret_cb = ret_cb; - command->data = data; - command->ttl = DEFAULT_TTL; - command->type = TYPE_ACK; - - if (urgent) { - prepend_command(command); - } else { - push_command(command); - } - - packet_unref(packet); - return DBOX_STATUS_ERROR_NONE; + struct command *command; + + command = create_command(handler, packet); + if (!command) { + ErrPrint("Failed to create a command\n"); + packet_unref(packet); + return DBOX_STATUS_ERROR_FAULT; + } + + command->ret_cb = ret_cb; + command->data = data; + command->ttl = DEFAULT_TTL; + command->type = TYPE_ACK; + + if (urgent) { + prepend_command(command); + } else { + push_command(command); + } + + packet_unref(packet); + return DBOX_STATUS_ERROR_NONE; } int master_rpc_request_only(dynamicbox_h handler, struct packet *packet) { - struct command *command; - - command = create_command(handler, packet); - if (!command) { - ErrPrint("Failed to create a command\n"); - packet_unref(packet); - return DBOX_STATUS_ERROR_FAULT; - } - - command->ret_cb = NULL; - command->data = NULL; - command->ttl = 0; - command->type = TYPE_NOACK; - - push_command(command); - packet_unref(packet); - return DBOX_STATUS_ERROR_NONE; + struct command *command; + + command = create_command(handler, packet); + if (!command) { + ErrPrint("Failed to create a command\n"); + packet_unref(packet); + return DBOX_STATUS_ERROR_FAULT; + } + + command->ret_cb = NULL; + command->data = NULL; + command->ttl = 0; + command->type = TYPE_NOACK; + + push_command(command); + packet_unref(packet); + return DBOX_STATUS_ERROR_NONE; } int master_rpc_clear_fault_package(const char *pkgname) { - struct dlist *l; - struct dlist *n; - struct command *command; - - if (!pkgname) { - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - dlist_foreach_safe(s_info.cmd_list, l, n, command) { - if (!command->handler) { - continue; - } - - if (!strcmp(command->handler->common->pkgname, pkgname)) { - s_info.cmd_list = dlist_remove(s_info.cmd_list, l); - if (command->ret_cb) { - command->ret_cb(command->handler, NULL, command->data); - } - - destroy_command(command); - } - } - - return 0; + struct dlist *l; + struct dlist *n; + struct command *command; + + if (!pkgname) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + dlist_foreach_safe(s_info.cmd_list, l, n, command) { + if (!command->handler) { + continue; + } + + if (!strcmp(command->handler->common->pkgname, pkgname)) { + s_info.cmd_list = dlist_remove(s_info.cmd_list, l); + if (command->ret_cb) { + command->ret_cb(command->handler, NULL, command->data); + } + + destroy_command(command); + } + } + + return 0; } int master_rpc_clear_all_request(void) { - struct command *command; - struct dlist *l; - struct dlist *n; + struct command *command; + struct dlist *l; + struct dlist *n; - dlist_foreach_safe(s_info.cmd_list, l, n, command) { - s_info.cmd_list = dlist_remove(s_info.cmd_list, l); + dlist_foreach_safe(s_info.cmd_list, l, n, command) { + s_info.cmd_list = dlist_remove(s_info.cmd_list, l); - if (command->ret_cb) { - command->ret_cb(command->handler, NULL, command->data); - } + if (command->ret_cb) { + command->ret_cb(command->handler, NULL, command->data); + } - destroy_command(command); - } + destroy_command(command); + } - return 0; + return 0; } int master_rpc_sync_request(struct packet *packet) { - struct packet *result; - int ret; - - result = com_core_packet_oneshot_send(client_addr(), packet, 0.0f); - if (result) { - if (packet_get(result, "i", &ret) != 1) { - ErrPrint("Invalid result packet\n"); - ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - packet_unref(result); - } else { - ErrPrint("Failed to send a sync request\n"); - ret = DBOX_STATUS_ERROR_FAULT; - } - - packet_unref(packet); - return ret; + struct packet *result; + int ret; + + result = com_core_packet_oneshot_send(client_addr(), packet, 0.0f); + if (result) { + if (packet_get(result, "i", &ret) != 1) { + ErrPrint("Invalid result packet\n"); + ret = DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + packet_unref(result); + } else { + ErrPrint("Failed to send a sync request\n"); + ret = DBOX_STATUS_ERROR_FAULT; + } + + packet_unref(packet); + return ret; } /* End of a file */ diff --git a/src/util.c b/src/util.c index 002a5f4..87bfbb9 100644 --- a/src/util.c +++ b/src/util.c @@ -31,120 +31,120 @@ int errno; #if defined(_USE_ECORE_TIME_GET) static struct { - clockid_t type; + clockid_t type; } s_info = { - .type = CLOCK_MONOTONIC, + .type = CLOCK_MONOTONIC, }; #endif int util_check_extension(const char *filename, const char *check_ptr) { - int name_len; + int name_len; - name_len = strlen(filename); - while (--name_len >= 0 && *check_ptr) { - if (filename[name_len] != *check_ptr) { - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } + name_len = strlen(filename); + while (--name_len >= 0 && *check_ptr) { + if (filename[name_len] != *check_ptr) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } - check_ptr ++; - } + check_ptr ++; + } - return 0; + return 0; } double util_timestamp(void) { #if defined(_USE_ECORE_TIME_GET) - struct timespec ts; - - do { - if (clock_gettime(s_info.type, &ts) == 0) { - return ts.tv_sec + ts.tv_nsec / 1000000000.0f; - } - - ErrPrint("%d: %s\n", s_info.type, strerror(errno)); - if (s_info.type == CLOCK_MONOTONIC) { - s_info.type = CLOCK_REALTIME; - } else if (s_info.type == CLOCK_REALTIME) { - struct timeval tv; - if (gettimeofday(&tv, NULL) < 0) { - ErrPrint("gettimeofday: %s\n", strerror(errno)); - break; - } - - return tv.tv_sec + tv.tv_usec / 1000000.0f; - } - } while (1); - - return 0.0f; + struct timespec ts; + + do { + if (clock_gettime(s_info.type, &ts) == 0) { + return ts.tv_sec + ts.tv_nsec / 1000000000.0f; + } + + ErrPrint("%d: %s\n", s_info.type, strerror(errno)); + if (s_info.type == CLOCK_MONOTONIC) { + s_info.type = CLOCK_REALTIME; + } else if (s_info.type == CLOCK_REALTIME) { + struct timeval tv; + if (gettimeofday(&tv, NULL) < 0) { + ErrPrint("gettimeofday: %s\n", strerror(errno)); + break; + } + + return tv.tv_sec + tv.tv_usec / 1000000.0f; + } + } while (1); + + return 0.0f; #else - struct timeval tv; + struct timeval tv; - if (gettimeofday(&tv, NULL) < 0) { - ErrPrint("gettimeofday: %s\n", strerror(errno)); - tv.tv_sec = 0; - tv.tv_usec = 0; - } + if (gettimeofday(&tv, NULL) < 0) { + ErrPrint("gettimeofday: %s\n", strerror(errno)); + tv.tv_sec = 0; + tv.tv_usec = 0; + } - return (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0f; + return (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0f; #endif } const char *util_basename(const char *name) { - int length; - length = name ? strlen(name) : 0; - if (!length) { - return "."; - } + int length; + length = name ? strlen(name) : 0; + if (!length) { + return "."; + } - while (--length > 0 && name[length] != '/'); + while (--length > 0 && name[length] != '/'); - return length <= 0 ? name : name + length + (name[length] == '/'); + return length <= 0 ? name : name + length + (name[length] == '/'); } const char *util_uri_to_path(const char *uri) { - int len; + int len; - len = strlen(SCHEMA_FILE); - if (strncasecmp(uri, SCHEMA_FILE, len)) { - return NULL; - } + len = strlen(SCHEMA_FILE); + if (strncasecmp(uri, SCHEMA_FILE, len)) { + return NULL; + } - return uri + len; + return uri + len; } int util_unlink(const char *filename) { - char *descfile; - int desclen; - int ret; - - if (!filename) { - return DBOX_STATUS_ERROR_INVALID_PARAMETER; - } - - desclen = strlen(filename) + 6; /* .desc */ - descfile = malloc(desclen); - if (!descfile) { - ErrPrint("Heap: %s\n", strerror(errno)); - return DBOX_STATUS_ERROR_OUT_OF_MEMORY; - } - - ret = snprintf(descfile, desclen, "%s.desc", filename); - if (ret < 0) { - ErrPrint("Error: %s\n", strerror(errno)); - free(descfile); - return DBOX_STATUS_ERROR_FAULT; - } - - (void)unlink(descfile); - free(descfile); - (void)unlink(filename); - - return DBOX_STATUS_ERROR_NONE; + char *descfile; + int desclen; + int ret; + + if (!filename) { + return DBOX_STATUS_ERROR_INVALID_PARAMETER; + } + + desclen = strlen(filename) + 6; /* .desc */ + descfile = malloc(desclen); + if (!descfile) { + ErrPrint("Heap: %s\n", strerror(errno)); + return DBOX_STATUS_ERROR_OUT_OF_MEMORY; + } + + ret = snprintf(descfile, desclen, "%s.desc", filename); + if (ret < 0) { + ErrPrint("Error: %s\n", strerror(errno)); + free(descfile); + return DBOX_STATUS_ERROR_FAULT; + } + + (void)unlink(descfile); + free(descfile); + (void)unlink(filename); + + return DBOX_STATUS_ERROR_NONE; } /* End of a file */ -- 2.7.4