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 minicontrol_monitor_cb callback;
33 static struct _minicontrol_monitor *g_monitor_h;
35 static minicontrol_priority_e _int_to_priority(unsigned int value)
37 minicontrol_priority_e priority = MINICONTROL_PRIORITY_LOW;
39 case MINICONTROL_PRIORITY_TOP:
40 priority = MINICONTROL_PRIORITY_TOP;
42 case MINICONTROL_PRIORITY_MIDDLE:
43 priority = MINICONTROL_PRIORITY_MIDDLE;
45 case MINICONTROL_PRIORITY_LOW:
47 priority = MINICONTROL_PRIORITY_LOW;
53 static void _provider_start_cb(void *data, DBusMessage *msg)
56 char *svr_name = NULL;
60 minicontrol_priority_e priority;
63 dbus_error_init(&err);
65 dbus_ret = dbus_message_get_args(msg, &err,
66 DBUS_TYPE_STRING, &svr_name,
69 DBUS_TYPE_UINT32, &pri,
72 ERR("fail to get args : %s", err.message);
73 dbus_error_free(&err);
77 priority = _int_to_priority(pri);
79 if (g_monitor_h->callback)
80 g_monitor_h->callback(MINICONTROL_ACTION_START,
81 svr_name, w, h, priority,
82 g_monitor_h->user_data);
84 dbus_error_free(&err);
87 static void _provider_stop_cb(void *data, DBusMessage *msg)
90 char *svr_name = NULL;
93 dbus_error_init(&err);
95 dbus_ret = dbus_message_get_args(msg, &err,
96 DBUS_TYPE_STRING, &svr_name,
99 ERR("fail to get args : %s", err.message);
100 dbus_error_free(&err);
104 if (g_monitor_h->callback)
105 g_monitor_h->callback(MINICONTROL_ACTION_STOP,
106 svr_name, 0, 0, MINICONTROL_PRIORITY_LOW,
107 g_monitor_h->user_data);
109 dbus_error_free(&err);
112 static void _provider_resize_cb(void *data, DBusMessage *msg)
115 char *svr_name = NULL;
118 unsigned int pri = 0;
119 minicontrol_priority_e priority;
120 dbus_bool_t dbus_ret;
122 dbus_error_init(&err);
124 dbus_ret = dbus_message_get_args(msg, &err,
125 DBUS_TYPE_STRING, &svr_name,
126 DBUS_TYPE_UINT32, &w,
127 DBUS_TYPE_UINT32, &h,
128 DBUS_TYPE_UINT32, &pri,
131 ERR("fail to get args : %s", err.message);
132 dbus_error_free(&err);
136 priority = _int_to_priority(pri);
138 if (g_monitor_h->callback)
139 g_monitor_h->callback(MINICONTROL_ACTION_RESIZE,
140 svr_name, w, h, priority,
141 g_monitor_h->user_data);
143 dbus_error_free(&err);
147 EXPORT_API minicontrol_error_e minicontrol_monitor_start(
148 minicontrol_monitor_cb callback, void *data)
151 return MINICONTROL_ERROR_INVALID_PARAMETER;
154 minictrl_sig_handle *start_sh;
155 minictrl_sig_handle *stop_sh;
156 minictrl_sig_handle *resize_sh;
157 struct _minicontrol_monitor *monitor_h;
159 start_sh = _minictrl_dbus_sig_handle_attach(
160 MINICTRL_DBUS_SIG_START,
161 _provider_start_cb, NULL);
163 ERR("fail to _minictrl_dbus_sig_handle_attach - %s",
164 MINICTRL_DBUS_SIG_START);
165 return MINICONTROL_ERROR_DBUS;
168 stop_sh = _minictrl_dbus_sig_handle_attach(
169 MINICTRL_DBUS_SIG_STOP,
170 _provider_stop_cb, NULL);
172 ERR("fail to _minictrl_dbus_sig_handle_attach - %s",
173 MINICTRL_DBUS_SIG_STOP);
174 return MINICONTROL_ERROR_DBUS;
177 resize_sh = _minictrl_dbus_sig_handle_attach(
178 MINICTRL_DBUS_SIG_RESIZE,
179 _provider_resize_cb, NULL);
181 ERR("fail to _minictrl_dbus_sig_handle_attach - %s",
182 MINICTRL_DBUS_SIG_RESIZE);
183 return MINICONTROL_ERROR_DBUS;
186 monitor_h = malloc(sizeof(struct _minicontrol_monitor));
188 ERR("fail to alloc monitor_h");
189 _minictrl_dbus_sig_handle_dettach(start_sh);
190 _minictrl_dbus_sig_handle_dettach(stop_sh);
191 _minictrl_dbus_sig_handle_dettach(resize_sh);
192 return MINICONTROL_ERROR_OUT_OF_MEMORY;
195 monitor_h->start_sh = start_sh;
196 monitor_h->stop_sh = stop_sh;
197 monitor_h->resize_sh = resize_sh;
198 g_monitor_h = monitor_h;
201 g_monitor_h->callback = callback;
202 g_monitor_h->user_data = data;
203 INFO("callback[%p], data[%p]", callback, data);
205 return _minictrl_viewer_req_message_send();
208 EXPORT_API minicontrol_error_e minicontrol_monitor_stop(void)
211 return MINICONTROL_ERROR_NONE;
213 if (g_monitor_h->start_sh)
214 _minictrl_dbus_sig_handle_dettach(g_monitor_h->start_sh);
216 if (g_monitor_h->stop_sh)
217 _minictrl_dbus_sig_handle_dettach(g_monitor_h->stop_sh);
219 if (g_monitor_h->resize_sh)
220 _minictrl_dbus_sig_handle_dettach(g_monitor_h->resize_sh);
225 return MINICONTROL_ERROR_NONE;