diff options
author | Jinkun Jang <jinkun.jang@samsung.com> | 2013-03-13 01:37:36 +0900 |
---|---|---|
committer | Jinkun Jang <jinkun.jang@samsung.com> | 2013-03-13 01:37:36 +0900 |
commit | ee9d4f1c589382dcd6b1a20ca98d262843f4359e (patch) | |
tree | dc94f0c578348defbc836737f26169df2ad62199 /include | |
parent | 30914695de4a9c11b3a4e1a23be815a2d0f2bbdd (diff) | |
download | libslp-alarm-ee9d4f1c589382dcd6b1a20ca98d262843f4359e.tar.gz libslp-alarm-ee9d4f1c589382dcd6b1a20ca98d262843f4359e.tar.bz2 libslp-alarm-ee9d4f1c589382dcd6b1a20ca98d262843f4359e.zip |
Tizen 2.1 base
Diffstat (limited to 'include')
-rw-r--r-- | include/alarm-engine.h | 624 | ||||
-rw-r--r-- | include/db-define.h | 43 | ||||
-rw-r--r-- | include/db-dlog.h | 163 | ||||
-rw-r--r-- | include/db-schema.h | 51 | ||||
-rw-r--r-- | include/db.h | 175 | ||||
-rw-r--r-- | include/libalarm.h | 25 |
6 files changed, 1081 insertions, 0 deletions
diff --git a/include/alarm-engine.h b/include/alarm-engine.h new file mode 100644 index 0000000..161a44a --- /dev/null +++ b/include/alarm-engine.h @@ -0,0 +1,624 @@ +/* +* +* Copyright 2012 Samsung Electronics Co., Ltd +* +* Licensed under the Flora License, Version 1.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://floralicense.org/license/ +* +* 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. +* +*/ + +/*! + * @defgroup app_lib Application library + * This is a framework for User interface + */ + +/*! + * @defgroup alarm_engine_group Alarm DB Library + * @ingroup app_lib + * Functions to APIs to access alarm DB. + */ + +/** + * @file alarm-engine.h + * @ingroup alarm_engine_group + * @brief This library provides APIs to access alarm DB. + * @author Jiwon Lee <jiwon11.lee@samsung.com>, Jae-yong Lee <jaeyong911.lee@samsung.com> + * @date 2010-01-07 + * @version 0.0.1 + */ + +#ifndef __ALARM_ENGINE_H__ +#define __ALARM_ENGINE_H__ + +#include <stdbool.h> +#include <time.h> + +//#include "sglib.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @def A_DBAPI + * prefix + */ +#ifndef A_DBAPI +#define A_DBAPI __attribute__ ((visibility("default"))) +#endif +/** + * @def ALARM_BUF_LEN + * Maxium length of Buffer + */ +#define ALARM_BUF_LEN (128) +/** + * @def DEFAULT_ALARM_DB_REPEAT + * default value about repeat + */ +#define DEFAULT_ALARM_DB_REPEAT ALARM_DB_REPEAT_NEVER +/** + * @def DEFAULT_ALARM_DB_TYPE + * default value about type + */ +#define DEFAULT_ALARM_DB_TYPE ALARM_DB_TYPE_MELODY +/** + * @def DEFAULT_ALARM_DB_SNOOZE_DURATION + * default value about snooze duration + */ +#define DEFAULT_ALARM_DB_SNOOZE_DURATION ALARM_DB_SNOOZE_MIN_5 +/** + * @def DEFAULT_ALARM_DB_SNOOZE_REPEAT + * default value about snooze repeat + */ +#define DEFAULT_ALARM_DB_SNOOZE_REPEAT ALARM_DB_SNOOZE_TIMES_3 +/** + * @def DEFAULT_ALARM_DB_VOLUME + * default value about volume + */ +#define DEFAULT_ALARM_DB_VOLUME (4) +/** + * return value + */ +#define ALARM_DB_RESULT_SUCCESS 0 +#define ALARM_DB_RESULT_FAILED -1 +/** + * @def ALARM_DB_MAGIC_VALUE + * magic value for judge struct type + */ +#define ALARM_DB_MAGIC_VALUE (0x6E) +#define MAGIC_VALUE_SET(p) (p) = ALARM_DB_MAGIC_VALUE; +#define MAGIC_VALUE_CHECK(p) IS_EQUAL(p, ALARM_DB_MAGIC_VALUE) + + typedef enum _alarm_db_author_t alarm_db_author_t; + typedef enum _alarm_db_repeat_t alarm_db_repeat_t; + typedef enum _alarm_db_type_t alarm_db_type_t; + typedef enum _alarm_db_snooze_duration_t alarm_db_snooze_duration_t; + typedef enum _alarm_db_snooze_repeat_t alarm_db_snooze_repeat_t; + typedef enum _alarm_db_auto_power_onoff_t alarm_db_auto_power_onoff_t; + typedef enum _alarm_db_enabled_t alarm_db_enabled_t; + typedef enum _alarm_db_missed_t alarm_db_missed_t; + typedef struct alarm_data AData; + typedef struct alarm_data_list ADList; + +/** +* @enum _db_alarm_author_t +* @brief This enumeration defines author +*/ + enum _alarm_db_author_t { + ALARM_DB_AUTHOR_ALARM = 0x00, //alarm + ALARM_DB_AUTHOR_TIMER, //timer + ALARM_DB_AUTHOR_POWEROFF_ALARM, //poweroff alarm, not support now + }; +/** +* @enum _db_alarm_repeat_t +* @brief This enumeration defines repeat value +* @details user can use like this: ALARM_REPEAT_SUN|ALARM_REPEAT_TUE +*/ + enum _alarm_db_repeat_t { + ALARM_DB_REPEAT_NEVER = 0x00, //never repeat + ALARM_DB_REPEAT_SUN = 0x01, //sunday + ALARM_DB_REPEAT_MON = 0x02, //monday + ALARM_DB_REPEAT_TUE = 0x04, //tuesday + ALARM_DB_REPEAT_WED = 0x08, //wednesday + ALARM_DB_REPEAT_THU = 0x10, //thursday + ALARM_DB_REPEAT_FRI = 0x20, //friday + ALARM_DB_REPEAT_SAT = 0x40, //saturday + ALARM_DB_REPEAT_WEEKDAYS = 0x3E, //monday~friday + ALARM_DB_REPEAT_EVERYDAY = 0x7F, //sunday~saturday + ALARM_DB_REPEAT_WEEKENDS = 0x41, //sunday+saturday + }; +/** +* @enum _alarm_db_type_t +* @brief This enumeration defines type value +*/ + enum _alarm_db_type_t { + ALARM_DB_TYPE_MELODY = 0x00, /**< Melody */ + ALARM_DB_TYPE_VIB, /**< Vibration */ + ALARM_DB_TYPE_VIB_AND_MEL, /**< Vibration and Melody */ + ALARM_DB_TYPE_MAX, + }; +/** +* @enum _alarm_db_snooze_duration_t +* @brief This enumeration defines duration type of alarm snoozing . +*/ + enum _alarm_db_snooze_duration_t { + ALARM_DB_SNOOZE_MIN_1 = 1, + /**< Snooze Time : 1 minute */ + ALARM_DB_SNOOZE_MIN_3 = 3, + /**< Snooze Time : 3 minutes */ + ALARM_DB_SNOOZE_MIN_5 = 5, + /**< Snooze Time : 5 minutes */ + ALARM_DB_SNOOZE_MIN_10 = 10, + /**< Snooze Time : 10 minutes */ + }; +/** +* @enum _alarm_db_snooze_repeat_t +* @brief This enumeration defines repeat times type of alarm snoozing . +*/ + enum _alarm_db_snooze_repeat_t { + ALARM_DB_SNOOZE_TIMES_1 = 1, + /**< Snooze Repeat : Once */ + ALARM_DB_SNOOZE_TIMES_3 = 3, + /**< Snooze Repeat : 3 times */ + ALARM_DB_SNOOZE_TIMES_5 = 5, + /**< Snooze Repeat : 5 times */ + ALARM_DB_SNOOZE_TIMES_10 = 10, + /**< Snooze Repeat : 10 times */ + }; +/** +* @enum _alarm_db_auto_power_onoff_t +* @brief This enumeration defines auto-power on/off . +*/ + enum _alarm_db_auto_power_onoff_t { + ALARM_DB_AUTOPOWER_OFF = 0x00, + /**< Autopower OFF */ + ALARM_DB_AUTOPOWER_ON = 0x01 + /**< Autopower ON */ + }; +/** +* @enum _alarm_db_enabled_t +* @brief This enumeration defines alarm on/off . +*/ + enum _alarm_db_enabled_t { + ALARM_DB_ENABLE_OFF = 0x00, + /**< Alarm OFF */ + ALARM_DB_ENABLE_ON = 0x01 + /**< Alarm ON */ + }; + /** +* @enum _alarm_db_missed_t +* @brief This enumeration defines alarm priority (For internal use). +*/ + enum _alarm_db_missed_t { + ALARM_DB_RESERVED_ALARM = 0x00, /**< Reserved alarm */ + ALARM_DB_LOW_PRIORITY_ALARM = 0x01,/**< Low priority alarm */ + ALARM_DB_MISSED_ALARM = 0x02, /**< Missed alarm */ + ALARM_DB_RESERVED_SNOOZING_ALARM = 0x03, + /**< Reseved Snoozing alarm */ + ALARM_DB_MISSED_SNOOZING_ALARM = 0x04, + /**< Missed snoozing alarm */ + }; + +/** +* @struct alarm_data +* @brief This structure defines alarm information. +*/ + struct alarm_data { + int _magic; /**< magic value for check struct type, + the value is equal to ALARM_DB_MAGIC_VALUE*/ + int id; /**< index of alarm */ + int alarm_mgr_id; /**< index from alarm-manager */ + alarm_db_enabled_t enable; /**< connected with activation in alarm-manager*/ + alarm_db_missed_t missed; /**< for checking missed alarm */ + alarm_db_author_t author; /**< alarm author (alarm/timer/...) */ + char name[ALARM_BUF_LEN]; /**< alarm name */ + time_t stime; /**< start time */ + time_t atime; /**< alert time */ + time_t etime; /**< create or edit time */ + time_t sdate; /**< start date */ + time_t edate; /**< end date */ + char timezone[ALARM_BUF_LEN]; /**< time zone id */ + bool repeat_once; /**< repeat once */ + bool repeat_every; /**< repeat everyday */ + alarm_db_repeat_t repeat_weekly; /**< repeat weekly */ + bool snooze_enable; /**< snooze enable */ + alarm_db_snooze_duration_t snooze_min; /**< snooze time */ + alarm_db_snooze_repeat_t snooze_times; /**< snooze repeat */ + char count; /**< count of snoozing times */ + alarm_db_type_t type; /**< alarm type */ + char tone[ALARM_BUF_LEN]; /**< alarm tone file */ + unsigned char volume; /**< volume level */ + alarm_db_auto_power_onoff_t auto_power_on; /**< use autopower on */ + }; +/** + * @struct alarm_data_list + * @brief List for Alarm data + */ + struct alarm_data_list { + struct alarm_data ad; /**< Alarm data */ + struct alarm_data_list *prev; + /**< Previous list */ + struct alarm_data_list *next; + /**< Next list */ + }; + +/** + * This function init alarm database, create db file to the @param dbfile if the dbfile is not null. + * If the file path is NULL, the db file will be created to the default path. + * + * @brief Initialize Alarm-Database + * + * @param [in] dbfile the path of user defined. + * + * @return On success, 0 is returned. On error, -1 is returned + * + * @remarks The function must be called fristly before calling other functions of alarm-db. + * + * @exception + * + * @see alarmdb_fini + * + */ + A_DBAPI int alarmdb_init(const char *dbfile); + +/** + * This function fini alarm database, it will close db and free db resource + * + * @brief Finialize Alarm-Database + * + * @param none + * + * @return None + * + * @remarks The function must be called finally when the application don't need db + * + * @exception + * + * @see alarmdb_init + * + */ + A_DBAPI void alarmdb_fini(void); + +/** + * This function create a pointer to AData. + * The function must be called after alarmdb_init() + * + * @brief Create alarm data structure, Ref: alarmdb_free_data() + * + * @param None + * + * @return This function returns a pointer of alarm_data on success or NULL on failure. + * + * @remarks + * + * @exception + * + * @see alarmdb_free_data + * + */ + A_DBAPI AData *alarmdb_create_data(void); + +/** + * This function gets the data of the alarm assosiated with alarm_id. + * It will connect to db and search by id. + * + * + * @brief Get a data from id + * + * @param [in] id the Database id of the alarm + * + * @return This function returns a pointer of alarm_data on success or NULL on failure. + * + * @remarks The function must be called after alarmdb_init(), and also given the correct id. + * + * @exception + * + * @see alarmdb_get_data_by_author alarmdb_get_data_list_by_author + * + */ + A_DBAPI AData *alarmdb_get_data(int id); + +/** + * This function gets the data of the alarm assosiated with alarm_id and auchor_id. + * The function must be called after alarmdb_init(), and also given the correct author. + * + * @brief Get a data from id and author + * + * @param [in] id the Database id of the alarm + * @param [in] author the author id of the alarm: + * ALARM_DB_AUTHOR_ALARM/ALARM_DB_AUTHOR_TIMER/ALARM_DB_AUTHOR_POWEROFF_ALARM + * + * @return This function returns a pointer of alarm_data on success or NULL on failure. + * @remarks + * + * @exception + * + * @see alarmdb_get_data alarmdb_get_data_list_by_author + * + */ + A_DBAPI AData *alarmdb_get_data_by_author(int id, char author); + +/** + * This function free the data: AData. + * The function must be called after alarmdb_create_data() + * + * @brief Free data struct + * + * @param [in] a pointer to AData* + * + * @return None + * + * @remarks When application don't need the alarm_data, must call the function to free the memory + * + * @exception + * + * @see alarmdb_create_data + * + */ + A_DBAPI void alarmdb_free_data(AData *); + +/** + * This function add the data: AData. + * This function is usually called together with alarmmgr_create(); + * + * @brief Insert a data to DB + * + * @param [in] a pointer to AData* + * + * @return This function returns the id,saved db id (int), if success, the int value >-1, else return -1. + * + * @remarks + * + * @exception + * + * @see alarmdb_mod_data alarmdb_del_data + * + */ + A_DBAPI int alarmdb_add_data(AData *); + +/** + * This function modify the data: AData. + * This function is usually called together with alarmmgr_update(); + * + * @brief Update a data to DB + * + * @param [in] a pointer to AData* + * + * @return This function returns the id,saved db id (int), if success, the int value >-1, else return -1. + * + * @remarks + * + * @exception + * + * @see alarmdb_add_data alarmdb_del_data + * + */ + A_DBAPI int alarmdb_mod_data(AData *); + +/** + * This function delete the data assosiated with alarm_id. + * This function is usually called together with alarmmgr_delete(); + * + * @brief Delete a data to DB + * + * @param [in] id db field + * + * @return This function returns 0 on success or -1 on fail + * + * @remarks + * + * @exception + * + * @see alarmdb_add_data alarmdb_mod_data + * + */ + A_DBAPI int alarmdb_del_data(int id); + +/** + * This function update the alarm is enable/disable. + * This function is usually called together with alarmmgr_update(); + * + * @brief Set enable/disable an alarm + * + * @param [in] id: id db field + * [in] enable: true->enable, false->disable + * + * @return This function returns 0 on success or -1 on fail + * + * @remarks + * + * @exception + * + * @see alarmdb_get_num_of_enable + * + */ + A_DBAPI int alarmdb_set_enable(int id, bool enable); + +/** + * This function get the number of the enabled alarm. + * This function is usually called together with vconf_set_int(VCONFKEY_ALARM_STATE, @return) + * + * @brief Get number of enabled alarm + * + * @param none + * + * @return This function returns the number of enable's alarm in db on success or -1 on fail + * + * @remarks + * + * @exception + * + * @see alarmdb_set_enable + * + */ + A_DBAPI int alarmdb_get_num_of_enable(void); + +/** + * This function set snooze on an alarm enable or disable + * + * @brief Set enable/disable snooze on an alarm + * + * @param [in] id: id db field + * [in] enable: true->enable, false->disable + * + * @return This function returns 0 on success or -1 on fail + * + * @remarks + * + * @exception + * + * @see + * + */ + A_DBAPI int alarmdb_set_snooze(int id, bool enable); + +/** + * This function get the last alarm id + * + * + * @brief Get last alarm id + * + * @param none + * + * @return This function returns the last alarm_id in db on success, -1 on fail + * + * @remarks + * + * @exception + * + * @see alarmdb_get_last_id_by_author + * + */ + A_DBAPI int alarmdb_get_last_id(void); + +/** + * This function gets the last alarm id assosiated with auchor_id. + * + * + * @brief Get last alarm (generated by specific author) + * + * @param [in] author the author id of the alarm: + * ALARM_DB_AUTHOR_ALARM/ALARM_DB_AUTHOR_TIMER/ALARM_DB_AUTHOR_POWEROFF_ALARM + * + * @return This function returns the last alarm_id in db on success, -1 on fail + * + * @remarks + * + * @exception + * + * @see alarmdb_get_last_id + * + */ + A_DBAPI int alarmdb_get_last_id_by_author(char author); + +/** + * This function get the number of the enabled alarm. + * + * + * @brief Get number of alarm (generated by specific author) + * + * @param [in] author the author id of the alarm: + * ALARM_DB_AUTHOR_ALARM/ALARM_DB_AUTHOR_TIMER/ALARM_DB_AUTHOR_POWEROFF_ALARM + * + * @return This function returns the number of alarm of the author in db on success , -1 on fail + * + * @remarks + * + * @exception + * + * @see + * + */ + A_DBAPI int alarmdb_get_number_of_data_by_author(char author); + +/** + * This function gets the data list of the alarm assosiated with auchor_id. + * The function can be called after alarmdb_init(), and also given the correct author. + * + * @brief Get power on/off value (generated by specific author) + * + * @param [in] author the author id of the alarm: + * ALARM_DB_AUTHOR_ALARM/ALARM_DB_AUTHOR_TIMER/ALARM_DB_AUTHOR_POWEROFF_ALARM + * + * @return This function returns the state of alarm auto-power state, + * enum alarm_auto_power_onoff_t: ALARM_DB_AUTOPOWER_OFF/ALARM_DB_AUTOPOWER_ON + * @remarks + * + * @exception + * + * @see enum:alarm_auto_power_onoff_t + * + */ + A_DBAPI int alarmdb_get_power_onoff_by_author(char author); + +/** + * This function gets the data list of the alarm assosiated. + * + * + * @brief Get all alarm list + * + * @param none + * + * @return This function returns a pointer of alarm_data_list on success or NULL on failure. + * + * @remarks + * + * @exception + * + * @see alarmdb_get_data_list_by_author + * + */ + A_DBAPI ADList *alarmdb_get_data_list_all(void); + +/** + * This function gets the data list of the alarm assosiated with auchor_id. + * The function can be called after alarmdb_init(), and also given the correct author. + * + * @brief Get alarm list(generated by specific author) + * + * @param [in] author the author id of the alarm: + * ALARM_DB_AUTHOR_ALARM/ALARM_DB_AUTHOR_TIMER/ALARM_DB_AUTHOR_POWEROFF_ALARM + * + * @return This function returns a pointer of alarm_data_list on success or NULL on failure. + * @remarks + * + * @exception + * + * @see alarmdb_get_data_list_all + * + */ + A_DBAPI ADList *alarmdb_get_data_list_by_author(char author); + +/** + * This function free the data list of ADList + * This function must be called when not being needed, if application call + * alarmdb_get_data_list_by_author/alarmdb_get_data_list_all. + * + * @brief Free data list + * + * @param [in] pointer of alarm_data_list + * + * @return None + * + * @remarks + * + * @exception + * + * @see alarmdb_get_data_list_all alarmdb_get_data_list_by_author + * + */ + A_DBAPI void alarmdb_free_data_list(ADList *); + +#ifdef __cplusplus +} +#endif +#endif /* __ALARM_ENGINE_H__ */ diff --git a/include/db-define.h b/include/db-define.h new file mode 100644 index 0000000..ff12283 --- /dev/null +++ b/include/db-define.h @@ -0,0 +1,43 @@ +/* +* +* Copyright 2012 Samsung Electronics Co., Ltd +* +* Licensed under the Flora License, Version 1.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://floralicense.org/license/ +* +* 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. +* +*/ +#ifndef __DB_DEFINE_H__ +#define __DB_DEFINE_H__ + +#include "db-dlog.h" +#include <stdlib.h> +#include <string.h> +#include <libintl.h> +#include <glib.h> +//tag +#ifdef LOG_TAG +#undef LOG_TAG +#endif +#define LOG_TAG "DB_ALARM" +// +#define DBROOT "/opt/dbspace/" +#define DBNAME ".alarm.db" +// +#define DBHandle sqlite3 +//equal +#define IS_EQUAL(a, b) ((a) == (b)) +#define IS_STR_EQUAL(a, b) (!strcmp(a, b)) +//******************define:free ************************************* +#define FREEIF(p) if (p) {free(p); p = NULL; } +#define GFREEIF(p) if (p) {g_free(p); p = NULL; } + +#endif //__DB_DEFINE_H__ diff --git a/include/db-dlog.h b/include/db-dlog.h new file mode 100644 index 0000000..4910f1d --- /dev/null +++ b/include/db-dlog.h @@ -0,0 +1,163 @@ +/* +* +* Copyright 2012 Samsung Electronics Co., Ltd +* +* Licensed under the Flora License, Version 1.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://floralicense.org/license/ +* +* 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. +* +*/ +#ifndef __DB_DLOG_H__ +#define __DB_DLOG_H__ + +#include <stdio.h> +#include <assert.h> +#include <dlog.h> +/********************************************************************** +******************define, struct ,typedef, union, enum, global val ************************************* +***********************************************************************/ +#define DB_FUN_BEG() DB_INFO("====>>>>fun=%s, BEGIN====>>>>", __FUNCTION__); +#define DB_FUN_END() DB_INFO("====>>>>fun=%s, END====>>>>", __FUNCTION__); +#define DB_INFO(fmt, arg...) LOGD("[%s:%d] "fmt, __FILE__, __LINE__, ##arg); +#define DB_ERR(fmt, arg...) LOGE(FONT_COLOR_RED"[%s:%d] "fmt FONT_COLOR_RESET, __FILE__, __LINE__, ##arg); + +#define DB_FUN_DEBUG_BEG() //DB_INFO("====>>>>fun=%s, BEGIN====>>>>",__FUNCTION__); +#define DB_FUN_DEBUG_END() //DB_INFO("====>>>>fun=%s, END====>>>>", __FUNCTION__); +#define DB_DEBUG_INFO(fmt, arg...) //DB_INFO(fmt, ##arg) +#define DB_DEBUG_INFO(fmt, arg...) //DB_ERR(fmt,##arg) + +#define DB_RET_IF(expr) \ + do { \ + if (expr) {\ + nErr = FAILED;\ + DB_INFO_RED("!!!!!!!!!!!!!!!!!!!! CHECK nErr=%d!!!!!!! \n(%s)return!!!!!!!!!!!\n\n", nErr, #expr); \ + goto End; \ + } \ + } \ + } while (1); +#define DB_RETV_IF(expr, val) \ + do { \ + if (expr) { \ + nErr = FAILED;\ + ret = val;\ + DB_INFO_RED("!!!!!!!!!!!!!!!!!!!! CHECK nErr=%d!!!!!!! \n(%s)return!!!!!!!!!!!\n\n", nErr, #expr); \ + goto End; \ + } \ + } while (0); +#define DB_RETE_IF(expr, errorId) \ + do { \ + if (expr) { \ + nErr = errorId;\ + DB_INFO_RED("!!!!!!!!!!!!!!!!!!!! CHECK nErr=%d!!!!!!! \n(%s)return!!!!!!!!!!!\n\n", nErr, #expr); \ + goto End; \ + } \ + } while (0); +#define DB_RETEM_IF(expr, errorId, fmt, arg...) \ + do { \ + if (expr) { \ + nErr = errorId;\ + DB_INFO_RED(fmt, ##arg); \ + DB_INFO_RED("!!!!!!!!!!!!!!!!!!!! CHECK nErr=%d!!!!!!! \n(%s)return!!!!!!!!!!!\n\n", nErr, #expr); \ + goto End; \ + } \ + } while (0); +#define DB_RETVE_IF(expr, val, errorId) \ + do { \ + if (expr) { \ + nErr = errorId;\ + ret = val;\ + DB_INFO_RED("!!!!!!!!!!!!!!!!!!!! CHECK nErr=%d!!!!!!! \n(%s)return!!!!!!!!!!!\n\n", nErr, #expr); \ + goto End; \ + } \ + } while (0); +#define DB_RETM_IF(expr, fmt, arg...) \ + do { \ + if (expr) { \ + nErr = FAILED;\ + DB_INFO_RED(fmt, ##arg); \ + DB_INFO_RED("!!!!!!!!!!!!!!!!!!!! CHECK nErr=%d!!!!!!! \n(%s)return!!!!!!!!!!!\n\n", nErr, #expr); \ + goto End; \ + } \ + } while (0); +#define DB_RETVM_IF(expr, val, fmt, arg...) \ + do { \ + if (expr) { \ + nErr = FAILED;\ + ret = val;\ + DB_INFO_RED(fmt, ##arg); \ + DB_INFO_RED("!!!!!!!!!!!!!!!!!!!! CHECK nErr=%d!!!!!!! \n(%s)return!!!!!!!!!!!\n\n", nErr, #expr); \ + goto End; \ + } \ + } while (0); +#define DB_RETVME_IF(expr, val, errorId, fmt, arg...) \ + do { \ + if (expr) { \ + nErr = errorId;\ + ret = val;\ + DB_INFO_RED(fmt, ##arg); \ + DB_INFO_RED("!!!!!!!!!!!!!!!!!!!! CHECK nErr=%d!!!!!!! \n(%s)return!!!!!!!!!!!\n\n", nErr, #expr); \ + goto End; \ + } \ + } while (0); +/* anci c color type */ +#define FONT_COLOR_RESET "\033[0m" +#define FONT_COLOR_RED "\033[31m" +#define FONT_COLOR_GREEN "\033[32m" +#define FONT_COLOR_YELLOW "\033[33m" +#define FONT_COLOR_BLUE "\033[34m" +#define FONT_COLOR_PURPLE "\033[35m" +#define FONT_COLOR_CYAN "\033[36m" +#define FONT_COLOR_GRAY "\033[37m" + +#define DB_INFO_RED(fmt, arg...) DB_INFO(FONT_COLOR_RED fmt FONT_COLOR_RESET, ##arg) +#define DB_INFO_GREEN(fmt, arg...) DB_INFO(FONT_COLOR_GREEN fmt FONT_COLOR_RESET, ##arg) +#define DB_INFO_YELLOW(fmt, arg...) DB_INFO(FONT_COLOR_YELLOW fmt FONT_COLOR_RESET, ##arg) +#define DB_INFO_BLUE(fmt, arg...) DB_INFO(FONT_COLOR_BLUE fmt FONT_COLOR_RESET, ##arg) +#define DB_INFO_PURPLE(fmt, arg...) DB_INFO(FONT_COLOR_PURPLE fmt FONT_COLOR_RESET, ##arg) +#define DB_INFO_GREEN(fmt, arg...) DB_INFO(FONT_COLOR_GREEN fmt FONT_COLOR_RESET, ##arg) +#define DB_INFO_CYAN(fmt, arg...) DB_INFO(FONT_COLOR_CYAN fmt FONT_COLOR_RESET, ##arg) +#define DB_INFO_GRAY(fmt, arg...) DB_INFO(FONT_COLOR_GRAY fmt FONT_COLOR_RESET, ##arg) + +#define DB_INFO_WITH_COLOR(color, fmt, arg...) DB_INFO(color fmt FONT_COLOR_RESET, ##arg) + +// +#define warn_if(expr, fmt, arg...) do { \ + if (expr) { \ + DB_INFO("(%s) -> "fmt, #expr, ##arg); \ + } \ + } while (0) +#define ret_if(expr) do { \ + if (expr) { \ + DB_ERR("(%s) -> %s() return", #expr, __FUNCTION__); \ + return; \ + } \ + } while (0) +#define retv_if(expr, val) do { \ + if (expr) { \ + DB_ERR("(%s) -> %s() return", #expr, __FUNCTION__); \ + return (val); \ + } \ + } while (0) +#define retm_if(expr, fmt, arg...) do { \ + if (expr) { \ + DB_ERR(fmt, ##arg); \ + DB_ERR("(%s) -> %s() return", #expr, __FUNCTION__); \ + return; \ + } \ + } while (0) +#define retvm_if(expr, val, fmt, arg...) do { \ + if (expr) { \ + DB_ERR(fmt, ##arg); \ + DB_ERR("(%s) -> %s() return", #expr, __FUNCTION__); \ + return (val); \ + } \ + } while (0) +#endif //__DB_DLOG_H__ diff --git a/include/db-schema.h b/include/db-schema.h new file mode 100644 index 0000000..284055a --- /dev/null +++ b/include/db-schema.h @@ -0,0 +1,51 @@ +/* +* +* Copyright 2012 Samsung Electronics Co., Ltd +* +* Licensed under the Flora License, Version 1.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://floralicense.org/license/ +* +* 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. +* +*/ +#ifndef __ALARM_SCHEMA_H__ +#define __ALARM_SCHEMA_H__ + +#include <db-util.h> + +#define CREATE_ALARM_TABLE " \ + create table if not exists alarm ( \ + id INTEGER PRIMARY KEY autoincrement, \ + magic INTEGER, \ + alarm_mgr_id INTEGER, \ + enable INTEGER, \ + missed INTEGER, \ + author INTEGER, \ + name TEXT, \ + stime INTEGER, \ + atime INTEGER, \ + etime INTEGER, \ + sdate INTEGER, \ + edate INTEGER, \ + timezone TEXT, \ + repeat_once INTEGER, \ + repeat_every INTEGER, \ + repeat_weekly INTEGER, \ + snooze_enable INTEGER, \ + snooze_min INTEGER, \ + snooze_times INTEGER, \ + count INTEGER, \ + type INTEGER, \ + tone TEXT, \ + volume INTEGER, \ + auto_power_on INTEGER \ + );" + +#endif /* __ALARM_SCHEMA_H__ */ diff --git a/include/db.h b/include/db.h new file mode 100644 index 0000000..f52a1e0 --- /dev/null +++ b/include/db.h @@ -0,0 +1,175 @@ +/* +* +* Copyright 2012 Samsung Electronics Co., Ltd +* +* Licensed under the Flora License, Version 1.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://floralicense.org/license/ +* +* 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. +* +*/ +#ifndef __ALARM_DB_H__ +#define __ALARM_DB_H__ + +#include <db-util.h> +#include "alarm-engine.h" + +/** + * This function opens a connection to database. + * @return This function returns database handler. + * @param[in] char* Path of database file to open. + */ +sqlite3 *db_init(char *); + +/** + * This function closes a connection with database. + * @param[in] sqlite3* Pointer of database handler. + */ +void db_fini(sqlite3 *); + +/** + * This function inserts the alarm data in database. + * + * @return This function returns id of alarm data. + * @param[in] sqlite3* Pointer to database handler. + * @param[in] struct alarm_data* Pointer to structure alarm_data to insert. + */ +int insert_data(sqlite3 *, struct alarm_data *); + +/** + * This function updates the alarm data in database. + * + * @return This function returns id of alarm data. + * @param[in] sqlite3* Pointer to database handler. + * @param[in] struct alarm_data* Pointer to structure alarm_data to update. + */ +int update_data(sqlite3 *, struct alarm_data *); + +/** + * This function removes the alarm data in database. + * + * @return This function returns id of alarm data. + * @param[in] sqlite3* Pointer to database handler. + * @param[in] struct alarm_data* Pointer to structure alarm_data to remove. + */ +int remove_data(sqlite3 *, int id); + +/** + * This function removes all of alarm data in database. + * + * @return This function returns id of alarm data. + * @param[in] sqlite3* Pointer to database handler. + */ +int remove_all_data(sqlite3 *); + +/** + * This function gets the alarm data in database by index of alarm data. + * + * @return This function returns id of alarm data. + * @param[in] sqlite3* Pointer to database handler. + * @param[in] int Index of alarm data to get. + * @param[in] struct alarm_data* Pointer to structure alarm_data to get. + */ +int get_data(sqlite3 *, int, struct alarm_data *); + +/** + * This function gets the alarm data in database by index & author of alarm data. + * + * @return This function returns id of alarm data. + * @param[in] sqlite3* Pointer to database handler. + * @param[in] int Index of alarm data to get. + * @param[in] struct alarm_data* Pointer to structure alarm_data to get. + * @param[in] char author Author of alarm data to get. + */ +int get_data_by_author(sqlite3 *, int, struct alarm_data *, char author); + +/** + * This function updates enable flag of the alarm data in database. + * + * @return This function returns id of alarm data. + * @param[in] sqlite3* Pointer to database handler. + * @param[in] int Index of alarm data to get. + * @param[in] bool Bool value where alarm enable. + */ +int update_enable(sqlite3 *, int id, bool enable); + +/** + * This function updates snooze flag of the alarm data in database. + * + * @return This function returns id of alarm data. + * @param[in] sqlite3* Pointer to database handler. + * @param[in] int Index of alarm data to get. + * @param[in] bool Bool value where alarm snooze enable. + */ +int update_snooze(sqlite3 *, int id, bool enable); + +/** + * This function gets list has all of the alarm data in database. + * + * @return This function returns pointer of alarm data list. + * @param[in] sqlite3* Pointer to database handler. + */ +struct alarm_data_list *get_data_list_all(sqlite3 *); + +/** + * This function gets list has all of the alarm data in database. + * + * @return This function returns pointer of alarm data list. + * @param[in] sqlite3* Pointer to database handler. + * @param[in] char Author of alarm data. + */ +struct alarm_data_list *get_data_list_by_author(sqlite3 *, char); + +/** + * This function gets index of last alarm data in database. + * + * @return This function returns index of the last alarm data. + * @param[in] sqlite3* db Pointer to database handler. + */ +int get_last_id(sqlite3 *db); + +/** + * This function gets index of last alarm data in database by author of alarm data. + * + * @return This function returns index of the last alarm data. + * @param[in] sqlite3* db Pointer to database handler. + * @param[in] char Author of alarm data. + */ +int get_last_id_by_author(sqlite3 *db, char author); + +/** + * This function gets number of alarm data in database by author of alarm data. + * + * @return This function returns number of the alarm data. + * @param[in] sqlite3* db Pointer to database handler. + * @param[in] char Author of alarm data. + */ +int get_number_of_data_by_author(sqlite3 *db, char author); + +/* int get_poweron_by_author(sqlite3 *db, char author); */ + +/** + * This function gets number of enabled alarm in database by db pointer + * + * @return This function returns number of the enabled alarm + * @param[in] sqlite3* db Pointer to database handler. + */ +int get_num_of_enable(sqlite3 *db); + +/** + * This function gets power_on flag of alarm data in database by author of alarm data. + * + * @return This function returns number of the alarm data. + * @param[in] sqlite3* db Pointer to database handler. + * @param[in] char Author of alarm data. + */ +int get_power_onoff_by_author(sqlite3 *db, char author); + +#endif /* __ALARM_DB_H__ */ diff --git a/include/libalarm.h b/include/libalarm.h new file mode 100644 index 0000000..84e1087 --- /dev/null +++ b/include/libalarm.h @@ -0,0 +1,25 @@ +/* +* +* Copyright 2012 Samsung Electronics Co., Ltd +* +* Licensed under the Flora License, Version 1.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://floralicense.org/license/ +* +* 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. +* +*/ +#ifndef __LIBALARM_H__ +#define __LIBALARM_H__ + +#include "alarm-engine.h" +#include "db-define.h" +#include "db.h" + +#endif //__LIBALARM_H__ |