summaryrefslogtreecommitdiff
path: root/include/alarm-internal.h
blob: bc7b174703724ae931a019ae5b7525318e87c425 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/*
 * Copyright (c) 2000 - 2019 Samsung Electronics Co., Ltd All Rights Reserved
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#pragma once

#ifdef __cplusplus
extern "C" {
#endif

#include <glib.h>
#include <dlog.h>
#include <bundle.h>
#include <appsvc.h>
#include <notification.h>
#include <gio/gio.h>

#include "alarm.h"

#ifdef LOG_TAG
#undef LOG_TAG
#endif
#define LOG_TAG "ALARM_MANAGER"

#define MAX_BUNDLE_NAME_LEN 2048
#define MAX_SERVICE_NAME_LEN 512
#define MAX_PKG_NAME_LEN MAX_SERVICE_NAME_LEN-8
#define MAX_PKG_ID_LEN 512
#define MAX_APP_ID_LEN 512
#define MIN_INEXACT_INTERVAL 600
#define REGULAR_UID_MIN 5000

typedef struct {
	GDBusConnection *connection;
	GDBusConnection *session_conn;
	GDBusProxy *proxy;
	guint sid; /* signal subscription id */
	alarm_cb_t alarm_handler;
	int handler_id;
	void *user_param;
	char *app_service_name;
	char *app_service_name_mod;
} alarm_context_t;

enum async_param_type {
	SET_SYSTIME = 0,
	SET_SYSTIME_WITH_PROPAGATION_DELAY,
};

typedef enum {
	PROFILE_UNKNOWN = 0,
	PROFILE_MOBILE,
	PROFILE_WEARABLE,
	PROFILE_TV,
	PROFILE_IVI,
	PROFILE_COMMON,
} profile_t;

#define	ALARM_TYPE_RELATIVE		0x80000000	/**< relative  */
#define	ALARM_TYPE_WITHCB		0x40000000	/**< withcb  */
#define	ALARM_TYPE_PERIOD		0x10000000	/**< periodic */

bool _send_alarm_create(alarm_context_t context, alarm_info_t *alarm,
			alarm_id_t *id, const char *dst_service_name, const char *dst_service_name_mod, int *error_code);
bool _send_alarm_create_appsvc(alarm_context_t context, alarm_info_t *alarm_info,
			alarm_id_t *alarm_id, bundle *b, int *error_code);
bool _send_alarm_create_noti(alarm_context_t context, alarm_info_t *alarm_info,
			alarm_id_t *alarm_id, notification_h noti, int *error_code);
bool _send_alarm_update(alarm_context_t context, alarm_id_t alarm_id,
			alarm_info_t *alarm_info, int update_flag, int *error_code);
bool _send_alarm_delete(alarm_context_t context, alarm_id_t alarm_id, int *error_code);
bool _send_alarm_delete_all(alarm_context_t context, int *error_code);
bool _send_alarm_get_list_of_ids(alarm_context_t context, int maxnum_of_ids,
			GVariantIter **iter, int *num_of_ids, int *error_code);
bool _send_alarm_get_number_of_ids(alarm_context_t context, int *num_of_ids, int *error_code);
bool _send_alarm_get_info(alarm_context_t context, alarm_id_t alarm_id, alarm_info_t *alarm_info, int *error_code);
bool _send_alarm_get_next_duetime(alarm_context_t context, alarm_id_t alarm_id, time_t* duetime, int *error_code);
bool _send_alarm_get_all_info(alarm_context_t context, char ** db_path, int *error_code);
bool _send_alarm_reset(alarm_context_t context, int *error_code);
bool _remove_from_scheduled_alarm_list(uid_t uid, alarm_id_t alarm_id);
bundle *_send_alarm_get_appsvc_info(alarm_context_t context, alarm_id_t alarm_id, int *error_code);
notification_h _send_alarm_get_noti_info(alarm_context_t context, alarm_id_t alarm_id, int *error_code);
bool _send_alarm_set_rtc_time(alarm_context_t context, alarm_date_t *time, int *error_code);
bool _send_alarm_set_time_with_propagation_delay(alarm_context_t context, struct timespec new_time, struct timespec req_time, int *error_code);
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);
bool _send_alarm_set_timezone(alarm_context_t context, char *tzpath_str, int *error_code);
bool _send_alarm_create_periodic(alarm_context_t context, int interval, int is_ref, int method, alarm_id_t *alarm_id, int *error_code);
bool _send_alarm_set_time(alarm_context_t context, time_t new_time, int *error_code);
bool _send_alarm_set_time_async(alarm_context_t context, time_t new_time, alarm_set_time_cb_t result_cb, void *user_data);
bool _send_alarm_set_global(alarm_context_t context, int alarm_id, bool global, int *error_code);
bool _send_alarm_get_global(alarm_context_t context, int alarm_id, bool *global, int *error_code);

/*  alarm manager*/
typedef struct {
	time_t start;
	time_t end;

	alarm_id_t alarm_id;
	uid_t uid;
	char *caller_pkgid;
	char *callee_pkgid;
	char *app_unique_name;
	char *app_service_name;
	char *app_service_name_mod;
	char *dst_service_name;
	char *dst_service_name_mod;
	time_t due_time;

	char *bundle;
	char *noti;

	alarm_info_t alarm_info;

	periodic_method_e method;
	long requested_interval;
	int is_ref;
	bool global;
} __alarm_info_t;

typedef struct {
	bool used;
	__alarm_info_t *__alarm_info;
} __alarm_entry_t;

typedef struct {
	int timer;
	time_t c_due_time;
	GSList *alarms;
	int gmt_idx;
	int dst;
	GDBusConnection *connection;
} __alarm_server_context_t;

typedef struct {
	bool used;
	alarm_id_t alarm_id;
	uid_t uid;
	__alarm_info_t *__alarm_info;
} __scheduled_alarm_t;

typedef struct {
	char service_name[MAX_SERVICE_NAME_LEN];
	uid_t uid;
	alarm_id_t alarm_id;
} __expired_alarm_t;

typedef struct _bg_category_cb_info_t {
	const char *appid;
	bool has_bg;
} bg_category_cb_info_t;

void _release_alarm_info_t();

void _alarm_set_next_duetime(__alarm_info_t *alarm_info);
void _alarm_schedule();
void _clear_scheduled_alarm_list();
void _add_to_scheduled_alarm_list(__alarm_info_t *__alarm_info);

void _alarm_set_timer(int timer, time_t due_time);
void _alarm_disable_timer();
int _initialize_timer();

void _alarm_initialize();
time_t _get_periodic_alarm_standard_time(void);
bool _can_skip_expired_cb(alarm_id_t alarm_id);

void _alarm_expired();
void _rtc_set();

int alarm_manager_alarm_create(GVariant *parameters, uid_t uid, pid_t pid, int *alarm_id);
int alarm_manager_alarm_create_appsvc(GVariant *parameters, uid_t uid, pid_t pid, int *alarm_id);
int alarm_manager_alarm_create_periodic(GVariant *parameters, uid_t uid, pid_t pid, int *alarm_id);
int alarm_manager_alarm_create_noti(GVariant *parameters, uid_t uid, pid_t pid, int *alarm_id);
int alarm_manager_alarm_delete(GVariant *parameters, uid_t uid, pid_t pid);
int alarm_manager_alarm_delete_all(GVariant *parameters, uid_t uid, pid_t pid);
int alarm_manager_alarm_update(GVariant *parameters, uid_t uid, pid_t pid);
int alarm_manager_alarm_get_number_of_ids(uid_t uid, pid_t pid, int *num_of_ids);
int alarm_manager_alarm_get_list_of_ids(GVariant *parameters, uid_t uid, pid_t pid, GVariant **alarm_array, int *num_of_alarm);
int alarm_manager_alarm_get_appsvc_info(GVariant *parameters, uid_t uid, gchar **b_data);
int alarm_manager_alarm_get_noti_info(GVariant *parameters, uid_t uid, gchar **noti_data);
int alarm_manager_alarm_get_info(GVariant *parameters, uid_t uid, alarm_info_t *alarm_info);
int alarm_manager_alarm_get_next_duetime(GVariant *parameters, uid_t uid, time_t *duetime);
int alarm_manager_alarm_get_all_info(uid_t uid, char **db_path);
int alarm_manager_alarm_set_rtc_time(GVariant *parameters);
int alarm_manager_alarm_set_time(GVariant* parameters);
int alarm_manager_alarm_set_time_with_propagation_delay(GVariant* parameters);
int alarm_manager_alarm_set_timezone(GVariant* parameters);
int alarm_manager_alarm_set_global(GVariant *parameters, uid_t uid);
int alarm_manager_alarm_get_global(GVariant *parameters, gboolean *global);

#define CHECK_NULL_STRING(x) x ? x : "null"
#define STRDUP_WITH_NULLCMP(a) strcmp(a, "null") ? strdup(a) : NULL

#ifdef __cplusplus
}
#endif