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.
21 /**********************************************************************
22 ******************define, struct ,typedef, union, enum, global val *************************************
23 ***********************************************************************/
26 #define COMP_FUNC(type) \
27 int __cmp_##type##_(type * d1, type * d2) \
29 if (d1->ad.id == 0 && d2->ad.id == 0) return -1; \
30 return (d1->ad.id - d2->ad.id); \
33 /**********************************************************************
34 ******************Local function declear, extern function declear*************************************
35 ***********************************************************************/
37 /**********************************************************************
38 ******************Global val , static global val*************************************
39 ***********************************************************************/
41 /**********************************************************************
42 ******************Local function ref*************************************
43 ***********************************************************************/
44 static DBHandle *db = NULL;
46 /**********************************************************************
47 ******************Global function ref*************************************
48 ***********************************************************************/
51 A_DBAPI int alarmdb_init(const char *dbfile)
54 char defname[PATH_MAX] = { 0, };
57 DB_INFO("Already initialized");
61 name = (char *)dbfile;
63 snprintf(defname, sizeof(defname), "%s/%s", DBROOT, DBNAME);
66 DB_INFO("DB name : %s", name);
68 retv_if(db == NULL, -1);
73 A_DBAPI void alarmdb_fini(void)
82 A_DBAPI struct alarm_data *alarmdb_create_data(void)
84 AData *ad = (struct alarm_data *)calloc(1, sizeof(struct alarm_data));
89 memset(ad, 0, sizeof(AData));
90 MAGIC_VALUE_SET(ad->_magic);
95 A_DBAPI struct alarm_data *alarmdb_get_data(int id)
98 struct alarm_data *ad = NULL;
100 retvm_if(db == NULL, NULL, "DB handler is NULL, needs alarm_init");
101 retvm_if(id < 1, NULL, "Invalid alarm data id");
103 ad = alarmdb_create_data();
104 retv_if(ad == NULL, NULL);
106 rc = get_data(db, id, ad);
108 alarmdb_free_data(ad);
115 A_DBAPI struct alarm_data *alarmdb_get_data_by_author(int id, char author)
118 struct alarm_data *ad = NULL;
120 retvm_if(db == NULL, NULL, "DB handler is NULL, needs alarm_init");
121 retvm_if(id < 1, NULL, "Invalid alarm data id");
123 ad = alarmdb_create_data();
124 retv_if(ad == NULL, NULL);
126 rc = get_data_by_author(db, id, ad, author);
128 alarmdb_free_data(ad);
135 A_DBAPI void alarmdb_free_data(struct alarm_data *ad)
137 retm_if(ad == NULL, "alarm data is NULL\n");
138 retm_if(!MAGIC_VALUE_CHECK(ad->_magic),
139 "alarm data is error, ad->_magic=%d,ALARM_DB_MAGIC_VALUE=%d\n",
140 ad->_magic, ALARM_DB_MAGIC_VALUE);
147 A_DBAPI int alarmdb_add_data(struct alarm_data *ad)
149 retvm_if(db == NULL, -1, "DB handler is NULL, needs alarm_init");
150 return insert_data(db, ad);
154 A_DBAPI int alarmdb_mod_data(struct alarm_data *ad)
156 retvm_if(db == NULL, -1, "DB handler is NULL, needs alarm_init");
157 return update_data(db, ad);
161 A_DBAPI int alarmdb_del_data(int id)
163 retvm_if(db == NULL, -1, "DB handler is NULL, needs alarm_init");
164 retvm_if(id < 1, -1, "Invalid alarm data id");
165 return remove_data(db, id);
169 A_DBAPI int alarmdb_set_enable(int id, bool enable)
171 retvm_if(db == NULL, -1, "DB handler is NULL, needs alarm_init");
172 return update_enable(db, id, enable);
176 A_DBAPI int alarmdb_get_num_of_enable(void)
178 retvm_if(db == NULL, -1, "DB handler is NULL, needs alarm_init");
179 return get_num_of_enable((sqlite3 *)db);
183 A_DBAPI int alarmdb_set_snooze(int id, bool enable)
185 retvm_if(db == NULL, -1, "DB handler is NULL, needs alarm_init");
186 return update_snooze((db), id, enable);
190 A_DBAPI struct alarm_data_list *alarmdb_get_data_list_all(void)
192 retvm_if(db == NULL, NULL, "DB handler is NULL, needs alarm_init");
193 return get_data_list_all(db);
197 A_DBAPI struct alarm_data_list *alarmdb_get_data_list_by_author(char author)
199 retvm_if(db == NULL, NULL, "DB handler is NULL, needs alarm_init");
200 return get_data_list_by_author(db, author);
204 A_DBAPI void alarmdb_free_data_list(struct alarm_data_list *adl)
206 struct alarm_data_list *d = NULL;
207 struct alarm_data_list *t = NULL;
209 retm_if(adl == NULL, "Invalid argument: alarm data list is NULL\n");
219 A_DBAPI int alarmdb_get_last_id(void)
221 return get_last_id(db);
225 A_DBAPI int alarmdb_get_last_id_by_author(char author)
227 return get_last_id_by_author(db, author);
231 A_DBAPI int alarmdb_get_number_of_data_by_author(char author)
233 return get_number_of_data_by_author(db, author);
237 A_DBAPI int alarmdb_get_power_on_by_author(char author)
239 return get_poweron_by_author(db, author);
243 A_DBAPI int alarmdb_get_power_onoff_by_author(char author)
245 return get_power_onoff_by_author(db, author);