2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.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.tizenopensource.org/license
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-log.h"
25 struct _minicontrol_monitor {
26 minictrl_sig_handle *start_sh;
27 minictrl_sig_handle *stop_sh;
28 minictrl_sig_handle *resize_sh;
29 minictrl_sig_handle *request_sh;
30 minicontrol_monitor_cb callback;
34 static struct _minicontrol_monitor *g_monitor_h;
36 static minicontrol_priority_e _int_to_priority(unsigned int value)
38 minicontrol_priority_e priority = MINICONTROL_PRIORITY_LOW;
40 case MINICONTROL_PRIORITY_TOP:
41 priority = MINICONTROL_PRIORITY_TOP;
43 case MINICONTROL_PRIORITY_MIDDLE:
44 priority = MINICONTROL_PRIORITY_MIDDLE;
46 case MINICONTROL_PRIORITY_LOW:
48 priority = MINICONTROL_PRIORITY_LOW;
54 static void _provider_start_cb(void *data, DBusMessage *msg)
57 char *svr_name = NULL;
61 minicontrol_priority_e priority;
64 dbus_error_init(&err);
66 dbus_ret = dbus_message_get_args(msg, &err,
67 DBUS_TYPE_STRING, &svr_name,
70 DBUS_TYPE_UINT32, &pri,
73 ERR("fail to get args : %s", err.message);
74 dbus_error_free(&err);
78 priority = _int_to_priority(pri);
80 if (g_monitor_h->callback)
81 g_monitor_h->callback(MINICONTROL_ACTION_START,
82 svr_name, w, h, priority,
83 g_monitor_h->user_data);
85 dbus_error_free(&err);
88 static void _provider_stop_cb(void *data, DBusMessage *msg)
91 char *svr_name = NULL;
94 dbus_error_init(&err);
96 dbus_ret = dbus_message_get_args(msg, &err,
97 DBUS_TYPE_STRING, &svr_name,
100 ERR("fail to get args : %s", err.message);
101 dbus_error_free(&err);
105 if (g_monitor_h->callback)
106 g_monitor_h->callback(MINICONTROL_ACTION_STOP,
107 svr_name, 0, 0, MINICONTROL_PRIORITY_LOW,
108 g_monitor_h->user_data);
110 dbus_error_free(&err);
113 static void _provider_resize_cb(void *data, DBusMessage *msg)
116 char *svr_name = NULL;
119 unsigned int pri = 0;
120 minicontrol_priority_e priority;
121 dbus_bool_t dbus_ret;
123 dbus_error_init(&err);
125 dbus_ret = dbus_message_get_args(msg, &err,
126 DBUS_TYPE_STRING, &svr_name,
127 DBUS_TYPE_UINT32, &w,
128 DBUS_TYPE_UINT32, &h,
129 DBUS_TYPE_UINT32, &pri,
132 ERR("fail to get args : %s", err.message);
133 dbus_error_free(&err);
137 priority = _int_to_priority(pri);
139 if (g_monitor_h->callback)
140 g_monitor_h->callback(MINICONTROL_ACTION_RESIZE,
141 svr_name, w, h, priority,
142 g_monitor_h->user_data);
144 dbus_error_free(&err);
147 static void _provider_request_cb(void *data, DBusMessage *msg)
150 char *svr_name = NULL;
153 unsigned int pri = 0;
154 minicontrol_priority_e priority;
155 dbus_bool_t dbus_ret;
157 dbus_error_init(&err);
159 dbus_ret = dbus_message_get_args(msg, &err,
160 DBUS_TYPE_STRING, &svr_name,
161 DBUS_TYPE_UINT32, &w,
162 DBUS_TYPE_UINT32, &h,
163 DBUS_TYPE_UINT32, &pri,
166 ERR("fail to get args : %s", err.message);
167 dbus_error_free(&err);
171 priority = _int_to_priority(pri);
173 if (g_monitor_h->callback)
174 g_monitor_h->callback(MINICONTROL_ACTION_REQUEST,
175 svr_name, w, h, priority,
176 g_monitor_h->user_data);
178 dbus_error_free(&err);
181 EXPORT_API minicontrol_error_e minicontrol_monitor_start(
182 minicontrol_monitor_cb callback, void *data)
185 return MINICONTROL_ERROR_INVALID_PARAMETER;
188 minictrl_sig_handle *start_sh;
189 minictrl_sig_handle *stop_sh;
190 minictrl_sig_handle *resize_sh;
191 minictrl_sig_handle *request_sh;
192 struct _minicontrol_monitor *monitor_h;
194 start_sh = _minictrl_dbus_sig_handle_attach(
195 MINICTRL_DBUS_SIG_START,
196 _provider_start_cb, NULL);
198 ERR("fail to _minictrl_dbus_sig_handle_attach - %s",
199 MINICTRL_DBUS_SIG_START);
200 return MINICONTROL_ERROR_DBUS;
203 stop_sh = _minictrl_dbus_sig_handle_attach(
204 MINICTRL_DBUS_SIG_STOP,
205 _provider_stop_cb, NULL);
207 ERR("fail to _minictrl_dbus_sig_handle_attach - %s",
208 MINICTRL_DBUS_SIG_STOP);
209 return MINICONTROL_ERROR_DBUS;
212 resize_sh = _minictrl_dbus_sig_handle_attach(
213 MINICTRL_DBUS_SIG_RESIZE,
214 _provider_resize_cb, NULL);
216 ERR("fail to _minictrl_dbus_sig_handle_attach - %s",
217 MINICTRL_DBUS_SIG_RESIZE);
218 return MINICONTROL_ERROR_DBUS;
221 request_sh = _minictrl_dbus_sig_handle_attach(
222 MINICTRL_DBUS_SIG_REQUEST,
223 _provider_request_cb, NULL);
225 ERR("fail to _minictrl_dbus_sig_handle_attach - %s",
226 MINICTRL_DBUS_SIG_REQUEST);
227 return MINICONTROL_ERROR_DBUS;
230 monitor_h = malloc(sizeof(struct _minicontrol_monitor));
232 ERR("fail to alloc monitor_h");
233 _minictrl_dbus_sig_handle_dettach(start_sh);
234 _minictrl_dbus_sig_handle_dettach(stop_sh);
235 _minictrl_dbus_sig_handle_dettach(resize_sh);
236 _minictrl_dbus_sig_handle_dettach(request_sh);
237 return MINICONTROL_ERROR_OUT_OF_MEMORY;
240 monitor_h->start_sh = start_sh;
241 monitor_h->stop_sh = stop_sh;
242 monitor_h->resize_sh = resize_sh;
243 monitor_h->request_sh = request_sh;
244 g_monitor_h = monitor_h;
247 g_monitor_h->callback = callback;
248 g_monitor_h->user_data = data;
249 INFO("callback[%p], data[%p]", callback, data);
251 return _minictrl_viewer_req_message_send();
254 EXPORT_API minicontrol_error_e minicontrol_monitor_stop(void)
257 return MINICONTROL_ERROR_NONE;
259 if (g_monitor_h->start_sh)
260 _minictrl_dbus_sig_handle_dettach(g_monitor_h->start_sh);
262 if (g_monitor_h->stop_sh)
263 _minictrl_dbus_sig_handle_dettach(g_monitor_h->stop_sh);
265 if (g_monitor_h->resize_sh)
266 _minictrl_dbus_sig_handle_dettach(g_monitor_h->resize_sh);
268 if (g_monitor_h->request_sh)
269 _minictrl_dbus_sig_handle_dettach(g_monitor_h->request_sh);
274 return MINICONTROL_ERROR_NONE;