2 * Copyright (c) 2013-2015 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <dbus/dbus.h>
20 #include "minicontrol-error.h"
21 #include "minicontrol-internal.h"
22 #include "minicontrol-monitor.h"
23 #include "minicontrol-viewer.h"
24 #include "minicontrol-log.h"
26 struct _minicontrol_monitor {
27 minictrl_sig_handle *event_sh;
28 minicontrol_monitor_cb callback;
32 static struct _minicontrol_monitor *g_monitor_h = NULL;
34 static minicontrol_priority_e _int_to_priority(unsigned int value)
36 minicontrol_priority_e priority = MINICONTROL_PRIORITY_LOW;
38 case MINICONTROL_PRIORITY_TOP:
39 priority = MINICONTROL_PRIORITY_TOP;
41 case MINICONTROL_PRIORITY_MIDDLE:
42 priority = MINICONTROL_PRIORITY_MIDDLE;
44 case MINICONTROL_PRIORITY_LOW:
46 priority = MINICONTROL_PRIORITY_LOW;
52 static void _sig_to_viewer_handler_cb(minicontrol_event_e event, const char *minicontrol_name, bundle *event_arg, void *data)
54 minicontrol_action_e action;
57 int priority_from_signal = 0;
58 minicontrol_priority_e priority = 0;
62 case MINICONTROL_EVENT_START:
63 action = MINICONTROL_ACTION_START;
66 case MINICONTROL_EVENT_STOP:
67 action = MINICONTROL_ACTION_STOP;
70 case MINICONTROL_EVENT_RESIZE:
71 action = MINICONTROL_ACTION_RESIZE;
74 case MINICONTROL_EVENT_REQUEST_HIDE:
75 case MINICONTROL_EVENT_REQUEST_ANGLE:
76 action = MINICONTROL_ACTION_REQUEST;
80 WARN("Not supported event [%d]", event);
85 if (action == MINICONTROL_ACTION_START || action == MINICONTROL_ACTION_RESIZE || action == MINICONTROL_ACTION_REQUEST) {
86 bundle_get_byte(event_arg, "width", (void*)&width, &n_size);
87 bundle_get_byte(event_arg, "height", (void*)&height, &n_size);
88 bundle_get_byte(event_arg, "priority", (void*)&priority_from_signal, &n_size);
89 priority = _int_to_priority(priority_from_signal);
92 priority = MINICONTROL_PRIORITY_LOW;
95 g_monitor_h->callback(action, minicontrol_name, width, height, priority, g_monitor_h->user_data);
98 EXPORT_API minicontrol_error_e minicontrol_monitor_start(minicontrol_monitor_cb callback, void *data)
101 return MINICONTROL_ERROR_INVALID_PARAMETER;
103 INFO("callback[%p], data[%p]", callback, data);
106 ERR("Already started");
107 return MINICONTROL_ERROR_UNKNOWN;
110 g_monitor_h = malloc(sizeof(struct _minicontrol_monitor));
111 if (g_monitor_h == NULL) {
112 ERR("fail to alloc monitor_h");
113 return MINICONTROL_ERROR_OUT_OF_MEMORY;
116 minicontrol_viewer_set_event_cb(_sig_to_viewer_handler_cb, data);
118 g_monitor_h->callback = callback;
119 g_monitor_h->user_data = data;
121 return _minictrl_viewer_req_message_send();
124 EXPORT_API minicontrol_error_e minicontrol_monitor_stop(void)
127 return MINICONTROL_ERROR_NONE;
129 minicontrol_viewer_unset_event_cb();
134 return MINICONTROL_ERROR_NONE;