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"
43 bool _send_alarm_create(alarm_context_t context, alarm_info_t *alarm_info,
44 alarm_id_t *alarm_id, const char *dst_service_name, const char *dst_service_name_mod,
46 bool _send_alarm_create_appsvc(alarm_context_t context, alarm_info_t *alarm_info,
47 alarm_id_t *alarm_id, bundle *b,int *error_code);
48 bool _send_alarm_delete(alarm_context_t context, alarm_id_t alarm_id,
51 bool _send_alarm_power_on(alarm_context_t context, bool on_off,
53 bool _send_alarm_power_off(alarm_context_t context, int *error_code);
54 bool _send_alarm_check_next_duetime(alarm_context_t context, int *error_code);
56 bool _send_alarm_get_list_of_ids(alarm_context_t context, int maxnum_of_ids,
57 alarm_id_t *alarm_id, int *num_of_ids,
59 bool _send_alarm_get_number_of_ids(alarm_context_t context, int *num_of_ids,
61 bool _send_alarm_get_info(alarm_context_t context, alarm_id_t alarm_id,
62 alarm_info_t *alarm_info, int *error_code);
66 bool _send_alarm_create_appsvc(alarm_context_t context, alarm_info_t *alarm_info,
67 alarm_id_t *alarm_id, bundle *b,
73 char cookie[256] = {0,};
74 char *e_cookie = NULL;
78 bundle_raw *b_data = NULL;
81 size = security_server_get_cookie_size();
82 retval = security_server_request_cookie(cookie, size);
85 ALARM_MGR_EXCEPTION_PRINT(
86 "security_server_request_cookie failed\n");
88 *error_code = -1; /* TODO: Need to redefine error codes */
92 e_cookie = g_base64_encode((const guchar *)cookie, size);
96 ALARM_MGR_EXCEPTION_PRINT(
97 "g_base64_encode failed\n");
99 *error_code = -1; /* TODO: Need to redefine error codes */
103 if (bundle_encode(b, &b_data, &datalen))
105 ALARM_MGR_EXCEPTION_PRINT("Unable to encode the bundle data\n");
107 *error_code = -1; /* TODO: Need to redefine error codes*/
117 if (!org_tizen_alarm_manager_alarm_create_appsvc(context.proxy, context.pid,
118 alarm_info->start.year,
119 alarm_info->start.month,
120 alarm_info->start.day,
121 alarm_info->start.hour,
122 alarm_info->start.min,
123 alarm_info->start.sec,
124 alarm_info->end.year,
125 alarm_info->end.month,
127 alarm_info->mode.u_interval.day_of_week,
128 alarm_info->mode.repeat,
129 alarm_info->alarm_type,
130 alarm_info->reserved_info,
131 (char *)b_data, e_cookie,
132 alarm_id, &return_code,
134 /* dbus-glib error */
135 /* error_code should be set */
136 ALARM_MGR_EXCEPTION_PRINT(
137 "org_tizen_alarm_manager_alarm_create()failed.alarm_id[%d], "
138 "return_code[%d]\n", alarm_id, return_code);
139 ALARM_MGR_EXCEPTION_PRINT("error->message is %s\n",
155 if (return_code != 0) {
157 *error_code = return_code;
166 bool _send_alarm_create(alarm_context_t context, alarm_info_t *alarm_info,
167 alarm_id_t *alarm_id, const char *dst_service_name, const char *dst_service_name_mod,
170 GError *error = NULL;
178 /*TODO: Dbus bus name validation is must & will be added to avoid alarm-server crash*/
179 if (g_quark_to_string(context.quark_app_service_name) == NULL
180 && strlen(dst_service_name) == 4
181 && strncmp(dst_service_name, "null",4) == 0 ){
182 ALARM_MGR_EXCEPTION_PRINT("Invalid arg. Provide valid destination or call alarmmgr_init()\n");
184 *error_code = ERR_ALARM_INVALID_PARAM;
188 size = security_server_get_cookie_size();
189 retval = security_server_request_cookie(cookie, size);
192 ALARM_MGR_EXCEPTION_PRINT(
193 "security_server_request_cookie failed\n");
197 e_cookie = g_base64_encode((const guchar *)cookie, size);
199 if (!org_tizen_alarm_manager_alarm_create(context.proxy, context.pid,
200 g_quark_to_string(context.quark_app_service_name),
201 g_quark_to_string(context.quark_app_service_name_mod),
202 alarm_info->start.year,
203 alarm_info->start.month,
204 alarm_info->start.day,
205 alarm_info->start.hour,
206 alarm_info->start.min,
207 alarm_info->start.sec,
208 alarm_info->end.year,
209 alarm_info->end.month,
211 alarm_info->mode.u_interval.day_of_week,
212 alarm_info->mode.repeat,
213 alarm_info->alarm_type,
214 alarm_info->reserved_info,
215 dst_service_name, dst_service_name_mod, e_cookie,
216 alarm_id, &return_code,
218 /* dbus-glib error */
219 /* error_code should be set */
220 ALARM_MGR_EXCEPTION_PRINT(
221 "org_tizen_alarm_manager_alarm_create()failed.alarm_id[%d], "
222 "return_code[%d]\n", alarm_id, return_code);
223 ALARM_MGR_EXCEPTION_PRINT("error->message is %s\n",
226 *error_code = -1; /* -1 means that system
227 failed internally. */
233 if (return_code != 0) {
235 *error_code = return_code;
241 bundle *_send_alarm_get_appsvc_info(alarm_context_t context, alarm_id_t alarm_id, int *error_code)
243 GError *error = NULL;
248 char cookie[256] = {0,};
249 char *e_cookie = NULL;
253 gchar *b_data = NULL;
256 size = security_server_get_cookie_size();
257 retval = security_server_request_cookie(cookie, size);
260 ALARM_MGR_EXCEPTION_PRINT(
261 "security_server_request_cookie failed\n");
263 *error_code = -1; /*TODO: define error*/
267 e_cookie = g_base64_encode((const guchar *)cookie, size);
269 if (NULL == e_cookie)
271 ALARM_MGR_EXCEPTION_PRINT(
272 "g_base64_encode failed\n");
274 *error_code = -1; /*TODO: define error*/
279 if (!org_tizen_alarm_manager_alarm_get_appsvc_info
280 (context.proxy, context.pid, alarm_id, e_cookie, &b_data, &return_code, &error)) {
281 /* dbus-glib error */
282 /*error_code should be set */
283 ALARM_MGR_EXCEPTION_PRINT(
284 "org_tizen_alarm_manager_alarm_delete() failed. "
285 "alarm_id[%d], return_code[%d]\n", alarm_id, return_code);
287 *error_code = ERR_ALARM_SYSTEM_FAIL; /*-1 means that system
297 if (return_code != 0){
299 *error_code = return_code;
301 b = bundle_decode((bundle_raw *)b_data, len);
312 bool _send_alarm_delete(alarm_context_t context, alarm_id_t alarm_id,
315 GError *error = NULL;
323 size = security_server_get_cookie_size();
324 retval = security_server_request_cookie(cookie, size);
327 ALARM_MGR_EXCEPTION_PRINT(
328 "security_server_request_cookie failed\n");
332 e_cookie = g_base64_encode((const guchar *)cookie, size);
334 if (!org_tizen_alarm_manager_alarm_delete
335 (context.proxy, context.pid, alarm_id, e_cookie, &return_code,
337 /* dbus-glib error */
338 /*error_code should be set */
339 ALARM_MGR_EXCEPTION_PRINT(
340 "org_tizen_alarm_manager_alarm_delete() failed. "
341 "alarm_id[%d], return_code[%d]\n", alarm_id, return_code);
343 *error_code = -1; /*-1 means that system
351 if (return_code != 0) {
353 *error_code = return_code;
362 bool _send_alarm_power_on(alarm_context_t context, bool on_off,
365 GError *error = NULL;
368 if (!org_tizen_alarm_manager_alarm_power_on
369 (context.proxy, context.pid, on_off, &return_code, &error)) {
370 /* dbus-glib error */
371 /* error_code should be set */
372 ALARM_MGR_EXCEPTION_PRINT(
373 "org_tizen_alarm_manager_alarm_power_on failed. "
374 "return_code[%d]\n", return_code);
376 *error_code = -1; /*-1 means that system
381 if (return_code != 0) {
383 *error_code = return_code;
391 bool _send_alarm_power_off(alarm_context_t context, int *error_code)
393 GError *error = NULL;
396 if (!org_tizen_alarm_manager_alarm_power_off(context.proxy,
397 context.pid, &return_code, &error)) {
398 /* dbus-glib error */
399 /* error_code should be set */
400 ALARM_MGR_EXCEPTION_PRINT(
401 "org_tizen_alarm_manager_alarm_power_off failed. "
402 "return_code[%d]\n", return_code);
404 *error_code = -1; /*-1 means that system
409 if (return_code != 0) {
411 *error_code = return_code;
419 bool _send_alarm_check_next_duetime(alarm_context_t context, int *error_code)
421 GError *error = NULL;
424 if (!org_tizen_alarm_manager_alarm_check_next_duetime(context.proxy,
425 context.pid, &return_code, &error)) {
427 /*error_code should be set */
428 ALARM_MGR_EXCEPTION_PRINT(
429 "org_tizen_alarm_manager_alarm_power_check_next_duetime's "
430 "return value is false. return_code[%d]\n", return_code);
432 *error_code = -1; /*-1 means that system
437 if (return_code != 0) {
439 *error_code = return_code;
447 #endif /* __ALARM_BOOT */
449 bool _send_alarm_get_list_of_ids(alarm_context_t context, int maxnum_of_ids,
450 alarm_id_t *alarm_id, int *num_of_ids,
454 GError *error = NULL;
455 GArray *alarm_array = NULL;
459 if (!org_tizen_alarm_manager_alarm_get_list_of_ids(context.proxy,
460 context.pid, maxnum_of_ids, &alarm_array,
461 num_of_ids, &return_code, &error)) {
463 /*error_code should be set */
464 ALARM_MGR_EXCEPTION_PRINT(
465 "org_tizen_alarm_manager_alarm_get_list_of_ids() failed. "
466 "alarm_id[%d], return_code[%d]\n", alarm_id, return_code);
468 *error_code = -1; /*-1 means that system
474 if (return_code != 0) {
476 *error_code = return_code;
479 for (i = 0; i < alarm_array->len && i < maxnum_of_ids; i++) {
480 alarm_id[i] = g_array_index(alarm_array, alarm_id_t, i);
481 ALARM_MGR_LOG_PRINT(" alarm_id(%d)\n", alarm_id[i]);
484 *num_of_ids = alarm_array->len;
485 g_array_free(alarm_array, true);
491 bool _send_alarm_get_number_of_ids(alarm_context_t context, int *num_of_ids,
494 GError *error = NULL;
495 gint return_code = 0;
497 if (!org_tizen_alarm_manager_alarm_get_number_of_ids(context.proxy,
498 context.pid, num_of_ids, &return_code, &error)) {
499 /* dbus-glib error */
500 /* error_code should be set */
501 ALARM_MGR_EXCEPTION_PRINT(
502 "org_tizen_alarm_manager_alarm_get_number_of_ids() failed. "
503 "return_code[%d], return_code[%s]\n", \
504 return_code, error->message);
506 *error_code = -1; /*-1 means that system
511 if (return_code != 0) {
513 *error_code = return_code;
521 bool _send_alarm_get_info(alarm_context_t context, alarm_id_t alarm_id,
522 alarm_info_t *alarm_info, int *error_code)
524 GError *error = NULL;
527 if (!org_tizen_alarm_manager_alarm_get_info(context.proxy,
528 context.pid, alarm_id, &alarm_info->start.year,
529 &alarm_info->start.month, &alarm_info->start.day,
530 &alarm_info->start.hour, &alarm_info->start.min,
531 &alarm_info->start.sec, &alarm_info->end.year,
532 &alarm_info->end.month, &alarm_info->end.day,
533 &alarm_info->mode.u_interval.day_of_week,
534 (gint *)&alarm_info->mode.repeat,
535 &alarm_info->alarm_type, &alarm_info->reserved_info,
536 &return_code, &error)) {
538 /* error_code should be set */
539 ALARM_MGR_EXCEPTION_PRINT(
540 "org_tizen_alarm_manager_alarm_get_info() failed. "
541 "alarm_id[%d], return_code[%d]\n", alarm_id, return_code);
543 *error_code = -1; /*-1 means that system failed
548 if (return_code != 0) {
550 *error_code = return_code;