3 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * Licensed under the Apache License, Version 2.0 (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://www.apache.org/licenses/LICENSE-2.0
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.
18 #include "utility/sync_util.h"
19 #include "data-adapter/common.h"
20 #include "data-adapter/agent_handler_manager.h"
21 #include "data-adapter/agent_handler_manager_internal.h"
23 #include "device-manager/mo_database.h"
25 #include "device-manager/mo_database_handler.h"
27 #ifndef SYNC_AGENT_LOG
29 #define LOG_TAG "AF_MO"
32 static dm_mo_handler_mgr_s *pMoDBHandlerMgr = NULL;
34 /* static function define */
35 static sync_agent_dm_mo_error_e _add_agent_handler(unsigned int key, SYNC_AGENT_DA_MO_HANDLER * pHandler);
36 static sync_agent_dm_mo_error_e _remove_agent_handler(unsigned int key);
37 static SYNC_AGENT_DA_MO_HANDLER *_get_agent_handler(unsigned int key);
38 static sync_agent_dm_mo_error_e __alloc_agent_dc_handlerTable(void);
39 static sync_agent_dm_mo_error_e _alloc_agent_dc_handlerTable_mutex(void);
40 static sync_agent_dm_mo_error_e _free_agent_dc_handlerTable(void);
41 static sync_agent_dm_mo_error_e _free_agent_dc_handlerTable_mutex(void);
42 static sync_agent_dm_mo_error_e _create_agentDBHandlerMgrInfo(void);
43 static void __destroy_agentDBHashTableValue(void *pHandler);
44 static void __destory_agentDBHashTableKey(void *key);
46 /* general function implementation */
48 * ==================================
49 * external API (1. about agent db handler mgr)
50 * ==================================
52 sync_agent_dm_mo_error_e dm_mo_alloc_modb_handler_mgr(void)
56 _DEBUG_INFO("[%s] start !\n", __func__);
57 sync_agent_dm_mo_error_e ret = SYNC_AGENT_DM_MO_SUCCESS;
59 /* alloc the agentDBHandlerMgr */
60 pMoDBHandlerMgr = (dm_mo_handler_mgr_s *) calloc(1, sizeof(dm_mo_handler_mgr_s));
61 if (pMoDBHandlerMgr == NULL)
62 return SYNC_AGENT_DM_MO_FAIL;
63 _DEBUG_INFO("[%s] pMoDBHandlerMgr alloc success !\n", __func__);
65 /* alloc the agentDBHandlerMgr information */
66 ret = _create_agentDBHandlerMgrInfo();
67 if (ret != SYNC_AGENT_DM_MO_SUCCESS) {
68 _DEBUG_INFO("[%s] _create_agentDBHandlerMgrInfo alloc fail !\n", __func__);
70 _DEBUG_INFO("[%s] _create_agentDBHandlerMgrInfo alloc success !\n", __func__);
73 _DEBUG_INFO("[%s] end !\n", __func__);
80 sync_agent_dm_mo_error_e dm_mo_free_modb_handler_mgr(void)
84 _DEBUG_INFO("[%s] start !\n", __func__);
85 sync_agent_dm_mo_error_e ret = SYNC_AGENT_DM_MO_SUCCESS;
87 if (pMoDBHandlerMgr != NULL) {
89 ret = _free_agent_dc_handlerTable_mutex();
90 if (ret != SYNC_AGENT_DM_MO_SUCCESS)
91 return SYNC_AGENT_DM_MO_FAIL;
93 ret = _free_agent_dc_handlerTable();
94 if (ret != SYNC_AGENT_DM_MO_SUCCESS)
95 return SYNC_AGENT_DM_MO_FAIL;
99 _DEBUG_INFO("[%s] end !\n", __func__);
107 * ==================================
108 * external API (2. about agent db )
109 * ==================================
111 sync_agent_dm_mo_error_e dm_mo_open(char *database_path)
115 _DEBUG_INFO("[%s] Start !\n", __func__);
118 SYNC_AGENT_DA_MO_HANDLER *mo_handler = _get_agent_handler(SYNC_AGENT_DA_GET_THREAD_ID);
119 if (mo_handler == NULL) {
121 _DEBUG_INFO("mo_handler is 0");
122 _DEBUG_INFO("should register mo_handler to mo_handler_hash_table");
123 ret = mo_open_agent(&mo_handler, database_path);
124 if (ret != SYNC_AGENT_DM_MO_SUCCESS)
127 if (mo_handler != NULL) {
129 /* add agentDB handler to agentDBHandleMgr */
130 ret = _add_agent_handler(SYNC_AGENT_DA_GET_THREAD_ID, mo_handler);
131 if (ret != SYNC_AGENT_DM_MO_SUCCESS)
136 _DEBUG_INFO("mo_handler is not null");
137 _DEBUG_INFO("should not register mo_handler to mo_handler_hash_table");
140 _DEBUG_INFO("agent_db_agent_open_success");
141 _DEBUG_INFO("[%s] End !\n", __func__);
145 return SYNC_AGENT_DM_MO_SUCCESS;
148 sync_agent_dm_mo_error_e dm_mo_close(void)
152 _DEBUG_INFO("[%s] Start !\n", __func__);
155 SYNC_AGENT_DA_MO_HANDLER *mo_handler = _get_agent_handler(SYNC_AGENT_DA_GET_THREAD_ID);
156 if (mo_handler != NULL) {
158 /* remove agentDB handler to agentDBHandleMgr */
159 ret = _remove_agent_handler(SYNC_AGENT_DA_GET_THREAD_ID);
160 if (ret != SYNC_AGENT_DM_MO_SUCCESS)
163 _DEBUG_INFO("agent_db_agent_close_success");
166 _DEBUG_INFO("[%s] End !\n", __func__);
170 return SYNC_AGENT_DM_MO_SUCCESS;
173 sync_agent_dm_mo_error_e dm_mo_create_mo_table_wraper(void)
177 SYNC_AGENT_DA_MO_HANDLER *mo_handler = _get_agent_handler(SYNC_AGENT_DA_GET_THREAD_ID);
178 if (mo_handler == NULL) {
179 _DEBUG_ERROR("[%s] no handler for key\n", __func__);
180 return SYNC_AGENT_DM_MO_FAIL;
185 return dm_mo_create_mo_table(mo_handler);
188 sync_agent_dm_mo_error_e dm_mo_begin_transaction_wraper(void)
192 SYNC_AGENT_DA_MO_HANDLER *mo_handler = _get_agent_handler(SYNC_AGENT_DA_GET_THREAD_ID);
193 if (mo_handler == NULL) {
194 _DEBUG_ERROR("[%s] no handler for key\n", __func__);
195 return SYNC_AGENT_DM_MO_FAIL;
200 return dm_mo_begin_transaction(mo_handler);
203 sync_agent_dm_mo_error_e dm_mo_end_transaction_wraper(sync_agent_da_transaction_e transaction)
207 SYNC_AGENT_DA_MO_HANDLER *mo_handler = _get_agent_handler(SYNC_AGENT_DA_GET_THREAD_ID);
208 if (mo_handler == NULL) {
209 _DEBUG_ERROR("[%s] no handler for key\n", __func__);
210 return SYNC_AGENT_DM_MO_FAIL;
215 return dm_mo_end_transaction(mo_handler, transaction);
218 sync_agent_dm_mo_error_e dm_mo_add_node_wraper(sync_agent_dm_mo_type_e mo_type, sync_agent_dm_mo_node_s * mo_node)
222 SYNC_AGENT_DA_MO_HANDLER *mo_handler = _get_agent_handler(SYNC_AGENT_DA_GET_THREAD_ID);
223 if (mo_handler == NULL) {
224 _DEBUG_ERROR("[%s] no handler for key\n", __func__);
225 return SYNC_AGENT_DM_MO_FAIL;
230 return dm_mo_add_node(mo_handler, mo_type, mo_node);
233 sync_agent_dm_mo_error_e dm_mo_delete_node_wraper(int mo_node_id)
237 SYNC_AGENT_DA_MO_HANDLER *mo_handler = _get_agent_handler(SYNC_AGENT_DA_GET_THREAD_ID);
238 if (mo_handler == NULL) {
239 _DEBUG_ERROR("[%s] no handler for key\n", __func__);
240 return SYNC_AGENT_DM_MO_FAIL;
245 return dm_mo_delete_node(mo_handler, mo_node_id);
248 sync_agent_dm_mo_error_e dm_mo_update_node_wraper(sync_agent_dm_mo_type_e mo_type, const char *path, const sync_agent_dm_mo_node_s * mo_node)
252 SYNC_AGENT_DA_MO_HANDLER *mo_handler = _get_agent_handler(SYNC_AGENT_DA_GET_THREAD_ID);
253 if (mo_handler == NULL) {
254 _DEBUG_ERROR("[%s] no handler for key\n", __func__);
255 return SYNC_AGENT_DM_MO_FAIL;
260 return dm_mo_update_node(mo_handler, mo_type, path, mo_node);
263 sync_agent_dm_mo_error_e dm_mo_get_node_wraper(const char *path, sync_agent_dm_mo_node_s ** mo_node)
267 SYNC_AGENT_DA_MO_HANDLER *mo_handler = _get_agent_handler(SYNC_AGENT_DA_GET_THREAD_ID);
268 if (mo_handler == NULL) {
269 _DEBUG_ERROR("[%s] no handler for key\n", __func__);
270 return SYNC_AGENT_DM_MO_FAIL;
275 return dm_mo_get_node(mo_handler, path, mo_node);
278 sync_agent_dm_mo_error_e dm_mo_get_nodes_wraper(const char *path, sync_agent_dm_mo_node_s ** mo_node)
282 SYNC_AGENT_DA_MO_HANDLER *mo_handler = _get_agent_handler(SYNC_AGENT_DA_GET_THREAD_ID);
283 if (mo_handler == NULL) {
284 _DEBUG_ERROR("[%s] no handler for key\n", __func__);
285 return SYNC_AGENT_DM_MO_FAIL;
290 return dm_mo_get_nodes(mo_handler, path, mo_node);
293 sync_agent_dm_mo_error_e dm_mo_is_exist_node_wraper(const char *path)
297 SYNC_AGENT_DA_MO_HANDLER *mo_handler = _get_agent_handler(SYNC_AGENT_DA_GET_THREAD_ID);
298 if (mo_handler == NULL) {
299 _DEBUG_ERROR("[%s] no handler for key\n", __func__);
300 return SYNC_AGENT_DM_MO_FAIL;
305 return dm_mo_is_exist_node(mo_handler, path);
308 sync_agent_dm_mo_error_e dm_mo_get_child_node_wraper(sync_agent_dm_mo_type_e mo_type, const char *path, sync_agent_dm_mo_node_s ** mo_node, int *count)
312 SYNC_AGENT_DA_MO_HANDLER *mo_handler = _get_agent_handler(SYNC_AGENT_DA_GET_THREAD_ID);
313 if (mo_handler == NULL) {
314 _DEBUG_ERROR("[%s] no handler for key\n", __func__);
315 return SYNC_AGENT_DM_MO_FAIL;
320 return dm_mo_get_child_node(mo_type, mo_handler, path, mo_node, count);
323 sync_agent_dm_mo_error_e dm_mo_delete_all_node_wraper(void)
327 SYNC_AGENT_DA_MO_HANDLER *mo_handler = _get_agent_handler(SYNC_AGENT_DA_GET_THREAD_ID);
328 if (mo_handler == NULL) {
329 _DEBUG_ERROR("[%s] no handler for key\n", __func__);
330 return SYNC_AGENT_DM_MO_FAIL;
335 return dm_mo_delete_all_node(mo_handler);
338 sync_agent_dm_mo_type_e dm_mo_get_mo_type_wraper(const char *mo_full_path)
342 SYNC_AGENT_DA_MO_HANDLER *mo_handler = _get_agent_handler(SYNC_AGENT_DA_GET_THREAD_ID);
343 if (mo_handler == NULL) {
344 _DEBUG_ERROR("[%s] no handler for key\n", __func__);
345 return SYNC_AGENT_DM_MO_FAIL;
350 return dm_mo_get_mo_type(mo_handler, mo_full_path);
353 sync_agent_dm_mo_error_e dm_mo_add_framework_property_wraper(int mo_node_id, sync_agent_dm_mo_framework_property_s * framework_property)
357 SYNC_AGENT_DA_MO_HANDLER *mo_handler = _get_agent_handler(SYNC_AGENT_DA_GET_THREAD_ID);
358 if (mo_handler == NULL) {
359 _DEBUG_ERROR("[%s] no handler for key\n", __func__);
360 return SYNC_AGENT_DM_MO_FAIL;
365 return dm_mo_add_framework_property(mo_handler, mo_node_id, framework_property);
368 sync_agent_dm_mo_error_e dm_mo_get_node_from_id_wraper(int node_id, sync_agent_dm_mo_node_s ** mo_node)
372 SYNC_AGENT_DA_MO_HANDLER *mo_handler = _get_agent_handler(SYNC_AGENT_DA_GET_THREAD_ID);
373 if (mo_handler == NULL) {
374 _DEBUG_ERROR("[%s] no handler for key\n", __func__);
375 return SYNC_AGENT_DM_MO_FAIL;
380 return dm_mo_get_node_from_id(mo_handler, node_id, mo_node);
383 sync_agent_dm_mo_error_e dm_mo_get_acc_info_wraper(const char *server_id, const char *server_id_string, const char *acc_type_string, sync_agent_dm_acc_info_s ** acc_info)
387 SYNC_AGENT_DA_MO_HANDLER *mo_handler = _get_agent_handler(SYNC_AGENT_DA_GET_THREAD_ID);
388 if (mo_handler == NULL) {
389 _DEBUG_ERROR("[%s] no handler for key\n", __func__);
390 return SYNC_AGENT_DM_MO_FAIL;
395 return dm_mo_get_acc_info(mo_handler, server_id, server_id_string, acc_type_string, acc_info);
398 sync_agent_dm_mo_error_e dm_mo_set_acc_info_wraper(const char *server_id, const char *server_id_string, const char *acc_type_string, sync_agent_dm_acc_info_s * acc_info)
402 SYNC_AGENT_DA_MO_HANDLER *mo_handler = _get_agent_handler(SYNC_AGENT_DA_GET_THREAD_ID);
403 if (mo_handler == NULL) {
404 _DEBUG_ERROR("[%s] no handler for key\n", __func__);
405 return SYNC_AGENT_DM_MO_FAIL;
410 return dm_mo_set_acc_info(mo_handler, server_id, server_id_string, acc_type_string, acc_info);
413 sync_agent_dm_mo_error_e dm_mo_get_server_id_list_wraper(const char *server_id_string, sync_agent_dm_server_info_s ** head_ptr)
417 SYNC_AGENT_DA_MO_HANDLER *mo_handler = _get_agent_handler(SYNC_AGENT_DA_GET_THREAD_ID);
418 if (mo_handler == NULL) {
419 _DEBUG_ERROR("[%s] no handler for key\n", __func__);
420 return SYNC_AGENT_DM_MO_FAIL;
425 return dm_mo_get_server_id_list(mo_handler, server_id_string, head_ptr);
428 sync_agent_dm_mo_error_e dm_mo_get_root_path_wraper(const char *mo_full_path, char **root_path)
432 SYNC_AGENT_DA_MO_HANDLER *mo_handler = _get_agent_handler(SYNC_AGENT_DA_GET_THREAD_ID);
433 if (mo_handler == NULL) {
434 _DEBUG_ERROR("[%s] no handler for key\n", __func__);
435 return SYNC_AGENT_DM_MO_FAIL;
440 return dm_mo_get_root_path(mo_handler, mo_full_path, root_path);
443 sync_agent_dm_mo_error_e dm_mo_delete_framework_property_wraper(int mo_node_id)
447 SYNC_AGENT_DA_MO_HANDLER *mo_handler = _get_agent_handler(SYNC_AGENT_DA_GET_THREAD_ID);
448 if (mo_handler == NULL) {
449 _DEBUG_ERROR("[%s] no handler for key\n", __func__);
450 return SYNC_AGENT_DM_MO_FAIL;
455 return dm_mo_delete_framework_property(mo_handler, mo_node_id);
458 sync_agent_dm_mo_error_e dm_mo_update_framework_property_wraper(int mo_node_id, sync_agent_dm_mo_framework_property_s * framework_property)
462 SYNC_AGENT_DA_MO_HANDLER *mo_handler = _get_agent_handler(SYNC_AGENT_DA_GET_THREAD_ID);
463 if (mo_handler == NULL) {
464 _DEBUG_ERROR("[%s] no handler for key\n", __func__);
465 return SYNC_AGENT_DM_MO_FAIL;
470 return dm_mo_update_framework_property(mo_handler, mo_node_id, framework_property);
473 sync_agent_dm_mo_error_e dm_mo_get_framework_property_wraper(int mo_node_id, sync_agent_dm_mo_framework_property_s ** framework_property)
477 SYNC_AGENT_DA_MO_HANDLER *mo_handler = _get_agent_handler(SYNC_AGENT_DA_GET_THREAD_ID);
478 if (mo_handler == NULL) {
479 _DEBUG_ERROR("[%s] no handler for key\n", __func__);
480 return SYNC_AGENT_DM_MO_FAIL;
485 return dm_mo_get_framework_property(mo_handler, mo_node_id, framework_property);
488 sync_agent_dm_mo_error_e dm_mo_delete_all_framework_property_wraper(void)
492 SYNC_AGENT_DA_MO_HANDLER *mo_handler = _get_agent_handler(SYNC_AGENT_DA_GET_THREAD_ID);
493 if (mo_handler == NULL) {
494 _DEBUG_ERROR("[%s] no handler for key\n", __func__);
495 return SYNC_AGENT_DM_MO_FAIL;
500 return dm_mo_delete_all_framework_property(mo_handler);
503 sync_agent_dm_mo_error_e dm_mo_add_runtime_property_wraper(int mo_node_id, sync_agent_dm_mo_runtime_property_s * runtime_property)
507 SYNC_AGENT_DA_MO_HANDLER *mo_handler = _get_agent_handler(SYNC_AGENT_DA_GET_THREAD_ID);
508 if (mo_handler == NULL) {
509 _DEBUG_ERROR("[%s] no handler for key\n", __func__);
510 return SYNC_AGENT_DM_MO_FAIL;
515 return dm_mo_add_runtime_property(mo_handler, mo_node_id, runtime_property);
518 sync_agent_dm_mo_error_e dm_mo_delete_runtime_property_wraper(int mo_node_id)
522 SYNC_AGENT_DA_MO_HANDLER *mo_handler = _get_agent_handler(SYNC_AGENT_DA_GET_THREAD_ID);
523 if (mo_handler == NULL) {
524 _DEBUG_ERROR("[%s] no handler for key\n", __func__);
525 return SYNC_AGENT_DM_MO_FAIL;
530 return dm_mo_delete_runtime_property(mo_handler, mo_node_id);
533 sync_agent_dm_mo_error_e dm_mo_update_runtime_property_wraper(int mo_node_id, sync_agent_dm_mo_runtime_property_s * runtime_property)
537 SYNC_AGENT_DA_MO_HANDLER *mo_handler = _get_agent_handler(SYNC_AGENT_DA_GET_THREAD_ID);
538 if (mo_handler == NULL) {
539 _DEBUG_ERROR("[%s] no handler for key\n", __func__);
540 return SYNC_AGENT_DM_MO_FAIL;
545 return dm_mo_update_runtime_property(mo_handler, mo_node_id, runtime_property);
548 sync_agent_dm_mo_error_e dm_mo_get_runtime_property_wraper(int mo_node_id, sync_agent_dm_mo_runtime_property_s ** runtime_property)
552 SYNC_AGENT_DA_MO_HANDLER *mo_handler = _get_agent_handler(SYNC_AGENT_DA_GET_THREAD_ID);
553 if (mo_handler == NULL) {
554 _DEBUG_ERROR("[%s] no handler for key\n", __func__);
555 return SYNC_AGENT_DM_MO_FAIL;
560 return dm_mo_get_runtime_property(mo_handler, mo_node_id, runtime_property);
563 sync_agent_dm_mo_error_e dm_mo_delete_all_runtime_property_wraper(void)
567 SYNC_AGENT_DA_MO_HANDLER *mo_handler = _get_agent_handler(SYNC_AGENT_DA_GET_THREAD_ID);
568 if (mo_handler == NULL) {
569 _DEBUG_ERROR("[%s] no handler for key\n", __func__);
570 return SYNC_AGENT_DM_MO_FAIL;
575 return dm_mo_delete_all_runtime_property(mo_handler);
579 * ==================================
580 * Mo module internal API
581 * ==================================
583 sync_agent_dm_mo_error_e _add_agent_handler(unsigned int key, SYNC_AGENT_DA_MO_HANDLER * pHandler)
587 if (pMoDBHandlerMgr == NULL || pMoDBHandlerMgr->mo_handlerTable_mutex == NULL) {
588 return SYNC_AGENT_DM_MO_FAIL;
591 sync_agent_dm_mo_error_e ret = SYNC_AGENT_DM_MO_SUCCESS;
593 unsigned int *pKey_copy = (unsigned int *)malloc(sizeof(unsigned int));
594 if (pKey_copy == NULL)
595 return SYNC_AGENT_DM_MO_FAIL;
599 pthread_mutex_lock(pMoDBHandlerMgr->mo_handlerTable_mutex);
600 if (pMoDBHandlerMgr->mo_handlerTable == NULL) {
601 ret = __alloc_agent_dc_handlerTable();
602 if (ret != SYNC_AGENT_DM_MO_SUCCESS)
603 goto addagentHandler;
606 /* insert to handler */
607 _DEBUG_TRACE("[%s] Key = %d, Handler = %p !\n", __func__, key, pHandler);
608 g_hash_table_insert(pMoDBHandlerMgr->mo_handlerTable, pKey_copy, pHandler);
612 __print_agentDBHashTableLog();
616 pthread_mutex_unlock(pMoDBHandlerMgr->mo_handlerTable_mutex);
623 sync_agent_dm_mo_error_e _remove_agent_handler(unsigned int key)
627 if (pMoDBHandlerMgr == NULL || pMoDBHandlerMgr->mo_handlerTable_mutex == NULL || pMoDBHandlerMgr->mo_handlerTable == NULL) {
628 return SYNC_AGENT_DM_MO_FAIL;
631 /* remove the handler to hash table */
632 pthread_mutex_lock(pMoDBHandlerMgr->mo_handlerTable_mutex);
633 int isSuccess = g_hash_table_remove(pMoDBHandlerMgr->mo_handlerTable, &key);
634 pthread_mutex_unlock(pMoDBHandlerMgr->mo_handlerTable_mutex);
638 __print_agentDBHashTableLog();
644 return SYNC_AGENT_DM_MO_SUCCESS;
646 return SYNC_AGENT_DM_MO_FAIL;
649 SYNC_AGENT_DA_MO_HANDLER *_get_agent_handler(unsigned int key)
653 if (pMoDBHandlerMgr == NULL || pMoDBHandlerMgr->mo_handlerTable_mutex == NULL || pMoDBHandlerMgr->mo_handlerTable == NULL) {
654 _DEBUG_TRACE("[%s] SYNC_AGENT_DM_MO_FAIL !\n", __func__);
658 /* get the handler to hash table */
659 pthread_mutex_lock(pMoDBHandlerMgr->mo_handlerTable_mutex);
660 SYNC_AGENT_DA_MO_HANDLER *pHandler = g_hash_table_lookup(pMoDBHandlerMgr->mo_handlerTable, &key);
661 pthread_mutex_unlock(pMoDBHandlerMgr->mo_handlerTable_mutex);
665 _DEBUG_TRACE("[%s] ######### > Value Search Success(key = %d, handler = %p)\n", __func__, key, pHandler);
667 _DEBUG_TRACE("[%s] ######### > Value Search Fail(key = %d, handler = %p)\n", __func__, key, pHandler);
676 /* static function implementation */
677 static sync_agent_dm_mo_error_e __alloc_agent_dc_handlerTable(void)
681 if (pMoDBHandlerMgr != NULL) {
682 pMoDBHandlerMgr->mo_handlerTable = g_hash_table_new_full(g_int_hash, g_int_equal, __destory_agentDBHashTableKey, __destroy_agentDBHashTableValue);
683 if (pMoDBHandlerMgr->mo_handlerTable == NULL) {
684 _DEBUG_ERROR("[%s] Not Create agent dc handler hash table \n", __func__);
685 return SYNC_AGENT_DM_MO_FAIL;
687 _DEBUG_VERBOSE("[%MO_FAILent dc handler hash table \n", __func__);
693 return SYNC_AGENT_DM_MO_SUCCESS;
696 static sync_agent_dm_mo_error_e _alloc_agent_dc_handlerTable_mutex(void)
700 if (pMoDBHandlerMgr != NULL) {
702 pMoDBHandlerMgr->mo_handlerTable_mutex = (pthread_mutex_t *) malloc(sizeof(pthread_mutex_t));
703 if (pMoDBHandlerMgr->mo_handlerTable_mutex == NULL) {
704 _DEBUG_TRACE("[%s] Not Create agent dc handler hash table mutex \n", __func__);
705 return SYNC_AGENT_DM_MO_FAIL;
708 if (0 != pthread_mutex_init(pMoDBHandlerMgr->mo_handlerTable_mutex, 0)) {
709 _DEBUG_TRACE("[%s] Not init agent dc handler hash table mutex\n", __func__);
710 return SYNC_AGENT_DM_MO_FAIL;
712 _DEBUG_TRACE("[%s] Init agent dc handler hash table mutex\n", __func__);
718 return SYNC_AGENT_DM_MO_SUCCESS;
721 static sync_agent_dm_mo_error_e _free_agent_dc_handlerTable(void)
725 if (pMoDBHandlerMgr != NULL && pMoDBHandlerMgr->mo_handlerTable != NULL) {
726 g_hash_table_destroy(pMoDBHandlerMgr->mo_handlerTable);
727 _DEBUG_TRACE("[%s] mo_handlerTable free success !\n", __func__);
728 pMoDBHandlerMgr->mo_handlerTable = NULL;
733 return SYNC_AGENT_DM_MO_SUCCESS;
736 static sync_agent_dm_mo_error_e _free_agent_dc_handlerTable_mutex(void)
740 if (pMoDBHandlerMgr != NULL && pMoDBHandlerMgr->mo_handlerTable_mutex != NULL) {
742 int ret = pthread_mutex_destroy(pMoDBHandlerMgr->mo_handlerTable_mutex);
744 _DEBUG_TRACE("[%s] mo_handlerTable_mutex free error !\n", __func__);
745 return SYNC_AGENT_DM_MO_FAIL;
747 free(pMoDBHandlerMgr->mo_handlerTable_mutex);
748 pMoDBHandlerMgr->mo_handlerTable_mutex = NULL;
749 _DEBUG_TRACE("[%s] mo_handlerTable_mutex free success !\n", __func__);
755 return SYNC_AGENT_DM_MO_SUCCESS;
758 static sync_agent_dm_mo_error_e _create_agentDBHandlerMgrInfo(void)
762 sync_agent_dm_mo_error_e ret = SYNC_AGENT_DM_MO_SUCCESS;
764 if (pMoDBHandlerMgr != NULL) {
766 /* alloc agent db hander hash table */
767 ret = __alloc_agent_dc_handlerTable();
768 if (ret != SYNC_AGENT_DM_MO_SUCCESS)
769 goto allocAgentDBHandlerMgrInfoErr;
771 /* alloc agent db hander hash table mutex */
772 ret = _alloc_agent_dc_handlerTable_mutex();
773 if (ret != SYNC_AGENT_DM_MO_SUCCESS)
774 goto allocAgentDBHandlerMgrInfoErr;
779 return SYNC_AGENT_DM_MO_SUCCESS;
781 allocAgentDBHandlerMgrInfoErr:
782 da_free_agentdb_handler_mgr();
783 return SYNC_AGENT_DM_MO_FAIL;
786 static void __destroy_agentDBHashTableValue(void *pHandler)
790 _DEBUG_VERBOSE("[%s] start \n", __func__);
791 if (pHandler != NULL) {
792 mo_close_agent((SYNC_AGENT_DA_MO_HANDLER *) pHandler);
794 _DEBUG_VERBOSE("[%s] end \n", __func__);
799 static void __destory_agentDBHashTableKey(void *key)
803 _DEBUG_VERBOSE("[%s] start \n", __func__);
806 _DEBUG_VERBOSE("[%s] end \n", __func__);