Fix build warning based on GCC-9
[platform/core/appfw/alarm-manager.git] / include / alarm-internal.h
1 /*
2  * Copyright (c) 2000 - 2019 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 #pragma once
17
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21
22 #include <glib.h>
23 #include <dlog.h>
24 #include <bundle.h>
25 #include <appsvc.h>
26 #include <notification.h>
27 #include <gio/gio.h>
28
29 #include "alarm.h"
30
31 #ifdef LOG_TAG
32 #undef LOG_TAG
33 #endif
34 #define LOG_TAG "ALARM_MANAGER"
35
36 #define MAX_BUNDLE_NAME_LEN 2048
37 #define MAX_SERVICE_NAME_LEN 512
38 #define MAX_PKG_NAME_LEN MAX_SERVICE_NAME_LEN-8
39 #define MAX_PKG_ID_LEN 512
40 #define MAX_APP_ID_LEN 256
41 #define MIN_INEXACT_INTERVAL 600
42 #define REGULAR_UID_MIN 5000
43
44 #define BILLION 1000000000 /* for calculating nano seconds */
45 #define MILLION 1000000 /* for calculating micro seconds */
46
47 typedef struct {
48         GDBusConnection *connection;
49         GDBusConnection *session_conn;
50         GDBusProxy *proxy;
51         guint sid; /* signal subscription id */
52         alarm_cb_t alarm_handler;
53         int handler_id;
54         void *user_param;
55         char *app_service_name;
56         char *app_service_name_mod;
57 } alarm_context_t;
58
59 enum async_param_type {
60         SET_SYSTIME = 0,
61         SET_SYSTIME_WITH_PROPAGATION_DELAY,
62 };
63
64 typedef enum {
65         PROFILE_UNKNOWN = 0,
66         PROFILE_MOBILE,
67         PROFILE_WEARABLE,
68         PROFILE_TV,
69         PROFILE_IVI,
70         PROFILE_COMMON,
71 } profile_t;
72
73 #define ALARM_TYPE_RELATIVE             0x80000000      /**< relative  */
74 #define ALARM_TYPE_WITHCB               0x40000000      /**< withcb  */
75 #define ALARM_TYPE_PERIOD               0x10000000      /**< periodic */
76
77 bool _send_alarm_create(alarm_context_t context, alarm_info_t *alarm,
78                         alarm_id_t *id, const char *dst_service_name, const char *dst_service_name_mod, int *error_code);
79 bool _send_alarm_create_appsvc(alarm_context_t context, alarm_info_t *alarm_info,
80                         alarm_id_t *alarm_id, bundle *b, int *error_code);
81 bool _send_alarm_create_noti(alarm_context_t context, alarm_info_t *alarm_info,
82                         alarm_id_t *alarm_id, notification_h noti, int *error_code);
83 bool _send_alarm_update(alarm_context_t context, alarm_id_t alarm_id,
84                         alarm_info_t *alarm_info, int update_flag, int *error_code);
85 bool _send_alarm_delete(alarm_context_t context, alarm_id_t alarm_id, int *error_code);
86 bool _send_alarm_delete_all(alarm_context_t context, int *error_code);
87 bool _send_alarm_get_list_of_ids(alarm_context_t context, int maxnum_of_ids,
88                         GVariantIter **iter, int *num_of_ids, int *error_code);
89 bool _send_alarm_get_number_of_ids(alarm_context_t context, int *num_of_ids, int *error_code);
90 bool _send_alarm_get_info(alarm_context_t context, alarm_id_t alarm_id, alarm_info_t *alarm_info, int *error_code);
91 bool _send_alarm_get_next_duetime(alarm_context_t context, alarm_id_t alarm_id, time_t* duetime, int *error_code);
92 bool _send_alarm_get_all_info(alarm_context_t context, char ** db_path, int *error_code);
93 bool _send_alarm_reset(alarm_context_t context, int *error_code);
94 bool _remove_from_scheduled_alarm_list(uid_t uid, alarm_id_t alarm_id);
95 bundle *_send_alarm_get_appsvc_info(alarm_context_t context, alarm_id_t alarm_id, int *error_code);
96 notification_h _send_alarm_get_noti_info(alarm_context_t context, alarm_id_t alarm_id, int *error_code);
97 bool _send_alarm_set_rtc_time(alarm_context_t context, alarm_date_t *time, int *error_code);
98 bool _send_alarm_set_time_with_propagation_delay(alarm_context_t context, struct timespec new_time, struct timespec req_time, int *error_code);
99 bool _send_alarm_set_time_with_propagation_delay_async(alarm_context_t context, struct timespec new_time, struct timespec req_time, alarm_set_time_cb_t result_cb, void *user_data);
100 bool _send_alarm_set_timezone(alarm_context_t context, char *tzpath_str, int *error_code);
101 bool _send_alarm_create_periodic(alarm_context_t context, int interval, int is_ref, int method, alarm_id_t *alarm_id, int *error_code);
102 bool _send_alarm_set_time(alarm_context_t context, time_t new_time, int *error_code);
103 bool _send_alarm_set_time_async(alarm_context_t context, time_t new_time, alarm_set_time_cb_t result_cb, void *user_data);
104 bool _send_alarm_set_global(alarm_context_t context, int alarm_id, bool global, int *error_code);
105 bool _send_alarm_get_global(alarm_context_t context, int alarm_id, bool *global, int *error_code);
106
107 /*  alarm manager*/
108 typedef struct {
109         time_t start;
110         time_t end;
111
112         alarm_id_t alarm_id;
113         uid_t uid;
114         char *caller_pkgid;
115         char *callee_pkgid;
116         char *app_unique_name;
117         char *app_service_name;
118         char *app_service_name_mod;
119         char *dst_service_name;
120         char *dst_service_name_mod;
121         time_t due_time;
122
123         char *bundle;
124         char *noti;
125
126         alarm_info_t alarm_info;
127
128         periodic_method_e method;
129         long requested_interval;
130         int is_ref;
131         bool global;
132         bool zombie_mode;
133 } __alarm_info_t;
134
135 typedef struct {
136         bool used;
137         __alarm_info_t *__alarm_info;
138 } __alarm_entry_t;
139
140 typedef struct {
141         int timer;
142         time_t c_due_time;
143         GSList *alarms;
144         int gmt_idx;
145         int dst;
146         GDBusConnection *connection;
147 } __alarm_server_context_t;
148
149 typedef struct {
150         bool used;
151         alarm_id_t alarm_id;
152         uid_t uid;
153         __alarm_info_t *__alarm_info;
154 } __scheduled_alarm_t;
155
156 typedef struct {
157         char service_name[MAX_SERVICE_NAME_LEN];
158         uid_t uid;
159         alarm_id_t alarm_id;
160 } __expired_alarm_t;
161
162 typedef struct _bg_category_cb_info_t {
163         const char *appid;
164         bool has_bg;
165 } bg_category_cb_info_t;
166
167 void _release_alarm_info_t();
168
169 void _alarm_set_next_duetime(__alarm_info_t *alarm_info);
170 void _alarm_schedule();
171 void _clear_scheduled_alarm_list();
172 void _add_to_scheduled_alarm_list(__alarm_info_t *__alarm_info);
173
174 void _alarm_set_timer(int timer, time_t due_time);
175 void _alarm_disable_timer();
176 int _initialize_timer();
177
178 void _alarm_initialize();
179 time_t _get_periodic_alarm_standard_time(void);
180 bool _can_skip_expired_cb(alarm_id_t alarm_id);
181
182 void _alarm_expired();
183 void _rtc_set();
184
185 int alarm_manager_alarm_create(GVariant *parameters, uid_t uid, pid_t pid, int *alarm_id);
186 int alarm_manager_alarm_create_appsvc(GVariant *parameters, uid_t uid, pid_t pid, int *alarm_id);
187 int alarm_manager_alarm_create_periodic(GVariant *parameters, uid_t uid, pid_t pid, int *alarm_id);
188 int alarm_manager_alarm_create_noti(GVariant *parameters, uid_t uid, pid_t pid, int *alarm_id);
189 int alarm_manager_alarm_delete(GVariant *parameters, uid_t uid, pid_t pid);
190 int alarm_manager_alarm_delete_all(GVariant *parameters, uid_t uid, pid_t pid);
191 int alarm_manager_alarm_update(GVariant *parameters, uid_t uid, pid_t pid);
192 int alarm_manager_alarm_get_number_of_ids(uid_t uid, pid_t pid, int *num_of_ids);
193 int alarm_manager_alarm_get_list_of_ids(GVariant *parameters, uid_t uid, pid_t pid, GVariant **alarm_array, int *num_of_alarm);
194 int alarm_manager_alarm_get_appsvc_info(GVariant *parameters, uid_t uid, gchar **b_data);
195 int alarm_manager_alarm_get_noti_info(GVariant *parameters, uid_t uid, gchar **noti_data);
196 int alarm_manager_alarm_get_info(GVariant *parameters, uid_t uid, alarm_info_t *alarm_info);
197 int alarm_manager_alarm_get_next_duetime(GVariant *parameters, uid_t uid, time_t *duetime);
198 int alarm_manager_alarm_get_all_info(uid_t uid, char **db_path);
199 int alarm_manager_alarm_set_rtc_time(GVariant *parameters);
200 int alarm_manager_alarm_set_time(GVariant* parameters, pid_t pid);
201 int alarm_manager_alarm_set_time_with_propagation_delay(GVariant* parameters, pid_t pid);
202 int alarm_manager_alarm_set_timezone(GVariant* parameters);
203 int alarm_manager_alarm_set_global(GVariant *parameters, uid_t uid);
204 int alarm_manager_alarm_get_global(GVariant *parameters, gboolean *global);
205
206 #define CHECK_NULL_STRING(x) x ? x : "null"
207 #define STRDUP_WITH_NULLCMP(a) strcmp(a, "null") ? strdup(a) : NULL
208
209 #ifdef __cplusplus
210 }
211 #endif
212