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.
31 #define MEMOAPI __attribute__ ((visibility("default")))
34 #define DB_PREFIX_PATH "/opt/dbspace"
35 #define DBNAME ".memo.db"
37 static void (*g_data_monitor) (void *) = NULL;
38 static int trans_count = 0;
40 static int ref_count = 0;
42 /******************************
44 *******************************/
46 * @fn int memo_init(char *dbfile)
47 * @brief initialize memo db library
48 * @param[in] dbfile db file path
49 * @return Return 0 (Success) or -1 (Failed)
51 MEMOAPI int memo_init(char *dbfile)
54 char defname[PATH_MAX];
65 snprintf(defname, sizeof(defname), "%s/%s",
66 DB_PREFIX_PATH, DBNAME);
70 DBG("DB name : %s", name);
72 retv_if(db == NULL, -1);
78 * @fn void memo_fini(void)
79 * @brief terminate memo db library
82 MEMOAPI void memo_fini(void)
92 * @fn struct memo_data* memo_create_data()
93 * @brief create memo data struct
94 * @return The pointer of created memo data
96 MEMOAPI struct memo_data* memo_create_data()
98 return (struct memo_data *)calloc(1, sizeof(struct memo_data));
102 * @fn struct memo_data* memo_get_data(int id)
103 * @brief Get memo data with specific id
104 * @param[in] id db id
105 * @return The pointer of memo data struct
107 MEMOAPI struct memo_data* memo_get_data(int id)
110 struct memo_data *md;
112 retvm_if(db == NULL, NULL, "DB Handle is null, need memo_init");
113 retvm_if(id < 1, NULL, "Invalid memo data id : %d", id);
115 md = memo_create_data();
116 retv_if(md == NULL, md);
118 rc = get_data(db, id, md);
128 * @fn void memo_free_data(struct memo_data *md)
129 * @brief deallocate memo data
130 * @param[in] md memo data
133 MEMOAPI void memo_free_data(struct memo_data *md)
144 free(md->doodle_path);
150 * @fn int memo_add_data(struct memo_data *md)
151 * @brief insert memo data
152 * @param[in] md memo data struct
153 * @return Return id (Success) or -1 (Failed)
155 MEMOAPI int memo_add_data(struct memo_data *md)
157 retvm_if(db == NULL, -1, "DB Handle is null, need memo_init");
158 return insert_data(db, md);
162 * @fn int memo_mod_data(struct memo_data *md)
163 * @brief Update data in DB
164 * @param[in] md The pointer of memo data
165 * @return Return 0 (Success) or -1 (Failed)
167 MEMOAPI int memo_mod_data(struct memo_data *md)
169 retvm_if(db == NULL, -1, "DB Handle is null, need memo_init");
170 retvm_if(md == NULL, -1, "Update data is null");
171 retvm_if(md->id < 1, -1, "Invalid memo data ID");
172 return update_data(db, md);
176 * @fn int memo_del_data(int id)
177 * @brief remove data of specific id from DB
178 * @param[in] id db id
179 * @return Return 0 (Success) or -1 (Failed)
181 MEMOAPI int memo_del_data(int id)
184 retvm_if(db == NULL, -1, "DB Handle is null, need memo_init");
185 retvm_if(id < 1, -1, "Invalid memo data ID");
186 memo_data_t *md = memo_get_data(id);
188 if(md->has_doodle == 1) {
189 snprintf(buf, 128, "/opt/usr/apps/org.tizen.memo/data/doodle/%d.png", id);
190 if(remove(buf) != 0) {
191 ERR("Remove file error\n");
197 return remove_data(db, id);
201 * @fn struct memo_data_list* memo_get_all_data_list()
202 * @brief Get the all data list
203 * @return the header of struct memo_data_list linked list
205 MEMOAPI struct memo_data_list* memo_get_all_data_list(void)
207 struct memo_data_list *mdl;
209 retvm_if(db == NULL, NULL, "DB Handle is null, need memo_init");
211 mdl = get_all_data_list(db);
216 * @fn void memo_free_data_list(struct memo_data_list *mdl)
217 * @brief deallocate memo data list
218 * @param[in] mdl the pointer of memo_data_list struct
221 MEMOAPI void memo_free_data_list(struct memo_data_list *mdl)
223 struct memo_data_list *t, *d;
229 if(d->md.content) free(d->md.content);
235 * @fn time_t memo_get_modified_time(int id)
236 * @brief Get modified time
237 * @param[in] id db id
238 * @return modified time
240 MEMOAPI time_t memo_get_modified_time(int id)
242 retvm_if(db == NULL, -1, "DB Handle is null, need memo_init");
244 return get_modtime(db, id);
248 * @fn int memo_get_count(int *count)
249 * @brief Get number of memo
250 * @return 0 on success
253 * Requested by widget memo
254 * Added by jy.Lee (jaeyong911.lee@samsung.com)
256 MEMOAPI int memo_get_count(int *count)
259 retvm_if(db == NULL, -1, "DB Handle is null, need memo_init");
260 retvm_if(count == NULL, -1, "count pointer is null");
262 rc = get_data_count(db, count);
270 MEMOAPI struct memo_operation_list* memo_get_operation_list(time_t stamp)
272 struct memo_operation_list *mol;
274 retvm_if(db == NULL, NULL, "DB Handle is null, need memo_init");
276 mol = get_operation_list(db, stamp);
280 MEMOAPI void memo_free_operation_list(struct memo_operation_list *mol)
282 struct memo_operation_list *t, *d;
292 static void _on_data_change(keynode_t *node, void *user_data)
294 if (g_data_monitor != NULL) {
295 g_data_monitor(user_data);
299 MEMOAPI int memo_subscribe_change(void (*cb)(void *), void *user_data)
302 vconf_notify_key_changed(VCONFKEY_MEMO_DATA_CHANGE, _on_data_change, user_data);
306 MEMOAPI int memo_unsubscribe_change(void (*cb)(void *))
308 vconf_ignore_key_changed(VCONFKEY_MEMO_DATA_CHANGE, _on_data_change);
309 g_data_monitor = NULL;
313 MEMOAPI void memo_begin_trans(void)
318 MEMOAPI void memo_end_trans(void)
322 if (trans_count == 0) {
323 if(vconf_get_int(VCONFKEY_MEMO_DATA_CHANGE, &value)) {
324 LOGD("vconf_get_int FAIL\n");
327 vconf_set_int(VCONFKEY_MEMO_DATA_CHANGE, 1);
329 vconf_set_int(VCONFKEY_MEMO_DATA_CHANGE, 0);
335 MEMOAPI int memo_get_indexes(int *aIndex, int len, MEMO_SORT_TYPE sort)
337 return get_indexes(db, aIndex, len, sort);
340 MEMOAPI int memo_search_data(const char *search_str, int limit, int offset, MEMO_SORT_TYPE sort,
341 memo_data_iterate_cb_t cb, void *user_data)
343 return search_data(db, search_str, limit, offset, sort, cb, user_data);
346 MEMOAPI int memo_all_data(memo_data_iterate_cb_t cb, void *user_data)
348 return all_data(db, cb, user_data);