2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.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.tizenopensource.org/license
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.
18 * @defgroup app_lib Application library
19 * This is a framework for User interface
23 * @defgroup alarm_engine_group Alarm DB Library
25 * Functions to APIs to access alarm DB.
29 * @file alarm-engine.h
30 * @ingroup alarm_engine_group
31 * @brief This library provides APIs to access alarm DB.
32 * @author Jiwon Lee <jiwon11.lee@samsung.com>, Jae-yong Lee <jaeyong911.lee@samsung.com>
37 #ifndef __ALARM_ENGINE_H__
38 #define __ALARM_ENGINE_H__
54 #define A_DBAPI __attribute__ ((visibility("default")))
58 * Maxium length of Buffer
60 #define ALARM_BUF_LEN (128)
62 * @def DEFAULT_ALARM_DB_REPEAT
63 * default value about repeat
65 #define DEFAULT_ALARM_DB_REPEAT ALARM_DB_REPEAT_NEVER
67 * @def DEFAULT_ALARM_DB_TYPE
68 * default value about type
70 #define DEFAULT_ALARM_DB_TYPE ALARM_DB_TYPE_MELODY
72 * @def DEFAULT_ALARM_DB_SNOOZE_DURATION
73 * default value about snooze duration
75 #define DEFAULT_ALARM_DB_SNOOZE_DURATION ALARM_DB_SNOOZE_MIN_5
77 * @def DEFAULT_ALARM_DB_SNOOZE_REPEAT
78 * default value about snooze repeat
80 #define DEFAULT_ALARM_DB_SNOOZE_REPEAT ALARM_DB_SNOOZE_TIMES_3
82 * @def DEFAULT_ALARM_DB_VOLUME
83 * default value about volume
85 #define DEFAULT_ALARM_DB_VOLUME (4)
89 #define ALARM_DB_RESULT_SUCCESS 0
90 #define ALARM_DB_RESULT_FAILED -1
92 * @def ALARM_DB_MAGIC_VALUE
93 * magic value for judge struct type
95 #define ALARM_DB_MAGIC_VALUE (0x6E)
96 #define MAGIC_VALUE_SET(p) (p) = ALARM_DB_MAGIC_VALUE;
97 #define MAGIC_VALUE_CHECK(p) IS_EQUAL(p, ALARM_DB_MAGIC_VALUE)
99 typedef enum _alarm_db_author_t alarm_db_author_t;
100 typedef enum _alarm_db_repeat_t alarm_db_repeat_t;
101 typedef enum _alarm_db_type_t alarm_db_type_t;
102 typedef enum _alarm_db_snooze_duration_t alarm_db_snooze_duration_t;
103 typedef enum _alarm_db_snooze_repeat_t alarm_db_snooze_repeat_t;
104 typedef enum _alarm_db_auto_power_onoff_t alarm_db_auto_power_onoff_t;
105 typedef enum _alarm_db_enabled_t alarm_db_enabled_t;
106 typedef enum _alarm_db_missed_t alarm_db_missed_t;
107 typedef struct alarm_data AData;
108 typedef struct alarm_data_list ADList;
111 * @enum _db_alarm_author_t
112 * @brief This enumeration defines author
114 enum _alarm_db_author_t {
115 ALARM_DB_AUTHOR_ALARM = 0x00, //alarm
116 ALARM_DB_AUTHOR_TIMER, //timer
117 ALARM_DB_AUTHOR_POWEROFF_ALARM, //poweroff alarm, not support now
120 * @enum _db_alarm_repeat_t
121 * @brief This enumeration defines repeat value
122 * @details user can use like this: ALARM_REPEAT_SUN|ALARM_REPEAT_TUE
124 enum _alarm_db_repeat_t {
125 ALARM_DB_REPEAT_NEVER = 0x00, //never repeat
126 ALARM_DB_REPEAT_SUN = 0x01, //sunday
127 ALARM_DB_REPEAT_MON = 0x02, //monday
128 ALARM_DB_REPEAT_TUE = 0x04, //tuesday
129 ALARM_DB_REPEAT_WED = 0x08, //wednesday
130 ALARM_DB_REPEAT_THU = 0x10, //thursday
131 ALARM_DB_REPEAT_FRI = 0x20, //friday
132 ALARM_DB_REPEAT_SAT = 0x40, //saturday
133 ALARM_DB_REPEAT_WEEKDAYS = 0x3E, //monday~friday
134 ALARM_DB_REPEAT_EVERYDAY = 0x7F, //sunday~saturday
135 ALARM_DB_REPEAT_WEEKENDS = 0x41, //sunday+saturday
138 * @enum _alarm_db_type_t
139 * @brief This enumeration defines type value
141 enum _alarm_db_type_t {
142 ALARM_DB_TYPE_MELODY = 0x00,
144 ALARM_DB_TYPE_INC_MEL, /**< Raising Melody */
145 ALARM_DB_TYPE_VIB, /**< Vibration */
146 ALARM_DB_TYPE_VIB_THEN_MEL,
147 /**< Vibration then Melody */
148 ALARM_DB_TYPE_VIB_AND_MEL,
149 /**< Vibration and Melody */
150 ALARM_DB_TYPE_VIB_AND_INC_MEL,
151 /**< Vibration then Raising Melody */
155 * @enum _alarm_db_snooze_duration_t
156 * @brief This enumeration defines duration type of alarm snoozing .
158 enum _alarm_db_snooze_duration_t {
159 ALARM_DB_SNOOZE_MIN_1 = 1,
160 /**< Snooze Time : 1 minute */
161 ALARM_DB_SNOOZE_MIN_3 = 3,
162 /**< Snooze Time : 3 minutes */
163 ALARM_DB_SNOOZE_MIN_5 = 5,
164 /**< Snooze Time : 5 minutes */
165 ALARM_DB_SNOOZE_MIN_10 = 10,
166 /**< Snooze Time : 10 minutes */
169 * @enum _alarm_db_snooze_repeat_t
170 * @brief This enumeration defines repeat times type of alarm snoozing .
172 enum _alarm_db_snooze_repeat_t {
173 ALARM_DB_SNOOZE_TIMES_1 = 1,
174 /**< Snooze Repeat : Once */
175 ALARM_DB_SNOOZE_TIMES_3 = 3,
176 /**< Snooze Repeat : 3 times */
177 ALARM_DB_SNOOZE_TIMES_5 = 5,
178 /**< Snooze Repeat : 5 times */
179 ALARM_DB_SNOOZE_TIMES_10 = 10,
180 /**< Snooze Repeat : 10 times */
183 * @enum _alarm_db_auto_power_onoff_t
184 * @brief This enumeration defines auto-power on/off .
186 enum _alarm_db_auto_power_onoff_t {
187 ALARM_DB_AUTOPOWER_OFF = 0x00,
188 /**< Autopower OFF */
189 ALARM_DB_AUTOPOWER_ON = 0x01
193 * @enum _alarm_db_enabled_t
194 * @brief This enumeration defines alarm on/off .
196 enum _alarm_db_enabled_t {
197 ALARM_DB_ENABLE_OFF = 0x00,
199 ALARM_DB_ENABLE_ON = 0x01
203 * @enum _alarm_db_missed_t
204 * @brief This enumeration defines alarm priority (For internal use).
206 enum _alarm_db_missed_t {
207 ALARM_DB_RESERVED_ALARM = 0x00, /**< Reserved alarm */
208 ALARM_DB_LOW_PRIORITY_ALARM = 0x01,/**< Low priority alarm */
209 ALARM_DB_MISSED_ALARM = 0x02, /**< Missed alarm */
210 ALARM_DB_RESERVED_SNOOZING_ALARM = 0x03,
211 /**< Reseved Snoozing alarm */
212 ALARM_DB_MISSED_SNOOZING_ALARM = 0x04,
213 /**< Missed snoozing alarm */
218 * @brief This structure defines alarm information.
221 int _magic; /**< magic value for check struct type,
222 the value is equal to ALARM_DB_MAGIC_VALUE*/
223 int id; /**< index of alarm */
224 int alarm_mgr_id; /**< index from alarm-manager */
225 alarm_db_enabled_t enable; /**< connected with activation in alarm-manager*/
226 alarm_db_missed_t missed; /**< for checking missed alarm */
227 alarm_db_author_t author; /**< alarm author (alarm/timer/...) */
228 char name[ALARM_BUF_LEN]; /**< alarm name */
229 time_t stime; /**< start time */
230 time_t atime; /**< alert time */
231 time_t etime; /**< create or edit time */
232 time_t sdate; /**< start date */
233 time_t edate; /**< end date */
234 char timezone[ALARM_BUF_LEN]; /**< time zone id */
235 bool repeat_once; /**< repeat once */
236 bool repeat_every; /**< repeat everyday */
237 alarm_db_repeat_t repeat_weekly; /**< repeat weekly */
238 bool snooze_enable; /**< snooze enable */
239 alarm_db_snooze_duration_t snooze_min; /**< snooze time */
240 alarm_db_snooze_repeat_t snooze_times; /**< snooze repeat */
241 char count; /**< count of snoozing times */
242 alarm_db_type_t type; /**< alarm type */
243 char tone[ALARM_BUF_LEN]; /**< alarm tone file */
244 unsigned char volume; /**< volume level */
245 alarm_db_auto_power_onoff_t auto_power_on; /**< use autopower on */
248 * @struct alarm_data_list
249 * @brief List for Alarm data
251 struct alarm_data_list {
252 struct alarm_data ad; /**< Alarm data */
253 struct alarm_data_list *prev;
254 /**< Previous list */
255 struct alarm_data_list *next;
260 * This function init alarm database, create db file to the @param dbfile if the dbfile is not null.
261 * If the file path is NULL, the db file will be created to the default path.
263 * @brief Initialize Alarm-Database
265 * @param [in] dbfile the path of user defined.
267 * @return On success, 0 is returned. On error, -1 is returned
269 * @remarks The function must be called fristly before calling other functions of alarm-db.
276 A_DBAPI int alarmdb_init(const char *dbfile);
279 * This function fini alarm database, it will close db and free db resource
281 * @brief Finialize Alarm-Database
287 * @remarks The function must be called finally when the application don't need db
294 A_DBAPI void alarmdb_fini(void);
297 * This function create a pointer to AData.
298 * The function must be called after alarmdb_init()
300 * @brief Create alarm data structure, Ref: alarmdb_free_data()
304 * @return This function returns a pointer of alarm_data on success or NULL on failure.
310 * @see alarmdb_free_data
313 A_DBAPI AData *alarmdb_create_data(void);
316 * This function gets the data of the alarm assosiated with alarm_id.
317 * It will connect to db and search by id.
320 * @brief Get a data from id
322 * @param [in] id the Database id of the alarm
324 * @return This function returns a pointer of alarm_data on success or NULL on failure.
326 * @remarks The function must be called after alarmdb_init(), and also given the correct id.
330 * @see alarmdb_get_data_by_author alarmdb_get_data_list_by_author
333 A_DBAPI AData *alarmdb_get_data(int id);
336 * This function gets the data of the alarm assosiated with alarm_id and auchor_id.
337 * The function must be called after alarmdb_init(), and also given the correct author.
339 * @brief Get a data from id and author
341 * @param [in] id the Database id of the alarm
342 * @param [in] author the author id of the alarm:
343 * ALARM_DB_AUTHOR_ALARM/ALARM_DB_AUTHOR_TIMER/ALARM_DB_AUTHOR_POWEROFF_ALARM
345 * @return This function returns a pointer of alarm_data on success or NULL on failure.
350 * @see alarmdb_get_data alarmdb_get_data_list_by_author
353 A_DBAPI AData *alarmdb_get_data_by_author(int id, char author);
356 * This function free the data: AData.
357 * The function must be called after alarmdb_create_data()
359 * @brief Free data struct
361 * @param [in] a pointer to AData*
365 * @remarks When application don't need the alarm_data, must call the function to free the memory
369 * @see alarmdb_create_data
372 A_DBAPI void alarmdb_free_data(AData *);
375 * This function add the data: AData.
376 * This function is usually called together with alarmmgr_create();
378 * @brief Insert a data to DB
380 * @param [in] a pointer to AData*
382 * @return This function returns the id,saved db id (int), if success, the int value >-1, else return -1.
388 * @see alarmdb_mod_data alarmdb_del_data
391 A_DBAPI int alarmdb_add_data(AData *);
394 * This function modify the data: AData.
395 * This function is usually called together with alarmmgr_update();
397 * @brief Update a data to DB
399 * @param [in] a pointer to AData*
401 * @return This function returns the id,saved db id (int), if success, the int value >-1, else return -1.
407 * @see alarmdb_add_data alarmdb_del_data
410 A_DBAPI int alarmdb_mod_data(AData *);
413 * This function delete the data assosiated with alarm_id.
414 * This function is usually called together with alarmmgr_delete();
416 * @brief Delete a data to DB
418 * @param [in] id db field
420 * @return This function returns 0 on success or -1 on fail
426 * @see alarmdb_add_data alarmdb_mod_data
429 A_DBAPI int alarmdb_del_data(int id);
432 * This function update the alarm is enable/disable.
433 * This function is usually called together with alarmmgr_update();
435 * @brief Set enable/disable an alarm
437 * @param [in] id: id db field
438 * [in] enable: true->enable, false->disable
440 * @return This function returns 0 on success or -1 on fail
446 * @see alarmdb_get_num_of_enable
449 A_DBAPI int alarmdb_set_enable(int id, bool enable);
452 * This function get the number of the enabled alarm.
453 * This function is usually called together with vconf_set_int(VCONFKEY_ALARM_STATE, @return)
455 * @brief Get number of enabled alarm
459 * @return This function returns the number of enable's alarm in db on success or -1 on fail
465 * @see alarmdb_set_enable
468 A_DBAPI int alarmdb_get_num_of_enable(void);
471 * This function set snooze on an alarm enable or disable
473 * @brief Set enable/disable snooze on an alarm
475 * @param [in] id: id db field
476 * [in] enable: true->enable, false->disable
478 * @return This function returns 0 on success or -1 on fail
487 A_DBAPI int alarmdb_set_snooze(int id, bool enable);
490 * This function get the last alarm id
493 * @brief Get last alarm id
497 * @return This function returns the last alarm_id in db on success, -1 on fail
503 * @see alarmdb_get_last_id_by_author
506 A_DBAPI int alarmdb_get_last_id(void);
509 * This function gets the last alarm id assosiated with auchor_id.
512 * @brief Get last alarm (generated by specific author)
514 * @param [in] author the author id of the alarm:
515 * ALARM_DB_AUTHOR_ALARM/ALARM_DB_AUTHOR_TIMER/ALARM_DB_AUTHOR_POWEROFF_ALARM
517 * @return This function returns the last alarm_id in db on success, -1 on fail
523 * @see alarmdb_get_last_id
526 A_DBAPI int alarmdb_get_last_id_by_author(char author);
529 * This function get the number of the enabled alarm.
532 * @brief Get number of alarm (generated by specific author)
534 * @param [in] author the author id of the alarm:
535 * ALARM_DB_AUTHOR_ALARM/ALARM_DB_AUTHOR_TIMER/ALARM_DB_AUTHOR_POWEROFF_ALARM
537 * @return This function returns the number of alarm of the author in db on success , -1 on fail
546 A_DBAPI int alarmdb_get_number_of_data_by_author(char author);
549 * This function gets the data list of the alarm assosiated with auchor_id.
550 * The function can be called after alarmdb_init(), and also given the correct author.
552 * @brief Get power on/off value (generated by specific author)
554 * @param [in] author the author id of the alarm:
555 * ALARM_DB_AUTHOR_ALARM/ALARM_DB_AUTHOR_TIMER/ALARM_DB_AUTHOR_POWEROFF_ALARM
557 * @return This function returns the state of alarm auto-power state,
558 * enum alarm_auto_power_onoff_t: ALARM_DB_AUTOPOWER_OFF/ALARM_DB_AUTOPOWER_ON
563 * @see enum:alarm_auto_power_onoff_t
566 A_DBAPI int alarmdb_get_power_onoff_by_author(char author);
569 * This function gets the data list of the alarm assosiated.
572 * @brief Get all alarm list
576 * @return This function returns a pointer of alarm_data_list on success or NULL on failure.
582 * @see alarmdb_get_data_list_by_author
585 A_DBAPI ADList *alarmdb_get_data_list_all(void);
588 * This function gets the data list of the alarm assosiated with auchor_id.
589 * The function can be called after alarmdb_init(), and also given the correct author.
591 * @brief Get alarm list(generated by specific author)
593 * @param [in] author the author id of the alarm:
594 * ALARM_DB_AUTHOR_ALARM/ALARM_DB_AUTHOR_TIMER/ALARM_DB_AUTHOR_POWEROFF_ALARM
596 * @return This function returns a pointer of alarm_data_list on success or NULL on failure.
601 * @see alarmdb_get_data_list_all
604 A_DBAPI ADList *alarmdb_get_data_list_by_author(char author);
607 * This function free the data list of ADList
608 * This function must be called when not being needed, if application call
609 * alarmdb_get_data_list_by_author/alarmdb_get_data_list_all.
611 * @brief Free data list
613 * @param [in] pointer of alarm_data_list
621 * @see alarmdb_get_data_list_all alarmdb_get_data_list_by_author
624 A_DBAPI void alarmdb_free_data_list(ADList *);
629 #endif /* __ALARM_ENGINE_H__ */