X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fminicontrol-monitor.c;h=2f948354d09d6e2bceeaa8a9d14c1c314ae89dcd;hb=cf4be8bb15d827cab3b4c4fcd9ef84c6dfa55490;hp=50f96097936d7c09684538362e7307abfd5942ff;hpb=9265db2c03d02584b6f9fcd4d0aba967f984a1e7;p=apps%2Fhome%2Fminicontrol.git diff --git a/src/minicontrol-monitor.c b/src/minicontrol-monitor.c old mode 100755 new mode 100644 index 50f9609..2f94835 --- a/src/minicontrol-monitor.c +++ b/src/minicontrol-monitor.c @@ -20,20 +20,16 @@ #include "minicontrol-error.h" #include "minicontrol-internal.h" #include "minicontrol-monitor.h" +#include "minicontrol-viewer.h" #include "minicontrol-log.h" struct _minicontrol_monitor { - minictrl_sig_handle *start_sh; - minictrl_sig_handle *realize_sh; - minictrl_sig_handle *stop_sh; - minictrl_sig_handle *resize_sh; - minictrl_sig_handle *request_sh; + minictrl_sig_handle *event_sh; minicontrol_monitor_cb callback; - minicontrol_monitor_with_handler_cb callback_with_handler; void *user_data; }; -static struct _minicontrol_monitor *g_monitor_h; +static struct _minicontrol_monitor *g_monitor_h = NULL; static minicontrol_priority_e _int_to_priority(unsigned int value) { @@ -53,384 +49,74 @@ static minicontrol_priority_e _int_to_priority(unsigned int value) return priority; } -static int _provider_get_data_from_dbus_message( - DBusMessage *msg, char **name, - unsigned int *w, unsigned int *h, unsigned int *pri, - minicontrol_h *handler) +static void _sig_to_viewer_handler_cb(minicontrol_event_e event, const char *minicontrol_name, bundle *event_arg, void *data) { + minicontrol_action_e action; + int width = 0; + int height = 0; + int priority_from_signal = 0; + minicontrol_priority_e priority = 0; + size_t n_size; + + switch(event) { + case MINICONTROL_EVENT_START: + action = MINICONTROL_ACTION_START; + break; - DBusError err; - dbus_bool_t dbus_ret; - char *raw_data = NULL; - int raw_data_len = 0; - - if (msg != NULL && name != NULL && - w != NULL && h != NULL && pri != NULL && - handler != NULL) { - dbus_error_init(&err); - dbus_ret = dbus_message_get_args(msg, &err, - DBUS_TYPE_STRING, name, - DBUS_TYPE_UINT32, w, - DBUS_TYPE_UINT32, h, - DBUS_TYPE_UINT32, pri, - DBUS_TYPE_STRING, &raw_data, - DBUS_TYPE_UINT32, &raw_data_len, - DBUS_TYPE_INVALID); - if (!dbus_ret) { - ERR("fail to get args : %s", err.message); - if (*name == NULL) { - ERR("Failed to get a service name, give up"); - dbus_error_free(&err); - return MINICONTROL_ERROR_DBUS; - } - } - - if (raw_data != NULL && raw_data_len > 0) { - _minictrl_handler_get_handler_from_raw_data(handler, raw_data, raw_data_len); - } else { - ERR("failed to get handler from DBUS message"); - } - dbus_error_free(&err); - } - - return MINICONTROL_ERROR_NONE; -} - -static void _provider_start_cb(void *data, DBusMessage *msg) -{ - char *svr_name = NULL; - unsigned int w = 0; - unsigned int h = 0; - unsigned int pri = 0; - minicontrol_h handler = NULL; - minicontrol_priority_e priority; - - if (_provider_get_data_from_dbus_message(msg, &svr_name, &w, &h, &pri, &handler) != MINICONTROL_ERROR_NONE) { - ERR("fail to data from DBUS message"); - return ; - } - - priority = _int_to_priority(pri); - - if (g_monitor_h->callback) { - g_monitor_h->callback(MINICONTROL_ACTION_START, - svr_name, w, h, priority, - g_monitor_h->user_data); - } - if (g_monitor_h->callback_with_handler) { - g_monitor_h->callback_with_handler(MINICONTROL_ACTION_START, - svr_name, w, h, priority, - handler, - g_monitor_h->user_data); - } - - if (handler != NULL) { - _minictrl_handler_destroy(handler); - } -} - -static void _provider_realized_cb(void *data, DBusMessage *msg) -{ - char *svr_name = NULL; - unsigned int w = 0; - unsigned int h = 0; - unsigned int pri = 0; - minicontrol_h handler = NULL; - minicontrol_priority_e priority; - - if (_provider_get_data_from_dbus_message(msg, &svr_name, &w, &h, &pri, &handler) != MINICONTROL_ERROR_NONE) { - ERR("fail to data from DBUS message"); - return ; - } - - priority = _int_to_priority(pri); - - if (g_monitor_h->callback) { - g_monitor_h->callback(MINICONTROL_ACTION_REALIZE, - svr_name, w, h, priority, - g_monitor_h->user_data); - } - if (g_monitor_h->callback_with_handler) { - g_monitor_h->callback_with_handler(MINICONTROL_ACTION_REALIZE, - svr_name, w, h, priority, - handler, - g_monitor_h->user_data); - } - - if (handler != NULL) { - _minictrl_handler_destroy(handler); - } -} - -static void _provider_stop_cb(void *data, DBusMessage *msg) -{ - char *svr_name = NULL; - unsigned int w = 0; - unsigned int h = 0; - unsigned int pri = 0; - minicontrol_h handler = NULL; - minicontrol_priority_e priority; - - if (_provider_get_data_from_dbus_message(msg, &svr_name, &w, &h, &pri, &handler) != MINICONTROL_ERROR_NONE) { - ERR("fail to data from DBUS message"); - return ; - } - - priority = _int_to_priority(pri); - - if (g_monitor_h->callback) { - g_monitor_h->callback(MINICONTROL_ACTION_STOP, - svr_name, w, h, priority, - g_monitor_h->user_data); - } - if (g_monitor_h->callback_with_handler) { - g_monitor_h->callback_with_handler(MINICONTROL_ACTION_STOP, - svr_name, w, h, priority, - handler, - g_monitor_h->user_data); - } - - if (handler != NULL) { - _minictrl_handler_destroy(handler); - } -} - -static void _provider_resize_cb(void *data, DBusMessage *msg) -{ - char *svr_name = NULL; - unsigned int w = 0; - unsigned int h = 0; - unsigned int pri = 0; - minicontrol_h handler = NULL; - minicontrol_priority_e priority; - - if (_provider_get_data_from_dbus_message(msg, &svr_name, &w, &h, &pri, &handler) != MINICONTROL_ERROR_NONE) { - ERR("fail to data from DBUS message"); - return ; - } - - priority = _int_to_priority(pri); - - if (g_monitor_h->callback) { - g_monitor_h->callback(MINICONTROL_ACTION_RESIZE, - svr_name, w, h, priority, - g_monitor_h->user_data); - } - if (g_monitor_h->callback_with_handler) { - g_monitor_h->callback_with_handler(MINICONTROL_ACTION_RESIZE, - svr_name, w, h, priority, - handler, - g_monitor_h->user_data); - } + case MINICONTROL_EVENT_STOP: + action = MINICONTROL_ACTION_STOP; + break; - if (handler != NULL) { - _minictrl_handler_destroy(handler); - } -} + case MINICONTROL_EVENT_RESIZE: + action = MINICONTROL_ACTION_RESIZE; + break; -static void _provider_request_cb(void *data, DBusMessage *msg) -{ - char *svr_name = NULL; - unsigned int w = 0; - unsigned int h = 0; - unsigned int pri = 0; - minicontrol_h handler = NULL; - minicontrol_priority_e priority; + case MINICONTROL_EVENT_REQUEST_HIDE: + case MINICONTROL_EVENT_REQUEST_ANGLE: + action = MINICONTROL_ACTION_REQUEST; + break; - if (_provider_get_data_from_dbus_message(msg, &svr_name, &w, &h, &pri, &handler) != MINICONTROL_ERROR_NONE) { - ERR("fail to data from DBUS message"); - return ; + default: + WARN("Not supported event [%d]", event); + action = event; + break; } - priority = _int_to_priority(pri); - - if (g_monitor_h->callback) { - g_monitor_h->callback(MINICONTROL_ACTION_REQUEST, - svr_name, w, h, priority, - g_monitor_h->user_data); + if (action == MINICONTROL_ACTION_START || action == MINICONTROL_ACTION_RESIZE || action == MINICONTROL_ACTION_REQUEST) { + bundle_get_byte(event_arg, "width", (void*)&width, &n_size); + bundle_get_byte(event_arg, "height", (void*)&height, &n_size); + bundle_get_byte(event_arg, "priority", (void*)&priority_from_signal, &n_size); + priority = _int_to_priority(priority_from_signal); } - if (g_monitor_h->callback_with_handler) { - g_monitor_h->callback_with_handler(MINICONTROL_ACTION_REQUEST, - svr_name, w, h, priority, - handler, - g_monitor_h->user_data); + else { + priority = MINICONTROL_PRIORITY_LOW; } - if (handler != NULL) { - _minictrl_handler_destroy(handler); - } + g_monitor_h->callback(action, minicontrol_name, width, height, priority, g_monitor_h->user_data); } -EXPORT_API minicontrol_error_e minicontrol_monitor_start( - minicontrol_monitor_cb callback, void *data) +EXPORT_API minicontrol_error_e minicontrol_monitor_start(minicontrol_monitor_cb callback, void *data) { if (!callback) return MINICONTROL_ERROR_INVALID_PARAMETER; - if (!g_monitor_h) { - minictrl_sig_handle *start_sh; - minictrl_sig_handle *realize_sh; - minictrl_sig_handle *stop_sh; - minictrl_sig_handle *resize_sh; - minictrl_sig_handle *request_sh; - struct _minicontrol_monitor *monitor_h; - - start_sh = _minictrl_dbus_sig_handle_attach( - MINICTRL_DBUS_SIG_START, - _provider_start_cb, NULL); - if (!start_sh) { - ERR("fail to _minictrl_dbus_sig_handle_attach - %s", - MINICTRL_DBUS_SIG_START); - return MINICONTROL_ERROR_DBUS; - } - - realize_sh = _minictrl_dbus_sig_handle_attach( - MINICTRL_DBUS_SIG_REALIZE, - _provider_realized_cb, NULL); - if (!realize_sh) { - ERR("fail to _minictrl_dbus_sig_handle_attach - %s", - MINICTRL_DBUS_SIG_REALIZE); - return MINICONTROL_ERROR_DBUS; - } - - stop_sh = _minictrl_dbus_sig_handle_attach( - MINICTRL_DBUS_SIG_STOP, - _provider_stop_cb, NULL); - if (!stop_sh) { - ERR("fail to _minictrl_dbus_sig_handle_attach - %s", - MINICTRL_DBUS_SIG_STOP); - return MINICONTROL_ERROR_DBUS; - } - - resize_sh = _minictrl_dbus_sig_handle_attach( - MINICTRL_DBUS_SIG_RESIZE, - _provider_resize_cb, NULL); - if (!resize_sh) { - ERR("fail to _minictrl_dbus_sig_handle_attach - %s", - MINICTRL_DBUS_SIG_RESIZE); - return MINICONTROL_ERROR_DBUS; - } - - request_sh = _minictrl_dbus_sig_handle_attach( - MINICTRL_DBUS_SIG_REQUEST, - _provider_request_cb, NULL); - if (!request_sh) { - ERR("fail to _minictrl_dbus_sig_handle_attach - %s", - MINICTRL_DBUS_SIG_REQUEST); - return MINICONTROL_ERROR_DBUS; - } - - monitor_h = calloc(1, sizeof(struct _minicontrol_monitor)); - if (!monitor_h) { - ERR("fail to alloc monitor_h"); - _minictrl_dbus_sig_handle_dettach(start_sh); - _minictrl_dbus_sig_handle_dettach(realize_sh); - _minictrl_dbus_sig_handle_dettach(stop_sh); - _minictrl_dbus_sig_handle_dettach(resize_sh); - _minictrl_dbus_sig_handle_dettach(request_sh); - return MINICONTROL_ERROR_OUT_OF_MEMORY; - } - - monitor_h->start_sh = start_sh; - monitor_h->realize_sh = realize_sh; - monitor_h->stop_sh = stop_sh; - monitor_h->resize_sh = resize_sh; - monitor_h->request_sh = request_sh; - monitor_h->callback = NULL; - monitor_h->callback_with_handler = NULL; - g_monitor_h = monitor_h; - } - - g_monitor_h->callback = callback; - g_monitor_h->user_data = data; INFO("callback[%p], data[%p]", callback, data); - return _minictrl_viewer_req_message_send(); -} - -EXPORT_API minicontrol_error_e minicontrol_monitor_start_with_handler( - minicontrol_monitor_with_handler_cb callback, void *data) -{ - if (!callback) - return MINICONTROL_ERROR_INVALID_PARAMETER; - - if (!g_monitor_h) { - minictrl_sig_handle *start_sh; - minictrl_sig_handle *realize_sh; - minictrl_sig_handle *stop_sh; - minictrl_sig_handle *resize_sh; - minictrl_sig_handle *request_sh; - struct _minicontrol_monitor *monitor_h; - - start_sh = _minictrl_dbus_sig_handle_attach( - MINICTRL_DBUS_SIG_START, - _provider_start_cb, NULL); - if (!start_sh) { - ERR("fail to _minictrl_dbus_sig_handle_attach - %s", - MINICTRL_DBUS_SIG_START); - return MINICONTROL_ERROR_DBUS; - } - - realize_sh = _minictrl_dbus_sig_handle_attach( - MINICTRL_DBUS_SIG_REALIZE, - _provider_realized_cb, NULL); - if (!realize_sh) { - ERR("fail to _minictrl_dbus_sig_handle_attach - %s", - MINICTRL_DBUS_SIG_REALIZE); - return MINICONTROL_ERROR_DBUS; - } - - stop_sh = _minictrl_dbus_sig_handle_attach( - MINICTRL_DBUS_SIG_STOP, - _provider_stop_cb, NULL); - if (!stop_sh) { - ERR("fail to _minictrl_dbus_sig_handle_attach - %s", - MINICTRL_DBUS_SIG_STOP); - return MINICONTROL_ERROR_DBUS; - } - - resize_sh = _minictrl_dbus_sig_handle_attach( - MINICTRL_DBUS_SIG_RESIZE, - _provider_resize_cb, NULL); - if (!resize_sh) { - ERR("fail to _minictrl_dbus_sig_handle_attach - %s", - MINICTRL_DBUS_SIG_RESIZE); - return MINICONTROL_ERROR_DBUS; - } - - request_sh = _minictrl_dbus_sig_handle_attach( - MINICTRL_DBUS_SIG_REQUEST, - _provider_request_cb, NULL); - if (!request_sh) { - ERR("fail to _minictrl_dbus_sig_handle_attach - %s", - MINICTRL_DBUS_SIG_REQUEST); - return MINICONTROL_ERROR_DBUS; - } - - monitor_h = calloc(1, sizeof(struct _minicontrol_monitor)); - if (!monitor_h) { - ERR("fail to alloc monitor_h"); - _minictrl_dbus_sig_handle_dettach(start_sh); - _minictrl_dbus_sig_handle_dettach(realize_sh); - _minictrl_dbus_sig_handle_dettach(stop_sh); - _minictrl_dbus_sig_handle_dettach(resize_sh); - _minictrl_dbus_sig_handle_dettach(request_sh); - return MINICONTROL_ERROR_OUT_OF_MEMORY; - } + if (g_monitor_h) { + ERR("Already started"); + return MINICONTROL_ERROR_UNKNOWN; + } - monitor_h->start_sh = start_sh; - monitor_h->realize_sh = realize_sh; - monitor_h->stop_sh = stop_sh; - monitor_h->resize_sh = resize_sh; - monitor_h->request_sh = request_sh; - monitor_h->callback = NULL; - monitor_h->callback_with_handler = NULL; - g_monitor_h = monitor_h; + g_monitor_h = malloc(sizeof(struct _minicontrol_monitor)); + if (g_monitor_h == NULL) { + ERR("fail to alloc monitor_h"); + return MINICONTROL_ERROR_OUT_OF_MEMORY; } - g_monitor_h->callback_with_handler = callback; + minicontrol_viewer_set_event_cb(_sig_to_viewer_handler_cb, data); + + g_monitor_h->callback = callback; g_monitor_h->user_data = data; - INFO("callback[%p], data[%p]", callback, data); return _minictrl_viewer_req_message_send(); } @@ -440,24 +126,10 @@ EXPORT_API minicontrol_error_e minicontrol_monitor_stop(void) if (!g_monitor_h) return MINICONTROL_ERROR_NONE; - if (g_monitor_h->start_sh) - _minictrl_dbus_sig_handle_dettach(g_monitor_h->start_sh); - - if (g_monitor_h->realize_sh) - _minictrl_dbus_sig_handle_dettach(g_monitor_h->realize_sh); - - if (g_monitor_h->stop_sh) - _minictrl_dbus_sig_handle_dettach(g_monitor_h->stop_sh); - - if (g_monitor_h->resize_sh) - _minictrl_dbus_sig_handle_dettach(g_monitor_h->resize_sh); - - if (g_monitor_h->request_sh) - _minictrl_dbus_sig_handle_dettach(g_monitor_h->request_sh); + minicontrol_viewer_unset_event_cb(); free(g_monitor_h); g_monitor_h = NULL; return MINICONTROL_ERROR_NONE; } -