3 * Copyright 2012 Samsung Electronics Co., Ltd
5 * Licensed under the Flora License, Version 1.1 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://floralicense.org/license/
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
20 * @defgroup app_lib Application library
21 * This is a framework for User interface
25 * @defgroup alarm_engine_group Alarm DB Library
27 * Functions to APIs to access alarm DB.
31 * @file alarm-engine.h
32 * @ingroup alarm_engine_group
33 * @brief This library provides APIs to access alarm DB.
34 * @author Jiwon Lee <jiwon11.lee@samsung.com>, Jae-yong Lee <jaeyong911.lee@samsung.com>
39 #ifndef __ALARM_ENGINE_H__
40 #define __ALARM_ENGINE_H__
56 #define A_DBAPI __attribute__ ((visibility("default")))
60 * Maxium length of Buffer
62 #define ALARM_BUF_LEN (128)
64 * @def DEFAULT_ALARM_DB_REPEAT
65 * default value about repeat
67 #define DEFAULT_ALARM_DB_REPEAT ALARM_DB_REPEAT_NEVER
69 * @def DEFAULT_ALARM_DB_TYPE
70 * default value about type
72 #define DEFAULT_ALARM_DB_TYPE ALARM_DB_TYPE_MELODY
74 * @def DEFAULT_ALARM_DB_SNOOZE_DURATION
75 * default value about snooze duration
77 #define DEFAULT_ALARM_DB_SNOOZE_DURATION ALARM_DB_SNOOZE_MIN_5
79 * @def DEFAULT_ALARM_DB_SNOOZE_REPEAT
80 * default value about snooze repeat
82 #define DEFAULT_ALARM_DB_SNOOZE_REPEAT ALARM_DB_SNOOZE_TIMES_3
84 * @def DEFAULT_ALARM_DB_VOLUME
85 * default value about volume
87 #define DEFAULT_ALARM_DB_VOLUME (4)
91 #define ALARM_DB_RESULT_SUCCESS 0
92 #define ALARM_DB_RESULT_FAILED -1
94 * @def ALARM_DB_MAGIC_VALUE
95 * magic value for judge struct type
97 #define ALARM_DB_MAGIC_VALUE (0x6E)
98 #define MAGIC_VALUE_SET(p) (p) = ALARM_DB_MAGIC_VALUE;
99 #define MAGIC_VALUE_CHECK(p) IS_EQUAL(p, ALARM_DB_MAGIC_VALUE)
101 typedef enum _alarm_db_author_t alarm_db_author_t;
102 typedef enum _alarm_db_repeat_t alarm_db_repeat_t;
103 typedef enum _alarm_db_type_t alarm_db_type_t;
104 typedef enum _alarm_db_snooze_duration_t alarm_db_snooze_duration_t;
105 typedef enum _alarm_db_snooze_repeat_t alarm_db_snooze_repeat_t;
106 typedef enum _alarm_db_auto_power_onoff_t alarm_db_auto_power_onoff_t;
107 typedef enum _alarm_db_enabled_t alarm_db_enabled_t;
108 typedef enum _alarm_db_missed_t alarm_db_missed_t;
109 typedef struct alarm_data AData;
110 typedef struct alarm_data_list ADList;
113 * @enum _db_alarm_author_t
114 * @brief This enumeration defines author
116 enum _alarm_db_author_t {
117 ALARM_DB_AUTHOR_ALARM = 0x00, //alarm
118 ALARM_DB_AUTHOR_TIMER, //timer
119 ALARM_DB_AUTHOR_POWEROFF_ALARM, //poweroff alarm, not support now
122 * @enum _db_alarm_repeat_t
123 * @brief This enumeration defines repeat value
124 * @details user can use like this: ALARM_REPEAT_SUN|ALARM_REPEAT_TUE
126 enum _alarm_db_repeat_t {
127 ALARM_DB_REPEAT_NEVER = 0x00, //never repeat
128 ALARM_DB_REPEAT_SUN = 0x01, //sunday
129 ALARM_DB_REPEAT_MON = 0x02, //monday
130 ALARM_DB_REPEAT_TUE = 0x04, //tuesday
131 ALARM_DB_REPEAT_WED = 0x08, //wednesday
132 ALARM_DB_REPEAT_THU = 0x10, //thursday
133 ALARM_DB_REPEAT_FRI = 0x20, //friday
134 ALARM_DB_REPEAT_SAT = 0x40, //saturday
135 ALARM_DB_REPEAT_WEEKDAYS = 0x3E, //monday~friday
136 ALARM_DB_REPEAT_EVERYDAY = 0x7F, //sunday~saturday
137 ALARM_DB_REPEAT_WEEKENDS = 0x41, //sunday+saturday
140 * @enum _alarm_db_type_t
141 * @brief This enumeration defines type value
143 enum _alarm_db_type_t {
144 ALARM_DB_TYPE_MELODY = 0x00, /**< Melody */
145 ALARM_DB_TYPE_VIB, /**< Vibration */
146 ALARM_DB_TYPE_VIB_AND_MEL, /**< Vibration and Melody */
150 * @enum _alarm_db_snooze_duration_t
151 * @brief This enumeration defines duration type of alarm snoozing .
153 enum _alarm_db_snooze_duration_t {
154 ALARM_DB_SNOOZE_MIN_1 = 1,
155 /**< Snooze Time : 1 minute */
156 ALARM_DB_SNOOZE_MIN_3 = 3,
157 /**< Snooze Time : 3 minutes */
158 ALARM_DB_SNOOZE_MIN_5 = 5,
159 /**< Snooze Time : 5 minutes */
160 ALARM_DB_SNOOZE_MIN_10 = 10,
161 /**< Snooze Time : 10 minutes */
164 * @enum _alarm_db_snooze_repeat_t
165 * @brief This enumeration defines repeat times type of alarm snoozing .
167 enum _alarm_db_snooze_repeat_t {
168 ALARM_DB_SNOOZE_TIMES_1 = 1,
169 /**< Snooze Repeat : Once */
170 ALARM_DB_SNOOZE_TIMES_3 = 3,
171 /**< Snooze Repeat : 3 times */
172 ALARM_DB_SNOOZE_TIMES_5 = 5,
173 /**< Snooze Repeat : 5 times */
174 ALARM_DB_SNOOZE_TIMES_10 = 10,
175 /**< Snooze Repeat : 10 times */
178 * @enum _alarm_db_auto_power_onoff_t
179 * @brief This enumeration defines auto-power on/off .
181 enum _alarm_db_auto_power_onoff_t {
182 ALARM_DB_AUTOPOWER_OFF = 0x00,
183 /**< Autopower OFF */
184 ALARM_DB_AUTOPOWER_ON = 0x01
188 * @enum _alarm_db_enabled_t
189 * @brief This enumeration defines alarm on/off .
191 enum _alarm_db_enabled_t {
192 ALARM_DB_ENABLE_OFF = 0x00,
194 ALARM_DB_ENABLE_ON = 0x01
198 * @enum _alarm_db_missed_t
199 * @brief This enumeration defines alarm priority (For internal use).
201 enum _alarm_db_missed_t {
202 ALARM_DB_RESERVED_ALARM = 0x00, /**< Reserved alarm */
203 ALARM_DB_LOW_PRIORITY_ALARM = 0x01,/**< Low priority alarm */
204 ALARM_DB_MISSED_ALARM = 0x02, /**< Missed alarm */
205 ALARM_DB_RESERVED_SNOOZING_ALARM = 0x03,
206 /**< Reseved Snoozing alarm */
207 ALARM_DB_MISSED_SNOOZING_ALARM = 0x04,
208 /**< Missed snoozing alarm */
213 * @brief This structure defines alarm information.
216 int _magic; /**< magic value for check struct type,
217 the value is equal to ALARM_DB_MAGIC_VALUE*/
218 int id; /**< index of alarm */
219 int alarm_mgr_id; /**< index from alarm-manager */
220 alarm_db_enabled_t enable; /**< connected with activation in alarm-manager*/
221 alarm_db_missed_t missed; /**< for checking missed alarm */
222 alarm_db_author_t author; /**< alarm author (alarm/timer/...) */
223 char name[ALARM_BUF_LEN]; /**< alarm name */
224 time_t stime; /**< start time */
225 time_t atime; /**< alert time */
226 time_t etime; /**< create or edit time */
227 time_t sdate; /**< start date */
228 time_t edate; /**< end date */
229 char timezone[ALARM_BUF_LEN]; /**< time zone id */
230 bool repeat_once; /**< repeat once */
231 bool repeat_every; /**< repeat everyday */
232 alarm_db_repeat_t repeat_weekly; /**< repeat weekly */
233 bool snooze_enable; /**< snooze enable */
234 alarm_db_snooze_duration_t snooze_min; /**< snooze time */
235 alarm_db_snooze_repeat_t snooze_times; /**< snooze repeat */
236 char count; /**< count of snoozing times */
237 alarm_db_type_t type; /**< alarm type */
238 char tone[ALARM_BUF_LEN]; /**< alarm tone file */
239 unsigned char volume; /**< volume level */
240 alarm_db_auto_power_onoff_t auto_power_on; /**< use autopower on */
243 * @struct alarm_data_list
244 * @brief List for Alarm data
246 struct alarm_data_list {
247 struct alarm_data ad; /**< Alarm data */
248 struct alarm_data_list *prev;
249 /**< Previous list */
250 struct alarm_data_list *next;
255 * This function init alarm database, create db file to the @param dbfile if the dbfile is not null.
256 * If the file path is NULL, the db file will be created to the default path.
258 * @brief Initialize Alarm-Database
260 * @param [in] dbfile the path of user defined.
262 * @return On success, 0 is returned. On error, -1 is returned
264 * @remarks The function must be called fristly before calling other functions of alarm-db.
271 A_DBAPI int alarmdb_init(const char *dbfile);
274 * This function fini alarm database, it will close db and free db resource
276 * @brief Finialize Alarm-Database
282 * @remarks The function must be called finally when the application don't need db
289 A_DBAPI void alarmdb_fini(void);
292 * This function create a pointer to AData.
293 * The function must be called after alarmdb_init()
295 * @brief Create alarm data structure, Ref: alarmdb_free_data()
299 * @return This function returns a pointer of alarm_data on success or NULL on failure.
305 * @see alarmdb_free_data
308 A_DBAPI AData *alarmdb_create_data(void);
311 * This function gets the data of the alarm assosiated with alarm_id.
312 * It will connect to db and search by id.
315 * @brief Get a data from id
317 * @param [in] id the Database id of the alarm
319 * @return This function returns a pointer of alarm_data on success or NULL on failure.
321 * @remarks The function must be called after alarmdb_init(), and also given the correct id.
325 * @see alarmdb_get_data_by_author alarmdb_get_data_list_by_author
328 A_DBAPI AData *alarmdb_get_data(int id);
331 * This function gets the data of the alarm assosiated with alarm_id and auchor_id.
332 * The function must be called after alarmdb_init(), and also given the correct author.
334 * @brief Get a data from id and author
336 * @param [in] id the Database id of the alarm
337 * @param [in] author the author id of the alarm:
338 * ALARM_DB_AUTHOR_ALARM/ALARM_DB_AUTHOR_TIMER/ALARM_DB_AUTHOR_POWEROFF_ALARM
340 * @return This function returns a pointer of alarm_data on success or NULL on failure.
345 * @see alarmdb_get_data alarmdb_get_data_list_by_author
348 A_DBAPI AData *alarmdb_get_data_by_author(int id, char author);
351 * This function free the data: AData.
352 * The function must be called after alarmdb_create_data()
354 * @brief Free data struct
356 * @param [in] a pointer to AData*
360 * @remarks When application don't need the alarm_data, must call the function to free the memory
364 * @see alarmdb_create_data
367 A_DBAPI void alarmdb_free_data(AData *);
370 * This function add the data: AData.
371 * This function is usually called together with alarmmgr_create();
373 * @brief Insert a data to DB
375 * @param [in] a pointer to AData*
377 * @return This function returns the id,saved db id (int), if success, the int value >-1, else return -1.
383 * @see alarmdb_mod_data alarmdb_del_data
386 A_DBAPI int alarmdb_add_data(AData *);
389 * This function modify the data: AData.
390 * This function is usually called together with alarmmgr_update();
392 * @brief Update a data to DB
394 * @param [in] a pointer to AData*
396 * @return This function returns the id,saved db id (int), if success, the int value >-1, else return -1.
402 * @see alarmdb_add_data alarmdb_del_data
405 A_DBAPI int alarmdb_mod_data(AData *);
408 * This function delete the data assosiated with alarm_id.
409 * This function is usually called together with alarmmgr_delete();
411 * @brief Delete a data to DB
413 * @param [in] id db field
415 * @return This function returns 0 on success or -1 on fail
421 * @see alarmdb_add_data alarmdb_mod_data
424 A_DBAPI int alarmdb_del_data(int id);
427 * This function update the alarm is enable/disable.
428 * This function is usually called together with alarmmgr_update();
430 * @brief Set enable/disable an alarm
432 * @param [in] id: id db field
433 * [in] enable: true->enable, false->disable
435 * @return This function returns 0 on success or -1 on fail
441 * @see alarmdb_get_num_of_enable
444 A_DBAPI int alarmdb_set_enable(int id, bool enable);
447 * This function get the number of the enabled alarm.
448 * This function is usually called together with vconf_set_int(VCONFKEY_ALARM_STATE, @return)
450 * @brief Get number of enabled alarm
454 * @return This function returns the number of enable's alarm in db on success or -1 on fail
460 * @see alarmdb_set_enable
463 A_DBAPI int alarmdb_get_num_of_enable(void);
466 * This function set snooze on an alarm enable or disable
468 * @brief Set enable/disable snooze on an alarm
470 * @param [in] id: id db field
471 * [in] enable: true->enable, false->disable
473 * @return This function returns 0 on success or -1 on fail
482 A_DBAPI int alarmdb_set_snooze(int id, bool enable);
485 * This function get the last alarm id
488 * @brief Get last alarm id
492 * @return This function returns the last alarm_id in db on success, -1 on fail
498 * @see alarmdb_get_last_id_by_author
501 A_DBAPI int alarmdb_get_last_id(void);
504 * This function gets the last alarm id assosiated with auchor_id.
507 * @brief Get last alarm (generated by specific author)
509 * @param [in] author the author id of the alarm:
510 * ALARM_DB_AUTHOR_ALARM/ALARM_DB_AUTHOR_TIMER/ALARM_DB_AUTHOR_POWEROFF_ALARM
512 * @return This function returns the last alarm_id in db on success, -1 on fail
518 * @see alarmdb_get_last_id
521 A_DBAPI int alarmdb_get_last_id_by_author(char author);
524 * This function get the number of the enabled alarm.
527 * @brief Get number of alarm (generated by specific author)
529 * @param [in] author the author id of the alarm:
530 * ALARM_DB_AUTHOR_ALARM/ALARM_DB_AUTHOR_TIMER/ALARM_DB_AUTHOR_POWEROFF_ALARM
532 * @return This function returns the number of alarm of the author in db on success , -1 on fail
541 A_DBAPI int alarmdb_get_number_of_data_by_author(char author);
544 * This function gets the data list of the alarm assosiated with auchor_id.
545 * The function can be called after alarmdb_init(), and also given the correct author.
547 * @brief Get power on/off value (generated by specific author)
549 * @param [in] author the author id of the alarm:
550 * ALARM_DB_AUTHOR_ALARM/ALARM_DB_AUTHOR_TIMER/ALARM_DB_AUTHOR_POWEROFF_ALARM
552 * @return This function returns the state of alarm auto-power state,
553 * enum alarm_auto_power_onoff_t: ALARM_DB_AUTOPOWER_OFF/ALARM_DB_AUTOPOWER_ON
558 * @see enum:alarm_auto_power_onoff_t
561 A_DBAPI int alarmdb_get_power_onoff_by_author(char author);
564 * This function gets the data list of the alarm assosiated.
567 * @brief Get all alarm list
571 * @return This function returns a pointer of alarm_data_list on success or NULL on failure.
577 * @see alarmdb_get_data_list_by_author
580 A_DBAPI ADList *alarmdb_get_data_list_all(void);
583 * This function gets the data list of the alarm assosiated with auchor_id.
584 * The function can be called after alarmdb_init(), and also given the correct author.
586 * @brief Get alarm list(generated by specific author)
588 * @param [in] author the author id of the alarm:
589 * ALARM_DB_AUTHOR_ALARM/ALARM_DB_AUTHOR_TIMER/ALARM_DB_AUTHOR_POWEROFF_ALARM
591 * @return This function returns a pointer of alarm_data_list on success or NULL on failure.
596 * @see alarmdb_get_data_list_all
599 A_DBAPI ADList *alarmdb_get_data_list_by_author(char author);
602 * This function free the data list of ADList
603 * This function must be called when not being needed, if application call
604 * alarmdb_get_data_list_by_author/alarmdb_get_data_list_all.
606 * @brief Free data list
608 * @param [in] pointer of alarm_data_list
616 * @see alarmdb_get_data_list_all alarmdb_get_data_list_by_author
619 A_DBAPI void alarmdb_free_data_list(ADList *);
624 #endif /* __ALARM_ENGINE_H__ */