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.
19 #include <libxml/parser.h>
20 #include <libxml/tree.h>
22 #include "utility/sync_util.h"
23 #include "utility/fw_mainloop.h"
25 #include "engine-controller/internal.h"
27 #include "data-adapter/agent.h"
28 #include "data-adapter/agent_handler_manager.h"
29 #include "data-adapter/agent_handler_manager_internal.h"
31 #include "utility/fw_sequential_id_provider.h"
33 #include "event/handler.h"
34 #include "event/config.h"
36 #include "plugin/struct.h"
37 #include "plugin/data_connector_plugin.h"
38 #include "plugin/data_converter_plugin.h"
39 #include "plugin/account_plugin.h"
40 #include "plugin/network_access_plugin.h"
41 #include "plugin/device_info_plugin.h"
42 #include "plugin/platform_monitor_plugin.h"
43 #include "plugin/mo_plugin.h"
44 #include "plugin/manager.h"
45 #include "plugin/device_manager_plugin.h"
47 #include "device-manager/mo_error.h"
48 #include "device-manager/mo_database_handler.h"
50 #include "device/information.h"
52 #include "network-access/callbacks.h"
54 #include "initialization/parser.h"
56 #ifndef SYNC_AGENT_LOG
58 #define LOG_TAG "AF_INIT"
61 static char *agent_key = NULL;
63 static int use_main_loop = 0;
65 static sync_agent_init_error_e _process_node(xmlNode * root_element);
67 static sync_agent_deinit_error_e _process_node_deinit(xmlNode * root_element);
69 static sync_agent_init_error_e __process_engine_controller(xmlNode * engine_controller_node);
71 static sync_agent_init_error_e __process_framework_db(xmlNode * framework_db_node);
73 static sync_agent_init_error_e __process_id_provider(xmlNode * id_provider_node);
75 static sync_agent_init_error_e __process_event(xmlNode * event_node);
77 static sync_agent_init_error_e __process_noti(xmlNode * event_node);
79 static sync_agent_init_error_e __process_plugin(xmlNode * plugin_mgr_node);
81 static sync_agent_deinit_error_e __process_plugin_deinit(xmlNode * plugin_mgr_node);
83 static sync_agent_init_error_e __process_device_manage(xmlNode * device_manage_node);
85 static char *__get_child_node_content(xmlNode * parent_node, const char *node_name);
87 static int __compare_uchar_with_char(const xmlChar * str, const char *str2);
89 sync_agent_init_error_e init_parse_init_config(const char *init_config_file_path)
94 xmlNode *root_element = NULL;
96 doc = xmlReadFile(init_config_file_path, 0, 0);
98 _DEBUG_ERROR("Failed to parse %s", init_config_file_path);
99 return SYNC_AGENT_INIT_FAIL;
102 root_element = xmlDocGetRootElement(doc);
104 sync_agent_init_error_e init_err = _process_node(root_element);
108 _DEBUG_INFO("[End]");
115 sync_agent_deinit_error_e deinit_parse_config(const char *config_file_path)
120 xmlNode *root_element = NULL;
122 doc = xmlReadFile(config_file_path, 0, 0);
124 _DEBUG_ERROR("Failed to parse %s", config_file_path);
125 return SYNC_AGENT_DEINIT_FAIL;
128 root_element = xmlDocGetRootElement(doc);
130 sync_agent_deinit_error_e deinit_err = _process_node_deinit(root_element);
134 _DEBUG_INFO("[End]");
141 char *init_get_agent_key(void)
150 int init_use_main_loop(void)
156 return use_main_loop;
159 static sync_agent_init_error_e _process_node(xmlNode * root_element)
163 sync_agent_init_error_e init_error = SYNC_AGENT_INIT_SUCCESS;
165 if (root_element == NULL) {
166 return SYNC_AGENT_INIT_FAIL;
169 xmlNode *cursor_node = root_element->children;
170 while (cursor_node != NULL) {
171 if (cursor_node->type == XML_ELEMENT_NODE) {
172 _DEBUG_TRACE("%s", cursor_node->name);
173 if (__compare_uchar_with_char(cursor_node->name, "Agent-Key")) {
174 agent_key = (char *)xmlNodeGetContent(cursor_node);
175 _DEBUG_TRACE("Agent-Key : %s", agent_key);
176 } else if (__compare_uchar_with_char(cursor_node->name, "MainLoop")) {
177 xmlChar *main_loop = xmlNodeGetContent(cursor_node);
178 if (__compare_uchar_with_char(main_loop, "1")) {
181 } else if (__compare_uchar_with_char(cursor_node->name, "EngineController")) {
182 init_error = __process_engine_controller(cursor_node);
183 } else if (__compare_uchar_with_char(cursor_node->name, "FrameworkDB")) {
184 init_error = __process_framework_db(cursor_node);
185 } else if (__compare_uchar_with_char(cursor_node->name, "ID-Provider")) {
186 init_error = __process_id_provider(cursor_node);
187 } else if (__compare_uchar_with_char(cursor_node->name, "Event")) {
188 init_error = __process_event(cursor_node);
189 } else if (__compare_uchar_with_char(cursor_node->name, "Noti")) {
190 init_error = __process_noti(cursor_node);
191 } else if (__compare_uchar_with_char(cursor_node->name, "PlugIn-Mgr")) {
192 init_error = __process_plugin(cursor_node);
193 } else if (__compare_uchar_with_char(cursor_node->name, "DeviceManage")) {
194 init_error = __process_device_manage(cursor_node);
198 cursor_node = cursor_node->next;
206 static sync_agent_deinit_error_e _process_node_deinit(xmlNode * root_element)
210 sync_agent_deinit_error_e deinit_error = SYNC_AGENT_DEINIT_SUCCESS;
212 if (root_element == NULL) {
213 return SYNC_AGENT_DEINIT_FAIL;
216 xmlNode *cursor_node = root_element->children;
217 while (cursor_node != NULL) {
218 if (cursor_node->type == XML_ELEMENT_NODE) {
219 _DEBUG_TRACE("%s", cursor_node->name);
220 if (__compare_uchar_with_char(cursor_node->name, "Agent-Key")) {
221 agent_key = (char *)xmlNodeGetContent(cursor_node);
222 _DEBUG_TRACE("Agent-Key : %s", agent_key);
223 } else if (__compare_uchar_with_char(cursor_node->name, "FrameworkDB")) {
224 sync_agent_da_return_e da_error = sync_agent_close_agent();
225 if (da_error != SYNC_AGENT_DA_SUCCESS) {
226 _DEBUG_ERROR("sync_agent_close_agent() failed !! [%d]", da_error);
227 return SYNC_AGENT_DEINIT_FAIL;
229 _DEBUG_TRACE("sync_agent_close_agent() success !!");
232 da_error = da_free_agentdb_handler_mgr();
233 if (da_error != SYNC_AGENT_DA_SUCCESS) {
234 _DEBUG_ERROR("da_free_agentdb_handler_mgr() failed !! [%d]", da_error);
235 return SYNC_AGENT_DEINIT_FAIL;
237 _DEBUG_TRACE("da_free_agentdb_handler_mgr() success !!");
239 } else if (__compare_uchar_with_char(cursor_node->name, "Event") || __compare_uchar_with_char(cursor_node->name, "Noti")) {
240 sync_agent_event_error_e event_error = sync_agent_clean_event_handler();
241 if (event_error != SYNC_AGENT_EVENT_SUCCESS) {
242 _DEBUG_ERROR("sync_agent_clean_event_handler() failed !! [%d]", event_error);
243 return SYNC_AGENT_DEINIT_FAIL;
245 _DEBUG_TRACE("sync_agent_clean_event_handler() success !!");
247 } else if (__compare_uchar_with_char(cursor_node->name, "PlugIn-Mgr")) {
248 deinit_error = __process_plugin_deinit(cursor_node);
249 if (deinit_error != SYNC_AGENT_DEINIT_SUCCESS) {
250 _DEBUG_ERROR("__process_plugin_deinit() failed !! [%d]", deinit_error);
253 _DEBUG_TRACE("__process_plugin_deinit() success !!");
255 } else if (__compare_uchar_with_char(cursor_node->name, "DeviceManage")) {
256 sync_agent_dm_mo_error_e mo_error = dm_mo_close();
257 if (mo_error != SYNC_AGENT_DM_MO_SUCCESS) {
258 _DEBUG_ERROR("Failed to dm_mo_close() : %d", mo_error);
259 return SYNC_AGENT_DEINIT_FAIL;
262 mo_error = dm_mo_free_modb_handler_mgr();
263 if (mo_error != SYNC_AGENT_DM_MO_SUCCESS) {
264 _DEBUG_ERROR("dm_mo_free_modb_handler_mgr() failed !! [%d]", mo_error);
265 return SYNC_AGENT_DEINIT_FAIL;
267 _DEBUG_TRACE("dm_mo_free_modb_handler_mgr() success !!");
272 cursor_node = cursor_node->next;
280 /********************** Implement static function *************************/
282 static sync_agent_init_error_e __process_engine_controller(xmlNode * engine_controller_node)
286 retvm_if(engine_controller_node == NULL, SYNC_AGENT_INIT_FAIL, "xmlNode is NULL !!");
288 xmlNode *max_thread = engine_controller_node->children;
289 if (max_thread == NULL) {
290 return SYNC_AGENT_INIT_PARSER_FAIL;
293 char *max_thread_count_str = __get_child_node_content(engine_controller_node, "Max-Thread");
294 int max_thread_count = atoi(max_thread_count_str);
296 if (max_thread_count <= 0) {
297 return SYNC_AGENT_INIT_ENGINE_CONTROLLER_FAIL;
300 bool init_success = ec_init_engine_controller(max_thread_count);
302 _DEBUG_VERBOSE("Engine controller initialize success");
304 _DEBUG_ERROR("Engine controller initialize fail");
305 return SYNC_AGENT_INIT_ENGINE_CONTROLLER_FAIL;
310 return SYNC_AGENT_INIT_SUCCESS;
313 static sync_agent_init_error_e __process_framework_db(xmlNode * framework_db_node)
317 retvm_if(framework_db_node == NULL, SYNC_AGENT_INIT_FAIL, "xmlNode is NULL !!");
319 const char *use_DB_str = (char *)xmlGetProp(framework_db_node, (xmlChar *) "use");
320 int use_DB = atoi(use_DB_str);
322 _DEBUG_VERBOSE("Not Use Framework Common DB");
323 return SYNC_AGENT_INIT_SUCCESS;
326 char *db_path = __get_child_node_content(framework_db_node, "Path");
327 _DEBUG_VERBOSE("Common DB Path : %s", db_path);
329 da_set_agent_db_file_path(db_path);
331 sync_agent_da_return_e da_err = da_alloc_agentdb_handler_mgr();
332 if (da_err != SYNC_AGENT_DA_SUCCESS) {
333 return SYNC_AGENT_INIT_COMMON_DB_FAIL;
336 da_err = sync_agent_open_agent();
337 if (da_err != SYNC_AGENT_DA_SUCCESS) {
338 return SYNC_AGENT_INIT_COMMON_DB_FAIL;
341 da_err = da_create_agent_default_table_wrapper();
342 if (da_err != SYNC_AGENT_DA_SUCCESS) {
343 return SYNC_AGENT_INIT_COMMON_DB_FAIL;
348 return SYNC_AGENT_INIT_SUCCESS;
351 static sync_agent_init_error_e __process_id_provider(xmlNode * id_provider_node)
355 retvm_if(id_provider_node == NULL, SYNC_AGENT_INIT_FAIL, "xmlNode is NULL !!");
357 char *code_str = __get_child_node_content(id_provider_node, "Code");
358 char *max_id_str = __get_child_node_content(id_provider_node, "MaxID");
359 char *page_size_str = __get_child_node_content(id_provider_node, "PageSize");
361 unsigned int code = atoi(code_str);
362 unsigned int id_max = atoi(max_id_str);
363 unsigned int log2_page_size = atoi(page_size_str);
365 util_id_provider_error_e error = util_create_id_persistent_provider(code, id_max, log2_page_size);
366 if (error == UTIL_ID_PROVIDER_OK) {
367 _DEBUG_VERBOSE("Done sync_agent_create_id_persistent_provider : %d", error);
372 return SYNC_AGENT_INIT_SUCCESS;
375 static sync_agent_init_error_e __process_event(xmlNode * event_node)
379 retvm_if(event_node == NULL, SYNC_AGENT_INIT_FAIL, "xmlNode is NULL !!");
381 char *event_key = __get_child_node_content(event_node, "Event-Key");
382 char *event_configfile = __get_child_node_content(event_node, "Event-Config");
383 xmlChar *run_eventHandler = (xmlChar *) __get_child_node_content(event_node, "RunEventHandler");
385 sync_agent_event_error_e event_err = event_set_event_spec_from_config_file(event_key, event_configfile);
386 if (event_err != SYNC_AGENT_EVENT_SUCCESS) {
387 _DEBUG_ERROR("Fail Load event config");
388 return SYNC_AGENT_INIT_SYNC_AGENT_EVENT_FAIL;
390 _DEBUG_VERBOSE("Success Load event config");
393 if (__compare_uchar_with_char(run_eventHandler, "1")) {
394 unsigned long int thread_id;
395 event_err = sync_agent_run_event_handler(&thread_id);
396 if (event_err != SYNC_AGENT_EVENT_SUCCESS) {
397 _DEBUG_ERROR("Failed to sync_agent_run_event_handler()");
398 return SYNC_AGENT_INIT_SYNC_AGENT_EVENT_FAIL;
404 return SYNC_AGENT_INIT_SUCCESS;
407 static sync_agent_init_error_e __process_noti(xmlNode * event_node)
411 retvm_if(event_node == NULL, SYNC_AGENT_INIT_FAIL, "xmlNode is NULL !!");
413 char *noti_key = __get_child_node_content(event_node, "Noti-Key");
414 char *noti_configfile = __get_child_node_content(event_node, "Noti-Config");
416 sync_agent_event_error_e event_err = event_set_noti_spec_from_config_file(noti_key, noti_configfile);
417 if (event_err != SYNC_AGENT_EVENT_SUCCESS) {
418 _DEBUG_ERROR("Fail Load noti config : %s", noti_configfile);
419 return SYNC_AGENT_INIT_SYNC_AGENT_EVENT_FAIL;
421 _DEBUG_VERBOSE("Success Load noti config");
426 return SYNC_AGENT_INIT_SUCCESS;
429 static sync_agent_init_error_e __process_plugin(xmlNode * plugin_mgr_node)
433 retvm_if(plugin_mgr_node == NULL, SYNC_AGENT_INIT_FAIL, "xmlNode is NULL !!");
435 xmlNode *domain_node = plugin_mgr_node->children;
436 while (domain_node != NULL) {
437 if (domain_node->type == XML_ELEMENT_NODE) {
438 const xmlChar *domain_name = xmlGetProp(domain_node, (xmlChar *) "name");
439 const xmlChar *domain_count = xmlGetProp(domain_node, (xmlChar *) "count");
441 if (domain_count != NULL) {
442 d_count = atoi((char *)domain_count);
444 _DEBUG_VERBOSE("Domain : %s ( count : %d ) =====================", domain_name, d_count);
446 xmlNode *plugIn_node = domain_node->children;
447 while (plugIn_node != NULL) {
448 if (plugIn_node->type == XML_ELEMENT_NODE) {
449 plugin_info_s plugIn_Info;
451 char *plugIn_ID = __get_child_node_content(plugIn_node, "ID");
452 char *plugIn_path = __get_child_node_content(plugIn_node, "Path");
454 plugIn_Info.plugin_id = atoi(plugIn_ID);
456 plugin_error_e plugIn_error;
457 plugIn_Info.plugin_handle = plugin_load_plugin(plugIn_path, &plugIn_error);
458 if (plugIn_error != PLUGIN_SUCCESS) {
459 _DEBUG_ERROR("load_PlugIn Failed [%s]", plugIn_path);
460 return SYNC_AGENT_INIT_PLUGIN_FAIL;
463 _DEBUG_VERBOSE("plugIn_ID : %d", plugIn_Info.plugin_id);
464 _DEBUG_VERBOSE("plugIn_Path : %s", plugIn_path);
466 if (__compare_uchar_with_char(domain_name, "DataConnector")) {
467 plugin_data_connector_s plugIn_dc;
468 char *dataConverter = __get_child_node_content(plugIn_node, "DataConverter-PlugIn");
469 char *handleChangeNoti = __get_child_node_content(plugIn_node, "Handle-ChangeNoti");
470 char *useMainLoop = __get_child_node_content(plugIn_node, "Use-MainLoop");
472 plugIn_dc.plugin_info = plugIn_Info;
473 plugIn_dc.data_converter_id = atoi(dataConverter);
474 plugIn_dc.handle_change_noti = atoi(handleChangeNoti);
475 plugIn_dc.use_main_loop = atoi(useMainLoop);
476 plugIn_dc.func_set = plugin_get_data_connector_func_set(plugIn_Info.plugin_handle, &plugIn_error);
478 plugin_register_plugin_data_connector(plugIn_dc);
479 } else if (__compare_uchar_with_char(domain_name, "DataConverter")) {
480 plugin_data_converter_s plugIn_dataconverter;
482 plugIn_dataconverter.plugin_info = plugIn_Info;
483 plugIn_dataconverter.func_set = plugin_get_data_converter_func_set(plugIn_Info.plugin_handle, &plugIn_error);
485 plugin_register_plugin_data_converter(plugIn_dataconverter);
486 } else if (__compare_uchar_with_char(domain_name, "Account")) {
487 plugin_account_s plugIn_acc;
489 plugIn_acc.plugin_info = plugIn_Info;
490 plugIn_acc.func_set = plugin_get_plugin_account_func_set(plugIn_Info.plugin_handle, &plugIn_error);
492 plugin_register_plugin_account(plugIn_acc);
493 } else if (__compare_uchar_with_char(domain_name, "NetworkAccess")) {
494 plugin_network_access_s plugIn_na;
496 plugIn_na.plugin_info = plugIn_Info;
497 plugIn_na.func_set = plugin_get_network_access_func_set(plugIn_Info.plugin_handle, &plugIn_error);
499 char *use_network = __get_child_node_content(plugIn_node, "UseNetwork");
500 plugIn_na.use_network = atoi(use_network);
502 plugin_register_plugin_network_access(plugIn_na);
503 } else if (__compare_uchar_with_char(domain_name, "DeviceInfo")) {
504 plugin_device_info_s plugIn_device;
506 plugIn_device.plugin_info = plugIn_Info;
507 plugIn_device.func_set = plugin_get_device_info_func_set(plugIn_Info.plugin_handle, &plugIn_error);
509 plugin_register_plugin_device_info(plugIn_device);
511 char *depends_on = __get_child_node_content(plugIn_node, "DependsOn");
512 if (depends_on != NULL) {
514 * Setting dependant DeviceInfo interface
516 int plugIn_id = atoi(depends_on);
517 if (plugin_is_exsist_device_info_plugin()) {
518 _DEBUG_INFO("Dependent DeviceInfo PlulgIn ID : %d", plugIn_id);
520 plugin_set_common_devinfo_function_cb func_point_set_common_devinfo_function = plugin_get_function_set_common_devinfo_function(plugIn_Info.plugin_id);
521 if (func_point_set_common_devinfo_function != 0) {
522 func_point_set_common_devinfo_function(sync_agent_get_devinfo);
524 _DEBUG_ERROR("func_point_set_func_get_device_info_common is NULL!!");
526 plugin_set_common_execute_dev_function_cb func_point_set_common_execute_dev_function = plugin_get_function_set_common_execute_dev_function(plugIn_Info.plugin_id);
527 if (func_point_set_common_execute_dev_function != 0) {
528 func_point_set_common_execute_dev_function(sync_agent_execute_dev_function);
530 _DEBUG_ERROR("func_point_set_func_execute_device_function_common is NULL!!");
533 _DEBUG_ERROR("FAIL!! Depending DeviceInfo PlulgIn not existing!!");
536 } else if (__compare_uchar_with_char(domain_name, "PlatformMonitor")) {
538 plugin_platform_monitor_s plugIn_pm;
539 sync_agent_pm_register_data_s **reg_data = NULL;
541 char *useMainLoop = __get_child_node_content(plugIn_node, "Use-MainLoop");
542 plugIn_pm.use_main_loop = atoi(useMainLoop);
544 xmlNode *cursor_node = plugIn_node->children;
545 while (cursor_node != NULL) {
546 if (__compare_uchar_with_char(cursor_node->name, "Register-Data")) {
547 char *reg_count = (char *)xmlGetProp(cursor_node, (xmlChar *) "count");
548 if (reg_count != NULL) {
549 r_count = atoi(reg_count);
551 _DEBUG_VERBOSE("Register-Data count : %d", r_count);
554 _DEBUG_VERBOSE("exist Register-Data ( count : %d ) !!", r_count);
555 xmlNode *cursor_child_node = cursor_node->children;
557 reg_data = (sync_agent_pm_register_data_s **) calloc(r_count, sizeof(sync_agent_pm_register_data_s *));
558 if (reg_data == NULL) {
559 _DEBUG_ERROR("calloc failed !!");
560 return SYNC_AGENT_INIT_FAIL;
564 while (cursor_child_node != NULL) {
565 if (__compare_uchar_with_char(cursor_child_node->name, "Data")) {
566 char *pkg_name = __get_child_node_content(cursor_child_node, "Pkg-Name");
567 char *additional_data = __get_child_node_content(cursor_child_node, "Additional-Data");
569 reg_data[i] = (sync_agent_pm_register_data_s *) calloc(1, sizeof(sync_agent_pm_register_data_s));
570 if (reg_data[i] == NULL) {
571 _DEBUG_ERROR("calloc failed !!");
572 if (reg_data != NULL)
574 return SYNC_AGENT_INIT_FAIL;
577 if (pkg_name != NULL) {
578 reg_data[i]->pkg_name = strdup(pkg_name);
579 _DEBUG_VERBOSE("pkg_name : %s", reg_data[i]->pkg_name);
581 _DEBUG_VERBOSE("pkg_name is NULL !!");
584 if (additional_data != NULL) {
585 reg_data[i]->additional_data = strdup(additional_data);
586 _DEBUG_VERBOSE("additional_data : %s", reg_data[i]->additional_data);
588 _DEBUG_VERBOSE("additional_data is NULL !!");
593 cursor_child_node = cursor_child_node->next;
596 _DEBUG_VERBOSE("not exist Register-Data !!");
601 cursor_node = cursor_node->next;
604 if ((r_count == 0) && (strstr(plugIn_path, "sysnoti-network-connection") != NULL)) {
605 _DEBUG_VERBOSE("set network connection cb data !!");
606 reg_data = (sync_agent_pm_register_data_s **) calloc(1, sizeof(sync_agent_pm_register_data_s *));
607 if (reg_data == NULL) {
608 _DEBUG_ERROR("calloc failed !!");
610 return SYNC_AGENT_INIT_FAIL;
613 *reg_data = (sync_agent_pm_register_data_s *) calloc(1, sizeof(sync_agent_pm_register_data_s));
614 if (*reg_data == NULL) {
615 _DEBUG_ERROR("calloc failed !!");
616 if (reg_data != NULL)
619 return SYNC_AGENT_INIT_FAIL;
622 sync_agent_user_callback_cb_plugin *usr_cb = (sync_agent_user_callback_cb_plugin *) calloc(2, sizeof(sync_agent_user_callback_cb_plugin));
623 if (usr_cb == NULL) {
624 _DEBUG_ERROR("calloc failed !!");
625 if (*reg_data != NULL)
627 if (reg_data != NULL)
630 return SYNC_AGENT_INIT_FAIL;
633 usr_cb[0] = na_handle_network_status;
634 usr_cb[1] = na_handle_network_all_cancel;
636 (*reg_data)->user_data = (void *)usr_cb;
641 plugIn_pm.reg_data = reg_data;
642 plugIn_pm.reg_data_count = r_count;
643 plugIn_pm.plugin_info = plugIn_Info;
644 plugIn_pm.func_set = plugin_get_platform_monitor_func_set(plugIn_Info.plugin_handle, &plugIn_error);
646 plugin_register_plugin_platform_monitor(plugIn_pm);
647 } else if (__compare_uchar_with_char(domain_name, "MO")) {
648 plugin_mo_s plugIn_mo;
650 plugIn_mo.plugin_info = plugIn_Info;
651 plugIn_mo.func_set = plugin_get_mo_func_set(plugIn_Info.plugin_handle, &plugIn_error);
653 char *mo_type = __get_child_node_content(plugIn_node, "Type");
654 if (mo_type != NULL) {
655 if (!strcmp(mo_type, "DEVDETAIL")) {
656 plugIn_mo.mo_type = SYNC_AGENT_DM_MO_TYPE_DEVDETAIL;
657 } else if (!strcmp(mo_type, "DEVINFO")) {
658 plugIn_mo.mo_type = SYNC_AGENT_DM_MO_TYPE_DEVINFO;
659 } else if (!strcmp(mo_type, "FUMO")) {
660 plugIn_mo.mo_type = SYNC_AGENT_DM_MO_TYPE_FUMO;
661 } else if (!strcmp(mo_type, "DMACC")) {
662 plugIn_mo.mo_type = SYNC_AGENT_DM_MO_TYPE_DMACC;
663 } else if (!strcmp(mo_type, "LAWMO")) {
664 plugIn_mo.mo_type = SYNC_AGENT_DM_MO_TYPE_LAWMO;
665 } else if (!strcmp(mo_type, "SCOMO")) {
666 plugIn_mo.mo_type = SYNC_AGENT_DM_MO_TYPE_SCOMO;
668 plugIn_mo.mo_type = SYNC_AGENT_DM_MO_TYPE_NO_TYPE;
671 plugin_register_plugin_mo(plugIn_mo);
673 } else if (__compare_uchar_with_char(domain_name, "DeviceManager")) {
674 plugin_device_manager_s plugIn_device_manager;
676 plugIn_device_manager.plugin_info = plugIn_Info;
677 plugIn_device_manager.func_set = plugin_get_device_manager_func_set(plugIn_Info.plugin_handle, &plugIn_error);
679 plugin_register_plugin_device_manager(plugIn_device_manager);
683 plugIn_node = plugIn_node->next;
686 domain_node = domain_node->next;
691 return SYNC_AGENT_INIT_SUCCESS;
694 static sync_agent_deinit_error_e __process_plugin_deinit(xmlNode * plugin_mgr_node)
698 retvm_if(plugin_mgr_node == NULL, SYNC_AGENT_DEINIT_FAIL, "xmlNode is NULL !!");
700 plugin_error_e plugin_error = PLUGIN_SUCCESS;
701 xmlNode *domain_node = plugin_mgr_node->children;
702 while (domain_node != NULL) {
703 if (domain_node->type == XML_ELEMENT_NODE) {
704 const xmlChar *domain_name = xmlGetProp(domain_node, (xmlChar *) "name");
705 const xmlChar *domain_count = xmlGetProp(domain_node, (xmlChar *) "count");
707 if (domain_count != NULL) {
708 d_count = atoi((char *)domain_count);
710 _DEBUG_VERBOSE("Domain : %s ( count : %d ) =====================", domain_name, d_count);
713 int plugin_count = 0;
714 if (__compare_uchar_with_char(domain_name, "DataConnector")) {
715 const plugin_data_connector_s *plugin_dc_repository = plugin_get_data_connector_plugin_repository(&plugin_count);
717 /* unload DataConnector's plug-in */
718 for (i = 0; i < plugin_count; i++) {
719 plugin_error = plugin_unload_plugin(plugin_dc_repository[i].plugin_info.plugin_handle);
720 if (plugin_error != PLUGIN_SUCCESS) {
721 _DEBUG_ERROR("plugin_unload_plugin() - %s [ID : %d] failed !!", domain_name, plugin_dc_repository[i].plugin_info.plugin_id);
723 _DEBUG_VERBOSE("plugin_unload_plugin() - %s [ID : %d] success !!", domain_name, plugin_dc_repository[i].plugin_info.plugin_id);
727 /* clear DataConnector's plug-in repository */
728 plugin_clear_plugin_data_connector();
729 } else if (__compare_uchar_with_char(domain_name, "DataConverter")) {
730 // int plugin_count = 0;
731 const plugin_data_converter_s *plugin_dc_repository = plugin_get_data_converter_plugin_repository(&plugin_count);
733 /* unload DataConnector's plug-in */
734 for (i = 0; i < plugin_count; i++) {
735 plugin_error = plugin_unload_plugin(plugin_dc_repository[i].plugin_info.plugin_handle);
736 if (plugin_error != PLUGIN_SUCCESS) {
737 _DEBUG_ERROR("plugin_unload_plugin() - %s [ID : %d] failed !!", domain_name, plugin_dc_repository[i].plugin_info.plugin_id);
739 _DEBUG_VERBOSE("plugin_unload_plugin() - %s [ID : %d] success !!", domain_name, plugin_dc_repository[i].plugin_info.plugin_id);
743 /* clear DataConverter's plug-in repository */
744 plugin_clear_plugin_data_converter();
745 } else if (__compare_uchar_with_char(domain_name, "Account")) {
746 const plugin_account_s plugin_acc_repository = plugin_get_account_plugin_repository();
748 /* unload Account's plug-in */
749 plugin_error = plugin_unload_plugin(plugin_acc_repository.plugin_info.plugin_handle);
750 if (plugin_error != PLUGIN_SUCCESS) {
751 _DEBUG_ERROR("plugin_unload_plugin() - %s [ID : %d] failed !!", domain_name, plugin_acc_repository.plugin_info.plugin_id);
753 _DEBUG_VERBOSE("plugin_unload_plugin() - %s [ID : %d] success !!", domain_name, plugin_acc_repository.plugin_info.plugin_id);
756 /* clear Account's plug-in repository */
757 plugin_clear_plugin_account();
758 } else if (__compare_uchar_with_char(domain_name, "NetworkAccess")) {
759 // int plugin_count = 0;
760 const plugin_network_access_s *plugin_na_repository = plugin_get_network_access_plugin_repository(&plugin_count);
762 /* unload NetworkAccess's plug-in */
763 for (i = 0; i < plugin_count; i++) {
764 plugin_error = plugin_unload_plugin(plugin_na_repository[i].plugin_info.plugin_handle);
765 if (plugin_error != PLUGIN_SUCCESS) {
766 _DEBUG_ERROR("plugin_unload_plugin() - %s [ID : %d] failed !!", domain_name, plugin_na_repository[i].plugin_info.plugin_id);
768 _DEBUG_VERBOSE("plugin_unload_plugin() - %s [ID : %d] success !!", domain_name, plugin_na_repository[i].plugin_info.plugin_id);
772 /* clear NetworkAccess's plug-in repository */
773 plugin_clear_plugin_network_access();
774 } else if (__compare_uchar_with_char(domain_name, "DeviceInfo")) {
775 // int plugin_count = 0;
776 const plugin_device_info_s *plugin_di_repository = plugin_get_device_info_plugin_repository(&plugin_count);
778 /* unload DeviceInfo's plug-in */
779 for (i = 0; i < plugin_count; i++) {
780 plugin_error = plugin_unload_plugin(plugin_di_repository[i].plugin_info.plugin_handle);
781 if (plugin_error != PLUGIN_SUCCESS) {
782 _DEBUG_ERROR("plugin_unload_plugin() - %s [ID : %d] failed !!", domain_name, plugin_di_repository[i].plugin_info.plugin_id);
784 _DEBUG_VERBOSE("plugin_unload_plugin() - %s [ID : %d] success !!", domain_name, plugin_di_repository[i].plugin_info.plugin_id);
788 /* clear DeviceInfo's plug-in repository */
789 plugin_clear_plugin_device_info();
790 } else if (__compare_uchar_with_char(domain_name, "PlatformMonitor")) {
791 // int plugin_count = 0;
792 const plugin_platform_monitor_s *plugin_pm_repository = plugin_get_platform_monitor_plugin_repository(&plugin_count);
794 /* unload PlatformMonitor's plug-in */
795 for (i = 0; i < plugin_count; i++) {
796 plugin_error = plugin_unload_plugin(plugin_pm_repository[i].plugin_info.plugin_handle);
797 if (plugin_error != PLUGIN_SUCCESS) {
798 _DEBUG_ERROR("plugin_unload_plugin() - %s [ID : %d] failed !!", domain_name, plugin_pm_repository[i].plugin_info.plugin_id);
800 _DEBUG_VERBOSE("plugin_unload_plugin() - %s [ID : %d] success !!", domain_name, plugin_pm_repository[i].plugin_info.plugin_id);
804 } else if (__compare_uchar_with_char(domain_name, "MO")) {
805 // int plugin_count = 0;
806 const plugin_mo_s *plugin_mo_repository = plugin_get_mo_plugin_repository(&plugin_count);
808 /* unload MO's plug-in */
809 for (i = 0; i < plugin_count; i++) {
810 plugin_error = plugin_unload_plugin(plugin_mo_repository[i].plugin_info.plugin_handle);
811 if (plugin_error != PLUGIN_SUCCESS) {
812 _DEBUG_ERROR("plugin_unload_plugin() - %s [ID : %d] failed !!", domain_name, plugin_mo_repository[i].plugin_info.plugin_id);
814 _DEBUG_VERBOSE("plugin_unload_plugin() - %s [ID : %d] success !!", domain_name, plugin_mo_repository[i].plugin_info.plugin_id);
818 /* clear MO's plug-in repository */
819 plugin_clear_plugin_mo();
820 } else if (__compare_uchar_with_char(domain_name, "DeviceManager")) {
821 // int plugin_count = 0;
822 const plugin_device_manager_s *plugin_dm_repository = plugin_get_device_manager_plugin_repository(&plugin_count);
824 /* unload DeviceManager's plug-in */
825 for (i = 0; i < plugin_count; i++) {
826 plugin_error = plugin_unload_plugin(plugin_dm_repository[i].plugin_info.plugin_handle);
827 if (plugin_error != PLUGIN_SUCCESS) {
828 _DEBUG_ERROR("plugin_unload_plugin() - %s [ID : %d] failed !!", domain_name, plugin_dm_repository[i].plugin_info.plugin_id);
830 _DEBUG_VERBOSE("plugin_unload_plugin() - %s [ID : %d] success !!", domain_name, plugin_dm_repository[i].plugin_info.plugin_id);
834 /* clear DeviceManager's plug-in repository */
835 plugin_clear_plugin_device_manager();
838 domain_node = domain_node->next;
843 return SYNC_AGENT_INIT_SUCCESS;
846 static sync_agent_init_error_e __process_device_manage(xmlNode * device_manage_node)
850 retvm_if(device_manage_node == NULL, SYNC_AGENT_INIT_FAIL, "xmlNode is NULL !!");
852 sync_agent_dm_mo_error_e mo_err = dm_mo_alloc_modb_handler_mgr();
853 if (mo_err != SYNC_AGENT_DM_MO_SUCCESS) {
854 _DEBUG_ERROR("Failed to dm_mo_alloc_modb_handler_mgr() : %d", mo_err);
855 return SYNC_AGENT_INIT_DM_FAIL;
859 * Setting MO PlugIn DeviceInfo
861 char *mo_db_path_str = __get_child_node_content(device_manage_node, "MO-DB-Path");
863 // mo_err = dm_mo_open("/opt/dbspace/.momanager.db");
864 mo_err = dm_mo_open(mo_db_path_str);
865 if (mo_err != SYNC_AGENT_DM_MO_SUCCESS) {
866 _DEBUG_ERROR("Failed to dm_mo_open() : %d", mo_err);
867 return SYNC_AGENT_INIT_DM_FAIL;
870 dm_mo_create_mo_table_wraper();
872 char *dependent_devinfo_id_str = __get_child_node_content(device_manage_node, "DependentDevInfoID");
873 int dependent_devinfo_id = atoi(dependent_devinfo_id_str);
875 if (plugin_is_exsist_device_info_plugin()) {
876 _DEBUG_VERBOSE("Dependent device Info PlulgIn ID : %d", dependent_devinfo_id);
878 int *mo_plugIn_id_list = NULL;
879 int mo_plugIn_cnt = plugin_get_mo_plugin_id_list(&mo_plugIn_id_list);
881 _DEBUG_VERBOSE("Loaded MO PlugIn Count : %d", mo_plugIn_cnt);
884 for (; i < mo_plugIn_cnt; i++) {
885 plugin_set_func_get_device_info func_point_set_func_get_device_info = plugin_get_function_set_func_get_device_info(mo_plugIn_id_list[i]);
886 if (func_point_set_func_get_device_info != 0) {
887 func_point_set_func_get_device_info(sync_agent_get_devinfo);
889 _DEBUG_ERROR("func_point_set_func_get_device_info is NULL!!");
893 free(mo_plugIn_id_list);
898 return SYNC_AGENT_INIT_SUCCESS;
901 static char *__get_child_node_content(xmlNode * parent_node, const char *node_name)
905 if (parent_node == NULL || node_name == NULL) {
909 xmlNode *cursor_node = parent_node->children;
911 while (cursor_node != NULL) {
912 if (cursor_node->type == XML_ELEMENT_NODE) {
913 const xmlChar *compare_name = cursor_node->name;
914 if (__compare_uchar_with_char(compare_name, node_name)) {
916 return (char *)xmlNodeGetContent(cursor_node);
919 cursor_node = cursor_node->next;
925 static int __compare_uchar_with_char(const xmlChar * str, const char *str2)
929 if (str == NULL || str2 == NULL) {
935 return xmlStrEqual(str, (const xmlChar *)str2);