2 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All rights reserved.
4 * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
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.
17 #include <app_alarm.h>
18 #include <app_common.h>
23 static int recurring_alarm_id = -1;
26 on_foreach_registered_alarm(int alarm_id, void *user_data)
28 bool *result = (bool *)user_data;
30 LOGD("alarm id : %d", alarm_id);
32 *result = *result | 0x1;
37 bool sync_alarm_register(const char *operation, int delay, int period)
40 app_control_h app_control = NULL;
44 ret = app_control_create(&app_control);
45 if (ret != APP_CONTROL_ERROR_NONE)
47 LOGE("Function app_control_create() failed.");
51 ret = app_control_set_operation(app_control, operation);
52 if (ret != APP_CONTROL_ERROR_NONE)
54 LOGE("Function app_control_set_operation() failed.");
58 if (app_get_id(&app_id) != APP_ERROR_NONE) {
62 LOGD("app id : %s", app_id);
67 ret = app_control_set_app_id(app_control, app_id);
68 if (ret != APP_CONTROL_ERROR_NONE)
70 LOGE("Function app_control_set_app_id() failed.");
76 ret = alarm_schedule_after_delay(app_control, delay, period, &recurring_alarm_id);
77 if (ret != ALARM_ERROR_NONE)
78 LOGE("Function alarm_schedule_after_delay() failed.");
80 LOGD("Function alarm_schedule_after_delay() succeed. delay : %d, interval : %d", delay, period);
89 ret = app_control_destroy(app_control);
90 if (ret != APP_CONTROL_ERROR_NONE)
91 LOGE("Function app_control_destroy() failed.");
93 LOGD("Set recurring alarm with id: %i", recurring_alarm_id);
99 bool sync_alarm_exist()
102 int ret = alarm_foreach_registered_alarm(on_foreach_registered_alarm, &result);
103 if (ret != ALARM_ERROR_NONE)
104 LOGD("Listing error : %d", ret);