diff options
author | Chandan <ch.kumar@samsung.com> | 2016-08-22 17:11:14 +0530 |
---|---|---|
committer | Chandan <ch.kumar@samsung.com> | 2016-08-29 17:36:25 +0530 |
commit | b955d8921b288a913f207d98c2d0872a1f2701f3 (patch) | |
tree | 6b46758736079736842222ff225884929cbe85ca /src/doc-db-update.c | |
parent | a35a819d0bfb948ef857f0d7bd0fc6f4620b6160 (diff) | |
download | attach-panel-document-b955d8921b288a913f207d98c2d0872a1f2701f3.tar.gz attach-panel-document-b955d8921b288a913f207d98c2d0872a1f2701f3.tar.bz2 attach-panel-document-b955d8921b288a913f207d98c2d0872a1f2701f3.zip |
Implemented the Basic functionalities
Change-Id: I7a766ec0c33496b62003b52fc35a70a1878a6c0d
Signed-off-by: Chandan <ch.kumar@samsung.com>
Diffstat (limited to 'src/doc-db-update.c')
-rw-r--r-- | src/doc-db-update.c | 187 |
1 files changed, 187 insertions, 0 deletions
diff --git a/src/doc-db-update.c b/src/doc-db-update.c new file mode 100644 index 0000000..c983834 --- /dev/null +++ b/src/doc-db-update.c @@ -0,0 +1,187 @@ +/* +* Copyright (c) 2000-2015 Samsung Electronics Co., Ltd All Rights Reserved +* +* Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0 +* +* 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. +* +*/ + +#include <media_content.h> +#include "attach-panel-document.h" +#include "doc-data.h" +#include "doc-local-data.h" +#include "doc-util.h" +#include "doc-debug.h" + +#define DOC_MONITOE_TIME_DELAY 1.0f + +struct doc_db_noti_t { + Ecore_Timer *db_timer; /*For update db data*/ + /*Make ture calling db update callback after other operations complete*/ + Ecore_Idler *db_idl; + //media_content_noti_h cloud_h; /* Notify handle fro cloud content updating in DB */ + media_content_db_update_item_type_e update_item; + media_content_db_update_type_e update_type; + int count; /* All media count got from DB */ +}; + +static Eina_Bool _doc_db_update_idler(void *data) +{ + DOC_CHECK_FALSE(data); + doc_ugdata *ugd = (doc_ugdata *)data; + DOC_CHECK_FALSE(ugd->db_noti_d); + doc_db_noti_s *db_noti = ugd->db_noti_d; + doc_update_view(ugd, DOC_UPDATE_VIEW_INOTIFY); + DOC_IF_DEL_IDLER(db_noti->db_idl); + return ECORE_CALLBACK_CANCEL; +} + +static Eina_Bool _doc_db_update_timer_cb(void *data) +{ + DOC_CHECK_FALSE(data); + doc_ugdata *ugd = (doc_ugdata *)data; + DOC_CHECK_FALSE(ugd->db_noti_d); + doc_db_noti_s *db_noti = ugd->db_noti_d; + + DOC_IF_DEL_IDLER(db_noti->db_idl); + db_noti->db_idl = ecore_idler_add(_doc_db_update_idler, data); + + DOC_IF_DEL_TIMER(db_noti->db_timer); + return ECORE_CALLBACK_CANCEL; +} + +static int _doc_db_update_add_timer(doc_ugdata *ugd) +{ + DOC_CHECK_VAL(ugd, -1); + DOC_CHECK_VAL(ugd->db_noti_d, -1); + doc_db_noti_s *db_noti = ugd->db_noti_d; + + DOC_IF_DEL_TIMER(db_noti->db_timer); + db_noti->db_timer = ecore_timer_add(DOC_MONITOE_TIME_DELAY, + _doc_db_update_timer_cb, ugd); + doc_dbgW("TIMER[1.0f] added!"); + return 0; +} + +static int _doc_db_update_op(media_content_error_e error, int pid, + media_content_db_update_item_type_e update_item, + media_content_db_update_type_e update_type, + media_content_type_e media_type, char *uuid, + char *path, char *mime_type, void *data) +{ + DOC_CHECK_VAL(data, -1); + doc_ugdata *ugd = (doc_ugdata *)data; + DOC_CHECK_VAL(ugd->db_noti_d, -1); + doc_db_noti_s *db_noti = ugd->db_noti_d; + + if (MEDIA_CONTENT_ERROR_NONE != error) { + doc_dbgE("Update db error[%d]!", error); + return -1; + } + if (update_item == MEDIA_ITEM_FILE && + MEDIA_CONTENT_TYPE_OTHERS != media_type) { + doc_dbg("Media type is wrong"); + return -1; + } else if (update_item == MEDIA_ITEM_DIRECTORY && media_type == -1) { + /* Batch operation, DB wouldn't return media type */ + int cnt = 0; + int ret = -1; + ret = doc_data_get_item_cnt(ugd, &cnt); + if (ret != 0 || cnt == 0) { + doc_dbgE("Empty!"); + } + doc_dbg("old: %d, new: %d", db_noti->count, cnt); + if (cnt == db_noti->count) { + doc_dbg("Nothing changed"); + if (path && + !strcmp(path, DOC_ROOT_PATH_MMC)) { + doc_dbg("MMC insert or remove!"); + } else if (path) { + doc_folder_s *album = NULL; + doc_local_data_get_folder_by_path(path, &album); + if (!album) { + return -1; + } else { + doc_data_type_free_geitem((void **)&album); + doc_dbgW("Updated album contains images"); + } + } else { + return -1; + } + } else { + db_noti->count = cnt; + } + } + + db_noti->update_item = update_item; + db_noti->update_type = update_type; + + _doc_db_update_add_timer(ugd); + return 0; +} + +static void _doc_db_update_cb(media_content_error_e error, int pid, + media_content_db_update_item_type_e update_item, + media_content_db_update_type_e update_type, + media_content_type_e media_type, char *uuid, + char *path, char *mime_type, void *data) +{ + doc_dbg("update_item[%d], update_type[%d], media_type[%d]", update_item, + update_type, media_type); + DOC_CHECK(data); + doc_dbg("uuid[%s], path[%s]", uuid, path); + _doc_db_update_op(error, pid, update_item, update_type, media_type, + uuid, path, mime_type, data); +} + +bool doc_db_update_reg_cb(doc_ugdata *ugd) +{ + DOC_CHECK_FALSE(ugd); + /*Init data*/ + doc_db_noti_s *db_noti = (doc_db_noti_s *)calloc(1, sizeof(doc_db_noti_s)); + DOC_CHECK_FALSE(db_noti); + ugd->db_noti_d = db_noti; + + int cnt = 0; + doc_data_get_item_cnt(ugd, &cnt); + db_noti->count = cnt; + + int ret = -1; + + doc_dbg("Set db updated callback"); + ret = media_content_set_db_updated_cb(_doc_db_update_cb, ugd); + if (ret != MEDIA_CONTENT_ERROR_NONE) { + doc_dbgE("Set db updated cb failed[%d]!", ret); + } + return true; +} + +bool doc_db_update_finalize(doc_ugdata *ugd) +{ + int ret = -1; + doc_dbg("Unset db updated callback"); + + ret = media_content_unset_db_updated_cb(); + if (ret != MEDIA_CONTENT_ERROR_NONE) { + doc_dbgE("UNSet db updated cb failed[%d]!", ret); + } + + DOC_CHECK_FALSE(ugd); + DOC_CHECK_FALSE(ugd->db_noti_d); + doc_db_noti_s *db_noti = ugd->db_noti_d; + + DOC_IF_DEL_TIMER(db_noti->db_timer); + DOC_IF_DEL_IDLER(db_noti->db_idl); + DOC_FREE(ugd->db_noti_d); + return true; +} + |