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);
313 bool _send_alarm_set_rtc_time(alarm_context_t context, alarm_date_t *time, int *error_code){
315 GError *error = NULL;
318 char cookie[256] = {0,};
319 char *e_cookie = 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");
330 *error_code = -1; /*TODO: define error*/
334 e_cookie = g_base64_encode((const guchar *)cookie, size);
336 if (NULL == e_cookie)
338 ALARM_MGR_EXCEPTION_PRINT(
339 "g_base64_encode failed\n");
341 *error_code = -1; /*TODO: define error*/
345 if (!org_tizen_alarm_manager_alarm_set_rtc_time
346 (context.proxy, context.pid,
347 time->year, time->month, time->day,
348 time->hour, time->min, time->sec,
349 e_cookie, &return_code, &error)) {
350 /* dbus-glib error */
351 /*error_code should be set */
352 ALARM_MGR_EXCEPTION_PRINT(
353 "org_tizen_alarm_manager_alarm_set_rtc_time() failed. "
354 "return_code[%d]\n", return_code);
356 *error_code = ERR_ALARM_SYSTEM_FAIL; /*-1 means that system
369 if (return_code != 0) {
371 *error_code = return_code;
379 bool _send_alarm_delete(alarm_context_t context, alarm_id_t alarm_id,
382 GError *error = NULL;
390 size = security_server_get_cookie_size();
391 retval = security_server_request_cookie(cookie, size);
394 ALARM_MGR_EXCEPTION_PRINT(
395 "security_server_request_cookie failed\n");
399 e_cookie = g_base64_encode((const guchar *)cookie, size);
401 if (!org_tizen_alarm_manager_alarm_delete
402 (context.proxy, context.pid, alarm_id, e_cookie, &return_code,
404 /* dbus-glib error */
405 /*error_code should be set */
406 ALARM_MGR_EXCEPTION_PRINT(
407 "org_tizen_alarm_manager_alarm_delete() failed. "
408 "alarm_id[%d], return_code[%d]\n", alarm_id, return_code);
410 *error_code = -1; /*-1 means that system
418 if (return_code != 0) {
420 *error_code = return_code;
429 bool _send_alarm_power_on(alarm_context_t context, bool on_off,
432 GError *error = NULL;
435 if (!org_tizen_alarm_manager_alarm_power_on
436 (context.proxy, context.pid, on_off, &return_code, &error)) {
437 /* dbus-glib error */
438 /* error_code should be set */
439 ALARM_MGR_EXCEPTION_PRINT(
440 "org_tizen_alarm_manager_alarm_power_on failed. "
441 "return_code[%d]\n", return_code);
443 *error_code = -1; /*-1 means that system
448 if (return_code != 0) {
450 *error_code = return_code;
458 bool _send_alarm_power_off(alarm_context_t context, int *error_code)
460 GError *error = NULL;
463 if (!org_tizen_alarm_manager_alarm_power_off(context.proxy,
464 context.pid, &return_code, &error)) {
465 /* dbus-glib error */
466 /* error_code should be set */
467 ALARM_MGR_EXCEPTION_PRINT(
468 "org_tizen_alarm_manager_alarm_power_off failed. "
469 "return_code[%d]\n", return_code);
471 *error_code = -1; /*-1 means that system
476 if (return_code != 0) {
478 *error_code = return_code;
486 bool _send_alarm_check_next_duetime(alarm_context_t context, int *error_code)
488 GError *error = NULL;
491 if (!org_tizen_alarm_manager_alarm_check_next_duetime(context.proxy,
492 context.pid, &return_code, &error)) {
494 /*error_code should be set */
495 ALARM_MGR_EXCEPTION_PRINT(
496 "org_tizen_alarm_manager_alarm_power_check_next_duetime's "
497 "return value is false. return_code[%d]\n", return_code);
499 *error_code = -1; /*-1 means that system
504 if (return_code != 0) {
506 *error_code = return_code;
514 #endif /* __ALARM_BOOT */
516 bool _send_alarm_get_list_of_ids(alarm_context_t context, int maxnum_of_ids,
517 alarm_id_t *alarm_id, int *num_of_ids,
521 GError *error = NULL;
522 GArray *alarm_array = NULL;
526 if (!org_tizen_alarm_manager_alarm_get_list_of_ids(context.proxy,
527 context.pid, maxnum_of_ids, &alarm_array,
528 num_of_ids, &return_code, &error)) {
530 /*error_code should be set */
531 ALARM_MGR_EXCEPTION_PRINT(
532 "org_tizen_alarm_manager_alarm_get_list_of_ids() failed. "
533 "alarm_id[%d], return_code[%d]\n", alarm_id, return_code);
535 *error_code = -1; /*-1 means that system
541 if (return_code != 0) {
543 *error_code = return_code;
546 for (i = 0; i < alarm_array->len && i < maxnum_of_ids; i++) {
547 alarm_id[i] = g_array_index(alarm_array, alarm_id_t, i);
548 ALARM_MGR_LOG_PRINT(" alarm_id(%d)\n", alarm_id[i]);
551 *num_of_ids = alarm_array->len;
552 g_array_free(alarm_array, true);
558 bool _send_alarm_get_number_of_ids(alarm_context_t context, int *num_of_ids,
561 GError *error = NULL;
562 gint return_code = 0;
564 if (!org_tizen_alarm_manager_alarm_get_number_of_ids(context.proxy,
565 context.pid, num_of_ids, &return_code, &error)) {
566 /* dbus-glib error */
567 /* error_code should be set */
568 ALARM_MGR_EXCEPTION_PRINT(
569 "org_tizen_alarm_manager_alarm_get_number_of_ids() failed. "
570 "return_code[%d], return_code[%s]\n", \
571 return_code, error->message);
573 *error_code = -1; /*-1 means that system
578 if (return_code != 0) {
580 *error_code = return_code;
588 bool _send_alarm_get_info(alarm_context_t context, alarm_id_t alarm_id,
589 alarm_info_t *alarm_info, int *error_code)
591 GError *error = NULL;
594 if (!org_tizen_alarm_manager_alarm_get_info(context.proxy,
595 context.pid, alarm_id, &alarm_info->start.year,
596 &alarm_info->start.month, &alarm_info->start.day,
597 &alarm_info->start.hour, &alarm_info->start.min,
598 &alarm_info->start.sec, &alarm_info->end.year,
599 &alarm_info->end.month, &alarm_info->end.day,
600 &alarm_info->mode.u_interval.day_of_week,
601 (gint *)&alarm_info->mode.repeat,
602 &alarm_info->alarm_type, &alarm_info->reserved_info,
603 &return_code, &error)) {
605 /* error_code should be set */
606 ALARM_MGR_EXCEPTION_PRINT(
607 "org_tizen_alarm_manager_alarm_get_info() failed. "
608 "alarm_id[%d], return_code[%d]\n", alarm_id, return_code);
610 *error_code = -1; /*-1 means that system failed
615 if (return_code != 0) {
617 *error_code = return_code;