4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Venkatesha Sarpangala <sarpangala.v@samsung.com>, Jayoun Lee <airjany@samsung.com>,
7 * Sewook Park <sewook7.park@samsung.com>, Jaeho Lee <jaeho81.lee@samsung.com>
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
34 #include "alarm-internal.h"
35 #include "alarm-stub.h"
36 #include "security-server.h"
38 #define ALARM_SERVICE_NAME "appframework.alarm"
39 #define ALARM_OBJECT_PATH "/appframework/alarm"
40 #define ALARM_INTERFACE_NAME "appframework.alarm"
44 bool _send_alarm_create(alarm_context_t context, alarm_info_t *alarm_info,
45 alarm_id_t *alarm_id, const char *dst_service_name, const char *dst_service_name_mod,
47 bool _send_alarm_create_appsvc(alarm_context_t context, alarm_info_t *alarm_info,
48 alarm_id_t *alarm_id, bundle *b,int *error_code);
49 bool _send_alarm_delete(alarm_context_t context, alarm_id_t alarm_id,
52 bool _send_alarm_power_on(alarm_context_t context, bool on_off,
54 bool _send_alarm_power_off(alarm_context_t context, int *error_code);
55 bool _send_alarm_check_next_duetime(alarm_context_t context, int *error_code);
57 bool _send_alarm_get_list_of_ids(alarm_context_t context, int maxnum_of_ids,
58 alarm_id_t *alarm_id, int *num_of_ids,
60 bool _send_alarm_get_number_of_ids(alarm_context_t context, int *num_of_ids,
62 bool _send_alarm_get_info(alarm_context_t context, alarm_id_t alarm_id,
63 alarm_info_t *alarm_info, int *error_code);
67 bool _send_alarm_create_appsvc(alarm_context_t context, alarm_info_t *alarm_info,
68 alarm_id_t *alarm_id, bundle *b,
74 char cookie[256] = {0,};
75 char *e_cookie = NULL;
79 bundle_raw *b_data = NULL;
82 size = security_server_get_cookie_size();
83 retval = security_server_request_cookie(cookie, size);
86 ALARM_MGR_EXCEPTION_PRINT(
87 "security_server_request_cookie failed\n");
89 *error_code = -1; /* TODO: Need to redefine error codes */
93 e_cookie = g_base64_encode((const guchar *)cookie, size);
97 ALARM_MGR_EXCEPTION_PRINT(
98 "g_base64_encode failed\n");
100 *error_code = -1; /* TODO: Need to redefine error codes */
104 if (bundle_encode(b, &b_data, &datalen))
106 ALARM_MGR_EXCEPTION_PRINT("Unable to encode the bundle data\n");
108 *error_code = -1; /* TODO: Need to redefine error codes*/
118 if (!org_tizen_alarm_manager_alarm_create_appsvc(context.proxy, context.pid,
119 alarm_info->start.year,
120 alarm_info->start.month,
121 alarm_info->start.day,
122 alarm_info->start.hour,
123 alarm_info->start.min,
124 alarm_info->start.sec,
125 alarm_info->end.year,
126 alarm_info->end.month,
128 alarm_info->mode.u_interval.day_of_week,
129 alarm_info->mode.repeat,
130 alarm_info->alarm_type,
131 alarm_info->reserved_info,
132 (char *)b_data, e_cookie,
133 alarm_id, &return_code,
135 /* dbus-glib error */
136 /* error_code should be set */
137 ALARM_MGR_EXCEPTION_PRINT(
138 "org_tizen_alarm_manager_alarm_create()failed.alarm_id[%d], "
139 "return_code[%d]\n", alarm_id, return_code);
140 ALARM_MGR_EXCEPTION_PRINT("error->message is %s\n",
156 if (return_code != 0) {
158 *error_code = return_code;
168 bool _send_alarm_create(alarm_context_t context, alarm_info_t *alarm_info,
169 alarm_id_t *alarm_id, const char *dst_service_name, const char *dst_service_name_mod,
172 GError *error = NULL;
180 size = security_server_get_cookie_size();
181 retval = security_server_request_cookie(cookie, size);
184 ALARM_MGR_EXCEPTION_PRINT(
185 "security_server_request_cookie failed\n");
189 e_cookie = g_base64_encode((const guchar *)cookie, size);
191 if (!org_tizen_alarm_manager_alarm_create(context.proxy, context.pid,
192 g_quark_to_string(context.quark_app_service_name),
193 g_quark_to_string(context.quark_app_service_name_mod),
194 alarm_info->start.year,
195 alarm_info->start.month,
196 alarm_info->start.day,
197 alarm_info->start.hour,
198 alarm_info->start.min,
199 alarm_info->start.sec,
200 alarm_info->end.year,
201 alarm_info->end.month,
203 alarm_info->mode.u_interval.day_of_week,
204 alarm_info->mode.repeat,
205 alarm_info->alarm_type,
206 alarm_info->reserved_info,
207 dst_service_name, dst_service_name_mod, e_cookie,
208 alarm_id, &return_code,
210 /* dbus-glib error */
211 /* error_code should be set */
212 ALARM_MGR_EXCEPTION_PRINT(
213 "org_tizen_alarm_manager_alarm_create()failed.alarm_id[%d], "
214 "return_code[%d]\n", alarm_id, return_code);
215 ALARM_MGR_EXCEPTION_PRINT("error->message is %s\n",
218 *error_code = -1; /* -1 means that system
219 failed internally. */
225 if (return_code != 0) {
227 *error_code = return_code;
234 bool _send_alarm_delete(alarm_context_t context, alarm_id_t alarm_id,
237 GError *error = NULL;
245 size = security_server_get_cookie_size();
246 retval = security_server_request_cookie(cookie, size);
249 ALARM_MGR_EXCEPTION_PRINT(
250 "security_server_request_cookie failed\n");
254 e_cookie = g_base64_encode((const guchar *)cookie, size);
256 if (!org_tizen_alarm_manager_alarm_delete
257 (context.proxy, context.pid, alarm_id, e_cookie, &return_code,
259 /* dbus-glib error */
260 /*error_code should be set */
261 ALARM_MGR_EXCEPTION_PRINT(
262 "org_tizen_alarm_manager_alarm_delete() failed. "
263 "alarm_id[%d], return_code[%d]\n", alarm_id, return_code);
265 *error_code = -1; /*-1 means that system
273 if (return_code != 0) {
275 *error_code = return_code;
284 bool _send_alarm_power_on(alarm_context_t context, bool on_off,
287 GError *error = NULL;
290 if (!org_tizen_alarm_manager_alarm_power_on
291 (context.proxy, context.pid, on_off, &return_code, &error)) {
292 /* dbus-glib error */
293 /* error_code should be set */
294 ALARM_MGR_EXCEPTION_PRINT(
295 "org_tizen_alarm_manager_alarm_power_on failed. "
296 "return_code[%d]\n", return_code);
298 *error_code = -1; /*-1 means that system
303 if (return_code != 0) {
305 *error_code = return_code;
313 bool _send_alarm_power_off(alarm_context_t context, int *error_code)
315 GError *error = NULL;
318 if (!org_tizen_alarm_manager_alarm_power_off(context.proxy,
319 context.pid, &return_code, &error)) {
320 /* dbus-glib error */
321 /* error_code should be set */
322 ALARM_MGR_EXCEPTION_PRINT(
323 "org_tizen_alarm_manager_alarm_power_off failed. "
324 "return_code[%d]\n", return_code);
326 *error_code = -1; /*-1 means that system
331 if (return_code != 0) {
333 *error_code = return_code;
341 bool _send_alarm_check_next_duetime(alarm_context_t context, int *error_code)
343 GError *error = NULL;
346 if (!org_tizen_alarm_manager_alarm_check_next_duetime(context.proxy,
347 context.pid, &return_code, &error)) {
349 /*error_code should be set */
350 ALARM_MGR_EXCEPTION_PRINT(
351 "org_tizen_alarm_manager_alarm_power_check_next_duetime's "
352 "return value is false. return_code[%d]\n", return_code);
354 *error_code = -1; /*-1 means that system
359 if (return_code != 0) {
361 *error_code = return_code;
369 #endif /* __ALARM_BOOT */
371 bool _send_alarm_get_list_of_ids(alarm_context_t context, int maxnum_of_ids,
372 alarm_id_t *alarm_id, int *num_of_ids,
376 GError *error = NULL;
377 GArray *alarm_array = NULL;
381 if (!org_tizen_alarm_manager_alarm_get_list_of_ids(context.proxy,
382 context.pid, maxnum_of_ids, &alarm_array,
383 num_of_ids, &return_code, &error)) {
385 /*error_code should be set */
386 ALARM_MGR_EXCEPTION_PRINT(
387 "org_tizen_alarm_manager_alarm_get_list_of_ids() failed. "
388 "alarm_id[%d], return_code[%d]\n", alarm_id, return_code);
390 *error_code = -1; /*-1 means that system
396 if (return_code != 0) {
398 *error_code = return_code;
401 for (i = 0; i < alarm_array->len && i < maxnum_of_ids; i++) {
402 alarm_id[i] = g_array_index(alarm_array, alarm_id_t, i);
403 ALARM_MGR_LOG_PRINT(" alarm_id(%d)\n", alarm_id[i]);
406 *num_of_ids = alarm_array->len;
407 g_array_free(alarm_array, true);
413 bool _send_alarm_get_number_of_ids(alarm_context_t context, int *num_of_ids,
416 GError *error = NULL;
417 gint return_code = 0;
419 if (!org_tizen_alarm_manager_alarm_get_number_of_ids(context.proxy,
420 context.pid, num_of_ids, &return_code, &error)) {
421 /* dbus-glib error */
422 /* error_code should be set */
423 ALARM_MGR_EXCEPTION_PRINT(
424 "org_tizen_alarm_manager_alarm_get_number_of_ids() failed. "
425 "return_code[%d], return_code[%s]\n", \
426 return_code, error->message);
428 *error_code = -1; /*-1 means that system
433 if (return_code != 0) {
435 *error_code = return_code;
443 bool _send_alarm_get_info(alarm_context_t context, alarm_id_t alarm_id,
444 alarm_info_t *alarm_info, int *error_code)
446 GError *error = NULL;
449 if (!org_tizen_alarm_manager_alarm_get_info(context.proxy,
450 context.pid, alarm_id, &alarm_info->start.year,
451 &alarm_info->start.month, &alarm_info->start.day,
452 &alarm_info->start.hour, &alarm_info->start.min,
453 &alarm_info->start.sec, &alarm_info->end.year,
454 &alarm_info->end.month, &alarm_info->end.day,
455 &alarm_info->mode.u_interval.day_of_week,
456 (gint *)&alarm_info->mode.repeat,
457 &alarm_info->alarm_type, &alarm_info->reserved_info,
458 &return_code, &error)) {
460 /* error_code should be set */
461 ALARM_MGR_EXCEPTION_PRINT(
462 "org_tizen_alarm_manager_alarm_get_info() failed. "
463 "alarm_id[%d], return_code[%d]\n", alarm_id, return_code);
465 *error_code = -1; /*-1 means that system failed
470 if (return_code != 0) {
472 *error_code = return_code;