From b5a98c405476f655e265993997afb9e8772f47e5 Mon Sep 17 00:00:00 2001 From: Kim Kibum Date: Sun, 29 Apr 2012 17:01:58 +0900 Subject: [PATCH] upload tizen1.0 source --- CMakeLists.txt | 22 + debian/changelog | 7 + debian/compat | 1 + debian/control | 29 + debian/control.slp | 7 + debian/dirs | 2 + debian/libsync-agent-framework-dev.install | 2 + debian/libsync-agent-framework-dev.postinst | 4 + debian/libsync-agent-framework.install | 1 + debian/rules | 104 + debian/unit_test.sh | 32 + framework/.cproject | 250 ++ framework/.project | 78 + framework/CMakeLists.src | 23 + framework/CMakeLists.sub | 67 + framework/CMakeLists.txt | 119 + framework/include/Account/Account_Error.h | 61 + framework/include/Account/Account_Mgr.h | 106 + framework/include/Account/Account_Util.h | 85 + framework/include/DataAdapter/DACI_Agent.h | 839 ++++++ .../DataAdapter/DACI_Agent_Handler_Manager.h | 788 +++++ framework/include/DataAdapter/DACI_Agent_Mgr.h | 108 + framework/include/DataAdapter/DACI_ChangeLog.h | 126 + framework/include/DataAdapter/DACI_Common.h | 359 +++ framework/include/DataAdapter/DACI_Luid.h | 71 + framework/include/DataAdapter/DACI_Service.h | 302 ++ framework/include/DataAdapter/EXT_DACI_Converter.h | 118 + framework/include/DataAdapter/EXT_DACI_Errors.h | 81 + framework/include/Device/EXT_DCI_Common.h | 75 + framework/include/Device/EXT_DCI_DevExecutor.h | 79 + framework/include/Device/EXT_DCI_DevInfo.h | 95 + framework/include/Device/EXT_DCI_Errors.h | 55 + .../include/EngineController/engine_controller.h | 132 + .../EngineController/engine_controller_define.h | 107 + .../EngineController/engine_controller_internal.h | 85 + .../EngineController/engine_controller_message.h | 142 + .../include/EngineController/fundamental_type.h | 151 + .../include/EngineController/graph_edge_pool.h | 53 + framework/include/EngineController/hash_set.h | 56 + framework/include/EngineController/param.h | 74 + framework/include/EngineController/param_spec.h | 251 ++ .../include/EngineController/param_spec_internal.h | 125 + framework/include/EngineController/param_value.h | 83 + .../include/EngineController/queuing_rule_spec.h | 85 + .../EngineController/queuing_rule_spec_internal.h | 116 + .../EngineController/queuing_rule_spec_pool.h | 65 + framework/include/EngineController/task.h | 146 + .../include/EngineController/task_cancel_info.h | 84 + framework/include/EngineController/task_error.h | 65 + .../include/EngineController/task_info_pool.h | 77 + framework/include/EngineController/task_message.h | 76 + framework/include/EngineController/task_pool.h | 61 + framework/include/EngineController/task_process.h | 229 ++ framework/include/EngineController/task_spec.h | 261 ++ .../include/EngineController/task_spec_internal.h | 147 + framework/include/EngineController/thread_pool.h | 59 + framework/include/Event/Event_Config.h | 81 + framework/include/Event/Event_Data_Accessor.h | 103 + framework/include/Event/Event_Error.h | 62 + framework/include/Event/Event_Handler.h | 148 + framework/include/Event/Event_Spec.h | 80 + framework/include/Event/Event_UI_API.h | 121 + framework/include/Event/Event_Util.h | 49 + framework/include/FSAPI/FSAPI_operation.h | 216 ++ framework/include/FSAPI/FSAPI_util.h | 47 + framework/include/Initialization/initialize.h | 74 + .../include/Initialization/initialize_error.h | 72 + .../include/Initialization/initialize_parser.h | 47 + .../include/NetworkAccess/EXT_NA_NetworkStatus.h | 67 + .../include/NetworkAccess/IN_NA_FW_Callbacks.h | 60 + .../include/NetworkAccess/IN_NA_Session_Manager.h | 247 ++ framework/include/NetworkAccess/NACI.h | 341 +++ framework/include/NetworkAccess/NACI_Common.h | 54 + framework/include/NetworkAccess/NACI_Errors.h | 72 + framework/include/NetworkAccess/NA_External.h | 53 + .../protocol_binder/protocol_binder.h | 242 ++ .../protocol_binder/protocol_binder_common.h | 47 + .../protocol_binder/protocol_binder_definition.h | 161 + .../protocol_binder/protocol_binder_error.h | 84 + .../protocol_binder/protocol_binder_internal.h | 104 + .../protocol_binder/protocol_binder_util.h | 321 ++ .../protocol_binder_util_internal.h | 151 + framework/include/PlatformMonitor/EXT_PMCI.h | 162 + .../include/PlatformMonitor/EXT_PMCI_Common.h | 47 + .../include/PlatformMonitor/EXT_PMCI_Errors.h | 52 + framework/include/PlatformMonitor/EXT_PMCI_Noti.h | 53 + .../include/PlatformMonitor/EXT_PMCI_Struct.h | 130 + framework/include/PlugIn/DataConverter_Resource.h | 65 + .../include/PlugIn/PlatformMonitor_Resource.h | 57 + framework/include/PlugIn/PlugIn_Account.h | 101 + framework/include/PlugIn/PlugIn_DataConnector.h | 206 ++ framework/include/PlugIn/PlugIn_DataConverter.h | 96 + framework/include/PlugIn/PlugIn_DeviceInfo.h | 84 + framework/include/PlugIn/PlugIn_Error.h | 51 + .../PlugIn/PlugIn_Interface/Account_Interface.h | 126 + .../PlugIn_Interface/DataConnector_Interface.h | 367 +++ .../PlugIn_Interface/DataConnector_Resource.h | 63 + .../PlugIn_Interface/DataConverter_Interface.h | 140 + .../PlugIn/PlugIn_Interface/DeviceInfo_Interface.h | 109 + .../PlugIn_Interface/NetworkAccess_Interface.h | 172 ++ .../PlugIn_Interface/PlatformMonitor_Interface.h | 185 ++ framework/include/PlugIn/PlugIn_Mgr.h | 76 + framework/include/PlugIn/PlugIn_NetworkAccess.h | 108 + framework/include/PlugIn/PlugIn_PlatformMonitor.h | 158 + framework/include/PlugIn/PlugIn_Struct.h | 49 + framework/include/SyncAgent_Info.h | 64 + framework/include/Utility/fw_alloc.h | 108 + framework/include/Utility/fw_alloc_internal.h | 82 + framework/include/Utility/fw_assert.h | 96 + framework/include/Utility/fw_async_queue.h | 112 + framework/include/Utility/fw_cache.h | 129 + framework/include/Utility/fw_common.h | 71 + framework/include/Utility/fw_compress.h | 78 + framework/include/Utility/fw_list.h | 70 + framework/include/Utility/fw_log.h | 152 + framework/include/Utility/fw_mainloop.h | 49 + framework/include/Utility/fw_ref.h | 110 + .../include/Utility/fw_sequential_id_provider.h | 156 + .../Utility/fw_sequential_id_provider_internal.h | 175 ++ framework/include/Utility/fw_thread.h | 74 + framework/include/Utility/fw_time.h | 63 + framework/include/Utility/fw_timer.h | 71 + .../agent-framework/Account/Account_Error.h | 61 + .../DACI/DACI_Agent_Handler_Manager.h | 767 +++++ .../include/agent-framework/DACI/DACI_Common.h | 359 +++ .../include/agent-framework/DACI/EXT_DACI_Errors.h | 81 + .../agent-framework/Device/EXT_DCI_Common.h | 75 + .../agent-framework/Device/EXT_DCI_DevExecutor.h | 79 + .../agent-framework/Device/EXT_DCI_DevInfo.h | 95 + .../agent-framework/Device/EXT_DCI_Errors.h | 55 + .../agent-framework/FSAPI/FSAPI_operation.h | 216 ++ .../NetworkAccess/EXT_NA_NetworkStatus.h | 67 + .../PlatformMonitor/EXT_PMCI_Struct.h | 130 + .../agent-framework/PlugIn/Account_Interface.h | 126 + .../PlugIn/DataConnector_Interface.h | 367 +++ .../PlugIn/DataConnector_Resource.h | 63 + .../PlugIn/DataConverter_Interface.h | 140 + .../PlugIn/DataConverter_Resource.h | 65 + .../agent-framework/PlugIn/DeviceInfo_Interface.h | 109 + .../PlugIn/NetworkAccess_Interface.h | 172 ++ .../PlugIn/PlatformMonitor_Interface.h | 185 ++ .../PlugIn/PlatformMonitor_Resource.h | 57 + .../agent-framework/Utility/fw_async_queue.h | 112 + .../include/agent-framework/Utility/fw_compress.h | 78 + framework/include/agent-framework/Utility/fw_log.h | 152 + .../EXT_SA_Encryption_Decryption.h | 94 + framework/include/fw_define.h | 47 + .../EXT_SA_Encryption_Decryption.h | 94 + .../IN_SA_Cryptograhic_Hash_Function.h | 46 + framework/include/securityAssistant/IN_SA_MD5.h | 73 + framework/src/Account/Account_Mgr.c | 279 ++ framework/src/Account/Account_Util.c | 144 + framework/src/DataAdapter/DACI_Agent.c | 3138 ++++++++++++++++++++ .../src/DataAdapter/DACI_Agent_Handler_Manager.c | 1181 ++++++++ framework/src/DataAdapter/DACI_Agent_Mgr.c | 571 ++++ framework/src/DataAdapter/DACI_ChangeLog.c | 641 ++++ framework/src/DataAdapter/DACI_Common.c | 142 + framework/src/DataAdapter/DACI_Luid.c | 131 + framework/src/DataAdapter/DACI_Service.c | 945 ++++++ framework/src/DataAdapter/EXT_DACI_Converter.c | 191 ++ framework/src/Device/EXT_DCI_DevExecutor.c | 87 + framework/src/Device/EXT_DCI_DevInfo.c | 125 + framework/src/EngineController/engine_controller.c | 680 +++++ .../EngineController/engine_controller_message.c | 235 ++ framework/src/EngineController/graph_edge_pool.c | 110 + framework/src/EngineController/hash_set.c | 107 + framework/src/EngineController/param.c | 74 + framework/src/EngineController/param_spec.c | 560 ++++ framework/src/EngineController/param_value.c | 112 + framework/src/EngineController/queuing_rule_spec.c | 647 ++++ .../src/EngineController/queuing_rule_spec_pool.c | 141 + framework/src/EngineController/task.c | 1033 +++++++ framework/src/EngineController/task_cancel_info.c | 284 ++ framework/src/EngineController/task_error.c | 64 + framework/src/EngineController/task_info_pool.c | 194 ++ framework/src/EngineController/task_message.c | 114 + framework/src/EngineController/task_pool.c | 121 + framework/src/EngineController/task_process.c | 88 + framework/src/EngineController/task_spec.c | 1043 +++++++ framework/src/EngineController/thread_pool.c | 169 ++ framework/src/Event/Event_Config.c | 351 +++ framework/src/Event/Event_Data_Accessor.c | 181 ++ framework/src/Event/Event_Handler.c | 403 +++ framework/src/Event/Event_UI_API.c | 348 +++ framework/src/Event/Event_Util.c | 63 + framework/src/FSAPI/FSAPI_operation.c | 692 +++++ framework/src/FSAPI/FSAPI_util.c | 61 + framework/src/Initialization/initialize.c | 162 + framework/src/Initialization/initialize_parser.c | 511 ++++ framework/src/NetworkAccess/IN_NA_FW_Callbacks.c | 119 + .../src/NetworkAccess/IN_NA_Session_Manager.c | 948 ++++++ framework/src/NetworkAccess/NACI.c | 740 +++++ .../protocol_binder/protocol_binder.c | 1116 +++++++ .../protocol_binder/protocol_binder_util.c | 824 +++++ framework/src/PlatformMonitor/EXT_PMCI.c | 388 +++ framework/src/PlugIn/PlugIn_Account.c | 163 + framework/src/PlugIn/PlugIn_DataConnector.c | 482 +++ framework/src/PlugIn/PlugIn_DataConverter.c | 181 ++ framework/src/PlugIn/PlugIn_DeviceInfo.c | 148 + framework/src/PlugIn/PlugIn_Mgr.c | 60 + framework/src/PlugIn/PlugIn_NetworkAccess.c | 241 ++ framework/src/PlugIn/PlugIn_PlatformMonitor.c | 297 ++ framework/src/Utility/fw_alloc.c | 352 +++ framework/src/Utility/fw_async_queue.c | 111 + framework/src/Utility/fw_cache.c | 251 ++ framework/src/Utility/fw_compress.c | 170 ++ framework/src/Utility/fw_list.c | 84 + framework/src/Utility/fw_log.c | 148 + framework/src/Utility/fw_mainloop.c | 128 + framework/src/Utility/fw_ref.c | 94 + framework/src/Utility/fw_sequential_id_provider.c | 1111 +++++++ framework/src/Utility/fw_thread.c | 86 + framework/src/Utility/fw_time.c | 71 + framework/src/Utility/fw_timer.c | 175 ++ .../EXT_SA_Encryption_Decryption.c | 147 + .../IN_SA_Cryptograhic_Hash_Function.c | 158 + framework/src/securityAssistant/IN_SA_MD5.c | 233 ++ .../test/include/suites/unit_test_fw_alloc_suite.h | 15 + .../test/include/suites/unit_test_fw_log_suite.h | 15 + .../unit_test_fw_sequential_id_provider_suite.h | 15 + .../suites/unit_test_protocol_binder_suite.h | 15 + .../test/include/suites/unit_test_sample_suite.h | 15 + framework/test/include/unit_test_common.h | 16 + framework/test/include/unit_test_run.h | 22 + framework/test/include/unit_test_suites.h | 28 + framework/test/src/fw_test_main.c | 14 + .../test/src/suites/unit_test_fw_alloc_suite.c | 105 + framework/test/src/suites/unit_test_fw_log_suite.c | 49 + .../unit_test_fw_sequential_id_provider_suite.c | 427 +++ .../test/src/suites/unit_test_protocol_binder.c | 253 ++ framework/test/src/suites/unit_test_sample_suite.c | 55 + framework/test/src/unit_test_run.c | 121 + fw-plugin/CMakeLists.txt | 11 + fw-plugin/account-plugIn/.cproject | 31 + fw-plugin/account-plugIn/.project | 78 + fw-plugin/account-plugIn/CMakeLists.src | 1 + fw-plugin/account-plugIn/CMakeLists.sub | 38 + fw-plugin/account-plugIn/CMakeLists.txt | 33 + fw-plugin/account-plugIn/include/Account_Info.h | 51 + fw-plugin/account-plugIn/src/PlugIn_Interface.c | 426 +++ fw-plugin/calendar-plugIn/.cproject | 31 + fw-plugin/calendar-plugIn/.project | 78 + fw-plugin/calendar-plugIn/CMakeLists.src | 1 + fw-plugin/calendar-plugIn/CMakeLists.sub | 37 + fw-plugin/calendar-plugIn/CMakeLists.txt | 33 + .../include/EXT_DataStore_Info_Calendar.h | 72 + fw-plugin/calendar-plugIn/include/Extern_Info.h | 44 + .../include/IN_DataStore_Info_Calendar.h | 80 + .../calendar-plugIn/include/Item_Change_Info.h | 43 + fw-plugin/calendar-plugIn/src/Item_Change_Info.c | 54 + fw-plugin/calendar-plugIn/src/PlugIn_Interface.c | 1208 ++++++++ fw-plugin/contact-plugIn/.cproject | 31 + fw-plugin/contact-plugIn/.project | 78 + fw-plugin/contact-plugIn/CMakeLists.src | 1 + fw-plugin/contact-plugIn/CMakeLists.sub | 37 + fw-plugin/contact-plugIn/CMakeLists.txt | 33 + .../include/EXT_DataStore_Info_Contact.h | 80 + fw-plugin/contact-plugIn/include/Extern_Info.h | 44 + .../include/IN_DataStore_Info_Contact.h | 99 + .../contact-plugIn/include/Item_Change_Info.h | 43 + fw-plugin/contact-plugIn/src/Item_Change_Info.c | 69 + fw-plugin/contact-plugIn/src/PlugIn_Interface.c | 1328 +++++++++ fw-plugin/http-plugIn/.cproject | 293 ++ fw-plugin/http-plugIn/.project | 145 + fw-plugin/http-plugIn/CMakeLists.src | 1 + fw-plugin/http-plugIn/CMakeLists.sub | 37 + fw-plugin/http-plugIn/CMakeLists.txt | 33 + fw-plugin/http-plugIn/include/NA_External.h | 44 + fw-plugin/http-plugIn/include/http_status.h | 135 + fw-plugin/http-plugIn/src/PlugIn_Interface.c | 859 ++++++ fw-plugin/memo-plugIn/.cproject | 31 + fw-plugin/memo-plugIn/.project | 78 + fw-plugin/memo-plugIn/CMakeLists.src | 1 + fw-plugin/memo-plugIn/CMakeLists.sub | 37 + fw-plugin/memo-plugIn/CMakeLists.txt | 33 + fw-plugin/memo-plugIn/include/Extern_Info.h | 44 + fw-plugin/memo-plugIn/include/Item_Change_Info.h | 43 + fw-plugin/memo-plugIn/src/Item_Change_Info.c | 54 + fw-plugin/memo-plugIn/src/PlugIn_Interface.c | 744 +++++ fw-plugin/plain-text-plugIn/.cproject | 31 + fw-plugin/plain-text-plugIn/.project | 78 + fw-plugin/plain-text-plugIn/CMakeLists.src | 1 + fw-plugin/plain-text-plugIn/CMakeLists.sub | 37 + fw-plugin/plain-text-plugIn/CMakeLists.txt | 33 + .../include/IN_DataStore_Info_Plain_Text.h | 50 + fw-plugin/plain-text-plugIn/src/PlugIn_Interface.c | 244 ++ fw-plugin/slp-device-plugIn/.cproject | 376 +++ fw-plugin/slp-device-plugIn/.project | 145 + fw-plugin/slp-device-plugIn/CMakeLists.src | 1 + fw-plugin/slp-device-plugIn/CMakeLists.sub | 37 + fw-plugin/slp-device-plugIn/CMakeLists.txt | 32 + .../include/PlugIn_DevExe_Error.h | 66 + .../slp-device-plugIn/include/slp_device_info.h | 57 + fw-plugin/slp-device-plugIn/include/slp_ref.h | 54 + .../src/PlugIn_Interface_DevExe.c | 130 + .../src/PlugIn_Interface_DevInfo.c | 362 +++ fw-plugin/slp-device-plugIn/src/slp_device_info.c | 288 ++ fw-plugin/slp-sysnoti-plugIn/.cproject | 293 ++ fw-plugin/slp-sysnoti-plugIn/.project | 145 + fw-plugin/slp-sysnoti-plugIn/CMakeLists.src | 1 + fw-plugin/slp-sysnoti-plugIn/CMakeLists.sub | 37 + fw-plugin/slp-sysnoti-plugIn/CMakeLists.txt | 32 + fw-plugin/slp-sysnoti-plugIn/include/SLP_Alarm.h | 51 + .../slp-sysnoti-plugIn/include/SLP_CallBack.h | 70 + .../slp-sysnoti-plugIn/include/SLP_ConnManager.h | 61 + fw-plugin/slp-sysnoti-plugIn/include/SLP_SAN.h | 52 + .../slp-sysnoti-plugIn/src/PlugIn_Interface.c | 319 ++ fw-plugin/slp-sysnoti-plugIn/src/SLP_Alarm.c | 449 +++ fw-plugin/slp-sysnoti-plugIn/src/SLP_CallBack.c | 234 ++ fw-plugin/slp-sysnoti-plugIn/src/SLP_ConnManager.c | 390 +++ fw-plugin/slp-sysnoti-plugIn/src/SLP_SAN.c | 394 +++ fw-plugin/vcalendar-plugIn/.cproject | 31 + fw-plugin/vcalendar-plugIn/.project | 78 + fw-plugin/vcalendar-plugIn/CMakeLists.src | 1 + fw-plugin/vcalendar-plugIn/CMakeLists.sub | 37 + fw-plugin/vcalendar-plugIn/CMakeLists.txt | 33 + .../include/IN_DataStore_Info_Vcalendar.h | 248 ++ fw-plugin/vcalendar-plugIn/include/encoding_util.h | 255 ++ fw-plugin/vcalendar-plugIn/src/PlugIn_Interface.c | 516 ++++ fw-plugin/vcalendar-plugIn/src/encoding_util.c | 775 +++++ fw-plugin/vcard-plugIn/.cproject | 31 + fw-plugin/vcard-plugIn/.project | 78 + fw-plugin/vcard-plugIn/CMakeLists.src | 1 + fw-plugin/vcard-plugIn/CMakeLists.sub | 37 + fw-plugin/vcard-plugIn/CMakeLists.txt | 33 + .../vcard-plugIn/include/IN_DataStore_Info_Vcard.h | 174 ++ fw-plugin/vcard-plugIn/include/PlugIn_Spec.h | 83 + fw-plugin/vcard-plugIn/include/encoding_util.h | 255 ++ fw-plugin/vcard-plugIn/src/PlugIn_Interface.c | 546 ++++ fw-plugin/vcard-plugIn/src/encoding_util.c | 758 +++++ packaging/sync-agent-framework.spec | 88 + pkg_build.sh | 4 + pkg_clean.sh | 28 + pkg_install.sh | 6 + pkg_uninstall.sh | 6 + sync-agent-framework.pc.in | 19 + 336 files changed, 60002 insertions(+) create mode 100755 CMakeLists.txt create mode 100755 debian/changelog create mode 100755 debian/compat create mode 100755 debian/control create mode 100755 debian/control.slp create mode 100755 debian/dirs create mode 100755 debian/libsync-agent-framework-dev.install create mode 100755 debian/libsync-agent-framework-dev.postinst create mode 100755 debian/libsync-agent-framework.install create mode 100755 debian/rules create mode 100755 debian/unit_test.sh create mode 100644 framework/.cproject create mode 100644 framework/.project create mode 100755 framework/CMakeLists.src create mode 100755 framework/CMakeLists.sub create mode 100755 framework/CMakeLists.txt create mode 100755 framework/include/Account/Account_Error.h create mode 100755 framework/include/Account/Account_Mgr.h create mode 100755 framework/include/Account/Account_Util.h create mode 100755 framework/include/DataAdapter/DACI_Agent.h create mode 100755 framework/include/DataAdapter/DACI_Agent_Handler_Manager.h create mode 100755 framework/include/DataAdapter/DACI_Agent_Mgr.h create mode 100755 framework/include/DataAdapter/DACI_ChangeLog.h create mode 100755 framework/include/DataAdapter/DACI_Common.h create mode 100755 framework/include/DataAdapter/DACI_Luid.h create mode 100755 framework/include/DataAdapter/DACI_Service.h create mode 100755 framework/include/DataAdapter/EXT_DACI_Converter.h create mode 100755 framework/include/DataAdapter/EXT_DACI_Errors.h create mode 100755 framework/include/Device/EXT_DCI_Common.h create mode 100755 framework/include/Device/EXT_DCI_DevExecutor.h create mode 100755 framework/include/Device/EXT_DCI_DevInfo.h create mode 100755 framework/include/Device/EXT_DCI_Errors.h create mode 100644 framework/include/EngineController/engine_controller.h create mode 100644 framework/include/EngineController/engine_controller_define.h create mode 100644 framework/include/EngineController/engine_controller_internal.h create mode 100644 framework/include/EngineController/engine_controller_message.h create mode 100644 framework/include/EngineController/fundamental_type.h create mode 100644 framework/include/EngineController/graph_edge_pool.h create mode 100644 framework/include/EngineController/hash_set.h create mode 100644 framework/include/EngineController/param.h create mode 100644 framework/include/EngineController/param_spec.h create mode 100644 framework/include/EngineController/param_spec_internal.h create mode 100644 framework/include/EngineController/param_value.h create mode 100644 framework/include/EngineController/queuing_rule_spec.h create mode 100644 framework/include/EngineController/queuing_rule_spec_internal.h create mode 100644 framework/include/EngineController/queuing_rule_spec_pool.h create mode 100644 framework/include/EngineController/task.h create mode 100644 framework/include/EngineController/task_cancel_info.h create mode 100644 framework/include/EngineController/task_error.h create mode 100644 framework/include/EngineController/task_info_pool.h create mode 100644 framework/include/EngineController/task_message.h create mode 100644 framework/include/EngineController/task_pool.h create mode 100644 framework/include/EngineController/task_process.h create mode 100644 framework/include/EngineController/task_spec.h create mode 100644 framework/include/EngineController/task_spec_internal.h create mode 100644 framework/include/EngineController/thread_pool.h create mode 100755 framework/include/Event/Event_Config.h create mode 100755 framework/include/Event/Event_Data_Accessor.h create mode 100755 framework/include/Event/Event_Error.h create mode 100755 framework/include/Event/Event_Handler.h create mode 100755 framework/include/Event/Event_Spec.h create mode 100755 framework/include/Event/Event_UI_API.h create mode 100644 framework/include/Event/Event_Util.h create mode 100644 framework/include/FSAPI/FSAPI_operation.h create mode 100644 framework/include/FSAPI/FSAPI_util.h create mode 100755 framework/include/Initialization/initialize.h create mode 100755 framework/include/Initialization/initialize_error.h create mode 100755 framework/include/Initialization/initialize_parser.h create mode 100755 framework/include/NetworkAccess/EXT_NA_NetworkStatus.h create mode 100644 framework/include/NetworkAccess/IN_NA_FW_Callbacks.h create mode 100755 framework/include/NetworkAccess/IN_NA_Session_Manager.h create mode 100644 framework/include/NetworkAccess/NACI.h create mode 100755 framework/include/NetworkAccess/NACI_Common.h create mode 100755 framework/include/NetworkAccess/NACI_Errors.h create mode 100755 framework/include/NetworkAccess/NA_External.h create mode 100755 framework/include/NetworkAssistant/protocol_binder/protocol_binder.h create mode 100755 framework/include/NetworkAssistant/protocol_binder/protocol_binder_common.h create mode 100755 framework/include/NetworkAssistant/protocol_binder/protocol_binder_definition.h create mode 100755 framework/include/NetworkAssistant/protocol_binder/protocol_binder_error.h create mode 100755 framework/include/NetworkAssistant/protocol_binder/protocol_binder_internal.h create mode 100755 framework/include/NetworkAssistant/protocol_binder/protocol_binder_util.h create mode 100755 framework/include/NetworkAssistant/protocol_binder/protocol_binder_util_internal.h create mode 100755 framework/include/PlatformMonitor/EXT_PMCI.h create mode 100755 framework/include/PlatformMonitor/EXT_PMCI_Common.h create mode 100755 framework/include/PlatformMonitor/EXT_PMCI_Errors.h create mode 100755 framework/include/PlatformMonitor/EXT_PMCI_Noti.h create mode 100755 framework/include/PlatformMonitor/EXT_PMCI_Struct.h create mode 100644 framework/include/PlugIn/DataConverter_Resource.h create mode 100644 framework/include/PlugIn/PlatformMonitor_Resource.h create mode 100755 framework/include/PlugIn/PlugIn_Account.h create mode 100755 framework/include/PlugIn/PlugIn_DataConnector.h create mode 100755 framework/include/PlugIn/PlugIn_DataConverter.h create mode 100755 framework/include/PlugIn/PlugIn_DeviceInfo.h create mode 100755 framework/include/PlugIn/PlugIn_Error.h create mode 100755 framework/include/PlugIn/PlugIn_Interface/Account_Interface.h create mode 100755 framework/include/PlugIn/PlugIn_Interface/DataConnector_Interface.h create mode 100755 framework/include/PlugIn/PlugIn_Interface/DataConnector_Resource.h create mode 100644 framework/include/PlugIn/PlugIn_Interface/DataConverter_Interface.h create mode 100644 framework/include/PlugIn/PlugIn_Interface/DeviceInfo_Interface.h create mode 100644 framework/include/PlugIn/PlugIn_Interface/NetworkAccess_Interface.h create mode 100644 framework/include/PlugIn/PlugIn_Interface/PlatformMonitor_Interface.h create mode 100755 framework/include/PlugIn/PlugIn_Mgr.h create mode 100755 framework/include/PlugIn/PlugIn_NetworkAccess.h create mode 100755 framework/include/PlugIn/PlugIn_PlatformMonitor.h create mode 100755 framework/include/PlugIn/PlugIn_Struct.h create mode 100755 framework/include/SyncAgent_Info.h create mode 100644 framework/include/Utility/fw_alloc.h create mode 100644 framework/include/Utility/fw_alloc_internal.h create mode 100644 framework/include/Utility/fw_assert.h create mode 100644 framework/include/Utility/fw_async_queue.h create mode 100644 framework/include/Utility/fw_cache.h create mode 100644 framework/include/Utility/fw_common.h create mode 100644 framework/include/Utility/fw_compress.h create mode 100644 framework/include/Utility/fw_list.h create mode 100644 framework/include/Utility/fw_log.h create mode 100644 framework/include/Utility/fw_mainloop.h create mode 100644 framework/include/Utility/fw_ref.h create mode 100644 framework/include/Utility/fw_sequential_id_provider.h create mode 100644 framework/include/Utility/fw_sequential_id_provider_internal.h create mode 100644 framework/include/Utility/fw_thread.h create mode 100644 framework/include/Utility/fw_time.h create mode 100644 framework/include/Utility/fw_timer.h create mode 100755 framework/include/agent-framework/Account/Account_Error.h create mode 100755 framework/include/agent-framework/DACI/DACI_Agent_Handler_Manager.h create mode 100755 framework/include/agent-framework/DACI/DACI_Common.h create mode 100755 framework/include/agent-framework/DACI/EXT_DACI_Errors.h create mode 100755 framework/include/agent-framework/Device/EXT_DCI_Common.h create mode 100755 framework/include/agent-framework/Device/EXT_DCI_DevExecutor.h create mode 100755 framework/include/agent-framework/Device/EXT_DCI_DevInfo.h create mode 100755 framework/include/agent-framework/Device/EXT_DCI_Errors.h create mode 100644 framework/include/agent-framework/FSAPI/FSAPI_operation.h create mode 100755 framework/include/agent-framework/NetworkAccess/EXT_NA_NetworkStatus.h create mode 100755 framework/include/agent-framework/PlatformMonitor/EXT_PMCI_Struct.h create mode 100755 framework/include/agent-framework/PlugIn/Account_Interface.h create mode 100755 framework/include/agent-framework/PlugIn/DataConnector_Interface.h create mode 100755 framework/include/agent-framework/PlugIn/DataConnector_Resource.h create mode 100644 framework/include/agent-framework/PlugIn/DataConverter_Interface.h create mode 100644 framework/include/agent-framework/PlugIn/DataConverter_Resource.h create mode 100644 framework/include/agent-framework/PlugIn/DeviceInfo_Interface.h create mode 100644 framework/include/agent-framework/PlugIn/NetworkAccess_Interface.h create mode 100644 framework/include/agent-framework/PlugIn/PlatformMonitor_Interface.h create mode 100644 framework/include/agent-framework/PlugIn/PlatformMonitor_Resource.h create mode 100644 framework/include/agent-framework/Utility/fw_async_queue.h create mode 100644 framework/include/agent-framework/Utility/fw_compress.h create mode 100644 framework/include/agent-framework/Utility/fw_log.h create mode 100755 framework/include/agent-framework/securityAssistant/EXT_SA_Encryption_Decryption.h create mode 100755 framework/include/fw_define.h create mode 100755 framework/include/securityAssistant/EXT_SA_Encryption_Decryption.h create mode 100755 framework/include/securityAssistant/IN_SA_Cryptograhic_Hash_Function.h create mode 100755 framework/include/securityAssistant/IN_SA_MD5.h create mode 100755 framework/src/Account/Account_Mgr.c create mode 100755 framework/src/Account/Account_Util.c create mode 100755 framework/src/DataAdapter/DACI_Agent.c create mode 100755 framework/src/DataAdapter/DACI_Agent_Handler_Manager.c create mode 100755 framework/src/DataAdapter/DACI_Agent_Mgr.c create mode 100755 framework/src/DataAdapter/DACI_ChangeLog.c create mode 100755 framework/src/DataAdapter/DACI_Common.c create mode 100755 framework/src/DataAdapter/DACI_Luid.c create mode 100755 framework/src/DataAdapter/DACI_Service.c create mode 100755 framework/src/DataAdapter/EXT_DACI_Converter.c create mode 100755 framework/src/Device/EXT_DCI_DevExecutor.c create mode 100755 framework/src/Device/EXT_DCI_DevInfo.c create mode 100755 framework/src/EngineController/engine_controller.c create mode 100755 framework/src/EngineController/engine_controller_message.c create mode 100755 framework/src/EngineController/graph_edge_pool.c create mode 100755 framework/src/EngineController/hash_set.c create mode 100755 framework/src/EngineController/param.c create mode 100755 framework/src/EngineController/param_spec.c create mode 100755 framework/src/EngineController/param_value.c create mode 100755 framework/src/EngineController/queuing_rule_spec.c create mode 100755 framework/src/EngineController/queuing_rule_spec_pool.c create mode 100755 framework/src/EngineController/task.c create mode 100755 framework/src/EngineController/task_cancel_info.c create mode 100755 framework/src/EngineController/task_error.c create mode 100755 framework/src/EngineController/task_info_pool.c create mode 100755 framework/src/EngineController/task_message.c create mode 100755 framework/src/EngineController/task_pool.c create mode 100755 framework/src/EngineController/task_process.c create mode 100755 framework/src/EngineController/task_spec.c create mode 100755 framework/src/EngineController/thread_pool.c create mode 100755 framework/src/Event/Event_Config.c create mode 100755 framework/src/Event/Event_Data_Accessor.c create mode 100755 framework/src/Event/Event_Handler.c create mode 100755 framework/src/Event/Event_UI_API.c create mode 100644 framework/src/Event/Event_Util.c create mode 100644 framework/src/FSAPI/FSAPI_operation.c create mode 100644 framework/src/FSAPI/FSAPI_util.c create mode 100755 framework/src/Initialization/initialize.c create mode 100755 framework/src/Initialization/initialize_parser.c create mode 100644 framework/src/NetworkAccess/IN_NA_FW_Callbacks.c create mode 100755 framework/src/NetworkAccess/IN_NA_Session_Manager.c create mode 100644 framework/src/NetworkAccess/NACI.c create mode 100755 framework/src/NetworkAssistant/protocol_binder/protocol_binder.c create mode 100755 framework/src/NetworkAssistant/protocol_binder/protocol_binder_util.c create mode 100755 framework/src/PlatformMonitor/EXT_PMCI.c create mode 100755 framework/src/PlugIn/PlugIn_Account.c create mode 100755 framework/src/PlugIn/PlugIn_DataConnector.c create mode 100755 framework/src/PlugIn/PlugIn_DataConverter.c create mode 100755 framework/src/PlugIn/PlugIn_DeviceInfo.c create mode 100755 framework/src/PlugIn/PlugIn_Mgr.c create mode 100755 framework/src/PlugIn/PlugIn_NetworkAccess.c create mode 100755 framework/src/PlugIn/PlugIn_PlatformMonitor.c create mode 100755 framework/src/Utility/fw_alloc.c create mode 100755 framework/src/Utility/fw_async_queue.c create mode 100755 framework/src/Utility/fw_cache.c create mode 100755 framework/src/Utility/fw_compress.c create mode 100644 framework/src/Utility/fw_list.c create mode 100755 framework/src/Utility/fw_log.c create mode 100755 framework/src/Utility/fw_mainloop.c create mode 100755 framework/src/Utility/fw_ref.c create mode 100755 framework/src/Utility/fw_sequential_id_provider.c create mode 100755 framework/src/Utility/fw_thread.c create mode 100755 framework/src/Utility/fw_time.c create mode 100755 framework/src/Utility/fw_timer.c create mode 100755 framework/src/securityAssistant/EXT_SA_Encryption_Decryption.c create mode 100755 framework/src/securityAssistant/IN_SA_Cryptograhic_Hash_Function.c create mode 100755 framework/src/securityAssistant/IN_SA_MD5.c create mode 100755 framework/test/include/suites/unit_test_fw_alloc_suite.h create mode 100755 framework/test/include/suites/unit_test_fw_log_suite.h create mode 100755 framework/test/include/suites/unit_test_fw_sequential_id_provider_suite.h create mode 100755 framework/test/include/suites/unit_test_protocol_binder_suite.h create mode 100755 framework/test/include/suites/unit_test_sample_suite.h create mode 100755 framework/test/include/unit_test_common.h create mode 100755 framework/test/include/unit_test_run.h create mode 100755 framework/test/include/unit_test_suites.h create mode 100755 framework/test/src/fw_test_main.c create mode 100755 framework/test/src/suites/unit_test_fw_alloc_suite.c create mode 100755 framework/test/src/suites/unit_test_fw_log_suite.c create mode 100755 framework/test/src/suites/unit_test_fw_sequential_id_provider_suite.c create mode 100755 framework/test/src/suites/unit_test_protocol_binder.c create mode 100755 framework/test/src/suites/unit_test_sample_suite.c create mode 100755 framework/test/src/unit_test_run.c create mode 100755 fw-plugin/CMakeLists.txt create mode 100755 fw-plugin/account-plugIn/.cproject create mode 100755 fw-plugin/account-plugIn/.project create mode 100755 fw-plugin/account-plugIn/CMakeLists.src create mode 100755 fw-plugin/account-plugIn/CMakeLists.sub create mode 100755 fw-plugin/account-plugIn/CMakeLists.txt create mode 100755 fw-plugin/account-plugIn/include/Account_Info.h create mode 100755 fw-plugin/account-plugIn/src/PlugIn_Interface.c create mode 100755 fw-plugin/calendar-plugIn/.cproject create mode 100755 fw-plugin/calendar-plugIn/.project create mode 100755 fw-plugin/calendar-plugIn/CMakeLists.src create mode 100755 fw-plugin/calendar-plugIn/CMakeLists.sub create mode 100755 fw-plugin/calendar-plugIn/CMakeLists.txt create mode 100755 fw-plugin/calendar-plugIn/include/EXT_DataStore_Info_Calendar.h create mode 100755 fw-plugin/calendar-plugIn/include/Extern_Info.h create mode 100755 fw-plugin/calendar-plugIn/include/IN_DataStore_Info_Calendar.h create mode 100755 fw-plugin/calendar-plugIn/include/Item_Change_Info.h create mode 100755 fw-plugin/calendar-plugIn/src/Item_Change_Info.c create mode 100755 fw-plugin/calendar-plugIn/src/PlugIn_Interface.c create mode 100755 fw-plugin/contact-plugIn/.cproject create mode 100755 fw-plugin/contact-plugIn/.project create mode 100755 fw-plugin/contact-plugIn/CMakeLists.src create mode 100755 fw-plugin/contact-plugIn/CMakeLists.sub create mode 100755 fw-plugin/contact-plugIn/CMakeLists.txt create mode 100755 fw-plugin/contact-plugIn/include/EXT_DataStore_Info_Contact.h create mode 100755 fw-plugin/contact-plugIn/include/Extern_Info.h create mode 100755 fw-plugin/contact-plugIn/include/IN_DataStore_Info_Contact.h create mode 100755 fw-plugin/contact-plugIn/include/Item_Change_Info.h create mode 100755 fw-plugin/contact-plugIn/src/Item_Change_Info.c create mode 100755 fw-plugin/contact-plugIn/src/PlugIn_Interface.c create mode 100755 fw-plugin/http-plugIn/.cproject create mode 100755 fw-plugin/http-plugIn/.project create mode 100755 fw-plugin/http-plugIn/CMakeLists.src create mode 100755 fw-plugin/http-plugIn/CMakeLists.sub create mode 100755 fw-plugin/http-plugIn/CMakeLists.txt create mode 100755 fw-plugin/http-plugIn/include/NA_External.h create mode 100755 fw-plugin/http-plugIn/include/http_status.h create mode 100755 fw-plugin/http-plugIn/src/PlugIn_Interface.c create mode 100755 fw-plugin/memo-plugIn/.cproject create mode 100755 fw-plugin/memo-plugIn/.project create mode 100755 fw-plugin/memo-plugIn/CMakeLists.src create mode 100755 fw-plugin/memo-plugIn/CMakeLists.sub create mode 100755 fw-plugin/memo-plugIn/CMakeLists.txt create mode 100755 fw-plugin/memo-plugIn/include/Extern_Info.h create mode 100755 fw-plugin/memo-plugIn/include/Item_Change_Info.h create mode 100755 fw-plugin/memo-plugIn/src/Item_Change_Info.c create mode 100755 fw-plugin/memo-plugIn/src/PlugIn_Interface.c create mode 100755 fw-plugin/plain-text-plugIn/.cproject create mode 100755 fw-plugin/plain-text-plugIn/.project create mode 100755 fw-plugin/plain-text-plugIn/CMakeLists.src create mode 100755 fw-plugin/plain-text-plugIn/CMakeLists.sub create mode 100755 fw-plugin/plain-text-plugIn/CMakeLists.txt create mode 100755 fw-plugin/plain-text-plugIn/include/IN_DataStore_Info_Plain_Text.h create mode 100755 fw-plugin/plain-text-plugIn/src/PlugIn_Interface.c create mode 100755 fw-plugin/slp-device-plugIn/.cproject create mode 100755 fw-plugin/slp-device-plugIn/.project create mode 100755 fw-plugin/slp-device-plugIn/CMakeLists.src create mode 100755 fw-plugin/slp-device-plugIn/CMakeLists.sub create mode 100755 fw-plugin/slp-device-plugIn/CMakeLists.txt create mode 100755 fw-plugin/slp-device-plugIn/include/PlugIn_DevExe_Error.h create mode 100755 fw-plugin/slp-device-plugIn/include/slp_device_info.h create mode 100755 fw-plugin/slp-device-plugIn/include/slp_ref.h create mode 100755 fw-plugin/slp-device-plugIn/src/PlugIn_Interface_DevExe.c create mode 100755 fw-plugin/slp-device-plugIn/src/PlugIn_Interface_DevInfo.c create mode 100755 fw-plugin/slp-device-plugIn/src/slp_device_info.c create mode 100755 fw-plugin/slp-sysnoti-plugIn/.cproject create mode 100755 fw-plugin/slp-sysnoti-plugIn/.project create mode 100755 fw-plugin/slp-sysnoti-plugIn/CMakeLists.src create mode 100755 fw-plugin/slp-sysnoti-plugIn/CMakeLists.sub create mode 100755 fw-plugin/slp-sysnoti-plugIn/CMakeLists.txt create mode 100755 fw-plugin/slp-sysnoti-plugIn/include/SLP_Alarm.h create mode 100644 fw-plugin/slp-sysnoti-plugIn/include/SLP_CallBack.h create mode 100755 fw-plugin/slp-sysnoti-plugIn/include/SLP_ConnManager.h create mode 100755 fw-plugin/slp-sysnoti-plugIn/include/SLP_SAN.h create mode 100755 fw-plugin/slp-sysnoti-plugIn/src/PlugIn_Interface.c create mode 100755 fw-plugin/slp-sysnoti-plugIn/src/SLP_Alarm.c create mode 100644 fw-plugin/slp-sysnoti-plugIn/src/SLP_CallBack.c create mode 100755 fw-plugin/slp-sysnoti-plugIn/src/SLP_ConnManager.c create mode 100755 fw-plugin/slp-sysnoti-plugIn/src/SLP_SAN.c create mode 100755 fw-plugin/vcalendar-plugIn/.cproject create mode 100755 fw-plugin/vcalendar-plugIn/.project create mode 100755 fw-plugin/vcalendar-plugIn/CMakeLists.src create mode 100755 fw-plugin/vcalendar-plugIn/CMakeLists.sub create mode 100755 fw-plugin/vcalendar-plugIn/CMakeLists.txt create mode 100755 fw-plugin/vcalendar-plugIn/include/IN_DataStore_Info_Vcalendar.h create mode 100755 fw-plugin/vcalendar-plugIn/include/encoding_util.h create mode 100755 fw-plugin/vcalendar-plugIn/src/PlugIn_Interface.c create mode 100755 fw-plugin/vcalendar-plugIn/src/encoding_util.c create mode 100755 fw-plugin/vcard-plugIn/.cproject create mode 100755 fw-plugin/vcard-plugIn/.project create mode 100755 fw-plugin/vcard-plugIn/CMakeLists.src create mode 100755 fw-plugin/vcard-plugIn/CMakeLists.sub create mode 100755 fw-plugin/vcard-plugIn/CMakeLists.txt create mode 100755 fw-plugin/vcard-plugIn/include/IN_DataStore_Info_Vcard.h create mode 100755 fw-plugin/vcard-plugIn/include/PlugIn_Spec.h create mode 100755 fw-plugin/vcard-plugIn/include/encoding_util.h create mode 100755 fw-plugin/vcard-plugIn/src/PlugIn_Interface.c create mode 100755 fw-plugin/vcard-plugIn/src/encoding_util.c create mode 100755 packaging/sync-agent-framework.spec create mode 100755 pkg_build.sh create mode 100755 pkg_clean.sh create mode 100755 pkg_install.sh create mode 100755 pkg_uninstall.sh create mode 100755 sync-agent-framework.pc.in diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100755 index 0000000..178bd9d --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,22 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(sync-agent-framework) + +SET(CMAKE_SKIP_BUILD_RPATH TRUE) +#SET(VERSION_MAJOR 1) +#SET(VERSION "${VERSION_MAJOR}.0.0")a + +MACRO(get_version _file _ver _ver_maj) + FILE(STRINGS ${_file} __log LIMIT_COUNT 1 REGEX "(.*)") + STRING(REGEX REPLACE ".*\\(\([0-9]+:\)*\([0-9a-zA-Z.]*\).*\\).*" "\\2" __ver ${__log}) + STRING(REGEX REPLACE "^\([0-9]+\)\\..*" "\\1" __ver_maj ${__ver}) + SET(${_ver} ${__ver}) + SET(${_ver_maj} ${__ver_maj}) +ENDMACRO(get_version) +get_version(debian/changelog VERSION VERSION_MAJOR) + +ADD_SUBDIRECTORY(framework) +ADD_SUBDIRECTORY(fw-plugin) + +CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc DESTINATION lib/pkgconfig) + diff --git a/debian/changelog b/debian/changelog new file mode 100755 index 0000000..4e09cea --- /dev/null +++ b/debian/changelog @@ -0,0 +1,7 @@ +libsync-agent-framework (0.1.9) unstable; urgency=low + + * pkg-init upload + * Git: shared/pkgs/s/sync-agent-framework-open + * Tag: libsync-agent-framework_0.1.9 + + -- Junhyuk Lee Mon, 12 Mar 2012 12:32:13 +0900 diff --git a/debian/compat b/debian/compat new file mode 100755 index 0000000..7ed6ff8 --- /dev/null +++ b/debian/compat @@ -0,0 +1 @@ +5 diff --git a/debian/control b/debian/control new file mode 100755 index 0000000..ed300da --- /dev/null +++ b/debian/control @@ -0,0 +1,29 @@ +Source: libsync-agent-framework +Section: embedded +Priority: optional +Maintainer: Joohark Park , Junhyuk Lee , Sunbong Ha +Uploaders: Joohark Park , Junhyuk Lee , Sunbong Ha +Build-Depends: debhelper (>= 5), libslp-calendar-dev, libslp-memo-dev, libcontacts-service-dev, libaccounts-svc-dev, drm-service-dev, libvconf-dev, uuid-dev, dlog-dev, libglib2.0-dev, libsqlite3-dev, libsoup2.4-dev, check, libxml2-dev, libslp-alarm-dev, libgcrypt11, libgcrypt11-dev, libwbxml2-dev, libslp-pm-dev, libslp-tapi-dev, libslp-sysman-dev, libslp-msg-service-dev +Standards-Version: 0.1.1 + +Package: libsync-agent-framework +Section: embedded +Architecture: any +Priority: optional +Depends: ${shlibs:Depends}, ${misc:Depends} +Description: Integrated Framework Library Package + +Package: libsync-agent-framework-dev +Section: embedded +Architecture: any +Priority: optional +Depends: ${shlibs:Depends}, ${misc:Depends}, libsync-agent-framework (= ${Source-Version}) +Description: Integrated Framework Library Package (dev) + +Package: libsync-agent-framework-dbg +Section: embedded +Architecture: any +Priority: optional +Depends: ${misc:Depends}, libsync-agent-framework (= ${Source-Version}) +Description: Integrated Framework Library Package (dbg) + diff --git a/debian/control.slp b/debian/control.slp new file mode 100755 index 0000000..fba21bb --- /dev/null +++ b/debian/control.slp @@ -0,0 +1,7 @@ +#Sat May 15 19:14:26 KST 2010 +Version=1.0.0 +IdealScreen=480x800,46x71 +Vendor=slp +Privileges= +AppInstallPath=/usr +UserUninstall=yes diff --git a/debian/dirs b/debian/dirs new file mode 100755 index 0000000..4418816 --- /dev/null +++ b/debian/dirs @@ -0,0 +1,2 @@ +usr/lib +usr/include diff --git a/debian/libsync-agent-framework-dev.install b/debian/libsync-agent-framework-dev.install new file mode 100755 index 0000000..5bb2016 --- /dev/null +++ b/debian/libsync-agent-framework-dev.install @@ -0,0 +1,2 @@ +/usr/lib/pkgconfig/* +/usr/include/* diff --git a/debian/libsync-agent-framework-dev.postinst b/debian/libsync-agent-framework-dev.postinst new file mode 100755 index 0000000..08d231a --- /dev/null +++ b/debian/libsync-agent-framework-dev.postinst @@ -0,0 +1,4 @@ +#!/bin/sh + +rm -rf /usr/include/agent-framework/agent-framework + diff --git a/debian/libsync-agent-framework.install b/debian/libsync-agent-framework.install new file mode 100755 index 0000000..c5a962b --- /dev/null +++ b/debian/libsync-agent-framework.install @@ -0,0 +1 @@ +/usr/lib/*.* diff --git a/debian/rules b/debian/rules new file mode 100755 index 0000000..63fe4ed --- /dev/null +++ b/debian/rules @@ -0,0 +1,104 @@ +#!/usr/bin/make -f + +## DO NOT MODIFY THIS AREA : BEGIN + +# Uncomment this to turn on verbose mode. +#export DH_VERBOSE=1 + +# $(PKGDIR) is a package build directory to create a final .deb package . +include debian/control.slp + +PKGDIR = debian/PKG +ifneq (,$(filter ide,$(DEB_BUILD_OPTIONS))) +DESTDIR = . +else +DESTDIR = .. +endif +CONTROLFILE = debian/control.slp +CONTROLFILE_SRC = debian/control + +BUILD_TYPE=Debug +# BUILD_TYPE=Release + +#UNIT_TEST_ENABLE=TRUE +UNIT_TEST_ENABLE=FALSE + +CFLAGS = -Wall -g + +ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS))) + CFLAGS += -O0 +else + CFLAGS += -O2 +endif + +build: pre-build configure + # Add here commands to compile the package. + $(MAKE) + + +configure: + cmake . -DCMAKE_INSTALL_PREFIX=${AppInstallPath} -DCMAKE_PROJECT=${Source} -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DUNIT_TEST_ENABLE=${UNIT_TEST_ENABLE} + rm -rf CMakeFiles/CompilerIdC* +# sed 's/^Package:.*$$/Package: $(Package)/' $(CONTROLFILE_SRC) > $(CONTROLFILE_SRC).tmp ; mv -f $(CONTROLFILE_SRC).tmp $(CONTROLFILE_SRC) + +clean: + # Add here commands to clean up before the build process. + # debian clean + -$(MAKE) clean + + -find . -name "CMakeFiles" -exec rm -rf {} \; + -find . -name "CMakeCache.txt" -exec rm -rf {} \; + -find . -name "Makefile" -exec rm -rf {} \; + -find . -name "cmake_install.cmake" -exec rm -rf {} \; + -find . -name "install_manifest.txt" -exec rm -rf {} \; + -find . -name "*.pc" -exec rm -rf {} \; + -find . -name "*.so" -exec rm -rf {} \; + + -rm -rf $(PKGDIR) + + dh_clean + +install: build pre-install + rm -rf $(PKGDIR) + mkdir $(PKGDIR) + + # Add here commands to install the package into $(PKGDIR). + $(MAKE) DESTDIR=$(CURDIR)/debian/tmp install + + #execute unit test + #debian/unit_test.sh ./debian/tmp/usr/bin/fw-test + +# Build architecture-dependent files here. +binary: install pre-binary + dh_testdir + dh_testroot + dh_installchangelogs + dh_installdocs + dh_installexamples + dh_install --sourcedir=debian/tmp + dh_link + dh_strip --dbg-package=libsync-agent-framework-dbg + dh_compress + dh_fixperms + dh_makeshlibs + dh_installdeb + dh_shlibdeps + dh_gencontrol + dh_md5sums + dh_builddeb + + + +.PHONY: build clean install binary +## DO NOT MODIFY THIS AREA : END + +## DO NOT MODIFY OR DELETE TARGET. +pre-build: + # Add here commands to execute before the build process. + +pre-install: + # Add here commands to execute before installing the binaries into $(PKGDIR). + +pre-binary: + # Add here commands to execute before creating a package. + diff --git a/debian/unit_test.sh b/debian/unit_test.sh new file mode 100755 index 0000000..c2bc14f --- /dev/null +++ b/debian/unit_test.sh @@ -0,0 +1,32 @@ +#!/bin/sh + +FW_TEST_BIN="$1" +echo "$FW_TEST_BIN" + +echo "" +echo "*********************************************************************************" +echo " executing framework unit test binary..." +echo "*********************************************************************************" +echo "" + +if [ ! -e "$FW_TEST_BIN" ] +then + echo " fw-test binary missing. (check debian package is in unit test mode)" +else + echo "" + echo "" + echo "*********************************************************************************" + echo " framework unit test START..." + echo "*********************************************************************************" + echo "" + + $FW_TEST_BIN + + echo "" + echo "" + echo "*********************************************************************************" + echo " framework unit test FINISH..." + echo "*********************************************************************************" + echo "" +fi + diff --git a/framework/.cproject b/framework/.cproject new file mode 100644 index 0000000..1283e87 --- /dev/null +++ b/framework/.cproject @@ -0,0 +1,250 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/framework/.project b/framework/.project new file mode 100644 index 0000000..5368133 --- /dev/null +++ b/framework/.project @@ -0,0 +1,78 @@ + + + agnt-fw-001-open + + + + + + com.samsung.slp2.SboxBuilder + + + com.samsung.slp2.SboxBuilder.needConfigure + false + + + org.eclipse.cdt.core.errorOutputParser + org.eclipse.cdt.core.MakeErrorParser;com.samsung.limo.SboxGCCErrorParser;org.eclipse.cdt.core.GLDErrorParser;org.eclipse.cdt.core.GASErrorParser; + + + org.eclipse.cdt.make.core.append_environment + true + + + org.eclipse.cdt.make.core.build.arguments + + + + org.eclipse.cdt.make.core.build.command + make + + + org.eclipse.cdt.make.core.build.target.auto + all + + + org.eclipse.cdt.make.core.build.target.clean + clean + + + org.eclipse.cdt.make.core.build.target.inc + all + + + org.eclipse.cdt.make.core.enableAutoBuild + true + + + org.eclipse.cdt.make.core.enableCleanBuild + true + + + org.eclipse.cdt.make.core.enableFullBuild + true + + + org.eclipse.cdt.make.core.enabledIncrementalBuild + true + + + org.eclipse.cdt.make.core.environment + + + + org.eclipse.cdt.make.core.stopOnError + true + + + org.eclipse.cdt.make.core.useDefaultBuildCmd + true + + + + + + org.eclipse.cdt.core.cnature + com.samsung.slp2.cnature + + diff --git a/framework/CMakeLists.src b/framework/CMakeLists.src new file mode 100755 index 0000000..f28f887 --- /dev/null +++ b/framework/CMakeLists.src @@ -0,0 +1,23 @@ +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src SRCS) +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src/Initialization SRCS) +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src/Account SRCS) +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src/DataAdapter SRCS) +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src/Device SRCS) +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src/PlugIn SRCS) +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src/Event SRCS) +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src/Utility SRCS) +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src/NetworkAccess SRCS) +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src/EngineController SRCS) +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src/scheduler SRCS) +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src/PlatformMonitor SRCS) +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src/securityAssistant SRCS) +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src/NetworkAssistant SRCS) +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src/NetworkAssistant/protocol_binder SRCS) +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src/FSAPI SRCS) + + +if (UNIT_TEST_ENABLE) + AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/test/src TEST_SRCS) + AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/test/src/suites TEST_SRCS) +endif (UNIT_TEST_ENABLE) + diff --git a/framework/CMakeLists.sub b/framework/CMakeLists.sub new file mode 100755 index 0000000..9768649 --- /dev/null +++ b/framework/CMakeLists.sub @@ -0,0 +1,67 @@ +################################################################################# +# THIS FILE IS CREATED AUTOMATICALLY. DO NOT DELETE OR MODIFY THIS FILE. +################################################################################# + +INCLUDE(CMakeLists.src) + +## PROJECT NAME +PROJECT(sync-agent-framework C) + +## PACKAGE CONFIG +SET(SLP_PKGCONFIG_LIST "glib-2.0 sqlite3 libsoup-2.4 vconf uuid drm-service libxml-2.0 libwbxml2 calendar pmapi") + +if (UNIT_TEST_ENABLE) + SET(SLP_PKGCONFIG_LIST "${SLP_PKGCONFIG_LIST} check") +endif (UNIT_TEST_ENABLE) + +if (PLATFORM MATCHES "SLP") + SET(SLP_PKGCONFIG_LIST "${SLP_PKGCONFIG_LIST} dlog") +endif (PLATFORM MATCHES "SLP") + +## INCLUDES +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include/Initialization) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include/Account) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include/PlugIn) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include/Event) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include/DataAdapter) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include/Device) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include/Utility) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include/NetworkAccess) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include/scheduler) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include/PlatformMonitor) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include/securityAssistant) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include/NetworkAssistant) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include/NetworkAssistant/protocol_binder) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include/FSAPI) + + +if (UNIT_TEST_ENABLE) + INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/test/include) +endif (UNIT_TEST_ENABLE) + + +## DEFINITIONS +ADD_DEFINITIONS("-DAPP_DIR=\"${CMAKE_INSTALL_PREFIX}\"") +if (PLATFORM MATCHES "SLP") + ADD_DEFINITIONS("-DSLP_PLATFORM") +endif (PLATFORM MATCHES "SLP") + +## LIBRARY PATH +SET(SLP_LD_PATH_FLAGS "") + +## LIBRARY +SET(SLP_LD_FLAGS "") + +## DEBUG +SET(SLP_DEBUG_FLAGS "-g") + +## OPTIMIZATION +SET(SLP_OPT_FLAGS "-O0") + +## COMPILER FLAGS +SET(SLP_COMPILER_FLAGS "-ldl -lpthread -lgcrypt -lm") + +## LINKER FLAGS +SET(SLP_LINKER_FLAGS "-ldl -lpthread -lgcrypt -lgpg-error -lm") + diff --git a/framework/CMakeLists.txt b/framework/CMakeLists.txt new file mode 100755 index 0000000..210f1a4 --- /dev/null +++ b/framework/CMakeLists.txt @@ -0,0 +1,119 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) + +SET(PLATFORM "SLP") +SET(FW_TEST "fw-test") + +# INCLUDE SUB CMAKELIST FILE +INCLUDE(CMakeLists.sub) + +SET(RESOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/res") + +INCLUDE(FindPkgConfig) +pkg_check_modules(pkgs_framework REQUIRED ${SLP_PKGCONFIG_LIST}) + +FOREACH(flag ${pkgs_framework_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(CMAKE_C_FLAGS "${SLP_DEBUG_FLAGS} ${SLP_OPT_FLAGS} ${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} ${SLP_COMPILER_FLAGS}") +SET(CMAKE_CXX_FLAGS "${SLP_DEBUG_FLAGS} ${SLP_OPT_FLAGS} ${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} ${SLP_COMPILER_FLAGS}") + +ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS}) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_framework_LDFLAGS} ${SLP_LD_PATH_FLAGS} ${SLP_LD_FLAGS} ${SLP_LINKER_FLAGS}) +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION lib) + +if (UNIT_TEST_ENABLE) + ADD_EXECUTABLE(${FW_TEST} ${TEST_SRCS} ${SRCS}) + TARGET_LINK_LIBRARIES(${FW_TEST} ${pkgs_framework_LDFLAGS} ${SLP_LD_PATH_FLAGS} ${SLP_LD_FLAGS} ${SLP_LINKER_FLAGS}) + INSTALL(TARGETS ${FW_TEST} DESTINATION bin) +endif (UNIT_TEST_ENABLE) + +#INSTALL(DIRECTORY ${RESOURCE_DIR}/data DESTINATION share) + +#added by KTS for install to the system +#CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY) +#INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc DESTINATION lib/pkgconfig) + +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/SyncAgent_Info.h DESTINATION include/agent-framework/) + +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/Initialization/initialize_error.h DESTINATION include/agent-framework/Initialization/) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/Initialization/initialize.h DESTINATION include/agent-framework/Initialization/) + +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/DataAdapter/EXT_DACI_Errors.h DESTINATION include/agent-framework/DACI/) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/DataAdapter/DACI_Common.h DESTINATION include/agent-framework/DACI/) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/DataAdapter/DACI_Agent_Handler_Manager.h DESTINATION include/agent-framework/DACI/) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/DataAdapter/EXT_DACI_Converter.h DESTINATION include/agent-framework/DACI/) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/DataAdapter/DACI_Service.h DESTINATION include/agent-framework/DACI/) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/DataAdapter/DACI_Luid.h DESTINATION include/agent-framework/DACI/) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/DataAdapter/DACI_ChangeLog.h DESTINATION include/agent-framework/DACI/) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/DataAdapter/DACI_Agent_Mgr.h DESTINATION include/agent-framework/DACI/) + +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/NetworkAccess/NACI_Common.h DESTINATION include/agent-framework/NetworkAccess/) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/NetworkAccess/NACI_Errors.h DESTINATION include/agent-framework/NetworkAccess/) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/NetworkAccess/NACI.h DESTINATION include/agent-framework/NetworkAccess/) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/NetworkAccess/NA_External.h DESTINATION include/agent-framework/NetworkAccess/) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/NetworkAccess/EXT_NA_NetworkStatus.h DESTINATION include/agent-framework/NetworkAccess/) + +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/Event/Event_Error.h DESTINATION include/agent-framework/Event/) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/Event/Event_UI_API.h DESTINATION include/agent-framework/Event/) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/Event/Event_Data_Accessor.h DESTINATION include/agent-framework/Event/) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/Event/Event_Handler.h DESTINATION include/agent-framework/Event/) + +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/Account/Account_Error.h DESTINATION include/agent-framework/Account/) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/Account/Account_Mgr.h DESTINATION include/agent-framework/Account/) + +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/EngineController/fundamental_type.h DESTINATION include/agent-framework/EngineController/) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/EngineController/engine_controller_define.h DESTINATION include/agent-framework/EngineController/) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/EngineController/engine_controller.h DESTINATION include/agent-framework/EngineController/) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/EngineController/task_spec.h DESTINATION include/agent-framework/EngineController/) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/EngineController/queuing_rule_spec.h DESTINATION include/agent-framework/EngineController/) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/EngineController/param_spec.h DESTINATION include/agent-framework/EngineController/) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/EngineController/param_value.h DESTINATION include/agent-framework/EngineController/) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/EngineController/param.h DESTINATION include/agent-framework/EngineController/) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/EngineController/task_process.h DESTINATION include/agent-framework/EngineController/) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/EngineController/task_error.h DESTINATION include/agent-framework/EngineController/) + +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/Utility/fw_alloc.h DESTINATION include/agent-framework/Utility/) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/Utility/fw_log.h DESTINATION include/agent-framework/Utility/) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/Utility/fw_assert.h DESTINATION include/agent-framework/Utility/) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/Utility/fw_ref.h DESTINATION include/agent-framework/Utility/) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/Utility/fw_compress.h DESTINATION include/agent-framework/Utility/) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/Utility/fw_cache.h DESTINATION include/agent-framework/Utility/) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/Utility/fw_time.h DESTINATION include/agent-framework/Utility/) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/Utility/fw_sequential_id_provider.h DESTINATION include/agent-framework/Utility/) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/Utility/fw_async_queue.h DESTINATION include/agent-framework/Utility/) + +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/PlatformMonitor/EXT_PMCI_Common.h DESTINATION include/agent-framework/PlatformMonitor/) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/PlatformMonitor/EXT_PMCI_Errors.h DESTINATION include/agent-framework/PlatformMonitor/) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/PlatformMonitor/EXT_PMCI_Noti.h DESTINATION include/agent-framework/PlatformMonitor/) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/PlatformMonitor/EXT_PMCI.h DESTINATION include/agent-framework/PlatformMonitor/) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/PlatformMonitor/EXT_PMCI_Struct.h DESTINATION include/agent-framework/PlatformMonitor/) + +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/securityAssistant/EXT_SA_Encryption_Decryption.h DESTINATION include/agent-framework/securityAssistant/) + +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/NetworkAssistant/protocol_binder/protocol_binder_common.h DESTINATION include/agent-framework/NetworkAssistant/protocol_binder/) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/NetworkAssistant/protocol_binder/protocol_binder_definition.h DESTINATION include/agent-framework/NetworkAssistant/protocol_binder/) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/NetworkAssistant/protocol_binder/protocol_binder_error.h DESTINATION include/agent-framework/NetworkAssistant/protocol_binder/) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/NetworkAssistant/protocol_binder/protocol_binder_util.h DESTINATION include/agent-framework/NetworkAssistant/protocol_binder/) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/NetworkAssistant/protocol_binder/protocol_binder.h DESTINATION include/agent-framework/NetworkAssistant/protocol_binder/) + +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/Device/EXT_DCI_Common.h DESTINATION include/agent-framework/Device/) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/Device/EXT_DCI_Errors.h DESTINATION include/agent-framework/Device/) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/Device/EXT_DCI_DevInfo.h DESTINATION include/agent-framework/Device/) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/Device/EXT_DCI_DevExecutor.h DESTINATION include/agent-framework/Device/) + +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/FSAPI/FSAPI_operation.h DESTINATION include/agent-framework/FSAPI/) + +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/PlugIn/PlugIn_Interface/Account_Interface.h DESTINATION include/agent-framework/PlugIn/) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/PlugIn/PlugIn_Interface/DataConnector_Interface.h DESTINATION include/agent-framework/PlugIn/) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/PlugIn/PlugIn_Interface/DataConnector_Resource.h DESTINATION include/agent-framework/PlugIn/) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/PlugIn/PlugIn_Interface/DataConverter_Interface.h DESTINATION include/agent-framework/PlugIn/) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/PlugIn/DataConverter_Resource.h DESTINATION include/agent-framework/PlugIn/) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/PlugIn/PlugIn_Interface/DeviceInfo_Interface.h DESTINATION include/agent-framework/PlugIn/) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/PlugIn/PlugIn_Interface/NetworkAccess_Interface.h DESTINATION include/agent-framework/PlugIn/) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/PlugIn/PlugIn_Interface/PlatformMonitor_Interface.h DESTINATION include/agent-framework/PlugIn/) + + +# INCLUDE LAYOUT DIRECTORY +# ADD_SUBDIRECTORY(layout) +#ADD_SUBDIRECTORY(res/locale) diff --git a/framework/include/Account/Account_Error.h b/framework/include/Account/Account_Error.h new file mode 100755 index 0000000..3bf87e6 --- /dev/null +++ b/framework/include/Account/Account_Error.h @@ -0,0 +1,61 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#ifndef ACCOUNT_ERROR_H_ +#define ACCOUNT_ERROR_H_ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/** + * @file Account_Error.h + * @brief Definition of framework error codes for Account module + */ + +/** + * @brief Enumerations of error codes for Account module + */ + typedef enum { + ACCOUNT_SUCCESS, /**< when Account Operation is succeed */ + ACCOUNT_FAIL, /**< when Account Operation is failed */ + ACCOUNT_EMPTY, /**< when Account is not exist */ + ACCOUNT_CHANGED /**< when Account storage changed */ + } ACCOUNT_ERROR; + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /* ACCOUNT_ERROR_H_ */ diff --git a/framework/include/Account/Account_Mgr.h b/framework/include/Account/Account_Mgr.h new file mode 100755 index 0000000..3d88a02 --- /dev/null +++ b/framework/include/Account/Account_Mgr.h @@ -0,0 +1,106 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#ifndef ACCOUNT_MGR_H_ +#define ACCOUNT_MGR_H_ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#include "Account_Error.h" + +/** + * @file Account_Mgr.h + * @brief Support to use framework Account module + */ + +/* + * @brief Register a new account to SyncAgent + * @param[in] email email + * @param[in] password password + * @param[in] serverIP serverIP + * @param[in] domain domain + * @param[in] isEnableSSL isEnableSSL + * @param[in] create_mode create_mode + * @param[in] access_name access name + * @return Operating result + * @retval SyncAgent account ID success + * @retval -1 failed + */ + int addAccount(char *email, char *password, char *serverIP, char *domain, int isEnableSSL, int create_mode, char *access_name); + +/* + * @brief Delete the account from SyncAgent + * @param[in] accountID id of SyncAgent + * @return Operating result + * @retval 1 success + * @retval 0 failed + */ + int deleteAccount(int accountID); + +/** + * @brief Mapping service's all account to F/W account + * @remarks Services which are provided as a DataConnector plug-In. + * @return ACCOUNT_SUCCESS on success, otherwise a error value. + * @retval ACCOUNT_SUCCESS Successful + * @retval ACCOUNT_FAIL Parsing the initialization config file failed + * @retval ACCOUNT_CHANGED service account repository changed + * @post Mapped service's all existed account id with F/W account id + */ + ACCOUNT_ERROR construct_AccountTbl_From_Service(); + +/** + * @brief Get fw account id list per service type. + * @param[in] content_type content type (Contact, Calendar, Memo ... ) + * @param [out] count count of fw account id which have content type service account id. + * @return list of fw account id on success, otherwise null pointer + */ + int *get_Account_ID_List(int content_type, int *count); + +/** + * @brief Get Account Information + * @remarks Account Information type is defined in account plugIn. + * @param[in] fw_account_id account id + * @param[in] content_type service type + * @return Account Information* defined in account plugIn on success, otherwise null pointer + * @pre account plugIn loaded + */ + void *get_Account_Info(int fw_account_id, int content_type); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /* ACCOUNT_MGR_H_ */ diff --git a/framework/include/Account/Account_Util.h b/framework/include/Account/Account_Util.h new file mode 100755 index 0000000..867bc55 --- /dev/null +++ b/framework/include/Account/Account_Util.h @@ -0,0 +1,85 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#ifndef SYNCACCOUNTMGR_H_ +#define SYNCACCOUNTMGR_H_ + +#include "Account_Error.h" + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/* + * @brief Checking whether the account is exist + * @param[in] accountID id of Framework account database + * @return Checking result + * @retval 1 exist + * @retval 0 not exist + */ + int isExistAccountID(int accountID); + + void addAccount_Platform(int fw_account_id, char *email, char *password, int create_mode); + + void delAccount_Platform(int fw_account_id); + + int *getAccountIDList_Service(int service_type, int *cnt); + + int getAccountID_Service(int service_type, int account_id); + + int getAccountID_FW(int service_type, int service_account_id, int index); + +/* + * @brief Get a list of account ID + * @param[out] count The current number of registered accounts + * @return Operating result + * @retval a list of account ID Registered accounts exist + * @retval NULL Not registered account + */ + int *getAccountList(int *count); + +/* + * @brief Get a email address of account + * @param[in] accountID id of SyncAgent + * @return Operating result + * @retval email address success + * @retval 0 not exist + */ + char *getEmailAddress(int accountID); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /* SYNCACCOUNTMGR_H_ */ diff --git a/framework/include/DataAdapter/DACI_Agent.h b/framework/include/DataAdapter/DACI_Agent.h new file mode 100755 index 0000000..122bc6d --- /dev/null +++ b/framework/include/DataAdapter/DACI_Agent.h @@ -0,0 +1,839 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#ifndef DACI_AGENT_H_ +#define DACI_AGENT_H_ + +#include "DACI_Common.h" + +/* + * ============================================================================================================================= + * Database Open & Close & Delete Account Data + * ============================================================================================================================= + */ + +/* +* @brief start Agent database transaction + * @param[in] daci_handler sqlite3 handler pointer about thread +* @return operation result +* @retval DACI_SUCCESS success +* @retval DACI_ERR_TRANSACTION_FAILED fail +*/ +DACI_RETURN begin_transaction(DACI_HANDLER *daci_handler); + +/* +* @brief finish Agent database transaction + * @param[in] daci_handler sqlite3 handler pointer about thread +* @param[in] transaction commit or rollback transaction +* @return operation result +* @retval DACI_SUCCESS success +* @retval DACI_ERR_TRANSACTION_FAILED fail +*/ +DACI_RETURN end_transaction(DACI_HANDLER *daci_handler, DACI_TRANSACTION transaction); + +/* + * @brief set agent db file path + * @param[in] file_path agent db file path + */ +void set_agentdb_file_path(char *file_path); + +/* + * @brief open Agent database + * @param[in] daci_handler sqlite3 handler pointer about thread + * @return operation result + * @retval DACI_SUCCESS success + * @retval DACI_ERR_OPEN_FAILED fail + */ +DACI_RETURN open_agent(DACI_HANDLER **daci_handler); + +/* + * @brief close Agent database + * @param[in] daci_handler sqlite3 handler pointer about thread + * @return operation result + * @retval DACI_SUCCESS success + * @retval DACI_ERR_CLOSE_FAILED fail + */ +DACI_RETURN close_Agent(DACI_HANDLER *daci_handler); + +/* + * @brief create Agent database + * @param[in] daci_handler sqlite3 handler pointer about thread + * @return operation result + * @retval DACI_SUCCESS success + * @retval DACI_ERR_CLOSE_FAILED fail + */ +DACI_RETURN create_AgentDefaultTable(DACI_HANDLER *daci_handler); + +/* + * ============================================================================================================================= + * account_tb + * ============================================================================================================================= + */ +/* + * @brief insert account into account_tbl + * @param[in] daci_handler sqlite3 handler pointer about thread + * @param[in] account account info + * @return operation result + * @retval accountId success + * @retval -1 fail + */ +int add_account(DACI_HANDLER *daci_handler, daci_account *account); + +/* + * @brief delete account data from Agent database + * @param[in] daci_handler sqlite3 handler pointer about thread + * @param[in] accountId accountId + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ +DACI_RETURN delete_account(DACI_HANDLER *daci_handler, int accountId); + +/* + * @brief set emailAddress to account_tbl + * @param[in] daci_handler sqlite3 handler pointer about thread + * @param[in] accountId accountId + * @param[in] emailAddress new emailAddress + * @param[in] accessName access module name + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ +DACI_RETURN set_accountEmailAddress(DACI_HANDLER *daci_handler, int accountId, char *emailAddress, char *accessName); + +/* + * @brief set password to account_tbl + * @param[in] daci_handler sqlite3 handler pointer about thread + * @param[in] accountId accountId + * @param[in] password new password + * @param[in] accessName access module name + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ +DACI_RETURN set_accountPassword(DACI_HANDLER *daci_handler, int accountId, char *password, char *accessName); + +/* + * @brief get all accountId from account_tbl + * @param[in] daci_handler sqlite3 handler pointer about thread + * @param[out] count count of accountId + * @return operation result + * @retval array of ccountId success + * @retval NULL fail + */ +int *get_accountAccountIdList(DACI_HANDLER *daci_handler, int *count); + +/* + * @brief get emailAddress from account_tbl + * @param[in] daci_handler sqlite3 handler pointer about thread + * @param[in] accountId accountId + * @return operation result + * @retval emailAddress success + * @retval NULL fail + */ +char *get_accountEmailAddress(DACI_HANDLER *daci_handler, int accountId); + +/* + * @brief get password from account_tbl + * @param[in] daci_handler sqlite3 handler pointer about thread + * @param[in] accountId accountId + * @return operation result + * @retval password success + * @retval NULL fail + */ +char *get_accountPassword(DACI_HANDLER *daci_handler, int accountId); + +/* + * @brief checking whether the accountId exist in account_tbl + * @param[in] daci_handler sqlite3 handler pointer about thread + * @param[in] accountId accountId + * @return checking result + * @retval true exist + * @retval false not exist + */ +int isExist_account(DACI_HANDLER *daci_handler, int accountId); + +char *get_accessName(DACI_HANDLER *daci_handler, int accountId); + +int *get_accountIdListByAccessName(DACI_HANDLER *daci_handler, char *access_name, int *accountId_count); + +/* + * @brief get account count + * @param[in] daci_handler sqlite3 handler pointer about thread + * @return checking result + * @retval true exist + * @retval false not exist + */ +int get_accountCount(DACI_HANDLER *daci_handler); + +/* + * ============================================================================================================================= + * folder_tbl + * ============================================================================================================================= + */ +/* + * @brief insert folder into folder_tbl + * @param[in] daci_handler sqlite3 handler pointer about thread + * @param[in] folder array of folder info + * @param[in] count count of folder info + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ +DACI_RETURN add_folder(DACI_HANDLER *daci_handler, daci_folder *folder, int count); + +DACI_RETURN delete_folderByFolderId(DACI_HANDLER *daci_handler, char *folderId); + +/* + * @brief get folderId from folder_tbl + * @param[in] daci_handler sqlite3 handler pointer about thread + * @param[in] accountId accountId + * @param[in] accountId itemTypeId + * @param[in] serviceId serviceId + * @param[in] folderTypeId folderTypeId + * @return operation result + * @retval folderId success + * @retval NULL fail + */ +char *get_folderFolderIdByServiceId(DACI_HANDLER *daci_handler, int accountId, int itemTypeId, char *serviceId, int folderTypeId); + +/* + * @brief get folderId from folder_tbl by folderTypeId + * @param[in] daci_handler sqlite3 handler pointer about thread + * @param[in] accountId accountId + * @param[in] folderTypeId folderTypeId + * @return operation result + * @retval folderId success + * @retval NULL fail + */ +daci_id_list *get_folderFolderIdByFolderTypeId(DACI_HANDLER *daci_handler, int accountId, int itemTypeId, int folderTypeId); + +/* + * @brief get serviceId from folder_tbl + * @param[in] daci_handler sqlite3 handler pointer about thread + * @param[in] folderId folderId + * @return operation result + * @retval serviceId success + * @retval NULL fail + */ +char *get_folderServiceId(DACI_HANDLER *daci_handler, char *folderId); + +daci_id_list *get_folderFolderIdListByItemTypeId(DACI_HANDLER *daci_handler, int accountId, int itemTypeId); + +/* + * @brief get item from folder_tbl + * belonging to different account of folder get folder with the same service_id + * @param[in] daci_handler sqlite3 handler pointer about thread + * @param[in] accountId accountId + * @param[in] folderId folderId + * @param[in] count count of item info + * @return operation result + * @retval array of folder info success + * @retval NULL fail + */ +daci_folder *get_folderMappingServiceId(DACI_HANDLER *daci_handler, int accountId, char *folderId, int *count); + +/* + * @brief checking whether the folderId exist in folder_tbl + * @param[in] daci_handler sqlite3 handler pointer about thread + * @param[in] accountId accountId + * @param[in] folderId folderId + * @return checking result + * @retval true exist + * @retval false not exist + */ +int isExist_folder(DACI_HANDLER *daci_handler, int accountId, char *folderId); + +/* + * ============================================================================================================================= + * item_tbl + * ============================================================================================================================= + */ +/* + * @brief insert item into item_tbl + * @param[in] daci_handler sqlite3 handler pointer about thread + * @param[in] item array of item info + * @param[in] count count of item info + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ +DACI_RETURN add_item(DACI_HANDLER *daci_handler, daci_item *item, int count); + +/* + * @brief delete item from item_tbl by itemId + * @param[in] daci_handler sqlite3 handler pointer about thread + * @param[in] itemId itemId + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ +DACI_RETURN delete_itemByItemId(DACI_HANDLER *daci_handler, char *itemId); + +/* + * @brief delete item from item_tbl by accountId and itemTypeId + * @param[in] daci_handler sqlite3 handler pointer about thread + * @param[in] accountId accountId + * @param[in] itemTypeId itemTypeId + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ +DACI_RETURN delete_itemByItemTypeId(DACI_HANDLER *daci_handler, int accountId, int itemTypeId); + +/* + * @brief get itemId from item_tbl + * @param[in] daci_handler sqlite3 handler pointer about thread + * @param[in] accountId accountId + * @param[in] serviceId serviceId + * @param[in] itemTypeId itemTypeId + * @return operation result + * @retval itemId success + * @retval NULL fail + */ +char *get_itemItemId(DACI_HANDLER *daci_handler, int accountId, char *serviceId, int itemTypeId); + +/* + * @brief get serviceId from item_tbl + * @param[in] accountId accountId + * @param[in] itemId itemId + * @return operation result + * @retval serviceId success + * @retval NULL fail + */ +char *get_itemServiceId(DACI_HANDLER *daci_handler, char *itemId); + +/* + * @brief get item from item_tbl + * @param[in] daci_handler sqlite3 handler pointer about thread + * @param[in] itemId itemId + * @return operation result + * @retval item info success + * @retval NULL fail + */ +daci_item *get_item(DACI_HANDLER *daci_handler, char *itemId); + +/* + * @brief get all id in folder from item_tbl + * @param[in] daci_handler sqlite3 handler pointer about thread + * @param[in] accountId accountId + * @param[in] folderId folderId + * @param[in] columnName columnName (COLUMN_NAME_ITEM_ID or COLUMN_NAME_SERVICE_ID) + * @return operation result + * @retval array of item id success + * @retval NULL fail + */ +daci_id_list *get_itemIdList(DACI_HANDLER *daci_handler, char *folderId, DACI_COLUMN_NAME columnName); + +daci_item *get_itemByAccountId(DACI_HANDLER *daci_handler, int accountId, int itemTypeId, int *count); + +/* + * @brief get item data from item_tbl and account_item_changelog_tbl + * Among the items that belong to the itemTypeId, Search for item info belong to the changelog + * @param[in] daci_handler sqlite3 handler pointer about thread + * @param[in] accountId accountId + * @param[in] itemTypeId itemTypeId + * @param[in] count count of item data + * @return operation result + * @retval array of item data success + * @retval NULL fail + */ +daci_item_info *get_itemInfoByItemTypeId(DACI_HANDLER *daci_handler, int accountId, int itemTypeId, int *count); + +/* + * @brief get item from item_tbl + * belonging to different account of item get item with the same service_id + * @param[in] daci_handler sqlite3 handler pointer about thread + * @param[in] accountId accountId + * @param[in] itemId itemId + * @param[in] count count of item info + * @return operation result + * @retval array of item info success + * @retval NULL fail + */ +daci_item *get_itemMappingServiceId(DACI_HANDLER *daci_handler, int accountId, char *itemId, int *count); + +daci_id_list *get_itemIdListByDataStoreId(DACI_HANDLER *daci_handler, int data_store_id); + +daci_id_list *get_itemIdListByDataStoreIdwithAccountId(DACI_HANDLER *daci_handler, int account_id, int data_store_id); + +daci_id_list *get_ItemIdListByOperationId(DACI_HANDLER *daci_handler, int account_id, int data_store_id, int operation_id); + +/* + * @brief checking whether the itemId exist in item_tbl + * @param[in] daci_handler sqlite3 handler pointer about thread + * @param[in] itemId itemId + * @return checking result + * @retval true exist + * @retval false not exist + */ +int isExist_item(DACI_HANDLER *daci_handler, char *itemId); + +/* + * ============================================================================================================================= + * config_tbl + * ============================================================================================================================= + */ +/* + * @brief insert config into config_tbl + * @param[in] daci_handler sqlite3 handler pointer about thread + * @param[in] config config info + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ +DACI_RETURN add_config(DACI_HANDLER *daci_handler, daci_config *config); + +/* + * @brief delete config from config_tbl by key + * @param[in] daci_handler sqlite3 handler pointer about thread + * @param[in] configId configId + * @param[in] key key + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ +DACI_RETURN delete_configByKey(DACI_HANDLER *daci_handler, int configId, char *key); + +/* + * @brief get config info from config_tbl by accountId + * get all the config in account + * @param[in] daci_handler sqlite3 handler pointer about thread + * @param[in] configId configId + * @param[in] count count of config info + * @return operation result + * @retval array of config info success + * @retval NULL fail + */ +daci_config *get_configByConfigId(DACI_HANDLER *daci_handler, int configId, int *count); + +/* + * @brief get config info from config_tbl by key + * @param[in] daci_handler sqlite3 handler pointer about thread + * @param[in] config config info (accountId, key) + * @param[out] config config info (accountId, key, value, type) + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ +DACI_RETURN get_configByKey(DACI_HANDLER *daci_handler, daci_config *config); + +/* + * @brief checking whether account of the config exist in config_tbl + * @param[in] daci_handler sqlite3 handler pointer about thread + * @param[in] configId configId + * @param[in] key key + * @return checking result + * @retval true exist + * @retval false not exist + */ +int isExist_config(DACI_HANDLER *daci_handler, int configId, char *key); + +/* + * @brief insert or update config into config_tbl + * checking whether the config exist in config_tbl + * If it does not exist, insert config into config_tbl + * If it existed, update config into config_tbl + * @param[in] daci_handler sqlite3 handler pointer about thread + * @param[in] config config info + * @param[in] count count of config info + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ +DACI_RETURN update_config(DACI_HANDLER *daci_handler, daci_config *config, int count); + +DACI_RETURN set_configValue(DACI_HANDLER *daci_handler, daci_config *config); + +/* + * ============================================================================================================================= + * account_item_changelog_tbl + * ============================================================================================================================= + */ +/* + * @brief insert itemChangelog into account_item_changelog_tbl + * @param[in] daci_handler sqlite3 handler pointer about thread + * @param[in] itemChangelog array of itemChangelog info + * @param[in] count count of itemChangelog info + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ +DACI_RETURN add_itemChangelog(DACI_HANDLER *daci_handler, int accountId, daci_item_changelog *itemChangelog, int count); + +/* + * @brief delete itemChangelog from account_item_changelog_tbl by itemId + * @param[in] daci_handler sqlite3 handler pointer about thread + * @param[in] accountId accountId + * @param[in] itemId itemId + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ +DACI_RETURN delete_itemChangelogByItemId(DACI_HANDLER *daci_handler, int accountId, char *itemId); + +/* + * @brief delete itemChangelog from account_item_changelog_tbl by itemId list + * @param[in] daci_handler sqlite3 handler pointer about thread + * @param[in] accountId accountId + * @param[in] itemIdList array of itemId + * @param[in] count count of itemId + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ +DACI_RETURN delete_itemChangelogByItemIdList(DACI_HANDLER *daci_handler, int accountId, char **itemIdList, int count); + +/* + * @brief delete itemChangelog from account_item_changelog_tbl by itemTypeId + * @param[in] daci_handler sqlite3 handler pointer about thread + * @param[in] accountId accountId + * @param[in] itemTypeId itemTypeId + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ +DACI_RETURN delete_itemChangelogByItemTypeId(DACI_HANDLER *daci_handler, int accountId, int itemTypeId); + +/* + * @brief set operationId and syncStatus to account_item_changelog_tbl + * @param[in] daci_handler sqlite3 handler pointer about thread + * @param[in] accountId accountId + * @param[in] itemChangelog itemChangelog info (operationId, syncStatus, accessName, itemId) + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ +DACI_RETURN set_itemChangelogOperationId(DACI_HANDLER *daci_handler, int accountId, daci_item_changelog *itemChangelog); + +/* + * @brief set syncStatus to account_item_changelog_tbl + * @param[in] daci_handler sqlite3 handler pointer about thread + * @param[in] accountId accountId + * @param[in] itemChangelog itemChangelog info (syncStatus, accessName, itemId) + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ +DACI_RETURN set_itemChangelogSyncStatus(DACI_HANDLER *daci_handler, int accountId, daci_item_changelog *itemChangelog); + +/* + * @brief set SYNC_WAIT to account_item_changelog_tbl + * Among the items that match to the itemTypeId and belong to the folder + * If it existed in account_item_changelog_tbl, set SYNC_WAIT to account_item_changelog_tbl + * @param[in] daci_handler sqlite3 handler pointer about thread + * @param[in] accountId accountId + * @param[in] folderIdList array of folderId + * @param[in] folderIdCount count of folderId + * @param[in] itemTypeIdList array of itemTypeId + * @param[in] itemTypeIdCount count of itemTypeId + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ +DACI_RETURN set_itemChangelogWaitStatus(DACI_HANDLER *daci_handler, int accountId, char **folderIdList, int folderIdCount, int *itemTypeIdList, int itemTypeIdCount); + +/* + * @brief get itemChangelog info from account_item_changelog_tbl by itemId + * @param[in] daci_handler sqlite3 handler pointer about thread + * @param[in] accountId accountId + * @param[in] itemChangelog itemChangelog info (itemId) + * @param[out] itemChangelog itemChangelog info (itemId, operationId, syncStatus, accessName) + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ +DACI_RETURN get_itemChangelogByItemId(DACI_HANDLER *daci_handler, int accountId, daci_item_changelog *itemChangelog); + +/* + * @brief checking whether the itemId exist in account_item_changelog_tbl + * @param[in] daci_handler sqlite3 handler pointer about thread + * @param[in] accountId accountId + * @param[in] itemId itemId + * @return checking result + * @retval true exist + * @retval false not exist + */ +int isExist_itemChangelog(DACI_HANDLER *daci_handler, int accountId, char *itemId); + +/* + * ============================================================================================================================= + * last_anchor_tbl + * ============================================================================================================================= + */ +/* + * @brief insert anchor into last_anchor_tbl + * @param[in] daci_handler sqlite3 handler pointer about thread + * @param[in] lastAnchor lastAnchor info + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ +DACI_RETURN add_lastAnchor(DACI_HANDLER *daci_handler, daci_last_anchor *lastAnchor); + +/* + * @brief delete anchor from last_anchor_tbl by accountId + * delete all the anchor in account + * @param[in] daci_handler sqlite3 handler pointer about thread + * @param[in] accountId accountId + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ +DACI_RETURN delete_lastAnchorByAccountId(DACI_HANDLER *daci_handler, int accountId); + +/* + * @brief delete anchor from last_anchor_tbl by itemTypeId + * delete all the anchor in account and itemTypeId + * @param[in] daci_handler sqlite3 handler pointer about thread + * @param[in] accountId accountId + * @param[in] itemTypeId itemTypeId + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ +DACI_RETURN delete_lastAnchorByItemTypeId(DACI_HANDLER *daci_handler, int accountId, int itemTypeId); + +/* + * @brief set last_anchor_server and last_anchor_client to last_anchor_tbl + * @param[in] daci_handler sqlite3 handler pointer about thread + * @param[in] lastAnchor lastAnchor info + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ +DACI_RETURN set_lastAnchor(DACI_HANDLER *daci_handler, daci_last_anchor *lastAnchor); + +/* + * @brief get all lastAnchor in account from last_anchor_tbl + * @param[in] daci_handler sqlite3 handler pointer about thread + * @param[in] accountId accountId + * @param[out] count count of lastAnchor info + * @return operation result + * @retval array of lastAnchor info success + * @retval NULL fail + */ +daci_last_anchor *get_lastAnchorByAccountId(DACI_HANDLER *daci_handler, int accountId, int *count); + +/* + * @brief get last_anchor_server and last_anchor_client from last_anchor_tbl by itemTypeId + * @param[in] daci_handler sqlite3 handler pointer about thread + * @param[in] accountId accountId + * @param[in] itemTypeId itemTypeId + * @param[out] count count of lastAnchor info + * @return operation result + * @retval lastAnchor info success + * @retval NULL fail + */ +daci_last_anchor *get_lastAnchorByItemTypeId(DACI_HANDLER *daci_handler, int accountId, int itemTypeId, int *count); + +/* + * @brief checking whether itemType of the anchor exist in last_anchor_tbl + * @param[in] daci_handler sqlite3 handler pointer about thread + * @param[in] accountId accountId + * @param[in] itemTypeId itemTypeId + * @return checking result + * @retval true exist + * @retval false not exist + */ +int isExist_lastAnchor(DACI_HANDLER *daci_handler, int accountId, int itemTypeId); + +/* + * ============================================================================================================================= + * mapping_tbl + * ============================================================================================================================= + */ +/* + * @brief insert mapping into mapping_tbl + * @param[in] daci_handler sqlite3 handler pointer about thread + * @param[in] mapping mapping info + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ +DACI_RETURN add_mapping(DACI_HANDLER *daci_handler, daci_mapping *mapping); + +/* + * @brief delete mapping from mapping_tbl by accountId + * delete all the mapping in account + * @param[in] daci_handler sqlite3 handler pointer about thread + * @param[in] accountId accountId + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ +DACI_RETURN delete_mappingByAccountId(DACI_HANDLER *daci_handler, int accountId); + +/* + * @brief delete mapping from mapping_tbl by luid + * @param[in] daci_handler sqlite3 handler pointer about thread + * @param[in] accountId accountId +* @param[in] luid luid + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ +DACI_RETURN delete_mappingByLuid(DACI_HANDLER *daci_handler, int accountId, char *luid); + +/* + * @brief get all mapping info from mapping_tbl by accountId + * get all the mapping info in account + * @param[in] daci_handler sqlite3 handler pointer about thread + * @param[in] accountId accountId + * @param[out] count count of mapping info + * @return operation result + * @retval array of mapping info success + * @retval NULL fail + */ +daci_mapping *get_mappingByAccountId(DACI_HANDLER *daci_handler, int accountId, int *count); + +/* + * @brief get luid from mapping_tbl by guid + * @param[in] daci_handler sqlite3 handler pointer about thread + * @param[in] accountId accountId + * @param[in] luid luid + * @return operation result + * @retval guid guid + * @retval NULL fail + */ +char *get_mappingGuid(DACI_HANDLER *daci_handler, int accountId, char *luid); + +/* + * @brief checking whether account exist in mapping_tbl + * @param[in] daci_handler sqlite3 handler pointer about thread + * @param[in] accountId accountId + * @return checking result + * @retval true exist + * @retval false not exist + */ +int isExist_mappingByAccountId(DACI_HANDLER *daci_handler, int accountId); + +/* + * @brief checking whether the account and itemTypeId of the itemTypeId exist in mapping_tbl + * @param[in] daci_handler sqlite3 handler pointer about thread + * @param[in] accountId accountId + * @param[in] luid luid + * @return checking result + * @retval true exist + * @retval false not exist + */ +int isExist_mappingByLuid(DACI_HANDLER *daci_handler, int accountId, char *luid); + +/* + * ============================================================================================================================= + * id_provider_tbl, id_page_tbl + * ============================================================================================================================= + */ +/* + * @brief insert id_provider into id_provider_tbl + * @param[in] id_provider id_provider info + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ +DACI_RETURN add_id_provider(DACI_HANDLER *daci_handler, daci_id_provider *id_provider); + +/* + * @brief get id_provider from id_provider_tbl + * @param[in] id_provider_code id_provider_code + * @param[out] id_provider id_provider info + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ +DACI_RETURN get_id_provider(DACI_HANDLER *daci_handler, unsigned int id_provider_code, daci_id_provider **id_provider); + +/* + * @brief update id_provider in id_provider_tbl + * @param[in] id_provider id_provider info + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ +DACI_RETURN update_id_provider(DACI_HANDLER *daci_handler, daci_id_provider *id_provider); + +/* + * @brief insert id_page into id_page_tbl + * @param[in] id_page id_page info + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ +DACI_RETURN add_id_page(DACI_HANDLER *daci_handler, daci_id_page *id_page, unsigned int page_byte_size); + +/* + * @brief delete id_page from id_page_tbl by page_index + * @param[in] id_provider_code id_provider_code + * @param[in] page_index page_index + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ +DACI_RETURN delete_id_page(DACI_HANDLER *daci_handler, unsigned int id_provider_code, unsigned int page_index); + +/* + * @brief insert id_page into id_page_tbl + * @param[in] id_provider_code id_provider_code + * @param[in] page_index page_index + * @param[out] page_bit page_bit + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ +DACI_RETURN get_id_page(DACI_HANDLER *daci_handler, unsigned int id_provider_code, unsigned int page_index, char **page_bit); + +/* + * @brief insert id_page into id_page_tbl + * @param[in] id_page id_page info + * @param[in] page_byte_size + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ +DACI_RETURN update_id_page(DACI_HANDLER *daci_handler, daci_id_page *id_page, unsigned int page_byte_size); + +/* + * ============================================================================================================================= + * Testing + * ============================================================================================================================= + */ +void drop_table(DACI_HANDLER *daci_handler, int *accountIdList, int accountCount); + +/* + * For ID_Provider todo i should remove this rutine!!!! + */ +char *get_daci_file_path(); + +#endif /* DACI_AGENT_H_ */ diff --git a/framework/include/DataAdapter/DACI_Agent_Handler_Manager.h b/framework/include/DataAdapter/DACI_Agent_Handler_Manager.h new file mode 100755 index 0000000..599d7cd --- /dev/null +++ b/framework/include/DataAdapter/DACI_Agent_Handler_Manager.h @@ -0,0 +1,788 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu , + * Heeyoung Hwang + */ + +#ifndef DACI_AGENT_HANDLER_MANAGER_H_ +#define DACI_AGENT_HANDLER_MANAGER_H_ + +#include "DACI_Common.h" + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/** + * @file DACI_Agent_Handler_Manager.h + * @brief Interface list to use framework Common DataBase + */ + +/** + * @brief Structure of managing database connection + */ + typedef struct { + GHashTable *daci_handlerTable; /**< agent db handler hash table */ + pthread_mutex_t *daci_handlerTable_mutex; + /**< mutex for agent db handler hash table */ + } daci_handler_mgr; + +/* + * @brief alloc the agent db handler manager + * @return operation result + * @retval DACI_SUCCESS success + * @retval DACI_ERR_DB_HANDLER_MGR fail + */ + DACI_RETURN DACI_Alloc_AgentDB_Handler_Mgr(); + +/* + * @brief free the agent db handler manager + * @return operation result + * @retval DACI_SUCCESS success + * @retval DACI_ERR_DB_HANDLER_MGR fail + */ + DACI_RETURN DACI_Free_AgentDB_Handler_Mgr(); + +/* + * @brief delete all accounts data from Email-Service, Contacts-Service database, Calendar-Service database, Agent database + * @return operation result + * @retval DACI_SUCCESS success + * @retval DACI_ERRORS fail + */ + DACI_RETURN DACI_Clear_All_Database_Account(); + +/* + * @brief delete one account data from Email-Service, Contacts-Service database, Calendar-Service database, Agent database + * @param[in] accountId account id of SyncAgent + * @return operation result + * @retval DACI_SUCCESS success + * @retval DACI_ERR_DELETE_LAST_ACCOUNT success ( delete last account ) + * @retval DACI_ERRORS fail + */ + DACI_RETURN DACI_Delete_All_Database_Account(int accountId); + +/* + * @brief open Agent database + * @return operation result + * @retval DACI_SUCCESS success + * @retval DACI_ERR_OPEN_FAILED fail + */ + DACI_RETURN DACI_Open_Agent(); + +/* + * @brief close Agent database + * @return operation result + * @retval DACI_SUCCESS success + * @retval DACI_ERR_CLOSE_FAILED fail + */ + DACI_RETURN DACI_Close_Agent(); + +/* + * @brief create Agent database + * @return operation result + * @retval DACI_SUCCESS success + * @retval DACI_ERR_CLOSE_FAILED fail + */ + DACI_RETURN DACI_Create_Agent_Default_Table(); + +/* +* @brief start Agent database transaction +* @return operation result +* @retval DACI_SUCCESS success +* @retval DACI_ERR_TRANSACTION_FAILED fail +*/ + DACI_RETURN DACI_Begin_Transaction(); + +/* +* @brief finish Agent database transaction +* @param[in] transaction commit or rollback transaction +* @return operation result +* @retval DACI_SUCCESS success +* @retval DACI_ERR_TRANSACTION_FAILED fail +*/ + DACI_RETURN DACI_End_Transaction(DACI_TRANSACTION transaction); + +/* + * @brief insert account into account_tbl + * @param[in] account account info + * @return operation result + * @retval accountId success + * @retval -1 fail + */ + int DACI_Add_Account(daci_account *account); + +/* + * @brief delete account data from Agent database + * @param[in] accountId accountId + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Delete_Account(int accountId); + +/* + * @brief set emailAddress to account_tbl + * @param[in] accountId accountId + * @param[in] emailAddress new emailAddress + * @param[in] accessName access module name + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Set_Account_Email_Address(int accountId, char *emailAddress, char *accessName); + +/* + * @brief set password to account_tbl + * @param[in] accountId accountId + * @param[in] password new password + * @param[in] accessName access module name + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Set_Account_Password(int accountId, char *password, char *accessName); + +/* + * @brief get all accountId from account_tbl + * @param[out] count count of accountId + * @return operation result + * @retval array of ccountId success + * @retval 0 fail + */ + int *DACI_Get_Account_Account_Id_List(int *count); + +/* + * @brief get emailAddress from account_tbl + * @param[in] accountId accountId + * @return operation result + * @retval emailAddress success + * @retval 0 fail + */ + char *DACI_Get_Account_Email_Address(int accountId); + +/* + * @brief get password from account_tbl + * @param[in] accountId accountId + * @return operation result + * @retval password success + * @retval 0 fail + */ + char *DACI_Get_Account_Password(int accountId); + +/* + * @brief checking whether the accountId exist in account_tbl + * @param[in] accountId accountId + * @return checking result + * @retval 1 exist + * @retval 0 (or error value) not exist + */ + int DACI_IsExist_Account(int accountId); + +/* + * @brief get access name from account_tbl + * @remarks caller should free return value + * @param[in] accountId accountId + * @return operation result + * @retval access name success + * @retval null pointer fail or not existed account id + */ + char *DACI_Get_Access_Name(int accountId); + +/* + * @brief get account id list from account_tbl by access name + * @remarks caller should free return value + * @param[in] access_name accountId + * @param[out] accountId_count account id count + * @return operation result + * @retval account id list success + * @retval null pointer fail or not existed account id + */ + int *DACI_Get_Account_Id_List_By_Access_Name(char *access_name, int *accountId_count); + +/* + * @brief insert folder into folder_tbl + * @param[in] folder array of folder info + * @param[out] count count of folder info + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Add_Folder(daci_folder *folder, int count); + +/* + * @brief delete folder from folder_tbl by folderId + * @param[in] folderId folderId + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Delete_Folder_By_Folder_Id(char *folderId); + +/* + * @brief get folderId from folder_tbl + * @param[in] accountId accountId + * @param[in] itemTypeId itemTypeId + * @param[in] serviceId serviceId + * @param[in] folderTypeId folderTypeId + * @return operation result + * @retval folderId success + * @retval 0 fail + */ + char *DACI_Get_Folder_Folder_Id_By_Service_Id(int accountId, int itemTypeId, char *serviceId, int folderTypeId); + +/* + * @brief get folderId from folder_tbl by folderTypeId + * @param[in] accountId accountId + * @param[in] itemTypeId itemTypeId + * @param[in] folderTypeId folderTypeId + * @return operation result + * @retval folderId success + * @retval 0 fail + */ + daci_id_list *DACI_Get_Folder_Folder_Id_By_Folder_Type_Id(int accountId, int itemTypeId, int folderTypeId); + +/* + * @brief get serviceId from folder_tbl + * @param[in] folderId folderId + * @return operation result + * @retval serviceId success + * @retval 0 fail + */ + char *DACI_Get_Folder_Service_Id(char *folderId); + +/* + * @brief get all folder_id_list from folder_tbl by data_store_id + * get all the folders in account and data store + * @param[in] account_id account_id + * @param[in] itemTypeId itemTypeId + * @return operation result + * @retval array of folder_id success + * @retval 0 fail + */ + daci_id_list *DACI_Get_Folder_Folder_Id_List_By_Item_Type_Id(int account_id, int itemTypeId); + +/* + * @brief get item from folder_tbl + * belonging to different account of folder get folder with the same service_id + * @param[in] accountId accountId + * @param[in] folderId folderId + * @param[in] count count of item info + * @return operation result + * @retval array of folder info success + * @retval 0 fail + */ + daci_folder *DACI_Get_Folder_Mapping_Service_Id(int accountId, char *folderId, int *count); + +/* + * @brief insert item into item_tbl + * @param[in] item array of item info + * @param[in] count count of item info + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Add_Item(daci_item *item, int count); + +/* + * @brief delete item from item_tbl by itemId + * @param[in] itemId itemId + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Delete_Item_By_Item_Id(char *itemId); + +/* + * @brief delete item from item_tbl by accountId and itemTypeId + * @param[in] accountId accountId + * @param[in] itemTypeId itemTypeId + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Delete_Item_By_Item_Type_Id(int accountId, int itemTypeId); + +/* + * @brief get itemId from item_tbl + * @param[in] accountId accountId + * @param[in] serviceId serviceId + * @param[in] itemTypeId itemTypeId + * @return operation result + * @retval itemId success + * @retval 0 fail + */ + char *DACI_Get_Item_Item_Id(int accountId, char *serviceId, int itemTypeId); + +/* + * @brief get serviceId from item_tbl + * @param[in] itemId itemId + * @return operation result + * @retval serviceId success + * @retval 0 fail + */ + char *DACI_Get_Item_Service_Id(char *itemId); + +/* + * @brief get item information from item_tbl + * @param[in] itemId itemId + * @return operation result + * @retval item info success + * @retval 0 fail + */ + daci_item *DACI_Get_Item(char *itemId); + +/* + * @brief get all id in folder from item_tbl + * @param[in] folderId folderId + * @param[in] columnName columnName (COLUMN_NAME_ITEM_ID or COLUMN_NAME_SERVICE_ID) + * @return operation result + * @retval array of item id success + * @retval 0 fail + */ + daci_id_list *DACI_Get_Item_Id_List(char *folderId, DACI_COLUMN_NAME columnName); + +/* + * @brief get item from item_tbl by accountId + * get all the items in account + * @param[in] accountId accountId + * @param[in] itemTypeId itemTypeId + * @param[in] count count of item info + * @return operation result + * @retval array of item info success + * @retval 0 fail + */ + daci_item *DACI_Get_item_By_Account_Id(int accountId, int itemTypeId, int *count); + +/* + * @brief get item data from item_tbl and account_item_changelog_tbl + * Among the items that belong to the itemTypeId, Search for item info belong to the changelog + * @param[in] accountId accountId + * @param[in] itemTypeId itemTypeId + * @param[in] count count of item data + * @return operation result + * @retval array of item data success + * @retval 0 fail + */ + daci_item_info *DACI_Get_Item_Info_By_Item_Type_Id(int accountId, int itemTypeId, int *count); + +/* + * @brief get item from item_tbl + * belonging to different account of item get item with the same service_id + * @param[in] accountId accountId + * @param[in] itemId itemId + * @param[in] count count of item info + * @return operation result + * @retval array of item info success + * @retval 0 fail + */ + daci_item *DACI_Get_item_Mapping_Service_Id(int accountId, char *itemId, int *count); + +/* + * @brief get all id from item_tbl + * @param[in] data_store_id data_store_id + * @return operation result + * @retval array of item id success + * @retval 0 fail + */ + daci_id_list *DACI_Get_Item_Id_List_By_Data_Store_Id(int data_store_id); + +/* + * @brief get item id list + * @param[in] account_id F/W account id + * @param[in] data_store_id data_store_id + * @return operation result + * @retval array of item id success + * @retval 0 fail or not exist + */ + daci_id_list *DACI_Get_Item_Id_List_By_Data_Store_Id_with_AccountID(int account_id, int data_store_id); + +/* + * @brief get item id list from item_tbl and account_item_changelog_tbl + * Among the items that belong to the data_store_id, Search for item info belong to the changelog by operation_id + * @param[in] account_id account_id + * @param[in] data_store_id data_store_id + * @param[in] operation_id operation_id + * @return operation result + * @retval array of item id success + * @retval 0 fail + */ + daci_id_list *DACI_Get_Item_Id_List_By_Operation_Id(int account_id, int data_store_id, int operation_id); + +/* + * @brief checking whether the itemId exist in item_tbl + * @param[in] itemId itemId + * @return checking result + * @retval 1 exist + * @retval 0(or error value) not exist + */ + int DACI_IsExist_Item(char *itemId); + +/* + * @brief insert config into config_tbl + * @param[in] config config info + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Add_Config(daci_config *config); + +/* + * @brief delete config from config_tbl by key + * @param[in] configId configId + * @param[in] key key + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Delete_Config_By_Key(int configId, char *key); + +/* + * @brief get config info from config_tbl by accountId + * get all the config in account + * @param[in] configId configId + * @param[in] count count of config info + * @return operation result + * @retval array of config info success + * @retval 0 fail + */ + daci_config *DACI_Get_Config_By_Config_Id(int configId, int *count); + +/* + * @brief get config info from config_tbl by key + * @param[in] config config info (configId, key) + * @param[out] config config info (configId, key, value, type) + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Get_Config_By_Key(daci_config *config); + +/* + * @brief checking whether config of the config exist in config_tbl + * @param[in] configId configId + * @param[in] key key + * @return checking result + * @retval 1 exist + * @retval 0(or error value) not exist + */ + int DACI_IsExist_Config(int configId, char *key); + +/* + * @brief insert or update config into config_tbl + * checking whether the config exist in config_tbl + * If it does not exist, insert config into config_tbl + * If it existed, update config into config_tbl + * @param[in] config config info + * @param[in] count count of config info + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Update_Config(daci_config *config, int count); + +/* + * @brief insert itemChangelog into account_item_changelog_tbl + * @param[in] accountId accountId + * @param[in] itemChangelog array of itemChangelog info + * @param[in] count count of itemChangelog info + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Add_Item_Changelog(int accountId, daci_item_changelog *itemChangelog, int count); + +/* + * @brief delete itemChangelog from account_item_changelog_tbl by itemId + * @param[in] accountId accountId + * @param[in] itemId itemId + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Delete_Item_Changelog_By_Item_Id(int accountId, char *itemId); + +/* + * @brief delete itemChangelog from account_item_changelog_tbl by itemId list + * @param[in] accountId accountId + * @param[in] itemIdList array of itemId + * @param[in] count count of itemId + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Delete_Item_Changelog_By_Item_Id_List(int accountId, char **itemIdList, int count); + +/* + * @brief delete itemChangelog from account_item_changelog_tbl by itemTypeId + * @param[in] accountId accountId + * @param[in] itemTypeId itemTypeId + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Delete_Item_Changelog_By_Item_Type_Id(int accountId, int itemTypeId); + +/* + * @brief set operationId and syncStatus to account_item_changelog_tbl + * @param[in] accountId accountId + * @param[in] itemChangelog itemChangelog info (operationId, syncStatus, accessName, itemId) + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Set_Item_Changelog_Operation_Id(int accountId, daci_item_changelog *itemChangelog); + +/* + * @brief set syncStatus to account_item_changelog_tbl + * @param[in] accountId accountId + * @param[in] itemChangelog itemChangelog info (syncStatus, accessName, itemId) + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Set_Item_Changelog_Sync_Status(int accountId, daci_item_changelog *itemChangelog); + +/* + * @brief set SYNC_WAIT to account_item_changelog_tbl + * Among the items that match to the itemTypeId and belong to the folder + * If it existed in account_item_changelog_tbl, set SYNC_WAIT to account_item_changelog_tbl + * @param[in] accountId accountId + * @param[in] folderIdList array of folderId + * @param[in] folderIdCount count of folderId + * @param[in] itemTypeIdList array of itemTypeId + * @param[in] itemTypeIdCount count of itemTypeId + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Set_Item_Changelog_Wait_Status(int accountId, char **folderIdList, int folderIdCount, int *itemTypeIdList, int itemTypeIdCount); + +/* + * @brief get itemChangelog info from account_item_changelog_tbl by itemId + * @param[in] accountId accountId + * @param[in] itemChangelog itemChangelog info (itemId) + * @param[out] itemChangelog itemChangelog info (itemId, operationId, syncStatus, accessName) + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Get_Item_Changelog_By_Item_Id(int accountId, daci_item_changelog *itemChangelog); + +/* + * @brief checking whether the itemId exist in account_item_changelog_tbl + * @param[in] accountId accountId + * @param[in] itemId itemId + * @return checking result + * @retval 1 exist + * @retval 0(or error value) not exist + */ + int DACI_IsExist_Item_Changelog(int accountId, char *itemId); + +/* + * @brief insert anchor into last_anchor_tbl + * @param[in] lastAnchor lastAnchor info + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Add_Last_Anchor(daci_last_anchor *lastAnchor); + +/* + * @brief set last_anchor_server and last_anchor_client to last_anchor_tbl + * @param[in] lastAnchor lastAnchor info + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Set_Last_Anchor(daci_last_anchor *lastAnchor); + +/* + * @brief get last_anchor_server and last_anchor_client from last_anchor_tbl by itemTypeId + * @param[in] accountId accountId + * @param[in] itemTypeId itemTypeId + * @param[out] count count of lastAnchor info + * @return operation result + * @retval lastAnchor info success + * @retval 0 fail + */ + daci_last_anchor *DACI_Get_Last_Anchor_By_Item_Type_Id(int accountId, int itemTypeId, int *count); + +/* + * @brief insert mapping into mapping_tbl + * @param[in] mapping mapping info + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Add_Mapping(daci_mapping *mapping); + +/* + * @brief delete mapping from mapping_tbl by luid + * @param[in] accountId accountId + * @param[in] luid luid + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Delete_Mapping_By_Luid(int accountId, char *luid); + +/* + * @brief get all mapping info from mapping_tbl by accountId + * get all the mapping info in account + * @param[in] accountId accountId + * @param[out] count count of mapping info + * @return operation result + * @retval array of mapping info success + * @retval 0 fail + */ + daci_mapping *DACI_Get_Mapping_By_Account_Id(int accountId, int *count); + +/* + * @brief get luid from mapping_tbl by guid + * @param[in] accountId accountId +* @param[in] luid luid + * @return operation result + * @retval guid guid + * @retval 0 fail + */ + char *DACI_Get_Mapping_Guid(int accountId, char *luid); + +/* + * @brief checking whether account exist in mapping_tbl + * @param[in] accountId accountId + * @return checking result + * @retval 1 exist + * @retval 0(or error value) not exist + */ + int DACI_IsExist_Mapping_By_Account_Id(int accountId); + +/* + * @brief insert id_provider into id_provider_tbl + * @param[in] id_provider id_provider info + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Add_ID_Provider(daci_id_provider *id_provider); + +/* + * @brief get id_provider from id_provider_tbl + * @param[in] id_provider_code id_provider_code + * @param[out] id_provider id_provider info + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Get_ID_Provider(unsigned int id_provider_code, daci_id_provider **id_provider); + +/* + * @brief update id_provider in id_provider_tbl + * @param[in] id_provider id_provider info + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Update_ID_Provider(daci_id_provider *id_provider); + +/* + * @brief insert id_page into id_page_tbl + * @param[in] id_page id_page info + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Add_ID_Page(daci_id_page *id_page, unsigned int page_byte_size); + +/* + * @brief delete id_page from id_page_tbl by page_index + * @param[in] id_provider_code id_provider_code + * @param[in] page_index page_index + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Delete_ID_Page(unsigned int id_provider_code, unsigned int page_index); + +/* + * @brief insert id_page into id_page_tbl + * @param[in] id_provider_code id_provider_code + * @param[in] page_index page_index + * @param[out] page_bit page_bit + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Get_ID_Page(unsigned int id_provider_code, unsigned int page_index, char **page_bit); + +/* + * @brief insert id_page into id_page_tbl + * @param[in] id_page id_page info + * @param[in] page_byte_size page_bit's byte size + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Update_ID_Page(daci_id_page *id_page, unsigned int page_byte_size); + +/* + * @brief add the handler pointer to handler hash table + * @param[in] key unique key to distinguish handler pointer + * @param[in] pHandler db handler pointer + * @return operation result + * @retval DACI_SUCCESS success + * @retval DACI_ERR_DB_HANDLER_MGR fail + */ + DACI_RETURN add_agentHandler(unsigned int key, DACI_HANDLER *pHandler); + +/* + * @brief add the handler pointer to handler hash table + * @param[in] key unique key to distinguish handler pointer + * @return operation result + * @retval DACI_SUCCESS success + * @retval DACI_ERR_DB_HANDLER_MGR fail + */ + DACI_RETURN remove_agentHandler(unsigned int key); + +/* + * @brief add the handler pointer to handler hash table + * @param[in] key unique key to distinguish handler pointer + * @return operation result + * @retval DACI_SUCCESS success + * @retval DACI_ERR_DB_HANDLER_MGR fail + */ + DACI_HANDLER *get_agentHandler(unsigned int key); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /* DACI_AGENT_HANDLER_MANAGER_H_ */ diff --git a/framework/include/DataAdapter/DACI_Agent_Mgr.h b/framework/include/DataAdapter/DACI_Agent_Mgr.h new file mode 100755 index 0000000..adb9101 --- /dev/null +++ b/framework/include/DataAdapter/DACI_Agent_Mgr.h @@ -0,0 +1,108 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu , + * Heeyoung Hwang + */ + +#ifndef DACI_AGENT_MGR_H_ +#define DACI_AGENT_MGR_H_ + +#include "EXT_DACI_Errors.h" + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/** + * @file DACI_Agent_Mgr.h + * @brief Support to sync F/W item, folder change log table with service storage + */ + +/** + * @brief Enumerations of change operation code + */ + typedef enum { + CHANGE_OPERATION_ADD = 301, /**< means add */ + CHANGE_OPERATION_UPDATE = 302, + /**< means update */ + CHANGE_OPERATION_DELETE = 303, + /**< means delete */ + } CHANAGE_OPERATION; + +/** + * @brief construct F/W item, change log table from Service storage + * @remarks F/W maintain change point of service storage change, this function use the change point. + * @param[in] fw_account_id F/W account ID + * @param[in] service_type service type - service data connector pluIn's ID described in F/W config file + * @return DACI_SUCCESS on success, otherwise a error value. + */ + DACI_RETURN construct_ItemTbl_From_Service(int fw_account_id, int service_type); + +/** + * @brief construct all account's F/W folder table from Service storage + * @param[in] service_type service type - service data connector pluIn's ID described in F/W config file + * @return DACI_SUCCESS on success, otherwise a error value. + */ + DACI_RETURN construct_FolderTbl_From_Service(int service_type); + +/** + * @brief refresh F/W only item table from Service storage + * @remarks delete all F/W item, change log table and construct item table from item in current Service storage. + * @param[in] fw_account_id F/W account ID + * @param[in] service_type service type - service data connector pluIn's ID described in F/W config file + * @return DACI_SUCCESS on success, otherwise a error value. + */ + DACI_RETURN refresh_Item_Tbl_From_Service(int fw_account_id, int service_type); + +/** + * @brief refresh F/W item, changeLog table from Service storage + * @remarks delete all F/W item, change log table and construct item, change log table from item in current Service storage. + * @param[in] fw_account_id F/W account ID + * @param[in] service_type service type - service data connector pluIn's ID described in F/W config file + * @return DACI_SUCCESS on success, otherwise a error value. + */ + DACI_RETURN refresh_ChangeLog_Tbl_From_Service(int fw_account_id, int service_type); + +/** + * @brief set service change point as flag + * @remarks this change point used when construct item, change log table + * @param[in] fw_account_id F/W account ID + * @param[in] service_type service type - service data connector pluIn's ID described in F/W config file + * @return DACI_SUCCESS on success, otherwise a error value. + */ + DACI_RETURN set_ChangePoint_Service(int fw_account_id, int service_type); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /* DACI_AGENT_MGR_H_ */ diff --git a/framework/include/DataAdapter/DACI_ChangeLog.h b/framework/include/DataAdapter/DACI_ChangeLog.h new file mode 100755 index 0000000..f8cd153 --- /dev/null +++ b/framework/include/DataAdapter/DACI_ChangeLog.h @@ -0,0 +1,126 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu , + * Heeyoung Hwang + */ + +#ifndef DACI_CHANGELOG_H_ +#define DACI_CHANGELOG_H_ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/** + * @file DACI_ChangeLog.h + * @brief Support to process changed service item, effect to F/W item, change log table. + */ + +/** + * @brief handling added item to service storage, update F/W item & change log table + * @remarks This function is called when the new item is added to the service storage. data connector plugIn developer use this function. + * @param[in] service_accountID service account id + * @param[in] index possible mapping one service account with multiple F/W account, so need index of F/W account. + * @param[in] service_itemID added service item id + * @param[in] itemType service type - service data connector pluIn's ID described in F/W config file + * @param[in] service_folderID service folder id + * @param[in] folderType folder type defined in data connector plug-In + * @return 1 on success, otherwise a negative error value. + * @see ChangeLog_Add_Item() + */ + int handle_ADD_ITEM(int service_accountID, int index, char *service_itemID, int itemType, char *service_folderID, int folderType); + +/** + * @brief handling deleted item from service storage, update F/W item & change log table + * @remarks This function is called when the item is deleted from the service storage. data connector plugIn developer use this function. + * @param[in] service_accountID service account id + * @param[in] index possible mapping one service account with multiple F/W account, so need index of F/W account. + * @param[in] service_itemID added service item id + * @param[in] itemType service type - service data connector pluIn's ID described in F/W config file + * @return 1 on success, otherwise a negative error value. + * @see ChangeLog_Delete_Item() + */ + int handle_DEL_ITEM(int service_accountID, int index, char *service_itemID, int itemType); + +/** + * @brief handling updated item from service storage, update F/W item & change log table + * @remarks This function is called when the item is updated from the service storage. data connector plugIn developer use this function. + * @param[in] service_accountID service account id + * @param[in] index possible mapping one service account with multiple F/W account, so need index of F/W account. + * @param[in] service_itemID added service item id + * @param[in] itemType service type - service data connector pluIn's ID described in F/W config file + * @return 1 on success, otherwise a negative error value. + * @see ChangeLog_Update_Item() + */ + int handle_UPDATE_ITEM(int service_accountID, int index, char *service_itemID, int itemType); + +/** + * @brief handling added item to service storage, update F/W item & change log table + * @remarks This function works very similar to @ref handle_ADD_ITEM(). + * This function is called force by Agent to set item & change log table manually. + * @param[in] fw_account_id F/W account id + * @param[in] fw_item_id F/W item id + * @param[in] service_itemID service item id + * @param[in] itemType service type - service data connector pluIn's ID described in F/W config file + * @param[in] fw_folder_id F/W folder id + * @return 1 on success, otherwise a negative error value. + * @see handle_ADD_ITEM() + */ + int ChangeLog_Add_Item(int fw_account_id, char *fw_item_id, char *service_item_id, int itemType, char *fw_folder_id); + +/** + * @brief handling deleted item from service storage, update F/W item & change log table + * @remarks This function works very similar to @ref handle_DEL_ITEM(). + * @param[in] fw_account_id F/W account id + * @param[in] fw_item_id F/W item id + * @param[in] itemType service type - service data connector pluIn's ID described in F/W config file + * @return 1 on success, otherwise a negative error value. + * @see handle_DEL_ITEM() + */ + int ChangeLog_Delete_Item(int fw_account_id, char *fw_item_id, int itemType); + +/** + * @brief handling updated item from service storage, update F/W item & change log table + * @remarks This function works very similar to @ref handle_UPDATE_ITEM(). + * @param[in] fw_account_id F/W account id + * @param[in] fw_item_id F/W item id + * @param[in] itemType service type - service data connector pluIn's ID described in F/W config file + * @return 1 on success, otherwise a negative error value. + * @see handle_UPDATE_ITEM() + */ + int ChangeLog_Update_Item(int fw_account_id, char *fw_item_id, int itemType); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /* DACI_CHANGELOG_H_ */ diff --git a/framework/include/DataAdapter/DACI_Common.h b/framework/include/DataAdapter/DACI_Common.h new file mode 100755 index 0000000..280e067 --- /dev/null +++ b/framework/include/DataAdapter/DACI_Common.h @@ -0,0 +1,359 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu , + * Heeyoung Hwang + */ + +#ifndef DACI_COMMON_H_ +#define DACI_COMMON_H_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "EXT_DACI_Errors.h" + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/** + * @file DACI_Common.h + * @brief Common factor of Framework common database + */ + +#define MO_HANDLER sqlite3 + +#define DACI_HANDLER sqlite3 + +#define DACI_RETRY_COUNT 10 + +#define DACI_MAX_QUERY_LENGTH 2048 + +#define DACI_MAX_ACCOUNT 10 + +#define DACI_FOLDER_TYPE_COUNT 19 + +#define DACI_ITEM_TYPE_COUNT 6 + +#define DACI_OPERATION_TYPE_COUNT 3 + +#define DACI_MEMORY_SET(ptr) memset(ptr, 0x00, sizeof(ptr)); + +#define DACI_MEMORY_MALLOC(type, size, count) (type)malloc(size*count) + +#define DACI_MEMORY_CALLOC(type, size, count) (type)calloc(count, size) + +#define DACI_MEMORY_FREE(src) \ + if (src != NULL) { \ + free(src); \ + src = NULL; \ + } \ + +#define DACI_STRDUP(src) (src == NULL) ? NULL : strdup(src); + +#define DACI_ATOI(src) (src == NULL) ? 0 : atoi(src); + +#define DACI_GET_THREAD_ID pthread_self() + +/** + * @brief rename sqlite3 connection + */ + typedef sqlite3_stmt *daci_stmt; + +/** + * @brief Enumerations of database peak type + */ + typedef enum { + PEAK_TYPE_ON = 601, /**< peak type on */ + PEAK_TYPE_ON_N_OFF, /**< peak type N off */ + PEAK_TYPE_OFF /**< peak type off */ + } DACI_PEAK_TYPE; + +/** + * @brief Enumerations of database transaction + */ + typedef enum { + TRANSACTION_COMMIT, /**< means commit */ + TRANSACTION_ROLLBACK + /**< means rollback */ + } DACI_TRANSACTION; + +/** + * @brief Enumerations of common db's table list + */ + typedef enum { + TABLE_NAME_ACCOUNT, /**< means account_tbl */ + TABLE_NAME_FOLDER, /**< means folder_tbl */ + TABLE_NAME_ITEM, /**< means item_tbl */ + TABLE_NAME_CONFIG, /**< means config_tbl */ + TABLE_NAME_ACCOUNT_ITEM_CHANGELOG, /**< means account_item_changelog_tbl */ + TABLE_NAME_LAST_ANCHOR, /**< means last_anchor_tbl */ + TABLE_NAME_MAPPING, /**< means mapping_tbl */ + TABLE_NAME_ID_PROVIDER, /**< means id_provider_tbl */ + TABLE_NAME_ID_PAGE, /**< means id_page_tbl */ + + TABLE_NAME_MAX /**< count of common database's tables */ + } DACI_TABLE_NAME; + +/** + * @brief Enumerations of common column + */ + typedef enum { + COLUMN_NAME_ACCOUNT_ID, /**< means column, account_id */ + COLUMN_NAME_ITEM_ID, /**< means column, item_id */ + COLUMN_NAME_SERVICE_ID, /**< means column, service_id */ + COLUMN_NAME_ACCESS_NAME, /**< means column, access_name */ + + COLUMN_NAME_MAX /**< count of common columns */ + } DACI_COLUMN_NAME; + +/** + * @brief Enumerations of structure type concern of DACI + */ + typedef enum { + STRUCT_TYPE_ACCOUNT, /**< means structure, daci_account */ + STRUCT_TYPE_FOLDER, /**< means structure, daci_folder */ + STRUCT_TYPE_ITEM, /**< means structure, daci_item */ + STRUCT_TYPE_CONFIG, /**< means structure, daci_config */ + STRUCT_TYPE_ITEM_CHANGELOG, /**< means structure, daci_item_changelog */ + STRUCT_TYPE_LAST_ANCHOR, /**< means structure, daci_last_anchor */ + STRUCT_TYPE_MAPPING, /**< means structure, daci_mapping */ + STRUCT_TYPE_ITEM_INFO, /**< means structure, daci_item_info */ + STRUCT_TYPE_ID_LIST, /**< means structure, daci_id_list */ + + STRUCT_TYPE_MAX /**< count of enumeration */ + } DACI_STRUCT_TYPE; + +/** + * @brief Structure of table - mapped column of account_tbl + */ + typedef struct { + int account_id; /**< account_id */ + char *email_address; /**< email_address */ + char *password; /**< password */ + bool enable; /**< enable */ + char *accessName; + /**< name of accessor */ + } daci_account; + +/** + * @brief Structure of table - mapped column of folder_tbl + */ + typedef struct { + char *folder_id; /**< F/W folder id */ + int data_store_id; + /**< service data connector pluIn's ID described in F/W config file */ + int account_id; /**< F/W account id */ + int folder_type_id; + /**< data connector plugIn has this folder type id */ + char *service_id; + /**< service folder id */ + char *parent_folder_id; + /**< parent folder id if exist hierarchy */ + char *access_name; + /**< name of accessor */ + } daci_folder; + +/** + * @brief Structure of table - mapped column of item_tbl + */ + typedef struct { + char *item_id; /**< F/W item id */ + int data_store_id; + /**< service data connector pluIn's ID described in F/W config file */ + int account_id; /**< F/W account id */ + char *folder_id; /**< F/W folder id */ + char *service_id; + /**< service item id */ + char *access_name; /**< name of accessor */ + } daci_item; + +/** + * @brief Structure of table - mapped column of config_tbl + */ + typedef struct { + int config_id; /**< configuration id, this means account id */ + char *key; /**< configuration key */ + char *value; /**< configuration value */ + char *type; /**< configuration type */ + char *access_name; /**< name of accessor */ + } daci_config; + +/** + * @brief Structure of table - mapped column of account_item_changelog_tbl + */ + typedef struct { + char *item_id; /**< F/W item id */ + int operation_id; /**< operation id - add, delete, update */ + char *status; /**< user defined status of item */ + char *access_name; /**< name of accessor */ + } daci_item_changelog; + +/** + * @brief Structure of table - mapped column of last_anchor_tbl + */ + typedef struct { + int account_id; /**< F/W account id */ + int data_store_id; /**< service data connector pluIn's ID described in F/W config file */ + char *last_anchor_server; /**< last anchor that server has */ + char *last_anchor_client; /**< last anchor that client has */ + char *access_name; /**< name of accessor */ + } daci_last_anchor; + +/** + * @brief Structure of table - mapped column of mapping_tbl + */ + typedef struct { + int account_id; /**< F/W account id */ + int data_store_id; /**< service data connector pluIn's ID described in F/W config file */ + char *luid; /**< Locally unique identifier */ + char *guid; + /**< Globally unique identifier */ + char *access_name; /**< name of accessor */ + } daci_mapping; + +/** + * @brief Structure of Item information + */ + typedef struct { + char *itemId; /**< F/W item id */ + int itemTypeId; /**< service data connector pluIn's ID described in F/W config file */ + char *serviceId; /**< service item id */ + int operationId; /**< operation type - add, delete, update */ + char *syncStatus; /**< user defined status of item */ + } daci_item_info; + +/** + * @brief Structure of Item id's container + */ + typedef struct { + int count; /**< count of id */ + char **id; /**< real id list */ + } daci_id_list; + +/** + * @brief Structure of table - mapped column of id_provider_tbl + */ + typedef struct { + unsigned int id_provider_code; /**< ID of id provider - this described in F/W configuration file */ + unsigned int id_capacity; /**< max ID count possible id provider generate - this described in F/W configuration file */ + unsigned int bit_per_page; + /**< most number of bit per one page */ + unsigned int last_id; /**< current last provided ID */ + unsigned int free_bit_cnt; + /**< the number of IDs that can be issued */ + } daci_id_provider; + +/** + * @brief Structure of table - mapped column of id_page_tbl + */ + typedef struct { + unsigned int page_index;/**< index of page */ + unsigned int id_provider_code; /**< ID of id provider - this described in F/W configuration file */ + char *page_bit; /**< real construction of ID issued */ + } daci_id_page; + +/* + * @brief free memory daci_account structure + * @param[in] account daci_account structure + * @param[in] count structure count + */ + void DACI_Free_Memory_Account(daci_account *account, int count); + +/* + * @brief free memory daci_folder structure + * @param[in] folder daci_folder structure + * @param[in] count structure count + */ + void DACI_Free_Memory_Folder(daci_folder *folder, int count); + +/* + * @brief free memory daci_item structure + * @param[in] item daci_item structure + * @param[in] count structure count + */ + void DACI_Free_Memory_Item(daci_item *item, int count); + +/* + * @brief free memory daci_config structure + * @param[in] config daci_config structure + * @param[in] count structure count + */ + void DACI_Free_Memory_Config(daci_config *config, int count); + +/* + * @brief free memory daci_item_changelog structure + * @param[in] itemChangelog daci_item_changelog structure + * @param[in] count structure count + */ + void DACI_Free_Memory_Item_Changelog(daci_item_changelog *itemChangelog, int count); + +/* + * @brief free memory daci_last_anchor structure + * @param[in] lastAnchor daci_last_anchor structure + * @param[in] count structure count + */ + void DACI_Free_Memory_Last_Anchor(daci_last_anchor *lastAnchor, int count); + +/* + * @brief free memory daci_mapping structure + * @param[in] mapping daci_mapping structure + * @param[in] count structure count + */ + void DACI_Free_Memory_Mapping(daci_mapping *mapping, int count); + +/* + * @brief free memory daci_item_info structure + * @param[in] itemInfo daci_item_info structure + * @param[in] count structure count + */ + void DACI_Free_Memory_Item_Info(daci_item_info *itemInfo, int count); + +/* + * @brief free memory daci_id_list structure + * @param[in] idList daci_id_list structure + */ + void DACI_Free_Memory_Id_List(daci_id_list *idList); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /* DACI_COMMON_H_ */ diff --git a/framework/include/DataAdapter/DACI_Luid.h b/framework/include/DataAdapter/DACI_Luid.h new file mode 100755 index 0000000..e68e3d9 --- /dev/null +++ b/framework/include/DataAdapter/DACI_Luid.h @@ -0,0 +1,71 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu , + * Heeyoung Hwang + */ + +#ifndef DACI_LUID_H_ +#define DACI_LUID_H_ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/** + * @file DACI_Luid.h + * @brief Support to generate unique ID + */ + +/* + * @brief Generate new item LUID to use inside agent, when add new item + * @remarks Generated Sequence ID ( 1, 2, 3, .... ) to max ID value described in F/W initiation config file + * @param[in] id_provider_code ID's seed value described in F/W initiation config file + * @param[in] count + * @return operation result + * @retval generated item_luid list success (new item LUID converted to string) + * @retval 0 fail + */ + char **DACI_Generate_Item_Luid(int id_provider_code, int count); + +/* + * @brief Generate new folder LUID to use inside agent, when add new folder + * @return operation result + * @retval folder_luid success (new folder LUID converted to string) + * @retval 0 fail + */ + char *DACI_Generate_Folder_Luid(); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /* DACI_LUID_H_ */ diff --git a/framework/include/DataAdapter/DACI_Service.h b/framework/include/DataAdapter/DACI_Service.h new file mode 100755 index 0000000..1606308 --- /dev/null +++ b/framework/include/DataAdapter/DACI_Service.h @@ -0,0 +1,302 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu , + * Heeyoung Hwang + */ + +#ifndef DACI_SERVICE_H_ +#define DACI_SERVICE_H_ + +#include "DACI_Common.h" + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/** + * @file DACI_Service.h + * @brief Support to use service storage + */ + +/* + * @brief open service database + * @param[in] content_type service type - service data connector pluIn's ID described in F/W config file + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Service_Open(int content_type); + +/* + * @brief close service database + * @param[in] content_type service type - service data connector pluIn's ID described in F/W config file + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Service_Close(int content_type); + +/* + * @brief start transaction for service database + * @param[in] content_type service type - service data connector pluIn's ID described in F/W config file + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Service_Begin(int content_type); + +/* + * @brief end transaction for service database + * @param[in] content_type service type - service data connector pluIn's ID described in F/W config file + * @param[in] is_success 1 : commit, 0 : rollback + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Service_End(int content_type, int is_success); + +/* + * @brief insert item into service database + * @param[in] content_type service type - service data connector pluIn's ID described in F/W config file + * @param[in] account_id F/W account_id + * @param[in] folder_id F/W folder_id + * @param[in] data item info + * @param[out] item_id success : service item_id, fail : 0 + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Service_Add_Item(int content_type, int account_id, char *folder_id, const void *data, char **item_id); + +/* + * @brief update item from service database + * @param[in] content_type service type - service data connector pluIn's ID described in F/W config file + * @param[in] account_id F/W account_id + * @param[in] folder_id F/W folder_id + * @param[in] item_id F/W item_id + * @param[in] data data + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Service_Update_Item(int content_type, int account_id, char *folder_id, char *item_id, const void *data); + +/* + * @brief delete item from service database + * @param[in] content_type service type - service data connector pluIn's ID described in F/W config file + * @param[in] account_id F/W account_id + * @param[in] folder_id F/W folder_id + * @param[in] item_id F/W item_id + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Service_Delete_Item(int content_type, int account_id, char *folder_id, char *item_id); + +/* + * @brief delete all items from service database + * @param[in] content_type service type - service data connector pluIn's ID described in F/W config file + * @param[in] account_id F/W account_id + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Service_Delete_All_Items(int content_type, int account_id); + +/* + * @brief get item from service database + * @param[in] content_type service type - service data connector pluIn's ID described in F/W config file + * @param[in] account_id F/W account_id + * @param[in] folder_id F/W folder_id + * @param[in] item_id F/W item_id + * @param[out] data success : item info, fail : 0 + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Service_Get_Item(int content_type, int account_id, char *folder_id, char *item_id, void **data); + +/* + * @brief insert folder into service database + * @param[in] content_type service type - service data connector pluIn's ID described in F/W config file + * @param[in] account_id F/W account_id + * @param[in] folder_name folder_name + * @param[in] folder_type folder_type + * @param[out] folder_id success : folder_id, fail : 0 + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Service_Add_Folder(int content_type, int account_id, char *folder_name, int folder_type, char **folder_id); + +/* + * @brief delete folder from service database + * @param[in] content_type service type - service data connector pluIn's ID described in F/W config file + * @param[in] account_id F/W account_id + * @param[in] folder_id F/W folder_id + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Service_Delete_Folder(int content_type, int account_id, char *folder_id); + +/* + * @brief get folder from service database + * @param[in] content_type service type - service data connector pluIn's ID described in F/W config file + * @param[in] account_id F/W account_id + * @param[in] folder_id F/W folder_id + * @param[out] out_folder_name success : folder name, fail : 0 + * @param[out] out_folder_type success : folder type, fail : -1 + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Service_Get_Folder(int content_type, int account_id, char *folder_id, char **out_folder_name, int *out_folder_type); + +/* + * @brief execute data into service + * @param[in] content_type service type - service data connector pluIn's ID described in F/W config file + * @param[in] account_id F/W account_id + * @param[in] execute_key execute_key + * @param[in] execute_values execute_values + * @param[out] result extension result info + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Service_Execute(int content_type, int account_ID, const char *execute_key, void *execute_values, void **result); + +/* + * @brief get item used count + * @param[in] content_type service type - service data connector pluIn's ID described in F/W config file + * @return operation result + * @retval current item count success + * @retval error value fail : minus + */ + int DACI_Service_Get_Used_Item_Count(int content_type); + +/* + * @brief get item used count for folder + * @param[in] content_type service type - service data connector pluIn's ID described in F/W config file + * @param[in] account_id F/W account_id + * @param[in] folder_id F/W folder_id + * @return operation result + * @retval current item count success + * @retval error value fail : minus + */ + int DACI_Service_Get_Used_Item_Count_For_Folder(int content_type, int account_id, char *folder_id); + +/* + * @brief write data store items to file + * @param[in] content_type service type - service data connector pluIn's ID described in F/W config file + * @param[in] account_id F/W account_id + * @param[out] file_path written file_path + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail :minus + */ + DACI_RETURN DACI_Service_Write_Items_To_FIle(int content_type, int account_id, char **file_path); + +/* + * @brief add file wrote item to data store + * @param[in] content_type service type - service data connector pluIn's ID described in F/W config file + * @param[in] account_id F/W account_id + * @param[in] file_path file_path + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail : minus + */ + DACI_RETURN DACI_Service_Add_File_Wrote_Items_To_Datastore(int content_type, int account_id, const char *file_path); + +/***************************************** Get Storage MetaInfo ****************************************/ +/* + * @brief get max item count per folder + * @param[in] content_type service type - service data connector pluIn's ID described in F/W config file + * @param[in] folder_type folder type provided plug-in + * @return operation result + * @retval max item count success + * @retval -1 fail + */ + int DACI_Service_Get_MAX_Item_Count(int content_type, int folder_type); + +/* + * @brief get service data's available field length + * @param[in] content_type service type - service data connector pluIn's ID described in F/W config file + * @param[in] field_name field_name provided data connector plug-In + * @param[in] child_field_name child_field_name provided data connector plug-In + * @return operation result + * @retval available field length success + * @retval -1 fail + */ + int DACI_Service_Get_MAX_Field_Length(int content_type, int field_name, int child_field_name); + +/* + * @brief get service data's available field count + * @param[in] content_type service type - service data connector pluIn's ID described in F/W config file + * @param[in] field_name field_name provided data connector plug-In + * @param[in] child_field_name child_field_name provided data connector plug-In + * @return operation result + * @retval available field count success + * @retval -1 fail + */ + int DACI_Service_Get_MAX_Field_Count(int content_type, int field_name, int child_field_name); + +/* + * @brief get service data's available field value's domain + * @param[in] content_type service type - service data connector pluIn's ID described in F/W config file + * @param[in] field_name field_name provided data connector plug-In + * @param[in] child_field_name child_field_name provided data connector plug-In + * @param[out] str_val when domain value is string + * @param[out] num_val1 when domain value is integer (ex minimum value) + * @param[out] num_val2 when domain value is integer (ex maximum value) + * @return operation result + * @retval 1 success + * @retval -1 fail + */ + int DACI_Service_Get_Field_Value(int content_type, int field_name, int child_field_name, char **str_val, int *num_val1, int *num_val2); + +/* + * @brief get service data's available field count + * @param[in] content_type service type - service data connector pluIn's ID described in F/W config file + * @param[in] feature feature provided data connector plug-In + * @return operation result + * @retval 1 support + * @retval 0 not support + * @retval -1 fail + */ + int DACI_Service_Get_Is_Support_Feature(int content_type, int feature); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /* DACI_SERVICE_H_ */ diff --git a/framework/include/DataAdapter/EXT_DACI_Converter.h b/framework/include/DataAdapter/EXT_DACI_Converter.h new file mode 100755 index 0000000..6664357 --- /dev/null +++ b/framework/include/DataAdapter/EXT_DACI_Converter.h @@ -0,0 +1,118 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu , + * Heeyoung Hwang + */ + +#ifndef EXT_DACI_CONVERTER_H_ +#define EXT_DACI_CONVERTER_H_ + +#include "../PlugIn/DataConverter_Resource.h" +#include "EXT_DACI_Errors.h" + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/** + * @file EXT_DACI_Converter.h + * @brief Support to use service converter module + */ + +/* + * @brief allocate internal object for content type + * @param[in] content_type service type - service data connector pluIn's ID described in F/W config file + * @return operation result + * @retval internal struct pointer success + * @retval 0 fail + */ + void *T_DACI_Alloc_Obj(int content_type); + +/* + * @brief free internal object for content type + * @param[in] content_type service type - service data connector pluIn's ID described in F/W config file + * @param[in] in_object internal object pointer + * @return operation result + * @retval DACI_SUCCESS success + * @retval DACI_ERRORS fail + */ + DACI_RETURN T_DACI_Free_Obj(int content_type, void *in_object); + +/* + * @brief set value for internal object + * @param[in] content_type service type - service data connector pluIn's ID described in F/W config file + * @param[in] in_object internal object pointer + * @param[in] key key + * @param[in] extension_key extension key + * @param[in] set_value value + * @return operation result + * @retval new object pointer success + * @retval 0 fail + */ + void *T_DACI_Set_Value_To_Obj(int content_type, void *in_object, int key, char *extension_key, void *set_value); + +/* + * @brief allocate internal object for content type + * @param[in] content_type service type - service data connector pluIn's ID described in F/W config file + * @param[in] in_object internal object pointer + * @param[in] key key + * @param[in] extension_key extension key + * @return operation result + * @retval value pointer success + * @retval 0 fail + */ + void *T_DACI_Get_Value_To_Obj(int content_type, void *in_object, int key, char *extension_key); + +/* + * @brief get meta infomation of internal object + * @param[in] content_type service type - service data connector pluIn's ID described in F/W config file + * @return operation result + * @retval value pointer success + * @retval 0 fail + */ + Object_Info *T_DACI_Get_Obj_Info(int content_type); + +/* + * @brief free infomation of internal object + * @param[in] content_type service type - service data connector pluIn's ID described in F/W config file + * @param[in] obj_info object info + * @return operation result + * @retval DACI_SUCCESS success + * @retval DACI_ERRORS fail + */ + DACI_RETURN T_DACI_Free_Obj_Info(int content_type, Object_Info *obj_info); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /* EXT_DACI_CONVERTER_H_ */ diff --git a/framework/include/DataAdapter/EXT_DACI_Errors.h b/framework/include/DataAdapter/EXT_DACI_Errors.h new file mode 100755 index 0000000..c98e131 --- /dev/null +++ b/framework/include/DataAdapter/EXT_DACI_Errors.h @@ -0,0 +1,81 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu , + * Heeyoung Hwang + */ + +#ifndef EXT_DACI_ERRORS_H_ +#define EXT_DACI_ERRORS_H_ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/** + * @file EXT_DACI_Errors.h + * @brief Definition of framework error codes for DACI + */ + +/** + * @brief Enumerations of error codes for DACI + */ + typedef enum _DACI_RETURN { + DACI_SUCCESS = 1, /**< successful */ + DACI_ERRORS = -800, /**< fail */ + DACI_NOT_FOUND_PLUG_IN = -801, /**< not found data connector or converter plugIn */ + DACI_ERR_OPEN_FAILED = -802, /**< database open fail */ + DACI_ERR_CLOSE_FAILED = -803, /**< database close fail */ + DACI_ERR_TRANSACTION_FAILED = -804, /**< transaction fail */ + DACI_ERR_CREATE_TABLE_FAILED = -805, /**< create table fail */ + DACI_ERR_DROP_TABLE_FAILED = -806, /**< drop table fail */ + DACI_ERR_QUERY_FAILED = -807, /**< process query fail */ + DACI_ERR_NOT_OPENED = -808, /**< database not opened so fail */ + DACI_ERR_ACCOUNT_FULL = -809, /**< exist full account */ + DACI_ERR_DELETE_LAST_ACCOUNT = -810, /**< */ + DACI_ERR_PRIMARY_KEY_NOT_UNIQUE = -811, /**< already exist primary key */ + DACI_ERR_DB_HANDLER_MGR = -812, /**< database connection fail - get or create */ + DACI_ERR_ALREADY_EXIST = -813, /**< */ + DACI_ERR_INVALID_CONTENT = -814, /**< */ + DACI_ERR_MEMORY_FULL = -815, /**< memory full */ + DACI_ERR_SUB_DATA_EXIST = -816, /**< item not empty */ + DACI_ERR_LOCKED = -817, /**< database lock */ + DACI_ERR_MORE_DATA = -818, /**< query result has more data, used when iterating */ + DACI_ERR_NO_DATA = -819, /**< query result not found */ + DACI_ERR_NOT_SUPPORTED = -820, /**< */ + DACI_ERR_NOT_EXECUTE = -821, /**< */ + } DACI_RETURN; + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /* EXT_DACI_ERRORS_H_ */ diff --git a/framework/include/Device/EXT_DCI_Common.h b/framework/include/Device/EXT_DCI_Common.h new file mode 100755 index 0000000..f7e7546 --- /dev/null +++ b/framework/include/Device/EXT_DCI_Common.h @@ -0,0 +1,75 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Seokgil Kang + */ + +#ifndef DICI_COMMON_H_ +#define DICI_COMMON_H_ + +#include "EXT_DCI_Errors.h" + +/** + * @file EXT_DCI_Common.h + * @brief Defines enumerations for device execution + */ + +/** + * @brief Enumerations for state of power manager + */ +typedef enum { + LCD_NORMAL = 0, + LCD_DIM, + LCD_OFF, + SUSPEND, + POWER_OFF, + SETALL +} PM_State; + +/** + * @brief Enumerations for lock state of power manager + */ +typedef enum { + GOTO_STATE_NOW = 0, + STAY_CUR_STATE +} PM_Lock_State_Flag; + +/** + * @brief Enumerations for unlock state of power manager + */ +typedef enum { + SLEEP_MARGIN = 0, + RESET_TIMER, + KEEP_TIMER +} PM_Unlock_State_Flag; + +#endif /* DICI_COMMON_H_ */ diff --git a/framework/include/Device/EXT_DCI_DevExecutor.h b/framework/include/Device/EXT_DCI_DevExecutor.h new file mode 100755 index 0000000..1894545 --- /dev/null +++ b/framework/include/Device/EXT_DCI_DevExecutor.h @@ -0,0 +1,79 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Seokgil Kang + * SeongWon Shim + */ + +#ifndef EXT_DCI_DEVEXECUTOR_H_ +#define EXT_DCI_DEVEXECUTOR_H_ + +#include "EXT_DCI_Common.h" + +/** + * @file EXT_DCI_DevExecutor.h + * @brief Defines device execution APIs + */ + +/** + * @brief Lock a particular power-state as the current power-state + * @remarks If parameter 'timeout' value is 0, state of power manager is always lock until calling DCI_PM_Unlock_State() + * @param[in] device_plugIn_id Device PlugIn ID + * @param[in] state LCD_NORMAL, LCD_DIM, LCD_OFF, SUSPEND, POWER_OFF, SETALL + * @param[in] flag GOTO_STATE_NOW, STAY_CUR_STATE + * @param[in] timeout lock-timeout in milliseconds + * @return Operation result + * @retval DICI_SUCCESS Successful + * @retval DCI_FAIL Operation failed + * + * @code +DCI_RETURN res = DCI_PM_Lock_State(1, LCD_OFF , STAY_CUR_STATE, 0); + * @endcode + */ +DCI_RETURN DCI_PM_Lock_State(int device_plugIn_id, PM_State state, PM_Lock_State_Flag flag, unsigned int timeout); + +/** + * @brief Unlock the power-state + * @param[in] device_plugIn_id Device PlugIn ID + * @param[in] state LCD_NORMAL, LCD_DIM, LCD_OFF, SUSPEND, POWER_OFF, SETALL + * @param[in] flag SLEEP_MARGIN, RESET_TIMER, KEEP_TIMER + * @return Operation result + * @retval DICI_SUCCESS Successful + * @retval DCI_FAIL Operation failed + * + * @code + DCI_RETURN res = DCI_PM_Unlock_State(1, LCD_OFF , RESET_TIMER); + * @endcode + */ +DCI_RETURN DCI_PM_Unlock_State(int device_plugIn_id, PM_State state, PM_Unlock_State_Flag flag); + +#endif /* EXT_DCI_DEVEXECUTOR_H_ */ diff --git a/framework/include/Device/EXT_DCI_DevInfo.h b/framework/include/Device/EXT_DCI_DevInfo.h new file mode 100755 index 0000000..132bcbb --- /dev/null +++ b/framework/include/Device/EXT_DCI_DevInfo.h @@ -0,0 +1,95 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Seokgil Kang + */ + +#ifndef EXT_DCI_H_ +#define EXT_DCI_H_ + +#include "EXT_DCI_Common.h" + +/** + * @file EXT_DCI_DevInfo.h + * @brief Defines device information APIs + */ + +/** + * @brief Load device information on the memory + * @remarks Run only once at the beginning of the process + * @param[in] device_plugIn_id Device plugIn ID + * @return Operation result + * @retval DICI_SUCCESS Successful + * @retval DCI_FAIL Operation failed + * + * @code +DCI_RETURN res = DICI_Init(1); + * @endcode + */ +DCI_RETURN DCI_Init(int device_plugIn_id); + +/** + * @brief Get particular device information on the memory + * @remarks Device information supported by sync-agent-framework (2012.03.19) + * DevID(device id), Man(manufacture), Mod(model id or model number), SwV(software version), + * HwV(hardware version), FwV(firmware version), OEM(original equipment manufacturer), + * DevTyp(device type), Lang(language), DTDV(DTD version), PDAV(PDA version), + * CSCV(CSC version), ModemV(modem version), KernelV(kernal version), OPCO(OPCO information) + * @param[in] device_plugIn_id Device plugIn ID + * @param[in] info_name Name of device information (see remarks) + * @param[out] value Value of device information + * @return Operation result + * @retval DICI_SUCCESS Successful + * @retval DICI_FAIL Operation failed + * @pre The application should be called DCI_Init() + * + * @code + char *value; + DCI_RETURN res = DICI_Get_DevInfo(1, "DevID", &value); + * @endcode + */ +DCI_RETURN DCI_Get_DevInfo(int device_plugIn_id, char *info_name, char **value); + +/** + * @brief Free memory for device information on the memory + * @param[in] device_plugIn_id Device plugIn ID + * @return Operation result + * @retval DICI_SUCCESS Successful + * @retval DICI_FAIL Operation failed + * + * @code +DCI_RETURN res = DICI_Destroy(1); + * @endcode + */ +DCI_RETURN DCI_Destroy(int device_plugIn_id); + +#endif /* EXT_DCI_H_ */ diff --git a/framework/include/Device/EXT_DCI_Errors.h b/framework/include/Device/EXT_DCI_Errors.h new file mode 100755 index 0000000..03859b3 --- /dev/null +++ b/framework/include/Device/EXT_DCI_Errors.h @@ -0,0 +1,55 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Seokgil Kang + */ + +#ifndef EXT_DCI_ERRORS_H_ +#define EXT_DCI_ERRORS_H_ + +/** + * @file EXT_DCI_Errors.h + * @brief Defines DCI errors + */ + +/** + * @brief Enumerations for the DCI errors + */ +typedef enum { + DCI_SUCCESS = 1, + DCI_FAIL = -1, + + DCI_NOT_EXIST_DEVINFO = -2, + DCI_DEVINFO_VALUE_IS_NULL = -3, +} DCI_RETURN; + +#endif /* EXT_DCI_ERRORS_H_ */ diff --git a/framework/include/EngineController/engine_controller.h b/framework/include/EngineController/engine_controller.h new file mode 100644 index 0000000..816cc04 --- /dev/null +++ b/framework/include/EngineController/engine_controller.h @@ -0,0 +1,132 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Wook Choi + */ + +#ifndef ENGINE_CONTROLLER_H_ +#define ENGINE_CONTROLLER_H_ + +#include "engine_controller_define.h" +#include "task_spec.h" +#include "queuing_rule_spec.h" + +/** + * @file engine_controller.h + * @brief Provides APIs to support task registration and request + */ + +/** + * @brief Callback function which is called when task is finsihed + * @param[in] task_error Result of the watching task + * @param[in] out_param_cnt Count of out parameter of the watching task + * @param[in] out_param_array Array of parameter values of the watching task + * @param[in] usr_data User defined data + */ +typedef void (*task_finish_callback_func) (task_error_t task_error, ec_uint out_param_cnt, param_t **out_param_array, ec_pointer usr_data); + +/** + * @brief Callback function which is called when queuing rule spec registration done + * @param[in] ec_error Result of the registration + * @param[in] registered_id ID of the registered queuing rule spec + * @param[in] usr_data User defined data + */ +typedef void (*register_finish_callback_func) (engine_controller_error_t ec_error, ec_uint registered_id, ec_pointer usr_data); + +/* external interfaces */ + +/** + * @brief Registers user created task spec + * @param[in] task_spec_id User defined task spec ID + * @param[in] task_spec_name User defined task spec ID + * @param[in] pTask_spec User created task spec in task_stpec_t type + * @param[in] cal_func ID calculation func + */ +void engine_controller_register_task_spec(ec_uint task_spec_id, ec_char *task_spec_name, task_spec_t *pTask_spec, calculate_identifier_func cal_func); + +/** + * @brief Registers user created asychronousqueuing rule spec + * @param[in] pSpec User created queuing rule spec to register + * @param[in] finish_callback Callback function to be called on registration done + * @param[in] usr_data User data to pass to the callback function + */ +void engine_controller_async_register_queuing_rule_spec(queuing_rule_spec_t *pSpec, register_finish_callback_func finish_callback, ec_pointer usr_data); + +/** + * @brief Registers user created sychronous queuing rule spec + * @param[in] pSpec User created queuing rule spec to register + * @param[in] ec_error Result of the registration + * @param[in] registered_id ID issued as a result of the registration + */ +void engine_controller_sync_register_queuing_rule_spec(queuing_rule_spec_t *pSpec, engine_controller_error_t *ec_error, ec_uint *registered_id); + +/** + * @brief Requests task asynchronously, using task spec/param info and etc + * @param[in] task_spec_id User defined task spec ID + * @param[in] identifier User defined task identifier + * @param[in] cnt_in_param Count of input parameters + * @param[in] in_param_index_array Array containing param index + * @param[in] in_param_value_type_array Array containing param value type + * @param[in] in_param_value_array Array containing param value + * @param[in] task_finish_callback Task finish callback + * @param[in] simple_task_finish_callback_usr_data User data passed to finish callback + * @param[out] request_id Task request ID which Engine Controller issues + */ +void engine_controller_async_request_task(ec_uint task_spec_id, ec_uint identifier, ec_int cnt_in_param, ec_int *in_param_index_array, ECValueType * in_param_value_type_array, ec_pointer * in_param_value_array, task_finish_callback_func task_finish_callback, ec_pointer simple_task_finish_callback_usr_data, ec_int *request_id); + +/** + * @brief + * @param[in] task_spec_id User defined task spec ID + * @param[in] identifier User defined task identifier + * @param[in] cnt_in_param Count of input parameters + * @param[in] in_param_index_array Array containing param index + * @param[in] in_param_value_type_array Array containing param value type + * @param[in] in_param_value_array Array containing param value + * @param[out] request_id Task request ID which Engine Controller issues + * @param[out] task_error Result of the task + * @param[out] out_param_cnt Count of output parameter of the task + * @param[out] out_param_array param_t type of array containing output parameter of the task + */ +void engine_controller_sync_request_task(ec_uint task_spec_id, ec_uint identifier, ec_int cnt_in_param, ec_int *in_param_index_array, ECValueType * in_param_value_type_array, ec_pointer * in_param_value_array, ec_int *request_id, task_error_t * task_error, ec_uint *out_param_cnt, param_t ***out_param_array); + +/** + * @brief Cancel task which has given request ID + * @param[in] request_id_to_cancel request ID of task to cancel + */ +void engine_controller_cancel_task(ec_int request_id_to_cancel); + +/** + * @brief Cancels all running task + */ +void engine_controller_cancel_all_task(); + +#endif /* ENGINE_CONTROLLER_H_ */ diff --git a/framework/include/EngineController/engine_controller_define.h b/framework/include/EngineController/engine_controller_define.h new file mode 100644 index 0000000..adc56cc --- /dev/null +++ b/framework/include/EngineController/engine_controller_define.h @@ -0,0 +1,107 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Wook Choi + */ + +#ifndef ENGINE_CONTROLLER_DEFINE_H_ +#define ENGINE_CONTROLLER_DEFINE_H_ + +#include "fundamental_type.h" +#include "task_error.h" + +/** + * @file engine_controller_define.h + * @brief Provides definitaion of result enum and data type enum + */ + +/** + * @brief Enumeration for type of value used in Engine Controller + */ +typedef enum ECValueType_e ECValueType; +enum ECValueType_e { + EC_VALUE_TYPE_UNKNOWN = 0, /**< Unknown type */ + EC_VALUE_TYPE_BOOLEAN, /**< boolean type */ + EC_VALUE_TYPE_CHAR, /**< char type */ + EC_VALUE_TYPE_UCHAR, /**< unsigned char type */ + EC_VALUE_TYPE_INT, /**< integer type */ + EC_VALUE_TYPE_UINT, /**< unsigned integer type */ + EC_VALUE_TYPE_FLOAT, /**< float type */ + EC_VALUE_TYPE_DOUBLE, /**< double type */ + EC_VALUE_TYPE_STRUCT /**< structure type */ +}; + +/** + * @brief Callback function which calculates ID + * @param[in] data Data to use for calculation + * @return Calculated ID in unsigned integer type + */ +typedef ec_uint (*calculate_identifier_func) (ec_pointer data); + +/** + * @brief Enumeration for type of error used in Engine Controller + */ +typedef enum engine_controller_error_e engine_controller_error_t; +enum engine_controller_error_e { + ENGINE_CONTROLLER_OK = 0, /**< OK, no error */ + ENGINE_CONTROLLER_UNKNOWN_ERROR, /**< Unknown error */ + + ENGINE_CONTROLLER_INVALID_PARAMETER, /**< When invalid parameters are used */ + + ENGINE_CONTROLLER_OUT_OF_MEMORY, /**< When system gets out of memory */ + ENGINE_CONTROLLER_TASK_PARAMETERS_NOT_CONNECTABLE, /**< When function parameters are not match each other so not connectable */ + ENGINE_CONTROLLER_INVALID_TASK, /**< When invalid task requested */ + + ENGINE_CONTROLLER_INVALID_CHILD_TASK_INDEX, /**< When child task's index is wrong */ + ENGINE_CONTROLLER_INVALID_PARAM_INDEX = 5, /**< When parameter index is wrong*/ + + ENGINE_CONTROLLER_MUST_USE_CONTAINER_TASK, /**< When 'simple' or 'dynamic container' task is used instead of 'dynamic' task */ + ENGINE_CONTROLLER_MUST_USE_DYNAMIC_CONTAINER_TASK, /**< When 'simple' or 'container' task is used instead of dynamic container task */ + + ENGINE_CONTROLLER_CANNOT_FIND_FROM_TASK, /**< When fail to get parameter from task */ + ENGINE_CONTROLLER_CANNOT_FIND_TO_TASK, /**< When fail to set parameter to task */ + ENGINE_CONTROLLER_CANNOT_FIND_FROM_PARAM = 10, /**< When fail to get value from parameter */ + ENGINE_CONTROLLER_CANNOT_FIND_TO_PARAM, /**< When fail to set parameter to parameter */ + + ENGINE_CONTROLLER_INVALID_CHILD_PATH, /**< When queuing rule related child has wrong path */ + ENGINE_CONTROLLER_DUPLICATE_CHILD_PATH, /**< When queuing rule related child has duplicated path */ + + ENGINE_CONTROLLER_OUT_OF_FREE_ID, /**< When there is no free ID to issue */ + + ENGINE_CONTROLLER_DUPLICATE_QUEUING_RULE_SPEC = 15, /**< When trying to register same queuing rule spec */ + + ENGINE_CONTROLLER_DUPLICATE_PROGRESS_BLOCKING_ENTITY, /**< When trying to registe same blocking entitiy in a queuing rule spec */ + + ENGINE_CONTROLLER_DUPLICATE_DATA_FLOW_EDGE /**< When trying to set same data flow edge */ +}; + +#endif /* ENGINE_CONTROLLER_DEFINE_H_ */ diff --git a/framework/include/EngineController/engine_controller_internal.h b/framework/include/EngineController/engine_controller_internal.h new file mode 100644 index 0000000..52ff1f5 --- /dev/null +++ b/framework/include/EngineController/engine_controller_internal.h @@ -0,0 +1,85 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Wook Choi + */ + +#ifndef ENGINE_CONTROLLER_INTERNAL_H_ +#define ENGINE_CONTROLLER_INTERNAL_H_ + +#include +#include +#include "Utility/fw_async_queue.h" +#include "thread_pool.h" +#include "task_info_pool.h" +#include "queuing_rule_spec_pool.h" +#include "engine_controller_message.h" +#include "task_message.h" +#include "task_pool.h" + +typedef struct engine_controller_s engine_controller_t; +struct engine_controller_s { + fw_async_queue_t *pQueue; /* receive operation_message */ + task_pool_t *pTask_pool; /* managing root tasks */ + queuing_rule_spec_pool_t *pQueuing_rule_spec_pool; + + pthread_t thread_id; + thread_pool_t *pThread_pool; +}; + +engine_controller_t *alloc_engine_controller(ec_uint max_thread_count); +void free_engine_controller(engine_controller_t *pEngine_controller); +void run_engine_controller(engine_controller_t *pEngine_controller); + +typedef struct engine_controller_receiver_s engine_controller_receiver_t; +struct engine_controller_receiver_s { + /* msg id management */ + ec_int next_msg_id; + + fw_async_queue_t *pQueue; /* receive message */ + pthread_t thread_id; + task_info_pool_t *pTask_info_pool; + queuing_rule_spec_pool_t *pQueuing_rule_spec_pool; + engine_controller_t *pEngine_controller; +}; + +engine_controller_receiver_t *alloc_engine_controller_receiver(engine_controller_t *pEngine_controller); +void free_engine_controller_receiver(engine_controller_receiver_t *pEngine_controller_receiver); +void run_engine_controller_receiver(engine_controller_receiver_t *pEngine_controller_receiver); + +void send_msg_to_engine_controller_receiver(engine_controller_msg_head_t *msg); +void send_msg_to_engine_controller(task_message_t *pTask_msg); +void send_msg_to_engine_controller_with_compare_priority(task_message_t *pTask_msg, compare_task_msg_priority_func ctmp_func, ec_pointer user_data); + +bool init_engine_controller(unsigned int max_thread_count); + +#endif /* ENGINE_CONTROLLER_INTERNAL_H_ */ diff --git a/framework/include/EngineController/engine_controller_message.h b/framework/include/EngineController/engine_controller_message.h new file mode 100644 index 0000000..e8f74b0 --- /dev/null +++ b/framework/include/EngineController/engine_controller_message.h @@ -0,0 +1,142 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Wook Choi + */ + +#ifndef ENGINE_CONTROLLER_MESSAGE_H_ +#define ENGINE_CONTROLLER_MESSAGE_H_ + +#include + +#include "engine_controller_define.h" +#include "engine_controller.h" +#include "param_value.h" +#include "param_spec.h" +#include "task_spec.h" + +typedef enum engine_controller_msg_type_e { + ENGINE_CONTROLLER_UNKNOWN_MSG_TYPE = 0, + ENGINE_CONTROLLER_REGISTER_MSG_TYPE, + ENGINE_CONTROLLER_UNREGISTER_MSG_TYPE, + ENGINE_CONTROLLER_REGISTER_QUEUING_RULE_SPEC_MSG_TYPE, + ENGINE_CONTROLLER_REQUEST_MSG_TYPE, + ENGINE_CONTROLLER_CANCEL_MSG_TYPE, + ENGINE_CONTROLLER_CANCEL_ALL_MSG_TYPE, +} engine_controller_msg_type_t; + +typedef struct engine_controller_msg_head_s engine_controller_msg_head_t; +struct engine_controller_msg_head_s { + engine_controller_msg_type_t msg_type; + ec_int msg_id; +}; + +typedef struct engine_controller_request_msg_s engine_controller_request_msg_t; +struct engine_controller_request_msg_s { + engine_controller_msg_head_t msg_head; + + ec_uint task_spec_id; + + /* input data */ + ec_uint identifier; + ec_int cnt_in_param; + ec_int *in_param_index_array; + param_value_t *in_param_value_array; + + /* aynchronous finish callback */ + task_finish_callback_func task_finish_callback; + ec_pointer simple_task_finish_callback_usr_data; +}; + +typedef struct engine_controller_cancel_all_msg_s engine_controller_cancel_all_msg_t; +struct engine_controller_cancel_all_msg_s { + engine_controller_msg_head_t msg_head; +}; + +typedef struct engine_controller_cancel_msg_s engine_controller_cancel_msg_t; +struct engine_controller_cancel_msg_s { + engine_controller_msg_head_t msg_head; + + ec_uint request_msg_id_to_cancel; +}; + +typedef struct engine_controller_register_msg_s engine_controller_register_msg_t; +struct engine_controller_register_msg_s { + engine_controller_msg_head_t msg_head; + + ec_uint task_spec_id; + task_spec_t *pTask_spec; + calculate_identifier_func id_calc_func; +}; + +typedef struct engine_controller_register_queuing_rule_spec_msg_s engine_controller_register_queuing_rule_spec_msg_t; +struct engine_controller_register_queuing_rule_spec_msg_s { + engine_controller_msg_head_t msg_head; + + queuing_rule_spec_t *pSpec; + + /* aynchronous finish callback */ + register_finish_callback_func register_finish_callback; + ec_pointer usr_data; +}; + +void engine_controller_msg_set_msg_head(engine_controller_msg_head_t *pMsg_head, engine_controller_msg_type_t msg_type, ec_uint msg_id); + +engine_controller_register_msg_t *engine_controller_msg_create_register_msg(ec_uint task_spec_id, task_spec_t *pTask_spec, calculate_identifier_func id_calc_func); + +void engine_controller_msg_free_register_msg(engine_controller_register_msg_t *pRegister_msg); + +engine_controller_register_queuing_rule_spec_msg_t *engine_controller_msg_create_register_queuing_rule_spec_msg(queuing_rule_spec_t *pSpec, register_finish_callback_func register_finish_callback, ec_pointer usr_data); + +void engine_controller_msg_free_register_queuing_rule_spec_msg(engine_controller_register_queuing_rule_spec_msg_t *pMsg); + +/* TODO : unregister msg */ + +engine_controller_request_msg_t *engine_controller_msg_create_request_msg(ec_uint task_spec_id, ec_uint identifier, ec_int cnt_in_param, ec_int *in_param_index_array, ECValueType * in_param_value_type_array, ec_pointer * in_param_value_array, task_finish_callback_func task_finish_callback, ec_pointer simple_task_finish_callback_usr_data); + +void engine_controller_msg_free_request_msg(engine_controller_request_msg_t *pMsg); + +engine_controller_cancel_all_msg_t *engine_controller_msg_create_cancel_all_msg(); +void engine_controller_msg_free_cancel_all_msg(engine_controller_cancel_all_msg_t *pCancel_all_msg); + +engine_controller_cancel_msg_t *engine_controller_msg_create_cancel_msg(ec_uint request_msg_id_to_cancel); +void engine_controller_msg_free_cancel_msg(engine_controller_cancel_msg_t *pCancel_msg); + +ec_boolean engine_controller_msg_check_same_msg_type(engine_controller_msg_head_t *pHead, engine_controller_msg_type_t msg_type); +ec_boolean engine_controller_msg_is_register_msg(engine_controller_msg_head_t *pHead); +ec_boolean engine_controller_msg_is_unregister_msg(engine_controller_msg_head_t *pHead); +ec_boolean engine_controller_msg_is_register_queuing_rule_spec_msg(engine_controller_msg_head_t *pHead); +ec_boolean engine_controller_msg_is_request_msg(engine_controller_msg_head_t *pHead); +ec_boolean engine_controller_msg_is_cancel_msg(engine_controller_msg_head_t *pHead); +ec_boolean engine_controller_msg_is_cancel_all_msg(engine_controller_msg_head_t *pHead); + +#endif /* ENGINE_CONTROLLER_MESSAGE_H_ */ diff --git a/framework/include/EngineController/fundamental_type.h b/framework/include/EngineController/fundamental_type.h new file mode 100644 index 0000000..f4d5ddd --- /dev/null +++ b/framework/include/EngineController/fundamental_type.h @@ -0,0 +1,151 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Wook Choi + */ + +#ifndef FUNDAMENTAL_TYPE_H_ +#define FUNDAMENTAL_TYPE_H_ + +#include + +/** + * @file fundamental_type.h + * @brief Provides data type definition internally used in Engine Controller + */ + +/** + * @brief Definition of internal char type used in Engine Controller + */ +typedef char ec_char; + +/** + * @brief Definition of internal short type used in Engine Controller + */ +typedef short ec_short; + +/** + * @brief Definition of internal long type used in Engine Controller + */ +typedef long ec_long; + +/** + * @brief Definition of internal int type used in Engine Controller + */ +typedef int ec_int; + +/** + * @brief Definition of internal boolean type used in Engine Controller + */ +typedef ec_int ec_boolean; + +/** + * @brief Definition of internal unsigned char type used in Engine Controller + */ +typedef unsigned char ec_uchar; + +/** + * @brief Definition of internal unsigned short type used in Engine Controller + */ +typedef unsigned short ec_ushort; + +/** + * @brief Definition of internal unsigned long type used in Engine Controller + */ +typedef unsigned long ec_ulong; + +/** + * @brief Definition of internal unsigned int type used in Engine Controller + */ +typedef unsigned int ec_uint; + +/** + * @brief Definition of internal float type used in Engine Controller + */ +typedef float ec_float; + +/** + * @brief Definition of internal double type used in Engine Controller + */ +typedef double ec_double; + +/** + * @brief Definition of internal void pointer type used in Engine Controller + */ +typedef void *ec_pointer; + +/** + * @brief Definition of internal const void pointer type used in Engine Controller + */ +typedef const void *ec_constpointer; + +/** + * @brief Definition of internal int8 type used in Engine Controller + */ +typedef signed char ec_int8; + +/** + * @brief Definition of internal unsigned int8 type used in Engine Controller + */ +typedef unsigned char ec_uint8; + +/** + * @brief Definition of internal int16 type used in Engine Controller + */ +typedef signed short ec_int16; + +/** + * @brief Definition of internal unsigned int16 type used in Engine Controller + */ +typedef unsigned short ec_uint16; + +/** + * @brief Definition of internal int32 type used in Engine Controller + */ +typedef signed int ec_int32; + +/** + * @brief Definition of internal unsigned int32 type used in Engine Controller + */ +typedef unsigned int ec_uint32; + +/** + * @brief Definition of internal int64 type used in Engine Controller + */ +typedef signed long long ec_int64; + +/** + * @brief Definition of internal unsigned int64 type used in Engine Controller + */ +typedef unsigned long long ec_uint64; + +#endif /* FUNDAMENTAL_TYPE_H_ */ diff --git a/framework/include/EngineController/graph_edge_pool.h b/framework/include/EngineController/graph_edge_pool.h new file mode 100644 index 0000000..9e3b633 --- /dev/null +++ b/framework/include/EngineController/graph_edge_pool.h @@ -0,0 +1,53 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Wook Choi + */ + +#ifndef GRAPH_EDGE_POOL_H_ +#define GRAPH_EDGE_POOL_H_ + +#include +#include "fundamental_type.h" + +typedef struct graph_edge_pool_s graph_edge_pool_t; + +graph_edge_pool_t *graph_edge_pool_new(); +void graph_edge_pool_free(graph_edge_pool_t *pPool); + +/* return add success or not */ +/* if already exist edge added, then return false */ +ec_boolean graph_edge_pool_add_edge(graph_edge_pool_t *pPool, ec_constpointer from_node, ec_constpointer to_node); + +GList *graph_edge_pool_query_to_node_list(graph_edge_pool_t *pPool, ec_constpointer from_node); + +#endif /* GRAPH_EDGE_POOL_H_ */ diff --git a/framework/include/EngineController/hash_set.h b/framework/include/EngineController/hash_set.h new file mode 100644 index 0000000..a15aa93 --- /dev/null +++ b/framework/include/EngineController/hash_set.h @@ -0,0 +1,56 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Wook Choi + */ + +#ifndef HASH_SET_H_ +#define HASH_SET_H_ + +#include "fundamental_type.h" +#include + +typedef struct hash_set_s hash_set_t; +struct hash_set_s { + GHashTable *pHashTable; +}; + +hash_set_t *hash_set_create(); +void hash_set_free(hash_set_t *pHash_set); + +/* return success */ +/* when same element added, it will do nothing and return true */ +ec_boolean hash_set_add(hash_set_t *pHash_set, ec_constpointer pElement); + +GList *hash_set_get_element_list(hash_set_t *pHash_set); + +#endif /* HASH_SET_H_ */ diff --git a/framework/include/EngineController/param.h b/framework/include/EngineController/param.h new file mode 100644 index 0000000..454b54a --- /dev/null +++ b/framework/include/EngineController/param.h @@ -0,0 +1,74 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Wook Choi + */ + +#ifndef PARAM_H_ +#define PARAM_H_ + +#include "param_value.h" +#include "param_spec.h" + +/** + * @file param.h + * @brief Provides alloc and free of param structure + */ + +/** + * @brief Structure for parameter which contains parameter information such as spec and value + */ +typedef struct param_s param_t; +struct param_s { + ec_uint read_ref_count; /**< Reference count for read */ + ec_uint write_ref_count; /**< Reference count for write */ + param_spec *pParam_spec; /**< Parameter spec */ + param_value_t param_value; /**< Parameter value */ +}; + +/** + * @brief Alocates and returns param_t type of structure using given param spec and param value + * @param[in] read_ref_count Reference count to set for read + * @param[in] write_ref_count Reference count to set for write + * @param[in] pParam_spec param spec to use + * @param[in] pParam_value param value to push in + * @return Newly alloced pointer of param_t type of structure + */ +param_t *param_alloc_param(ec_uint read_ref_count, ec_uint write_ref_count, param_spec *pParam_spec, param_value_t *pParam_value); + +/** + * @brief Provides free operation for param_t type of structure + * @param[in] pParam param_t type of structure to free + */ +void param_free_param(param_t *pParam); + +#endif /* PARAM_H_ */ diff --git a/framework/include/EngineController/param_spec.h b/framework/include/EngineController/param_spec.h new file mode 100644 index 0000000..9f219f9 --- /dev/null +++ b/framework/include/EngineController/param_spec.h @@ -0,0 +1,251 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Wook Choi + */ + +#ifndef PARAM_SPEC_H_ +#define PARAM_SPEC_H_ + +#include "fundamental_type.h" +#include "engine_controller_define.h" + +/** + * @file papram_spec.h + * @brief Provides parameter spec creation for various data type + */ + +/** + * @brief Callback function which copies parameter data in structure type + * @param[in] pStruct Parameter data in structure type to copy from + * @return Pointer of newly copied structureà + */ +typedef ec_pointer(*copy_struct_func_callback) (ec_pointer pStruct); + +/** + * @brief Callback function which frees parameter data in structure type + * @param[in] pStruct Parameter data in structure type to free + */ +typedef void (*free_struct_func_callback) (ec_pointer pStruct); + +/** + * @brief Callback function which validates parameter data in structure type + * @param[in] pStruct Parameter data in structure type to validate + * @return 1 on validation success case, otherwise 0 + */ +typedef ec_boolean(*validate_struct_func_callback) (ec_pointer pStruct, ec_pointer usr_data); + +/** + * @brief Enumerations of flag which indicates sort of parameter + */ +typedef enum ECParamFlags_e ECParamFlags; +enum ECParamFlags_e { + EC_PARAM_FLAG_DEFAULT = 0, /**< Default type */ + EC_PARAM_FLAG_INPUT = 1, /**< Input type */ + EC_PARAM_FLAG_OUTPUT = 2, /**< Output type */ + EC_PARAM_FLAG_INPUT_VALIDATE_ON = 4, /**< Input-validate type */ + EC_PARAM_FLAG_OUTPUT_VALIDATE_ON = 8, /**< Output-validate type */ + EC_PARAM_FLAG_INPUT_DEFAULT_VALUE_ON = 16 /**< Intput-default-value type */ +}; + +/** + * @brief Structure of parameter spec which contains function parameter spec + */ +typedef struct _param_spec param_spec; + +/** + * @brief Increases reference count of parameter spec + * @param[in] pParam_spec Pointer of parameter spec to increase ref count + * @return Pointer of parameter spec itself on success, otherwise NULL + */ +param_spec *param_spec_ref(param_spec *pParam_spec); + +/** + * @brief Decreases reference count of parameter spec + * @param[in] pParam_spec Pointer of parameter spec to decrease ref count + */ +void param_spec_unref(param_spec *pParam_spec); + +/** + * @brief Allocs and returns boolean type of parameter spec + * @param[in] name Name of parameter which user defined + * @param[in] is_input On if this parameter to be used as input + * @param[in] is_output On if this parameter to be used as output + * @param[in] input_default_on On if this parameter to contain default value + * @param[in] input_default_value Default value for this parameter to contain + * @return Pointer of parameter spec which defined as ordered type + */ +param_spec *param_spec_boolean(const ec_char *name, ec_boolean is_input, ec_boolean is_output, ec_boolean input_default_on, ec_boolean input_default_value); + +/** + * @brief Allocs and returns char type of parameter spec + * @param[in] name Name of parameter which user defined + * @param[in] is_input On if this parameter to be used as input + * @param[in] is_output On if this parameter to be used as output + * @param[in] input_validate_on On if want to perform input parameter value validation + * @param[in] input_minimum Minimum value of valid input parameter value range + * @param[in] input_maximum Maximum value of valid input parameter value range + * @param[in] input_default_on On if this parameter to contain default value + * @param[in] input_default_value Default value for this parameter to contain + * @param[in] output_validate_on On if want to perform output parameter value validation + * @param[in] output_minimum Minimum value of valid output parameter value range + * @param[in] output_maximum Maximum value of valid output parameter value range + * @return Pointer of parameter spec which defined as ordered type + */ +param_spec *param_spec_char(const ec_char *name, ec_boolean is_input, ec_boolean is_output, ec_boolean input_validate_on, ec_int8 input_minimum, ec_int8 input_maximum, ec_boolean input_default_on, ec_int8 input_default_value, ec_boolean output_validate_on, ec_int8 output_minimum, ec_int8 output_maximum); + +/** + * @brief Allocs and returns unsigned char type of parameter spec + * @param[in] name Name of parameter which user defined + * @param[in] is_input On if this parameter to be used as input + * @param[in] is_output On if this parameter to be used as output + * @param[in] input_validate_on On if want to perform input parameter value validation + * @param[in] input_minimum Minimum value of valid input parameter value range + * @param[in] input_maximum Maximum value of valid input parameter value range + * @param[in] input_default_on On if this parameter to contain default value + * @param[in] input_default_value Default value for this parameter to contain + * @param[in] output_validate_on On if want to perform output parameter value validation + * @param[in] output_minimum Minimum value of valid output parameter value range + * @param[in] output_maximum Maximum value of valid output parameter value range + * @return Pointer of parameter spec which defined as ordered type + */ +param_spec *param_spec_uchar(const ec_char *name, ec_boolean is_input, ec_boolean is_output, ec_boolean input_validate_on, ec_uint8 input_minimum, ec_uint8 input_maximum, ec_boolean input_default_on, ec_uint8 input_default_value, ec_boolean output_validate_on, ec_uint8 output_minimum, ec_uint8 output_maximum); + +/** + * @brief Allocs and returns int type of parameter spec + * @param[in] name Name of parameter which user defined + * @param[in] is_input On if this parameter to be used as input + * @param[in] is_output On if this parameter to be used as output + * @param[in] input_validate_on On if want to perform input parameter value validation + * @param[in] input_minimum Minimum value of valid input parameter value range + * @param[in] input_maximum Maximum value of valid input parameter value range + * @param[in] input_default_on On if this parameter to contain default value + * @param[in] input_default_value Default value for this parameter to contain + * @param[in] output_validate_on On if want to perform output parameter value validation + * @param[in] output_minimum Minimum value of valid output parameter value range + * @param[in] output_maximum Maximum value of valid output parameter value range + * @return Pointer of parameter spec which defined as ordered type + */ +param_spec *param_spec_int(const ec_char *name, ec_boolean is_input, ec_boolean is_output, ec_boolean input_validate_on, ec_int input_minimum, ec_int input_maximum, ec_boolean input_default_on, ec_int input_default_value, ec_boolean output_validate_on, ec_int output_minimum, ec_int output_maximum); + +/** + * @brief Allocs and returns unsigned int type of parameter spec + * @param[in] name Name of parameter which user defined + * @param[in] is_input On if this parameter to be used as input + * @param[in] is_output On if this parameter to be used as output + * @param[in] input_validate_on On if want to perform input parameter value validation + * @param[in] input_minimum Minimum value of valid input parameter value range + * @param[in] input_maximum Maximum value of valid input parameter value range + * @param[in] input_default_on On if this parameter to contain default value + * @param[in] input_default_value Default value for this parameter to contain + * @param[in] output_validate_on On if want to perform output parameter value validation + * @param[in] output_minimum Minimum value of valid output parameter value range + * @param[in] output_maximum Maximum value of valid output parameter value range + * @return Pointer of parameter spec which defined as ordered type + */ +param_spec *param_spec_uint(const ec_char *name, ec_boolean is_input, ec_boolean is_output, ec_boolean input_validate_on, ec_uint input_minimum, ec_uint input_maximum, ec_boolean input_default_on, ec_uint input_default_value, ec_boolean output_validate_on, ec_uint output_minimum, ec_uint output_maximum); + +/** + * @brief Allocs and returns float type of parameter spec + * @param[in] name Name of parameter which user defined + * @param[in] is_input On if this parameter to be used as input + * @param[in] is_output On if this parameter to be used as output + * @param[in] input_validate_on On if want to perform input parameter value validation + * @param[in] input_minimum Minimum value of valid input parameter value range + * @param[in] input_maximum Maximum value of valid input parameter value range + * @param[in] input_default_on On if this parameter to contain default value + * @param[in] input_default_value Default value for this parameter to contain + * @param[in] output_validate_on On if want to perform output parameter value validation + * @param[in] output_minimum Minimum value of valid output parameter value range + * @param[in] output_maximum Maximum value of valid output parameter value range + * @return Pointer of parameter spec which defined as ordered type + */ +param_spec *param_spec_float(const ec_char *name, ec_boolean is_input, ec_boolean is_output, ec_boolean input_validate_on, ec_float input_minimum, ec_float input_maximum, ec_boolean input_default_on, ec_float input_default_value, ec_boolean output_validate_on, ec_float output_minimum, ec_float output_maximum); + +/** + * @brief Allocs and returns double type of parameter spec + * @param[in] name Name of parameter which user defined + * @param[in] is_input On if this parameter to be used as input + * @param[in] is_output On if this parameter to be used as output + * @param[in] input_validate_on On if want to perform input parameter value validation + * @param[in] input_minimum Minimum value of valid input parameter value range + * @param[in] input_maximum Maximum value of valid input parameter value range + * @param[in] input_default_on On if this parameter to contain default value + * @param[in] input_default_value Default value for this parameter to contain + * @param[in] output_validate_on On if want to perform output parameter value validation + * @param[in] output_minimum Minimum value of valid output parameter value range + * @param[in] output_maximum Maximum value of valid output parameter value range + * @return Pointer of parameter spec which defined as ordered type + */ +param_spec *param_spec_double(const ec_char *name, ec_boolean is_input, ec_boolean is_output, ec_boolean input_validate_on, ec_double input_minimum, ec_double input_maximum, ec_boolean input_default_on, ec_double input_default_value, ec_boolean output_validate_on, ec_double output_minimum, ec_double output_maximum); + +/** + * @brief Allocs and returns structure(Pointer) type of parameter spec + * @param[in] name Name of parameter which user defined + * @param[in] copy_func Function which can make copy of this structure type of parameter + * @param[in] free_func Function which can free this structure type of parameter + * @param[in] is_input On if this parameter to be used as input + * @param[in] is_output On if this parameter to be used as output + * @param[in] input_validate_on On if want to perform input parameter value validation + * @param[in] in_val_func Function which can validate this structure type of input parameter + * @param[in] input_default_on On if this parameter to contain default value + * @param[in] pDefault_Struct Default value of this structure type of parameter + * @param[in] output_validate_on On if want to perform output parameter value validation + * @param[in] out_val_funcFunction which can validate this structure type of output parameter + * @return Pointer of parameter spec which defined as ordered type + */ +param_spec *param_spec_structure(const ec_char *name, copy_struct_func_callback copy_func, free_struct_func_callback free_func, ec_boolean is_input, ec_boolean is_output, ec_boolean input_validate_on, validate_struct_func_callback in_val_func, ec_boolean input_default_on, ec_pointer pDefault_Struct, ec_boolean output_validate_on, validate_struct_func_callback out_val_func); + +/** + * @brief Provides data type of requested parameter spec + * @param[in] pParam_spec Parameter spec to get data type from + * @return ECValueType Type of enumeration value + * @retval EC_VALUE_TYPE_UNKNOWN Unknown type + * @retval EC_VALUE_TYPE_BOOLEAN Boolean type + * @retval EC_VALUE_TYPE_CHAR Char type + * @retval EC_VALUE_TYPE_UCHAR Unsigned char type + * @retval EC_VALUE_TYPE_INT Integer type + * @retval EC_VALUE_TYPE_UINT Unsigned integer type + * @retval EC_VALUE_TYPE_FLOAT Float type + * @retval EC_VALUE_TYPE_DOUBLE Double type + * @retval EC_VALUE_TYPE_STRUCT Structure(Pointer) type + */ +const ECValueType param_spec_get_value_type(param_spec *pParam_spec); + +/** + * @brief Provides name of requested parameter spec + * @param[in] pParam_spec Parameter spec to get data type from + * @return Name of parameter spec which user assigned on spec creation + */ +const ec_char *param_spec_get_name(param_spec *pParam_spec); + +#endif /* PARAM_SPEC_H_ */ diff --git a/framework/include/EngineController/param_spec_internal.h b/framework/include/EngineController/param_spec_internal.h new file mode 100644 index 0000000..5a6593f --- /dev/null +++ b/framework/include/EngineController/param_spec_internal.h @@ -0,0 +1,125 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Wook Choi + */ + +#ifndef PARAM_SPEC_INTERNAL_H_ +#define PARAM_SPEC_INTERNAL_H_ + +#include "param_value.h" + +typedef ec_boolean(*char_validate_func) (ec_int8 value, ec_int8 minimum, ec_int8 maximum); +typedef ec_boolean(*uchar_validate_func) (ec_uint8 value, ec_uint8 minimum, ec_uint8 maximum); +typedef ec_boolean(*int_validate_func) (ec_int value, ec_int minimum, ec_int maximum); +typedef ec_boolean(*uint_validate_func) (ec_uint value, ec_uint minimum, ec_uint maximum); +typedef ec_boolean(*float_validate_func) (ec_float value, ec_float minimum, ec_float maximum); +typedef ec_boolean(*double_validate_func) (ec_double value, ec_double minimum, ec_double maximum); + +typedef struct _param_spec_char_validate param_spec_char_validate; +typedef struct _param_spec_uchar_validate param_spec_uchar_validate; +typedef struct _param_spec_int_validate param_spec_int_validate; +typedef struct _param_spec_uint_validate param_spec_uint_validate; +typedef struct _param_spec_float_validate param_spec_float_validate; +typedef struct _param_spec_double_validate param_spec_double_validate; + +struct _param_spec_char_validate { + ec_int8 minimum; + ec_int8 maximum; + char_validate_func valid_func; +}; + +struct _param_spec_uchar_validate { + ec_uint8 minimum; + ec_uint8 maximum; + uchar_validate_func valid_func; +}; + +struct _param_spec_int_validate { + ec_int minimum; + ec_int maximum; + int_validate_func valid_func; +}; + +struct _param_spec_uint_validate { + ec_uint minimum; + ec_uint maximum; + uint_validate_func valid_func; +}; + +struct _param_spec_float_validate { + ec_float minimum; + ec_float maximum; + float_validate_func valid_func; +}; + +struct _param_spec_double_validate { + ec_double minimum; + ec_double maximum; + double_validate_func valid_func; +}; + +struct _param_spec_struct_validate { + +}; + +typedef union { + param_spec_char_validate *char_validate; + param_spec_uchar_validate *uchar_validate; + param_spec_int_validate *int_validate; + param_spec_uint_validate *uint_validate; + param_spec_float_validate *float_validate; + param_spec_double_validate *double_validate; + validate_struct_func_callback struct_validate_func; +} private_validate; + +struct _param_spec { + ec_int ref_count; + ECValueType value_type; + ec_char *name; + ECParamFlags flags; + + param_value_t default_value; + private_validate input_validate; + private_validate output_validate; + + copy_struct_func_callback copy_struct_func; + free_struct_func_callback free_struct_func; +}; + +inline ec_boolean is_input_flag_on(ECParamFlags flags); +inline ec_boolean is_output_flag_on(ECParamFlags flags); +inline ec_boolean is_input_validate_on_flag_on(ECParamFlags flags); +inline ec_boolean is_output_validate_on_flag_on(ECParamFlags flags); +inline ec_boolean is_input_default_value_on_flag_on(ECParamFlags flags); + +#endif /* PARAM_SPEC_INTERNAL_H_ */ diff --git a/framework/include/EngineController/param_value.h b/framework/include/EngineController/param_value.h new file mode 100644 index 0000000..417302a --- /dev/null +++ b/framework/include/EngineController/param_value.h @@ -0,0 +1,83 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Wook Choi + */ + +#ifndef PARAM_VALUE_H_ +#define PARAM_VALUE_H_ + +#include "fundamental_type.h" +#include "engine_controller_define.h" + +/** + * @file param_value.h + * @brief Provides set/get operation of parameter value + */ + +/** + * @brief Union for parameter value corresponding to various data type + */ +typedef union { + ec_boolean boolean_value; /**< boolean type */ + ec_char char_value; /**< char type */ + ec_uchar uchar_value; /**< unsigned char type */ + ec_int int_value; /**< int type */ + ec_uint uint_value; /**< unsigned int type */ + ec_float float_value; /**< float type */ + ec_double double_value; /**< double type */ + ec_pointer pointer_value; /**< pointer type */ +} param_value_t; + +/** + * @brief Provides set operation for parameter value + * @param[in] pParam_value param_value_t type of variable to set in + * @param[in] value_type Type of value to set in ECValueType type + * @param[in] pValue Value of parameter to set + */ +void param_value_set_value(param_value_t *pParam_value, ECValueType value_type, ec_constpointer pValue); + +/** + * @brief Provides set operation from existing param_value_t type of variable + * @param[in] pDest_param_value param_value_t type of variable to set value to + * @param[in] pSrc_param_value param_value_t type of variable to get value from + */ +void param_value_set_value_with_other_param_value(param_value_t *pDest_param_value, param_value_t *pSrc_param_value); +/** + * @brief Provides get operation for parameter value + * @param[in] pParam_value param_value_t type of variable to get from + * @param[in] value_type Type of value to get in ECValueType type + * @param[out] pValue Value of requested parameter + */ +void param_value_get_value(param_value_t *pParam_value, ECValueType value_type, ec_pointer pValue); + +#endif /* PARAM_VALUE_H_ */ diff --git a/framework/include/EngineController/queuing_rule_spec.h b/framework/include/EngineController/queuing_rule_spec.h new file mode 100644 index 0000000..a9609d8 --- /dev/null +++ b/framework/include/EngineController/queuing_rule_spec.h @@ -0,0 +1,85 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Wook Choi + */ + +#ifndef QUEUING_RULE_SPEC_H_ +#define QUEUING_RULE_SPEC_H_ + +#include +#include "fundamental_type.h" +#include "engine_controller_define.h" +#include "task_spec.h" + +/** + * @file queuing_rule_spec.h + * @brief Provides queuing rule related operation such as create, add + */ + +/** + * @brief Structure for queuing rule spec which contains queuing-related information + */ +typedef struct queuing_rule_spec_s queuing_rule_spec_t; + +/** + * @brief Initiates and returns queuing_rule_spec_t type of instance + * @param[in] queuing_rule_name User defined name to use as name of rule + * @return Newly allocated instance in queuing_rule_spec_t type + */ +queuing_rule_spec_t *queuing_rule_spec_create_queuing_rule_spec_outline(ec_char *queuing_rule_name); + +/** + * @brief Adds progress blocking element + * @param[in] + * @param[in] + * @param[in] + * @param[in] + * @param[in] ... Iteration of detail information about element in the path from root to blocking element (ec_boolean is_dynamic, ec_int dynamic_case, ec_int child_index) + * @return engine_controller_error_t type of enumeration value + */ +engine_controller_error_t queuing_rule_spec_add_progress_blocking_element(queuing_rule_spec_t *pRule, ec_uint root_task_spec_id, task_spec_t *pRoot_task_spec, ec_uint child_depth, ...); + +/** +* @brief Increases reference count of queuing rule spec +* @param[in] pRule pointer of queuing rule spec to increase ref count +* @return Pointer of queuing rule spec itself on success, otherwise NULL +*/ +queuing_rule_spec_t *queuing_rule_spec_ref(queuing_rule_spec_t *pRule); + +/** +* @brief Decreases reference count of queuing rule spec +* @param[in] pRule pointer of queuing rule spec to decrease ref count +*/ +void queuing_rule_spec_unref(queuing_rule_spec_t *pRule); + +#endif /* QUEUING_RULE_SPEC_H_ */ diff --git a/framework/include/EngineController/queuing_rule_spec_internal.h b/framework/include/EngineController/queuing_rule_spec_internal.h new file mode 100644 index 0000000..b893d70 --- /dev/null +++ b/framework/include/EngineController/queuing_rule_spec_internal.h @@ -0,0 +1,116 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Wook Choi + */ + +#ifndef QUEUING_RULE_SPEC_INTERNAL_H_ +#define QUEUING_RULE_SPEC_INTERNAL_H_ + +#include +#include "queuing_rule_spec.h" + +typedef struct n_ary_tree_node_with_flag_s n_ary_tree_node_with_flag_t; +struct n_ary_tree_node_with_flag_s { + ec_boolean blocking_flag; + + ec_uint tree_level; + ec_boolean is_dynamic_child; + ec_int dynamic_case; + ec_uint child_index; + + n_ary_tree_node_with_flag_t *parent_node; + n_ary_tree_node_with_flag_t *first_child_node; + n_ary_tree_node_with_flag_t *next_sibling_node; + n_ary_tree_node_with_flag_t *prev_sibling_node; +}; + +n_ary_tree_node_with_flag_t *n_ary_tree_node_with_flag_new(ec_boolean blocking_flag, ec_uint tree_level, ec_boolean is_dynamic_child, ec_int dynamic_case, ec_uint child_index); + +void n_ary_tree_node_with_flag_free_1(n_ary_tree_node_with_flag_t *node); +void n_ary_tree_node_with_flag_free_subtree(n_ary_tree_node_with_flag_t *node); + +ec_uint n_ary_tree_node_with_flag_count_subtree_flag_on_number(n_ary_tree_node_with_flag_t *node); + +void n_ary_tree_node_with_flag_set_blocking_flag_on(n_ary_tree_node_with_flag_t *node); +ec_boolean n_ary_tree_node_with_flag_is_blocking_flag_on(n_ary_tree_node_with_flag_t *node); + +ec_boolean n_ary_tree_node_with_flag_has_same_content_without_blocking_flag(n_ary_tree_node_with_flag_t *node, ec_uint tree_level, ec_boolean is_dynamic_child, ec_int dynamic_case, ec_uint child_index); + +n_ary_tree_node_with_flag_t *n_ary_tree_node_with_flag_add_child_node(n_ary_tree_node_with_flag_t *parent_node, ec_boolean blocking_flag, ec_boolean is_dynamic_child, ec_int dynamic_case, ec_uint child_index); + +void n_ary_tree_node_with_flag_link_child_node(n_ary_tree_node_with_flag_t *parent_node, n_ary_tree_node_with_flag_t *child_node); + +void n_ary_tree_node_with_flag_unlink_child_node(n_ary_tree_node_with_flag_t *parent_node, n_ary_tree_node_with_flag_t *child_node); + +n_ary_tree_node_with_flag_t *n_ary_tree_node_with_flag_get_child_node(n_ary_tree_node_with_flag_t *parent_node, ec_boolean is_dynamic_child, ec_int dynamic_case, ec_uint child_index); + +typedef struct progress_blocking_element_set_s progress_blocking_element_set_t; +struct progress_blocking_element_set_s { + ec_uint progress_blocking_element_cnt; + + n_ary_tree_node_with_flag_t *n_ary_tree_with_flag; +}; + +progress_blocking_element_set_t *progress_blocking_element_set_new(); +void progress_blocking_element_set_free(progress_blocking_element_set_t *pSet); +engine_controller_error_t progress_blocking_element_add(progress_blocking_element_set_t *pSet, ec_uint depth, va_list ap); + +typedef struct progress_blocking_entity_s progress_blocking_entity_t; +struct progress_blocking_entity_s { + ec_int ref_count; + + queuing_rule_spec_t *pQueuing_rule_spec; /* mother of blocking entity */ + + ec_uint root_task_spec_id; + progress_blocking_element_set_t *pElement_set; +}; + +progress_blocking_entity_t *progress_blocking_entity_new(ec_uint root_task_spec_id, queuing_rule_spec_t *pQueuing_rule_spec); +void progress_blocking_entity_free(progress_blocking_entity_t *pEntity); +progress_blocking_entity_t *progress_blocking_entity_ref(progress_blocking_entity_t *pEntity); +void progress_blocking_entity_unref(progress_blocking_entity_t *pEntity); + +struct queuing_rule_spec_s { + ec_int ref_count; + + ec_uint id; + ec_char *name; + + ec_uint total_progress_blocking_element_cnt; + GSList *progress_blocking_entity_list; /* containing progress_blocking_entity_t* */ + /* containing progress_blocking_entities related to queuing_rule_spec */ + + GQueue *progress_blocking_queue; +}; + +#endif /* QUEUING_RULE_SPEC_INTERNAL_H_ */ diff --git a/framework/include/EngineController/queuing_rule_spec_pool.h b/framework/include/EngineController/queuing_rule_spec_pool.h new file mode 100644 index 0000000..16548c2 --- /dev/null +++ b/framework/include/EngineController/queuing_rule_spec_pool.h @@ -0,0 +1,65 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Wook Choi + */ + +#ifndef QUEUING_RULE_SPEC_POOL_H_ +#define QUEUING_RULE_SPEC_POOL_H_ + +#include +#include "fundamental_type.h" +#include "engine_controller_define.h" +#include "queuing_rule_spec.h" +#include "task_info_pool.h" +#include "Utility/fw_sequential_id_provider.h" + +typedef struct queuing_rule_spec_pool_s queuing_rule_spec_pool_t; +struct queuing_rule_spec_pool_s { + id_provider_t *pId_provider; + GHashTable *pQueuing_rule_spec_hash; /* key : queuing_rule_spec_id + value : queuing_rule_spec_t* */ + + task_info_pool_t *pTask_info_pool; /* when register queuing_rule_spec to pool, we have to update task_info */ +}; + +queuing_rule_spec_pool_t *queuing_rule_spec_pool_alloc(ec_uint queuing_rule_max_cnt, task_info_pool_t *pTask_info_pool); +void queuing_rule_spec_pool_free(queuing_rule_spec_pool_t *pPool); + +engine_controller_error_t queuing_rule_spec_pool_add_queuing_rule_spec(queuing_rule_spec_pool_t *pPool, queuing_rule_spec_t *pSpec, ec_uint *queuing_rule_id); + +queuing_rule_spec_t *queueing_rule_spec_pool_search_queuing_rule_spec(queuing_rule_spec_pool_t *pPool, ec_uint queuing_rule_id); + +/* TODO */ +engine_controller_error_t queuing_rule_spec_pool_remove_queuing_rule_spec(queuing_rule_spec_pool_t *pPool, ec_uint queuing_rule_id); + +#endif /* QUEUING_RULE_SPEC_POOL_H_ */ diff --git a/framework/include/EngineController/task.h b/framework/include/EngineController/task.h new file mode 100644 index 0000000..24b8ddf --- /dev/null +++ b/framework/include/EngineController/task.h @@ -0,0 +1,146 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Wook Choi + */ + +#ifndef TASK_H_ +#define TASK_H_ + +#include +#include +#include "param.h" +#include "task_spec.h" +#include "task_cancel_info.h" +#include "engine_controller_message.h" +#include "task_info_pool.h" +#include "Utility/fw_ref.h" + +typedef struct task_s task_t; +struct task_s { + ec_int ref_count; + + task_error_t task_error; + + task_info_t *pTask_info; + GSList *progress_blocking_realized_entity_list; /* containing progress_blocking_realized_entity_t* */ + GSList *current_node_in_progress_blocking_entity_list; /* containing n_ary_tree_node_with_flag_t* */ + + task_spec_t *pTask_spec; + refObject_t *pRequestMsg; /* containing engine_controller_request_msg_t* */ + + task_cancel_info_t *pCancel_Information; + param_t **param_array; + + /* information of dynamic case */ + ec_int dynamic_case; /* only use when task spec is dynamic */ + + /* information of parent link */ + task_t *pParent_task; + ec_int child_task_index_in_parent_task; + + /* information of child link */ + task_t **child_task_array; + + ec_uint cnt_left_child_task_to_finish; + + ec_uint *current_child_task_control_flow_in_degree_array; + + struct timeval create_time; + struct timeval run_time; + struct timeval finish_time; +}; + +GSList *task_construct_progress_blocking_realized_entity_list(task_info_t *pTask_info); + +task_t *task_alloc_root_task(task_spec_t *pTask_spec, engine_controller_request_msg_t *pRequest_Msg, task_info_pool_t *pTask_info_pool); +task_t *task_alloc_child_task(task_t *pParent_task, ec_int child_index); + +task_t *task_ref_task(task_t *pTask); +void task_unref_task(task_t *pTask); + +ec_boolean task_is_simple_task(task_t *pTask); +ec_boolean task_is_container_task(task_t *pTask); +ec_boolean task_is_root_task(task_t *pTask); + +ec_int task_get_param_cnt(task_t *pTask); +ec_int task_get_output_param_info(task_t *pTask, ec_int *pOutput_param_cnt, ec_int **pOutput_param_index_array); +ec_uint task_get_child_task_cnt(task_t *pTask); +task_t *task_get_parent_task(task_t *pTask); +ec_int task_get_child_index_in_parent_task(task_t *pTask); + +void task_set_task_error(task_t *pTask, task_error_t task_error); +ec_boolean task_check_same_task_error(task_t *pTask, task_error_t task_error); +ec_boolean task_is_not_yet_run(task_t *pTask); + +void task_do_cancellation(task_t *pTask); + +void task_call_task_finish_callback(task_t *pTask); + +void task_remove_control_flow(task_t *pParent_task, ec_int from_task_index, ec_int to_task_index); + +void task_set_left_child_to_run(task_t *pParent_task, ec_uint number); +ec_boolean task_is_left_child_to_run_zero(task_t *pParent_task); +void task_decrease_left_child_to_run(task_t *pParent_task); + +ec_boolean task_is_parent_task_done(task_t *pParent_task); +void task_collect_parent_task_output_parameter(task_t *pParent_task); + +GSList *collect_firstly_runnable_child_tasks(task_t *pParent_task); +GSList *collect_become_runnable_child_tasks_by_remove_control_flow(task_t *pParent_task, ec_int from_child_task_index); + +task_error_t task_run_simple_task(task_t *pSimple_task); + +/* return true if pending is done */ +ec_boolean task_add_pending_task_list_of_first_progress_blocking_realized_entity(task_t *pTask); + +void task_update_progress_blocking_realized_entity_and_pop_if_possible(task_t *pTask); + +typedef struct progress_blocking_realized_entity_s progress_blocking_realized_entity_t; +struct progress_blocking_realized_entity_s { + ec_uint left_progress_blocking_element_cnt; + + progress_blocking_entity_t *pEntity; + GSList *pending_task_list; /* containing task_t* */ +}; + +progress_blocking_realized_entity_t *progress_blocking_realized_entity_new(progress_blocking_entity_t *pEntity); +void progress_blocking_realized_entity_free(progress_blocking_realized_entity_t *pRealized_entity); + +void progress_blocking_realized_entity_restart_pending_task(progress_blocking_realized_entity_t *pRealized_entity); +void progress_blocking_realized_entity_add_pending_task(progress_blocking_realized_entity_t *pEntity, task_t *pending_task); + +/* return true when left_progress_blocking_element_cnt are updated and become zero */ +ec_boolean progress_blocking_realized_entity_update_and_test_left_progress_blocking_element_cnt(progress_blocking_realized_entity_t *pRealized_entity, n_ary_tree_node_with_flag_t *current_node, task_t *pTask); +ec_boolean progress_blocking_realized_entity_is_zero_left_progress_blocking_element_cnt(progress_blocking_realized_entity_t *pRealized_entity); + +#endif /* TASK_H_ */ diff --git a/framework/include/EngineController/task_cancel_info.h b/framework/include/EngineController/task_cancel_info.h new file mode 100644 index 0000000..e905f5e --- /dev/null +++ b/framework/include/EngineController/task_cancel_info.h @@ -0,0 +1,84 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Wook Choi + */ + +#ifndef TASK_CANCEL_INFO_H_ +#define TASK_CANCEL_INFO_H_ + +#include +#include +#include "Utility/fw_ref.h" +#include "engine_controller_define.h" + +typedef void (*cancel_callback) (void *user_data); + +typedef struct cancel_callback_info_s cancel_callback_info_t; +struct cancel_callback_info_s { + GThread *who_registered; + cancel_callback how_to_do; + ec_pointer user_data; +}; + +cancel_callback_info_t *cancel_callback_info_init(GThread *who_registered, cancel_callback how_to_do, ec_pointer user_data); +ec_boolean cancel_callback_info_compare(cancel_callback_info_t *pCancel_callback_info, GThread *who_registered, cancel_callback how_to_do, ec_pointer user_data); +void cancel_callback_info_call_callback(cancel_callback_info_t *pCancel_callback_info); +void cancel_callback_info_destroy(cancel_callback_info_t *pCancel_callback_info); + +typedef struct task_cancel_info_s task_cancel_info_t; +struct task_cancel_info_s { + ec_int ref_count; + + ec_boolean cancel_flag; + refObject_t *pRequestMsg; /* containing engine_controller_request_msg_t* */ + + GMutex *cancel_info_mutex; + struct timeval cancel_time; + GSList *cancel_callback_infos; /* containing cancel_callback_info_t* */ +}; + +task_cancel_info_t *task_cancel_info_init(refObject_t *pRequestMsg); +task_cancel_info_t *task_cancel_info_ref(task_cancel_info_t *pInfo); +void task_cancel_info_unref(task_cancel_info_t *pInfo); + +ec_boolean task_cancel_info_get_cancel_flag_atomic(task_cancel_info_t *pCancel_info); +void task_cancel_info_set_cancel_flag_atomic(task_cancel_info_t *pCancel_info); + +ec_int task_cancel_info_get_request_msg_id(task_cancel_info_t *pCancel_info); + +void task_cancel_info_call_cancel_callbacks_unlocked(task_cancel_info_t *pCancel_info); + +engine_controller_error_t task_cancel_info_register_cancel_callback_unlocked(task_cancel_info_t *pCancel_info, cancel_callback callback_func, ec_pointer user_data); +engine_controller_error_t task_cancel_info_unregister_cancel_callback_unlocked(task_cancel_info_t *pCancel_info, cancel_callback callback_func, ec_pointer user_data); + +#endif /* TASK_CANCEL_INFO_H_ */ diff --git a/framework/include/EngineController/task_error.h b/framework/include/EngineController/task_error.h new file mode 100644 index 0000000..eeaa3bc --- /dev/null +++ b/framework/include/EngineController/task_error.h @@ -0,0 +1,65 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Wook Choi + */ + +#ifndef TASK_ERROR_H_ +#define TASK_ERROR_H_ + +#include "fundamental_type.h" + +/** + * @file task_error.h + * @brief Provides enum definition for task status + */ + +/** + * @brief Enumeration for task result cases + */ +typedef enum task_error_e task_error_t; +enum task_error_e { + TASK_ERROR_NOT_YET_RUN = 0, /**< 'Not run yet' case */ + TASK_ERROR_RUN_SUCCESS, /**< 'Success' case */ + TASK_ERROR_RUN_FAILED, /**< 'Fail' case */ + TASK_ERROR_CANCELED, /**< 'Canceled' case */ + TASK_ERROR_INVALID_TASK /**< 'Invalid' case */ +}; + +/** + * @brief Provides readable expressiong of task error cases + * @param[in] error task_error_t type of enumeration + * @return Error string of given error case + */ +ec_char *task_error_string(task_error_t error); + +#endif /* TASK_ERROR_H_ */ diff --git a/framework/include/EngineController/task_info_pool.h b/framework/include/EngineController/task_info_pool.h new file mode 100644 index 0000000..fe8899f --- /dev/null +++ b/framework/include/EngineController/task_info_pool.h @@ -0,0 +1,77 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Wook Choi + */ + +#ifndef TASK_INFO_POOL_H_ +#define TASK_INFO_POOL_H_ + +#include +#include "fundamental_type.h" +#include "engine_controller_message.h" + +#include "task_spec.h" +#include "queuing_rule_spec_internal.h" + +typedef struct task_info_s task_info_t; +struct task_info_s { + ec_int task_spec_id; + task_spec_t *pTask_spec; + GSList *progress_blocking_entity_list; /* related to queuing rule */ + /* containing progress_blocking_entities related to task_spec */ +}; + +task_info_t *task_info_new(ec_int task_spec_id, task_spec_t *pTask_spec); +void task_info_free(task_info_t *pTask_info); +task_info_t *task_info_ref(task_info_t *pTask_info); +void task_info_unref(task_info_t *pTask_info); + +ec_boolean task_info_is_progress_blocking_entity_exist(task_info_t *pTask_info, progress_blocking_entity_t *pEntity); +engine_controller_error_t task_info_add_progress_blocking_entity(task_info_t *pTask_info, progress_blocking_entity_t *pEntity); +engine_controller_error_t task_info_remove_blocking_entity(task_info_t *pTask_info, progress_blocking_entity_t *pEntity); + +typedef struct task_info_pool_s task_info_pool_t; +struct task_info_pool_s { + GHashTable *pTask_info_pool; /* key : msg id + value : task_info_t* */ +}; + +task_info_pool_t *task_info_pool_alloc(); +void task_info_pool_free(task_info_pool_t *pTask_info_pool); + +ec_boolean task_info_pool_add_task_info(task_info_pool_t *pTask_info_pool, task_info_t *pTask_info, ec_boolean replace); +ec_boolean task_info_pool_remove_task_info(task_info_pool_t *pTask_info_pool, ec_uint msg_type); + +task_info_t *task_info_pool_search_task_info(task_info_pool_t *pTask_info_pool, ec_uint msg_type); + +#endif /* TASK_INFO_POOL_H_ */ diff --git a/framework/include/EngineController/task_message.h b/framework/include/EngineController/task_message.h new file mode 100644 index 0000000..74c604e --- /dev/null +++ b/framework/include/EngineController/task_message.h @@ -0,0 +1,76 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Wook Choi + */ + +#ifndef TASK_MESSAGE_H_ +#define TASK_MESSAGE_H_ + +#include "task.h" + +/* note that task state also related to priority ( TASK_ROOT_START == TASK_ROOT_DONE == TASK_CANCEL == TASK_CANCEL_ALL > TASK_DONE > TASK_START ) */ +/* note that TASK_ROOT_START, TASK_CANCEL, TASK_CANCEL_ALL coming from engine controller receiver, + TASK_START, TASK_DONE, TASK_ROOT_DONE coming from engine controller */ +typedef enum task_state_e task_state_t; +enum task_state_e { + TASK_ROOT_START = 0, + TASK_ROOT_DONE, + TASK_CANCEL, + TASK_CANCEL_ALL, + TASK_DONE, + TASK_START +}; + +/* lower priority, more urgent */ +ec_uint task_state_priority(task_state_t state); + +typedef struct task_message_s task_message_t; +struct task_message_s { + ec_uint priority; + task_state_t task_state; + union { + task_t *pTask; + ec_uint request_msg_id; /* task_state == TASK_CANCEL */ + /* nothing *//* task_state == TASK_CANCEL_ALL */ + } u; +}; + +typedef ec_int (*compare_task_msg_priority_func) (task_message_t *pTask_message1, task_message_t *pTask_message2, ec_pointer user_data); + +ec_int compare_priority_of_task_message_append_way(task_message_t *pTask_message1, task_message_t *pTask_message2, ec_pointer user_data); +ec_int compare_priority_of_task_message_prepend_way(task_message_t *pTask_message1, task_message_t *pTask_message2, ec_pointer user_data); + +task_message_t *task_message_create(task_state_t state, task_t *pTask, ec_uint request_msg_id); +void task_message_free(task_message_t *pTask_msg); + +#endif /* TASK_MESSAGE_H_ */ diff --git a/framework/include/EngineController/task_pool.h b/framework/include/EngineController/task_pool.h new file mode 100644 index 0000000..0992b23 --- /dev/null +++ b/framework/include/EngineController/task_pool.h @@ -0,0 +1,61 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Wook Choi + */ + +#ifndef TASK_POOL_H_ +#define TASK_POOL_H_ + +#include +#include +#include "task.h" + +/* it contains only root task */ +typedef struct task_pool_s task_pool_t; +struct task_pool_s { + GHashTable *pTask_hash; /* key : ec_uint (request_id) + value : task_t* */ +}; + +task_pool_t *task_pool_create_task_pool(); +void task_pool_free_task_pool(task_pool_t *pTask_pool); + +void task_pool_add_task(task_pool_t *pTask_pool, ec_uint request_id, task_t *pTask); + +task_t *task_pool_fetch_task(task_pool_t *pTask_pool, ec_uint request_id); + +GList *task_pool_fetch_all_tasks(task_pool_t *pTask_pool); + +void task_pool_remove_task(task_pool_t *pTask_pool, ec_uint request_id); + +#endif /* TASK_POOL_H_ */ diff --git a/framework/include/EngineController/task_process.h b/framework/include/EngineController/task_process.h new file mode 100644 index 0000000..32297d9 --- /dev/null +++ b/framework/include/EngineController/task_process.h @@ -0,0 +1,229 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Wook Choi + */ + +#ifndef TASK_PROCESS_H_ +#define TASK_PROCESS_H_ + +#include "engine_controller_define.h" +#include "param.h" + +/** + * @file task_process.h + * @brief Provides process related operations such as cancel flag check, callbak de/registration + */ + +/** + * @brief TASK_PROCESS function which is considered as default unit of task for Engine Controller to launch + * @param[in] param_cnt Count of parameters which will be used in the processing logic + * @param[in] param_array Array of parameters which contains parameters values itself + * @return task_error_t type of result + */ +typedef task_error_t(*TASK_PROCESS) (ec_uint param_cnt, param_t **param_array); + +/** + * @brief process_cancel_callback function which is called when cancel flag gets on + * @param[in] user_data User data to process inside the calcel callback function + */ +typedef void (*process_cancel_callback) (void *user_data); + +/** + * @brief process_cancel_callback function which is called when cancel flag gets on + * @remarks Note that below functions are valid only inside the TASK_PROCESS function which will be registered at task spec + * @return 1 when cancel flag is on, otherwiae 0 + * @code + task_error_t sample_add_task_process(ec_uint param_cnt, param_t** param_array) { + task_error_t err = TASK_ERROR_RUN_SUCCESS; + ec_boolean cancel_flag = false; + + ec_int a = 0; + ec_int b = 0; + ec_int c = 0; + + //get input parameter pass by user or previous task + param_value_get_value(&(param_array[0]->param_value), EC_VALUE_TYPE_INT, &a); + param_value_get_value(&(param_array[1]->param_value), EC_VALUE_TYPE_INT, &b); + + //processing logic will be located here + //checking cancel flag and register, unregister cancel callback will be done inside here + { + //register cancel callback (note that this can be called every where inside processing logic) + task_process_register_cancel_callback_when_cancel_flag_off(simple_add_cancel_callback, NULL); + + //check cancel flag (note that this can be called every where inside processing logic) + cancel_flag = task_process_check_cancel_flag(); + if (cancel_flag) { + err = TASK_ERROR_CANCELLED; + goto return_part; + } + + //processing logic + c = a+b; + + //if fail occured during processing logic, then set task failed state. + if (c != a+b) { + err = TASK_ERROR_RUN_FAILED; + goto return_part; + } + + //unregister cancel callback (note that this can be called every where inside processing logic) + task_process_unregister_cancel_callback_when_cancel_flag_off(simple_add_cancel_callback, NULL); + } + + //set output parameter + param_value_set_value(&(param_array[2]->param_value), EC_VALUE_TYPE_INT, &c); + + return_part: + return err; + } + * @endcode + */ +ec_boolean task_process_check_cancel_flag(void); + +/** + * @brief Registers cancel callback function which is called when cancel flag gets on + * @remarks Note that below functions are valid only inside the TASK_PROCESS function which will be registered at task spec + * @param[in] callback_func process_cancel_callback type of function to use on cancellation + * @param[in] user_data User data to pass to the callback function on cancellation + * @code + task_error_t sample_add_task_process(ec_uint param_cnt, param_t** param_array) { + task_error_t err = TASK_ERROR_RUN_SUCCESS; + ec_boolean cancel_flag = false; + + ec_int a = 0; + ec_int b = 0; + ec_int c = 0; + + //get input parameter pass by user or previous task + param_value_get_value(&(param_array[0]->param_value), EC_VALUE_TYPE_INT, &a); + param_value_get_value(&(param_array[1]->param_value), EC_VALUE_TYPE_INT, &b); + + //processing logic will be located here + //checking cancel flag and register, unregister cancel callback will be done inside here + { + //register cancel callback (note that this can be called every where inside processing logic) + task_process_register_cancel_callback_when_cancel_flag_off(simple_add_cancel_callback, NULL); + + //check cancel flag (note that this can be called every where inside processing logic) + cancel_flag = task_process_check_cancel_flag(); + if (cancel_flag) { + err = TASK_ERROR_CANCELLED; + goto return_part; + } + + //processing logic + c = a+b; + + //if fail occured during processing logic, then set task failed state. + if (c != a+b) { + err = TASK_ERROR_RUN_FAILED; + goto return_part; + } + + //unregister cancel callback (note that this can be called every where inside processing logic) + task_process_unregister_cancel_callback_when_cancel_flag_off(simple_add_cancel_callback, NULL); + } + + //set output parameter + param_value_set_value(&(param_array[2]->param_value), EC_VALUE_TYPE_INT, &c); + + return_part: + return err; + } + * @endcode + */ +void task_process_register_cancel_callback_when_cancel_flag_off(process_cancel_callback callback_func, ec_pointer user_data); + +/** + * @brief Unregisters cancel callback function registered in advance + * @remarks Note that below functions are valid only inside the TASK_PROCESS function which will be registered at task spec + * @param[in] callback_func process_cancel_callback type of function registered in advance + * @param[in] user_data User data registered with above callback functionin advnace + * @code + task_error_t sample_add_task_process(ec_uint param_cnt, param_t** param_array) { + task_error_t err = TASK_ERROR_RUN_SUCCESS; + ec_boolean cancel_flag = false; + + ec_int a = 0; + ec_int b = 0; + ec_int c = 0; + + //get input parameter pass by user or previous task + param_value_get_value(&(param_array[0]->param_value), EC_VALUE_TYPE_INT, &a); + param_value_get_value(&(param_array[1]->param_value), EC_VALUE_TYPE_INT, &b); + + //processing logic will be located here + //checking cancel flag and register, unregister cancel callback will be done inside here + { + //register cancel callback (note that this can be called every where inside processing logic) + task_process_register_cancel_callback_when_cancel_flag_off(simple_add_cancel_callback, NULL); + + //check cancel flag (note that this can be called every where inside processing logic) + cancel_flag = task_process_check_cancel_flag(); + if (cancel_flag) { + err = TASK_ERROR_CANCELLED; + goto return_part; + } + + //processing logic + c = a+b; + + //if fail occured during processing logic, then set task failed state. + if (c != a+b) { + err = TASK_ERROR_RUN_FAILED; + goto return_part; + } + + //unregister cancel callback (note that this can be called every where inside processing logic) + task_process_unregister_cancel_callback_when_cancel_flag_off(simple_add_cancel_callback, NULL); + } + + //set output parameter + param_value_set_value(&(param_array[2]->param_value), EC_VALUE_TYPE_INT, &c); + + return_part: + return err; + } + * @endcode + */ +void task_process_unregister_cancel_callback_when_cancel_flag_off(process_cancel_callback callback_func, ec_pointer user_data); + +/** + * @brief Provides task request ID of itself + * @remarks Note that below functions are valid only inside the TASK_PROCESS function which will be registered at task spec + * @return task request ID of itself + */ +ec_int task_process_get_self_request_id(void); + +#endif /* TASK_PROCESS_H_ */ diff --git a/framework/include/EngineController/task_spec.h b/framework/include/EngineController/task_spec.h new file mode 100644 index 0000000..92b401d --- /dev/null +++ b/framework/include/EngineController/task_spec.h @@ -0,0 +1,261 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Wook Choi + */ + +#ifndef TASK_SPEC_H_ +#define TASK_SPEC_H_ + +#include +#include + +#include "engine_controller_define.h" +#include "param_spec.h" +#include "param.h" +#include "task_process.h" + +/** + * @file task_spec.h + * @brief Provides task spec related operations such as create, child task fetch, data/control flow set and etc.. + */ + +/** + * @brief Callback function called after task running done + * @param[in] usr_post_task_func_data User data to pass to the post_task_callback_func + * @param[in] msg_id Task request msg ID + */ +typedef void (*post_task_callback_func) (ec_pointer usr_post_task_func_data, ec_uint msg_id); + +/** + * @brief Callback function which calculates result of dynamic task + * @param[in] param_cnt Count of output parameters resulted from dynamic task + * @param[in] param_array Array of output parameters resulted from dynamic task + * @return Result of the case calculatio callback function as integer + */ +typedef ec_int (*calculate_case_callback_func) (ec_uint param_cnt, param_t **param_array); + +/** + * @brief Structure of task spec which contains task related spec information such as parameter and callabck and etc + */ +typedef struct task_spec_s task_spec_t; + +/* external interface */ + +/** + * @brief Allocs and returns task_spec_t type of structure,using given parameters + * @param[in] task_name User defined task name + * @param[in] task_process TASK_PROCESS type of function pointer + * @param[in] post_task_func_usr_data User data to pass to the post_task_callback_func + * @param[in] post_task_callback Callback function called after task running done + * @param[in] param_cnt Count of input parameters + * @param[in] param_spec_array Array of input parameters + * @return Newly alloced task_spec_t type of task spec + */ +task_spec_t *task_spec_alloc_simple_task_spec(ec_char *task_name, TASK_PROCESS task_process, ec_pointer post_task_func_usr_data, post_task_callback_func post_task_callback, ec_uint param_cnt, param_spec **param_spec_array); + +/** + * @brief Increases reference count of task spec + * @param[in] pTask_spec Pointer of task spec to increase ref count + * @return Pointer of task spec itself on success, otherwise NULL + */ +task_spec_t *task_spec_ref(task_spec_t *pTask_spec); + +/** + * @brief Decreases reference count of task spec + * @param[in] pTask_spec Pointer of task spec to decrease ref count + */ +void task_spec_unref(task_spec_t *pTask_spec); + +/** + * @brief Comparea if given two task specs are same each other + * @param[in] pTask_spec1 Task spec to compare with + * @param[in] pTask_spec2 Task spec to compare with + * @return 1 on positive case, otherwise 0 + */ +ec_boolean task_spec_is_same(task_spec_t *pTask_spec1, task_spec_t *pTask_spec2); + +/** + * @brief Checks if given task spec is simple task + * @param[in] pTask_spec Task spec to check + * @return 1 on positive case, otherwise 0 + */ +ec_boolean task_spec_is_simple_task_spec(task_spec_t *pTask_spec); + +/** + * @brief Checks if given task spec is container task + * @param[in] pTask_spec Task spec to check + * @return 1 on positive case, otherwise 0 + */ +ec_boolean task_spec_is_container_task_spec(task_spec_t *pTask_spec); + +/** + * @brief Checks if given task spec is dynamic container task + * @param[in] pTask_spec Task spec to check + * @return 1 on positive case, otherwise 0 + */ +ec_boolean task_spec_is_dynamic_container_task_spec(task_spec_t *pTask_spec); + +/** + * @brief Returns number of child task in given task spec + * @param[in] pTask_spec Task spec to get child task count from + * @return Number of child task + */ +ec_uint task_spec_get_child_task_cnt(task_spec_t *pTask_spec); + +/** + * @brief Returns task spec of n'th child task in given parent task spec + * @param[in] pParent_task_spec Task spec to get child task spec from + * @param[in] child_task_index Index of child task to get spec from + * @return Task spec of requested child task + */ +task_spec_t *task_spec_get_child_task_spec(task_spec_t *pParent_task_spec, ec_int child_task_index); + +/** + * @brief Returns task spec of n'th child task in given parent task spec + * @param[in] pDynamic_task_spec Dynamic task spec to get child task count from + * @param[in] dynamic_case Case number to get child task count from under given dynamic task + * @return Count of child task under given dynamic task + */ +ec_uint task_spec_get_child_task_cnt_on_dynamic_case(task_spec_t *pDynamic_task_spec, ec_int dynamic_case); + +/** + * @brief Returns task spec of n'th child task in given parent dynamic task spec + * @param[in] dynamic_case Case number to get child task count from under given dynamic task + * @param[in] pParent_dynamic_task_spec Task spec to get child task spec from + * @param[in] child_task_index Index of child task to get spec from + * @return Task spec of requested child task + */ +task_spec_t *task_spec_get_child_task_spec_on_dynamic_case(ec_int dynamic_case, task_spec_t *pParent_dynamic_task_spec, ec_int child_task_index); + +/** + * @brief Returns number of input parameters + * @param[in] pTask_spec Case number to get child task count from under given dynamic task + * @return Number of parameters in given task spec + */ +ec_int task_spec_get_param_cnt(task_spec_t *pTask_spec); + +/** + * @brief Returns calculate_case_callback_func of given dynamic container task spec + * @param[in] pDynamic_container_task_spec Task spec of dynamic container task to get callback function info + * @return calculate_case_callback_func type of case calculation callback + */ +calculate_case_callback_func task_spec_get_calculate_case_callback_func(task_spec_t *pDynamic_container_task_spec); + +/** + * @brief Returns output parameter info such as param count and param value array + * @param[in] pTask_spec Task spec to get output parameter info + * @param[in] pOutput_param_cnt Count of output parameter + * @param[in] pOutput_param_index_array Array of output parameter value + * @return 1 when success, otherwise 0 + */ +ec_boolean task_spec_get_output_param_info(task_spec_t *pTask_spec, ec_int *pOutput_param_cnt, ec_int **pOutput_param_index_array); + +/** + * @brief Allocs and returns task_spec_t type of structure,using given parameters + * @param[in] task_name User defined task name + * @param[in] post_task_func_usr_data User data to pass to the post_task_callback_func + * @param[in] post_func Callback function called after task running done + * @param[in] param_cnt Count of input parameters + * @param[in] param_spec_array Array of input parameters + * @param[in] child_task_cnt Number of child tasks to put under + * @param[in] child_task_array Array of child task specs to put under + * @return Newly alloced task_spec_t type of task spec + */ +task_spec_t *task_spec_alloc_container_task_spec_outline(ec_char *task_name, ec_pointer usr_post_task_func_data, post_task_callback_func post_func, ec_uint param_cnt, param_spec **param_spec_array, ec_uint child_task_cnt, task_spec_t **child_task_array); + +/** + * @brief Sets data flow on given container task + * @param[in] pContainer_task_spec Container task spec to set data flow on + * @param[in] from_task_index Index of task to take data from + * @param[in] from_param_index Index of parameter to take data from + * @param[in] to_task_index Index of task to put data to + * @param[in] to_param_index Index of parameter to put data to + * @return Enumeration value of engine_controller_error_t + */ +engine_controller_error_t task_spec_set_data_flow(task_spec_t *pContainer_task_spec, ec_int from_task_index, ec_int from_param_index, ec_int to_task_index, ec_int to_param_index); + +/** + * @brief Sets control flow on given container task + * @param[in] pContainer_task_spec Container task spec to set control flow on + * @param[in] from_task_index Index of task to take data from + * @param[in] to_task_index Index of task to put data to + * @return Enumeration value of engine_controller_error_t + */ +engine_controller_error_t task_spec_set_control_flow(task_spec_t *pContainer_task_spec, ec_int from_task_index, ec_int to_task_index); + +/** + * @brief Checks if all child tasks under given container task are done + * @param[in] pContainer_task_spec Task spec of container task to check + * @return Enumeration value of engine_controller_error_t + */ +engine_controller_error_t task_spec_check_everything_done(task_spec_t *pContainer_task_spec); + +/** + * @brief Allocs and returns task_spec_t type of structure,using given parameters + * @param[in] task_name User defined task name + * @param[in] post_task_func_usr_data User data to pass to the post_task_callback_func + * @param[in] post_func Callback function called after task running done + * @param[in] param_cnt Count of input parameters + * @param[in] param_spec_array Array of input parameters + * @param[in] calculate_case_func Function which will calculate result case of dynamic task + * @param[in] case_cnt Count of cases in dynamic case + * @param[in] case_array Array of cases used in dynamic task + * @param[in] child_task_cnt_array Array of count of child task in each case + * @param[in] child_task_array_per_case_array Array of array of child task spec in each case + * @return Newly alloced task_spec_t type of task spec + */ +task_spec_t *task_spec_alloc_dynamic_container_task_spec_outline(ec_char *task_name, ec_pointer usr_post_task_func_data, post_task_callback_func post_func, ec_uint param_cnt, param_spec **param_spec_array, calculate_case_callback_func calculate_case_func, ec_uint case_cnt, ec_int *case_array, ec_uint *child_task_cnt_array, task_spec_t ***child_task_array_per_case_array); + +/** + * @brief Sets data flow on given dynamic case + * @param[in] dynamic_case Case number under given dynamic container task + * @param[in] pDynamic_container_task_spec Dynamic container task spec to set data flow on + * @param[in] from_task_index Index of task to take data from + * @param[in] from_param_index Index of parameter to take data from + * @param[in] to_task_index Index of task to put data to + * @param[in] to_param_index Index of parameter to put data to + * @return Enumeration value of engine_controller_error_t + */ +engine_controller_error_t task_spec_set_data_flow_on_dynamic_case(ec_int dynamic_case, task_spec_t *pDynamic_container_task_spec, ec_int from_task_index, ec_int from_param_index, ec_int to_task_index, ec_int to_param_index); + +/** + * @brief Sets control flow on given dynamic case + * @param[in] dynamic_case Case number under given dynamic container task + * @param[in] pDynamic_container_task_spec Dynamic container task spec to set control flow on + * @param[in] from_task_index Index of task to take data from + * @param[in] to_task_index Index of task to put data to + * @return Enumeration value of engine_controller_error_t + */ +engine_controller_error_t task_spec_set_control_flow_on_dynamic_case(ec_int dynamic_case, task_spec_t *pDynamic_container_task_spec, ec_int from_task_index, ec_int to_task_index); + +#endif /* TASK_SPEC_H_ */ diff --git a/framework/include/EngineController/task_spec_internal.h b/framework/include/EngineController/task_spec_internal.h new file mode 100644 index 0000000..09cf5d0 --- /dev/null +++ b/framework/include/EngineController/task_spec_internal.h @@ -0,0 +1,147 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Wook Choi + */ + +#ifndef TASK_SPEC_INTERNAL_H_ +#define TASK_SPEC_INTERNAL_H_ + +#include +#include "param_spec.h" +#include "graph_edge_pool.h" +#include "queuing_rule_spec.h" + +typedef struct data_flow_edges_s data_flow_edges_t; +/* all parameter in container task has unique index which calculated as following */ +/* parent container task param[0] : 0 + * ... + * parent container task param[parent_param_cnt - 1] : parent_param_cnt - 1 + * ... + * child task 1 param[0] : parent_param_cnt + * ... + * child task 1 param[child_1_param_cnt - 1] : parent_param_cnt + child_1_param_cnt - 1 + * ... + */ +struct data_flow_edges_s { + ec_int child_task_cnt; + ec_int *child_task_param_start_index_array; + + ec_int total_param_cnt; /* total_param_cnt = parent_task_param_cnt + sum of (child_task_param_cnt_array[i]) for all i */ + ec_int *from_param_array; /* containing data flow (from_param_array[idx] th param -> idx th param ) */ +}; + +data_flow_edges_t *data_flow_edges_new(ec_int parent_task_param_cnt, ec_uint child_task_cnt, task_spec_t **child_task_array); +void data_flow_edges_free(data_flow_edges_t *pData_flow_edges); + +ec_int data_flow_edges_compute_internal_index(data_flow_edges_t *pData_flow_edges, ec_int task_index, ec_int param_index); + +/* return true when valid internal index used, false otherwise */ +ec_boolean data_flow_edges_compute_task_index_and_param_index(data_flow_edges_t *pData_flow_edges, ec_int internal_index, ec_int *pTask_index, ec_int *pParam_index); + +/* return true when success, false otherwise */ +ec_boolean data_flow_edges_add_edge(data_flow_edges_t *pData_flow_edges, ec_int from_task_index, ec_int from_param_index, ec_int to_task_index, ec_int to_param_index); + +/* return true when from part exist, false otherwise */ +ec_boolean data_flow_edges_get_from_param_info(data_flow_edges_t *pData_flow_edges, ec_int to_task_index, ec_int to_param_index, ec_int *from_task_index, ec_int *from_param_index); + +typedef struct child_tasks_info_s child_tasks_info_t; +struct child_tasks_info_s { + ec_uint child_task_cnt; + /* node index description */ + /* -1 : parent node */ + /* 0 ~ child_task_cnt - 1 : child nodes */ + task_spec_t **child_task_array; + + /* data, control flows between child tasks */ + ec_uint *child_task_control_flow_in_degree; + graph_edge_pool_t *pControl_edge_pool; /* node type : int */ + data_flow_edges_t *pData_flow_edges; +}; + +task_spec_t *task_spec_get_child_task_spec_from_child_task_info(child_tasks_info_t *pChild_tasks_info, ec_uint child_task_index); + +typedef struct dynamic_container_task_specific_s dynamic_container_task_specific_t; +struct dynamic_container_task_specific_s { + calculate_case_callback_func calculate_case_func; + + ec_uint case_cnt; + ec_int *case_array; + + child_tasks_info_t **case_specific_child_task_info_array; +}; + +typedef enum task_type_e task_type_t; +enum task_type_e { + TASK_SIMPLE = 0, + TASK_CONTAINER, + TASK_DYNAMIC_CONTAINER +}; + +struct task_spec_s { + ec_int ref_count; + task_type_t task_type; + ec_char *task_name; + + ec_int task_param_cnt; + param_spec **task_param_spec_array; + + void *usr_post_task_func_data; + post_task_callback_func post_func; + + union { + /* simple task */ + TASK_PROCESS task_process; + + /* container task */ + child_tasks_info_t *pContainer_task_specific; + + /* dynamic container task */ + dynamic_container_task_specific_t *pDynmaic_container_task_specific; + } u; +}; + +/* engine_controller_error_t task_spec_attach_queuing_rule_spec(task_spec_t* pSpec, queuing_rule_spec_t* pQueuing_rule_spec); */ + +engine_controller_error_t task_spec_valididate_child_task_index(task_spec_t *pContainer_task_spec, ec_int child_task_index); + +engine_controller_error_t task_spec_valididate_child_task_index_on_dynamic_case(ec_int dynamic_case, task_spec_t *pDynamic_container_task_spec, ec_int child_task_index); + +ec_uint *task_spec_duplicate_child_task_control_flow_in_degree(task_spec_t *pTask_spec); + +ec_uint *task_spec_duplicate_child_task_control_flow_in_degree_on_dynamic_case(task_spec_t *pDynamic_task_spec, ec_int dynamic_case); + +child_tasks_info_t *task_spec_find_child_tasks_info(task_spec_t *pParent_container_task_spec); + +child_tasks_info_t *task_spec_find_case_specific_child_tasks_info(task_spec_t *pParent_dynamic_task_spec, ec_int dynamic_case); + +#endif /* TASK_SPEC_INTERNAL_H_ */ diff --git a/framework/include/EngineController/thread_pool.h b/framework/include/EngineController/thread_pool.h new file mode 100644 index 0000000..2026b8f --- /dev/null +++ b/framework/include/EngineController/thread_pool.h @@ -0,0 +1,59 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Wook Choi + */ + +#ifndef THREAD_POOL_H_ +#define THREAD_POOL_H_ + +#include +#include "task.h" + +typedef struct thread_pool_s thread_pool_t; +struct thread_pool_s { + GPrivate *cancel_tsk; + + ec_uint max_thread_count; + GThreadPool *pPool; +}; + +GPrivate *thread_pool_create_cancel_TSK(void); +GPrivate *thread_pool_get_cancel_TSK(thread_pool_t *pThread_pool); + +ec_uint thread_pool_get_max_thread_count(thread_pool_t *pThread_pool); + +thread_pool_t *thread_pool_alloc_and_init(ec_uint max_thread_count); +void thread_pool_destroy(thread_pool_t *pPool); +void thread_pool_push_task(thread_pool_t *pPool, task_t *pTask); + +#endif /* THREAD_POOL_H_ */ diff --git a/framework/include/Event/Event_Config.h b/framework/include/Event/Event_Config.h new file mode 100755 index 0000000..daf763e --- /dev/null +++ b/framework/include/Event/Event_Config.h @@ -0,0 +1,81 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#ifndef EVENT_INIT_H_ +#define EVENT_INIT_H_ + +#include "Event_Error.h" +#include "Event_Handler.h" +#include "Event/Event_UI_API.h" +#include "Event/Event_Spec.h" + +#define EVENT_COMMUNICATION_PATH "/tmp/agent_fw_event_" +#define EVENT_REPLY_COMMUNICATION_PATH "/tmp/agent_fw_event_reply_" +#define NOTI_COMMUNICATION_PATH "/tmp/agent_fw_noti_" +#define NOTI_REPLY_COMMUNICATION_PATH "/tmp/agent_fw_noti_reply_" + +#define MAX_STREAM_SIZE 102400 + +const char *get_Noti_Path(const char *noti_key); + +const char *get_Noti_Reply_Path(const char *noti_key); + +const char *get_Event_Path(); + +const char *get_Event_Reply_Path(); + +EVENT_ERROR set_EventSpec_from_ConfigFile(const char *event_key, const char *configfile); + +EVENT_ERROR clean_EventSpec(); + +EVENT_ERROR set_NotiSpec_from_ConfigFile(const char *noti_key, const char *configfile); + +EVENT_ERROR clean_NotiSpec(); + +EVENT_ERROR register_EventCallback(int eventNum, EVENT_CALLBACK callback); + +EVENT_ERROR register_NotiCallback(int notiNum, NOTI_CALLBACK callback, void *data); /* only UI */ + +EVENT_CALLBACK get_EventCallback(int eventNum); + +NOTI_CALLBACK get_NotiCallback(int notiNum); /* only UI */ + +void *get_NotiCallback_AdditinalParam(int notiNum); /* only UI */ + +EVENT_TYPE get_EventType(int eventNum); + +NOTI_TYPE get_NotiType(const char *noti_key, int notiNum); /* UI and Agent */ + +#endif /* EVENT_INIT_H_ */ diff --git a/framework/include/Event/Event_Data_Accessor.h b/framework/include/Event/Event_Data_Accessor.h new file mode 100755 index 0000000..8ccf05e --- /dev/null +++ b/framework/include/Event/Event_Data_Accessor.h @@ -0,0 +1,103 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#ifndef EVENT_DATA_ACCESSOR_H_ +#define EVENT_DATA_ACCESSOR_H_ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/** + * @file Event_Data_Accessor.h + * @brief Support to access (create, append, get, remove) Event packet structure + */ + +/** + * @brief Structure of Event Packet + */ + typedef struct { + int eventNum; + /**< event number described in event config file */ + char *size; /**< need to iterate real data */ + char *data; /**< real data expected to send */ + } Event_Data; + +/** + * @brief type of parameter in Event_Data + */ + typedef enum { + INTEGER = 'I', + /**< Interger type */ + STRING = 'S' /**< String type */ + } param_type; + +/** + * @brief Add parameter to Event packet + * @remarks Once one parameter is added each time it's invoked. parameter type can be Number or String. + * @param[out] iter Event_Data* parameters to be added + * @param[in] type parameter type (INTEGER, STRING) @ref param_type + * @param[in] data real parameter data + * @see get_eventdata_param() + */ + void append_eventdata_param(Event_Data *iter, param_type type, void *data); + +/** + * @brief Extract parameter from Event packet + * @remarks This function will be used when Extracting Recieved Event packet. + * extracted order is matched the order of @ref append_eventdata_param(). + * @param[out] iter Event_Data* parameters to be extracted + * @param[out] data real extracted data + * @see append_eventdata_param() + */ + void get_eventdata_param(Event_Data *iter, void *data); + +/** + * @brief Print Event_Data' packet contents Heuristically + * @remarks for Debugging. LOG_TAG "AF_EVENT" + * @param[in] msg_stream print msg packet + */ + void print_eventdata(char *msg_stream); + +/** + * @brief Free Event_Data * + * @param[in] event will be freed + */ + void free_eventdata(Event_Data *event); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /* EVENT_DATA_ACCESSOR_H_ */ diff --git a/framework/include/Event/Event_Error.h b/framework/include/Event/Event_Error.h new file mode 100755 index 0000000..ea7fd5c --- /dev/null +++ b/framework/include/Event/Event_Error.h @@ -0,0 +1,62 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#ifndef EVENT_ERROR_H_ +#define EVENT_ERROR_H_ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/** + * @file Event_Error.h + * @brief Definition of framework error codes for Event module + */ + +/** + * @brief Enumerations of error codes for Event module + */ + typedef enum { + EVENT_SUCCESS, /**< when Event Operation is succeed */ + EVENT_FAIL, /**< when Event Operation is failed */ + EVENT_TIME_OVER,/**< when Event Operation is failed because of time over */ + EVENT_IPC_ERR, /**< when Event Operation is failed because of IPC */ + EVENT_CANCLED /**< when Event Operation is canceled */ + } EVENT_ERROR; + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /* EVENT_ERROR_H_ */ diff --git a/framework/include/Event/Event_Handler.h b/framework/include/Event/Event_Handler.h new file mode 100755 index 0000000..008aa6a --- /dev/null +++ b/framework/include/Event/Event_Handler.h @@ -0,0 +1,148 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#ifndef EVENT_HANDLER_H_ +#define EVENT_HANDLER_H_ + +#include "Event_Error.h" +#include "Event_Data_Accessor.h" + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/** + * @file Event_Handler.h + * @brief Support to use framework Event module for agent + */ + +/** + * @brief Enumerations of need for cancel IPC + */ + typedef enum { + NEED_CANCEL = 1, /**< need to cancel IPC */ + UN_NEED_CANCEL /**< not need to cancel IPC */ + } IPC_CANCEL; + +/** + * @brief Event callback + * @remark event described in event config file will be processed in this callback function. + * @param[in] request received event packet from UI + * @param[in] response if event need to synchronous response, use this parameter + * @see set_EventCallback() + */ + typedef int (*EVENT_CALLBACK) (Event_Data *request, Event_Data *response); + +/** + * @brief checking logic, need for IPC cancel + * @remark this function is used in @ref send_Noti(). + * @param[in] user_data user data used in callback function + * @see send_Noti() + */ + typedef IPC_CANCEL(*CONFIRM_IPC_CANCEL) (void *user_data); + +/** + * @brief Activate the Event Handler + * @remarks Event Handler is a thread. Thread's routine is UNIX Domain Socket Server. + * @param[out] thread_id Created thread's ID + * @return EVENT_SUCCESS on success, otherwise a error value. + * @retval EVENT_SUCCESS Successful + * @retval EVENT_FAIL thread creation failed + * @pre This function should be called one time. or after clean_Event_Handler() called. + * @post new thread is created. Agent can receive event from UI. + * @see clean_Event_Handler() + */ + EVENT_ERROR run_Event_Handler(unsigned long int *thread_id); + +/** + * @brief Cleaning the Running Event Handler + * @remarks Event handler thread is killed. event/noti config is removed from memory + * @return EVENT_SUCCESS on success, otherwise a error value. + * @retval EVENT_SUCCESS Successful + * @retval EVENT_FAIL clean failed + * @post Agent can not receive event from UI. + * @see run_Event_Handler() + */ + EVENT_ERROR clean_Event_Handler(); + +/** + * @brief set callback function to process event from UI + * @param[in] eventNum event number in event config file + * @param[in] callback event processing callback function + * @return EVENT_SUCCESS on success, otherwise a error value. + * @retval EVENT_SUCCESS Successful + * @retval EVENT_FAIL registration failed + * @pre eventNum must be in event config file. + * @post callback function will be called when UI send the event. + */ + EVENT_ERROR set_EventCallback(int eventNum, EVENT_CALLBACK callback); + +/** + * @brief Creation Empty Notification packet. + * @remarks Notification is from Agent to UI. Complete using returned Event_Data pointer. and + * send completed Event_Data to UI. Event_Data* should be freed with @ref free_Noti() by you. + * @param[in] notiNum notification number in notification config file + * @return Event_Data structure on success, otherwise a null pointer. + * @retval Event_Data* Successful + * @retval NullPointer creation failed + * @pre notiNum must be in notification config file. + * @see free_Noti() + */ + Event_Data *create_Noti(int notiNum); + +/** + * @brief Agent send Notification to UI + * @param[in] noti_key destination, descripted in framework initialization config file tag + * @param[in] noti real notification packet + * @param[in] confirm_cancel function pointer checking cancel condition. it's needed when response is required. + * @param[in] user_data use in confirm_cancel function + * @param[out] error result + * @return Event_Data* when response is required, otherwise null pointer + * @see create_Noti(), free_Noti() + */ + Event_Data *send_Noti(const char *noti_key, Event_Data *noti, CONFIRM_IPC_CANCEL confirm_cancel, void *user_data, EVENT_ERROR *error); + +/** + * @brief free notification packet + * @remarks this function will release Event_Data* returned from @ref create_Noti(), send_Noti(). + * @param[in] noti Expected to be freed notification packet + * @see create_Noti(), send_Noti() + */ + void free_Noti(Event_Data *noti); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /* EVENT_HANDLER_H_ */ diff --git a/framework/include/Event/Event_Spec.h b/framework/include/Event/Event_Spec.h new file mode 100755 index 0000000..cf8471b --- /dev/null +++ b/framework/include/Event/Event_Spec.h @@ -0,0 +1,80 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#ifndef EVENT_SPEC_H_ +#define EVENT_SPEC_H_ + +#define MAX_EVENT_COUNT 100 +#define MAX_NOTI_COUNT 100 + +typedef enum { + EVENT_TYPE_NO_RESPONSE = 0, + EVENT_TYPE_NEED_RESPONSE, + EVENT_TYPE_NEED_NOTI_RESPONSE, + EVENT_TYPE_IS_RESPONSE +} EVENT_TYPE; + +typedef enum { + NOTI_TYPE_SIMPLE = 0, + NOTI_TYPE_IS_REPLY, + NOTI_TYPE_NEED_REPLY +} NOTI_TYPE; + +typedef struct { + int eventNum; + EVENT_TYPE event_type; + int relational_notiNum; + int pendingtime; + EVENT_CALLBACK callback; +} Event_Spec; + +typedef struct { + int notiNum; + NOTI_TYPE noti_type; + int relational_eventNum; + int pendingtime; + void *additional_param; + NOTI_CALLBACK callback; +} Noti_Spec; + +typedef struct { + char *noti_key; + char *communication_path_noti; + char *communication_path_reply_noti; + int noti_count; + Noti_Spec *noti_Spec_list[MAX_NOTI_COUNT]; +} Noti_Spec_Bag; + +#endif /* EVENT_SPEC_H_ */ diff --git a/framework/include/Event/Event_UI_API.h b/framework/include/Event/Event_UI_API.h new file mode 100755 index 0000000..34c4b1b --- /dev/null +++ b/framework/include/Event/Event_UI_API.h @@ -0,0 +1,121 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#ifndef EVENT_UI_API_H_ +#define EVENT_UI_API_H_ + +#include "Event_Error.h" +#include "Event_Data_Accessor.h" + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/** + * @file Event_UI_API.h + * @brief Support to use framework Event module for UI + */ + +/** + * @brief Notification callback + * @remark notification described in notification config file will be processed in this callback function. + * @param[in] noti received notification packet from agent + * @param[in] data user data + * @see set_NotiCallBack() + */ + typedef int (*NOTI_CALLBACK) (Event_Data *noti, void *data); + +/** + * @brief Creation Empty Event packet. + * @remarks Event is from UI to Agent. Complete using returned Event_Data pointer. and + * send completed Event_Data to Agent. Event_Data* should be freed with @ref free_Event() by you. + * @param[in] eventNum Event number in notification config file + * @return Event_Data structure on success, otherwise a null pointer. + * @retval Event_Data* Successful + * @retval NullPointer creation failed + * @pre eventNum must be in event config file. + * @see free_Eventi() + */ + Event_Data *create_Event(int eventNum); + +/** + * @brief UI send Event to Agent + * @param[in] event real Event packet + * @param[out] error result + * @return Event_Data* when response is required, otherwise null pointer + * @see create_Event(), free_Event() + */ + Event_Data *send_Event(Event_Data *event, EVENT_ERROR *error); + +/** + * @brief Activate the Notification Listener + * @remarks Notification Listener is a thread. Thread's routine is UNIX Domain Socket Server. + * @return EVENT_SUCCESS on success, otherwise a error value. + * @retval EVENT_SUCCESS Successful + * @retval EVENT_FAIL thread creation failed + * @pre This function should be called one time. or after stop_NotiListener() called. + * @post new thread is created. UI can receive event from Agent. + * @see stop_NotiListener() + */ + EVENT_ERROR run_NotiListener(); + +/** + * @brief Stop the Running Notification Listener + * @remarks Notification Listener thread is killed. event/noti config is removed from memory + * @return EVENT_SUCCESS on success, otherwise a error value. + * @retval EVENT_SUCCESS Successful + * @retval EVENT_FAIL clean failed + * @post UI can not receive event from Agent. + * @see run_NotiListener() + */ + EVENT_ERROR stop_NotiListener(); + +/** + * @brief set callback function to process Notification from Agent + * @param[in] notiType notification number in notification config file + * @param[in] callback notification processing callback function + * @param[in] data use in notification callback function + * @return EVENT_SUCCESS on success, otherwise a error value. + * @retval EVENT_SUCCESS Successful + * @retval EVENT_FAIL registration failed + * @pre notiType must be in notification config file. + * @post callback function will be called when Agent send the UI. + */ + EVENT_ERROR set_NotiCallBack(int notiType, NOTI_CALLBACK callback, void *data); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /* EVENT_UI_API_H_ */ diff --git a/framework/include/Event/Event_Util.h b/framework/include/Event/Event_Util.h new file mode 100644 index 0000000..ab81786 --- /dev/null +++ b/framework/include/Event/Event_Util.h @@ -0,0 +1,49 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#ifndef EVENT_UTIL_H_ +#define EVENT_UTIL_H_ + +#include "Event_Data_Accessor.h" + +void init_eventdata_iter(Event_Data *event); + +int get_eventdata_byte_size(Event_Data *iter); + +int get_eventdata_element_size(Event_Data *iter); + +void remove_buffer(Event_Data *event); + +#endif /* EVENT_UTIL_H_ */ diff --git a/framework/include/FSAPI/FSAPI_operation.h b/framework/include/FSAPI/FSAPI_operation.h new file mode 100644 index 0000000..ed90aa1 --- /dev/null +++ b/framework/include/FSAPI/FSAPI_operation.h @@ -0,0 +1,216 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Wook Choi + */ + +#ifndef FSAPI_OPERATION_H_ +#define FSAPI_OPERATION_H_ + +#include +#include +#include + +/** + * @file FSAPI_operation.h + * @brief Provides file system related operations such as file/folder create, delete, read, write and etc.. + */ + +/** + * @brief Check whether given file path is existing or not + * @remarks file path can be either a file or a folder. + * @param[in] filename File path you want to check + * @return 1 when the instance you want to check exists, otherwise 0 + */ +int FSAPI_isExisting(const char *filename); + +/** + * @brief Provides free size and total size of file system which your file path exists on + * @param[in] root File path you want to check + * @param[out] sizeFree Free size of file system in bytes + * @param[out] sizeTotal Total size of file system in bytes + * @return 1 on success, otherwise 0 + */ +int FSAPI_memSize(const char *root, long double *sizeFree, long double *sizeTotal); + +/** + * @brief Provides size of your file + * @param[in] filename File path you want to check + * @param[out] size Size of requested file in bytes + * @return 1 on success, otherwise 0 + */ +int FSAPI_fileSize(const char *filename, unsigned long *size); + +/** + * @brief Provides date information of your file in character stream + * @remarks The return char stream format is "Y:m:d H:M:S". + * The Date info stream should be freed when no more in use. + * @param[in] filename File path you want to check + * @param[out] time_string Double pointer of the char variable you want to load file date info on + * @return 1 on success, otherwise 0 + */ +int FSAPI_fileDate(const char *filename, char **time_string); + +/** + * @brief Provides file copy operation + * @remarks Operation will fail if destination already exists. + * @param[in] source Source file path + * @param[in] dest Destination file path + * @return 1 on success, otherwise 0 + */ +int FSAPI_fileCopy(const char *source, const char *dest); + +/** + * @brief Provides file delete operation + * @param[in] filename File path to delete + * @return 1 on success, otherwise 0 + */ +int FSAPI_fileDelete(const char *filename); + +/** + * @brief Provides file move operation + * @remarks Operation will fail if destination already exists. + * @param[in] source Source file path + * @param[in] dest Destination file path + * @return 1 on success, otherwise 0 + */ +int FSAPI_fileMove(const char *source, const char *dest); + +/** + * @brief Provides file rename operation + * @remarks Operation will fail if destination already exists. + * @param[in] source Source file path + * @param[in] dest Destination file path + * @return 1 on success, otherwise 0 + */ +int FSAPI_fileRename(const char *source, const char *dest); + +/** + * @brief Provides file read operation (Keeps file descriptor until reaching end of file) + * @remarks Need to call repeatedly with proper 'required_length' until you get TRUE value of the bool option 'isFinal'. + * Provided contents 'required_contents' should be freed when no more in use. + * @param[in] filename File path which you want to read + * @param[in] required_length Size to read + * @param[out] required_contents Char variable to load file contents on + * @param[out] size_return Size of invoked file contents + * @param[out] isFinal Boolean value to indicate whether end of file reached or not + * @return 1 on success, otherwise 0 + */ +int FSAPI_fileRead(const char *filename, char **required_contents, unsigned long required_length, unsigned long *size_return, bool *isFinal); + +/** + * @brief Provides file read operation (Entire contents at once) + * @remarks Provided 'required_contents' should be freed when no more in use. + * @param[in] filename File path which you want to read + * @param[out] required_contents Char variable to load file contents on + * @param[out] size_return Size of invoked file contents + * @return 1 on success, otherwise 0 + */ +int FSAPI_fileReadWhole(const char *filename, char **required_contents, unsigned long *size_return); + +/** + * @brief Provides free operation for file contents loaded from FSAPI_fileRead, FSAPI_fileReadWhole + * @param[in] requested_contents File contents to free + */ +int FSAPI_fileRead_Free(char **requested_contents); + +/** + * @brief Provides file write operation (Keeps file descriptor until finish order) + * @remarks Writes given contents to given file until 'isFinal' option enabled. + * Destination file won't be appeared until you give 'isFinal' option. + * Useful when writing several chunks into new file in one task. + * @param[in] filename File path which you want to write + * @param[in] contents Contents to write + * @param[in] length Size of the contents + * @param[in] isFinal Option to order operation finish + * @param[in] overwrite Option to order overwriting + * @return 1 on success, otherwise 0 + */ +int FSAPI_fileWrite(const char *filename, const char *contents, unsigned long length, bool isFinal, bool overwrite); + +/** + * @brief Provides file write operation (Entire contents at once) + * @param[in] filename File path which you want to write + * @param[in] contents Contents to write + * @param[in] length Size of the contents + * @param[in] overwrite Option to order overwriting + * @return 1 on success, otherwise 0 + */ +int FSAPI_fileWriteWhole(const char *filename, const char *contents, unsigned long length, bool overwrite); + +/** + * @brief Provides file append operation + * @remarks Appends given contents to given file. + * If given file not existing, create first and start appending. + * @param[in] filename File path which you want to write + * @param[in] contents Contents to write + * @param[in] length Size of the contents + * @param[in] overwrite Option to order overwriting + * @return 1 on success, otherwise 0 + */ +int FSAPI_fileAppend(const char *filename, const char *contents, unsigned long length, bool overwrite); + +/** + * @brief Provides folder create operation + * @remarks All parents folder will be created along + * in case any upper parents folders in the ordered folder path not existing. + * @param[in] foldername Folder path to create + * @return 1 on success, otherwise 0 + */ +int FSAPI_folderCreate(const char *foldername); + +/** + * @brief Provides folder delete operation + * @remarks Operation will fail in case the requested folder is not empty if 'recusive' option not given. + * @param[in] foldername Folder path to delete + * @param[in] recursive Option to delete inside recursively + * @return 1 on success, otherwise 0 + */ +int FSAPI_folderDelete(const char *foldername, bool recursive); + +/** + * @brief Provides folder delete operation without deleting root of the requested folder itself + * @param[in] foldername Folder path to delete inside + * @return 1 on success, otherwise 0 + */ +int FSAPI_folderEmptyContents(const char *foldername); + +/** + * @brief Provides folder rename operation + * @remarks Operation will fail if destination already exists. + * @param[in] source Source file path + * @param[in] dest Destination file path + * @return 1 on success, otherwise 0 + */ +int FSAPI_folderRename(const char *source, const char *dest); + +#endif /* FSAPI_OPERATION_H_ */ diff --git a/framework/include/FSAPI/FSAPI_util.h b/framework/include/FSAPI/FSAPI_util.h new file mode 100644 index 0000000..a941952 --- /dev/null +++ b/framework/include/FSAPI/FSAPI_util.h @@ -0,0 +1,47 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Wook Choi + */ + +#ifndef FSAPI_UTIL_H_ +#define FSAPI_UTIL_H_ + +#include + +int isExisting(const char *filename); + +int isDirectory(const char *filename); + +int getTimeString(time_t *time_stamp, char *time_string); + +#endif /* FSAPI_UTIL_H_ */ diff --git a/framework/include/Initialization/initialize.h b/framework/include/Initialization/initialize.h new file mode 100755 index 0000000..5cde9ca --- /dev/null +++ b/framework/include/Initialization/initialize.h @@ -0,0 +1,74 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#ifndef INITIALIZE_H_ +#define INITIALIZE_H_ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#include "initialize_error.h" + +/** + * @file initialize.h + * @brief Support to initialize framework for agent + */ + +/** + * @brief Initialization of Agent Framework + * @remarks Framework will be initialized using by config file written by the agent developer. + * Initialization config file format is XML. + * @param[in] init_config_path framework init config file - XML format + * @return INIT_SUCCESS on success, otherwise a error value. + * @retval INIT_SUCCESS Successful + * @retval INIT_PARSER_FAIL Parsing the initialization config file failed + * @retval INIT_ENGINE_CONTROLLER_FAIL Engine controller Initialization failed + * @retval INIT_EVENT_FAIL Event module Initialization failed + * @retval INIT_COMMON_DB_FAIL CommonDataBase Initialization failed + * @retval INIT_PLUGIN_FAIL PlugIn Initialization failed + * @retval INIT_PM_FAIL PlatformMonitor Initialization failed + * @retval INIT_DM_FAIL DeviceManagent Initialization failed + * @retval INIT_NETWORK_FAIL NetworkAccess Initialization failed + * @retval INIT_DEVICE_FAIL Device Initialization failed + * @pre Has not been called before. This function should be called one time. + * @post Framework is initialized as described in the file. Agent can use the Framework's function. + */ + INIT_ERROR Init_Framework(const char *init_config_path); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /* INITIALIZE_H_ */ diff --git a/framework/include/Initialization/initialize_error.h b/framework/include/Initialization/initialize_error.h new file mode 100755 index 0000000..02ea7ab --- /dev/null +++ b/framework/include/Initialization/initialize_error.h @@ -0,0 +1,72 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#ifndef INITIALIZE_ERROR_H_ +#define INITIALIZE_ERROR_H_ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/** + * @file initialize_error.h + * @brief Definition of framework error codes for Initialization + */ + +/** + * @brief Enumerations of error codes for Initialization + */ + typedef enum { + INIT_SUCCESS = 0, + /**< Successful */ + INIT_FAIL, /**< Fail */ + INIT_PARSER_FAIL, /**< Failed to parse the config file */ + INIT_ENGINE_CONTROLLER_FAIL, + /**< Failed to initialize the engine controller module */ + INIT_EVENT_FAIL, /**< Failed to initialize the event module */ + INIT_COMMON_DB_FAIL, + /**< Failed to initialize the common database module */ + INIT_PLUGIN_FAIL, /**< Failed to initialize the plugIn module */ + INIT_SERVICE_DB_FAIL, /**< Failed to initialize the service module */ + INIT_PM_FAIL, /**< Failed to initialize the platform monitor module */ + INIT_DM_FAIL, /**< Failed to initialize the device manage module */ + INIT_NETWORK_FAIL, /**< Failed to initialize the network access module */ + INIT_DEVICE_FAIL /**< Failed to initialize the device module */ + } INIT_ERROR; + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /* INITIALIZE_ERROR_H_ */ diff --git a/framework/include/Initialization/initialize_parser.h b/framework/include/Initialization/initialize_parser.h new file mode 100755 index 0000000..4e5b60d --- /dev/null +++ b/framework/include/Initialization/initialize_parser.h @@ -0,0 +1,47 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#ifndef INITIALIZE_PARSER_H_ +#define INITIALIZE_PARSER_H_ + +#include "initialize_error.h" + +INIT_ERROR parse_Init_config(const char *init_config_file_path); + +char *get_AgentKey(); + +int use_MainLoop(); + +#endif /* INITIALIZE_PARSER_H_ */ diff --git a/framework/include/NetworkAccess/EXT_NA_NetworkStatus.h b/framework/include/NetworkAccess/EXT_NA_NetworkStatus.h new file mode 100755 index 0000000..362cfaf --- /dev/null +++ b/framework/include/NetworkAccess/EXT_NA_NetworkStatus.h @@ -0,0 +1,67 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Seokgil Kang + */ + +#ifndef EXT_NA_NETWORKSTATUS_H_ +#define EXT_NA_NETWORKSTATUS_H_ + +/** + * @file EXT_NA_NetworkStatus.h + * @brief Defines network status/type provided by sync-agent-framework + */ + +/** + * @brief Enumerations for the information about current network status provided by sync-agent-framework + */ +typedef enum { + NETWORK_UNKNOWN = 0, /** initial network status */ + NETWORK_ON, /** network connection */ + NETWORK_OFF, /** network disconnection */ + NETWORK_CHANGE /** change ip/proxy information */ +} FW_NETWORK_STATUS; + +/** + * @brief Enumerations for the information about current network connection type provided by sync-agent-framework + */ +typedef enum { + NETWORK_NONE = 0, /** initial network type */ + NETWORK_3G_ON, /** network UMTS on */ + NETWORK_3G_OFF, /** network UMTS off */ + NETWORK_WIFI_ON, /** network WIFI on */ + NETWORK_WIFI_ON_NOT_CONNECTED, /** network WIFI on but not connected */ + NETWORK_WIFI_OFF, /** network WIFI off */ + NETWORK_WIFI_3G_ON, /** network UMTS and WIFI on */ +} FW_NETWORK_TYPE; + +#endif /* EXT_NA_NETWORKSTATUS_H_ */ diff --git a/framework/include/NetworkAccess/IN_NA_FW_Callbacks.h b/framework/include/NetworkAccess/IN_NA_FW_Callbacks.h new file mode 100644 index 0000000..d67a602 --- /dev/null +++ b/framework/include/NetworkAccess/IN_NA_FW_Callbacks.h @@ -0,0 +1,60 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Seokgil Kang + */ +#ifndef IN_NA_FW_CALLBACKS_H_ +#define IN_NA_FW_CALLBACKS_H_ + +/** + * @brief Set current network status (callback function used in slp-sysnoti-plugIn) + * @param[in] na_plugIn_id NetworkAccess PlugIn ID , means protocol type + * @param[in] fw_network_status Network status + * @param[in] fw_network_type Network type + * @param[in] proxy Proxy information + * @param[in] ip Ip information + * @return Operation result + * @retval 1 Successful + * @retval 0 Operation failed + */ +int handle_Network_Status(int na_plugIn_id, int fw_network_status, int fw_network_type, char *proxy, char *ip); + +/** + * @brief Request cancel and disconnect connection about all network session (callback function used in slp-sysnoti-plugIn) + * @param[in] na_plugIn_id NetworkAccess PlugIn ID , means protocol type + * @return Operation result + * @retval 1 Successful + * @retval 0 Operation failed + */ +int handle_Network_All_Cancel(int na_plugIn_id); + +#endif /* IN_NA_FW_CALLBACKS_H_ */ diff --git a/framework/include/NetworkAccess/IN_NA_Session_Manager.h b/framework/include/NetworkAccess/IN_NA_Session_Manager.h new file mode 100755 index 0000000..b1c20ce --- /dev/null +++ b/framework/include/NetworkAccess/IN_NA_Session_Manager.h @@ -0,0 +1,247 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Seokgil Kang + */ +#ifndef IN_NA_SESSION_MANAGER_H_ +#define IN_NA_SESSION_MANAGER_H_ + +#include +#include +#include + +#include "NetworkAccess/EXT_NA_NetworkStatus.h" + +/* + * @brief structure for multiple sessions management + */ +typedef struct { + GList *session_info_list; + char *ip; + char *proxy; + FW_NETWORK_STATUS fw_network_status; + FW_NETWORK_TYPE fw_network_type; +} NA_Session_Manager; + +/* + * @brief session information + */ +typedef struct { + int session_id; + void *session; + void *msg; + int timeout; + char *id; + char *password; +} NA_Session_Info; + +/* + * @brief initialize session manager + */ +void init_session_manager(); + +/* + * @brief destroy session manager + */ +void destroy_session_manager(); + +/* + * @brief create session information + * @param[out] session address of session in session information + * @return operation result + * @retval 1 success + * @retval -1 fail + */ +int create_session_info(void **session); + +/* + * @brief provide session id for the created session + * @param[out] session_id session id to provide the user + * @return operation result + * @retval 1 success + * @retval -1 fail + */ +int provide_session_id(unsigned int *session_id); + +/* + * @brief get session by using session id + * @param[in] session_id session id to provide the user + * @param[out] session address of session in session information + * @return operation result + * @retval 1 success + * @retval -1 fail + */ +int get_session(unsigned int session_id, void **session); + +/* + * @brief set session by using session id + * @param[in] session_id session id to provide the user + * @param[in] session address of session in session information + * @return operation result + * @retval 1 success + * @retval -1 fail + */ +int set_session(unsigned int session_id, void *session); + +/* + * @brief get current network status + * @return information about current network status provided by framework + * @retval NETWORK_UNKNOWN initial network status + * @retval NETWORK_ON network connection + * @retval NETWORK_OFF network disconnection + * @retval NETWORK_CHANGE change ip/proxy information + */ +FW_NETWORK_STATUS get_network_status(); + +/* + * @brief set current network status (exception case : for mobex) + * @param[in] information about current network status provided by framework + * @return operation result + * @retval 1 success + * @retval -1 fail + */ +int set_network_status(FW_NETWORK_STATUS network_status); + +/* + * @brief get current network type + * @return information about current network connection type provided by framework + * @retval NETWORK_NONE initial network type + * @retval NETWORK_3G_ON network UMTS on + * @retval NETWORK_3G_OFF network UMTS off + * @retval NETWORK_WIFI_ON network WIFI on + * @retval NETWORK_WIFI_ON_NOT_CONNECTED network WIFI on but not connected + * @retval NETWORK_WIFI_OFF network WIFI off + * @retval NETWORK_WIFI_3G_ON network UMTS and WIFI on + */ +FW_NETWORK_TYPE get_network_type(); + +/* + * @brief get current proxy information + * @return current proxy information + * @retval current proxy information (ex> http://xxx.xxx.xxx.xxx or https://xxx.xxx.xxx.xxx) + */ +char *get_proxy(); + +/* + * @brief get message by using session id + * @param[in] session_id session id to provide the user + * @param[out] msg message + * @return operation result + * @retval 1 success + * @retval -1 fail + */ +int get_msg(unsigned int session_id, void **msg); + +/* + * @brief get timeout time by using session id + * @param[in] session_id session id to provide the user + * @param[out] timeout timeout time + * @return operation result + * @retval 1 success + * @retval -1 fail + */ +int get_timeout(unsigned int session_id, int *timeout); + +/* + * @brief set timeout time + * @param[in] session_id session id to provide the user + * @param[in] timeout timeout time + * @return operation result + * @retval 1 success + * @retval -1 fail + */ +int set_timeout(unsigned int session_id, int timeout); + +/* + * @brief get user id and password by using session id (not used) + * @param[in] session_id session id to provide the user + * @param[out] id user id + * @param[out] password user password + * @return operation result + * @retval 1 success + * @retval -1 fail + */ +int get_id_n_password(unsigned int session_id, char **id, char **password); + +/* + * @brief set user id and password for authentication at EAS + * @param[in] session_id session id to provide the user + * @param[in] id user id + * @param[in] password user password + * @return operation result + * @retval 1 success + * @retval -1 fail + */ +int set_id_n_password(unsigned int session_id, char *id, char *password); + +/* + * @brief get all sessions in session manager + * @param[out] session_list list of sessions + * @return operation result + * @retval 1 success + * @retval -1 fail + */ +int get_all_session(GList **session_list); + +/* + * @brief remove session information that has specific session id + * @param[in] session_id session id to provide the user + * @param[in] flag ( 1 : need not session memory free, 0 : need session memory free ) + * @return operation result + * @retval 1 success + * @retval -1 fail + */ +int remove_session_info(unsigned int session_id, int flag); + +/* + * @brief remove all session information + * @param[in] flag ( 1 : need not session memory free, 0 : need session memory free ) + * @return operation result + * @retval 1 success + * @retval -1 fail + */ +int remove_all_session_info(int flag); + +/* + * @brief set network information (network status/type) in session manager + * @param[in] protocol_type protocol type (ex> FW_HTTP, FW_MOBEX, ...) + * @param[in] net_status network status + * @param[in] net_type network type + * @param[in] proxy proxy information + * @param[in] ip ip information + * @return operation result + * @retval 1 success + * @retval -1 fail + */ +int set_network_info(int na_plugIn_id, int net_status, int net_type, char *proxy, char *ip); + +#endif /* IN_NA_SESSION_MANAGER_H_ */ diff --git a/framework/include/NetworkAccess/NACI.h b/framework/include/NetworkAccess/NACI.h new file mode 100644 index 0000000..ec0263b --- /dev/null +++ b/framework/include/NetworkAccess/NACI.h @@ -0,0 +1,341 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Seokgil Kang + */ + +#ifndef NACI_H_ +#define NACI_H_ + +#include +#include +#include + +#include "NACI_Common.h" + +/** + * @file NACI.h + * @brief Defines network data communication APIs + */ + +/** + * @code + +#include "agent-framework/NetworkAccess/NACI.h" +#include "agent-framework/NetworkAccess/NA_External.h" + +int main() +{ + NACI_RESULT res = NACI_SUCCESS; + + GList *header_list = NULL; + GList *recv_header = NULL; + char *send_msg = "xxxxxxx"; + char *recv_msg = NULL; + unsigned int recv_msg_length = 0; + char *content_value = NULL; + unsigned int session_id = 0; + int na_plugIn_id = 1; // defined each agent-config.xml files + + char *ip = "http://xxx.xxx.xxx.xxx"; + char *id = "abcd"; + char *pw = "1234"; + + // init NACI + res = NACI_Init(); + if (res != NACI_SUCCESS) { + // exception handling + } + + // open connection + res = NACI_Open_Connection(na_plugIn_id, 300, &session_id); + if (res != NACI_SUCCESS) { + // exception handling + } + + // add user authentication information - used if necessary + res = NACI_Add_Authentication_Info(na_plugIn_id, id, pw, session_id); + if (res != NACI_SUCCESS) { + // exception handling + } + + // header binding - these elements are necessary to configure the header information !! + key : "method" value : "options" / "get" / "head" / "post" / "put" / "delete" / "trace" / "connect" + key : "uri" value : ip address (ex> "http://xxx.xxx.xxx.xxx") + common_header_info *method = (common_header_info*)malloc(sizeof(common_header_info)); + if (method == 0x00) { + // exception handling + } + memset(method, 0x00, sizeof(common_header_info)); + + method->key = "method"; + method->value = "post"; + header_list = g_list_append(header_list, method); + + common_header_info *uri = (common_header_info*)malloc(sizeof(common_header_info)); + if (uri == 0x00) { + // exception handling + } + memset(uri, 0x00, sizeof(common_header_info)); + + uri->key = "uri"; + uri->value = ip; + header_list = g_list_append(header_list, uri); + + // test - check header information + GList *iter = NULL; + for (iter = header_list; iter != NULL; iter = g_list_next(iter)) { + fprintf(stdout, "key : %s, \t value : %s\n", ((common_header_info*)(iter->data))->key, ((common_header_info*)(iter->data))->value); + } + + // send message + res = NACI_Send_Msg(header_list, + na_plugIn_id, + send_msg, + strlen(send_msg), + &recv_header, + &recv_msg, + &recv_msg_length, + SEND_N_RECEIVE, + session_id); + + switch (res) { + case NACI_SUCCESS : + break; + case NACI_NETWORK_UNAVAILABLE : + // exception handling + break; + case NACI_HEADER_BINDING_FAIL : + // exception handling + break; + case NACI_SEND_MSG_FAIL : + // exception handling + break; + case NACI_TIME_OUT_SEND_MSG : + // exception handling + break; + case NACI_SEND_MSG_CANCEL : + // exception handling + break; + case NACI_SEND_MSG_TRY_AGAIN : + // exception handling + break; + case NACI_HEADER_UNBINDING_FAIL : + // exception handling + break; + default : + break; + } + + ... + + // get header information + res = NACI_Get_Header_Info(na_plugIn_id, recv_header, "Content", &content_value); + if (res != NACI_SUCCESS) { + // exception handling + } + + // free header information received from server + res = NACI_Free_Recv_Header_Info(recv_header); + if (res != NACI_SUCCESS) { + // exception handling + } + + // close connection + res = NACI_Close_Connection(na_plugIn_id, session_id); + if (res != NACI_SUCCESS) { + // exception handling + } + + // destroy NACI + res = NACI_Destroy(); + if (res != NACI_SUCCESS) { + // exception handling + } + + return 0; +} +* @endcode +*/ + +/** + * @brief Initialize NACI + * @remarks Run only once at the beginning of the process + * @param[in] na_plugIn_id NetworkAccess PlugIn ID, means protocol type + * @return Operation result + * @retval NACI_SUCCESS Successful + * @retval NACI_FAIL Operation failed + */ +NACI_RESULT NACI_Init(int na_plugIn_id); + +/** + * @brief Open network connection (ex> create http session / create socket ...) + * @param[in] na_plugIn_id NetworkAccess PlugIn ID, means protocol type + * @param[in] timeout Set user preferred time-out seconds used in sending message (ex> 30 : means 30sec) + * @param[out] session_id Session id to provide the user + * @return Operation result + * @retval NACI_SUCCESS Successful + * @retval NACI_OPEN_CONNECTION_FAIL Open connection failed + */ +NACI_RESULT NACI_Open_Connection(int na_plugIn_id, int timeout, unsigned int *session_id); + +/** + * @brief Close network connection (ex> close http session / close socket ...) + * @param[in] na_plugIn_id NetworkAccess PlugIn ID, means protocol type + * @param[in] session_id Session id to provide the user + * @return Operation result + * @retval NACI_SUCCESS Successful + * @retval NACI_CLOSE_CONNECTION_FAIL Close connection failed + */ +NACI_RESULT NACI_Close_Connection(int na_plugIn_id, unsigned int session_id); + +/** + * @brief Send message to server + * 1. Header binding for network protocol + * 2, Send message to server + * 3. Receive message from server + * 4. Divide header and body information from the received message + * @param[in] header_info Header information that depending on the protocol type + * @param[in] na_plugIn_id NetworkAccess PlugIn ID, means protocol type + * @param[in] send_msg Body message + * @param[in] send_msg_length Length of body message + * @param[out] recv_header Header information (key - value pair) of received message + * @param[out] recv_msg Body information of received message + * @param[out] recv_msg_length Length of received body message + * @param[in] send_type Type of send message + * @param[in] session_id Session id to provide the user + * @return Operation result + * @retval NACI_SUCCESS Successful + * @retval NACI_NETWORK_UNAVAILABLE Network Unavailable (fail to send message) + * @retval NACI_HEADER_BINDING_FAIL Header binding failed + * @retval NACI_SEND_MSG_FAIL Send message failed - send_type : SEND_N_RECEIVE + * @retval NACI_TIME_OUT_SEND_MSG Send message failed (failure due to timeout) - send_type : SEND_N_RECEIVE + * @retval NACI_SEND_MSG_CANCEL Send message failed (failure due to cancel operation request) - send_type : SEND_N_RECEIVE + * @retval NACI_SEND_MSG_TRY_AGAIN Send message failed (failure due to over the number of retries (3) for send message) - send_type : SEND_N_RECEIVE + * @retval NACI_JUST_SEND_MSG_FAIL Send message failed - send_type : JUST_SEND + * @retval NACI_HEADER_UNBINDING_FAIL Header unbinding failed + */ +NACI_RESULT NACI_Send_Msg(GList *header_info, int na_plugIn_id, char *send_msg, unsigned int send_msg_length, GList **recv_header, unsigned char **recv_msg, unsigned int *recv_msg_length, NACI_SEND_TYPE send_type, unsigned int session_id); + +/** + * @brief Cancel operation about message being sent to the server + * @remarks This API is must called by other thread + * @param[in] na_plugIn_id NetworkAccess PlugIn ID, means protocol type + * @param[in] session_id Session id to provide the user + * @return Operation result + * @retval NACI_SUCCESS Successful + * @retval NACI_CANCEL_MSG_FAIL Cancel message sending operation is failed + */ +NACI_RESULT NACI_Cancel_Msg(int na_plugIn_id, unsigned int session_id); + +/** + * @brief Destroy NACI + * @remarks Run only once at the end of the process + * @return Operation result + * @retval NACI_SUCCESS Successful + * @retval NACI_FAIL Operation failed + * @pre The application should be called NACI_Init() and returned NACI_SUCCESS + */ +NACI_RESULT NACI_Destroy(); + +/** + * @brief Get network header information about specific keyword + * @param[in] na_plugIn_id NetworkAccess PlugIn ID, means protocol type + * @param[in] header_info List of network header information (key-value pair) + * @param[in] key Specific keyword of header information that user want to know + * @param[out] value Value for the key + * @return Operation result + * @retval NACI_SUCCESS Successful + * @retval NACI_GET_HEADER_INFO_FAIL Operation failed + * @pre The application should be called NACI_Send_Msg() and returned NACI_SUCCESS + */ +NACI_RESULT NACI_Get_Header_Info(int na_plugIn_id, GList *header_info, char *key, char **value); + +/** + * @brief Memory free for the header information received from the server + * @param[in] header_info Header information received from the server + * @return Operation result + * @retval NACI_SUCCESS Successful + * @retval NACI_FAIL Operation failed + * @pre The application should be called NACI_Get_Header_Info() and returned NACI_SUCCESS + */ +NACI_RESULT NACI_Free_Recv_Header_Info(GList *header_info); + +/** + * @brief Check the current network status provided by sync-agent-framework + * @param[in] interval Interval time for checking network status (ex> 3 : 3sec) + * @param[in] retry_cnt The number of retries for checking network status + * @return Operation result + * @retval NACI_SUCCESS Network is available + * @retval NACI_NETWORK_UNAVAILABLE Network is unavailable + */ +NACI_RESULT NACI_Check_Network_Status(int interval, int retry_cnt); + +/** + * @brief Get current network type provided by sync-agent-framework + * @param[in] net_type Current network type + * @return Operation result + * @retval NACI_SUCCESS Successful + * @retval NACI_FAIL Operation failed + */ +NACI_RESULT NACI_Get_Network_Type(int *net_type); + +/** + * @brief Download data from server + * @param[in] header_info Header information that depending on the protocol type + * @param[in] na_plugIn_id NetworkAccess PlugIn ID, means protocol type + * @param[in] download_folder Folder path for download + * @param[in] download_start_size Download start size + * @param[in] download_body_size Download message size + * @param[out] out_download_path File path to download + * @param[in] send_type Type of send message + * @param[in] session_id Session id to provide the user + * @return Operation result + * @retval NACI_SUCCESS Successful + * @retval NACI_DOWNLOAD_DATA_FAIL Operation failed + */ +NACI_RESULT NACI_Download_Data(GList *header_info, int na_plugIn_id, unsigned char *download_folder, unsigned int download_start_size, unsigned int download_body_size, unsigned char **out_download_path, NACI_SEND_TYPE send_type, unsigned int session_id); + +/** + * @brief Add user authentication information (id, password) to session and + * register authentication callback for 'authenticate' signal + * @param[in] na_plugIn_id NetworkAccess PlugIn ID, means protocol type + * @param[in] id User id + * @param[in] password User password + * @param[in] session_id Session id to provide the user + * @return Operation result + * @retval NACI_SUCCESS Successful + * @retval NACI_ADD_AUTH_INFO_FAIL Operation failed + */ +NACI_RESULT NACI_Add_Authentication_Info(int na_plugIn_id, char *id, char *password, unsigned int session_id); + +#endif /* NACI_H_ */ diff --git a/framework/include/NetworkAccess/NACI_Common.h b/framework/include/NetworkAccess/NACI_Common.h new file mode 100755 index 0000000..ae11d64 --- /dev/null +++ b/framework/include/NetworkAccess/NACI_Common.h @@ -0,0 +1,54 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Seokgil Kang + */ + +#ifndef NACI_COMMON_H_ +#define NACI_COMMON_H_ + +#include "NACI_Errors.h" + +/** + * @file NACI_Common.h + * @brief Support to send message to the server + */ + +/** + * @brief Enumerations for the type of sending message + */ +typedef enum { + SEND_N_RECEIVE = 0, /** general process */ + JUST_SEND, /** specific process (send only) */ +} NACI_SEND_TYPE; + +#endif /* NACI_COMMON_H_ */ diff --git a/framework/include/NetworkAccess/NACI_Errors.h b/framework/include/NetworkAccess/NACI_Errors.h new file mode 100755 index 0000000..1e06c40 --- /dev/null +++ b/framework/include/NetworkAccess/NACI_Errors.h @@ -0,0 +1,72 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Seokgil Kang + */ + +#ifndef NACI_ERRORS_H_ +#define NACI_ERRORS_H_ + +/** + * @file NACI_Errors.h + * @brief Defines NACI errors + */ + +/** + * @brief Enumerations for the NACI error + */ +typedef enum { + NACI_SUCCESS = 1, + + NACI_FAIL = -1000, + + NACI_NETWORK_UNAVAILABLE = -1001, + NACI_INIT_FAIL = -1002, + NACI_OPEN_CONNECTION_FAIL = -1003, + NACI_HEADER_BINDING_FAIL = -1004, + NACI_SEND_MSG_FAIL = -1005, + NACI_SEND_MSG_CANCEL = -1006, + NACI_JUST_SEND_MSG_FAIL = -1007, + NACI_HEADER_UNBINDING_FAIL = -1008, + NACI_CLOSE_CONNECTION_FAIL = -1009, + NACI_CANCEL_MSG_FAIL = -1010, + NACI_GET_HEADER_INFO_FAIL = -1011, + NACI_DOWNLOAD_DATA_FAIL = -1012, + + /* for http */ + NACI_TIME_OUT_SEND_MSG = -1100, + NACI_SEND_MSG_TRY_AGAIN = -1101, + NACI_ADD_AUTH_INFO_FAIL = -1102, + +} NACI_RESULT; + +#endif /* NACI_ERRORS_H_ */ diff --git a/framework/include/NetworkAccess/NA_External.h b/framework/include/NetworkAccess/NA_External.h new file mode 100755 index 0000000..001f53d --- /dev/null +++ b/framework/include/NetworkAccess/NA_External.h @@ -0,0 +1,53 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Seokgil Kang + */ + +#ifndef NA_EXTERNALL_H_ +#define NA_EXTERNAL_H_ + +/** + * @file NA_External.h + * @brief Defines common network header setting + */ + +/** + * @brief Structure for the network protocol header information setting + * @remarks Key-value pair + */ +typedef struct { + char *key; + char *value; +} common_header_info; + +#endif /* NA_EXTERNAL_H_ */ diff --git a/framework/include/NetworkAssistant/protocol_binder/protocol_binder.h b/framework/include/NetworkAssistant/protocol_binder/protocol_binder.h new file mode 100755 index 0000000..f79eb7c --- /dev/null +++ b/framework/include/NetworkAssistant/protocol_binder/protocol_binder.h @@ -0,0 +1,242 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * SeongWon Shim + */ + +#ifndef PROTOCOL_BINDER_H_ +#define PROTOCOL_BINDER_H_ + +#include "protocol_binder_common.h" + +/* binder function set */ + +/** + * @brief Initialize binder function set + * @param[in] binder_function_cnt Count of binder function + * @param[in] info_array Binder_function_info + * @param[out] pBinder_function_set Binder_function_set + * @return 0 on success, otherwise a negative error value. + * @retval PROTOCOL_BINDER_OK Successful + * @retval PROTOCOL_BINDER_OUT_OF_MEMORY Out of memory + */ +PROTOCOL_BINDER_ERROR init_binder_function_set(unsigned int binder_function_cnt, Binder_function_info *info_array, Binder_function_set **pBinder_function_set); + +/** + * @brief Ignore previous binder function set built and rebuild binder function set with new function informations + * @param[in] pBinder_functino_set Binder function set + * @param[in] new_binder_function_info_cnt Number of new binder function informations + * @param[in] new_info_array Array of new binder function informations + * @return 0 on success, otherwise a negative error value. + * @retval PROTOCOL_BINDER_OK Successful + * @retval PROTOCOL_BINDER_OUT_OF_MEMORY Out of memory + */ +PROTOCOL_BINDER_ERROR reset_binder_function_set(Binder_function_set *pBinder_function_set, unsigned int new_binder_function_info_cnt, Binder_function_info *new_info_array); + +/** + * @brief Add more function informations to binder function set + * @remarks you should notice that if same value of protocol_element + * or protocol_element_xml_name are already existed in binder function set, + * then previous information is removed from binder function set + * @param[in] pBinder_functino_set Binder function set + * @param[in] binder_function_info_cnt Number of new binder function informations to be added + * @param[in] info_array_to_be_added Array of new binder function informations to be added + * @return 0 on success, otherwise a negative error value. + * @retval PROTOCOL_BINDER_OK Successful + * @retval PROTOCOL_BINDER_OUT_OF_MEMORY Out of memory + */ +PROTOCOL_BINDER_ERROR add_binder_function_set(Binder_function_set *pBinder_function_set, unsigned int binder_function_info_cnt, Binder_function_info *info_array_to_be_added); + +/** + * @brief Free binder function set + * @param[in] pBinder_function_set Binder_function_set + */ +void free_binder_function_set(Binder_function_set *pBinder_function_set); + +/* protocol binder */ + +/** + * @brief Initialize protocol binder + * @param[in] pBinder protocol_binder + * @param[in] protocol Protocol enum value + * @param[in] option Function pointer of Protocol_Option_Ptr + * @param[in] enc Encoding enum value + * @param[in] encode_xml_header Whether need XML header encoding or not + * @param[in] use_strtbl Whether use string table or not + * @param[in] produce_anonymous whether produce an anonymous document or not + * @param[in] use_flow_mode Whether use flow mode or not + * @param[in] restrict_params List of restrict parameter + * @param[in] restrict_condition_checker Function pointer of restrict condition + * @param[in] pBinder_function_set Binder_function_set + * @return protocol_binder on success, NULL on fail + */ +protocol_binder *protocol_binder_init(protocol_binder *pBinder, Protocol protocol, Protocol_Option_Ptr option, Encoding enc, bool encode_xml_header, bool use_strtbl, bool produce_anonymous, bool use_flow_mode, GList *restrict_params, Restrict_Condition_Checker_callback restrict_condition_checker, Binder_function_set *pBinder_function_set); + +/** + * @brief Append specific XML element to WBXMLTree + * @remarks Process callback function that has registered to Binder_function_set + * pContent by pass to callback function + * @param[in] pBinder protocol_binder + * @param[in] protocol_element Protocol_Element + * @param[in] pContent Structure that need to append to WBXMLTree + * @return 0 on success, otherwise a negative error value. + * @retval PROTOCOL_BINDER_OK Successful + * @retval PROTOCOL_BINDER_NOT_DEFINED Invalid parameter(pBinder) + * @retval PROTOCOL_BINDER_BINDER_FUNCTION_SET_NOT_DEFINED Binder Function Set is not defined + * @retval PROTOCOL_BINDER_APPEND_INVALID_PROTOCOL_ELEMENT Invalid protocol element + * @retval PROTOCOL_BINDER_UNKNOWN_ERROR + */ +PROTOCOL_BINDER_ERROR protocol_binder_append(protocol_binder *pBinder, Protocol_Element protocol_element, Content_Ptr pContent); + +/** + * @brief Terminate protocol binder + * @param[in] pBinder protocol_binder + */ +void protocol_binder_terminate(protocol_binder *pBinder); + +/** + * @brief Get stream from protocol binder + * @param[in] pBinder protocol_binder + * @param[out] byte_stream Encoded stream + * @param[out] byte_stream_size Size of Encoded stream + * @return 0 on success, otherwise a negative error value. + * @retval PROTOCOL_BINDER_OK Successful + * @retval PROTOCOL_BINDER_NOT_DEFINED Invalid parameter(pBinder) + * @retval PROTOCOL_BINDER_INVALID_INPUT_PARAMETER Invalid parameter + * @retval PROTOCOL_BINDER_UNKNOWN_ERROR + */ +PROTOCOL_BINDER_ERROR protocol_binder_get_stream(protocol_binder *pBinder, char **byte_stream, unsigned int *byte_stream_size); + +/** + * @brief Get XML stream from protocol binder + * @remarks Only support when protocol binder encoding == ENCODING_WBXML_XX + * @param[in] pBinder protocol_binder + * @param[out] xml XML + * @param[out] xml_size Size of XML + * @return 0 on success, otherwise a negative error value. + * @retval PROTOCOL_BINDER_OK Successful + * @retval PROTOCOL_BINDER_NOT_DEFINED Invalid parameter(pBinder) + * @retval PROTOCOL_BINDER_NOT_SUPPORT_FOR_XML_ENCODING Encoding type is ENCODING_XML + * @retval PROTOCOL_BINDER_UNKNOWN_ERROR + */ +PROTOCOL_BINDER_ERROR protocol_binder_get_xml_for_debugging(protocol_binder *pBinder, char **xml, unsigned int *xml_size); + +/** + * @brief Get stream size from protocol binder + * @param[in] pBinder protocol_binder + * @param[out] byte_stream_size Size of byte stream + * @return 0 on success, otherwise a negative error value. + * @retval PROTOCOL_BINDER_OK Successful + * @retval PROTOCOL_BINDER_NOT_DEFINED Invalid parameter(pBinder) + * @retval PROTOCOL_BINDER_INVALID_INPUT_PARAMETER Invalid parameter + * @retval PROTOCOL_BINDER_UNKNOWN_ERROR + */ +PROTOCOL_BINDER_ERROR protocol_binder_get_stream_size(protocol_binder *pBinder, unsigned int *byte_stream_size); + +/** + * @brief Get encoding type protocol binder + * @param[in] pBinder protocol_binder + * @param[out] enc Encoding enum value + * @return 0 on success, otherwise a negative error value. + * @retval PROTOCOL_BINDER_OK Successful + * @retval PROTOCOL_BINDER_NOT_DEFINED Invalid parameter(pBinder) + */ +PROTOCOL_BINDER_ERROR protocol_binder_get_encoding(protocol_binder *pBinder, Encoding * enc); + +/* reverse protocol binder */ + +/** + * @brief Initialize reverse protocol binder + * @param[in] byte_stream WBXML or XML byte stream + * @param[in] byte_stream_len Length of byte stream + * @param[in] dec Type of Decoding(DECODING_XML, DECODING_WBXML) + * @param[in] pProtocol Protocol Enum value(which Protocol) + * @param[in] pBinder_function_set Binder_function_set + * @param[in] user_data + * @param[out] ppBinder Reverse_protocol_binder + * @return 0 on success, otherwise a negative error value. + * @retval PROTOCOL_BINDER_OK Successful + * @retval PROTOCOL_BINDER_INVALID_INPUT_PARAMETER Invalid parameter + * @retval PROTOCOL_BINDER_UNKNOWN_ENCODING Unknown Encoding type + * @retval PROTOCOL_BINDER_OUT_OF_MEMORY Out of memory + */ +PROTOCOL_BINDER_ERROR reverse_protocol_binder_init(char *byte_stream, unsigned int byte_stream_len, Decoding dec, Protocol * pProtocol, Binder_function_set *pBinder_function_set, void *user_data, Reverse_protocol_binder **ppBinder); + +/** + * @brief Set user data to reverse protocol binder + * @param[in] pBinder Reverse_protocol_binder + * @param[in] user_data User data + */ +void reverse_protocol_binder_set_user_data(Reverse_protocol_binder *pBinder, void *user_data); + +/** + * @brief get user data from reverse protocol binder + * @param[in] pBinder Reverse_protocol_binder + * @return void* on success + */ +void *reverse_protocol_binder_get_user_data(Reverse_protocol_binder *pBinder); + +/** + * @brief Process next registered XML element related callback function and get structure as a result + * @param[in] pBinder Reverse_protocol_binder + * @param[in] protocol_element Protocol_Element + * @param[out] protocol_element_name XML element name + * @param[out] pContent Structure as a callback process result + * @return 0 on success, otherwise a negative error value. + * @retval PROTOCOL_BINDER_OK Successful + * @retval PROTOCOL_BINDER_HAS_NO_MORE_ELEMENT No more XML element + * @retval PROTOCOL_BINDER_OUT_OF_MEMORY Out of memory + */ +PROTOCOL_BINDER_ERROR reverse_protocol_binder_next(Reverse_protocol_binder *pBinder, Protocol_Element * protocol_element, char **protocol_element_name, Content_Ptr *pContent); + +/** + * @brief Terminate Reverse protocol binder + * @param[in] pBinder Reverse_protocol_binder + */ +void reverse_protocol_binder_terminate(Reverse_protocol_binder *pBinder); + +/** + * @brief Get XML stream from reverse protocol binder + * @remarks Only support when protocol binder encoding == ENCODING_WBXML_XX + * @param[in] pBinder Reverse_protocol_binder + * @param[out] xml XML + * @param[out] xml_size Size of XML + * @return 0 on success, otherwise a negative error value. + * @retval PROTOCOL_BINDER_OK Successful + * @retval PROTOCOL_BINDER_NOT_DEFINED Invalid parameter(pBinder) + * @retval PROTOCOL_BINDER_INIT_REQUIRED_OR_INVALID_BINDER Invalid parameter(pBinder) + * @retval PROTOCOL_BINDER_NOT_SUPPORT_FOR_XML_DECODING Encoding type is ENCODING_XML + * @retval PROTOCOL_BINDER_UNKNOWN_ERROR + */ +PROTOCOL_BINDER_ERROR reverse_protocol_binder_get_xml_for_debugging(Reverse_protocol_binder *pBinder, char **xml, unsigned int *xml_size); + +#endif /* PROTOCOL_BINDER_H_ */ diff --git a/framework/include/NetworkAssistant/protocol_binder/protocol_binder_common.h b/framework/include/NetworkAssistant/protocol_binder/protocol_binder_common.h new file mode 100755 index 0000000..f9420da --- /dev/null +++ b/framework/include/NetworkAssistant/protocol_binder/protocol_binder_common.h @@ -0,0 +1,47 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * SeongWon Shim + */ + +#ifndef PROTOCOL_BINDER_COMMON_H_ +#define PROTOCOL_BINDER_COMMON_H_ + +/* common includes */ +#include + +/* our includes */ +#include "protocol_binder_definition.h" +#include "protocol_binder_error.h" +#include "protocol_binder_util.h" + +#endif /* PROTOCOL_BINDER_COMMON_H_ */ diff --git a/framework/include/NetworkAssistant/protocol_binder/protocol_binder_definition.h b/framework/include/NetworkAssistant/protocol_binder/protocol_binder_definition.h new file mode 100755 index 0000000..84b6b65 --- /dev/null +++ b/framework/include/NetworkAssistant/protocol_binder/protocol_binder_definition.h @@ -0,0 +1,161 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * SeongWon Shim + */ + +#ifndef PROTOCOL_BINDER_DEFINITION_H_ +#define PROTOCOL_BINDER_DEFINITION_H_ + +#include +#include +#include "protocol_binder_error.h" +#include +#include +#include +#include + +typedef void *Content_Ptr; +typedef void *Protocol_Option_Ptr; +typedef unsigned int Protocol_Element; + +/* common definition */ + +/** + * @brief Enumerations of encoding type + */ +typedef enum { + ENCODING_UNKNOWN = 0, + ENCODING_XML, /**< XML*/ + ENCODING_WBXML_10, /**< WBXML 1.0*/ + ENCODING_WBXML_11, /**< WBXML 1.1*/ + ENCODING_WBXML_12, /**< WBXML 1.2*/ + ENCODING_WBXML_13 /**< WBXML 1.3*/ +} Encoding; + +/** + * @brief Enumerations of decoding type + */ +typedef enum { + DECODING_UNKNOWN = 0, + DECODING_XML, /**< XML*/ + DECODING_WBXML /**< WBXML*/ +} Decoding; + +/** + * @brief Enumerations of Protocol that supports by Protocol binder + */ +typedef enum { + PROTOCOL_UNKNOWN = 0, + PROTOCOL_SYNCML_SYNCML10, /**< SYNCML1.0*/ + PROTOCOL_SYNCML_SYNCML11, /**< SYNCML1.1*/ + PROTOCOL_SYNCML_SYNCML12, /**< SYNCML1.2*/ + + PROTOCOL_SYNCML_DEVINF10, /**< SYNCML Device Information 1.0*/ + PROTOCOL_SYNCML_DEVINF11, /**< SYNCML Device Information 1.1*/ + PROTOCOL_SYNCML_DEVINF12, /**< SYNCML Device Information 1.2*/ + + PROTOCOL_SYNCML_METINF10, /**< SYNCML Meta Information 1.0*/ + PROTOCOL_SYNCML_METINF11, /**< SYNCML Meta Information 1.1*/ + PROTOCOL_SYNCML_METINF12, /**< SYNCML Meta Information 1.2*/ + + PROTOCOL_SYNCML_DMDDF12, /**< SYNCML DM DDF 1.2*/ + + PROTOCOL_ACTIVESYNC, /**< EAS*/ + + PROTOCOL_PROV10, /**< EAS Provisioning*/ + + PROTOCOL_MAX_COUNT /**< for counting supporting protocol*/ +} Protocol; + +/* protocol binder */ + +/** + * @brief Structure for protocol binder + */ +typedef struct _protocol_binder protocol_binder; + +/** + * @brief Restrict Condition Checker callback + * @param[in] enc Encoding enum value + * @param[in] option Protocol_Option_Ptr + * @param[in] restrict_params List of restrict parameter + * @param[in] arguments List of parameter + */ +typedef bool (*Restrict_Condition_Checker_callback) (Encoding enc, Protocol_Option_Ptr option, GList *restrict_params, GList *arguments); + +/** + * @brief Binder Object converter function + * @param[in] pBinder protocol_binder + * @param[in] pContent Void pointer + * @param[in] ppWbxml_dom_node WBXMLTreeNode + */ +typedef PROTOCOL_BINDER_ERROR(*Binder_Object_converter_function) (protocol_binder *pBinder, Content_Ptr pContent, WBXMLTreeNode **ppWbxml_dom_node); + +/* reverse protocol binder */ + +/*typedef struct _Reverse_binder_function_info Reverse_binder_function_info;*/ +/*typedef struct _Reverse_binder_function_set Reverse_binder_function_set;*/ + +/** + * @brief Structure for reverse protocol binder + */ +typedef struct _Reverse_protocol_binder Reverse_protocol_binder; + +/** + * @brief Reverse Binder Object converter function + * @param[in] pReverse_binder Reverse_protocol_binder + * @param[in] wbxml_dom_node WBXMLTreeNode + * @param[in] pContent Content_Ptr + */ +typedef PROTOCOL_BINDER_ERROR(*Reverse_Binder_Object_converter_function) (Reverse_protocol_binder *pReverse_binder, WBXMLTreeNode *wbxml_dom_node, Content_Ptr *pContent); + +/* protocol binder & reverse protocol binder callback */ + +/** + * @brief Structure for Binder function set + */ +typedef struct _Binder_function_set Binder_function_set; + +/** + * @brief Structure for Binder function info + */ +typedef struct _Binder_function_info Binder_function_info; +struct _Binder_function_info { + Protocol_Element protocol_element; + char *protocol_element_xml_name; + Binder_Object_converter_function binder_object_converter_function; + Reverse_Binder_Object_converter_function reverse_binder_object_converter_function; + bool isTerminal; +}; + +#endif /* PROTOCOL_BINDER_DEFINITION_H_ */ diff --git a/framework/include/NetworkAssistant/protocol_binder/protocol_binder_error.h b/framework/include/NetworkAssistant/protocol_binder/protocol_binder_error.h new file mode 100755 index 0000000..7fca01f --- /dev/null +++ b/framework/include/NetworkAssistant/protocol_binder/protocol_binder_error.h @@ -0,0 +1,84 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * SeongWon Shim + */ + +#ifndef PROTOCOL_BINDER_ERROR_H_ +#define PROTOCOL_BINDER_ERROR_H_ + +/** + * @brief Enumerations of error code for protocol binder + */ +typedef enum { + PROTOCOL_BINDER_OK = 0, /**< Successful */ + PROTOCOL_BINDER_HAS_NO_MORE_ELEMENT = 1, /**< No more XML Element */ + + PROTOCOL_BINDER_UNKNOWN_ERROR, /**< Unknown Error */ + PROTOCOL_BINDER_OUT_OF_MEMORY, /**< Out of memory */ + PROTOCOL_BINDER_NOT_DEFINED, /**< Something that have to be defined is not defined */ + PROTOCOL_BINDER_INIT_REQUIRED_OR_INVALID_BINDER, + PROTOCOL_BINDER_UNKNOWN_ENCODING, /**< Unknown Encoding type */ + + PROTOCOL_BINDER_NOT_SUPPORT_FOR_XML_ENCODING, /**< Not Support for XML encoding */ + PROTOCOL_BINDER_NOT_SUPPORT_FOR_XML_DECODING, /**< Not Support for XML decoding */ + + PROTOCOL_BINDER_UNKNOWN_LANGUAGE, /**< Unknown Language */ + PROTOCOL_BINDER_WBXML_PARSE_FAIL, /**< WBXML Parse Fail */ + PROTOCOL_BINDER_XML_PARSE_FAIL, /**< XML Parse Fail */ + PROTOCOL_BINDER_INVALID_XML, /**< Invalid XML */ + PROTOCOL_BINDER_BINDER_FUNCTION_SET_NOT_DEFINED, /**< Function Set Not Defined */ + PROTOCOL_BINDER_BINDER_FUNCTION_SET_LOOKUP_TBL_NOT_DEFINED, /**< Lookup table has not defined */ + + PROTOCOL_BINDER_INVALID_PROTOCOL, /**< Invalid Protocol */ + PROTOCOL_BINDER_INVALID_CONTENT, /**< Invalid Content */ + + PROTOCOL_BINDER_UNEXPECTED_CASE_ACCORDING_TO_PROTOCOL_SPEC, + + PROTOCOL_BINDER_ALREADY_SWITCH_PROTOCOL, /**< Operation failed */ + PROTOCOL_BINDER_HAS_NO_UNDO_SWITCH_PROTOCOL, /**< Operation failed */ + PROTOCOL_BINDER_INVALID_PROTOCOL_ELEMENT, /**< Invalid protocol element */ + PROTOCOL_BINDER_APPEND_INVALID_PROTOCOL_ELEMENT, /**< Invalid protocol element */ + + PROTOCOL_BINDER_INVALID_INPUT_PARAMETER, /**< Invalid input parameter */ + + PROTOCOL_BINDER_TREE_NODE_IS_NOT_ELEMENT_NODE, /**< Invalid parameter */ + + PROTOCOL_BINDER_TREE_ALREADY_HAS_ROOT, /**< Already has root in WBXMLTree */ + + /* protocol binder error */ + PROTOCOL_BINDER_UTIL_NO_TEXT_VALUE, /* TODO remove */ + PROTOCOL_BINDER_UTIL_NO_BINARY_VALUE, /**, + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * SeongWon Shim + */ + +#ifndef PROTOCOL_BINDER_INTERNAL_H_ +#define PROTOCOL_BINDER_INTERNAL_H_ + +#include "protocol_binder_common.h" +#include "protocol_binder.h" +#include +#include + +/* protocol binder */ + +/** + * @brief Structure for Binder function set + */ +struct _Binder_function_set { + unsigned int set_size; + Binder_function_info *info_array; + + GHashTable *protocol_element_lookup_tbl; + GHashTable *protocol_element_xml_name_lookup_tbl; +}; + +/** + * @brief Structure for protocol binder + */ +struct _protocol_binder { + Protocol protocol; + Protocol_Option_Ptr option; + Encoding enc; + bool encode_xml_header; /* use only when enc = ENCODING_XML */ + bool use_strtbl; /* use only when enc = ENCODING_WBXML_... */ + bool produce_anonymous; /* use only when enc = ENCODING_WBXML_... */ + bool use_flow_mode; + GList *restrict_params; + Restrict_Condition_Checker_callback restrict_condition_checker; + Binder_function_set *binder_functions; + + WBXMLLangEntry *lang_table; + WBXMLLangEntry *prev_lang_table; + /* use only if flow_mode = false */ + WBXMLTree *tree; + + /* use only if flow mode = true */ + WBXMLEncoder *wbxml_encoder; + + GSList *tree_node_stack; + bool is_current_node_terminal; +}; + +/* reverse protocol binder */ + +/** + * @brief Structure for reverse protocol binder + */ +struct _Reverse_protocol_binder { + Protocol protocol; + Decoding dec; + Binder_function_set *binder_functions; + void *user_data; + + WBXMLTree *tree; /* TODO : replace this part to our code */ + GSList *tree_stack; /* this part is needed for traversing wbxml tree with two language */ + WBXMLTreeNode *current_tree_node; /* TODO : replace this part to our code */ + bool current_tree_node_first_visit; + + bool no_tree_node_visited; + bool all_tree_node_visited; +}; + +#endif /* PROTOCOL_BINDER_INTERNAL_H_ */ diff --git a/framework/include/NetworkAssistant/protocol_binder/protocol_binder_util.h b/framework/include/NetworkAssistant/protocol_binder/protocol_binder_util.h new file mode 100755 index 0000000..eeadbc7 --- /dev/null +++ b/framework/include/NetworkAssistant/protocol_binder/protocol_binder_util.h @@ -0,0 +1,321 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * SeongWon Shim + */ + +#ifndef PROTOCOL_BINDER_UTIL_H_ +#define PROTOCOL_BINDER_UTIL_H_ + +#include +#include "protocol_binder_error.h" +#include "protocol_binder_definition.h" +#include "protocol_binder.h" + +/* protocol binder property managing functions */ +/** + * @brief Change protocol + * @param[in] pBinder Structure(protocol_binder) + * @param[in] protocol Enum value that means specific protocol + * @return 0 on success, otherwise a negative error value. + * @retval PROTOCOL_BINDER_OK Successful + * @retval PROTOCOL_BINDER_NOT_DEFINED Invalid parameter(pBinder) + * @retval PROTOCOL_BINDER_INVALID_PROTOCOL Invalid parameter(protocol) + * @retval PROTOCOL_BINDER_ALREADY_SWITCH_PROTOCOL Operation failed + */ +PROTOCOL_BINDER_ERROR switch_protocol(protocol_binder *pBinder, Protocol protocol); + +/** + * @brief Go back to previous protocol + * @param[in] pBinder Structure(protocol_binder) + * @return 0 on success, otherwise a negative error value. + * @retval PROTOCOL_BINDER_OK Successful + * @retval PROTOCOL_BINDER_NOT_DEFINED Invalid parameter(pBinder) + * @retval PROTOCOL_BINDER_HAS_NO_UNDO_SWITCH_PROTOCOL Operation failed + */ +PROTOCOL_BINDER_ERROR undo_switch_protocol(protocol_binder *pBinder); + +/* wbxml dom tree building functions */ +/** + * @brief Create WBXMLTree using information in protocol_binder structure + * @param[in] pBinder Structure(protocol_binder) + * @return WBXMLTree on success, NULL on fail + */ +WBXMLTree *create_wbxml_tree(const protocol_binder *pBinder); + +/** + * @brief Add WBXMLTree to WBXMLTreeNode as a subree + * @param[in] parent_node WBXMLTreeNode + * @param[in] tree WBXMLTree + * @return 0 on success, otherwise a negative error value. + * @retval PROTOCOL_BINDER_OK Successful + * @retval PROTOCOL_BINDER_INVALID_INPUT_PARAMETER Invalid parameter(parent_node, tree) + * @retval PROTOCOL_BINDER_OUT_OF_MEMORY Out of memory + */ +PROTOCOL_BINDER_ERROR add_wbxml_tree_to_wbxml_node(WBXMLTreeNode *parent_node, WBXMLTree *tree); + +/** + * @brief Set root node of WBXMLTree + * @param[in] tree WBXMLTree + * @param[in] node WBXMLTreeNode + * @return 0 on success, otherwise a negative error value. + * @retval PROTOCOL_BINDER_OK Successful + * @retval PROTOCOL_BINDER_INVALID_INPUT_PARAMETER Invalid parameter(parent_node, tree) + * @retval PROTOCOL_BINDER_TREE_ALREADY_HAS_ROOT + */ +PROTOCOL_BINDER_ERROR set_wbxml_tree_root(WBXMLTree *tree, WBXMLTreeNode *node); + +/** + * @brief Create WBXMLTreeNode using XML element name + * @param[in] pBinder protocol_binder + * @param[in] xml_name XML element name + * @return WBXMLTreeNode on success, NULL on fail + */ +WBXMLTreeNode *create_wbxml_node_using_xml_name(const protocol_binder *pBinder, const char *xml_name); + +/** + * @brief Create WBXMLTreeNode using XML element name and XML name space + * @param[in] pBinder protocol_binder + * @param[in] xml_name XML element name + * @param[in] namespace XML name space + * @return WBXMLTreeNode on success, NULL on fail + */ +WBXMLTreeNode *create_wbxml_node_using_xml_name_and_namespace(const protocol_binder *pBinder, const char *xml_name, const char *namespace); + +/** + * @brief Create WBXMLTreeNode using XML element name with text content + * @param[in] pBinder protocol_binder + * @param[in] xml_name XML element name + * @param[in] text Content + * @param[in] text_len Length of Content + * @return WBXMLTreeNode on success, NULL on fail + */ +WBXMLTreeNode *create_wbxml_node_using_xml_name_with_text(const protocol_binder *pBinder, const char *xml_name, const char *text, unsigned int text_len); + +/** + * @brief Create WBXMLTreeNode using XML element name and XML name space with text content + * @param[in] pBinder protocol_binder + * @param[in] xml_name XML element name + * @param[in] namespace XML name space + * @param[in] text Content + * @param[in] text_len Length of Content + * @return WBXMLTreeNode on success, NULL on fail + */ +WBXMLTreeNode *create_wbxml_node_using_xml_name_and_namespace_with_text(const protocol_binder *pBinder, const char *xml_name, const char *namespace, const char *text, unsigned int text_len); + +/** + * @brief Create WBXMLTreeNode using XML element name with cdata content + * @param[in] pBinder protocol_binder + * @param[in] xml_name XML element name + * @param[in] text Content + * @param[in] text_len Length of Content + * @return WBXMLTreeNode on success, NULL on fail + */ +WBXMLTreeNode *create_wbxml_node_using_xml_name_with_cdata(const protocol_binder *pBinder, const char *xml_name, const char *text, unsigned int text_len); + +/** + * @brief Create WBXMLTreeNode using XML element name, and add WBXMLTreeNode to parent node as a child node + * @param[in] pBinder protocol_binder + * @param[in] parent_node Parent node + * @param[in] xml_name XML element name + * @return WBXMLTreeNode on success, NULL on fail + */ +WBXMLTreeNode *add_child_wbxml_node_using_xml_name(const protocol_binder *pBinder, WBXMLTreeNode *parent_node, const char *xml_name); + +/** + * @brief Create WBXMLTreeNode using XML element name and XML name space, and add WBXMLTreeNode to parent node as a child node + * @param[in] pBinder protocol_binder + * @param[in] parent_node Parent node + * @param[in] xml_name XML element name + * @param[in] namespace XML name space + * @return WBXMLTreeNode on success, NULL on fail + */ +WBXMLTreeNode *add_child_wbxml_node_using_xml_name_and_namespace(const protocol_binder *pBinder, WBXMLTreeNode *parent_node, const char *xml_name, const char *namespace); + +/** + * @brief Create WBXMLTreeNode using XML element name with text content, and add WBXMLTreeNode to parent node as a child node + * @param[in] pBinder protocol_binder + * @param[in] parent_node Parent node + * @param[in] xml_name XML element name + * @param[in] text Content + * @param[in] text_len Length of Content + * @return WBXMLTreeNode on success, NULL on fail + */ +WBXMLTreeNode *add_child_wbxml_node_using_xml_name_with_text(const protocol_binder *pBinder, WBXMLTreeNode *parent_node, const char *xml_name, const char *text, unsigned int text_len); + +/** + * @brief Create WBXMLTreeNode using XML element name and XML name space with text content, and add WBXMLTreeNode to parent node as a child node + * @param[in] pBinder protocol_binder + * @param[in] parent_node Parent node + * @param[in] xml_name XML element name + * @param[in] namespace XML name space + * @param[in] text Content + * @param[in] text_len Length of Content + * @return WBXMLTreeNode on success, NULL on fail + */ +WBXMLTreeNode *add_child_wbxml_node_using_xml_name_and_namespace_with_text(const protocol_binder *pBinder, WBXMLTreeNode *parent_node, const char *xml_name, const char *namespace, const char *text, unsigned int text_len); + +/** + * @brief Create WBXMLTreeNode using XML element name with cdata content, and add WBXMLTreeNode to parent node as a child node + * @param[in] pBinder protocol_binder + * @param[in] parent_node Parent node + * @param[in] xml_name XML element name + * @param[in] text Content + * @param[in] text_len Length of Content + * @return WBXMLTreeNode on success, NULL on fail + */ +WBXMLTreeNode *add_child_wbxml_node_using_xml_name_with_cdata(const protocol_binder *pBinder, WBXMLTreeNode *parent_node, const char *xml_name, const char *text, unsigned int text_len); + +/** + * @brief Create WBXMLTreeNode using XML element name with int content, and add WBXMLTreeNode to parent node as a child node + * @param[in] pBinder protocol_binder + * @param[in] parent_node Parent node + * @param[in] xml_name XML element name + * @param[in] num Content + * @return WBXMLTreeNode on success, NULL on fail + */ +WBXMLTreeNode *add_child_wbxml_node_using_xml_name_with_int(const protocol_binder *pBinder, WBXMLTreeNode *parent_node, const char *xml_name, const int num); + +/** + * @brief Create WBXMLTreeNode using XML element name with int content, and add WBXMLTreeNode to parent node as a child node + * @param[in] pBinder protocol_binder + * @param[in] parent_node Parent node + * @param[in] xml_name XML element name + * @param[in] namespace XML name space + * @param[in] num Content + * @return WBXMLTreeNode on success, NULL on fail + */ +WBXMLTreeNode *add_child_wbxml_node_using_xml_name_and_namespace_with_int(const protocol_binder *pBinder, WBXMLTreeNode *parent_node, const char *xml_name, const char *namespace, const int num); + +/** + * @brief Create WBXMLTreeNode using XML element name with unsigned int content, and add WBXMLTreeNode to parent node as a child node + * @param[in] pBinder protocol_binder + * @param[in] parent_node Parent node + * @param[in] xml_name XML element name + * @param[in] num Content + * @return WBXMLTreeNode on success, NULL on fail + */ +WBXMLTreeNode *add_child_wbxml_node_using_xml_name_with_unsigned_int(const protocol_binder *pBinder, WBXMLTreeNode *parent_node, const char *xml_name, const unsigned int num); + +/** + * @brief Create WBXMLTreeNode using XML element name and XML name space with unsigned int content, and add WBXMLTreeNode to parent node as a child node + * @param[in] pBinder protocol_binder + * @param[in] parent_node Parent node + * @param[in] xml_name XML element name + * @param[in] namespace XML name space + * @param[in] num Content + * @return WBXMLTreeNode on success, NULL on fail + */ +WBXMLTreeNode *add_child_wbxml_node_using_xml_name_and_namespace_with_unsigned_int(const protocol_binder *pBinder, WBXMLTreeNode *parent_node, const char *xml_name, const char *namespace, const unsigned int num); + +/** + * @brief Add WBXMLTreeNode to parent node as a child node + * @param[in] parent Parent node + * @param[in] child Child node + * @return WBXMLTreeNode on success, NULL on fail + */ +bool wbxml_node_add_child_node(WBXMLTreeNode *parent, WBXMLTreeNode *child); + +/* wbxml dom tree getter functions */ + +/** + * @brief Get XML element name from WBXMLTreeNode + * @param[in] element_node WBXMLTreeNode + * @param[out] element_xml_name XML element name + * @return 0 on success, otherwise a negative error value. + * @retval PROTOCOL_BINDER_OK Successful + * @retval PROTOCOL_BINDER_TREE_NODE_IS_NOT_ELEMENT_NODE Invalid parameter(element_node) + */ +PROTOCOL_BINDER_ERROR get_xml_name_from_element_wbxml_node(const WBXMLTreeNode *element_node, char **element_xml_name); + +/** + * @brief Get XML name space from WBXMLTreeNode + * @param[in] pBinder Reverse_protocol_binder + * @param[in] element_node WBXMLTreeNode + * @param[out] namespace XML name space + * @return 0 on success, otherwise a negative error value. + * @retval PROTOCOL_BINDER_OK Successful + * @retval PROTOCOL_BINDER_TREE_NODE_IS_NOT_ELEMENT_NODE Invalid parameter(element_node) + */ +PROTOCOL_BINDER_ERROR get_namespace_from_element_wbxml_node(const Reverse_protocol_binder *pBinder, const WBXMLTreeNode *element_node, char **namespace); + +/** + * @brief Get pointer of text content from WBXMLTreeNode + * @param[in] element_node WBXMLTreeNode + * @param[out] text_pointer Pointer of text content + * @return 0 on success, otherwise a negative error value. + * @retval PROTOCOL_BINDER_OK Successful + */ +PROTOCOL_BINDER_ERROR get_text_pointer_from_wbxml_node(WBXMLTreeNode *element_node, char **text_pointer); + +/** + * @brief Get pointer of binary content from WBXMLTreeNode + * @param[in] element_node WBXMLTreeNode + * @param[out] binary_pointer Pointer of binary content + * @param[out] binary_size Size of binary content + * @return 0 on success, otherwise a negative error value. + * @retval PROTOCOL_BINDER_OK Successful + * @retval PROTOCOL_BINDER_UTIL_NO_BINARY_VALUE Invalid parameter(element_node) + */ +PROTOCOL_BINDER_ERROR get_binary_pointer_from_wbxml_node(WBXMLTreeNode *element_node, char **binary_pointer, unsigned int *binary_size); + +/** + * @brief Get int content from WBXMLTreeNode + * @param[in] element_node WBXMLTreeNode + * @param[out] value Int content + * @return 0 on success, otherwise a negative error value. + * @retval PROTOCOL_BINDER_OK Successful + * @retval PROTOCOL_BINDER_UTIL_NO_INT_VALUE Invalid parameter(element_node) + */ +PROTOCOL_BINDER_ERROR get_int_from_wbxml_node(WBXMLTreeNode *element_node, int *value); + +/** + * @brief Get pointer of text content from WBXMLTreeNode(cdata node) + * @param[in] element_node WBXMLTreeNode + * @param[out] text_pointer Pointer of text content + * @return 0 on success, otherwise a negative error value. + * @retval PROTOCOL_BINDER_OK Successful + */ +PROTOCOL_BINDER_ERROR get_text_pointer_from_wbxml_cdata_node(WBXMLTreeNode *element_node, char **text_pointer); + +/** + * @brief Get pointer of binary content from WBXMLTreeNode(cdata node) + * @param[in] element_node WBXMLTreeNode + * @param[out] binary_pointer Pointer of binary content + * @param[out] binary_size Size of binary content + * @return 0 on success, otherwise a negative error value. + * @retval PROTOCOL_BINDER_OK Successful + * @retval PROTOCOL_BINDER_UTIL_NO_BINARY_VALUE Invalid parameter(element_node) + */ +PROTOCOL_BINDER_ERROR get_binary_pointer_from_wbxml_cdata_node(WBXMLTreeNode *element_node, char **binary_pointer, unsigned int *binary_size); + +#endif /* PROTOCOL_BINDER_UTIL_H_ */ diff --git a/framework/include/NetworkAssistant/protocol_binder/protocol_binder_util_internal.h b/framework/include/NetworkAssistant/protocol_binder/protocol_binder_util_internal.h new file mode 100755 index 0000000..c5576c3 --- /dev/null +++ b/framework/include/NetworkAssistant/protocol_binder/protocol_binder_util_internal.h @@ -0,0 +1,151 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * SeongWon Shim + */ + +#ifndef PROTOCOL_BINDER_UTIL_INTERNAL_H_ +#define PROTOCOL_BINDER_UTIL_INTERNAL_H_ + +#include "protocol_binder_util.h" + +/** + * @brief XML document adjusting + * @remarks Remove XML header from XML msg + * @param[in] Pointer of XML message + * @param[in] Length of XML + * @return Length of XML after remove header + */ +unsigned int remove_xml_header(char *xml, unsigned int xml_len); + +/* wbxml related part */ +/** + * @brief Validate protocol + * @remarks Validate that protocol is supported by portocol binder + * @param[in] protocol Enum value that means specific protocol + * @return True on success, False on fail + */ +bool validate_protocol(Protocol protocol); + +/** + * @brief Get WBXMLLanguage enum value + * @remarks Convert to WBXMLLanguage from Protocol + * @param[in] Enum value that means specific protocol + * @return WBXMLLanguage enum value on success + */ +WBXMLLanguage get_wbxml_language(Protocol protocol); + +/** + * @brief Get Protocol enum value + * @remarks Convert to Protocol from WBXMLLanguage + * @param[in] WBXMLLanguage enum value + * @return Protocol enum value on success + */ +Protocol get_protocol_from_wbxml_lang(WBXMLLanguage wbxml_lang); + +/** + * @brief Get WBXMLVersion enum value + * @remarks Convert to WBXMLVersion from Encoding + * @param[in] WBXMLVersion enum value + * @return WBXMLVersion enum value on success + */ +WBXMLVersion get_wbxml_version(Encoding enc); + +/** + * @brief Get WBXML tree from WBXML byte stream + * @remarks Parse WBXML byte stream and build WBXMLTree + * @param[in] byte_stream Byte stream of WBXML message + * @param[in] byte_stream_len Length of WBXML message + * @param[in] wbxml_lang WBXMLLanguage enum value + * @param[out] wbxml_tree WBXMLTree + * @return 0 on success, otherwise a negative error value. + * @retval PROTOCOL_BINDER_OK Successful + * @retval PROTOCOL_BINDER_WBXML_PARSE_FAIL Parse failed + */ +PROTOCOL_BINDER_ERROR get_wbxml_tree_from_wbxml(char *byte_stream, int byte_stream_len, WBXMLLanguage wbxml_lang, WBXMLTree **wbxml_tree); + +/** + * @brief Get WBXML tree from XML byte stream + * @remarks Parse WBXML byte stream and build WBXMLTree using libwbxml library + * @param[in] byte_stream Byte stream of XML message + * @param[in] byte_stream_len Length of XML message + * @param[in] wbxml_lang WBXMLLanguage enum value + * @param[out] wbxml_tree WBXMLTree + * @return 0 on success, otherwise a negative error value. + * @retval PROTOCOL_BINDER_OK Successful + * @retval PROTOCOL_BINDER_WBXML_PARSE_FAIL Parse failed + */ +PROTOCOL_BINDER_ERROR get_wbxml_tree_from_xml(char *byte_stream, int byte_stream_len, WBXMLLanguage wbxml_lang, WBXMLTree **wbxml_tree); + +/** + * @brief Get next WBXMLTreeNode from current WBXMLTreeNode + * @remarks if current WBXMLTreeNode's type is + * WBXML_TREE_TREE_NODE(WBXMLTree has a subtree as a tree node), + * use this API to get next WBXMLTreeNode of subtree + * @param[in] node Current WBXMLTreeNode + * @param[out] first_visit Whether first visit for this tree node or not + * @return WBXMLTreeNode on success + */ +WBXMLTreeNode *get_next_node_of_tree_node(WBXMLTreeNode *node, bool *first_visit); + +/** + * @brief Get next WBXMLTreeNode from current WBXMLTreeNode + * @remarks if current WBXMLTreeNode's type is not WBXML_TREE_TREE_NODE, + * use this API to get next WBXMLTreeNode of current WBXMLTreeNode + * @param[in] node Current WBXMLTreeNode + * @param[out] first_visit Whether first visit for this tree node or not + * @return WBXMLTreeNode on success + */ +WBXMLTreeNode *get_next_node_of_element_node(WBXMLTreeNode *node, bool *first_visit); + +/** + * @brief Get WBXMLLangEntry of subtree + * @param[in] pReverse_binder Reverse_protocol_binder + * @return WBXMLLangEntry on success + */ +const WBXMLLangEntry *get_current_subtree_lang(Reverse_protocol_binder *pReverse_binder); + +/** + * @brief whether node has a same type as inputted type + * @param[in] node WBXMLTreeNode + * @param[in] type WBXMLTreeNodeType + * @return true is node has a type which is inputted, false is not + */ +bool has_wbxml_node_same_type(WBXMLTreeNode *node, WBXMLTreeNodeType type); + +/** + * @brief print XML from current WBXMLTree + * @param[in] tree WBXMLTree + */ +void print_wbxml_dom_in_xml(const WBXMLTree *tree); + +#endif /* PROTOCOL_BINDER_UTIL_INTERNAL_H_ */ diff --git a/framework/include/PlatformMonitor/EXT_PMCI.h b/framework/include/PlatformMonitor/EXT_PMCI.h new file mode 100755 index 0000000..69d7a0c --- /dev/null +++ b/framework/include/PlatformMonitor/EXT_PMCI.h @@ -0,0 +1,162 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Seokgil Kang + */ + +#ifndef EXT_PMCI_H_ +#define EXT_PMCI_H_ + +#include +#include +#include + +#include "EXT_PMCI_Common.h" + +/** + * @file EXT_PMCI.h + * @brief Defines service platform notification APIs + */ + +/** + * @brief Destroy default platform notification + * @remarks Network notification is only supported currently + * @param[in] pm_plugIn_id PlatformMonitor PlugIn ID + * @return Operation result + * @retval PMCI_SUCCESS Successful + * @retval PMCI_FAIL Operation failed + */ +PMCI_RETURN PMCI_Destroy_Default_Noti_Types(int pm_plugIn_id); + +/** + * @brief Prototype of callback function for platform notification + * @remarks This callback function must be implemented by user + * @param[out] item_id Item id (It is only used in ALARM service) + * @param[out] user_data Data that is passed to the user + * @return Operation result + * @retval 1 Successful + * @retval 0 Operation failed + * @see EXT_PMCI_Struct.h + */ +typedef int (*SPECIFIC_TYPE_CALLBACK) (int item_id, void *user_data); + +/** + * @brief Initialize specific platform notification + * @remarks Connect to the service and register user notification callback function to the service + * @param[in] pm_plugIn_id PlatformMonitor PlugIn ID + * @param[in] noti_type Platform notification type defined in FW_PLATFORM_NOTI_TYPE + * @param[in] pkg_name Package name (ex> com.samsung.test) + * @param[in] user_data Some data for passing to the service + * @param[in] callback_cnt The number of callback functions + * @param[in] ... Variable number of callback functions (type : 'SPECIFIC_TYPE_CALLBACK') + * @return Operation result + * @retval PMCI_SUCCESS Successful + * @retval PMCI_FAIL Operation failed + * @see EXT_PMCI_Noti.h + * + * @code + +1. noti_type : NETWORK + +int network_on_callback(int item_id, void *user_data); +int network_off_callback(int item_id, void *user_data); +PMCI_RETURN ret = PMCI_Init_Specific_Type(1, NETWORK, NULL, NULL, 2, network_on_callback, network_off_callback); + +2. noti_type : SAN + +int san_incoming_callback(int item_id, void *user_data); +int san_operation_callback(int item_id, void *user_data); +PMCI_RETURN ret = PMCI_Init_Specific_Type(1, SAN, NULL, NULL, 2, san_incoming_callback, san_operation_callback); + +3. noti_type : ALARM + +int alarm_callback(int item_id, void *user_data); +PMCI_RETURN ret = PMCI_Init_Specific_Type(1, ALARM, "package_name", NULL, 1, alarm_callback); + + * @endcode + */ +PMCI_RETURN PMCI_Init_Specific_Type(int pm_plugIn_id, FW_SERVICE_NOTI_TYPE noti_type, const char *pkg_name, const char *user_data, int callback_cnt, ...); + +/** + * @brief Unregister user notification callback function that was previously registered to the service and disconnect to the service + * @param[in] pm_plugIn_id PlatformMonitor PlugIn ID + * @param[in] noti_type Platform notification type defined in FW_PLATFORM_NOTI_TYPE + * @return Operation result + * @retval PMCI_SUCCESS Successful + * @retval PMCI_FAIL Operation failed + * @pre The application should be called PMCI_Init_Specific_Type() and returned PMCI_SUCCESS + * @see EXT_PMCI_Noti.h + */ +PMCI_RETURN PMCI_Destory_Specific_Type(int pm_plugIn_id, FW_SERVICE_NOTI_TYPE noti_type); + +/** + * @brief Add item to the service that was previously initialized by user using 'PMCI_Init_Specific_Type()' + * @param[in] pm_plugIn_id PlatformMonitor PlugIn ID + * @param[in] noti_type Platform notification type defined in FW_PLATFORM_NOTI_TYPE + * @param[in] add_item Item to add to the service + * @param[out] out_add_item_id Id of the newly Item added to the service + * @return Operation result + * @retval PMCI_SUCCESS Successful + * @retval PMCI_FAIL Operation failed + * @pre The application should be called PMCI_Init_Specific_Type() and returned PMCI_SUCCESS + * @see EXT_PMCI_Noti.h, EXT_PMCI_Struct.h + */ +PMCI_RETURN PMCI_Add_Item_To_Specific_Type(int pm_plugIn_id, FW_SERVICE_NOTI_TYPE noti_type, void *add_item, int *out_add_item_id); + +/** + * @brief Remove item from the service + * @param[in] pm_plugIn_id PlatformMonitor PlugIn ID + * @param[in] noti_type Platform notification type defined in FW_PLATFORM_NOTI_TYPE + * @param[in] remove_item_id Id of Item that user want to remove from service + * @return Operation result + * @retval PMCI_SUCCESS Successful + * @retval PMCI_FAIL Operation failed + * @pre The application should be called PMCI_Init_Specific_Type() and returned PMCI_SUCCESS + * @see EXT_PMCI_Noti.h + */ +PMCI_RETURN PMCI_Remove_Item_To_Specific_Type(int pm_plugIn_id, FW_SERVICE_NOTI_TYPE noti_type, int remove_item_id); + +/** + * @brief Get item that user want to know from the service + * @param[in] pm_plugIn_id PlatformMonitor PlugIn ID + * @param[in] noti_type Platform notification type defined in FW_PLATFORM_NOTI_TYPE + * @param[in] get_item_id Id of the item that user want to know + * @param[out] out_get_item Item that user want to know + * @return Operation result + * @retval PMCI_SUCCESS Successful + * @retval PMCI_FAIL Operation failed + * @pre The application should be called PMCI_Init_Specific_Type() and returned PMCI_SUCCESS + * @see EXT_PMCI_Noti.h, EXT_PMCI_Struct.h + */ +PMCI_RETURN PMCI_Get_Item_To_Specific_Type(int pm_plugIn_id, FW_SERVICE_NOTI_TYPE noti_type, int get_item_id, void **out_get_item); + +#endif /* EXT_PMCI_H_ */ diff --git a/framework/include/PlatformMonitor/EXT_PMCI_Common.h b/framework/include/PlatformMonitor/EXT_PMCI_Common.h new file mode 100755 index 0000000..f48a053 --- /dev/null +++ b/framework/include/PlatformMonitor/EXT_PMCI_Common.h @@ -0,0 +1,47 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Seokgil Kang + */ + +#ifndef EXT_PMCI_COMMON_H_ +#define EXT_PMCI_COMMON_H_ + +#include "EXT_PMCI_Errors.h" +#include "EXT_PMCI_Noti.h" + +/** + * @file EXT_PMCI_Common.h + * @brief Includes header files needed for using PMCI APIs + */ + +#endif /* EXT_PMCI_COMMON_H_ */ diff --git a/framework/include/PlatformMonitor/EXT_PMCI_Errors.h b/framework/include/PlatformMonitor/EXT_PMCI_Errors.h new file mode 100755 index 0000000..cf2d5cb --- /dev/null +++ b/framework/include/PlatformMonitor/EXT_PMCI_Errors.h @@ -0,0 +1,52 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Seokgil Kang + */ + +#ifndef EXT_PMCI_ERRORS_H_ +#define EXT_PMCI_ERRORS_H_ + +/** + * @file EXT_PMCI_Errors.h + * @brief Defines PMCI errors + */ + +/** + * @brief Enumerations for the PMCI error + */ +typedef enum { + PMCI_SUCCESS, + PMCI_FAIL, +} PMCI_RETURN; + +#endif /* EXT_PMCI_ERRORS_H_ */ diff --git a/framework/include/PlatformMonitor/EXT_PMCI_Noti.h b/framework/include/PlatformMonitor/EXT_PMCI_Noti.h new file mode 100755 index 0000000..14d3c30 --- /dev/null +++ b/framework/include/PlatformMonitor/EXT_PMCI_Noti.h @@ -0,0 +1,53 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Seokgil Kang + */ + +#ifndef EXT_PMCI_NOTI_H_ +#define EXT_PMCI_NOTI_H_ + +/** + * @file EXT_PMCI_Noti.h + * @brief Defines notification types provided by sync-agent-framework + */ + +/** + * @brief Enumerations for the Service notification type + */ +typedef enum { + NETWORK, + SAN, /* Server Alert Notification */ + ALARM, +} FW_SERVICE_NOTI_TYPE; + +#endif /* EXT_PMCI_NOTI_H_ */ diff --git a/framework/include/PlatformMonitor/EXT_PMCI_Struct.h b/framework/include/PlatformMonitor/EXT_PMCI_Struct.h new file mode 100755 index 0000000..c114b3f --- /dev/null +++ b/framework/include/PlatformMonitor/EXT_PMCI_Struct.h @@ -0,0 +1,130 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Seokgil Kang + */ + +#ifndef EXT_PMCI_STRUCT_H_ +#define EXT_PMCI_STRUCT_H_ + +#include + +/** + * @file EXT_PMCI_Struct.h + * @brief Defines enumerations & structures for PMCI + */ + +#define DAY_CNT 7 + +/** + * @brief Enumerations for the day type + */ +typedef enum { + DAY_NO_TYPE = 0x00, + DAY_SUN = 0x01, + DAY_MON = 0x02, + DAY_TUE = 0x04, + DAY_WED = 0x08, + DAY_THU = 0x10, + DAY_FRI = 0x20, + DAY_SAT = 0x40 +} PMCI_DAY_TYPE; + +/** + * @brief Enumerations for the repeat type + */ +typedef enum { + REPEAT_NO_TYPE = 0, + ONCE = 1, + REPEAT, + REPEAT_WEEKLY, + REPEAT_MONTHLY, + REPEAT_ANNUALLY, +} PMCI_REPEAT_TYPE; + +/** + * @brief Alarm structure provided by sync-agent-framework + * @see PMCI_Add_Item_To_Specific_Type(), SPECIFIC_TYPE_CALLBACK + */ +typedef struct { + /* start alarm time : time to start alarm at first. + * format: 2011-01-02T15:13:02Z + */ + char *start_alarm_time; + + /* repeat type */ + PMCI_REPEAT_TYPE repeat_type; + + /* repeat value + * 1) repeat_type: ONCE => repeat_value: do not mean + * 1) repeat_type: REPEAT => repeat_value: interval time (second) + * 2) repeat_type: etc => repeat_value: PMCI_DAY_TYPE + */ + int repeat_value; + + int isDisposable; +} pmci_alarm_t; + +/** + * @brief Incoming data (SAN) structure provided by sync-agent-framework + * @remarks Notification data for 'SAN Incoming' operation + * @see SPECIFIC_TYPE_CALLBACK + */ +typedef struct { + const char *msgBody; + unsigned int msgSize; + int version; +} pmci_san_incoming_t; + +/** + * @brief Operation data (SAN) structure provided by sync-agent-framework + * @remarks Notification data for 'SAN Operation' operation + * @see SPECIFIC_TYPE_CALLBACK + */ +typedef struct { + int msgId; + int extId; + void *user_param; +} pmci_san_operation_t; + +/** + * @brief Message data (SAN) structure provided by sync-agent-framework + * @see PMCI_Add_Item_To_Specific_Type() + */ +/* SAN (send message) fw struct */ +typedef struct { + int extId; + int pinCode; + char *msgData; +} pmci_san_message_t; + +#endif /* EXT_PMCI_STRUCT_H_ */ diff --git a/framework/include/PlugIn/DataConverter_Resource.h b/framework/include/PlugIn/DataConverter_Resource.h new file mode 100644 index 0000000..1022db1 --- /dev/null +++ b/framework/include/PlugIn/DataConverter_Resource.h @@ -0,0 +1,65 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#ifndef DATACONVERTER_RESOURCE_H_ +#define DATACONVERTER_RESOURCE_H_ + +/** + * @file DataConverter_Resource.h + * @brief Support to share structure DataConverter plugIn with F/W + */ + +/** + * @brief Structure of Converter plugin's object's field - linked list + */ +struct Field_Info { + char *field_name; /**< field name */ + int field_child_cnt; /**< field's child count */ + struct Field_Info *field_child_list; /**< next field info node */ +}; + +/** + * @brief Structure of Converter plugin's Object info + */ +typedef struct { + char *type; /**< object type */ + char *version; /**< object version */ + int field_cnt; /**< field count */ + struct Field_Info *field_list; /**< real field list **/ +} Object_Info; + +typedef struct Field_Info Field_Info; + +#endif /* DATACONVERTER_RESOURCE_H_ */ diff --git a/framework/include/PlugIn/PlatformMonitor_Resource.h b/framework/include/PlugIn/PlatformMonitor_Resource.h new file mode 100644 index 0000000..5965347 --- /dev/null +++ b/framework/include/PlugIn/PlatformMonitor_Resource.h @@ -0,0 +1,57 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#ifndef PLATFORMMONITOR_RESOURCE_H_ +#define PLATFORMMONITOR_RESOURCE_H_ + +#ifdef dnet + typedef int (*CALLBACK_NETWORK_STATUS) (int dev_network_status, int fw_network_status, char *proxy, char *ip); +#endif + +typedef int (*CALLBACK_NETWORK_STATUS) (int protocol_type, int fw_network_status, int fw_network_type, char *proxy, char *ip); + +typedef int (*CALLBACK_NETWORK_CANCEL) (int protocol_type); + +typedef int (*CALLBACK_SYNCML_SAN_INCOMING) (int item_id, void *user_data); + +typedef int (*CALLBACK_SYNCML_SAN_OPERATION) (int item_id, void *user_data); + +typedef int (*CALLBACK_ALARM) (int alarm_id, void *user_data); + +typedef int (*CALLBACK_NETWORK_ON) (int item_id, void *user_data); + +typedef int (*CALLBACK_NETWORK_OFF) (int item_id, void *user_data); + +#endif /* PLATFORMMONITOR_RESOURCE_H_ */ diff --git a/framework/include/PlugIn/PlugIn_Account.h b/framework/include/PlugIn/PlugIn_Account.h new file mode 100755 index 0000000..5daeafb --- /dev/null +++ b/framework/include/PlugIn/PlugIn_Account.h @@ -0,0 +1,101 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#ifndef PLUGIN_ACCOUNT_H_ +#define PLUGIN_ACCOUNT_H_ + +#include "PlugIn_Error.h" +#include "PlugIn_Struct.h" + +typedef void (*Set_AccountReposioryName) (const char *agent_name); + +typedef void (*Add_PlatformAccount) (int fw_account_id, char *email, char *password, int create_mode); + +typedef void (*Set_PlatformAccount_Service) (int fw_account_id, int service_type, int service_account_id); + +typedef void (*Del_PlatformAccount) (int fw_account_id); + +typedef void (*Del_PlatformAccount_Service) (int fw_account_id, int service_type); + +typedef int (*Has_PlatformAccount_Service) (int fw_account_id, int service_type); + +typedef int (*Get_Service_AccountID) (int service_type, int fw_account_id); + +typedef int (*Get_FW_AccountID) (int service_type, int service_account_id, int index); + +typedef void *(*Get_Service_AccountInfo) (int fw_account_id, int service_type); + +typedef struct { + Set_AccountReposioryName pFunc_Set_AccountReposioryName; + Add_PlatformAccount pFunc_Add_PlatformAccount; + Set_PlatformAccount_Service pFunc_Set_PlatformAccount_Service; + Del_PlatformAccount pFunc_Del_PlatformAccount; + Del_PlatformAccount_Service pFunc_Del_PlatformAccount_Service; + Has_PlatformAccount_Service pFunc_Has_PlatformAccount_Service; + Get_Service_AccountID pFunc_Get_Service_AccountID; + Get_FW_AccountID pFunc_Get_FW_AccountID; + Get_Service_AccountInfo pFunc_Get_Service_AccountInfo; +} Account_Func_Set; + +typedef struct { + PlugIn_Info_t plugIn_info; + Account_Func_Set func_Set; +} PlugIn_Account; + +Account_Func_Set getAccount_Func_Set(void *plugIn_handle, PLUGIN_ERROR * error_code); + +PLUGIN_ERROR registerPlugIn_Account(PlugIn_Account plugIn); + +int getAccount_PlugIn_ID(); + +Set_AccountReposioryName getFunction_Set_AccountReposioryName(int plugIn_id); + +Add_PlatformAccount getFunction_Account_Add_PlatformAccount(int plugIn_id); + +Set_PlatformAccount_Service getFunction_Set_PlatformAccount_Service(int plugIn_id); + +Del_PlatformAccount getFunction_Account_Del_PlatformAccount(int plugIn_id); + +Del_PlatformAccount_Service getFunction_Account_Del_PlatformAccount_Service(int plugIn_id); + +Has_PlatformAccount_Service getFunction_Account_Has_PlatformAccount_Service(int plugIn_id); + +Get_Service_AccountID getFunction_Account_Get_Service_AccountID(int plugIn_id); + +Get_FW_AccountID getFunction_Account_Get_FW_AccountID(int plugIn_id); + +Get_Service_AccountInfo getFunction_Get_Service_AccountInfo(int plugIn_id); + +#endif /* PLUGIN_ACCOUNT_H_ */ diff --git a/framework/include/PlugIn/PlugIn_DataConnector.h b/framework/include/PlugIn/PlugIn_DataConnector.h new file mode 100755 index 0000000..3e780e3 --- /dev/null +++ b/framework/include/PlugIn/PlugIn_DataConnector.h @@ -0,0 +1,206 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#ifndef PLUGIN_DATACONNECTOR_H_ +#define PLUGIN_DATACONNECTOR_H_ + +#include "PlugIn_Error.h" +#include "PlugIn_Struct.h" +#include "PlugIn_Interface/DataConnector_Resource.h" +#include "DataAdapter/EXT_DACI_Errors.h" + +#define MAX_PLUGIN_DATACONNECTOR 20 + +typedef DACI_RETURN(*Service_Open) (void); +typedef DACI_RETURN(*Service_Close) (void); +typedef DACI_RETURN(*Begin_Transaction) (void); +typedef DACI_RETURN(*End_Transaction) (int is_success); + +typedef DACI_RETURN(*ADD_ITEM) (int account_ID, char *folder_id, void *data, char **item_id); +typedef DACI_RETURN(*UPDATE_ITEM) (int account_ID, char *folder_id, char *item_id, void *data); +typedef DACI_RETURN(*DEL_ITEM) (int account_ID, char *folder_id, char *item_id); +typedef DACI_RETURN(*DEL_ALL_ITEMS) (int account_ID); +typedef DACI_RETURN(*GET_ITEM) (int account_ID, char *folder_id, char *item_id, void **data); +typedef DACI_RETURN(*ADD_FOLDER) (int account_ID, const char *folder_name, int folder_type, char **folder_id); +typedef DACI_RETURN(*DEL_FOLDER) (int account_ID, const char *folder_id); +typedef DACI_RETURN(*GET_FOLDER) (int account_ID, const char *folder_id, char **folder_name, int *folder_type); +typedef DACI_RETURN(*EXECUTE) (int account_ID, const char *execute_key, void *execute_values, void **result); +typedef int (*GET_USED_ITEM_COUNT) (); +typedef int (*GET_USED_COUNT_FOR_FOLDER) (int account_ID, const char *folder_id); +typedef DACI_RETURN(*WRITE_ITEMS_TO_FILE) (int account_ID, char **file_path); +typedef DACI_RETURN(*ADD_FILE_WROTE_ITEMS_TO_DATASTORE) (int account_ID, const char *file_path); + +typedef char **(*GET_FOLDER_ID_LIST) (int account_ID, int *folder_count, int **folder_type_list); +typedef int *(*GET_ACCOUNT_ID_LIST) (int *count); +typedef Item_Node *(*GET_CHANED_ITEM_FOR_FOLDER_ADD) (int account_ID, const char *folder_id, int chagepoint, int *changeCount); +typedef Item_Node *(*GET_CHANED_ITEM_FOR_FOLDER_DEL) (int account_ID, const char *folder_id, int chagepoint, int *changeCount); +typedef Item_Node *(*GET_CHANED_ITEM_FOR_FOLDER_UPDATE) (int account_ID, const char *folder_id, int chagepoint, int *changeCount); + +typedef int (*GET_LAST_CHANGEPOINT) (); +typedef void (*StartListening_ChangeNoti) (void *filter_flag); +typedef void (*SetCallBack_AddItem) (CALLBACK_ADD_ITEM callback); +typedef void (*SetCallBack_DeleteItem) (CALLBACK_DEL_ITEM callback); +typedef void (*SetCallBack_UpdateItem) (CALLBACK_UPDATE_ITEM callback); +typedef void (*SetCallBack_GetAccountIDList) (GET_ACCOUNTIDLIST callback); + +/********************* Get Meta Info ******************/ +typedef int (*GET_MAX_ITEM_COUNT) (int folder_type); +typedef int (*GET_MAX_FIELD_LENGTH) (int field_name, int child_field_name); +typedef int (*GET_MAX_FIELD_COUNT) (int field_name, int child_field_name); +typedef int (*GET_FIELD_VALUE) (int field_name, int child_field_name, char **str_val, int *num_val1, int *num_val2); +typedef int (*GET_IS_SUPPORT_FEATURE) (int feature); + +typedef struct { + Service_Open pFunc_Service_Open; + Service_Close pFunc_Service_Close; + Begin_Transaction pFunc_Begin_Transaction; + End_Transaction pFunc_End_Transaction; + ADD_ITEM pFunc_ADD_ITEM; + UPDATE_ITEM pFunc_UPDATE_ITEM; + DEL_ITEM pFunc_DEL_ITEM; + DEL_ALL_ITEMS pFunc_DEL_ALL_ITEMS; + GET_ITEM pFunc_GET_ITEM; + ADD_FOLDER pFunc_ADD_FOLDER; + DEL_FOLDER pFunc_DEL_FOLDER; + GET_FOLDER pFunc_GET_FOLDER; + EXECUTE pFunc_EXECUTE; + GET_USED_ITEM_COUNT pFunc_GET_USED_ITEM_CNT; + GET_USED_COUNT_FOR_FOLDER pFunc_GET_USED_CNT_FOR_FOLDER; + WRITE_ITEMS_TO_FILE pFunc_WRITE_ITEMS_TO_FILE; + ADD_FILE_WROTE_ITEMS_TO_DATASTORE pFunc_ADD_FILE_WROTE_ITEMS_TO_DATASTORE; + + GET_FOLDER_ID_LIST pFunc_GET_FOLDER_ID_LIST; + GET_ACCOUNT_ID_LIST pFunc_GET_ACCOUNT_ID_LIST; + GET_CHANED_ITEM_FOR_FOLDER_ADD pFunc_GET_CHANED_ITEM_FOR_FOLDER_ADD; + GET_CHANED_ITEM_FOR_FOLDER_DEL pFunc_GET_CHANED_ITEM_FOR_FOLDER_DEL; + GET_CHANED_ITEM_FOR_FOLDER_UPDATE pFunc_GET_CHANED_ITEM_FOR_FOLDER_UPDATE; + GET_LAST_CHANGEPOINT pFunc_GET_LAST_CHANGEPOINT; + StartListening_ChangeNoti pFunc_StartListening_ChangeNoti; + SetCallBack_AddItem pFunc_SetCallBack_AddItem; + SetCallBack_DeleteItem pFunc_setCallBack_DeleteItem; + SetCallBack_UpdateItem pFunc_setCallBack_UpdateItem; + SetCallBack_GetAccountIDList pFunc_SetCallBack_GetAccountIDList; + GET_MAX_ITEM_COUNT pFunc_GET_MAX_ITEM_COUNT; + GET_MAX_FIELD_LENGTH pFunc_GET_MAX_FIELD_LENGTH; + GET_MAX_FIELD_COUNT pFunc_GET_MAX_FIELD_COUNT; + GET_FIELD_VALUE pFunc_GET_FIELD_VALUE; + GET_IS_SUPPORT_FEATURE pFunc_GET_IS_SUPPORT_FEATURE; +} DataConnector_Func_Set; + +typedef struct { + PlugIn_Info_t plugIn_info; + DataConnector_Func_Set func_set; + int data_converter_id; + int handle_changenoti; + int use_mainloop; +} PlugIn_DataConnector; + +DataConnector_Func_Set getDataConnector_Func_Set(void *plugIn_handle, PLUGIN_ERROR * error_code); + +PLUGIN_ERROR registerPlugIn_DataConnector(PlugIn_DataConnector plugIn); + +const PlugIn_DataConnector *getDataConnector_PlugInRepository(int *count); + +int getDataConverter_PlugIn_ID(int dc_plugIn_id); + +int *get_DataConnector_PlugIn_ID_List(int *count); + +Service_Open getFunction_DataConnector_Service_Open(int plugIn_id); + +Service_Close getFunction_DataConnector_Service_Close(int plugIn_id); + +Begin_Transaction getFunction_DataConnector_Begin_Transaction(int plugIn_id); + +End_Transaction getFunction_DataConnector_End_Transaction(int plugIn_id); + +ADD_ITEM getFunction_DataConnector_ADD_ITEM(int plugIn_id); + +UPDATE_ITEM getFunction_DataConnector_UPDATE_ITEM(int plugIn_id); + +DEL_ITEM getFunction_DataConnector_DEL_ITEM(int plugIn_id); + +DEL_ALL_ITEMS getFunction_DataConnector_DEL_ALL_ITEMS(int plugIn_id); + +GET_ITEM getFunction_DataConnector_GET_ITEM(int plugIn_id); + +ADD_FOLDER getFunction_DataConnector_ADD_FOLDER(int plugIn_id); + +DEL_FOLDER getFunction_DataConnector_DEL_FOLDER(int plugIn_id); + +GET_FOLDER getFunction_DataConnector_GET_FOLDER(int plugIn_id); + +EXECUTE getFunction_DataConnector_EXECUTE(int plugIn_id); + +GET_USED_ITEM_COUNT getFunction_DataConnector_GET_USED_ITEM_COUNT(int plugIn_id); + +GET_USED_COUNT_FOR_FOLDER getFunction_DataConnector_GET_USED_COUNT_FOR_FOLDER(int plugIn_id); + +GET_FOLDER_ID_LIST getFunction_DataConnector_GET_FOLDER_ID_LIST(int plugIn_id); + +GET_ACCOUNT_ID_LIST getFunction_DataConnector_GET_ACCOUNT_ID_LIST(int plugIn_id); + +WRITE_ITEMS_TO_FILE getFunction_DataConnector_WRITE_ITEMS_TO_FILE(int plugIn_id); + +ADD_FILE_WROTE_ITEMS_TO_DATASTORE getFunction_DataConnector_ADD_FILE_WROTE_ITEM_TO_DATASTORE(int plugIn_id); + +GET_CHANED_ITEM_FOR_FOLDER_ADD getFunction_DataConnector_GET_CHANED_ITEM_FOR_FOLDER_ADD(int plugIn_id); + +GET_CHANED_ITEM_FOR_FOLDER_DEL getFunction_DataConnector_GET_CHANED_ITEM_FOR_FOLDER_DEL(int plugIn_id); + +GET_CHANED_ITEM_FOR_FOLDER_UPDATE getFunction_DataConnector_GET_CHANED_ITEM_FOR_FOLDER_UPDATE(int plugIn_id); + +GET_LAST_CHANGEPOINT getFunction_DataConnector_GET_LAST_CHANGEPOINT(int plugIn_id); + +StartListening_ChangeNoti getFunction_DataConnector_StartListening_ChangeNoti(int plugIn_id); + +SetCallBack_AddItem getFunction_DataConnector_SetCallBack_AddItem(int plugIn_id); + +SetCallBack_DeleteItem getFunction_DataConnector_SetCallBack_DeleteItem(int plugIn_id); + +SetCallBack_UpdateItem getFunction_DataConnector_SetCallBack_UpdateItem(int plugIn_id); + +SetCallBack_GetAccountIDList getFunction_DataConnector_SetCallBack_GetAccountIDList(int plugIn_id); + +GET_MAX_ITEM_COUNT getFunction_DataConnector_GET_MAX_ITEM_COUNT(int plugIn_id); + +GET_MAX_FIELD_LENGTH getFunction_DataConnector_GET_MAX_FIELD_LENGTH(int plugIn_id); + +GET_MAX_FIELD_COUNT getFunction_DataConnector_GET_MAX_FIELD_COUNT(int plugIn_id); + +GET_FIELD_VALUE getFunction_DataConnector_GET_FIELD_VALUE(int plugIn_id); + +GET_IS_SUPPORT_FEATURE getFunction_DataConnector_GET_IS_SUPPORT_FEATURE(int plugIn_id); + +#endif /* PLUGIN_DATACONNECTOR_H_ */ diff --git a/framework/include/PlugIn/PlugIn_DataConverter.h b/framework/include/PlugIn/PlugIn_DataConverter.h new file mode 100755 index 0000000..0145e25 --- /dev/null +++ b/framework/include/PlugIn/PlugIn_DataConverter.h @@ -0,0 +1,96 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#ifndef PLUGIN_DATACONVERTER_H_ +#define PLUGIN_DATACONVERTER_H_ + +#include "PlugIn_Struct.h" +#include "PlugIn_Error.h" +#include "DataAdapter/EXT_DACI_Errors.h" +#include "DataConverter_Resource.h" + +#define MAX_PLUGIN_DATACONVERTER 10 + +typedef DACI_RETURN(*Converter) (const void *agent_data, void **service_data); +typedef DACI_RETURN(*Replace_Converter) (void *old_service_data, const void *agent_data, void **new_service_data); +typedef DACI_RETURN(*Reverse_Converter) (void *service_data, void **agent_data); + +typedef void *(*Alloc_Object) (); +typedef int (*Free_Object) (void *in_object); +typedef void *(*Set_Value) (void *in_object, int key, char *extension_key, void *set_value); +typedef void *(*Get_Value) (void *in_object, int key, char *extension_key); +typedef Object_Info *(*Get_Obj_Info) (); +typedef int (*Free_Obj_Info) (Object_Info *obj_info); + +typedef struct { + Converter pFunc_Converter; + Replace_Converter pFunc_Replace_Converter; + Reverse_Converter pFunc_Reverse_Converter; + Alloc_Object pFunc_Alloc_Object; + Free_Object pFunc_Free_Object; + Set_Value pFunc_Set_Value; + Get_Value pFunc_Get_Value; + Get_Obj_Info pFunc_Get_Obj_Info; + Free_Obj_Info pFunc_Free_Obj_Info; +} DataConverter_Func_Set; + +typedef struct { + PlugIn_Info_t plugIn_info; + DataConverter_Func_Set func_Set; +} PlugIn_DataConverter; + +DataConverter_Func_Set getDataConverter_Func_Set(void *plugIn_handle, PLUGIN_ERROR * error_code); + +PLUGIN_ERROR registerPlugIn_DataConverter(PlugIn_DataConverter plugIn); + +Converter getFunction_DataConverter_Converter(int plugIn_id); + +Replace_Converter getFunction_DataConverter_Replace_Converter(int plugIn_id); + +Reverse_Converter getFunction_DataConverter_Reverse_Converter(int plugIn_id); + +Alloc_Object getFunction_DataConverter_Alloc_Object(int plugIn_id); + +Free_Object getFunction_DataConverter_Free_Object(int plugIn_id); + +Set_Value getFunction_DataConverter_Set_Value_To_Object(int plugIn_id); + +Get_Value getFunction_DataConverter_Get_Value_To_Object(int plugIn_id); + +Get_Obj_Info getFunction_DataConverter_Get_Obj_Info(int plugIn_id); + +Free_Obj_Info getFunction_DataConverter_Free_Obj_Info(int plugIn_id); + +#endif /* PLUGIN_DATACONVERTER_H_ */ diff --git a/framework/include/PlugIn/PlugIn_DeviceInfo.h b/framework/include/PlugIn/PlugIn_DeviceInfo.h new file mode 100755 index 0000000..cde45ee --- /dev/null +++ b/framework/include/PlugIn/PlugIn_DeviceInfo.h @@ -0,0 +1,84 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Seokgil Kang + */ + +#ifndef PLUGIN_DEVICEINFO_H_ +#define PLUGIN_DEVICEINFO_H_ + +#include + +#include "PlugIn_Struct.h" +#include "PlugIn_Error.h" +#include "Device/EXT_DCI_DevExecutor.h" + +#define MAX_PLUGIN_DEVICEINFO 10 + +typedef int (*Load_DevInfo) (GList **devInfo); +typedef int (*Get_DevInfo) (GList *devInfo, char *info_name, char **value); +typedef int (*Clear_DevInfo) (GList **devInfo); +typedef int (*PM_Lock_State) (PM_State state, PM_Lock_State_Flag flag, unsigned int timeout); +typedef int (*PM_Unlock_State) (PM_State state, PM_Unlock_State_Flag flag); + +typedef struct { + Load_DevInfo pFunc_Load_DevInfo; + Get_DevInfo pFunc_Get_DevInfo; + Clear_DevInfo pFunc_Clear_DevInfo; + + /* execute function */ + PM_Lock_State pFunc_PM_Lock_State; + PM_Unlock_State pFunc_PM_Unlock_State; +} DeviceInfo_Func_Set; + +typedef struct { + PlugIn_Info_t plugIn_info; + DeviceInfo_Func_Set func_Set; +} PlugIn_DeviceInfo; + +DeviceInfo_Func_Set getDeviceInfo_Func_Set(void *plugIn_handle, PLUGIN_ERROR * error_code); + +PLUGIN_ERROR registerPlugIn_DeviceInfo(PlugIn_DeviceInfo plugIn); + +int isExsist_DeviceInfo_PlugIn(int *plugIn_id); + +Load_DevInfo getFunction_DeviceInfo_Load_DevInfo(int plugIn_id); + +Get_DevInfo getFunction_DeviceInfo_Get_DevInfo(int plugIn_id); + +Clear_DevInfo getFunction_DeviceInfo_Clear_DevInfo(int plugIn_id); + +PM_Lock_State getFunction_PM_Lock_State(int plugIn_id); + +PM_Unlock_State getFunction_PM_Unlock_State(int plugIn_id); + +#endif /* PLUGIN_DEVICEINFO_H_ */ diff --git a/framework/include/PlugIn/PlugIn_Error.h b/framework/include/PlugIn/PlugIn_Error.h new file mode 100755 index 0000000..6022371 --- /dev/null +++ b/framework/include/PlugIn/PlugIn_Error.h @@ -0,0 +1,51 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#ifndef PLUGIN_ERROR_H_ +#define PLUGIN_ERROR_H_ + +/** + @brief Error Code about Operation result concern with Plug-In + */ +typedef enum { + PLUGIN_SUCCESS, /**< when Plug In Operation is succeed */ + PLUGIN_FAIL, /**< when Plug In Operation is failed */ + PLUGIN_LOAD_FAIL, + PLUGIN_DEPENDENCY_FAIL, /**< when Plug In Operation is failed because dependency */ + PLUGIN_FULL_CAPACITY, + PLUGIN_INVALID_PARAM +} PLUGIN_ERROR; + +#endif /* PLUGIN_ERROR_H_ */ diff --git a/framework/include/PlugIn/PlugIn_Interface/Account_Interface.h b/framework/include/PlugIn/PlugIn_Interface/Account_Interface.h new file mode 100755 index 0000000..ceeda53 --- /dev/null +++ b/framework/include/PlugIn/PlugIn_Interface/Account_Interface.h @@ -0,0 +1,126 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#ifndef ACCOUNT_INTERFACE_H_ +#define ACCOUNT_INTERFACE_H_ + +/** + * @file Account_Interface.h + * @brief Interface list in this header will be implemented plugIn developer. + * Implementation will operate F/W Account module. + */ + +/** + * @brief Setting Account Repository name + * @remarks Repository means mapping storage, between service account ID and F/W account ID + * @param[in] agent_name means repository name - described in F/W config file + */ +void Set_AccountReposioryName(const char *agent_name); + +/** + * @brief Add account to Platform + * @remarks mapping platform account id with f/w account_id + * @param[in] fw_account_id F/W account ID + * @param[in] email account's email address + * @param[in] password account's password + * @param[in] create_mode whether create new Platform account or only mapping f/w account id with existed platform account + */ +void Add_PlatformAccount(int fw_account_id, char *email, char *password, int create_mode); + +/** + * @brief Mapping F/W account ID with service account ID + * @remarks You must register non-volatile storage not memory. ex) File, DataBase.. + * @param[in] fw_account_id F/W account ID + * @param[in] service_type service type - service data connector pluIn's ID described in F/W config file + * @param[in] service_account_id service account ID + */ +void Set_PlatformAccount_Service(int fw_account_id, int service_type, int service_account_id); + +/** + * @brief Mapping relationship is off - F/W account ID with platform account ID + * @remarks You must remove from storage. + * @param[in] fw_account_id F/W account ID + */ +void Del_PlatformAccount(int fw_account_id); + +/** + * @brief Mapping relationship is off - F/W account ID with service account ID + * @remarks You must remove from storage. + * @param[in] fw_account_id F/W account ID + * @param[in] service_type service type - service data connector pluIn's ID described in F/W config file + */ +void Del_PlatformAccount_Service(int fw_account_id, int service_type); + +/** + * @brief whether F/W account ID has the service account ID + * @param[in] fw_account_id F/W account ID + * @param[in] service_type service type - service data connector pluIn's ID described in F/W config file + * @return 1 if has, otherwise 0 + * @retval 1 if has + * @retval 0 if has not + */ +int Has_PlatformAccount_Service(int fw_account_id, int service_type); + +/** + * @brief get service account ID mapped with F/W account ID + * @param[in] service_type service type - service data connector pluIn's ID described in F/W config file + * @param[in] fw_account_id F/W account ID + * @return service account id if it exist mapping relationship, otherwise -100 + * @retval service account id if it exist mapping relationship + * @retval -100 not exist mapping relationship + */ +int Get_Service_AccountID(int service_type, int fw_account_id); + +/** + * @brief get F/W account ID mapped with service account ID + * @param[in] service_type service type - service data connector pluIn's ID described in F/W config file + * @param[in] service_account_id service account ID + * @param[in] index possible mapping one service account with multiple F/W account, so need index of F/W account. + * @return F/W account id if it exist mapping relationship, otherwise -1 + * @retval F/W account id if it exist mapping relationship + * @retval -1 not exist mapping relationship + */ +int Get_FW_AccountID(int service_type, int service_account_id, int index); + +/** + * @brief Get service account information + * @remarks account information type must be defined in account plugIn. + * @param[in] fw_account_id F/W account id + * @param[in] service_type service type - service data connector pluIn's ID described in F/W config file + * @return Account Information* defined in account plugIn on success, otherwise null pointer + */ +void *Get_Service_AccountInfo(int fw_account_id, int service_type); + +#endif /* ACCOUNT_INTERFACE_H_ */ diff --git a/framework/include/PlugIn/PlugIn_Interface/DataConnector_Interface.h b/framework/include/PlugIn/PlugIn_Interface/DataConnector_Interface.h new file mode 100755 index 0000000..924b145 --- /dev/null +++ b/framework/include/PlugIn/PlugIn_Interface/DataConnector_Interface.h @@ -0,0 +1,367 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#ifndef DATACONNECTOR_INTERFACE_H_ +#define DATACONNECTOR_INTERFACE_H_ + +#include "agent-framework/DACI/EXT_DACI_Errors.h" + +#include "DataConnector_Resource.h" + +/** + * @file DataConnector_Interface.h + * @brief Interface list in this header will be implemented plugIn developer. + * Implementation will operate F/W DataAdapter module. + */ + +/* + * @brief service opening work + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ +DACI_RETURN Service_Open(); + +/* + * @brief service closing work + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ +DACI_RETURN Service_Close(); + +/* + * @brief start transaction for service storage + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ +DACI_RETURN Begin_Transaction(); + +/* + * @brief end transaction for service storage + * @param[in] is_success 1 : commit, 0 : rollback + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ +DACI_RETURN End_Transaction(int is_success); + +/* + * @brief insert item into service storage + * @param[in] account_id service account id + * @param[in] folder_id service folder_id + * @param[in] data service structure * + * @param[out] item_id success : service item_id, fail : 0 + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ +DACI_RETURN Add_Item(int account_id, char *folder_id, void *data, char **item_id); + +/* + * @brief update item from service storage + * @param[in] account_id service account id + * @param[in] folder_id service folder_id + * @param[in] item_id service item_id + * @param[in] data service structure * + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ +DACI_RETURN Update_Item(int account_id, char *folder_id, char *item_id, void *data); + +/* + * @brief delete item from service storage + * @param[in] account_id service account id + * @param[in] folder_id service folder_id + * @param[in] item_id service id of item expected to be deleted + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ +DACI_RETURN Del_Item(int account_id, char *folder_id, char *item_id); + +/* + * @brief delete all items from service storage + * @param[in] account_id service account id + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ +DACI_RETURN Del_All_Items(int account_id); + +/* + * @brief get item from service storage + * @param[in] account_id service account id + * @param[in] folder_id service folder id + * @param[in] item_id expected to get service item id + * @param[out] data success : item info, fail : 0 + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ +DACI_RETURN Get_Item(int account_id, char *folder_id, char *item_id, void **data); + +/* + * @brief insert folder into service storage + * @param[in] account_id service account id + * @param[in] folder_name folder name + * @param[in] folder_type folder type + * @param[out] folder_id success : folder_id, fail : 0 + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ +DACI_RETURN Add_Folder(int account_id, char *folder_name, int folder_type, char **folder_id); + +/* + * @brief delete folder from service storage + * @param[in] account_id service account id + * @param[in] folder_id service folder_id + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ +DACI_RETURN Del_Folder(int account_id, char *folder_id); + +/* + * @brief get folder from service storage + * @param[in] account_id service account id + * @param[in] folder_id service folder id + * @param[out] out_folder_name success : folder name, fail : 0 + * @param[out] out_folder_type success : folder type, fail : -1 + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ +DACI_RETURN Get_Folder(int account_id, char *folder_id, char **out_folder_name, int *out_folder_type); + +/* + * @brief execute data into service + * @param[in] account_id service account id + * @param[in] execute_key execute key + * @param[in] execute_values execute values + * @param[out] result extension result info + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ +DACI_RETURN Execute(int account_ID, const char *execute_key, void *execute_values, void **result); + +/* + * @brief get item used count + * @return operation result + * @retval current item count success + * @retval error value fail : minus + */ +int Get_Used_Item_Count(); + +/* + * @brief get item used count for folder + * @param[in] account_id service account id + * @param[in] folder_id service folder id + * @return operation result + * @retval current item count success + * @retval error value fail : minus + */ +int Get_Used_Item_Count_For_Folder(int account_id, char *folder_id); + +/* + * @brief get folder id list of a account + * @param[in] account_id service account id + * @param[out] folder_count success : folder count, fail or not exist : 0 + * @param[out] folder_type_list success : list, fail or not exist : null pointer + * @return operation result + * @retval folder id list success + * @retval error value fail or not exist : null pointer + */ +char **Get_Folder_ID_List(int account_id, int *folder_count, int **folder_type_list); + +/* + * @brief get all account id list that service has currently + * @param[out] count success : account id count, fail or not exist : 0 + * @return operation result + * @retval account id list success + * @retval error value fail or not exist : null pointer + */ +int *Get_Account_ID_List(int *count); + +/* + * @brief write data store items to file + * @param[in] account_id service account id + * @param[out] file_path written file_path + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail :minus + */ +DACI_RETURN Write_Items_To_File(int account_ID, char **file_path); + +/* + * @brief add file wrote item to data store + * @param[in] account_id service account_id + * @param[in] file_path file_path + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail : minus + */ +DACI_RETURN Add_File_Wrote_Items_To_Datastore(int account_ID, const char *file_path); + +/* + * @brief get added item list after specific point + * @param[in] account_id service account id + * @param[in] folder_id service folder id + * @param[in] changepoint specific point + * @param[out] changeCount added item count + * @return operation result + * @retval added item info list if exist + * @retval null pointer fail or not exist + */ +Item_Node *Get_Changed_ITEM_For_Folder_Add(int account_id, const char *folder_id, int changepoint, int *changeCount); + +/* + * @brief get deleted item list after specific point + * @param[in] account_id service account id + * @param[in] folder_id service folder id + * @param[in] changepoint specific point + * @param[out] changeCount deleted item count + * @return operation result + * @retval deleted item info list if exist + * @retval null pointer fail or not exist + */ +Item_Node *Get_Changed_ITEM_For_Folder_Del(int account_id, const char *folder_id, int changepoint, int *changeCount); + +/* + * @brief get updated item list after specific point + * @param[in] account_id service account id + * @param[in] folder_id service folder id + * @param[in] changepoint specific point + * @param[out] changeCount updated item count + * @return operation result + * @retval updated item info list if exist + * @retval null pointer fail or not exist + */ +Item_Node *Get_Changed_ITEM_For_Folder_Update(int account_id, const char *folder_id, int changepoint, int *changeCount); + +/* + * @brief get last storage change point information + * @return operation result + * @retval last storage change point information + */ +int Get_Last_ChangePoint(); + +/* + * @brief check notification for the storage change + * @param[in] data user data + */ +void StartListening_ChangeNoti(void *data); + +/* + * @brief set callback function to handle added item to storage + * @param[in] callback callback function - this function is provided from F/W + */ +void SetCallBack_AddItem(CALLBACK_ADD_ITEM callback); + +/* + * @brief set callback function to handle deleted item to storage + * @param[in] callback callback function - this function is provided from F/W + */ +void SetCallBack_DeleteItem(CALLBACK_DEL_ITEM callback); + +/* + * @brief set callback function to handle updated item to storage + * @param[in] callback callback function - this function is provided from F/W + */ +void SetCallBack_UpdateItem(CALLBACK_UPDATE_ITEM callback); + +/* + * @brief set callback function to get service account id list mapped f/w account id + * @param[in] callback callback function - this function is provided from F/W + */ +void SetCallBack_GetAccountIDList(GET_ACCOUNTIDLIST callback); + +/* + * @brief get max item count per folder + * @param[in] folder_type folder type provided plug-in + * @return operation result + * @retval max item count success + * @retval -1 fail + */ +int Get_MAX_Item_Count(int folder_type); + +/* + * @brief get service data's available field length + * @param[in] field_name field_name provided data connector plug-In + * @param[in] child_field_name child_field_name provided data connector plug-In + * @return operation result + * @retval available field length success + * @retval -1 fail + */ +int Get_MAX_Field_Length(int field_name, int child_field_name); + +/* + * @brief get service data's available field count + * @param[in] field_name field_name provided data connector plug-In + * @param[in] child_field_name child_field_name provided data connector plug-In + * @return operation result + * @retval available field count success + * @retval -1 fail + */ +int Get_MAX_Field_Count(int field_name, int child_field_name); + +/* + * @brief get service data's available field value's domain + * @param[in] field_name field_name provided data connector plug-In + * @param[in] child_field_name child_field_name provided data connector plug-In + * @param[out] str_val when domain value is string + * @param[out] num_val1 when domain value is integer (ex minimum value) + * @param[out] num_val2 when domain value is integer (ex maximum value) + * @return operation result + * @retval 1 success + * @retval -1 fail + */ +int Get_Field_Value(int field_name, int child_field_name, char **str_val, int *num_val1, int *num_val2); + +/* + * @brief get service data's available field count + * @param[in] feature feature provided data connector plug-In + * @return operation result + * @retval 1 support + * @retval 0 not support + * @retval -1 fail + */ +int Get_Is_Support_Feature(int feature); + +#endif /* DATACONNECTOR_INTERFACE_H_ */ diff --git a/framework/include/PlugIn/PlugIn_Interface/DataConnector_Resource.h b/framework/include/PlugIn/PlugIn_Interface/DataConnector_Resource.h new file mode 100755 index 0000000..48001a2 --- /dev/null +++ b/framework/include/PlugIn/PlugIn_Interface/DataConnector_Resource.h @@ -0,0 +1,63 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#ifndef DATACONNECTOR_RESOURCE_H_ +#define DATACONNECTOR_RESOURCE_H_ + +/** + * @file DataConnector_Resource.h + * @brief Item id list container + */ + +/** + * @brief Structure of Item ID Node - Linked List + */ +struct Item_Node { + char *item_id; /**< item id */ + struct Item_Node *next; /**< next pointer */ +}; + +typedef struct Item_Node Item_Node; + +typedef int (*CALLBACK_ADD_ITEM) (int accountID, int index, char *itemID, int itemType, char *folderID, int folderType); + +typedef int (*CALLBACK_DEL_ITEM) (int accountID, int index, char *itemID, int itemType); + +typedef int (*CALLBACK_UPDATE_ITEM) (int accountID, int index, char *itemID, int itemType); + +typedef int *(*GET_ACCOUNTIDLIST) (int service_type, int *cnt); + + +#endif /* DATACONNECTOR_RESOURCE_H_ */ diff --git a/framework/include/PlugIn/PlugIn_Interface/DataConverter_Interface.h b/framework/include/PlugIn/PlugIn_Interface/DataConverter_Interface.h new file mode 100644 index 0000000..b0533fb --- /dev/null +++ b/framework/include/PlugIn/PlugIn_Interface/DataConverter_Interface.h @@ -0,0 +1,140 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#ifndef DATACONVERTER_INTERFACE_H_ +#define DATACONVERTER_INTERFACE_H_ + +#include "agent-framework/DACI/EXT_DACI_Errors.h" + +#include "DataConverter_Resource.h" + +/** + * @file DataConverter_Interface.h + * @brief Interface list in this header will be implemented plugIn developer. + * Implementation will operate DataAdapter module. + */ + +/** + * @brief convert agent type data to service structure format data + * @remarks agent data's type can be v-object. (vcard, vcalendar .. ) + * @param[in] agent_data agent data + * @param[out] service_data created service data + * @return operation result + * @retval DACI_SUCCESS success + * @retval DACI_ERRORS fail + */ +DACI_RETURN Converter(const void *agent_data, void **service_data); + +/** + * @brief convert result of the merge agent data with old service data to service structure format data + * @remarks agent data's type can be v-object. (vcard, vcalendar .. ) + * @param[in] old_service_data old_service_data + * @param[in] agent_data agent data + * @param[out] new_service_data created service data + * @return operation result + * @retval DACI_SUCCESS success + * @retval DACI_ERRORS fail + */ +DACI_RETURN Replace_Converter(void *old_service_data, const void *agent_data, void **new_service_data); + +/** + * @brief convert service structure format data to agent type data + * @remarks agent data's type can be v-object. (vcard, vcalendar .. ) + * @param[in] service_data created service data + * @param[out] agent_data agent data + * @return operation result + * @retval DACI_SUCCESS success + * @retval DACI_ERRORS fail + */ +DACI_RETURN Reverse_Converter(void *service_data, void **agent_data); + +/* + * @brief allocate internal object for content type + * @return operation result + * @retval internal struct pointer success + * @retval null pointer fail + */ +void *Alloc_Object(); + +/* + * @brief free internal object for content type + * @param[in] in_object internal object pointer + * @return operation result + * @retval DACI_SUCCESS success + * @retval DACI_ERRORS fail + */ +int Free_Object(void *in_object); + +/* + * @brief set value for internal object + * @param[in] in_object internal object pointer + * @param[in] key key + * @param[in] extension_key extension key + * @param[in] set_value value + * @return operation result + * @retval new object pointer success + * @retval null pointer fail + */ +void *Set_Value(void *in_object, int key, char *extension_key, void *set_value); + +/* + * @brief allocate internal object for content type + * @param[in] in_object internal object pointer + * @param[in] key key + * @param[in] extension_key extension key + * @return operation result + * @retval value pointer success + * @retval 0 fail + */ +void *Get_Value(void *in_object, int key, char *extension_key); + +/* + * @brief get meta infomation of internal object + * @return operation result + * @retval value pointer success + * @retval 0 fail + */ +Object_Info *Get_Obj_Info(); + +/* + * @brief free infomation of internal object + * @param[in] obj_info object info + * @return operation result + * @retval DACI_SUCCESS success + * @retval DACI_ERRORS fail + */ +int Free_Obj_Info(Object_Info *obj_info); + +#endif /* DATACONVERTER_INTERFACE_H_ */ diff --git a/framework/include/PlugIn/PlugIn_Interface/DeviceInfo_Interface.h b/framework/include/PlugIn/PlugIn_Interface/DeviceInfo_Interface.h new file mode 100644 index 0000000..886f7f8 --- /dev/null +++ b/framework/include/PlugIn/PlugIn_Interface/DeviceInfo_Interface.h @@ -0,0 +1,109 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Seokgil Kang + */ + +#ifndef DEVICEINFO_INTERFACE_H_ +#define DEVICEINFO_INTERFACE_H_ + +#include +#include "agent-framework/Device/EXT_DCI_Common.h" + +/** + * @file DeviceInfo_Interface.h + * @brief Defines plug-in interfaces about device information + */ + +/** + * @brief Device information structure + * @remarks This structure is member of list (devInfo) + * Key(info_name) - value(value) pair + */ +typedef struct { + char *info_name; + char *value; +} dici_dev_info; + +/** + * @brief Get device information in the system and load this information on the memory + * @param[out] devInfo List of dici_dev_info structures + * @return Operation result + * @retval 1 Successful + * @retval 0 Operation failed + */ +int Load_DevInfo(GList **devInfo); + +/** + * @brief Get device information on the memory that user want to know + * @param[in] devInfo List of dici_dev_info structures + * @param[in] info_name Name of device information + * @param[out] value Value of device information + * @return Operation result + * @retval 1 Successful + * @retval 0 Operation failed + */ +int Get_DevInfo(GList *devInfo, char *info_name, char **value); + +/** + * @brief Clear device information on the memory (free memory) + * @param[in] defInfo List of dici_dev_info structures + * @return Operation result + * @retval 1 Successful + * @retval 0 Operation failed + */ +int Clear_DevInfo(GList **devInfo); + +/** + * @brief Lock a particular power-state as the current power-state + * @remarks If parameter 'timeout' value is 0, state of power manager is always lock until calling PM_Unlock_State() + * @param[in] The power state which user want to lock + * @param[in] Set if user want to go the requested lock state directly + * @param[in] Specifies lock-timeout in milliseconds + * @return Operation result + * @retval 0 Successful + * @retval -1 Operation failed + * @see /Device/EXT_DCI_Common.h + */ +int PM_Lock_State(PM_State state, PM_Lock_State_Flag flag, unsigned int timeout); + +/** + * @brief Unlock the power-state + * @param[in] Specifies the power state which user want to unlock + * @param[in] Set if user want to go to the requested state directly after unlocking (not supported yet) + * @return Operation result + * @retval 0 Succesful + * @retval -1 Operation failed + */ +int PM_Unlock_State(PM_State state, PM_Unlock_State_Flag flag); + +#endif /* DEVICEINFO_INTERFACE_H_ */ diff --git a/framework/include/PlugIn/PlugIn_Interface/NetworkAccess_Interface.h b/framework/include/PlugIn/PlugIn_Interface/NetworkAccess_Interface.h new file mode 100644 index 0000000..12321d0 --- /dev/null +++ b/framework/include/PlugIn/PlugIn_Interface/NetworkAccess_Interface.h @@ -0,0 +1,172 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Seokgil Kang + */ + +#ifndef NETWORKACCESS_INTERFACE_H_ +#define NETWORKACCESS_INTERFACE_H_ + +#include + +/** + * @file NetworkAccess_Interface.h + * @brief Defines plug-in interfaces about network access + */ + +/** + * @brief Open network connection + * @param[out] session Network session information + * @param[in] proxy Proxy information + * @param[in] timeout User preferred time-out seconds used in sending message (ex> 30 means 30seconds) + * @return Operation result + * @retval 1 Successful + * @retval 0 Operation failed + */ +int Open_Connection(void **session, char *proxy, int timeout); + +/** + * @brief Bind header information for each network protocol + * @param[in] header_info Header information for each network protocol + * @param[out] header_binding Header information bound each network protocol + * @return Operation result + * @retval 1 Successful + * @retval 0 Operation failed + */ +int Header_Binding(GList *header_info, void **header_binding); + +/** + * @brief Send message to server and receive message from the server + * @param[in] session Network session information + * @param[out] header_binding Header binding information + * @param[in] send_msg Body message + * @param[in] send_msg_length Length of body message + * @param[out] recv_msg_size The size of received message from the server + * @return Operation result + * @retval 1 Successful + * @retval 0 Operation failed + * @retval -1 Cancel message + * @retval -8 Try again + * @retval -408 request timeout + */ +int Send_Message(void *session, void **header_binding, char *send_msg, unsigned int send_msg_length, unsigned int *recv_msg_size); + +/** + * @brief Divide header/body information using received message from the server + * @param[in] msg Received message from the server + * @param[in] msg_size The size of received message from the server + * @param[out] recv_header Header information of received message from the server + * @param[out] recv_msg Body information of received message from the server + * @param[out] recv_msg_length The length of body information + * @return Operation result + * @retval 1 Successful + * @retval 0 Operation failed + */ +int Header_Unbinding(void *msg, unsigned int msg_size, GList **recv_header, unsigned char **recv_msg, unsigned int *recv_msg_length); + +/** + * @brief Close network connection + * @param[in] session Network session information + * @return Operation result + * @retval 1 Successful + * @retval 0 Operation failed + */ +int Close_Connection(void *session); + +/** + * @brief Cancel operation about message being sent to the server + * @param[in] session Network session information + * @return Operation result + * @retval 1 Successful + * @retval 0 Operation failed + */ +int Cancel_Message(void *session); + +/** + * @brief Just send message to the server (do not receive message from the server) + * @param[in] session Network session information + * @param[out] header_binding Header binding information + * @param[in] send_msg Body message + * @param[in] send_msg_length Length of body message + * @return Operation result + * @retval 1 Successful + * @retval 0 Operation failed + */ +int Just_Send_Message(void *session, void **header_binding, char *send_msg, unsigned int send_msg_length); + +/** + * @brief Get network header information about specific keyword + * @param[in] header_info List of network header information (key-value pair) + * @param[in] key Specific keyword of header information that user want to know + * @param[out] value Value for the key + * @return Operation result + * @retval 1 Successful + * @retval 0 Operation failed + * @see Header_Unbinding() + */ +int Get_Header_Info(GList *header_info, char *key, char **value); + +/** + * @brief Set download information(download range) to download header information of specific network protocol + * @param[in] down_info Download header information of specific network protocol + * @param[in] current_down_range Download current range + * @return Operation result + * @retval 1 Successful + * @retval 0 Operation failed + */ +int Set_Data_Download_Info(void *down_info, char *current_down_range); + +/** + * @brief Get download information(download range, filename) to download header information of specific network protocol + * @param[in] down_info Download header information of specific network protocol + * @param[out] total_down_size Total download size + * @param[out] current_down_range Current download range + * @param[out] down_file_name Download file name + * @return Operation result + * @retval 1 Successful + * @retval 0 Operation failed + */ +int Get_Data_Download_Info(void *down_info, int *total_down_size, char **current_down_range, char **down_file_name); + +/** + * @brief Add user authentication information (id, password) to session and + * register authentication callback for 'authenticate' signal + * @param[in] session Network session information + * @param[in] id User id + * @param[in] password User password + * @return Operation result + * @retval 1 Successful + * @retval 0 Operation failed + */ +int Add_Authentication_Info(void *session, char *id, char *password); + +#endif /* NETWORKACCESS_INTERFACE_H_ */ diff --git a/framework/include/PlugIn/PlugIn_Interface/PlatformMonitor_Interface.h b/framework/include/PlugIn/PlugIn_Interface/PlatformMonitor_Interface.h new file mode 100644 index 0000000..4391d71 --- /dev/null +++ b/framework/include/PlugIn/PlugIn_Interface/PlatformMonitor_Interface.h @@ -0,0 +1,185 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Seokgil Kang + */ + +#ifndef PLATFORMMONITOR_INTERFACE_H_ +#define PLATFORMMONITOR_INTERFACE_H_ + +#include "PlatformMonitor_Resource.h" + +/** + * @file PlatformMonitor_Interface.h + * @brief Defines plug-in interfaces about service platform notification + */ + +/** + * @brief Data structure to register at main loop of sync-agent-framework + */ +typedef struct { + char *pkg_name; + char *app_id; + void *user_data; +} pm_register_data_t; + +/** + * @brief Check the current network status/connection type and + * register network notification callback function(used in sync-agent-framework) to network platform + * @param[in] data User data (meaningless data) + */ +void Init_Network_Status_Noti_Handler(void *data); + +/** + * @brief Unregister network notification callback function(used in sync-agent-framework) to network platform + */ +int Terminate_Network_Status_Noti_Handler(void); + +/** + * @brief Initialize to receive SAN notification from the service + * @remarks Connect to the service and register notification callback function to the service + * @param[in] data User data (meaningless data) + */ +void Init_Syncml_SAN_Noti_Handler(void *data); + +/** + * @brief Unregister notification callback function that was previously registered to the service and disconnect to the service + */ +int Terminate_Syncml_SAN_Noti_Handler(void); + +/** + * @brief Add SAN message to the service + * @param[in] add_item Item to add to the service + * @return Operation result + * @retval 1 Successful + * @retval -1 Operation failed + * @see /PlatformMonitor/EXT_PMCI_Struct.h - pmci_san_message_t + */ +int Add_Message(void *add_item); + +/** + * @brief Remove SAN message from service + * @param[in] remove_item_id Id of Item that user want to remove from service + * @return Operation result + * @retval 1 Successful + * @retval -1 Operation failed + */ +int Remove_Message(int remove_item_id); + +/** + * @brief Initialize to receive alarm notification from the service + * @remarks Connect to the service and register notification callback function to the service + * @param[in] data Structure 'pm_register_data_t' + */ +void Init_Alarm_Noti_Handler(void *data); + +/** + * @brief Unregister notification callback function that was previously registered to the service and disconnect to the service + * @remarks Not supported yet + */ +int Terminate_Alarm_Noti_Handler(); + +/** + * @brief Add alarm data to the service + * @param[in] add_item Item to add to the service + * @param[out] out_add_item_id Id of the newly item added to the service + * @return Operation result + * @retval 1 Successful + * @retval 0 Operation failed + */ +int Add_Alarm(void *add_item, int *out_add_item_id); + +/** + * @brief Remove alarm data from the service + * @param[in] remove_item_id Id of Item that user want to remove from service + * @return Operation result + * @retval 1 Successful + * @retval -1 Operation failed + */ +int Remove_Alarm(int remove_item_id); + +/** + * @brief Get item that user want to know from the service + * @param[in] get_item_id Id of the item that user want to know + * @param[out] out_get_item Item that user want to know + * @return Operation result + * @retval 1 Successful + * @retval 0 Operation failed + * @see /PlatformMonitor/EXT_PMCI_Struct.h - pmci_alarm_t + */ +int Get_Alarm(int get_item_id, void **out_get_item); + +/** + * @brief Register user callback function for network status to the service + * @remarks This api is used in sync-agent-framework + * @param[in] callback User callback function + */ +void SetCallBack_NetworkStatus(CALLBACK_NETWORK_STATUS callback); + +/** + * @brief Register user callback function for network cancel to the service + * @remarks This api is used in sync-agent-framework + * @param[in] callback User callback function + */ +void SetCallBack_NetworkAllCancel(CALLBACK_NETWORK_CANCEL callback); + +/** + * @brief Register user callback function for SAN incoming notification to the service + * @param[in] callback User callback function + */ +void SetCallBack_Syncml_SAN_Incoming(CALLBACK_SYNCML_SAN_INCOMING callback); + +/** + * @brief Register user callback function for SAN operation notification to the service + * @param[in] callback User callback function + */ +void SetCallBack_Syncml_SAN_Operation(CALLBACK_SYNCML_SAN_OPERATION callback); + +/** + * @brief Register user callback function for alarm notification to the service + * @param[in] callback User callback function + */ +void SetCallBack_Alarm(CALLBACK_ALARM callback); + +/** + * @brief Register user callback function for network on status to the service + * @param[in] callback User callback function + */ +void SetCallBack_Network_On(CALLBACK_NETWORK_ON callback); + +/** + * @brief Register user callback function for network off status to the service + * @param[in] callback User callback function + */ +void SetCallBack_Network_Off(CALLBACK_NETWORK_OFF callback); + +#endif /* PLATFORMMONITOR_INTERFACE_H_ */ diff --git a/framework/include/PlugIn/PlugIn_Mgr.h b/framework/include/PlugIn/PlugIn_Mgr.h new file mode 100755 index 0000000..9a98fd1 --- /dev/null +++ b/framework/include/PlugIn/PlugIn_Mgr.h @@ -0,0 +1,76 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#ifndef PLUGIN_MGR_H_ +#define PLUGIN_MGR_H_ + +#include "PlugIn_Error.h" + +typedef enum { + PLUGIN_DataConnector = 0, + PLUGIN_DataConverter, + PLUGIN_NetworkAccess, + PLUGIN_Account, + PLUGIN_DeviceInfo, + PLUGIN_MO, + PLUGIN_PlatformMonitor, + + PLUGIN_DOMAIN_CNT +} PLUGIN_DOMAIN; + +/** + @brief Load the Plug-In. + + Received a Plug-In as a parameter will be loaded. + + @param[in] plugin_path To Load Plug-In's path + @param[out] error Error Code + @return if it succeed plugIn handle, if it failed NULL pointer + */ +void *load_PlugIn(const char *plugin_path, PLUGIN_ERROR * error); + +/** + @brief UnLoad the Plug-In. + + By default, Received a Plug-In as a parameter will be Unloaded. + but If another Plug-In is dependent on Plug-In, this function will be failed. + + @param domain_name To Load Plug-In's domain name (ex) SA, DataConnector, NetworkAccess ... + @param plugin_name To Load Plug-In's name + @return results of the unload if it succeed, success code(PLUGIN_SUCCESS) will be returned. + */ +PLUGIN_ERROR unLoad_PlugIn(PLUGIN_DOMAIN domain, const char *plugin_name); + +#endif /* PLUGIN_MGR_H_ */ diff --git a/framework/include/PlugIn/PlugIn_NetworkAccess.h b/framework/include/PlugIn/PlugIn_NetworkAccess.h new file mode 100755 index 0000000..de340b4 --- /dev/null +++ b/framework/include/PlugIn/PlugIn_NetworkAccess.h @@ -0,0 +1,108 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Seokgil Kang + */ + +#ifndef PLUGIN_NETWORKACCESS_H_ +#define PLUGIN_NETWORKACCESS_H_ + +#include + +#include "PlugIn_Struct.h" +#include "PlugIn_Error.h" + +#define MAX_PLUGIN_NETWORKACCESS 10 + +typedef int (*Open_Connection) (void **session, char *proxy, int timeout); +typedef int (*Header_Binding) (GList *header_info, void **header_binding); +typedef int (*Send_Message) (void *session, void **header_binding, char *send_msg, unsigned int send_msg_length, unsigned int *recv_msg_size); +typedef int (*Header_Unbinding) (void *msg, unsigned int msg_size, GList **recv_header, unsigned char **recv_msg, unsigned int *recv_msg_length); +typedef int (*Close_Connection) (void *session); +typedef int (*Cancel_Message) (void *session); +typedef int (*Just_Send_Message) (void *session, void **header_binding, char *send_msg, unsigned int send_msg_length); +typedef int (*Get_Header_Info) (GList *header_info, char *key, char **value); +typedef int (*Set_Data_Download_Info) (void *down_info, char *current_down_range); +typedef int (*Get_Data_Download_Info) (void *down_info, int *total_down_size, char **current_down_range, char **down_file_name); +typedef int (*Add_Authentication_Info) (void *session, char *id, char *password); + +typedef struct { + Open_Connection pFunc_Open_Connection; + Header_Binding pFunc_Header_Binding; + Send_Message pFunc_Send_Message; + Header_Unbinding pFunc_Header_Unbinding; + Close_Connection pFunc_Close_Connection; + Cancel_Message pFunc_Cancel_Message; + Just_Send_Message pFunc_Just_Send_Message; + Get_Header_Info pFunc_Get_Header_Info; + Set_Data_Download_Info pFunc_Set_Data_Down_Info; + Get_Data_Download_Info pFunc_Get_Data_Down_Info; + Add_Authentication_Info pFunc_Add_Authentication_Info; +} NetworkAccess_Func_Set; + +typedef struct { + PlugIn_Info_t plugIn_info; + NetworkAccess_Func_Set func_Set; + int use_network; +} PlugIn_NetworkAccess; + +NetworkAccess_Func_Set getNetworkAccess_Func_Set(void *plugIn_handle, PLUGIN_ERROR * error_code); + +PLUGIN_ERROR registerPlugIn_NetworkAccess(PlugIn_NetworkAccess plugIn); + +int use_Network(int plugIn_id); + +int get_NetworkAccess_PlugIn_ID_List(int **plugIn_id_list); + +Open_Connection getFunction_NetworkAccess_Open_Connection(int plugIn_id); + +Header_Binding getFunction_NetworkAccess_Header_Binding(int plugIn_id); + +Send_Message getFunction_NetworkAccess_Send_Message(int plugIn_id); + +Header_Unbinding getFunction_NetworkAccess_Header_Unbinding(int plugIn_id); + +Close_Connection getFunction_NetworkAccess_Close_Connection(int plugIn_id); + +Cancel_Message getFunction_NetworkAccess_Cancel_Message(int plugIn_id); + +Just_Send_Message getFunction_NetworkAccess_Just_Send_Message(int plugIn_id); + +Get_Header_Info getFunction_NetworkAccess_Get_Header_Info(int plugIn_id); + +Set_Data_Download_Info getFunction_NetworkAccess_Set_Data_Download_Info(int plugIn_id); + +Get_Data_Download_Info getFunction_NetworkAccess_Get_Data_Download_Info(int plugIn_id); + +Add_Authentication_Info getFunction_NetworkAccess_Add_Authentication_Info(int plugIn_id); + +#endif /* PLUGIN_NETWORKACCESS_H_ */ diff --git a/framework/include/PlugIn/PlugIn_PlatformMonitor.h b/framework/include/PlugIn/PlugIn_PlatformMonitor.h new file mode 100755 index 0000000..14fe256 --- /dev/null +++ b/framework/include/PlugIn/PlugIn_PlatformMonitor.h @@ -0,0 +1,158 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Seokgil Kang + */ + +#ifndef PLUGIN_PLATFORMMONITOR_H_ +#define PLUGIN_PLATFORMMONITOR_H_ + +#include + +#include "PlugIn_Struct.h" +#include "PlugIn_Error.h" +#include "PlatformMonitor_Resource.h" + +#define MAX_PLUGIN_PLATFORMMONITOR 10 + +/* for register FW main loop */ +typedef struct { + char *pkg_name; + char *app_id; + void *user_data; +} pm_register_data_t; + +/* register FW g_main_loop */ + +/* FW Common Notification */ +typedef void (*Init_Network_Status_Noti_Handler) (void *data); + +typedef int (*Terminate_Network_Status_Noti_Handler) (void); + +/* Specific Service Notification */ +typedef void (*Init_Syncml_SAN_Noti_Handler) (void *data); +typedef int (*Terminate_Syncml_SAN_Noti_Handler) (void); +typedef int (*Add_Message) (void *add_item); +typedef int (*Remove_Message) (int remove_item_id); + +/* Alarm noti */ +typedef void (*Init_Alarm_Noti_Handler) (void *data); +typedef int (*Terminate_Alarm_Noti_Handler) (); +typedef int (*Add_Alarm) (void *add_item, int *out_add_item_id); +typedef int (*Remove_Alarm) (int remove_item_id); +typedef int (*Get_Alarm) (int get_item_id, void **out_get_item); + +/* Set Callback */ +typedef void (*SetCallBack_NetworkStatus) (CALLBACK_NETWORK_STATUS callback); +typedef void (*SetCallBack_NetworkAllCancel) (CALLBACK_NETWORK_CANCEL callback); +typedef void (*SetCallBack_Syncml_SAN_Incoming) (CALLBACK_SYNCML_SAN_INCOMING callback); +typedef void (*SetCallBack_Syncml_SAN_Operation) (CALLBACK_SYNCML_SAN_OPERATION callback); +typedef void (*SetCallBack_Alarm) (CALLBACK_ALARM callback); +typedef void (*SetCallBack_Network_On) (CALLBACK_NETWORK_ON callback); +typedef void (*SetCallBack_Network_Off) (CALLBACK_NETWORK_OFF callback); + +typedef struct { + Init_Network_Status_Noti_Handler pFunc_Init_Network_Status_Noti_Handler; + Terminate_Network_Status_Noti_Handler pFunc_Terminate_Network_Status_Noti_Handler; + + Init_Syncml_SAN_Noti_Handler pFunc_Init_Syncml_SAN_Noti_Handler; + Terminate_Syncml_SAN_Noti_Handler pFunc_Terminate_Syncml_SAN_Noti_Handler; + Add_Message pFunc_Add_Message; + Remove_Message pFunc_Remove_Message; + + Init_Alarm_Noti_Handler pFunc_Init_Alarm_Noti_Handler; + Terminate_Alarm_Noti_Handler pFunc_Terminate_Alarm_Noti_Handler; + Add_Alarm pFunc_Add_Alarm; + Remove_Alarm pFunc_Remove_Alarm; + Get_Alarm pFunc_Get_Alarm; + + SetCallBack_NetworkStatus pFunc_SetCallBack_NetworkStatus; + SetCallBack_NetworkAllCancel pFunc_SetCallBack_NetworkAllCancel; + + SetCallBack_Syncml_SAN_Incoming pFunc_SetCallBack_Syncml_SAN_Incoming; + SetCallBack_Syncml_SAN_Operation pFunc_SetCallBack_Syncml_SAN_Operation; + + SetCallBack_Alarm pFunc_SetCallBack_Alarm; + + SetCallBack_Network_On pFunc_SetCallBack_Network_On; + SetCallBack_Network_Off pFunc_SetCallBack_Network_Off; + +} PlatformMonitor_Func_Set; + +typedef struct { + PlugIn_Info_t plugIn_info; + PlatformMonitor_Func_Set func_Set; +} PlugIn_PlatformMonitor; + +PlatformMonitor_Func_Set getPlatformMonitor_Func_Set(void *plugIn_handle, PLUGIN_ERROR * error_code); + +PLUGIN_ERROR registerPlugIn_PlatformMonitor(PlugIn_PlatformMonitor plugIn); + +int get_PlatformMonitor_PlugIn_Id(); + +Init_Network_Status_Noti_Handler getFunction_PlatformMonitor_Init_Network_Status_Noti_Handler(int plugIn_id); + +Terminate_Network_Status_Noti_Handler getFunction_PlatformMonitor_Terminate_Network_Status_Noti_Handler(int plugIn_id); + +Init_Syncml_SAN_Noti_Handler getFunction_PlatformMonitor_Init_Syncml_SAN_Noti_Handler(int plugIn_id); + +Terminate_Syncml_SAN_Noti_Handler getFunction_PlatformMonitor_Terminate_Symcml_SAN_Noti_Handler(int plugIn_id); + +Add_Message getFunction_PlatformMonitor_Add_Message(int plugIn_id); + +Remove_Message getFunction_PlatformMonitor_Remove_Message(int plugIn_id); + +Init_Alarm_Noti_Handler getFunction_PlatformMonitor_Init_Alarm_Noti_Handler(int plugIn_id); + +Terminate_Alarm_Noti_Handler getFunction_PlatformMonitor_Terminate_Alarm_Noti_Handler(int plugIn_id); + +Add_Alarm getFunction_PlatformMonitor_Add_Alarm(int plugIn_id); + +Remove_Alarm getFunction_PlatformMonitor_Remove_Alarm(int plugIn_id); + +Get_Alarm getFunction_PlatformMonitor_Get_Alarm(int plugIn_id); + +SetCallBack_NetworkStatus getFunction_PlatformMonitor_SetCallBack_NetworkStatus(int plugIn_id); + +SetCallBack_NetworkAllCancel getFunction_PlatformMonitor_SetCallBack_NetworkAllCancel(int plugIn_id); + +SetCallBack_Syncml_SAN_Incoming getFunction_PlatformMonitor_SetCallBack_Syncml_SAN_Incoming(int plugIn_id); + +SetCallBack_Syncml_SAN_Operation getFunction_PlatformMonitor_SetCallBack_Syncml_SAN_Operation(int plugIn_id); + +SetCallBack_Alarm getFunction_PlatformMonitor_SetCallBack_Alarm(int plugIn_id); + +SetCallBack_Network_On getFunction_PlatformMonitor_SetCallBack_Network_On(int plugIn_id); + +SetCallBack_Network_Off getFunction_PlatformMonitor_SetCallBack_Network_Off(int plugIn_id); + +#endif /* PLUGIN_PLATFORMMONITOR_H_ */ diff --git a/framework/include/PlugIn/PlugIn_Struct.h b/framework/include/PlugIn/PlugIn_Struct.h new file mode 100755 index 0000000..46eae3e --- /dev/null +++ b/framework/include/PlugIn/PlugIn_Struct.h @@ -0,0 +1,49 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#ifndef PLUGIN_STRUCT_H_ +#define PLUGIN_STRUCT_H_ + +/** + @brief This structure represents one of the PlugIn. + */ +struct PlugIn_Info { + int plugIn_id; + void *plugIn_handle; +}; + +typedef struct PlugIn_Info PlugIn_Info_t; + +#endif /* PLUGIN_STRUCT_H_ */ diff --git a/framework/include/SyncAgent_Info.h b/framework/include/SyncAgent_Info.h new file mode 100755 index 0000000..86d2cf2 --- /dev/null +++ b/framework/include/SyncAgent_Info.h @@ -0,0 +1,64 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Jungwook Ryu + */ + +#ifndef SYNCAGENT_COMMON_H_ +#define SYNCAGENT_COMMON_H_ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +typedef enum { + FW_CONTACT = 0, + FW_CALENDAR, + FW_MEMO, + FW_EMAIL, + FW_CONTACT_GROUP, + FW_SMS, + FW_CALL_LOG, + FW_BOOKMARK, + FW_ALARM, + FW_DRM, + FW_ACCOUNT_EMAIL, + FW_ACCOUNT_EAS, + + FW_CONTENT_COUNT +} FW_CONTENT_TYPE; + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* SYNCAGENT_COMMON_H_ */ diff --git a/framework/include/Utility/fw_alloc.h b/framework/include/Utility/fw_alloc.h new file mode 100644 index 0000000..4062107 --- /dev/null +++ b/framework/include/Utility/fw_alloc.h @@ -0,0 +1,108 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#ifndef FW_ALLOC_H_ +#define FW_ALLOC_H_ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/* data structure alignment */ +#define FW_ALIGN(n, m) (((n) + ((m) - 1)) & ~((m) - 1)) + +#define FW_ALIGN16(n) FW_ALIGN(n, 2) +#define FW_ALIGN32(n) FW_ALIGN(n, 4) +#define FW_ALIGN64(n) FW_ALIGN(n, 8) + +/* memory allocation */ +#ifdef NDEBUG +#include +#include + +/* release version */ + static inline void *fw_malloc(size_t bytes) { + return malloc(bytes); + } static inline void *fw_calloc(size_t nmemb, size_t size) { + return calloc(nmemb, size); + } + + static inline void *fw_realloc(void *ptr, size_t bytes) { + return realloc(ptr, bytes); + } + + static inline char *fw_strdup(const char *src) { + return strdup(src); + } + + static inline char *fw_strndup(const char *src, unsigned int n) { + return strndup(src, n); + } + +#define fw_free free + +#else +/* debug version */ +#define fw_malloc(bytes) \ + _fw_malloc(bytes, __FILE__, __LINE__) +#define fw_calloc(nmemb, size) \ + _fw_calloc((nmemb) * (size), __FILE__, __LINE__) +#define fw_realloc(ptr, bytes) \ + _fw_realloc(ptr, bytes, __FILE__, __LINE__) +#define fw_free(ptr) \ + _fw_free(ptr) +#define fw_free_no_info \ + _fw_free_no_info + +#define fw_strdup(src) \ + _fw_strdup(src, __FILE__, __LINE__) +#define fw_strndup(src, n) \ + _fw_strndup(src, n, __FILE__, __LINE__) + + void *_fw_malloc(unsigned int bytes, const char *file, int line); + void *_fw_calloc(unsigned int bytes, const char *file, int line); + void *_fw_realloc(void *ptr, unsigned int bytes, const char *file, int line); + void _fw_free(void *ptr); + +/* TODO */ + char *_fw_strdup(const char *src, const char *file, int line); + char *_fw_strndup(const char *src, unsigned int n, const char *file, int line); + +#endif /* no DEBUG_ALLOC */ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /* FW_ALLOC_H_ */ diff --git a/framework/include/Utility/fw_alloc_internal.h b/framework/include/Utility/fw_alloc_internal.h new file mode 100644 index 0000000..c548951 --- /dev/null +++ b/framework/include/Utility/fw_alloc_internal.h @@ -0,0 +1,82 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#ifndef FW_ALLOC_INTERNAL_H_ +#define FW_ALLOC_INTERNAL_H_ + +#include +#include +#include +#include "Utility/fw_list.h" + +#include "fw_define.h" + +#define ALLOC_FRONT_REDZONE_SIZE 8 +#define ALLOC_REAR_REDZONE_SIZE 8 +#define ALLOC_FRONT_REDZONE_PATTERN 0xa7 +#define ALLOC_REAR_REDZONE_PATTERN 0x9d + +/* internal structure */ +typedef struct alloc_debug_info_s alloc_debug_info_t; +struct alloc_debug_info_s { + const char *file; + time_t time; + unsigned int line; + unsigned int size; +}; + +/* get pointer interface */ +FW_STATIC FW_INLINE void *get_realbytes(void *pBytes); +FW_STATIC FW_INLINE alloc_debug_info_t *get_debug_info(void *pRealbytes); +FW_STATIC FW_INLINE void *get_front_redzone(void *pRealbytes); +FW_STATIC FW_INLINE void *get_bytes(void *pRealbytes); +FW_STATIC FW_INLINE void *get_rear_redzone(void *pRealbytes, unsigned int bytes); +FW_STATIC FW_INLINE fw_list_node_t *get_my_list_node(void *pRealbytes); + +/* checking redzone */ +FW_STATIC FW_INLINE bool check_redzone(void *pRealbytes); +FW_STATIC FW_INLINE bool check_front_redzone(void *pRealbytes); +FW_STATIC FW_INLINE bool check_rear_redzone(void *pRealbytes); +FW_STATIC FW_INLINE bool check_redzone_with_pattern(char *redzone, char pattern, unsigned int pattern_size); + +/* alloc and init interface */ +FW_STATIC FW_INLINE void _init_debug_info(alloc_debug_info_t *debug_info, unsigned int byte_size, const char *file, int line); +FW_STATIC bool init_realbytes(void *pRealbytes, unsigned int bytes, const char *file, int line); +FW_STATIC void *_alloc_init_realbytes(unsigned int bytes, const char *file, int line); + +/* free interface */ +FW_STATIC void _free_realbytes(void *pRealbytes); + +#endif /* FW_ALLOC_INTERNAL_H_ */ diff --git a/framework/include/Utility/fw_assert.h b/framework/include/Utility/fw_assert.h new file mode 100644 index 0000000..da9413a --- /dev/null +++ b/framework/include/Utility/fw_assert.h @@ -0,0 +1,96 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#ifndef FW_ASSERT_H_ +#define FW_ASSERT_H_ + +#include +#include +#include +#include "fw_log.h" + +/** + * @file fw_assert.h + * @brief Provides assertion on exception case + */ + +/** + * @brief this macro checks errno and abort if errno != 0 + * @param[in] text string to print out on errno != 0 case + * @code +#include "agent-framework/Utility/fw_assert.h" +#include + + int main() + { + //try something + FILE* fp = fopen("ABCD.txt", "r"); + + //checking errno == 0 + //if errno != 0, then the program aborted and print "ABCD.txt open failed" in log file + fw_errno_abort("ABCD.txt open failed"); + } + * @endcode + */ +#define fw_errno_abort(text) do {\ + if (errno != 0) {\ + FW_LOGE("(errno_abort) text : %s, string error (errno = %d) : %s", text, errno, strerror(errno));\ + abort();\ + } \ + } while (0) + +/** + * @brief this macro checks whether condition failed or not and abort on condition failed case + * @param[in] condition checking condition + * @param[in] text string to print out on condition failed case + * @code +#include "agent-framework/Utility/fw_assert.h" + + int main() + { + //checking condition 1 !=2 is true or false + //if the condition is false, then the program aborted and print "1 is not same as 2" in log file + fw_assert_condition(1 != 2, "1 is not same as 2"); + } + * @endcode + */ +#define fw_assert_condition(condition, text) do {\ + if (!(condition)) {\ + FW_LOGE("(assertion failed) text : %s, condition failed at : %s", text, #condition);\ + abort();\ + } \ + } while (0) + +#endif /* FW_ASSERT_H_ */ diff --git a/framework/include/Utility/fw_async_queue.h b/framework/include/Utility/fw_async_queue.h new file mode 100644 index 0000000..b225d45 --- /dev/null +++ b/framework/include/Utility/fw_async_queue.h @@ -0,0 +1,112 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#ifndef FW_ASYNC_QUEUE_H_ +#define FW_ASYNC_QUEUE_H_ + +#include + +/** + * @file fw_async_queue.h + * @brief provide DataStructure - asynchronous Queue + */ + +/** + * @brief determine priority + * @param[in] msg1 item + * @param[in] msg2 compare item + * @param[in] user_data user_data + * @return + * @see fw_async_queue_send_msg_with_compare_priority() + */ +typedef int (*compare_priority_func) (const void *msg1, const void *msg2, void *user_data); + +/** + * @brief asynchronous Queue + */ +typedef struct fw_async_queue_s fw_async_queue_t; +struct fw_async_queue_s { + GAsyncQueue *pQueue; /**< real queue data structure */ +}; + +/** + * @brief create empty asynchronous Queue + * @return created asynchronous queue on success, otherwise a null pointer. + */ +fw_async_queue_t *fw_async_queue_alloc(); + +/** + * @brief destroy asynchronous Queue + * @param[in] pQueue asynchronous Queue + */ +void fw_async_queue_destroy(fw_async_queue_t *pQueue); + +/** + * @brief lock asynchronous Queue + * @param[in] pQueue asynchronous Queue + */ +void fw_async_queue_lock(fw_async_queue_t *pQueue); + +/** + * @brief unlock asynchronous Queue + * @param[in] pQueue asynchronous Queue + */ +void fw_async_queue_unlock(fw_async_queue_t *pQueue); + +/** + * @brief pop item from asynchronous Queue + * @remarks blocking until enter item to Queue + * @param[in] pQueue asynchronous Queue + * return item on success, otherwise null pointer + */ +void *fw_async_queue_receive_msg(fw_async_queue_t *pQueue); + +/** + * @brief send item to asynchronous Queue + * @param[in] pQueue asynchronous Queue + * @param[in] msg item + */ +void fw_async_queue_send_msg(fw_async_queue_t *pQueue, void *msg); + +/** + * @brief send item to asynchronous Queue with priority + * @param[in] pQueue asynchronous Queue + * @param[in] msg item + * @param[in] cpf priority for callback function + * @param[in] user_data user_data + */ +void fw_async_queue_send_msg_with_compare_priority(fw_async_queue_t *pQueue, void *msg, compare_priority_func cpf, void *user_data); + +#endif /* FW_ASYNC_QUEUE_H_ */ diff --git a/framework/include/Utility/fw_cache.h b/framework/include/Utility/fw_cache.h new file mode 100644 index 0000000..1e4c040 --- /dev/null +++ b/framework/include/Utility/fw_cache.h @@ -0,0 +1,129 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#ifndef FW_CACHE_H_ +#define FW_CACHE_H_ + +/** + * @file fw_cache.h + * @brief Provides cache service such as create, destroy, reload and etc + */ + +/** + * @brief Constructor used to initialize allocated objects + * @param[in] key key to allocate + * @return operation result + * @retval object pointer to cache success + * @retval 0 fail + */ +typedef void *cache_constructor_t (const char *key); + +/** + * @brief Destructor used to clean up allocated objects before they are + * @param[in] key key to allocate + * @param[in] obj object pointer + */ +typedef void cache_destructor_t (const char *key, void *obj); + +/** + * @brief Reloader used to reload allocated objects + * @param[in] key key to allocate + * @return operation result + * @retval object pointer to cache success + * @retval 0 fail + */ +typedef void *cache_reloader_t (const char *key); + +/** + * @brief Create a cache. + * + * you should register only once per process + * + * @param[in] constructor the function to be called to initialize memory when we need to allocate more memory from the os. + * @param[in] destructor destructor the function to be called before we release the memory back to the os. + * @param[in] reloader reloader the function to be called when we need to reload from the os. + * @return operation result + * @retval 1 success + * @retval 0 fail + */ +int FW_Create_Cache(cache_constructor_t *constructor, cache_destructor_t *destructor, cache_reloader_t *reloader); + +/** + * @brief Destroy a cache. + * + * you should register only once per process + * + * @return operation result + * @retval 1 success + * @retval 0 fail + */ +int FW_Destroy_Cache(); + +/** + * @brief Allocate a cache object and register has table + * + * That corresponds to the cache_name of the constructor callback function should be written. + * + * @param[in] cache_name cache name (is used hash table key) + * @return operation result + * @retval 1 success + * @retval 0 fail + */ +void *FW_Use_Cache_Info(const char *cache_name); + +/** + * @brief Return an object back to the cache. + * + * That corresponds to the cache_name of the destructor callback function should be written. + * + * @param[in] cache_name cache name (is used hash table key) + * @return operation result + * @retval 1 success + * @retval 0 fail + */ +int FW_Return_Cache_Info(const char *cache_name); + +/** + * @brief Reload an object to the cache + * + * That corresponds to the cache_name of the reloader callback function should be written. + * + * @param[in] cache_name cache name (is used hash table key) + * @retval 1 success + * @retval 0 fail + */ +void *FW_Reload_Cache_Info(const char *cache_name); + +#endif /* FW_CACHE_H_ */ diff --git a/framework/include/Utility/fw_common.h b/framework/include/Utility/fw_common.h new file mode 100644 index 0000000..09d235c --- /dev/null +++ b/framework/include/Utility/fw_common.h @@ -0,0 +1,71 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#ifndef FW_COMMON_H_ +#define FW_COMMON_H_ + +/* TODO: 종류별로 옮겨져야 한다. */ +#include +#include +#include + +#include + +#define FW_SLIST GSList + +#define fw_slist_sort(list, compare_func) g_slist_sort(list, compare_func) +#define fw_slist_find(list, data) g_slist_find(list, data) +#define fw_slist_prepend(list, data) g_slist_prepend(list, data) +#define fw_slist_append(list, data) g_slist_append(list, data) +#define fw_slist_remove(list, data) g_slist_remove(list, data) +#define fw_slist_find_custom(list, data, func) g_slist_find_custom(list, data, func) +#define fw_slist_insert_sorted(list, data, func) g_slist_insert_sorted(list, data, func) +#define fw_slist_foreach(list, func, user_data) g_slist_foreach(list, func, user_data) +#define fw_slist_free(list) g_slist_free(list) +#define fw_slist_remove_link(list, link) g_slist_remove_link(list, link) +#define fw_slist_next(list) g_slist_next(iist) + +#define FW_HASH_TABLE GHashTable + +#define fw_hash_table_new(hash_func, equal_func) g_hash_table_new(hash_func, equal_func) +#define fw_hash_table_destory(hash_table) g_hash_table_destroy(hash_table) +#define fw_hash_table_lookup(hasn_table, key) g_hash_table_lookup(hasn_table, key) +#define fw_hash_table_insert(hash_table, key, valaue) g_hash_table_insert(hash_table, key, value) +#define fw_hash_table_remove(hash_table, key) g_hash_table_remove(hash_table, key) + +#include +#define FW_BOOL bool + +#endif /* FW_COMMON_H_ */ diff --git a/framework/include/Utility/fw_compress.h b/framework/include/Utility/fw_compress.h new file mode 100644 index 0000000..71ebfb3 --- /dev/null +++ b/framework/include/Utility/fw_compress.h @@ -0,0 +1,78 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#ifndef FW_COMPRESS_H_ +#define FW_COMPRESS_H_ + +/** + * @file fw_compress.h + * @brief Provides folder de/compress operations + */ + +/** + * @brief Enumeration of compress result + */ +typedef enum { + FW_COMPRESS_SUCCESS = 1, + FW_COMPRESS_FAIL +} FW_COMPRESS_RESULT; + +/** + * @brief Enumeration of compress type + */ +typedef enum { + FW_COMPRESS_TYPE_TAR = 1, + FW_COMPRESS_TYPE_ZIP +} FW_COMPRESS_TYPE; + +/** + * @brief Compresses folder into desired format + * @param[in] type Type of compress in FW_COMPRESS_TYPE type of value + * @param[in] input_directory_path Folder path to compress + * @param[in] output_file_path Path to put comressed file + # @return FW_COMPRESS_RESULT type of value + */ +FW_COMPRESS_RESULT FW_COMPRESS(FW_COMPRESS_TYPE type, const char *input_directory_path, const char *output_file_path); + +/** + * @brief Decreases reference count of parameter spec + * @param[in] type Type of compress in FW_COMPRESS_TYPE type of value + * @param[in] input_file_path Compressed file path to decompress + * @param[in] output_direcory_path Path to put decompressed folder +# @return FW_COMPRESS_RESULT type of value + */ +FW_COMPRESS_RESULT FW_UNCOMPRESS(FW_COMPRESS_TYPE type, const char *input_file_path, const char *output_direcory_path); + +#endif /* FW_COMPRESS_H_ */ diff --git a/framework/include/Utility/fw_list.h b/framework/include/Utility/fw_list.h new file mode 100644 index 0000000..b45d397 --- /dev/null +++ b/framework/include/Utility/fw_list.h @@ -0,0 +1,70 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#ifndef FW_LIST_H_ +#define FW_LIST_H_ + +/** + * @file fw_async_queue.h + * @brief provide DataStructure - Linked List + */ + +#define prefetch(link) + +#define fw_list_iter(iter, head_ptr) \ +for (iter = (head_ptr)->next; (prefetch(iter->next) iter != (head_ptr)); \ + iter = iter->next) + + +/** + * @brief Node structure of Double Linked List + */ +typedef struct fw_list_node_s fw_list_node_t; +struct fw_list_node_s { + fw_list_node_t *next; + fw_list_node_t *prev; +}; + +void fw_list_add_node(fw_list_node_t *new_node, fw_list_node_t *head_ptr); + +void fw_list_delete_node(fw_list_node_t *target_node); + +void fw_list_move_node(fw_list_node_t *list, fw_list_node_t *head_ptr); + +int fw_list_node_count(const fw_list_node_t *head_ptr); + +void fw_list_init(fw_list_node_t *node_ptr); + +#endif /* FW_LIST_H_ */ diff --git a/framework/include/Utility/fw_log.h b/framework/include/Utility/fw_log.h new file mode 100644 index 0000000..03aecf4 --- /dev/null +++ b/framework/include/Utility/fw_log.h @@ -0,0 +1,152 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#ifndef LOG_H_ +#define LOG_H_ + +/** + * @file fw_log.h + * @brief Provides various of DLOG wrappers + */ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/** + * @brief Enumeration of log priority level + */ + typedef enum fw_log_priority_e { + FW_LOG_UNKNOWN = 0, + /**< Unknown level */ + FW_LOG_DEFAULT, /**< Default level */ + FW_LOG_VERBOSE, /**< Verbose level */ + FW_LOG_DEBUG, /**< Debug level */ + FW_LOG_INFO, /**< Info level */ + FW_LOG_WARN, /**< Warn level */ + FW_LOG_ERROR, /**< Error level */ + FW_LOG_FATAL, /**< Fatal level */ + FW_LOG_SILENT /**< Silent level */ + } fw_log_priority_t; + +/** + * @brief Terminal option for character coloring + */ +#define FW_TM_OPT_RED_WORD "\033[31m" +#define FW_TM_OPT_GREEN_WORD "\033[32m" +#define FW_TM_OPT_YELLOW_WORD "\033[33m" +#define FW_TM_OPT_BLUE_WORD "\033[34m" +#define FW_TM_OPT_PURPLE_WORD "\033[35m" +#define FW_TM_OPT_WHITE_WORD "\033[37m" + +/** + * @brief Terminal option for background coloring + */ +#define FW_TM_OPT_RED_BACKGROUND "\033[41m" +#define FW_TM_OPT_GREEN_BACKGROUND "\033[42m" +#define FW_TM_OPT_YELLOW_BACKGROUND "\033[43m" +#define FW_TM_OPT_BLUE_BACKGROUND "\033[44m" +#define FW_TM_OPT_PURPLE_BACKGROUND "\033[45m" +#define FW_TM_OPT_WHITE_BACKGROUND "\033[47m" + +/* common interface */ +#ifndef NDEBUG + +/** + * @brief Macro with pre-defined priority level + */ +#define FW_LOGV(...) FW_LOG(FW_LOG_VERBOSE, LOG_TAG, __VA_ARGS__) +#define FW_LOGD(...) FW_LOG(FW_LOG_DEBUG, LOG_TAG, __VA_ARGS__) +#define FW_LOGI(...) FW_LOG(FW_LOG_INFO, LOG_TAG, __VA_ARGS__) + +#else + +/** + * @brief Macro with pre-defined priority level + */ +#define FW_LOGV(...) +#define FW_LOGD(...) +#define FW_LOGI(...) + +#endif /* NDEBUG */ + +/** + * @brief Macro with pre-defined priority level + */ +#define FW_LOGW(...) FW_LOG(FW_LOG_WARN, LOG_TAG, __VA_ARGS__) +#define FW_LOGE(...) FW_LOG(FW_LOG_ERROR, LOG_TAG, __VA_ARGS__) +#define FW_LOGF(...) FW_LOG(FW_LOG_FATAL, LOG_TAG, __VA_ARGS__) + +/** + * @brief Macro with pre-defined priority level and terminal option + */ +#ifndef NDEBUG +#define FW_LOGV_WITH_TERMINAL_OPTION(TM_OPT, ...) FW_LOG_WITH_TERMINAL_OPTION(FW_LOG_VERBOSE, LOG_TAG, TM_OPT, __VA_ARGS__) +#else +#define FW_LOGV_WITH_TERMINAL_OPTION(TM_OPT, ...) +#endif +#define FW_LOGD_WITH_TERMINAL_OPTION(TM_OPT, ...) FW_LOG_WITH_TERMINAL_OPTION(FW_LOG_DEBUG, LOG_TAG, TM_OPT, __VA_ARGS__) +#define FW_LOGI_WITH_TERMINAL_OPTION(TM_OPT, ...) FW_LOG_WITH_TERMINAL_OPTION(FW_LOG_INFO, LOG_TAG, TM_OPT, __VA_ARGS__) +#define FW_LOGW_WITH_TERMINAL_OPTION(TM_OPT, ...) FW_LOG_WITH_TERMINAL_OPTION(FW_LOG_WARN, LOG_TAG, TM_OPT, __VA_ARGS__) +#define FW_LOGE_WITH_TERMINAL_OPTION(TM_OPT, ...) FW_LOG_WITH_TERMINAL_OPTION(FW_LOG_ERROR, LOG_TAG, TM_OPT, __VA_ARGS__) +#define FW_LOGF_WITH_TERMINAL_OPTION(TM_OPT, ...) FW_LOG_WITH_TERMINAL_OPTION(FW_LOG_FATAL, LOG_TAG, TM_OPT, __VA_ARGS__) + +/** + * @brief Macro with no concern about file/funn name and line number + */ +#define FW_LOG(LOG_PRIORITY, TAG, FORMAT...) \ + _fw_log(LOG_PRIORITY, TAG, 0, __FILE__, __func__, __LINE__, FORMAT) +#define FW_LOG_WITH_TERMINAL_OPTION(LOG_PRIORITY, TAG, TM_OPT, FORMAT...) \ + _fw_log(LOG_PRIORITY, TAG, TM_OPT, __FILE__, __func__, __LINE__, FORMAT) + +/* internal function */ + +/** + * @brief Decreases reference count of parameter spec + * @param[in] prio Priority in fw_log_priority_t type + * @param[in] log_tag Log tag to be displayed under + * @param[in] terminal_option Terminal option such as character color or background color + * @param[in] file_path Source file path + * @param[in] func_name Func name + * @param[in] line Line number + * @param[in] format Printf format + * @param[in] ... VA_LIST + */ + void _fw_log(int prio, const char *log_tag, const char *terminal_option, const char *file_path, const char *func_name, const unsigned int line, const char *format, ...); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /* LOG_H_ */ diff --git a/framework/include/Utility/fw_mainloop.h b/framework/include/Utility/fw_mainloop.h new file mode 100644 index 0000000..c3c306a --- /dev/null +++ b/framework/include/Utility/fw_mainloop.h @@ -0,0 +1,49 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#ifndef FW_MAINLOOP_H_ +#define FW_MAINLOOP_H_ + +typedef void (*Callback_Rutine) (void *data); + +void register_Callback2MainLoop(Callback_Rutine callback, void *data); + +void run_MainLoop(); + +void stop_MainLoop(); + +int isRunning_MainLoop(); + +#endif /* FW_MAINLOOP_H_ */ diff --git a/framework/include/Utility/fw_ref.h b/framework/include/Utility/fw_ref.h new file mode 100644 index 0000000..bd88359 --- /dev/null +++ b/framework/include/Utility/fw_ref.h @@ -0,0 +1,110 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#ifndef FW_REF_H_ +#define FW_REF_H_ + +#include + +/** + * @file fw_ref.h + * @brief Provides conversion service from regular object to referenced object + */ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/** + * @brief Function which is called when need to alloc some object + * @param[in] void Object to alloc + */ + typedef void *(*ALLOC_FUNCTION) (void); + +/** + * @brief Function which is called when need to free some object + * @param[in] void* Object to free + */ + typedef void (*FREE_FUNCTION) (void *); + +/** + * @brief Structure of referenced object + */ + typedef struct refObject_s { + int refcount; /**< Reference count */ + void *data; /**< Void pointer for original regular object */ + FREE_FUNCTION free_func;/**< Free function */ + } refObject_t; + +/** + * @brief Creates referenced object using given data with void pointer and function pointer for free logic + * @param[in] data Data to maintain reference information for + * @param[in] data_free_func Function pointer for free logic + * @return Referenced object in refObject_t type of structure + */ + refObject_t *create_refObject(void *data, FREE_FUNCTION data_free_func); + +/** + * @brief Returns referenced object using already referenced object and just increase reference count + * @param[in] object Referenced object to increase ref count by 1 + * @return Referenced object in refObject_t type of structure + */ + refObject_t *getRef(refObject_t *object); + +/** + * @brief Returns original object taking from referenced object + * @param[in] object Referenced object to take original object from + */ + void *getData(refObject_t *object); + +/** + * @brief Compares if two refereced object has same original object + * @param[in] object1 Referenced object to compare with + * @param[in] object2 Referenced object to compare with + * @return 1 when two are same, otherwise 0 + */ + bool same_ref(refObject_t *object1, refObject_t *object2); + +/** + * @brief Decrease reference count of given referenced object + * @remarks The object will be freed in case reference count becomes 0 + * @param[in] pRef Referenced object to decrease ref count by 1 + */ + void unref_refObject(refObject_t *pRef); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /* FW_REF_H_ */ diff --git a/framework/include/Utility/fw_sequential_id_provider.h b/framework/include/Utility/fw_sequential_id_provider.h new file mode 100644 index 0000000..368cd29 --- /dev/null +++ b/framework/include/Utility/fw_sequential_id_provider.h @@ -0,0 +1,156 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#ifndef FW_SEQUENTIAL_ID_PROVIDER_H_ +#define FW_SEQUENTIAL_ID_PROVIDER_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/** + * @file fw_sequential_id_provider.h + * @brief Support to generate unique ID + */ + +/** + * @brief Enumerations of error codes for Id provider + */ + typedef enum id_provider_error id_provider_error_t; + enum id_provider_error { + ID_PROVIDER_OK = 0, /**< successful */ + + ID_PROVIDER_NOT_EXIST_ID, /**< not exist id */ + ID_PROVIDER_OUT_OF_ID_RANGE, /**< out of id range */ + ID_PROVIDER_NOT_ENOUGH_ID, /**< full assigned */ + ID_PROVIDER_NOT_EXIST_PAGE, /**< already exist page */ + ID_PROVIDER_NOT_ENOUGH_MEMORY, /**< not enough memory */ + ID_PROVIDER_ALREADY_TRACKING_MODE_ON, /**< already tracking mode on status */ + ID_PROVIDER_ALREADY_TRACKING_MODE_OFF, /**< already tracking mode off status */ + ID_PROVIDER_PERSISTENT_CREATE_ERROR, /**< storage create fail */ + ID_PROVIDER_PERSISTENT_NOT_EXIST_PAGE /**< not exist page in storage */ + }; + +/** + * @brief Structure of ID Provider + */ + typedef struct id_provider id_provider_t; + +/** + * @brief create new id provider and register to F/W storage + * @param[in] code ID of id provider - this described in F/W configuration file + * @param[in] id_max max ID count possible id provider generate - this described in F/W configuration file + * @param[in] log2_page_size + * @return ID_PROVIDER_OK on success, otherwise a error code. + * @see id_provider_create() + */ + id_provider_error_t id_persistent_provider_create(unsigned int code, unsigned int id_max, unsigned int log2_page_size); + +/** + * @brief load id provider from F/W id_provider_tbl + * @param[in] code ID of id provider - this described in F/W configuration file + * @param[in] support_thread_safety whether thread safety or not + * @return id_provider_t * on success, otherwise a null pointer. + */ + id_provider_t *id_persistent_provider_load(unsigned int code, bool support_thread_safety); + +/** + * @brief register updated id provider to F/W id_provider_tbl + * @param[in] pId_provider updated ID provider structure + * @return ID_PROVIDER_OK on success, otherwise a error code. + */ + id_provider_error_t id_persistent_provider_update(id_provider_t *pId_provider); + +/** + * @brief create new id provider + * @remarks very similar to @ref id_persistent_provider_create(). this function use only memory but F/W storage. + * @param[in] id_max max ID count possible id provider generate - this described in F/W configuration file + * @param[in] log2_page_size + * @param[in] support_thread_safety whether thread safety or not + * @return id_provider_t * on success, otherwise a null pointer. + * @see id_persistent_provider_create() + */ + id_provider_t *id_provider_create(unsigned int id_max, unsigned int log2_page_size, bool support_thread_safety); + +/** + * @brief destroy id provider + * @remarks common interface for both persistence mode and memory mode + * @param[in] pId_provider expected to destroyed id provider + */ + void id_provider_destroy(id_provider_t *pId_provider); + +/** + * @brief tracking bit of id provider -> ON + * @param[in] pId_provider id provider + * @return ID_PROVIDER_OK on success, otherwise a error code. + */ + id_provider_error_t id_provider_tracking_mode_on(id_provider_t *pId_provider); + +/** + * @brief tracking bit of id provider -> OFF + * @param[in] pId_provider id provider + * @return ID_PROVIDER_OK on success, otherwise a error code. + */ + id_provider_error_t id_provider_tracking_mode_off(id_provider_t *pId_provider); + +/** + * @brief generate new unique ID + * @param[in] pId_provider id provider + * @param[out] new_id generated unique ID + * @return id_provider_t * on success, otherwise a null pointer. + */ + id_provider_error_t id_provider_provide_id(id_provider_t *pId_provider, unsigned int *new_id); + +/** + * @brief delete unique ID + * @param[in] pId_provider id provider + * @param[in] id expected to deleted ID + * @return id_provider_t * on success, otherwise a null pointer. + */ + id_provider_error_t id_provider_delete_id(id_provider_t *pId_provider, unsigned int id); + +/** + * @brief get number of IDs that can be issued + * @param[in] pId_provider id provider + * @return number of IDs + */ + unsigned int id_provider_get_total_free_cnt(id_provider_t *pId_provider); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /* FW_SEQUENTIAL_ID_PROVIDER_H_ */ diff --git a/framework/include/Utility/fw_sequential_id_provider_internal.h b/framework/include/Utility/fw_sequential_id_provider_internal.h new file mode 100644 index 0000000..9c9e103 --- /dev/null +++ b/framework/include/Utility/fw_sequential_id_provider_internal.h @@ -0,0 +1,175 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#ifndef FW_SEQUENTIAL_ID_PROVIDER_INTERNAL_H_ +#define FW_SEQUENTIAL_ID_PROVIDER_INTERNAL_H_ + +#include +#include "fw_list.h" +#include "fw_sequential_id_provider.h" + +#define ID_PAGE_CNT(ID_MAX_LIMIT, BITS_PER_PAGE) (((ID_MAX_LIMIT) + 1 + (BITS_PER_PAGE) - 1))/(BITS_PER_PAGE) /* since 0, 1, ... ID_MAX_LIMIT */ +#define BITS_PER_PAGE(PAGE_SIZE) ((PAGE_SIZE) * 8) +#define BITS_PER_PAGE_MASK(BITS_PER_PAGE) ((BITS_PER_PAGE) - 1) +#define DIVIDE_INT_ROUND_UP(NUM1, NUM2) (((NUM1) + (NUM2) - 1)/(NUM2)) + +unsigned int __calculate_free_bit_cnt(char *bits, unsigned int bit_cnt); +inline bool __is_bit_on(unsigned int offset, char *bits); +inline bool __is_bit_off(unsigned int offset, char *bits); +inline void __set_bit_on(unsigned int offset, char *bits); +inline void __set_bit_off(unsigned int offset, char *bits); + +typedef unsigned int id_page_flag_t; +#define ID_PAGE_FLAG_UNKNOWN 0x00 +#define ID_PAGE_FLAG_UNCHANGED 0x01 +#define ID_PAGE_FLAG_ADD 0x02 +#define ID_PAGE_FLAG_DELETE 0x04 +#define ID_PAGE_FLAG_UPDATE 0x08 + +typedef struct id_page id_page_t; +struct id_page { + fw_list_node_t link; + id_page_flag_t flag; + unsigned int page_index; + unsigned int free_bit_cnt; + unsigned int page_bit_cnt; + char *bits; +}; + +id_page_t *id_page_alloc(id_page_flag_t flag, unsigned int page_index, unsigned int free_bit_cnt, unsigned int page_bit_cnt, char *bits); +id_page_t *id_page_alloc_new_page(unsigned int page_index, unsigned int page_bit_cnt); +id_page_t *id_page_load(unsigned int code, unsigned int page_index, unsigned int page_bit_cnt); +void id_page_free(id_page_t *pId_page); + +inline bool id_page_is_empty(id_page_t *pId_page); +inline void id_page_set_flag(id_page_t *pId_page, id_page_flag_t flag); +inline id_page_flag_t id_page_get_flag(id_page_t *pId_page); +inline bool id_page_has_same_flag(id_page_t *pId_page, id_page_flag_t flag); + +inline bool id_page_is_unknown_flag(id_page_t *pId_page); +inline bool id_page_is_add_flag(id_page_t *pId_page); +inline bool id_page_is_delete_flag(id_page_t *pId_page); +inline bool id_page_is_update_flag(id_page_t *pId_page); +inline bool id_page_is_unchanged_flag(id_page_t *pId_page); + +inline unsigned int id_page_get_page_index(id_page_t *pId_page); +inline void id_page_set_page_index(id_page_t *pId_page, unsigned int index); + +inline bool id_page_is_bit_on(id_page_t *pId_page, unsigned int offset); +inline bool id_page_is_bit_off(id_page_t *pId_page, unsigned int offset); +/* return true when success */ +inline bool id_page_set_bit_on(id_page_t *pId_page, unsigned int offset); +/* return true when success */ +inline bool id_page_set_bit_off(id_page_t *pId_page, unsigned int offset); + +bool id_page_find_next_free_offset(id_page_t *id_page, unsigned int search_start_offset, unsigned int *next_free_offset); + +typedef struct id_provider_change_tracking_s id_provider_change_tracking_t; +struct id_provider_change_tracking_s { + fw_list_node_t id_page_add_list_head; + fw_list_node_t id_page_update_list_head; + fw_list_node_t id_page_delete_list_head; + fw_list_node_t id_page_unchanged_list_head; +}; + +id_provider_change_tracking_t *id_provider_change_tracking_alloc(); +void id_provider_change_tracking_free(id_provider_change_tracking_t *pTracking); +inline fw_list_node_t *id_provider_change_tracking_get_list(id_provider_change_tracking_t *pTracking, id_page_flag_t flag); + +struct id_provider { + bool persistent_mode; + unsigned int code; /* only used in persistent mode */ + + bool tracking; + + bool support_thread_safety; + GMutex *mutex; + unsigned int id_max; + + unsigned int log2_page_size; + unsigned int page_size; + unsigned int bits_per_page; + + unsigned int last_id; + + unsigned int total_free_cnt; + + unsigned int id_page_cnt; + id_page_t **id_page_array; + + id_provider_change_tracking_t *pTracking; +}; + +id_provider_t *id_provider_create_internal(bool persistent_mode, unsigned int code, unsigned int total_free_bit_cnt, unsigned int id_max, unsigned int log2_page_size, bool support_thread_safety); + +/* initial routine */ +inline void id_provider_init_routine(); + +/* lock interface */ +inline void id_provider_lock(id_provider_t *pId_provider); +inline void id_provider_unlock(id_provider_t *pId_provider); + +/* validation of id & page index */ +inline bool id_provider_is_valid_id_range(id_provider_t *pId_provider, unsigned int id); +inline bool id_provider_is_valid_page_index(id_provider_t *pId_provider, unsigned int id_page_index); + +/* calculation */ +inline bool id_provider_is_last_page_index(id_provider_t *pId_provider, unsigned int id_page_index); +inline unsigned int id_provider_calculate_id_page_array_index(id_provider_t *pId_provider, unsigned int id); +inline id_provider_error_t id_provider_calculate_page_cnt_for_id_page(id_provider_t *pId_provider, unsigned int id_page_index, unsigned int *page_cnt); +inline unsigned int id_provider_calculate_offset_in_page(unsigned int id, unsigned int bits_per_page); +inline unsigned int id_provider_calculate_id(id_provider_t *pProvider, unsigned int id_page_index, unsigned int offset); + +/* fetch id page */ +inline id_provider_error_t id_provider_fetch_id_page_by_index(id_provider_t *pId_provider, unsigned int index, id_page_t **ppId_page); +inline id_provider_error_t id_provider_fetch_id_page(id_provider_t *pId_provider, unsigned int id, id_page_t **ppId_page); + +/* id page management */ +inline id_provider_error_t id_provider_set_id_page_index(id_provider_t *pId_provider, id_page_t *pId_page, unsigned int index); + +void id_provider_move_id_page(id_provider_t *pId_provider, id_page_t *id_page, id_page_flag_t next); +void id_provider_remove_id_page(id_provider_t *pId_provider, id_page_t *id_page); +id_page_t *id_provider_add_id_page(id_provider_t *pId_provider, unsigned int page_index); +id_provider_error_t id_provider_load_id_page(id_provider_t *pId_provider, unsigned int page_index, id_page_t **id_page); + +bool id_provider_set_id_page_bit_on(id_provider_t *pId_provider, id_page_t *id_page, unsigned int offset); +bool id_provider_set_id_page_bit_off(id_provider_t *pId_provider, id_page_t *id_page, unsigned int offset); + +void id_provider_reset_tracking_info(id_provider_t *pId_provider); + +/* alloc & free */ +void id_provider_destroy_id_page_array(unsigned int id_page_cnt, id_page_t **id_page_array); + +#endif /* FW_SEQUENTIAL_ID_PROVIDER_INTERNAL_H_ */ diff --git a/framework/include/Utility/fw_thread.h b/framework/include/Utility/fw_thread.h new file mode 100644 index 0000000..f816599 --- /dev/null +++ b/framework/include/Utility/fw_thread.h @@ -0,0 +1,74 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#ifndef FW_THREAD_H_ +#define FW_THREAD_H_ + +#include +#include + +/* for pthread.h */ +#define FW_THREAD_T pthread_t +#define FW_THREAD_MUTEX_T pthread_mutex_t +#define FW_THREAD_COND_T pthread_cond_t +#define FW_THREAD_KET_T pthread_key_t + +#define fw_thread_mutex_lock(mutex) pthread_mutex_lock(mutex) +#define fw_thread_mutex_unlock(mutex) pthread_mutex_unlock(mutex) +#define fw_thread_create(thread_id, attr, start_function, arg) pthread_create(thread_id, attr, start_function, arg) +#define fw_thread_detach(thread_id) pthread_detach(thread_id) +#define fw_thread_cond_signal(cond) pthread_cond_signal(cond) +#define fw_thread_cond_wait(cond, mutex) pthread_cond_wait(cond, mutex) +#define fw_thread_kill(thread_id, signo) pthread_kill(thread_id, signo) +#define fw_thread_self() pthread_self() +#define fw_thread_exit(retval) pthread_exit(retval) +#define fw_thread_setspecific(key, value) pthread_setspecific(key, value) +#define fw_thread_sigmask(how, new_mask, signo) pthread_sigmask(how, new_mask, signo) + +pthread_mutex_t *fw_alloc_init_mutex(); +void fw_free_mutex(pthread_mutex_t *mutex); + +pthread_cond_t *fw_alloc_init_thread_cond(); +void fw_free_thread_cond(pthread_cond_t *thread_cond); + +/* for signal.h */ +#define FW_SIGSET_T sigset_t +#define FW_SIGACTION_T struct sigaction + +#define fw_sigaction(signum, act, oldact) sigaction(signum, act, oldact) +#define fw_sigemptyset(set) sigemptyset(set) +#define fw_sigaddset(set, signum) sigaddset(set, signum) + +#endif /* FW_THREAD_H_ */ diff --git a/framework/include/Utility/fw_time.h b/framework/include/Utility/fw_time.h new file mode 100644 index 0000000..5143a5a --- /dev/null +++ b/framework/include/Utility/fw_time.h @@ -0,0 +1,63 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#ifndef FW_TIME_H_ +#define FW_TIME_H_ + +#include + +/** + * @file fw_time.h + * @brief Provides time manipulation functionality + */ + +#define FW_TIME_T time_t + +#define fw_time(t) time(t) + +#define FW_TM struct tm + +#define fw_localtime(time) localtime(time) + +#define fw_mktime(tm_time) mktime(tm_time) + +/** + * @brief Convert time stamp in second to UTC time stampà + * @param[in] seconds Time stamp in second + * @return UTC time stamp + */ +int FW_Convert_Seconds_To_UTC(int seconds); + +#endif /* FW_TIME_H_ */ diff --git a/framework/include/Utility/fw_timer.h b/framework/include/Utility/fw_timer.h new file mode 100644 index 0000000..0f4dfbe --- /dev/null +++ b/framework/include/Utility/fw_timer.h @@ -0,0 +1,71 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#ifndef FW_TIMER_H_ +#define FW_TIMER_H_ + +#include +#include "fw_list.h" + +#define FW_TIMER_MAX_LABEL_LEN 512 + +typedef struct fw_timer_element_s fw_timer_element_t; +typedef struct fw_timer_s fw_timer_t; + +typedef enum { + FW_TIMER_OK = 0, + FW_TIMER_OUT_OF_MEMORY, + FW_TIMER_INVALID_TIMER, + FW_TIMER_GETTIME_ERROR +} FW_ERROR; + +struct fw_timer_element_s { + fw_list_node_t link; + struct timeval start_time; + struct timeval finish_time; + char label[FW_TIMER_MAX_LABEL_LEN + 1]; +}; + +struct fw_timer_s { + fw_list_node_t element_head; +}; + +fw_timer_t *fw_timer_alloc(); +FW_ERROR fw_timer_start(fw_timer_t *pTimer, char *label); +FW_ERROR fw_timer_finish(fw_timer_t *pTimer, char *label, double *passed_sec); +FW_ERROR fw_timer_print(fw_timer_t *pTimer); +FW_ERROR fw_timer_free(fw_timer_t *pTimer); + +#endif /* FW_TIMER_H_ */ diff --git a/framework/include/agent-framework/Account/Account_Error.h b/framework/include/agent-framework/Account/Account_Error.h new file mode 100755 index 0000000..3bf87e6 --- /dev/null +++ b/framework/include/agent-framework/Account/Account_Error.h @@ -0,0 +1,61 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#ifndef ACCOUNT_ERROR_H_ +#define ACCOUNT_ERROR_H_ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/** + * @file Account_Error.h + * @brief Definition of framework error codes for Account module + */ + +/** + * @brief Enumerations of error codes for Account module + */ + typedef enum { + ACCOUNT_SUCCESS, /**< when Account Operation is succeed */ + ACCOUNT_FAIL, /**< when Account Operation is failed */ + ACCOUNT_EMPTY, /**< when Account is not exist */ + ACCOUNT_CHANGED /**< when Account storage changed */ + } ACCOUNT_ERROR; + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /* ACCOUNT_ERROR_H_ */ diff --git a/framework/include/agent-framework/DACI/DACI_Agent_Handler_Manager.h b/framework/include/agent-framework/DACI/DACI_Agent_Handler_Manager.h new file mode 100755 index 0000000..5317d9e --- /dev/null +++ b/framework/include/agent-framework/DACI/DACI_Agent_Handler_Manager.h @@ -0,0 +1,767 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu , + * Heeyoung Hwang + */ + +#ifndef DACI_AGENT_HANDLER_MANAGER_H_ +#define DACI_AGENT_HANDLER_MANAGER_H_ + +#include "DACI_Common.h" + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/** + * @file DACI_Agent_Handler_Manager.h + * @brief Interface list to use framework Common DataBase + */ + +/** + * @brief Structure of managing database connection + */ + typedef struct { + GHashTable *daci_handlerTable; /**< agent db handler hash table */ + pthread_mutex_t *daci_handlerTable_mutex; + /**< mutex for agent db handler hash table */ + } daci_handler_mgr; + +/* + * @brief alloc the agent db handler manager + * @return operation result + * @retval DACI_SUCCESS success + * @retval DACI_ERR_DB_HANDLER_MGR fail + */ + DACI_RETURN DACI_Alloc_AgentDB_Handler_Mgr(); + +/* + * @brief free the agent db handler manager + * @return operation result + * @retval DACI_SUCCESS success + * @retval DACI_ERR_DB_HANDLER_MGR fail + */ + DACI_RETURN DACI_Free_AgentDB_Handler_Mgr(); + +/* + * @brief delete all accounts data from Email-Service, Contacts-Service database, Calendar-Service database, Agent database + * @return operation result + * @retval DACI_SUCCESS success + * @retval DACI_ERRORS fail + */ + DACI_RETURN DACI_Clear_All_Database_Account(); + +/* + * @brief delete one account data from Email-Service, Contacts-Service database, Calendar-Service database, Agent database + * @param[in] accountId account id of SyncAgent + * @return operation result + * @retval DACI_SUCCESS success + * @retval DACI_ERR_DELETE_LAST_ACCOUNT success ( delete last account ) + * @retval DACI_ERRORS fail + */ + DACI_RETURN DACI_Delete_All_Database_Account(int accountId); + +/* + * @brief open Agent database + * @return operation result + * @retval DACI_SUCCESS success + * @retval DACI_ERR_OPEN_FAILED fail + */ + DACI_RETURN DACI_Open_Agent(); + +/* + * @brief close Agent database + * @return operation result + * @retval DACI_SUCCESS success + * @retval DACI_ERR_CLOSE_FAILED fail + */ + DACI_RETURN DACI_Close_Agent(); + +/* + * @brief create Agent database + * @return operation result + * @retval DACI_SUCCESS success + * @retval DACI_ERR_CLOSE_FAILED fail + */ + DACI_RETURN DACI_Create_Agent_Default_Table(); + +/* +* @brief start Agent database transaction +* @return operation result +* @retval DACI_SUCCESS success +* @retval DACI_ERR_TRANSACTION_FAILED fail +*/ + DACI_RETURN DACI_Begin_Transaction(); + +/* +* @brief finish Agent database transaction +* @param[in] transaction commit or rollback transaction +* @return operation result +* @retval DACI_SUCCESS success +* @retval DACI_ERR_TRANSACTION_FAILED fail +*/ + DACI_RETURN DACI_End_Transaction(DACI_TRANSACTION transaction); + +/* + * @brief insert account into account_tbl + * @param[in] account account info + * @return operation result + * @retval accountId success + * @retval -1 fail + */ + int DACI_Add_Account(daci_account *account); + +/* + * @brief delete account data from Agent database + * @param[in] accountId accountId + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Delete_Account(int accountId); + +/* + * @brief set emailAddress to account_tbl + * @param[in] accountId accountId + * @param[in] emailAddress new emailAddress + * @param[in] accessName access module name + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Set_Account_Email_Address(int accountId, char *emailAddress, char *accessName); + +/* + * @brief set password to account_tbl + * @param[in] accountId accountId + * @param[in] password new password + * @param[in] accessName access module name + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Set_Account_Password(int accountId, char *password, char *accessName); + +/* + * @brief get all accountId from account_tbl + * @param[out] count count of accountId + * @return operation result + * @retval array of ccountId success + * @retval 0 fail + */ + int *DACI_Get_Account_Account_Id_List(int *count); + +/* + * @brief get emailAddress from account_tbl + * @param[in] accountId accountId + * @return operation result + * @retval emailAddress success + * @retval 0 fail + */ + char *DACI_Get_Account_Email_Address(int accountId); + +/* + * @brief get password from account_tbl + * @param[in] accountId accountId + * @return operation result + * @retval password success + * @retval 0 fail + */ + char *DACI_Get_Account_Password(int accountId); + +/* + * @brief checking whether the accountId exist in account_tbl + * @param[in] accountId accountId + * @return checking result + * @retval 1 exist + * @retval 0 (or error value) not exist + */ + int DACI_IsExist_Account(int accountId); + +/* + * @brief insert folder into folder_tbl + * @param[in] folder array of folder info + * @param[out] count count of folder info + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Add_Folder(daci_folder *folder, int count); + +/* + * @brief delete folder from folder_tbl by folderId + * @param[in] folderId folderId + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Delete_Folder_By_Folder_Id(char *folderId); + +/* + * @brief get folderId from folder_tbl + * @param[in] accountId accountId + * @param[in] itemTypeId itemTypeId + * @param[in] serviceId serviceId + * @param[in] folderTypeId folderTypeId + * @return operation result + * @retval folderId success + * @retval 0 fail + */ + char *DACI_Get_Folder_Folder_Id_By_Service_Id(int accountId, int itemTypeId, char *serviceId, int folderTypeId); + +/* + * @brief get folderId from folder_tbl by folderTypeId + * @param[in] accountId accountId + * @param[in] itemTypeId itemTypeId + * @param[in] folderTypeId folderTypeId + * @return operation result + * @retval folderId success + * @retval 0 fail + */ + daci_id_list *DACI_Get_Folder_Folder_Id_By_Folder_Type_Id(int accountId, int itemTypeId, int folderTypeId); + +/* + * @brief get serviceId from folder_tbl + * @param[in] folderId folderId + * @return operation result + * @retval serviceId success + * @retval 0 fail + */ + char *DACI_Get_Folder_Service_Id(char *folderId); + +/* + * @brief get all folder_id_list from folder_tbl by data_store_id + * get all the folders in account and data store + * @param[in] account_id account_id + * @param[in] itemTypeId itemTypeId + * @return operation result + * @retval array of folder_id success + * @retval 0 fail + */ + daci_id_list *DACI_Get_Folder_Folder_Id_List_By_Item_Type_Id(int account_id, int itemTypeId); + +/* + * @brief get item from folder_tbl + * belonging to different account of folder get folder with the same service_id + * @param[in] accountId accountId + * @param[in] folderId folderId + * @param[in] count count of item info + * @return operation result + * @retval array of folder info success + * @retval 0 fail + */ + daci_folder *DACI_Get_Folder_Mapping_Service_Id(int accountId, char *folderId, int *count); + +/* + * @brief insert item into item_tbl + * @param[in] item array of item info + * @param[in] count count of item info + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Add_Item(daci_item *item, int count); + +/* + * @brief delete item from item_tbl by itemId + * @param[in] itemId itemId + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Delete_Item_By_Item_Id(char *itemId); + +/* + * @brief delete item from item_tbl by accountId and itemTypeId + * @param[in] accountId accountId + * @param[in] itemTypeId itemTypeId + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Delete_Item_By_Item_Type_Id(int accountId, int itemTypeId); + +/* + * @brief get itemId from item_tbl + * @param[in] accountId accountId + * @param[in] serviceId serviceId + * @param[in] itemTypeId itemTypeId + * @return operation result + * @retval itemId success + * @retval 0 fail + */ + char *DACI_Get_Item_Item_Id(int accountId, char *serviceId, int itemTypeId); + +/* + * @brief get serviceId from item_tbl + * @param[in] itemId itemId + * @return operation result + * @retval serviceId success + * @retval 0 fail + */ + char *DACI_Get_Item_Service_Id(char *itemId); + +/* + * @brief get item information from item_tbl + * @param[in] itemId itemId + * @return operation result + * @retval item info success + * @retval 0 fail + */ + daci_item *DACI_Get_Item(char *itemId); + +/* + * @brief get all id in folder from item_tbl + * @param[in] folderId folderId + * @param[in] columnName columnName (COLUMN_NAME_ITEM_ID or COLUMN_NAME_SERVICE_ID) + * @return operation result + * @retval array of item id success + * @retval 0 fail + */ + daci_id_list *DACI_Get_Item_Id_List(char *folderId, DACI_COLUMN_NAME columnName); + +/* + * @brief get item from item_tbl by accountId + * get all the items in account + * @param[in] accountId accountId + * @param[in] itemTypeId itemTypeId + * @param[in] count count of item info + * @return operation result + * @retval array of item info success + * @retval 0 fail + */ + daci_item *DACI_Get_item_By_Account_Id(int accountId, int itemTypeId, int *count); + +/* + * @brief get item data from item_tbl and account_item_changelog_tbl + * Among the items that belong to the itemTypeId, Search for item info belong to the changelog + * @param[in] accountId accountId + * @param[in] itemTypeId itemTypeId + * @param[in] count count of item data + * @return operation result + * @retval array of item data success + * @retval 0 fail + */ + daci_item_info *DACI_Get_Item_Info_By_Item_Type_Id(int accountId, int itemTypeId, int *count); + +/* + * @brief get item from item_tbl + * belonging to different account of item get item with the same service_id + * @param[in] accountId accountId + * @param[in] itemId itemId + * @param[in] count count of item info + * @return operation result + * @retval array of item info success + * @retval 0 fail + */ + daci_item *DACI_Get_item_Mapping_Service_Id(int accountId, char *itemId, int *count); + +/* + * @brief get all id from item_tbl + * @param[in] data_store_id data_store_id + * @return operation result + * @retval array of item id success + * @retval 0 fail + */ + daci_id_list *DACI_Get_Item_Id_List_By_Data_Store_Id(int data_store_id); + +/* + * @brief get item id list + * @param[in] account_id F/W account id + * @param[in] data_store_id data_store_id + * @return operation result + * @retval array of item id success + * @retval 0 fail or not exist + */ + daci_id_list *DACI_Get_Item_Id_List_By_Data_Store_Id_with_AccountID(int account_id, int data_store_id); + +/* + * @brief get item id list from item_tbl and account_item_changelog_tbl + * Among the items that belong to the data_store_id, Search for item info belong to the changelog by operation_id + * @param[in] account_id account_id + * @param[in] data_store_id data_store_id + * @param[in] operation_id operation_id + * @return operation result + * @retval array of item id success + * @retval 0 fail + */ + daci_id_list *DACI_Get_Item_Id_List_By_Operation_Id(int account_id, int data_store_id, int operation_id); + +/* + * @brief checking whether the itemId exist in item_tbl + * @param[in] itemId itemId + * @return checking result + * @retval 1 exist + * @retval 0(or error value) not exist + */ + int DACI_IsExist_Item(char *itemId); + +/* + * @brief insert config into config_tbl + * @param[in] config config info + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Add_Config(daci_config *config); + +/* + * @brief delete config from config_tbl by key + * @param[in] configId configId + * @param[in] key key + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Delete_Config_By_Key(int configId, char *key); + +/* + * @brief get config info from config_tbl by accountId + * get all the config in account + * @param[in] configId configId + * @param[in] count count of config info + * @return operation result + * @retval array of config info success + * @retval 0 fail + */ + daci_config *DACI_Get_Config_By_Config_Id(int configId, int *count); + +/* + * @brief get config info from config_tbl by key + * @param[in] config config info (configId, key) + * @param[out] config config info (configId, key, value, type) + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Get_Config_By_Key(daci_config *config); + +/* + * @brief checking whether config of the config exist in config_tbl + * @param[in] configId configId + * @param[in] key key + * @return checking result + * @retval 1 exist + * @retval 0(or error value) not exist + */ + int DACI_IsExist_Config(int configId, char *key); + +/* + * @brief insert or update config into config_tbl + * checking whether the config exist in config_tbl + * If it does not exist, insert config into config_tbl + * If it existed, update config into config_tbl + * @param[in] config config info + * @param[in] count count of config info + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Update_Config(daci_config *config, int count); + +/* + * @brief insert itemChangelog into account_item_changelog_tbl + * @param[in] accountId accountId + * @param[in] itemChangelog array of itemChangelog info + * @param[in] count count of itemChangelog info + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Add_Item_Changelog(int accountId, daci_item_changelog *itemChangelog, int count); + +/* + * @brief delete itemChangelog from account_item_changelog_tbl by itemId + * @param[in] accountId accountId + * @param[in] itemId itemId + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Delete_Item_Changelog_By_Item_Id(int accountId, char *itemId); + +/* + * @brief delete itemChangelog from account_item_changelog_tbl by itemId list + * @param[in] accountId accountId + * @param[in] itemIdList array of itemId + * @param[in] count count of itemId + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Delete_Item_Changelog_By_Item_Id_List(int accountId, char **itemIdList, int count); + +/* + * @brief delete itemChangelog from account_item_changelog_tbl by itemTypeId + * @param[in] accountId accountId + * @param[in] itemTypeId itemTypeId + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Delete_Item_Changelog_By_Item_Type_Id(int accountId, int itemTypeId); + +/* + * @brief set operationId and syncStatus to account_item_changelog_tbl + * @param[in] accountId accountId + * @param[in] itemChangelog itemChangelog info (operationId, syncStatus, accessName, itemId) + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Set_Item_Changelog_Operation_Id(int accountId, daci_item_changelog *itemChangelog); + +/* + * @brief set syncStatus to account_item_changelog_tbl + * @param[in] accountId accountId + * @param[in] itemChangelog itemChangelog info (syncStatus, accessName, itemId) + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Set_Item_Changelog_Sync_Status(int accountId, daci_item_changelog *itemChangelog); + +/* + * @brief set SYNC_WAIT to account_item_changelog_tbl + * Among the items that match to the itemTypeId and belong to the folder + * If it existed in account_item_changelog_tbl, set SYNC_WAIT to account_item_changelog_tbl + * @param[in] accountId accountId + * @param[in] folderIdList array of folderId + * @param[in] folderIdCount count of folderId + * @param[in] itemTypeIdList array of itemTypeId + * @param[in] itemTypeIdCount count of itemTypeId + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Set_Item_Changelog_Wait_Status(int accountId, char **folderIdList, int folderIdCount, int *itemTypeIdList, int itemTypeIdCount); + +/* + * @brief get itemChangelog info from account_item_changelog_tbl by itemId + * @param[in] accountId accountId + * @param[in] itemChangelog itemChangelog info (itemId) + * @param[out] itemChangelog itemChangelog info (itemId, operationId, syncStatus, accessName) + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Get_Item_Changelog_By_Item_Id(int accountId, daci_item_changelog *itemChangelog); + +/* + * @brief checking whether the itemId exist in account_item_changelog_tbl + * @param[in] accountId accountId + * @param[in] itemId itemId + * @return checking result + * @retval 1 exist + * @retval 0(or error value) not exist + */ + int DACI_IsExist_Item_Changelog(int accountId, char *itemId); + +/* + * @brief insert anchor into last_anchor_tbl + * @param[in] lastAnchor lastAnchor info + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Add_Last_Anchor(daci_last_anchor *lastAnchor); + +/* + * @brief set last_anchor_server and last_anchor_client to last_anchor_tbl + * @param[in] lastAnchor lastAnchor info + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Set_Last_Anchor(daci_last_anchor *lastAnchor); + +/* + * @brief get last_anchor_server and last_anchor_client from last_anchor_tbl by itemTypeId + * @param[in] accountId accountId + * @param[in] itemTypeId itemTypeId + * @param[out] count count of lastAnchor info + * @return operation result + * @retval lastAnchor info success + * @retval 0 fail + */ + daci_last_anchor *DACI_Get_Last_Anchor_By_Item_Type_Id(int accountId, int itemTypeId, int *count); + +/* + * @brief insert mapping into mapping_tbl + * @param[in] mapping mapping info + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Add_Mapping(daci_mapping *mapping); + +/* + * @brief delete mapping from mapping_tbl by luid + * @param[in] accountId accountId + * @param[in] luid luid + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Delete_Mapping_By_Luid(int accountId, char *luid); + +/* + * @brief get all mapping info from mapping_tbl by accountId + * get all the mapping info in account + * @param[in] accountId accountId + * @param[out] count count of mapping info + * @return operation result + * @retval array of mapping info success + * @retval 0 fail + */ + daci_mapping *DACI_Get_Mapping_By_Account_Id(int accountId, int *count); + +/* + * @brief get luid from mapping_tbl by guid + * @param[in] accountId accountId +* @param[in] luid luid + * @return operation result + * @retval guid guid + * @retval 0 fail + */ + char *DACI_Get_Mapping_Guid(int accountId, char *luid); + +/* + * @brief checking whether account exist in mapping_tbl + * @param[in] accountId accountId + * @return checking result + * @retval 1 exist + * @retval 0(or error value) not exist + */ + int DACI_IsExist_Mapping_By_Account_Id(int accountId); + +/* + * @brief insert id_provider into id_provider_tbl + * @param[in] id_provider id_provider info + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Add_ID_Provider(daci_id_provider *id_provider); + +/* + * @brief get id_provider from id_provider_tbl + * @param[in] id_provider_code id_provider_code + * @param[out] id_provider id_provider info + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Get_ID_Provider(unsigned int id_provider_code, daci_id_provider **id_provider); + +/* + * @brief update id_provider in id_provider_tbl + * @param[in] id_provider id_provider info + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Update_ID_Provider(daci_id_provider *id_provider); + +/* + * @brief insert id_page into id_page_tbl + * @param[in] id_page id_page info + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Add_ID_Page(daci_id_page *id_page, unsigned int page_byte_size); + +/* + * @brief delete id_page from id_page_tbl by page_index + * @param[in] id_provider_code id_provider_code + * @param[in] page_index page_index + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Delete_ID_Page(unsigned int id_provider_code, unsigned int page_index); + +/* + * @brief insert id_page into id_page_tbl + * @param[in] id_provider_code id_provider_code + * @param[in] page_index page_index + * @param[out] page_bit page_bit + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Get_ID_Page(unsigned int id_provider_code, unsigned int page_index, char **page_bit); + +/* + * @brief insert id_page into id_page_tbl + * @param[in] id_page id_page info + * @param[in] page_byte_size page_bit's byte size + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ + DACI_RETURN DACI_Update_ID_Page(daci_id_page *id_page, unsigned int page_byte_size); + +/* + * @brief add the handler pointer to handler hash table + * @param[in] key unique key to distinguish handler pointer + * @param[in] pHandler db handler pointer + * @return operation result + * @retval DACI_SUCCESS success + * @retval DACI_ERR_DB_HANDLER_MGR fail + */ + DACI_RETURN add_agentHandler(unsigned int key, DACI_HANDLER *pHandler); + +/* + * @brief add the handler pointer to handler hash table + * @param[in] key unique key to distinguish handler pointer + * @return operation result + * @retval DACI_SUCCESS success + * @retval DACI_ERR_DB_HANDLER_MGR fail + */ + DACI_RETURN remove_agentHandler(unsigned int key); + +/* + * @brief add the handler pointer to handler hash table + * @param[in] key unique key to distinguish handler pointer + * @return operation result + * @retval DACI_SUCCESS success + * @retval DACI_ERR_DB_HANDLER_MGR fail + */ + DACI_HANDLER *get_agentHandler(unsigned int key); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /* DACI_AGENT_HANDLER_MANAGER_H_ */ diff --git a/framework/include/agent-framework/DACI/DACI_Common.h b/framework/include/agent-framework/DACI/DACI_Common.h new file mode 100755 index 0000000..280e067 --- /dev/null +++ b/framework/include/agent-framework/DACI/DACI_Common.h @@ -0,0 +1,359 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu , + * Heeyoung Hwang + */ + +#ifndef DACI_COMMON_H_ +#define DACI_COMMON_H_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "EXT_DACI_Errors.h" + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/** + * @file DACI_Common.h + * @brief Common factor of Framework common database + */ + +#define MO_HANDLER sqlite3 + +#define DACI_HANDLER sqlite3 + +#define DACI_RETRY_COUNT 10 + +#define DACI_MAX_QUERY_LENGTH 2048 + +#define DACI_MAX_ACCOUNT 10 + +#define DACI_FOLDER_TYPE_COUNT 19 + +#define DACI_ITEM_TYPE_COUNT 6 + +#define DACI_OPERATION_TYPE_COUNT 3 + +#define DACI_MEMORY_SET(ptr) memset(ptr, 0x00, sizeof(ptr)); + +#define DACI_MEMORY_MALLOC(type, size, count) (type)malloc(size*count) + +#define DACI_MEMORY_CALLOC(type, size, count) (type)calloc(count, size) + +#define DACI_MEMORY_FREE(src) \ + if (src != NULL) { \ + free(src); \ + src = NULL; \ + } \ + +#define DACI_STRDUP(src) (src == NULL) ? NULL : strdup(src); + +#define DACI_ATOI(src) (src == NULL) ? 0 : atoi(src); + +#define DACI_GET_THREAD_ID pthread_self() + +/** + * @brief rename sqlite3 connection + */ + typedef sqlite3_stmt *daci_stmt; + +/** + * @brief Enumerations of database peak type + */ + typedef enum { + PEAK_TYPE_ON = 601, /**< peak type on */ + PEAK_TYPE_ON_N_OFF, /**< peak type N off */ + PEAK_TYPE_OFF /**< peak type off */ + } DACI_PEAK_TYPE; + +/** + * @brief Enumerations of database transaction + */ + typedef enum { + TRANSACTION_COMMIT, /**< means commit */ + TRANSACTION_ROLLBACK + /**< means rollback */ + } DACI_TRANSACTION; + +/** + * @brief Enumerations of common db's table list + */ + typedef enum { + TABLE_NAME_ACCOUNT, /**< means account_tbl */ + TABLE_NAME_FOLDER, /**< means folder_tbl */ + TABLE_NAME_ITEM, /**< means item_tbl */ + TABLE_NAME_CONFIG, /**< means config_tbl */ + TABLE_NAME_ACCOUNT_ITEM_CHANGELOG, /**< means account_item_changelog_tbl */ + TABLE_NAME_LAST_ANCHOR, /**< means last_anchor_tbl */ + TABLE_NAME_MAPPING, /**< means mapping_tbl */ + TABLE_NAME_ID_PROVIDER, /**< means id_provider_tbl */ + TABLE_NAME_ID_PAGE, /**< means id_page_tbl */ + + TABLE_NAME_MAX /**< count of common database's tables */ + } DACI_TABLE_NAME; + +/** + * @brief Enumerations of common column + */ + typedef enum { + COLUMN_NAME_ACCOUNT_ID, /**< means column, account_id */ + COLUMN_NAME_ITEM_ID, /**< means column, item_id */ + COLUMN_NAME_SERVICE_ID, /**< means column, service_id */ + COLUMN_NAME_ACCESS_NAME, /**< means column, access_name */ + + COLUMN_NAME_MAX /**< count of common columns */ + } DACI_COLUMN_NAME; + +/** + * @brief Enumerations of structure type concern of DACI + */ + typedef enum { + STRUCT_TYPE_ACCOUNT, /**< means structure, daci_account */ + STRUCT_TYPE_FOLDER, /**< means structure, daci_folder */ + STRUCT_TYPE_ITEM, /**< means structure, daci_item */ + STRUCT_TYPE_CONFIG, /**< means structure, daci_config */ + STRUCT_TYPE_ITEM_CHANGELOG, /**< means structure, daci_item_changelog */ + STRUCT_TYPE_LAST_ANCHOR, /**< means structure, daci_last_anchor */ + STRUCT_TYPE_MAPPING, /**< means structure, daci_mapping */ + STRUCT_TYPE_ITEM_INFO, /**< means structure, daci_item_info */ + STRUCT_TYPE_ID_LIST, /**< means structure, daci_id_list */ + + STRUCT_TYPE_MAX /**< count of enumeration */ + } DACI_STRUCT_TYPE; + +/** + * @brief Structure of table - mapped column of account_tbl + */ + typedef struct { + int account_id; /**< account_id */ + char *email_address; /**< email_address */ + char *password; /**< password */ + bool enable; /**< enable */ + char *accessName; + /**< name of accessor */ + } daci_account; + +/** + * @brief Structure of table - mapped column of folder_tbl + */ + typedef struct { + char *folder_id; /**< F/W folder id */ + int data_store_id; + /**< service data connector pluIn's ID described in F/W config file */ + int account_id; /**< F/W account id */ + int folder_type_id; + /**< data connector plugIn has this folder type id */ + char *service_id; + /**< service folder id */ + char *parent_folder_id; + /**< parent folder id if exist hierarchy */ + char *access_name; + /**< name of accessor */ + } daci_folder; + +/** + * @brief Structure of table - mapped column of item_tbl + */ + typedef struct { + char *item_id; /**< F/W item id */ + int data_store_id; + /**< service data connector pluIn's ID described in F/W config file */ + int account_id; /**< F/W account id */ + char *folder_id; /**< F/W folder id */ + char *service_id; + /**< service item id */ + char *access_name; /**< name of accessor */ + } daci_item; + +/** + * @brief Structure of table - mapped column of config_tbl + */ + typedef struct { + int config_id; /**< configuration id, this means account id */ + char *key; /**< configuration key */ + char *value; /**< configuration value */ + char *type; /**< configuration type */ + char *access_name; /**< name of accessor */ + } daci_config; + +/** + * @brief Structure of table - mapped column of account_item_changelog_tbl + */ + typedef struct { + char *item_id; /**< F/W item id */ + int operation_id; /**< operation id - add, delete, update */ + char *status; /**< user defined status of item */ + char *access_name; /**< name of accessor */ + } daci_item_changelog; + +/** + * @brief Structure of table - mapped column of last_anchor_tbl + */ + typedef struct { + int account_id; /**< F/W account id */ + int data_store_id; /**< service data connector pluIn's ID described in F/W config file */ + char *last_anchor_server; /**< last anchor that server has */ + char *last_anchor_client; /**< last anchor that client has */ + char *access_name; /**< name of accessor */ + } daci_last_anchor; + +/** + * @brief Structure of table - mapped column of mapping_tbl + */ + typedef struct { + int account_id; /**< F/W account id */ + int data_store_id; /**< service data connector pluIn's ID described in F/W config file */ + char *luid; /**< Locally unique identifier */ + char *guid; + /**< Globally unique identifier */ + char *access_name; /**< name of accessor */ + } daci_mapping; + +/** + * @brief Structure of Item information + */ + typedef struct { + char *itemId; /**< F/W item id */ + int itemTypeId; /**< service data connector pluIn's ID described in F/W config file */ + char *serviceId; /**< service item id */ + int operationId; /**< operation type - add, delete, update */ + char *syncStatus; /**< user defined status of item */ + } daci_item_info; + +/** + * @brief Structure of Item id's container + */ + typedef struct { + int count; /**< count of id */ + char **id; /**< real id list */ + } daci_id_list; + +/** + * @brief Structure of table - mapped column of id_provider_tbl + */ + typedef struct { + unsigned int id_provider_code; /**< ID of id provider - this described in F/W configuration file */ + unsigned int id_capacity; /**< max ID count possible id provider generate - this described in F/W configuration file */ + unsigned int bit_per_page; + /**< most number of bit per one page */ + unsigned int last_id; /**< current last provided ID */ + unsigned int free_bit_cnt; + /**< the number of IDs that can be issued */ + } daci_id_provider; + +/** + * @brief Structure of table - mapped column of id_page_tbl + */ + typedef struct { + unsigned int page_index;/**< index of page */ + unsigned int id_provider_code; /**< ID of id provider - this described in F/W configuration file */ + char *page_bit; /**< real construction of ID issued */ + } daci_id_page; + +/* + * @brief free memory daci_account structure + * @param[in] account daci_account structure + * @param[in] count structure count + */ + void DACI_Free_Memory_Account(daci_account *account, int count); + +/* + * @brief free memory daci_folder structure + * @param[in] folder daci_folder structure + * @param[in] count structure count + */ + void DACI_Free_Memory_Folder(daci_folder *folder, int count); + +/* + * @brief free memory daci_item structure + * @param[in] item daci_item structure + * @param[in] count structure count + */ + void DACI_Free_Memory_Item(daci_item *item, int count); + +/* + * @brief free memory daci_config structure + * @param[in] config daci_config structure + * @param[in] count structure count + */ + void DACI_Free_Memory_Config(daci_config *config, int count); + +/* + * @brief free memory daci_item_changelog structure + * @param[in] itemChangelog daci_item_changelog structure + * @param[in] count structure count + */ + void DACI_Free_Memory_Item_Changelog(daci_item_changelog *itemChangelog, int count); + +/* + * @brief free memory daci_last_anchor structure + * @param[in] lastAnchor daci_last_anchor structure + * @param[in] count structure count + */ + void DACI_Free_Memory_Last_Anchor(daci_last_anchor *lastAnchor, int count); + +/* + * @brief free memory daci_mapping structure + * @param[in] mapping daci_mapping structure + * @param[in] count structure count + */ + void DACI_Free_Memory_Mapping(daci_mapping *mapping, int count); + +/* + * @brief free memory daci_item_info structure + * @param[in] itemInfo daci_item_info structure + * @param[in] count structure count + */ + void DACI_Free_Memory_Item_Info(daci_item_info *itemInfo, int count); + +/* + * @brief free memory daci_id_list structure + * @param[in] idList daci_id_list structure + */ + void DACI_Free_Memory_Id_List(daci_id_list *idList); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /* DACI_COMMON_H_ */ diff --git a/framework/include/agent-framework/DACI/EXT_DACI_Errors.h b/framework/include/agent-framework/DACI/EXT_DACI_Errors.h new file mode 100755 index 0000000..c98e131 --- /dev/null +++ b/framework/include/agent-framework/DACI/EXT_DACI_Errors.h @@ -0,0 +1,81 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu , + * Heeyoung Hwang + */ + +#ifndef EXT_DACI_ERRORS_H_ +#define EXT_DACI_ERRORS_H_ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/** + * @file EXT_DACI_Errors.h + * @brief Definition of framework error codes for DACI + */ + +/** + * @brief Enumerations of error codes for DACI + */ + typedef enum _DACI_RETURN { + DACI_SUCCESS = 1, /**< successful */ + DACI_ERRORS = -800, /**< fail */ + DACI_NOT_FOUND_PLUG_IN = -801, /**< not found data connector or converter plugIn */ + DACI_ERR_OPEN_FAILED = -802, /**< database open fail */ + DACI_ERR_CLOSE_FAILED = -803, /**< database close fail */ + DACI_ERR_TRANSACTION_FAILED = -804, /**< transaction fail */ + DACI_ERR_CREATE_TABLE_FAILED = -805, /**< create table fail */ + DACI_ERR_DROP_TABLE_FAILED = -806, /**< drop table fail */ + DACI_ERR_QUERY_FAILED = -807, /**< process query fail */ + DACI_ERR_NOT_OPENED = -808, /**< database not opened so fail */ + DACI_ERR_ACCOUNT_FULL = -809, /**< exist full account */ + DACI_ERR_DELETE_LAST_ACCOUNT = -810, /**< */ + DACI_ERR_PRIMARY_KEY_NOT_UNIQUE = -811, /**< already exist primary key */ + DACI_ERR_DB_HANDLER_MGR = -812, /**< database connection fail - get or create */ + DACI_ERR_ALREADY_EXIST = -813, /**< */ + DACI_ERR_INVALID_CONTENT = -814, /**< */ + DACI_ERR_MEMORY_FULL = -815, /**< memory full */ + DACI_ERR_SUB_DATA_EXIST = -816, /**< item not empty */ + DACI_ERR_LOCKED = -817, /**< database lock */ + DACI_ERR_MORE_DATA = -818, /**< query result has more data, used when iterating */ + DACI_ERR_NO_DATA = -819, /**< query result not found */ + DACI_ERR_NOT_SUPPORTED = -820, /**< */ + DACI_ERR_NOT_EXECUTE = -821, /**< */ + } DACI_RETURN; + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /* EXT_DACI_ERRORS_H_ */ diff --git a/framework/include/agent-framework/Device/EXT_DCI_Common.h b/framework/include/agent-framework/Device/EXT_DCI_Common.h new file mode 100755 index 0000000..f7e7546 --- /dev/null +++ b/framework/include/agent-framework/Device/EXT_DCI_Common.h @@ -0,0 +1,75 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Seokgil Kang + */ + +#ifndef DICI_COMMON_H_ +#define DICI_COMMON_H_ + +#include "EXT_DCI_Errors.h" + +/** + * @file EXT_DCI_Common.h + * @brief Defines enumerations for device execution + */ + +/** + * @brief Enumerations for state of power manager + */ +typedef enum { + LCD_NORMAL = 0, + LCD_DIM, + LCD_OFF, + SUSPEND, + POWER_OFF, + SETALL +} PM_State; + +/** + * @brief Enumerations for lock state of power manager + */ +typedef enum { + GOTO_STATE_NOW = 0, + STAY_CUR_STATE +} PM_Lock_State_Flag; + +/** + * @brief Enumerations for unlock state of power manager + */ +typedef enum { + SLEEP_MARGIN = 0, + RESET_TIMER, + KEEP_TIMER +} PM_Unlock_State_Flag; + +#endif /* DICI_COMMON_H_ */ diff --git a/framework/include/agent-framework/Device/EXT_DCI_DevExecutor.h b/framework/include/agent-framework/Device/EXT_DCI_DevExecutor.h new file mode 100755 index 0000000..1894545 --- /dev/null +++ b/framework/include/agent-framework/Device/EXT_DCI_DevExecutor.h @@ -0,0 +1,79 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Seokgil Kang + * SeongWon Shim + */ + +#ifndef EXT_DCI_DEVEXECUTOR_H_ +#define EXT_DCI_DEVEXECUTOR_H_ + +#include "EXT_DCI_Common.h" + +/** + * @file EXT_DCI_DevExecutor.h + * @brief Defines device execution APIs + */ + +/** + * @brief Lock a particular power-state as the current power-state + * @remarks If parameter 'timeout' value is 0, state of power manager is always lock until calling DCI_PM_Unlock_State() + * @param[in] device_plugIn_id Device PlugIn ID + * @param[in] state LCD_NORMAL, LCD_DIM, LCD_OFF, SUSPEND, POWER_OFF, SETALL + * @param[in] flag GOTO_STATE_NOW, STAY_CUR_STATE + * @param[in] timeout lock-timeout in milliseconds + * @return Operation result + * @retval DICI_SUCCESS Successful + * @retval DCI_FAIL Operation failed + * + * @code +DCI_RETURN res = DCI_PM_Lock_State(1, LCD_OFF , STAY_CUR_STATE, 0); + * @endcode + */ +DCI_RETURN DCI_PM_Lock_State(int device_plugIn_id, PM_State state, PM_Lock_State_Flag flag, unsigned int timeout); + +/** + * @brief Unlock the power-state + * @param[in] device_plugIn_id Device PlugIn ID + * @param[in] state LCD_NORMAL, LCD_DIM, LCD_OFF, SUSPEND, POWER_OFF, SETALL + * @param[in] flag SLEEP_MARGIN, RESET_TIMER, KEEP_TIMER + * @return Operation result + * @retval DICI_SUCCESS Successful + * @retval DCI_FAIL Operation failed + * + * @code + DCI_RETURN res = DCI_PM_Unlock_State(1, LCD_OFF , RESET_TIMER); + * @endcode + */ +DCI_RETURN DCI_PM_Unlock_State(int device_plugIn_id, PM_State state, PM_Unlock_State_Flag flag); + +#endif /* EXT_DCI_DEVEXECUTOR_H_ */ diff --git a/framework/include/agent-framework/Device/EXT_DCI_DevInfo.h b/framework/include/agent-framework/Device/EXT_DCI_DevInfo.h new file mode 100755 index 0000000..132bcbb --- /dev/null +++ b/framework/include/agent-framework/Device/EXT_DCI_DevInfo.h @@ -0,0 +1,95 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Seokgil Kang + */ + +#ifndef EXT_DCI_H_ +#define EXT_DCI_H_ + +#include "EXT_DCI_Common.h" + +/** + * @file EXT_DCI_DevInfo.h + * @brief Defines device information APIs + */ + +/** + * @brief Load device information on the memory + * @remarks Run only once at the beginning of the process + * @param[in] device_plugIn_id Device plugIn ID + * @return Operation result + * @retval DICI_SUCCESS Successful + * @retval DCI_FAIL Operation failed + * + * @code +DCI_RETURN res = DICI_Init(1); + * @endcode + */ +DCI_RETURN DCI_Init(int device_plugIn_id); + +/** + * @brief Get particular device information on the memory + * @remarks Device information supported by sync-agent-framework (2012.03.19) + * DevID(device id), Man(manufacture), Mod(model id or model number), SwV(software version), + * HwV(hardware version), FwV(firmware version), OEM(original equipment manufacturer), + * DevTyp(device type), Lang(language), DTDV(DTD version), PDAV(PDA version), + * CSCV(CSC version), ModemV(modem version), KernelV(kernal version), OPCO(OPCO information) + * @param[in] device_plugIn_id Device plugIn ID + * @param[in] info_name Name of device information (see remarks) + * @param[out] value Value of device information + * @return Operation result + * @retval DICI_SUCCESS Successful + * @retval DICI_FAIL Operation failed + * @pre The application should be called DCI_Init() + * + * @code + char *value; + DCI_RETURN res = DICI_Get_DevInfo(1, "DevID", &value); + * @endcode + */ +DCI_RETURN DCI_Get_DevInfo(int device_plugIn_id, char *info_name, char **value); + +/** + * @brief Free memory for device information on the memory + * @param[in] device_plugIn_id Device plugIn ID + * @return Operation result + * @retval DICI_SUCCESS Successful + * @retval DICI_FAIL Operation failed + * + * @code +DCI_RETURN res = DICI_Destroy(1); + * @endcode + */ +DCI_RETURN DCI_Destroy(int device_plugIn_id); + +#endif /* EXT_DCI_H_ */ diff --git a/framework/include/agent-framework/Device/EXT_DCI_Errors.h b/framework/include/agent-framework/Device/EXT_DCI_Errors.h new file mode 100755 index 0000000..03859b3 --- /dev/null +++ b/framework/include/agent-framework/Device/EXT_DCI_Errors.h @@ -0,0 +1,55 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Seokgil Kang + */ + +#ifndef EXT_DCI_ERRORS_H_ +#define EXT_DCI_ERRORS_H_ + +/** + * @file EXT_DCI_Errors.h + * @brief Defines DCI errors + */ + +/** + * @brief Enumerations for the DCI errors + */ +typedef enum { + DCI_SUCCESS = 1, + DCI_FAIL = -1, + + DCI_NOT_EXIST_DEVINFO = -2, + DCI_DEVINFO_VALUE_IS_NULL = -3, +} DCI_RETURN; + +#endif /* EXT_DCI_ERRORS_H_ */ diff --git a/framework/include/agent-framework/FSAPI/FSAPI_operation.h b/framework/include/agent-framework/FSAPI/FSAPI_operation.h new file mode 100644 index 0000000..ed90aa1 --- /dev/null +++ b/framework/include/agent-framework/FSAPI/FSAPI_operation.h @@ -0,0 +1,216 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Wook Choi + */ + +#ifndef FSAPI_OPERATION_H_ +#define FSAPI_OPERATION_H_ + +#include +#include +#include + +/** + * @file FSAPI_operation.h + * @brief Provides file system related operations such as file/folder create, delete, read, write and etc.. + */ + +/** + * @brief Check whether given file path is existing or not + * @remarks file path can be either a file or a folder. + * @param[in] filename File path you want to check + * @return 1 when the instance you want to check exists, otherwise 0 + */ +int FSAPI_isExisting(const char *filename); + +/** + * @brief Provides free size and total size of file system which your file path exists on + * @param[in] root File path you want to check + * @param[out] sizeFree Free size of file system in bytes + * @param[out] sizeTotal Total size of file system in bytes + * @return 1 on success, otherwise 0 + */ +int FSAPI_memSize(const char *root, long double *sizeFree, long double *sizeTotal); + +/** + * @brief Provides size of your file + * @param[in] filename File path you want to check + * @param[out] size Size of requested file in bytes + * @return 1 on success, otherwise 0 + */ +int FSAPI_fileSize(const char *filename, unsigned long *size); + +/** + * @brief Provides date information of your file in character stream + * @remarks The return char stream format is "Y:m:d H:M:S". + * The Date info stream should be freed when no more in use. + * @param[in] filename File path you want to check + * @param[out] time_string Double pointer of the char variable you want to load file date info on + * @return 1 on success, otherwise 0 + */ +int FSAPI_fileDate(const char *filename, char **time_string); + +/** + * @brief Provides file copy operation + * @remarks Operation will fail if destination already exists. + * @param[in] source Source file path + * @param[in] dest Destination file path + * @return 1 on success, otherwise 0 + */ +int FSAPI_fileCopy(const char *source, const char *dest); + +/** + * @brief Provides file delete operation + * @param[in] filename File path to delete + * @return 1 on success, otherwise 0 + */ +int FSAPI_fileDelete(const char *filename); + +/** + * @brief Provides file move operation + * @remarks Operation will fail if destination already exists. + * @param[in] source Source file path + * @param[in] dest Destination file path + * @return 1 on success, otherwise 0 + */ +int FSAPI_fileMove(const char *source, const char *dest); + +/** + * @brief Provides file rename operation + * @remarks Operation will fail if destination already exists. + * @param[in] source Source file path + * @param[in] dest Destination file path + * @return 1 on success, otherwise 0 + */ +int FSAPI_fileRename(const char *source, const char *dest); + +/** + * @brief Provides file read operation (Keeps file descriptor until reaching end of file) + * @remarks Need to call repeatedly with proper 'required_length' until you get TRUE value of the bool option 'isFinal'. + * Provided contents 'required_contents' should be freed when no more in use. + * @param[in] filename File path which you want to read + * @param[in] required_length Size to read + * @param[out] required_contents Char variable to load file contents on + * @param[out] size_return Size of invoked file contents + * @param[out] isFinal Boolean value to indicate whether end of file reached or not + * @return 1 on success, otherwise 0 + */ +int FSAPI_fileRead(const char *filename, char **required_contents, unsigned long required_length, unsigned long *size_return, bool *isFinal); + +/** + * @brief Provides file read operation (Entire contents at once) + * @remarks Provided 'required_contents' should be freed when no more in use. + * @param[in] filename File path which you want to read + * @param[out] required_contents Char variable to load file contents on + * @param[out] size_return Size of invoked file contents + * @return 1 on success, otherwise 0 + */ +int FSAPI_fileReadWhole(const char *filename, char **required_contents, unsigned long *size_return); + +/** + * @brief Provides free operation for file contents loaded from FSAPI_fileRead, FSAPI_fileReadWhole + * @param[in] requested_contents File contents to free + */ +int FSAPI_fileRead_Free(char **requested_contents); + +/** + * @brief Provides file write operation (Keeps file descriptor until finish order) + * @remarks Writes given contents to given file until 'isFinal' option enabled. + * Destination file won't be appeared until you give 'isFinal' option. + * Useful when writing several chunks into new file in one task. + * @param[in] filename File path which you want to write + * @param[in] contents Contents to write + * @param[in] length Size of the contents + * @param[in] isFinal Option to order operation finish + * @param[in] overwrite Option to order overwriting + * @return 1 on success, otherwise 0 + */ +int FSAPI_fileWrite(const char *filename, const char *contents, unsigned long length, bool isFinal, bool overwrite); + +/** + * @brief Provides file write operation (Entire contents at once) + * @param[in] filename File path which you want to write + * @param[in] contents Contents to write + * @param[in] length Size of the contents + * @param[in] overwrite Option to order overwriting + * @return 1 on success, otherwise 0 + */ +int FSAPI_fileWriteWhole(const char *filename, const char *contents, unsigned long length, bool overwrite); + +/** + * @brief Provides file append operation + * @remarks Appends given contents to given file. + * If given file not existing, create first and start appending. + * @param[in] filename File path which you want to write + * @param[in] contents Contents to write + * @param[in] length Size of the contents + * @param[in] overwrite Option to order overwriting + * @return 1 on success, otherwise 0 + */ +int FSAPI_fileAppend(const char *filename, const char *contents, unsigned long length, bool overwrite); + +/** + * @brief Provides folder create operation + * @remarks All parents folder will be created along + * in case any upper parents folders in the ordered folder path not existing. + * @param[in] foldername Folder path to create + * @return 1 on success, otherwise 0 + */ +int FSAPI_folderCreate(const char *foldername); + +/** + * @brief Provides folder delete operation + * @remarks Operation will fail in case the requested folder is not empty if 'recusive' option not given. + * @param[in] foldername Folder path to delete + * @param[in] recursive Option to delete inside recursively + * @return 1 on success, otherwise 0 + */ +int FSAPI_folderDelete(const char *foldername, bool recursive); + +/** + * @brief Provides folder delete operation without deleting root of the requested folder itself + * @param[in] foldername Folder path to delete inside + * @return 1 on success, otherwise 0 + */ +int FSAPI_folderEmptyContents(const char *foldername); + +/** + * @brief Provides folder rename operation + * @remarks Operation will fail if destination already exists. + * @param[in] source Source file path + * @param[in] dest Destination file path + * @return 1 on success, otherwise 0 + */ +int FSAPI_folderRename(const char *source, const char *dest); + +#endif /* FSAPI_OPERATION_H_ */ diff --git a/framework/include/agent-framework/NetworkAccess/EXT_NA_NetworkStatus.h b/framework/include/agent-framework/NetworkAccess/EXT_NA_NetworkStatus.h new file mode 100755 index 0000000..362cfaf --- /dev/null +++ b/framework/include/agent-framework/NetworkAccess/EXT_NA_NetworkStatus.h @@ -0,0 +1,67 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Seokgil Kang + */ + +#ifndef EXT_NA_NETWORKSTATUS_H_ +#define EXT_NA_NETWORKSTATUS_H_ + +/** + * @file EXT_NA_NetworkStatus.h + * @brief Defines network status/type provided by sync-agent-framework + */ + +/** + * @brief Enumerations for the information about current network status provided by sync-agent-framework + */ +typedef enum { + NETWORK_UNKNOWN = 0, /** initial network status */ + NETWORK_ON, /** network connection */ + NETWORK_OFF, /** network disconnection */ + NETWORK_CHANGE /** change ip/proxy information */ +} FW_NETWORK_STATUS; + +/** + * @brief Enumerations for the information about current network connection type provided by sync-agent-framework + */ +typedef enum { + NETWORK_NONE = 0, /** initial network type */ + NETWORK_3G_ON, /** network UMTS on */ + NETWORK_3G_OFF, /** network UMTS off */ + NETWORK_WIFI_ON, /** network WIFI on */ + NETWORK_WIFI_ON_NOT_CONNECTED, /** network WIFI on but not connected */ + NETWORK_WIFI_OFF, /** network WIFI off */ + NETWORK_WIFI_3G_ON, /** network UMTS and WIFI on */ +} FW_NETWORK_TYPE; + +#endif /* EXT_NA_NETWORKSTATUS_H_ */ diff --git a/framework/include/agent-framework/PlatformMonitor/EXT_PMCI_Struct.h b/framework/include/agent-framework/PlatformMonitor/EXT_PMCI_Struct.h new file mode 100755 index 0000000..c114b3f --- /dev/null +++ b/framework/include/agent-framework/PlatformMonitor/EXT_PMCI_Struct.h @@ -0,0 +1,130 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Seokgil Kang + */ + +#ifndef EXT_PMCI_STRUCT_H_ +#define EXT_PMCI_STRUCT_H_ + +#include + +/** + * @file EXT_PMCI_Struct.h + * @brief Defines enumerations & structures for PMCI + */ + +#define DAY_CNT 7 + +/** + * @brief Enumerations for the day type + */ +typedef enum { + DAY_NO_TYPE = 0x00, + DAY_SUN = 0x01, + DAY_MON = 0x02, + DAY_TUE = 0x04, + DAY_WED = 0x08, + DAY_THU = 0x10, + DAY_FRI = 0x20, + DAY_SAT = 0x40 +} PMCI_DAY_TYPE; + +/** + * @brief Enumerations for the repeat type + */ +typedef enum { + REPEAT_NO_TYPE = 0, + ONCE = 1, + REPEAT, + REPEAT_WEEKLY, + REPEAT_MONTHLY, + REPEAT_ANNUALLY, +} PMCI_REPEAT_TYPE; + +/** + * @brief Alarm structure provided by sync-agent-framework + * @see PMCI_Add_Item_To_Specific_Type(), SPECIFIC_TYPE_CALLBACK + */ +typedef struct { + /* start alarm time : time to start alarm at first. + * format: 2011-01-02T15:13:02Z + */ + char *start_alarm_time; + + /* repeat type */ + PMCI_REPEAT_TYPE repeat_type; + + /* repeat value + * 1) repeat_type: ONCE => repeat_value: do not mean + * 1) repeat_type: REPEAT => repeat_value: interval time (second) + * 2) repeat_type: etc => repeat_value: PMCI_DAY_TYPE + */ + int repeat_value; + + int isDisposable; +} pmci_alarm_t; + +/** + * @brief Incoming data (SAN) structure provided by sync-agent-framework + * @remarks Notification data for 'SAN Incoming' operation + * @see SPECIFIC_TYPE_CALLBACK + */ +typedef struct { + const char *msgBody; + unsigned int msgSize; + int version; +} pmci_san_incoming_t; + +/** + * @brief Operation data (SAN) structure provided by sync-agent-framework + * @remarks Notification data for 'SAN Operation' operation + * @see SPECIFIC_TYPE_CALLBACK + */ +typedef struct { + int msgId; + int extId; + void *user_param; +} pmci_san_operation_t; + +/** + * @brief Message data (SAN) structure provided by sync-agent-framework + * @see PMCI_Add_Item_To_Specific_Type() + */ +/* SAN (send message) fw struct */ +typedef struct { + int extId; + int pinCode; + char *msgData; +} pmci_san_message_t; + +#endif /* EXT_PMCI_STRUCT_H_ */ diff --git a/framework/include/agent-framework/PlugIn/Account_Interface.h b/framework/include/agent-framework/PlugIn/Account_Interface.h new file mode 100755 index 0000000..ceeda53 --- /dev/null +++ b/framework/include/agent-framework/PlugIn/Account_Interface.h @@ -0,0 +1,126 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#ifndef ACCOUNT_INTERFACE_H_ +#define ACCOUNT_INTERFACE_H_ + +/** + * @file Account_Interface.h + * @brief Interface list in this header will be implemented plugIn developer. + * Implementation will operate F/W Account module. + */ + +/** + * @brief Setting Account Repository name + * @remarks Repository means mapping storage, between service account ID and F/W account ID + * @param[in] agent_name means repository name - described in F/W config file + */ +void Set_AccountReposioryName(const char *agent_name); + +/** + * @brief Add account to Platform + * @remarks mapping platform account id with f/w account_id + * @param[in] fw_account_id F/W account ID + * @param[in] email account's email address + * @param[in] password account's password + * @param[in] create_mode whether create new Platform account or only mapping f/w account id with existed platform account + */ +void Add_PlatformAccount(int fw_account_id, char *email, char *password, int create_mode); + +/** + * @brief Mapping F/W account ID with service account ID + * @remarks You must register non-volatile storage not memory. ex) File, DataBase.. + * @param[in] fw_account_id F/W account ID + * @param[in] service_type service type - service data connector pluIn's ID described in F/W config file + * @param[in] service_account_id service account ID + */ +void Set_PlatformAccount_Service(int fw_account_id, int service_type, int service_account_id); + +/** + * @brief Mapping relationship is off - F/W account ID with platform account ID + * @remarks You must remove from storage. + * @param[in] fw_account_id F/W account ID + */ +void Del_PlatformAccount(int fw_account_id); + +/** + * @brief Mapping relationship is off - F/W account ID with service account ID + * @remarks You must remove from storage. + * @param[in] fw_account_id F/W account ID + * @param[in] service_type service type - service data connector pluIn's ID described in F/W config file + */ +void Del_PlatformAccount_Service(int fw_account_id, int service_type); + +/** + * @brief whether F/W account ID has the service account ID + * @param[in] fw_account_id F/W account ID + * @param[in] service_type service type - service data connector pluIn's ID described in F/W config file + * @return 1 if has, otherwise 0 + * @retval 1 if has + * @retval 0 if has not + */ +int Has_PlatformAccount_Service(int fw_account_id, int service_type); + +/** + * @brief get service account ID mapped with F/W account ID + * @param[in] service_type service type - service data connector pluIn's ID described in F/W config file + * @param[in] fw_account_id F/W account ID + * @return service account id if it exist mapping relationship, otherwise -100 + * @retval service account id if it exist mapping relationship + * @retval -100 not exist mapping relationship + */ +int Get_Service_AccountID(int service_type, int fw_account_id); + +/** + * @brief get F/W account ID mapped with service account ID + * @param[in] service_type service type - service data connector pluIn's ID described in F/W config file + * @param[in] service_account_id service account ID + * @param[in] index possible mapping one service account with multiple F/W account, so need index of F/W account. + * @return F/W account id if it exist mapping relationship, otherwise -1 + * @retval F/W account id if it exist mapping relationship + * @retval -1 not exist mapping relationship + */ +int Get_FW_AccountID(int service_type, int service_account_id, int index); + +/** + * @brief Get service account information + * @remarks account information type must be defined in account plugIn. + * @param[in] fw_account_id F/W account id + * @param[in] service_type service type - service data connector pluIn's ID described in F/W config file + * @return Account Information* defined in account plugIn on success, otherwise null pointer + */ +void *Get_Service_AccountInfo(int fw_account_id, int service_type); + +#endif /* ACCOUNT_INTERFACE_H_ */ diff --git a/framework/include/agent-framework/PlugIn/DataConnector_Interface.h b/framework/include/agent-framework/PlugIn/DataConnector_Interface.h new file mode 100755 index 0000000..924b145 --- /dev/null +++ b/framework/include/agent-framework/PlugIn/DataConnector_Interface.h @@ -0,0 +1,367 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#ifndef DATACONNECTOR_INTERFACE_H_ +#define DATACONNECTOR_INTERFACE_H_ + +#include "agent-framework/DACI/EXT_DACI_Errors.h" + +#include "DataConnector_Resource.h" + +/** + * @file DataConnector_Interface.h + * @brief Interface list in this header will be implemented plugIn developer. + * Implementation will operate F/W DataAdapter module. + */ + +/* + * @brief service opening work + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ +DACI_RETURN Service_Open(); + +/* + * @brief service closing work + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ +DACI_RETURN Service_Close(); + +/* + * @brief start transaction for service storage + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ +DACI_RETURN Begin_Transaction(); + +/* + * @brief end transaction for service storage + * @param[in] is_success 1 : commit, 0 : rollback + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ +DACI_RETURN End_Transaction(int is_success); + +/* + * @brief insert item into service storage + * @param[in] account_id service account id + * @param[in] folder_id service folder_id + * @param[in] data service structure * + * @param[out] item_id success : service item_id, fail : 0 + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ +DACI_RETURN Add_Item(int account_id, char *folder_id, void *data, char **item_id); + +/* + * @brief update item from service storage + * @param[in] account_id service account id + * @param[in] folder_id service folder_id + * @param[in] item_id service item_id + * @param[in] data service structure * + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ +DACI_RETURN Update_Item(int account_id, char *folder_id, char *item_id, void *data); + +/* + * @brief delete item from service storage + * @param[in] account_id service account id + * @param[in] folder_id service folder_id + * @param[in] item_id service id of item expected to be deleted + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ +DACI_RETURN Del_Item(int account_id, char *folder_id, char *item_id); + +/* + * @brief delete all items from service storage + * @param[in] account_id service account id + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ +DACI_RETURN Del_All_Items(int account_id); + +/* + * @brief get item from service storage + * @param[in] account_id service account id + * @param[in] folder_id service folder id + * @param[in] item_id expected to get service item id + * @param[out] data success : item info, fail : 0 + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ +DACI_RETURN Get_Item(int account_id, char *folder_id, char *item_id, void **data); + +/* + * @brief insert folder into service storage + * @param[in] account_id service account id + * @param[in] folder_name folder name + * @param[in] folder_type folder type + * @param[out] folder_id success : folder_id, fail : 0 + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ +DACI_RETURN Add_Folder(int account_id, char *folder_name, int folder_type, char **folder_id); + +/* + * @brief delete folder from service storage + * @param[in] account_id service account id + * @param[in] folder_id service folder_id + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ +DACI_RETURN Del_Folder(int account_id, char *folder_id); + +/* + * @brief get folder from service storage + * @param[in] account_id service account id + * @param[in] folder_id service folder id + * @param[out] out_folder_name success : folder name, fail : 0 + * @param[out] out_folder_type success : folder type, fail : -1 + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ +DACI_RETURN Get_Folder(int account_id, char *folder_id, char **out_folder_name, int *out_folder_type); + +/* + * @brief execute data into service + * @param[in] account_id service account id + * @param[in] execute_key execute key + * @param[in] execute_values execute values + * @param[out] result extension result info + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail + */ +DACI_RETURN Execute(int account_ID, const char *execute_key, void *execute_values, void **result); + +/* + * @brief get item used count + * @return operation result + * @retval current item count success + * @retval error value fail : minus + */ +int Get_Used_Item_Count(); + +/* + * @brief get item used count for folder + * @param[in] account_id service account id + * @param[in] folder_id service folder id + * @return operation result + * @retval current item count success + * @retval error value fail : minus + */ +int Get_Used_Item_Count_For_Folder(int account_id, char *folder_id); + +/* + * @brief get folder id list of a account + * @param[in] account_id service account id + * @param[out] folder_count success : folder count, fail or not exist : 0 + * @param[out] folder_type_list success : list, fail or not exist : null pointer + * @return operation result + * @retval folder id list success + * @retval error value fail or not exist : null pointer + */ +char **Get_Folder_ID_List(int account_id, int *folder_count, int **folder_type_list); + +/* + * @brief get all account id list that service has currently + * @param[out] count success : account id count, fail or not exist : 0 + * @return operation result + * @retval account id list success + * @retval error value fail or not exist : null pointer + */ +int *Get_Account_ID_List(int *count); + +/* + * @brief write data store items to file + * @param[in] account_id service account id + * @param[out] file_path written file_path + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail :minus + */ +DACI_RETURN Write_Items_To_File(int account_ID, char **file_path); + +/* + * @brief add file wrote item to data store + * @param[in] account_id service account_id + * @param[in] file_path file_path + * @return operation result + * @retval DACI_SUCCESS success + * @retval error value fail : minus + */ +DACI_RETURN Add_File_Wrote_Items_To_Datastore(int account_ID, const char *file_path); + +/* + * @brief get added item list after specific point + * @param[in] account_id service account id + * @param[in] folder_id service folder id + * @param[in] changepoint specific point + * @param[out] changeCount added item count + * @return operation result + * @retval added item info list if exist + * @retval null pointer fail or not exist + */ +Item_Node *Get_Changed_ITEM_For_Folder_Add(int account_id, const char *folder_id, int changepoint, int *changeCount); + +/* + * @brief get deleted item list after specific point + * @param[in] account_id service account id + * @param[in] folder_id service folder id + * @param[in] changepoint specific point + * @param[out] changeCount deleted item count + * @return operation result + * @retval deleted item info list if exist + * @retval null pointer fail or not exist + */ +Item_Node *Get_Changed_ITEM_For_Folder_Del(int account_id, const char *folder_id, int changepoint, int *changeCount); + +/* + * @brief get updated item list after specific point + * @param[in] account_id service account id + * @param[in] folder_id service folder id + * @param[in] changepoint specific point + * @param[out] changeCount updated item count + * @return operation result + * @retval updated item info list if exist + * @retval null pointer fail or not exist + */ +Item_Node *Get_Changed_ITEM_For_Folder_Update(int account_id, const char *folder_id, int changepoint, int *changeCount); + +/* + * @brief get last storage change point information + * @return operation result + * @retval last storage change point information + */ +int Get_Last_ChangePoint(); + +/* + * @brief check notification for the storage change + * @param[in] data user data + */ +void StartListening_ChangeNoti(void *data); + +/* + * @brief set callback function to handle added item to storage + * @param[in] callback callback function - this function is provided from F/W + */ +void SetCallBack_AddItem(CALLBACK_ADD_ITEM callback); + +/* + * @brief set callback function to handle deleted item to storage + * @param[in] callback callback function - this function is provided from F/W + */ +void SetCallBack_DeleteItem(CALLBACK_DEL_ITEM callback); + +/* + * @brief set callback function to handle updated item to storage + * @param[in] callback callback function - this function is provided from F/W + */ +void SetCallBack_UpdateItem(CALLBACK_UPDATE_ITEM callback); + +/* + * @brief set callback function to get service account id list mapped f/w account id + * @param[in] callback callback function - this function is provided from F/W + */ +void SetCallBack_GetAccountIDList(GET_ACCOUNTIDLIST callback); + +/* + * @brief get max item count per folder + * @param[in] folder_type folder type provided plug-in + * @return operation result + * @retval max item count success + * @retval -1 fail + */ +int Get_MAX_Item_Count(int folder_type); + +/* + * @brief get service data's available field length + * @param[in] field_name field_name provided data connector plug-In + * @param[in] child_field_name child_field_name provided data connector plug-In + * @return operation result + * @retval available field length success + * @retval -1 fail + */ +int Get_MAX_Field_Length(int field_name, int child_field_name); + +/* + * @brief get service data's available field count + * @param[in] field_name field_name provided data connector plug-In + * @param[in] child_field_name child_field_name provided data connector plug-In + * @return operation result + * @retval available field count success + * @retval -1 fail + */ +int Get_MAX_Field_Count(int field_name, int child_field_name); + +/* + * @brief get service data's available field value's domain + * @param[in] field_name field_name provided data connector plug-In + * @param[in] child_field_name child_field_name provided data connector plug-In + * @param[out] str_val when domain value is string + * @param[out] num_val1 when domain value is integer (ex minimum value) + * @param[out] num_val2 when domain value is integer (ex maximum value) + * @return operation result + * @retval 1 success + * @retval -1 fail + */ +int Get_Field_Value(int field_name, int child_field_name, char **str_val, int *num_val1, int *num_val2); + +/* + * @brief get service data's available field count + * @param[in] feature feature provided data connector plug-In + * @return operation result + * @retval 1 support + * @retval 0 not support + * @retval -1 fail + */ +int Get_Is_Support_Feature(int feature); + +#endif /* DATACONNECTOR_INTERFACE_H_ */ diff --git a/framework/include/agent-framework/PlugIn/DataConnector_Resource.h b/framework/include/agent-framework/PlugIn/DataConnector_Resource.h new file mode 100755 index 0000000..48001a2 --- /dev/null +++ b/framework/include/agent-framework/PlugIn/DataConnector_Resource.h @@ -0,0 +1,63 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#ifndef DATACONNECTOR_RESOURCE_H_ +#define DATACONNECTOR_RESOURCE_H_ + +/** + * @file DataConnector_Resource.h + * @brief Item id list container + */ + +/** + * @brief Structure of Item ID Node - Linked List + */ +struct Item_Node { + char *item_id; /**< item id */ + struct Item_Node *next; /**< next pointer */ +}; + +typedef struct Item_Node Item_Node; + +typedef int (*CALLBACK_ADD_ITEM) (int accountID, int index, char *itemID, int itemType, char *folderID, int folderType); + +typedef int (*CALLBACK_DEL_ITEM) (int accountID, int index, char *itemID, int itemType); + +typedef int (*CALLBACK_UPDATE_ITEM) (int accountID, int index, char *itemID, int itemType); + +typedef int *(*GET_ACCOUNTIDLIST) (int service_type, int *cnt); + + +#endif /* DATACONNECTOR_RESOURCE_H_ */ diff --git a/framework/include/agent-framework/PlugIn/DataConverter_Interface.h b/framework/include/agent-framework/PlugIn/DataConverter_Interface.h new file mode 100644 index 0000000..b0533fb --- /dev/null +++ b/framework/include/agent-framework/PlugIn/DataConverter_Interface.h @@ -0,0 +1,140 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#ifndef DATACONVERTER_INTERFACE_H_ +#define DATACONVERTER_INTERFACE_H_ + +#include "agent-framework/DACI/EXT_DACI_Errors.h" + +#include "DataConverter_Resource.h" + +/** + * @file DataConverter_Interface.h + * @brief Interface list in this header will be implemented plugIn developer. + * Implementation will operate DataAdapter module. + */ + +/** + * @brief convert agent type data to service structure format data + * @remarks agent data's type can be v-object. (vcard, vcalendar .. ) + * @param[in] agent_data agent data + * @param[out] service_data created service data + * @return operation result + * @retval DACI_SUCCESS success + * @retval DACI_ERRORS fail + */ +DACI_RETURN Converter(const void *agent_data, void **service_data); + +/** + * @brief convert result of the merge agent data with old service data to service structure format data + * @remarks agent data's type can be v-object. (vcard, vcalendar .. ) + * @param[in] old_service_data old_service_data + * @param[in] agent_data agent data + * @param[out] new_service_data created service data + * @return operation result + * @retval DACI_SUCCESS success + * @retval DACI_ERRORS fail + */ +DACI_RETURN Replace_Converter(void *old_service_data, const void *agent_data, void **new_service_data); + +/** + * @brief convert service structure format data to agent type data + * @remarks agent data's type can be v-object. (vcard, vcalendar .. ) + * @param[in] service_data created service data + * @param[out] agent_data agent data + * @return operation result + * @retval DACI_SUCCESS success + * @retval DACI_ERRORS fail + */ +DACI_RETURN Reverse_Converter(void *service_data, void **agent_data); + +/* + * @brief allocate internal object for content type + * @return operation result + * @retval internal struct pointer success + * @retval null pointer fail + */ +void *Alloc_Object(); + +/* + * @brief free internal object for content type + * @param[in] in_object internal object pointer + * @return operation result + * @retval DACI_SUCCESS success + * @retval DACI_ERRORS fail + */ +int Free_Object(void *in_object); + +/* + * @brief set value for internal object + * @param[in] in_object internal object pointer + * @param[in] key key + * @param[in] extension_key extension key + * @param[in] set_value value + * @return operation result + * @retval new object pointer success + * @retval null pointer fail + */ +void *Set_Value(void *in_object, int key, char *extension_key, void *set_value); + +/* + * @brief allocate internal object for content type + * @param[in] in_object internal object pointer + * @param[in] key key + * @param[in] extension_key extension key + * @return operation result + * @retval value pointer success + * @retval 0 fail + */ +void *Get_Value(void *in_object, int key, char *extension_key); + +/* + * @brief get meta infomation of internal object + * @return operation result + * @retval value pointer success + * @retval 0 fail + */ +Object_Info *Get_Obj_Info(); + +/* + * @brief free infomation of internal object + * @param[in] obj_info object info + * @return operation result + * @retval DACI_SUCCESS success + * @retval DACI_ERRORS fail + */ +int Free_Obj_Info(Object_Info *obj_info); + +#endif /* DATACONVERTER_INTERFACE_H_ */ diff --git a/framework/include/agent-framework/PlugIn/DataConverter_Resource.h b/framework/include/agent-framework/PlugIn/DataConverter_Resource.h new file mode 100644 index 0000000..1022db1 --- /dev/null +++ b/framework/include/agent-framework/PlugIn/DataConverter_Resource.h @@ -0,0 +1,65 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#ifndef DATACONVERTER_RESOURCE_H_ +#define DATACONVERTER_RESOURCE_H_ + +/** + * @file DataConverter_Resource.h + * @brief Support to share structure DataConverter plugIn with F/W + */ + +/** + * @brief Structure of Converter plugin's object's field - linked list + */ +struct Field_Info { + char *field_name; /**< field name */ + int field_child_cnt; /**< field's child count */ + struct Field_Info *field_child_list; /**< next field info node */ +}; + +/** + * @brief Structure of Converter plugin's Object info + */ +typedef struct { + char *type; /**< object type */ + char *version; /**< object version */ + int field_cnt; /**< field count */ + struct Field_Info *field_list; /**< real field list **/ +} Object_Info; + +typedef struct Field_Info Field_Info; + +#endif /* DATACONVERTER_RESOURCE_H_ */ diff --git a/framework/include/agent-framework/PlugIn/DeviceInfo_Interface.h b/framework/include/agent-framework/PlugIn/DeviceInfo_Interface.h new file mode 100644 index 0000000..886f7f8 --- /dev/null +++ b/framework/include/agent-framework/PlugIn/DeviceInfo_Interface.h @@ -0,0 +1,109 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Seokgil Kang + */ + +#ifndef DEVICEINFO_INTERFACE_H_ +#define DEVICEINFO_INTERFACE_H_ + +#include +#include "agent-framework/Device/EXT_DCI_Common.h" + +/** + * @file DeviceInfo_Interface.h + * @brief Defines plug-in interfaces about device information + */ + +/** + * @brief Device information structure + * @remarks This structure is member of list (devInfo) + * Key(info_name) - value(value) pair + */ +typedef struct { + char *info_name; + char *value; +} dici_dev_info; + +/** + * @brief Get device information in the system and load this information on the memory + * @param[out] devInfo List of dici_dev_info structures + * @return Operation result + * @retval 1 Successful + * @retval 0 Operation failed + */ +int Load_DevInfo(GList **devInfo); + +/** + * @brief Get device information on the memory that user want to know + * @param[in] devInfo List of dici_dev_info structures + * @param[in] info_name Name of device information + * @param[out] value Value of device information + * @return Operation result + * @retval 1 Successful + * @retval 0 Operation failed + */ +int Get_DevInfo(GList *devInfo, char *info_name, char **value); + +/** + * @brief Clear device information on the memory (free memory) + * @param[in] defInfo List of dici_dev_info structures + * @return Operation result + * @retval 1 Successful + * @retval 0 Operation failed + */ +int Clear_DevInfo(GList **devInfo); + +/** + * @brief Lock a particular power-state as the current power-state + * @remarks If parameter 'timeout' value is 0, state of power manager is always lock until calling PM_Unlock_State() + * @param[in] The power state which user want to lock + * @param[in] Set if user want to go the requested lock state directly + * @param[in] Specifies lock-timeout in milliseconds + * @return Operation result + * @retval 0 Successful + * @retval -1 Operation failed + * @see /Device/EXT_DCI_Common.h + */ +int PM_Lock_State(PM_State state, PM_Lock_State_Flag flag, unsigned int timeout); + +/** + * @brief Unlock the power-state + * @param[in] Specifies the power state which user want to unlock + * @param[in] Set if user want to go to the requested state directly after unlocking (not supported yet) + * @return Operation result + * @retval 0 Succesful + * @retval -1 Operation failed + */ +int PM_Unlock_State(PM_State state, PM_Unlock_State_Flag flag); + +#endif /* DEVICEINFO_INTERFACE_H_ */ diff --git a/framework/include/agent-framework/PlugIn/NetworkAccess_Interface.h b/framework/include/agent-framework/PlugIn/NetworkAccess_Interface.h new file mode 100644 index 0000000..12321d0 --- /dev/null +++ b/framework/include/agent-framework/PlugIn/NetworkAccess_Interface.h @@ -0,0 +1,172 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Seokgil Kang + */ + +#ifndef NETWORKACCESS_INTERFACE_H_ +#define NETWORKACCESS_INTERFACE_H_ + +#include + +/** + * @file NetworkAccess_Interface.h + * @brief Defines plug-in interfaces about network access + */ + +/** + * @brief Open network connection + * @param[out] session Network session information + * @param[in] proxy Proxy information + * @param[in] timeout User preferred time-out seconds used in sending message (ex> 30 means 30seconds) + * @return Operation result + * @retval 1 Successful + * @retval 0 Operation failed + */ +int Open_Connection(void **session, char *proxy, int timeout); + +/** + * @brief Bind header information for each network protocol + * @param[in] header_info Header information for each network protocol + * @param[out] header_binding Header information bound each network protocol + * @return Operation result + * @retval 1 Successful + * @retval 0 Operation failed + */ +int Header_Binding(GList *header_info, void **header_binding); + +/** + * @brief Send message to server and receive message from the server + * @param[in] session Network session information + * @param[out] header_binding Header binding information + * @param[in] send_msg Body message + * @param[in] send_msg_length Length of body message + * @param[out] recv_msg_size The size of received message from the server + * @return Operation result + * @retval 1 Successful + * @retval 0 Operation failed + * @retval -1 Cancel message + * @retval -8 Try again + * @retval -408 request timeout + */ +int Send_Message(void *session, void **header_binding, char *send_msg, unsigned int send_msg_length, unsigned int *recv_msg_size); + +/** + * @brief Divide header/body information using received message from the server + * @param[in] msg Received message from the server + * @param[in] msg_size The size of received message from the server + * @param[out] recv_header Header information of received message from the server + * @param[out] recv_msg Body information of received message from the server + * @param[out] recv_msg_length The length of body information + * @return Operation result + * @retval 1 Successful + * @retval 0 Operation failed + */ +int Header_Unbinding(void *msg, unsigned int msg_size, GList **recv_header, unsigned char **recv_msg, unsigned int *recv_msg_length); + +/** + * @brief Close network connection + * @param[in] session Network session information + * @return Operation result + * @retval 1 Successful + * @retval 0 Operation failed + */ +int Close_Connection(void *session); + +/** + * @brief Cancel operation about message being sent to the server + * @param[in] session Network session information + * @return Operation result + * @retval 1 Successful + * @retval 0 Operation failed + */ +int Cancel_Message(void *session); + +/** + * @brief Just send message to the server (do not receive message from the server) + * @param[in] session Network session information + * @param[out] header_binding Header binding information + * @param[in] send_msg Body message + * @param[in] send_msg_length Length of body message + * @return Operation result + * @retval 1 Successful + * @retval 0 Operation failed + */ +int Just_Send_Message(void *session, void **header_binding, char *send_msg, unsigned int send_msg_length); + +/** + * @brief Get network header information about specific keyword + * @param[in] header_info List of network header information (key-value pair) + * @param[in] key Specific keyword of header information that user want to know + * @param[out] value Value for the key + * @return Operation result + * @retval 1 Successful + * @retval 0 Operation failed + * @see Header_Unbinding() + */ +int Get_Header_Info(GList *header_info, char *key, char **value); + +/** + * @brief Set download information(download range) to download header information of specific network protocol + * @param[in] down_info Download header information of specific network protocol + * @param[in] current_down_range Download current range + * @return Operation result + * @retval 1 Successful + * @retval 0 Operation failed + */ +int Set_Data_Download_Info(void *down_info, char *current_down_range); + +/** + * @brief Get download information(download range, filename) to download header information of specific network protocol + * @param[in] down_info Download header information of specific network protocol + * @param[out] total_down_size Total download size + * @param[out] current_down_range Current download range + * @param[out] down_file_name Download file name + * @return Operation result + * @retval 1 Successful + * @retval 0 Operation failed + */ +int Get_Data_Download_Info(void *down_info, int *total_down_size, char **current_down_range, char **down_file_name); + +/** + * @brief Add user authentication information (id, password) to session and + * register authentication callback for 'authenticate' signal + * @param[in] session Network session information + * @param[in] id User id + * @param[in] password User password + * @return Operation result + * @retval 1 Successful + * @retval 0 Operation failed + */ +int Add_Authentication_Info(void *session, char *id, char *password); + +#endif /* NETWORKACCESS_INTERFACE_H_ */ diff --git a/framework/include/agent-framework/PlugIn/PlatformMonitor_Interface.h b/framework/include/agent-framework/PlugIn/PlatformMonitor_Interface.h new file mode 100644 index 0000000..4391d71 --- /dev/null +++ b/framework/include/agent-framework/PlugIn/PlatformMonitor_Interface.h @@ -0,0 +1,185 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Seokgil Kang + */ + +#ifndef PLATFORMMONITOR_INTERFACE_H_ +#define PLATFORMMONITOR_INTERFACE_H_ + +#include "PlatformMonitor_Resource.h" + +/** + * @file PlatformMonitor_Interface.h + * @brief Defines plug-in interfaces about service platform notification + */ + +/** + * @brief Data structure to register at main loop of sync-agent-framework + */ +typedef struct { + char *pkg_name; + char *app_id; + void *user_data; +} pm_register_data_t; + +/** + * @brief Check the current network status/connection type and + * register network notification callback function(used in sync-agent-framework) to network platform + * @param[in] data User data (meaningless data) + */ +void Init_Network_Status_Noti_Handler(void *data); + +/** + * @brief Unregister network notification callback function(used in sync-agent-framework) to network platform + */ +int Terminate_Network_Status_Noti_Handler(void); + +/** + * @brief Initialize to receive SAN notification from the service + * @remarks Connect to the service and register notification callback function to the service + * @param[in] data User data (meaningless data) + */ +void Init_Syncml_SAN_Noti_Handler(void *data); + +/** + * @brief Unregister notification callback function that was previously registered to the service and disconnect to the service + */ +int Terminate_Syncml_SAN_Noti_Handler(void); + +/** + * @brief Add SAN message to the service + * @param[in] add_item Item to add to the service + * @return Operation result + * @retval 1 Successful + * @retval -1 Operation failed + * @see /PlatformMonitor/EXT_PMCI_Struct.h - pmci_san_message_t + */ +int Add_Message(void *add_item); + +/** + * @brief Remove SAN message from service + * @param[in] remove_item_id Id of Item that user want to remove from service + * @return Operation result + * @retval 1 Successful + * @retval -1 Operation failed + */ +int Remove_Message(int remove_item_id); + +/** + * @brief Initialize to receive alarm notification from the service + * @remarks Connect to the service and register notification callback function to the service + * @param[in] data Structure 'pm_register_data_t' + */ +void Init_Alarm_Noti_Handler(void *data); + +/** + * @brief Unregister notification callback function that was previously registered to the service and disconnect to the service + * @remarks Not supported yet + */ +int Terminate_Alarm_Noti_Handler(); + +/** + * @brief Add alarm data to the service + * @param[in] add_item Item to add to the service + * @param[out] out_add_item_id Id of the newly item added to the service + * @return Operation result + * @retval 1 Successful + * @retval 0 Operation failed + */ +int Add_Alarm(void *add_item, int *out_add_item_id); + +/** + * @brief Remove alarm data from the service + * @param[in] remove_item_id Id of Item that user want to remove from service + * @return Operation result + * @retval 1 Successful + * @retval -1 Operation failed + */ +int Remove_Alarm(int remove_item_id); + +/** + * @brief Get item that user want to know from the service + * @param[in] get_item_id Id of the item that user want to know + * @param[out] out_get_item Item that user want to know + * @return Operation result + * @retval 1 Successful + * @retval 0 Operation failed + * @see /PlatformMonitor/EXT_PMCI_Struct.h - pmci_alarm_t + */ +int Get_Alarm(int get_item_id, void **out_get_item); + +/** + * @brief Register user callback function for network status to the service + * @remarks This api is used in sync-agent-framework + * @param[in] callback User callback function + */ +void SetCallBack_NetworkStatus(CALLBACK_NETWORK_STATUS callback); + +/** + * @brief Register user callback function for network cancel to the service + * @remarks This api is used in sync-agent-framework + * @param[in] callback User callback function + */ +void SetCallBack_NetworkAllCancel(CALLBACK_NETWORK_CANCEL callback); + +/** + * @brief Register user callback function for SAN incoming notification to the service + * @param[in] callback User callback function + */ +void SetCallBack_Syncml_SAN_Incoming(CALLBACK_SYNCML_SAN_INCOMING callback); + +/** + * @brief Register user callback function for SAN operation notification to the service + * @param[in] callback User callback function + */ +void SetCallBack_Syncml_SAN_Operation(CALLBACK_SYNCML_SAN_OPERATION callback); + +/** + * @brief Register user callback function for alarm notification to the service + * @param[in] callback User callback function + */ +void SetCallBack_Alarm(CALLBACK_ALARM callback); + +/** + * @brief Register user callback function for network on status to the service + * @param[in] callback User callback function + */ +void SetCallBack_Network_On(CALLBACK_NETWORK_ON callback); + +/** + * @brief Register user callback function for network off status to the service + * @param[in] callback User callback function + */ +void SetCallBack_Network_Off(CALLBACK_NETWORK_OFF callback); + +#endif /* PLATFORMMONITOR_INTERFACE_H_ */ diff --git a/framework/include/agent-framework/PlugIn/PlatformMonitor_Resource.h b/framework/include/agent-framework/PlugIn/PlatformMonitor_Resource.h new file mode 100644 index 0000000..5965347 --- /dev/null +++ b/framework/include/agent-framework/PlugIn/PlatformMonitor_Resource.h @@ -0,0 +1,57 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#ifndef PLATFORMMONITOR_RESOURCE_H_ +#define PLATFORMMONITOR_RESOURCE_H_ + +#ifdef dnet + typedef int (*CALLBACK_NETWORK_STATUS) (int dev_network_status, int fw_network_status, char *proxy, char *ip); +#endif + +typedef int (*CALLBACK_NETWORK_STATUS) (int protocol_type, int fw_network_status, int fw_network_type, char *proxy, char *ip); + +typedef int (*CALLBACK_NETWORK_CANCEL) (int protocol_type); + +typedef int (*CALLBACK_SYNCML_SAN_INCOMING) (int item_id, void *user_data); + +typedef int (*CALLBACK_SYNCML_SAN_OPERATION) (int item_id, void *user_data); + +typedef int (*CALLBACK_ALARM) (int alarm_id, void *user_data); + +typedef int (*CALLBACK_NETWORK_ON) (int item_id, void *user_data); + +typedef int (*CALLBACK_NETWORK_OFF) (int item_id, void *user_data); + +#endif /* PLATFORMMONITOR_RESOURCE_H_ */ diff --git a/framework/include/agent-framework/Utility/fw_async_queue.h b/framework/include/agent-framework/Utility/fw_async_queue.h new file mode 100644 index 0000000..b225d45 --- /dev/null +++ b/framework/include/agent-framework/Utility/fw_async_queue.h @@ -0,0 +1,112 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#ifndef FW_ASYNC_QUEUE_H_ +#define FW_ASYNC_QUEUE_H_ + +#include + +/** + * @file fw_async_queue.h + * @brief provide DataStructure - asynchronous Queue + */ + +/** + * @brief determine priority + * @param[in] msg1 item + * @param[in] msg2 compare item + * @param[in] user_data user_data + * @return + * @see fw_async_queue_send_msg_with_compare_priority() + */ +typedef int (*compare_priority_func) (const void *msg1, const void *msg2, void *user_data); + +/** + * @brief asynchronous Queue + */ +typedef struct fw_async_queue_s fw_async_queue_t; +struct fw_async_queue_s { + GAsyncQueue *pQueue; /**< real queue data structure */ +}; + +/** + * @brief create empty asynchronous Queue + * @return created asynchronous queue on success, otherwise a null pointer. + */ +fw_async_queue_t *fw_async_queue_alloc(); + +/** + * @brief destroy asynchronous Queue + * @param[in] pQueue asynchronous Queue + */ +void fw_async_queue_destroy(fw_async_queue_t *pQueue); + +/** + * @brief lock asynchronous Queue + * @param[in] pQueue asynchronous Queue + */ +void fw_async_queue_lock(fw_async_queue_t *pQueue); + +/** + * @brief unlock asynchronous Queue + * @param[in] pQueue asynchronous Queue + */ +void fw_async_queue_unlock(fw_async_queue_t *pQueue); + +/** + * @brief pop item from asynchronous Queue + * @remarks blocking until enter item to Queue + * @param[in] pQueue asynchronous Queue + * return item on success, otherwise null pointer + */ +void *fw_async_queue_receive_msg(fw_async_queue_t *pQueue); + +/** + * @brief send item to asynchronous Queue + * @param[in] pQueue asynchronous Queue + * @param[in] msg item + */ +void fw_async_queue_send_msg(fw_async_queue_t *pQueue, void *msg); + +/** + * @brief send item to asynchronous Queue with priority + * @param[in] pQueue asynchronous Queue + * @param[in] msg item + * @param[in] cpf priority for callback function + * @param[in] user_data user_data + */ +void fw_async_queue_send_msg_with_compare_priority(fw_async_queue_t *pQueue, void *msg, compare_priority_func cpf, void *user_data); + +#endif /* FW_ASYNC_QUEUE_H_ */ diff --git a/framework/include/agent-framework/Utility/fw_compress.h b/framework/include/agent-framework/Utility/fw_compress.h new file mode 100644 index 0000000..71ebfb3 --- /dev/null +++ b/framework/include/agent-framework/Utility/fw_compress.h @@ -0,0 +1,78 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#ifndef FW_COMPRESS_H_ +#define FW_COMPRESS_H_ + +/** + * @file fw_compress.h + * @brief Provides folder de/compress operations + */ + +/** + * @brief Enumeration of compress result + */ +typedef enum { + FW_COMPRESS_SUCCESS = 1, + FW_COMPRESS_FAIL +} FW_COMPRESS_RESULT; + +/** + * @brief Enumeration of compress type + */ +typedef enum { + FW_COMPRESS_TYPE_TAR = 1, + FW_COMPRESS_TYPE_ZIP +} FW_COMPRESS_TYPE; + +/** + * @brief Compresses folder into desired format + * @param[in] type Type of compress in FW_COMPRESS_TYPE type of value + * @param[in] input_directory_path Folder path to compress + * @param[in] output_file_path Path to put comressed file + # @return FW_COMPRESS_RESULT type of value + */ +FW_COMPRESS_RESULT FW_COMPRESS(FW_COMPRESS_TYPE type, const char *input_directory_path, const char *output_file_path); + +/** + * @brief Decreases reference count of parameter spec + * @param[in] type Type of compress in FW_COMPRESS_TYPE type of value + * @param[in] input_file_path Compressed file path to decompress + * @param[in] output_direcory_path Path to put decompressed folder +# @return FW_COMPRESS_RESULT type of value + */ +FW_COMPRESS_RESULT FW_UNCOMPRESS(FW_COMPRESS_TYPE type, const char *input_file_path, const char *output_direcory_path); + +#endif /* FW_COMPRESS_H_ */ diff --git a/framework/include/agent-framework/Utility/fw_log.h b/framework/include/agent-framework/Utility/fw_log.h new file mode 100644 index 0000000..03aecf4 --- /dev/null +++ b/framework/include/agent-framework/Utility/fw_log.h @@ -0,0 +1,152 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#ifndef LOG_H_ +#define LOG_H_ + +/** + * @file fw_log.h + * @brief Provides various of DLOG wrappers + */ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/** + * @brief Enumeration of log priority level + */ + typedef enum fw_log_priority_e { + FW_LOG_UNKNOWN = 0, + /**< Unknown level */ + FW_LOG_DEFAULT, /**< Default level */ + FW_LOG_VERBOSE, /**< Verbose level */ + FW_LOG_DEBUG, /**< Debug level */ + FW_LOG_INFO, /**< Info level */ + FW_LOG_WARN, /**< Warn level */ + FW_LOG_ERROR, /**< Error level */ + FW_LOG_FATAL, /**< Fatal level */ + FW_LOG_SILENT /**< Silent level */ + } fw_log_priority_t; + +/** + * @brief Terminal option for character coloring + */ +#define FW_TM_OPT_RED_WORD "\033[31m" +#define FW_TM_OPT_GREEN_WORD "\033[32m" +#define FW_TM_OPT_YELLOW_WORD "\033[33m" +#define FW_TM_OPT_BLUE_WORD "\033[34m" +#define FW_TM_OPT_PURPLE_WORD "\033[35m" +#define FW_TM_OPT_WHITE_WORD "\033[37m" + +/** + * @brief Terminal option for background coloring + */ +#define FW_TM_OPT_RED_BACKGROUND "\033[41m" +#define FW_TM_OPT_GREEN_BACKGROUND "\033[42m" +#define FW_TM_OPT_YELLOW_BACKGROUND "\033[43m" +#define FW_TM_OPT_BLUE_BACKGROUND "\033[44m" +#define FW_TM_OPT_PURPLE_BACKGROUND "\033[45m" +#define FW_TM_OPT_WHITE_BACKGROUND "\033[47m" + +/* common interface */ +#ifndef NDEBUG + +/** + * @brief Macro with pre-defined priority level + */ +#define FW_LOGV(...) FW_LOG(FW_LOG_VERBOSE, LOG_TAG, __VA_ARGS__) +#define FW_LOGD(...) FW_LOG(FW_LOG_DEBUG, LOG_TAG, __VA_ARGS__) +#define FW_LOGI(...) FW_LOG(FW_LOG_INFO, LOG_TAG, __VA_ARGS__) + +#else + +/** + * @brief Macro with pre-defined priority level + */ +#define FW_LOGV(...) +#define FW_LOGD(...) +#define FW_LOGI(...) + +#endif /* NDEBUG */ + +/** + * @brief Macro with pre-defined priority level + */ +#define FW_LOGW(...) FW_LOG(FW_LOG_WARN, LOG_TAG, __VA_ARGS__) +#define FW_LOGE(...) FW_LOG(FW_LOG_ERROR, LOG_TAG, __VA_ARGS__) +#define FW_LOGF(...) FW_LOG(FW_LOG_FATAL, LOG_TAG, __VA_ARGS__) + +/** + * @brief Macro with pre-defined priority level and terminal option + */ +#ifndef NDEBUG +#define FW_LOGV_WITH_TERMINAL_OPTION(TM_OPT, ...) FW_LOG_WITH_TERMINAL_OPTION(FW_LOG_VERBOSE, LOG_TAG, TM_OPT, __VA_ARGS__) +#else +#define FW_LOGV_WITH_TERMINAL_OPTION(TM_OPT, ...) +#endif +#define FW_LOGD_WITH_TERMINAL_OPTION(TM_OPT, ...) FW_LOG_WITH_TERMINAL_OPTION(FW_LOG_DEBUG, LOG_TAG, TM_OPT, __VA_ARGS__) +#define FW_LOGI_WITH_TERMINAL_OPTION(TM_OPT, ...) FW_LOG_WITH_TERMINAL_OPTION(FW_LOG_INFO, LOG_TAG, TM_OPT, __VA_ARGS__) +#define FW_LOGW_WITH_TERMINAL_OPTION(TM_OPT, ...) FW_LOG_WITH_TERMINAL_OPTION(FW_LOG_WARN, LOG_TAG, TM_OPT, __VA_ARGS__) +#define FW_LOGE_WITH_TERMINAL_OPTION(TM_OPT, ...) FW_LOG_WITH_TERMINAL_OPTION(FW_LOG_ERROR, LOG_TAG, TM_OPT, __VA_ARGS__) +#define FW_LOGF_WITH_TERMINAL_OPTION(TM_OPT, ...) FW_LOG_WITH_TERMINAL_OPTION(FW_LOG_FATAL, LOG_TAG, TM_OPT, __VA_ARGS__) + +/** + * @brief Macro with no concern about file/funn name and line number + */ +#define FW_LOG(LOG_PRIORITY, TAG, FORMAT...) \ + _fw_log(LOG_PRIORITY, TAG, 0, __FILE__, __func__, __LINE__, FORMAT) +#define FW_LOG_WITH_TERMINAL_OPTION(LOG_PRIORITY, TAG, TM_OPT, FORMAT...) \ + _fw_log(LOG_PRIORITY, TAG, TM_OPT, __FILE__, __func__, __LINE__, FORMAT) + +/* internal function */ + +/** + * @brief Decreases reference count of parameter spec + * @param[in] prio Priority in fw_log_priority_t type + * @param[in] log_tag Log tag to be displayed under + * @param[in] terminal_option Terminal option such as character color or background color + * @param[in] file_path Source file path + * @param[in] func_name Func name + * @param[in] line Line number + * @param[in] format Printf format + * @param[in] ... VA_LIST + */ + void _fw_log(int prio, const char *log_tag, const char *terminal_option, const char *file_path, const char *func_name, const unsigned int line, const char *format, ...); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /* LOG_H_ */ diff --git a/framework/include/agent-framework/securityAssistant/EXT_SA_Encryption_Decryption.h b/framework/include/agent-framework/securityAssistant/EXT_SA_Encryption_Decryption.h new file mode 100755 index 0000000..c58ae91 --- /dev/null +++ b/framework/include/agent-framework/securityAssistant/EXT_SA_Encryption_Decryption.h @@ -0,0 +1,94 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Wook Choi + * Sooyi Kim + */ + +#ifndef EXT_SA_ENCRYPTION_DECRYPTION_H_ +#define EXT_SA_ENCRYPTION_DECRYPTION_H_ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + + typedef enum { + + SA_ENCRYPTION_NO_TYPE = 0, + SA_ENCRYPTION_BASIC, + SA_ENCRYPTION_MD5, + } SA_ENCRYPTION_TYPE; + + unsigned char *SA_Get_Encryption_Value(SA_ENCRYPTION_TYPE encryption_type, char *plain, int plain_length); + char *SA_Get_Decryption_Value(SA_ENCRYPTION_TYPE decryption_type, char *encryption_text); + + typedef enum { + CRYPTOGRAHIC_HASH_FUNTION_NO_TYPE = 0, + CRYPTOGRAHIC_HASH_FUNTION_MD5 = 1, /* length : 16 byte */ + CRYPTOGRAHIC_HASH_FUNTION_SHA1 = 2, /* length : 20 byte */ + + } CRYPTOGRAHIC_HASH_FUNTION_TYPE; + + typedef enum { + CRYPTOGRAHIC_HASH_FUN_HMAC = 1 + } CRYPTOGRAHIC_HASH_FUNTION_FLAGS; + +/* + * @brief get hash code + * @param[in] type hash function type + * @param[in] plain text + * @param[in] plain_len text length + * @return operation result + * @retval encrypt data success + * @retval 0 fail + * + */ + unsigned char *SA_Encrypt_Cryptograhic_Hash(CRYPTOGRAHIC_HASH_FUNTION_TYPE type, const char *plain, int plain_len); + +/* + * @brief get hash code + * @param[in] type hash function type + * @param[in] plain text + * @param[in] plain_len text length + * @param[in] key key + * @param[in] key_len key length + * @param[in] flags CRYPTOGRAHIC_HASH_FUNTION_FLAGS + * @return operation result + * @retval encrypt data success + * @retval 0 fail + */ + unsigned char *SA_Encrypt_Cryptograhic_Hash_With_Flags(CRYPTOGRAHIC_HASH_FUNTION_TYPE type, const char *plain, int plain_len, const char *key, int key_len, CRYPTOGRAHIC_HASH_FUNTION_FLAGS flags); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /* EXT_SA_ENCRYPTION_DECRYPTION_H_ */ diff --git a/framework/include/fw_define.h b/framework/include/fw_define.h new file mode 100755 index 0000000..900b3ce --- /dev/null +++ b/framework/include/fw_define.h @@ -0,0 +1,47 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Jungwook Ryu + */ + +#ifndef FW_DEFINE_H_ +#define FW_DEFINE_H_ + +#ifdef NDEBUG +#define FW_STATIC static +#define FW_INLINE inline +#else +#define FW_STATIC +#define FW_INLINE +#endif + +#endif /* FW_DEFINE_H_ */ diff --git a/framework/include/securityAssistant/EXT_SA_Encryption_Decryption.h b/framework/include/securityAssistant/EXT_SA_Encryption_Decryption.h new file mode 100755 index 0000000..c58ae91 --- /dev/null +++ b/framework/include/securityAssistant/EXT_SA_Encryption_Decryption.h @@ -0,0 +1,94 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Wook Choi + * Sooyi Kim + */ + +#ifndef EXT_SA_ENCRYPTION_DECRYPTION_H_ +#define EXT_SA_ENCRYPTION_DECRYPTION_H_ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + + typedef enum { + + SA_ENCRYPTION_NO_TYPE = 0, + SA_ENCRYPTION_BASIC, + SA_ENCRYPTION_MD5, + } SA_ENCRYPTION_TYPE; + + unsigned char *SA_Get_Encryption_Value(SA_ENCRYPTION_TYPE encryption_type, char *plain, int plain_length); + char *SA_Get_Decryption_Value(SA_ENCRYPTION_TYPE decryption_type, char *encryption_text); + + typedef enum { + CRYPTOGRAHIC_HASH_FUNTION_NO_TYPE = 0, + CRYPTOGRAHIC_HASH_FUNTION_MD5 = 1, /* length : 16 byte */ + CRYPTOGRAHIC_HASH_FUNTION_SHA1 = 2, /* length : 20 byte */ + + } CRYPTOGRAHIC_HASH_FUNTION_TYPE; + + typedef enum { + CRYPTOGRAHIC_HASH_FUN_HMAC = 1 + } CRYPTOGRAHIC_HASH_FUNTION_FLAGS; + +/* + * @brief get hash code + * @param[in] type hash function type + * @param[in] plain text + * @param[in] plain_len text length + * @return operation result + * @retval encrypt data success + * @retval 0 fail + * + */ + unsigned char *SA_Encrypt_Cryptograhic_Hash(CRYPTOGRAHIC_HASH_FUNTION_TYPE type, const char *plain, int plain_len); + +/* + * @brief get hash code + * @param[in] type hash function type + * @param[in] plain text + * @param[in] plain_len text length + * @param[in] key key + * @param[in] key_len key length + * @param[in] flags CRYPTOGRAHIC_HASH_FUNTION_FLAGS + * @return operation result + * @retval encrypt data success + * @retval 0 fail + */ + unsigned char *SA_Encrypt_Cryptograhic_Hash_With_Flags(CRYPTOGRAHIC_HASH_FUNTION_TYPE type, const char *plain, int plain_len, const char *key, int key_len, CRYPTOGRAHIC_HASH_FUNTION_FLAGS flags); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /* EXT_SA_ENCRYPTION_DECRYPTION_H_ */ diff --git a/framework/include/securityAssistant/IN_SA_Cryptograhic_Hash_Function.h b/framework/include/securityAssistant/IN_SA_Cryptograhic_Hash_Function.h new file mode 100755 index 0000000..c00a72b --- /dev/null +++ b/framework/include/securityAssistant/IN_SA_Cryptograhic_Hash_Function.h @@ -0,0 +1,46 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Wook Choi + * Sooyi Kim + */ + +#ifndef IN_SA_CRYPTOGRAHIC_HASH_FUNCTION_H_ +#define IN_SA_CRYPTOGRAHIC_HASH_FUNCTION_H_ + +#include "securityAssistant/EXT_SA_Encryption_Decryption.h" + +unsigned char *crypt_DES(const char *plain, int plain_len, const char *key, int key_len); +unsigned char *crypt_MD5(CRYPTOGRAHIC_HASH_FUNTION_FLAGS flags, const char *plain, int plain_len, const char *key, int key_len); +unsigned char *crypt_SHA1(CRYPTOGRAHIC_HASH_FUNTION_FLAGS flags, const char *plain, int plain_len, const char *key, int key_len); + +#endif /* IN_SA_CRYPTOGRAHIC_HASH_FUNCTION_H_ */ diff --git a/framework/include/securityAssistant/IN_SA_MD5.h b/framework/include/securityAssistant/IN_SA_MD5.h new file mode 100755 index 0000000..fe127ce --- /dev/null +++ b/framework/include/securityAssistant/IN_SA_MD5.h @@ -0,0 +1,73 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Wook Choi + * Sooyi Kim + */ + +#ifndef IN_SA_MD5_H_ +#define IN_SA_MD5_H_ + +#include + +typedef struct MD5Context { + unsigned long int buf[4]; + unsigned long int bits[2]; + unsigned char in[64]; + int doByteReverse; +} MD5Context; + +static gint _ie = 0x44332211; +static union _endian { + gint i; + gchar b[4]; +} *_endian = (union _endian *)&_ie; +#define IS_BIG_ENDIAN() (_endian->b[0] == '\x44') +#define IS_LITTLE_ENDIAN() (_endian->b[0] == '\x11') + +/* The four core functions - F1 is optimized somewhat */ + +/* #define F1(x, y, z) (x & y | ~x & z) */ +#define F1(x, y, z) (z ^ (x & (y ^ z))) +#define F2(x, y, z) F1(z, x, y) +#define F3(x, y, z) (x ^ y ^ z) +#define F4(x, y, z) (y ^ (x | ~z)) + +/* This is the central step in the MD5 algorithm. */ +#define MD5STEP(f, w, x, y, z, data, s) (w += f(x, y, z) + data, w = w<>(32-s), w += x) + +void MD5GetDigest(const char *buffer, int buffer_size, unsigned char *digest); +void MD5Init(MD5Context *ctx); +void MD5Update(MD5Context *ctx, const char *buf, unsigned long int len); +void MD5Final(MD5Context *ctx, unsigned char *digest); + +#endif /* IN_SA_MD5_H_ */ diff --git a/framework/src/Account/Account_Mgr.c b/framework/src/Account/Account_Mgr.c new file mode 100755 index 0000000..bce8c18 --- /dev/null +++ b/framework/src/Account/Account_Mgr.c @@ -0,0 +1,279 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#include "PlugIn/PlugIn_DataConnector.h" +#include "PlugIn/PlugIn_Account.h" +#include "Utility/fw_alloc.h" +#include "Utility/fw_log.h" + +#include "DataAdapter/DACI_Agent_Handler_Manager.h" + +#include "Account/Account_Util.h" + +#include "Account/Account_Mgr.h" + +#define LOG_TAG "AF_ACCOUNT" + +int addAccount(char *email, char *password, char *serverIP, char *domain, int isEnableSSL, int create_mode, char *access_name) +{ + daci_account account; + account.email_address = email; + account.password = password; + account.enable = 1; + account.accessName = access_name; + + /* insert account info to Sync Agent DB account database */ + int account_id = DACI_Add_Account(&account); + + if (account_id == -1) { + FW_LOGE("[addAccount] SA_DA_Add_Account() Error"); + } + + /* + * todo Process Platform Specific Account + */ + addAccount_Platform(account_id, email, password, create_mode); + + /* Update ServerInfo */ + + /* + * todo Update Policy + */ + + return account.account_id; +} + +int deleteAccount(int accountID) +{ + /* Remove from Service DB & Syncagent DB */ + DACI_RETURN result = DACI_Delete_All_Database_Account(accountID); + + if ((result == DACI_SUCCESS) || (result == DACI_ERR_DELETE_LAST_ACCOUNT)) { + /* Update the Cache */ + + /* + * todo Remove from Platform account database + */ + delAccount_Platform(accountID); + + return 1; + } + + return 0; +} + +ACCOUNT_ERROR construct_AccountTbl_From_Service() +{ + ACCOUNT_ERROR err_code = ACCOUNT_SUCCESS; + + int *fw_account_id_list = 0; + int fw_account_id_cnt = 0; + + int content_count = 0; + int *service_plugin_id_list = get_DataConnector_PlugIn_ID_List(&content_count); + + if (service_plugin_id_list == 0) { + FW_LOGV("No Data PlugIn loaded!!"); + return ACCOUNT_SUCCESS; + } + + int index = 0; + for (; index < content_count; index++) { + int service = service_plugin_id_list[index]; + FW_LOGV("Service ID : %d", service); + + /* + * Get account id List from agent account table + */ + fw_account_id_list = DACI_Get_Account_Account_Id_List(&fw_account_id_cnt); +/* if (fw_account_id_list == 0 || fw_account_id_cnt == 0) { + continue; + }*/ + + FW_LOGV("fw_account_id_cnt : %d", fw_account_id_cnt); + + /* + * Get current All Service Account ID + */ + GET_ACCOUNT_ID_LIST pFunc_Get_Service_Account_Id_List = getFunction_DataConnector_GET_ACCOUNT_ID_LIST(service); + if (pFunc_Get_Service_Account_Id_List == 0) { + FW_LOGV("pFunc_Get_Service_Account_Id_List is null : %d", service); + continue; + } + + int service_account_id_cnt; + int *service_account_id_list = pFunc_Get_Service_Account_Id_List(&service_account_id_cnt); + + FW_LOGV("[%d] service_account_id_cnt : %d", service, service_account_id_cnt); + + int *service_account_id_new = 0; + if (service_account_id_cnt != 0) { + service_account_id_new = (int *)fw_malloc(sizeof(int) * service_account_id_cnt); + if (service_account_id_new == 0) { + FW_LOGE("fw_malloc Failed!!"); + return ACCOUNT_FAIL; + } + + int i = 0; + for (; i < service_account_id_cnt; i++) { + service_account_id_new[i] = 1; + FW_LOGV("service_account_id_list[%d] : %d", i, service_account_id_list[i]); + } + } + + int i = 0; + for (; fw_account_id_list != 0 && i < fw_account_id_cnt; i++) { + Has_PlatformAccount_Service pFunc_Has_PlatformAccount_Service = getFunction_Account_Has_PlatformAccount_Service(getAccount_PlugIn_ID()); + int hasServiceAccountID = pFunc_Has_PlatformAccount_Service(fw_account_id_list[i], service); + if (hasServiceAccountID) { + /* + * Get Service Account ID, Fw has + */ + int fw_service_account_id = getAccountID_Service(service, fw_account_id_list[i]); + FW_LOGV("fw_account_id_list[%d] : %d", i, fw_account_id_list[i]); + FW_LOGV("fw_service_account_id : %d", fw_service_account_id); + + int k = 0; + for (; k < service_account_id_cnt; k++) { + if (fw_service_account_id == service_account_id_list[k]) { + FW_LOGV("service_account_id_list[%d] : %d", k, service_account_id_list[k]); + service_account_id_new[k] = 0; + break; + } + } + + FW_LOGV("\n\nk : %d\n", k); + /* + * Delete fw_service_account_id from vconf + */ + if (k >= service_account_id_cnt) { + Del_PlatformAccount_Service pFunc_Del_PlatformAccount_Service = getFunction_Account_Del_PlatformAccount_Service(getAccount_PlugIn_ID()); + pFunc_Del_PlatformAccount_Service(fw_account_id_list[i], service); + err_code = ACCOUNT_CHANGED; + } + } + } + + i = 0; + for (; i < service_account_id_cnt; i++) { + if (service_account_id_new[i] == 1) { + int k = 0; + for (; fw_account_id_list != 0 && k < fw_account_id_cnt; k++) { + /* + * find empty slot in fw_account_id_list[k] + */ + Has_PlatformAccount_Service pFunc_Has_PlatformAccount_Service = getFunction_Account_Has_PlatformAccount_Service(getAccount_PlugIn_ID()); + int hasServiceAccountID = pFunc_Has_PlatformAccount_Service(fw_account_id_list[k], service); + if (!hasServiceAccountID) { + Set_PlatformAccount_Service pFunc_Set_PlatformAccount_Service = getFunction_Set_PlatformAccount_Service(getAccount_PlugIn_ID()); + pFunc_Set_PlatformAccount_Service(fw_account_id_list[k], service, service_account_id_list[i]); + service_account_id_new[i] = 0; + break; + } + } + + if (service_account_id_new[i] == 1) { + /* + * Create new FW account and append service account id + */ + FW_LOGV("Create new FW account!!"); + + daci_account account; + account.email_address = "0"; + account.password = "0"; + account.accessName = "Account"; + + int fw_account_id = DACI_Add_Account(&account);; + Set_PlatformAccount_Service pFunc_Set_PlatformAccount_Service = getFunction_Set_PlatformAccount_Service(getAccount_PlugIn_ID()); + pFunc_Set_PlatformAccount_Service(fw_account_id, service, service_account_id_list[i]); + } + + err_code = ACCOUNT_CHANGED; + } + } + + if (fw_account_id_list != 0) { + free(fw_account_id_list); + } + } + + if (service_plugin_id_list != 0) { + free(service_plugin_id_list); + } + + return err_code; +} + +int *get_Account_ID_List(int content_type, int *count) +{ + *count = 0; + int fw_account_count = 0; + int *fw_account_id_list = DACI_Get_Account_Account_Id_List(&fw_account_count); + + if (fw_account_count == 0 || fw_account_id_list == 0) { + return 0; + } + + int *account_id_list = (int *)calloc(fw_account_count, sizeof(int)); + + int i = 0; + for (; i < fw_account_count; i++) { + Has_PlatformAccount_Service pFunc_Has_PlatformAccount_Service = getFunction_Account_Has_PlatformAccount_Service(getAccount_PlugIn_ID()); + int hasServiceAccountID = pFunc_Has_PlatformAccount_Service(fw_account_id_list[i], content_type); + + if (hasServiceAccountID) { + account_id_list[*count] = fw_account_id_list[i]; + *count = *count + 1; + } + } + + if (fw_account_id_list != 0) { + free(fw_account_id_list); + } + + return account_id_list; +} + +void *get_Account_Info(int fw_account_id, int content_type) +{ + Get_Service_AccountInfo pFunc_Get_Service_AccountInfo = getFunction_Get_Service_AccountInfo(getAccount_PlugIn_ID()); + + if (pFunc_Get_Service_AccountInfo == 0) { + FW_LOGE("pFunc_Get_Service_AccountInfo is null!!"); + return 0; + } + + return pFunc_Get_Service_AccountInfo(fw_account_id, content_type); +} diff --git a/framework/src/Account/Account_Util.c b/framework/src/Account/Account_Util.c new file mode 100755 index 0000000..e80ba46 --- /dev/null +++ b/framework/src/Account/Account_Util.c @@ -0,0 +1,144 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#include "Utility/fw_log.h" +#include "Utility/fw_ref.h" +#include "PlugIn/PlugIn_Account.h" + +#include "DataAdapter/DACI_Agent_Handler_Manager.h" + +#include "Account/Account_Util.h" + +#define LOG_TAG "AF_ACCOUNT" + +int isExistAccountID(int accountID) +{ + return DACI_IsExist_Account(accountID); +} + +int *getAccountIDList_Service(int service_type, int *cnt) +{ + int *accountID_list = getAccountList(cnt); + + if ((*cnt != 0) && (accountID_list != 0)) { + int *service_accountID_list = (int *)calloc(*cnt, sizeof(int)); + int i = 0; + for (; i < *cnt; i++) { + service_accountID_list[i] = getAccountID_Service(service_type, accountID_list[i]); + } + if (accountID_list != 0) { + free(accountID_list); + } + return service_accountID_list; + } + + if (accountID_list != 0) { + free(accountID_list); + } + + return 0; +} + +int getAccountID_Service(int service_type, int account_id) +{ + Get_Service_AccountID pFunc = getFunction_Account_Get_Service_AccountID(getAccount_PlugIn_ID()); + + if (pFunc != 0) { + int service_account_id = pFunc(service_type, account_id); + + return service_account_id; + } + + return -1; +} + +int getAccountID_FW(int service_type, int service_account_id, int index) +{ + Get_FW_AccountID pFunc = getFunction_Account_Get_FW_AccountID(getAccount_PlugIn_ID()); + + if (pFunc != 0) { + int account_id = pFunc(service_type, service_account_id, index); + + return account_id; + } + + return -1; +} + +int *getAccountList(int *cnt) +{ + DACI_RETURN da_err = DACI_Open_Agent(); + FW_LOGI("Done Open Agent DB : %d", da_err); + + int *accountList = DACI_Get_Account_Account_Id_List(cnt); + + da_err = DACI_Close_Agent(); + FW_LOGI("Done Close Agent DB : %d", da_err); + + return accountList; +} + +void addAccount_Platform(int fw_account_id, char *email, char *password, int create_mode) +{ + FW_LOGV("addAccount_Platform called"); + Add_PlatformAccount pFunc = getFunction_Account_Add_PlatformAccount(getAccount_PlugIn_ID()); + + if (pFunc != 0) { + FW_LOGV("pFunc is not null"); + pFunc(fw_account_id, email, password, create_mode); + } else { + FW_LOGV("pFunc is null"); + } +} + +void delAccount_Platform(int fw_account_id) +{ + FW_LOGV("delAccount_Platform called"); + Del_PlatformAccount pFunc = getFunction_Account_Del_PlatformAccount(getAccount_PlugIn_ID()); + + if (pFunc != 0) { + FW_LOGV("pFunc is not null"); + pFunc(fw_account_id); + } else { + FW_LOGV("pFunc is null"); + } +} + +char *getEmailAddress(int accountID) +{ + char *emailAddress = DACI_Get_Account_Email_Address(accountID); + + return emailAddress; +} diff --git a/framework/src/DataAdapter/DACI_Agent.c b/framework/src/DataAdapter/DACI_Agent.c new file mode 100755 index 0000000..155211a --- /dev/null +++ b/framework/src/DataAdapter/DACI_Agent.c @@ -0,0 +1,3138 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu , + * Heeyoung Hwang + */ + +#include + +#include "Utility/fw_log.h" +#include "DataAdapter/DACI_Agent_Handler_Manager.h" +#include "DataAdapter/DACI_Agent.h" + +#define LOG_TAG "AF_DACI" + +/* static function define */ +static int __busy_handler(void *pData, int count); +static DACI_RETURN __query_exec(DACI_HANDLER *daci_handler, char *query, char *errMsg); +static daci_stmt __query_prepare(DACI_HANDLER *daci_handler, char *query, int size); +static DACI_RETURN __stmt_bind_text(DACI_HANDLER *daci_handler, daci_stmt stmt, int index, const char *value); +static DACI_RETURN __stmt_bind_int(DACI_HANDLER *daci_handler, daci_stmt stmt, int index, const int value); +static DACI_RETURN __stmt_bind_blob(DACI_HANDLER *daci_handler, daci_stmt stmt, int index, const void *value, int nByte); +static DACI_RETURN __stmt_bind_null(DACI_HANDLER *daci_handler, daci_stmt stmt, int index); +static DACI_RETURN __stmt_read_step(DACI_HANDLER *daci_handler, daci_stmt stmt); +static DACI_RETURN __stmt_write_step(DACI_HANDLER *daci_handler, daci_stmt stmt); +static DACI_RETURN __stmt_reset(DACI_HANDLER *daci_handler, daci_stmt stmt); +static DACI_RETURN __stmt_finalize(DACI_HANDLER *daci_handler, daci_stmt stmt); +static char *__stmt_column_text(daci_stmt stmt, int index); +static int __stmt_column_int(daci_stmt stmt, int index); +static DACI_RETURN __get_table(DACI_HANDLER *daci_handler, char *query, char ***result, int *rowCount, int *colCount); +static void __free_table(char **result); + +static DACI_RETURN __create_changelog_table(DACI_HANDLER *daci_handler, int accountId); +static DACI_RETURN __drop_changelog_table(DACI_HANDLER *daci_handler, int accountId); + +static int __exist_table(DACI_HANDLER *daci_handler, const char *tableName); +static int __get_data_count(DACI_HANDLER *daci_handler, char *query, int size); +static char *__replace_table_name(char *old, int accountId, int count); +static char *__get_table_name(DACI_TABLE_NAME tableName); +static char *__get_column_name(DACI_COLUMN_NAME columnName); +static int __get_next_account_id(); +static DACI_RETURN __delete_account(DACI_HANDLER *daci_handler, DACI_TABLE_NAME tableName, int accountId); + +static char *daci_file_path = 0; +static pthread_t use_transaction_thread_id = 0; +static pthread_mutex_t transaction_lock; +static pthread_mutex_t exec_lock; + +static char *g_daci_create_table[] = { + /* 1. create account_tbl */ + "create table account_tbl" "(" "account_id integer not null," "email_address varchar(51) not null," "password varchar(51) not null," "enable boolean not null default 1," "last_update date not null default current_timestamp," "access_name varchar(64) not null," "constraint account_tbl_pk primary key(account_id)" ");", + + /* 2. create folder_tbl */ + "create table folder_tbl" "(" "folder_id varchar(64) not null," "data_store_id integer not null," "account_id integer not null," "folder_type_id integer not null," "service_id varchar(20) default null," "parent_folder_id varchar(64) default null," "last_update date not null default current_timestamp," "access_name varchar(64) not null," "constraint folder_tbl_pk primary key(folder_id)," "constraint folder_tbl_account_id_fk foreign key(account_id) references account_tbl(account_id)" ");", + + /* 3. create item_tbl */ + "create table item_tbl" + "(" + "item_id varchar(64) not null," + "data_store_id integer not null," "account_id integer not null," "folder_id varchar(64) not null," "service_id varchar(20) not null," "last_update date not null default current_timestamp," "access_name varchar(64) not null," "constraint item_tbl_pk primary key(item_id)," "constraint item_tbl_account_id_fk foreign key(account_id) references account_tbl(account_id)," "constraint itme_tbl_folder_id_fk foreign key(folder_id) references folder_tbl(folder_id)" ");", + + /* 4. create config_tbl */ + "create table config_tbl" "(" "config_id integer not null," "key varchar(50) not null," "value varchar(30) default null," "type varchar(10) default null," "last_update date not null default current_timestamp," "access_name varchar(64) not null," "constraint config_tbl_pk primary key(config_id, Key)" ");", + + /* 5. create account_item_changelog_tbl */ + "create table account_%d_item_changelog_tbl" "(" "item_id varchar(64) not null," "operation_id integer not null," "status varchar(15) not null default \'SYNC_REQUIRED\'," "last_update date not null default current_timestamp," "access_name varchar(64) not null," "constraint account_%d_item_changelog_tbl_pk primary key(item_id)," "constraint account_%d_item_changelog_tbl_item_id_fk foreign key(item_id) references item_tbl(item_id)" ");", + + /* 6. create last_anchor_tbl */ + "create table last_anchor_tbl" "(" "account_id integer not null," "data_store_id integer not null," "last_anchor_server varchar(20) default null," "last_anchor_client varchar(20) default null," "last_update date not null default current_timestamp," "access_name varchar(64) not null," "constraint last_anchor_tbl_pk primary key(account_id, data_store_id)," "constraint last_anchor_tbl_account_id_fk foreign key(account_id) references account_tbl(account_id)" ");", + + /* 7. create mapping_tbl */ + "create table mapping_tbl" "(" "account_id integer not null," "data_store_id integer not null," "luid varchar(64) default null," "guid varchar(64) default null," "last_update date not null default current_timestamp," "access_name varchar(64) not null," "constraint mapping_tbl_pk primary key(account_id, luid)," "constraint mapping_tbl_account_id_fk foreign key(account_id) references account_tbl(account_id)" ");", + + /* 8. create id_provider_tbl */ + "create table id_provider_tbl" "(" "id_provider_code integer not null," "id_capacity integer not null," "bit_per_page integer not null," "last_id integer not null," "free_bit_cnt integer not null," "constraint id_provider_tbl_pk primary key(id_provider_code)" ");", + + /* 9. create id_page_tbl */ + "create table id_page_tbl" "(" "page_index integer not null," "id_provider_code integer not null," "page_bit BLOB," "constraint id_page_tbl_pk primary key(page_index, id_provider_code)," "constraint id_page_tbl_fk foreign key(id_provider_code) references id_provider_tbl(id_provider_code)" ");" +}; + +static char *g_daci_drop_table[] = { + /* 1. drop account_tbl */ + "drop table account_tbl", + + /* 2. drop folder_tbl */ + "drop table folder_tbl", + + /* 3. drop item_tbl */ + "drop table item_tbl", + + /* 4. drop config_tbl */ + "drop table config_tbl", + + /* 5. drop account_item_changelog_tbl */ + "drop table account_%d_item_changelog_tbl", + + /* 6. drop last_anchor_tbl */ + "drop table last_anchor_tbl", + + /* 7. drop mapping_tbl */ + "drop table mapping_tbl" + /* 8. drop id_provider_tbl */ + "drop table id_provider_tbl" + /* 9. drop id_page_tbl */ + "drop table id_page_tbl" +}; + +DACI_RETURN open_agent(DACI_HANDLER **daci_handler) +{ + FW_LOGV("[%s] Start !\n", __func__); + int ret = 0; + char *errMsg = 0; + + if (*daci_handler == 0) { + + /* db open */ + /* ret = db_util_open(DACI_FILE_PATH, &(*daci_handler), 0); */ + + ret = sqlite3_open(daci_file_path, daci_handler); + if (ret != SQLITE_OK) + goto DACI_FINISH; + + /* register busy handler */ + ret = sqlite3_busy_handler(*daci_handler, __busy_handler, 0); + if (ret != SQLITE_OK) { + FW_LOGV("Fail to register busy handler", errMsg); + goto DACI_FINISH; + } + + FW_LOGV("agent_db_open_success"); + + } else { + FW_LOGV("agent_db_already_opened"); + } + + FW_LOGV("[%s] End !\n", __func__); + return DACI_SUCCESS; + +DACI_FINISH: + + FW_LOGE("agent_open failed(%d) : %s", ret, sqlite3_errmsg(*daci_handler)); + + if (errMsg) + sqlite3_free(errMsg); + + sqlite3_close(*daci_handler); + *daci_handler = 0; + + return DACI_ERR_OPEN_FAILED; +} + +DACI_RETURN close_Agent(DACI_HANDLER *daci_handler) +{ + FW_LOGV("[%s] Start !\n", __func__); + + int ret = 0; + ret = sqlite3_close(daci_handler); + daci_handler = 0; + + if (ret != SQLITE_OK) { + FW_LOGE("agent_db_agent_close failed(%d) : %s", ret, sqlite3_errmsg(daci_handler)); + return DACI_ERR_CLOSE_FAILED; + } + + FW_LOGV("agent_db_agent_close_success"); + FW_LOGV("[%s] End !\n", __func__); + + return DACI_SUCCESS; +} + +DACI_RETURN begin_transaction(DACI_HANDLER *daci_handler) +{ + FW_LOGV("[%s] Start !\n", __func__); + + DACI_RETURN ret = DACI_SUCCESS; + + pthread_mutex_lock(&transaction_lock); + use_transaction_thread_id = DACI_GET_THREAD_ID; + + pthread_mutex_lock(&exec_lock); + ret = __query_exec(daci_handler, "begin immediate", "agent_db_begin_transaction failed"); + pthread_mutex_unlock(&exec_lock); + + if (ret == DACI_ERR_QUERY_FAILED) + ret = DACI_ERR_TRANSACTION_FAILED; + + FW_LOGV("[%s] End !\n", __func__); + return ret; +} + +DACI_RETURN end_transaction(DACI_HANDLER *daci_handler, DACI_TRANSACTION transaction) +{ + FW_LOGV("[%s] Start !\n", __func__); + + DACI_RETURN ret = DACI_SUCCESS; + char *query = 0; + char *errMsg = 0; + + if (transaction == TRANSACTION_COMMIT) { + query = "commit transaction"; + errMsg = "agent_db_commit_transaction failed"; + } else if (transaction == TRANSACTION_ROLLBACK) { + query = "rollback transaction"; + errMsg = "agent_db_rollback_transaction failed"; + } + + pthread_mutex_lock(&exec_lock); + ret = __query_exec(daci_handler, query, errMsg); + pthread_mutex_unlock(&exec_lock); + + use_transaction_thread_id = 0; + pthread_mutex_unlock(&transaction_lock); + + if (ret == DACI_ERR_QUERY_FAILED) { + if (transaction == TRANSACTION_COMMIT) { + query = "rollback transaction"; + errMsg = "agent_db_rollback_transaction failed"; + ret = __query_exec(daci_handler, query, errMsg); + if (ret == DACI_SUCCESS) + FW_LOGV("agent_db_rollback_transaction success"); + } + ret = DACI_ERR_TRANSACTION_FAILED; + } + + FW_LOGV("[%s] End !\n", __func__); + return ret; +} + +void set_agentdb_file_path(char *file_path) +{ + daci_file_path = file_path; +} + +DACI_RETURN create_AgentDefaultTable(DACI_HANDLER *daci_handler) +{ + FW_LOGE("[%s] start", __func__); + DACI_RETURN ret = DACI_SUCCESS; + + if (daci_handler == 0) { + FW_LOGV("[%s] DACI_ERRORS !\n", __func__); + return DACI_ERRORS; + } + + if ((begin_transaction(daci_handler) != DACI_SUCCESS)) { + FW_LOGE("agent_db_default_tbl_create failed"); + return DACI_ERR_CREATE_TABLE_FAILED; + } + + /* 1. create account_tbl */ + if (__exist_table(daci_handler, "account_tbl") == 0) { + ret = __query_exec(daci_handler, g_daci_create_table[TABLE_NAME_ACCOUNT], "account_tbl_create failed"); + if (ret != DACI_SUCCESS) + goto DACI_FINISH; + } + + /* 2. create folder_tbl */ + if (__exist_table(daci_handler, "folder_tbl") == 0) { + ret = __query_exec(daci_handler, g_daci_create_table[TABLE_NAME_FOLDER], "folder_tbl_create failed"); + if (ret != DACI_SUCCESS) + goto DACI_FINISH; + } + + /* 3. create item_tbl */ + if (__exist_table(daci_handler, "item_tbl") == 0) { + ret = __query_exec(daci_handler, g_daci_create_table[TABLE_NAME_ITEM], "item_tbl_create failed"); + if (ret != DACI_SUCCESS) + goto DACI_FINISH; + } + + /* 4. create config_tbl */ + if (__exist_table(daci_handler, "config_tbl") == 0) { + ret = __query_exec(daci_handler, g_daci_create_table[TABLE_NAME_CONFIG], "config_tbl_create failed"); + if (ret != DACI_SUCCESS) + goto DACI_FINISH; + } + + /* 5. create last_anchor_tbl */ + if (__exist_table(daci_handler, "last_anchor_tbl") == 0) { + ret = __query_exec(daci_handler, g_daci_create_table[TABLE_NAME_LAST_ANCHOR], "last_anchor_tbl_create failed"); + if (ret != DACI_SUCCESS) + goto DACI_FINISH; + } + + /* 6. create mapping_tbl */ + if (__exist_table(daci_handler, "mapping_tbl") == 0) { + ret = __query_exec(daci_handler, g_daci_create_table[TABLE_NAME_MAPPING], "mapping_tbl_create failed"); + if (ret != DACI_SUCCESS) + goto DACI_FINISH; + } + + /* 7. create id_provider_tbl */ + if (__exist_table(daci_handler, "id_provider_tbl") == 0) { + ret = __query_exec(daci_handler, g_daci_create_table[TABLE_NAME_ID_PROVIDER], "id_provider_tbl_create failed"); + if (ret != DACI_SUCCESS) + goto DACI_FINISH; + } + + /* 8. create id_page_tbl */ + if (__exist_table(daci_handler, "id_page_tbl") == 0) { + ret = __query_exec(daci_handler, g_daci_create_table[TABLE_NAME_ID_PAGE], "id_page_tbl_create failed"); + if (ret != DACI_SUCCESS) + goto DACI_FINISH; + } + +DACI_FINISH: + + if (ret != DACI_SUCCESS) { + end_transaction(daci_handler, TRANSACTION_ROLLBACK); + ret = DACI_ERR_CREATE_TABLE_FAILED; + } else { + ret = end_transaction(daci_handler, TRANSACTION_COMMIT); + } + + FW_LOGE("[%s] end", __func__); + return ret; +} + +int add_account(DACI_HANDLER *daci_handler, daci_account *account) +{ + FW_LOGV("[%s] Start !\n", __func__); + + DACI_RETURN ret = DACI_SUCCESS; + daci_stmt stmt = 0; + char *query = "insert into account_tbl (account_id, email_address, password, enable, access_name) values (?, ?, ?, ?, ?)"; + + account->account_id = __get_next_account_id(); + + if (account->account_id > DACI_MAX_ACCOUNT) { + FW_LOGE("account registration is full"); + account->account_id = -1; + goto DACI_FINISH; + } + + stmt = __query_prepare(daci_handler, query, strlen(query)); + if (stmt == 0) { + account->account_id = -1; + goto DACI_FINISH; + } + + __stmt_bind_int(daci_handler, stmt, 1, account->account_id); + __stmt_bind_text(daci_handler, stmt, 2, account->email_address); + __stmt_bind_text(daci_handler, stmt, 3, account->password); + __stmt_bind_int(daci_handler, stmt, 4, account->enable); + __stmt_bind_text(daci_handler, stmt, 5, account->accessName); + + ret = __stmt_write_step(daci_handler, stmt); + if (ret != DACI_SUCCESS) + account->account_id = -1; + + __stmt_finalize(daci_handler, stmt); + + if (account->account_id != -1) { + __create_changelog_table(daci_handler, account->account_id); + } + +DACI_FINISH: + + FW_LOGV("[%s] End !\n", __func__); + return account->account_id; +} + +DACI_RETURN delete_account(DACI_HANDLER *daci_handler, int accountId) +{ + FW_LOGV("[%s] Start !\n", __func__); + + DACI_RETURN ret = DACI_SUCCESS; + int i = 0; + + /* delete default table by accountId */ + for (i = 0; i < TABLE_NAME_MAX; i++) { + if (i == TABLE_NAME_ACCOUNT_ITEM_CHANGELOG) { + continue; + } + + ret = __delete_account(daci_handler, i, accountId); + if (ret != DACI_SUCCESS) { + ret = DACI_ERR_QUERY_FAILED; + goto DACI_FINISH; + } + } + + /* drop changelog table */ + ret = __drop_changelog_table(daci_handler, accountId); + if (ret != DACI_SUCCESS) { + ret = DACI_ERR_QUERY_FAILED; + goto DACI_FINISH; + } + +DACI_FINISH: + + FW_LOGV("[%s] End !\n", __func__); + return ret; +} + +DACI_RETURN set_accountEmailAddress(DACI_HANDLER *daci_handler, int accountId, char *emailAddress, char *accessName) +{ + FW_LOGV("[%s] Start !\n", __func__); + + DACI_RETURN ret = DACI_SUCCESS; + daci_stmt stmt = 0; + char *query = "update account_tbl set email_address = ?, last_update = current_timestamp, access_name = ? where account_id = ?"; + + stmt = __query_prepare(daci_handler, query, strlen(query)); + if (stmt == 0) + return DACI_ERR_QUERY_FAILED; + + __stmt_bind_text(daci_handler, stmt, 1, emailAddress); + __stmt_bind_text(daci_handler, stmt, 2, accessName); + __stmt_bind_int(daci_handler, stmt, 3, accountId); + + ret = __stmt_write_step(daci_handler, stmt); + __stmt_finalize(daci_handler, stmt); + + FW_LOGV("[%s] End !\n", __func__); + return ret; +} + +DACI_RETURN set_accountPassword(DACI_HANDLER *daci_handler, int accountId, char *password, char *accessName) +{ + FW_LOGV("[%s] Start !\n", __func__); + + DACI_RETURN ret = DACI_SUCCESS; + daci_stmt stmt = 0; + char *query = "update account_tbl set password = ?, last_update = current_timestamp, access_name = ? where account_id = ?"; + + stmt = __query_prepare(daci_handler, query, strlen(query)); + if (stmt == 0) + return DACI_ERR_QUERY_FAILED; + + __stmt_bind_text(daci_handler, stmt, 1, password); + __stmt_bind_text(daci_handler, stmt, 2, accessName); + __stmt_bind_int(daci_handler, stmt, 3, accountId); + + ret = __stmt_write_step(daci_handler, stmt); + __stmt_finalize(daci_handler, stmt); + + FW_LOGV("[%s] End !\n", __func__); + return ret; +} + +int *get_accountAccountIdList(DACI_HANDLER *daci_handler, int *count) +{ + FW_LOGV("[%s] Start !\n", __func__); + + daci_stmt stmt = 0; + int *accountIdList = 0; + int dataCount = 0; + int i = 0; + char g_daci_query[DACI_MAX_QUERY_LENGTH] = { 0, }; + + snprintf(g_daci_query, sizeof(g_daci_query), "select count(*) from account_tbl"); + + dataCount = __get_data_count(daci_handler, g_daci_query, strlen(g_daci_query)); + *count = dataCount; + + if (dataCount != 0) { + /* query initialize */ + DACI_MEMORY_SET(g_daci_query); + + accountIdList = DACI_MEMORY_MALLOC(int *, sizeof(int), dataCount); + if (accountIdList == 0) { + FW_LOGE("memory_allocation failed"); + FW_LOGV("[%s] End !\n", __func__); + return accountIdList; + } + + snprintf(g_daci_query, sizeof(g_daci_query), "select account_id from account_tbl"); + + stmt = __query_prepare(daci_handler, g_daci_query, strlen(g_daci_query)); + if (stmt != 0) { + for (i = 0; i < dataCount; i++) { + if (__stmt_read_step(daci_handler, stmt) != DACI_ERR_MORE_DATA) + break; + + accountIdList[i] = __stmt_column_int(stmt, 0); + } + __stmt_finalize(daci_handler, stmt); + } + } + + FW_LOGV("[%s] End !\n", __func__); + + return accountIdList; +} + +char *get_accountEmailAddress(DACI_HANDLER *daci_handler, int accountId) +{ + FW_LOGV("[%s] Start !\n", __func__); + + daci_stmt stmt = 0; + char *query = "select email_address from account_tbl where account_id = ?"; + char *emailAddress = 0; + + stmt = __query_prepare(daci_handler, query, strlen(query)); + if (stmt != 0) { + __stmt_bind_int(daci_handler, stmt, 1, accountId); + + if (__stmt_read_step(daci_handler, stmt) == DACI_ERR_MORE_DATA) + emailAddress = __stmt_column_text(stmt, 0); + + __stmt_finalize(daci_handler, stmt); + } + + FW_LOGV("[%s] End !\n", __func__); + return emailAddress; +} + +char *get_accountPassword(DACI_HANDLER *daci_handler, int accountId) +{ + FW_LOGV("[%s] Start !\n", __func__); + + daci_stmt stmt = 0; + char *query = "select password from account_tbl where account_id = ?"; + char *password = 0; + + stmt = __query_prepare(daci_handler, query, strlen(query)); + if (stmt != 0) { + __stmt_bind_int(daci_handler, stmt, 1, accountId); + + if (__stmt_read_step(daci_handler, stmt) == DACI_ERR_MORE_DATA) + password = __stmt_column_text(stmt, 0); + + __stmt_finalize(daci_handler, stmt); + } + + FW_LOGV("[%s] End !\n", __func__); + return password; +} + +int isExist_account(DACI_HANDLER *daci_handler, int accountId) +{ + FW_LOGV("[%s] Start !\n", __func__); + + int ret = 1; + int dataCount = 0; + char g_daci_query[DACI_MAX_QUERY_LENGTH] = { 0, }; + + snprintf(g_daci_query, sizeof(g_daci_query), "select count(*) from account_tbl where account_id = %d", accountId); + + dataCount = __get_data_count(daci_handler, g_daci_query, strlen(g_daci_query)); + + if (dataCount == 0) + ret = 0; + + FW_LOGV("[%s] End !\n", __func__); + return ret; +} + +char *get_accessName(DACI_HANDLER *daci_handler, int accountId) +{ + FW_LOGV("[%s] Start !\n", __func__); + + daci_stmt stmt = 0; + char *query = "select access_name from account_tbl where account_id = ?"; + char *access_name = 0; + + stmt = __query_prepare(daci_handler, query, strlen(query)); + if (stmt != 0) { + __stmt_bind_int(daci_handler, stmt, 1, accountId); + + if (__stmt_read_step(daci_handler, stmt) == DACI_ERR_MORE_DATA) + access_name = __stmt_column_text(stmt, 0); + + __stmt_finalize(daci_handler, stmt); + } + + FW_LOGV("[%s] End !\n", __func__); + + return access_name; +} + +int *get_accountIdListByAccessName(DACI_HANDLER *daci_handler, char *access_name, int *accountId_count) +{ + FW_LOGV("[%s] Start !\n", __func__); + + daci_stmt stmt = 0; + int *accountIdList = 0; + int dataCount = 0; + int i = 0; + char g_daci_query[DACI_MAX_QUERY_LENGTH] = { 0, }; + + snprintf(g_daci_query, sizeof(g_daci_query), "select count(*) from account_tbl where access_name = \'%s\'", access_name); + + dataCount = __get_data_count(daci_handler, g_daci_query, strlen(g_daci_query)); + *accountId_count = dataCount; + + if (dataCount != 0) { + /* query initialize */ + DACI_MEMORY_SET(g_daci_query); + + accountIdList = DACI_MEMORY_MALLOC(int *, sizeof(int), dataCount); + if (accountIdList == 0) { + FW_LOGE("memory_allocation failed"); + FW_LOGV("[%s] End !\n", __func__); + return accountIdList; + } + + snprintf(g_daci_query, sizeof(g_daci_query), "select account_id from account_tbl where access_name = \'%s\'", access_name); + + stmt = __query_prepare(daci_handler, g_daci_query, strlen(g_daci_query)); + if (stmt != 0) { + for (i = 0; i < dataCount; i++) { + if (__stmt_read_step(daci_handler, stmt) != DACI_ERR_MORE_DATA) + break; + + accountIdList[i] = __stmt_column_int(stmt, 0); + } + __stmt_finalize(daci_handler, stmt); + } + } + + FW_LOGV("[%s] End !\n", __func__); + + return accountIdList; +} + +int get_accountCount(DACI_HANDLER *daci_handler) +{ + FW_LOGV("[%s] Start !\n", __func__); + + int dataCount = 0; + char g_daci_query[DACI_MAX_QUERY_LENGTH] = { 0, }; + + snprintf(g_daci_query, sizeof(g_daci_query), "select count(*) from account_tbl"); + + dataCount = __get_data_count(daci_handler, g_daci_query, strlen(g_daci_query)); + + FW_LOGV("[%s] End !\n", __func__); + return dataCount; +} + +DACI_RETURN add_folder(DACI_HANDLER *daci_handler, daci_folder *folder, int count) +{ + FW_LOGV("[%s] Start !\n", __func__); + + daci_stmt stmt = 0; + DACI_RETURN ret = DACI_SUCCESS; + int i = 0; + char *query = 0; + + for (i = 0; i < count; i++) { + if (isExist_folder(daci_handler, folder[i].account_id, folder[i].folder_id) == 1) + return DACI_ERR_PRIMARY_KEY_NOT_UNIQUE; + } + + query = "insert into folder_tbl (folder_id, data_store_id, account_id, folder_type_id, service_id, parent_folder_id, access_name) values (?, ?, ?, ?, ?, ?, ?)"; + + stmt = __query_prepare(daci_handler, query, strlen(query)); + if (stmt == 0) + return DACI_ERR_QUERY_FAILED; + + for (i = 0; i < count; i++) { + __stmt_bind_text(daci_handler, stmt, 1, folder[i].folder_id); + __stmt_bind_int(daci_handler, stmt, 2, folder[i].data_store_id); + __stmt_bind_int(daci_handler, stmt, 3, folder[i].account_id); + __stmt_bind_int(daci_handler, stmt, 4, folder[i].folder_type_id); + __stmt_bind_text(daci_handler, stmt, 5, folder[i].service_id); + __stmt_bind_text(daci_handler, stmt, 6, folder[i].parent_folder_id); + __stmt_bind_text(daci_handler, stmt, 7, folder[i].access_name); + + ret = __stmt_write_step(daci_handler, stmt); + if ((ret != DACI_ERR_MORE_DATA) && (ret != DACI_SUCCESS)) { + __stmt_finalize(daci_handler, stmt); + return DACI_ERR_QUERY_FAILED; + } + __stmt_reset(daci_handler, stmt); + } + __stmt_finalize(daci_handler, stmt); + + FW_LOGV("[%s] End !\n", __func__); + + return ret; +} + +DACI_RETURN delete_folderByFolderId(DACI_HANDLER *daci_handler, char *folderId) +{ + FW_LOGV("[%s] Start !\n", __func__); + + DACI_RETURN ret = DACI_SUCCESS; + daci_stmt stmt = 0; + char *query = "delete from folder_tbl where folder_id = ?"; + + stmt = __query_prepare(daci_handler, query, strlen(query)); + if (stmt == 0) + return DACI_ERR_QUERY_FAILED; + + __stmt_bind_text(daci_handler, stmt, 1, folderId); + + ret = __stmt_write_step(daci_handler, stmt); + __stmt_finalize(daci_handler, stmt); + + FW_LOGV("[%s] End !\n", __func__); + + return ret; +} + +char *get_folderFolderIdByServiceId(DACI_HANDLER *daci_handler, int accountId, int itemTypeId, char *serviceId, int folderTypeId) +{ + FW_LOGV("[%s] Start !\n", __func__); + + daci_stmt stmt = 0; + char *folderId = 0; + char g_daci_query[DACI_MAX_QUERY_LENGTH] = { 0, }; + + snprintf(g_daci_query, sizeof(g_daci_query), "select folder_id from folder_tbl where account_id = %d and data_store_id = %d and service_id = %s and folder_type_id = %d", accountId, itemTypeId, serviceId, folderTypeId); + + FW_LOGV("Query : %s", g_daci_query); + + stmt = __query_prepare(daci_handler, g_daci_query, strlen(g_daci_query)); + if (stmt != 0) { + if (__stmt_read_step(daci_handler, stmt) == DACI_ERR_MORE_DATA) + folderId = __stmt_column_text(stmt, 0); + + __stmt_finalize(daci_handler, stmt); + } + + FW_LOGV("[%s] End !\n", __func__); + return folderId; +} + +daci_id_list *get_folderFolderIdByFolderTypeId(DACI_HANDLER *daci_handler, int accountId, int itemTypeId, int folderTypeId) +{ + FW_LOGV("[%s] Start !\n", __func__); + + daci_stmt stmt = 0; + daci_id_list *folder_id_list = 0; + char g_daci_query[DACI_MAX_QUERY_LENGTH] = { 0, }; + + snprintf(g_daci_query, sizeof(g_daci_query), "select count(*) from folder_tbl where account_id = %d and folder_type_id = %d and data_store_id = %d", accountId, folderTypeId, itemTypeId); + + int data_count = __get_data_count(daci_handler, g_daci_query, strlen(g_daci_query)); + + if (data_count != 0) { + snprintf(g_daci_query, sizeof(g_daci_query), "select folder_id from folder_tbl where account_id = %d and folder_type_id = %d and data_store_id = %d", accountId, folderTypeId, itemTypeId); + + stmt = __query_prepare(daci_handler, g_daci_query, strlen(g_daci_query)); + if (stmt != 0) { + folder_id_list = (daci_id_list *)calloc(1, sizeof(daci_id_list)); + folder_id_list->id = (char **)calloc(data_count, sizeof(char *)); + folder_id_list->count = data_count; + int i = 0; + for (; i < data_count; i++) { + if (__stmt_read_step(daci_handler, stmt) != DACI_ERR_MORE_DATA) { + break; + } + + folder_id_list->id[i] = __stmt_column_text(stmt, 0); + } + __stmt_finalize(daci_handler, stmt); + } + } + + FW_LOGV("[%s] End !\n", __func__); + + return folder_id_list; +} + +char *get_folderServiceId(DACI_HANDLER *daci_handler, char *folderId) +{ + FW_LOGV("[%s] Start !\n", __func__); + + daci_stmt stmt = 0; + char *query = "select service_id from folder_tbl where folder_id = ?"; + char *serviceId = 0; + + stmt = __query_prepare(daci_handler, query, strlen(query)); + if (stmt != 0) { + __stmt_bind_text(daci_handler, stmt, 1, folderId); + + if (__stmt_read_step(daci_handler, stmt) == DACI_ERR_MORE_DATA) + serviceId = __stmt_column_text(stmt, 0); + + __stmt_finalize(daci_handler, stmt); + } + + FW_LOGV("[%s] End !\n", __func__); + return serviceId; +} + +daci_id_list *get_folderFolderIdListByItemTypeId(DACI_HANDLER *daci_handler, int accountId, int itemTypeId) +{ + FW_LOGV("[%s] Start !\n", __func__); + + daci_stmt stmt = 0; + daci_id_list *folder_id_list = 0; + char g_daci_query[DACI_MAX_QUERY_LENGTH] = { 0, }; + + snprintf(g_daci_query, sizeof(g_daci_query), "select count(*) from folder_tbl where account_id = %d and data_store_id = %d", accountId, itemTypeId); + + int data_count = __get_data_count(daci_handler, g_daci_query, strlen(g_daci_query)); + + if (data_count != 0) { + DACI_MEMORY_SET(g_daci_query); + + snprintf(g_daci_query, sizeof(g_daci_query), "select folder_id from folder_tbl where account_id = %d and data_store_id = %d", accountId, itemTypeId); + + stmt = __query_prepare(daci_handler, g_daci_query, strlen(g_daci_query)); + if (stmt != 0) { + folder_id_list = (daci_id_list *)calloc(1, sizeof(daci_id_list)); + folder_id_list->id = (char **)calloc(data_count, sizeof(char *)); + folder_id_list->count = data_count; + int i = 0; + for (; i < data_count; i++) { + if (__stmt_read_step(daci_handler, stmt) != DACI_ERR_MORE_DATA) { + break; + } + + folder_id_list->id[i] = __stmt_column_text(stmt, 0); + } + __stmt_finalize(daci_handler, stmt); + } + } + + FW_LOGV("[%s] End !\n", __func__); + + return folder_id_list; +} + +daci_folder *get_folderMappingServiceId(DACI_HANDLER *daci_handler, int accountId, char *folderId, int *count) +{ + FW_LOGV("[%s] Start !\n", __func__); + + daci_stmt stmt = 0; + daci_folder *folder = 0; + int dataCount = 0; + int i = 0; + char g_daci_query[DACI_MAX_QUERY_LENGTH] = { 0, }; + + snprintf(g_daci_query, sizeof(g_daci_query), "select count(*) from folder_tbl where folder_type_id in (select folder_type_id from folder_tbl where account_id = %d and folder_id = \'%s\') " "and (account_id != %d) and (account_id != %d) and data_store_id in (select data_store_id from folder_tbl where folder_id = \'%s\')", accountId, folderId, accountId, accountId, folderId); + + FW_LOGV("[RJW] %s", g_daci_query); + + dataCount = __get_data_count(daci_handler, g_daci_query, strlen(g_daci_query)); + *count = dataCount; + + if (dataCount != 0) { + /* query initialize */ + DACI_MEMORY_SET(g_daci_query); + + folder = DACI_MEMORY_MALLOC(daci_folder *, sizeof(daci_folder), dataCount); + if (folder == 0) { + FW_LOGE("memory_allocation failed"); + return folder; + } + + snprintf(g_daci_query, sizeof(g_daci_query), "select * from folder_tbl where folder_type_id in (select folder_type_id from folder_tbl where account_id = %d and folder_id = \'%s\') " "and (account_id != %d) and (account_id != %d) and data_store_id in (select data_store_id from folder_tbl where folder_id = \'%s\')", accountId, folderId, accountId, accountId, folderId); + + FW_LOGV("[RJW] %s", g_daci_query); + + stmt = __query_prepare(daci_handler, g_daci_query, strlen(g_daci_query)); + if (stmt != 0) { + for (i = 0; i < dataCount; i++) { + if (__stmt_read_step(daci_handler, stmt) != DACI_ERR_MORE_DATA) + break; + + folder[i].folder_id = __stmt_column_text(stmt, 0); + folder[i].data_store_id = __stmt_column_int(stmt, 1); + folder[i].account_id = __stmt_column_int(stmt, 2); + folder[i].folder_type_id = __stmt_column_int(stmt, 3); + folder[i].service_id = __stmt_column_text(stmt, 4); + folder[i].parent_folder_id = __stmt_column_text(stmt, 5); + folder[i].access_name = __stmt_column_text(stmt, 7); + } + __stmt_finalize(daci_handler, stmt); + } + } + + FW_LOGV("[%s] End !\n", __func__); + return folder; +} + +int isExist_folder(DACI_HANDLER *daci_handler, int accountId, char *folderId) +{ + FW_LOGV("[%s] Start !\n", __func__); + + int ret = 1; + int dataCount = 0; + char g_daci_query[DACI_MAX_QUERY_LENGTH] = { 0, }; + + snprintf(g_daci_query, sizeof(g_daci_query), "select count(*) from folder_tbl where account_id = %d and folder_id = \'%s\'", accountId, folderId); + + dataCount = __get_data_count(daci_handler, g_daci_query, strlen(g_daci_query)); + + if (dataCount == 0) + ret = 0; + + FW_LOGV("[%s] End !\n", __func__); + return ret; +} + +DACI_RETURN add_item(DACI_HANDLER *daci_handler, daci_item *item, int count) +{ + FW_LOGV("[%s] Start !\n", __func__); + + daci_stmt stmt = 0; + DACI_RETURN ret = DACI_SUCCESS; + + int i; + for (i = 0; i < count; i++) { + if (isExist_item(daci_handler, item[i].item_id) == 1) + return DACI_ERR_PRIMARY_KEY_NOT_UNIQUE; + } + + char *query = "insert into item_tbl (item_id, data_store_id, account_id, folder_id, service_id, access_name) values (?, ?, ?, ?, ?, ?)"; + + stmt = __query_prepare(daci_handler, query, strlen(query)); + if (stmt == 0) { + return DACI_ERR_QUERY_FAILED; + } + + for (i = 0; i < count; i++) { + __stmt_bind_text(daci_handler, stmt, 1, item[i].item_id); + __stmt_bind_int(daci_handler, stmt, 2, item[i].data_store_id); + __stmt_bind_int(daci_handler, stmt, 3, item[i].account_id); + __stmt_bind_text(daci_handler, stmt, 4, item[i].folder_id); + __stmt_bind_text(daci_handler, stmt, 5, item[i].service_id); + __stmt_bind_text(daci_handler, stmt, 6, item[i].access_name); + + ret = __stmt_write_step(daci_handler, stmt); + if ((ret != DACI_ERR_MORE_DATA) && (ret != DACI_SUCCESS)) { + __stmt_finalize(daci_handler, stmt); + return DACI_ERR_QUERY_FAILED; + } + __stmt_reset(daci_handler, stmt); + } + + __stmt_finalize(daci_handler, stmt); + + FW_LOGV("[%s] End !\n", __func__); + return ret; +} + +DACI_RETURN delete_itemByItemId(DACI_HANDLER *daci_handler, char *itemId) +{ + FW_LOGV("[%s] Start !\n", __func__); + + DACI_RETURN ret = DACI_SUCCESS; + daci_stmt stmt = 0; + char *query = "delete from item_tbl where item_id = ?"; + + stmt = __query_prepare(daci_handler, query, strlen(query)); + if (stmt == 0) + return DACI_ERR_QUERY_FAILED; + + __stmt_bind_text(daci_handler, stmt, 1, itemId); + + ret = __stmt_write_step(daci_handler, stmt); + __stmt_finalize(daci_handler, stmt); + + FW_LOGV("[%s] End !\n", __func__); + + return ret; +} + +DACI_RETURN delete_itemByItemTypeId(DACI_HANDLER *daci_handler, int accountId, int itemTypeId) +{ + FW_LOGV("[%s] Start !\n", __func__); + + DACI_RETURN ret = DACI_SUCCESS; + daci_stmt stmt = 0; + int i = 0; + int count = 0; + daci_item_info *itemInfo = 0; + char *query = "delete from item_tbl where account_id = ? and data_store_id = ?"; + + /* delete changelog */ + itemInfo = get_itemInfoByItemTypeId(daci_handler, accountId, itemTypeId, &count); + if (count != 0) { + for (i = 0; i < count; i++) { + ret = delete_itemChangelogByItemId(daci_handler, accountId, itemInfo[i].itemId); + if (ret != DACI_SUCCESS) + goto DACI_FINISH; + } + } + + stmt = __query_prepare(daci_handler, query, strlen(query)); + if (stmt == 0) + goto DACI_FINISH; + + __stmt_bind_int(daci_handler, stmt, 1, accountId); + __stmt_bind_int(daci_handler, stmt, 2, itemTypeId); + + ret = __stmt_write_step(daci_handler, stmt); + if (ret != DACI_SUCCESS) { + goto DACI_FINISH; + } + + DACI_Free_Memory_Item_Info(itemInfo, count); + return __stmt_finalize(daci_handler, stmt); + +DACI_FINISH: + + DACI_Free_Memory_Item_Info(itemInfo, count); + + if (stmt != 0) + __stmt_finalize(daci_handler, stmt); + + FW_LOGV("[%s] End !\n", __func__); + return DACI_ERR_QUERY_FAILED; + +} + +char *get_itemItemId(DACI_HANDLER *daci_handler, int accountId, char *serviceId, int itemTypeId) +{ + FW_LOGV("[%s] Start !\n", __func__); + + daci_stmt stmt = 0; + char *query = "select item_id from item_tbl where account_id = ? and service_id = ? and data_store_id = ?"; + char *itemId = 0; + + stmt = __query_prepare(daci_handler, query, strlen(query)); + if (stmt != 0) { + __stmt_bind_int(daci_handler, stmt, 1, accountId); + __stmt_bind_text(daci_handler, stmt, 2, serviceId); + __stmt_bind_int(daci_handler, stmt, 3, itemTypeId); + + if (__stmt_read_step(daci_handler, stmt) == DACI_ERR_MORE_DATA) + itemId = __stmt_column_text(stmt, 0); + + __stmt_finalize(daci_handler, stmt); + } + + FW_LOGV("[%s] End !\n", __func__); + return itemId; +} + +char *get_itemServiceId(DACI_HANDLER *daci_handler, char *itemId) +{ + FW_LOGV("[%s] Start !\n", __func__); + + daci_stmt stmt = 0; + char *query = "select service_id from item_tbl where item_id = ?"; + char *serviceId = 0; + + stmt = __query_prepare(daci_handler, query, strlen(query)); + if (stmt != 0) { + __stmt_bind_text(daci_handler, stmt, 1, itemId); + + if (__stmt_read_step(daci_handler, stmt) == DACI_ERR_MORE_DATA) + serviceId = __stmt_column_text(stmt, 0); + + __stmt_finalize(daci_handler, stmt); + } + + FW_LOGV("[%s] End !\n", __func__); + return serviceId; +} + +daci_item *get_item(DACI_HANDLER *daci_handler, char *itemId) +{ + FW_LOGV("[%s] Start !\n", __func__); + + daci_stmt stmt = 0; + char *query = "select * from item_tbl where item_id = ?"; + daci_item *item = 0; + + stmt = __query_prepare(daci_handler, query, strlen(query)); + if (stmt != 0) { + __stmt_bind_text(daci_handler, stmt, 1, itemId); + + if (__stmt_read_step(daci_handler, stmt) == DACI_ERR_MORE_DATA) { + item = DACI_MEMORY_MALLOC(daci_item *, sizeof(daci_item), 1); + if (item == 0) { + __stmt_finalize(daci_handler, stmt); + + FW_LOGE("memory_allocation failed"); + return item; + } + + item->item_id = __stmt_column_text(stmt, 0); + item->data_store_id = __stmt_column_int(stmt, 1); + item->account_id = __stmt_column_int(stmt, 2); + item->folder_id = __stmt_column_text(stmt, 3); + item->service_id = __stmt_column_text(stmt, 4); + item->access_name = __stmt_column_text(stmt, 6); + } + __stmt_finalize(daci_handler, stmt); + } + + FW_LOGV("[%s] End !\n", __func__); + + return item; +} + +daci_id_list *get_itemIdList(DACI_HANDLER *daci_handler, char *folderId, DACI_COLUMN_NAME columnName) +{ + FW_LOGV("[%s] Start !\n", __func__); + + DACI_RETURN ret = DACI_SUCCESS; + daci_id_list *idList = 0; + char *columnStr = 0; + char **result = 0; + int rowCount = 0; + int colCount = 0; + int index = 1; + int i = 0; + char g_daci_query[DACI_MAX_QUERY_LENGTH] = { 0, }; + + columnStr = __get_column_name(columnName); + + snprintf(g_daci_query, sizeof(g_daci_query), "select %s from item_tbl where folder_id = \'%s\'", columnStr, folderId); + + ret = __get_table(daci_handler, g_daci_query, &result, &rowCount, &colCount); + + if ((ret == DACI_SUCCESS) && (rowCount != 0) && (result != 0)) { + idList = DACI_MEMORY_MALLOC(daci_id_list *, sizeof(daci_id_list), 1); + if (idList == 0) { + FW_LOGE("memory_allocation failed"); + goto DACI_FINISH; + } + + idList->count = rowCount; + idList->id = DACI_MEMORY_CALLOC(char **, sizeof(char *), rowCount); + + for (i = 0; i < rowCount; i++) { + idList->id[i] = DACI_STRDUP(result[index]); + index++; + } + } + +DACI_FINISH: + + if (result != 0) + __free_table(result); + + FW_LOGV("[%s] End !\n", __func__); + return idList; +} + +daci_item *get_itemByAccountId(DACI_HANDLER *daci_handler, int accountId, int itemTypeId, int *count) +{ + FW_LOGV("[%s] Start !\n", __func__); + + daci_stmt stmt = 0; + daci_item *item = 0; + int dataCount = 0; + int i = 0; + char g_daci_query[DACI_MAX_QUERY_LENGTH] = { 0, }; + + snprintf(g_daci_query, sizeof(g_daci_query), "select count(*) from item_tbl where account_id = %d and data_store_id = %d", accountId, itemTypeId); + + dataCount = __get_data_count(daci_handler, g_daci_query, strlen(g_daci_query)); + *count = dataCount; + + if (dataCount != 0) { + /* query initialize */ + DACI_MEMORY_SET(g_daci_query); + + item = DACI_MEMORY_MALLOC(daci_item *, sizeof(daci_item), dataCount); + if (item == 0) { + FW_LOGE("memory_allocation failed"); + return item; + } + + snprintf(g_daci_query, sizeof(g_daci_query), "select * from item_tbl where account_id = %d and data_store_id = %d", accountId, itemTypeId); + + stmt = __query_prepare(daci_handler, g_daci_query, strlen(g_daci_query)); + if (stmt != 0) { + for (i = 0; i < dataCount; i++) { + if (__stmt_read_step(daci_handler, stmt) != DACI_ERR_MORE_DATA) { + break; + } + + item[i].item_id = __stmt_column_text(stmt, 0); + item[i].data_store_id = __stmt_column_int(stmt, 1); + item[i].account_id = __stmt_column_int(stmt, 2); + item[i].folder_id = __stmt_column_text(stmt, 3); + item[i].service_id = __stmt_column_text(stmt, 4); + item[i].access_name = __stmt_column_text(stmt, 6); + } + + __stmt_finalize(daci_handler, stmt); + } + } + + FW_LOGV("[%s] End !\n", __func__); + + return item; +} + +daci_item_info *get_itemInfoByItemTypeId(DACI_HANDLER *daci_handler, int accountId, int itemTypeId, int *count) +{ + FW_LOGV("[%s] Start !\n", __func__); + + DACI_RETURN ret = DACI_SUCCESS; + daci_item_info *itemInfo = 0; + char *newTable = 0; + char **result = 0; + int rowCount = 0; + int colCount = 0; + int i = 0; + int index = 5; + char g_daci_query[DACI_MAX_QUERY_LENGTH] = { 0, }; + + newTable = __replace_table_name("account_%d_item_changelog_tbl", accountId, 1); + if (newTable == 0) + return itemInfo; + snprintf(g_daci_query, sizeof(g_daci_query), "select item.item_id, item.data_store_id, item.service_id, changelog.operation_id, changelog.status " "from item_tbl as item " "join %s as changelog " "using (item_id) " "where item.account_id = %d and item.data_store_id = %d", newTable, accountId, itemTypeId); + + ret = __get_table(daci_handler, g_daci_query, &result, &rowCount, &colCount); + *count = rowCount; + if ((ret == DACI_SUCCESS) && (rowCount != 0) && (result != 0)) { + itemInfo = DACI_MEMORY_MALLOC(daci_item_info *, sizeof(daci_item_info), rowCount); + if (itemInfo == 0) { + FW_LOGE("memory_allocation failed"); + goto DACI_FINISH; + } + for (i = 0; i < rowCount; i++) { + itemInfo[i].itemId = DACI_STRDUP(result[index]); + index++; + itemInfo[i].itemTypeId = DACI_ATOI(result[index]); + index++; + itemInfo[i].serviceId = DACI_STRDUP(result[index]); + index++; + itemInfo[i].operationId = DACI_ATOI(result[index]); + index++; + itemInfo[i].syncStatus = DACI_STRDUP(result[index]); + index++; + } + } + +DACI_FINISH: + + if (result != 0) + __free_table(result); + + /* memory free */ + DACI_MEMORY_FREE(newTable); + + FW_LOGV("[%s] End !\n", __func__); + return itemInfo; +} + +daci_item *get_itemMappingServiceId(DACI_HANDLER *daci_handler, int accountId, char *itemId, int *count) +{ + FW_LOGV("[%s] Start !\n", __func__); + + daci_stmt stmt = 0; + daci_item *item = 0; + int dataCount = 0; + int i = 0; + char g_daci_query[DACI_MAX_QUERY_LENGTH] = { 0, }; + + snprintf(g_daci_query, sizeof(g_daci_query), "select count(*) from item_tbl where data_store_id in (select data_store_id from item_tbl where account_id = %d and item_id = \'%s\') " "and service_id in (select service_id from item_tbl where account_id = %d and item_id = \'%s\') " "and (account_id != %d and item_id != \'%s\')", accountId, itemId, accountId, itemId, accountId, itemId); + + dataCount = __get_data_count(daci_handler, g_daci_query, strlen(g_daci_query)); + *count = dataCount; + + if (dataCount != 0) { + /* query initialize */ + DACI_MEMORY_SET(g_daci_query); + + item = DACI_MEMORY_MALLOC(daci_item *, sizeof(daci_item), dataCount); + if (item == 0) { + FW_LOGE("memory_allocation failed"); + return item; + } + + snprintf(g_daci_query, sizeof(g_daci_query), "select * from item_tbl where data_store_id in (select data_store_id from item_tbl where account_id = %d and item_id = \'%s\') " "and service_id in (select service_id from item_tbl where account_id = %d and item_id = \'%s\') " "and (account_id != %d and item_id != \'%s\')", accountId, itemId, accountId, itemId, accountId, itemId); + + stmt = __query_prepare(daci_handler, g_daci_query, strlen(g_daci_query)); + if (stmt != 0) { + for (i = 0; i < dataCount; i++) { + if (__stmt_read_step(daci_handler, stmt) != DACI_ERR_MORE_DATA) + break; + + item[i].item_id = __stmt_column_text(stmt, 0); + item[i].data_store_id = __stmt_column_int(stmt, 1); + item[i].account_id = __stmt_column_int(stmt, 2); + item[i].folder_id = __stmt_column_text(stmt, 3); + item[i].service_id = __stmt_column_text(stmt, 4); + item[i].access_name = __stmt_column_text(stmt, 6); + } + + __stmt_finalize(daci_handler, stmt); + } + } + + FW_LOGV("[%s] End !\n", __func__); + return item; +} + +daci_id_list *get_itemIdListByDataStoreId(DACI_HANDLER *daci_handler, int data_store_id) +{ + FW_LOGV("[%s] Start !\n", __func__); + + daci_stmt stmt = 0; + daci_id_list *item_id_list = 0; + int dataCount = 0; + int i = 0; + char g_daci_query[DACI_MAX_QUERY_LENGTH] = { 0, }; + + snprintf(g_daci_query, sizeof(g_daci_query), "select count(*) from item_tbl where data_store_id = %d", data_store_id); + + dataCount = __get_data_count(daci_handler, g_daci_query, strlen(g_daci_query)); + + if (dataCount != 0) { + /* query initialize */ + DACI_MEMORY_SET(g_daci_query); + + item_id_list = (daci_id_list *)calloc(1, sizeof(daci_id_list)); + item_id_list->id = (char **)calloc(dataCount, sizeof(char *)); + item_id_list->count = dataCount; + + snprintf(g_daci_query, sizeof(g_daci_query), "select item_id from item_tbl where data_store_id = %d", data_store_id); + + stmt = __query_prepare(daci_handler, g_daci_query, strlen(g_daci_query)); + if (stmt != 0) { + for (i = 0; i < dataCount; i++) { + if (__stmt_read_step(daci_handler, stmt) != DACI_ERR_MORE_DATA) { + break; + } + + item_id_list->id[i] = __stmt_column_text(stmt, 0); + } + + __stmt_finalize(daci_handler, stmt); + } + } + + FW_LOGV("[%s] End !\n", __func__); + + return item_id_list; +} + +daci_id_list *get_itemIdListByDataStoreIdwithAccountId(DACI_HANDLER *daci_handler, int account_id, int data_store_id) +{ + FW_LOGV("[%s] Start !\n", __func__); + + daci_stmt stmt = 0; + daci_id_list *item_id_list = 0; + int dataCount = 0; + int i = 0; + char g_daci_query[DACI_MAX_QUERY_LENGTH] = { 0, }; + + snprintf(g_daci_query, sizeof(g_daci_query), "select count(*) from item_tbl where account_id = %d and data_store_id = %d", account_id, data_store_id); + + dataCount = __get_data_count(daci_handler, g_daci_query, strlen(g_daci_query)); + + if (dataCount != 0) { + /* query initialize */ + DACI_MEMORY_SET(g_daci_query); + + item_id_list = (daci_id_list *)calloc(1, sizeof(daci_id_list)); + item_id_list->id = (char **)calloc(dataCount, sizeof(char *)); + item_id_list->count = dataCount; + + snprintf(g_daci_query, sizeof(g_daci_query), "select item_id from item_tbl where account_id = %d and data_store_id = %d", account_id, data_store_id); + + stmt = __query_prepare(daci_handler, g_daci_query, strlen(g_daci_query)); + if (stmt != 0) { + for (i = 0; i < dataCount; i++) { + if (__stmt_read_step(daci_handler, stmt) != DACI_ERR_MORE_DATA) { + break; + } + + item_id_list->id[i] = __stmt_column_text(stmt, 0); + } + + __stmt_finalize(daci_handler, stmt); + } + } + + FW_LOGV("[%s] End !\n", __func__); + + return item_id_list; +} + +daci_id_list *get_ItemIdListByOperationId(DACI_HANDLER *daci_handler, int account_id, int data_store_id, int operation_id) +{ + FW_LOGV("[%s] Start !\n", __func__); + + DACI_RETURN ret = DACI_SUCCESS; + daci_id_list *id_list = 0; + char *new_table = 0; + char **result = 0; + int row_count = 0; + int col_count = 0; + int index = 1; + int i = 0; + char query[DACI_MAX_QUERY_LENGTH] = { 0, }; + + new_table = __replace_table_name("account_%d_item_changelog_tbl", account_id, 1); + if (new_table == 0) + return id_list; + + snprintf(query, sizeof(query), "select item.item_id " "from item_tbl as item " "join %s as changelog " "using (item_id) " "where item.account_id = %d and item.data_store_id = %d and changelog.operation_id = %d", new_table, account_id, data_store_id, operation_id); + + ret = __get_table(daci_handler, query, &result, &row_count, &col_count); + if ((ret == DACI_SUCCESS) && (row_count != 0) && (result != 0)) { + id_list = DACI_MEMORY_MALLOC(daci_id_list *, sizeof(daci_id_list), 1); + + if (id_list == 0) { + FW_LOGE("memory_allocation failed"); + goto DACI_FINISH; + } + + id_list->count = row_count; + id_list->id = DACI_MEMORY_CALLOC(char **, sizeof(char *), row_count); + + for (i = 0; i < row_count; i++) { + id_list->id[i] = DACI_STRDUP(result[index]); + index++; + } + } + +DACI_FINISH: + if (result != 0) { + __free_table(result); + } + /* memory free */ + DACI_MEMORY_FREE(new_table); + + FW_LOGV("[%s] End !\n", __func__); + + return id_list; +} + +int isExist_item(DACI_HANDLER *daci_handler, char *itemId) +{ + FW_LOGV("[%s] Start !\n", __func__); + + int ret = 1; + int dataCount = 0; + char g_daci_query[DACI_MAX_QUERY_LENGTH] = { 0, }; + + snprintf(g_daci_query, sizeof(g_daci_query), "select count(*) from item_tbl where item_id = \'%s\'", itemId); + + dataCount = __get_data_count(daci_handler, g_daci_query, strlen(g_daci_query)); + + if (dataCount == 0) + ret = 0; + + FW_LOGV("[%s] End !\n", __func__); + return ret; +} + +DACI_RETURN add_config(DACI_HANDLER *daci_handler, daci_config *config) +{ + FW_LOGV("[%s] Start !\n", __func__); + + daci_stmt stmt = 0; + DACI_RETURN ret = DACI_SUCCESS; + char *query = "insert into config_tbl (config_id, key, value, type, access_name) values (?, ?, ?, ?, ?)"; + + if (isExist_config(daci_handler, config->config_id, config->key) == 1) + return DACI_ERR_PRIMARY_KEY_NOT_UNIQUE; + + stmt = __query_prepare(daci_handler, query, strlen(query)); + if (stmt == 0) + return DACI_ERR_QUERY_FAILED; + + __stmt_bind_int(daci_handler, stmt, 1, config->config_id); + __stmt_bind_text(daci_handler, stmt, 2, config->key); + __stmt_bind_text(daci_handler, stmt, 3, config->value); + __stmt_bind_text(daci_handler, stmt, 4, config->type); + __stmt_bind_text(daci_handler, stmt, 5, config->access_name); + + ret = __stmt_write_step(daci_handler, stmt); + __stmt_finalize(daci_handler, stmt); + + FW_LOGV("[%s] End !\n", __func__); + return ret; +} + +DACI_RETURN delete_configByKey(DACI_HANDLER *daci_handler, int configId, char *key) +{ + FW_LOGV("[%s] Start !\n", __func__); + + DACI_RETURN ret = DACI_SUCCESS; + daci_stmt stmt = 0; + char *query = "delete from config_tbl where config_id = ? and key = ?"; + + stmt = __query_prepare(daci_handler, query, strlen(query)); + if (stmt == 0) + return DACI_ERR_QUERY_FAILED; + + __stmt_bind_int(daci_handler, stmt, 1, configId); + __stmt_bind_text(daci_handler, stmt, 2, key); + + ret = __stmt_write_step(daci_handler, stmt); + __stmt_finalize(daci_handler, stmt); + + FW_LOGV("[%s] End !\n", __func__); + return ret; +} + +daci_config *get_configByConfigId(DACI_HANDLER *daci_handler, int configId, int *count) +{ + FW_LOGV("[%s] Start !\n", __func__); + + daci_stmt stmt = 0; + daci_config *config = 0; + int dataCount = 0; + int i = 0; + char g_daci_query[DACI_MAX_QUERY_LENGTH] = { 0, }; + + snprintf(g_daci_query, sizeof(g_daci_query), "select count(*) from config_tbl where config_id = %d", configId); + + dataCount = __get_data_count(daci_handler, g_daci_query, strlen(g_daci_query)); + *count = dataCount; + + if (dataCount != 0) { + /* query initialize */ + DACI_MEMORY_SET(g_daci_query); + + config = DACI_MEMORY_MALLOC(daci_config *, sizeof(daci_config), dataCount); + if (config == 0) { + FW_LOGE("memory_allocation failed"); + return config; + } + + snprintf(g_daci_query, sizeof(g_daci_query), "select * from config_tbl where config_id = %d", configId); + + stmt = __query_prepare(daci_handler, g_daci_query, strlen(g_daci_query)); + if (stmt != 0) { + for (i = 0; i < dataCount; i++) { + if (__stmt_read_step(daci_handler, stmt) != DACI_ERR_MORE_DATA) + break; + + config[i].config_id = __stmt_column_int(stmt, 0); + config[i].key = __stmt_column_text(stmt, 1); + config[i].value = __stmt_column_text(stmt, 2); + config[i].type = __stmt_column_text(stmt, 3); + config[i].access_name = __stmt_column_text(stmt, 5); + } + __stmt_finalize(daci_handler, stmt); + } + } + + FW_LOGV("[%s] End !\n", __func__); + return config; +} + +DACI_RETURN get_configByKey(DACI_HANDLER *daci_handler, daci_config *config) +{ + FW_LOGV("[%s] Start !\n", __func__); + + int ret = DACI_SUCCESS; + daci_stmt stmt = 0; + char *query = "select value, type from config_tbl where config_id = ? and key =?"; + + stmt = __query_prepare(daci_handler, query, strlen(query)); + if (stmt == 0) { + return DACI_ERRORS; + } + + __stmt_bind_int(daci_handler, stmt, 1, config->config_id); + __stmt_bind_text(daci_handler, stmt, 2, config->key); + + if (__stmt_read_step(daci_handler, stmt) == DACI_ERR_MORE_DATA) { + config->value = __stmt_column_text(stmt, 0); + config->type = __stmt_column_text(stmt, 1); + config->access_name = 0; + } else { + ret = DACI_ERR_NO_DATA; + } + + __stmt_finalize(daci_handler, stmt); + + FW_LOGV("[%s] End !\n", __func__); + return ret; +} + +int isExist_config(DACI_HANDLER *daci_handler, int configId, char *key) +{ + FW_LOGV("[%s] Start !\n", __func__); + + int ret = 1; + int dataCount = 0; + char g_daci_query[DACI_MAX_QUERY_LENGTH] = { 0, }; + + snprintf(g_daci_query, sizeof(g_daci_query), "select count(*) from config_tbl where config_id = %d and key = \'%s\'", configId, key); + + dataCount = __get_data_count(daci_handler, g_daci_query, strlen(g_daci_query)); + + if (dataCount == 0) + ret = 0; + + FW_LOGV("[%s] End !\n", __func__); + return ret; +} + +DACI_RETURN update_config(DACI_HANDLER *daci_handler, daci_config *config, int count) +{ + FW_LOGV("[%s] Start !\n", __func__); + + DACI_RETURN ret = DACI_SUCCESS; + int i; + + for (i = 0; i < count; i++) { + if (isExist_config(daci_handler, config[i].config_id, config[i].key) == 1) + ret = set_configValue(daci_handler, &config[i]); + else + ret = add_config(daci_handler, &config[i]); + + if (ret != DACI_SUCCESS) + return DACI_ERR_QUERY_FAILED; + } + + FW_LOGV("[%s] End !\n", __func__); + return ret; +} + +DACI_RETURN set_configValue(DACI_HANDLER *daci_handler, daci_config *config) +{ + FW_LOGV("[%s] Start !\n", __func__); + + DACI_RETURN ret = DACI_SUCCESS; + + daci_stmt stmt = 0; + char *query = "update config_tbl set value = ?, type = ?, last_update = current_timestamp, access_name = ? " "where config_id = ? and key = ?"; + + stmt = __query_prepare(daci_handler, query, strlen(query)); + if (stmt == 0) + return DACI_ERR_QUERY_FAILED; + + __stmt_bind_text(daci_handler, stmt, 1, config->value); + __stmt_bind_text(daci_handler, stmt, 2, config->type); + __stmt_bind_text(daci_handler, stmt, 3, config->access_name); + __stmt_bind_int(daci_handler, stmt, 4, config->config_id); + __stmt_bind_text(daci_handler, stmt, 5, config->key); + + ret = __stmt_read_step(daci_handler, stmt); + __stmt_finalize(daci_handler, stmt); + + FW_LOGV("[%s] End !\n", __func__); + + return ret; +} + +DACI_RETURN add_itemChangelog(DACI_HANDLER *daci_handler, int accountId, daci_item_changelog *itemChangelog, int count) +{ + FW_LOGV("[%s] Start !\n", __func__); + + DACI_RETURN ret = DACI_SUCCESS; + daci_stmt stmt = 0; + int i = 0; + char *newTable = 0; + char g_daci_query[DACI_MAX_QUERY_LENGTH] = { 0, }; + + for (i = 0; i < count; i++) { + if (isExist_itemChangelog(daci_handler, accountId, itemChangelog[i].item_id) == 1) + return DACI_ERR_PRIMARY_KEY_NOT_UNIQUE; + } + + newTable = __replace_table_name("account_%d_item_changelog_tbl", accountId, 1); + if (newTable == 0) + return DACI_ERR_QUERY_FAILED; + + snprintf(g_daci_query, sizeof(g_daci_query), "insert into %s (item_id, operation_id, status, access_name) values (?, ?, ?, ?)", newTable); + + stmt = __query_prepare(daci_handler, g_daci_query, strlen(g_daci_query)); + if (stmt == 0) + return DACI_ERR_QUERY_FAILED; + + for (i = 0; i < count; i++) { + __stmt_bind_text(daci_handler, stmt, 1, itemChangelog[i].item_id); + __stmt_bind_int(daci_handler, stmt, 2, itemChangelog[i].operation_id); + __stmt_bind_text(daci_handler, stmt, 3, ((itemChangelog[i].status == 0) ? "SYNC_REQUIRED" : itemChangelog[i].status)); + __stmt_bind_text(daci_handler, stmt, 4, itemChangelog[i].access_name); + + ret = __stmt_write_step(daci_handler, stmt); + if ((ret != DACI_ERR_MORE_DATA) && (ret != DACI_SUCCESS)) { + __stmt_finalize(daci_handler, stmt); + return DACI_ERR_QUERY_FAILED; + } + __stmt_reset(daci_handler, stmt); + } + + ret = __stmt_finalize(daci_handler, stmt); + + /* memory free */ + DACI_MEMORY_FREE(newTable); + + FW_LOGV("[%s] End !\n", __func__); + return ret; +} + +DACI_RETURN delete_itemChangelogByItemId(DACI_HANDLER *daci_handler, int accountId, char *itemId) +{ + FW_LOGV("[%s] Start !\n", __func__); + + DACI_RETURN ret = DACI_SUCCESS; + daci_stmt stmt = 0; + char *newTable = 0; + char g_daci_query[DACI_MAX_QUERY_LENGTH] = { 0, }; + + newTable = __replace_table_name("account_%d_item_changelog_tbl", accountId, 1); + if (newTable == 0) + return DACI_ERR_QUERY_FAILED; + + snprintf(g_daci_query, sizeof(g_daci_query), "delete from %s where item_id = ?", newTable); + + stmt = __query_prepare(daci_handler, g_daci_query, strlen(g_daci_query)); + if (stmt == 0) + return DACI_ERR_QUERY_FAILED; + + __stmt_bind_text(daci_handler, stmt, 1, itemId); + + ret = __stmt_write_step(daci_handler, stmt); + __stmt_finalize(daci_handler, stmt); + + /* memory free */ + DACI_MEMORY_FREE(newTable); + + FW_LOGV("[%s] End !\n", __func__); + return ret; +} + +DACI_RETURN delete_itemChangelogByItemIdList(DACI_HANDLER *daci_handler, int accountId, char **itemIdList, int count) +{ + FW_LOGV("[%s] Start !\n", __func__); + + daci_stmt stmt = 0; + DACI_RETURN ret = DACI_SUCCESS; + char *newTable = 0; + int i; + char g_daci_query[DACI_MAX_QUERY_LENGTH] = { 0, }; + + newTable = __replace_table_name("account_%d_item_changelog_tbl", accountId, 1); + if (newTable == 0) + return DACI_ERR_QUERY_FAILED; + + snprintf(g_daci_query, sizeof(g_daci_query), "delete from %s where item_id = ?", newTable); + + stmt = __query_prepare(daci_handler, g_daci_query, strlen(g_daci_query)); + if (stmt == 0) + return DACI_ERR_QUERY_FAILED; + + for (i = 0; i < count; i++) { + __stmt_bind_text(daci_handler, stmt, 1, itemIdList[i]); + + ret = __stmt_write_step(daci_handler, stmt); + + if (ret != DACI_SUCCESS) { + __stmt_finalize(daci_handler, stmt); + return DACI_ERR_QUERY_FAILED; + } + __stmt_reset(daci_handler, stmt); + } + __stmt_finalize(daci_handler, stmt); + + /* memory free */ + DACI_MEMORY_FREE(newTable); + + FW_LOGV("[%s] End !\n", __func__); + return ret; +} + +DACI_RETURN delete_itemChangelogByItemTypeId(DACI_HANDLER *daci_handler, int accountId, int itemTypeId) +{ + FW_LOGV("[%s] Start !\n", __func__); + + DACI_RETURN ret = DACI_SUCCESS; + daci_stmt stmt = 0; + char *newTable = 0; + char g_daci_query[DACI_MAX_QUERY_LENGTH] = { 0, }; + + newTable = __replace_table_name("account_%d_item_changelog_tbl", accountId, 1); + if (newTable == 0) { + ret = DACI_ERR_QUERY_FAILED; + goto DACI_FINISH; + } + + snprintf(g_daci_query, sizeof(g_daci_query), "delete from %s " "where item_id in " "(select item_id " "from %s as changelog " "join item_tbl as item " "using (item_id) " "where item.account_id = %d and item.data_store_id = %d)", newTable, newTable, accountId, itemTypeId); + + stmt = __query_prepare(daci_handler, g_daci_query, strlen(g_daci_query)); + if (stmt == 0) { + ret = DACI_ERR_QUERY_FAILED; + goto DACI_FINISH; + } + + ret = __stmt_write_step(daci_handler, stmt); + if (ret != DACI_SUCCESS) { + ret = DACI_ERR_QUERY_FAILED; + goto DACI_FINISH; + } + +DACI_FINISH: + + if (stmt != 0) + __stmt_finalize(daci_handler, stmt); + + /* memory free */ + DACI_MEMORY_FREE(newTable); + + FW_LOGV("[%s] End !\n", __func__); + return ret; +} + +DACI_RETURN set_itemChangelogOperationId(DACI_HANDLER *daci_handler, int accountId, daci_item_changelog *itemChangelog) +{ + FW_LOGV("[%s] Start !\n", __func__); + + DACI_RETURN ret = DACI_SUCCESS; + daci_stmt stmt = 0; + char *newTable = 0; + char g_daci_query[DACI_MAX_QUERY_LENGTH] = { 0, }; + + newTable = __replace_table_name("account_%d_item_changelog_tbl", accountId, 1); + if (newTable == 0) + return DACI_ERR_QUERY_FAILED; + + snprintf(g_daci_query, sizeof(g_daci_query), "update %s set operation_id = ?, status = ?, last_update = current_timestamp, access_name = ? where item_id = ?", newTable); + + stmt = __query_prepare(daci_handler, g_daci_query, strlen(g_daci_query)); + if (stmt == 0) + return DACI_ERR_QUERY_FAILED; + + __stmt_bind_int(daci_handler, stmt, 1, itemChangelog->operation_id); + __stmt_bind_text(daci_handler, stmt, 2, itemChangelog->status); + __stmt_bind_text(daci_handler, stmt, 3, itemChangelog->access_name); + __stmt_bind_text(daci_handler, stmt, 4, itemChangelog->item_id); + + ret = __stmt_write_step(daci_handler, stmt); + __stmt_finalize(daci_handler, stmt); + + /* memory free */ + DACI_MEMORY_FREE(newTable); + + FW_LOGV("[%s] End !\n", __func__); + return ret; +} + +DACI_RETURN set_itemChangelogSyncStatus(DACI_HANDLER *daci_handler, int accountId, daci_item_changelog *itemChangelog) +{ + FW_LOGV("[%s] Start !\n", __func__); + + DACI_RETURN ret = DACI_SUCCESS; + daci_stmt stmt = 0; + char *newTable = 0; + char g_daci_query[DACI_MAX_QUERY_LENGTH] = { 0, }; + + newTable = __replace_table_name("account_%d_item_changelog_tbl", accountId, 1); + if (newTable == 0) + return DACI_ERR_QUERY_FAILED; + + snprintf(g_daci_query, sizeof(g_daci_query), "update %s set status = ?, last_update = current_timestamp, access_name = ? where item_id = ?", newTable); + + stmt = __query_prepare(daci_handler, g_daci_query, strlen(g_daci_query)); + if (stmt == 0) + return DACI_ERR_QUERY_FAILED; + + __stmt_bind_text(daci_handler, stmt, 1, itemChangelog->status); + __stmt_bind_text(daci_handler, stmt, 2, itemChangelog->access_name); + __stmt_bind_text(daci_handler, stmt, 3, itemChangelog->item_id); + + ret = __stmt_write_step(daci_handler, stmt); + __stmt_finalize(daci_handler, stmt); + + /* memory free */ + DACI_MEMORY_FREE(newTable); + + FW_LOGV("[%s] End !\n", __func__); + return ret; +} + +DACI_RETURN set_itemChangelogWaitStatus(DACI_HANDLER *daci_handler, int accountId, char **folderIdList, int folderIdCount, int *itemTypeIdList, int itemTypeIdCount) +{ + FW_LOGV("[%s] Start !\n", __func__); + + DACI_RETURN ret = DACI_SUCCESS; + daci_stmt stmt = 0; + char *newTable = 0; + char tempStr[10]; + int i = 0; + char g_daci_query[DACI_MAX_QUERY_LENGTH] = { 0, }; + + newTable = __replace_table_name("account_%d_item_changelog_tbl", accountId, 1); + if (newTable == 0) + return DACI_ERR_QUERY_FAILED; + + snprintf(g_daci_query, sizeof(g_daci_query), "update %s " "set status = \'SYNC_WAIT\' " "where item_id in (select item_id " "from item_tbl as item " "join %s as changelog " "using(item_id) " "where item.account_id = %d and (", newTable, newTable, accountId); + + for (i = 0; i < folderIdCount; i++) { + strcat(g_daci_query, "item.folder_id = \'"); + strcat(g_daci_query, folderIdList[i]); + + if (i < folderIdCount - 1) + strcat(g_daci_query, "\' or "); + else + strcat(g_daci_query, "\') and ("); + } + + for (i = 0; i < itemTypeIdCount; i++) { + memset(tempStr, 0x00, sizeof(tempStr)); + snprintf(tempStr, sizeof(tempStr), "%d", itemTypeIdList[i]); + + strcat(g_daci_query, "item.data_store_id = "); + strcat(g_daci_query, tempStr); + + if (i < itemTypeIdCount - 1) + strcat(g_daci_query, " or "); + else + strcat(g_daci_query, ") )"); + } + + stmt = __query_prepare(daci_handler, g_daci_query, strlen(g_daci_query)); + if (stmt == 0) + return DACI_ERR_QUERY_FAILED; + + ret = __stmt_write_step(daci_handler, stmt); + __stmt_finalize(daci_handler, stmt); + + /* memory free */ + DACI_MEMORY_FREE(newTable); + + FW_LOGV("[%s] End !\n", __func__); + return ret; +} + +DACI_RETURN get_itemChangelogByItemId(DACI_HANDLER *daci_handler, int accountId, daci_item_changelog *itemChangelog) +{ + FW_LOGV("[%s] Start !\n", __func__); + + DACI_RETURN ret = DACI_ERR_QUERY_FAILED; + daci_stmt stmt = 0; + char *newTable = 0; + char g_daci_query[DACI_MAX_QUERY_LENGTH] = { 0, }; + + newTable = __replace_table_name("account_%d_item_changelog_tbl", accountId, 1); + if (newTable == 0) + return ret; + + snprintf(g_daci_query, sizeof(g_daci_query), "select * from %s where item_id = \'%s\'", newTable, itemChangelog->item_id); + + stmt = __query_prepare(daci_handler, g_daci_query, strlen(g_daci_query)); + if (stmt != 0) { + if (__stmt_read_step(daci_handler, stmt) == DACI_ERR_MORE_DATA) { + itemChangelog->operation_id = __stmt_column_int(stmt, 1); + itemChangelog->status = __stmt_column_text(stmt, 2); + itemChangelog->access_name = __stmt_column_text(stmt, 4); + ret = DACI_SUCCESS; + } else if (__stmt_read_step(daci_handler, stmt) == DACI_SUCCESS) { + ret = DACI_ERR_NO_DATA; + } + __stmt_finalize(daci_handler, stmt); + } + + /* memory free */ + DACI_MEMORY_FREE(newTable); + + return ret; + FW_LOGV("[%s] End !\n", __func__); +} + +daci_item_changelog *get_itemChangelogByOperationId(DACI_HANDLER *daci_handler, int accountId, int operationId, int *count) +{ + FW_LOGV("[%s] Start !\n", __func__); + + daci_stmt stmt = 0; + daci_item_changelog *itemChangelog = 0; + char *newTable = 0; + int dataCount = 0; + int i = 0; + char g_daci_query[DACI_MAX_QUERY_LENGTH] = { 0, }; + + newTable = __replace_table_name("account_%d_item_changelog_tbl", accountId, 1); + if (newTable == 0) + return itemChangelog; + + snprintf(g_daci_query, sizeof(g_daci_query), "select count(*) from %s where operation_id = %d", newTable, operationId); + + dataCount = __get_data_count(daci_handler, g_daci_query, strlen(g_daci_query)); + *count = dataCount; + + if (dataCount != 0) { + /* query initialize */ + DACI_MEMORY_SET(g_daci_query); + + itemChangelog = DACI_MEMORY_MALLOC(daci_item_changelog *, sizeof(daci_item_changelog), dataCount); + if (itemChangelog == 0) { + FW_LOGE("memory_allocation failed"); + + /* memory free */ + DACI_MEMORY_FREE(newTable); + + return itemChangelog; + } + + snprintf(g_daci_query, sizeof(g_daci_query), "select * from %s where operation_id = %d", newTable, operationId); + + stmt = __query_prepare(daci_handler, g_daci_query, strlen(g_daci_query)); + if (stmt != 0) { + for (i = 0; i < dataCount; i++) { + if (__stmt_read_step(daci_handler, stmt) != DACI_ERR_MORE_DATA) + break; + + itemChangelog[i].item_id = __stmt_column_text(stmt, 0); + itemChangelog[i].operation_id = __stmt_column_int(stmt, 1); + itemChangelog[i].status = __stmt_column_text(stmt, 2); + itemChangelog[i].access_name = __stmt_column_text(stmt, 4); + } + __stmt_finalize(daci_handler, stmt); + } + } + + /* memory free */ + DACI_MEMORY_FREE(newTable); + + FW_LOGV("[%s] End !\n", __func__); + return itemChangelog; +} + +int isExist_itemChangelog(DACI_HANDLER *daci_handler, int accountId, char *itemId) +{ + FW_LOGV("[%s] Start !\n", __func__); + + int ret = 1; + char *newTable = 0; + int dataCount = 0; + char g_daci_query[DACI_MAX_QUERY_LENGTH] = { 0, }; + + newTable = __replace_table_name("account_%d_item_changelog_tbl", accountId, 1); + if (newTable == 0) + return 0; + + snprintf(g_daci_query, sizeof(g_daci_query), "select count(*) from %s where item_id = \'%s\'", newTable, itemId); + + dataCount = __get_data_count(daci_handler, g_daci_query, strlen(g_daci_query)); + + if (dataCount == 0) + ret = 0; + + /* memory free */ + DACI_MEMORY_FREE(newTable); + + FW_LOGV("[%s] End !\n", __func__); + return ret; +} + +DACI_RETURN add_lastAnchor(DACI_HANDLER *daci_handler, daci_last_anchor *lastAnchor) +{ + FW_LOGV("[%s] Start !\n", __func__); + + DACI_RETURN ret = DACI_SUCCESS; + daci_stmt stmt = 0; + char *query = 0; + + if (isExist_lastAnchor(daci_handler, lastAnchor->account_id, lastAnchor->data_store_id) == 1) + return DACI_ERR_PRIMARY_KEY_NOT_UNIQUE; + + query = "insert into last_anchor_tbl (account_id, data_store_id, last_anchor_server, last_anchor_client, access_name) values (?, ?, ?, ?, ?)"; + + stmt = __query_prepare(daci_handler, query, strlen(query)); + if (stmt == 0) + return DACI_ERR_QUERY_FAILED; + + __stmt_bind_int(daci_handler, stmt, 1, lastAnchor->account_id); + __stmt_bind_int(daci_handler, stmt, 2, lastAnchor->data_store_id); + __stmt_bind_text(daci_handler, stmt, 3, lastAnchor->last_anchor_server); + __stmt_bind_text(daci_handler, stmt, 4, lastAnchor->last_anchor_client); + __stmt_bind_text(daci_handler, stmt, 5, lastAnchor->access_name); + + ret = __stmt_write_step(daci_handler, stmt); + __stmt_finalize(daci_handler, stmt); + + FW_LOGV("[%s] End !\n", __func__); + return ret; +} + +DACI_RETURN delete_lastAnchorByAccountId(DACI_HANDLER *daci_handler, int accountId) +{ + FW_LOGV("[%s] Start !\n", __func__); + + DACI_RETURN ret = __delete_account(daci_handler, TABLE_NAME_LAST_ANCHOR, accountId); + if (ret != DACI_SUCCESS) + return DACI_ERR_QUERY_FAILED; + + FW_LOGV("[%s] End !\n", __func__); + return ret; +} + +DACI_RETURN delete_lastAnchorByItemTypeId(DACI_HANDLER *daci_handler, int accountId, int itemTypeId) +{ + FW_LOGV("[%s] Start !\n", __func__); + + DACI_RETURN ret = DACI_SUCCESS; + daci_stmt stmt = 0; + char *query = "delete from last_anchor_tbl where account_id = ? and data_store_id = ?"; + + stmt = __query_prepare(daci_handler, query, strlen(query)); + if (stmt == 0) + return DACI_ERR_QUERY_FAILED; + + __stmt_bind_int(daci_handler, stmt, 1, accountId); + __stmt_bind_int(daci_handler, stmt, 2, itemTypeId); + + ret = __stmt_write_step(daci_handler, stmt); + __stmt_finalize(daci_handler, stmt); + + FW_LOGV("[%s] End !\n", __func__); + return ret; +} + +DACI_RETURN set_lastAnchor(DACI_HANDLER *daci_handler, daci_last_anchor *lastAnchor) +{ + FW_LOGV("[%s] Start !\n", __func__); + + DACI_RETURN ret = DACI_SUCCESS; + daci_stmt stmt = 0; + char *query = "update last_anchor_tbl set last_anchor_server = ?, last_anchor_client = ?, last_update = current_timestamp, access_name = ?" "where account_id = ? and data_store_id = ?"; + + stmt = __query_prepare(daci_handler, query, strlen(query)); + if (stmt == 0) + return DACI_ERR_QUERY_FAILED; + + __stmt_bind_text(daci_handler, stmt, 1, lastAnchor->last_anchor_server); + __stmt_bind_text(daci_handler, stmt, 2, lastAnchor->last_anchor_client); + __stmt_bind_text(daci_handler, stmt, 3, lastAnchor->access_name); + __stmt_bind_int(daci_handler, stmt, 4, lastAnchor->account_id); + __stmt_bind_int(daci_handler, stmt, 5, lastAnchor->data_store_id); + + ret = __stmt_write_step(daci_handler, stmt); + __stmt_finalize(daci_handler, stmt); + + FW_LOGV("[%s] End !\n", __func__); + return ret; +} + +daci_last_anchor *get_lastAnchorByAccountId(DACI_HANDLER *daci_handler, int accountId, int *count) +{ + FW_LOGV("[%s] Start !\n", __func__); + + DACI_RETURN ret = DACI_SUCCESS; + daci_last_anchor *lastAnchor = 0; + char **result = 0; + int rowCount = 0; + int colCount = 0; + int i = 0; + int index = 4; + char g_daci_query[DACI_MAX_QUERY_LENGTH] = { 0, }; + + snprintf(g_daci_query, sizeof(g_daci_query), "select account_id, data_store_id, last_anchor_server, last_anchor_client from last_anchor_tbl where account_id = %d", accountId); + + ret = __get_table(daci_handler, g_daci_query, &result, &rowCount, &colCount); + *count = rowCount; + + if ((ret == DACI_SUCCESS) && (rowCount != 0) && (result != 0)) { + lastAnchor = DACI_MEMORY_MALLOC(daci_last_anchor *, sizeof(daci_last_anchor), rowCount); + if (lastAnchor == 0) { + FW_LOGE("memory_allocation failed"); + goto DACI_FINISH; + } + + for (i = 0; i < rowCount; i++) { + lastAnchor[i].account_id = DACI_ATOI(result[index]); + index++; + lastAnchor[i].data_store_id = DACI_ATOI(result[index]); + index++; + lastAnchor[i].last_anchor_server = DACI_STRDUP(result[index]); + index++; + lastAnchor[i].last_anchor_client = DACI_STRDUP(result[index]); + index++; + lastAnchor[i].access_name = 0; + } + } + +DACI_FINISH: + + if (result != 0) + __free_table(result); + + FW_LOGV("[%s] End !\n", __func__); + + return lastAnchor; +} + +daci_last_anchor *get_lastAnchorByItemTypeId(DACI_HANDLER *daci_handler, int accountId, int itemTypeId, int *count) +{ + FW_LOGV("[%s] Start !\n", __func__); + + DACI_RETURN ret = DACI_SUCCESS; + daci_last_anchor *lastAnchor = 0; + char **result = 0; + int rowCount = 0; + int colCount = 0; + int i = 0; + int index = 4; + char g_daci_query[DACI_MAX_QUERY_LENGTH] = { 0, }; + + snprintf(g_daci_query, sizeof(g_daci_query), "select account_id, data_store_id, last_anchor_server, last_anchor_client from last_anchor_tbl where account_id = %d and data_store_id = %d", accountId, itemTypeId); + + ret = __get_table(daci_handler, g_daci_query, &result, &rowCount, &colCount); + *count = rowCount; + + if ((ret == DACI_SUCCESS) && (rowCount != 0) && (result != 0)) { + lastAnchor = DACI_MEMORY_MALLOC(daci_last_anchor *, sizeof(daci_last_anchor), rowCount); + if (lastAnchor == 0) { + FW_LOGE("memory_allocation failed"); + goto DACI_FINISH; + } + + for (i = 0; i < rowCount; i++) { + lastAnchor[i].account_id = DACI_ATOI(result[index]); + index++; + lastAnchor[i].data_store_id = DACI_ATOI(result[index]); + index++; + lastAnchor[i].last_anchor_server = DACI_STRDUP(result[index]); + index++; + lastAnchor[i].last_anchor_client = DACI_STRDUP(result[index]); + index++; + lastAnchor[i].access_name = 0; + } + } + +DACI_FINISH: + + if (result != 0) + __free_table(result); + + FW_LOGV("[%s] End !\n", __func__); + + return lastAnchor; +} + +int isExist_lastAnchor(DACI_HANDLER *daci_handler, int accountId, int itemTypeId) +{ + FW_LOGV("[%s] Start !\n", __func__); + + int ret = 1; + int dataCount = 0; + char g_daci_query[DACI_MAX_QUERY_LENGTH] = { 0, }; + + snprintf(g_daci_query, sizeof(g_daci_query), "select count(*) from last_anchor_tbl where account_id = %d and data_store_id = %d", accountId, itemTypeId); + + dataCount = __get_data_count(daci_handler, g_daci_query, strlen(g_daci_query)); + + if (dataCount == 0) + ret = 0; + + FW_LOGV("[%s] End !\n", __func__); + return ret; +} + +DACI_RETURN add_mapping(DACI_HANDLER *daci_handler, daci_mapping *mapping) +{ + FW_LOGV("[%s] Start !\n", __func__); + + DACI_RETURN ret = DACI_SUCCESS; + daci_stmt stmt = 0; + char *query = 0; + + if (isExist_mappingByLuid(daci_handler, mapping->account_id, mapping->luid) == 1) + return DACI_ERR_PRIMARY_KEY_NOT_UNIQUE; + + query = "insert into mapping_tbl (account_id, data_store_id, luid, guid, access_name) values (?, ?, ?, ?, ?)"; + + stmt = __query_prepare(daci_handler, query, strlen(query)); + if (stmt == 0) + return DACI_ERR_QUERY_FAILED; + + __stmt_bind_int(daci_handler, stmt, 1, mapping->account_id); + __stmt_bind_int(daci_handler, stmt, 2, mapping->data_store_id); + __stmt_bind_text(daci_handler, stmt, 3, mapping->luid); + __stmt_bind_text(daci_handler, stmt, 4, mapping->guid); + __stmt_bind_text(daci_handler, stmt, 5, mapping->access_name); + + ret = __stmt_write_step(daci_handler, stmt); + __stmt_finalize(daci_handler, stmt); + + FW_LOGV("[%s] End !\n", __func__); + return ret; +} + +DACI_RETURN delete_mappingByAccountId(DACI_HANDLER *daci_handler, int accountId) +{ + FW_LOGV("[%s] Start !\n", __func__); + + DACI_RETURN ret = __delete_account(daci_handler, TABLE_NAME_MAPPING, accountId); + if (ret != DACI_SUCCESS) + return DACI_ERR_QUERY_FAILED; + + FW_LOGV("[%s] End !\n", __func__); + return ret; +} + +DACI_RETURN delete_mappingByLuid(DACI_HANDLER *daci_handler, int accountId, char *luid) +{ + FW_LOGV("[%s] Start !\n", __func__); + + DACI_RETURN ret = DACI_SUCCESS; + daci_stmt stmt = 0; + char *query = "delete from mapping_tbl where account_id = ? and luid = ?"; + + stmt = __query_prepare(daci_handler, query, strlen(query)); + if (stmt == 0) + return DACI_ERR_QUERY_FAILED; + + __stmt_bind_int(daci_handler, stmt, 1, accountId); + __stmt_bind_text(daci_handler, stmt, 2, luid); + + ret = __stmt_write_step(daci_handler, stmt); + __stmt_finalize(daci_handler, stmt); + + FW_LOGV("[%s] End !\n", __func__); + return ret; +} + +daci_mapping *get_mappingByAccountId(DACI_HANDLER *daci_handler, int accountId, int *count) +{ + FW_LOGV("[%s] Start !\n", __func__); + + daci_stmt stmt = 0; + daci_mapping *mapping = 0; + int dataCount = 0; + int i = 0; + char g_daci_query[DACI_MAX_QUERY_LENGTH] = { 0, }; + + snprintf(g_daci_query, sizeof(g_daci_query), "select count(*) from mapping_tbl where account_id = %d", accountId); + + dataCount = __get_data_count(daci_handler, g_daci_query, strlen(g_daci_query)); + *count = dataCount; + + if (dataCount != 0) { + /* query initialize */ + DACI_MEMORY_SET(g_daci_query); + + mapping = DACI_MEMORY_MALLOC(daci_mapping *, sizeof(daci_mapping), dataCount); + if (mapping == 0) { + FW_LOGE("memory_allocation failed"); + return mapping; + } + + snprintf(g_daci_query, sizeof(g_daci_query), "select * from mapping_tbl where account_id = %d", accountId); + + stmt = __query_prepare(daci_handler, g_daci_query, strlen(g_daci_query)); + if (stmt != 0) { + for (i = 0; i < dataCount; i++) { + if (__stmt_read_step(daci_handler, stmt) != DACI_ERR_MORE_DATA) + break; + + mapping[i].account_id = __stmt_column_int(stmt, 0); + mapping[i].data_store_id = __stmt_column_int(stmt, 1); + mapping[i].luid = __stmt_column_text(stmt, 2); + mapping[i].guid = __stmt_column_text(stmt, 3); + mapping[i].access_name = __stmt_column_text(stmt, 5); + } + __stmt_finalize(daci_handler, stmt); + } + } + + FW_LOGV("[%s] End !\n", __func__); + return mapping; +} + +char *get_mappingGuid(DACI_HANDLER *daci_handler, int accountId, char *luid) +{ + FW_LOGV("[%s] Start !\n", __func__); + + daci_stmt stmt = 0; + char *query = "select guid from mapping_tbl where account_id = ? and luid = ?"; + char *guid = 0; + + stmt = __query_prepare(daci_handler, query, strlen(query)); + if (stmt != 0) { + __stmt_bind_int(daci_handler, stmt, 1, accountId); + __stmt_bind_text(daci_handler, stmt, 2, luid); + + if (__stmt_read_step(daci_handler, stmt) == DACI_ERR_MORE_DATA) + guid = __stmt_column_text(stmt, 0); + + __stmt_finalize(daci_handler, stmt); + } + + FW_LOGV("[%s] End !\n", __func__); + return guid; +} + +int isExist_mappingByAccountId(DACI_HANDLER *daci_handler, int accountId) +{ + FW_LOGV("[%s] Start !\n", __func__); + + int ret = 1; + int dataCount = 0; + char g_daci_query[DACI_MAX_QUERY_LENGTH] = { 0, }; + + snprintf(g_daci_query, sizeof(g_daci_query), "select count(*) from mapping_tbl where account_id = %d", accountId); + + dataCount = __get_data_count(daci_handler, g_daci_query, strlen(g_daci_query)); + + if (dataCount == 0) + ret = 0; + + FW_LOGV("[%s] End !\n", __func__); + return ret; +} + +int isExist_mappingByLuid(DACI_HANDLER *daci_handler, int accountId, char *luid) +{ + FW_LOGV("[%s] Start !\n", __func__); + + int ret = 1; + int dataCount = 0; + char g_daci_query[DACI_MAX_QUERY_LENGTH] = { 0, }; + + snprintf(g_daci_query, sizeof(g_daci_query), "select count(*) from mapping_tbl where account_id = %d and luid = \'%s\'", accountId, luid); + + dataCount = __get_data_count(daci_handler, g_daci_query, strlen(g_daci_query)); + + if (dataCount == 0) + ret = 0; + + FW_LOGV("[%s] End !\n", __func__); + return ret; +} + +DACI_RETURN add_id_provider(DACI_HANDLER *daci_handler, daci_id_provider *id_provider) +{ + FW_LOGV("[%s] Start !\n", __func__); + + daci_stmt stmt = 0; + DACI_RETURN ret = DACI_SUCCESS; + char *query = 0; + + query = "insert into id_provider_tbl (id_provider_code, id_capacity, bit_per_page, last_id, free_bit_cnt) values (?, ?, ?, ?, ?)"; + + stmt = __query_prepare(daci_handler, query, strlen(query)); + if (stmt == 0) { + return DACI_ERR_QUERY_FAILED; + } + + __stmt_bind_int(daci_handler, stmt, 1, id_provider->id_provider_code); + __stmt_bind_int(daci_handler, stmt, 2, id_provider->id_capacity); + __stmt_bind_int(daci_handler, stmt, 3, id_provider->bit_per_page); + __stmt_bind_int(daci_handler, stmt, 4, id_provider->last_id); + __stmt_bind_int(daci_handler, stmt, 5, id_provider->free_bit_cnt); + + ret = __stmt_write_step(daci_handler, stmt); + if (ret != DACI_SUCCESS) { + __stmt_finalize(daci_handler, stmt); + return DACI_ERR_QUERY_FAILED; + } + + __stmt_finalize(daci_handler, stmt); + + FW_LOGV("[%s] End !\n", __func__); + return ret; +} + +DACI_RETURN get_id_provider(DACI_HANDLER *daci_handler, unsigned int id_provider_code, daci_id_provider **id_provider) +{ + FW_LOGV("[%s] Start !\n", __func__); + + int ret = DACI_SUCCESS; + daci_stmt stmt = 0; + char *query = "select id_capacity, bit_per_page, last_id, free_bit_cnt from id_provider_tbl where id_provider_code = ?"; + + stmt = __query_prepare(daci_handler, query, strlen(query)); + if (stmt != 0) { + __stmt_bind_int(daci_handler, stmt, 1, id_provider_code); + + if (__stmt_read_step(daci_handler, stmt) == DACI_ERR_MORE_DATA) { + *id_provider = (daci_id_provider *)calloc(1, sizeof(daci_id_provider)); + (*id_provider)->id_capacity = __stmt_column_int(stmt, 0); + (*id_provider)->bit_per_page = __stmt_column_int(stmt, 1); + (*id_provider)->last_id = __stmt_column_int(stmt, 2); + (*id_provider)->free_bit_cnt = __stmt_column_int(stmt, 3); + } else { + ret = DACI_ERR_NO_DATA; + } + __stmt_finalize(daci_handler, stmt); + } + + FW_LOGV("[%s] End !\n", __func__); + return ret; +} + +DACI_RETURN update_id_provider(DACI_HANDLER *daci_handler, daci_id_provider *id_provider) +{ + FW_LOGV("[%s] Start !\n", __func__); + + DACI_RETURN ret = DACI_SUCCESS; + daci_stmt stmt = 0; + char *query = "update id_provider_tbl set last_id = ?, free_bit_cnt = ? where id_provider_code = ?"; + + stmt = __query_prepare(daci_handler, query, strlen(query)); + if (stmt == 0) + return DACI_ERR_QUERY_FAILED; + + __stmt_bind_int(daci_handler, stmt, 1, id_provider->last_id); + __stmt_bind_int(daci_handler, stmt, 2, id_provider->free_bit_cnt); + __stmt_bind_int(daci_handler, stmt, 3, id_provider->id_provider_code); + + ret = __stmt_write_step(daci_handler, stmt); + __stmt_finalize(daci_handler, stmt); + + FW_LOGV("[%s] End !\n", __func__); + return ret; +} + +DACI_RETURN add_id_page(DACI_HANDLER *daci_handler, daci_id_page *id_page, unsigned int page_byte_size) +{ + FW_LOGV("[%s] Start !\n", __func__); + + daci_stmt stmt = 0; + DACI_RETURN ret = DACI_SUCCESS; + char *query = 0; + + query = "insert into id_page_tbl (page_index, id_provider_code, page_bit) values (?, ?, ?)"; + + stmt = __query_prepare(daci_handler, query, strlen(query)); + if (stmt == 0) { + return DACI_ERR_QUERY_FAILED; + } + + __stmt_bind_int(daci_handler, stmt, 1, id_page->page_index); + __stmt_bind_int(daci_handler, stmt, 2, id_page->id_provider_code); + __stmt_bind_blob(daci_handler, stmt, 3, id_page->page_bit, page_byte_size); + int i = 0; + for (; i < page_byte_size; i++) { + FW_LOGV("[%d] %d\n", i, (id_page->page_bit)[i]); + } + + ret = __stmt_write_step(daci_handler, stmt); + if (ret != DACI_SUCCESS) { + __stmt_finalize(daci_handler, stmt); + return DACI_ERR_QUERY_FAILED; + } + + __stmt_finalize(daci_handler, stmt); + + FW_LOGV("[%s] End !\n", __func__); + return ret; +} + +DACI_RETURN delete_id_page(DACI_HANDLER *daci_handler, unsigned int id_provider_code, unsigned int page_index) +{ + FW_LOGV("[%s] Start !\n", __func__); + + DACI_RETURN ret = DACI_SUCCESS; + daci_stmt stmt = 0; + char *query = "delete from id_page_tbl where id_provider_code = ? and page_index = ?"; + + stmt = __query_prepare(daci_handler, query, strlen(query)); + if (stmt == 0) + return DACI_ERR_QUERY_FAILED; + + __stmt_bind_int(daci_handler, stmt, 1, id_provider_code); + __stmt_bind_int(daci_handler, stmt, 2, page_index); + + ret = __stmt_write_step(daci_handler, stmt); + __stmt_finalize(daci_handler, stmt); + + FW_LOGV("[%s] End !\n", __func__); + return ret; +} + +DACI_RETURN get_id_page(DACI_HANDLER *daci_handler, unsigned int id_provider_code, unsigned int page_index, char **page_bit) +{ + FW_LOGV("[%s] Start !\n", __func__); + + DACI_RETURN ret = DACI_SUCCESS; + daci_stmt stmt = 0; + char *query = "select page_bit from id_page_tbl where id_provider_code = ? and page_index = ?"; + + stmt = __query_prepare(daci_handler, query, strlen(query)); + if (stmt != 0) { + __stmt_bind_int(daci_handler, stmt, 1, id_provider_code); + __stmt_bind_int(daci_handler, stmt, 2, page_index); + + if (__stmt_read_step(daci_handler, stmt) == DACI_ERR_MORE_DATA) { + int byte_len = sqlite3_column_bytes(stmt, 0); + *page_bit = (char *)calloc(byte_len, sizeof(char)); + char *geted_page_bit = __stmt_column_text(stmt, 0); + + memcpy(*page_bit, geted_page_bit, byte_len); + + DACI_MEMORY_FREE(geted_page_bit); + } else { + FW_LOGV("NO DATA"); + *page_bit = 0; + } + __stmt_finalize(daci_handler, stmt); + } + + FW_LOGV("[%s] End !\n", __func__); + return ret; +} + +DACI_RETURN update_id_page(DACI_HANDLER *daci_handler, daci_id_page *id_page, unsigned int page_byte_size) +{ + FW_LOGV("[%s] Start !\n", __func__); + + DACI_RETURN ret = DACI_SUCCESS; + daci_stmt stmt = 0; + char *query = "update id_page_tbl set page_bit = ? where id_provider_code = ? and page_index = ?"; + + stmt = __query_prepare(daci_handler, query, strlen(query)); + if (stmt == 0) + return DACI_ERR_QUERY_FAILED; + + __stmt_bind_blob(daci_handler, stmt, 1, id_page->page_bit, page_byte_size); + __stmt_bind_int(daci_handler, stmt, 2, id_page->id_provider_code); + __stmt_bind_int(daci_handler, stmt, 3, id_page->page_index); + + ret = __stmt_write_step(daci_handler, stmt); + __stmt_finalize(daci_handler, stmt); + + FW_LOGV("[%s] End !\n", __func__); + return ret; +} + +int __busy_handler(void *pData, int count) +{ + FW_LOGV("__busy_handler %d called", count); + + /* sleep time when SQLITE_LOCK */ + usleep(100000); + + /* retry will be stopped if busy handler return 0 */ + return DACI_RETRY_COUNT - count; +} + +DACI_RETURN __query_exec(DACI_HANDLER *daci_handler, char *query, char *errMsg) +{ + char *queryMsg = 0; + int ret = 0; + + if (daci_handler == 0) + return DACI_ERR_NOT_OPENED; + + ret = sqlite3_exec(daci_handler, query, 0, 0, &queryMsg); + if (ret != SQLITE_OK) { + FW_LOGE("%s(%d) : %s", errMsg, ret, queryMsg); + + if (0 != queryMsg) + sqlite3_free(queryMsg); + + if (ret == SQLITE_BUSY) + return DACI_ERR_LOCKED; + + return DACI_ERR_QUERY_FAILED; + } + + return DACI_SUCCESS; +} + +daci_stmt __query_prepare(DACI_HANDLER *daci_handler, char *query, int size) +{ + int ret = 0; + daci_stmt stmt = 0; + + pthread_mutex_lock(&exec_lock); + ret = sqlite3_prepare_v2(daci_handler, query, size, &stmt, 0); + pthread_mutex_unlock(&exec_lock); + + if (ret != SQLITE_OK) + FW_LOGE("sqlite3_query_prepare failed(%d) : %s ", ret, sqlite3_errmsg(daci_handler)); + + return stmt; +} + +DACI_RETURN __stmt_bind_text(DACI_HANDLER *daci_handler, daci_stmt stmt, int index, const char *value) +{ + int ret = 0; + + if (value != 0) { + ret = sqlite3_bind_text(stmt, index, value, strlen(value), SQLITE_STATIC); + } else { + ret = __stmt_bind_null(daci_handler, stmt, index); + + if (ret == DACI_SUCCESS) + ret = SQLITE_OK; + } + + if (ret != SQLITE_OK) { + FW_LOGE("sqlite3_stmt_bind_text failed(%d) : %s ", ret, sqlite3_errmsg(daci_handler)); + return DACI_ERR_QUERY_FAILED; + } + + return DACI_SUCCESS; +} + +DACI_RETURN __stmt_bind_int(DACI_HANDLER *daci_handler, daci_stmt stmt, int index, const int value) +{ + int ret = 0; + + ret = sqlite3_bind_int(stmt, index, value); + if (ret != SQLITE_OK) { + FW_LOGE("sqlite3_stmt_bind_int failed(%d) : %s \n", ret, sqlite3_errmsg(daci_handler)); + return DACI_ERR_QUERY_FAILED; + } + + return DACI_SUCCESS; +} + +static DACI_RETURN __stmt_bind_blob(DACI_HANDLER *daci_handler, daci_stmt stmt, int index, const void *value, int nByte) +{ + int ret = 0; + + ret = sqlite3_bind_blob(stmt, index, value, nByte, 0); + if (ret != SQLITE_OK) { + FW_LOGE("sqlite3_bind_blob failed(%d) : %s \n", ret, sqlite3_errmsg(daci_handler)); + return DACI_ERR_QUERY_FAILED; + } + + return DACI_SUCCESS; +} + +DACI_RETURN __stmt_bind_null(DACI_HANDLER *daci_handler, daci_stmt stmt, int index) +{ + int ret = 0; + + ret = sqlite3_bind_null(stmt, index); + if (ret != SQLITE_OK) { + FW_LOGE("sqlite3_stmt_bind_null failed(%d) : %s", ret, sqlite3_errmsg(daci_handler)); + return DACI_ERR_QUERY_FAILED; + } + + return DACI_SUCCESS; +} + +DACI_RETURN __stmt_read_step(DACI_HANDLER *daci_handler, daci_stmt stmt) +{ + int ret = 0; + + pthread_mutex_lock(&exec_lock); + + ret = sqlite3_step(stmt); + + pthread_mutex_unlock(&exec_lock); + + if (ret == SQLITE_ROW) + return DACI_ERR_MORE_DATA; + + if (ret != SQLITE_DONE) { + FW_LOGE("sqlite3_stmt_step failed(%d) : %s", ret, sqlite3_errmsg(daci_handler)); + + if (ret == SQLITE_BUSY) + return DACI_ERR_LOCKED; + + return DACI_ERR_QUERY_FAILED; + } + + return DACI_SUCCESS; +} + +static DACI_RETURN __stmt_write_step(DACI_HANDLER *daci_handler, daci_stmt stmt) +{ + int transaction_flag = 0; + + if (use_transaction_thread_id != 0) { + if (use_transaction_thread_id != DACI_GET_THREAD_ID) { + pthread_mutex_lock(&transaction_lock); + use_transaction_thread_id = DACI_GET_THREAD_ID; + transaction_flag = 1; + } + } + + pthread_mutex_lock(&exec_lock); + + int ret = sqlite3_step(stmt); + + pthread_mutex_unlock(&exec_lock); + + if (transaction_flag) { + use_transaction_thread_id = 0; + pthread_mutex_unlock(&transaction_lock); + } + + if (ret == SQLITE_ROW) { + return DACI_ERR_MORE_DATA; + } + + if (ret != SQLITE_DONE) { + FW_LOGE("sqlite3_stmt_step failed(%d) : %s", ret, sqlite3_errmsg(daci_handler)); + if (ret == SQLITE_BUSY) { + FW_LOGE("Never reached this line!!"); + return DACI_ERR_LOCKED; + } + return DACI_ERR_QUERY_FAILED; + } + + return DACI_SUCCESS; +} + +DACI_RETURN __stmt_reset(DACI_HANDLER *daci_handler, daci_stmt stmt) +{ + int ret = 0; + + if (sqlite3_reset(stmt) != SQLITE_OK) { + FW_LOGE("sqlite3_stmt_reset failed(%d) : %s", ret, sqlite3_errmsg(daci_handler)); + return DACI_ERRORS; + } + + return DACI_SUCCESS; +} + +DACI_RETURN __stmt_finalize(DACI_HANDLER *daci_handler, daci_stmt stmt) +{ + int ret = 0; + + if (sqlite3_finalize(stmt) != SQLITE_OK) { + FW_LOGE("sqlite3_stmt_finalize failed(%d) : %s", ret, sqlite3_errmsg(daci_handler)); + return DACI_ERRORS; + } + + return DACI_SUCCESS; +} + +char *__stmt_column_text(daci_stmt stmt, int index) +{ + char *temp = 0; + temp = (char *)sqlite3_column_text(stmt, index); + + return DACI_STRDUP(temp); +} + +int __stmt_column_int(daci_stmt stmt, int index) +{ + return (int)sqlite3_column_int(stmt, index); +} + +DACI_RETURN __get_table(DACI_HANDLER *daci_handler, char *query, char ***result, int *rowCount, int *colCount) +{ + int ret = 0; + char *errMsg; + + if (daci_handler == 0) + return DACI_ERR_NOT_OPENED; + + ret = sqlite3_get_table(daci_handler, query, result, rowCount, colCount, &errMsg); + if (ret != SQLITE_OK) { + FW_LOGE("sqlite3_get_table failed(%d) : %s", ret, errMsg); + + __free_table(*result); + if (0 != errMsg) + sqlite3_free(errMsg); + return DACI_ERR_QUERY_FAILED; + } + return DACI_SUCCESS; +} + +void __free_table(char **result) +{ + if (result != 0) + sqlite3_free_table(result); +} + +DACI_RETURN __create_changelog_table(DACI_HANDLER *daci_handler, int accountId) +{ + DACI_RETURN ret = DACI_SUCCESS; + char *newTable = 0; + char *newTableCreate = 0; + + ret = begin_transaction(daci_handler); + if (ret != DACI_SUCCESS) { + FW_LOGE("agent_db_changelog_tbl_create failed"); + return DACI_ERR_CREATE_TABLE_FAILED; + } + + /* 9. create account_item_changelog_tbl */ + newTable = __replace_table_name("account_%d_item_changelog_tbl", accountId, 1); + if (newTable == 0) { + end_transaction(daci_handler, TRANSACTION_ROLLBACK); + return DACI_ERR_CREATE_TABLE_FAILED; + } + + if (__exist_table(daci_handler, newTable) == 0) { + newTableCreate = __replace_table_name(g_daci_create_table[TABLE_NAME_ACCOUNT_ITEM_CHANGELOG], accountId, 4); + + ret = __query_exec(daci_handler, newTableCreate, "Item_changelog_tbl_create failed"); + + if (ret != DACI_SUCCESS) { + end_transaction(daci_handler, TRANSACTION_ROLLBACK); + return DACI_ERR_CREATE_TABLE_FAILED; + } + } + + /* memory free */ + DACI_MEMORY_FREE(newTable); + DACI_MEMORY_FREE(newTableCreate); + + return end_transaction(daci_handler, TRANSACTION_COMMIT); +} + +DACI_RETURN __drop_changelog_table(DACI_HANDLER *daci_handler, int accountId) +{ + DACI_RETURN ret = DACI_SUCCESS; + char *newTableDrop = 0; + + /* 9. drop account_item_changelog_tbl */ + newTableDrop = __replace_table_name(g_daci_drop_table[TABLE_NAME_ACCOUNT_ITEM_CHANGELOG], accountId, 1); + + ret = __query_exec(daci_handler, newTableDrop, "Item_changelog_tbl_drop failed"); + if (ret != DACI_SUCCESS) { +/* end_transaction(daci_handler, TRANSACTION_ROLLBACK);*/ + return DACI_ERR_DROP_TABLE_FAILED; + } + + /* memory free */ + DACI_MEMORY_FREE(newTableDrop); + + return ret; +} + +int __exist_table(DACI_HANDLER *daci_handler, const char *tableName) +{ + daci_stmt stmt = 0; + int tableCount = 0; + char *query = "select count(*) from sqlite_master where tbl_name= ?"; + + stmt = __query_prepare(daci_handler, query, strlen(query)); + if ((stmt != 0) && (__stmt_bind_text(daci_handler, stmt, 1, tableName) == DACI_SUCCESS)) { + + if (__stmt_read_step(daci_handler, stmt) == DACI_ERR_MORE_DATA) + tableCount = __stmt_column_int(stmt, 0); + + __stmt_finalize(daci_handler, stmt); + + if (tableCount > 0) + return 1; + } + return 0; +} + +int __get_data_count(DACI_HANDLER *daci_handler, char *query, int size) +{ + daci_stmt stmt = 0; + int dataCount = 0; + + stmt = __query_prepare(daci_handler, query, size); + if (stmt != 0) { + if (__stmt_read_step(daci_handler, stmt) == DACI_ERR_MORE_DATA) + dataCount = __stmt_column_int(stmt, 0); + + __stmt_finalize(daci_handler, stmt); + } + + return dataCount; +} + +char *__replace_table_name(char *oldTable, int accountId, int count) +{ + char *newTable = 0; + int length = 0; + + if (oldTable == 0) { + FW_LOGE("oldTable is null"); + return newTable; + } + + /* SVACE : Measure the size for allocation memory. */ + if (count == 1) /* table name convert */ + length = snprintf(0, 0, oldTable, accountId); + else if (count == 4) /* table create query convert */ + length = snprintf(0, 0, oldTable, accountId, accountId, accountId, accountId); + + newTable = DACI_MEMORY_MALLOC(char *, sizeof(char), (length + 1)); + if (newTable == 0) { + FW_LOGE("memory_allocation failed"); + return newTable; + } + + if (count == 1) + sprintf(newTable, oldTable, accountId); + else if (count == 4) + sprintf(newTable, oldTable, accountId, accountId, accountId, accountId); + + return newTable; +} + +char *__get_table_name(DACI_TABLE_NAME tableName) +{ + char *tableStr = 0; + + switch (tableName) { + case TABLE_NAME_ACCOUNT: + { + tableStr = "account_tbl"; + } + break; + case TABLE_NAME_FOLDER: + { + tableStr = "folder_tbl"; + } + break; + case TABLE_NAME_ITEM: + { + tableStr = "item_tbl"; + } + break; + case TABLE_NAME_CONFIG: + { + tableStr = "config_tbl"; + } + break; + case TABLE_NAME_ACCOUNT_ITEM_CHANGELOG: + { + tableStr = "account_item_changelog_tbl"; + } + break; + case TABLE_NAME_LAST_ANCHOR: + { + tableStr = "last_anchor_tbl"; + } + break; + case TABLE_NAME_MAPPING: + { + tableStr = "mapping_tbl"; + } + break; + case TABLE_NAME_ID_PROVIDER: + { + tableStr = "id_provider_tbl"; + } + break; + case TABLE_NAME_ID_PAGE: + { + tableStr = "id_page_tbl"; + } + break; + default: + break; + } + + return tableStr; +} + +char *__get_column_name(DACI_COLUMN_NAME columnName) +{ + char *columnStr = 0; + + switch (columnName) { + case COLUMN_NAME_ITEM_ID: + { + columnStr = "item_id"; + } + break; + case COLUMN_NAME_SERVICE_ID: + { + columnStr = "service_id"; + } + break; + default: + break; + } + + return columnStr; +} + +int __get_next_account_id() +{ + int nextAccountId = 1; + int *accountIdList = 0; + int count = 0; + int i = 0; + + accountIdList = DACI_Get_Account_Account_Id_List(&count); + if (accountIdList != 0) { + for (i = 0; i < count; i++) { + if ((i + 1) != accountIdList[i]) + break; + + nextAccountId++; + } + + free(accountIdList); + } + return nextAccountId; +} + +DACI_RETURN __delete_account(DACI_HANDLER *daci_handler, DACI_TABLE_NAME tableName, int accountId) +{ + daci_stmt stmt = 0; + DACI_RETURN ret = DACI_SUCCESS; + char *tableStr = 0; + char g_daci_query[DACI_MAX_QUERY_LENGTH] = { 0, }; + + tableStr = __get_table_name(tableName); + + if (!strcmp(tableStr, "config_tbl")) { + snprintf(g_daci_query, sizeof(g_daci_query), "delete from %s where config_id = %d", tableStr, accountId); + } else if (!strcmp(tableStr, "id_provider_tbl") || !strcmp(tableStr, "id_page_tbl")) { + return ret; + } else { + snprintf(g_daci_query, sizeof(g_daci_query), "delete from %s where account_id = %d", tableStr, accountId); + } + + FW_LOGV("i = %d, tableName = %s, query = %s", tableName, tableStr, g_daci_query); + stmt = __query_prepare(daci_handler, g_daci_query, strlen(g_daci_query)); + if (stmt == 0) + return DACI_ERR_QUERY_FAILED; + + ret = __stmt_write_step(daci_handler, stmt); + __stmt_finalize(daci_handler, stmt); + + return ret; +} + +/* + *============================================================================================================================= + * Testing + *============================================================================================================================= +*/ +void drop_table(DACI_HANDLER *daci_handler, int *accountIdList, int accountCount) +{ + int i; + + for (i = 0; i < accountCount; i++) + __drop_changelog_table(daci_handler, accountIdList[i]); +} + +char *get_daci_file_path() +{ + return daci_file_path; +} diff --git a/framework/src/DataAdapter/DACI_Agent_Handler_Manager.c b/framework/src/DataAdapter/DACI_Agent_Handler_Manager.c new file mode 100755 index 0000000..28a4508 --- /dev/null +++ b/framework/src/DataAdapter/DACI_Agent_Handler_Manager.c @@ -0,0 +1,1181 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu , + * Heeyoung Hwang + */ + +#include "Utility/fw_log.h" + +#include "DataAdapter/DACI_Agent.h" + +#include "DataAdapter/DACI_Agent_Handler_Manager.h" + +#define LOG_TAG "AF_DACI" + +static daci_handler_mgr *pAgentDBHandlerMgr = 0; + +/* static function define */ +static DACI_RETURN __alloc_agent_dc_handlerTable(); +static DACI_RETURN __alloc_agent_dc_handlerTable_mutex(); +static DACI_RETURN __free_agent_dc_handlerTable(); +static DACI_RETURN __free_agent_dc_handlerTable_mutex(); +static DACI_RETURN __create_agentDBHandlerMgrInfo(); +static void __destroy_agentDBHashTableValue(void *pHandler); +static void __destory_agentDBHashTableKey(void *key); + +/* general function implementation */ +/* + * ================================== + * external API (1. about agent db handler mgr) + * ================================== + */ +DACI_RETURN DACI_Alloc_AgentDB_Handler_Mgr() +{ + FW_LOGV("[%s] start !\n", __func__); + DACI_RETURN ret = DACI_SUCCESS; + + /* alloc the agentDBHandlerMgr */ + pAgentDBHandlerMgr = (daci_handler_mgr *) calloc(1, sizeof(daci_handler_mgr)); + if (pAgentDBHandlerMgr == 0) + return DACI_ERR_DB_HANDLER_MGR; + FW_LOGV("[%s] pAgentDBHandlerMgr alloc success !\n", __func__); + + /* alloc the agentDBHandlerMgr information */ + ret = __create_agentDBHandlerMgrInfo(); + if (ret != DACI_SUCCESS) + FW_LOGV("[%s] __create_agentDBHandlerMgrInfo alloc fail !\n", __func__); + else + FW_LOGV("[%s] __create_agentDBHandlerMgrInfo alloc success !\n", __func__); + + FW_LOGV("[%s] end !\n", __func__); + return ret; +} + +DACI_RETURN DACI_Free_AgentDB_Handler_Mgr() +{ + FW_LOGV("[%s] start !\n", __func__); + DACI_RETURN ret = DACI_SUCCESS; + + if (pAgentDBHandlerMgr != 0) { + + ret = __free_agent_dc_handlerTable_mutex(); + if (ret != DACI_SUCCESS) + return DACI_ERR_DB_HANDLER_MGR; + + ret = __free_agent_dc_handlerTable(); + if (ret != DACI_SUCCESS) + return DACI_ERR_DB_HANDLER_MGR; + + } + + FW_LOGV("[%s] end !\n", __func__); + return ret; +} + +/* + * ================================== + * external API (2. about agent db ) + * ================================== + */ +DACI_RETURN DACI_Clear_All_Database_Account() +{ + DACI_RETURN ret = DACI_SUCCESS; + int *accountIdList = 0; + int count = 0; + int i = 0; + + accountIdList = DACI_Get_Account_Account_Id_List(&count); + if (accountIdList == 0) { + FW_LOGE("accountIdList empty"); + return DACI_ERR_DB_HANDLER_MGR; + } else { + FW_LOGV("accountListCount : %d", count); + } + + for (i = 0; i < count; i++) { + ret = DACI_Delete_All_Database_Account(accountIdList[i]); + if (ret != DACI_SUCCESS) + break; + } + + /* memory free */ + if (accountIdList != 0) + free(accountIdList); + + return ret; +} + +DACI_RETURN DACI_Delete_All_Database_Account(int accountId) +{ + DACI_RETURN ret = 0; + + DACI_HANDLER *daci_handler = get_agentHandler(DACI_GET_THREAD_ID); + if (daci_handler == 0) { + FW_LOGE("[%s] no handler for key\n", __func__); + return DACI_ERRORS; + } + + int dataCount = 0; +/* if (DACI_IsExist_Account(accountId) && DACI_Delete_EmailAccount(accountId) && + DACI_Delete_ContactAccount(accountId) && DACI_Delete_CalendarAccount(accountId) && + (DACI_Delete_Account(accountId) == DACI_SUCCESS)) {*/ + + if (DACI_IsExist_Account(accountId) && (DACI_Delete_Account(accountId) == DACI_SUCCESS)) { + /* all of the deleted account */ + dataCount = get_accountCount(daci_handler); + if (dataCount == 0) + ret = DACI_ERR_DELETE_LAST_ACCOUNT; + else + ret = DACI_SUCCESS; + + } else { + ret = DACI_ERRORS; + } + + return ret; +} + +DACI_RETURN DACI_Open_Agent() +{ + FW_LOGV("[%s] Start !\n", __func__); + int ret = 0; + + DACI_HANDLER *daci_handler = get_agentHandler(DACI_GET_THREAD_ID); + if (daci_handler == 0) { + + FW_LOGV("daci_handler is 0"); + FW_LOGV("should register agent_handler to agent_handler_hash_table"); + ret = open_agent(&daci_handler); + if (ret != DACI_SUCCESS) + return ret; + + if (daci_handler != 0) { + /* add agentDB handler to agentDBHandleMgr */ + ret = add_agentHandler(DACI_GET_THREAD_ID, daci_handler); + if (ret != DACI_SUCCESS) + return ret; + } + + } else { + FW_LOGV("daci_handler is not null"); + FW_LOGV("should not register mo_handler to mo_handler_hash_table"); + } + + FW_LOGV("agent_db_agent_open_success"); + FW_LOGV("[%s] End !\n", __func__); + return DACI_SUCCESS; +} + +DACI_RETURN DACI_Close_Agent() +{ + FW_LOGV("[%s] Start !\n", __func__); + int ret = 0; + + DACI_HANDLER *daci_handler = get_agentHandler(DACI_GET_THREAD_ID); + if (daci_handler != 0) { + + /* remove agentDB handler to agentDBHandleMgr */ + ret = remove_agentHandler(DACI_GET_THREAD_ID); + if (ret != DACI_SUCCESS) + return ret; + + FW_LOGV("agent_db_agent_close_success"); + } + + FW_LOGV("[%s] End !\n", __func__); + return DACI_SUCCESS; +} + +DACI_RETURN DACI_Create_Agent_Default_Table() +{ + DACI_HANDLER *daci_handler = get_agentHandler(DACI_GET_THREAD_ID); + + return create_AgentDefaultTable(daci_handler); +} + +DACI_RETURN DACI_Begin_Transaction() +{ + DACI_HANDLER *daci_handler = get_agentHandler(DACI_GET_THREAD_ID); + if (daci_handler == 0) { + FW_LOGE("[%s] no handler for key\n", __func__); + return DACI_ERR_DB_HANDLER_MGR; + } + + return begin_transaction(daci_handler); +} + +DACI_RETURN DACI_End_Transaction(DACI_TRANSACTION transaction) +{ + DACI_HANDLER *daci_handler = get_agentHandler(DACI_GET_THREAD_ID); + if (daci_handler == 0) { + FW_LOGE("[%s] no handler for key\n", __func__); + return DACI_ERR_DB_HANDLER_MGR; + } + + return end_transaction(daci_handler, transaction); +} + +int DACI_Add_Account(daci_account *account) +{ + DACI_HANDLER *daci_handler = get_agentHandler(DACI_GET_THREAD_ID); + if (daci_handler == 0) { + FW_LOGE("[%s] no handler for key\n", __func__); + return -1; + } + + return add_account(daci_handler, account); +} + +DACI_RETURN DACI_Delete_Account(int accountId) +{ + DACI_HANDLER *daci_handler = get_agentHandler(DACI_GET_THREAD_ID); + if (daci_handler == 0) { + FW_LOGE("[%s] no handler for key\n", __func__); + return DACI_ERR_DB_HANDLER_MGR; + } + + return delete_account(daci_handler, accountId); +} + +DACI_RETURN DACI_Set_Account_Email_Address(int accountId, char *emailAddress, char *accessName) +{ + DACI_HANDLER *daci_handler = get_agentHandler(DACI_GET_THREAD_ID); + if (daci_handler == 0) { + FW_LOGE("[%s] no handler for key\n", __func__); + return DACI_ERR_DB_HANDLER_MGR; + } + + return set_accountEmailAddress(daci_handler, accountId, emailAddress, accessName); +} + +DACI_RETURN DACI_Set_Account_Password(int accountId, char *password, char *accessName) +{ + DACI_HANDLER *daci_handler = get_agentHandler(DACI_GET_THREAD_ID); + if (daci_handler == 0) { + FW_LOGE("[%s] no handler for key\n", __func__); + return DACI_ERR_DB_HANDLER_MGR; + } + + return set_accountPassword(daci_handler, accountId, password, accessName); +} + +int *DACI_Get_Account_Account_Id_List(int *count) +{ + DACI_HANDLER *daci_handler = get_agentHandler(DACI_GET_THREAD_ID); + if (daci_handler == 0) { + FW_LOGE("[%s] no handler for key\n", __func__); + return 0; + } + + return get_accountAccountIdList(daci_handler, count); +} + +char *DACI_Get_Account_Email_Address(int accountId) +{ + DACI_HANDLER *daci_handler = get_agentHandler(DACI_GET_THREAD_ID); + if (daci_handler == 0) { + FW_LOGE("[%s] no handler for key\n", __func__); + return 0; + } + + return get_accountEmailAddress(daci_handler, accountId); +} + +char *DACI_Get_Account_Password(int accountId) +{ + DACI_HANDLER *daci_handler = get_agentHandler(DACI_GET_THREAD_ID); + if (daci_handler == 0) { + FW_LOGE("[%s] no handler for key\n", __func__); + return 0; + } + + return get_accountPassword(daci_handler, accountId); +} + +int DACI_IsExist_Account(int accountId) +{ + DACI_HANDLER *daci_handler = get_agentHandler(DACI_GET_THREAD_ID); + if (daci_handler == 0) { + FW_LOGE("[%s] no handler for key\n", __func__); + return DACI_ERR_DB_HANDLER_MGR; + } + + return isExist_account(daci_handler, accountId); +} + +char *DACI_Get_Access_Name(int accountId) +{ + DACI_HANDLER *daci_handler = get_agentHandler(DACI_GET_THREAD_ID); + if (daci_handler == 0) { + FW_LOGE("[%s] no handler for key\n", __func__); + return 0; + } + + return get_accessName(daci_handler, accountId); +} + +int *DACI_Get_Account_Id_List_By_Access_Name(char *access_name, int *accountId_count) +{ + DACI_HANDLER *daci_handler = get_agentHandler(DACI_GET_THREAD_ID); + if (daci_handler == 0) { + FW_LOGE("[%s] no handler for key\n", __func__); + return 0; + } + + return get_accountIdListByAccessName(daci_handler, access_name, accountId_count); +} + +DACI_RETURN DACI_Add_Folder(daci_folder *folder, int count) +{ + DACI_HANDLER *daci_handler = get_agentHandler(DACI_GET_THREAD_ID); + if (daci_handler == 0) { + FW_LOGE("[%s] no handler for key\n", __func__); + return DACI_ERR_DB_HANDLER_MGR; + } + + return add_folder(daci_handler, folder, count); +} + +DACI_RETURN DACI_Delete_Folder_By_Folder_Id(char *folderId) +{ + DACI_HANDLER *daci_handler = get_agentHandler(DACI_GET_THREAD_ID); + if (daci_handler == 0) { + FW_LOGE("[%s] no handler for key\n", __func__); + return DACI_ERR_DB_HANDLER_MGR; + } + + return delete_folderByFolderId(daci_handler, folderId); +} + +char *DACI_Get_Folder_Folder_Id_By_Service_Id(int accountId, int itemTypeId, char *serviceId, int folderTypeId) +{ + DACI_HANDLER *daci_handler = get_agentHandler(DACI_GET_THREAD_ID); + if (daci_handler == 0) { + FW_LOGE("[%s] no handler for key\n", __func__); + return 0; + } + + return get_folderFolderIdByServiceId(daci_handler, accountId, itemTypeId, serviceId, folderTypeId); +} + +daci_id_list *DACI_Get_Folder_Folder_Id_By_Folder_Type_Id(int accountId, int itemTypeId, int folderTypeId) +{ + DACI_HANDLER *daci_handler = get_agentHandler(DACI_GET_THREAD_ID); + if (daci_handler == 0) { + FW_LOGE("[%s] no handler for key\n", __func__); + return 0; + } + + return get_folderFolderIdByFolderTypeId(daci_handler, accountId, itemTypeId, folderTypeId); +} + +char *DACI_Get_Folder_Service_Id(char *folderId) +{ + DACI_HANDLER *daci_handler = get_agentHandler(DACI_GET_THREAD_ID); + if (daci_handler == 0) { + FW_LOGE("[%s] no handler for key\n", __func__); + return 0; + } + + return get_folderServiceId(daci_handler, folderId); +} + +daci_id_list *DACI_Get_Folder_Folder_Id_List_By_Item_Type_Id(int account_id, int itemTypeId) +{ + DACI_HANDLER *daci_handler = get_agentHandler(DACI_GET_THREAD_ID); + if (daci_handler == 0) { + FW_LOGE("[%s] no handler for key\n", __func__); + return 0; + } + + return get_folderFolderIdListByItemTypeId(daci_handler, account_id, itemTypeId); +} + +daci_folder *DACI_Get_Folder_Mapping_Service_Id(int accountId, char *folderId, int *count) +{ + DACI_HANDLER *daci_handler = get_agentHandler(DACI_GET_THREAD_ID); + if (daci_handler == 0) { + FW_LOGE("[%s] no handler for key\n", __func__); + return 0; + } + + return get_folderMappingServiceId(daci_handler, accountId, folderId, count); +} + +DACI_RETURN DACI_Add_Item(daci_item *item, int count) +{ + DACI_HANDLER *daci_handler = get_agentHandler(DACI_GET_THREAD_ID); + if (daci_handler == 0) { + FW_LOGE("[%s] no handler for key\n", __func__); + return DACI_ERR_DB_HANDLER_MGR; + } + + return add_item(daci_handler, item, count); +} + +DACI_RETURN DACI_Delete_Item_By_Item_Id(char *itemId) +{ + DACI_HANDLER *daci_handler = get_agentHandler(DACI_GET_THREAD_ID); + if (daci_handler == 0) { + FW_LOGE("[%s] no handler for key\n", __func__); + return DACI_ERR_DB_HANDLER_MGR; + } + + return delete_itemByItemId(daci_handler, itemId); +} + +DACI_RETURN DACI_Delete_Item_By_Item_Type_Id(int accountId, int itemTypeId) +{ + DACI_HANDLER *daci_handler = get_agentHandler(DACI_GET_THREAD_ID); + if (daci_handler == 0) { + FW_LOGE("[%s] no handler for key\n", __func__); + return DACI_ERR_DB_HANDLER_MGR; + } + + return delete_itemByItemTypeId(daci_handler, accountId, itemTypeId); +} + +char *DACI_Get_Item_Item_Id(int accountId, char *serviceId, int itemTypeId) +{ + DACI_HANDLER *daci_handler = get_agentHandler(DACI_GET_THREAD_ID); + if (daci_handler == 0) { + FW_LOGE("[%s] no handler for key\n", __func__); + return 0; + } + + return get_itemItemId(daci_handler, accountId, serviceId, itemTypeId); +} + +char *DACI_Get_Item_Service_Id(char *itemId) +{ + DACI_HANDLER *daci_handler = get_agentHandler(DACI_GET_THREAD_ID); + if (daci_handler == 0) { + FW_LOGE("[%s] no handler for key\n", __func__); + return 0; + } + + return get_itemServiceId(daci_handler, itemId); +} + +daci_item *DACI_Get_Item(char *itemId) +{ + DACI_HANDLER *daci_handler = get_agentHandler(DACI_GET_THREAD_ID); + if (daci_handler == 0) { + FW_LOGE("[%s] no handler for key\n", __func__); + return 0; + } + + return get_item(daci_handler, itemId); +} + +daci_id_list *DACI_Get_Item_Id_List(char *folderId, DACI_COLUMN_NAME columnName) +{ + DACI_HANDLER *daci_handler = get_agentHandler(DACI_GET_THREAD_ID); + if (daci_handler == 0) { + FW_LOGE("[%s] no handler for key\n", __func__); + return 0; + } + + return get_itemIdList(daci_handler, folderId, columnName); +} + +daci_item *DACI_Get_item_By_Account_Id(int accountId, int itemTypeId, int *count) +{ + DACI_HANDLER *daci_handler = get_agentHandler(DACI_GET_THREAD_ID); + if (daci_handler == 0) { + FW_LOGE("[%s] no handler for key\n", __func__); + return 0; + } + + return get_itemByAccountId(daci_handler, accountId, itemTypeId, count); +} + +daci_item_info *DACI_Get_Item_Info_By_Item_Type_Id(int accountId, int itemTypeId, int *count) +{ + DACI_HANDLER *daci_handler = get_agentHandler(DACI_GET_THREAD_ID); + if (daci_handler == 0) { + FW_LOGE("[%s] no handler for key\n", __func__); + return 0; + } + + return get_itemInfoByItemTypeId(daci_handler, accountId, itemTypeId, count); +} + +daci_item *DACI_Get_item_Mapping_Service_Id(int accountId, char *itemId, int *count) +{ + DACI_HANDLER *daci_handler = get_agentHandler(DACI_GET_THREAD_ID); + if (daci_handler == 0) { + FW_LOGE("[%s] no handler for key\n", __func__); + return 0; + } + + return get_itemMappingServiceId(daci_handler, accountId, itemId, count); +} + +daci_id_list *DACI_Get_Item_Id_List_By_Data_Store_Id(int data_store_id) +{ + DACI_HANDLER *daci_handler = get_agentHandler(DACI_GET_THREAD_ID); + if (daci_handler == 0) { + FW_LOGE("[%s] no handler for key\n", __func__); + return 0; + } + + return get_itemIdListByDataStoreId(daci_handler, data_store_id); +} + +daci_id_list *DACI_Get_Item_Id_List_By_Data_Store_Id_with_AccountID(int account_id, int data_store_id) +{ + DACI_HANDLER *daci_handler = get_agentHandler(DACI_GET_THREAD_ID); + if (daci_handler == 0) { + FW_LOGE("[%s] no handler for key\n", __func__); + return 0; + } + + return get_itemIdListByDataStoreIdwithAccountId(daci_handler, account_id, data_store_id); +} + +daci_id_list *DACI_Get_Item_Id_List_By_Operation_Id(int account_id, int data_store_id, int operation_id) +{ + DACI_HANDLER *daci_handler = get_agentHandler(DACI_GET_THREAD_ID); + if (daci_handler == 0) { + FW_LOGE("[%s] no handler for key\n", __func__); + return 0; + } + + return get_ItemIdListByOperationId(daci_handler, account_id, data_store_id, operation_id); +} + +int DACI_IsExist_Item(char *itemId) +{ + DACI_HANDLER *daci_handler = get_agentHandler(DACI_GET_THREAD_ID); + if (daci_handler == 0) { + FW_LOGE("[%s] no handler for key\n", __func__); + return DACI_ERR_DB_HANDLER_MGR; + } + + return isExist_item(daci_handler, itemId); +} + +DACI_RETURN DACI_Add_Config(daci_config *config) +{ + DACI_HANDLER *daci_handler = get_agentHandler(DACI_GET_THREAD_ID); + if (daci_handler == 0) { + FW_LOGE("[%s] no handler for key\n", __func__); + return DACI_ERR_DB_HANDLER_MGR; + } + + return add_config(daci_handler, config); +} + +DACI_RETURN DACI_Delete_Config_By_Key(int configId, char *key) +{ + DACI_HANDLER *daci_handler = get_agentHandler(DACI_GET_THREAD_ID); + if (daci_handler == 0) { + FW_LOGE("[%s] no handler for key\n", __func__); + return DACI_ERR_DB_HANDLER_MGR; + } + + return delete_configByKey(daci_handler, configId, key); +} + +daci_config *DACI_Get_Config_By_Config_Id(int configId, int *count) +{ + DACI_HANDLER *daci_handler = get_agentHandler(DACI_GET_THREAD_ID); + if (daci_handler == 0) { + FW_LOGE("[%s] no handler for key\n", __func__); + return 0; + } + + return get_configByConfigId(daci_handler, configId, count); +} + +DACI_RETURN DACI_Get_Config_By_Key(daci_config *config) +{ + DACI_HANDLER *daci_handler = get_agentHandler(DACI_GET_THREAD_ID); + if (daci_handler == 0) { + FW_LOGE("[%s] no handler for key\n", __func__); + return DACI_ERR_DB_HANDLER_MGR; + } + + return get_configByKey(daci_handler, config); +} + +int DACI_IsExist_Config(int configId, char *key) +{ + DACI_HANDLER *daci_handler = get_agentHandler(DACI_GET_THREAD_ID); + if (daci_handler == 0) { + FW_LOGE("[%s] no handler for key\n", __func__); + return DACI_ERR_DB_HANDLER_MGR; + } + + return isExist_config(daci_handler, configId, key); +} + +DACI_RETURN DACI_Update_Config(daci_config *config, int count) +{ + DACI_HANDLER *daci_handler = get_agentHandler(DACI_GET_THREAD_ID); + if (daci_handler == 0) { + FW_LOGE("[%s] no handler for key\n", __func__); + return DACI_ERR_DB_HANDLER_MGR; + } + + return update_config(daci_handler, config, count); +} + +DACI_RETURN DACI_Add_Item_Changelog(int accountId, daci_item_changelog *itemChangelog, int count) +{ + DACI_HANDLER *daci_handler = get_agentHandler(DACI_GET_THREAD_ID); + if (daci_handler == 0) { + FW_LOGE("[%s] no handler for key\n", __func__); + return DACI_ERR_DB_HANDLER_MGR; + } + + return add_itemChangelog(daci_handler, accountId, itemChangelog, count); +} + +DACI_RETURN DACI_Delete_Item_Changelog_By_Item_Id(int accountId, char *itemId) +{ + DACI_HANDLER *daci_handler = get_agentHandler(DACI_GET_THREAD_ID); + if (daci_handler == 0) { + FW_LOGE("[%s] no handler for key\n", __func__); + return DACI_ERR_DB_HANDLER_MGR; + } + + return delete_itemChangelogByItemId(daci_handler, accountId, itemId); +} + +DACI_RETURN DACI_Delete_Item_Changelog_By_Item_Id_List(int accountId, char **itemIdList, int count) +{ + DACI_HANDLER *daci_handler = get_agentHandler(DACI_GET_THREAD_ID); + if (daci_handler == 0) { + FW_LOGE("[%s] no handler for key\n", __func__); + return DACI_ERR_DB_HANDLER_MGR; + } + + return delete_itemChangelogByItemIdList(daci_handler, accountId, itemIdList, count); +} + +DACI_RETURN DACI_Delete_Item_Changelog_By_Item_Type_Id(int accountId, int itemTypeId) +{ + DACI_HANDLER *daci_handler = get_agentHandler(DACI_GET_THREAD_ID); + if (daci_handler == 0) { + FW_LOGE("[%s] no handler for key\n", __func__); + return DACI_ERR_DB_HANDLER_MGR; + } + + return delete_itemChangelogByItemTypeId(daci_handler, accountId, itemTypeId); +} + +DACI_RETURN DACI_Set_Item_Changelog_Operation_Id(int accountId, daci_item_changelog *itemChangelog) +{ + DACI_HANDLER *daci_handler = get_agentHandler(DACI_GET_THREAD_ID); + if (daci_handler == 0) { + FW_LOGE("[%s] no handler for key\n", __func__); + return DACI_ERR_DB_HANDLER_MGR; + } + + return set_itemChangelogOperationId(daci_handler, accountId, itemChangelog); +} + +DACI_RETURN DACI_Set_Item_Changelog_Sync_Status(int accountId, daci_item_changelog *itemChangelog) +{ + DACI_HANDLER *daci_handler = get_agentHandler(DACI_GET_THREAD_ID); + if (daci_handler == 0) { + FW_LOGE("[%s] no handler for key\n", __func__); + return DACI_ERR_DB_HANDLER_MGR; + } + + return set_itemChangelogSyncStatus(daci_handler, accountId, itemChangelog); +} + +DACI_RETURN DACI_Set_Item_Changelog_Wait_Status(int accountId, char **folderIdList, int folderIdCount, int *itemTypeIdList, int itemTypeIdCount) +{ + DACI_HANDLER *daci_handler = get_agentHandler(DACI_GET_THREAD_ID); + if (daci_handler == 0) { + FW_LOGE("[%s] no handler for key\n", __func__); + return DACI_ERR_DB_HANDLER_MGR; + } + + return set_itemChangelogWaitStatus(daci_handler, accountId, folderIdList, folderIdCount, itemTypeIdList, itemTypeIdCount); + +} + +DACI_RETURN DACI_Get_Item_Changelog_By_Item_Id(int accountId, daci_item_changelog *itemChangelog) +{ + DACI_HANDLER *daci_handler = get_agentHandler(DACI_GET_THREAD_ID); + if (daci_handler == 0) { + FW_LOGE("[%s] no handler for key\n", __func__); + return DACI_ERR_DB_HANDLER_MGR; + } + + return get_itemChangelogByItemId(daci_handler, accountId, itemChangelog); +} + +int DACI_IsExist_Item_Changelog(int accountId, char *itemId) +{ + DACI_HANDLER *daci_handler = get_agentHandler(DACI_GET_THREAD_ID); + if (daci_handler == 0) { + FW_LOGE("[%s] no handler for key\n", __func__); + return DACI_ERR_DB_HANDLER_MGR; + } + + return isExist_itemChangelog(daci_handler, accountId, itemId); +} + +DACI_RETURN DACI_Add_Last_Anchor(daci_last_anchor *lastAnchor) +{ + DACI_HANDLER *daci_handler = get_agentHandler(DACI_GET_THREAD_ID); + if (daci_handler == 0) { + FW_LOGE("[%s] no handler for key\n", __func__); + return DACI_ERR_DB_HANDLER_MGR; + } + + return add_lastAnchor(daci_handler, lastAnchor); +} + +DACI_RETURN DACI_Delete_Last_Anchor_By_Account_Id(int accountId) +{ + DACI_HANDLER *daci_handler = get_agentHandler(DACI_GET_THREAD_ID); + if (daci_handler == 0) { + FW_LOGE("[%s] no handler for key\n", __func__); + return DACI_ERR_DB_HANDLER_MGR; + } + + return delete_lastAnchorByAccountId(daci_handler, accountId); +} + +DACI_RETURN DACI_Delete_Last_Anchor_By_Item_Type_Id(int accountId, int itemTypeId) +{ + DACI_HANDLER *daci_handler = get_agentHandler(DACI_GET_THREAD_ID); + if (daci_handler == 0) { + FW_LOGE("[%s] no handler for key\n", __func__); + return DACI_ERR_DB_HANDLER_MGR; + } + + return delete_lastAnchorByItemTypeId(daci_handler, accountId, itemTypeId); +} + +DACI_RETURN DACI_Set_Last_Anchor(daci_last_anchor *lastAnchor) +{ + DACI_HANDLER *daci_handler = get_agentHandler(DACI_GET_THREAD_ID); + if (daci_handler == 0) { + FW_LOGE("[%s] no handler for key\n", __func__); + return DACI_ERR_DB_HANDLER_MGR; + } + + return set_lastAnchor(daci_handler, lastAnchor); +} + +daci_last_anchor *DACI_Get_Last_Anchor_By_Account_Id(int accountId, int *count) +{ + DACI_HANDLER *daci_handler = get_agentHandler(DACI_GET_THREAD_ID); + if (daci_handler == 0) { + FW_LOGE("[%s] no handler for key\n", __func__); + return 0; + } + + return get_lastAnchorByAccountId(daci_handler, accountId, count); +} + +daci_last_anchor *DACI_Get_Last_Anchor_By_Item_Type_Id(int accountId, int itemTypeId, int *count) +{ + DACI_HANDLER *daci_handler = get_agentHandler(DACI_GET_THREAD_ID); + if (daci_handler == 0) { + FW_LOGE("[%s] no handler for key\n", __func__); + return 0; + } + + return get_lastAnchorByItemTypeId(daci_handler, accountId, itemTypeId, count); +} + +int DACI_IsExist_Last_Anchor(int accountId, int itemTypeId) +{ + DACI_HANDLER *daci_handler = get_agentHandler(DACI_GET_THREAD_ID); + if (daci_handler == 0) { + FW_LOGE("[%s] no handler for key\n", __func__); + return DACI_ERR_DB_HANDLER_MGR; + } + + return isExist_lastAnchor(daci_handler, accountId, itemTypeId); +} + +DACI_RETURN DACI_Add_Mapping(daci_mapping *mapping) +{ + DACI_HANDLER *daci_handler = get_agentHandler(DACI_GET_THREAD_ID); + if (daci_handler == 0) { + FW_LOGE("[%s] no handler for key\n", __func__); + return DACI_ERR_DB_HANDLER_MGR; + } + + return add_mapping(daci_handler, mapping); +} + +DACI_RETURN DACI_Delete_Mapping_By_Account_Id(int accountId) +{ + DACI_HANDLER *daci_handler = get_agentHandler(DACI_GET_THREAD_ID); + if (daci_handler == 0) { + FW_LOGE("[%s] no handler for key\n", __func__); + return DACI_ERR_DB_HANDLER_MGR; + } + + return delete_mappingByAccountId(daci_handler, accountId); +} + +DACI_RETURN DACI_Delete_Mapping_By_Luid(int accountId, char *luid) +{ + DACI_HANDLER *daci_handler = get_agentHandler(DACI_GET_THREAD_ID); + if (daci_handler == 0) { + FW_LOGE("[%s] no handler for key\n", __func__); + return DACI_ERR_DB_HANDLER_MGR; + } + + return delete_mappingByLuid(daci_handler, accountId, luid); +} + +daci_mapping *DACI_Get_Mapping_By_Account_Id(int accountId, int *count) +{ + DACI_HANDLER *daci_handler = get_agentHandler(DACI_GET_THREAD_ID); + if (daci_handler == 0) { + FW_LOGE("[%s] no handler for key\n", __func__); + return 0; + } + + return get_mappingByAccountId(daci_handler, accountId, count); +} + +char *DACI_Get_Mapping_Guid(int accountId, char *luid) +{ + DACI_HANDLER *daci_handler = get_agentHandler(DACI_GET_THREAD_ID); + if (daci_handler == 0) { + FW_LOGE("[%s] no handler for key\n", __func__); + return 0; + } + + return get_mappingGuid(daci_handler, accountId, luid); +} + +int DACI_IsExist_Mapping_By_Account_Id(int accountId) +{ + DACI_HANDLER *daci_handler = get_agentHandler(DACI_GET_THREAD_ID); + if (daci_handler == 0) { + FW_LOGE("[%s] no handler for key\n", __func__); + return DACI_ERR_DB_HANDLER_MGR; + } + + return isExist_mappingByAccountId(daci_handler, accountId); +} + +int DACI_IsExist_Mapping_By_Luid(int accountId, char *luid) +{ + DACI_HANDLER *daci_handler = get_agentHandler(DACI_GET_THREAD_ID); + if (daci_handler == 0) { + FW_LOGE("[%s] no handler for key\n", __func__); + return DACI_ERR_DB_HANDLER_MGR; + } + + return isExist_mappingByLuid(daci_handler, accountId, luid); +} + +DACI_RETURN DACI_Add_ID_Provider(daci_id_provider *id_provider) +{ + DACI_HANDLER *daci_handler = get_agentHandler(DACI_GET_THREAD_ID); + if (daci_handler == 0) { + FW_LOGE("[%s] no handler for key\n", __func__); + return DACI_ERR_DB_HANDLER_MGR; + } + + return add_id_provider(daci_handler, id_provider); +} + +DACI_RETURN DACI_Get_ID_Provider(unsigned int id_provider_code, daci_id_provider **id_provider) +{ + DACI_HANDLER *daci_handler = get_agentHandler(DACI_GET_THREAD_ID); + if (daci_handler == 0) { + FW_LOGE("[%s] no handler for key\n", __func__); + return DACI_ERR_DB_HANDLER_MGR; + } + + return get_id_provider(daci_handler, id_provider_code, id_provider); +} + +DACI_RETURN DACI_Update_ID_Provider(daci_id_provider *id_provider) +{ + DACI_HANDLER *daci_handler = get_agentHandler(DACI_GET_THREAD_ID); + if (daci_handler == 0) { + FW_LOGE("[%s] no handler for key\n", __func__); + return DACI_ERR_DB_HANDLER_MGR; + } + + return update_id_provider(daci_handler, id_provider); +} + +DACI_RETURN DACI_Add_ID_Page(daci_id_page *id_page, unsigned int page_byte_size) +{ + DACI_HANDLER *daci_handler = get_agentHandler(DACI_GET_THREAD_ID); + if (daci_handler == 0) { + FW_LOGE("[%s] no handler for key\n", __func__); + return DACI_ERR_DB_HANDLER_MGR; + } + + return add_id_page(daci_handler, id_page, page_byte_size); +} + +DACI_RETURN DACI_Delete_ID_Page(unsigned int id_provider_code, unsigned int page_index) +{ + DACI_HANDLER *daci_handler = get_agentHandler(DACI_GET_THREAD_ID); + if (daci_handler == 0) { + FW_LOGE("[%s] no handler for key\n", __func__); + return DACI_ERR_DB_HANDLER_MGR; + } + + return delete_id_page(daci_handler, id_provider_code, page_index); +} + +DACI_RETURN DACI_Get_ID_Page(unsigned int id_provider_code, unsigned int page_index, char **page_bit) +{ + DACI_HANDLER *daci_handler = get_agentHandler(DACI_GET_THREAD_ID); + if (daci_handler == 0) { + FW_LOGE("[%s] no handler for key\n", __func__); + return DACI_ERR_DB_HANDLER_MGR; + } + + return get_id_page(daci_handler, id_provider_code, page_index, page_bit); +} + +DACI_RETURN DACI_Update_ID_Page(daci_id_page *id_page, unsigned int page_byte_size) +{ + DACI_HANDLER *daci_handler = get_agentHandler(DACI_GET_THREAD_ID); + if (daci_handler == 0) { + FW_LOGE("[%s] no handler for key\n", __func__); + return DACI_ERR_DB_HANDLER_MGR; + } + + return update_id_page(daci_handler, id_page, page_byte_size); +} + +/* + * ================================== + * Data connector module internal API + * ================================== + */ +DACI_RETURN add_agentHandler(unsigned int key, DACI_HANDLER *pHandler) +{ + if (pAgentDBHandlerMgr == 0 || pAgentDBHandlerMgr->daci_handlerTable_mutex == 0) { + return DACI_ERR_DB_HANDLER_MGR; + } + + FW_LOGV("[%s] start !\n", __func__); + DACI_RETURN ret = DACI_SUCCESS; + + unsigned int *pKey_copy = (unsigned int *)malloc(sizeof(unsigned int)); + if (pKey_copy == 0) + return DACI_ERR_DB_HANDLER_MGR; + + *pKey_copy = key; + + pthread_mutex_lock(pAgentDBHandlerMgr->daci_handlerTable_mutex); + if (pAgentDBHandlerMgr->daci_handlerTable == 0) { + ret = __alloc_agent_dc_handlerTable(); + if (ret != DACI_SUCCESS) + goto addagentHandler; + } + + /* insert to handler */ + FW_LOGV("[%s] Key = %d, Handler = %p !\n", __func__, key, pHandler); + g_hash_table_insert(pAgentDBHandlerMgr->daci_handlerTable, pKey_copy, pHandler); + +#ifdef DC_PRINT + /* For test log */ + __print_agentDBHashTableLog(); +#endif + +addagentHandler: + pthread_mutex_unlock(pAgentDBHandlerMgr->daci_handlerTable_mutex); + + FW_LOGV("[%s] end !\n", __func__); + return ret; +} + +DACI_RETURN remove_agentHandler(unsigned int key) +{ + FW_LOGV("[%s] start !\n", __func__); + if (pAgentDBHandlerMgr == 0 || pAgentDBHandlerMgr->daci_handlerTable_mutex == 0 || pAgentDBHandlerMgr->daci_handlerTable == 0) { + return DACI_ERR_DB_HANDLER_MGR; + } + + /* remove the handler to hash table */ + pthread_mutex_lock(pAgentDBHandlerMgr->daci_handlerTable_mutex); + int isSuccess = g_hash_table_remove(pAgentDBHandlerMgr->daci_handlerTable, &key); + pthread_mutex_unlock(pAgentDBHandlerMgr->daci_handlerTable_mutex); + +#ifdef DC_PRINT + /* for test log */ + __print_agentDBHashTableLog(); +#endif + + FW_LOGV("[%s] end !\n", __func__); + if (isSuccess == true) + return DACI_SUCCESS; + + return DACI_ERR_DB_HANDLER_MGR; +} + +DACI_HANDLER *get_agentHandler(unsigned int key) +{ + if (pAgentDBHandlerMgr == 0 || pAgentDBHandlerMgr->daci_handlerTable_mutex == 0 || pAgentDBHandlerMgr->daci_handlerTable == 0) { + FW_LOGV("[%s] DACI_ERR_DB_HANDLER_MGR !\n", __func__); + return 0; + } + + /* get the handler to hash table */ + pthread_mutex_lock(pAgentDBHandlerMgr->daci_handlerTable_mutex); + DACI_HANDLER *pHandler = g_hash_table_lookup(pAgentDBHandlerMgr->daci_handlerTable, &key); + pthread_mutex_unlock(pAgentDBHandlerMgr->daci_handlerTable_mutex); + +#ifdef DC_PRINT + if (pHandler != 0) { + FW_LOGV("[%s] ######### > Value Search Success(key = %d, handler = %p)\n", __func__, key, pHandler); + } else { + FW_LOGV("[%s] ######### > Value Search Fail(key = %d, handler = %p)\n", __func__, key, pHandler); + } +#endif + + return pHandler; +} + +/* static function implementation */ +static DACI_RETURN __alloc_agent_dc_handlerTable() +{ + if (pAgentDBHandlerMgr != 0) { + pAgentDBHandlerMgr->daci_handlerTable = g_hash_table_new_full(g_int_hash, g_int_equal, __destory_agentDBHashTableKey, __destroy_agentDBHashTableValue); + if (pAgentDBHandlerMgr->daci_handlerTable == 0) { + FW_LOGV("[%s] Not Create agent dc handler hash table \n", __func__); + return DACI_ERR_DB_HANDLER_MGR; + } else { + FW_LOGV("[%DACI_ERR_DB_HANDLER_MGRent dc handler hash table \n", __func__); + } + } + + return DACI_SUCCESS; +} + +static DACI_RETURN __alloc_agent_dc_handlerTable_mutex() +{ + if (pAgentDBHandlerMgr != 0) { + + pAgentDBHandlerMgr->daci_handlerTable_mutex = (pthread_mutex_t *)malloc(sizeof(pthread_mutex_t)); + if (pAgentDBHandlerMgr->daci_handlerTable_mutex == 0) { + FW_LOGV("[%s] Not Create agent dc handler hash table mutex \n", __func__); + return DACI_ERR_DB_HANDLER_MGR; + } else { + + if (0 != pthread_mutex_init(pAgentDBHandlerMgr->daci_handlerTable_mutex, 0)) { + FW_LOGV("[%s] Not init agent dc handler hash table mutex\n", __func__); + return DACI_ERR_DB_HANDLER_MGR; + } + FW_LOGV("[%s] Init agent dc handler hash table mutex\n", __func__); + } + } + + return DACI_SUCCESS; +} + +static DACI_RETURN __free_agent_dc_handlerTable() +{ + if (pAgentDBHandlerMgr != 0 && pAgentDBHandlerMgr->daci_handlerTable != 0) { + g_hash_table_destroy(pAgentDBHandlerMgr->daci_handlerTable); + FW_LOGV("[%s] daci_handlerTable free success !\n", __func__); + pAgentDBHandlerMgr->daci_handlerTable = 0;; + } + + return DACI_SUCCESS; +} + +static DACI_RETURN __free_agent_dc_handlerTable_mutex() +{ + if (pAgentDBHandlerMgr != 0 && pAgentDBHandlerMgr->daci_handlerTable_mutex != 0) { + + int ret = pthread_mutex_destroy(pAgentDBHandlerMgr->daci_handlerTable_mutex); + if (ret != 0) { + FW_LOGV("[%s] daci_handlerTable_mutex free error !\n", __func__); + return DACI_ERR_DB_HANDLER_MGR; + } else { + free(pAgentDBHandlerMgr->daci_handlerTable_mutex); + pAgentDBHandlerMgr->daci_handlerTable_mutex = 0; + FW_LOGV("[%s] daci_handlerTable_mutex free success !\n", __func__); + } + } + + return DACI_SUCCESS; +} + +static DACI_RETURN __create_agentDBHandlerMgrInfo() +{ + DACI_RETURN ret = DACI_SUCCESS; + + if (pAgentDBHandlerMgr != 0) { + + /* alloc agent db hander hash table */ + ret = __alloc_agent_dc_handlerTable(); + if (ret != DACI_SUCCESS) + goto allocAgentDBHandlerMgrInfoErr; + + /* alloc agent db hander hash table mutex */ + ret = __alloc_agent_dc_handlerTable_mutex(); + if (ret != DACI_SUCCESS) + goto allocAgentDBHandlerMgrInfoErr; + } + + return DACI_SUCCESS; + +allocAgentDBHandlerMgrInfoErr: + DACI_Free_AgentDB_Handler_Mgr(); + return DACI_ERR_DB_HANDLER_MGR; +} + +static void __destroy_agentDBHashTableValue(void *pHandler) +{ + FW_LOGV("[%s] start \n", __func__); + if (pHandler != 0) { + close_Agent((DACI_HANDLER *)pHandler); + } + FW_LOGV("[%s] end \n", __func__); +} + +static void __destory_agentDBHashTableKey(void *key) +{ + FW_LOGV("[%s] start \n", __func__); + if (key != 0) + free(key); + FW_LOGV("[%s] end \n", __func__); +} diff --git a/framework/src/DataAdapter/DACI_Agent_Mgr.c b/framework/src/DataAdapter/DACI_Agent_Mgr.c new file mode 100755 index 0000000..32b1ac4 --- /dev/null +++ b/framework/src/DataAdapter/DACI_Agent_Mgr.c @@ -0,0 +1,571 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu , + * Heeyoung Hwang + */ + +#include + +#include "Initialization/initialize_parser.h" + +#include "Utility/fw_alloc.h" +#include "Utility/fw_log.h" + +#include "PlugIn/PlugIn_DataConnector.h" +#include "PlugIn/PlugIn_Account.h" + +#include "Account/Account_Util.h" + +#include "DACI_ChangeLog.h" +#include "DACI_Luid.h" + +#include "DACI_Agent_Handler_Manager.h" + +#include "DACI_Agent_Mgr.h" + +#define LOG_TAG "AF_DACI" + +/* + * Key : db/Apps/AgentFramework/[Agent Name]/ServiceChangePoint/[FW AccountID]/[Service_Type] + * Value : Change Point (TimeStamp) + */ +#define VCONF_KEY_SERIVCE_CHANGEPOINT "db/Apps/AgentFramework/%s/ServiceChangePoint/%d/%d" + +static void __set_Serivce_ChangePoint(int fw_account_id, int service_type, int change_point); + +static int __get_Serivce_ChangePoint(int fw_account_id, int service_type); + +static DACI_RETURN __construct_ChangeLogTbl_From_Service(int fw_account_id, int service_type); + +DACI_RETURN construct_ItemTbl_From_Service(int fw_account_id, int service_type) +{ + DACI_RETURN err_code = DACI_SUCCESS; + + err_code = __construct_ChangeLogTbl_From_Service(fw_account_id, service_type); + + return err_code; +} + +DACI_RETURN construct_FolderTbl_From_Service(int service_type) +{ + int fw_account_cnt = 0; + int *fw_account_id_list = DACI_Get_Account_Account_Id_List(&fw_account_cnt); + + if (fw_account_id_list == 0 || fw_account_cnt == 0) { + return DACI_SUCCESS; + } + + int *service_account_id_list = 0; + if (fw_account_cnt != 0) { + service_account_id_list = (int *)calloc(fw_account_cnt, sizeof(int)); + int i = 0; + for (; i < fw_account_cnt; i++) { + service_account_id_list[i] = getAccountID_Service(service_type, fw_account_id_list[i]); + FW_LOGV("service_account_id_list[%d] : %d", i, service_account_id_list[i]); + } + } + + int service_account_id_cnt = fw_account_cnt; + FW_LOGV("service_account_id_cnt : %d", service_account_id_cnt); + + int i = 0; + for (; i < service_account_id_cnt; i++) { + int fw_account_id = getAccountID_FW(service_type, service_account_id_list[i], 0); + FW_LOGV("fw_account_id[%d] : %d", i, fw_account_id); + + GET_FOLDER_ID_LIST pFunc_GET_FOLDER_ID_LIST = getFunction_DataConnector_GET_FOLDER_ID_LIST(service_type); + int service_folder_cnt = 0; + int *service_folder_type_list = 0; + char **service_folder_list = pFunc_GET_FOLDER_ID_LIST(service_account_id_list[i], &service_folder_cnt, &service_folder_type_list); + FW_LOGV("service_folder_cnt : %d", service_folder_cnt); + +/* + //Hard Coding - If account has one folder, consider folder' state complete. + + t_daci_id_list_t *foder_id_list_info = T_DACI_Get_Folder_Folder_Id_List_By_Account_Id(fw_account_id); + + if (foder_id_list_info != 0) { + if (foder_id_list_info->count > 0) { + FW_LOGV("foder_id_list_info->count : %d", foder_id_list_info->count); + return DACI_SUCCESS; + } + }*/ + + int i = 0; + for (; i < service_folder_cnt; i++) { + + /* checking whether the service_id exist in Folder table */ + char *temp_folder_id = DACI_Get_Folder_Folder_Id_By_Service_Id(fw_account_id, service_type, service_folder_list[i], service_folder_type_list[i]); + + FW_LOGV("fw_account_id : %d", fw_account_id); + FW_LOGV("service_folder_list[i] : %s", service_folder_list[i]); + FW_LOGV("service_folder_type_list[i] : %d", service_folder_type_list[i]); + FW_LOGV("temp_folder_id : %s", temp_folder_id); + if (temp_folder_id != 0) { + free(temp_folder_id); + } else { + /* Add Agent Folder table */ + daci_folder folder; + folder.account_id = fw_account_id; + folder.folder_id = DACI_Generate_Folder_Luid(); + folder.parent_folder_id = "0"; + folder.data_store_id = service_type; + folder.folder_type_id = service_folder_type_list[i]; + folder.service_id = service_folder_list[i]; + folder.access_name = "DACI"; + + DACI_Add_Folder(&folder, 1); + } + } + } + + if (fw_account_id_list != 0) { + free(fw_account_id_list); + } + + return DACI_SUCCESS; +} + +DACI_RETURN refresh_Item_Tbl_From_Service(int fw_account_id, int service_type) +{ + /* + * todo Delete folder table + */ + + /* + * Delete Changelog table + */ + DACI_Delete_Item_Changelog_By_Item_Type_Id(fw_account_id, service_type); + + /* + * Delete item table + */ + DACI_Delete_Item_By_Item_Type_Id(fw_account_id, service_type); + + /* + * todo Insert folder table + */ + + /* + * insert item table + */ + GET_CHANED_ITEM_FOR_FOLDER_ADD pFunc_GET_CHANED_ITEM_FOR_FOLDER_ADD = getFunction_DataConnector_GET_CHANED_ITEM_FOR_FOLDER_ADD(service_type); + GET_CHANED_ITEM_FOR_FOLDER_UPDATE pFunc_GET_CHANED_ITEM_FOR_FOLDER_UPDATE = getFunction_DataConnector_GET_CHANED_ITEM_FOR_FOLDER_UPDATE(service_type); + + int service_account_id = getAccountID_Service(service_type, fw_account_id); + FW_LOGV("service_account_id : %d", service_account_id); + + daci_id_list *fw_folder_id_list_info = DACI_Get_Folder_Folder_Id_List_By_Item_Type_Id(fw_account_id, service_type); + + char **fw_folder_id_list = 0; + int fw_folder_id_cnt = 0; + if (fw_folder_id_list_info != 0) { + fw_folder_id_list = fw_folder_id_list_info->id; + fw_folder_id_cnt = fw_folder_id_list_info->count; + + FW_LOGV("fw_folder_id_cnt : %d", fw_folder_id_cnt); + FW_LOGV("fw_folder_id_list[0] : %s", fw_folder_id_list_info->id[0]); + FW_LOGV("fw_folder_id_list[0] : %s", fw_folder_id_list[0]); + } + + int i = 0; + for (; i < fw_folder_id_cnt; i++) { + FW_LOGV("fw_folder_id_list[%d] : %s", i, fw_folder_id_list[i]); + + char *service_folder_id = DACI_Get_Folder_Service_Id(fw_folder_id_list[i]); + + FW_LOGV("service_folder_id : %s", service_folder_id); + + int added_item_cnt = 0; + Item_Node *added_service_item_id_list = pFunc_GET_CHANED_ITEM_FOR_FOLDER_ADD(service_account_id, service_folder_id, 0, &added_item_cnt); + Item_Node *cursor_ptr = added_service_item_id_list; + + FW_LOGV("added_item_cnt : %d", added_item_cnt); + + /* + * Process Add Item + */ + DACI_Begin_Transaction(); + char **fw_item_id_list = DACI_Generate_Item_Luid(1, added_item_cnt); + if (fw_item_id_list != 0) { + int y = 0; + for (; y < added_item_cnt; y++) { + daci_item item; + item.account_id = fw_account_id; + item.item_id = fw_item_id_list[y]; + item.folder_id = fw_folder_id_list[i]; + item.data_store_id = service_type; + item.service_id = cursor_ptr->item_id; + item.access_name = "DACI"; + + DACI_RETURN ret = DACI_Add_Item(&item, 1); + if (ret != DACI_SUCCESS) { + FW_LOGE("add item failed return : %d", ret); + } + + Item_Node *temp = cursor_ptr; + cursor_ptr = cursor_ptr->next; + free(temp->item_id); + free(temp); + + if (fw_item_id_list[y] != 0) { + free(fw_item_id_list[y]); + } + } + free(fw_item_id_list); + } + DACI_End_Transaction(TRANSACTION_COMMIT); + + /* + * Process Update Item + */ + int updated_item_cnt = 0; + Item_Node *updated_service_item_id_list = pFunc_GET_CHANED_ITEM_FOR_FOLDER_UPDATE(service_account_id, service_folder_id, 0, &updated_item_cnt); + cursor_ptr = updated_service_item_id_list; + + FW_LOGV("updated_item_cnt : %d", updated_item_cnt); + + DACI_Begin_Transaction(); + fw_item_id_list = DACI_Generate_Item_Luid(1, updated_item_cnt); + if (fw_item_id_list != 0) { + int y = 0; + for (; y < updated_item_cnt; y++) { + daci_item item; + item.account_id = fw_account_id; + item.item_id = fw_item_id_list[y]; + item.folder_id = fw_folder_id_list[i]; + item.data_store_id = service_type; + item.service_id = cursor_ptr->item_id; + item.access_name = "DACI"; + + DACI_RETURN ret = DACI_Add_Item(&item, 1); + if (ret != DACI_SUCCESS) { + FW_LOGE("add item failed return : %d", ret); + } + + Item_Node *temp = cursor_ptr; + cursor_ptr = cursor_ptr->next; + free(temp->item_id); + free(temp); + + if (fw_item_id_list[y] != 0) { + free(fw_item_id_list[y]); + } + } + free(fw_item_id_list); + } + DACI_End_Transaction(TRANSACTION_COMMIT); + + if (fw_folder_id_list[i] != 0) { + free(fw_folder_id_list[i]); + } + + if (service_folder_id != 0) { + free(service_folder_id); + } + } + + if (fw_folder_id_list_info != 0) { + if (fw_folder_id_list_info->id != 0) { + free(fw_folder_id_list_info->id); + } + free(fw_folder_id_list_info); + } + + return DACI_SUCCESS; +} + +DACI_RETURN refresh_ChangeLog_Tbl_From_Service(int fw_account_id, int service_type) +{ + DACI_RETURN ret = DACI_SUCCESS; + + /* + * Delete Changelog table + */ + ret = DACI_Delete_Item_Changelog_By_Item_Type_Id(fw_account_id, service_type); + + /* + * Delete item table + */ + ret = DACI_Delete_Item_By_Item_Type_Id(fw_account_id, service_type); + + /* + * Construct Item & changelog table + */ + GET_CHANED_ITEM_FOR_FOLDER_ADD pFunc_GET_CHANED_ITEM_FOR_FOLDER_ADD = getFunction_DataConnector_GET_CHANED_ITEM_FOR_FOLDER_ADD(service_type); + + int service_account_id = getAccountID_Service(service_type, fw_account_id); + FW_LOGV("service_account_id : %d", service_account_id); + + daci_id_list *fw_folder_id_list_info = DACI_Get_Folder_Folder_Id_List_By_Item_Type_Id(fw_account_id, service_type); + + char **fw_folder_id_list = 0; + int fw_folder_id_cnt = 0; + if (fw_folder_id_list_info != 0) { + fw_folder_id_list = fw_folder_id_list_info->id; + fw_folder_id_cnt = fw_folder_id_list_info->count; + + FW_LOGV("[RJW] fw_folder_id_cnt : %d", fw_folder_id_cnt); + FW_LOGV("[RJW] fw_folder_id_list[0] : %s", fw_folder_id_list_info->id[0]); + FW_LOGV("[RJW] fw_folder_id_list[0] : %s", fw_folder_id_list[0]); + } + + int i = 0; + for (; i < fw_folder_id_cnt; i++) { + FW_LOGV("fw_folder_id_list[%d] : %s", i, fw_folder_id_list[i]); + + char *service_folder_id = DACI_Get_Folder_Service_Id(fw_folder_id_list[i]); + + FW_LOGV("service_folder_id : %s", service_folder_id); + + int item_cnt = 0; + Item_Node *service_item_id_list = pFunc_GET_CHANED_ITEM_FOR_FOLDER_ADD(service_account_id, service_folder_id, 0, &item_cnt); + Item_Node *cursor_ptr = service_item_id_list; + + FW_LOGV("item_cnt : %d", item_cnt); + + DACI_Begin_Transaction(); + char **fw_item_id_list = DACI_Generate_Item_Luid(1, item_cnt); + if (fw_item_id_list != 0 ) { + int k = 0; + for (; k < item_cnt; k++) { + char *service_item_id = cursor_ptr->item_id; + FW_LOGV("service_item_id[%d] : %s", k, service_item_id); + FW_LOGV("fw_item_id : %s", fw_item_id_list[k]); + + ChangeLog_Add_Item(fw_account_id, fw_item_id_list[k], cursor_ptr->item_id, service_type, fw_folder_id_list[i]); + + Item_Node *temp = cursor_ptr; + cursor_ptr = cursor_ptr->next; + free(temp->item_id); + free(temp); + if (fw_item_id_list[k] != 0) { + free(fw_item_id_list[k]); + } + } + free(fw_item_id_list); + } + DACI_End_Transaction(TRANSACTION_COMMIT); + } + + return ret; +} + +DACI_RETURN set_ChangePoint_Service(int fw_account_id, int service_type) +{ + GET_LAST_CHANGEPOINT pFunc_GET_LAST_CHANGEPOINT = getFunction_DataConnector_GET_LAST_CHANGEPOINT(service_type); + + int new_last_change_point = pFunc_GET_LAST_CHANGEPOINT(); + + FW_LOGV("new_last_change_point : %d", new_last_change_point); + + __set_Serivce_ChangePoint(fw_account_id, service_type, new_last_change_point); + + return DACI_SUCCESS; +} + +/********************************************* static function ****************************/ + +static void __set_Serivce_ChangePoint(int fw_account_id, int service_type, int change_point) +{ + const char *agent_key = get_AgentKey(); + + char vConfKey[100]; + sprintf(vConfKey, VCONF_KEY_SERIVCE_CHANGEPOINT, agent_key, fw_account_id, service_type); + + FW_LOGV("vConfKey : %s", vConfKey); + + if (vconf_set_int(vConfKey, change_point)) { + FW_LOGE("vconf_set_id FAIL"); + } else { + FW_LOGV("Sucess Vconf Set Id"); + } +} + +static int __get_Serivce_ChangePoint(int fw_account_id, int service_type) +{ + const char *agent_key = get_AgentKey(); + + char vConfKey[100]; + sprintf(vConfKey, VCONF_KEY_SERIVCE_CHANGEPOINT, agent_key, fw_account_id, service_type); + + int change_point = 0; + if (vconf_get_int(vConfKey, &change_point)) { + FW_LOGV("vconf_set_id FAIL - First attempt??"); + return 0; + } + + return change_point; +} + +DACI_RETURN __construct_ChangeLogTbl_From_Service(int fw_account_id, int service_type) +{ + int service_account_id = getAccountID_Service(service_type, fw_account_id); + FW_LOGV("service_account_id : %d", service_account_id); + + int changed_flag = 0; + int fw_change_point = __get_Serivce_ChangePoint(fw_account_id, service_type); + FW_LOGV("fw_last_change_point : %d", fw_change_point); + + GET_CHANED_ITEM_FOR_FOLDER_ADD pFunc_GET_CHANED_ITEM_FOR_FOLDER_ADD = getFunction_DataConnector_GET_CHANED_ITEM_FOR_FOLDER_ADD(service_type); + GET_CHANED_ITEM_FOR_FOLDER_DEL pFunc_GET_CHANED_ITEM_FOR_FOLDER_DEL = getFunction_DataConnector_GET_CHANED_ITEM_FOR_FOLDER_DEL(service_type); + GET_CHANED_ITEM_FOR_FOLDER_UPDATE pFunc_GET_CHANED_ITEM_FOR_FOLDER_UPDATE = getFunction_DataConnector_GET_CHANED_ITEM_FOR_FOLDER_UPDATE(service_type); + + /* + * todo Get fw_folder_id list in the service + */ + daci_id_list *fw_folder_id_list_info = DACI_Get_Folder_Folder_Id_List_By_Item_Type_Id(fw_account_id, service_type); + + char **fw_folder_id_list = 0; + int fw_folder_id_cnt = 0; + if (fw_folder_id_list_info != 0) { + fw_folder_id_list = fw_folder_id_list_info->id; + fw_folder_id_cnt = fw_folder_id_list_info->count; + + FW_LOGV("fw_folder_id_cnt : %d", fw_folder_id_cnt); + FW_LOGV("fw_folder_id_list[0] : %s", fw_folder_id_list_info->id[0]); + FW_LOGV("fw_folder_id_list[0] : %s", fw_folder_id_list[0]); + } + + int i = 0; + for (; i < fw_folder_id_cnt; i++) { + FW_LOGV("fw_folder_id_list[%d] : %s", i, fw_folder_id_list[i]); + + char *service_folder_id = DACI_Get_Folder_Service_Id(fw_folder_id_list[i]); + FW_LOGV("service_folder_id : %s", service_folder_id); + + /* + * 1. Process Add Item + */ + int added_item_cnt = 0; + Item_Node *added_service_item_id_list = pFunc_GET_CHANED_ITEM_FOR_FOLDER_ADD(service_account_id, service_folder_id, fw_change_point, &added_item_cnt); + Item_Node *cursor_ptr = added_service_item_id_list; + + FW_LOGV("added_item_cnt : %d", added_item_cnt); + if (added_item_cnt > 0) { + changed_flag = 1; + } + + char **fw_item_id_list = DACI_Generate_Item_Luid(1, added_item_cnt); + int y = 0; + for (; y < added_item_cnt; y++) { + ChangeLog_Add_Item(fw_account_id, fw_item_id_list[y], cursor_ptr->item_id, service_type, fw_folder_id_list[i]); + Item_Node *temp = cursor_ptr; + cursor_ptr = cursor_ptr->next; + free(temp->item_id); + free(temp); + free(fw_item_id_list[y]); + } + + if (fw_item_id_list != 0) { + free(fw_item_id_list); + } + + /* + * 2. Process Delete Item + */ + int deleted_item_cnt = 0; + Item_Node *deleted_service_item_id_list = pFunc_GET_CHANED_ITEM_FOR_FOLDER_DEL(service_account_id, service_folder_id, fw_change_point, &deleted_item_cnt); + cursor_ptr = deleted_service_item_id_list; + + FW_LOGV("deleted_item_cnt : %d", deleted_item_cnt); + if (deleted_item_cnt > 0) { + changed_flag = 1; + } + + y = 0; + for (; y < deleted_item_cnt; y++) { + char *fw_item_id = DACI_Get_Item_Item_Id(fw_account_id, cursor_ptr->item_id, service_type); + Item_Node *temp = cursor_ptr; + cursor_ptr = cursor_ptr->next; + free(temp->item_id); + free(temp); + + ChangeLog_Delete_Item(fw_account_id, fw_item_id, service_type); + + free(fw_item_id); + } + + /* + * 3. Process Update Item + */ + int updated_item_cnt = 0; + Item_Node *updated_service_item_id_list = pFunc_GET_CHANED_ITEM_FOR_FOLDER_UPDATE(service_account_id, service_folder_id, fw_change_point, &updated_item_cnt); + cursor_ptr = updated_service_item_id_list; + + FW_LOGV("updated_item_cnt : %d", updated_item_cnt); + if (updated_item_cnt > 0) { + changed_flag = 1; + } + + fw_item_id_list = DACI_Generate_Item_Luid(1, updated_item_cnt); + y = 0; + for (; fw_item_id_list != 0 || y < updated_item_cnt; y++) { + char *fw_item_id = DACI_Get_Item_Item_Id(fw_account_id, cursor_ptr->item_id, service_type); + + if (fw_item_id == 0) { + ChangeLog_Add_Item(fw_account_id, fw_item_id_list[y], cursor_ptr->item_id, service_type, fw_folder_id_list[i]); + } else { + ChangeLog_Update_Item(fw_account_id, fw_item_id, service_type); + } + + Item_Node *temp = cursor_ptr; + cursor_ptr = cursor_ptr->next; + free(temp->item_id); + free(temp); + + if (fw_item_id_list[y] != 0) { + free(fw_item_id_list[y]); + } + + if (fw_item_id != 0) { + free(fw_item_id); + } + } + + if (fw_folder_id_list[i] != NULL) + free(fw_folder_id_list[i]); + + if (service_folder_id != NULL) + free(service_folder_id); + } + + if (fw_folder_id_list_info != 0) { + if (fw_folder_id_list_info->id != 0) { + free(fw_folder_id_list_info->id); + } + free(fw_folder_id_list_info); + } + + return DACI_SUCCESS; +} diff --git a/framework/src/DataAdapter/DACI_ChangeLog.c b/framework/src/DataAdapter/DACI_ChangeLog.c new file mode 100755 index 0000000..2ff7a88 --- /dev/null +++ b/framework/src/DataAdapter/DACI_ChangeLog.c @@ -0,0 +1,641 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu , + * Seokgil Kang + */ + +#include +#include + +#include "Utility/fw_log.h" +#include "Utility/fw_alloc.h" + +#include "Account/Account_Util.h" + +#include "DataAdapter/DACI_Agent_Handler_Manager.h" +#include "DataAdapter/DACI_Common.h" +#include "DataAdapter/DACI_Luid.h" + +#include "DataAdapter/DACI_ChangeLog.h" + +#define LOG_TAG "AF_DACI" + +static pthread_mutex_t change_lock; + +int handle_ADD_ITEM(int service_accountID, int index, char *service_itemID, int itemType, char *service_folderID, int folderType) +{ + /* + * TODO : 1. Need to Null check parameter + * 2. converting type : itemType, folderType + * 3. get fw id : accountID, folderID + * 4. check whether the item is included + * 5. generate item luid + * 6. add item & change log + */ + if (pthread_mutex_lock(&change_lock)) { + FW_LOGV("pthread_mutex_lock error\n"); + return 0; + } + + FW_LOGV("Index : %d", index); + FW_LOGV("service_accountID : %d", service_accountID); + FW_LOGV("service_itemID : %s", service_itemID); + FW_LOGV("itemType : %d", itemType); + FW_LOGV("service_folderID : %s", service_folderID); + FW_LOGV("folderType : %d", folderType); + + DACI_RETURN ret = DACI_ERRORS; + DACI_RETURN open_ret = DACI_SUCCESS; + char *fw_folder_id = 0; + char *fw_item_id = 0; + char **fw_item_id_list = 0; + daci_item item; + daci_item_changelog item_changelog; + + open_ret = DACI_Open_Agent(); + FW_LOGV("Done Open Agent DB : %d", open_ret); + + /* + * if folderID value is NULL ==> folderID set NULL + */ + if ((service_folderID != 0) && !strcmp(service_folderID, "")) + service_folderID = 0; + + /* + * get fw account id + */ + int fw_account_id = getAccountID_FW(itemType, service_accountID, index); + FW_LOGV("fw_account_id : %d", fw_account_id); + + if (fw_account_id == -1) { + FW_LOGE("fw account id does not exist"); + goto DACI_FINISH; + } + + /* + * get fw folder id + */ + fw_folder_id = DACI_Get_Folder_Folder_Id_By_Service_Id(fw_account_id, itemType, service_folderID, folderType); + if (fw_folder_id == 0) { + FW_LOGE("fw folder id does not exist"); + goto DACI_FINISH; + } + + /* + * check whether the item is included + */ + fw_item_id = DACI_Get_Item_Item_Id(fw_account_id, service_itemID, itemType); + if (fw_item_id != 0) { + FW_LOGE("fw item already exists : %s", fw_item_id); + goto DACI_FINISH; + } + + /* + * generate item luid + */ + fw_item_id_list = DACI_Generate_Item_Luid(1, 1); + if (fw_item_id_list == 0) { + FW_LOGE("Failed to Generate Item LUID"); + goto DACI_FINISH; + } + + fw_item_id = fw_item_id_list[0]; + if (fw_item_id == 0) { + FW_LOGE("Failed to Generate Item LUID"); + goto DACI_FINISH; + } + + /* + * add item + */ + item.account_id = fw_account_id; + item.item_id = fw_item_id; + item.folder_id = fw_folder_id; + item.data_store_id = itemType; + item.service_id = service_itemID; + item.access_name = "DACI_ChangeLog"; + + ret = DACI_Add_Item(&item, 1); + if (ret != DACI_SUCCESS) { + FW_LOGE("Failed to Add Item : %d", ret); + goto DACI_FINISH; + } + + /* + * add change log + */ + item_changelog.item_id = fw_item_id; + item_changelog.operation_id = 301; + item_changelog.status = "SYNC_REQUIRED"; + item_changelog.access_name = "DACI_ChangeLog"; + + ret = DACI_Add_Item_Changelog(fw_account_id, &item_changelog, 1); + if (ret != DACI_SUCCESS) { + FW_LOGE("Failed to Add Item changelog : %d", ret); + goto DACI_FINISH; + } + +DACI_FINISH: + open_ret = DACI_Close_Agent(); + FW_LOGV("Done Close Agent DB : %d", open_ret); + + if (fw_folder_id != 0) { + free(fw_folder_id); + fw_folder_id = 0; + } + if (fw_item_id != 0) { + free(fw_item_id); + fw_item_id = 0; + } + if (fw_item_id_list != 0) { + free(fw_item_id_list); + fw_item_id_list = 0; + } + if (pthread_mutex_unlock(&change_lock)) { + FW_LOGE("pthread_mutex_unlock error\n"); + return 0; + } + + return ret; +} + +int handle_DEL_ITEM(int service_accountID, int index, char *service_itemID, int itemType) +{ + /* + * TODO : 1. Need to Null check parameter + * 2. converting type : itemType + * 3. get fw id : accountID + * 4. check whether the item is included + * 5. check whether the change log is included + * 6. add/update/delete item change log + */ + FW_LOGV("service_accountID : %d", service_accountID); + FW_LOGV("index : %d", index); + FW_LOGV("service_itemID : %s", service_itemID); + FW_LOGV("itemType : %d", itemType); + + DACI_RETURN ret = DACI_ERRORS; + DACI_RETURN open_ret = DACI_SUCCESS; + + char *fw_item_id = 0; + daci_item_changelog item_changelog; + item_changelog.status = 0; + item_changelog.access_name = 0; + + open_ret = DACI_Open_Agent(); + FW_LOGI("Done Open Agent DB : %d", open_ret); + + /* + * get fw account id + */ + int fw_account_id = getAccountID_FW(itemType, service_accountID, index); + if (fw_account_id == -1) { + FW_LOGE("fw account id does not exist"); + goto DACI_FINISH; + } + + /* + * check whether the item is included + */ + fw_item_id = DACI_Get_Item_Item_Id(fw_account_id, service_itemID, itemType); + if (fw_item_id != 0) { + FW_LOGI("Item Already Exists : %s", fw_item_id); + } else { + FW_LOGE("Item is not existed!!"); + goto DACI_FINISH; + } + + /* check whether the change log is included */ + if (DACI_IsExist_Item_Changelog(fw_account_id, fw_item_id)) { + item_changelog.item_id = fw_item_id; + DACI_Get_Item_Changelog_By_Item_Id(fw_account_id, &item_changelog); + + switch (item_changelog.operation_id) { + case 301: /* ADD */ + { + FW_LOGI("Item Changelog Already Exists : ADD Operation"); + ret = DACI_Delete_Item_By_Item_Id(fw_item_id); + if (ret != DACI_SUCCESS) { + FW_LOGE("Failed to Delete Item : %d", ret); + goto DACI_FINISH; + } + + ret = DACI_Delete_Item_Changelog_By_Item_Id(fw_account_id, fw_item_id); + if (ret != DACI_SUCCESS) { + FW_LOGE("Failed to Delete Item Change Log : %d", ret); + goto DACI_FINISH; + } + } + break; + case 302: /* UPDATE */ + { + FW_LOGI("Item Changelog Already Exists : UPDATE Operation"); + item_changelog.operation_id = 303; + ret = DACI_Set_Item_Changelog_Operation_Id(fw_account_id, &item_changelog); + if (ret != DACI_SUCCESS) { + FW_LOGE("Failed to Delete Item : %d", ret); + goto DACI_FINISH; + } + } + break; + case 303: /* DELETE */ + { + FW_LOGI("Item Changelog Already Exists : DELETE Operation"); + } + break; + } + + } else { + /* + * add change log + */ + item_changelog.item_id = fw_item_id; + item_changelog.operation_id = 303; + item_changelog.status = strdup("SYNC_REQUIRED"); + item_changelog.access_name = strdup("DACI_ChangeLog"); + + ret = DACI_Add_Item_Changelog(fw_account_id, &item_changelog, 1); + if (ret != DACI_SUCCESS) { + FW_LOGE("Failed to Add Item Change Log : %d", ret); + goto DACI_FINISH; + } + } + +DACI_FINISH: + open_ret = DACI_Close_Agent(); + FW_LOGI("Done Close Agent DB : %d", open_ret); + + if (fw_item_id != 0) { + free(fw_item_id); + fw_item_id = 0; + } + if (item_changelog.status != 0) { + free(item_changelog.status); + item_changelog.status = 0; + } + if (item_changelog.access_name != 0) { + free(item_changelog.access_name); + item_changelog.access_name = 0; + } + + return ret; +} + +int handle_UPDATE_ITEM(int service_accountID, int index, char *service_itemID, int itemType) +{ + /* + * TODO : 1. Need to Null check parameter + * 2. converting type : itemType + * 3. get fw id : accountID + * 4. check whether the item is included + * 5. check whether the change log is included + * 6. add item change log + */ + + FW_LOGV("service_accountID : %d", service_accountID); + FW_LOGV("service_itemID : %s", service_itemID); + FW_LOGV("itemType : %d", itemType); + + DACI_RETURN ret = DACI_ERRORS; + DACI_RETURN open_ret = DACI_SUCCESS; + + char *fw_item_id = 0; + daci_item_changelog item_changelog; + item_changelog.status = 0; + item_changelog.access_name = 0; + + open_ret = DACI_Open_Agent(); + FW_LOGV("Done Open Agent DB : %d", open_ret); + + /* + * get fw account id + */ + int fw_account_id = getAccountID_FW(itemType, service_accountID, index); + if (fw_account_id == -1) { + FW_LOGE("fw account id does not exist"); + goto DACI_FINISH; + } + + /* + * check whether the item is included + */ + fw_item_id = DACI_Get_Item_Item_Id(fw_account_id, service_itemID, itemType); + if (fw_item_id != 0) { + FW_LOGV("Item Already Exists : %s", fw_item_id); + } else { + FW_LOGE("Item is Not Existed!!"); + goto DACI_FINISH; + } + + /* + * check whether the change log is included + */ + if (DACI_IsExist_Item_Changelog(fw_account_id, fw_item_id)) { + item_changelog.item_id = fw_item_id; + DACI_Get_Item_Changelog_By_Item_Id(fw_account_id, &item_changelog); + + if (item_changelog.operation_id == 303) { /* DELETE */ + FW_LOGE("Already Deleted Item : %s", fw_item_id); + goto DACI_FINISH; + } + } else { + /* + * add change log + */ + item_changelog.item_id = fw_item_id; + item_changelog.operation_id = 302; + item_changelog.status = strdup("SYNC_REQUIRED"); + item_changelog.access_name = strdup("DACI_ChangeLog"); + + ret = DACI_Add_Item_Changelog(fw_account_id, &item_changelog, 1); + if (ret != DACI_SUCCESS) { + FW_LOGE("Failed to Add Item Change Log : %d", ret); + goto DACI_FINISH; + } + } + +DACI_FINISH: + open_ret = DACI_Close_Agent(); + FW_LOGI("Done Close Agent DB : %d", open_ret); + + if (fw_item_id != 0) { + free(fw_item_id); + fw_item_id = 0; + } + if (item_changelog.status != 0) { + free(item_changelog.status); + item_changelog.status = 0; + } + if (item_changelog.access_name != 0) { + free(item_changelog.access_name); + item_changelog.access_name = 0; + } + + return ret; +} + +int ChangeLog_Add_Item(int fw_account_id, char *fw_item_id, char *service_item_id, int itemType, char *fw_folder_id) +{ + /* + * TODO : 1. Need to Null check parameter + * 2. converting type : itemType + * 3. check whether the item is included + * 4. generate item luid + * 5. add item & change log + */ + FW_LOGV("fw_account_id : %d", fw_account_id); + FW_LOGV("fw_item_id : %s", fw_item_id); + FW_LOGV("service_item_id : %s", service_item_id); + FW_LOGV("itemType : %d", itemType); + FW_LOGV("fw_folder_id : %s", fw_folder_id); + + DACI_RETURN ret = DACI_ERRORS; + + daci_item item; + daci_item_changelog item_changelog; + + /* + * check whether the item is included + */ + char *item_id = DACI_Get_Item_Item_Id(fw_account_id, service_item_id, itemType); + if (item_id != 0) { + FW_LOGE("Item already exists : %s", item_id); + goto DACI_FINISH; + } + + /* + * add item + */ + item.account_id = fw_account_id; + item.item_id = fw_item_id; + item.folder_id = fw_folder_id; + item.data_store_id = itemType; + item.service_id = service_item_id; + item.access_name = "DACI_ChangeLog"; + + ret = DACI_Add_Item(&item, 1); + if (ret != DACI_SUCCESS) { + FW_LOGE("add item failed return : %d", ret); + goto DACI_FINISH; + } + + /* + * add change log + */ + item_changelog.item_id = fw_item_id; + item_changelog.operation_id = 301; + item_changelog.status = "SYNC_REQUIRED"; + item_changelog.access_name = "DACI_ChangeLog"; + + ret = DACI_Add_Item_Changelog(fw_account_id, &item_changelog, 1); + if (ret != DACI_SUCCESS) { + FW_LOGE("add item changelog failed return : %d", ret); + goto DACI_FINISH; + } + +DACI_FINISH: + if (item_id != 0) { + free(item_id); + } + + return ret; +} + +int ChangeLog_Delete_Item(int fw_account_id, char *fw_item_id, int itemType) +{ + /* + * TODO : 1. Need to Null check parameter + * 2. check whether the item is included + * 3. check whether the change log is included + * 4. add/update/delete item change log + */ + FW_LOGV("fw_account_id : %d", fw_account_id); + FW_LOGV("fw_item_id : %s", fw_item_id); + FW_LOGV("itemType : %d", itemType); + + DACI_RETURN ret = DACI_ERRORS; + + daci_item_changelog item_changelog; + item_changelog.status = 0; + item_changelog.access_name = 0; + + /* + * check whether the item is included + */ + ret = DACI_IsExist_Item(fw_item_id); + if (ret == 1) { + FW_LOGV("Item already exists : %s", fw_item_id); + } else { + FW_LOGE("Item is not existed!!"); + goto DACI_FINISH; + } + + /* + * check whether the change log is included + */ + if (DACI_IsExist_Item_Changelog(fw_account_id, fw_item_id)) { + item_changelog.item_id = fw_item_id; + DACI_Get_Item_Changelog_By_Item_Id(fw_account_id, &item_changelog); + + switch (item_changelog.operation_id) { + case 301: /* ADD */ + { + FW_LOGI("Item changelog already exists : ADD Operation"); + ret = DACI_Delete_Item_By_Item_Id(fw_item_id); + if (ret != DACI_SUCCESS) { + FW_LOGE("Failed to Delete Item : %d", ret); + goto DACI_FINISH; + } + + ret = DACI_Delete_Item_Changelog_By_Item_Id(fw_account_id, fw_item_id); + if (ret != DACI_SUCCESS) { + FW_LOGE("Failed to Delete Item Change Log : %d", ret); + goto DACI_FINISH; + } + } + break; + case 302: /* UPDATE */ + { + FW_LOGV("Item Changelog Already Exists : UPDATE Operation"); + item_changelog.operation_id = 303; + ret = DACI_Set_Item_Changelog_Operation_Id(fw_account_id, &item_changelog); + if (ret != DACI_SUCCESS) { + FW_LOGE("Failed to Set Item ChangeLog Operation : %d", ret); + goto DACI_FINISH; + } + } + break; + case 303: /* DELETE */ + { + FW_LOGV("Item Changelog Already Exists : DELETE Operation"); + } + break; + } + } else { + /* + * add change log + */ + item_changelog.item_id = fw_item_id; + item_changelog.operation_id = 303; + item_changelog.status = strdup("SYNC_REQUIRED"); + item_changelog.access_name = strdup("DACI_ChangeLog"); + + ret = DACI_Add_Item_Changelog(fw_account_id, &item_changelog, 1); + if (ret != DACI_SUCCESS) { + FW_LOGE("[ChangeLog_Delete_Item] add item change log failed return : %d", ret); + goto DACI_FINISH; + } + } + +DACI_FINISH: + if (item_changelog.status != 0) { + free(item_changelog.status); + item_changelog.status = 0; + } + if (item_changelog.access_name != 0) { + free(item_changelog.access_name); + item_changelog.access_name = 0; + } + + return ret; +} + +int ChangeLog_Update_Item(int fw_account_id, char *fw_item_id, int itemType) +{ + /* + * TODO : 1. Need to Null check parameter + * 2. converting type : itemType + * 3. check whether the item is included + * 4. check whether the change log is included + * 5. add item change log + */ + + FW_LOGV("fw_account_id : %d", fw_account_id); + FW_LOGV("fw_item_id : %s", fw_item_id); + FW_LOGV("itemType : %d", itemType); + + DACI_RETURN ret = DACI_ERRORS; + + daci_item_changelog item_changelog; + item_changelog.status = 0; + item_changelog.access_name = 0; + + /* + * check whether the item is included + */ + ret = DACI_IsExist_Item(fw_item_id); + if (ret == 1) { + FW_LOGV("Item already exists : %s", fw_item_id); + } else { + FW_LOGE("Item is not existed!!"); + goto DACI_FINISH; + } + + /* check whether the change log is included */ + if (DACI_IsExist_Item_Changelog(fw_account_id, fw_item_id)) { + item_changelog.item_id = fw_item_id; + DACI_Get_Item_Changelog_By_Item_Id(fw_account_id, &item_changelog); + + if (item_changelog.operation_id == 303) { /* DELETE */ + FW_LOGE("already deleted item"); + goto DACI_FINISH; + } + + } else { + /* + * add change log + */ + item_changelog.item_id = fw_item_id; + item_changelog.operation_id = 302; + item_changelog.status = strdup("SYNC_REQUIRED"); + item_changelog.access_name = strdup("DACI_ChangeLog"); + + ret = DACI_Add_Item_Changelog(fw_account_id, &item_changelog, 1); + if (ret != DACI_SUCCESS) { + FW_LOGE("Failed to Add Item Change Log : %d", ret); + goto DACI_FINISH; + } + } + +DACI_FINISH: + if (item_changelog.status != 0) { + free(item_changelog.status); + item_changelog.status = 0; + } + if (item_changelog.access_name != 0) { + free(item_changelog.access_name); + item_changelog.access_name = 0; + } + + return ret; +} diff --git a/framework/src/DataAdapter/DACI_Common.c b/framework/src/DataAdapter/DACI_Common.c new file mode 100755 index 0000000..4ce3222 --- /dev/null +++ b/framework/src/DataAdapter/DACI_Common.c @@ -0,0 +1,142 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu , + * Heeyoung Hwang + */ + +#include "DataAdapter/DACI_Common.h" + +/* + * ========================================================== + * Structure Memory Free + * ========================================================== + */ +void DACI_Free_Memory_Account(daci_account *account, int count) +{ + int i; + for (i = 0; i < count; i++) { + DACI_MEMORY_FREE(account[i].email_address); + DACI_MEMORY_FREE(account[i].password); + DACI_MEMORY_FREE(account[i].accessName); + } + DACI_MEMORY_FREE(account); +} + +void DACI_Free_Memory_Folder(daci_folder *folder, int count) +{ + int i; + for (i = 0; i < count; i++) { + DACI_MEMORY_FREE(folder[i].folder_id); + DACI_MEMORY_FREE(folder[i].parent_folder_id); + DACI_MEMORY_FREE(folder[i].service_id); + DACI_MEMORY_FREE(folder[i].access_name); + } + DACI_MEMORY_FREE(folder); +} + +void DACI_Free_Memory_Item(daci_item *item, int count) +{ + int i; + for (i = 0; i < count; i++) { + DACI_MEMORY_FREE(item[i].item_id); + DACI_MEMORY_FREE(item[i].folder_id); + DACI_MEMORY_FREE(item[i].service_id); + DACI_MEMORY_FREE(item[i].access_name); + } + DACI_MEMORY_FREE(item); +} + +void DACI_Free_Memory_Config(daci_config *config, int count) +{ + int i; + for (i = 0; i < count; i++) { + DACI_MEMORY_FREE(config[i].key); + DACI_MEMORY_FREE(config[i].value); + DACI_MEMORY_FREE(config[i].type); + DACI_MEMORY_FREE(config[i].access_name); + } + DACI_MEMORY_FREE(config); +} + +void DACI_Free_Memory_Item_Changelog(daci_item_changelog *itemChangelog, int count) +{ + int i; + for (i = 0; i < count; i++) { + DACI_MEMORY_FREE(itemChangelog[i].item_id); + DACI_MEMORY_FREE(itemChangelog[i].status); + DACI_MEMORY_FREE(itemChangelog[i].access_name); + } + DACI_MEMORY_FREE(itemChangelog); +} + +void DACI_Free_Memory_Last_Anchor(daci_last_anchor *lastAnchor, int count) +{ + int i; + for (i = 0; i < count; i++) { + DACI_MEMORY_FREE(lastAnchor[i].last_anchor_server); + DACI_MEMORY_FREE(lastAnchor[i].last_anchor_client); + DACI_MEMORY_FREE(lastAnchor[i].access_name); + } + DACI_MEMORY_FREE(lastAnchor); +} + +void DACI_Free_Memory_Mapping(daci_mapping *mapping, int count) +{ + int i; + for (i = 0; i < count; i++) { + DACI_MEMORY_FREE(mapping[i].luid); + DACI_MEMORY_FREE(mapping[i].guid); + DACI_MEMORY_FREE(mapping[i].access_name); + } + DACI_MEMORY_FREE(mapping); +} + +void DACI_Free_Memory_Item_Info(daci_item_info *itemInfo, int count) +{ + int i; + for (i = 0; i < count; i++) { + DACI_MEMORY_FREE(itemInfo[i].itemId); + DACI_MEMORY_FREE(itemInfo[i].serviceId); + DACI_MEMORY_FREE(itemInfo[i].syncStatus); + } + DACI_MEMORY_FREE(itemInfo); +} + +void DACI_Free_Memory_Id_List(daci_id_list *idList) +{ + int i; + for (i = 0; i < idList->count; i++) { + DACI_MEMORY_FREE(idList->id[i]); + } + DACI_MEMORY_FREE(idList); +} diff --git a/framework/src/DataAdapter/DACI_Luid.c b/framework/src/DataAdapter/DACI_Luid.c new file mode 100755 index 0000000..28f07d1 --- /dev/null +++ b/framework/src/DataAdapter/DACI_Luid.c @@ -0,0 +1,131 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu , + */ + +#include "DataAdapter/DACI_Agent_Handler_Manager.h" + +#include "Utility/fw_log.h" +#include "fw_sequential_id_provider_internal.h" + +#include "DataAdapter/DACI_Luid.h" + +#include +#include +#include +#include + +#define LOG_TAG "AF_DACI" + +/* + * temporary - item id gen -> sequence + */ +#include + +#define VCONF_KEY_ITEM_SEQUENCE "db/Apps/AgentFramework/ItemSequence/" +#define VCONF_KEY_FOLDEs_SEQUENCE "db/Apps/AgentFramework/FolderSequence/" + +static pthread_mutex_t lockx; + +char **DACI_Generate_Item_Luid(int id_provider_code, int count) +{ + FW_LOGV("=========== Start ============"); + + if (count == 0) { + return 0; + } + + /* + * Start Critical Section + */ + if (pthread_mutex_lock(&lockx)) { + FW_LOGE("pthread_mutex_lock error"); + } + + id_provider_t *id_provider_local = 0; + id_provider_local = id_persistent_provider_load(id_provider_code, true); + + char **item_luid_list = (char **)calloc(count, sizeof(char *)); + + id_provider_error_t id_error = ID_PROVIDER_OK; + id_provider_tracking_mode_on(id_provider_local); + int i = 0; + unsigned int new_id = 0; + for (i = 0; i < count; i++) { + id_error = id_provider_provide_id(id_provider_local, &new_id); + assert(id_error == ID_PROVIDER_OK); + if (id_error != ID_PROVIDER_OK) { + printf("provider error : %d\n", id_error); + } + + char *item_luid = (char *)calloc(5, sizeof(char)); + if (item_luid != 0) + sprintf(item_luid, "%d", new_id); + item_luid_list[i] = item_luid; + } + + id_error = id_persistent_provider_update(id_provider_local); + id_provider_tracking_mode_off(id_provider_local); + id_provider_destroy(id_provider_local); + + /* + * End Critical Section + */ + if (pthread_mutex_unlock(&lockx)) { + FW_LOGE("pthread_mutex_unlock error"); + } + + FW_LOGV("=========== End ============"); + + return item_luid_list; +} + +char *DACI_Generate_Folder_Luid() +{ + char *folder_luid = 0; + uuid_t out; + + folder_luid = (char *)calloc(sizeof(char) * 36 + 1, 1); + if (folder_luid == 0) { + FW_LOGE("[DACI_Generate_Folder_Luid] memory allocation failed"); + return folder_luid; + } + + /* generate random uuid */ + uuid_generate_random(out); + + /* convert a UUID to string */ + uuid_unparse(out, folder_luid); + + return folder_luid; +} diff --git a/framework/src/DataAdapter/DACI_Service.c b/framework/src/DataAdapter/DACI_Service.c new file mode 100755 index 0000000..4e6d300 --- /dev/null +++ b/framework/src/DataAdapter/DACI_Service.c @@ -0,0 +1,945 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu , + * Heeyoung Hwang + */ + +#include "Utility/fw_log.h" + +#include "PlugIn/PlugIn_DataConnector.h" +#include "PlugIn/PlugIn_DataConverter.h" + +#include "Account/Account_Util.h" + +#include "DataAdapter/DACI_Agent_Handler_Manager.h" + +#include "DataAdapter/DACI_Service.h" +/* +// JSON ========================================== +#include +// JSON ========================================== +*/ + +#define LOG_TAG "AF_DACI" + +/* +// JSON ========================================== + +void freeFeeds(Feeds* resultFeeds) +{ + if( resultFeeds->feedItemList->activityList ) + free( resultFeeds->feedItemList->activityList ); + + if( resultFeeds->feedItemList ) + free( resultFeeds->feedItemList ); + + if( resultFeeds ) + free( resultFeeds ); +} + +Feeds* JSON2feedItem(char* resultBuffer) +{ + char errbuf[1024]; + yajl_val root = yajl_tree_parse(resultBuffer, errbuf, sizeof(errbuf)); + + if (root) + { + const char* path1[] = { "feeds", (const char*) 0 }; + const char* path2[] = { "feedId", (const char*) 0 }; + const char* path3[] = { "userId", (const char*) 0 }; + const char* path4[] = { "userName", (const char*) 0 }; + const char* path5[] = { "userPicUrl", (const char*) 0 }; + const char* path6[] = { "message", (const char*) 0 }; + const char* path7[] = { "createTime", (const char*) 0 }; + const char* path8[] = { "replyCount", (const char*) 0 }; + const char* path9[] = { "location", (const char*) 0 }; + const char* path10[] = { "latitude", (const char*) 0 }; + const char* path11[] = { "longitude", (const char*) 0 }; + const char* path12[] = { "address", (const char*) 0 }; + const char* path13[] = { "activityList", (const char*) 0 }; + const char* path14[] = { "activityId", (const char*) 0 }; + const char* path15[] = { "title", (const char*) 0 }; + const char* path16[] = { "type", (const char*) 0 }; + const char* path17[] = { "category", (const char*) 0 }; + const char* path18[] = { "packageName", (const char*) 0 }; + const char* path19[] = { "picUrl", (const char*) 0 }; + const char* path20[] = { "link", (const char*) 0 }; + const char* path21[] = { "platform", (const char*) 0 }; + const char* path22[] = { "platformVersion", (const char*) 0 }; + const char* path23[] = { "launchTime", (const char*) 0 }; + const char* path24[] = { "finishTime", (const char*) 0 }; + const char* path25[] = { "sharedCount", (const char*) 0 }; + + yajl_val feeds = yajl_tree_get(root, path1, yajl_t_array); + unsigned int FeedItemCnt = feeds->u.array.len; + + Feeds* structFeeds; + structFeeds = (Feeds*)calloc(1, sizeof(Feeds)); + structFeeds->feedItemList = (FeedItem*)calloc(FeedItemCnt, sizeof(FeedItem)); + structFeeds->feedItemCnt = FeedItemCnt; + + unsigned int i; + + for (i = 0 ; i < FeedItemCnt ; i++ ) + { + yajl_val FeedItem = feeds->u.array.values[i]; + + strcpy(structFeeds->feedItemList[i].msgID, YAJL_GET_STRING(yajl_tree_get(FeedItem, path2, yajl_t_string))); + strcpy(structFeeds->feedItemList[i].userID, YAJL_GET_STRING(yajl_tree_get(FeedItem, path3, yajl_t_string))); + strcpy(structFeeds->feedItemList[i].userName, YAJL_GET_STRING(yajl_tree_get(FeedItem, path4, yajl_t_string))); + strcpy(structFeeds->feedItemList[i].userImgUrl, YAJL_GET_STRING(yajl_tree_get(FeedItem, path5, yajl_t_string))); + strcpy(structFeeds->feedItemList[i].msg, YAJL_GET_STRING(yajl_tree_get(FeedItem, path6, yajl_t_string))); + structFeeds->feedItemList[i].date = (long)YAJL_GET_INTEGER(yajl_tree_get(FeedItem, path7, yajl_t_number)); + structFeeds->feedItemList[i].commentCount = (long)YAJL_GET_INTEGER(yajl_tree_get(FeedItem, path8, yajl_t_number)); + +// yajl_val msgID = yajl_tree_get(FeedItem, "feedId", yajl_t_string); +// yajl_val userID = yajl_tree_get(FeedItem, "userId", yajl_t_string); +// yajl_val userName = yajl_tree_get(FeedItem, "userName", yajl_t_string); +// yajl_val userImgUrl = yajl_tree_get(FeedItem, "userPicUrl", yajl_t_string); +// yajl_val msg = yajl_tree_get(FeedItem, "message", yajl_t_string); +// yajl_val date = yajl_tree_get(FeedItem, "createTime", yajl_t_number); +// yajl_val commentCount = yajl_tree_get(FeedItem, "replyCount", yajl_t_number); + + yajl_val location = yajl_tree_get(FeedItem, path9, yajl_t_object); + if (location) + { + structFeeds->feedItemList[i].loc.mLat = (double)YAJL_GET_INTEGER(yajl_tree_get(location, path10, yajl_t_number)); + structFeeds->feedItemList[i].loc.mLong = (double)YAJL_GET_INTEGER(yajl_tree_get(location, path11, yajl_t_number)); + strcpy(structFeeds->feedItemList[i].loc.mAddress, YAJL_GET_STRING(yajl_tree_get(location, path12, yajl_t_string))); + +// yajl_val mLat = yajl_tree_get(location, "latitude", yajl_t_number); +// yajl_val mLong = yajl_tree_get(location, "longitude", yajl_t_number); +// yajl_val mAddress = yajl_tree_get(location, "address", yajl_t_string); + + } + + yajl_val activityList = yajl_tree_get(FeedItem, path13, yajl_t_array); + if (activityList) + { + unsigned int ActivityItemCnt = activityList->u.array.len; + + structFeeds->feedItemList[i].activityList = (ActivityItem*)calloc(ActivityItemCnt, sizeof(ActivityItem)); + + unsigned int j; + + for (j = 0 ; j < ActivityItemCnt ; j++ ) + { + yajl_val ActivityItem = activityList->u.array.values[i]; + + strcpy(structFeeds->feedItemList[i].activityList[j].mActivityID, YAJL_GET_STRING(yajl_tree_get(ActivityItem, path14, yajl_t_string))); + strcpy(structFeeds->feedItemList[i].activityList[j].mName, YAJL_GET_STRING(yajl_tree_get(ActivityItem, path15, yajl_t_string))); + strcpy(structFeeds->feedItemList[i].activityList[j].mType, YAJL_GET_STRING(yajl_tree_get(ActivityItem, path16, yajl_t_string))); + strcpy(structFeeds->feedItemList[i].activityList[j].mCategory, YAJL_GET_STRING(yajl_tree_get(ActivityItem, path17, yajl_t_string))); + strcpy(structFeeds->feedItemList[i].activityList[j].mPname, YAJL_GET_STRING(yajl_tree_get(ActivityItem, path18, yajl_t_string))); + strcpy(structFeeds->feedItemList[i].activityList[j].mIconUrl, YAJL_GET_STRING(yajl_tree_get(ActivityItem, path19, yajl_t_string))); + strcpy(structFeeds->feedItemList[i].activityList[j].mMarketUrl, YAJL_GET_STRING(yajl_tree_get(ActivityItem, path20, yajl_t_string))); + strcpy(structFeeds->feedItemList[i].activityList[j].mPlatform, YAJL_GET_STRING(yajl_tree_get(ActivityItem, path21, yajl_t_string))); + strcpy(structFeeds->feedItemList[i].activityList[j].mPlatform, YAJL_GET_STRING(yajl_tree_get(ActivityItem, path22, yajl_t_string))); + structFeeds->feedItemList[i].activityList[j].mLaunchTime = (long)YAJL_GET_INTEGER(yajl_tree_get(ActivityItem, path23, yajl_t_number)); + structFeeds->feedItemList[i].activityList[j].mFinishTime = (long)YAJL_GET_INTEGER(yajl_tree_get(ActivityItem, path24, yajl_t_number)); + structFeeds->feedItemList[i].activityList[j].mShareCount = (long)YAJL_GET_INTEGER(yajl_tree_get(ActivityItem, path25, yajl_t_number)); + +// yajl_val mActivityID = yajl_tree_get(ActivityItem, "activityId", yajl_t_string); +// yajl_val mName = yajl_tree_get(ActivityItem, "title", yajl_t_string); +// yajl_val mType = yajl_tree_get(ActivityItem, "type", yajl_t_string); +// yajl_val mCategory = yajl_tree_get(ActivityItem, "category", yajl_t_string); +// yajl_val mPname = yajl_tree_get(ActivityItem, "packageName", yajl_t_string); +// yajl_val mIconUrl = yajl_tree_get(ActivityItem, "picUrl", yajl_t_string); +// yajl_val mMarketUrl = yajl_tree_get(ActivityItem, "link", yajl_t_string); +// yajl_val mPlatform = yajl_tree_get(ActivityItem, "platform", yajl_t_string); +// yajl_val mPlatformVersion = yajl_tree_get(ActivityItem, "platformVersion", yajl_t_string); +// yajl_val mLaunchTime = yajl_tree_get(ActivityItem, "launchTime", yajl_t_number); +// yajl_val mFinishTime = yajl_tree_get(ActivityItem, "finishTime", yajl_t_number); +// yajl_val mShareCount = yajl_tree_get(ActivityItem, "sharedCount", yajl_t_number); + + } + } + } + + yajl_tree_free(root); + + return structFeeds; + } + +} +// JSON ========================================== +*/ + +DACI_RETURN DACI_Service_Open(int content_type) +{ + FW_LOGV("[DACI_Service_Open] start"); + + DACI_RETURN ret = DACI_SUCCESS; + Service_Open pFunc_Service_Open = getFunction_DataConnector_Service_Open(content_type); + + if (pFunc_Service_Open == 0) { + FW_LOGI("%d", __LINE__); + return DACI_NOT_FOUND_PLUG_IN; + } + + ret = pFunc_Service_Open(); + if (ret != DACI_SUCCESS) { + FW_LOGE("[DACI_Service_Open] Fail!"); + } else { + FW_LOGV("[DACI_Service_Open] Success!"); + } + + return ret; +} + +DACI_RETURN DACI_Service_Close(int content_type) +{ + FW_LOGV("[DACI_Service_Close] start"); + + DACI_RETURN ret = DACI_SUCCESS; + Service_Close pFunc_Service_Close = getFunction_DataConnector_Service_Close(content_type); + + if (pFunc_Service_Close == 0) { + FW_LOGI("%d", __LINE__); + return DACI_NOT_FOUND_PLUG_IN; + } + + ret = pFunc_Service_Close(); + if (ret != DACI_SUCCESS) { + FW_LOGE("[DACI_Service_Close] Fail!"); + } else { + FW_LOGV("[DACI_Service_Close] Success!"); + } + + return ret; +} + +DACI_RETURN DACI_Service_Begin(int content_type) +{ + FW_LOGV("[DACI_Service_Begin] start"); + + DACI_RETURN ret = DACI_SUCCESS; + Begin_Transaction pFunc_Begin_Transaction = getFunction_DataConnector_Begin_Transaction(content_type); + + if (pFunc_Begin_Transaction == 0) { + FW_LOGI("%d", __LINE__); + return DACI_NOT_FOUND_PLUG_IN; + } + + ret = pFunc_Begin_Transaction(); + if (ret != DACI_SUCCESS) { + FW_LOGE("[DACI_Service_Begin] Fail!"); + } else { + FW_LOGV("[DACI_Service_Begin] Success!"); + } + + return ret; +} + +DACI_RETURN DACI_Service_End(int content_type, int is_success) +{ + FW_LOGV("[DACI_Service_End] start"); + + DACI_RETURN ret = DACI_SUCCESS; + End_Transaction pFunc_End_Transaction = getFunction_DataConnector_End_Transaction(content_type); + + if (pFunc_End_Transaction == 0) { + FW_LOGI("%d", __LINE__); + return DACI_NOT_FOUND_PLUG_IN; + } + + ret = pFunc_End_Transaction(is_success); + if (ret != DACI_SUCCESS) { + FW_LOGE("[DACI_Service_End] Fail!"); + } else { + FW_LOGV("[DACI_Service_End] Success!"); + } + + return ret; +} + +DACI_RETURN DACI_Service_Add_Item(int content_type, int account_id, char *folder_id, const void *data, char **item_id) +{ + FW_LOGV("[DACI_Service_Add_Item] start"); + + DACI_RETURN ret = DACI_SUCCESS; + int service_account_id = 0; + char *service_folder_id = 0; + void *service_data = 0; + Converter pFunc_Converter; + ADD_ITEM pFunc_AddItem; + + /* 1. get service account id */ + service_account_id = getAccountID_Service(content_type, account_id); + FW_LOGV("[DACI_Service_Add_Item] service_acount_id : %d", service_account_id); + + /* 2. get service folder id */ + service_folder_id = DACI_Get_Folder_Service_Id(folder_id); + FW_LOGV("[DACI_Service_Add_Item] service_folder_id : %s", service_folder_id); + + /* 3. call plugIn dataconverter */ + int converter_plugIn_id = getDataConverter_PlugIn_ID(content_type); + pFunc_Converter = getFunction_DataConverter_Converter(converter_plugIn_id); + if (pFunc_Converter == 0) { + FW_LOGI("%d", __LINE__); + ret = DACI_NOT_FOUND_PLUG_IN; + goto DACI_FINISH; + } + + ret = pFunc_Converter(data, &service_data); + if (ret != DACI_SUCCESS) { + FW_LOGI("%d", __LINE__); + goto DACI_FINISH; + } + + /* 4. call plugIn dataconnector */ + pFunc_AddItem = getFunction_DataConnector_ADD_ITEM(content_type); + if (pFunc_AddItem == 0) { + FW_LOGI("%d", __LINE__); + ret = DACI_NOT_FOUND_PLUG_IN; + goto DACI_FINISH; + } + + ret = pFunc_AddItem(service_account_id, service_folder_id, service_data, item_id); + if (ret != DACI_SUCCESS) { + FW_LOGV("[DACI_Service_Add_Item] failed pFunc_AddItem()\n"); + } else { + FW_LOGV("[DACI_Service_Add_Item] success pFunc_AddItem()\n"); + FW_LOGV("[DACI_Service_Add_Item] added service id : %s", *item_id); + } + +DACI_FINISH: + + if (ret != DACI_SUCCESS) + *item_id = 0; + + /* memory free */ + if (service_folder_id != 0) + free(service_folder_id); + + return ret; +} + +DACI_RETURN DACI_Service_Update_Item(int content_type, int account_id, char *folder_id, char *item_id, const void *data) +{ + FW_LOGV("[DACI_Service_Update_Item] start"); + + FW_LOGV("[DACI_Service_Update_Item] account_id : %d", account_id); + FW_LOGV("[DACI_Service_Update_Item] folder_id : %s", folder_id); + FW_LOGV("[DACI_Service_Update_Item] item_id : %s", item_id); + FW_LOGV("[DACI_Service_Update_Item] data : %s", (char *)data); + + DACI_RETURN ret = DACI_SUCCESS; + int service_account_id = 0; + char *service_folder_id = 0; + char *service_item_id = 0; + void *service_data = 0; + void *new_service_data = 0; + GET_ITEM pFunc_Get_Item; + UPDATE_ITEM pFunc_UPDATE_ITEM; + Replace_Converter pFunc_Replace_Converter; + + /* 1. get service account id */ + service_account_id = getAccountID_Service(content_type, account_id); + FW_LOGV("[DACI_Service_Update_Item] service_acount_id : %d", service_account_id); + + /* 2. get service folder id */ + service_folder_id = DACI_Get_Folder_Service_Id(folder_id); + FW_LOGV("[DACI_Service_Update_Item] service_folder_id : %s", service_folder_id); + + /* 3. get service item id */ + service_item_id = DACI_Get_Item_Service_Id(item_id); + FW_LOGV("[DACI_Service_Update_Item] service_item_id : %s", service_item_id); + + /* 4. call plugIn dataconnector */ + pFunc_Get_Item = getFunction_DataConnector_GET_ITEM(content_type); + if (pFunc_Get_Item == 0) { + FW_LOGI("%d", __LINE__); + ret = DACI_NOT_FOUND_PLUG_IN; + goto DACI_FINISH; + } + + ret = pFunc_Get_Item(service_account_id, service_folder_id, service_item_id, &service_data); + if (ret != DACI_SUCCESS) { + FW_LOGI("%d", __LINE__); + goto DACI_FINISH; + } + + /* 5. call plugIn dataconverter */ + int converter_plugIn_id = getDataConverter_PlugIn_ID(content_type); + pFunc_Replace_Converter = getFunction_DataConverter_Replace_Converter(converter_plugIn_id); + if (pFunc_Replace_Converter == 0) { + FW_LOGI("%d", __LINE__); + ret = DACI_NOT_FOUND_PLUG_IN; + goto DACI_FINISH; + } + + ret = pFunc_Replace_Converter(service_data, data, &new_service_data); + if (ret != DACI_SUCCESS) { + FW_LOGI("%d", __LINE__); + goto DACI_FINISH; + } + + /* 6. call plugIn dataconverter */ + pFunc_UPDATE_ITEM = getFunction_DataConnector_UPDATE_ITEM(content_type); + if (pFunc_UPDATE_ITEM == 0) { + FW_LOGI("%d", __LINE__); + ret = DACI_NOT_FOUND_PLUG_IN; + goto DACI_FINISH; + } + + ret = pFunc_UPDATE_ITEM(service_account_id, service_folder_id, service_item_id, new_service_data); + if (ret != DACI_SUCCESS) { + FW_LOGV("[DACI_Service_Update_Item] failed pFunc_UPDATE_ITEM()\n"); + } else { + FW_LOGV("[DACI_Service_Update_Item] success pFunc_UPDATE_ITEM()\n"); + } + +DACI_FINISH: + + /* memory free */ + if (service_folder_id != 0) + free(service_folder_id); + + if (service_item_id != 0) + free(service_item_id); + + return ret; +} + +DACI_RETURN DACI_Service_Delete_Item(int content_type, int account_id, char *folder_id, char *item_id) +{ + FW_LOGV("[DACI_Service_Delete_Item] start"); + + DACI_RETURN ret = DACI_SUCCESS; + int service_account_id = 0; + char *service_folder_id = 0; + char *service_item_id = 0; + DEL_ITEM pFunc_DelItem; + + /* 1. get service account id */ + service_account_id = getAccountID_Service(content_type, account_id); + FW_LOGV("[DACI_Service_Delete_Item] service_acount_id : %d", service_account_id); + + /* 2. get service folder id */ + service_folder_id = DACI_Get_Folder_Service_Id(folder_id); + FW_LOGV("[DACI_Service_Delete_Item] service_folder_id : %s", service_folder_id); + + /* 3. get service item id */ + service_item_id = DACI_Get_Item_Service_Id(item_id); + FW_LOGV("[DACI_Service_Delete_Item] service_item_id : %s", service_item_id); + + /* 4. call plugIn dataconnector */ + pFunc_DelItem = getFunction_DataConnector_DEL_ITEM(content_type); + if (pFunc_DelItem == 0) { + FW_LOGI("%d", __LINE__); + ret = DACI_NOT_FOUND_PLUG_IN; + goto DACI_FINISH; + } + + ret = pFunc_DelItem(service_account_id, service_folder_id, service_item_id); + if (ret != DACI_SUCCESS) { + FW_LOGV("[DACI_Service_Delete_Item] failed pFunc_DelItem()\n"); + } else { + FW_LOGV("[DACI_Service_Delete_Item] success pFunc_DelItem()\n"); + } + +DACI_FINISH: + + /* memory free */ + if (service_folder_id != 0) + free(service_folder_id); + + if (service_item_id != 0) + free(service_item_id); + + return ret; +} + +DACI_RETURN DACI_Service_Delete_All_Items(int content_type, int account_id) +{ + FW_LOGV("[DACI_Service_Delete_All_Items] start"); + + DACI_RETURN ret = DACI_SUCCESS; + int service_account_id = 0; +/* char **folder_id_list = 0; + int folder_id_list_cnt = 0; + char *service_item_id =0;*/ + DEL_ALL_ITEMS pFunc_Del_All_Items; + + /* 1. get service account id */ + service_account_id = getAccountID_Service(content_type, account_id); + FW_LOGV("[DACI_Service_Delete_All_Items] service_acount_id : %d", service_account_id); + +/* //2. get folder id list for account id + folder_id_list = DACI_Get_Folder_Folder_Id_List_By_Account_Id(account_id, &folder_id_list_cnt); + FW_LOGV("[DACI_Service_Delete_All_Items] folder_id_list_cnt : %d", folder_id_list_cnt); + + //3. get service item id + service_item_id = DACI_Get_Item_Service_Id(item_id); + FW_LOGV("[DACI_Service_Delete_Item] service_item_id : %s", service_item_id);*/ + + /* 2. call plugIn dataconnector */ + pFunc_Del_All_Items = getFunction_DataConnector_DEL_ALL_ITEMS(content_type); + if (pFunc_Del_All_Items == 0) { + FW_LOGI("%d", __LINE__); + return DACI_NOT_FOUND_PLUG_IN; + } + + ret = pFunc_Del_All_Items(service_account_id); + if (ret != DACI_SUCCESS) { + FW_LOGV("[DACI_Service_Delete_All_Items] failed pFunc_Del_All_Items()\n"); + } else { + FW_LOGV("[DACI_Service_Delete_All_Items] success pFunc_Del_All_Items()\n"); + } + + /* memory free */ +/* if (service_folder_id != 0) + free(service_folder_id); + + if (service_item_id != 0) + free(service_item_id);*/ + + return ret; +} + +DACI_RETURN DACI_Service_Get_Item(int content_type, int account_id, char *folder_id, char *item_id, void **data) +{ + FW_LOGV("[DACI_Service_Get_Item] start"); + + DACI_RETURN ret = DACI_SUCCESS; + int service_account_id = 0; + char *service_folder_id = 0; + char *service_item_id = 0; + void *service_data = 0; + GET_ITEM pFunc_Get_Item; + Reverse_Converter pFunc_Reverse_Converter; + + /* 1. get service account id */ + service_account_id = getAccountID_Service(content_type, account_id); + FW_LOGV("[DACI_Service_Get_Item] service_acount_id : %d", service_account_id); + + /* 2. get service folder id */ + service_folder_id = DACI_Get_Folder_Service_Id(folder_id); + FW_LOGV("[DACI_Service_Get_Item] service_folder_id : %s", service_folder_id); + + /* 3. get service item id */ + service_item_id = DACI_Get_Item_Service_Id(item_id); + FW_LOGV("[DACI_Service_Get_Item] service_item_id : %s", service_item_id); + + /* 4. call plugIn dataconnector */ + pFunc_Get_Item = getFunction_DataConnector_GET_ITEM(content_type); + if (pFunc_Get_Item == 0) { + FW_LOGI("%d", __LINE__); + ret = DACI_NOT_FOUND_PLUG_IN; + goto DACI_FINISH; + } + + ret = pFunc_Get_Item(service_account_id, service_folder_id, service_item_id, &service_data); + if (ret != DACI_SUCCESS) { + FW_LOGI("%d", __LINE__); + goto DACI_FINISH; + } + + /* 5. call plugIn dataconverter */ + int converter_plugIn_id = getDataConverter_PlugIn_ID(content_type); + pFunc_Reverse_Converter = getFunction_DataConverter_Reverse_Converter(converter_plugIn_id); + if (pFunc_Reverse_Converter == 0) { + FW_LOGI("%d", __LINE__); + ret = DACI_NOT_FOUND_PLUG_IN; + goto DACI_FINISH; + } + + ret = pFunc_Reverse_Converter(service_data, data); + if (ret != DACI_SUCCESS) { + FW_LOGV("[DACI_Service_Get_Item] failed pFunc_Reverse_Converter()\n"); + } else { + FW_LOGV("[DACI_Service_Get_Item] success pFunc_Reverse_Converter()\n"); + } + +DACI_FINISH: + + /* memory free */ + if (service_folder_id != 0) + free(service_folder_id); + + if (service_item_id != 0) + free(service_item_id); + + return ret; +} + +DACI_RETURN DACI_Service_Add_Folder(int content_type, int account_id, char *folder_name, int folder_type, char **folder_id) +{ + FW_LOGV("[DACI_Service_Add_Folder] start"); + + DACI_RETURN ret = DACI_SUCCESS; + int service_account_id = 0; + ADD_FOLDER pFunc_AddFolder; + + /* 1. get service account id */ + service_account_id = getAccountID_Service(content_type, account_id); + FW_LOGV("[DACI_Service_Add_Folder] service_acount_id: %d", service_account_id); + + /* 2. call plugIn dataconnector */ + pFunc_AddFolder = getFunction_DataConnector_ADD_FOLDER(content_type); + if (pFunc_AddFolder == 0) { + FW_LOGI("%d", __LINE__); + return DACI_NOT_FOUND_PLUG_IN; + } + + ret = pFunc_AddFolder(service_account_id, folder_name, folder_type, folder_id); + if (ret != DACI_SUCCESS) { + FW_LOGV("[DACI_Service_Add_Folder] failed pFunc_AddFolder()\n"); + } else { + FW_LOGV("[DACI_Service_Add_Folder] success pFunc_AddFolder()\n"); + FW_LOGV("[DACI_Service_Add_Folder] added service id : %s", *folder_id); + } + + return ret; +} + +DACI_RETURN DACI_Service_Delete_Folder(int content_type, int account_id, char *folder_id) +{ + FW_LOGV("[DACI_Service_Delete_Folder] start"); + + DACI_RETURN ret = DACI_SUCCESS; + int service_account_id = 0; + char *service_folder_id = 0; + DEL_FOLDER pFunc_DelFolder; + + /* 1. get service account id */ + service_account_id = getAccountID_Service(content_type, account_id); + FW_LOGV("[DACI_Service_Delete_Folder] service_acount_id : %d", service_account_id); + + /* 2. get service folder id */ + service_folder_id = DACI_Get_Folder_Service_Id(folder_id); + FW_LOGV("[DACI_Service_Delete_Folder] service_folder_id : %s", service_folder_id); + + /* 3. call plugIn dataconnector */ + pFunc_DelFolder = getFunction_DataConnector_DEL_FOLDER(content_type); + if (pFunc_DelFolder == 0) { + FW_LOGI("%d", __LINE__); + ret = DACI_NOT_FOUND_PLUG_IN; + goto DACI_FINISH; + } + + ret = pFunc_DelFolder(service_account_id, service_folder_id); + if (ret != DACI_SUCCESS) { + FW_LOGV("[DACI_Service_Delete_Folder] failed pFunc_DelFolder()\n"); + } else { + FW_LOGV("[DACI_Service_Delete_Folder] success pFunc_DelFolder()\n"); + } + +DACI_FINISH: + + if (service_folder_id != 0) + free(service_folder_id); + + return ret; +} + +DACI_RETURN DACI_Service_Get_Folder(int content_type, int account_id, char *folder_id, char **out_folder_name, int *out_folder_type) +{ + FW_LOGV("[DACI_Service_Get_Folder] start"); + + DACI_RETURN ret = DACI_SUCCESS; + int service_account_id = 0; + char *service_folder_id = 0; + GET_FOLDER pFunc_GetFolder; + + /* 1. get service account id */ + service_account_id = getAccountID_Service(content_type, account_id); + FW_LOGV("[DACI_Service_Get_Folder] service_acount_id : %d", service_account_id); + + /* 2. get service folder id */ + service_folder_id = DACI_Get_Folder_Service_Id(folder_id); + FW_LOGV("[DACI_Service_Get_Folder] service_folder_id : %s", service_folder_id); + + /* 3. call plugIn dataconnector */ + pFunc_GetFolder = getFunction_DataConnector_GET_FOLDER(content_type); + if (pFunc_GetFolder == 0) { + FW_LOGI("%d", __LINE__); + ret = DACI_NOT_FOUND_PLUG_IN; + goto DACI_FINISH; + } + + ret = pFunc_GetFolder(service_account_id, service_folder_id, out_folder_name, out_folder_type); + if (ret != DACI_SUCCESS) { + FW_LOGV("[DACI_Service_Get_Folder] failed pFunc_GetFolder()\n"); + } else { + FW_LOGV("[DACI_Service_Get_Folder] success pFunc_GetFolder()\n"); + } + +DACI_FINISH: + + if (service_folder_id != 0) + free(service_folder_id); + + return ret; +} + +DACI_RETURN DACI_Service_Execute(int content_type, int account_ID, const char *execute_key, void *execute_values, void **result) +{ + FW_LOGV("[DACI_Service_Execute] start"); + + DACI_RETURN ret = DACI_SUCCESS; + int service_account_id = 0; + EXECUTE pFunc_Execute; + + /* 1. get service account id */ + service_account_id = getAccountID_Service(content_type, account_ID); + FW_LOGV("[DACI_Service_Execute] service_acount_id : %d", service_account_id); + + /* 2. call plugIn dataconnector */ + pFunc_Execute = getFunction_DataConnector_EXECUTE(content_type); + if (pFunc_Execute == 0) { + FW_LOGI("%d", __LINE__); + *result = 0; + return DACI_NOT_FOUND_PLUG_IN; + } + + ret = pFunc_Execute(service_account_id, execute_key, execute_values, result); + if (ret != DACI_SUCCESS) { + FW_LOGV("[DACI_Service_Execute] failed pFunc_Execute()\n"); + } else { + FW_LOGV("[DACI_Service_Execute] success pFunc_Execute()\n"); + } + + return ret; +} + +int DACI_Service_Get_Used_Item_Count(int content_type) +{ + FW_LOGV("[DACI_Service_Get_Used_Item_Count] start"); + + GET_USED_ITEM_COUNT pFunc_Get_Used_Count = getFunction_DataConnector_GET_USED_ITEM_COUNT(content_type); + if (pFunc_Get_Used_Count == 0) { + FW_LOGI("%d", __LINE__); + return DACI_NOT_FOUND_PLUG_IN; + } + + /* 1. call plugIn dataconnector */ + int used_count = pFunc_Get_Used_Count(); + if (used_count <= -1) { + FW_LOGV("[DACI_Service_Get_Used_Item_Count] failed pFunc_Get_Used_Count()\n"); + } else { + FW_LOGV("[DACI_Service_Get_Used_Item_Count] success pFunc_Get_Used_Count() : %d\n", used_count); + } + + return used_count; +} + +int DACI_Service_Get_Used_Item_Count_For_Folder(int content_type, int account_id, char *folder_id) +{ + FW_LOGV("[DACI_Service_Get_Used_Item_Count_For_Folder] start"); + + int used_count = DACI_SUCCESS; + int service_account_id = 0; + char *service_folder_id = 0; + GET_USED_COUNT_FOR_FOLDER pFunc_Get_Used_item_Count_For_Folder; + + /* 1. get service account id */ + service_account_id = getAccountID_Service(content_type, account_id); + FW_LOGV("[DACI_Service_Get_Used_Item_Count_For_Folder] service_acount_id : %d", service_account_id); + + /* 2. get service folder id */ + service_folder_id = DACI_Get_Folder_Service_Id(folder_id); + FW_LOGV("[DACI_Service_Get_Used_Item_Count_For_Folder] service_folder_id : %s", service_folder_id); + + /* 3. call plugIn dataconnector */ + pFunc_Get_Used_item_Count_For_Folder = getFunction_DataConnector_GET_USED_COUNT_FOR_FOLDER(content_type); + if (pFunc_Get_Used_item_Count_For_Folder == 0) { + FW_LOGI("%d", __LINE__); + used_count = DACI_NOT_FOUND_PLUG_IN; + goto DACI_FINISH; + } + + used_count = pFunc_Get_Used_item_Count_For_Folder(service_account_id, service_folder_id); + if (used_count <= -1) { + FW_LOGV("[DACI_Service_Get_Used_Item_Count_For_Folder] failed pFunc_Get_Used_item_Count_For_Folder()\n"); + } else { + FW_LOGV("[DACI_Service_Get_Used_Item_Count_For_Folder] success pFunc_Get_Used_item_Count_For_Folder() : %d\n", used_count); + } + +DACI_FINISH: + + /* memory free */ + if (service_folder_id != 0) + free(service_folder_id); + + return used_count; +} + +DACI_RETURN DACI_Service_Write_Items_To_FIle(int content_type, int account_id, char **file_path) +{ + FW_LOGV("start"); + + DACI_RETURN ret = DACI_SUCCESS; + int service_account_id = 0; + WRITE_ITEMS_TO_FILE pFunc_Write_Items_To_Files; + + /* 1. get service account id */ + service_account_id = getAccountID_Service(content_type, account_id); + FW_LOGV("service_acount_id : %d", service_account_id); + + /* 3. call plugIn dataconnector */ + pFunc_Write_Items_To_Files = getFunction_DataConnector_WRITE_ITEMS_TO_FILE(content_type); + if (pFunc_Write_Items_To_Files == 0) { + FW_LOGI("%d", __LINE__); + ret = DACI_NOT_FOUND_PLUG_IN; + goto DACI_FINISH; + } + + ret = pFunc_Write_Items_To_Files(service_account_id, file_path); + if (ret != DACI_SUCCESS) { + FW_LOGV("failed pFunc_Write_Items_To_Files()\n"); + } else { + FW_LOGV("success pFunc_Write_Items_To_Files() : %d\n", ret); + } + +DACI_FINISH: + + return ret; +} + +DACI_RETURN DACI_Service_Add_File_Wrote_Items_To_Datastore(int content_type, int account_id, const char *file_path) +{ + FW_LOGV("start"); + + DACI_RETURN ret = DACI_SUCCESS; + int service_account_id = 0; + ADD_FILE_WROTE_ITEMS_TO_DATASTORE pFunc_Add_File_Wrote_Items_To_Datastore; + + /* 1. get service account id */ + service_account_id = getAccountID_Service(content_type, account_id); + FW_LOGV("service_acount_id : %d", service_account_id); + + /* 3. call plugIn dataconnector */ + pFunc_Add_File_Wrote_Items_To_Datastore = getFunction_DataConnector_ADD_FILE_WROTE_ITEM_TO_DATASTORE(content_type); + if (pFunc_Add_File_Wrote_Items_To_Datastore == 0) { + FW_LOGI("%d", __LINE__); + ret = DACI_NOT_FOUND_PLUG_IN; + goto DACI_FINISH; + } + + ret = pFunc_Add_File_Wrote_Items_To_Datastore(service_account_id, file_path); + if (ret != DACI_SUCCESS) { + FW_LOGV("failed pFunc_Add_File_Wrote_Items_To_Datastore()\n"); + } else { + FW_LOGV("success pFunc_Add_File_Wrote_Items_To_Datastore() : %d\n", ret); + } + +DACI_FINISH: + + return ret; +} + +int DACI_Service_Get_MAX_Item_Count(int content_type, int folder_type) +{ + int max_item_count = 0; + GET_MAX_ITEM_COUNT pFunc_Get_Max_Item_Count; + + pFunc_Get_Max_Item_Count = getFunction_DataConnector_GET_MAX_ITEM_COUNT(content_type); + if (pFunc_Get_Max_Item_Count == 0) { + FW_LOGE("[DACI_Service_Get_MAX_Item_Count] Fail!"); + } + + max_item_count = pFunc_Get_Max_Item_Count(folder_type); + + FW_LOGI("End"); + return max_item_count; + +} + +int DACI_Service_Get_MAX_Field_Length(int content_type, int field_name, int child_field_name) +{ + int max_field_len = 0; + GET_MAX_FIELD_LENGTH pFunc_Get_Max_Field_Len; + + pFunc_Get_Max_Field_Len = getFunction_DataConnector_GET_MAX_FIELD_LENGTH(content_type); + if (pFunc_Get_Max_Field_Len == 0) { + FW_LOGE("[DACI_Service_Get_MAX_Field_Length] Fail!"); + } + + max_field_len = pFunc_Get_Max_Field_Len(field_name, child_field_name); + + FW_LOGI("End"); + return max_field_len; + +} + +int DACI_Service_Get_MAX_Field_Count(int content_type, int field_name, int child_field_name) +{ + int max_field_count = 0; + GET_MAX_FIELD_COUNT pFunc_Get_Max_Field_Count; + + pFunc_Get_Max_Field_Count = getFunction_DataConnector_GET_MAX_FIELD_COUNT(content_type); + if (pFunc_Get_Max_Field_Count == 0) { + FW_LOGE("[DACI_Service_Get_MAX_Field_Count] Fail!"); + } + + max_field_count = pFunc_Get_Max_Field_Count(field_name, child_field_name); + + FW_LOGI("End"); + return max_field_count; + +} + +int DACI_Service_Get_Field_Value(int content_type, int field_name, int child_field_name, char **str_val, int *num_val1, int *num_val2) +{ + GET_FIELD_VALUE pFunc_Get_Field_Value; + + pFunc_Get_Field_Value = getFunction_DataConnector_GET_FIELD_VALUE(content_type); + if (pFunc_Get_Field_Value == 0) { + FW_LOGE("[DACI_Service_Get_Field_Value] Fail!"); + } + + if (pFunc_Get_Field_Value(field_name, child_field_name, &(*str_val), num_val1, num_val2) == 0) { + FW_LOGE("[DACI_Service_Get_Field_Value] Error!"); + return 0; + } + + FW_LOGI("End"); + return 1; + +} + +int DACI_Service_Get_Is_Support_Feature(int content_type, int feature) +{ + GET_IS_SUPPORT_FEATURE pFunc_Get_Is_Support_Feature; + + pFunc_Get_Is_Support_Feature = getFunction_DataConnector_GET_IS_SUPPORT_FEATURE(content_type); + if (pFunc_Get_Is_Support_Feature == 0) { + FW_LOGE("[DACI_Service_Get_Is_Support_Feature] Fail!"); + } + + FW_LOGI("End"); + return pFunc_Get_Is_Support_Feature(feature); + +} diff --git a/framework/src/DataAdapter/EXT_DACI_Converter.c b/framework/src/DataAdapter/EXT_DACI_Converter.c new file mode 100755 index 0000000..c179ff6 --- /dev/null +++ b/framework/src/DataAdapter/EXT_DACI_Converter.c @@ -0,0 +1,191 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu , + * Heeyoung Hwang + */ + +#include "PlugIn/PlugIn_DataConnector.h" +#include "PlugIn/PlugIn_DataConverter.h" + +#include "Utility/fw_log.h" + +#include "DataAdapter/EXT_DACI_Converter.h" + +#define LOG_TAG "AF_DACI" + +void *T_DACI_Alloc_Obj(int content_type) +{ + FW_LOGV("start"); + + DACI_RETURN ret = DACI_SUCCESS; + Alloc_Object pFunc_Alloc_Object; + + int converter_plugIn_id = getDataConverter_PlugIn_ID(content_type); + pFunc_Alloc_Object = getFunction_DataConverter_Alloc_Object(converter_plugIn_id); + if (pFunc_Alloc_Object == 0) { + FW_LOGI("%d", __LINE__); + } + + void *result = pFunc_Alloc_Object(); + if (result == 0) { + FW_LOGE("Fail!"); + ret = DACI_ERR_OPEN_FAILED; + } else { + FW_LOGV("Success!"); + } + + return result; +} + +DACI_RETURN T_DACI_Free_Obj(int content_type, void *in_object) +{ + FW_LOGV("start"); + + DACI_RETURN ret = DACI_SUCCESS; + Free_Object pFunc_Free_Object; + + int converter_plugIn_id = getDataConverter_PlugIn_ID(content_type); + pFunc_Free_Object = getFunction_DataConverter_Free_Object(converter_plugIn_id); + if (pFunc_Free_Object == 0) { + FW_LOGI("%d", __LINE__); + } + + FW_LOGV("mid"); + int err = pFunc_Free_Object(in_object); + if (err != 1) { + FW_LOGE("Fail!"); + ret = DACI_ERRORS; + } else { + FW_LOGV("Success!"); + } + + FW_LOGV("end"); + return ret; +} + +void *T_DACI_Set_Value_To_Obj(int content_type, void *in_object, int key, char *extension_key, void *set_value) +{ + FW_LOGV("start"); + + DACI_RETURN ret = DACI_SUCCESS; + Set_Value pFunc_Set_Value_To_Object; + + int converter_plugIn_id = getDataConverter_PlugIn_ID(content_type); + pFunc_Set_Value_To_Object = getFunction_DataConverter_Set_Value_To_Object(converter_plugIn_id); + if (pFunc_Set_Value_To_Object == 0) { + FW_LOGI("%d", __LINE__); + } + + void *result = pFunc_Set_Value_To_Object(in_object, key, extension_key, set_value); + if (result == 0) { + FW_LOGE("Fail!"); + ret = DACI_ERRORS; + } else { + FW_LOGV("Success!"); + } + + return result; +} + +void *T_DACI_Get_Value_To_Obj(int content_type, void *in_object, int key, char *extension_key) +{ + FW_LOGV("start"); + + DACI_RETURN ret = DACI_SUCCESS; + Get_Value pFunc_Get_Value_To_Object; + + int converter_plugIn_id = getDataConverter_PlugIn_ID(content_type); + pFunc_Get_Value_To_Object = getFunction_DataConverter_Get_Value_To_Object(converter_plugIn_id); + if (pFunc_Get_Value_To_Object == 0) { + FW_LOGI("%d", __LINE__); + } + + void *result = pFunc_Get_Value_To_Object(in_object, key, extension_key); + if (result == 0) { + FW_LOGE("Fail!"); + ret = DACI_ERRORS; + } else { + FW_LOGV("Success!"); + } + + return result; +} + +Object_Info *T_DACI_Get_Obj_Info(int content_type) +{ + FW_LOGV("start"); + + DACI_RETURN ret = DACI_SUCCESS; + Get_Obj_Info pFunc_Get_Obj_Info; + + int converter_plugIn_id = getDataConverter_PlugIn_ID(content_type); + pFunc_Get_Obj_Info = getFunction_DataConverter_Get_Obj_Info(converter_plugIn_id); + if (pFunc_Get_Obj_Info == 0) { + FW_LOGI("%d", __LINE__); + } + + Object_Info *result = pFunc_Get_Obj_Info(); + if (result == 0) { + FW_LOGE("Fail!"); + ret = DACI_ERRORS; + } else { + FW_LOGV("Success!"); + } + + return result; +} + +DACI_RETURN T_DACI_Free_Obj_Info(int content_type, Object_Info *obj_info) +{ + FW_LOGV("start"); + + DACI_RETURN ret = DACI_SUCCESS; + Free_Obj_Info pFunc_Free_Obj_Info; + + int converter_plugIn_id = getDataConverter_PlugIn_ID(content_type); + pFunc_Free_Obj_Info = getFunction_DataConverter_Free_Obj_Info(converter_plugIn_id); + if (pFunc_Free_Obj_Info == 0) { + FW_LOGI("%d", __LINE__); + } + + int err = pFunc_Free_Obj_Info(obj_info); + if (err != 1) { + FW_LOGE("Fail!"); + ret = DACI_ERRORS; + } else { + FW_LOGV("Success!"); + } + + FW_LOGV("end"); + return ret; +} diff --git a/framework/src/Device/EXT_DCI_DevExecutor.c b/framework/src/Device/EXT_DCI_DevExecutor.c new file mode 100755 index 0000000..53c756b --- /dev/null +++ b/framework/src/Device/EXT_DCI_DevExecutor.c @@ -0,0 +1,87 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Seokgil Kang + * Seongwon Shim + */ +#include + +#include "Device/EXT_DCI_DevExecutor.h" +#include "PlugIn/PlugIn_DeviceInfo.h" +#include "Utility/fw_log.h" + +#define LOG_TAG "AF_DCI" + +DCI_RETURN DCI_PM_Lock_State(int device_plugIn_id, PM_State state, PM_Lock_State_Flag flag, unsigned int timeout) +{ + FW_LOGV("Start !! \n"); + DCI_RETURN res = DCI_SUCCESS; + + PM_Lock_State pFunc_PM_Lock_State = getFunction_PM_Lock_State(device_plugIn_id); + if (pFunc_PM_Lock_State == 0) { + FW_LOGV("[%s] cannot get pFunc !! \n", __func__); + } + + int err = pFunc_PM_Lock_State(state, flag, timeout); + if (err < 0) { + FW_LOGV("fail !!\n"); + res = DCI_FAIL; + } else { + FW_LOGV("success !! \n"); + } + + FW_LOGV("End !! \n"); + return res; + +} + +DCI_RETURN DCI_PM_Unlock_State(int device_plugIn_id, PM_State state, PM_Unlock_State_Flag flag) +{ + FW_LOGV("Start !! \n"); + DCI_RETURN res = DCI_SUCCESS; + + PM_Unlock_State pFunc_PM_Unlock_State = getFunction_PM_Unlock_State(device_plugIn_id); + if (pFunc_PM_Unlock_State == 0) { + FW_LOGV("[%s] cannot get pFunc !! \n", __func__); + } + + int err = pFunc_PM_Unlock_State(state, flag); + if (err < 0) { + FW_LOGV("fail !!\n"); + res = DCI_FAIL; + } else { + FW_LOGV("success !! \n"); + } + + FW_LOGV("End !! \n"); + return res; +} diff --git a/framework/src/Device/EXT_DCI_DevInfo.c b/framework/src/Device/EXT_DCI_DevInfo.c new file mode 100755 index 0000000..9e2ee63 --- /dev/null +++ b/framework/src/Device/EXT_DCI_DevInfo.c @@ -0,0 +1,125 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Seokgil Kang + */ + +#include + +#include "Utility/fw_log.h" +#include "Device/EXT_DCI_DevInfo.h" +#include "PlugIn/PlugIn_DeviceInfo.h" + +#define LOG_TAG "AF_DCI" + +static GList *dev_info; + +DCI_RETURN DCI_Init(int device_plugIn_id) +{ + FW_LOGV("[%s] Start !! \n", __func__); + DCI_RETURN res = DCI_SUCCESS; + + FW_LOGI("[%s] plug-in id : %d\n", __func__, device_plugIn_id); + + Load_DevInfo pFunc_Load_DevInfo = getFunction_DeviceInfo_Load_DevInfo(device_plugIn_id); + if (pFunc_Load_DevInfo == 0) { + FW_LOGV("[%s] cannot get pFunc_Load_DevInfo !! \n", __func__); + return DCI_FAIL; + } + + int err = pFunc_Load_DevInfo(&dev_info); + if (err != 1) { + FW_LOGV("[%s] fail !!\n", __func__); + res = DCI_FAIL; + } else { + FW_LOGV("[%s] success !! \n", __func__); + } + + FW_LOGV("[%s] End !! \n", __func__); + return res; +} + +DCI_RETURN DCI_Get_DevInfo(int device_plugIn_id, char *info_name, char **value) +{ + FW_LOGV("[%s] Start !! \n", __func__); + DCI_RETURN res = DCI_SUCCESS; + + if (info_name == NULL || !strcmp(info_name, "")) + return DCI_FAIL; + + Get_DevInfo pFunc_Get_DevInfo = getFunction_DeviceInfo_Get_DevInfo(device_plugIn_id); + if (pFunc_Get_DevInfo == 0) { + FW_LOGV("[%s] cannot get pFunc_Get_DevInfo !! \n", __func__); + return DCI_FAIL; + } + + int err = pFunc_Get_DevInfo(dev_info, info_name, value); + FW_LOGV("[%s] info name : %s\n", __func__, info_name); + FW_LOGV("[%s] value : %s\n", __func__, *value); + + if (err == 0) { + FW_LOGV("[%s] fail - value is null !!\n", __func__); + res = DCI_DEVINFO_VALUE_IS_NULL; + } else if (err == -1) { + FW_LOGV("[%s] fail - not exist this information !!\n", __func__); + res = DCI_NOT_EXIST_DEVINFO; + } else { + FW_LOGV("[%s] success !! \n", __func__); + } + + FW_LOGV("[%s] End !! \n", __func__); + + return res; +} + +DCI_RETURN DCI_Destroy(int device_plugIn_id) +{ + FW_LOGV("[%s] Start !! \n", __func__); + DCI_RETURN res = DCI_SUCCESS; + + Clear_DevInfo pFunc_Clear_DevInfo = getFunction_DeviceInfo_Clear_DevInfo(device_plugIn_id); + if (pFunc_Clear_DevInfo == 0) { + FW_LOGV("[%s] cannot get pFunc_Clear_DevInfo !! \n", __func__); + } + + int err = pFunc_Clear_DevInfo(&dev_info); + if (err != 1) { + FW_LOGV("[%s] fail !!\n", __func__); + res = DCI_FAIL; + } else { + FW_LOGV("[%s] success !! \n", __func__); + } + + FW_LOGV("[%s] End !! \n", __func__); + + return res; +} diff --git a/framework/src/EngineController/engine_controller.c b/framework/src/EngineController/engine_controller.c new file mode 100755 index 0000000..c3c608f --- /dev/null +++ b/framework/src/EngineController/engine_controller.c @@ -0,0 +1,680 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Wook Choi + */ + +#include +#include +#include +#include +#include +#include +#include "Utility/fw_assert.h" +#include "Utility/fw_log.h" +#include "EngineController/engine_controller.h" +#include "EngineController/engine_controller_internal.h" +#include "EngineController/task_message.h" +#include "EngineController/task_spec.h" +#include "EngineController/task_pool.h" +#include "EngineController/task_spec_internal.h" + +#define LOG_TAG "AF_EC" + +GPrivate *pCancel_TSK = NULL; + +typedef void *(*engine_controller_logic_func) (engine_controller_t *); + +typedef void *(*thread_start_routine) (void *); + +static engine_controller_t *pGlobal_engine_controller = NULL; +static engine_controller_receiver_t *pGlobal_engine_controller_receiver = NULL; + +typedef struct sync_task_output_s sync_task_output_t; +struct sync_task_output_s { + pthread_mutex_t mutex; + pthread_cond_t output_set_done_cond; + ec_boolean output_set_done; + task_error_t task_error; + ec_uint out_param_cnt; + param_t **out_param_array; +}; + +static sync_task_output_t *alloc_and_init_sync_task_output() +{ + sync_task_output_t *pOutput = (sync_task_output_t *)calloc(1, sizeof(sync_task_output_t)); + if (pOutput == NULL) { + goto error_part; + } + + pOutput->output_set_done = false; + pthread_mutex_init(&(pOutput->mutex), NULL); + pthread_cond_init(&(pOutput->output_set_done_cond), NULL); + + return pOutput; + +error_part: + return NULL; +} + +static void destory_sync_task_output(sync_task_output_t *pOutput) +{ + if (pOutput != NULL) { + pthread_cond_destroy(&(pOutput->output_set_done_cond)); + pthread_mutex_destroy(&(pOutput->mutex)); + + free(pOutput); + } +} + +static void static_sync_task_finish_callback(task_error_t task_error, ec_uint out_param_cnt, param_t **out_param_array, ec_pointer usr_data) +{ + FW_LOGD("started\n"); + sync_task_output_t *pOutput = (sync_task_output_t *)usr_data; + + pthread_mutex_lock(&(pOutput->mutex)); + /* set output */ + pOutput->task_error = task_error; + pOutput->out_param_cnt = out_param_cnt; + pOutput->out_param_array = out_param_array; + + g_atomic_int_set(&(pOutput->output_set_done), true); + FW_LOGD("before conditional signal\n"); + /* wake up receiver */ + pthread_cond_signal(&(pOutput->output_set_done_cond)); + pthread_mutex_unlock(&(pOutput->mutex)); + FW_LOGD("after conditional signal\n"); + + FW_LOGD("finished\n"); +} + +static void engine_controller_send_parent_task_done_msg_to_itseft(task_t *pParent_task) +{ + FW_LOGD("called. task_name = %s\n", pParent_task->pTask_spec->task_name); + task_message_t *pNew_task_msg = task_message_create(TASK_DONE, pParent_task, 0); + if (pNew_task_msg == NULL) { + FW_LOGE("error. out of memory. we can not create parent container done message."); + assert(false); + /* TODO : error handling */ + } + send_msg_to_engine_controller_with_compare_priority(pNew_task_msg, compare_priority_of_task_message_append_way, NULL); +} + +static void engine_controller_send_new_runnerable_child_task_msgs_to_itself(GSList *runnable_child_task_list, task_message_t *pReceived_task_msg) +{ + task_message_t *pNew_task_msg = NULL; + task_t *pChild_task = NULL; + GSList *iter = NULL; + for (iter = runnable_child_task_list; iter != NULL; iter = g_slist_next(iter)) { + pChild_task = (task_t *)(iter->data); + pNew_task_msg = task_message_create(TASK_START, pChild_task, 0); + if (pReceived_task_msg->task_state == TASK_START) { + /* note that we have to prepend task message in front of other messages with same priority */ + /* otherwise, child task in container task always has penalty then new task input */ + send_msg_to_engine_controller_with_compare_priority(pNew_task_msg, compare_priority_of_task_message_append_way, NULL); + } else if (pReceived_task_msg->task_state == TASK_DONE) { + send_msg_to_engine_controller_with_compare_priority(pNew_task_msg, compare_priority_of_task_message_append_way, NULL); + } else { + FW_LOGE("task msg has invalid task state"); + assert(false); + } + } +} + +static void *engine_controller_logic(engine_controller_t *pEngine_controller) +{ + fw_async_queue_t *pQueue = pEngine_controller->pQueue; + thread_pool_t *pPool = pEngine_controller->pThread_pool; + task_pool_t *pTask_pool = pEngine_controller->pTask_pool; + task_t *pTask = NULL; + task_t *pParent_task = NULL; + ec_int child_task_index_in_parent_task = -1; + task_message_t *pReceived_task_msg = NULL; + GSList *runnable_child_task_list = NULL; + + FW_LOGD("started\n"); + + while (true) { + /* receive msg */ + pReceived_task_msg = fw_async_queue_receive_msg(pQueue); + if (pReceived_task_msg == NULL) { + FW_LOGE("null returned from receive_msg_fw_async_queue\n"); + continue; + } + + if (pReceived_task_msg->task_state == TASK_ROOT_START) { + pTask = task_ref_task(pReceived_task_msg->u.pTask); + engine_controller_request_msg_t *pRequest_msg = (engine_controller_request_msg_t *)getData(pTask->pRequestMsg); + FW_LOGD("\n\n======= [CONTROLLER : TASK_ROOT_START] task(msg id : %d, task name : %s, task spec id : %d) ========= \n\n", pRequest_msg->msg_head.msg_id, pTask->pTask_spec->task_name, pRequest_msg->task_spec_id); + + assert(task_is_root_task(pTask)); + task_pool_add_task(pTask_pool, pRequest_msg->msg_head.msg_id, pTask); + + task_message_t *pNew_task_msg = task_message_create(TASK_START, pTask, 0); + if (pNew_task_msg == NULL) { + /* TODO */ + assert(false); + } + send_msg_to_engine_controller_with_compare_priority(pNew_task_msg, compare_priority_of_task_message_append_way, NULL); + + task_unref_task(pTask); + + } else if (pReceived_task_msg->task_state == TASK_START) { + pTask = task_ref_task(pReceived_task_msg->u.pTask); + engine_controller_request_msg_t *pRequest_msg = (engine_controller_request_msg_t *)getData(pTask->pRequestMsg); + FW_LOGD("\n\n======= [CONTROLLER : TASK_START] =========\ntask(task name : %s) related to root_task(msg id : %d, task spec id : %d)\n\n", pTask->pTask_spec->task_name, pRequest_msg->msg_head.msg_id, pRequest_msg->task_spec_id); + + /* queuing if task applied to queuing rule */ + ec_boolean is_pending_task = task_add_pending_task_list_of_first_progress_blocking_realized_entity(pTask); + if (is_pending_task) { + FW_LOGI("task name : %s pending by queuing rule\n", pTask->pTask_spec->task_name); + task_unref_task(pTask); + goto last; + } + + if (task_is_simple_task(pTask)) { + thread_pool_push_task(pPool, pTask); + } + + if (task_is_container_task(pTask)) { + /* update progress blocking realized entity when dynamic task case */ + /* this can be done since other dynamic case conditions can be ignored now */ + if (task_spec_is_dynamic_container_task_spec(pTask->pTask_spec)) { + task_update_progress_blocking_realized_entity_and_pop_if_possible(pTask); + } + + /* check runnable child task */ + runnable_child_task_list = collect_firstly_runnable_child_tasks(pTask); + if (runnable_child_task_list == NULL) { + FW_LOGE("no runnable child task exist.\n"); + assert(false); + } + + /* send task message to engine controller itself */ + engine_controller_send_new_runnerable_child_task_msgs_to_itself(runnable_child_task_list, pReceived_task_msg); + } + + task_unref_task(pTask); + + } else if (pReceived_task_msg->task_state == TASK_ROOT_DONE) { + pTask = task_ref_task(pReceived_task_msg->u.pTask); + engine_controller_request_msg_t *pRequest_Msg = (engine_controller_request_msg_t *)getData(pTask->pRequestMsg); + + FW_LOGD("\n\n======= [CONTROLLER : TASK_ROOT_DONE] task(result : %s), msg id : %d, task name : %s, task spec id : %d) ========= \n\n", task_error_string(pTask->task_error), pRequest_Msg->msg_head.msg_id, pTask->pTask_spec->task_name, pRequest_Msg->task_spec_id); + + task_pool_remove_task(pTask_pool, pRequest_Msg->msg_head.msg_id); + task_call_task_finish_callback(pTask); + FW_LOGD("root task task_call_task_finish_callback done\n"); + FW_LOGD("root task done\n"); + } else if (pReceived_task_msg->task_state == TASK_DONE) { + pTask = task_ref_task(pReceived_task_msg->u.pTask); + engine_controller_request_msg_t *pRequest_msg = (engine_controller_request_msg_t *)getData(pTask->pRequestMsg); + + /* loggiing */ + FW_LOGD("\n\n======= [CONTROLLER : TASK_DONE : %s] =========\ntask(task name : %s) related to root_task(msg id : %d, task spec id : %d)\n\n", task_error_string(pTask->task_error), pTask->pTask_spec->task_name, pRequest_msg->msg_head.msg_id, pRequest_msg->task_spec_id); + + task_update_progress_blocking_realized_entity_and_pop_if_possible(pTask); + + if (task_is_root_task(pTask)) { + + task_message_t *pNew_task_msg = task_message_create(TASK_ROOT_DONE, pTask, 0); + if (pNew_task_msg == NULL) { + /* TODO */ + assert(false); + } + send_msg_to_engine_controller_with_compare_priority(pNew_task_msg, compare_priority_of_task_message_append_way, NULL); + } else { + switch (pTask->task_error) { + case TASK_ERROR_RUN_SUCCESS: + { + pParent_task = task_get_parent_task(pTask); + child_task_index_in_parent_task = task_get_child_index_in_parent_task(pTask); + + task_decrease_left_child_to_run(pParent_task); + + if (task_is_parent_task_done(pParent_task)) { + task_set_task_error(pParent_task, TASK_ERROR_RUN_SUCCESS); + + /* get parent task output from child tasks */ + task_collect_parent_task_output_parameter(pParent_task); + + /* send parent task done message to engine controller itself */ + engine_controller_send_parent_task_done_msg_to_itseft(pParent_task); + + /* TODO : update */ + } else { + /* remove dependencies related to done operation */ + /* if some operations has no dependency, then push in thread_pool */ + runnable_child_task_list = collect_become_runnable_child_tasks_by_remove_control_flow(pParent_task, child_task_index_in_parent_task); + + /* send task message to engine controller itself */ + engine_controller_send_new_runnerable_child_task_msgs_to_itself(runnable_child_task_list, pReceived_task_msg); + } + } + break; + case TASK_ERROR_RUN_FAILED: + case TASK_ERROR_CANCELED: + pParent_task = task_get_parent_task(pTask); + + if (task_is_not_yet_run(pParent_task)) { + /* FIXME : do i have to wait other child task finished? */ + task_set_task_error(pParent_task, pTask->task_error); + + /* send parent task done message to engine controller itself */ + engine_controller_send_parent_task_done_msg_to_itseft(pParent_task); + } + break; + default: /* TODO : other task error must be handled */ + break; + } + } + + task_unref_task(pTask); + + } else if (pReceived_task_msg->task_state == TASK_CANCEL) { + pTask = task_pool_fetch_task(pTask_pool, pReceived_task_msg->u.request_msg_id); + if (pTask != NULL) { + engine_controller_request_msg_t *pRequest_msg = (engine_controller_request_msg_t *)getData(pTask->pRequestMsg); + FW_LOGD("\n\n======= [CONTROLLER : TASK_CANCEL] =========\ncancel task(request message id : %d, task name : %s) related to root_task(msg id : %d, task spec id : %d)\n\n", pReceived_task_msg->u.request_msg_id, pTask->pTask_spec->task_name, pRequest_msg->msg_head.msg_id, pRequest_msg->task_spec_id); + + task_do_cancellation(pTask); + task_unref_task(pTask); + } else { + /* TODO : task request may be not handled yet. becuase cancel request has high priority */ + FW_LOGD("\n\n======= [CONTROLLER : TASK_CANCEL] =========\ncancel task(request message id : %d) received, " "but no such task exist. it could be already executed or you never requested\n\n", pReceived_task_msg->u.request_msg_id); + } + } else if (pReceived_task_msg->task_state == TASK_CANCEL_ALL) { + FW_LOGD("\n\n======= [CONTROLLER : TASK_CANCEL_ALL] =========\n\n\n"); + + GList *all_tasks_list = task_pool_fetch_all_tasks(pTask_pool); + GList *iter = NULL; + task_t *pTask = NULL; + ec_uint i = 0; + engine_controller_request_msg_t *pRequest_msg = NULL; + for (i = 0, iter = all_tasks_list; iter != NULL; i++, iter = g_list_next(iter)) { + pTask = iter->data; + pRequest_msg = (engine_controller_request_msg_t *)getData(pTask->pRequestMsg); + FW_LOGD("\n\n======= [CONTROLLER : TASK_CANCEL_ALL_DETAIL (%d)] =========\ncancel task(request message id : %d, task name : %s) related to root_task(msg id : %d, task spec id : %d)\n\n", i, pReceived_task_msg->u.request_msg_id, pTask->pTask_spec->task_name, pRequest_msg->msg_head.msg_id, pRequest_msg->task_spec_id); + + task_do_cancellation(pTask); + task_unref_task(pTask); + } + + if (all_tasks_list != NULL) + g_list_free(all_tasks_list); + } else { + FW_LOGE("task msg has invalid task state\n"); + assert(false); + } + +last: + task_message_free(pReceived_task_msg); + } + + return NULL; /* TODO */ +} + +static void *engine_controller_receiver_logic(engine_controller_receiver_t *pEngine_controller_receiver) +{ + fw_async_queue_t *pQueue = pEngine_controller_receiver->pQueue; + task_info_pool_t *pTask_info_pool = pEngine_controller_receiver->pTask_info_pool; + queuing_rule_spec_pool_t *pQueuing_rule_spec_pool = pEngine_controller_receiver->pQueuing_rule_spec_pool; + engine_controller_error_t ec_error = ENGINE_CONTROLLER_OK; + + task_message_t *pTask_msg = NULL; + fw_assert_condition(pQueue != NULL, "engine controller receiver has no queue\n"); + + while (true) { + void *pMsg = fw_async_queue_receive_msg(pQueue); + if (engine_controller_msg_is_register_msg(pMsg)) { + FW_LOGD("\n\n======= [RECEIVER : REGISTER TASK SPEC MSG] =========\n\n"); + engine_controller_register_msg_t *pRegister_msg = (engine_controller_register_msg_t *)pMsg; + + /* create task info and add to task info pool */ + task_info_t *pTask_info = task_info_new(pRegister_msg->task_spec_id, pRegister_msg->pTask_spec); + + task_info_pool_add_task_info(pTask_info_pool, pTask_info, false); + /* TODO */ + + engine_controller_msg_free_register_msg(pRegister_msg); + } else if (engine_controller_msg_is_unregister_msg(pMsg)) { + FW_LOGD("\n\n======= [RECEIVER : UNREGISTER TASK SPEC MSG] =========\n\n"); + /* TODO */ + } else if (engine_controller_msg_is_register_queuing_rule_spec_msg(pMsg)) { + FW_LOGD("\n\n======= [RECEIVER : REGISTER QUEUING RULE SPEC MSG] =========\n\n"); + ec_uint queuing_rule_id = 0; + engine_controller_register_queuing_rule_spec_msg_t *pQueuing_rule_register_Msg = (engine_controller_register_queuing_rule_spec_msg_t *)pMsg; + + ec_error = queuing_rule_spec_pool_add_queuing_rule_spec(pQueuing_rule_spec_pool, pQueuing_rule_register_Msg->pSpec, &queuing_rule_id); + + if (pQueuing_rule_register_Msg->register_finish_callback) { + pQueuing_rule_register_Msg->register_finish_callback(ec_error, queuing_rule_id, pQueuing_rule_register_Msg->usr_data); + } + /* TODO */ + } else if (engine_controller_msg_is_cancel_msg(pMsg)) { + FW_LOGD("\n\n======= [RECEIVER : CANCEL MSG] =========\n\n"); + engine_controller_cancel_msg_t *pCancel_Msg = ((engine_controller_cancel_msg_t *)pMsg); + + pTask_msg = task_message_create(TASK_CANCEL, NULL, pCancel_Msg->request_msg_id_to_cancel); + if (pTask_msg == NULL) { + FW_LOGE("out of memory during task_message_create\n"); + assert(false); + continue; + } + + send_msg_to_engine_controller_with_compare_priority(pTask_msg, compare_priority_of_task_message_append_way, NULL); + + } else if (engine_controller_msg_is_cancel_all_msg(pMsg)) { + FW_LOGD("\n\n======= [RECEIVER : CANCEL ALL MSG] =========\n\n"); + + pTask_msg = task_message_create(TASK_CANCEL_ALL, NULL, 0); + if (pTask_msg == NULL) { + FW_LOGE("out of memory during task_message_create\n"); + assert(false); + continue; + } + + send_msg_to_engine_controller_with_compare_priority(pTask_msg, compare_priority_of_task_message_append_way, NULL); + + } else if (engine_controller_msg_is_request_msg(pMsg)) { + + FW_LOGD("\n\n======= [RECEIVER : REQUEST MSG] =========\n\n"); + engine_controller_request_msg_t *pRequest_Msg = ((engine_controller_request_msg_t *)pMsg); + + task_info_t *pTask_info = task_info_pool_search_task_info(pTask_info_pool, pRequest_Msg->task_spec_id); + task_spec_t *pTask_spec = NULL; + task_t *pTask = NULL; + + if (pTask_info == NULL) { + FW_LOGI("no msg spec found\n"); + } else { + /* create task */ + pTask_spec = pTask_info->pTask_spec; + pTask = task_alloc_root_task(pTask_spec, pRequest_Msg, pTask_info_pool); + if (pTask == NULL) { + FW_LOGE("out of memory during task_alloc_root_task\n"); + assert(false); + continue; + } + + pTask_msg = task_message_create(TASK_ROOT_START, pTask, 0); + if (pTask_msg == NULL) { + FW_LOGE("out of memory during task_message_create\n"); + assert(false); + continue; + } + + send_msg_to_engine_controller_with_compare_priority(pTask_msg, compare_priority_of_task_message_append_way, NULL); + task_unref_task(pTask); + } + } else { + FW_LOGD("\n\n======= [RECEIVER : UNKNOWN MSG] =========\n\n"); + /* unknown msg type */ + FW_LOGE("unknown msg type\n"); + } + } + return NULL; /* TODO */ +} + +engine_controller_t *alloc_engine_controller(ec_uint max_thread_count) +{ + engine_controller_t *pEngine_controller = (engine_controller_t *)calloc(1, sizeof(engine_controller_t)); + if (pEngine_controller == NULL) { + goto return_part; + } + + pEngine_controller->pQueue = fw_async_queue_alloc(); + if (pEngine_controller->pQueue == NULL) { + goto error_part; + } + + pEngine_controller->pTask_pool = task_pool_create_task_pool(); + if (pEngine_controller->pTask_pool == NULL) { + goto error_part; + } + + pEngine_controller->pQueuing_rule_spec_pool = NULL; + + pEngine_controller->pThread_pool = thread_pool_alloc_and_init(max_thread_count); + if (pEngine_controller->pThread_pool == NULL) { + goto error_part; + } + + pCancel_TSK = thread_pool_get_cancel_TSK(pEngine_controller->pThread_pool); + if (pCancel_TSK == NULL) { + goto error_part; + } + +return_part: + return pEngine_controller; + +error_part: + free_engine_controller(pEngine_controller); + return NULL; +} + +void free_engine_controller(engine_controller_t *pEngine_controller) +{ + if (pEngine_controller != NULL) { + /* TODO */ + } +} + +/* TODO error handling */ +void run_engine_controller(engine_controller_t *pEngine_controller) +{ + pthread_create(&(pEngine_controller->thread_id), NULL, (thread_start_routine) engine_controller_logic, (void *)pEngine_controller); + pthread_detach(pEngine_controller->thread_id); +} + +engine_controller_receiver_t *alloc_engine_controller_receiver(engine_controller_t *pEngine_controller) +{ + engine_controller_receiver_t *pReceiver = NULL; + + pReceiver = (engine_controller_receiver_t *)calloc(1, sizeof(engine_controller_receiver_t)); + if (pReceiver == NULL) { + goto return_part; + } + + pReceiver->next_msg_id = 0; + + pReceiver->pQueue = fw_async_queue_alloc(); + if (pReceiver->pQueue == NULL) { + goto error_part; + } + + pReceiver->pTask_info_pool = task_info_pool_alloc(); + if (pReceiver->pTask_info_pool == NULL) { + goto error_part; + } + + /* TODO : remove below 1024 hard coding */ + pReceiver->pQueuing_rule_spec_pool = queuing_rule_spec_pool_alloc(1024, pReceiver->pTask_info_pool); + if (pReceiver->pQueuing_rule_spec_pool == NULL) { + goto error_part; + } + + pReceiver->pEngine_controller = pEngine_controller; + + /* TODO */ + pEngine_controller->pQueuing_rule_spec_pool = pReceiver->pQueuing_rule_spec_pool; + +return_part: + return pReceiver; + +error_part: + free_engine_controller_receiver(pReceiver); + return NULL; +} + +void free_engine_controller_receiver(engine_controller_receiver_t *pEngine_controller_receiver) +{ + if (pEngine_controller_receiver != NULL) { + /* TODO */ + + /* NOTE : do not free engine_controller */ + } +} + +/* TODO error handling */ +void run_engine_controller_receiver(engine_controller_receiver_t *pEngine_controller_receiver) +{ + /* TODO */ + pthread_create(&(pEngine_controller_receiver->thread_id), NULL, (thread_start_routine) engine_controller_receiver_logic, (void *)pEngine_controller_receiver); + pthread_detach(pEngine_controller_receiver->thread_id); +} + +void send_msg_to_engine_controller_receiver(engine_controller_msg_head_t *msg) +{ + /* msg id management */ + msg->msg_id = g_atomic_int_exchange_and_add(&(pGlobal_engine_controller_receiver->next_msg_id), 1); + FW_LOGD("============= msg id = %d =============\n", msg->msg_id); + + fw_async_queue_send_msg(pGlobal_engine_controller_receiver->pQueue, (void *)msg); +} + +void send_msg_to_engine_controller(task_message_t *pTask_msg) +{ + fw_async_queue_send_msg(pGlobal_engine_controller->pQueue, (void *)pTask_msg); +} + +void send_msg_to_engine_controller_with_compare_priority(task_message_t *pTask_msg, compare_task_msg_priority_func ctmp_func, ec_pointer user_data) +{ + fw_async_queue_send_msg_with_compare_priority(pGlobal_engine_controller->pQueue, (void *)pTask_msg, (compare_priority_func) ctmp_func, (void *)user_data); +} + +/* external interfaces */ +bool init_engine_controller(unsigned int max_thread_count) +{ + bool success = true; + engine_controller_t *pEngine_controller = NULL; + engine_controller_receiver_t *pEngine_controller_receiver = NULL; + + /* alloc engine controller */ + pEngine_controller = alloc_engine_controller(max_thread_count); + if (pEngine_controller == NULL) { + success = false; + goto return_part; + } + + /* alloc engine controller receiver */ + pEngine_controller_receiver = alloc_engine_controller_receiver(pEngine_controller); + if (pEngine_controller_receiver == NULL) { + success = false; + goto return_part; + } + + /* run engine controller */ + run_engine_controller(pEngine_controller); + run_engine_controller_receiver(pEngine_controller_receiver); + +return_part: + if (success) { + pGlobal_engine_controller = pEngine_controller; + pGlobal_engine_controller_receiver = pEngine_controller_receiver; + } else { + /* TODO : stop engine controller & receiver & free */ + } + + return success; +} + +/* TODO : error handling */ +void engine_controller_register_task_spec(ec_uint task_spec_id, ec_char *task_spec_name, task_spec_t *pTask_spec, calculate_identifier_func cal_func) +{ + engine_controller_register_msg_t *pRegister_msg = engine_controller_msg_create_register_msg(task_spec_id, pTask_spec, cal_func); + send_msg_to_engine_controller_receiver((engine_controller_msg_head_t *)pRegister_msg); +} + +void engine_controller_async_register_queuing_rule_spec(queuing_rule_spec_t *pSpec, register_finish_callback_func register_finish_callback, ec_pointer usr_data) +{ + engine_controller_register_queuing_rule_spec_msg_t *pMsg = engine_controller_msg_create_register_queuing_rule_spec_msg(pSpec, register_finish_callback, usr_data); + + send_msg_to_engine_controller_receiver((engine_controller_msg_head_t *)pMsg); +} + +void engine_controller_sync_register_queuing_rule_spec(queuing_rule_spec_t *pSpec, engine_controller_error_t *ec_error, ec_uint *registered_id) +{ + /* TODO */ +} + +/* TODO : error handling */ +void engine_controller_async_request_task(ec_uint task_spec_id, ec_uint identifier, ec_int cnt_in_param, ec_int *in_param_index_array, ECValueType * in_param_value_type_array, ec_pointer * in_param_value_array, task_finish_callback_func task_finish_callback, ec_pointer simple_task_finish_callback_usr_data, ec_int *request_id) +{ + engine_controller_request_msg_t *pMsg = engine_controller_msg_create_request_msg(task_spec_id, identifier, cnt_in_param, + in_param_index_array, in_param_value_type_array, in_param_value_array, + task_finish_callback, simple_task_finish_callback_usr_data); + + send_msg_to_engine_controller_receiver((engine_controller_msg_head_t *)pMsg); + *request_id = pMsg->msg_head.msg_id; +} + +void engine_controller_sync_request_task(ec_uint task_spec_id, ec_uint identifier, ec_int cnt_in_param, ec_int *in_param_index_array, ECValueType * in_param_value_type_array, ec_pointer * in_param_value_array, ec_int *request_id, task_error_t * task_error, ec_uint *out_param_cnt, param_t ***out_param_array) +{ + task_finish_callback_func sync_task_finish_callback = static_sync_task_finish_callback; + sync_task_output_t *pSync_task_output = alloc_and_init_sync_task_output(); + if (pSync_task_output == NULL) { + return; /* error */ + } + + engine_controller_request_msg_t *pMsg = engine_controller_msg_create_request_msg(task_spec_id, identifier, cnt_in_param, + in_param_index_array, in_param_value_type_array, in_param_value_array, + sync_task_finish_callback, pSync_task_output); + + pthread_mutex_lock(&(pSync_task_output->mutex)); + send_msg_to_engine_controller_receiver((engine_controller_msg_head_t *)pMsg); + + while (!g_atomic_int_get(&(pSync_task_output->output_set_done))) { + pthread_cond_wait(&(pSync_task_output->output_set_done_cond), &(pSync_task_output->mutex)); + } + + pthread_mutex_unlock(&(pSync_task_output->mutex)); + + *request_id = pMsg->msg_head.msg_id; + *task_error = pSync_task_output->task_error; + *out_param_cnt = pSync_task_output->out_param_cnt; + *out_param_array = pSync_task_output->out_param_array; + + destory_sync_task_output(pSync_task_output); +} + +void engine_controller_cancel_task(ec_int request_id_to_cancel) +{ + engine_controller_cancel_msg_t *pCancel_msg = engine_controller_msg_create_cancel_msg(request_id_to_cancel); + send_msg_to_engine_controller_receiver((engine_controller_msg_head_t *)pCancel_msg); +} + +void engine_controller_cancel_all_task() +{ + engine_controller_cancel_all_msg_t *pCancel_all_msg = engine_controller_msg_create_cancel_all_msg(); + send_msg_to_engine_controller_receiver((engine_controller_msg_head_t *)pCancel_all_msg); +} diff --git a/framework/src/EngineController/engine_controller_message.c b/framework/src/EngineController/engine_controller_message.c new file mode 100755 index 0000000..767eee2 --- /dev/null +++ b/framework/src/EngineController/engine_controller_message.c @@ -0,0 +1,235 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Wook Choi + */ + +#include +#include +#include "EngineController/engine_controller_message.h" + +void engine_controller_msg_set_msg_head(engine_controller_msg_head_t *pMsg_head, engine_controller_msg_type_t msg_type, ec_uint msg_id) +{ + if (pMsg_head != NULL) { + pMsg_head->msg_id = msg_id; + pMsg_head->msg_type = msg_type; + } +} + +engine_controller_register_msg_t *engine_controller_msg_create_register_msg(ec_uint task_spec_id, task_spec_t *pTask_spec, calculate_identifier_func id_calc_func) +{ + engine_controller_register_msg_t *pRegister_msg = (engine_controller_register_msg_t *)calloc(1, sizeof(engine_controller_register_msg_t)); + if (pRegister_msg == NULL) { + goto error_part; + } + + engine_controller_msg_set_msg_head(&(pRegister_msg->msg_head), ENGINE_CONTROLLER_REGISTER_MSG_TYPE, 0); + + pRegister_msg->task_spec_id = task_spec_id; + pRegister_msg->pTask_spec = task_spec_ref(pTask_spec); + if (id_calc_func != NULL) { + pRegister_msg->id_calc_func = id_calc_func; + } + + return pRegister_msg; +error_part: + engine_controller_msg_free_register_msg(pRegister_msg); + return NULL; +} + +void engine_controller_msg_free_register_msg(engine_controller_register_msg_t *pRegister_msg) +{ + if (pRegister_msg != NULL) { + if (pRegister_msg->pTask_spec != NULL) { + task_spec_unref(pRegister_msg->pTask_spec); + } + + free(pRegister_msg); + } +} + +engine_controller_register_queuing_rule_spec_msg_t *engine_controller_msg_create_register_queuing_rule_spec_msg(queuing_rule_spec_t *pSpec, register_finish_callback_func register_finish_callback, ec_pointer usr_data) +{ + engine_controller_register_queuing_rule_spec_msg_t *pMsg = (engine_controller_register_queuing_rule_spec_msg_t *)calloc(1, sizeof(engine_controller_register_queuing_rule_spec_msg_t)); + if (pMsg == NULL) { + goto error_part; + } + + engine_controller_msg_set_msg_head(&(pMsg->msg_head), ENGINE_CONTROLLER_REGISTER_QUEUING_RULE_SPEC_MSG_TYPE, 0); + pMsg->pSpec = queuing_rule_spec_ref(pSpec); + + pMsg->register_finish_callback = register_finish_callback; + pMsg->usr_data = usr_data; + + return pMsg; +error_part: + engine_controller_msg_free_register_queuing_rule_spec_msg(pMsg); + return NULL; +} + +void engine_controller_msg_free_register_queuing_rule_spec_msg(engine_controller_register_queuing_rule_spec_msg_t *pMsg) +{ + if (pMsg != NULL) { + /* TODO */ + } +} + +engine_controller_request_msg_t *engine_controller_msg_create_request_msg(ec_uint task_spec_id, ec_uint identifier, ec_int cnt_in_param, ec_int *in_param_index_array, ECValueType * in_param_value_type_array, ec_pointer * in_param_value_array, task_finish_callback_func task_finish_callback, ec_pointer simple_task_finish_callback_usr_data) +{ + engine_controller_request_msg_t *pMsg = (engine_controller_request_msg_t *)calloc(1, sizeof(engine_controller_request_msg_t)); + ec_int i = 0; + if (pMsg == NULL) { + goto error_part; + } + + engine_controller_msg_set_msg_head(&(pMsg->msg_head), ENGINE_CONTROLLER_REQUEST_MSG_TYPE, 0); + pMsg->task_spec_id = task_spec_id; + pMsg->identifier = identifier; + pMsg->cnt_in_param = cnt_in_param; + if (cnt_in_param > 0) { + pMsg->in_param_index_array = (ec_int *)malloc(cnt_in_param * sizeof(ec_int)); + if (pMsg->in_param_index_array == NULL) { + goto error_part; + } + memcpy(pMsg->in_param_index_array, in_param_index_array, cnt_in_param * sizeof(ec_int)); + + pMsg->in_param_value_array = (param_value_t *)calloc(cnt_in_param, sizeof(param_value_t)); + if (pMsg->in_param_value_array == NULL) { + goto error_part; + } + + for (i = 0; i < cnt_in_param; i++) { + param_value_set_value(&(pMsg->in_param_value_array[i]), in_param_value_type_array[i], in_param_value_array[i]); + } + } + pMsg->task_finish_callback = task_finish_callback; + pMsg->simple_task_finish_callback_usr_data = simple_task_finish_callback_usr_data; + + return pMsg; + +error_part: + engine_controller_msg_free_request_msg(pMsg); + return NULL; +} + +void engine_controller_msg_free_request_msg(engine_controller_request_msg_t *pMsg) +{ + if (pMsg != NULL) { + /* TODO */ + + free(pMsg); + } +} + +engine_controller_cancel_all_msg_t *engine_controller_msg_create_cancel_all_msg() +{ + engine_controller_cancel_all_msg_t *pCancel_all_msg = (engine_controller_cancel_all_msg_t *)calloc(1, sizeof(engine_controller_cancel_all_msg_t)); + if (pCancel_all_msg == NULL) { + goto error_part; + } + + engine_controller_msg_set_msg_head(&(pCancel_all_msg->msg_head), ENGINE_CONTROLLER_CANCEL_ALL_MSG_TYPE, 0); + + return pCancel_all_msg; +error_part: + engine_controller_msg_free_cancel_all_msg(pCancel_all_msg); + return NULL; +} + +void engine_controller_msg_free_cancel_all_msg(engine_controller_cancel_all_msg_t *pCancel_all_msg) +{ + if (pCancel_all_msg != NULL) { + /* TODO */ + } +} + +engine_controller_cancel_msg_t *engine_controller_msg_create_cancel_msg(ec_uint request_msg_id_to_cancel) +{ + engine_controller_cancel_msg_t *pCancel_msg = (engine_controller_cancel_msg_t *)calloc(1, sizeof(engine_controller_cancel_msg_t)); + if (pCancel_msg == NULL) { + goto error_part; + } + + engine_controller_msg_set_msg_head(&(pCancel_msg->msg_head), ENGINE_CONTROLLER_CANCEL_MSG_TYPE, 0); + pCancel_msg->request_msg_id_to_cancel = request_msg_id_to_cancel; + + return pCancel_msg; +error_part: + engine_controller_msg_free_cancel_msg(pCancel_msg); + return NULL; +} + +void engine_controller_msg_free_cancel_msg(engine_controller_cancel_msg_t *pCancel_msg) +{ + if (pCancel_msg != NULL) { + /* TODO */ + } +} + +ec_boolean engine_controller_msg_check_same_msg_type(engine_controller_msg_head_t *pHead, engine_controller_msg_type_t msg_type) +{ + if (pHead->msg_type == msg_type) { + return true; + } else { + return false; + } +} + +ec_boolean engine_controller_msg_is_register_msg(engine_controller_msg_head_t *pHead) +{ + return engine_controller_msg_check_same_msg_type(pHead, ENGINE_CONTROLLER_REGISTER_MSG_TYPE); +} + +ec_boolean engine_controller_msg_is_unregister_msg(engine_controller_msg_head_t *pHead) +{ + return engine_controller_msg_check_same_msg_type(pHead, ENGINE_CONTROLLER_UNREGISTER_MSG_TYPE); +} + +ec_boolean engine_controller_msg_is_register_queuing_rule_spec_msg(engine_controller_msg_head_t *pHead) +{ + return engine_controller_msg_check_same_msg_type(pHead, ENGINE_CONTROLLER_REGISTER_QUEUING_RULE_SPEC_MSG_TYPE); +} + +ec_boolean engine_controller_msg_is_request_msg(engine_controller_msg_head_t *pHead) +{ + return engine_controller_msg_check_same_msg_type(pHead, ENGINE_CONTROLLER_REQUEST_MSG_TYPE); +} + +ec_boolean engine_controller_msg_is_cancel_msg(engine_controller_msg_head_t *pHead) +{ + return engine_controller_msg_check_same_msg_type(pHead, ENGINE_CONTROLLER_CANCEL_MSG_TYPE); +} + +ec_boolean engine_controller_msg_is_cancel_all_msg(engine_controller_msg_head_t *pHead) +{ + return engine_controller_msg_check_same_msg_type(pHead, ENGINE_CONTROLLER_CANCEL_ALL_MSG_TYPE); +} diff --git a/framework/src/EngineController/graph_edge_pool.c b/framework/src/EngineController/graph_edge_pool.c new file mode 100755 index 0000000..8947bd6 --- /dev/null +++ b/framework/src/EngineController/graph_edge_pool.c @@ -0,0 +1,110 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Wook Choi + */ + +#include /* TODO : replace with framework assert */ +#include +#include +#include "EngineController/graph_edge_pool.h" +#include "EngineController/hash_set.h" + +struct graph_edge_pool_s { + GHashTable *from_graph_node_hash; /* containing hash_set_t* to_graph_nodes */ +}; + +graph_edge_pool_t *graph_edge_pool_new() +{ + graph_edge_pool_t *pPool = (graph_edge_pool_t *)calloc(1, sizeof(graph_edge_pool_t)); + if (pPool == NULL) { + goto error_part; + } + + pPool->from_graph_node_hash = g_hash_table_new(g_direct_hash, g_direct_equal); + if (pPool->from_graph_node_hash == NULL) { + goto error_part; + } + + return pPool; + +error_part: + graph_edge_pool_free(pPool); + return NULL; +} + +void graph_edge_pool_free(graph_edge_pool_t *pPool) +{ + if (pPool != NULL) { + if (pPool->from_graph_node_hash != NULL) { + g_hash_table_destroy(pPool->from_graph_node_hash); + } + free(pPool); + } +} + +/* return add success or not */ +/* if already exist edge added, then return false */ +ec_boolean graph_edge_pool_add_edge(graph_edge_pool_t *pPool, ec_constpointer from_node, ec_constpointer to_node) +{ + ec_boolean add_success = false; + hash_set_t *pTo_node_set = NULL; + + pTo_node_set = g_hash_table_lookup(pPool->from_graph_node_hash, from_node); + if (pTo_node_set == NULL) { + pTo_node_set = hash_set_create(); + if (pTo_node_set == NULL) { + assert(false); + } + g_hash_table_insert(pPool->from_graph_node_hash, (gpointer) from_node, (gpointer) pTo_node_set); + } + + add_success = hash_set_add(pTo_node_set, to_node); + + return add_success; +} + +GList *graph_edge_pool_query_to_node_list(graph_edge_pool_t *pPool, ec_constpointer from_node) +{ + GList *to_nodes_list = NULL; + + hash_set_t *pTo_node_set = NULL; + pTo_node_set = g_hash_table_lookup(pPool->from_graph_node_hash, from_node); + if (pTo_node_set == NULL) { + goto return_part; + } + + to_nodes_list = hash_set_get_element_list(pTo_node_set); + +return_part: + return to_nodes_list; +} diff --git a/framework/src/EngineController/hash_set.c b/framework/src/EngineController/hash_set.c new file mode 100755 index 0000000..a0ea89e --- /dev/null +++ b/framework/src/EngineController/hash_set.c @@ -0,0 +1,107 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Wook Choi + */ + +#include +#include +#include "Utility/fw_log.h" +#include "EngineController/hash_set.h" + +#define LOG_TAG "AF_EC" + +hash_set_t *hash_set_create() +{ + hash_set_t *pHash_set = (hash_set_t *)calloc(1, sizeof(hash_set_t)); + if (pHash_set == NULL) { + goto error_part; + } + + pHash_set->pHashTable = NULL; + + return pHash_set; + +error_part: + return NULL; +} + +void hash_set_free(hash_set_t *pHash_set) +{ + if (pHash_set != NULL) { + if (pHash_set->pHashTable != NULL) { + g_hash_table_destroy(pHash_set->pHashTable); + } + + free(pHash_set); + } +} + +ec_boolean hash_set_add(hash_set_t *pHash_set, ec_constpointer pElement) +{ + ec_boolean success = true; + + if (pHash_set == NULL) { + FW_LOGE("pHash_set == NULL\n"); + success = false; + goto return_part; + } + + if (pHash_set->pHashTable == NULL) { + pHash_set->pHashTable = g_hash_table_new(g_direct_hash, g_direct_equal); + } + + g_hash_table_insert(pHash_set->pHashTable, (gpointer) pElement, (gpointer) pElement); + +return_part: + return success; +} + +GList *hash_set_get_element_list(hash_set_t *pHash_set) +{ + GList *element_list = NULL; + if (pHash_set == NULL) { + FW_LOGE("pHash_set == NULL\n"); + goto error_part; + } + + if (pHash_set->pHashTable != NULL) { + element_list = g_hash_table_get_values(pHash_set->pHashTable); + } + return element_list; + +error_part: + if (element_list != NULL) { + g_list_free(element_list); + } + return NULL; +} diff --git a/framework/src/EngineController/param.c b/framework/src/EngineController/param.c new file mode 100755 index 0000000..17392ac --- /dev/null +++ b/framework/src/EngineController/param.c @@ -0,0 +1,74 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Wook Choi + */ + +#include +#include +#include "EngineController/param.h" +#include "EngineController/param_spec_internal.h" + +param_t *param_alloc_param(ec_uint read_ref_count, ec_uint write_ref_count, param_spec *pParam_spec, param_value_t *pParam_value) +{ + param_t *pParam = (param_t *)calloc(1, sizeof(param_t)); + if (pParam == NULL) { + goto error_part; + } + + pParam->read_ref_count = read_ref_count; + pParam->write_ref_count = write_ref_count; + pParam->pParam_spec = param_spec_ref(pParam_spec); + + if (pParam_value != NULL) { + param_value_set_value_with_other_param_value(&(pParam->param_value), pParam_value); + } else { + if (pParam_spec->flags & EC_PARAM_FLAG_INPUT) { + param_value_set_value_with_other_param_value(&(pParam->param_value), &(pParam_spec->default_value)); + } + } + + return pParam; +error_part: + param_free_param(pParam); + return NULL; +} + +void param_free_param(param_t *pParam) +{ + if (pParam != NULL) { + if (pParam->pParam_spec != NULL) { + param_spec_unref(pParam->pParam_spec); + } + free(pParam); + } +} diff --git a/framework/src/EngineController/param_spec.c b/framework/src/EngineController/param_spec.c new file mode 100755 index 0000000..0fb1ac2 --- /dev/null +++ b/framework/src/EngineController/param_spec.c @@ -0,0 +1,560 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Wook Choi + */ + +#include +#include +#include +#include +#include /* TODO : replace with fw_assert.h */ +#include +#include "EngineController/param_spec.h" +#include "EngineController/param_spec_internal.h" + +static inline ec_boolean is_flag_on(ECParamFlags flags, ECParamFlags check_flag); +static inline void on_flag(ECParamFlags *flags, ECParamFlags on_flag); + +/* TODO */ +static void free_param_spec(param_spec *pParam_spec); + +/* internal */ +static ec_boolean param_char_validate_func(ec_int8 value, ec_int8 minimum, ec_int8 maximum); +static ec_boolean param_uchar_validate_func(ec_uint8 value, ec_uint8 minimum, ec_uint8 maximum); +static ec_boolean param_int_validate_func(ec_int value, ec_int minimum, ec_int maximum); +static ec_boolean param_uint_validate_func(ec_uint value, ec_uint minimum, ec_uint maximum); +static ec_boolean param_float_validate_func(ec_float value, ec_float minimum, ec_float maximum); +static ec_boolean param_double_validate_func(ec_double value, ec_double minimum, ec_double maximum); + +static param_spec_char_validate *alloc_init_param_spec_char_validate(ec_int8 minimum, ec_int8 maximum, char_validate_func valid_func); +static param_spec_uchar_validate *alloc_init_param_spec_uchar_validate(ec_uint8 minimum, ec_uint8 maximum, uchar_validate_func valid_func); +static param_spec_int_validate *alloc_init_param_spec_int_validate(ec_int minimum, ec_int maximum, int_validate_func valid_func); +static param_spec_uint_validate *alloc_init_param_spec_uint_validate(ec_uint minimum, ec_uint maximum, uint_validate_func valid_func); +static param_spec_float_validate *alloc_init_param_spec_float_validate(ec_float minimum, ec_float maximum, float_validate_func valid_func); +static param_spec_double_validate *alloc_init_param_spec_double_validate(ec_double minimum, ec_double maximum, double_validate_func valid_func); + +static ec_boolean alloc_and_init_param_spec_number_type_validate(const ECValueType value_type, ec_constpointer minimum, ec_constpointer maximum, private_validate *pPrivate_validate); + +static param_spec *alloc_and_init_param_spec_default(const ECValueType value_type, const ec_char *name); + +static param_spec *alloc_and_init_param_spec_number_type(const ECValueType value_type, const ec_char *name, ec_boolean is_input, ec_boolean is_output, ec_boolean input_validate_on, ec_constpointer input_minimum, ec_constpointer input_maximum, ec_boolean input_default_on, ec_constpointer input_default_value, ec_boolean output_validate_on, ec_constpointer output_minimum, ec_constpointer output_maximum); + +static inline param_spec *alloc_and_init_param_spec_struct_type(const ec_char *name, ec_boolean is_input, ec_boolean is_output, ec_boolean input_validate_on, validate_struct_func_callback input_val_func, ec_boolean input_default_on, ec_constpointer input_default_value, ec_boolean output_validate_on, validate_struct_func_callback output_val_func, copy_struct_func_callback copy_func, free_struct_func_callback free_func); + +static ec_boolean param_char_validate_func(ec_int8 value, ec_int8 minimum, ec_int8 maximum) +{ + if (value < minimum) + return false; + if (value > maximum) + return false; + return true; +} + +static ec_boolean param_uchar_validate_func(ec_uint8 value, ec_uint8 minimum, ec_uint8 maximum) +{ + if (value < minimum) + return false; + if (value > maximum) + return false; + return true; +} + +static ec_boolean param_int_validate_func(ec_int value, ec_int minimum, ec_int maximum) +{ + if (value < minimum) + return false; + if (value > maximum) + return false; + return true; +} + +static ec_boolean param_uint_validate_func(ec_uint value, ec_uint minimum, ec_uint maximum) +{ + if (value < minimum) + return false; + if (value > maximum) + return false; + return true; +} + +static ec_boolean param_float_validate_func(ec_float value, ec_float minimum, ec_float maximum) +{ + if (value < minimum) + return false; + if (value > maximum) + return false; + return true; +} + +static ec_boolean param_double_validate_func(ec_double value, ec_double minimum, ec_double maximum) +{ + if (value < minimum) + return false; + if (value > maximum) + return false; + return true; +} + +static param_spec_char_validate *alloc_init_param_spec_char_validate(ec_int8 minimum, ec_int8 maximum, char_validate_func valid_func) +{ + param_spec_char_validate *pValid = (param_spec_char_validate *) malloc(sizeof(param_spec_char_validate)); + if (pValid == NULL) { + return NULL; + } + + pValid->minimum = minimum; + pValid->maximum = maximum; + pValid->valid_func = valid_func; + + return pValid; +} + +static param_spec_uchar_validate *alloc_init_param_spec_uchar_validate(ec_uint8 minimum, ec_uint8 maximum, uchar_validate_func valid_func) +{ + param_spec_uchar_validate *pValid = (param_spec_uchar_validate *) malloc(sizeof(param_spec_uchar_validate)); + if (pValid == NULL) { + return NULL; + } + + pValid->minimum = minimum; + pValid->maximum = maximum; + pValid->valid_func = valid_func; + + return pValid; +} + +static param_spec_int_validate *alloc_init_param_spec_int_validate(ec_int minimum, ec_int maximum, int_validate_func valid_func) +{ + param_spec_int_validate *pValid = (param_spec_int_validate *) malloc(sizeof(param_spec_int_validate)); + if (pValid == NULL) { + return NULL; + } + + pValid->minimum = minimum; + pValid->maximum = maximum; + pValid->valid_func = valid_func; + + return pValid; +} + +static param_spec_uint_validate *alloc_init_param_spec_uint_validate(ec_uint minimum, ec_uint maximum, uint_validate_func valid_func) +{ + param_spec_uint_validate *pValid = (param_spec_uint_validate *) malloc(sizeof(param_spec_uint_validate)); + if (pValid == NULL) { + return NULL; + } + + pValid->minimum = minimum; + pValid->maximum = maximum; + pValid->valid_func = valid_func; + + return pValid; +} + +static param_spec_float_validate *alloc_init_param_spec_float_validate(ec_float minimum, ec_float maximum, float_validate_func valid_func) +{ + param_spec_float_validate *pValid = (param_spec_float_validate *) malloc(sizeof(param_spec_float_validate)); + if (pValid == NULL) { + return NULL; + } + + pValid->minimum = minimum; + pValid->maximum = maximum; + pValid->valid_func = valid_func; + + return pValid; +} + +static param_spec_double_validate *alloc_init_param_spec_double_validate(ec_double minimum, ec_double maximum, double_validate_func valid_func) +{ + param_spec_double_validate *pValid = (param_spec_double_validate *) malloc(sizeof(param_spec_double_validate)); + if (pValid == NULL) { + return NULL; + } + + pValid->minimum = minimum; + pValid->maximum = maximum; + pValid->valid_func = valid_func; + + return pValid; +} + +static param_spec *alloc_and_init_param_spec_default(const ECValueType value_type, const ec_char *name) +{ + param_spec *pParam_spec = (param_spec *)calloc(1, sizeof(param_spec)); + if (pParam_spec == NULL) { + return NULL; + } + + ec_char *dup_name = strdup(name); + if (dup_name == NULL) { + free_param_spec(pParam_spec); + return NULL; + } + + pParam_spec->ref_count = 1; + pParam_spec->value_type = value_type; + pParam_spec->name = dup_name; + pParam_spec->flags = EC_PARAM_FLAG_DEFAULT; + + return pParam_spec; +} + +static ec_boolean alloc_and_init_param_spec_number_type_validate(const ECValueType value_type, ec_constpointer minimum, ec_constpointer maximum, private_validate *pPrivate_validate) +{ + ec_boolean success = false; + switch (value_type) { + case EC_VALUE_TYPE_CHAR: + { + param_spec_char_validate *pValid = alloc_init_param_spec_char_validate(*(ec_int8 *) minimum, *(ec_int8 *) maximum, param_char_validate_func); + if (pValid == NULL) { + goto return_part; + } + pPrivate_validate->char_validate = pValid; + } + break; + case EC_VALUE_TYPE_UCHAR: + { + param_spec_uchar_validate *pValid = alloc_init_param_spec_uchar_validate(*(ec_uint8 *) minimum, *(ec_uint8 *) maximum, param_uchar_validate_func); + if (pValid == NULL) { + goto return_part; + } + pPrivate_validate->uchar_validate = pValid; + } + break; + case EC_VALUE_TYPE_INT: + { + param_spec_int_validate *pValid = alloc_init_param_spec_int_validate(*(ec_int *)minimum, *(ec_int *)maximum, param_int_validate_func); + if (pValid == NULL) { + goto return_part; + } + pPrivate_validate->int_validate = pValid; + } + break; + case EC_VALUE_TYPE_UINT: + { + param_spec_uint_validate *pValid = alloc_init_param_spec_uint_validate(*(ec_uint *)minimum, *(ec_uint *)maximum, param_uint_validate_func); + if (pValid == NULL) { + goto return_part; + } + pPrivate_validate->uint_validate = pValid; + } + break; + case EC_VALUE_TYPE_FLOAT: + { + param_spec_float_validate *pValid = alloc_init_param_spec_float_validate(*(ec_float *) minimum, *(ec_float *) maximum, param_float_validate_func); + if (pValid == NULL) { + goto return_part; + } + pPrivate_validate->float_validate = pValid; + } + break; + case EC_VALUE_TYPE_DOUBLE: + { + param_spec_double_validate *pValid = alloc_init_param_spec_double_validate(*(ec_double *) minimum, *(ec_double *) maximum, param_double_validate_func); + if (pValid == NULL) { + goto return_part; + } + pPrivate_validate->double_validate = pValid; + } + break; + default: + assert(false); + } + + success = true; + +return_part: + return success; +} + +static param_spec *alloc_and_init_param_spec_number_type(const ECValueType value_type, const ec_char *name, ec_boolean is_input, ec_boolean is_output, ec_boolean input_validate_on, ec_constpointer input_minimum, ec_constpointer input_maximum, ec_boolean input_default_on, ec_constpointer input_default_value, ec_boolean output_validate_on, ec_constpointer output_minimum, ec_constpointer output_maximum) +{ + ec_boolean success = true; + param_spec *pParam_spec = alloc_and_init_param_spec_default(value_type, name); + if (pParam_spec == NULL) { + goto error_part; + } + + if (is_input) { + on_flag(&(pParam_spec->flags), EC_PARAM_FLAG_INPUT); + + if (input_validate_on) { + on_flag(&(pParam_spec->flags), EC_PARAM_FLAG_INPUT_VALIDATE_ON); + success = alloc_and_init_param_spec_number_type_validate(value_type, input_minimum, input_maximum, &(pParam_spec->input_validate)); + if (!success) { + goto error_part; + } + } + + if (input_default_on) { + on_flag(&(pParam_spec->flags), EC_PARAM_FLAG_INPUT_DEFAULT_VALUE_ON); + param_value_set_value(&(pParam_spec->default_value), value_type, input_default_value); + } + } + + if (is_output) { + on_flag(&(pParam_spec->flags), EC_PARAM_FLAG_OUTPUT); + success = alloc_and_init_param_spec_number_type_validate(value_type, output_minimum, output_maximum, &(pParam_spec->output_validate)); + } + + return pParam_spec; + +error_part: + free_param_spec(pParam_spec); + return NULL; +} + +static inline param_spec *alloc_and_init_param_spec_struct_type(const ec_char *name, ec_boolean is_input, ec_boolean is_output, ec_boolean input_validate_on, validate_struct_func_callback input_val_func, ec_boolean input_default_on, ec_constpointer input_default_value, ec_boolean output_validate_on, validate_struct_func_callback output_val_func, copy_struct_func_callback copy_func, free_struct_func_callback free_func) +{ + ec_boolean success = true; + param_spec *pParam_spec = alloc_and_init_param_spec_default(EC_VALUE_TYPE_STRUCT, name); + if (pParam_spec == NULL) { + goto error_part; + } + + if (is_input) { + on_flag(&(pParam_spec->flags), EC_PARAM_FLAG_INPUT); + + if (input_validate_on) { + on_flag(&(pParam_spec->flags), EC_PARAM_FLAG_INPUT_VALIDATE_ON); + pParam_spec->input_validate.struct_validate_func = input_val_func; + + if (!success) { + goto error_part; + } + } + + if (input_default_on) { + on_flag(&(pParam_spec->flags), EC_PARAM_FLAG_INPUT_DEFAULT_VALUE_ON); + param_value_set_value(&(pParam_spec->default_value), EC_VALUE_TYPE_STRUCT, input_default_value); + } + } + + if (is_output) { + on_flag(&(pParam_spec->flags), EC_PARAM_FLAG_OUTPUT); + pParam_spec->output_validate.struct_validate_func = output_val_func; + } + + pParam_spec->copy_struct_func = copy_func; + pParam_spec->free_struct_func = free_func; + + return pParam_spec; + +error_part: + free_param_spec(pParam_spec); + return NULL; +} + +inline ec_boolean is_input_flag_on(ECParamFlags flags) +{ + return is_flag_on(flags, EC_PARAM_FLAG_INPUT); +} + +inline ec_boolean is_output_flag_on(ECParamFlags flags) +{ + return is_flag_on(flags, EC_PARAM_FLAG_OUTPUT); +} + +inline ec_boolean is_input_validate_on_flag_on(ECParamFlags flags) +{ + return is_flag_on(flags, EC_PARAM_FLAG_INPUT_VALIDATE_ON); +} + +inline ec_boolean is_output_validate_on_flag_on(ECParamFlags flags) +{ + return is_flag_on(flags, EC_PARAM_FLAG_OUTPUT_VALIDATE_ON); +} + +inline ec_boolean is_input_default_value_on_flag_on(ECParamFlags flags) +{ + return is_flag_on(flags, EC_PARAM_FLAG_INPUT_DEFAULT_VALUE_ON); +} + +inline ec_boolean is_flag_on(ECParamFlags flags, ECParamFlags check_flag) +{ + return (flags & check_flag); +} + +static inline void on_flag(ECParamFlags *flags, ECParamFlags on_flag) +{ + *flags |= on_flag; +} + +static void free_param_spec(param_spec *pParam_spec) +{ + if (pParam_spec != NULL) { + if (pParam_spec->name != NULL) { + free(pParam_spec->name); + } + + /* note : don't free pParam_spec->pTask */ + + /* TODO : free other element */ + free(pParam_spec); + } +} + +/* external */ +param_spec *param_spec_ref(param_spec *pParam_spec) +{ + if (pParam_spec == NULL) { + return NULL; + } + + g_atomic_int_inc(&(pParam_spec->ref_count)); + + return pParam_spec; +} + +void param_spec_unref(param_spec *pParam_spec) +{ + if (pParam_spec == NULL) { + return; + } + + if (g_atomic_int_dec_and_test(&(pParam_spec->ref_count))) { + free_param_spec(pParam_spec); + } +} + +param_spec *param_spec_boolean(const ec_char *name, ec_boolean is_input, ec_boolean is_output, ec_boolean input_default_on, ec_boolean input_default_value) +{ + ECValueType value_type = EC_VALUE_TYPE_BOOLEAN; + param_spec *pParam_spec = alloc_and_init_param_spec_default(value_type, name); + if (pParam_spec == NULL) { + goto error_part; + } + + if (is_input) { + on_flag(&(pParam_spec->flags), EC_PARAM_FLAG_INPUT); + + if (input_default_on) { + on_flag(&(pParam_spec->flags), EC_PARAM_FLAG_INPUT_DEFAULT_VALUE_ON); + param_value_set_value(&(pParam_spec->default_value), value_type, &input_default_value); + } + } + + if (is_output) { + on_flag(&(pParam_spec->flags), EC_PARAM_FLAG_OUTPUT); + } + + return pParam_spec; + +error_part: + free_param_spec(pParam_spec); + return NULL; +} + +param_spec *param_spec_char(const ec_char *name, ec_boolean is_input, ec_boolean is_output, ec_boolean input_validate_on, ec_int8 input_minimum, ec_int8 input_maximum, ec_boolean input_default_on, ec_int8 input_default_value, ec_boolean output_validate_on, ec_int8 output_minimum, ec_int8 output_maximum) +{ + param_spec *pParam_spec = alloc_and_init_param_spec_number_type(EC_VALUE_TYPE_CHAR, name, + is_input, is_output, + input_validate_on, &input_minimum, &input_maximum, + input_default_on, &input_default_value, + output_validate_on, &output_minimum, &output_maximum); + return pParam_spec; +} + +param_spec *param_spec_uchar(const ec_char *name, ec_boolean is_input, ec_boolean is_output, ec_boolean input_validate_on, ec_uint8 input_minimum, ec_uint8 input_maximum, ec_boolean input_default_on, ec_uint8 input_default_value, ec_boolean output_validate_on, ec_uint8 output_minimum, ec_uint8 output_maximum) +{ + param_spec *pParam_spec = alloc_and_init_param_spec_number_type(EC_VALUE_TYPE_UCHAR, name, + is_input, is_output, + input_validate_on, &input_minimum, &input_maximum, + input_default_on, &input_default_value, + output_validate_on, &output_minimum, &output_maximum); + return pParam_spec; +} + +param_spec *param_spec_int(const ec_char *name, ec_boolean is_input, ec_boolean is_output, ec_boolean input_validate_on, ec_int input_minimum, ec_int input_maximum, ec_boolean input_default_on, ec_int input_default_value, ec_boolean output_validate_on, ec_int output_minimum, ec_int output_maximum) +{ + param_spec *pParam_spec = alloc_and_init_param_spec_number_type(EC_VALUE_TYPE_INT, name, + is_input, is_output, + input_validate_on, &input_minimum, &input_maximum, + input_default_on, &input_default_value, + output_validate_on, &output_minimum, &output_maximum); + return pParam_spec; +} + +param_spec *param_spec_uint(const ec_char *name, ec_boolean is_input, ec_boolean is_output, ec_boolean input_validate_on, ec_uint input_minimum, ec_uint input_maximum, ec_boolean input_default_on, ec_uint input_default_value, ec_boolean output_validate_on, ec_uint output_minimum, ec_uint output_maximum) +{ + param_spec *pParam_spec = alloc_and_init_param_spec_number_type(EC_VALUE_TYPE_UINT, name, + is_input, is_output, + input_validate_on, &input_minimum, &input_maximum, + input_default_on, &input_default_value, + output_validate_on, &output_minimum, &output_maximum); + return pParam_spec; +} + +param_spec *param_spec_float(const ec_char *name, ec_boolean is_input, ec_boolean is_output, ec_boolean input_validate_on, ec_float input_minimum, ec_float input_maximum, ec_boolean input_default_on, ec_float input_default_value, ec_boolean output_validate_on, ec_float output_minimum, ec_float output_maximum) +{ + param_spec *pParam_spec = alloc_and_init_param_spec_number_type(EC_VALUE_TYPE_FLOAT, name, + is_input, is_output, + input_validate_on, &input_minimum, &input_maximum, + input_default_on, &input_default_value, + output_validate_on, &output_minimum, &output_maximum); + return pParam_spec; +} + +param_spec *param_spec_double(const ec_char *name, ec_boolean is_input, ec_boolean is_output, ec_boolean input_validate_on, ec_double input_minimum, ec_double input_maximum, ec_boolean input_default_on, ec_double input_default_value, ec_boolean output_validate_on, ec_double output_minimum, ec_double output_maximum) +{ + param_spec *pParam_spec = alloc_and_init_param_spec_number_type(EC_VALUE_TYPE_DOUBLE, name, + is_input, is_output, + input_validate_on, &input_minimum, &input_maximum, + input_default_on, &input_default_value, + output_validate_on, &output_minimum, &output_maximum); + return pParam_spec; +} + +param_spec *param_spec_structure(const ec_char *name, copy_struct_func_callback copy_func, free_struct_func_callback free_func, ec_boolean is_input, ec_boolean is_output, ec_boolean input_validate_on, validate_struct_func_callback in_val_func, ec_boolean input_default_on, ec_pointer pDefault_Struct, ec_boolean output_validate_on, validate_struct_func_callback out_val_func) +{ + return alloc_and_init_param_spec_struct_type(name, is_input, is_output, input_validate_on, in_val_func, input_default_on, pDefault_Struct, output_validate_on, out_val_func, copy_func, free_func); +} + +const ECValueType param_spec_get_value_type(param_spec *pParam_spec) +{ + if (pParam_spec == NULL) { + return EC_VALUE_TYPE_UNKNOWN; + } + + return pParam_spec->value_type; +} + +const ec_char *param_spec_get_name(param_spec *pParam_spec) +{ + if (pParam_spec == NULL) { + return NULL; + } + + return pParam_spec->name; +} diff --git a/framework/src/EngineController/param_value.c b/framework/src/EngineController/param_value.c new file mode 100755 index 0000000..467fd80 --- /dev/null +++ b/framework/src/EngineController/param_value.c @@ -0,0 +1,112 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Wook Choi + */ + +#include +#include +#include +#include "EngineController/param_value.h" + +void param_value_set_value(param_value_t *pParam_value, ECValueType value_type, ec_constpointer pValue) +{ + if (pValue != NULL) { + switch (value_type) { + case EC_VALUE_TYPE_BOOLEAN: + pParam_value->boolean_value = *(ec_boolean *) pValue; + break; + case EC_VALUE_TYPE_CHAR: + pParam_value->char_value = *(ec_char *)pValue; + break; + case EC_VALUE_TYPE_UCHAR: + pParam_value->uchar_value = *(ec_uchar *) pValue; + break; + case EC_VALUE_TYPE_INT: + pParam_value->int_value = *(ec_int *)pValue; + break; + case EC_VALUE_TYPE_UINT: + pParam_value->uint_value = *(ec_uint *)pValue; + break; + case EC_VALUE_TYPE_FLOAT: + pParam_value->float_value = *(ec_float *) pValue; + break; + case EC_VALUE_TYPE_DOUBLE: + pParam_value->double_value = *(ec_double *) pValue; + break; + case EC_VALUE_TYPE_STRUCT: + pParam_value->pointer_value = *(ec_pointer *) pValue; + break; + default: + assert(false); + } + } +} + +void param_value_set_value_with_other_param_value(param_value_t *pDest_param_value, param_value_t *pSrc_param_value) +{ + memcpy(pDest_param_value, pSrc_param_value, sizeof(param_value_t)); +} + +void param_value_get_value(param_value_t *pParam_value, ECValueType value_type, ec_pointer pValue) +{ + if (pValue != NULL) { + switch (value_type) { + case EC_VALUE_TYPE_BOOLEAN: + *(ec_boolean *) pValue = pParam_value->boolean_value; + break; + case EC_VALUE_TYPE_CHAR: + *(ec_char *)pValue = pParam_value->char_value; + break; + case EC_VALUE_TYPE_UCHAR: + *(ec_uchar *) pValue = pParam_value->uchar_value; + break; + case EC_VALUE_TYPE_INT: + *(ec_int *)pValue = pParam_value->int_value; + break; + case EC_VALUE_TYPE_UINT: + *(ec_uint *)pValue = pParam_value->uint_value; + break; + case EC_VALUE_TYPE_FLOAT: + *(ec_float *) pValue = pParam_value->float_value; + break; + case EC_VALUE_TYPE_DOUBLE: + *(ec_double *) pValue = pParam_value->double_value; + break; + case EC_VALUE_TYPE_STRUCT: + *(ec_pointer *) pValue = pParam_value->pointer_value; + break; + default: + assert(false); + } + } +} diff --git a/framework/src/EngineController/queuing_rule_spec.c b/framework/src/EngineController/queuing_rule_spec.c new file mode 100755 index 0000000..37cdd38 --- /dev/null +++ b/framework/src/EngineController/queuing_rule_spec.c @@ -0,0 +1,647 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Wook Choi + */ + +#include +#include +#include +#include +#include "Utility/fw_assert.h" +#include "Utility/fw_log.h" +#include "EngineController/queuing_rule_spec.h" +#include "EngineController/queuing_rule_spec_internal.h" +#include "EngineController/task_spec_internal.h" +#include "EngineController/task.h" +#include "EngineController/task_message.h" +#include "EngineController/engine_controller_internal.h" + +#define LOG_TAG "AF_EC" + +static progress_blocking_entity_t *__queuing_rule_spec_get_progress_blocking_entity(queuing_rule_spec_t *pRule, ec_uint root_task_spec_id) +{ + GSList *iter = NULL; + progress_blocking_entity_t *pEntity = NULL; + for (iter = pRule->progress_blocking_entity_list; iter != NULL; iter = g_slist_next(iter)) { + pEntity = (progress_blocking_entity_t *)(iter->data); + if (pEntity->root_task_spec_id == root_task_spec_id) { + return pEntity; + } + } + + return NULL; +} + +static ec_boolean queuing_rule_spec_is_valid_child_path(task_spec_t *pRoot_task_spec, ec_uint child_depth, va_list ap) +{ + ec_uint i = 0; + ec_boolean is_dynamic = false; + ec_int dynamic_case = 0; + ec_int child_index = 0; + + task_spec_t *pParent_task_spec = pRoot_task_spec; + ec_boolean parent_is_dynamic = false; + task_spec_t *pChild_task_spec = NULL; + + for (i = 0; i < child_depth; i++) { + is_dynamic = va_arg(ap, ec_boolean); + dynamic_case = va_arg(ap, ec_int); + child_index = va_arg(ap, ec_int); + + /* not container or dynamic container case */ + if (task_spec_is_simple_task_spec(pParent_task_spec)) { + return false; + } + + /* check dynamic equality */ + parent_is_dynamic = task_spec_is_dynamic_container_task_spec(pParent_task_spec); + if ((is_dynamic && !parent_is_dynamic) || (!is_dynamic && parent_is_dynamic)) { + return false; + } + + if (is_dynamic) { + if (ENGINE_CONTROLLER_OK != task_spec_valididate_child_task_index_on_dynamic_case(dynamic_case, pParent_task_spec, child_index)) { + return false; + } + pChild_task_spec = task_spec_get_child_task_spec_on_dynamic_case(dynamic_case, pParent_task_spec, child_index); + } else { + if (ENGINE_CONTROLLER_OK != task_spec_valididate_child_task_index(pParent_task_spec, child_index)) { + return false; + } + pChild_task_spec = task_spec_get_child_task_spec(pParent_task_spec, child_index); + } + + fw_assert_condition(pChild_task_spec != NULL, "valid child but can task_spec_get_child_task_spec or task_spec_get_child_task_spec_on_dynamic_case return NULL\n"); + + pParent_task_spec = pChild_task_spec; + } + + return true; +} + +static void queuing_rule_spec_free_queuing_rule_spec(queuing_rule_spec_t *pRule) +{ + if (pRule != NULL) { + if (pRule->name != NULL) { + free(pRule->name); + } + + if (pRule->progress_blocking_entity_list != NULL) { + GSList *iter = NULL; + progress_blocking_entity_t *pEntity = NULL; + for (iter = pRule->progress_blocking_entity_list; iter != NULL; iter = g_slist_next(iter)) { + pEntity = (progress_blocking_entity_t *)(iter->data); + progress_blocking_entity_free(pEntity); + } + + g_slist_free(pRule->progress_blocking_entity_list); + } + + if (pRule->progress_blocking_queue != NULL) { + g_queue_free(pRule->progress_blocking_queue); + } + + free(pRule); + } +} + +/* implementation of queuing_rule_spec_internal.h */ + +n_ary_tree_node_with_flag_t *n_ary_tree_node_with_flag_new(ec_boolean blocking_flag, ec_uint tree_level, ec_boolean is_dynamic_child, ec_int dynamic_case, ec_uint child_index) +{ + n_ary_tree_node_with_flag_t *node = (n_ary_tree_node_with_flag_t *)malloc(sizeof(n_ary_tree_node_with_flag_t)); + if (node == NULL) { + goto error_part; + } + + node->blocking_flag = blocking_flag; + + node->tree_level = tree_level; + node->is_dynamic_child = is_dynamic_child; + node->dynamic_case = dynamic_case; + node->child_index = child_index; + + node->parent_node = NULL; + node->first_child_node = NULL; + node->next_sibling_node = NULL; + node->prev_sibling_node = NULL; + + return node; + +error_part: + n_ary_tree_node_with_flag_free_1(node); + return NULL; +} + +void n_ary_tree_node_with_flag_free_1(n_ary_tree_node_with_flag_t *node) +{ + if (node != NULL) { + free(node); + } +} + +void n_ary_tree_node_with_flag_free_subtree(n_ary_tree_node_with_flag_t *node) +{ + if (node->parent_node != NULL) { + n_ary_tree_node_with_flag_unlink_child_node(node->parent_node, node); + } + + /* destroy all children without using recursive call */ + n_ary_tree_node_with_flag_t *current_node = node; + n_ary_tree_node_with_flag_t *previous_node = NULL; + + ec_boolean end_of_walk = false; + ec_boolean has_to_check_child = true; + while (!end_of_walk) { + previous_node = current_node; + if (has_to_check_child) { + if (current_node->first_child_node == NULL) { + if (current_node->next_sibling_node == NULL) { + current_node = current_node->parent_node; + has_to_check_child = false; + } else { + current_node = current_node->next_sibling_node; + has_to_check_child = true; + } + n_ary_tree_node_with_flag_free_1(previous_node); + } else { + /* goto leaf node step by step */ + current_node = current_node->first_child_node; + + /* note that we do not free prev node in this case */ + } + } else { + if (current_node->next_sibling_node == NULL) { + current_node = current_node->parent_node; + } else { + /* goto next sibling since all children of current node are freed */ + current_node = current_node->next_sibling_node; + has_to_check_child = true; + } + n_ary_tree_node_with_flag_free_1(previous_node); + } + + if (current_node == NULL) { + end_of_walk = true; + } + } +} + +ec_uint n_ary_tree_node_with_flag_count_subtree_flag_on_number(n_ary_tree_node_with_flag_t *node) +{ + ec_uint count_flag_on = 0; + + /* visit all children to count flag on number without using recursive call */ + n_ary_tree_node_with_flag_t *current_node = node; + n_ary_tree_node_with_flag_t *previous_node = NULL; + + ec_boolean end_of_walk = false; + ec_boolean has_to_check_child = true; + while (!end_of_walk) { + previous_node = current_node; + if (has_to_check_child) { + if (current_node->first_child_node == NULL) { + /* set next current node */ + if (current_node->next_sibling_node == NULL) { + current_node = current_node->parent_node; + has_to_check_child = false; + } else { + current_node = current_node->next_sibling_node; + has_to_check_child = true; + } + + if (n_ary_tree_node_with_flag_is_blocking_flag_on(previous_node)) { + count_flag_on++; + } + } else { + /* goto leaf node step by step */ + current_node = current_node->first_child_node; + + /* note that we do not free prev node in this case */ + } + } else { + if (current_node->next_sibling_node == NULL) { + current_node = current_node->parent_node; + } else { + /* goto next sibling since all children of current node are freed */ + current_node = current_node->next_sibling_node; + has_to_check_child = true; + } + + if (n_ary_tree_node_with_flag_is_blocking_flag_on(previous_node)) { + count_flag_on++; + } + } + + if (current_node == node->parent_node || current_node == node->next_sibling_node) { + end_of_walk = true; + } + } + + return count_flag_on; +} + +void n_ary_tree_node_with_flag_set_blocking_flag_on(n_ary_tree_node_with_flag_t *node) +{ + node->blocking_flag = true; +} + +ec_boolean n_ary_tree_node_with_flag_is_blocking_flag_on(n_ary_tree_node_with_flag_t *node) +{ + return node->blocking_flag; +} + +ec_boolean n_ary_tree_node_with_flag_has_same_content_without_blocking_flag(n_ary_tree_node_with_flag_t *node, ec_uint tree_level, ec_boolean is_dynamic_child, ec_int dynamic_case, ec_uint child_index) +{ + if (node->tree_level == tree_level && node->is_dynamic_child == is_dynamic_child) { + if (is_dynamic_child) { + if (node->dynamic_case == dynamic_case && node->child_index == child_index) { + return true; + } + } else { + if (node->child_index == child_index) { + return true; + } + } + } + + return false; +} + +n_ary_tree_node_with_flag_t *n_ary_tree_node_with_flag_add_child_node(n_ary_tree_node_with_flag_t *parent_node, ec_boolean blocking_flag, ec_boolean is_dynamic_child, ec_int dynamic_case, ec_uint child_index) +{ + n_ary_tree_node_with_flag_t *child_node = n_ary_tree_node_with_flag_new(blocking_flag, parent_node->tree_level + 1, + is_dynamic_child, dynamic_case, child_index); + if (child_node == NULL) { + return NULL; + } + + n_ary_tree_node_with_flag_link_child_node(parent_node, child_node); + return child_node; +} + +void n_ary_tree_node_with_flag_link_child_node(n_ary_tree_node_with_flag_t *parent_node, n_ary_tree_node_with_flag_t *child_node) +{ + /* set parent */ + child_node->parent_node = parent_node; + + /* set child */ + if (parent_node->first_child_node != NULL) { + parent_node->first_child_node->prev_sibling_node = child_node; + } + child_node->next_sibling_node = parent_node->first_child_node; + parent_node->first_child_node = child_node; +} + +void n_ary_tree_node_with_flag_unlink_child_node(n_ary_tree_node_with_flag_t *parent_node, n_ary_tree_node_with_flag_t *child_node) +{ + if (parent_node == NULL) { + return; + } + + if (parent_node->first_child_node == child_node) { + parent_node->first_child_node = child_node->next_sibling_node; + } + + child_node->parent_node = NULL; + + /* unlink sibling list */ + if (child_node->prev_sibling_node != NULL) { + child_node->prev_sibling_node->next_sibling_node = child_node->next_sibling_node; + } + if (child_node->next_sibling_node != NULL) { + child_node->next_sibling_node->prev_sibling_node = child_node->prev_sibling_node; + } +} + +n_ary_tree_node_with_flag_t *n_ary_tree_node_with_flag_get_child_node(n_ary_tree_node_with_flag_t *parent_node, ec_boolean is_dynamic_child, ec_int dynamic_case, ec_uint child_index) +{ + n_ary_tree_node_with_flag_t *child_node = NULL; + for (child_node = parent_node->first_child_node; child_node != NULL; child_node = child_node->next_sibling_node) { + if (n_ary_tree_node_with_flag_has_same_content_without_blocking_flag(child_node, parent_node->tree_level + 1, is_dynamic_child, dynamic_case, child_index)) { + break; + } + } + + return child_node; +} + +progress_blocking_element_set_t *progress_blocking_element_set_new() +{ + progress_blocking_element_set_t *pSet = (progress_blocking_element_set_t *)calloc(1, sizeof(progress_blocking_element_set_t)); + if (pSet == NULL) { + goto error_part; + } + + pSet->progress_blocking_element_cnt = 0; + pSet->n_ary_tree_with_flag = n_ary_tree_node_with_flag_new(false, 0, 0, 0, 0); /* set root node */ + if (pSet->n_ary_tree_with_flag == NULL) { + goto error_part; + } + + return pSet; + +error_part: + progress_blocking_element_set_free(pSet); + return NULL; +} + +void progress_blocking_element_set_free(progress_blocking_element_set_t *pSet) +{ + if (pSet != NULL) { + if (pSet->n_ary_tree_with_flag != NULL) { + n_ary_tree_node_with_flag_free_subtree(pSet->n_ary_tree_with_flag); + pSet->n_ary_tree_with_flag = NULL; + } + + free(pSet); + } +} + +engine_controller_error_t progress_blocking_element_add(progress_blocking_element_set_t *pSet, ec_uint depth, va_list ap) +{ + engine_controller_error_t ec_error = ENGINE_CONTROLLER_OK; + + n_ary_tree_node_with_flag_t *root_node = pSet->n_ary_tree_with_flag; /* note that root_node != NULL */ + n_ary_tree_node_with_flag_t *last_exist_parent_node = NULL; + n_ary_tree_node_with_flag_t *first_alloc_node = NULL; + n_ary_tree_node_with_flag_t *parent_node = NULL; + n_ary_tree_node_with_flag_t *child_node = NULL; + + ec_boolean is_dynamic_child = false; + ec_int dynamic_case = 0; + ec_uint child_index = 0; + + ec_uint i = 0; + + if (depth == 0) { + if (!(root_node->blocking_flag)) { + (pSet->progress_blocking_element_cnt)++; + n_ary_tree_node_with_flag_set_blocking_flag_on(root_node); + } + + return ec_error; + } + + parent_node = root_node; + for (i = 1; i <= depth; i++) { + is_dynamic_child = va_arg(ap, ec_boolean); + dynamic_case = va_arg(ap, ec_int); + child_index = va_arg(ap, ec_int); + + child_node = n_ary_tree_node_with_flag_get_child_node(parent_node, is_dynamic_child, dynamic_case, child_index); + + if (child_node == NULL) { + last_exist_parent_node = parent_node; + first_alloc_node = n_ary_tree_node_with_flag_add_child_node(parent_node, i == depth, is_dynamic_child, dynamic_case, child_index); + if (first_alloc_node == NULL) { + ec_error = ENGINE_CONTROLLER_OUT_OF_MEMORY; + goto error_part; + } + + if (i == depth) { + (pSet->progress_blocking_element_cnt)++; + goto return_part; + } + + parent_node = first_alloc_node; + break; + } + parent_node = child_node; + } + + if (child_node != NULL) { + /* already exist child node */ + if (!(child_node->blocking_flag)) { + n_ary_tree_node_with_flag_set_blocking_flag_on(child_node); + (pSet->progress_blocking_element_cnt)++; + } + goto return_part; + } else { + /* add child node */ + for (i++; i <= depth; i++) { + is_dynamic_child = va_arg(ap, ec_boolean); + dynamic_case = va_arg(ap, ec_int); + child_index = va_arg(ap, ec_int); + + child_node = n_ary_tree_node_with_flag_add_child_node(parent_node, (i == depth), is_dynamic_child, dynamic_case, child_index); + if (child_node == NULL) { + goto error_part; + } + + parent_node = child_node; + } + (pSet->progress_blocking_element_cnt)++; + } + +return_part: + if (last_exist_parent_node == NULL) { /* when pSet->n_ary_tree_with_flag == NULL */ + pSet->n_ary_tree_with_flag = first_alloc_node; + } + + return ec_error; + +error_part: + if (first_alloc_node != NULL) { + n_ary_tree_node_with_flag_free_subtree(first_alloc_node); + } + return ec_error; +} + +progress_blocking_entity_t *progress_blocking_entity_new(ec_uint root_task_spec_id, queuing_rule_spec_t *pQueuing_rule_spec) +{ + progress_blocking_entity_t *pEntity = (progress_blocking_entity_t *)calloc(1, sizeof(progress_blocking_entity_t)); + if (pEntity == NULL) { + goto error_part; + } + + pEntity->ref_count = 1; + pEntity->root_task_spec_id = root_task_spec_id; + pEntity->pQueuing_rule_spec = queuing_rule_spec_ref(pQueuing_rule_spec); + pEntity->pElement_set = progress_blocking_element_set_new(); + if (pEntity->pElement_set == NULL) { + goto error_part; + } + + return pEntity; + +error_part: + progress_blocking_entity_free(pEntity); + return NULL; +} + +void progress_blocking_entity_free(progress_blocking_entity_t *pEntity) +{ + if (pEntity != NULL) { + if (pEntity->pElement_set != NULL) { + progress_blocking_element_set_free(pEntity->pElement_set); + } + if (pEntity->pQueuing_rule_spec != NULL) { + queuing_rule_spec_unref(pEntity->pQueuing_rule_spec); + } + } +} + +progress_blocking_entity_t *progress_blocking_entity_ref(progress_blocking_entity_t *pEntity) +{ + if (pEntity == NULL) { + return NULL; + } + + g_atomic_int_inc(&(pEntity->ref_count)); + + return pEntity; +} + +void progress_blocking_entity_unref(progress_blocking_entity_t *pEntity) +{ + if (pEntity == NULL) { + return; + } + + if (g_atomic_int_dec_and_test(&(pEntity->ref_count))) { + progress_blocking_entity_free(pEntity); + } +} + +/* implementation of queuing_rule_spec.h */ + +queuing_rule_spec_t *queuing_rule_spec_create_queuing_rule_spec_outline(ec_char *queuing_rule_name) +{ + queuing_rule_spec_t *pRule = (queuing_rule_spec_t *)calloc(1, sizeof(queuing_rule_spec_t)); + if (pRule == NULL) { + goto error_part; + } + + pRule->ref_count = 1; + pRule->name = strdup(queuing_rule_name); + if (pRule->name == NULL) { + goto error_part; + } + + pRule->total_progress_blocking_element_cnt = 0; + pRule->progress_blocking_entity_list = NULL; + + pRule->progress_blocking_queue = g_queue_new(); + if (pRule->progress_blocking_queue == NULL) { + goto error_part; + } + + return pRule; + +error_part: + queuing_rule_spec_free_queuing_rule_spec(pRule); + return NULL; +} + +/* TODO : better performance expected if validation & check duplication & add new queuing element are done by one scanning */ +engine_controller_error_t queuing_rule_spec_add_progress_blocking_element(queuing_rule_spec_t *pRule, ec_uint root_task_spec_id, task_spec_t *pRoot_task_spec, ec_uint child_depth, ...) +{ + /* ec_boolean is_dynamic, ec_int dynamic_case, ec_int child_index */ + engine_controller_error_t ec_error = ENGINE_CONTROLLER_OK; + ec_boolean new_entity = false; + + va_list ap; + va_start(ap, child_depth); + + /* check validity of child path */ + if (!queuing_rule_spec_is_valid_child_path(pRoot_task_spec, child_depth, ap)) { + ec_error = ENGINE_CONTROLLER_INVALID_CHILD_PATH; + va_end(ap); + + goto return_part; + } + + va_end(ap); + va_start(ap, child_depth); + + /* find progress blocking entity */ + progress_blocking_entity_t *pEntity = __queuing_rule_spec_get_progress_blocking_entity(pRule, root_task_spec_id); + if (pEntity == NULL) { + pEntity = progress_blocking_entity_new(root_task_spec_id, pRule); + if (pEntity == NULL) { + ec_error = ENGINE_CONTROLLER_OUT_OF_MEMORY; + goto return_part; + } else { + new_entity = true; + } + } + + /* add_child_path to blocking entity */ + ec_error = progress_blocking_element_add(pEntity->pElement_set, child_depth, ap); + if (ec_error != ENGINE_CONTROLLER_OK) { + va_end(ap); + goto return_part; + } + + va_end(ap); + + if (new_entity) { + pRule->total_progress_blocking_element_cnt++; + pRule->progress_blocking_entity_list = g_slist_prepend(pRule->progress_blocking_entity_list, pEntity); + } + +return_part: + return ec_error; + +/* +error_part: + if (new_entity) { + progress_blocking_entity_unref(pEntity); + } + return ec_error; +*/ +} + +queuing_rule_spec_t *queuing_rule_spec_ref(queuing_rule_spec_t *pRule) +{ + fw_assert_condition(pRule != NULL, "error. pRule == NULL\n"); + + g_atomic_int_inc(&(pRule->ref_count)); + return pRule; +} + +void queuing_rule_spec_unref(queuing_rule_spec_t *pRule) +{ + if (pRule == NULL) { + return; + } + + if (g_atomic_int_get(&(pRule->ref_count)) <= 0) { + FW_LOGE("ref count <= 0\n"); + } + + if (g_atomic_int_dec_and_test(&(pRule->ref_count))) { + queuing_rule_spec_free_queuing_rule_spec(pRule); + } +} diff --git a/framework/src/EngineController/queuing_rule_spec_pool.c b/framework/src/EngineController/queuing_rule_spec_pool.c new file mode 100755 index 0000000..93ec916 --- /dev/null +++ b/framework/src/EngineController/queuing_rule_spec_pool.c @@ -0,0 +1,141 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Wook Choi + */ + +#include +#include +#include "EngineController/queuing_rule_spec_pool.h" + +queuing_rule_spec_pool_t *queuing_rule_spec_pool_alloc(ec_uint queuing_rule_max_cnt, task_info_pool_t *pTask_info_pool) +{ + queuing_rule_spec_pool_t *pPool = NULL; + if (queuing_rule_max_cnt == 0) { + goto error_part; + } + + pPool = (queuing_rule_spec_pool_t *)calloc(1, sizeof(queuing_rule_spec_pool_t)); + if (pPool == NULL) { + goto return_part; + } + + pPool->pId_provider = id_provider_create(queuing_rule_max_cnt - 1, 12, false); + if (pPool->pId_provider == NULL) { + goto error_part; + } + + pPool->pQueuing_rule_spec_hash = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, (GDestroyNotify) queuing_rule_spec_unref); + if (pPool->pQueuing_rule_spec_hash == NULL) { + goto error_part; + } + + pPool->pTask_info_pool = pTask_info_pool; + +return_part: + return pPool; + +error_part: + queuing_rule_spec_pool_free(pPool); + return NULL; +} + +void queuing_rule_spec_pool_free(queuing_rule_spec_pool_t *pPool) +{ + if (pPool != NULL) { + if (pPool->pId_provider != NULL) { + id_provider_destroy(pPool->pId_provider); + } + if (pPool->pQueuing_rule_spec_hash != NULL) { + g_hash_table_destroy(pPool->pQueuing_rule_spec_hash); + } + } +} + +engine_controller_error_t queuing_rule_spec_pool_add_queuing_rule_spec(queuing_rule_spec_pool_t *pPool, queuing_rule_spec_t *pSpec, ec_uint *queuing_rule_id) +{ + engine_controller_error_t ec_error = ENGINE_CONTROLLER_OK; + + task_info_pool_t *pTask_info_pool = pPool->pTask_info_pool; + + /* generate id */ + id_provider_error_t id_error = ID_PROVIDER_OK; + ec_uint new_id = 0; + id_error = id_provider_provide_id(pPool->pId_provider, &new_id); + if (id_error != ID_PROVIDER_OK) { + if (id_error == ID_PROVIDER_NOT_ENOUGH_ID) { + ec_error = ENGINE_CONTROLLER_OUT_OF_FREE_ID; + } else { + ec_error = ENGINE_CONTROLLER_UNKNOWN_ERROR; + } + goto error_part; + } + + /* TODO : error handling */ + + /* add queuing_rule_spec info to each task_specs */ + progress_blocking_entity_t *pEntity = NULL; + task_info_t *pTask_info = NULL; + GSList *iter = NULL; + for (iter = pSpec->progress_blocking_entity_list; iter != NULL; iter = g_slist_next(iter)) { + pEntity = (progress_blocking_entity_t *)(iter->data); + + pTask_info = task_info_pool_search_task_info(pTask_info_pool, pEntity->root_task_spec_id); + ec_error = task_info_add_progress_blocking_entity(pTask_info, pEntity); + if (ec_error != ENGINE_CONTROLLER_OK) { + /* undo */ + GSList *iter2 = NULL; + progress_blocking_entity_t *pEntity2 = NULL; + for (iter2 = pSpec->progress_blocking_entity_list; iter2 != iter; iter2 = g_slist_next(iter2)) { + pEntity2 = (progress_blocking_entity_t *)(iter2->data); + task_info_remove_blocking_entity(pTask_info, pEntity2); + } + + assert(ID_PROVIDER_OK == id_provider_delete_id(pPool->pId_provider, new_id)); + goto error_part; + } + } + + g_hash_table_insert(pPool->pQueuing_rule_spec_hash, (gpointer) new_id, pSpec); + + *queuing_rule_id = new_id; + +error_part: + return ec_error; +} + +queuing_rule_spec_t *queueing_rule_spec_pool_search_queuing_rule_spec(queuing_rule_spec_pool_t *pPool, ec_uint queuing_rule_id) +{ + queuing_rule_spec_t *pQueuing_rule_spec = g_hash_table_lookup(pPool->pQueuing_rule_spec_hash, (gconstpointer) queuing_rule_id); + + return pQueuing_rule_spec; +} diff --git a/framework/src/EngineController/task.c b/framework/src/EngineController/task.c new file mode 100755 index 0000000..80bf322 --- /dev/null +++ b/framework/src/EngineController/task.c @@ -0,0 +1,1033 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Wook Choi + */ + +#include +#include +#include +#include "Utility/fw_ref.h" +#include "Utility/fw_assert.h" +#include "Utility/fw_log.h" +#include "EngineController/engine_controller_internal.h" +#include "EngineController/task.h" +#include "EngineController/task_spec_internal.h" +#include "EngineController/param_spec_internal.h" + +#define LOG_TAG "AF_EC" + +static param_t *task_fetch_from_param(task_t *pParent_task, ec_int to_child_task_index, ec_int to_param_index); +static void task_free_task(task_t *pTask); + +static param_t *task_fetch_from_param(task_t *pParent_task, ec_int to_child_task_index, ec_int to_param_index) +{ + param_t *pFetched_param = NULL; + task_spec_t *pParent_task_spec = pParent_task->pTask_spec; + child_tasks_info_t *pChild_task_info = NULL; + if (task_spec_is_container_task_spec(pParent_task_spec)) { + pChild_task_info = task_spec_find_child_tasks_info(pParent_task_spec); + } else if (task_spec_is_dynamic_container_task_spec(pParent_task_spec)) { + pChild_task_info = task_spec_find_case_specific_child_tasks_info(pParent_task_spec, pParent_task->dynamic_case); + } else { + assert(false); + } + + data_flow_edges_t *pData_flow_edges; + + if (pChild_task_info != NULL) { + pData_flow_edges = pChild_task_info->pData_flow_edges; + } else { + goto error_part; + } + + ec_int from_task_index = 0; + ec_int from_param_index = 0; + ec_boolean find_success = data_flow_edges_get_from_param_info(pData_flow_edges, + to_child_task_index, to_param_index, + &from_task_index, &from_param_index); + if (find_success) { + if (from_task_index == -1) { + /* get from parent_task */ + pFetched_param = pParent_task->param_array[from_param_index]; + } else { + /* validation from_task_index */ + engine_controller_error_t ec_error = ENGINE_CONTROLLER_OK; + if (task_spec_is_container_task_spec(pParent_task_spec)) { + ec_error = task_spec_valididate_child_task_index(pParent_task_spec, from_task_index); + } else if (task_spec_is_dynamic_container_task_spec(pParent_task_spec)) { + ec_error = task_spec_valididate_child_task_index_on_dynamic_case(pParent_task->dynamic_case, pParent_task_spec, from_task_index); + } + if (ec_error != ENGINE_CONTROLLER_OK) { + goto error_part; + } + + /* get from child task */ + task_t *pChild_task = pParent_task->child_task_array[from_task_index]; + pFetched_param = pChild_task->param_array[from_param_index]; + } + } + + return pFetched_param; + +error_part: + return NULL; +} + +/* TODO : handling error case */ +GSList *task_construct_progress_blocking_realized_entity_list(task_info_t *pTask_info) +{ + GSList *progress_blocking_realized_entity_list = NULL; + + /* add progress blocking entity according to queuing rule */ + GSList *iter = NULL; + progress_blocking_entity_t *pEntity = NULL; + progress_blocking_realized_entity_t *pRealized_entity = NULL; + for (iter = pTask_info->progress_blocking_entity_list; iter != NULL; iter = g_slist_next(iter)) { + pEntity = (progress_blocking_entity_t *)(iter->data); + + pRealized_entity = progress_blocking_realized_entity_new(pEntity); + + progress_blocking_realized_entity_list = g_slist_prepend(progress_blocking_realized_entity_list, pRealized_entity); + + /* create progress_queuing_entity */ + g_queue_push_tail(pEntity->pQueuing_rule_spec->progress_blocking_queue, pRealized_entity); + } + + return progress_blocking_realized_entity_list; +} + +/* TODO : handling error case */ +GSList *task_construct_current_node_in_progress_blocking_entity_list(task_info_t *pTask_info) +{ + GSList *current_node_in_progress_blocking_entity_list = NULL; + + /* add progress blocking entity according to queuing rule */ + GSList *iter = NULL; + progress_blocking_entity_t *pEntity = NULL; + for (iter = pTask_info->progress_blocking_entity_list; iter != NULL; iter = g_slist_next(iter)) { + pEntity = (progress_blocking_entity_t *)(iter->data); + + current_node_in_progress_blocking_entity_list = g_slist_prepend(current_node_in_progress_blocking_entity_list, pEntity->pElement_set->n_ary_tree_with_flag); + } + + return current_node_in_progress_blocking_entity_list; +} + +GSList *task_construct_current_node_in_progress_blocking_entity_list_from_parent_task(task_t *pParent_task, ec_int child_index) +{ + GSList *current_node_in_progress_blocking_entity_list = NULL; + + /* add progress blocking entity according to queuing rule */ + GSList *iter = NULL; + n_ary_tree_node_with_flag_t *parent_tree_node = NULL; + n_ary_tree_node_with_flag_t *child_tree_node = NULL; + for (iter = pParent_task->current_node_in_progress_blocking_entity_list; iter != NULL; iter = g_slist_next(iter)) { + parent_tree_node = (n_ary_tree_node_with_flag_t *)(iter->data); + if (parent_tree_node == NULL) { + child_tree_node = NULL; + } else { + child_tree_node = n_ary_tree_node_with_flag_get_child_node(parent_tree_node, task_spec_is_dynamic_container_task_spec(pParent_task->pTask_spec), pParent_task->dynamic_case, child_index); + /* note that child_tree_node could be NULL */ + } + + current_node_in_progress_blocking_entity_list = g_slist_prepend(current_node_in_progress_blocking_entity_list, child_tree_node); + } + + return current_node_in_progress_blocking_entity_list; +} + +task_t *task_alloc_root_task(task_spec_t *pTask_spec, engine_controller_request_msg_t *pRequest_Msg, task_info_pool_t *pTask_info_pool) +{ + task_t *pTask = NULL; + ec_int i = 0; + ec_uint child_task_cnt = 0; + + if (pTask_spec == NULL) { + FW_LOGD("input task is NULL"); + goto error_part; + } + + pTask = (task_t *)calloc(1, sizeof(task_t)); + if (pTask == NULL) { + goto error_part; + } + + pTask->ref_count = 1; + pTask->task_error = TASK_ERROR_NOT_YET_RUN; + + pTask->pTask_info = task_info_pool_search_task_info(pTask_info_pool, pRequest_Msg->task_spec_id); + + pTask->progress_blocking_realized_entity_list = task_construct_progress_blocking_realized_entity_list(pTask->pTask_info); + + pTask->current_node_in_progress_blocking_entity_list = task_construct_current_node_in_progress_blocking_entity_list(pTask->pTask_info); + + pTask->pParent_task = NULL; + pTask->child_task_index_in_parent_task = 0; /* meaningless value */ + + pTask->param_array = (param_t **)calloc(pTask_spec->task_param_cnt, sizeof(param_t *)); + if (pTask->param_array == NULL) { + goto error_part; + } + + /* set parameter values in param_array */ + int index = 0; + for (i = 0; i < pRequest_Msg->cnt_in_param; i++) { + index = pRequest_Msg->in_param_index_array[i]; + pTask->param_array[index] = param_alloc_param(1, 1, /* TODO : set ref count */ + pTask_spec->task_param_spec_array[index], &(pRequest_Msg->in_param_value_array[i])); + } + + /* set output parameter values */ + for (i = 0; i < pTask_spec->task_param_cnt; i++) { + if (pTask->param_array[i] == NULL) { + pTask->param_array[i] = param_alloc_param(1, 1, /* TODO : set ref count */ + pTask_spec->task_param_spec_array[i], NULL); + } + } + + if (task_spec_is_container_task_spec(pTask_spec)) { + child_task_cnt = task_spec_get_child_task_cnt(pTask_spec); + } else if (task_spec_is_dynamic_container_task_spec(pTask_spec)) { + /* compute case */ + calculate_case_callback_func calculate_case_func = task_spec_get_calculate_case_callback_func(pTask_spec); + pTask->dynamic_case = calculate_case_func(pTask_spec->task_param_cnt, pTask->param_array); + + child_task_cnt = task_spec_get_child_task_cnt_on_dynamic_case(pTask_spec, pTask->dynamic_case); + } + + if (child_task_cnt > 0) { + pTask->child_task_array = (task_t **)calloc(child_task_cnt, sizeof(task_t *)); + if (pTask->child_task_array == NULL) { + goto error_part; + } + } + + task_set_left_child_to_run(pTask, child_task_cnt); + + if (task_spec_is_container_task_spec(pTask_spec)) { + /* copy child_task_control_flow_in_degree */ + pTask->current_child_task_control_flow_in_degree_array = task_spec_duplicate_child_task_control_flow_in_degree(pTask_spec); + if (pTask->current_child_task_control_flow_in_degree_array == NULL) { + goto error_part; + } + } else if (task_spec_is_dynamic_container_task_spec(pTask_spec)) { + pTask->current_child_task_control_flow_in_degree_array = task_spec_duplicate_child_task_control_flow_in_degree_on_dynamic_case(pTask_spec, pTask->dynamic_case); + if (pTask->current_child_task_control_flow_in_degree_array == NULL) { + goto error_part; + } + } else { + pTask->current_child_task_control_flow_in_degree_array = NULL; + } + + pTask->pTask_spec = task_spec_ref(pTask_spec); + refObject_t *pRequest_Msg_ref = create_refObject(pRequest_Msg, NULL); /* TODO : free fucntion */ + if (pRequest_Msg_ref == NULL) { + goto error_part; + } + pTask->pRequestMsg = pRequest_Msg_ref; + + pTask->pCancel_Information = task_cancel_info_init(pRequest_Msg_ref); + if (pTask->pCancel_Information == NULL) { + goto error_part; + } + + if (-1 == gettimeofday(&(pTask->create_time), NULL)) { + goto error_part; + } + + return pTask; + +error_part: + task_free_task(pTask); + return NULL; +} + +task_t *task_alloc_child_task(task_t *pParent_task, ec_int child_index) +{ + task_t *pChild_task = NULL; + task_spec_t *pParent_task_spec = pParent_task->pTask_spec; + child_tasks_info_t *pChild_tasks_info = NULL; + + /* validation & get child_task_info */ + if (task_spec_is_container_task_spec(pParent_task_spec)) { + engine_controller_error_t ec_error = task_spec_valididate_child_task_index(pParent_task_spec, child_index); + if (ec_error != ENGINE_CONTROLLER_OK) { + FW_LOGE("invalid child index, child_index = %d\n", child_index); + goto error_part; + } + + pChild_tasks_info = task_spec_find_child_tasks_info(pParent_task_spec); + } else if (task_spec_is_dynamic_container_task_spec(pParent_task_spec)) { + engine_controller_error_t ec_error = task_spec_valididate_child_task_index_on_dynamic_case(pParent_task->dynamic_case, pParent_task_spec, child_index); + if (ec_error != ENGINE_CONTROLLER_OK) { + FW_LOGE("invalid child index, child_index = %d\n", child_index); + goto error_part; + } + + pChild_tasks_info = task_spec_find_case_specific_child_tasks_info(pParent_task_spec, pParent_task->dynamic_case); + } + + task_spec_t *pChild_task_spec; + + if (pChild_tasks_info != NULL) { + pChild_task_spec = pChild_tasks_info->child_task_array[child_index]; + } else { + goto error_part; + } + + ec_int i = 0; + ec_uint grand_child_task_cnt = 0; + + pChild_task = (task_t *)calloc(1, sizeof(task_t)); + if (pChild_task == NULL) { + goto error_part; + } + + pChild_task->ref_count = 1; + pChild_task->task_error = TASK_ERROR_NOT_YET_RUN; + pChild_task->pParent_task = pParent_task; + pChild_task->child_task_index_in_parent_task = child_index; + + pChild_task->progress_blocking_realized_entity_list = pParent_task->progress_blocking_realized_entity_list; + pChild_task->current_node_in_progress_blocking_entity_list = task_construct_current_node_in_progress_blocking_entity_list_from_parent_task(pParent_task, child_index); + + pChild_task->param_array = (param_t **)calloc(pChild_task_spec->task_param_cnt, sizeof(param_t *)); + if (pChild_task->param_array == NULL) { + goto error_part; + } + + /* set parameter values */ + for (i = 0; i < pChild_task_spec->task_param_cnt; i++) { + param_t *pFrom_param = task_fetch_from_param(pParent_task, child_index, i); + pChild_task->param_array[i] = param_alloc_param(1, 1, /* TODO : set ref count */ + pChild_task_spec->task_param_spec_array[i], pFrom_param != NULL ? &(pFrom_param->param_value) : NULL); + } + + if (task_spec_is_container_task_spec(pChild_task_spec)) { + grand_child_task_cnt = task_spec_get_child_task_cnt(pChild_task_spec); + } else if (task_spec_is_dynamic_container_task_spec(pChild_task_spec)) { + /* compute dynamic case */ + calculate_case_callback_func calculate_case_func = task_spec_get_calculate_case_callback_func(pChild_task_spec); + pChild_task->dynamic_case = calculate_case_func(pChild_task_spec->task_param_cnt, pChild_task->param_array); + + grand_child_task_cnt = task_spec_get_child_task_cnt_on_dynamic_case(pChild_task_spec, pChild_task->dynamic_case); + } + pChild_task->child_task_array = (task_t **)calloc(grand_child_task_cnt, sizeof(task_t *)); + if (pChild_task->child_task_array == NULL) { + goto error_part; + } + + task_set_left_child_to_run(pChild_task, grand_child_task_cnt); + + if (task_spec_is_container_task_spec(pChild_task_spec)) { + /* copy child_task_control_flow_in_degree */ + pChild_task->current_child_task_control_flow_in_degree_array = task_spec_duplicate_child_task_control_flow_in_degree(pChild_task_spec); + if (pChild_task->current_child_task_control_flow_in_degree_array == NULL) { + goto error_part; + } + } else if (task_spec_is_dynamic_container_task_spec(pChild_task_spec)) { + pChild_task->current_child_task_control_flow_in_degree_array = task_spec_duplicate_child_task_control_flow_in_degree_on_dynamic_case(pChild_task_spec, pChild_task->dynamic_case); + if (pChild_task->current_child_task_control_flow_in_degree_array == NULL) { + goto error_part; + } + } else { + pChild_task->current_child_task_control_flow_in_degree_array = NULL; + } + + pChild_task->pTask_info = task_info_ref(pParent_task->pTask_info); + pChild_task->pTask_spec = task_spec_ref(pChild_task_spec); + pChild_task->pRequestMsg = getRef(pParent_task->pRequestMsg); + pChild_task->pCancel_Information = task_cancel_info_ref(pParent_task->pCancel_Information); + + if (-1 == gettimeofday(&(pChild_task->create_time), NULL)) { + goto error_part; + } + + return pChild_task; + +error_part: + + if (pChild_task) { + task_free_task(pChild_task); + } + return NULL; +} + +static void task_free_task(task_t *pTask) +{ + FW_LOGD("called\n"); + if (pTask != NULL) { + /* TODO */ + + task_cancel_info_unref(pTask->pCancel_Information); + free(pTask); + } +} + +task_t *task_ref_task(task_t *pTask) +{ + fw_assert_condition(pTask != NULL, "error. pTask == NULL\n"); + + g_atomic_int_inc(&(pTask->ref_count)); + return pTask; +} + +void task_unref_task(task_t *pTask) +{ + if (pTask == NULL) { + return; + } + + if (g_atomic_int_get(&(pTask->ref_count)) <= 0) { + FW_LOGE("ref count <= 0\n"); + } + + if (g_atomic_int_dec_and_test(&(pTask->ref_count))) { + task_free_task(pTask); + } +} + +ec_boolean task_is_simple_task(task_t *pTask) +{ + if (pTask == NULL) { + FW_LOGW("pTask == NULL\n"); + return false; + } + + task_spec_t *pTask_spec = pTask->pTask_spec; + return task_spec_is_simple_task_spec(pTask_spec); +} + +ec_boolean task_is_container_task(task_t *pTask) +{ + if (pTask == NULL) { + FW_LOGW("pTask == NULL\n"); + return false; + } + + task_spec_t *pTask_spec = pTask->pTask_spec; + return (task_spec_is_container_task_spec(pTask_spec) || task_spec_is_dynamic_container_task_spec(pTask_spec)); +} + +ec_boolean task_is_root_task(task_t *pTask) +{ + task_t *pParent_task = task_get_parent_task(pTask); + if (pParent_task == NULL) { + return true; + } else { + return false; + } +} + +ec_int task_get_param_cnt(task_t *pTask) +{ + if (pTask == NULL) { + FW_LOGE("pTask == NULL\n"); + return -1; + } + + return task_spec_get_param_cnt(pTask->pTask_spec); +} + +ec_boolean task_get_output_param_info(task_t *pTask, ec_int *pOutput_param_cnt, ec_int **pOutput_param_index_array) +{ + if (pTask == NULL) { + FW_LOGE("pTask == NULL"); + return false; + } + + if (pTask->pTask_spec == NULL) { + FW_LOGE("pTask->pTask_spec == NULL\n"); + return false; + } + + return task_spec_get_output_param_info(pTask->pTask_spec, pOutput_param_cnt, pOutput_param_index_array); +} + +ec_uint task_get_child_task_cnt(task_t *pTask) +{ + if (pTask == NULL) { + FW_LOGE("pTask == NULL\n"); + return -1; + } + + return task_spec_get_child_task_cnt(pTask->pTask_spec); +} + +task_t *task_get_parent_task(task_t *pTask) +{ + if (pTask == NULL) { + FW_LOGE("pTask == NULL\n"); + return NULL; + } + + return pTask->pParent_task; +} + +ec_int task_get_child_index_in_parent_task(task_t *pTask) +{ + if (pTask == NULL) { + FW_LOGE("pTask == NULL\n"); + return -1; + } + + return pTask->child_task_index_in_parent_task; +} + +void task_set_task_error(task_t *pTask, task_error_t task_error) +{ + if (pTask == NULL) { + FW_LOGE("pTask == NULL\n"); + return; + } + + pTask->task_error = task_error; +} + +ec_boolean task_check_same_task_error(task_t *pTask, task_error_t task_error) +{ + if (pTask == NULL) { + FW_LOGE("pTask == NULL\n"); + return false; + } + + if (pTask->task_error == task_error) { + return true; + } + return false; +} + +ec_boolean task_is_not_yet_run(task_t *pTask) +{ + return task_check_same_task_error(pTask, TASK_ERROR_NOT_YET_RUN); +} + +void task_do_cancellation(task_t *pTask) +{ + FW_LOGD("started\n"); + + g_mutex_lock(pTask->pCancel_Information->cancel_info_mutex); + + task_cancel_info_set_cancel_flag_atomic(pTask->pCancel_Information); + FW_LOGD("pTask->pCancel_Information->cancel_flag = %d\n", pTask->pCancel_Information->cancel_flag); + task_cancel_info_call_cancel_callbacks_unlocked(pTask->pCancel_Information); + + g_mutex_unlock(pTask->pCancel_Information->cancel_info_mutex); + FW_LOGD("ended\n"); +} + +void task_call_task_finish_callback(task_t *pTask) +{ + engine_controller_request_msg_t *pRequest_msg = (engine_controller_request_msg_t *)getData(pTask->pRequestMsg); + task_finish_callback_func task_finish_callback = pRequest_msg->task_finish_callback; + ec_pointer simple_task_finish_callback_usr_data = pRequest_msg->simple_task_finish_callback_usr_data; + FW_LOGD("started\n"); + + if (task_finish_callback != NULL) { + FW_LOGD("call finish callback\n"); + task_error_t task_error = pTask->task_error; + ec_int i = 0; + ec_int cnt_out_param = 0; + ec_int out_param_index = 0; + ec_int *out_param_index_array = NULL; + param_t **out_param_array = NULL; + if (!task_get_output_param_info(pTask, &cnt_out_param, &out_param_index_array)) { + FW_LOGE("out of memory during task_get_output_param_info\n"); + assert(false); + } + + if (cnt_out_param > 0 && out_param_index_array != NULL) { + out_param_array = (param_t **)calloc(cnt_out_param, sizeof(param_t *)); + if (out_param_array == NULL) { + FW_LOGE("out of memory during task_get_output_param_info\n"); + assert(false); + } + + for (i = 0; i < cnt_out_param; i++) { + out_param_index = out_param_index_array[i]; + out_param_array[i] = pTask->param_array[out_param_index]; + } + } + + if (out_param_index_array != NULL) { + free(out_param_index_array); + } + + /* call task_finish_callback */ + task_finish_callback(task_error, cnt_out_param, out_param_array, simple_task_finish_callback_usr_data); + + } else { + FW_LOGD("cannot call finish callback\n"); + /* TODO : remove output parameters since we have to nothing to return but prevent memory leak */ + } +} + +void task_remove_control_flow(task_t *pParent_task, ec_int from_task_index, ec_int to_task_index) +{ + if (pParent_task == NULL) { + FW_LOGE("pParent_task == NULL\n"); + return; + } + + task_spec_t *pParent_task_spec = pParent_task->pTask_spec; + engine_controller_error_t ec_error = ENGINE_CONTROLLER_OK; + if (task_spec_is_container_task_spec(pParent_task_spec)) { + ec_error = task_spec_valididate_child_task_index(pParent_task_spec, to_task_index); + + } else if (task_spec_is_dynamic_container_task_spec(pParent_task_spec)) { + ec_error = task_spec_valididate_child_task_index_on_dynamic_case(pParent_task->dynamic_case, pParent_task_spec, to_task_index); + } + + if (ec_error != ENGINE_CONTROLLER_OK) { + FW_LOGE("invalid to_task_index. to_task_index = %d\n", to_task_index); + return; + } + + /* remove in_degree of to_task */ + pParent_task->current_child_task_control_flow_in_degree_array[to_task_index] -= 1; +} + +void task_set_left_child_to_run(task_t *pParent_task, ec_uint number) +{ + pParent_task->cnt_left_child_task_to_finish = number; +} + +ec_boolean task_is_left_child_to_run_zero(task_t *pParent_task) +{ + return (pParent_task->cnt_left_child_task_to_finish == 0); +} + +void task_decrease_left_child_to_run(task_t *pParent_task) +{ + (pParent_task->cnt_left_child_task_to_finish)--; +} + +ec_boolean task_is_parent_task_done(task_t *pParent_task) +{ + if (task_is_left_child_to_run_zero(pParent_task)) { + return true; + } else { + return false; + } +} + +void task_collect_parent_task_output_parameter(task_t *pParent_task) +{ + if (pParent_task == NULL) { + FW_LOGE("pParent_task == NULL\n"); + return; + } + + if (!task_is_container_task(pParent_task)) { + FW_LOGE("pParent_task is not container task\n"); + return; + } + + param_t *pTo_param = NULL; + param_spec *pTo_param_spec = NULL; + param_t *pFrom_param = NULL; + + ec_int i = 0; + ec_int param_cnt = task_get_param_cnt(pParent_task); + for (i = 0; i < param_cnt; i++) { + pTo_param = pParent_task->param_array[i]; + pTo_param_spec = pTo_param->pParam_spec; + + if (is_output_flag_on(pTo_param_spec->flags)) { + pFrom_param = task_fetch_from_param(pParent_task, -1, i); + + if (pFrom_param != NULL) { + /* set output parameter values */ + param_value_set_value_with_other_param_value(&(pTo_param->param_value), &(pFrom_param->param_value)); + } + } + } +} + +GSList *collect_firstly_runnable_child_tasks(task_t *pParent_task) +{ + GSList *runnable_child_task_list = NULL; + if (!task_is_container_task(pParent_task)) { + goto error_part; + } + + ec_int i = 0; + task_spec_t *pParent_task_spec = pParent_task->pTask_spec; + child_tasks_info_t *pChild_task_info = NULL; + if (task_spec_is_container_task_spec(pParent_task_spec)) { + pChild_task_info = task_spec_find_child_tasks_info(pParent_task_spec); + } else if (task_spec_is_dynamic_container_task_spec(pParent_task_spec)) { + pChild_task_info = task_spec_find_case_specific_child_tasks_info(pParent_task_spec, pParent_task->dynamic_case); + } else { + assert(false); + } + + ec_int child_task_cnt; + ec_uint *child_task_control_flow_in_degree; + + if (pChild_task_info != NULL) { + child_task_cnt = pChild_task_info->child_task_cnt; + child_task_control_flow_in_degree = pChild_task_info->child_task_control_flow_in_degree; + } else { + goto error_part; + } + + task_t *pChild_task = NULL; + for (i = 0; i < child_task_cnt; i++) { + if (child_task_control_flow_in_degree[i] == 0) { + pChild_task = task_alloc_child_task(pParent_task, i); + if (pChild_task == NULL) { + goto error_part; + } + + pParent_task->child_task_array[i] = pChild_task; + runnable_child_task_list = g_slist_append(runnable_child_task_list, pChild_task); + } + } + + return runnable_child_task_list; + +error_part: + if (runnable_child_task_list != NULL) { + GSList *iter = NULL; + for (iter = runnable_child_task_list; iter != NULL; iter = g_slist_next(iter)) { + pChild_task = (task_t *)(iter->data); + task_unref_task(pChild_task); + } + g_slist_free(runnable_child_task_list); + } + + return NULL; +} + +GSList *collect_become_runnable_child_tasks_by_remove_control_flow(task_t *pParent_task, ec_int from_child_task_index) +{ + GSList *runnable_child_task_list = NULL; + if (!task_is_container_task(pParent_task)) { + goto error_part; + } + + /* validation */ + task_spec_t *pParent_task_spec = pParent_task->pTask_spec; + engine_controller_error_t ec_error = ENGINE_CONTROLLER_OK; + if (task_spec_is_container_task_spec(pParent_task_spec)) { + ec_error = task_spec_valididate_child_task_index(pParent_task_spec, from_child_task_index); + + } else if (task_spec_is_dynamic_container_task_spec(pParent_task_spec)) { + ec_error = task_spec_valididate_child_task_index_on_dynamic_case(pParent_task->dynamic_case, pParent_task_spec, from_child_task_index); + } + if (ec_error != ENGINE_CONTROLLER_OK) { + FW_LOGE("invalid from child task index. from child task index = %d\n", from_child_task_index); + goto error_part; + } + + child_tasks_info_t *pChild_task_info = NULL; + if (task_spec_is_container_task_spec(pParent_task_spec)) { + pChild_task_info = task_spec_find_child_tasks_info(pParent_task_spec); + } else if (task_spec_is_dynamic_container_task_spec(pParent_task_spec)) { + pChild_task_info = task_spec_find_case_specific_child_tasks_info(pParent_task_spec, pParent_task->dynamic_case); + } else { + assert(false); + } + + graph_edge_pool_t *pControl_edge_pool; + + if (pChild_task_info != NULL) { + pControl_edge_pool = pChild_task_info->pControl_edge_pool; + } else { + goto error_part; + } + + /* get to node list from child_index */ + /* note that to nodes_list containing ec_int */ + GList *to_node_list = graph_edge_pool_query_to_node_list(pControl_edge_pool, (ec_constpointer) from_child_task_index); + + /* remove control flow from child task at child_index of parent task */ + GList *iter = NULL; + ec_int to_child_task_index = 0; + task_t *pTo_child_task = NULL; + for (iter = to_node_list; iter != NULL; iter = g_list_next(iter)) { + to_child_task_index = (ec_int)(iter->data); + task_remove_control_flow(pParent_task, from_child_task_index, to_child_task_index); + + /* if zero in-degree of control flow detected, make child task and append runnable_child_task_list */ + if (pParent_task->current_child_task_control_flow_in_degree_array[to_child_task_index] == 0) { + pTo_child_task = task_alloc_child_task(pParent_task, to_child_task_index); + if (pTo_child_task == NULL) { + FW_LOGE("out of memory\n"); + goto error_part; + } + + pParent_task->child_task_array[to_child_task_index] = pTo_child_task; + runnable_child_task_list = g_slist_append(runnable_child_task_list, pTo_child_task); + } + } + + return runnable_child_task_list; + +error_part: + if (runnable_child_task_list != NULL) { + GSList *iter = NULL; + task_t *pChild_task; + for (iter = runnable_child_task_list; iter != NULL; iter = g_slist_next(iter)) { + pChild_task = (task_t *)(iter->data); + task_unref_task(pChild_task); + } + g_slist_free(runnable_child_task_list); + } + + return NULL; +} + +task_error_t task_run_simple_task(task_t *pSimple_task) +{ + task_error_t task_error = TASK_ERROR_NOT_YET_RUN; + + task_spec_t *pTask_spec = pSimple_task->pTask_spec; + task_cancel_info_t *pCancel_Info = pSimple_task->pCancel_Information; + + refObject_t *pRequestMsg_ref = pSimple_task->pRequestMsg; + engine_controller_request_msg_t *pRequestMsg = (engine_controller_request_msg_t *)getData(pRequestMsg_ref); + + ec_int request_msg_id = pRequestMsg->msg_head.msg_id; + + if (-1 == gettimeofday(&(pSimple_task->run_time), NULL)) { + FW_LOGW("setting run time error\n"); + } + + if (task_cancel_info_get_cancel_flag_atomic(pCancel_Info)) { + FW_LOGD("cancel flag on case\n"); + + /* do not run task if cancellation flag on */ + task_error = TASK_ERROR_CANCELED; + } else { + FW_LOGD("cancel flag off case\n"); + task_error = pTask_spec->u.task_process(pSimple_task->pTask_spec->task_param_cnt, pSimple_task->param_array); + } + + if (-1 == gettimeofday(&(pSimple_task->finish_time), NULL)) { + FW_LOGE("setting finish time error\n"); + } + + /* set task error information */ + task_set_task_error(pSimple_task, task_error); + + if (pTask_spec->post_func != NULL) { + pTask_spec->post_func(pTask_spec->usr_post_task_func_data, request_msg_id); + } + + return task_error; +} + +ec_boolean task_add_pending_task_list_of_first_progress_blocking_realized_entity(task_t *pTask) +{ + ec_boolean is_pending_task = false; + + GSList *iter_current_node = NULL; + GSList *iter_realized_entity = NULL; + n_ary_tree_node_with_flag_t *current_node = NULL; + progress_blocking_realized_entity_t *pRealized_entity = NULL; + progress_blocking_realized_entity_t *pPrev_realized_entity = NULL; + GQueue *progress_blocking_queue = NULL; + + /* iterate all queuing rules related to pTask */ + for (iter_current_node = pTask->current_node_in_progress_blocking_entity_list, iter_realized_entity = pTask->progress_blocking_realized_entity_list; iter_current_node != NULL && iter_realized_entity != NULL; iter_current_node = g_slist_next(iter_current_node), iter_realized_entity = g_slist_next(iter_realized_entity)) { + current_node = (n_ary_tree_node_with_flag_t *)(iter_current_node->data); + pRealized_entity = (progress_blocking_realized_entity_t *)(iter_realized_entity->data); + + progress_blocking_queue = pRealized_entity->pEntity->pQueuing_rule_spec->progress_blocking_queue; + if (current_node != NULL && n_ary_tree_node_with_flag_is_blocking_flag_on(current_node) && g_queue_peek_head(progress_blocking_queue) != pRealized_entity) { + /* pending condition */ + GList *realized_entity_node = g_queue_find(progress_blocking_queue, pRealized_entity); + GList *prev_realized_entity_node = realized_entity_node->prev; + + pPrev_realized_entity = (progress_blocking_realized_entity_t *)(prev_realized_entity_node->data); + progress_blocking_realized_entity_add_pending_task(pPrev_realized_entity, pTask); + is_pending_task = true; + break; /* note that only append first found queue */ + } + } + + return is_pending_task; +} + +void task_update_progress_blocking_realized_entity_and_pop_if_possible(task_t *pTask) +{ + GSList *iter_current_node = NULL; + GSList *iter_realized_entity = NULL; + n_ary_tree_node_with_flag_t *current_node = NULL; + progress_blocking_realized_entity_t *pRealized_entity = NULL; + GQueue *progress_blocking_queue = NULL; + + for (iter_current_node = pTask->current_node_in_progress_blocking_entity_list, iter_realized_entity = pTask->progress_blocking_realized_entity_list; iter_current_node != NULL && iter_realized_entity != NULL; iter_current_node = g_slist_next(iter_current_node), iter_realized_entity = g_slist_next(iter_realized_entity)) { + current_node = (n_ary_tree_node_with_flag_t *)(iter_current_node->data); + pRealized_entity = (progress_blocking_realized_entity_t *)(iter_realized_entity->data); + if (progress_blocking_realized_entity_update_and_test_left_progress_blocking_element_cnt(pRealized_entity, current_node, pTask)) { + /* pop pRealized_entity in queue */ + progress_blocking_queue = pRealized_entity->pEntity->pQueuing_rule_spec->progress_blocking_queue; + g_queue_remove(progress_blocking_queue, pRealized_entity); + + /* restart pending tasks due to pRealized_entity */ + progress_blocking_realized_entity_restart_pending_task(pRealized_entity); + } + } +} + +#include "EngineController/task_message.h" + +progress_blocking_realized_entity_t *progress_blocking_realized_entity_new(progress_blocking_entity_t *pEntity) +{ + progress_blocking_realized_entity_t *pRealized_entity = (progress_blocking_realized_entity_t *)calloc(1, sizeof(progress_blocking_realized_entity_t)); + if (pRealized_entity == NULL) { + goto error_part; + } + + pRealized_entity->pEntity = progress_blocking_entity_ref(pEntity); + pRealized_entity->left_progress_blocking_element_cnt = pEntity->pElement_set->progress_blocking_element_cnt; + pRealized_entity->pending_task_list = NULL; + + return pRealized_entity; + +error_part: + progress_blocking_realized_entity_free(pRealized_entity); + return NULL; +} + +void progress_blocking_realized_entity_free(progress_blocking_realized_entity_t *pRealized_entity) +{ + if (pRealized_entity != NULL) { + if (pRealized_entity->pEntity != NULL) { + progress_blocking_entity_unref(pRealized_entity->pEntity); + } + + if (pRealized_entity->pending_task_list != NULL) { + GSList *iter = NULL; + task_t *pPending_task = NULL; + for (iter = pRealized_entity->pending_task_list; iter != NULL; iter = g_slist_next(iter)) { + pPending_task = (task_t *)(iter->data); + task_unref_task(pPending_task); + } + + g_slist_free(pRealized_entity->pending_task_list); + } + + free(pRealized_entity); + } +} + +void progress_blocking_realized_entity_restart_pending_task(progress_blocking_realized_entity_t *pRealized_entity) +{ + GSList *iter = NULL; + task_t *pPending_task = NULL; + engine_controller_request_msg_t *pRequest_msg = NULL; + task_message_t *pNew_task_msg = NULL; + for (iter = pRealized_entity->pending_task_list; iter != NULL; iter = g_slist_next(iter)) { + pPending_task = (task_t *)(iter->data); + pRequest_msg = (engine_controller_request_msg_t *)getData(pPending_task->pRequestMsg); + + FW_LOGD("pending task (request msg id = %d, task spec id = %d, task spec name = %s) by queuing rule restarted\n", pRequest_msg->msg_head.msg_id, pPending_task->pTask_info->task_spec_id, pPending_task->pTask_info->pTask_spec->task_name); + + /* send msg to engine controller itself */ + pNew_task_msg = task_message_create(TASK_START, pPending_task, 0); + send_msg_to_engine_controller_with_compare_priority(pNew_task_msg, compare_priority_of_task_message_append_way, NULL); + + /* TODO : error handling */ + } +} + +void progress_blocking_realized_entity_add_pending_task(progress_blocking_realized_entity_t *pEntity, task_t *pending_task) +{ + pEntity->pending_task_list = g_slist_append(pEntity->pending_task_list, task_ref_task(pending_task)); +} + +ec_boolean progress_blocking_realized_entity_update_and_test_left_progress_blocking_element_cnt(progress_blocking_realized_entity_t *pRealized_entity, n_ary_tree_node_with_flag_t *current_node, task_t *pTask) +{ + if (progress_blocking_realized_entity_is_zero_left_progress_blocking_element_cnt(pRealized_entity)) { + return false; + } + + ec_boolean become_zero_after_update = false; + + switch (pTask->task_error) { + case TASK_ERROR_INVALID_TASK: + FW_LOGW("invalid task error returned\n"); + case TASK_ERROR_RUN_FAILED: + case TASK_ERROR_CANCELED: + become_zero_after_update = true; + pRealized_entity->left_progress_blocking_element_cnt = 0; + break; + case TASK_ERROR_RUN_SUCCESS: + if (current_node != NULL && n_ary_tree_node_with_flag_is_blocking_flag_on(current_node)) { + (pRealized_entity->left_progress_blocking_element_cnt)--; + + if (progress_blocking_realized_entity_is_zero_left_progress_blocking_element_cnt(pRealized_entity)) { + become_zero_after_update = true; + } + } + break; + case TASK_ERROR_NOT_YET_RUN: + if (current_node != NULL && task_spec_is_dynamic_container_task_spec(pTask->pTask_spec)) { + /* we can remove other dynamic case progress_blocking_element */ + + ec_uint can_remove_flag_on_cnt = 0; + + n_ary_tree_node_with_flag_t *child_node = NULL; + for (child_node = current_node->first_child_node; child_node != NULL; child_node = child_node->next_sibling_node) { + if (child_node->dynamic_case != pTask->dynamic_case) { + can_remove_flag_on_cnt += n_ary_tree_node_with_flag_count_subtree_flag_on_number(child_node); + } + } + + if (can_remove_flag_on_cnt > 0) { + (pRealized_entity->left_progress_blocking_element_cnt) -= can_remove_flag_on_cnt; + + if (progress_blocking_realized_entity_is_zero_left_progress_blocking_element_cnt(pRealized_entity)) { + become_zero_after_update = true; + } + } + } + break; + default: + FW_LOGW("unknown task error returned\n"); + become_zero_after_update = true; + pRealized_entity->left_progress_blocking_element_cnt = 0; + break; + } + + return become_zero_after_update; +} + +ec_boolean progress_blocking_realized_entity_is_zero_left_progress_blocking_element_cnt(progress_blocking_realized_entity_t *pRealized_entity) +{ + return pRealized_entity->left_progress_blocking_element_cnt == 0; +} diff --git a/framework/src/EngineController/task_cancel_info.c b/framework/src/EngineController/task_cancel_info.c new file mode 100755 index 0000000..955e453 --- /dev/null +++ b/framework/src/EngineController/task_cancel_info.c @@ -0,0 +1,284 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Wook Choi + */ + +#include +#include "Utility/fw_log.h" +#include "EngineController/task_message.h" +#include "EngineController/task_cancel_info.h" + +#define LOG_TAG "AF_EC" + +static void task_cancel_info_destroy(task_cancel_info_t *pInfo) +{ + if (pInfo != NULL) { + if (pInfo->pRequestMsg != NULL) { + unref_refObject(pInfo->pRequestMsg); + } + if (pInfo->cancel_info_mutex != NULL) { + g_mutex_free(pInfo->cancel_info_mutex); + } + if (pInfo->cancel_callback_infos != NULL) { + GSList *iter = NULL; + cancel_callback_info_t *pCancel_callback_info = NULL; + for (iter = pInfo->cancel_callback_infos; iter != NULL; iter = g_slist_next(iter)) { + pCancel_callback_info = iter->data; + cancel_callback_info_destroy(pCancel_callback_info); + } + g_slist_free(pInfo->cancel_callback_infos); + } + free(pInfo); + } +} + +cancel_callback_info_t *cancel_callback_info_init(GThread *who_registered, cancel_callback how_to_do, ec_pointer user_data) +{ + cancel_callback_info_t *pCancel_callback_info = (cancel_callback_info_t *)malloc(sizeof(cancel_callback_info_t)); + if (pCancel_callback_info == NULL) { + goto error_part; + } + + pCancel_callback_info->who_registered = who_registered; + pCancel_callback_info->how_to_do = how_to_do; + pCancel_callback_info->user_data = user_data; + + return pCancel_callback_info; + +error_part: + cancel_callback_info_destroy(pCancel_callback_info); + return NULL; +} + +ec_boolean cancel_callback_info_compare(cancel_callback_info_t *pCancel_callback_info, GThread *who_registered, cancel_callback how_to_do, ec_pointer user_data) +{ + FW_LOGD("started\n"); + ec_boolean is_same = false; + if (pCancel_callback_info == NULL) { + FW_LOGW("pCancel_callback_info == NULL\n"); + goto return_part; + } + + if (pCancel_callback_info->who_registered == who_registered && pCancel_callback_info->how_to_do == how_to_do && pCancel_callback_info->user_data == user_data) { + is_same = true; + } + +return_part: + FW_LOGD("ended with return = %d\n", is_same); + return is_same; +} + +void cancel_callback_info_call_callback(cancel_callback_info_t *pCancel_callback_info) +{ + FW_LOGD("started\n"); + if (pCancel_callback_info != NULL) { + /* call callback */ + FW_LOGD("cancel callback will be called by thread (thread structure = %p)\n", pCancel_callback_info->who_registered); + FW_LOGD("before call cancel callback\n"); + pCancel_callback_info->how_to_do(pCancel_callback_info->user_data); + FW_LOGD("after call cancel callback\n"); + } else { + FW_LOGW("pCancel_callback_info = NULL. Do nothing\n"); + } + FW_LOGD("ended\n"); +} + +void cancel_callback_info_destroy(cancel_callback_info_t *pCancel_callback_info) +{ + FW_LOGD("started\n"); + if (pCancel_callback_info != NULL) { + free(pCancel_callback_info); + } else { + FW_LOGW("pCancel_callback_info = NULL. Do nothing\n"); + } + FW_LOGD("ended\n"); +} + +task_cancel_info_t *task_cancel_info_init(refObject_t *pRequestMsg) +{ + task_cancel_info_t *pInfo = (task_cancel_info_t *)calloc(1, sizeof(task_cancel_info_t)); + if (pInfo == NULL) { + goto error_part; + } + + pInfo->cancel_info_mutex = g_mutex_new(); + if (pInfo->cancel_info_mutex == NULL) { + goto error_part; + } + pInfo->cancel_flag = false; + pInfo->pRequestMsg = getRef(pRequestMsg); + pInfo->ref_count = 1; + + return pInfo; + +error_part: + task_cancel_info_destroy(pInfo); + return NULL; +} + +task_cancel_info_t *task_cancel_info_ref(task_cancel_info_t *pInfo) +{ + if (pInfo == NULL) { + return NULL; + } + + g_atomic_int_inc(&(pInfo->ref_count)); + + return pInfo; +} + +void task_cancel_info_unref(task_cancel_info_t *pInfo) +{ + if (pInfo == NULL) { + return; + } + + if (g_atomic_int_dec_and_test(&(pInfo->ref_count))) { + task_cancel_info_destroy(pInfo); + } +} + +ec_boolean task_cancel_info_get_cancel_flag_atomic(task_cancel_info_t *pCancel_info) +{ + if (pCancel_info == NULL) { + FW_LOGE("pCancel_info == NULL\n"); + return false; + } + return g_atomic_int_get(&(pCancel_info->cancel_flag)); +} + +void task_cancel_info_set_cancel_flag_atomic(task_cancel_info_t *pCancel_info) +{ + FW_LOGD("start\n"); + if (pCancel_info == NULL) { + FW_LOGE("pCancel_info == NULL\n"); + return; + } + g_atomic_int_set(&(pCancel_info->cancel_flag), true); + FW_LOGD("end\n"); +} + +ec_int task_cancel_info_get_request_msg_id(task_cancel_info_t *pCancel_info) +{ + FW_LOGD("start\n"); + if (pCancel_info == NULL) { + FW_LOGE("pCancel_info == NULL\n"); + return -1; + } + if (pCancel_info->pRequestMsg == NULL) { + FW_LOGE("pCancel_info->pRequestMsg == NULL\n"); + return -1; + } + + engine_controller_request_msg_t *pRequest_msg = (engine_controller_request_msg_t *)getData(pCancel_info->pRequestMsg); + FW_LOGD("end with return = %d\n", pRequest_msg->msg_head.msg_id); + return pRequest_msg->msg_head.msg_id; +} + +void task_cancel_info_call_cancel_callbacks_unlocked(task_cancel_info_t *pCancel_info) +{ + FW_LOGD("start\n"); + if (pCancel_info == NULL) { + FW_LOGE("pCancel_info == NULL\n"); + return; + } + + GSList *iter = NULL; + cancel_callback_info_t *pCancel_callback_info = NULL; + FW_LOGD("%d number of cancel callback is registered by threads of thread pool\n", g_slist_length(pCancel_info->cancel_callback_infos)); + for (iter = pCancel_info->cancel_callback_infos; iter != NULL; iter = g_slist_next(iter)) { + pCancel_callback_info = iter->data; + cancel_callback_info_call_callback(pCancel_callback_info); + } + FW_LOGD("end\n"); +} + +engine_controller_error_t task_cancel_info_register_cancel_callback_unlocked(task_cancel_info_t *pCancel_info, cancel_callback callback_func, ec_pointer user_data) +{ + FW_LOGD("start\n"); + engine_controller_error_t ec_error = ENGINE_CONTROLLER_OK; + + if (pCancel_info == NULL) { + FW_LOGE("pCancel_info == NULL\n"); + ec_error = ENGINE_CONTROLLER_INVALID_PARAMETER; + goto return_part; + } + + /* create cancel callback info */ + cancel_callback_info_t *pCancel_callback_info = cancel_callback_info_init(g_thread_self(), callback_func, user_data); + if (pCancel_callback_info == NULL) { + FW_LOGE("cancel_callback_info_init failed because of out of memory\n"); + ec_error = ENGINE_CONTROLLER_OUT_OF_MEMORY; + goto return_part; + } + + pCancel_info->cancel_callback_infos = g_slist_prepend(pCancel_info->cancel_callback_infos, pCancel_callback_info); + +return_part: + FW_LOGD("end with return = %d\n", ec_error); + return ec_error; +} + +engine_controller_error_t task_cancel_info_unregister_cancel_callback_unlocked(task_cancel_info_t *pCancel_info, cancel_callback callback_func, ec_pointer user_data) +{ + FW_LOGD("start\n"); + engine_controller_error_t ec_error = ENGINE_CONTROLLER_OK; + + if (pCancel_info == NULL) { + FW_LOGE("pCancel_info == NULL\n"); + ec_error = ENGINE_CONTROLLER_INVALID_PARAMETER; + goto return_part; + } + + /* remove in callback list */ + GThread *current_thread = g_thread_self(); + GSList *iter = NULL; + cancel_callback_info_t *pCancel_callback_info = NULL; + ec_boolean is_same = false; + for (iter = pCancel_info->cancel_callback_infos; iter != NULL; iter = g_slist_next(iter)) { + pCancel_callback_info = iter->data; + + is_same = cancel_callback_info_compare(pCancel_callback_info, current_thread, callback_func, user_data); + if (is_same) { + cancel_callback_info_destroy(pCancel_callback_info); + pCancel_info->cancel_callback_infos = g_slist_delete_link(pCancel_info->cancel_callback_infos, iter); + break; + } + } + + FW_LOGD("no same callback exist in the list\n"); + +return_part: + FW_LOGD("end with return = %d\n", ec_error); + return ec_error; +} diff --git a/framework/src/EngineController/task_error.c b/framework/src/EngineController/task_error.c new file mode 100755 index 0000000..45d463e --- /dev/null +++ b/framework/src/EngineController/task_error.c @@ -0,0 +1,64 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Wook Choi + */ + +#include "EngineController/task_error.h" + +typedef struct task_error_map_s task_error_map_t; +struct task_error_map_s { + task_error_t err; + ec_char *str; +}; + +static task_error_map_t task_error_string_tbl[5] = { + {TASK_ERROR_NOT_YET_RUN, "not yet run"}, + {TASK_ERROR_RUN_SUCCESS, "success"}, + {TASK_ERROR_RUN_FAILED, "failed"}, + {TASK_ERROR_CANCELED, "canceled"}, + {TASK_ERROR_INVALID_TASK, "invalid"} +}; + +ec_char *task_error_string(task_error_t error) +{ + ec_char *str = task_error_string_tbl[4].str; + ec_int i = 0; + for (i = 0; i < 5; i++) { + if (error == task_error_string_tbl[i].err) { + str = task_error_string_tbl[i].str; + break; + } + } + + return str; +} diff --git a/framework/src/EngineController/task_info_pool.c b/framework/src/EngineController/task_info_pool.c new file mode 100755 index 0000000..fded975 --- /dev/null +++ b/framework/src/EngineController/task_info_pool.c @@ -0,0 +1,194 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Wook Choi + */ + +#include +#include "Utility/fw_log.h" +#include "EngineController/task_info_pool.h" +#include "EngineController/queuing_rule_spec.h" + +#define LOG_TAG "AF_EC" + +task_info_t *task_info_new(ec_int task_spec_id, task_spec_t *pTask_spec) +{ + task_info_t *pTask_info = (task_info_t *)calloc(1, sizeof(task_info_t)); + if (pTask_info == NULL) { + goto error_part; + } + + pTask_info->task_spec_id = task_spec_id; + pTask_info->progress_blocking_entity_list = NULL; + pTask_info->pTask_spec = task_spec_ref(pTask_spec); + + return pTask_info; + +error_part: + task_info_free(pTask_info); + return NULL; +} + +void task_info_free(task_info_t *pTask_info) +{ + if (pTask_info != NULL) { + if (pTask_info->pTask_spec != NULL) { + task_spec_unref(pTask_info->pTask_spec); + } + + if (pTask_info->progress_blocking_entity_list != NULL) { + GSList *iter = NULL; + progress_blocking_entity_t *pEntity = NULL; + for (iter = pTask_info->progress_blocking_entity_list; iter != NULL; iter = g_slist_next(iter)) { + pEntity = (progress_blocking_entity_t *)(iter->data); + progress_blocking_entity_unref(pEntity); + } + g_slist_free(pTask_info->progress_blocking_entity_list); + } + + free(pTask_info); + } +} + +task_info_t *task_info_ref(task_info_t *pTask_info) +{ + /* TODO */ + return pTask_info; +} + +void task_info_unref(task_info_t *pTask_info) +{ + /* TODO */ +} + +ec_boolean task_info_is_progress_blocking_entity_exist(task_info_t *pTask_info, progress_blocking_entity_t *pEntity) +{ + GSList *found_node = g_slist_find(pTask_info->progress_blocking_entity_list, pEntity); + if (found_node != NULL) { + return true; + } + + return false; +} + +engine_controller_error_t task_info_add_progress_blocking_entity(task_info_t *pTask_info, progress_blocking_entity_t *pEntity) +{ + engine_controller_error_t ec_error = ENGINE_CONTROLLER_OK; + + if (task_info_is_progress_blocking_entity_exist(pTask_info, pEntity)) { + FW_LOGW("task info has already same entity"); + goto return_part; + } + + pTask_info->progress_blocking_entity_list = g_slist_prepend(pTask_info->progress_blocking_entity_list, pEntity); + /* TODO : error handling */ + +return_part: + return ec_error; +} + +engine_controller_error_t task_info_remove_blocking_entity(task_info_t *pTask_info, progress_blocking_entity_t *pEntity) +{ + engine_controller_error_t ec_error = ENGINE_CONTROLLER_OK; + + if (!task_info_is_progress_blocking_entity_exist(pTask_info, pEntity)) { + FW_LOGW("task info has no such entity"); + goto return_part; + } + + pTask_info->progress_blocking_entity_list = g_slist_remove(pTask_info->progress_blocking_entity_list, pEntity); + +return_part: + return ec_error; +} + +task_info_pool_t *task_info_pool_alloc() +{ + task_info_pool_t *pTask_info_pool = (task_info_pool_t *)calloc(1, sizeof(task_info_pool_t)); + if (pTask_info_pool == NULL) { + goto return_part; + } + + pTask_info_pool->pTask_info_pool = g_hash_table_new(g_direct_hash, g_direct_equal); + if (pTask_info_pool->pTask_info_pool == NULL) { + goto error_part; + } + +return_part: + return pTask_info_pool; + +error_part: + task_info_pool_free(pTask_info_pool); + return NULL; +} + +void task_info_pool_free(task_info_pool_t *pTask_info_pool) +{ + if (pTask_info_pool != NULL) { + /* TODO */ + } +} + +ec_boolean task_info_pool_add_task_info(task_info_pool_t *pTask_info_pool, task_info_t *pTask_info, ec_boolean replace) +{ + ec_boolean success = false; + + GHashTable *pHash = pTask_info_pool->pTask_info_pool; + if (replace) { + g_hash_table_replace(pHash, (gpointer) (pTask_info->task_spec_id), pTask_info); /* TODO : check free well done */ + success = true; + } else { + gpointer tmp = g_hash_table_lookup(pHash, (gpointer) (pTask_info->task_spec_id)); + if (tmp != NULL) { + success = false; + } else { + g_hash_table_insert(pHash, (gpointer) (pTask_info->task_spec_id), pTask_info); + } + } + + return success; +} + +ec_boolean task_info_pool_remove_task_info(task_info_pool_t *pTask_info_pool, ec_uint msg_type) +{ + /* TODO */ + return true; +} + +task_info_t *task_info_pool_search_task_info(task_info_pool_t *pTask_info_pool, ec_uint msg_type) +{ + GHashTable *pHash = pTask_info_pool->pTask_info_pool; + task_info_t *pTask_info = NULL; + + pTask_info = (task_info_t *)g_hash_table_lookup(pHash, (gpointer) msg_type); + return pTask_info; +} diff --git a/framework/src/EngineController/task_message.c b/framework/src/EngineController/task_message.c new file mode 100755 index 0000000..0488585 --- /dev/null +++ b/framework/src/EngineController/task_message.c @@ -0,0 +1,114 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Wook Choi + */ + +#include +#include "EngineController/task_message.h" + +/* lower priority, more urgent */ +ec_uint task_state_priority(task_state_t state) +{ + ec_uint priority = 0; + switch (state) { + case TASK_ROOT_START: + case TASK_ROOT_DONE: + case TASK_CANCEL: + case TASK_CANCEL_ALL: + priority = 0; + break; + case TASK_DONE: + priority = 1; + break; + case TASK_START: + priority = 2; + break; + } + + return priority; +} + +ec_int compare_priority_of_task_message_append_way(task_message_t *pTask_message1, task_message_t *pTask_message2, ec_pointer user_data) +{ + if (pTask_message1->priority < pTask_message2->priority) { + return -1; + } else if (pTask_message1->priority == pTask_message2->priority) { + return 0; + } else { + return 1; + } +} + +ec_int compare_priority_of_task_message_prepend_way(task_message_t *pTask_message1, task_message_t *pTask_message2, ec_pointer user_data) +{ + if (pTask_message1->priority < pTask_message2->priority) { + return -1; + } else { + return 1; + } +} + +task_message_t *task_message_create(task_state_t state, task_t *pTask, ec_uint request_msg_id) +{ + task_message_t *pTask_msg = (task_message_t *)calloc(1, sizeof(task_message_t)); + if (pTask_msg == NULL) { + goto error_part; + } + pTask_msg->priority = task_state_priority(state); + pTask_msg->task_state = state; + if (state == TASK_CANCEL) { + pTask_msg->u.request_msg_id = request_msg_id; + } else if (state == TASK_CANCEL_ALL) { + /* nothing */ + } else { + pTask_msg->u.pTask = task_ref_task(pTask); + } + + return pTask_msg; +error_part: + task_message_free(pTask_msg); + return NULL; +} + +void task_message_free(task_message_t *pTask_msg) +{ + if (pTask_msg != NULL) { + if (pTask_msg->task_state != TASK_CANCEL) { + if (pTask_msg->u.pTask != NULL) { + task_unref_task(pTask_msg->u.pTask); + } + } + + free(pTask_msg); + } +} diff --git a/framework/src/EngineController/task_pool.c b/framework/src/EngineController/task_pool.c new file mode 100755 index 0000000..a3b5f2a --- /dev/null +++ b/framework/src/EngineController/task_pool.c @@ -0,0 +1,121 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Wook Choi + */ + +#include +#include +#include +#include "EngineController/task_pool.h" + +task_pool_t *task_pool_create_task_pool() +{ + task_pool_t *pTask_pool = (task_pool_t *)calloc(1, sizeof(task_pool_t)); + if (pTask_pool == NULL) { + goto return_part; + } + + pTask_pool->pTask_hash = g_hash_table_new(g_direct_hash, g_direct_equal); + if (pTask_pool->pTask_hash == NULL) { + goto error_part; + } + +return_part: + return pTask_pool; + +error_part: + task_pool_free_task_pool(pTask_pool); + return NULL; +} + +void task_pool_free_task_pool(task_pool_t *pTask_pool) +{ + if (pTask_pool != NULL) { + GHashTable *pTask_hash = pTask_pool->pTask_hash; + if (pTask_hash != NULL) { + GHashTableIter iter; + ec_int *request_msg_id_key = NULL; + task_t *pTask = NULL; + g_hash_table_iter_init(&iter, pTask_hash); + while (g_hash_table_iter_next(&iter, (void **)&request_msg_id_key, (void **)&pTask)) { + if (pTask != NULL) { + task_unref_task(pTask); + } + } + + g_hash_table_destroy(pTask_hash); + } + + free(pTask_pool); + } +} + +void task_pool_add_task(task_pool_t *pTask_pool, ec_uint request_id, task_t *pTask) +{ + g_hash_table_insert(pTask_pool->pTask_hash, (gpointer) request_id, (gpointer) task_ref_task(pTask)); +} + +task_t *task_pool_fetch_task(task_pool_t *pTask_pool, ec_uint request_id) +{ + GHashTable *pTask_hash = pTask_pool->pTask_hash; + task_t *pTask = (task_t *)g_hash_table_lookup(pTask_hash, (gconstpointer) request_id); + + if (pTask != NULL) { + return task_ref_task(pTask); + } else { + return NULL; + } +} + +GList *task_pool_fetch_all_tasks(task_pool_t *pTask_pool) +{ + GList *all_task_list = g_hash_table_get_values(pTask_pool->pTask_hash); + GList *iter = NULL; + task_t *pTask = NULL; + for (iter = all_task_list; iter != NULL; iter = g_list_next(iter)) { + pTask = iter->data; + task_ref_task(pTask); + } + + return all_task_list; +} + +void task_pool_remove_task(task_pool_t *pTask_pool, ec_uint request_id) +{ + GHashTable *pTask_hash = pTask_pool->pTask_hash; + task_t *pTask = (task_t *)g_hash_table_lookup(pTask_hash, (gconstpointer) request_id); + if (pTask != NULL) { + task_unref_task(pTask); + g_hash_table_remove(pTask_hash, (gconstpointer) request_id); + } +} diff --git a/framework/src/EngineController/task_process.c b/framework/src/EngineController/task_process.c new file mode 100755 index 0000000..cfab13c --- /dev/null +++ b/framework/src/EngineController/task_process.c @@ -0,0 +1,88 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Wook Choi + */ + +#include +#include "EngineController/task_process.h" +#include "EngineController/task_cancel_info.h" +#include "Utility/fw_log.h" +#include "Utility/fw_assert.h" + +#define LOG_TAG "AF_EC" + +extern GPrivate *pCancel_TSK; + +ec_boolean task_process_check_cancel_flag(void) +{ + task_cancel_info_t *pCancel_info = g_private_get(pCancel_TSK); + + return task_cancel_info_get_cancel_flag_atomic(pCancel_info); +} + +void task_process_register_cancel_callback_when_cancel_flag_off(process_cancel_callback callback_func, ec_pointer user_data) +{ + task_cancel_info_t *pCancel_info = g_private_get(pCancel_TSK); + + g_mutex_lock(pCancel_info->cancel_info_mutex); + if (!task_cancel_info_get_cancel_flag_atomic(pCancel_info)) { + FW_LOGD("cancel flag is off. Register cancel callback\n"); + engine_controller_error_t ec_error = task_cancel_info_register_cancel_callback_unlocked(pCancel_info, callback_func, user_data); + fw_assert_condition(ec_error == ENGINE_CONTROLLER_OK, "task_cancel_info_register_cancel_callback_unlocked failed\n"); + } else { + FW_LOGD("cancel flag is on. Do nothing\n"); + } + g_mutex_unlock(pCancel_info->cancel_info_mutex); +} + +void task_process_unregister_cancel_callback_when_cancel_flag_off(process_cancel_callback callback_func, ec_pointer user_data) +{ + task_cancel_info_t *pCancel_info = g_private_get(pCancel_TSK); + + g_mutex_lock(pCancel_info->cancel_info_mutex); + if (!task_cancel_info_get_cancel_flag_atomic(pCancel_info)) { + FW_LOGD("cancel flag is off. Unregister cancel callback\n"); + engine_controller_error_t ec_error = task_cancel_info_unregister_cancel_callback_unlocked(pCancel_info, callback_func, user_data); + fw_assert_condition(ec_error == ENGINE_CONTROLLER_OK, "task_cancel_info_unregister_cancel_callback_unlocked failed\n"); + } else { + FW_LOGD("cancel flag is on. Do nothing\n"); + } + g_mutex_unlock(pCancel_info->cancel_info_mutex); +} + +ec_int task_process_get_self_request_id(void) +{ + task_cancel_info_t *pCancel_info = g_private_get(pCancel_TSK); + + return task_cancel_info_get_request_msg_id(pCancel_info); +} diff --git a/framework/src/EngineController/task_spec.c b/framework/src/EngineController/task_spec.c new file mode 100755 index 0000000..5fffabe --- /dev/null +++ b/framework/src/EngineController/task_spec.c @@ -0,0 +1,1043 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Wook Choi + */ + +#include +#include +#include "Utility/fw_log.h" +#include "EngineController/task_spec.h" +#include "EngineController/task_spec_internal.h" +#include "EngineController/param_spec_internal.h" + +#define LOG_TAG "AF_EC" + +static task_spec_t *task_spec_new_default_task_spec(ec_char *task_name, ec_pointer post_task_func_usr_data, post_task_callback_func post_task_callback, ec_uint param_cnt, param_spec **param_spec_array); +static void task_spec_free_task_spec(task_spec_t *pTask_spec); + +static child_tasks_info_t *task_spec_new_child_tasks_info(ec_uint parent_param_cnt, ec_uint child_task_cnt, task_spec_t **child_task_array); + +static void task_spec_free_child_tasks_info(child_tasks_info_t *pChild_task_info); + +static dynamic_container_task_specific_t *task_spec_new_dynamic_container_task_specific(ec_uint parent_param_cnt, calculate_case_callback_func calculate_case_func, ec_uint case_cnt, ec_int *case_array, ec_uint *child_task_cnt_array, task_spec_t ***child_task_array_per_case_array); + +static void task_spec_free_dynamic_container_task_specific(dynamic_container_task_specific_t *pDynamic_container_task_specific); + +static param_spec *task_spec_find_param_spec(task_spec_t *pTask_spec, ec_int param_index); + +static engine_controller_error_t task_spec_validate_container_task_spec(task_spec_t *pContainer_task_spec); + +static engine_controller_error_t task_spec_validate_dynamic_container_task_spec(task_spec_t *pDynamic_container_task_spec); + +static engine_controller_error_t task_spec_validate_param_index(task_spec_t *pTask_spec, ec_int param_index); + +static engine_controller_error_t task_spec_validate_set_control_flow_input_parameters(task_spec_t *pContainer_task_spec, ec_int from_task_index, ec_int to_task_index); + +static engine_controller_error_t task_spec_validate_set_control_flow_input_parameters_on_dynamic_case(ec_int dynamic_case, task_spec_t *pDynamic_container_task_spec, ec_int from_task_index, ec_int to_task_index); + +static engine_controller_error_t task_spec_validate_set_data_flow_input_parameters(task_spec_t *pContainer_task_spec, ec_int from_task_index, ec_int from_param_index, ec_int to_task_index, ec_int to_param_index); + +static engine_controller_error_t task_spec_validate_set_data_flow_input_parameters_on_dynamic_case(ec_int dynamic_case, task_spec_t *pContainer_task_spec, ec_int from_task_index, ec_int from_param_index, ec_int to_task_index, ec_int to_param_index); + +data_flow_edges_t *data_flow_edges_new(ec_int parent_task_param_cnt, ec_uint child_task_cnt, task_spec_t **child_task_array) +{ + ec_int i = 0; + ec_int total_param_cnt = 0; + + data_flow_edges_t *pData_flow_edges = (data_flow_edges_t *)calloc(1, sizeof(data_flow_edges_t)); + if (pData_flow_edges == NULL) { + goto error_part; + } + + pData_flow_edges->child_task_param_start_index_array = (ec_int *)calloc(child_task_cnt, sizeof(ec_int)); + if (pData_flow_edges->child_task_param_start_index_array == NULL) { + goto error_part; + } + + /* compute total param cnt and child_task_param_start_index_array */ + total_param_cnt = parent_task_param_cnt; + for (i = 0; i < child_task_cnt; i++) { + pData_flow_edges->child_task_param_start_index_array[i] = total_param_cnt; + total_param_cnt += child_task_array[i]->task_param_cnt; + } + + pData_flow_edges->child_task_cnt = child_task_cnt; + pData_flow_edges->total_param_cnt = total_param_cnt; + + ec_int *from_param_array = (ec_int *)malloc(total_param_cnt * sizeof(ec_int)); + if (from_param_array == NULL) { + goto error_part; + } + + pData_flow_edges->from_param_array = from_param_array; + for (i = 0; i < total_param_cnt; i++) { + from_param_array[i] = -1; /* when -1, no from_param exist */ + } + + return pData_flow_edges; + +error_part: + data_flow_edges_free(pData_flow_edges); + return NULL; +} + +void data_flow_edges_free(data_flow_edges_t *pData_flow_edges) +{ + if (pData_flow_edges != NULL) { + if (pData_flow_edges->child_task_param_start_index_array != NULL) { + free(pData_flow_edges->child_task_param_start_index_array); + } + + if (pData_flow_edges->from_param_array != NULL) { + free(pData_flow_edges->from_param_array); + } + + free(pData_flow_edges); + } +} + +ec_int data_flow_edges_compute_internal_index(data_flow_edges_t *pData_flow_edges, ec_int task_index, ec_int param_index) +{ + ec_int *child_task_param_start_index_array = pData_flow_edges->child_task_param_start_index_array; + + if (task_index == -1) { + return param_index; + } else { + return param_index + child_task_param_start_index_array[task_index]; + } +} + +ec_boolean data_flow_edges_compute_task_index_and_param_index(data_flow_edges_t *pData_flow_edges, ec_int internal_index, ec_int *pTask_index, ec_int *pParam_index) +{ + ec_boolean valid_internal_index = false; + ec_int task_index = -1; + ec_int param_index = -1; + ec_int i = 0; + + if (internal_index >= 0 && internal_index < pData_flow_edges->total_param_cnt) { + valid_internal_index = true; + + for (i = 0; i < pData_flow_edges->child_task_cnt; i++) { + if (internal_index < pData_flow_edges->child_task_param_start_index_array[i]) { + task_index = i - 1; + + if (i == 0) { + param_index = internal_index; + } else { + param_index = internal_index - pData_flow_edges->child_task_param_start_index_array[i - 1]; + } + break; + } + } + + if (i == pData_flow_edges->child_task_cnt) { + task_index = i - 1; + param_index = internal_index - pData_flow_edges->child_task_param_start_index_array[i - 1]; + } + + *pTask_index = task_index; + *pParam_index = param_index; + } + + return valid_internal_index; +} + +ec_boolean data_flow_edges_add_edge(data_flow_edges_t *pData_flow_edges, ec_int from_task_index, ec_int from_param_index, ec_int to_task_index, ec_int to_param_index) +{ + ec_boolean success = false; + + ec_int from_param_internal_index = data_flow_edges_compute_internal_index(pData_flow_edges, from_task_index, from_param_index); + ec_int to_param_internal_index = data_flow_edges_compute_internal_index(pData_flow_edges, to_task_index, to_param_index); + + /* record edge */ + if (pData_flow_edges->from_param_array[to_param_internal_index] == -1) { /* -1 means no from param exist */ + success = true; + pData_flow_edges->from_param_array[to_param_internal_index] = from_param_internal_index; + } + + return success; +} + +/* TODO : make this function accessible by other operation file */ +ec_boolean data_flow_edges_get_from_param_info(data_flow_edges_t *pData_flow_edges, ec_int to_task_index, ec_int to_param_index, ec_int *from_task_index, ec_int *from_param_index) +{ + ec_boolean from_part_exist = false; + + ec_int to_internal_index = data_flow_edges_compute_internal_index(pData_flow_edges, to_task_index, to_param_index); + ec_int from_internal_index = pData_flow_edges->from_param_array[to_internal_index]; + if (from_internal_index != -1) { + data_flow_edges_compute_task_index_and_param_index(pData_flow_edges, from_internal_index, from_task_index, from_param_index); + from_part_exist = true; + } + + return from_part_exist; +} + +task_spec_t *task_spec_get_child_task_spec_from_child_task_info(child_tasks_info_t *pChild_tasks_info, ec_uint child_task_index) +{ + if (0 <= child_task_index && child_task_index < pChild_tasks_info->child_task_cnt) + return pChild_tasks_info->child_task_array[child_task_index]; + else + return NULL; +} + +ec_uint *task_spec_duplicate_child_task_control_flow_in_degree(task_spec_t *pTask_spec) +{ + ec_uint *duplcated_child_task_control_flow_in_degree = NULL; + + if (!task_spec_is_container_task_spec(pTask_spec)) { + goto error_part; + } + + child_tasks_info_t *pChild_task_info = task_spec_find_child_tasks_info(pTask_spec); + ec_uint child_task_cnt = pChild_task_info->child_task_cnt; + ec_uint *child_task_control_flow_in_degree = pChild_task_info->child_task_control_flow_in_degree; + + duplcated_child_task_control_flow_in_degree = (ec_uint *)malloc(child_task_cnt * sizeof(ec_uint)); + if (duplcated_child_task_control_flow_in_degree == NULL) { + goto error_part; + } + + memcpy(duplcated_child_task_control_flow_in_degree, child_task_control_flow_in_degree, child_task_cnt * sizeof(ec_uint)); + + return duplcated_child_task_control_flow_in_degree; + +error_part: + if (duplcated_child_task_control_flow_in_degree != NULL) { + free(duplcated_child_task_control_flow_in_degree); + } + return NULL; +} + +ec_uint *task_spec_duplicate_child_task_control_flow_in_degree_on_dynamic_case(task_spec_t *pDynamic_task_spec, ec_int dynamic_case) +{ + ec_uint *duplcated_child_task_control_flow_in_degree = NULL; + + if (!task_spec_is_dynamic_container_task_spec(pDynamic_task_spec)) { + goto error_part; + } + + ec_uint child_task_cnt; + ec_uint *child_task_control_flow_in_degree; + + child_tasks_info_t *pChild_task_info = task_spec_find_case_specific_child_tasks_info(pDynamic_task_spec, dynamic_case); + if (pChild_task_info != NULL) { + child_task_cnt = pChild_task_info->child_task_cnt; + child_task_control_flow_in_degree = pChild_task_info->child_task_control_flow_in_degree; + } else { + goto error_part; + } + + duplcated_child_task_control_flow_in_degree = (ec_uint *)malloc(child_task_cnt * sizeof(ec_uint)); + if (duplcated_child_task_control_flow_in_degree == NULL) { + goto error_part; + } + + memcpy(duplcated_child_task_control_flow_in_degree, child_task_control_flow_in_degree, child_task_cnt * sizeof(ec_uint)); + + return duplcated_child_task_control_flow_in_degree; + +error_part: + if (duplcated_child_task_control_flow_in_degree != NULL) { + free(duplcated_child_task_control_flow_in_degree); + } + return NULL; +} + +static task_spec_t *task_spec_new_default_task_spec(ec_char *task_name, ec_pointer post_task_func_usr_data, post_task_callback_func post_task_callback, ec_uint param_cnt, param_spec **param_spec_array) +{ + int i = 0; + task_spec_t *pTask = NULL; + + /* TODO : input parameter validation */ + + pTask = (task_spec_t *)calloc(1, sizeof(task_spec_t)); + if (pTask == NULL) { + goto return_part; + } + + pTask->task_name = strdup(task_name); + if (pTask->task_name == NULL) { + goto error_part; + } + + pTask->task_param_spec_array = (param_spec **)calloc(param_cnt, sizeof(param_spec *)); + if (pTask->task_param_spec_array == NULL) { + goto error_part; + } + + pTask->task_param_cnt = param_cnt; + for (i = 0; i < param_cnt; i++) { + pTask->task_param_spec_array[i] = param_spec_ref(param_spec_array[i]); + } + + pTask->usr_post_task_func_data = post_task_func_usr_data; + pTask->post_func = post_task_callback; + pTask->ref_count = 1; + +return_part: + return pTask; + +error_part: + task_spec_free_task_spec(pTask); + return NULL; +} + +static void task_spec_free_task_spec(task_spec_t *pTask_spec) +{ + if (pTask_spec != NULL) { + if (pTask_spec->task_name != NULL) { + free(pTask_spec->task_name); + } + + if (pTask_spec->task_param_cnt > 0) { + int i = 0; + for (i = 0; i < pTask_spec->task_param_cnt; i++) { + param_spec_unref(pTask_spec->task_param_spec_array[i]); + } + } + + /* TODO : child_parallel_task_list when container task */ + /* TODO : usr_task_data */ + + free(pTask_spec); + } +} + +static child_tasks_info_t *task_spec_new_child_tasks_info(ec_uint parent_param_cnt, ec_uint child_task_cnt, task_spec_t **child_task_array) +{ + ec_uint i = 0; + child_tasks_info_t *pChild_task_info = (child_tasks_info_t *)calloc(1, sizeof(child_tasks_info_t)); + + pChild_task_info->child_task_cnt = child_task_cnt; + pChild_task_info->child_task_array = (task_spec_t **)calloc(child_task_cnt, sizeof(task_spec_t *)); + if (pChild_task_info->child_task_array == NULL) { + goto error_part; + } + + for (i = 0; i < child_task_cnt; i++) { + pChild_task_info->child_task_array[i] = task_spec_ref(child_task_array[i]); + } + + pChild_task_info->child_task_control_flow_in_degree = (ec_uint *)calloc(child_task_cnt, sizeof(ec_uint)); + if (pChild_task_info->child_task_control_flow_in_degree == NULL) { + goto error_part; + } + + pChild_task_info->pControl_edge_pool = graph_edge_pool_new(); + if (pChild_task_info->pControl_edge_pool == NULL) { + goto error_part; + } + + pChild_task_info->pData_flow_edges = data_flow_edges_new(parent_param_cnt, child_task_cnt, child_task_array); + if (pChild_task_info->pData_flow_edges == NULL) { + goto error_part; + } + + return pChild_task_info; + +error_part: + task_spec_free_child_tasks_info(pChild_task_info); + return NULL; +} + +static void task_spec_free_child_tasks_info(child_tasks_info_t *pChild_task_info) +{ + if (pChild_task_info != NULL) { + ec_uint cnt = pChild_task_info->child_task_cnt; + ec_uint i = 0; + + if (pChild_task_info->pData_flow_edges != NULL) { + data_flow_edges_free(pChild_task_info->pData_flow_edges); + } + + if (pChild_task_info->pControl_edge_pool != NULL) { + graph_edge_pool_free(pChild_task_info->pControl_edge_pool); + } + + if (pChild_task_info->child_task_control_flow_in_degree != NULL) { + free(pChild_task_info->child_task_control_flow_in_degree); + } + + if (pChild_task_info->child_task_array != NULL) { + for (i = 0; i < cnt; i++) { + task_spec_unref(pChild_task_info->child_task_array[i]); + } + free(pChild_task_info->child_task_array); + } + + free(pChild_task_info); + } +} + +static dynamic_container_task_specific_t *task_spec_new_dynamic_container_task_specific(ec_uint parent_param_cnt, calculate_case_callback_func calculate_case_func, ec_uint case_cnt, ec_int *case_array, ec_uint *child_task_cnt_array, task_spec_t ***child_task_array_per_case_array) +{ + ec_uint i = 0; + dynamic_container_task_specific_t *pDynamic_container_task_specific = (dynamic_container_task_specific_t *)calloc(1, sizeof(dynamic_container_task_specific_t)); + + pDynamic_container_task_specific->calculate_case_func = calculate_case_func; + pDynamic_container_task_specific->case_cnt = case_cnt; + pDynamic_container_task_specific->case_array = (ec_int *)malloc(case_cnt * sizeof(ec_int)); + if (pDynamic_container_task_specific->case_array == NULL) { + goto error_part; + } + memcpy(pDynamic_container_task_specific->case_array, case_array, case_cnt * sizeof(ec_int)); + + pDynamic_container_task_specific->case_specific_child_task_info_array = (child_tasks_info_t **)calloc(case_cnt, sizeof(child_tasks_info_t)); + if (pDynamic_container_task_specific->case_specific_child_task_info_array == NULL) { + goto error_part; + } + + for (i = 0; i < case_cnt; i++) { + pDynamic_container_task_specific->case_specific_child_task_info_array[i] = task_spec_new_child_tasks_info(parent_param_cnt, child_task_cnt_array[i], child_task_array_per_case_array[i]); + if (pDynamic_container_task_specific->case_specific_child_task_info_array[i] == NULL) { + goto error_part; + } + } + + return pDynamic_container_task_specific; + +error_part: + task_spec_free_dynamic_container_task_specific(pDynamic_container_task_specific); + return NULL; +} + +static void task_spec_free_dynamic_container_task_specific(dynamic_container_task_specific_t *pDynamic_container_task_specific) +{ + if (pDynamic_container_task_specific != NULL) { + /* TODO */ + } +} + +child_tasks_info_t *task_spec_find_child_tasks_info(task_spec_t *pParent_container_task_spec) +{ + return pParent_container_task_spec->u.pContainer_task_specific; +} + +child_tasks_info_t *task_spec_find_case_specific_child_tasks_info(task_spec_t *pParent_dynamic_task_spec, ec_int dynamic_case) +{ + child_tasks_info_t *pChild_task_info = NULL; + + dynamic_container_task_specific_t *pDynmaic_container_task_specific = pParent_dynamic_task_spec->u.pDynmaic_container_task_specific; + ec_uint case_cnt = pDynmaic_container_task_specific->case_cnt; + ec_int *case_array = pDynmaic_container_task_specific->case_array; + child_tasks_info_t **case_specific_child_task_info_array = pDynmaic_container_task_specific->case_specific_child_task_info_array; + + ec_uint i = 0; + for (i = 0; i < case_cnt; i++) { + if (case_array[i] == dynamic_case) { + pChild_task_info = case_specific_child_task_info_array[i]; + break; + } + } + + return pChild_task_info; +} + +static param_spec *task_spec_find_param_spec(task_spec_t *pTask_spec, ec_int param_index) +{ + param_spec *pParam_spec = NULL; + ec_int param_cnt = task_spec_get_param_cnt(pTask_spec); + param_spec **param_spec_array = pTask_spec->task_param_spec_array; + + if (param_index >= 0 && param_index < param_cnt) { + pParam_spec = param_spec_array[param_index]; + } + + return pParam_spec; +} + +static engine_controller_error_t task_spec_validate_container_task_spec(task_spec_t *pContainer_task_spec) +{ + engine_controller_error_t err = ENGINE_CONTROLLER_OK; + if (pContainer_task_spec == NULL) { + err = ENGINE_CONTROLLER_INVALID_TASK; + goto error_part; + } + + if (pContainer_task_spec->task_type != TASK_CONTAINER) { + if (pContainer_task_spec->task_type == TASK_SIMPLE || pContainer_task_spec->task_type == TASK_DYNAMIC_CONTAINER) { + err = ENGINE_CONTROLLER_MUST_USE_CONTAINER_TASK; + } else { + err = ENGINE_CONTROLLER_INVALID_TASK; + } + goto error_part; + } + +error_part: + return err; +} + +static engine_controller_error_t task_spec_validate_dynamic_container_task_spec(task_spec_t *pDynamic_container_task_spec) +{ + engine_controller_error_t err = ENGINE_CONTROLLER_OK; + if (pDynamic_container_task_spec == NULL) { + err = ENGINE_CONTROLLER_INVALID_TASK; + goto error_part; + } + + if (pDynamic_container_task_spec->task_type != TASK_DYNAMIC_CONTAINER) { + if (pDynamic_container_task_spec->task_type == TASK_SIMPLE || pDynamic_container_task_spec->task_type == TASK_CONTAINER) { + err = ENGINE_CONTROLLER_MUST_USE_DYNAMIC_CONTAINER_TASK; + } else { + err = ENGINE_CONTROLLER_INVALID_TASK; + } + goto error_part; + } + +error_part: + return err; +} + +/* +engine_controller_error_t task_spec_attach_queuing_rule_spec(task_spec_t* pSpec, queuing_rule_spec_t* pQueuing_rule_spec) +{ + engine_controller_error_t err = ENGINE_CONTROLLER_OK; + GSList* listnode = g_slist_find(pSpec->queuing_rule_spec_list, pQueuing_rule_spec); + if (listnode != NULL) { + err = ENGINE_CONTROLLER_DUPLICATE_QUEUING_RULE_SPEC; + goto error_part; + } + + pSpec->queuing_rule_spec_list = g_slist_prepend(pSpec->queuing_rule_spec_list, queuing_rule_spec_ref(pQueuing_rule_spec)); + + error_part: + return err; +} +*/ + +engine_controller_error_t task_spec_valididate_child_task_index(task_spec_t *pContainer_task_spec, ec_int child_task_index) +{ + engine_controller_error_t err = ENGINE_CONTROLLER_OK; + + task_spec_t *pChild_task_spec = task_spec_get_child_task_spec(pContainer_task_spec, child_task_index); + if (pChild_task_spec == NULL) { + err = ENGINE_CONTROLLER_INVALID_CHILD_TASK_INDEX; + } + + return err; +} + +engine_controller_error_t task_spec_valididate_child_task_index_on_dynamic_case(ec_int dynamic_case, task_spec_t *pDynamic_container_task_spec, ec_int child_task_index) +{ + engine_controller_error_t err = ENGINE_CONTROLLER_OK; + + task_spec_t *pChild_task_spec = task_spec_get_child_task_spec_on_dynamic_case(dynamic_case, + pDynamic_container_task_spec, + child_task_index); + if (pChild_task_spec == NULL) { + err = ENGINE_CONTROLLER_INVALID_CHILD_TASK_INDEX; + } + + return err; +} + +static engine_controller_error_t task_spec_validate_param_index(task_spec_t *pTask_spec, ec_int param_index) +{ + engine_controller_error_t err = ENGINE_CONTROLLER_OK; + + param_spec *pParam_spec = task_spec_find_param_spec(pTask_spec, param_index); + if (pParam_spec == NULL) { + err = ENGINE_CONTROLLER_INVALID_PARAM_INDEX; + } + + return err; +} + +static engine_controller_error_t task_spec_validate_set_control_flow_input_parameters(task_spec_t *pContainer_task_spec, ec_int from_task_index, ec_int to_task_index) +{ + engine_controller_error_t err = ENGINE_CONTROLLER_OK; + + err = task_spec_validate_container_task_spec(pContainer_task_spec); + if (err != ENGINE_CONTROLLER_OK) { + goto error_part; + } + + err = task_spec_valididate_child_task_index(pContainer_task_spec, from_task_index); + if (err != ENGINE_CONTROLLER_OK) { + goto error_part; + } + + err = task_spec_valididate_child_task_index(pContainer_task_spec, to_task_index); + +error_part: + return err; +} + +static engine_controller_error_t task_spec_validate_set_control_flow_input_parameters_on_dynamic_case(ec_int dynamic_case, task_spec_t *pDynamic_container_task_spec, ec_int from_task_index, ec_int to_task_index) +{ + engine_controller_error_t err = ENGINE_CONTROLLER_OK; + + err = task_spec_validate_dynamic_container_task_spec(pDynamic_container_task_spec); + if (err != ENGINE_CONTROLLER_OK) { + goto error_part; + } + + err = task_spec_valididate_child_task_index_on_dynamic_case(dynamic_case, pDynamic_container_task_spec, from_task_index); + if (err != ENGINE_CONTROLLER_OK) { + goto error_part; + } + + err = task_spec_valididate_child_task_index_on_dynamic_case(dynamic_case, pDynamic_container_task_spec, to_task_index); + +error_part: + return err; +} + +static engine_controller_error_t task_spec_validate_set_data_flow_input_parameters(task_spec_t *pContainer_task_spec, ec_int from_task_index, ec_int from_param_index, ec_int to_task_index, ec_int to_param_index) +{ + engine_controller_error_t err = ENGINE_CONTROLLER_OK; + + err = task_spec_validate_container_task_spec(pContainer_task_spec); + if (err != ENGINE_CONTROLLER_OK) { + goto error_part; + } + + task_spec_t *pFrom_task_spec = NULL; + task_spec_t *pTo_task_spec = NULL; + if (from_task_index != -1) { + err = task_spec_valididate_child_task_index(pContainer_task_spec, from_task_index); + if (err != ENGINE_CONTROLLER_OK) { + goto error_part; + } + + pFrom_task_spec = task_spec_get_child_task_spec(pContainer_task_spec, from_task_index); + } else { + pFrom_task_spec = pContainer_task_spec; + } + err = task_spec_validate_param_index(pFrom_task_spec, from_param_index); + if (err != ENGINE_CONTROLLER_OK) { + goto error_part; + } + + if (to_task_index != -1) { + err = task_spec_valididate_child_task_index(pContainer_task_spec, to_task_index); + if (err != ENGINE_CONTROLLER_OK) { + goto error_part; + } + + pTo_task_spec = task_spec_get_child_task_spec(pContainer_task_spec, to_task_index); + } else { + pTo_task_spec = pContainer_task_spec; + } + err = task_spec_validate_param_index(pTo_task_spec, to_param_index); + +error_part: + return err; +} + +static engine_controller_error_t task_spec_validate_set_data_flow_input_parameters_on_dynamic_case(ec_int dynamic_case, task_spec_t *pDynamic_container_task_spec, ec_int from_task_index, ec_int from_param_index, ec_int to_task_index, ec_int to_param_index) +{ + engine_controller_error_t err = ENGINE_CONTROLLER_OK; + + err = task_spec_validate_dynamic_container_task_spec(pDynamic_container_task_spec); + if (err != ENGINE_CONTROLLER_OK) { + goto error_part; + } + + task_spec_t *pFrom_task_spec = NULL; + task_spec_t *pTo_task_spec = NULL; + if (from_task_index != -1) { + err = task_spec_valididate_child_task_index_on_dynamic_case(dynamic_case, pDynamic_container_task_spec, from_task_index); + if (err != ENGINE_CONTROLLER_OK) { + goto error_part; + } + + pFrom_task_spec = task_spec_get_child_task_spec_on_dynamic_case(dynamic_case, pDynamic_container_task_spec, from_task_index); + } else { + pFrom_task_spec = pDynamic_container_task_spec; + } + err = task_spec_validate_param_index(pFrom_task_spec, from_param_index); + if (err != ENGINE_CONTROLLER_OK) { + goto error_part; + } + + if (to_task_index != -1) { + err = task_spec_valididate_child_task_index_on_dynamic_case(dynamic_case, pDynamic_container_task_spec, to_task_index); + if (err != ENGINE_CONTROLLER_OK) { + goto error_part; + } + + pTo_task_spec = task_spec_get_child_task_spec_on_dynamic_case(dynamic_case, pDynamic_container_task_spec, to_task_index); + } else { + pTo_task_spec = pDynamic_container_task_spec; + } + err = task_spec_validate_param_index(pTo_task_spec, to_param_index); + +error_part: + return err; +} + +task_spec_t *task_spec_alloc_simple_task_spec(ec_char *task_name, TASK_PROCESS task_process, ec_pointer post_task_func_usr_data, post_task_callback_func post_task_callback, ec_uint param_cnt, param_spec **param_spec_array) +{ + task_spec_t *pTask = NULL; + + pTask = task_spec_new_default_task_spec(task_name, post_task_func_usr_data, post_task_callback, param_cnt, param_spec_array); + + if (pTask == NULL) { + return NULL; + } + pTask->task_type = TASK_SIMPLE; + pTask->u.task_process = task_process; + + return pTask; +} + +task_spec_t *task_spec_ref(task_spec_t *pTask_spec) +{ + if (pTask_spec == NULL) { + return NULL; + } + + g_atomic_int_inc(&(pTask_spec->ref_count)); + + return pTask_spec; +} + +void task_spec_unref(task_spec_t *pTask_spec) +{ + if (pTask_spec == NULL) { + return; + } + + if (g_atomic_int_dec_and_test(&(pTask_spec->ref_count))) { + task_spec_free_task_spec(pTask_spec); + } +} + +ec_boolean task_spec_is_same(task_spec_t *pTask_spec1, task_spec_t *pTask_spec2) +{ + if (pTask_spec1 == pTask_spec2) { + return true; + } + return false; +} + +ec_boolean task_spec_is_simple_task_spec(task_spec_t *pTask_spec) +{ + if (pTask_spec == NULL) { + FW_LOGW("pTask_spec == NULL\n"); + return false; + } + + if (pTask_spec->task_type == TASK_SIMPLE) { + return true; + } else { + return false; + } +} + +ec_boolean task_spec_is_container_task_spec(task_spec_t *pTask_spec) +{ + if (pTask_spec == NULL) { + FW_LOGW("pTask_spec == NULL\n"); + return false; + } + + if (pTask_spec->task_type == TASK_CONTAINER) { + return true; + } else { + return false; + } +} + +ec_boolean task_spec_is_dynamic_container_task_spec(task_spec_t *pTask_spec) +{ + if (pTask_spec == NULL) { + FW_LOGW("pTask_spec == NULL\n"); + return false; + } + + if (pTask_spec->task_type == TASK_DYNAMIC_CONTAINER) { + return true; + } else { + return false; + } +} + +ec_uint task_spec_get_child_task_cnt(task_spec_t *pTask_spec) +{ + if (task_spec_is_container_task_spec(pTask_spec)) { + return pTask_spec->u.pContainer_task_specific->child_task_cnt; + } else { + return 0; + } +} + +task_spec_t *task_spec_get_child_task_spec(task_spec_t *pParent_task_spec, ec_int child_task_index) +{ + task_spec_t *pChild_task_spec = NULL; + + child_tasks_info_t *pChild_task_info = task_spec_find_child_tasks_info(pParent_task_spec); + pChild_task_spec = task_spec_get_child_task_spec_from_child_task_info(pChild_task_info, child_task_index); + + return pChild_task_spec; +} + +ec_uint task_spec_get_child_task_cnt_on_dynamic_case(task_spec_t *pDynamic_task_spec, ec_int dynamic_case) +{ + if (task_spec_is_dynamic_container_task_spec(pDynamic_task_spec)) { + child_tasks_info_t *pChild_task_info = task_spec_find_case_specific_child_tasks_info(pDynamic_task_spec, dynamic_case); + if (pChild_task_info != NULL) { + return pChild_task_info->child_task_cnt; + } else { + return 0; + } + } else { + return 0; + } +} + +task_spec_t *task_spec_get_child_task_spec_on_dynamic_case(ec_int dynamic_case, task_spec_t *pParent_dynamic_task_spec, ec_int child_task_index) +{ + task_spec_t *pChild_task_spec = NULL; + + engine_controller_error_t ec_error = task_spec_validate_dynamic_container_task_spec(pParent_dynamic_task_spec); + if (ec_error != ENGINE_CONTROLLER_OK) { + goto error_part; + } + + child_tasks_info_t *pChild_task_info = task_spec_find_case_specific_child_tasks_info(pParent_dynamic_task_spec, dynamic_case); + pChild_task_spec = task_spec_get_child_task_spec_from_child_task_info(pChild_task_info, child_task_index); + + return pChild_task_spec; + +error_part: + return NULL; +} + +ec_int task_spec_get_param_cnt(task_spec_t *pTask_spec) +{ + return pTask_spec->task_param_cnt; +} + +calculate_case_callback_func task_spec_get_calculate_case_callback_func(task_spec_t *pDynamic_container_task_spec) +{ + return pDynamic_container_task_spec->u.pDynmaic_container_task_specific->calculate_case_func; +} + +ec_boolean task_spec_get_output_param_info(task_spec_t *pTask_spec, ec_int *pOutput_param_cnt, ec_int **pOutput_param_index_array) +{ + if (pTask_spec == NULL || pOutput_param_cnt == NULL || pOutput_param_index_array == NULL) { + goto error_part; + } + + ec_int i = 0; + ec_int param_cnt = task_spec_get_param_cnt(pTask_spec); + param_spec **task_param_spec_array = pTask_spec->task_param_spec_array; + + ec_int output_param_cnt = 0; + ec_int *output_param_index_array = NULL; + output_param_index_array = (ec_int *)calloc(param_cnt, sizeof(ec_int)); + if (output_param_index_array == NULL) { + goto error_part; + } + + param_spec *pParam_spec = NULL; + for (i = 0; i < param_cnt; i++) { + pParam_spec = task_param_spec_array[i]; + if (is_output_flag_on(pParam_spec->flags)) { + output_param_index_array[output_param_cnt] = i; + output_param_cnt++; + } + } + + *pOutput_param_cnt = output_param_cnt; + *pOutput_param_index_array = output_param_index_array; + + return true; + +error_part: + + return false; +} + +task_spec_t *task_spec_alloc_container_task_spec_outline(ec_char *task_name, ec_pointer usr_post_task_func_data, post_task_callback_func post_func, ec_uint param_cnt, param_spec **param_spec_array, ec_uint child_task_cnt, task_spec_t **child_task_array) +{ + task_spec_t *pTask_spec = NULL; + + pTask_spec = task_spec_new_default_task_spec(task_name, usr_post_task_func_data, post_func, param_cnt, param_spec_array); + + if (pTask_spec == NULL) { + return NULL; + } + pTask_spec->task_type = TASK_CONTAINER; + pTask_spec->u.pContainer_task_specific = task_spec_new_child_tasks_info(param_cnt, child_task_cnt, child_task_array); + + if (pTask_spec->u.pContainer_task_specific == NULL) { + goto error_part; + } + + return pTask_spec; + +error_part: + task_spec_free_task_spec(pTask_spec); + return NULL; +} + +engine_controller_error_t task_spec_set_data_flow(task_spec_t *pContainer_task_spec, ec_int from_task_index, ec_int from_param_index, ec_int to_task_index, ec_int to_param_index) +{ + engine_controller_error_t err = ENGINE_CONTROLLER_OK; + + /* validation */ + err = task_spec_validate_set_data_flow_input_parameters(pContainer_task_spec, from_task_index, from_param_index, to_task_index, to_param_index); + if (err != ENGINE_CONTROLLER_OK) { + goto error_part; + } + + if (from_task_index != -1 && to_task_index != -1) { + /* add control flow */ + err = task_spec_set_control_flow(pContainer_task_spec, from_task_index, to_task_index); + if (err != ENGINE_CONTROLLER_OK) { + goto error_part; + } + } + + /* add data flow */ + child_tasks_info_t *pChild_task_info = task_spec_find_child_tasks_info(pContainer_task_spec); + data_flow_edges_t *pData_flow_edges = pChild_task_info->pData_flow_edges; + if (!data_flow_edges_add_edge(pData_flow_edges, from_task_index, from_param_index, to_task_index, to_param_index)) { + err = ENGINE_CONTROLLER_DUPLICATE_DATA_FLOW_EDGE; + } + +error_part: + return err; +} + +engine_controller_error_t task_spec_set_data_flow_on_dynamic_case(ec_int dynamic_case, task_spec_t *pDynamic_container_task_spec, ec_int from_task_index, ec_int from_param_index, ec_int to_task_index, ec_int to_param_index) +{ + engine_controller_error_t err = ENGINE_CONTROLLER_OK; + + /* validation */ + err = task_spec_validate_set_data_flow_input_parameters_on_dynamic_case(dynamic_case, pDynamic_container_task_spec, from_task_index, from_param_index, to_task_index, to_param_index); + if (err != ENGINE_CONTROLLER_OK) { + goto error_part; + } + + if (from_task_index != -1 && to_task_index != -1) { + /* add control flow */ + err = task_spec_set_control_flow_on_dynamic_case(dynamic_case, pDynamic_container_task_spec, from_task_index, to_task_index); + if (err != ENGINE_CONTROLLER_OK) { + goto error_part; + } + } + + /* add data flow */ + data_flow_edges_t *pData_flow_edges; + child_tasks_info_t *pChild_task_info = task_spec_find_case_specific_child_tasks_info(pDynamic_container_task_spec, dynamic_case); + if (pChild_task_info != NULL) { + pData_flow_edges = pChild_task_info->pData_flow_edges; + } else { + err = ENGINE_CONTROLLER_INVALID_TASK; + goto error_part; + } + if (!data_flow_edges_add_edge(pData_flow_edges, from_task_index, from_param_index, to_task_index, to_param_index)) { + err = ENGINE_CONTROLLER_DUPLICATE_DATA_FLOW_EDGE; + } + +error_part: + return err; +} + +engine_controller_error_t task_spec_set_control_flow(task_spec_t *pContainer_task_spec, ec_int from_task_index, ec_int to_task_index) +{ + engine_controller_error_t err = ENGINE_CONTROLLER_OK; + + err = task_spec_validate_set_control_flow_input_parameters(pContainer_task_spec, from_task_index, to_task_index); + if (err != ENGINE_CONTROLLER_OK) { + goto error_part; + } + + child_tasks_info_t *pChild_task_info = task_spec_find_child_tasks_info(pContainer_task_spec); + graph_edge_pool_t *pControl_edge_pool = pChild_task_info->pControl_edge_pool; + ec_uint *control_flow_in_degree_array = pChild_task_info->child_task_control_flow_in_degree; + + /* add edge and in_degree count */ + if (graph_edge_pool_add_edge(pControl_edge_pool, (ec_constpointer) from_task_index, (ec_constpointer) to_task_index)) { + control_flow_in_degree_array[to_task_index]++; + } + +error_part: + return err; +} + +engine_controller_error_t task_spec_set_control_flow_on_dynamic_case(ec_int dynamic_case, task_spec_t *pDynamic_container_task_spec, ec_int from_task_index, ec_int to_task_index) +{ + engine_controller_error_t err = ENGINE_CONTROLLER_OK; + + err = task_spec_validate_set_control_flow_input_parameters_on_dynamic_case(dynamic_case, pDynamic_container_task_spec, from_task_index, to_task_index); + if (err != ENGINE_CONTROLLER_OK) { + goto error_part; + } + + graph_edge_pool_t *pControl_edge_pool; + child_tasks_info_t *pChild_task_info = task_spec_find_case_specific_child_tasks_info(pDynamic_container_task_spec, dynamic_case); + if (pChild_task_info != NULL) { + pControl_edge_pool = pChild_task_info->pControl_edge_pool; + } else { + err = ENGINE_CONTROLLER_INVALID_TASK; + goto error_part; + } + ec_uint *control_flow_in_degree_array = pChild_task_info->child_task_control_flow_in_degree; + + /* add edge and in_degree count */ + if (graph_edge_pool_add_edge(pControl_edge_pool, (ec_constpointer) from_task_index, (ec_constpointer) to_task_index)) { + control_flow_in_degree_array[to_task_index]++; + } + +error_part: + return err; +} + +task_spec_t *task_spec_alloc_dynamic_container_task_spec_outline(ec_char *task_name, ec_pointer usr_post_task_func_data, post_task_callback_func post_func, ec_uint param_cnt, param_spec **param_spec_array, calculate_case_callback_func calculate_case_func, ec_uint case_cnt, ec_int *case_array, ec_uint *child_task_cnt_array, task_spec_t ***child_task_array_per_case_array) +{ + task_spec_t *pTask_spec = NULL; + + pTask_spec = task_spec_new_default_task_spec(task_name, usr_post_task_func_data, post_func, param_cnt, param_spec_array); + + if (pTask_spec == NULL) { + return NULL; + } + pTask_spec->task_type = TASK_DYNAMIC_CONTAINER; + pTask_spec->u.pDynmaic_container_task_specific = task_spec_new_dynamic_container_task_specific(param_cnt, calculate_case_func, case_cnt, case_array, child_task_cnt_array, child_task_array_per_case_array); + + if (pTask_spec->u.pDynmaic_container_task_specific == NULL) { + goto error_part; + } + + return pTask_spec; + +error_part: + task_spec_free_task_spec(pTask_spec); + return NULL; +} diff --git a/framework/src/EngineController/thread_pool.c b/framework/src/EngineController/thread_pool.c new file mode 100755 index 0000000..1e54fba --- /dev/null +++ b/framework/src/EngineController/thread_pool.c @@ -0,0 +1,169 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Wook Choi + */ + +#include +#include +#include +#include "Utility/fw_log.h" +#include "EngineController/param_spec.h" +#include "EngineController/param_spec_internal.h" +#include "EngineController/thread_pool.h" +#include "EngineController/task_spec_internal.h" +#include "EngineController/engine_controller_message.h" +#include "EngineController/task_message.h" +#include "EngineController/engine_controller_internal.h" + +#define LOG_TAG "AF_EC" + +void thread_pool_run_operation(task_t *pTask, gpointer user_data) +{ + FW_LOGD("started\n"); + + task_error_t err = TASK_ERROR_RUN_SUCCESS; + task_message_t *pTask_msg = NULL; + GPrivate *cancel_tsk = (GPrivate *) user_data; + + if (pTask != NULL) { + task_spec_t *pTask_spec = pTask->pTask_spec; + FW_LOGD("run task\n"); + + /* set thread specific value related to cancellation */ + g_private_set(cancel_tsk, task_cancel_info_ref(pTask->pCancel_Information)); + + /* run task */ + if (pTask_spec->task_type == TASK_SIMPLE) { + err = task_run_simple_task(pTask); + } else if (pTask_spec->task_type == TASK_CONTAINER) { + err = TASK_ERROR_INVALID_TASK; + FW_LOGE("container task! only simple task can be put in thread pool\n"); + } else { + err = TASK_ERROR_INVALID_TASK; + FW_LOGE("invalid task type. task type must be either simple or container\n"); + } + + /* set thread specific value related to cancellation */ + /* Note that this part must be done before send_msg_to_engine_controller_with_compare_priority */ + /* othrewise, we can lost pTask->pCancel_Information because of threading race between engine controller & thread inside thread pool */ + task_cancel_info_unref(pTask->pCancel_Information); + + /* send task result report to engine controller */ + pTask_msg = task_message_create(TASK_DONE, pTask, 0); + send_msg_to_engine_controller_with_compare_priority(pTask_msg, compare_priority_of_task_message_append_way, NULL); + + g_private_set(cancel_tsk, NULL); + } + FW_LOGD("ended\n"); +} + +/* TODO : change void to GDestroyNotify */ +GPrivate *thread_pool_create_cancel_TSK(void) +{ + return g_private_new(NULL); +} + +GPrivate *thread_pool_get_cancel_TSK(thread_pool_t *pThread_pool) +{ + if (pThread_pool == NULL) { + return NULL; + } + + return pThread_pool->cancel_tsk; +} + +ec_uint thread_pool_get_max_thread_count(thread_pool_t *pThread_pool) +{ + if (pThread_pool == NULL) { + return 0; + } + + return pThread_pool->max_thread_count; +} + +thread_pool_t *thread_pool_alloc_and_init(ec_uint max_thread_count) +{ + if (!g_thread_supported()) { + g_thread_init(NULL); + } + + thread_pool_t *pPool = (thread_pool_t *)calloc(1, sizeof(thread_pool_t)); + if (pPool == NULL) { + goto error_part; + } + + pPool->cancel_tsk = thread_pool_create_cancel_TSK(); + if (pPool->cancel_tsk == NULL) { + goto error_part; + } + + pPool->max_thread_count = max_thread_count; + + pPool->pPool = g_thread_pool_new((GFunc) thread_pool_run_operation, pPool->cancel_tsk, max_thread_count, TRUE, NULL); + if (pPool->pPool == NULL) { + goto error_part; + } + + return pPool; + +error_part: + thread_pool_destroy(pPool); + return NULL; +} + +void thread_pool_destroy(thread_pool_t *pPool) +{ + if (pPool != NULL) { + if (pPool->pPool != NULL) { + g_thread_pool_free(pPool->pPool, TRUE, TRUE); + } + if (pPool->cancel_tsk != NULL) { + /* TODO : i don't know what to do. May be free need to do */ + } + + free(pPool); + } +} + +void thread_pool_push_task(thread_pool_t *pPool, task_t *pTask) +{ + if (pPool != NULL && pPool->pPool != NULL && pTask != NULL) { + g_thread_pool_push(pPool->pPool, pTask, NULL); + } else { + if (pPool == NULL || pPool->pPool == NULL) { + FW_LOGW("invalid thread pool structure. we do nothing in this case\n"); + } else { + FW_LOGW("valid thread pool structure, but invalid task. we do nothing in this case\n"); + } + } +} diff --git a/framework/src/Event/Event_Config.c b/framework/src/Event/Event_Config.c new file mode 100755 index 0000000..e99e76a --- /dev/null +++ b/framework/src/Event/Event_Config.c @@ -0,0 +1,351 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu , + */ + +#include +#include +#include + +#include "Utility/fw_log.h" +#include "Event/Event_Config.h" + +#define LOG_TAG "AF_EVENT" + +static int current_event_count = 0; +static Event_Spec *event_Spec_list[MAX_EVENT_COUNT] = { 0 }; + +static int current_noti_bag_count = 0; +Noti_Spec_Bag *noti_Spec_Bag_list[MAX_NOTI_COUNT] = { 0 }; + +static char *__communication_path_event = 0; +static char *__communication_path_reply_event = 0; + +static int __find_NotiSpecBag(const char *noti_key); + +static int __find_EventSpec(int eventNum); +static int __find_NotiSpec(int noti_Spec_Bag_num, int notiNum); + +const char *get_Noti_Path(const char *noti_key) +{ + if (noti_key == 0) { + if (noti_Spec_Bag_list[0] != 0) { + return noti_Spec_Bag_list[0]->communication_path_noti; + } else { + return 0; + } + } + + int index = __find_NotiSpecBag(noti_key); + + return noti_Spec_Bag_list[index]->communication_path_noti; +} + +const char *get_Noti_Reply_Path(const char *noti_key) +{ + if (noti_key == 0) { + if (noti_Spec_Bag_list[0] != 0) { + return noti_Spec_Bag_list[0]->communication_path_reply_noti; + } else { + return 0; + } + } + + int index = __find_NotiSpecBag(noti_key); + + return noti_Spec_Bag_list[index]->communication_path_reply_noti; +} + +const char *get_Event_Path() +{ + return __communication_path_event; +} + +const char *get_Event_Reply_Path() +{ + return __communication_path_reply_event; +} + +EVENT_ERROR set_EventSpec_from_ConfigFile(const char *event_key, const char *configfile) +{ + FILE *fp = fopen(configfile, "r"); + if (fp == 0) { + FW_LOGE("file open failed [%s]\n", configfile); + return EVENT_FAIL; + } + + while (!feof(fp)) { + Event_Spec *event_spec = (Event_Spec *) malloc(sizeof(Event_Spec)); + + char description[1000]; + fscanf(fp, "%d, %d, %d, %d, %999s\n", &(event_spec->eventNum), (int *)(&(event_spec->event_type)), &(event_spec->relational_notiNum), &(event_spec->pendingtime), (char *)(&description)); + + event_Spec_list[current_event_count] = event_spec; + current_event_count++; + } + + fclose(fp); + + if (__communication_path_event == 0) { + __communication_path_event = (char *)calloc(strlen(EVENT_COMMUNICATION_PATH) + strlen(event_key) + 1, sizeof(char)); + strcat(__communication_path_event, EVENT_COMMUNICATION_PATH); + strcat(__communication_path_event, event_key); + FW_LOGV("EVENT_COMMUNICATION_PATH : %s", __communication_path_event); + } + + if (__communication_path_reply_event == 0) { + __communication_path_reply_event = (char *)calloc(strlen(EVENT_REPLY_COMMUNICATION_PATH) + strlen(event_key) + 1, sizeof(char)); + strcat(__communication_path_reply_event, EVENT_REPLY_COMMUNICATION_PATH); + strcat(__communication_path_reply_event, event_key); + FW_LOGV("EVENT_REPLY_COMMUNICATION_PATH : %s", __communication_path_reply_event); + } + + return EVENT_SUCCESS; +} + +EVENT_ERROR clean_EventSpec() +{ + int i = 0; + for (; i < current_event_count; i++) { + Event_Spec *event_spec = event_Spec_list[i]; + if (event_spec != 0) { + free(event_spec); + } + } + + return EVENT_SUCCESS; +} + +EVENT_ERROR set_NotiSpec_from_ConfigFile(const char *noti_key, const char *configfile) +{ + if (noti_key == 0 || configfile == 0) { + return EVENT_FAIL; + } + + FILE *fp = fopen(configfile, "r"); + if (fp == 0) { + FW_LOGE("file open failed [%s]\n", configfile); + return EVENT_FAIL; + } + + /* + * Create Noti Spec Bag + */ + Noti_Spec_Bag *noti_spec_bag = (Noti_Spec_Bag *) calloc(1, sizeof(Noti_Spec_Bag)); + noti_spec_bag->noti_count = 0; + + /* + * Setting noti_Spec_list + */ + while (!feof(fp)) { + Noti_Spec *noti_spec = (Noti_Spec *)calloc(1, sizeof(Noti_Spec)); + + char description[1000]; + fscanf(fp, "%d, %d, %d, %d, %999s\n", &(noti_spec->notiNum), (int *)(&(noti_spec->noti_type)), &(noti_spec->relational_eventNum), &(noti_spec->pendingtime), (char *)(&description)); + + noti_spec_bag->noti_Spec_list[noti_spec_bag->noti_count] = noti_spec; + noti_spec_bag->noti_count++; + } + fclose(fp); + + /* + * Setting noti_key + */ + noti_spec_bag->noti_key = strdup(noti_key); + + /* + * Setting communication_path_noti + */ + if (noti_spec_bag->communication_path_noti == 0) { + noti_spec_bag->communication_path_noti = (char *)calloc(strlen(NOTI_COMMUNICATION_PATH) + strlen(noti_key) + 1, sizeof(char)); + strcat(noti_spec_bag->communication_path_noti, NOTI_COMMUNICATION_PATH); + strcat(noti_spec_bag->communication_path_noti, noti_key); + FW_LOGV("NOTI_COMMUNICATION_PATH : %s", noti_spec_bag->communication_path_noti); + } + + /* + * Setting communication_path_reply_noti + */ + if (noti_spec_bag->communication_path_reply_noti == 0) { + noti_spec_bag->communication_path_reply_noti = (char *)calloc(strlen(NOTI_REPLY_COMMUNICATION_PATH) + strlen(noti_key) + 1, sizeof(char)); + strcat(noti_spec_bag->communication_path_reply_noti, NOTI_REPLY_COMMUNICATION_PATH); + strcat(noti_spec_bag->communication_path_reply_noti, noti_key); + FW_LOGV("NOTI_REPLY_COMMUNICATION_PATH : %s", noti_spec_bag->communication_path_reply_noti); + } + + noti_Spec_Bag_list[current_noti_bag_count] = noti_spec_bag; + current_noti_bag_count++; + + return EVENT_SUCCESS; +} + +EVENT_ERROR clean_NotiSpec() +{ + int i = 0; + for (; i < current_noti_bag_count; i++) { + Noti_Spec_Bag *noti_Spec_Bag = noti_Spec_Bag_list[i]; + if (noti_Spec_Bag != 0) { + free(noti_Spec_Bag->noti_key); + free(noti_Spec_Bag->communication_path_noti); + free(noti_Spec_Bag->communication_path_reply_noti); + + int k = 0; + for (; k < noti_Spec_Bag->noti_count; k++) { + Noti_Spec *noti_spec = noti_Spec_Bag->noti_Spec_list[k]; + if (noti_spec != 0) { + free(noti_spec); + } + } + } + } + + return EVENT_SUCCESS; +} + +EVENT_ERROR register_EventCallback(int eventNum, EVENT_CALLBACK callback) +{ + int index = __find_EventSpec(eventNum); + if (index == -1) { + return EVENT_FAIL; + } + + event_Spec_list[index]->callback = callback; + + return EVENT_SUCCESS; +} + +EVENT_ERROR register_NotiCallback(int notiNum, NOTI_CALLBACK callback, void *data) +{ + int index = __find_NotiSpec(0, notiNum); + if (index == -1) { + return EVENT_FAIL; + } + + noti_Spec_Bag_list[0]->noti_Spec_list[index]->callback = callback; + noti_Spec_Bag_list[0]->noti_Spec_list[index]->additional_param = data; + + return EVENT_SUCCESS; +} + +EVENT_CALLBACK get_EventCallback(int eventNum) +{ + int index = __find_EventSpec(eventNum); + if (index == -1) { + return 0; + } + + return event_Spec_list[index]->callback; +} + +NOTI_CALLBACK get_NotiCallback(int notiNum) +{ + int index = __find_NotiSpec(0, notiNum); + if (index == -1) { + return 0; + } + + return noti_Spec_Bag_list[0]->noti_Spec_list[index]->callback; +} + +void *get_NotiCallback_AdditinalParam(int notiNum) +{ + int index = __find_NotiSpec(0, notiNum); + if (index == -1) { + return 0; + } + + return noti_Spec_Bag_list[0]->noti_Spec_list[index]->additional_param; +} + +EVENT_TYPE get_EventType(int eventNum) +{ + int index = __find_EventSpec(eventNum); + if (index == -1) { + return 0; + } + + return event_Spec_list[index]->event_type; +} + +NOTI_TYPE get_NotiType(const char *noti_key, int notiNum) +{ + int noti_Spec_Bag_num = __find_NotiSpecBag(noti_key); + + int noti_index = __find_NotiSpec(noti_Spec_Bag_num, notiNum); + if (noti_index == -1) { + return 0; + } + + return noti_Spec_Bag_list[noti_Spec_Bag_num]->noti_Spec_list[noti_index]->noti_type; +} + +static int __find_NotiSpecBag(const char *noti_key) +{ + int i = 0; + for (; i < current_noti_bag_count; i++) { + Noti_Spec_Bag *noti_Spec_Bag = noti_Spec_Bag_list[i]; + if (noti_Spec_Bag != 0) { + if (!strcmp(noti_Spec_Bag->noti_key, noti_key)) { + return i; + } + } + } + + return 0; +} + +static int __find_EventSpec(int eventNum) +{ + int i = 0; + for (; i < current_event_count; i++) { + if (event_Spec_list[i]->eventNum == eventNum) { + return i; + } + } + + return -1; +} + +static int __find_NotiSpec(int noti_Spec_Bag_num, int notiNum) +{ + Noti_Spec_Bag *noti_Spec_Bag = noti_Spec_Bag_list[noti_Spec_Bag_num]; + + int i = 0; + for (; i < noti_Spec_Bag->noti_count; i++) { + if ((noti_Spec_Bag->noti_Spec_list[i])->notiNum == notiNum) { + return i; + } + } + + return -1; +} diff --git a/framework/src/Event/Event_Data_Accessor.c b/framework/src/Event/Event_Data_Accessor.c new file mode 100755 index 0000000..9b8ec62 --- /dev/null +++ b/framework/src/Event/Event_Data_Accessor.c @@ -0,0 +1,181 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu , + */ + +#include +#include + +#include "Utility/fw_log.h" + +#include "Event/Event_Util.h" +#include "Event/Event_Data_Accessor.h" + +#define LOG_TAG "AF_EVENT" + +static char *__ipc_print_message_size(char *msg_stream); +static char *__ipc_print_message_type_and_body(char *msg_sub_stream); + +void append_eventdata_param(Event_Data *iter, param_type type, void *data) +{ + /* increase argument cnt */ + (iter->size[0])++; + + /* append type */ + if (type == INTEGER) { + strcat(iter->data, "I"); + } else if (type == STRING) { + strcat(iter->data, "S"); + } + iter->data += 1; + + /* append size and data */ + if (type == INTEGER) { + /* append data */ + memcpy(iter->data, data, sizeof(int)); + iter->data += sizeof(int); + } else if (type == STRING) { + if (data == 0) { + /* append size */ + int size = 0; + memcpy(iter->data, &size, sizeof(int)); + iter->data += sizeof(int); + } else { + /* append size */ + int size = strlen(data) + 1; + memcpy(iter->data, &size, sizeof(int)); + iter->data += sizeof(int); + + /* append data */ + strcat(iter->data, data); + iter->data += size; + } + } +} + +void get_eventdata_param(Event_Data *iter, void *data) +{ + /* get type */ + param_type type = *(iter->data++); + + if (type == INTEGER) { + /* get data */ + memcpy(data, iter->data, sizeof(int)); + iter->data += sizeof(int); + } else if (type == STRING) { + int size; + /* get size */ + memcpy(&size, iter->data, sizeof(int)); + iter->data += sizeof(int); + + if (size > 0) { + /* get data */ + char *return_char = (char *)malloc(size * sizeof(char)); + if (!return_char) { + FW_LOGE("Memory malloc FAILED. [return_char]"); + } else { + memcpy(return_char, iter->data, size * sizeof(char)); + } + iter->data += (sizeof(char) * size); + + *(char **)data = return_char; + } else { + *(char **)data = 0; + } + } + + /* setting for next */ + *(iter->size) -= 1; +} + +void print_eventdata(char *msg_stream) +{ + char *ptr = msg_stream; + /* print size */ + ptr = __ipc_print_message_size(ptr); + + /* print type and body */ + while (*ptr != '\0') { + ptr = __ipc_print_message_type_and_body(ptr); + } +} + +void free_eventdata(Event_Data *event) +{ + if (event != 0) { + if (event->size != 0) { + free(event->size); + } + + free(event); + } +} + +/* return pointer after message size */ +char *__ipc_print_message_size(char *msg_stream) +{ + char *ptr = msg_stream; + + /* print size */ + int size = (int)*((char *)ptr); + FW_LOGV("message size : %d", size); + ptr += sizeof(char); + + return ptr; +} + +char *__ipc_print_message_type_and_body(char + *msg_sub_stream) +{ + /* check type */ + char *ptr = msg_sub_stream; + + if ((*ptr) == INTEGER) { + FW_LOGV("type : INTEGER"); + ptr++; + FW_LOGV("value : %d", *(int *)ptr); + ptr += sizeof(int); + } else if ((*ptr) == STRING) { + FW_LOGV("type : STRING"); + ptr++; + int size = *(int *)ptr; + FW_LOGV("size : %d", size); + ptr += sizeof(int); + FW_LOGV("content : %s", ptr); + ptr += size; + } else { + FW_LOGE("assertion failed in ipc_print_type_and_body"); + } + + return ptr; +} diff --git a/framework/src/Event/Event_Handler.c b/framework/src/Event/Event_Handler.c new file mode 100755 index 0000000..bcb50ed --- /dev/null +++ b/framework/src/Event/Event_Handler.c @@ -0,0 +1,403 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu , + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "Utility/fw_log.h" +#include "DataAdapter/DACI_Agent_Handler_Manager.h" + +#include "Event/Event_Util.h" +#include "Event/Event_Data_Accessor.h" +#include "Event/Event_Config.h" +#include "Event/Event_Handler.h" + +#define LOG_TAG "AF_EVENT" + +static int _event_server_socket_id = 0; + +static pthread_t Event_Handler_thread_id; + +static void *__event_listener(void *arg); + +static Event_Data *__response_listener(int send_sockfd, Event_Data *noti, CONFIRM_IPC_CANCEL confirm_cancel, void *user_data, EVENT_ERROR *error); + +static void __dispatch_event(int eventNum, Event_Data *request, Event_Data *response); + +static int __getSocketConnector(const char *sock_file); + +EVENT_ERROR run_Event_Handler(unsigned long int *thread_id) +{ + FW_LOGI("run_Event_Handler() start\n"); + + pthread_create(&Event_Handler_thread_id, 0, __event_listener, 0); + + *thread_id = Event_Handler_thread_id; + + return EVENT_SUCCESS; +} + +EVENT_ERROR clean_Event_Handler() +{ + EVENT_ERROR event_err = clean_EventSpec(); + if (event_err != EVENT_SUCCESS) { + FW_LOGE("Fail clean_EventSpec : %d", event_err); + } + event_err = clean_NotiSpec(); + if (event_err != EVENT_SUCCESS) { + FW_LOGE("Fail clean_NotiSpec : %d", event_err); + } + + if (_event_server_socket_id != 0) { + close(_event_server_socket_id); + _event_server_socket_id = 0; + } + + pthread_cancel(Event_Handler_thread_id); + + return EVENT_SUCCESS; +} + +EVENT_ERROR set_EventCallback(int eventNum, EVENT_CALLBACK callback) +{ + return register_EventCallback(eventNum, callback); +} + +Event_Data *create_Noti(int notiNum) +{ + Event_Data *noti = (Event_Data *)malloc(sizeof(Event_Data)); + if (!noti) { + FW_LOGE("Memory malloc FAILED. [noti]"); + return noti; + } else { + noti->eventNum = notiNum; + } + + char *serialized_data = (char *)calloc(MAX_STREAM_SIZE, sizeof(char)); + noti->size = serialized_data; + noti->data = serialized_data + 1; + + append_eventdata_param(noti, INTEGER, ¬iNum); + + return noti; +} + +Event_Data *send_Noti(const char *noti_key, Event_Data *noti, CONFIRM_IPC_CANCEL confirm_cancel, void *user_data, EVENT_ERROR *error) +{ + *error = EVENT_SUCCESS; + const char *communication_path = 0; + + NOTI_TYPE noti_type = get_NotiType(noti_key, noti->eventNum); + + switch (noti_type) { + case NOTI_TYPE_SIMPLE: + case NOTI_TYPE_NEED_REPLY: + communication_path = get_Noti_Path(noti_key); + break; + case NOTI_TYPE_IS_REPLY: + communication_path = get_Noti_Reply_Path(noti_key); + break; + default: + *error = EVENT_IPC_ERR; + return 0; + break; + } + + FW_LOGV("noti_type : %d", noti_type); + FW_LOGV("communication_path : %s", communication_path); + + int client_sockfd = __getSocketConnector(communication_path); + + /* + * if noti type is NOTI_TYPE_NEED_REPLY, Start Socket Server to recieve event as response + * Pending until recieve reply + */ + if (noti_type == NOTI_TYPE_NEED_REPLY) { + Event_Data *reply = __response_listener(client_sockfd, noti, confirm_cancel, user_data, error); + return reply; + } else { + int send_data_size = (noti->data - noti->size) + 1; + write(client_sockfd, (void *)(noti->size), send_data_size); + + if (client_sockfd != -1) { + close(client_sockfd); + } + + free_Noti(noti); + } + + return 0; +} + +void free_Noti(Event_Data *noti) +{ + if (noti != NULL) { + free_eventdata(noti); + } +} + +static void *__event_listener(void *arg) +{ + signal(SIGPIPE, SIG_IGN); + + int client_sockfd; + int state; + socklen_t client_len; + struct sockaddr_un clientaddr, serveraddr; + + const char *communication_path = get_Event_Path(); + FW_LOGV("event_path : %s", communication_path); + + if (access(communication_path, F_OK) == 0) { + unlink(communication_path); /* when file exist, remove previous file */ + } + + client_len = sizeof(clientaddr); + if ((_event_server_socket_id = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) { + return 0; + } + + bzero(&serveraddr, sizeof(serveraddr)); + serveraddr.sun_family = AF_UNIX; + strcpy(serveraddr.sun_path, communication_path); + + state = bind(_event_server_socket_id, (struct sockaddr *)&serveraddr, sizeof(serveraddr)); + if (state == -1) { + return 0; + } + + mode_t sock_mode = (S_IRWXU | S_IRWXG | S_IRWXO); + if (-1 == chmod(communication_path, sock_mode)) { + ; + } + + state = listen(_event_server_socket_id, 5); + if (state == -1) { + return 0; + } + + while (1) { + FW_LOGI("In EventHandler loop=\n"); + + char inbuf[MAX_STREAM_SIZE]; + char outbuf[MAX_STREAM_SIZE]; + memset(inbuf, 0x00, MAX_STREAM_SIZE); + memset(outbuf, 0x00, MAX_STREAM_SIZE); + Event_Data request; + Event_Data response; + request.data = inbuf; + response.data = outbuf; + init_eventdata_iter(&request); + init_eventdata_iter(&response); + + client_sockfd = accept(_event_server_socket_id, (struct sockaddr *)&clientaddr, &client_len); + + if (read(client_sockfd, (void *)inbuf, MAX_STREAM_SIZE) <= 0) { + close(client_sockfd); + return 0; + } + FW_LOGI("accept() was called\n"); + + int eventNum; + get_eventdata_param(&request, &eventNum); + FW_LOGI("Recieved Event Number : %d\n", eventNum); + + __dispatch_event(eventNum, &request, &response); + /* + * need synchronous response case + */ + EVENT_TYPE event_type = get_EventType(eventNum); + if (event_type == EVENT_TYPE_NEED_RESPONSE) { + if (get_eventdata_element_size(&response) > 0) { + int byte_size = get_eventdata_byte_size(&response); + write(client_sockfd, outbuf, byte_size); + } + } + + close(client_sockfd); + } + + return 0; +} + +static Event_Data *__response_listener(int send_sockfd, Event_Data *noti, CONFIRM_IPC_CANCEL confirm_cancel, void *user_data, EVENT_ERROR *error) +{ + int reply_server_socketfd; + int state; + socklen_t client_len; + struct sockaddr_un clientaddr, serveraddr; + + const char *communication_path = get_Event_Reply_Path(); + FW_LOGV("event_reply_path : %s", communication_path); + + if (access(communication_path, F_OK) == 0) { + unlink(communication_path); /* when file exist, remove previous file */ + } + + client_len = sizeof(clientaddr); + if ((reply_server_socketfd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) { + *error = EVENT_IPC_ERR; + return 0; + } + + int flag = fcntl(reply_server_socketfd, F_GETFL, 0); + fcntl(reply_server_socketfd, F_SETFL, flag | O_NONBLOCK); + + bzero(&serveraddr, sizeof(serveraddr)); + serveraddr.sun_family = AF_UNIX; + strcpy(serveraddr.sun_path, communication_path); + + state = bind(reply_server_socketfd, (struct sockaddr *)&serveraddr, sizeof(serveraddr)); + if (state == -1) { + *error = EVENT_IPC_ERR; + close(reply_server_socketfd); + return 0; + } + + mode_t sock_mode = (S_IRWXU | S_IRWXG | S_IRWXO); + if (-1 == chmod(communication_path, sock_mode)) { + ; + } + + state = listen(reply_server_socketfd, 5); + if (state == -1) { + *error = EVENT_IPC_ERR; + close(reply_server_socketfd); + return 0; + } + + int not_yet_sended = 1; + while (1) { + FW_LOGI("In Reply Event Handler loop"); + + if (confirm_cancel != 0) { + IPC_CANCEL need_cancel = confirm_cancel(user_data); + if (need_cancel == NEED_CANCEL) { + FW_LOGV("Cancel to listen response event"); + *error = EVENT_CANCLED; + close(reply_server_socketfd); + return 0; + } + } + + int client_sockfd = accept(reply_server_socketfd, (struct sockaddr *)&clientaddr, &client_len); + + if (not_yet_sended) { + int send_data_size = (noti->data - noti->size) + 1; + write(send_sockfd, (void *)(noti->size), send_data_size); + + if (send_sockfd != -1) { + close(send_sockfd); + } + + free_Noti(noti); + not_yet_sended = 0; + FW_LOGV("Sended to Notification [%d]"); + } + + if (client_sockfd < 0) { + if (errno == EWOULDBLOCK) { + FW_LOGV("No client accepted, not yet"); + usleep(100000); + continue; + } else { + FW_LOGE("Failed to accept()"); + close(reply_server_socketfd); + break; + } + } + + char *inbuf = (char *)calloc(MAX_STREAM_SIZE, sizeof(char)); + Event_Data *reply = (Event_Data *)calloc(1, sizeof(Event_Data)); + reply->data = inbuf; + init_eventdata_iter(reply); + + if (read(client_sockfd, (void *)inbuf, MAX_STREAM_SIZE) <= 0) { + FW_LOGE("Socket Error - failed to read()"); + close(client_sockfd); + close(reply_server_socketfd); + free_eventdata(reply); + *error = EVENT_IPC_ERR; + + return 0; + } + + close(client_sockfd); + close(reply_server_socketfd); + + int eventNum; + get_eventdata_param(reply, &eventNum); + FW_LOGI("Recieved Response Event Num : %d", eventNum); + + return reply; + } + + return 0; +} + +static void __dispatch_event(int eventNum, Event_Data *request, Event_Data *response) +{ + EVENT_CALLBACK event_callback = get_EventCallback(eventNum); + + event_callback(request, response); +} + +static int __getSocketConnector(const char *sock_file) +{ + int client_len; + int client_sockfd; + struct sockaddr_un clientaddr; + + client_sockfd = socket(AF_UNIX, SOCK_STREAM, 0); + if (client_sockfd == -1) + FW_LOGE("socket create error!!"); + + bzero(&clientaddr, sizeof(clientaddr)); + clientaddr.sun_family = AF_UNIX; + strcpy(clientaddr.sun_path, sock_file); + client_len = sizeof(clientaddr); + + if (connect(client_sockfd, (struct sockaddr *)&clientaddr, client_len) < 0) { + FW_LOGE("Socket Connect error!!"); + } + + return client_sockfd; +} diff --git a/framework/src/Event/Event_UI_API.c b/framework/src/Event/Event_UI_API.c new file mode 100755 index 0000000..af29fe9 --- /dev/null +++ b/framework/src/Event/Event_UI_API.c @@ -0,0 +1,348 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu , + */ + +#include +#include +#include +#include +#include +#include + +#include "Utility/fw_log.h" + +#include "Event_Config.h" +#include "Event_Util.h" +#include "Event_Data_Accessor.h" +#include "Event_UI_API.h" + +#define LOG_TAG "AF_EVENT_UI" + +static int noti_server_socket_id = 0; +static pthread_t Noti_Listener_thread_id = 0; + +static void *__noti_listener(void *arg); + +static Event_Data *__response_listener(EVENT_ERROR *error); + +static void __dispatch_noti(int notiNum, Event_Data *noti); + +Event_Data *create_Event(int eventNum) +{ + Event_Data *event = (Event_Data *)malloc(sizeof(Event_Data)); + if (!event) { + FW_LOGE("Memory malloc FAILED. [event]"); + return event; + } + event->eventNum = eventNum; + + char *serialized_data = (char *)calloc(MAX_STREAM_SIZE, sizeof(char)); + event->size = serialized_data; + event->data = serialized_data + 1; + + append_eventdata_param(event, INTEGER, &eventNum); + + return event; +} + +Event_Data *send_Event(Event_Data *event, EVENT_ERROR *error) +{ + *error = EVENT_SUCCESS; + int client_len; + int client_sockfd; + struct sockaddr_un clientaddr; + + client_sockfd = socket(AF_UNIX, SOCK_STREAM, 0); + if (client_sockfd == -1) { + FW_LOGE("socket create Error!!"); + *error = EVENT_IPC_ERR; + return 0; + } + + bzero(&clientaddr, sizeof(clientaddr)); + clientaddr.sun_family = AF_UNIX; + /* + * select socket path, whether event type is response for notification + */ + const char *communication_path = 0; + EVENT_TYPE event_type = get_EventType(event->eventNum); + switch (event_type) { + case EVENT_TYPE_NO_RESPONSE: + case EVENT_TYPE_NEED_RESPONSE: + case EVENT_TYPE_NEED_NOTI_RESPONSE: + communication_path = get_Event_Path(); + break; + case EVENT_TYPE_IS_RESPONSE: + communication_path = get_Event_Reply_Path(); + break; + } + + if (communication_path == 0) { + return 0; + } + + FW_LOGV("communication_path : %s", communication_path); + + strcpy(clientaddr.sun_path, communication_path); + client_len = sizeof(clientaddr); + + if (connect(client_sockfd, (struct sockaddr *)&clientaddr, client_len) < 0) { + FW_LOGE("socket connect error"); + close(client_sockfd); + *error = EVENT_IPC_ERR; + + return 0; + } + + int send_data_size = (event->data - event->size) + 1; + write(client_sockfd, (void *)(event->size), send_data_size); + + if (event_type != EVENT_TYPE_NEED_RESPONSE) { + FW_LOGI("Do not need synchronous response"); + close(client_sockfd); + return 0; + } + + if (event_type == EVENT_TYPE_NEED_NOTI_RESPONSE) { + Event_Data *reply = __response_listener(error); + close(client_sockfd); + return reply; + } + + /* + * recieve Logic + */ + char *connection_result = (char *)calloc(MAX_STREAM_SIZE, sizeof(char)); + read(client_sockfd, connection_result, MAX_STREAM_SIZE); + close(client_sockfd); + + print_eventdata(connection_result); + + Event_Data *reply_msg = (Event_Data *)malloc(sizeof(Event_Data)); + if (!reply_msg) { + FW_LOGE("Memory malloc FAILED. [reply_msg]"); + *error = EVENT_FAIL; + return reply_msg; + } + reply_msg->data = connection_result; + + init_eventdata_iter(reply_msg); + + return reply_msg; +} + +EVENT_ERROR run_NotiListener() +{ + FW_LOGI("============ start"); + + if (Noti_Listener_thread_id == 0) { + FW_LOGI("Run NotiListener!!"); + pthread_create(&Noti_Listener_thread_id, 0, __noti_listener, 0); + return EVENT_SUCCESS; + } + + FW_LOGI("============ end"); + return EVENT_FAIL; +} + +EVENT_ERROR stop_NotiListener() +{ + if (Noti_Listener_thread_id == 0) { + return EVENT_FAIL; + } + + if (noti_server_socket_id != 0) { + close(noti_server_socket_id); + noti_server_socket_id = 0; + } + + pthread_cancel(Noti_Listener_thread_id); + Noti_Listener_thread_id = 0; + + return EVENT_SUCCESS; +} + +EVENT_ERROR set_NotiCallBack(int notiType, NOTI_CALLBACK callback, void *data) +{ + return register_NotiCallback(notiType, callback, data); +} + +static void *__noti_listener(void *arg) +{ + int client_sockfd; + int state; + socklen_t client_len; + struct sockaddr_un clientaddr, serveraddr; + + const char *communication_path = get_Noti_Path(0); + FW_LOGV("Noti communication path : %s", communication_path); + + if (access(communication_path, F_OK) == 0) { + unlink(communication_path); /* when file exist, remove previous file */ + } + + client_len = sizeof(clientaddr); + if ((noti_server_socket_id = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) { + return 0; + } + + bzero(&serveraddr, sizeof(serveraddr)); + serveraddr.sun_family = AF_UNIX; + strcpy(serveraddr.sun_path, communication_path); + + state = bind(noti_server_socket_id, (struct sockaddr *)&serveraddr, sizeof(serveraddr)); + if (state == -1) { + return 0; + } + + mode_t sock_mode = (S_IRWXU | S_IRWXG | S_IRWXO); + if (-1 == chmod(communication_path, sock_mode)) { + ; + } + + state = listen(noti_server_socket_id, 5); + if (state == -1) { + return 0; + } + + while (1) { + FW_LOGI("In Listen Notification loop="); + + char *inbuf = (char *)calloc(MAX_STREAM_SIZE, sizeof(char)); + Event_Data *noti = (Event_Data *)calloc(1, sizeof(Event_Data)); + noti->data = inbuf; + init_eventdata_iter(noti); + + client_sockfd = accept(noti_server_socket_id, (struct sockaddr *)&clientaddr, &client_len); + + if (read(client_sockfd, (void *)inbuf, MAX_STREAM_SIZE) <= 0) { + close(client_sockfd); + return 0; + } + FW_LOGI("accept() was called"); + + int notiNum; + get_eventdata_param(noti, ¬iNum); + FW_LOGI("Recieved Noti Number : %d", notiNum); + + __dispatch_noti(notiNum, noti); + + close(client_sockfd); + } + + return 0; +} + +static Event_Data *__response_listener(EVENT_ERROR *error) +{ + int reply_server_socketfd, client_sockfd; + int state; + socklen_t client_len; + struct sockaddr_un clientaddr, serveraddr; + + const char *communication_path = get_Noti_Reply_Path(0); + FW_LOGV("Noti reply communication path : %s", communication_path); + + if (access(communication_path, F_OK) == 0) { + unlink(communication_path); /* when file exist, remove previous file */ + } + + client_len = sizeof(clientaddr); + if ((reply_server_socketfd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) { + *error = EVENT_IPC_ERR; + return 0; + } + + bzero(&serveraddr, sizeof(serveraddr)); + serveraddr.sun_family = AF_UNIX; + strcpy(serveraddr.sun_path, communication_path); + + state = bind(reply_server_socketfd, (struct sockaddr *)&serveraddr, sizeof(serveraddr)); + if (state == -1) { + *error = EVENT_IPC_ERR; + close(reply_server_socketfd); + return 0; + } + + mode_t sock_mode = (S_IRWXU | S_IRWXG | S_IRWXO); + if (-1 == chmod(communication_path, sock_mode)) { + ; + } + + state = listen(reply_server_socketfd, 5); + if (state == -1) { + *error = EVENT_IPC_ERR; + close(reply_server_socketfd); + return 0; + } + + while (1) { + FW_LOGI("In Reply Noti Handler loop"); + + char *inbuf = (char *)calloc(MAX_STREAM_SIZE, sizeof(char)); + Event_Data *reply = (Event_Data *)calloc(1, sizeof(Event_Data)); + reply->data = inbuf; + init_eventdata_iter(reply); + + client_sockfd = accept(reply_server_socketfd, (struct sockaddr *)&clientaddr, &client_len); + FW_LOGI("accept() was called"); + + if (read(client_sockfd, (void *)inbuf, MAX_STREAM_SIZE) <= 0) { + FW_LOGE("Socket Error - failed to read()"); + close(client_sockfd); + close(reply_server_socketfd); + free_eventdata(reply); + *error = EVENT_IPC_ERR; + + return 0; + } + + close(client_sockfd); + close(reply_server_socketfd); + + int notiNum; + get_eventdata_param(reply, ¬iNum); + FW_LOGI("Recieved Noti Num : %d", notiNum); + + return reply; + } +} + +static void __dispatch_noti(int notiNum, Event_Data *noti) +{ + NOTI_CALLBACK noti_callback = get_NotiCallback(notiNum); + void *additional_param = get_NotiCallback_AdditinalParam(notiNum); + + noti_callback(noti, additional_param); +} diff --git a/framework/src/Event/Event_Util.c b/framework/src/Event/Event_Util.c new file mode 100644 index 0000000..0ca7ae8 --- /dev/null +++ b/framework/src/Event/Event_Util.c @@ -0,0 +1,63 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu , + */ + +#include + +#include "Event/Event_Util.h" + +void init_eventdata_iter(Event_Data *event) +{ + event->size = event->data; + event->data = event->data + 1; +} + +int get_eventdata_byte_size(Event_Data *iter) +{ + return (iter->data - iter->size + 1); +} + +int get_eventdata_element_size(Event_Data *iter) +{ + return (int)(iter->size[0]); +} + +void remove_buffer(Event_Data *event) +{ + if (event != 0) { + if (event->size != 0) { + free(event->size); + } + } +} diff --git a/framework/src/FSAPI/FSAPI_operation.c b/framework/src/FSAPI/FSAPI_operation.c new file mode 100644 index 0000000..ea33b2b --- /dev/null +++ b/framework/src/FSAPI/FSAPI_operation.c @@ -0,0 +1,692 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Wook Choi + */ + +#include +#include +#include +#include +#include +#include +#include +#include /* for statfs */ +#include "FSAPI/FSAPI_operation.h" +#include "FSAPI/FSAPI_util.h" + +#include "Utility/fw_log.h" +#define LOG_TAG "AF_FS" + +#define BUFFER_SIZE 2048 + +static bool file_append_started = FALSE; +static bool file_read_started = FALSE; +static char *temp_filename_kept = NULL; +static char *requested_filename_kept = NULL; +static FILE *fd_source_kept = NULL; + +int FSAPI_isExisting(const char *filename) +{ + return isExisting(filename); +} + +int FSAPI_memSize(const char *root, long double *sizeFree, long double *sizeTotal) +{ + if (!isExisting(root)) { + FW_LOGE("[%s] Requested instance '%s' not exist.\n", __func__, root); + return 0; + } + + struct statfs fs_info; + + if (statfs(root, &fs_info) != 0) { + FW_LOGE("[FSAPI_memSize] statfs error."); + return 0; + } + + *sizeFree = ((long double)fs_info.f_bavail * (long double)fs_info.f_bsize); /* / 1024; */ + *sizeTotal = ((long double)fs_info.f_blocks * (long double)fs_info.f_bsize); /* / 1024; */ + + FW_LOGI("[FSAPI_memSize] FS info root : %s.", root); + FW_LOGI("[FSAPI_memSize] FS info free size : %.0f", *sizeFree); + FW_LOGI("[FSAPI_memSize] FS info total size : %.0f", *sizeTotal); + + return 1; +} + +/* + * File operation + */ + +int FSAPI_fileSize(const char *filename, unsigned long *size) +{ + if (!isExisting(filename) || isDirectory(filename)) { + FW_LOGE("[%s] Requested instance '%s' not exist, or not a file.\n", __func__, filename); + return 0; + } + + struct stat buf; + + int ret = stat(filename, &buf); + if (ret == -1) { + FW_LOGE("[%s] stat error : %s", __func__, strerror(errno)); + return 0; + } + + *size = (unsigned long)buf.st_size; + + return 1; +} + +int FSAPI_fileDate(const char *filename, char **time_string) +{ + if (!isExisting(filename) || isDirectory(filename)) { + FW_LOGE("[%s] Requested instance '%s' not exist, or not a file.\n", __func__, filename); + return 0; + } + + struct stat buf; + char time[20] = { 0 }; + + int ret = stat(filename, &buf); + if (ret == -1) { + FW_LOGE("[%s] stat error : %s", __func__, strerror(errno)); + return 0; + } + + getTimeString(&buf.st_mtime, time); + *time_string = g_strdup(time); + + return 1; +} + +int FSAPI_fileCopy(const char *source, const char *dest) +{ + if (!isExisting(source) || isDirectory(source) || isExisting(dest)) { + FW_LOGE("[%s] Requested source instance '%s' not exist or not a file, or\n", __func__, source); + FW_LOGE("[%s] requested dest instance '%s' already exist.\n", __func__, dest); + return 0; + } + + FILE *f1 = NULL, *f2 = NULL; + int ret = 1; + char buf[1024 * 100] = { 0 }; + unsigned long bytes_read = 0; + unsigned long bytes_written = 0; + + f1 = (FILE *)g_fopen(source, "rb"); + if (!f1) { + FW_LOGE("[FSAPI_fileCopy] file f1 open error."); + ret = 0; + goto return_part; + } + + f2 = (FILE *)g_fopen(dest, "wb"); + if (!f2) { + FW_LOGE("[FSAPI_fileCopy] file f2 open error."); + ret = 0; + goto return_part; + } + + while ((bytes_read = fread(buf, 1, sizeof(buf), f1)) > 0) { + if (bytes_read > sizeof(buf)) { + FW_LOGE("[FSAPI_fileCopy] read error."); + ret = 0; + goto return_part; + } + + bytes_written = fwrite(buf, 1, bytes_read, f2); + if (!feof(f1) && bytes_written != bytes_read) { + FW_LOGE("[FSAPI_fileCopy] write error."); + ret = 0; + goto return_part; + } + } + +return_part: + if (f1) + fclose(f1); + if (f2) + fclose(f2); + return ret; + +/* + char *body = NULL; + unsigned long size; + + if( !File_Read(source, &body, &size) ) { + fprintf(stderr, "[%s] File_Read() returned error.\n", __func__); + return 0; + } + + if( !File_Write(dest, body, size) ) { + fprintf(stderr, "[%s] File_Read() returned error.\n", __func__); + return 0; + } + + free(body); + + return 1; +*/ +} + +int FSAPI_fileDelete(const char *filename) +{ + if (!isExisting(filename) || isDirectory(filename)) { + FW_LOGE("[%s] Requested instance '%s' not exist, or not a file.\n", __func__, filename); + return 0; + } + + int ret = g_unlink(filename); + if (ret == -1) { + FW_LOGE("[%s] g_unlink error : %s\n", __func__, strerror(errno)); + return 0; + } + + return 1; +} + +int FSAPI_fileMove(const char *source, const char *dest) +{ + if (!isExisting(source) || isDirectory(source) || isExisting(dest)) { + FW_LOGE("[%s] Requested source instance '%s' not exist or not a file, or\n", __func__, source); + FW_LOGE("[%s] requested dest instance '%s' already exist.\n", __func__, dest); + return 0; + } + + int ret = g_rename(source, dest); + if (ret == -1) { + FW_LOGE("[FSAPI_fileMove] g_rename error : %s", strerror(errno)); + FW_LOGE("[FSAPI_fileMove] source : %s target : %s", source, dest); + return 0; + } + + return 1; +} + +int FSAPI_fileRename(const char *source, const char *dest) +{ + return FSAPI_fileMove(source, dest); +} + +int FSAPI_fileRead(const char *filename, char **required_contents, unsigned long required_length, unsigned long *size_return, bool *isFinal) +{ + if (!isExisting(filename) || isDirectory(filename)) { + FW_LOGE("[%s] Requested instance '%s' not exist, or not a file.\n", __func__, filename); + return 0; + } + + int ret = 1; + + if (!fd_source_kept && !file_read_started) { + if (!(fd_source_kept = (FILE *)g_fopen(filename, "rb"))) { + FW_LOGE("[FSAPI_fileRead] temp_filename_kept open error."); + ret = 0; + goto return_part; + } + file_read_started = TRUE; + } else if (fd_source_kept && file_read_started) { + } else { + FW_LOGE("[%s] internal condition not matching.\n", __func__); + ret = 0; + goto return_part; + } + + *required_contents = (char *)calloc(required_length, sizeof(char)); + if (*required_contents == NULL) { + FW_LOGE("[FSAPI_fileRead] calloc error. [*required_contents]"); + ret = 0; + goto return_part; + } + + int bytes_read = 0; + bytes_read = fread(*required_contents, 1, required_length, fd_source_kept); + + if ((bytes_read > required_length) || ((!feof(fd_source_kept)) && (bytes_read < required_length))) { + FW_LOGE("[FSAPI_fileRead] read error."); + ret = 0; + goto return_part; + } + + *size_return = bytes_read; + + if (feof(fd_source_kept)) { + *isFinal = TRUE; + goto return_part; + } + + return ret; + +return_part: + + if (fd_source_kept) { + fclose(fd_source_kept); + fd_source_kept = NULL; + } + file_read_started = FALSE; + + return ret; + +/* + if( !isExisting(filename) || isDirectory(filename) ) { + fprintf(stderr, "[%s] Requested instance '%s' not exist, or not a file.\n", __func__, filename); + return 0; + } + + GError *gerror = NULL; + + if( !g_file_get_contents(filename, contents, (gsize*)length, &gerror) ) { + fprintf(stderr, "[%s] g_file_get_contents error : %s\n", __func__, gerror->message); + + g_error_free(gerror); + return 0; + } + + return 1; +*/ +} + +int FSAPI_fileReadWhole(const char *filename, char **required_contents, unsigned long *size_return) +{ + if (!isExisting(filename) || isDirectory(filename)) { + FW_LOGE("[%s] Requested instance '%s' not exist, or not a file.\n", __func__, filename); + return 0; + } + + GError *gerror = NULL; + + if (!g_file_get_contents(filename, required_contents, (gsize *) size_return, &gerror)) { + FW_LOGE("[%s] g_file_get_contents error : %s\n", __func__, gerror->message); + + g_error_free(gerror); + return 0; + } + + return 1; +} + +int FSAPI_fileRead_Free(char **requested_contents) +{ + if (*requested_contents) + free(*requested_contents); + return 1; +} + +int FSAPI_fileWrite(const char *filename, const char *contents, unsigned long length, bool isFinal, bool overwrite) +{ + if (!overwrite) { + if (isExisting(filename)) { + FW_LOGE("[%s] Requested instance '%s' already exist.\n", __func__, filename); + return 0; + } + } + + FILE *fd_temp = NULL; + GError *gerror = NULL; + int ret = 1; + unsigned long temp_size = 0; + + if (!temp_filename_kept && !file_append_started) { + if (!g_file_open_tmp(NULL, &temp_filename_kept, &gerror)) { + FW_LOGE("[%s] g_file_open_tmp error : %s\n", __func__, gerror->message); + + g_error_free(gerror); + ret = 0; + goto return_part; + } + FW_LOGI("[FSAPI_fileWrite] Temp file name kept new : %s", temp_filename_kept); + + file_append_started = TRUE; + requested_filename_kept = g_strdup(filename); + + } else if (temp_filename_kept && file_append_started) { + if (!isExisting(temp_filename_kept)) { + FW_LOGE("[%s] Temp file '%s' not existing.\n", __func__, temp_filename_kept); + ret = 0; + goto return_part; + } + FW_LOGI("[FSAPI_fileWrite] Temp file %s kept previously, existing", temp_filename_kept); + + } else { + FW_LOGE("[%s] internal condition not matching.\n", __func__); + ret = 0; + goto return_part; + } + + if (temp_filename_kept) { + fd_temp = (FILE *)g_fopen(temp_filename_kept, "ab"); + } else { + goto return_part; + } + + if (!fd_temp) { + FW_LOGE("[FSAPI_fileWrite] temp file open error."); + ret = 0; + goto return_part; + } + + if (fwrite(contents, 1, length, fd_temp) != length) { + FW_LOGE("[FSAPI_fileWrite] fwrite error."); + ret = 0; + goto return_part; + } + + if (fd_temp) { + fclose(fd_temp); + fd_temp = NULL; + } + + FSAPI_fileSize(temp_filename_kept, &temp_size); + FW_LOGI("[FSAPI_fileWrite] temp file size %ld", temp_size); + + if (isFinal) { + if (overwrite) { + if (isExisting(filename)) { + if (!FSAPI_fileDelete(filename)) { + FW_LOGE("[FSAPI_fileWrite] deleting destination file for overwriting fail."); + ret = 0; + } else { + if (!FSAPI_fileCopy(temp_filename_kept, filename)) { + FW_LOGE("[FSAPI_fileWrite] copying temp file to destination fail."); + ret = 0; + } else { + if (!FSAPI_fileDelete(temp_filename_kept)) { + FW_LOGE("[FSAPI_fileWrite] deleting temp file fail."); + ret = 0; + } + } + } + } else { + if (!FSAPI_fileCopy(temp_filename_kept, filename)) { + FW_LOGE("[FSAPI_fileWrite] copying temp file to destination fail."); + ret = 0; + } else { + if (!FSAPI_fileDelete(temp_filename_kept)) { + FW_LOGE("[FSAPI_fileWrite] deleting temp file fail."); + ret = 0; + } + } + } + } else { + if (!FSAPI_fileCopy(temp_filename_kept, filename)) { + FW_LOGE("[FSAPI_fileWrite] copying temp file to destination fail."); + ret = 0; + } else { + if (!FSAPI_fileDelete(temp_filename_kept)) { + FW_LOGE("[FSAPI_fileWrite] deleting temp file fail."); + ret = 0; + } + } + } + goto return_part; + } + + return ret; + +return_part: + + if (fd_temp) + fclose(fd_temp); + g_free(temp_filename_kept); + g_free(requested_filename_kept); + temp_filename_kept = NULL; + requested_filename_kept = NULL; + file_append_started = FALSE; + + return ret; + +/* + if( isExisting(filename) ) { + fprintf(stderr, "[%s] Requested instance '%s' already exist.", __func__, filename); + return 0; + } + + GError *gerror = NULL; + + if( !g_file_set_contents(filename, contents, length, &gerror) ) { + fprintf(stderr, "[%s] g_file_set_contents error : %s\n", __func__, gerror->message); + + g_error_free(gerror); + return 0; + } + + return 1; +*/ +} + +int FSAPI_fileWriteWhole(const char *filename, const char *contents, unsigned long length, bool overwrite) +{ + if (isExisting(filename)) { + if (overwrite && !isDirectory(filename)) { + FSAPI_fileDelete(filename); + } else { + FW_LOGE("[%s] Requested instance '%s' already exist.", __func__, filename); + return 0; + } + } + + GError *gerror = NULL; + + if (!g_file_set_contents(filename, contents, length, &gerror)) { + FW_LOGE("[%s] g_file_set_contents error : %s\n", __func__, gerror->message); + + g_error_free(gerror); + return 0; + } + + return 1; +} + +int FSAPI_fileAppend(const char *filename, const char *contents, unsigned long length, bool overwrite) +{ + if (overwrite) { + if (!FSAPI_fileDelete(filename)) { + if (!isExisting(filename)) { + FW_LOGE("[%s] The file %s requested to delete for overwriting is not existing, so just continue.", __func__, filename); + } else { + if (isDirectory(filename)) { + FW_LOGE("[%s] Can't overwrite because requested instance '%s' not a file.", __func__, filename); + return 0; + } else { + FW_LOGE("[%s] FAILED to delete requested file '%s'.", __func__, filename); + return 0; + } + } + } + } + + FILE *fd; + int ret = 1; + + fd = (FILE *)g_fopen(filename, "ab"); + if (!fd) { + FW_LOGE("[FSAPI_fileAppend] file open error."); + ret = 0; + goto return_part; + } + + if (fwrite(contents, 1, length, fd) != length) { + FW_LOGE("[%s] fwrite error '%s'.", __func__, filename); + ret = 0; + goto return_part; + } + + if (fsync(fileno(fd)) != 0) + ret = 0; + +return_part: + + if (fd) + fclose(fd); + + FW_LOGI("[%s] Returning..", __func__); + return ret; +} + +/* + * Folder operation + */ + +int FSAPI_folderCreate(const char *foldername) +{ + if (isExisting(foldername)) { + FW_LOGE("[%s] Requested instance '%s' already exist.\n", __func__, foldername); + return 0; + } + + int ret = g_mkdir_with_parents(foldername, 0755); + if (ret == -1) { + FW_LOGE("[%s] g_mkdir error : %s\n", __func__, strerror(errno)); + return 0; + } + + return 1; +} + +int FSAPI_folderDelete(const char *foldername, bool recursive) +{ + if (!isExisting(foldername) || !isDirectory(foldername)) { + FW_LOGE("[%s] Requested instance '%s' not exist, or not a directory.\n", __func__, foldername); + return 0; + } + + GError *gerror = NULL; + GDir *dir = NULL;; + int ret = 0; + char *path = NULL; + char *name = NULL; + + if (recursive) { + dir = g_dir_open(foldername, 0, &gerror); + if (!dir) { + FW_LOGE("[%s] g_dir_open error : %s\n", __func__, gerror->message); + g_error_free(gerror); + return 0; + } + + name = (char *)g_dir_read_name(dir); + + for (; name; name = (char *)g_dir_read_name(dir)) { + + path = g_strdup_printf("%s/%s", foldername, name); + + if (isDirectory(path)) { + if (!FSAPI_folderDelete(path, true)) + return 0; + } else { + if (!FSAPI_fileDelete(path)) + return 0; + } + } + + if (name) + free(name); + if (path) + free(path); + g_dir_close(dir); + dir = NULL; + } + + ret = g_rmdir(foldername); + if (ret == -1) { + FW_LOGE("[%s] g_rmdir error : %s\n", __func__, strerror(errno)); + return 0; + } + + return 1; +} + +int FSAPI_folderEmptyContents(const char *foldername) +{ + if (!isExisting(foldername) || !isDirectory(foldername)) { + FW_LOGE("[%s] Requested instance '%s' not exist, or not a directory.\n", __func__, foldername); + return 0; + } + + GError *gerror = NULL; + GDir *dir = NULL;; + char *path = NULL; + char *name = NULL; + + dir = g_dir_open(foldername, 0, &gerror); + if (!dir) { + FW_LOGE("[%s] g_dir_open error : %s\n", __func__, gerror->message); + g_error_free(gerror); + return 0; + } + + name = (char *)g_dir_read_name(dir); + + for (; name; name = (char *)g_dir_read_name(dir)) { + + path = g_strdup_printf("%s/%s", foldername, name); + + if (isDirectory(path)) { + if (!FSAPI_folderDelete(path, true)) { + FW_LOGE("[%s] FSAPI_folderDelete error : %s\n", __func__, strerror(errno)); + return 0; + } + } else { + if (!FSAPI_fileDelete(path)) { + FW_LOGE("[%s] FSAPI_fileDelete error : %s\n", __func__, strerror(errno)); + return 0; + } + } + } + + if (name) + free(name); + if (path) + free(path); + g_dir_close(dir); + dir = NULL; + + return 1; +} + +int FSAPI_folderRename(const char *source, const char *dest) +{ + if (!isExisting(source) || !isDirectory(source) || isExisting(dest)) { + FW_LOGE("[%s] Requested source instance '%s' not exist or not a directory, or\n", __func__, source); + FW_LOGE("[%s] requested dest instance '%s' already exist.\n", __func__, dest); + return 0; + } + + int ret = g_rename(source, dest); + if (ret == -1) { + FW_LOGE("[%s] g_rename error : %s\n", __func__, strerror(errno)); + return 0; + } + + return 1; +} diff --git a/framework/src/FSAPI/FSAPI_util.c b/framework/src/FSAPI/FSAPI_util.c new file mode 100644 index 0000000..0cb067a --- /dev/null +++ b/framework/src/FSAPI/FSAPI_util.c @@ -0,0 +1,61 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Wook Choi + */ + +#include +#include +#include +#include "FSAPI/FSAPI_util.h" + +int isExisting(const char *filename) +{ + return g_file_test(filename, G_FILE_TEST_EXISTS); +} + +int isDirectory(const char *filename) +{ + return g_file_test(filename, G_FILE_TEST_IS_DIR); +} + +int getTimeString(time_t *time_stamp, char *time_string) +{ + struct tm *time; + char buf[20] = { 0 }; + + time = localtime(time_stamp); + strftime(buf, 20, "%Y:%m:%d %H:%M:%S", time); + strcpy(time_string, buf); + + return 1; +} diff --git a/framework/src/Initialization/initialize.c b/framework/src/Initialization/initialize.c new file mode 100755 index 0000000..9de206d --- /dev/null +++ b/framework/src/Initialization/initialize.c @@ -0,0 +1,162 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu , + */ + +#include "Utility/fw_log.h" +#include "Utility/fw_mainloop.h" + +#include "Account/Account_Util.h" + +#include "PlugIn/PlugIn_DataConnector.h" +#include "PlugIn/PlugIn_Account.h" +#include "PlugIn/PlugIn_PlatformMonitor.h" +#include "PlugIn/PlugIn_NetworkAccess.h" +#include "PlugIn/PlugIn_DeviceInfo.h" + +#include "DataAdapter/DACI_Service.h" +#include "DataAdapter/DACI_ChangeLog.h" + +#include "NetworkAccess/NACI.h" + +#include "Device/EXT_DCI_Errors.h" +#include "Device/EXT_DCI_DevInfo.h" + +#include "PlatformMonitor/EXT_PMCI_Errors.h" + +#include "Initialization/initialize_parser.h" +#include "Initialization/initialize.h" + +#define LOG_TAG "AF_INIT" + +INIT_ERROR Init_Framework(const char *init_config_path) +{ + INIT_ERROR init_error = parse_Init_config(init_config_path); + + if (init_error != INIT_SUCCESS) { + return init_error; + } + + const char *agent_key = get_AgentKey(); + FW_LOGV("Agent KEY : %s", agent_key); + + int plugIn_dc_count = 0; + const PlugIn_DataConnector *plugIn_dc_repository = getDataConnector_PlugInRepository(&plugIn_dc_count); + + /* + * Account + */ + if (plugIn_dc_count != 0) { + int plugIn_acc_id = getAccount_PlugIn_ID(); + Set_AccountReposioryName pFunc_Set_AccountReposioryName = getFunction_Set_AccountReposioryName(plugIn_acc_id); + if (pFunc_Set_AccountReposioryName != 0) { + pFunc_Set_AccountReposioryName(agent_key); + } + } + + /* + * DataConnector Process ChangeNoti + */ + int i = 0; + for (; i < plugIn_dc_count; i++) { + if (plugIn_dc_repository[i].handle_changenoti) { + int plugIn_id = plugIn_dc_repository[i].plugIn_info.plugIn_id; + + SetCallBack_AddItem setCallBack_AddItem = getFunction_DataConnector_SetCallBack_AddItem(plugIn_id); + SetCallBack_DeleteItem setCallBack_DeleteItem = getFunction_DataConnector_SetCallBack_DeleteItem(plugIn_id); + SetCallBack_UpdateItem setCallBack_UpdateItem = getFunction_DataConnector_SetCallBack_UpdateItem(plugIn_id); + SetCallBack_GetAccountIDList setCallBack_GetAccountIDList = getFunction_DataConnector_SetCallBack_GetAccountIDList(plugIn_id); + StartListening_ChangeNoti startListening_ChangeNoti = getFunction_DataConnector_StartListening_ChangeNoti(plugIn_id); + + DACI_RETURN da_error = DACI_Service_Open(plugIn_id); + if (da_error != DACI_SUCCESS) { + FW_LOGE("DACI_Service_Open(%d) Failed!!", plugIn_id); + return INIT_SERVICE_DB_FAIL; + } else { + FW_LOGV("DACI_Service_Open(%d) Success!!", plugIn_id); + } + setCallBack_AddItem(handle_ADD_ITEM); + setCallBack_DeleteItem(handle_DEL_ITEM); + setCallBack_UpdateItem(handle_UPDATE_ITEM); + setCallBack_GetAccountIDList(getAccountIDList_Service); + + if (plugIn_dc_repository[i].use_mainloop) { + register_Callback2MainLoop(startListening_ChangeNoti, 0); + } + } + } + + /* + * NetworkAccess + */ + int *na_plugIn_id_list = 0; + int na_plugIn_cnt = get_NetworkAccess_PlugIn_ID_List(&na_plugIn_id_list); + + if (na_plugIn_id_list != 0) { + i = 0; + for (; i < na_plugIn_cnt; i++) { + NACI_RESULT res = NACI_Init(na_plugIn_id_list[i]); + if (res == NACI_SUCCESS) { + FW_LOGI("Success NACI_init() : %d", na_plugIn_id_list[i]); + } else { + FW_LOGE("Failed NACI_init() : %d, %d", res, na_plugIn_id_list[i]); + if (na_plugIn_id_list != 0) { + free(na_plugIn_id_list); + } + return INIT_NETWORK_FAIL; + } + } + free(na_plugIn_id_list); + } + + /* + * Device Initialization + */ + int plugIn_device_id; + if (isExsist_DeviceInfo_PlugIn(&plugIn_device_id)) { + DCI_RETURN res = DCI_Init(plugIn_device_id); + if (res == DCI_SUCCESS) { + FW_LOGI("Success DCI_init() : %d", plugIn_device_id); + } else { + FW_LOGI("Failed DCI_init() : %d, %d", res, plugIn_device_id); + return INIT_DEVICE_FAIL; + } + } + + if (use_MainLoop()) { + FW_LOGV("Run Main Loop!!"); + run_MainLoop(); + } + + return INIT_SUCCESS; +} diff --git a/framework/src/Initialization/initialize_parser.c b/framework/src/Initialization/initialize_parser.c new file mode 100755 index 0000000..4a94ffa --- /dev/null +++ b/framework/src/Initialization/initialize_parser.c @@ -0,0 +1,511 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu , + */ + +#include +#include +#include + +#include "Utility/fw_log.h" +#include "Utility/fw_mainloop.h" + +#include "EngineController/engine_controller_internal.h" + +#include "DataAdapter/DACI_Agent.h" +#include "DataAdapter/DACI_Agent_Handler_Manager.h" + +#include "Utility/fw_sequential_id_provider.h" + +#include "Event/Event_Handler.h" +#include "Event/Event_Config.h" + +#include "PlugIn/PlugIn_Struct.h" +#include "PlugIn/PlugIn_DataConnector.h" +#include "PlugIn/PlugIn_DataConverter.h" +#include "PlugIn/PlugIn_Account.h" +#include "PlugIn/PlugIn_NetworkAccess.h" +#include "PlugIn/PlugIn_DeviceInfo.h" +#include "PlugIn/PlugIn_PlatformMonitor.h" +#include "PlugIn/PlugIn_Mgr.h" + +#include "Device/EXT_DCI_DevInfo.h" + +#include "NetworkAccess/IN_NA_FW_Callbacks.h" + +#include "Initialization/initialize_parser.h" + + +#define LOG_TAG "AF_INIT" + +static char *agent_key = 0; + +static int use_main_loop = 0; + +static INIT_ERROR __processNode(xmlNode *root_element); + +static INIT_ERROR __process_EngineController(xmlNode *engineController_node); + +static INIT_ERROR __process_FrameworkDB(xmlNode *frameworkDB_node); + +static INIT_ERROR __process_ID_Provider(xmlNode *idProvider_node); + +static INIT_ERROR __process_Event(xmlNode *event_node); + +static INIT_ERROR __process_Noti(xmlNode *event_node); + +static INIT_ERROR __process_PlugIn(xmlNode *plugInMgr_node); + +static INIT_ERROR __process_PlatformMonitor(xmlNode *platformMonitor_node); + +static char *__getChildNodeContent(xmlNode *parent_node, const char *node_name); + +static int __compareUCharwithChar(const xmlChar *str, const char *str2); + + +INIT_ERROR parse_Init_config(const char *init_config_file_path) +{ + FW_LOGV("[Start]"); + + xmlDoc *doc = 0; + xmlNode *root_element = 0; + + doc = xmlReadFile(init_config_file_path, 0, 0); + if (doc == 0) { + FW_LOGE("Failed to parse %s", init_config_file_path); + return INIT_FAIL; + } + + root_element = xmlDocGetRootElement(doc); + + INIT_ERROR init_err = __processNode(root_element); + + xmlFreeDoc(doc); + + xmlCleanupParser(); + + FW_LOGV("[End]"); + + return init_err; +} + +char *get_AgentKey() +{ + return agent_key; +} + +int use_MainLoop() +{ + return use_main_loop; +} + +static INIT_ERROR __processNode(xmlNode *root_element) +{ + FW_LOGV("[Start]"); + + INIT_ERROR init_error = INIT_SUCCESS; + + if (root_element == 0) { + return INIT_FAIL; + } + + xmlNode *cursor_node = root_element->children; + while (cursor_node != 0) { + if (cursor_node->type == XML_ELEMENT_NODE) { + FW_LOGV("%s", cursor_node->name); + if (__compareUCharwithChar(cursor_node->name, "Agent-Key")) { + agent_key = (char *)xmlNodeGetContent(cursor_node); + FW_LOGV("Agent-Key : %s", agent_key); + } else if (__compareUCharwithChar(cursor_node->name, "MainLoop")) { + xmlChar *main_loop = xmlNodeGetContent(cursor_node); + if (__compareUCharwithChar(main_loop, "1")) { + use_main_loop = 1; + } + } else if (__compareUCharwithChar(cursor_node->name, "EngineController")) { + init_error = __process_EngineController(cursor_node); + } else if (__compareUCharwithChar(cursor_node->name, "FrameworkDB")) { + init_error = __process_FrameworkDB(cursor_node); + } else if (__compareUCharwithChar(cursor_node->name, "ID-Provider")) { + init_error = __process_ID_Provider(cursor_node); + } else if (__compareUCharwithChar(cursor_node->name, "Event")) { + init_error = __process_Event(cursor_node); + } else if (__compareUCharwithChar(cursor_node->name, "Noti")) { + init_error = __process_Noti(cursor_node); + } else if (__compareUCharwithChar(cursor_node->name, "PlugIn-Mgr")) { + init_error = __process_PlugIn(cursor_node); + } else if (__compareUCharwithChar(cursor_node->name, "PlatformMonitor")) { + init_error = __process_PlatformMonitor(cursor_node); + } + } + + cursor_node = cursor_node->next; + } + + FW_LOGV("[End]"); + + return init_error; +} + +/********************** Implement static function *************************/ + +static INIT_ERROR __process_EngineController(xmlNode *engineController_node) +{ + xmlNode *max_thread = engineController_node->children; + if (max_thread == 0) { + return INIT_PARSER_FAIL; + } + + char *max_thread_count_str = __getChildNodeContent(engineController_node, "Max-Thread"); + int max_thread_count = atoi(max_thread_count_str); + + if (max_thread_count <= 0) { + return INIT_ENGINE_CONTROLLER_FAIL; + } + + bool init_success = init_engine_controller(max_thread_count); + if (init_success) { + FW_LOGI("Engine controller initialize success"); + } else { + FW_LOGI("Engine controller initialize fail"); + return INIT_ENGINE_CONTROLLER_FAIL; + } + + return INIT_SUCCESS; +} + +static INIT_ERROR __process_FrameworkDB(xmlNode *frameworkDB_node) +{ + const char *use_DB_str = (char *)xmlGetProp(frameworkDB_node, (xmlChar *)"use"); + int use_DB = atoi(use_DB_str); + if (!use_DB) { + FW_LOGV("Not Use Framework Common DB"); + return INIT_SUCCESS; + } + + char *db_path = __getChildNodeContent(frameworkDB_node, "Path"); + FW_LOGV("Common DB Path : %s", db_path); + + set_agentdb_file_path(db_path); + + DACI_RETURN da_err = DACI_Alloc_AgentDB_Handler_Mgr(); + if (da_err != DACI_SUCCESS) { + return INIT_COMMON_DB_FAIL; + } + + da_err = DACI_Open_Agent(); + if (da_err != DACI_SUCCESS) { + return INIT_COMMON_DB_FAIL; + } + + da_err = DACI_Create_Agent_Default_Table(); + if (da_err != DACI_SUCCESS) { + return INIT_COMMON_DB_FAIL; + } + + return INIT_SUCCESS; +} + +static INIT_ERROR __process_ID_Provider(xmlNode *idProvider_node) +{ + char *code_str = __getChildNodeContent(idProvider_node, "Code"); + char *max_id_str = __getChildNodeContent(idProvider_node, "MaxID"); + char *page_size_str = __getChildNodeContent(idProvider_node, "PageSize"); + + unsigned int code = atoi(code_str); + unsigned int id_max = atoi(max_id_str); + unsigned int log2_page_size = atoi(page_size_str); + + id_provider_error_t error = id_persistent_provider_create(code, id_max, log2_page_size); + if (error == ID_PROVIDER_OK) { + FW_LOGV("Done id_persistent_provider_create : %d", error); + } + + return INIT_SUCCESS; +} + +static INIT_ERROR __process_Event(xmlNode *event_node) +{ + char *event_key = __getChildNodeContent(event_node, "Event-Key"); + char *event_configfile = __getChildNodeContent(event_node, "Event-Config"); + xmlChar *run_eventHandler = (xmlChar *)__getChildNodeContent(event_node, "RunEventHandler"); + + EVENT_ERROR event_err = set_EventSpec_from_ConfigFile(event_key, event_configfile); + if (event_err != EVENT_SUCCESS) { + FW_LOGE("Fail Load event config"); + return INIT_EVENT_FAIL; + } else { + FW_LOGI("Success Load event config"); + } + + if (__compareUCharwithChar(run_eventHandler, "1")) { + unsigned long int thread_id; + event_err = run_Event_Handler(&thread_id); + if (event_err != EVENT_SUCCESS) { + FW_LOGE("Failed to run_Event_Handler()"); + return INIT_EVENT_FAIL; + } + } + + return INIT_SUCCESS; +} + +static INIT_ERROR __process_Noti(xmlNode *event_node) +{ + char *noti_key = __getChildNodeContent(event_node, "Noti-Key"); + char *noti_configfile = __getChildNodeContent(event_node, "Noti-Config"); + + EVENT_ERROR event_err = set_NotiSpec_from_ConfigFile(noti_key, noti_configfile); + if (event_err != EVENT_SUCCESS) { + FW_LOGE("Fail Load noti config : %s", noti_configfile); + return INIT_EVENT_FAIL; + } else { + FW_LOGI("Success Load noti config"); + } + + return INIT_SUCCESS; +} + +static INIT_ERROR __process_PlugIn(xmlNode *plugInMgr_node) +{ + xmlNode *domain_node = plugInMgr_node->children; + while (domain_node != 0) { + if (domain_node->type == XML_ELEMENT_NODE) { + const xmlChar *domain_name = xmlGetProp(domain_node, (xmlChar *)"name"); + FW_LOGV("Domain : %s =====================", domain_name); + + xmlNode *plugIn_node = domain_node->children; + while (plugIn_node != 0) { + if (plugIn_node->type == XML_ELEMENT_NODE) { + PlugIn_Info_t plugIn_Info; + + char *plugIn_ID = __getChildNodeContent(plugIn_node, "ID"); + char *plugIn_path = __getChildNodeContent(plugIn_node, "Path"); + + plugIn_Info.plugIn_id = atoi(plugIn_ID); + + PLUGIN_ERROR plugIn_error; + plugIn_Info.plugIn_handle = load_PlugIn(plugIn_path, &plugIn_error); + if (plugIn_error != PLUGIN_SUCCESS) { + FW_LOGE("load_PlugIn Failed [%s]", plugIn_path); + return INIT_PLUGIN_FAIL; + } + + FW_LOGV("plugIn_ID : %d", plugIn_Info.plugIn_id); + FW_LOGV("plugIn_Path : %s", plugIn_path); + + if (__compareUCharwithChar(domain_name, "DataConnector")) { + PlugIn_DataConnector plugIn_dc; + char *dataConverter = __getChildNodeContent(plugIn_node, "DataConverter-PlugIn"); + char *handleChangeNoti = __getChildNodeContent(plugIn_node, "Handle-ChangeNoti"); + char *useMainLoop = __getChildNodeContent(plugIn_node, "Use-MainLoop"); + + plugIn_dc.plugIn_info = plugIn_Info; + plugIn_dc.data_converter_id = atoi(dataConverter); + plugIn_dc.handle_changenoti = atoi(handleChangeNoti); + plugIn_dc.use_mainloop = atoi(useMainLoop); + plugIn_dc.func_set = getDataConnector_Func_Set(plugIn_Info.plugIn_handle, &plugIn_error); + + registerPlugIn_DataConnector(plugIn_dc); + } else if (__compareUCharwithChar(domain_name, "DataConverter")) { + PlugIn_DataConverter plugIn_dataconverter; + + plugIn_dataconverter.plugIn_info = plugIn_Info; + plugIn_dataconverter.func_Set = getDataConverter_Func_Set(plugIn_Info.plugIn_handle, &plugIn_error); + + registerPlugIn_DataConverter(plugIn_dataconverter); + } else if (__compareUCharwithChar(domain_name, "Account")) { + PlugIn_Account plugIn_acc; + + plugIn_acc.plugIn_info = plugIn_Info; + plugIn_acc.func_Set = getAccount_Func_Set(plugIn_Info.plugIn_handle, &plugIn_error); + + registerPlugIn_Account(plugIn_acc); + } else if (__compareUCharwithChar(domain_name, "NetworkAccess")) { + PlugIn_NetworkAccess plugIn_na; + + plugIn_na.plugIn_info = plugIn_Info; + plugIn_na.func_Set = getNetworkAccess_Func_Set(plugIn_Info.plugIn_handle, &plugIn_error); + + char *use_network = __getChildNodeContent(plugIn_node, "UseNetwork"); + plugIn_na.use_network = atoi(use_network); + + registerPlugIn_NetworkAccess(plugIn_na); + } else if (__compareUCharwithChar(domain_name, "DeviceInfo")) { + PlugIn_DeviceInfo plugIn_device; + + plugIn_device.plugIn_info = plugIn_Info; + plugIn_device.func_Set = getDeviceInfo_Func_Set(plugIn_Info.plugIn_handle, &plugIn_error); + + registerPlugIn_DeviceInfo(plugIn_device); + } else if (__compareUCharwithChar(domain_name, "PlatformMonitor")) { + PlugIn_PlatformMonitor plugIn_pm; + + plugIn_pm.plugIn_info = plugIn_Info; + plugIn_pm.func_Set = getPlatformMonitor_Func_Set(plugIn_Info.plugIn_handle, &plugIn_error); + + registerPlugIn_PlatformMonitor(plugIn_pm); + } + } + + plugIn_node = plugIn_node->next; + } + } + domain_node = domain_node->next; + } + + return INIT_SUCCESS; +} + +static INIT_ERROR __process_PlatformMonitor(xmlNode *platformMonitor_node) +{ + xmlNode *cursor_node = platformMonitor_node->children; + while (cursor_node != 0) { + if (cursor_node->type == XML_ELEMENT_NODE) { + pm_register_data_t *reg_data = NULL; + + const xmlChar *child_name = cursor_node->name; + FW_LOGV("PlatformMonitor function : %s", child_name); + + char *use_str = (char *)xmlGetProp(cursor_node, (xmlChar *)"use"); + char *mainloop_str = (char *)xmlGetProp(cursor_node, (xmlChar *)"mainloop"); + int use_function = atoi(use_str); + int use_main_loop = atoi(mainloop_str); + int pm_plugin_id = get_PlatformMonitor_PlugIn_Id(); + + if (pm_plugin_id == 0) { + return INIT_PM_FAIL; + } + + if (__compareUCharwithChar(child_name, "NetworkStat")) { + if (use_function) { + SetCallBack_NetworkStatus setCallBack_NetStatus = getFunction_PlatformMonitor_SetCallBack_NetworkStatus(pm_plugin_id); + SetCallBack_NetworkAllCancel setCallBack_NetAllCancel = getFunction_PlatformMonitor_SetCallBack_NetworkAllCancel(pm_plugin_id); + setCallBack_NetStatus(handle_Network_Status); + setCallBack_NetAllCancel(handle_Network_All_Cancel); + + Init_Network_Status_Noti_Handler pFunc_Init_Network_Stat = getFunction_PlatformMonitor_Init_Network_Status_Noti_Handler(pm_plugin_id); + if (pFunc_Init_Network_Stat == 0) { + FW_LOGE("cannot get pFunc_Init_Network_Stat !!"); + return INIT_PM_FAIL; + } + + if (use_main_loop) { + FW_LOGV("register_Callback2MainLoop( Init_Network_Stat ) !!"); + register_Callback2MainLoop(pFunc_Init_Network_Stat, 0); + } else { + pFunc_Init_Network_Stat(0); + } + } + } else if (__compareUCharwithChar(child_name, "SAN")) { + if (use_function) { + Init_Syncml_SAN_Noti_Handler pFunc_Init_SAN = getFunction_PlatformMonitor_Init_Syncml_SAN_Noti_Handler(pm_plugin_id); + if (pFunc_Init_SAN == 0) { + FW_LOGE("cannot get pFunc_Init_SAN !!"); + return INIT_PM_FAIL; + } + + if (use_main_loop) { + FW_LOGV("register_Callback2MainLoop( pFunc_Init_SAN ) !!"); + register_Callback2MainLoop(pFunc_Init_SAN, 0); + } else { + pFunc_Init_SAN(0); + } + } + } else if (__compareUCharwithChar(child_name, "ALARM")) { + if (use_function) { + const char *pkg_name = __getChildNodeContent(cursor_node, "Pkg-Name"); + + Init_Alarm_Noti_Handler pFunc_Init_Alarm = getFunction_PlatformMonitor_Init_Alarm_Noti_Handler(pm_plugin_id); + if (pFunc_Init_Alarm == 0) { + FW_LOGE("cannot get pFunc_Init_Alarm !!"); + return INIT_PM_FAIL; + } + + reg_data = (pm_register_data_t *) calloc(1, sizeof(pm_register_data_t)); + if (reg_data == NULL) { + FW_LOGE("calloc pm_register_data_t fail !!"); + return INIT_PM_FAIL; + } + + if (pkg_name != NULL) { + FW_LOGV("pkg_name : %s", pkg_name); + reg_data->pkg_name = strdup(pkg_name); + } + + if (use_main_loop) { + FW_LOGV("register_Callback2MainLoop( pFunc_Init_Alarm ) !!"); + register_Callback2MainLoop(pFunc_Init_Alarm, (void *)reg_data); + } else { + pFunc_Init_Alarm((void *)reg_data); + } + } + } else { + FW_LOGE("Not Supported Platform Function : %s", child_name); + } + } + + cursor_node = cursor_node->next; + } + + return INIT_SUCCESS; +} + +static char *__getChildNodeContent(xmlNode *parent_node, const char *node_name) +{ + if (parent_node == 0 || node_name == 0) { + return 0; + } + + xmlNode *cursor_node = parent_node->children; + + while (cursor_node != 0) { + if (cursor_node->type == XML_ELEMENT_NODE) { + const xmlChar *compare_name = cursor_node->name; + if (__compareUCharwithChar(compare_name, node_name)) { + return (char *)xmlNodeGetContent(cursor_node); + } + } + cursor_node = cursor_node->next; + } + + return 0; +} + +static int __compareUCharwithChar(const xmlChar *str, const char *str2) +{ + if (str == 0 || str2 == 0) { + return 0; + } + + return xmlStrEqual(str, (const xmlChar *)str2); +} diff --git a/framework/src/NetworkAccess/IN_NA_FW_Callbacks.c b/framework/src/NetworkAccess/IN_NA_FW_Callbacks.c new file mode 100644 index 0000000..903b915 --- /dev/null +++ b/framework/src/NetworkAccess/IN_NA_FW_Callbacks.c @@ -0,0 +1,119 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Seokgil Kang + */ + +#include "Utility/fw_log.h" +#include "NetworkAccess/IN_NA_FW_Callbacks.h" +#include "NetworkAccess/IN_NA_Session_Manager.h" +#include "PlugIn/PlugIn_NetworkAccess.h" + +#define LOG_TAG "AF_NACI" + +int handle_Network_Status(int na_plugIn_id, int fw_network_status, int fw_network_type, char *proxy, char *ip) +{ + FW_LOGV("Start !!"); + + int err = set_network_info(na_plugIn_id, fw_network_status, fw_network_type, proxy, ip); + if (err != 1) { + FW_LOGE("set_network_info() is fail !!"); + return err; + } else { + FW_LOGV("set_network_info() is success !!"); + } + + FW_LOGV("End !!"); + + return err; +} + +int handle_Network_All_Cancel(int na_plugIn_id) +{ + FW_LOGV("Start !!"); + + int res = 1; + GList *session_list = NULL; + + int err = get_all_session(&session_list); + if (err != 1) { + FW_LOGE("get_all_session() is fail !!"); + return -1; + } else { + FW_LOGV("get_all_session() is success !!"); + } + + Cancel_Message pFunc_Cancel_Message = getFunction_NetworkAccess_Cancel_Message(na_plugIn_id); + + if (pFunc_Cancel_Message == 0) { + FW_LOGV("[%s] cannot get pFunc !!\n", __func__); + } + + if (session_list != NULL) { + GList *iter = NULL; + void *session = NULL; + + for (iter = session_list; iter != NULL; iter = g_list_next(iter)) { + session = (void *)(iter->data); + + if (session != NULL) { + FW_LOGV("session : %d", session); + err = pFunc_Cancel_Message(session); + + if (err != 1) { + FW_LOGE("cancel message() is fail !!"); + return -1; + } else { + FW_LOGV("cancel message() is success !!"); + } + } else { + FW_LOGE("session is NULL !!"); + return -1; + } + } + } else { + FW_LOGE("session_list is NULL !!"); + } + + err = remove_all_session_info(1); + + if (err != 1) { + FW_LOGE("remove_all_session_info() is fail !!"); + return -1; + } else { + FW_LOGV("remove_all_session_info() success !!"); + } + + FW_LOGV("End !!"); + + return res; +} diff --git a/framework/src/NetworkAccess/IN_NA_Session_Manager.c b/framework/src/NetworkAccess/IN_NA_Session_Manager.c new file mode 100755 index 0000000..63459f5 --- /dev/null +++ b/framework/src/NetworkAccess/IN_NA_Session_Manager.c @@ -0,0 +1,948 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Seokgil Kang + */ + +#include +#include "NetworkAccess/IN_NA_Session_Manager.h" + +#include "Utility/fw_sequential_id_provider.h" +#include "Utility/fw_log.h" + +#include "PlugIn/PlugIn_NetworkAccess.h" + +#define MAX_ID_CNT 1000 + +#define LOG_TAG "AF_NA_SM" + +static NA_Session_Manager session_manager; +static id_provider_t *pid_provider; + +static int remove_all_session(int na_plugIn_id); +static int create_all_session(int na_plugIn_id); +static void set_ip_n_proxy(char *ip, char *proxy); +static int change_all_session_info(int na_plugIn_id); + +void init_session_manager() +{ + FW_LOGV("Start !!"); + + session_manager.session_info_list = NULL; + session_manager.ip = NULL; + session_manager.proxy = NULL; + session_manager.fw_network_status = NETWORK_UNKNOWN; + session_manager.fw_network_type = NETWORK_NONE; + + pid_provider = id_provider_create(MAX_ID_CNT, 12, true); + + FW_LOGV("End !!"); +} + +void destroy_session_manager() +{ + FW_LOGV("Start !!"); + + int err = remove_all_session_info(0); + if (err != 1) { + FW_LOGE("remove_all_session_info() fail !!"); + /* todo : exception handling */ + } else { + FW_LOGV("remove_all_session_info() success !!"); + } + + if (session_manager.ip != NULL) { + free(session_manager.ip); + } + FW_LOGV("free ip address !!"); + + if (session_manager.proxy != NULL) { + free(session_manager.proxy); + } + FW_LOGV("free proxy !!"); + + session_manager.fw_network_status = NETWORK_UNKNOWN; + session_manager.fw_network_type = NETWORK_NONE; + FW_LOGV("clear network info !!"); + + id_provider_destroy(pid_provider); + FW_LOGV("id_provider_destroy() success !!"); + + FW_LOGV("End !!"); +} + +int create_session_info(void **session) +{ + FW_LOGV("Start !!"); + + int res = 1; + NA_Session_Info *session_info; + + /* memory alloc - session_info */ + session_info = (NA_Session_Info *) calloc(1, sizeof(NA_Session_Info)); + if (session_info == NULL) { + FW_LOGE("session_info calloc fail !!"); + return -1; + } + FW_LOGV("session_info calloc success !!"); + + session_info->msg = (void *)calloc(1, sizeof(session_info->msg)); + session_info->id = (char *)calloc(1, sizeof(session_info->id)); + session_info->password = (char *)calloc(1, sizeof(session_info->password)); + + session_info->session = (void *)calloc(1, sizeof(session_info->session)); + *session = session_info->session; + + /* append session_info to session_info_list */ + session_manager.session_info_list = g_list_append(session_manager.session_info_list, session_info); + FW_LOGV("append session_info"); + + FW_LOGV("End !!"); + + return res; +} + +int provide_session_id(unsigned int *session_id) +{ + FW_LOGV("Start !!"); + + id_provider_error_t id_error = ID_PROVIDER_OK; + int res = 1; + + /* check session validation */ + + /* generate session id */ + id_error = id_provider_provide_id(pid_provider, session_id); + if (id_error == ID_PROVIDER_NOT_ENOUGH_ID) { + FW_LOGE("provided session id is full !!"); + /* todo : reset MAX_ID_CNT & re-generate */ + return -1; + } + FW_LOGV("session id : %d", *session_id); + + /* add session & session_id to session_info */ + ((NA_Session_Info *) ((g_list_last(session_manager.session_info_list))->data))->session_id = *session_id; + FW_LOGV("add session_id success !!"); + + FW_LOGV("End !!"); + + return res; +} + +int get_session(unsigned int session_id, void **session) +{ + FW_LOGV("Start !!"); + + int res = 1; + + GList *iter = NULL; + NA_Session_Info *iter_data; + + /* find same session_id in session_info_list */ + for (iter = session_manager.session_info_list; iter != NULL; iter = g_list_next(iter)) { + iter_data = NULL; + if (((NA_Session_Info *) (iter->data))->session_id != -1) { + if (((NA_Session_Info *) (iter->data))->session_id == session_id) { + iter_data = (NA_Session_Info *) (iter->data); + FW_LOGV("find session_id : %d", session_id); + break; + } + } else { + FW_LOGE("invalid session_id : -1 !!"); + res = -1; + /* todo : exception handling */ + } + } + + if (iter_data != NULL) { + *session = ((NA_Session_Info *) iter_data)->session; + + FW_LOGV("get_session() is success !!"); + } else { + FW_LOGE("iter_data is NULL !!"); + FW_LOGE("not exist session_id ( %d ) in session_info_list !!", session_id); + res = -1; + /* todo : exception handling */ + } + + FW_LOGV("End !!"); + + return res; +} + +int set_session(unsigned int session_id, void *session) +{ + FW_LOGV("Start !!"); + + int res = 1; + + GList *iter = NULL; + NA_Session_Info *iter_data; + + /* find same session_id in session_info_list */ + for (iter = session_manager.session_info_list; iter != NULL; iter = g_list_next(iter)) { + iter_data = NULL; + if (((NA_Session_Info *) (iter->data))->session_id != -1) { + if (((NA_Session_Info *) (iter->data))->session_id == session_id) { + iter_data = (NA_Session_Info *) (iter->data); + FW_LOGV("find session_id : %d", session_id); + break; + } + } else { + FW_LOGE("invalid session_id : -1 !!"); + res = -1; + /* todo : exception handling */ + } + } + + if (iter_data != NULL) { + iter_data->session = session; + FW_LOGV("iter_data->session : %d", iter_data->session); + + FW_LOGV("set_session() is success !!"); + } else { + FW_LOGE("iter_data is NULL !!"); + FW_LOGE("not exist session_id ( %d ) in session_info_list !!", session_id); + res = -1; + /* todo : exception handling */ + } + + FW_LOGV("End !!"); + + return res; +} + +FW_NETWORK_STATUS get_network_status() +{ + return session_manager.fw_network_status; +} + +int set_network_status(FW_NETWORK_STATUS network_status) +{ + int res = 1; + session_manager.fw_network_status = network_status; + return res; +} + +FW_NETWORK_TYPE get_network_type() +{ + return session_manager.fw_network_type; +} + +char *get_proxy() +{ + return session_manager.proxy; +} + +int get_msg(unsigned int session_id, void **msg) +{ + FW_LOGV("Start !!"); + + int res = 1; + + GList *iter = NULL; + NA_Session_Info *iter_data; + + /* find same session_id in session_info_list */ + for (iter = session_manager.session_info_list; iter != NULL; iter = g_list_next(iter)) { + iter_data = NULL; + if (((NA_Session_Info *) (iter->data))->session_id != -1) { + if (((NA_Session_Info *) (iter->data))->session_id == session_id) { + iter_data = (NA_Session_Info *) (iter->data); + FW_LOGV("find session_id : %d", session_id); + break; + } + } else { + FW_LOGE("invalid session_id : -1 !!"); + res = -1; + /* todo : exception handling */ + } + } + + if (iter_data != NULL) { + *msg = ((NA_Session_Info *) iter_data)->msg; + + FW_LOGV("get_msg() is success !!"); + } else { + FW_LOGE("iter_data is NULL !!"); + FW_LOGE("not exist session_id ( %d ) in session_info_list !!", session_id); + res = -1; + /* todo : exception handling */ + } + + FW_LOGV("End !!"); + + return res; +} + +int get_timeout(unsigned int session_id, int *timeout) +{ + FW_LOGV("Start !!"); + + int res = 1; + + GList *iter = NULL; + NA_Session_Info *iter_data; + + /* find same session_id in session_info_list */ + for (iter = session_manager.session_info_list; iter != NULL; iter = g_list_next(iter)) { + iter_data = NULL; + if (((NA_Session_Info *) (iter->data))->session_id != -1) { + if (((NA_Session_Info *) (iter->data))->session_id == session_id) { + iter_data = (NA_Session_Info *) (iter->data); + FW_LOGV("find session_id : %d", session_id); + break; + } + } else { + FW_LOGE("invalid session_id : -1 !!"); + res = -1; + /* todo : exception handling */ + } + } + + if (iter_data != NULL) { + *timeout = ((NA_Session_Info *) iter_data)->timeout; + FW_LOGV("timeout : %d", *timeout); + + FW_LOGV("get_timeout() is success !!"); + } else { + FW_LOGE("iter_data is NULL !!"); + FW_LOGE("not exist session_id ( %d ) in session_info_list !!", session_id); + res = -1; + /* todo : exception handling */ + } + + FW_LOGV("End !!"); + + return res; +} + +int set_timeout(unsigned int session_id, int timeout) +{ + FW_LOGV("Start !!"); + + int res = 1; + + GList *iter = NULL; + NA_Session_Info *iter_data; + + /* find same session_id in session_info_list */ + for (iter = session_manager.session_info_list; iter != NULL; iter = g_list_next(iter)) { + iter_data = NULL; + if (((NA_Session_Info *) (iter->data))->session_id != -1) { + if (((NA_Session_Info *) (iter->data))->session_id == session_id) { + iter_data = (NA_Session_Info *) (iter->data); + FW_LOGV("find session_id : %d", session_id); + break; + } + } else { + FW_LOGE("invalid session_id : -1 !!"); + res = -1; + /* todo : exception handling */ + } + } + + if (iter_data != NULL) { + ((NA_Session_Info *) iter_data)->timeout = timeout; + FW_LOGV("timeout : %d", ((NA_Session_Info *) iter_data)->timeout); + + FW_LOGV("set_timeout() is success !!"); + } else { + FW_LOGE("iter_data is NULL !!"); + FW_LOGE("not exist session_id ( %d ) in session_info_list !!", session_id); + res = -1; + /* todo : exception handling */ + } + + FW_LOGV("End !!"); + + return res; +} + +int get_id_n_password(unsigned int session_id, char **id, char **password) +{ + FW_LOGV("Start !!"); + + int res = 1; + + GList *iter = NULL; + NA_Session_Info *iter_data; + + /* find same session_id in session_info_list */ + for (iter = session_manager.session_info_list; iter != NULL; iter = g_list_next(iter)) { + iter_data = NULL; + if (((NA_Session_Info *) (iter->data))->session_id != -1) { + if (((NA_Session_Info *) (iter->data))->session_id == session_id) { + iter_data = (NA_Session_Info *) (iter->data); + FW_LOGV("find session_id : %d", session_id); + break; + } + } else { + FW_LOGE("invalid session_id : -1 !!"); + res = -1; + /* todo : exception handling */ + } + } + + if (iter_data != NULL) { + *id = ((NA_Session_Info *) iter_data)->id; + FW_LOGV("id : %s", *id); + + *password = ((NA_Session_Info *) iter_data)->password; + FW_LOGV("password : %s", *password); + + FW_LOGV("get_id_n_password() is success !!"); + } else { + FW_LOGE("iter_data is NULL !!"); + FW_LOGE("not exist session_id ( %d ) in session_info_list !!", session_id); + res = -1; + /* todo : exception handling */ + } + + FW_LOGV("End !!"); + + return res; +} + +int set_id_n_password(unsigned int session_id, char *id, char *password) +{ + FW_LOGV("Start !!"); + + int res = 1; + + GList *iter = NULL; + /* NA_Session_Info *iter_data; */ + + /* find same session_id in session_info_list */ + for (iter = session_manager.session_info_list; iter != NULL; iter = g_list_next(iter)) { + /* iter_data = NULL; */ + if (iter->data != NULL) { + if (((NA_Session_Info *) (iter->data))->session_id != -1) { + if (((NA_Session_Info *) (iter->data))->session_id == session_id) { + FW_LOGV("find session_id : %d", session_id); + + if ((iter->data) != NULL) { + ((NA_Session_Info *) (iter->data))->id = strdup(id); + FW_LOGV("id : %s", ((NA_Session_Info *) (iter->data))->id); + ((NA_Session_Info *) (iter->data))->password = strdup(password); + FW_LOGV("password : %s", ((NA_Session_Info *) (iter->data))->password); + + FW_LOGV("set_id_n_password() is success !!"); + } else { + FW_LOGE("iter_data is NULL !!"); + FW_LOGE("not exist session_id ( %d ) in session_info_list !!", session_id); + res = -1; + } + break; + } + } else { + FW_LOGE("invalid session_id : -1 !!"); + /*res = -1;*/ + return -1; + /* todo : exception handling */ + } + } else { + FW_LOGE("iter->data is NULL !!"); + /*res = -1;*/ + return -1; + /* todo : exception handling */ + } + } + +/* if (iter_data != NULL) { + ((NA_Session_Info *) iter_data)->id = strdup(id); + FW_LOGV("id : %s", ((NA_Session_Info *) iter_data)->id); + + ((NA_Session_Info *) iter_data)->password = strdup(password); + FW_LOGV("password : %s", ((NA_Session_Info *) iter_data)->password); + + FW_LOGV("set_id_n_password() is success !!"); + } else { + FW_LOGE("iter_data is NULL !!"); + FW_LOGE("not exist session_id ( %d ) in session_info_list !!", session_id); + res = -1; + todo : exception handling + } */ + + FW_LOGV("End !!"); + + return res; +} + +int get_all_session(GList **session_list) +{ + FW_LOGV("Start !!"); + + int res = 1; + + if (session_manager.session_info_list != NULL) { + GList *iter = NULL; + NA_Session_Info *iter_data; + + for (iter = session_manager.session_info_list; iter != NULL; iter = g_list_next(iter)) { + iter_data = NULL; + iter_data = ((NA_Session_Info *) (iter->data)); + + if (iter_data != NULL) { + FW_LOGV("session : %d", iter_data->session); + *session_list = g_list_append(*session_list, (void *)(iter_data->session)); + } else { + FW_LOGE("iter_data is NULL !!"); + return -1; + /* todo : exception handling */ + } + } + } else { + FW_LOGE("session_info_list is NULL !!"); + return -1; + /* todo : exception handling */ + } + + FW_LOGV("End !!"); + + return res; +} + +int remove_session_info(unsigned int session_id, int flag) +{ + FW_LOGV("Start !!"); + + int res = 1; + + GList *iter = NULL; + NA_Session_Info *iter_data; + + /* find same session_id in session_info_list */ + for (iter = session_manager.session_info_list; iter != NULL; iter = g_list_next(iter)) { + iter_data = NULL; + if (((NA_Session_Info *) (iter->data))->session_id != -1) { + if (((NA_Session_Info *) (iter->data))->session_id == session_id) { + iter_data = (NA_Session_Info *) (iter->data); + FW_LOGV("find session_id : %d", session_id); + break; + } + } else { + FW_LOGE("invalid session_id : -1 !!"); + res = -1; + /* todo : exception handling */ + } + } + + /* remove session_info */ + if (iter_data != NULL) { + session_manager.session_info_list = g_list_remove(session_manager.session_info_list, iter_data); + + if (flag == 0) { + if (((NA_Session_Info *) (iter_data))->session != NULL) + free(((NA_Session_Info *) iter_data)->session); + } + if (((NA_Session_Info *) iter_data)->msg != NULL) + free(((NA_Session_Info *) iter_data)->msg); + + if (((NA_Session_Info *) iter_data)->id != NULL) + free(((NA_Session_Info *) iter_data)->id); + + if (((NA_Session_Info *) iter_data)->password != NULL) + free(((NA_Session_Info *) iter_data)->password); + + int err = id_provider_delete_id(pid_provider, session_id); + if (err != ID_PROVIDER_OK) { + FW_LOGE("id_provider_delete_id() is fail !!"); + res = -1; + /* todo : exception handling */ + } + + free((NA_Session_Info *) iter_data); + + FW_LOGV("remove_session_info() is success !!"); + } else { + FW_LOGE("iter_data is NULL !!"); + FW_LOGE("not exist session_id ( %d ) in session_info_list !!", session_id); + res = -1; + /* todo : exception handling */ + } + + FW_LOGV("End !!"); + + return res; +} + +int remove_all_session_info(int flag) +{ + FW_LOGV("Start !!"); + + int res = 1; + + if (session_manager.session_info_list != NULL) { + GList *iter = NULL; + NA_Session_Info *iter_data; + + for (iter = session_manager.session_info_list; iter != NULL;) { + iter_data = NULL; + iter_data = ((NA_Session_Info *) (iter->data)); + iter = g_list_next(iter); + session_manager.session_info_list = g_list_remove(session_manager.session_info_list, iter_data); + + if (iter_data != NULL) { + if (flag == 0) { + if (((NA_Session_Info *) iter_data)->session != NULL) + free(((NA_Session_Info *) iter_data)->session); + } + if (((NA_Session_Info *) iter_data)->msg != NULL) + free(((NA_Session_Info *) iter_data)->msg); + + if (((NA_Session_Info *) iter_data)->id != NULL) + free(((NA_Session_Info *) iter_data)->id); + + if (((NA_Session_Info *) iter_data)->password != NULL) + free(((NA_Session_Info *) iter_data)->password); + + int err = id_provider_delete_id(pid_provider, ((NA_Session_Info *) iter_data)->session_id); + if (err != ID_PROVIDER_OK) { + FW_LOGE("id_provider_delete_id() is fail !!"); + res = -1; + /* todo : exception handling */ + } + + ((NA_Session_Info *) iter_data)->timeout = 0; + + free((NA_Session_Info *) iter_data); + } + } + + g_list_free(session_manager.session_info_list); + session_manager.session_info_list = NULL; + } else { + FW_LOGE("session_info_list is NULL !!"); + res = -1; + /* todo : exception handling */ + } + FW_LOGV("clear session_info_list !!"); + + FW_LOGV("End !!"); + + return res; +} + +int set_network_info(int na_plugIn_id, int net_status, int net_type, char *proxy, char *ip) +{ + FW_LOGV("Start !!"); + + int res = 1; + + FW_LOGV("network status : %d", net_status); + FW_LOGV("network type : %d", net_type); + FW_LOGV("ip : %s", ip); + FW_LOGV("proxy : %s", proxy); + + /* set network status */ + session_manager.fw_network_status = net_status; + + /* set network type */ + session_manager.fw_network_type = net_type; + + /* + * proxy 와 ip setting이 처음인지 판단하여 비교하는 부분 수행할 것인지 결정 + * => session_info_list가 NULL이면 처음으로 판단 + */ + if (session_manager.session_info_list == NULL) { /* or g_list_length(session_manager.session_info_list) == 0 */ + /* set ip & proxy */ + set_ip_n_proxy(ip, proxy); + } else { + /* + * session_info가 하나라도 존재할 경우, + * 기존 data와 비교(ip, proxy)하여 처리 + * - 기존 data와 다를 경우, 모든 session의 재설정 필요 + * - NULL check !! + */ + if ((net_status == NETWORK_ON) && ((net_type == NETWORK_3G_ON) || (net_type == NETWORK_WIFI_ON) || (net_type == NETWORK_WIFI_3G_ON))) { + /* ip */ + if ((session_manager.ip != NULL) && (ip != NULL)) { + if (!strcmp(session_manager.ip, ip)) { + FW_LOGV("same ip : do nothing !!"); + } else { + FW_LOGV("different ip : change all session !!"); + + /* set ip & proxy */ + set_ip_n_proxy(ip, proxy); + + /* change all session info */ + int err = change_all_session_info(na_plugIn_id); + if (err != 1) { + FW_LOGE("change_all_session_info() is fail !!"); + return -1; + /* todo : exception handling */ + } else { + FW_LOGV("change_all_session_info() is success !!"); + } + } + } else if (((session_manager.ip == NULL) && (ip != NULL)) || ((session_manager.ip != NULL) && (ip == NULL))) { + FW_LOGV("different ip : change all session !!"); + + /* set ip & proxy */ + set_ip_n_proxy(ip, proxy); + + /* change all session info */ + int err = change_all_session_info(na_plugIn_id); + if (err != 1) { + FW_LOGE("change_all_session_info() is fail !!"); + return -1; + /* todo : exception handling */ + } else { + FW_LOGV("change_all_session_info() is success !!"); + } + } else { /* if ((session_manager.ip == NULL) && (ip == NULL)) { */ + FW_LOGV("same ip : do nothing !!"); + } + + /* proxy */ + if ((session_manager.proxy != NULL) && (proxy != NULL)) { + if (!strcmp(session_manager.proxy, proxy)) { + FW_LOGV("same proxy : do nothing !!"); + } else { + FW_LOGV("different proxy : change all session !!"); + + /* set ip & proxy */ + set_ip_n_proxy(ip, proxy); + + /* change all session info */ + int err = change_all_session_info(na_plugIn_id); + if (err != 1) { + FW_LOGE("change_all_session_info() is fail !!"); + return -1; + /* todo : exception handling */ + } else { + FW_LOGV("change_all_session_info() is success !!"); + } + } + } else if (((session_manager.proxy == NULL) && (proxy != NULL)) || ((session_manager.proxy != NULL) && (proxy == NULL))) { + FW_LOGV("different ip : change all session !!"); + + /* set ip & proxy */ + set_ip_n_proxy(ip, proxy); + + /* change all session info */ + int err = change_all_session_info(na_plugIn_id); + if (err != 1) { + FW_LOGE("change_all_session_info() is fail !!"); + return -1; + /* todo : exception handling */ + } else { + FW_LOGV("change_all_session_info() is success !!"); + } + } else { /* if ((session_manager.proxy == NULL) && (proxy == NULL)) { */ + FW_LOGV("same proxy : do nothing !!"); + } + } else { + /* set ip & proxy */ + set_ip_n_proxy(ip, proxy); + } + } + + FW_LOGV("End !!"); + + return res; +} + +static int remove_all_session(int na_plugIn_id) +{ + FW_LOGV("Start !!"); + + int res = 1; + + Cancel_Message pFunc_Cancel_Message = getFunction_NetworkAccess_Cancel_Message(na_plugIn_id); + + if (pFunc_Cancel_Message == 0) { + FW_LOGV("cannot get pFunc !!"); + } + + if (session_manager.session_info_list != NULL) { + GList *iter = NULL; + NA_Session_Info *iter_data; + int err = 0; + + for (iter = session_manager.session_info_list; iter != NULL; iter = g_list_next(iter)) { + iter_data = NULL; + iter_data = ((NA_Session_Info *) (iter->data)); + + if (iter_data != NULL) { + err = pFunc_Cancel_Message(((NA_Session_Info *) iter_data)->session); + if (err != 1) { + FW_LOGE("cancel message fail !!"); + return -1; + /* todo : exception handling */ + } else { + FW_LOGV("cancel message success !!"); + } + iter_data->session = NULL; + + if (((NA_Session_Info *) iter_data)->msg != NULL) { + free(((NA_Session_Info *) iter_data)->msg); + iter_data->msg = NULL; + } + } else { + FW_LOGE("iter_data is NULL !!"); + return -1; + /* todo : exception handling */ + } + } + } else { + FW_LOGE("session_info_list is NULL !!"); + return -1; + /* todo : exception handling */ + } + + FW_LOGV("End !!"); + + return res; +} + +static int create_all_session(int na_plugIn_id) +{ + FW_LOGV("Start !!"); + + int res = 1; + FW_LOGV("protocol_type : %d", na_plugIn_id); + + Open_Connection pFunc_Open_Connection = getFunction_NetworkAccess_Open_Connection(na_plugIn_id); + + if (pFunc_Open_Connection == 0) { + FW_LOGV("[%s] cannot get pFunc !!\n", __func__); + } + + if (session_manager.session_info_list != NULL) { + GList *iter = NULL; + NA_Session_Info *iter_data; + int err = 0; + + for (iter = session_manager.session_info_list; iter != NULL; iter = g_list_next(iter)) { + iter_data = NULL; + iter_data = ((NA_Session_Info *) (iter->data)); + + if (iter_data != NULL) { + err = pFunc_Open_Connection(&iter_data->session, session_manager.proxy, iter_data->timeout); + if (err != 1) { + FW_LOGE("open connection fail !!"); + return -1; + /* todo : exception handling */ + } else { + FW_LOGV("open connection success !!"); + } + } else { + FW_LOGE("iter_data is NULL !!"); + return -1; + /* todo : exception handling */ + } + } + } else { + FW_LOGE("session_info_list is NULL !!"); + return -1; + /* todo : exception handling */ + } + + FW_LOGV("End !!"); + + return res; +} + +static void set_ip_n_proxy(char *ip, char *proxy) +{ + FW_LOGV("Start !!"); + + /* + * check & set proxy info + */ + if ((proxy != NULL) && (strcmp(proxy, "") != 0) && (strstr(proxy, "0.0.0.0") == NULL)) { + FW_LOGV("The proxy host is ( %s )", proxy); + + if ((strstr(proxy, "http://") != NULL) || (strstr(proxy, "https://") != NULL)) { + FW_LOGV("proxy value is complete format !!"); + session_manager.proxy = strdup(proxy); + FW_LOGV("session_manager.proxy : %s", session_manager.proxy); + } else { + FW_LOGV("proxy value is incomplete format !!"); + char FullProxyAddr[100] = { 0, }; + snprintf(FullProxyAddr, sizeof(FullProxyAddr), "http://%s", proxy); + FW_LOGV("fullproxyaddr : %s ( %d )", FullProxyAddr, strlen(FullProxyAddr)); + + session_manager.proxy = strdup(FullProxyAddr); + FW_LOGV("session_manager.proxy : %s", session_manager.proxy); + } + } else { + FW_LOGV("proxy is NULL !!"); + session_manager.proxy = NULL; + FW_LOGV("session_manager.proxy : %s", session_manager.proxy); + } + + /* + * set ip info + */ + if (ip != NULL) { + session_manager.ip = strdup(ip); + FW_LOGV("session_manager.ip : %s", session_manager.ip); + free(ip); + } else { + session_manager.ip = NULL; + FW_LOGV("ip is NULL !!"); + } + + FW_LOGV("End !!"); +} + +static int change_all_session_info(int na_plugIn_id) +{ + FW_LOGV("Start !!"); + + int res = 1; + + /* 1. remove all session */ + int err = remove_all_session(na_plugIn_id); + if (err != 1) { + FW_LOGE("remove_all_session_info() is fail !!"); + return -1; + } else { + FW_LOGV("remove_all_session_info() is success !!"); + } + + /* 2. create all session */ + err = create_all_session(na_plugIn_id); + if (err != 1) { + FW_LOGE("create_all_session() is fail !!"); + return -1; + } else { + FW_LOGV("create_all_session() is success !!"); + } + + FW_LOGV("End !!"); + + return res; +} diff --git a/framework/src/NetworkAccess/NACI.c b/framework/src/NetworkAccess/NACI.c new file mode 100644 index 0000000..90dd817 --- /dev/null +++ b/framework/src/NetworkAccess/NACI.c @@ -0,0 +1,740 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Seokgil Kang + */ + +#include +#include +#include + +#include "Utility/fw_log.h" +#include "NetworkAccess/NACI.h" +#include "NetworkAccess/NA_External.h" +#include "PlugIn/PlugIn_NetworkAccess.h" +#include "FSAPI/FSAPI_operation.h" + +#include "Utility/fw_mainloop.h" + +#include "NetworkAccess/EXT_NA_NetworkStatus.h" + +#include "NetworkAccess/IN_NA_Session_Manager.h" + +#define RETRY_CNT 3 + +#define LOG_TAG "AF_NACI" + +NACI_RESULT NACI_Init(int na_plugIn_id) +{ + FW_LOGV("Start !!"); + + NACI_RESULT res = NACI_SUCCESS; + + init_session_manager(); + + FW_LOGV("End !!"); + + return res; +} + +NACI_RESULT NACI_Open_Connection(int na_plugIn_id, int timeout, unsigned int *session_id) +{ + FW_LOGV("Start !!"); + NACI_RESULT res = NACI_SUCCESS; + void *session = NULL; + + int err = create_session_info(&session); + if (err != 1) { + FW_LOGE("create_session_info() fail !!"); + return NACI_OPEN_CONNECTION_FAIL; + } else { + FW_LOGV("create_session_info() success !!"); + } + + err = provide_session_id(session_id); + if (err != 1) { + FW_LOGE("provide_session_id() fail !!"); + return NACI_OPEN_CONNECTION_FAIL; + } else { + FW_LOGV("provide_session_id() success !!"); + FW_LOGV("session id : %d", *session_id); + } + + err = set_timeout(*session_id, timeout); + if (err != 1) { + FW_LOGE("set_timeout() fail !!"); + return NACI_OPEN_CONNECTION_FAIL; + } else { + FW_LOGV("set_timeout() success !!"); + } + + switch (get_network_status()) { + case NETWORK_UNKNOWN: + case NETWORK_OFF: + { + FW_LOGE("network OFF !!"); + + err = remove_session_info(*session_id, 0); + if (err != 1) { + FW_LOGE("remove_session_info() fail !!"); + } else { + FW_LOGV("remove_session_info() success !!"); + } + return NACI_NETWORK_UNAVAILABLE; + } + break; + case NETWORK_ON: + { + FW_LOGV("network ON !!"); + FW_NETWORK_TYPE fw_net_type = get_network_type(); + if ((fw_net_type == NETWORK_NONE) || (fw_net_type == NETWORK_3G_OFF) || (fw_net_type == NETWORK_WIFI_OFF) || (fw_net_type == NETWORK_WIFI_ON_NOT_CONNECTED)) { + FW_LOGE("network ON but not connected !!"); + + err = remove_session_info(*session_id, 0); + if (err != 1) { + FW_LOGE("remove_session_info() fail !!"); + } else { + FW_LOGV("remove_session_info() success !!"); + } + return NACI_NETWORK_UNAVAILABLE; + } + } + break; + default: + break; + } + + Open_Connection pFunc_Open_Connection = getFunction_NetworkAccess_Open_Connection(na_plugIn_id); + + if (pFunc_Open_Connection == 0) { + FW_LOGE("cannot get pFunc_Open_Connection !!"); + return NACI_OPEN_CONNECTION_FAIL; + } + + err = pFunc_Open_Connection(&session, get_proxy(), timeout); + if (err != 1) { + FW_LOGE("Open_Connection() fail !!"); + return NACI_OPEN_CONNECTION_FAIL; + } else { + FW_LOGV("Open_Connection() success !!"); + } + + err = set_session(*session_id, session); + if (err != 1) { + FW_LOGE("set_session() fail !!"); + return NACI_OPEN_CONNECTION_FAIL; + } else { + FW_LOGV("set_session() success !!"); + } + + FW_LOGV("End !!"); + + return res; +} + +NACI_RESULT NACI_Close_Connection(int na_plugIn_id, unsigned int session_id) +{ + FW_LOGV("Start !!"); + NACI_RESULT res = NACI_SUCCESS; + void *session = NULL; + + if (get_network_status() == NETWORK_ON) { + FW_LOGV("session id : %d", session_id); + int err = get_session(session_id, &session); + if (err != 1) { + FW_LOGV("get session() fail !!"); + return NACI_CLOSE_CONNECTION_FAIL; + } else { + FW_LOGV("get session() success !!"); + } + + Close_Connection pFunc_Close_Connection = getFunction_NetworkAccess_Close_Connection(na_plugIn_id); + + if (pFunc_Close_Connection == 0) { + FW_LOGE("cannot get pFunc_Close_Connection !!"); + return NACI_CLOSE_CONNECTION_FAIL; + } + + err = pFunc_Close_Connection(session); + if (err != 1) { + FW_LOGE("Close_Connection() fail !!"); + return NACI_CLOSE_CONNECTION_FAIL; + } else { + FW_LOGV("Close_Connection() success !!"); + } + + err = remove_session_info(session_id, 1); + if (err != 1) { + FW_LOGE("remove_session_info() fail !!"); + return NACI_CLOSE_CONNECTION_FAIL; + } else { + FW_LOGV("remove_session_info() success !!"); + } + } else { + FW_LOGV("session is already closed !!"); + } + + FW_LOGV("End !!"); + + return res; +} + +NACI_RESULT NACI_Send_Msg(GList *header_info, int na_plugIn_id, char *send_msg, unsigned int send_msg_length, GList **recv_header, unsigned char **recv_msg, unsigned int *recv_msg_length, NACI_SEND_TYPE send_type, unsigned int session_id) +{ + FW_LOGV("Start !!"); + NACI_RESULT res = NACI_SUCCESS; + void *session = NULL; + void *msg = NULL; + int try_again_cnt = 0; + + /* check current network status */ + if (use_Network(na_plugIn_id) == 1) { + res = NACI_Check_Network_Status(0, 1); + if (res == NACI_NETWORK_UNAVAILABLE) { + int err = remove_session_info(session_id, 0); + if (err != 1) { + FW_LOGE("remove_session_info() fail !!"); + } else { + FW_LOGV("remove_session_info() success !!"); + } + return res; + } + } + + /* + * Header Binding + */ + Header_Binding pFunc_Header_Binding = getFunction_NetworkAccess_Header_Binding(na_plugIn_id); + + if (pFunc_Header_Binding == 0) { + FW_LOGE("cannot get pFunc_Header_Binding !!"); + return NACI_HEADER_BINDING_FAIL; + } + + int err = get_msg(session_id, &msg); + if (err != 1) { + FW_LOGE("get_msg() fail !!"); + return NACI_HEADER_BINDING_FAIL; + } else { + FW_LOGV("get_msg() success !!"); + } + + unsigned int recv_msg_size = 0; + + err = pFunc_Header_Binding(header_info, &msg); + if (err != 1) { + FW_LOGE("Header_Binding() fail !!"); + return NACI_HEADER_BINDING_FAIL; + } else { + FW_LOGV("Header_Binding() success !!"); + } + + /* + * Send Message + */ + err = get_session(session_id, &session); + if (err != 1) { + FW_LOGE("get_session() fail !!"); + return NACI_SEND_MSG_FAIL; + } else { + FW_LOGV("get_session() success !!"); + } + + if (send_type == SEND_N_RECEIVE) { + Send_Message pFunc_Send_Message = getFunction_NetworkAccess_Send_Message(na_plugIn_id); + + if (pFunc_Send_Message == 0) { + FW_LOGE("cannot get pFunc_Send_Message !!"); + return NACI_SEND_MSG_FAIL; + } + +send_message: + err = pFunc_Send_Message(session, &msg, send_msg, send_msg_length, &recv_msg_size); + if (err != 1) { + if (err == -408) { /* FIXME : request time-out (temporary) */ + FW_LOGE("request time-out !!"); + return NACI_TIME_OUT_SEND_MSG; + } else if (err == -1) { /* FIXME : cancel message (temporary) */ + FW_LOGV("send message canceled !!"); + FW_LOGV("End !!"); + return NACI_SEND_MSG_CANCEL; + } else if (err == -8) { /* try again - retry 3 times */ + FW_LOGE("send message try again ( %d ) !!", try_again_cnt); + + if (try_again_cnt < RETRY_CNT) { + FW_LOGV("re-make session !!"); + + try_again_cnt++; + + session = NULL; + + Open_Connection pFunc_Open_Connection = getFunction_NetworkAccess_Open_Connection(na_plugIn_id); + if (pFunc_Open_Connection == 0) { + FW_LOGE("cannot get pFunc_Open_Connection !!"); + return NACI_SEND_MSG_TRY_AGAIN; + } + + int timeout = 0; + int er = get_timeout(session_id, &timeout); + if (er != 1) { + FW_LOGE("get_timeout() fail !!"); + return NACI_SEND_MSG_TRY_AGAIN; + } + + err = pFunc_Open_Connection(&session, get_proxy(), timeout); + if (err != 1) { + FW_LOGE("Open_Connection() fail !!"); + return NACI_SEND_MSG_TRY_AGAIN; + } else { + FW_LOGV("Open_Connection() success !!"); + } + + err = set_session(session_id, session); + if (err != 1) { + FW_LOGE("set_session() fail !!"); + return NACI_SEND_MSG_TRY_AGAIN; + } else { + FW_LOGV("set_session() success !!"); + } + + goto send_message; + } else { + FW_LOGE("try again count over 3 times !!"); + FW_LOGE("Send_Messasge() fail !!"); + + return NACI_SEND_MSG_TRY_AGAIN; + } + } else { + FW_LOGE("Send_Message() fail !!"); + return NACI_SEND_MSG_FAIL; + } + } else { + FW_LOGV("Send_Message success !!"); + } + } else if (send_type == JUST_SEND) { + Just_Send_Message pFunc_Just_Send_Message = getFunction_NetworkAccess_Just_Send_Message(na_plugIn_id); + + if (pFunc_Just_Send_Message == 0) { + FW_LOGE("cannot get pFunc_Just_Send_Message !!"); + return NACI_JUST_SEND_MSG_FAIL; + } + + err = pFunc_Just_Send_Message(session, &msg, send_msg, send_msg_length); + if (err != 1) { + FW_LOGE("Just_Send_Message() fail !!"); + return NACI_JUST_SEND_MSG_FAIL; + } else { + FW_LOGV("Just_Send_Message() success !!"); + FW_LOGV("End !!"); + return res; + } + } + + /* + * Header Unbinding + */ + Header_Unbinding pFunc_Header_Unbinding = getFunction_NetworkAccess_Header_Unbinding(na_plugIn_id); + + if (pFunc_Header_Unbinding == 0) { + FW_LOGE("cannot get pFunc_Header_Unbinding !!"); + return NACI_HEADER_UNBINDING_FAIL; + } + + /* + * extract header/body information using message from server + */ + err = pFunc_Header_Unbinding(msg, recv_msg_size, recv_header, recv_msg, recv_msg_length); + if (err != 1) { + FW_LOGE("Header_Unbinding() fail !!"); + return NACI_HEADER_UNBINDING_FAIL; + } else { + FW_LOGV("Header_Unbinding() success !!"); + } + + FW_LOGV("End !!"); + + return res; +} + +NACI_RESULT NACI_Cancel_Msg(int na_plugIn_id, unsigned int session_id) +{ + FW_LOGV("Start !!"); + NACI_RESULT res = NACI_SUCCESS; + void *session = NULL; + + Cancel_Message pFunc_Cancel_Message = getFunction_NetworkAccess_Cancel_Message(na_plugIn_id); + + if (pFunc_Cancel_Message == 0) { + FW_LOGE("cannot get pFunc_Cancel_Message !!"); + } + + int err = get_session(session_id, &session); + if (err != 1) { + FW_LOGE("get_session() fail !!"); + return NACI_CANCEL_MSG_FAIL; + } else { + FW_LOGV("get_session() success !!"); + } + + FW_LOGV("session id : %d", session_id); + err = pFunc_Cancel_Message(session); + if (err != 1) { + FW_LOGE("Cancel_Message() fail !!"); + return NACI_CANCEL_MSG_FAIL; + } else { + FW_LOGV("Cancel_Message() success !!"); + } + + FW_LOGV("End !!"); + + return res; +} + +NACI_RESULT NACI_Destroy() +{ + FW_LOGV("Start !!"); + + NACI_RESULT res = NACI_SUCCESS; + + destroy_session_manager(); + + FW_LOGV("End !!"); + + return res; +} + +NACI_RESULT NACI_Get_Header_Info(int na_plugIn_id, GList *header_info, char *key, char **value) +{ + FW_LOGV("Start !!"); + NACI_RESULT res = NACI_SUCCESS; + + Get_Header_Info pFunc_Get_Header_Info = getFunction_NetworkAccess_Get_Header_Info(na_plugIn_id); + + if (pFunc_Get_Header_Info == 0) { + FW_LOGE("cannot get pFunc_Get_Header_Info !!"); + } + + int err = pFunc_Get_Header_Info(header_info, key, value); + if (err != 1) { + FW_LOGE("Get_Header_Info() fail !!"); + return NACI_GET_HEADER_INFO_FAIL; + } else { + FW_LOGV("Get_Header_Info() success !!"); + } + + FW_LOGV("End !!"); + + return res; +} + +NACI_RESULT NACI_Free_Recv_Header_Info(GList *header_info) +{ + FW_LOGV("Start !!"); + + NACI_RESULT res = NACI_SUCCESS; + + if (header_info != NULL) { + GList *iter = NULL; + common_header_info *iter_data; + + for (iter = header_info; iter != NULL;) { + iter_data = NULL; + iter_data = ((common_header_info *) (iter->data)); + + iter = g_list_next(iter); + header_info = g_list_remove(header_info, iter_data); + + if (iter_data->key != NULL) + free(iter_data->key); + if (iter_data->value != NULL) + free(iter_data->value); + free(iter_data); + } + + g_list_free(header_info); + + FW_LOGV("header_info is free !!"); + } else { + FW_LOGV("header_info is NULL !!"); + } + + FW_LOGV("End !!"); + + return res; +} + +NACI_RESULT NACI_Check_Network_Status(int interval, int retry_cnt) +{ + FW_LOGV("Start !!"); + + NACI_RESULT res = NACI_SUCCESS; + int i = 0; + + for (; i < retry_cnt; i++) { + switch (get_network_status()) { + case NETWORK_UNKNOWN: + case NETWORK_OFF: + { + FW_LOGE("network OFF !!"); + res = NACI_NETWORK_UNAVAILABLE; + } + break; + case NETWORK_ON: + { + FW_LOGV("[%s] network ON \n", __func__); + FW_NETWORK_TYPE fw_net_type = get_network_type(); + if ((fw_net_type == NETWORK_NONE) || (fw_net_type == NETWORK_3G_OFF) || (fw_net_type == NETWORK_WIFI_OFF) || (fw_net_type == NETWORK_WIFI_ON_NOT_CONNECTED)) { + FW_LOGE("network ON but not connected !!"); + res = NACI_NETWORK_UNAVAILABLE; + } else { + res = NACI_SUCCESS; + return res; + } + } + break; + default: + break; + } + sleep(interval); + } + + FW_LOGV("End !!"); + + return res; +} + +NACI_RESULT NACI_Get_Network_Type(int *net_type) +{ + FW_LOGV("Start !!"); + + NACI_RESULT res = NACI_SUCCESS; + + *net_type = get_network_type(); + FW_LOGV("current network type : %d", *net_type); + + FW_LOGV("End !!"); + + return res; +} + +NACI_RESULT NACI_Download_Data(GList *header_info, int na_plugIn_id, unsigned char *download_folder, unsigned int download_start_size, unsigned int download_body_size, unsigned char **out_download_path, NACI_SEND_TYPE send_type, unsigned int session_id) +{ + GList *recv_header_info = 0; + /* char *recvMsg = 0; */ + unsigned char *recvMsg = 0; + unsigned int recvMsg_size = 0; + + unsigned int download_current_size = download_start_size; + /* unsigned int download_total_size = 0; */ + int download_total_size = 0; + char *current_download_range = 0; + char *download_file_name = 0; + + int count = 0; /* for test log */ + NACI_RESULT ret = NACI_SUCCESS; + while (download_total_size == 0 || download_current_size < download_total_size - 1) { + + FW_LOGV("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); + FW_LOGV("############# %d th download", ++count); + FW_LOGV("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); + + /* back up the header list TODO */ + /* GSList *backup_send_head_info_list = 0; */ + GList *backup_send_head_info_list = 0; + GList *iter = NULL; + for (iter = header_info; iter != NULL; iter = g_list_next(iter)) { + common_header_info *header_item_info = (common_header_info *) calloc(1, sizeof(common_header_info)); + if (((common_header_info *) (iter->data))->key != NULL) { + header_item_info->key = strdup(((common_header_info *) (iter->data))->key); + + if (((common_header_info *) (iter->data))->value != NULL) { + header_item_info->value = strdup(((common_header_info *) (iter->data))->value); + } else { + FW_LOGE("key : %s, value is NULL !!", header_item_info->key); + header_item_info->value = 0; + } + + backup_send_head_info_list = g_list_append(backup_send_head_info_list, header_item_info); + } else { + FW_LOGE("key is NULL !!"); + header_item_info->key = 0; + header_item_info->value = 0; + } + + /*backup_send_head_info_list = g_list_append(backup_send_head_info_list, header_item_info);*/ + if (header_item_info->key != NULL) { + if (strcmp(header_item_info->key, "Range") == 0) + FW_LOGV("[Before] key : %s, value : %s", header_item_info->key, header_item_info->value); + } + } + + /* send_msg */ + ret = NACI_Send_Msg(backup_send_head_info_list, na_plugIn_id, 0, 0, &recv_header_info, &recvMsg, &recvMsg_size, send_type, session_id); + if (ret != NACI_SUCCESS) { + FW_LOGE("NACI_Send_Msg() fail"); + ret = NACI_DOWNLOAD_DATA_FAIL; + goto return_part; + } + + FW_LOGV("RecvMSg_Size = %d", recvMsg_size); + FW_LOGV("############# NACI_Send_Msg() success !!"); + + /* get download total size, download current range */ + Get_Data_Download_Info pFunc_Get_Data_Down_Info = getFunction_NetworkAccess_Get_Data_Download_Info(na_plugIn_id); + if (pFunc_Get_Data_Down_Info == 0) { + FW_LOGE("cannot get pFunc_Get_Data_Down_Info !!"); + ret = NACI_DOWNLOAD_DATA_FAIL; + goto return_part; + } + + ret = pFunc_Get_Data_Down_Info(recv_header_info, &download_total_size, ¤t_download_range, &download_file_name); + if (ret != NACI_SUCCESS) { + FW_LOGE("Get_Data_Down_Info() fail !!"); + ret = NACI_DOWNLOAD_DATA_FAIL; + goto return_part; + } + + FW_LOGV("############# Get_Data_Down_Info() success !!"); + if (current_download_range == 0 || download_total_size == 0 || download_file_name == 0) { + FW_LOGE("current_download_range == 0 || download_total_size == 0 || download_file_name == 0"); + ret = NACI_DOWNLOAD_DATA_FAIL; + goto return_part; + } + + FW_LOGV("download_total_size = %d", download_total_size); + FW_LOGV("current_download_range = %s", current_download_range); + FW_LOGV("download_file_name = %s", download_file_name); + + /* download path setting */ + if (*out_download_path == 0) { + *out_download_path = (unsigned char *)g_strdup_printf("%s/%s", download_folder, download_file_name); + FW_LOGV("*out_download_path = %s", *out_download_path); + } + + /* imcrement download count */ + char *del = "-"; + /* int down_size = 0; */ + char *ptr = strtok(current_download_range, del); + if (ptr != 0) { + + int start_size = 0; + int end_size = 0; + + FW_LOGV("start_size = %s", ptr); + start_size = atoi(ptr); + + ptr = strtok(NULL, del); + FW_LOGV("end_size = %s", ptr); + end_size = atoi(ptr); + + FW_LOGV("prev download_current_size = %d", download_current_size); + FW_LOGV("Gap = %d", end_size - start_size); + + download_current_size += (end_size - start_size + 1); + FW_LOGV("after download_current_size = %d", download_current_size); + } + + bool isFinal = false; + if (download_current_size >= download_total_size - 1) + isFinal = true; + + /* set file */ + FW_LOGV("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! RecvMSg_Size = %d", recvMsg_size); + ret = FSAPI_fileAppend((char *)(*out_download_path), (char *)recvMsg, recvMsg_size, false); + if (ret != NACI_SUCCESS) { + FW_LOGE("FSAPI_fileWrite() fail !!"); + ret = NACI_DOWNLOAD_DATA_FAIL; + goto return_part; + } else { + FW_LOGV("############# FSAPI_fileWrite() success !!"); + } + + /* set download total size, download current range */ + Set_Data_Download_Info pFunc_Set_Data_Down_Info = getFunction_NetworkAccess_Set_Data_Download_Info(na_plugIn_id); + if (pFunc_Set_Data_Down_Info == 0) { + FW_LOGE("cannot get pFunc_Set_Data_Down_Info !!"); + ret = NACI_DOWNLOAD_DATA_FAIL; + goto return_part; + } + + char *new_download_range = g_strdup_printf("%d-%d", download_current_size, download_current_size + (download_body_size - 1)); + ret = pFunc_Set_Data_Down_Info(header_info, new_download_range); + if (ret != NACI_SUCCESS) { + FW_LOGE("Set_Data_Down_Info() fail !!"); + ret = NACI_DOWNLOAD_DATA_FAIL; + goto return_part; + } + + FW_LOGV("############# Set_Data_Down_Info() success !!"); + + } + +return_part: + + /* todo : free logic */ + return ret; +} + +NACI_RESULT NACI_Add_Authentication_Info(int na_plugIn_id, char *id, char *password, unsigned int session_id) +{ + FW_LOGV("Start !!"); + NACI_RESULT res = NACI_SUCCESS; + void *session = NULL; + + Add_Authentication_Info pFunc_Add_Authentication_Info = getFunction_NetworkAccess_Add_Authentication_Info(na_plugIn_id); + + if (pFunc_Add_Authentication_Info == 0) { + FW_LOGV("cannot get pFunc_Add_Authentication_Info !!"); + } + + int err = get_session(session_id, &session); + if (err != 1) { + FW_LOGE("get_session() fail !!"); + return NACI_ADD_AUTH_INFO_FAIL; + } else { + FW_LOGV("get_session() success !!"); + } + + FW_LOGV("session id : %d", session_id); + + err = pFunc_Add_Authentication_Info(session, id, password); + if (err != 1) { + FW_LOGE("Add_Authentication_Info() fail !!"); + return NACI_ADD_AUTH_INFO_FAIL; + } else { + FW_LOGV("Add_Authentication_Info() success !!"); + } + + FW_LOGV("End !!"); + + return res; +} diff --git a/framework/src/NetworkAssistant/protocol_binder/protocol_binder.c b/framework/src/NetworkAssistant/protocol_binder/protocol_binder.c new file mode 100755 index 0000000..e621a96 --- /dev/null +++ b/framework/src/NetworkAssistant/protocol_binder/protocol_binder.c @@ -0,0 +1,1116 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * SeongWon Shim + */ + +#include "protocol_binder/protocol_binder_internal.h" +#include "protocol_binder/protocol_binder_util_internal.h" +#include "Utility/fw_log.h" +#include "Utility/fw_assert.h" +#include + +#define LOG_TAG "AF_PB" + +/* internal functions */ + +static PROTOCOL_BINDER_ERROR init_encoder(WBXMLLanguage lang, WBXMLCharsetMIBEnum orig_charset, Encoding enc, WBXMLEncoder **pEncoder) +{ + FW_LOGD("start"); + WBXMLError err = WBXML_OK; + WBXMLEncoder *pOut_encoder = NULL; + + if ((pOut_encoder = wbxml_encoder_create()) == NULL) { + err = PROTOCOL_BINDER_OUT_OF_MEMORY; + goto error_part; + } + + /* set language and orig charset */ + wbxml_encoder_set_lang(pOut_encoder, lang); + wbxml_encoder_set_output_charset(pOut_encoder, orig_charset); + + wbxml_encoder_set_flow_mode(pOut_encoder, true); + wbxml_encoder_set_produce_anonymous(pOut_encoder, true); + + /* ignore whitespaces */ + wbxml_encoder_set_ignore_empty_text(pOut_encoder, true); + wbxml_encoder_set_remove_text_blanks(pOut_encoder, true); + + if (enc == ENCODING_XML) { + wbxml_encoder_set_output_type(pOut_encoder, WBXML_ENCODER_OUTPUT_XML); + } else { + wbxml_encoder_set_output_type(pOut_encoder, WBXML_ENCODER_OUTPUT_WBXML); + WBXMLVersion wbxml_version = get_wbxml_version(enc); + + assert(wbxml_version != WBXML_VERSION_UNKNOWN); + wbxml_encoder_set_wbxml_version(pOut_encoder, wbxml_version); + } + + if (pOut_encoder != NULL) { + *pEncoder = pOut_encoder; + } + + FW_LOGD("ended with pEncoder = %p", pOut_encoder); + + return err; + +error_part: + FW_LOGD("error occurred"); + return err; +} + +static PROTOCOL_BINDER_ERROR build_lookup_tbl_of_binder_function_set(Binder_function_set *pSet) +{ + PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK; + int i; + int cnt = pSet->set_size; + + Binder_function_info *info_array = pSet->info_array; + GHashTable *pProtocol_element_lookup_tbl = NULL; + GHashTable *pProtocol_element_xml_name_lookup_tbl = NULL; + + pProtocol_element_lookup_tbl = g_hash_table_new(g_int_hash, g_int_equal); + if (pProtocol_element_lookup_tbl == NULL) { + err = PROTOCOL_BINDER_OUT_OF_MEMORY; + goto return_part; + } + + pProtocol_element_xml_name_lookup_tbl = g_hash_table_new(g_str_hash, g_str_equal); + if (pProtocol_element_xml_name_lookup_tbl == NULL) { + err = PROTOCOL_BINDER_OUT_OF_MEMORY; + goto return_part; + } + + for (i = 0; i < cnt; i++) { + g_hash_table_insert(pProtocol_element_lookup_tbl, &(info_array[i].protocol_element), &(info_array[i])); + + if (info_array[i].protocol_element_xml_name != NULL) { + g_hash_table_insert(pProtocol_element_xml_name_lookup_tbl, info_array[i].protocol_element_xml_name, &(info_array[i])); + } + } + +return_part: + if (err == PROTOCOL_BINDER_OK) { + pSet->protocol_element_lookup_tbl = pProtocol_element_lookup_tbl; + pSet->protocol_element_xml_name_lookup_tbl = pProtocol_element_xml_name_lookup_tbl; + } else { + if (pProtocol_element_lookup_tbl != NULL) { + g_hash_table_destroy(pProtocol_element_lookup_tbl); + } + } + return err; +} + +static PROTOCOL_BINDER_ERROR lookup_binder_function(Binder_function_set *pBinder_function_set, Protocol_Element protocol_element, char *protocol_element_xml_name, Binder_function_info **pFunctionInfo) +{ + FW_LOGD("started : protocol_element = %d, protocol_element_xml_name = %s\n", protocol_element, protocol_element_xml_name); + + PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK; + GHashTable *lookup_tbl = NULL; + void *key = NULL; + if (pBinder_function_set == NULL) { + err = PROTOCOL_BINDER_BINDER_FUNCTION_SET_NOT_DEFINED; + goto return_part; + } + + if (protocol_element_xml_name != NULL) { + key = protocol_element_xml_name; + lookup_tbl = pBinder_function_set->protocol_element_xml_name_lookup_tbl; + } else { + key = &protocol_element; + lookup_tbl = pBinder_function_set->protocol_element_lookup_tbl; + } + + if (lookup_tbl == NULL) { + err = PROTOCOL_BINDER_BINDER_FUNCTION_SET_LOOKUP_TBL_NOT_DEFINED; + goto return_part; + } + + Binder_function_info *binder_function_info = g_hash_table_lookup(lookup_tbl, key); + if (binder_function_info == NULL) { + err = PROTOCOL_BINDER_INVALID_PROTOCOL_ELEMENT; + goto return_part; + } + +return_part: + if (err == PROTOCOL_BINDER_OK) { + *pFunctionInfo = binder_function_info; + } + + FW_LOGD("ended\n"); + return err; +} + +static void remove_contents_binder_function_set(Binder_function_set *pBinder_function_set) +{ + if (pBinder_function_set != NULL) { + if (pBinder_function_set->info_array != NULL) { + free(pBinder_function_set->info_array); + pBinder_function_set->info_array = NULL; + } + if (pBinder_function_set->protocol_element_lookup_tbl != NULL) { + g_hash_table_destroy(pBinder_function_set->protocol_element_lookup_tbl); + pBinder_function_set->protocol_element_lookup_tbl = NULL; + } + if (pBinder_function_set->protocol_element_xml_name_lookup_tbl != NULL) { + g_hash_table_destroy(pBinder_function_set->protocol_element_xml_name_lookup_tbl); + pBinder_function_set->protocol_element_xml_name_lookup_tbl = NULL; + } + } +} + +/*static char *duplicate_byte_stream(char *byte_stream, unsigned int byte_stream_len) +{ + char *ret_byte_stream = malloc(byte_stream_len + 1); + if (ret_byte_stream == NULL) { + goto return_part; + } + + memcpy(ret_byte_stream, byte_stream, byte_stream_len * sizeof(char)); + ret_byte_stream[byte_stream_len] = '\0'; +return_part: + return ret_byte_stream; +}*/ + +/* external functions */ + +/* binder function set */ + +void free_binder_function_set(Binder_function_set *pBinder_function_set) +{ + if (pBinder_function_set != NULL) { + remove_contents_binder_function_set(pBinder_function_set); + + free(pBinder_function_set); + } +} + +PROTOCOL_BINDER_ERROR init_binder_function_set(unsigned int binder_function_cnt, Binder_function_info *info_array, Binder_function_set **pBinder_function_set) +{ + FW_LOGD("start\n"); + PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK; + + Binder_function_set *pSet = (Binder_function_set *)calloc(1, sizeof(Binder_function_set)); + if (pSet == NULL) { + err = PROTOCOL_BINDER_OUT_OF_MEMORY; + goto return_part; + } + + pSet->set_size = binder_function_cnt; + pSet->info_array = (Binder_function_info *)malloc(binder_function_cnt * sizeof(Binder_function_info)); + if (pSet->info_array == NULL) { + err = PROTOCOL_BINDER_OUT_OF_MEMORY; + goto return_part; + } + memcpy(pSet->info_array, info_array, binder_function_cnt * sizeof(Binder_function_info)); + + /* build lookup table */ + err = build_lookup_tbl_of_binder_function_set(pSet); + if (err != PROTOCOL_BINDER_OK) { + goto return_part; + } + +return_part: + if (err != PROTOCOL_BINDER_OK) { + FW_LOGD("error occurred\n"); + if (pSet != NULL) { + free_binder_function_set(pSet); + } + } else { + *pBinder_function_set = pSet; + FW_LOGD("end with return pBinder_function_set = %p\n", pSet); + } + return err; +} + +/* + * @brief ignore previous binder function set built and rebuild binder function set with new function informations + * @param[in] pBinder_functino_set binder function set + * @param[in] binder_function_info_cnt number of new binder function informations + * @param[in] info_array_to_be_added array of new binder function informations + * @return protocol binder error + */ +PROTOCOL_BINDER_ERROR reset_binder_function_set(Binder_function_set *pBinder_function_set, unsigned int new_binder_function_info_cnt, Binder_function_info *new_info_array) +{ + FW_LOGV("start\n"); + PROTOCOL_BINDER_ERROR pb_error = PROTOCOL_BINDER_OK; + Binder_function_set *pSet = pBinder_function_set; + Binder_function_set backup_set; + + /* make backup set */ + memcpy(&backup_set, pSet, sizeof(Binder_function_set)); + + /* reset contents */ + pSet->set_size = new_binder_function_info_cnt; + pSet->info_array = (Binder_function_info *)malloc(new_binder_function_info_cnt * sizeof(Binder_function_info)); + if (pSet->info_array == NULL) { + pb_error = PROTOCOL_BINDER_OUT_OF_MEMORY; + goto error_part; + } + memcpy(pSet->info_array, new_info_array, new_binder_function_info_cnt * sizeof(Binder_function_info)); + + /* build lookup table */ + pb_error = build_lookup_tbl_of_binder_function_set(pSet); + if (pb_error != PROTOCOL_BINDER_OK) { + goto error_part; + } + + /* remove previous binder set */ + remove_contents_binder_function_set(&backup_set); + + FW_LOGD("success\n"); + return pb_error; + +error_part: + if (pSet->info_array != NULL) { + free(pSet->info_array); + } + + /* restore pBinder_function_set */ + memcpy(pSet, &backup_set, sizeof(Binder_function_set)); + + FW_LOGD("error occurred with pb_error = %d\n", pb_error); + return pb_error; +} + +/* + * @brief add more function informations to binder function set + * @note you should notice that if same value of protocol_element or protocol_element_xml_name are + * already existed in binder function set, then previous information is removed from binder function set + * @param[in] pBinder_functino_set binder function set + * @param[in] binder_function_info_cnt number of new binder function informations to be added + * @param[in] info_array_to_be_added array of new binder function informations to be added + * @return protocol binder error + */ +PROTOCOL_BINDER_ERROR add_binder_function_set(Binder_function_set *pBinder_function_set, unsigned int binder_function_info_cnt, Binder_function_info *info_array_to_be_added) +{ + FW_LOGV("start"); + PROTOCOL_BINDER_ERROR pb_error = PROTOCOL_BINDER_OK; + Binder_function_set *pSet = pBinder_function_set; + unsigned int prev_set_size = pSet->set_size; + Binder_function_info *prev_info_array = pSet->info_array; + + /* reset set_size and info_array */ + unsigned int new_set_size = prev_set_size + binder_function_info_cnt; + Binder_function_info *new_info_array = (Binder_function_info *)malloc(new_set_size * sizeof(Binder_function_info)); + if (new_info_array == NULL) { + pb_error = PROTOCOL_BINDER_OUT_OF_MEMORY; + goto error_part; + } + + memcpy(new_info_array, prev_info_array, prev_set_size * sizeof(Binder_function_info)); + + memcpy(new_info_array + prev_set_size, info_array_to_be_added, binder_function_info_cnt * sizeof(Binder_function_info)); + + /* update binder function set */ + pb_error = reset_binder_function_set(pSet, new_set_size, new_info_array); + if (pb_error != PROTOCOL_BINDER_OK) { + goto error_part; + } + + FW_LOGV("success"); + return pb_error; + +error_part: + if (new_info_array != NULL) { + free(new_info_array); + } + + FW_LOGV("error with pb_error = %d", pb_error); + return pb_error; +} + +/* protocol binder */ + +protocol_binder *protocol_binder_init(protocol_binder *pBinder, Protocol protocol, Protocol_Option_Ptr option, Encoding enc, bool encode_xml_header, bool use_strtbl, bool produce_anonymous, bool use_flow_mode, GList *restrict_params, Restrict_Condition_Checker_callback restrict_condition_checker, Binder_function_set *pBinder_function_set) +{ + FW_LOGD("started with input pBinder = %p\n", pBinder); + PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK; + + /* TODO : validation input parameters */ + + if (pBinder == NULL) { + pBinder = (protocol_binder *)malloc(sizeof(protocol_binder)); + } + + if (pBinder != NULL) { + memset(pBinder, 0x00, sizeof(protocol_binder)); + /* TODO : check validity of input parameters */ + pBinder->protocol = protocol; + pBinder->option = option; + pBinder->enc = enc; + pBinder->encode_xml_header = encode_xml_header; + pBinder->use_strtbl = use_strtbl; + pBinder->produce_anonymous = produce_anonymous; + pBinder->use_flow_mode = use_flow_mode; + pBinder->restrict_params = restrict_params; + pBinder->restrict_condition_checker = restrict_condition_checker; + pBinder->binder_functions = pBinder_function_set; + + WBXMLCharsetMIBEnum orig_charset = WBXML_PARSER_DEFAULT_CHARSET; + + WBXMLLanguage lang = get_wbxml_language(protocol); + FW_LOGV("lang = %d\n", lang); + + pBinder->lang_table = (WBXMLLangEntry *) wbxml_tables_get_table(lang); + /* SVACE : NULL check routine added. */ + if (pBinder->lang_table == NULL) { + FW_LOGE("language table is not found\n"); + goto error_part; + } + pBinder->prev_lang_table = NULL; + + FW_LOGD("Binder has follwing information\n" + "protocol = %d, encoding = %d, string table option = %d, " "flow mode option = %d, lang = %d, lang table pointer = %p\n" "lang table detail info (langID = %d, Public ID = (xmlPublicID : %s, xmlRootElt : %s, xmlDTD : %s))", protocol, enc, use_strtbl, use_flow_mode, lang, pBinder->lang_table, pBinder->lang_table->langID, pBinder->lang_table->publicID->xmlPublicID, pBinder->lang_table->publicID->xmlRootElt, pBinder->lang_table->publicID->xmlDTD); + + if (use_flow_mode) { + err = init_encoder(lang, orig_charset, enc, &(pBinder->wbxml_encoder)); + if (err != PROTOCOL_BINDER_OK) { + goto error_part; + } + } else { + pBinder->tree = wbxml_tree_create(lang, orig_charset); + if (pBinder->tree == NULL) { + goto error_part; + } + + pBinder->tree_node_stack = NULL; + } + } + + FW_LOGD("ended with pBinder = %p\n", pBinder); + + return pBinder; + +error_part: + FW_LOGE("error occurred\n"); + /* TODO */ + return NULL; +} + +PROTOCOL_BINDER_ERROR protocol_binder_append(protocol_binder *pBinder, Protocol_Element protocol_element, Content_Ptr pContent) +{ + FW_LOGD("started"); + PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK; + WBXMLError wbxml_err = WBXML_OK; + + if (pBinder == NULL) { + err = PROTOCOL_BINDER_NOT_DEFINED; + goto return_part; + } + Binder_function_set *pBinder_function_set = pBinder->binder_functions; + Binder_Object_converter_function binder_object_converter_function = NULL; + Binder_function_info *pFunctionInfo = NULL; + + WBXMLTreeNode *wbxml_tree_node = NULL; + WBXMLTreeNode *current_parent_tree_node = NULL; + bool is_terminal = false; + bool is_start_tag = false; + + if (pBinder_function_set == NULL) { + err = PROTOCOL_BINDER_BINDER_FUNCTION_SET_NOT_DEFINED; + goto return_part; + } + + /* get binder_function by content_id */ + err = lookup_binder_function(pBinder_function_set, protocol_element, NULL, &pFunctionInfo); + if (err != PROTOCOL_BINDER_OK) { + err = PROTOCOL_BINDER_APPEND_INVALID_PROTOCOL_ELEMENT; + goto return_part; + } + binder_object_converter_function = pFunctionInfo->binder_object_converter_function; + is_start_tag = (pFunctionInfo->protocol_element_xml_name[0] != '/'); + is_terminal = pFunctionInfo->isTerminal; + pBinder->is_current_node_terminal = is_terminal; + + if (is_start_tag) { + /* execute binder_object_converter_function */ + if (binder_object_converter_function != NULL) { + FW_LOGD("calling binder_object_converter_function"); + err = binder_object_converter_function(pBinder, pContent, &wbxml_tree_node); + if (err != PROTOCOL_BINDER_OK) { + FW_LOGE("error occurred during calling binder_object_converter_function"); + goto return_part; + } + + if (wbxml_tree_node == NULL) { + FW_LOGE("after calling binder_object_converter_function, we get NULL wbxml_tree_node"); + err = PROTOCOL_BINDER_UNKNOWN_ERROR; /* TODO : define new err code */ + goto return_part; + } + FW_LOGD("after calling binder_object_converter_function, we get wbxml_tree_node = %p", wbxml_tree_node); + + if (pBinder->use_flow_mode) { + /* since encoder has bug with has content flag, we do below meaningless work */ + if (!is_terminal && wbxml_tree_node->children == NULL) { + /* TODO : error handling */ + WBXMLTreeNode *text_node = wbxml_tree_node_create_text(NULL, 0); + wbxml_tree_node_add_child(wbxml_tree_node, text_node); + } + + /* TODO : error handling */ + wbxml_err = wbxml_encoder_encode_node_with_elt_end(pBinder->wbxml_encoder, wbxml_tree_node, is_terminal); + if (wbxml_err != WBXML_OK) { + err = PROTOCOL_BINDER_UNKNOWN_ERROR; + FW_LOGE("wbxml_encoder_encode_node_with_elt_end failed. err(%d) : %s", wbxml_err, wbxml_errors_string(wbxml_err)); + goto return_part; + } + + if (is_terminal) { + if (wbxml_tree_node != NULL) { + FW_LOGD("free wbxml tree node when non terminal case"); + wbxml_tree_node_destroy_all(wbxml_tree_node); + wbxml_tree_node = NULL; + } + } + } else { + /* append node to wbxml dom tree */ + if (pBinder->tree_node_stack != NULL) { + current_parent_tree_node = (WBXMLTreeNode *)(pBinder->tree_node_stack->data); + } + + WB_BOOL add_node_success = wbxml_tree_add_node(pBinder->tree, current_parent_tree_node, wbxml_tree_node); + if (!add_node_success) { + /* TODO : error handling */ + FW_LOGD("wbxml_tree_add_node failed\n"); + err = PROTOCOL_BINDER_UNKNOWN_ERROR; /* TODO : define new err code */ + goto return_part; + } + } + + /* save wbxml_tree_node in stack */ + if (!is_terminal) { + /* TODO : error handling */ + pBinder->tree_node_stack = g_slist_prepend(pBinder->tree_node_stack, wbxml_tree_node); + } + } + } else { + if (pBinder->tree_node_stack == NULL) { + FW_LOGD("end tag not exist. failed\n"); + err = PROTOCOL_BINDER_UNKNOWN_ERROR; /* TODO : define new err code */ + goto return_part; + } + + /* pop one tree node from stack */ + GSList *tmp_node = pBinder->tree_node_stack; + if (pBinder->use_flow_mode) { + /* TODO : error handling */ + WBXMLTreeNode *current_parent_node = (WBXMLTreeNode *)(tmp_node->data); + wbxml_encoder_encode_raw_elt_end(pBinder->wbxml_encoder, current_parent_node, true); + if (current_parent_node != NULL) { + FW_LOGD("free wbxml tree node when pop in tree node stack"); + wbxml_tree_node_destroy_all(current_parent_node); + } + } + + pBinder->tree_node_stack = g_slist_next(pBinder->tree_node_stack); + g_slist_free_1(tmp_node); + } + +return_part: + if (err != PROTOCOL_BINDER_OK) { + FW_LOGD("error occurred"); + if (wbxml_tree_node != NULL) { + wbxml_tree_node_destroy_all(wbxml_tree_node); + } + } else { + FW_LOGD("end : protocol_element_xml_name = %s\n", pFunctionInfo->protocol_element_xml_name); + } + return err; +} + +void protocol_binder_terminate(protocol_binder *pBinder) +{ + FW_LOGD("start"); + if (pBinder != NULL) { + FW_LOGD("pBinder != NULL"); + if (pBinder->binder_functions != NULL) { + FW_LOGD("free binder functions"); + free_binder_function_set(pBinder->binder_functions); + } + + if (pBinder->use_flow_mode) { + if (pBinder->wbxml_encoder != NULL) { + FW_LOGD("free wbxml_encoder"); + wbxml_encoder_destroy(pBinder->wbxml_encoder); + } + } else { + if (pBinder->tree != NULL) { + FW_LOGD("free tree"); + wbxml_tree_destroy(pBinder->tree); + } + } + + if (pBinder->tree_node_stack != NULL) { + FW_LOGD("free tree node stack"); + g_slist_free(pBinder->tree_node_stack); + } + + free(pBinder); + } + FW_LOGD("end"); +} + +PROTOCOL_BINDER_ERROR protocol_binder_get_stream(protocol_binder *pBinder, char **byte_stream, unsigned int *byte_stream_size) +{ + FW_LOGD("start\n"); + PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK; + unsigned char *temp_byte_stream = NULL; + unsigned int temp_byte_stream_size = 0; + + WBXMLError wbxml_err = WBXML_OK; + + if (pBinder == NULL) { + err = PROTOCOL_BINDER_NOT_DEFINED; + goto return_part; + } + + if (byte_stream == NULL || byte_stream_size == NULL) { + err = PROTOCOL_BINDER_INVALID_INPUT_PARAMETER; + goto return_part; + } + + FW_LOGD("flow mode = %d, encoding = %d\n", pBinder->use_flow_mode, pBinder->enc); + + /* flow mode */ + if (pBinder->use_flow_mode) { + wbxml_err = wbxml_encoder_get_output(pBinder->wbxml_encoder, &temp_byte_stream, &temp_byte_stream_size); + /* TODO : how to apply produce_anonymous */ + /* not in flow mode */ + } else { + WBXMLTree *tree = pBinder->tree; + + if (pBinder->enc == ENCODING_XML) { + WBXMLGenXMLParams params = { WBXML_GEN_XML_INDENT, WBXML_LANG_UNKNOWN, WBXML_CHARSET_UNKNOWN, 4, FALSE }; + wbxml_err = wbxml_tree_to_xml(tree, &temp_byte_stream, &temp_byte_stream_size, ¶ms); + } else { + WBXMLGenWBXMLParams params; + + /* set encoding language */ + params.wbxml_version = get_wbxml_version(pBinder->enc); + params.keep_ignorable_ws = FALSE; + params.use_strtbl = pBinder->use_strtbl; + params.produce_anonymous = pBinder->produce_anonymous; + + wbxml_err = wbxml_tree_to_wbxml(tree, &temp_byte_stream, &temp_byte_stream_size, ¶ms); + } + } + + if (wbxml_err != WBXML_OK) { + FW_LOGE("wbxml err = (%d) %s\n", wbxml_err, wbxml_errors_string(wbxml_err)); + err = PROTOCOL_BINDER_UNKNOWN_ERROR; + goto return_part; + } + + if (pBinder->enc == ENCODING_XML && !(pBinder->encode_xml_header)) { + /* remove xml header */ + temp_byte_stream_size = remove_xml_header((char *)temp_byte_stream, temp_byte_stream_size); + } + + /* for debugging printing result in xml */ + if (pBinder->enc != ENCODING_XML) { + char *xml_result = NULL; + unsigned int xml_result_len = 0; + protocol_binder_get_xml_for_debugging(pBinder, &xml_result, &xml_result_len); + + FW_LOGD("============= binder wbxml logging start ==============\n"); + FW_LOGD("wbxml_conv_wbxml2xml_withlen err = (%d) %s\n", err, wbxml_errors_string(err)); + if (wbxml_err == WBXML_OK) { + FW_LOGD("wbxml : %s\n", temp_byte_stream); + FW_LOGD("wbxml len : %u\n", temp_byte_stream_size); + FW_LOGD("converted xml : %s\n", xml_result); + FW_LOGD("converted xml len : %u\n", xml_result_len); + } + FW_LOGD("============= binder wbxml logging end ==============\n"); + + if (xml_result != NULL) { + free(xml_result); + } + } else { + FW_LOGD("============= binder xml logging start ==============\n"); + FW_LOGD("xml : %s\n", temp_byte_stream); + FW_LOGD("xml len : %u\n", temp_byte_stream_size); + FW_LOGD("============= binder xml logging end ==============\n"); + } + +return_part: + if (err != PROTOCOL_BINDER_OK) { + if (temp_byte_stream != NULL) { + free(temp_byte_stream); + } + } else { + *byte_stream = (char *)temp_byte_stream; + *byte_stream_size = temp_byte_stream_size; + } + + FW_LOGD("end\n"); + return err; +} + +PROTOCOL_BINDER_ERROR protocol_binder_get_xml_for_debugging(protocol_binder *pBinder, char **xml, unsigned int *xml_size) +{ + FW_LOGD("start"); + PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK; + unsigned char *wbxml = NULL; + unsigned int wbxml_len = 0; + WBXMLError wbxml_err = WBXML_OK; + + unsigned char *out_xml = NULL; + unsigned int out_xml_len = 0; + WBXMLConvWBXML2XML *conv = NULL; + WBXMLGenXMLParams xml_params = { WBXML_GEN_XML_INDENT, WBXML_LANG_UNKNOWN, WBXML_CHARSET_UNKNOWN, 4, TRUE }; + + if (pBinder == NULL) { + err = PROTOCOL_BINDER_NOT_DEFINED; + goto return_part; + } + + if (pBinder->enc == ENCODING_XML) { + err = PROTOCOL_BINDER_NOT_SUPPORT_FOR_XML_ENCODING; + goto return_part; + } + + FW_LOGD("flow mode = %d\n", pBinder->use_flow_mode); + + if (pBinder->use_flow_mode) { + wbxml_err = wbxml_encoder_get_output(pBinder->wbxml_encoder, &wbxml, &wbxml_len); + if (wbxml_err != WBXML_OK) { + FW_LOGE("wbxml_encoder_get_output error occurred.\n"); + goto wbxml_error_part; + } + + wbxml_err = wbxml_conv_wbxml2xml_create(&conv); + if (wbxml_err != WBXML_OK){ + FW_LOGE("wbxml_conv_wbxml2xml_create error occurred.\n"); + goto wbxml_error_part; + } + + wbxml_conv_wbxml2xml_set_gen_type(conv, xml_params.gen_type); + wbxml_conv_wbxml2xml_set_language(conv,xml_params.lang); + wbxml_conv_wbxml2xml_set_charset(conv, xml_params.charset); + wbxml_conv_wbxml2xml_set_indent(conv, xml_params.indent); + if (xml_params.keep_ignorable_ws) + wbxml_conv_wbxml2xml_enable_preserve_whitespaces(conv); + + wbxml_err = wbxml_conv_wbxml2xml_run(conv, wbxml, wbxml_len, &out_xml, &out_xml_len); + if (wbxml_err != WBXML_OK){ + FW_LOGE("wbxml_conv_wbxml2xml_run error occurred.\n"); + goto wbxml_error_part; + } + wbxml_conv_wbxml2xml_destroy(conv); + + } else { + WBXMLTree *tree = pBinder->tree; + wbxml_err = wbxml_tree_to_xml(tree, &out_xml, &out_xml_len, &xml_params); + } + +wbxml_error_part: + if (wbxml_err != WBXML_OK) { + FW_LOGE("wbxml err = (%d) %s\n", err, wbxml_errors_string(err)); + err = PROTOCOL_BINDER_UNKNOWN_ERROR; + goto return_part; + } + +return_part: + if (wbxml != NULL) { + free(wbxml); + } + + if (err == PROTOCOL_BINDER_OK) { + *xml = (char *)out_xml; + *xml_size = out_xml_len; + } else { + if (out_xml != NULL) { + free(out_xml); + } + } + + return err; +} + +PROTOCOL_BINDER_ERROR protocol_binder_get_stream_size(protocol_binder *pBinder, unsigned int *byte_stream_size) +{ + PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK; + char *out_byte_stream = NULL; + unsigned int out_byte_stream_size = 0; + + if (pBinder->use_flow_mode) { + out_byte_stream_size = wbxml_encoder_get_output_len(pBinder->wbxml_encoder); + } else { + err = protocol_binder_get_stream(pBinder, &out_byte_stream, &out_byte_stream_size); + if (out_byte_stream != NULL) { + free(out_byte_stream); + } + } + + if (err == PROTOCOL_BINDER_OK) { + *byte_stream_size = out_byte_stream_size; + } + + return err; +} + +PROTOCOL_BINDER_ERROR protocol_binder_get_encoding(protocol_binder *pBinder, Encoding * enc) +{ + PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK; + + if (pBinder == NULL) { + err = PROTOCOL_BINDER_NOT_DEFINED; + goto return_part; + } + + *enc = pBinder->enc; + +return_part: + return err; +} + +/* reverse protocol binder */ + +PROTOCOL_BINDER_ERROR reverse_protocol_binder_init(char *byte_stream, unsigned int byte_stream_len, Decoding dec, Protocol * pProtocol, Binder_function_set *pBinder_function_set, void *user_data, Reverse_protocol_binder **ppBinder) +{ + PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK; + Reverse_protocol_binder *pBinder = NULL; + WBXMLTree *wbxml_tree = NULL; + Protocol input_protocol = PROTOCOL_UNKNOWN; + if (pProtocol != NULL) { + input_protocol = *pProtocol; + if (!validate_protocol(input_protocol)) { + err = PROTOCOL_BINDER_INVALID_INPUT_PARAMETER; + goto return_part; + } + } + Protocol output_protocol = PROTOCOL_UNKNOWN; + WBXMLLanguage input_wbxml_lang = get_wbxml_language(input_protocol); + + switch (dec) { + case DECODING_WBXML: + { + err = get_wbxml_tree_from_wbxml(byte_stream, byte_stream_len, input_wbxml_lang, &wbxml_tree); + if (err != PROTOCOL_BINDER_OK) { + goto return_part; + } +#ifndef NDEBUG + print_wbxml_dom_in_xml(wbxml_tree); +#endif + } + break; + case DECODING_XML: + { + err = get_wbxml_tree_from_xml(byte_stream, byte_stream_len, input_wbxml_lang, &wbxml_tree); + if (err != PROTOCOL_BINDER_OK) { + goto return_part; + } + } + break; + default: + err = PROTOCOL_BINDER_UNKNOWN_ENCODING; + goto return_part; + } + + assert(wbxml_tree != NULL); + assert(wbxml_tree->lang != NULL); + /* SVACE : wbxml_tree->lang NULL check added. */ + + output_protocol = get_protocol_from_wbxml_lang(wbxml_tree->lang->langID); + + /* allocation Reverse_protocol_binder */ + pBinder = (Reverse_protocol_binder *)calloc(1, sizeof(Reverse_protocol_binder)); + if (pBinder == NULL) { + err = PROTOCOL_BINDER_OUT_OF_MEMORY; + goto return_part; + } + + /* set property */ + pBinder->protocol = output_protocol; + pBinder->dec = dec; + pBinder->binder_functions = pBinder_function_set; + pBinder->user_data = user_data; + + pBinder->tree = wbxml_tree; + pBinder->tree_stack = NULL; + pBinder->current_tree_node = NULL; + pBinder->current_tree_node_first_visit = true; + + pBinder->no_tree_node_visited = true; + pBinder->all_tree_node_visited = false; + +return_part: + if (err != PROTOCOL_BINDER_OK) { + if (pBinder == NULL) { + if (wbxml_tree != NULL) { + wbxml_tree_destroy(wbxml_tree); + } + } + if (pBinder != NULL) { + reverse_protocol_binder_terminate(pBinder); + pBinder = NULL; + } + } else { + *ppBinder = pBinder; + if (pProtocol != NULL) + *pProtocol = output_protocol; + } + return err; +} + +void reverse_protocol_binder_set_user_data(Reverse_protocol_binder *pBinder, void *user_data) +{ + pBinder->user_data = user_data; +} + +void *reverse_protocol_binder_get_user_data(Reverse_protocol_binder *pBinder) +{ + return pBinder->user_data; +} + +PROTOCOL_BINDER_ERROR reverse_protocol_binder_next(Reverse_protocol_binder *pBinder, Protocol_Element * protocol_element, char **protocol_element_name, Content_Ptr *pContent) +{ + FW_LOGD("start\n"); + PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK; + + char *ret_protocol_element = NULL; + + WBXMLTreeNode *current_tree_node = pBinder->current_tree_node; + bool first_visit = pBinder->current_tree_node_first_visit; + + Binder_function_info *pFunction_info = NULL; + Reverse_Binder_Object_converter_function reverse_binder_object_converter_function = NULL; + bool is_element_node = false; + bool is_tree_node = false; + char *current_tree_node_protocol_element_name = NULL; + char *search_element_name = NULL; + + /* if all node already visited, then "PROTOCOL_BINDER_HAS_NO_MORE_ELEMENT" error occurs */ + if (pBinder->all_tree_node_visited) { + err = PROTOCOL_BINDER_HAS_NO_MORE_ELEMENT; + goto return_part; + } + + /* find next element which has callback */ + do { + /* get next tree node (order : depth-first) */ + if (pBinder->no_tree_node_visited) { + current_tree_node = pBinder->tree->root; + pBinder->no_tree_node_visited = false; + } else { + + is_tree_node = has_wbxml_node_same_type(current_tree_node, WBXML_TREE_TREE_NODE); + if (!is_tree_node) { + current_tree_node = get_next_node_of_element_node(current_tree_node, &first_visit); + + /* get subtree node when all nodes of subtree are visited */ + if (current_tree_node == NULL && pBinder->tree_stack != NULL) { + first_visit = false; + current_tree_node = (WBXMLTreeNode *)(pBinder->tree_stack->data); + continue; + } + } else { + /* if root tree has sub-tree which has different language, + * then save it to tree stack */ + if (first_visit) { + /* push sub-tree into tree stack */ + pBinder->tree_stack = g_slist_prepend(pBinder->tree_stack, current_tree_node); + } else { + /* pop sub-tree from tree stack */ + pBinder->tree_stack = g_slist_delete_link(pBinder->tree_stack, pBinder->tree_stack); /* remove the head */ + } + current_tree_node = get_next_node_of_tree_node(current_tree_node, &first_visit); + } + } + + /* break when no next node to get */ + if (current_tree_node == NULL) + break; + + is_element_node = has_wbxml_node_same_type(current_tree_node, WBXML_TREE_ELEMENT_NODE); + if (!is_element_node) { + continue; + } + + /* get callback */ + err = get_xml_name_from_element_wbxml_node(current_tree_node, ¤t_tree_node_protocol_element_name); + assert(err == PROTOCOL_BINDER_OK); + + assert(current_tree_node_protocol_element_name != NULL); + if (first_visit) { + FW_LOGD("currently traversing element name = %s first\n", current_tree_node_protocol_element_name); + } else { + FW_LOGD("currently traversing element name = %s second\n", current_tree_node_protocol_element_name); + } + + Binder_function_set *binder_functions = pBinder->binder_functions; + + if (first_visit) { + search_element_name = strdup(current_tree_node_protocol_element_name); + } else { + unsigned int protocol_element_name_len = strlen(current_tree_node_protocol_element_name); + search_element_name = malloc(protocol_element_name_len + 2); + if (search_element_name == NULL) { + err = PROTOCOL_BINDER_OUT_OF_MEMORY; + goto return_part; + } + + search_element_name[0] = '/'; + memcpy(search_element_name + 1, current_tree_node_protocol_element_name, protocol_element_name_len); + search_element_name[protocol_element_name_len + 1] = '\0'; + } + if (search_element_name == NULL) { + err = PROTOCOL_BINDER_OUT_OF_MEMORY; + goto return_part; + } + + err = lookup_binder_function(binder_functions, 0, search_element_name, &pFunction_info); + + assert(search_element_name != NULL); + FW_LOGD("search_element_name = %s\n", search_element_name); + free(search_element_name); + FW_LOGD("search_element_name free success\n"); + search_element_name = NULL; + + if (err != PROTOCOL_BINDER_OK) { + continue; /* TODO */ + } + + reverse_binder_object_converter_function = pFunction_info->reverse_binder_object_converter_function; + + } while (reverse_binder_object_converter_function == NULL); + + /* all xml tags are visited case */ + if (current_tree_node == NULL) { + err = PROTOCOL_BINDER_HAS_NO_MORE_ELEMENT; + goto return_part; + } + /* get next callback case */ + else { + assert(reverse_binder_object_converter_function != NULL); + + /* logging */ + FW_LOGD("reverse callback call at <%s>\n", pFunction_info->protocol_element_xml_name); + + /* reverse convert */ + err = reverse_binder_object_converter_function(pBinder, current_tree_node, pContent); + if (err != PROTOCOL_BINDER_OK) { + goto return_part; + } + + /* set protocol element, protocol element name */ + ret_protocol_element = strdup(pFunction_info->protocol_element_xml_name); + if (ret_protocol_element == NULL) { + err = PROTOCOL_BINDER_OUT_OF_MEMORY; + goto return_part; + } + + err = PROTOCOL_BINDER_OK; + goto return_part; + } + +return_part: + FW_LOGD("return part : err = %d\n", err); + if (err == PROTOCOL_BINDER_OK) { + pBinder->current_tree_node = current_tree_node; + pBinder->current_tree_node_first_visit = first_visit; + + *protocol_element = pFunction_info->protocol_element; + if (protocol_element_name != NULL) { + *protocol_element_name = ret_protocol_element; + } else { + if (ret_protocol_element != NULL) + free(ret_protocol_element); + } + } else { + if (ret_protocol_element != NULL) { + free(ret_protocol_element); + } + } + return err; +} + +void reverse_protocol_binder_terminate(Reverse_protocol_binder *pBinder) +{ + if (pBinder != NULL) { + if (pBinder->tree != NULL) { + wbxml_tree_destroy(pBinder->tree); + pBinder->tree = NULL; + } + if (pBinder->tree_stack != NULL) { + g_slist_free(pBinder->tree_stack); + pBinder->tree_stack = NULL; + } + if (pBinder->current_tree_node != NULL) { + pBinder->current_tree_node = NULL; /* DO NOT FREE THIS NODE */ + } + if (pBinder->binder_functions != NULL) { + pBinder->binder_functions = NULL; /* DO NOT FREE THIS */ + } + + free(pBinder); + } +} + +PROTOCOL_BINDER_ERROR reverse_protocol_binder_get_xml_for_debugging(Reverse_protocol_binder *pBinder, char **xml, unsigned int *xml_size) +{ + FW_LOGD("reverse_protocol_binder_xml_print started\n"); + PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK; + unsigned char *out_xml = NULL; + unsigned int out_xml_len = 0; + + if (pBinder == NULL) { + err = PROTOCOL_BINDER_NOT_DEFINED; + goto return_part; + } + if (pBinder->tree == NULL) { + err = PROTOCOL_BINDER_INIT_REQUIRED_OR_INVALID_BINDER; + goto return_part; + } + + if (pBinder->dec == DECODING_XML) { + err = PROTOCOL_BINDER_NOT_SUPPORT_FOR_XML_DECODING; + goto return_part; + } + + WBXMLGenXMLParams params = { WBXML_GEN_XML_INDENT, WBXML_LANG_UNKNOWN, WBXML_CHARSET_UNKNOWN, 4, FALSE }; + WBXMLError wbxml_err = wbxml_tree_to_xml(pBinder->tree, &out_xml, &out_xml_len, ¶ms); + if (wbxml_err != WBXML_OK) { + err = PROTOCOL_BINDER_UNKNOWN_ERROR; + goto return_part; + } + +return_part: + if (err == PROTOCOL_BINDER_OK) { + *xml = (char *)out_xml; + *xml_size = out_xml_len; + } + + FW_LOGD("reverse_protocol_binder_xml_print ended, err = %d\n", err); + return err; +} diff --git a/framework/src/NetworkAssistant/protocol_binder/protocol_binder_util.c b/framework/src/NetworkAssistant/protocol_binder/protocol_binder_util.c new file mode 100755 index 0000000..a7ca4a1 --- /dev/null +++ b/framework/src/NetworkAssistant/protocol_binder/protocol_binder_util.c @@ -0,0 +1,824 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * SeongWon Shim + */ + +#include +#include + +#include "protocol_binder/protocol_binder_util_internal.h" +#include "protocol_binder/protocol_binder_internal.h" +#include "Utility/fw_log.h" +#include "Utility/fw_assert.h" + +#define LOG_TAG "AF_PB_UTIL" + +/* internal function */ +unsigned int remove_xml_header(char *xml, unsigned int xml_len) +{ + /* note that xml generated by wbxml library always have '); + fw_assert_condition(doctype_part_end != NULL, "prev_lang_table != NULL) { + err = PROTOCOL_BINDER_ALREADY_SWITCH_PROTOCOL; + goto return_part; + } + + pBinder->prev_lang_table = pBinder->lang_table; + pBinder->lang_table = (WBXMLLangEntry *) wbxml_tables_get_table(lang); + +return_part: + return err; +} + +PROTOCOL_BINDER_ERROR undo_switch_protocol(protocol_binder *pBinder) +{ + PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK; + + if (pBinder == NULL) { + err = PROTOCOL_BINDER_NOT_DEFINED; + goto return_part; + } + + if (pBinder->prev_lang_table == NULL) { + err = PROTOCOL_BINDER_HAS_NO_UNDO_SWITCH_PROTOCOL; + goto return_part; + } + + pBinder->lang_table = pBinder->prev_lang_table; + pBinder->prev_lang_table = NULL; + +return_part: + return err; +} + +WBXMLTree *create_wbxml_tree(const protocol_binder *pBinder) +{ + WBXMLCharsetMIBEnum orig_charset = WBXML_PARSER_DEFAULT_CHARSET; + WBXMLLanguage lang = pBinder->lang_table->langID; + + return wbxml_tree_create(lang, orig_charset); +} + +PROTOCOL_BINDER_ERROR add_wbxml_tree_to_wbxml_node(WBXMLTreeNode *parent_node, WBXMLTree *tree) +{ + PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK; + if (parent_node == NULL || tree == NULL) { + err = PROTOCOL_BINDER_INVALID_INPUT_PARAMETER; + goto return_part; + } + + WBXMLTreeNode *tree_node = wbxml_tree_node_create(WBXML_TREE_TREE_NODE); + if (tree_node == NULL) { + err = PROTOCOL_BINDER_OUT_OF_MEMORY; + goto return_part; + } + + WB_BOOL success = wbxml_tree_node_add_child(parent_node, tree_node); + if (!success) { + err = PROTOCOL_BINDER_INVALID_INPUT_PARAMETER; + wbxml_tree_node_destroy(tree_node); + goto return_part; + } + + tree_node->tree = tree; + +return_part: + return err; +} + +PROTOCOL_BINDER_ERROR set_wbxml_tree_root(WBXMLTree *tree, WBXMLTreeNode *node) +{ + PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK; + if (tree == NULL || node == NULL) { + err = PROTOCOL_BINDER_INVALID_INPUT_PARAMETER; + goto return_part; + } + + WB_BOOL success = wbxml_tree_add_node(tree, NULL, node); + if (!success) { + err = PROTOCOL_BINDER_TREE_ALREADY_HAS_ROOT; + goto return_part; + } + +return_part: + return err; +} + +WBXMLTreeNode *create_wbxml_node_using_xml_name(const protocol_binder *pBinder, const char *xml_name) +{ + return wbxml_tree_node_create_xml_elt(pBinder->lang_table, (unsigned char *)xml_name); +} + +WBXMLTreeNode *create_wbxml_node_using_xml_name_and_namespace(const protocol_binder *pBinder, const char *xml_name, const char *namespace) +{ + WBXMLTreeNode *node = NULL; + + const WBXMLTagEntry *tag_entry = NULL; + WBXMLTag *tag = NULL; + WB_UTINY code_page = 0; + + code_page = wbxml_tables_get_code_page(pBinder->lang_table->nsTable, namespace); + if ((tag_entry = wbxml_tables_get_tag_from_xml(pBinder->lang_table, code_page, (unsigned char *)xml_name)) != NULL) { + /* token tag */ + tag = wbxml_tag_create_token(tag_entry); + } else { + tag = wbxml_tag_create_literal((unsigned char *)xml_name); + } + + if (tag == NULL) + return NULL; + + /* Create a new Node */ + if ((node = wbxml_tree_node_create(WBXML_TREE_ELEMENT_NODE)) == NULL) { + wbxml_tag_destroy(tag); + return NULL; + } + + /* Set Node Tag */ + node->name = tag; + + return node; +} + +WBXMLTreeNode *create_wbxml_node_using_xml_name_with_text(const protocol_binder *pBinder, const char *xml_name, const char *text, unsigned int text_len) +{ + return wbxml_tree_node_create_xml_elt_with_text(pBinder->lang_table, (unsigned char *)xml_name, (unsigned char *)text, text_len); +} + +WBXMLTreeNode *create_wbxml_node_using_xml_name_and_namespace_with_text(const protocol_binder *pBinder, const char *xml_name, const char *namespace, const char *text, unsigned int text_len) +{ + WBXMLTreeNode *node = NULL; + WBXMLTreeNode *text_node = NULL; + + node = create_wbxml_node_using_xml_name_and_namespace(pBinder, xml_name, namespace); + if (node == NULL) { + return NULL; + } + + /* Create text node */ + if ((text_node = wbxml_tree_node_create_text((unsigned char *)text, text_len)) == NULL) { + wbxml_tree_node_destroy(node); + return NULL; + } + + /* Add text node to element node */ + if (!wbxml_tree_node_add_child(node, text_node)) { + wbxml_tree_node_destroy(node); + wbxml_tree_node_destroy(text_node); + return NULL; + } + + return node; +} + +WBXMLTreeNode *create_wbxml_node_using_xml_name_with_cdata(const protocol_binder *pBinder, const char *xml_name, const char *text, unsigned int text_len) +{ + bool success = false; + WBXMLTreeNode *wbxml_tree_node = wbxml_tree_node_create_xml_elt(pBinder->lang_table, (unsigned char *)xml_name); + if (wbxml_tree_node == NULL) { + goto return_part; + } + + if (text != NULL) { + WBXMLTreeNode *text_node = wbxml_tree_node_create_cdata((unsigned char *)text, text_len); + if (text_node == NULL) { + success = false; + goto return_part; + } + + success = wbxml_node_add_child_node(wbxml_tree_node, text_node); + if (!success) { + wbxml_tree_node_destroy(text_node); + goto return_part; + } + } + +return_part: + if (!success) { + if (wbxml_tree_node != NULL) { + wbxml_tree_node_destroy(wbxml_tree_node); + wbxml_tree_node = NULL; + } + } + return wbxml_tree_node; +} + +WBXMLTreeNode *add_child_wbxml_node_using_xml_name(const protocol_binder *pBinder, WBXMLTreeNode *parent_node, const char *xml_name) +{ + WBXMLTreeNode *new_node = create_wbxml_node_using_xml_name(pBinder, xml_name); + if (new_node == NULL) { + return new_node; + } + + bool success = wbxml_node_add_child_node(parent_node, new_node); + if (success) { + return new_node; + } else { + wbxml_tree_node_destroy(new_node); + return NULL; + } +} + +WBXMLTreeNode *add_child_wbxml_node_using_xml_name_and_namespace(const protocol_binder *pBinder, WBXMLTreeNode *parent_node, const char *xml_name, const char *namespace) +{ + WBXMLTreeNode *new_node = create_wbxml_node_using_xml_name_and_namespace(pBinder, + xml_name, + namespace); + if (new_node == NULL) { + return NULL; + } + + bool success = wbxml_node_add_child_node(parent_node, new_node); + if (success) { + return new_node; + } else { + wbxml_tree_node_destroy(new_node); + return NULL; + } +} + +WBXMLTreeNode *add_child_wbxml_node_using_xml_name_with_text(const protocol_binder *pBinder, WBXMLTreeNode *parent_node, const char *xml_name, const char *text, unsigned int text_len) +{ + WBXMLTreeNode *new_node = create_wbxml_node_using_xml_name_with_text(pBinder, xml_name, text, text_len); + if (new_node == NULL) { + return new_node; + } + + bool success = wbxml_node_add_child_node(parent_node, new_node); + if (success) { + return new_node; + } else { + wbxml_tree_node_destroy(new_node); + return NULL; + } +} + +WBXMLTreeNode *add_child_wbxml_node_using_xml_name_and_namespace_with_text(const protocol_binder *pBinder, WBXMLTreeNode *parent_node, const char *xml_name, const char *namespace, const char *text, unsigned int text_len) +{ + WBXMLTreeNode *new_node = create_wbxml_node_using_xml_name_and_namespace_with_text(pBinder, + xml_name, + namespace, + text, + text_len); + + bool success = wbxml_node_add_child_node(parent_node, new_node); + if (success) { + return new_node; + } else { + wbxml_tree_node_destroy(new_node); + return NULL; + } +} + +WBXMLTreeNode *add_child_wbxml_node_using_xml_name_with_cdata(const protocol_binder *pBinder, WBXMLTreeNode *parent_node, const char *xml_name, const char *text, unsigned int text_len) +{ + WBXMLTreeNode *new_node = create_wbxml_node_using_xml_name_with_cdata(pBinder, xml_name, text, text_len); + if (new_node == NULL) { + return new_node; + } + + bool success = wbxml_node_add_child_node(parent_node, new_node); + if (success) { + return new_node; + } else { + wbxml_tree_node_destroy(new_node); + return NULL; + } +} + +WBXMLTreeNode *add_child_wbxml_node_using_xml_name_with_int(const protocol_binder *pBinder, WBXMLTreeNode *parent_node, const char *xml_name, const int num) +{ + WBXMLTreeNode *node = NULL; + char *num_string = g_strdup_printf("%d", num); + if (num_string == NULL) { + return NULL; + } + + node = add_child_wbxml_node_using_xml_name_with_text(pBinder, parent_node, xml_name, num_string, strlen(num_string)); + g_free(num_string); + + return node; +} + +WBXMLTreeNode *add_child_wbxml_node_using_xml_name_and_namespace_with_int(const protocol_binder *pBinder, WBXMLTreeNode *parent_node, const char *xml_name, const char *namespace, const int num) +{ + WBXMLTreeNode *node = NULL; + char *num_string = g_strdup_printf("%d", num); + if (num_string == NULL) { + return NULL; + } + + node = add_child_wbxml_node_using_xml_name_and_namespace_with_text(pBinder, parent_node, xml_name, namespace, num_string, strlen(num_string)); + g_free(num_string); + + return node; +} + +WBXMLTreeNode *add_child_wbxml_node_using_xml_name_with_unsigned_int(const protocol_binder *pBinder, WBXMLTreeNode *parent_node, const char *xml_name, const unsigned int num) +{ + WBXMLTreeNode *node = NULL; + char *num_string = g_strdup_printf("%u", num); + if (num_string == NULL) { + return NULL; + } + + node = add_child_wbxml_node_using_xml_name_with_text(pBinder, parent_node, xml_name, num_string, strlen(num_string)); + g_free(num_string); + + return node; +} + +WBXMLTreeNode *add_child_wbxml_node_using_xml_name_and_namespace_with_unsigned_int(const protocol_binder *pBinder, WBXMLTreeNode *parent_node, const char *xml_name, const char *namespace, const unsigned int num) +{ + WBXMLTreeNode *node = NULL; + char *num_string = g_strdup_printf("%u", num); + if (num_string == NULL) { + return NULL; + } + + node = add_child_wbxml_node_using_xml_name_and_namespace_with_text(pBinder, parent_node, xml_name, namespace, num_string, strlen(num_string)); + g_free(num_string); + + return node; +} + +bool wbxml_node_add_child_node(WBXMLTreeNode *parent, WBXMLTreeNode *child) +{ + return wbxml_tree_node_add_child(parent, child); +} + +PROTOCOL_BINDER_ERROR get_xml_name_from_element_wbxml_node(const WBXMLTreeNode *element_node, char **element_xml_name) +{ + PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK; + char *out_element_xml_name = NULL; + + if (!has_wbxml_node_same_type((WBXMLTreeNode *)element_node, WBXML_TREE_ELEMENT_NODE)) { + err = PROTOCOL_BINDER_TREE_NODE_IS_NOT_ELEMENT_NODE; + goto return_part; + } + + if (element_node->name != NULL) { + out_element_xml_name = (char *)wbxml_tag_get_xml_name(element_node->name); + } + +return_part: + if (err == PROTOCOL_BINDER_OK) { + *element_xml_name = out_element_xml_name; + } + return err; +} + +PROTOCOL_BINDER_ERROR get_namespace_from_element_wbxml_node(const Reverse_protocol_binder *pBinder, const WBXMLTreeNode *element_node, char **namespace) +{ + PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK; + char *out_namespace = NULL; + + if (!has_wbxml_node_same_type((WBXMLTreeNode *)element_node, WBXML_TREE_ELEMENT_NODE)) { + err = PROTOCOL_BINDER_TREE_NODE_IS_NOT_ELEMENT_NODE; + goto return_part; + } + + if (element_node->name != NULL && element_node->name->type == WBXML_VALUE_TOKEN) { + const WBXMLLangEntry *pLang = get_current_subtree_lang((Reverse_protocol_binder *)pBinder); + assert(pLang != NULL); + + out_namespace = (char *)wbxml_tables_get_xmlns(pLang->nsTable, element_node->name->u.token->wbxmlCodePage); + } + +return_part: + if (err == PROTOCOL_BINDER_OK) { + *namespace = out_namespace; + } + return err; +} + +PROTOCOL_BINDER_ERROR get_text_pointer_from_wbxml_node(WBXMLTreeNode *parent, char **text_pointer) +{ + PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK; + if (parent->children != NULL && parent->children->type == WBXML_TREE_TEXT_NODE && parent->children->content != NULL) { + *text_pointer = (char *)wbxml_buffer_get_cstr(parent->children->content); + } else { + *text_pointer = NULL; + } + + return err; +} + +PROTOCOL_BINDER_ERROR get_binary_pointer_from_wbxml_node(WBXMLTreeNode *parent, char **binary_pointer, unsigned int *binary_size) +{ + PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK; + if (parent->children != NULL && parent->children->type == WBXML_TREE_TEXT_NODE && parent->children->content != NULL) { + *binary_pointer = (char *)wbxml_buffer_get_cstr(parent->children->content); + *binary_size = wbxml_buffer_len(parent->children->content); + } else { + err = PROTOCOL_BINDER_UTIL_NO_BINARY_VALUE; + } + + return err; +} + +PROTOCOL_BINDER_ERROR get_int_from_wbxml_node(WBXMLTreeNode *parent, int *value) +{ + PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK; + char *text_pointer = NULL; + err = get_text_pointer_from_wbxml_node(parent, &text_pointer); + /*if (err != PROTOCOL_BINDER_OK) { + assert(err == PROTOCOL_BINDER_UTIL_NO_TEXT_VALUE); + err = PROTOCOL_BINDER_UTIL_NO_INT_VALUE; + return err; + } */ + + if (text_pointer != NULL) { + *value = atoi(text_pointer); + } else { + err = PROTOCOL_BINDER_UTIL_NO_INT_VALUE; + } + + return err; +} + +PROTOCOL_BINDER_ERROR get_text_pointer_from_wbxml_cdata_node(WBXMLTreeNode *parent, char **text_pointer) +{ + PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK; + WBXMLTreeNode *cdata_node = parent->children; + + if (cdata_node != NULL && cdata_node->type == WBXML_TREE_CDATA_NODE) { + err = get_text_pointer_from_wbxml_node(cdata_node, text_pointer); + } else { + *text_pointer = NULL; + } + + return err; +} + +PROTOCOL_BINDER_ERROR get_binary_pointer_from_wbxml_cdata_node(WBXMLTreeNode *parent, char **binary_pointer, unsigned int *binary_size) +{ + PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK; + WBXMLTreeNode *cdata_node = parent->children; + + if (cdata_node != NULL && cdata_node->type == WBXML_TREE_CDATA_NODE) { + err = get_binary_pointer_from_wbxml_node(cdata_node, binary_pointer, binary_size); + } else { + err = PROTOCOL_BINDER_UTIL_NO_BINARY_VALUE; + } + + return err; +} + +PROTOCOL_BINDER_ERROR get_wbxml_tree_from_wbxml(char *byte_stream, int byte_stream_len, WBXMLLanguage wbxml_lang, WBXMLTree **wbxml_tree) +{ + PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK; + WBXMLTree *ret_wbxml_tree = NULL; + + FW_LOGD("start with byte_stream = %x, byte_stream_len = %d\n", byte_stream, byte_stream_len); + WBXMLError wbxml_err = wbxml_tree_from_wbxml((unsigned char *)byte_stream, byte_stream_len, wbxml_lang, WBXML_CHARSET_UNKNOWN, &ret_wbxml_tree); + + if (wbxml_err != WBXML_OK) { + FW_LOGE("wbxml_tree_from_wbxml error occurred. wbxml error(%d) = %s", wbxml_err, wbxml_errors_string(wbxml_err)); + err = PROTOCOL_BINDER_WBXML_PARSE_FAIL; + goto return_part; + } + +return_part: + if (err == PROTOCOL_BINDER_OK) { + *wbxml_tree = ret_wbxml_tree; + } + FW_LOGD("ended with err = %d\n", err); + return err; +} + +PROTOCOL_BINDER_ERROR get_wbxml_tree_from_xml(char *byte_stream, int byte_stream_len, WBXMLLanguage wbxml_lang, WBXMLTree **wbxml_tree) +{ + PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK; + WBXMLTree *ret_wbxml_tree = NULL; + + FW_LOGD("start with byte_stream = %x, byte_stream_len = %d\n", byte_stream, byte_stream_len); + WBXMLError wbxml_err = wbxml_tree_from_xml_with_lang((unsigned char *)byte_stream, byte_stream_len, wbxml_lang, &ret_wbxml_tree); + + if (wbxml_err != WBXML_OK) { + FW_LOGE("wbxml_tree_from_xml error occurred. wbxml error(%d) = %s", wbxml_err, wbxml_errors_string(wbxml_err)); + err = PROTOCOL_BINDER_XML_PARSE_FAIL; + goto return_part; + } + +return_part: + if (err == PROTOCOL_BINDER_OK) { + *wbxml_tree = ret_wbxml_tree; + } + FW_LOGD("ended with err = %d\n", err); + return err; +} + +bool validate_protocol(Protocol protocol) +{ + if (PROTOCOL_UNKNOWN <= protocol && protocol < PROTOCOL_MAX_COUNT) { + return true; + } + return false; +} + +WBXMLLanguage get_wbxml_language(Protocol protocol) +{ + WBXMLLanguage lang = WBXML_LANG_UNKNOWN; + + switch (protocol) { + case PROTOCOL_SYNCML_SYNCML10: + lang = WBXML_LANG_SYNCML_SYNCML10; + break; + case PROTOCOL_SYNCML_SYNCML11: + lang = WBXML_LANG_SYNCML_SYNCML11; + break; + case PROTOCOL_SYNCML_SYNCML12: + lang = WBXML_LANG_SYNCML_SYNCML12; + break; + case PROTOCOL_SYNCML_DEVINF10: + lang = WBXML_LANG_SYNCML_DEVINF10; + break; + case PROTOCOL_SYNCML_DEVINF11: + lang = WBXML_LANG_SYNCML_DEVINF11; + break; + case PROTOCOL_SYNCML_DEVINF12: + lang = WBXML_LANG_SYNCML_DEVINF12; + break; + case PROTOCOL_SYNCML_METINF10: + lang = WBXML_LANG_SYNCML_METINF10; + break; + case PROTOCOL_SYNCML_METINF11: + lang = WBXML_LANG_SYNCML_METINF11; + break; + case PROTOCOL_SYNCML_METINF12: + lang = WBXML_LANG_SYNCML_METINF12; + break; + case PROTOCOL_SYNCML_DMDDF12: + lang = WBXML_LANG_SYNCML_DMDDF12; + break; + case PROTOCOL_ACTIVESYNC: + lang = WBXML_LANG_ACTIVESYNC; + break; + case PROTOCOL_PROV10: + lang = WBXML_LANG_PROV10; + break; + default: + break; + } + + return lang; +} + +Protocol get_protocol_from_wbxml_lang(WBXMLLanguage wbxml_lang) +{ + Protocol protocol = PROTOCOL_UNKNOWN; + + switch (wbxml_lang) { + case WBXML_LANG_SYNCML_SYNCML10: + protocol = PROTOCOL_SYNCML_SYNCML10; + break; + case WBXML_LANG_SYNCML_SYNCML11: + protocol = PROTOCOL_SYNCML_SYNCML11; + break; + case WBXML_LANG_SYNCML_SYNCML12: + protocol = PROTOCOL_SYNCML_SYNCML12; + break; + case WBXML_LANG_SYNCML_DEVINF10: + protocol = PROTOCOL_SYNCML_DEVINF10; + break; + case WBXML_LANG_SYNCML_DEVINF11: + protocol = PROTOCOL_SYNCML_DEVINF11; + break; + case WBXML_LANG_SYNCML_DEVINF12: + protocol = PROTOCOL_SYNCML_DEVINF12; + break; + case WBXML_LANG_SYNCML_METINF10: + protocol = PROTOCOL_SYNCML_METINF10; + break; + case WBXML_LANG_SYNCML_METINF11: + protocol = PROTOCOL_SYNCML_METINF11; + break; + case WBXML_LANG_SYNCML_METINF12: + protocol = PROTOCOL_SYNCML_METINF12; + break; + case WBXML_LANG_SYNCML_DMDDF12: + protocol = PROTOCOL_SYNCML_DMDDF12; + break; + case WBXML_LANG_ACTIVESYNC: + protocol = PROTOCOL_ACTIVESYNC; + break; + case WBXML_LANG_PROV10: + protocol = PROTOCOL_PROV10; + break; + default: + break; + } + + return protocol; +} + +WBXMLVersion get_wbxml_version(Encoding enc) +{ + WBXMLVersion version = WBXML_VERSION_UNKNOWN; + switch (enc) { + case ENCODING_WBXML_10: + version = WBXML_VERSION_10; + break; + case ENCODING_WBXML_11: + version = WBXML_VERSION_11; + break; + case ENCODING_WBXML_12: + version = WBXML_VERSION_12; + break; + case ENCODING_WBXML_13: + version = WBXML_VERSION_13; + break; + default: + break; + } + + return version; +} + +WBXMLTreeNode *get_next_node_of_tree_node(WBXMLTreeNode *node, bool *first_visit) +{ + WBXMLTreeNode *next_node = NULL; + + if (*first_visit) { + /* *first_visit = true; */ + + /* get tree node */ + next_node = node->tree->root; + + /* if child node does not exist, then mark second visit and set current_node as next_node */ + if (next_node == NULL) { + *first_visit = false; + next_node = node; + } + } else { + next_node = node->next; + + /* if next node exist */ + if (next_node != NULL) { + *first_visit = true; + } + /* if next node does not exist, then set next node as parent node */ + else { + /* *first_visit = false; */ + next_node = node->parent; + } + } + + return next_node; +} + +WBXMLTreeNode *get_next_node_of_element_node(WBXMLTreeNode *node, bool *first_visit) +{ + WBXMLTreeNode *next_node = NULL; + + if (*first_visit) { + /* *first_visit = true; */ + + /* get child node */ + next_node = node->children; + + /* if child node does not exist, then mark second visit and set current_node as next_node */ + if (next_node == NULL) { + *first_visit = false; + next_node = node; + } + } else { + next_node = node->next; + + /* if next node exist */ + if (next_node != NULL) { + *first_visit = true; + } + /* if next node does not exist, then set next node as parent node */ + else { + /* *first_visit = false; */ + next_node = node->parent; + } + } + + return next_node; +} + +const WBXMLLangEntry *get_current_subtree_lang(Reverse_protocol_binder *pReverse_binder) +{ + const WBXMLLangEntry *pLang = NULL; + + if (pReverse_binder->tree_stack != NULL) { + /* current node belongs to subtree of root tree */ + WBXMLTreeNode *tree_node = (WBXMLTreeNode *)(pReverse_binder->tree_stack->data); + assert(tree_node != NULL); + assert(has_wbxml_node_same_type(tree_node, WBXML_TREE_TREE_NODE)); + + pLang = tree_node->tree->lang; + } else { + pLang = pReverse_binder->tree->lang; + } + + return pLang; +} + +bool has_wbxml_node_same_type(WBXMLTreeNode *node, WBXMLTreeNodeType type) +{ + bool ret = false; + if (node->type == type) { + ret = true; + } + return ret; +} + +void print_wbxml_dom_in_xml(const WBXMLTree *tree) +{ + FW_LOGD("started\n"); + /* debugging */ + unsigned char *xml = NULL; + unsigned int xml_len = 0; + WBXMLGenXMLParams params = { WBXML_GEN_XML_INDENT, WBXML_LANG_UNKNOWN, WBXML_CHARSET_UNKNOWN, 4, FALSE }; + WBXMLError wbxml_err = wbxml_tree_to_xml((WBXMLTree *)tree, &xml, &xml_len, ¶ms); + + if (wbxml_err != WBXML_OK) { + /* TODO : FW_LOGE using wbxml_errors_string(wbxml_err) */ + return; + } + + FW_LOGD("xml printing : \n%s\n", xml); + if (xml != NULL) { + free(xml); + } + + FW_LOGD("ended\n"); +} diff --git a/framework/src/PlatformMonitor/EXT_PMCI.c b/framework/src/PlatformMonitor/EXT_PMCI.c new file mode 100755 index 0000000..542af88 --- /dev/null +++ b/framework/src/PlatformMonitor/EXT_PMCI.c @@ -0,0 +1,388 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Seokgil Kang + */ + +#include "Utility/fw_log.h" +#include "PlatformMonitor/EXT_PMCI.h" +#include "PlugIn/PlugIn_PlatformMonitor.h" +#include "Utility/fw_mainloop.h" + +#define LOG_TAG "AF_PMCI" + +PMCI_RETURN PMCI_Destroy_Default_Noti_Types(int pm_plugIn_id) +{ + FW_LOGV("Start !! \n"); + + PMCI_RETURN res = PMCI_SUCCESS; + + /* 1. terminate network status */ + Terminate_Network_Status_Noti_Handler pFunc_Terminate_NS_Noti_Handler = getFunction_PlatformMonitor_Terminate_Network_Status_Noti_Handler(pm_plugIn_id); + + if (pFunc_Terminate_NS_Noti_Handler == 0) { + FW_LOGV("cannot get pFunc_Terminate_NS_Noti_Handler !! \n"); + res = PMCI_FAIL; + return res; + } + + int err = pFunc_Terminate_NS_Noti_Handler(); + if (err != 1) { + FW_LOGE("fail !!\n"); + res = PMCI_FAIL; + } else { + FW_LOGV("success !! \n"); + } + + FW_LOGV("End !!\n"); + return res; +} + +PMCI_RETURN PMCI_Init_Specific_Type(int pm_plugIn_id, FW_SERVICE_NOTI_TYPE noti_type, const char *pkg_name, const char *user_data, int callback_cnt, ...) +{ + FW_LOGV("Start !!"); + + PMCI_RETURN res = PMCI_SUCCESS; + + va_list list; + va_start(list, callback_cnt); + int i = 0; + + switch (noti_type) { + case NETWORK: + { + FW_LOGV("noti_type = NETWORK"); + + for (; i < callback_cnt; i++) { + switch (i) { + case 0: + { + FW_LOGV("SetCallBack_Network_On() !!"); + SetCallBack_Network_On pFunc_SetCallBack_Network_On = getFunction_PlatformMonitor_SetCallBack_Network_On(pm_plugIn_id); + if (pFunc_SetCallBack_Network_On == 0) { + FW_LOGE("cannot get pFunc_SetCallBack_Network_On !!"); + res = PMCI_FAIL; + goto return_part; + } + + pFunc_SetCallBack_Network_On(va_arg(list, SPECIFIC_TYPE_CALLBACK)); + } + break; + case 1: + { + FW_LOGV("SetCallBack_Network_Off() !!"); + SetCallBack_Network_Off pFunc_SetCallBack_Network_Off = getFunction_PlatformMonitor_SetCallBack_Network_Off(pm_plugIn_id); + if (pFunc_SetCallBack_Network_Off == 0) { + FW_LOGE("cannot get pFunc_SetCallBack_Network_Off !!"); + res = PMCI_FAIL; + goto return_part; + } + + pFunc_SetCallBack_Network_Off(va_arg(list, SPECIFIC_TYPE_CALLBACK)); + } + break; + default: + break; + } + } + } + break; + case SAN: + { + FW_LOGV("noti_type = SAN"); + + for (; i < callback_cnt; i++) { + switch (i) { + case 0: + { + FW_LOGV("SetCallBack_Syncml_SAN_Incoming() !!"); + SetCallBack_Syncml_SAN_Incoming pFunc_SetCallBack_SAN_Incoming = getFunction_PlatformMonitor_SetCallBack_Syncml_SAN_Incoming(pm_plugIn_id); + if (pFunc_SetCallBack_SAN_Incoming == 0) { + FW_LOGE("cannot get pFunc_SetCallBack_SAN_Incoming !!"); + res = PMCI_FAIL; + goto return_part; + } + + pFunc_SetCallBack_SAN_Incoming(va_arg(list, SPECIFIC_TYPE_CALLBACK)); + } + break; + case 1: + { + FW_LOGV("SetCallBack_Syncml_SAN_Operation() !!"); + SetCallBack_Syncml_SAN_Operation pFunc_SetCallBack_SAN_operation = getFunction_PlatformMonitor_SetCallBack_Syncml_SAN_Operation(pm_plugIn_id); + if (pFunc_SetCallBack_SAN_operation == 0) { + FW_LOGE("cannot get pFunc_SetCallBack_SAN_operation !!"); + res = PMCI_FAIL; + goto return_part; + } + + pFunc_SetCallBack_SAN_operation(va_arg(list, SPECIFIC_TYPE_CALLBACK)); + } + break; + default: + break; + } + } + } + break; + case ALARM: + { + FW_LOGV("noti_type = ALARM"); + + for (; i < callback_cnt; i++) { + switch (i) { + case 0: + { + SetCallBack_Alarm pFunc_SetCallBack_Alarm = getFunction_PlatformMonitor_SetCallBack_Alarm(pm_plugIn_id); + if (pFunc_SetCallBack_Alarm == 0) { + FW_LOGE("cannot get pFunc_SetCallBack_Alarm !!"); + goto return_part; + } + + pFunc_SetCallBack_Alarm(va_arg(list, SPECIFIC_TYPE_CALLBACK)); + } + break; + default: + break; + } + } + } + break; + default: + { + FW_LOGV("Can not access this line"); + res = PMCI_FAIL; + goto return_part; + } + break; + } + +return_part: + va_end(list); + + FW_LOGV("End !!"); + return res; +} + +PMCI_RETURN PMCI_Destory_Specific_Type(int pm_plugIn_id, FW_SERVICE_NOTI_TYPE noti_type) +{ + FW_LOGV("Start !! \n"); + + PMCI_RETURN res = PMCI_SUCCESS; + int err = 1; + + switch (noti_type) { + case SAN: + { + FW_LOGV("noti_type = SAN\n"); + Terminate_Syncml_SAN_Noti_Handler pFunc_Terminate_SAN_Noti_Handler = getFunction_PlatformMonitor_Terminate_Symcml_SAN_Noti_Handler(pm_plugIn_id); + if (pFunc_Terminate_SAN_Noti_Handler == 0) { + FW_LOGE("cannot get pFunc_Terminate_SAN_Noti_Handler !! \n"); + res = PMCI_FAIL; + return res; + } + + err = pFunc_Terminate_SAN_Noti_Handler(); + } + break; + case ALARM: + { + FW_LOGV("noti_type = ALARM\n"); + Terminate_Alarm_Noti_Handler pFunc_Terminate_Alarm_Noti_Handler = getFunction_PlatformMonitor_Terminate_Alarm_Noti_Handler(pm_plugIn_id); + if (pFunc_Terminate_Alarm_Noti_Handler == 0) { + FW_LOGV("cannot get pFunc_Terminate_Alarm_Noti_Handler !! \n"); + res = PMCI_FAIL; + return res; + } + } + break; + default: + FW_LOGV("Can not access this line"); + return PMCI_FAIL; + break; + } + + if (err != 1) { + FW_LOGE("fail !!\n"); + res = PMCI_FAIL; + } else { + FW_LOGV("success !! \n"); + } + + FW_LOGV("End !!\n"); + return res; +} + +PMCI_RETURN PMCI_Add_Item_To_Specific_Type(int pm_plugIn_id, FW_SERVICE_NOTI_TYPE noti_type, void *add_item, int *out_add_item_id) +{ + FW_LOGV("Start !! \n"); + + PMCI_RETURN res = PMCI_SUCCESS; + int err = 1; + + switch (noti_type) { + case SAN: + { + FW_LOGV("noti_type = SAN\n"); + Add_Message pFunc_Add_Message = getFunction_PlatformMonitor_Add_Message(pm_plugIn_id); + if (pFunc_Add_Message == 0) { + FW_LOGE("cannot get pFunc_Add_Message !!"); + res = PMCI_FAIL; + return res; + } + + err = pFunc_Add_Message(add_item); + } + break; + case ALARM: + { + FW_LOGV("noti_type = ALARM\n"); + Add_Alarm pFunc_Add_Alarm = getFunction_PlatformMonitor_Add_Alarm(pm_plugIn_id); + if (pFunc_Add_Alarm == 0) { + FW_LOGV("cannot get pFunc_Add_Alarm !! \n"); + res = PMCI_FAIL; + return res; + } + + err = pFunc_Add_Alarm(add_item, out_add_item_id); + } + break; + default: + FW_LOGV("Can not access this line"); + return PMCI_FAIL; + break; + } + + if (err != 1) { + FW_LOGE("fail !!\n"); + res = PMCI_FAIL; + } else { + FW_LOGV("success !! \n"); + } + + FW_LOGV("End !!\n"); + return res; +} + +PMCI_RETURN PMCI_Remove_Item_To_Specific_Type(int pm_plugIn_id, FW_SERVICE_NOTI_TYPE noti_type, int remove_item_id) +{ + FW_LOGV("Start !! \n"); + + PMCI_RETURN res = PMCI_SUCCESS; + int err = 1; + + switch (noti_type) { + case SAN: + { + FW_LOGV("noti_type = SAN\n"); + Remove_Message pFunc_Remove_Message = getFunction_PlatformMonitor_Remove_Message(pm_plugIn_id); + if (pFunc_Remove_Message == 0) { + FW_LOGE("cannot get pFunc_Remove_Message !!"); + res = PMCI_FAIL; + return res; + } + + err = pFunc_Remove_Message(remove_item_id); + } + break; + case ALARM: + { + FW_LOGV("noti_type = ALARM\n"); + Remove_Alarm pFunc_Remove_Alarm = getFunction_PlatformMonitor_Remove_Alarm(pm_plugIn_id); + if (pFunc_Remove_Alarm == 0) { + FW_LOGV("cannot get pFunc_Remove_Alarm !! \n"); + res = PMCI_FAIL; + return res; + } + + err = pFunc_Remove_Alarm(remove_item_id); + } + break; + default: + FW_LOGV("Can not access this line"); + return PMCI_FAIL; + break; + } + + if (err != 1) { + FW_LOGE("fail !!\n"); + res = PMCI_FAIL; + } else { + FW_LOGV("success !! \n"); + } + + FW_LOGV("End !!\n"); + return res; +} + +PMCI_RETURN PMCI_Get_Item_To_Specific_Type(int pm_plugIn_id, FW_SERVICE_NOTI_TYPE noti_type, int get_item_id, void **out_get_item) +{ + FW_LOGV("Start !! \n"); + + PMCI_RETURN res = PMCI_SUCCESS; + int err = 1; + + switch (noti_type) { + case SAN: + { + FW_LOGV("noti_type = SAN\n"); + } + break; + case ALARM: + { + FW_LOGV("noti_type = ALARM\n"); + Get_Alarm pFunc_Get_Alarm = getFunction_PlatformMonitor_Get_Alarm(pm_plugIn_id); + if (pFunc_Get_Alarm == 0) { + FW_LOGV("cannot get pFunc_Get_Alarm !! \n"); + res = PMCI_FAIL; + return res; + } + + err = pFunc_Get_Alarm(get_item_id, out_get_item); + } + break; + default: + FW_LOGV("Can not access this line"); + return PMCI_FAIL; + break; + } + + if (err != 1) { + FW_LOGE("fail !!\n"); + res = PMCI_FAIL; + } else { + FW_LOGV("success !! \n"); + } + + FW_LOGV("End !!\n"); + return res; +} diff --git a/framework/src/PlugIn/PlugIn_Account.c b/framework/src/PlugIn/PlugIn_Account.c new file mode 100755 index 0000000..ae56a5e --- /dev/null +++ b/framework/src/PlugIn/PlugIn_Account.c @@ -0,0 +1,163 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu , + */ + +#include + +#include "Utility/fw_log.h" +#include "PlugIn/PlugIn_Account.h" + +#define LOG_TAG "AF_PlugIn" + +static int isExistPlugIn = 0; + +static PlugIn_Account plugIn_repository; /* singleton */ + +Account_Func_Set getAccount_Func_Set(void *plugIn_handle, PLUGIN_ERROR * error_code) +{ + *error_code = PLUGIN_SUCCESS; + + Account_Func_Set func_Set; + + func_Set.pFunc_Set_AccountReposioryName = dlsym(plugIn_handle, "Set_AccountReposioryName"); + func_Set.pFunc_Add_PlatformAccount = dlsym(plugIn_handle, "Add_PlatformAccount"); + func_Set.pFunc_Set_PlatformAccount_Service = dlsym(plugIn_handle, "Set_PlatformAccount_Service"); + func_Set.pFunc_Del_PlatformAccount = dlsym(plugIn_handle, "Del_PlatformAccount"); + func_Set.pFunc_Del_PlatformAccount_Service = dlsym(plugIn_handle, "Del_PlatformAccount_Service"); + func_Set.pFunc_Has_PlatformAccount_Service = dlsym(plugIn_handle, "Has_PlatformAccount_Service"); + func_Set.pFunc_Get_Service_AccountID = dlsym(plugIn_handle, "Get_Service_AccountID"); + func_Set.pFunc_Get_FW_AccountID = dlsym(plugIn_handle, "Get_FW_AccountID"); + func_Set.pFunc_Get_Service_AccountInfo = dlsym(plugIn_handle, "Get_Service_AccountInfo"); + + return func_Set; +} + +PLUGIN_ERROR registerPlugIn_Account(PlugIn_Account plugIn) +{ + plugIn_repository = plugIn; + + isExistPlugIn = 1; + + return PLUGIN_SUCCESS; +} + +int getAccount_PlugIn_ID() +{ + if (isExistPlugIn) { + return plugIn_repository.plugIn_info.plugIn_id; + } + + return -1; +} + +Set_AccountReposioryName getFunction_Set_AccountReposioryName(int plugIn_id) +{ + if (isExistPlugIn) { + return plugIn_repository.func_Set.pFunc_Set_AccountReposioryName; + } + + return 0; +} + +Add_PlatformAccount getFunction_Account_Add_PlatformAccount(int plugIn_id) +{ + if (isExistPlugIn) { + return plugIn_repository.func_Set.pFunc_Add_PlatformAccount; + } + + return 0; +} + +Set_PlatformAccount_Service getFunction_Set_PlatformAccount_Service(int plugIn_id) +{ + if (isExistPlugIn) { + return plugIn_repository.func_Set.pFunc_Set_PlatformAccount_Service; + } + + return 0; +} + +Del_PlatformAccount getFunction_Account_Del_PlatformAccount(int plugIn_id) +{ + if (isExistPlugIn) { + return plugIn_repository.func_Set.pFunc_Del_PlatformAccount; + } + + return 0; +} + +Del_PlatformAccount_Service getFunction_Account_Del_PlatformAccount_Service(int plugIn_id) +{ + if (isExistPlugIn) { + return plugIn_repository.func_Set.pFunc_Del_PlatformAccount_Service; + } + + return 0; +} + +Has_PlatformAccount_Service getFunction_Account_Has_PlatformAccount_Service(int plugIn_id) +{ + if (isExistPlugIn) { + return plugIn_repository.func_Set.pFunc_Has_PlatformAccount_Service; + } + + return 0; +} + +Get_Service_AccountID getFunction_Account_Get_Service_AccountID(int plugIn_id) +{ + if (isExistPlugIn) { + return plugIn_repository.func_Set.pFunc_Get_Service_AccountID; + } + + return 0; +} + +Get_FW_AccountID getFunction_Account_Get_FW_AccountID(int plugIn_id) +{ + if (isExistPlugIn) { + return plugIn_repository.func_Set.pFunc_Get_FW_AccountID; + } + + return 0; +} + +Get_Service_AccountInfo getFunction_Get_Service_AccountInfo(int plugIn_id) +{ + if (isExistPlugIn) { + return plugIn_repository.func_Set.pFunc_Get_Service_AccountInfo; + } + + return 0; +} diff --git a/framework/src/PlugIn/PlugIn_DataConnector.c b/framework/src/PlugIn/PlugIn_DataConnector.c new file mode 100755 index 0000000..91dece9 --- /dev/null +++ b/framework/src/PlugIn/PlugIn_DataConnector.c @@ -0,0 +1,482 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu , + */ + +#include +#include + +#include "Utility/fw_log.h" +#include "PlugIn/PlugIn_DataConnector.h" + +#define LOG_TAG "AF_PlugIn" + +static int current_PlugIn_count_DataConnector = 0; + +static PlugIn_DataConnector plugIn_repository[MAX_PLUGIN_DATACONNECTOR]; + +static int __findPlugIn_DataConnector(int plugIn_id); + +DataConnector_Func_Set getDataConnector_Func_Set(void *plugIn_handle, PLUGIN_ERROR * error_code) +{ + *error_code = PLUGIN_SUCCESS; + + DataConnector_Func_Set func_Set; + + func_Set.pFunc_Service_Open = dlsym(plugIn_handle, "Service_Open"); + func_Set.pFunc_Service_Close = dlsym(plugIn_handle, "Service_Close"); + func_Set.pFunc_Begin_Transaction = dlsym(plugIn_handle, "Begin_Transaction"); + func_Set.pFunc_End_Transaction = dlsym(plugIn_handle, "End_Transaction"); + func_Set.pFunc_ADD_ITEM = dlsym(plugIn_handle, "Add_Item"); + func_Set.pFunc_UPDATE_ITEM = dlsym(plugIn_handle, "Update_Item"); + func_Set.pFunc_DEL_ITEM = dlsym(plugIn_handle, "Del_Item"); + func_Set.pFunc_DEL_ALL_ITEMS = dlsym(plugIn_handle, "Del_All_Items"); + func_Set.pFunc_GET_ITEM = dlsym(plugIn_handle, "Get_Item"); + func_Set.pFunc_ADD_FOLDER = dlsym(plugIn_handle, "Add_Folder"); + func_Set.pFunc_DEL_FOLDER = dlsym(plugIn_handle, "Del_Folder"); + func_Set.pFunc_GET_FOLDER = dlsym(plugIn_handle, "Get_Folder"); + func_Set.pFunc_EXECUTE = dlsym(plugIn_handle, "Execute"); + func_Set.pFunc_GET_USED_ITEM_CNT = dlsym(plugIn_handle, "Get_Used_Item_Count"); + func_Set.pFunc_GET_USED_CNT_FOR_FOLDER = dlsym(plugIn_handle, "Get_Used_Item_Count_For_Folder"); + func_Set.pFunc_GET_FOLDER_ID_LIST = dlsym(plugIn_handle, "Get_Folder_ID_List"); + func_Set.pFunc_GET_ACCOUNT_ID_LIST = dlsym(plugIn_handle, "Get_Account_ID_List"); + func_Set.pFunc_WRITE_ITEMS_TO_FILE = dlsym(plugIn_handle, "Write_Items_To_File"); + func_Set.pFunc_ADD_FILE_WROTE_ITEMS_TO_DATASTORE = dlsym(plugIn_handle, "Add_File_Wrote_Items_To_Datastore"); + func_Set.pFunc_GET_CHANED_ITEM_FOR_FOLDER_ADD = dlsym(plugIn_handle, "Get_Changed_ITEM_For_Folder_Add"); + func_Set.pFunc_GET_CHANED_ITEM_FOR_FOLDER_DEL = dlsym(plugIn_handle, "Get_Changed_ITEM_For_Folder_Del"); + func_Set.pFunc_GET_CHANED_ITEM_FOR_FOLDER_UPDATE = dlsym(plugIn_handle, "Get_Changed_ITEM_For_Folder_Update"); + func_Set.pFunc_GET_LAST_CHANGEPOINT = dlsym(plugIn_handle, "Get_Last_ChangePoint"); + func_Set.pFunc_StartListening_ChangeNoti = dlsym(plugIn_handle, "StartListening_ChangeNoti"); + func_Set.pFunc_SetCallBack_AddItem = dlsym(plugIn_handle, "SetCallBack_AddItem"); + func_Set.pFunc_setCallBack_DeleteItem = dlsym(plugIn_handle, "SetCallBack_DeleteItem"); + func_Set.pFunc_setCallBack_UpdateItem = dlsym(plugIn_handle, "SetCallBack_UpdateItem"); + func_Set.pFunc_SetCallBack_GetAccountIDList = dlsym(plugIn_handle, "SetCallBack_GetAccountIDList"); + func_Set.pFunc_GET_MAX_ITEM_COUNT = dlsym(plugIn_handle, "Get_MAX_Item_Count"); + func_Set.pFunc_GET_MAX_FIELD_LENGTH = dlsym(plugIn_handle, "Get_MAX_Field_Length"); + func_Set.pFunc_GET_MAX_FIELD_COUNT = dlsym(plugIn_handle, "Get_MAX_Field_Count"); + func_Set.pFunc_GET_FIELD_VALUE = dlsym(plugIn_handle, "Get_Field_Value"); + func_Set.pFunc_GET_IS_SUPPORT_FEATURE = dlsym(plugIn_handle, "Get_Is_Support_Feature"); + + return func_Set; +} + +PLUGIN_ERROR registerPlugIn_DataConnector(PlugIn_DataConnector plugIn) +{ + if (current_PlugIn_count_DataConnector >= MAX_PLUGIN_DATACONNECTOR) { + return PLUGIN_FULL_CAPACITY; + } + + plugIn_repository[current_PlugIn_count_DataConnector] = plugIn; + + current_PlugIn_count_DataConnector++; + + return PLUGIN_SUCCESS; +} + +const PlugIn_DataConnector *getDataConnector_PlugInRepository(int *count) +{ + *count = current_PlugIn_count_DataConnector; + + return plugIn_repository; +} + +int getDataConverter_PlugIn_ID(int dc_plugIn_id) +{ + int index = __findPlugIn_DataConnector(dc_plugIn_id); + if (index == -1) { + return -1; + } + + return plugIn_repository[index].data_converter_id; +} + +int *get_DataConnector_PlugIn_ID_List(int *count) +{ + int *dc_plugin_id_list = 0; + *count = 0; + + if (current_PlugIn_count_DataConnector > 0) { + *count = current_PlugIn_count_DataConnector; + dc_plugin_id_list = (int *)calloc(current_PlugIn_count_DataConnector, sizeof(int)); + int i = 0; + for (; i < current_PlugIn_count_DataConnector; i++) { + dc_plugin_id_list[i] = plugIn_repository[i].plugIn_info.plugIn_id; + } + } + + return dc_plugin_id_list; +} + +Service_Open getFunction_DataConnector_Service_Open(int plugIn_id) +{ + int index = __findPlugIn_DataConnector(plugIn_id); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_set.pFunc_Service_Open; +} + +Service_Close getFunction_DataConnector_Service_Close(int plugIn_id) +{ + int index = __findPlugIn_DataConnector(plugIn_id); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_set.pFunc_Service_Close; +} + +Begin_Transaction getFunction_DataConnector_Begin_Transaction(int plugIn_id) +{ + int index = __findPlugIn_DataConnector(plugIn_id); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_set.pFunc_Begin_Transaction; +} + +End_Transaction getFunction_DataConnector_End_Transaction(int plugIn_id) +{ + int index = __findPlugIn_DataConnector(plugIn_id); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_set.pFunc_End_Transaction; +} + +ADD_ITEM getFunction_DataConnector_ADD_ITEM(int plugIn_id) +{ + int index = __findPlugIn_DataConnector(plugIn_id); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_set.pFunc_ADD_ITEM; +} + +UPDATE_ITEM getFunction_DataConnector_UPDATE_ITEM(int plugIn_id) +{ + int index = __findPlugIn_DataConnector(plugIn_id); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_set.pFunc_UPDATE_ITEM; +} + +DEL_ITEM getFunction_DataConnector_DEL_ITEM(int plugIn_id) +{ + int index = __findPlugIn_DataConnector(plugIn_id); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_set.pFunc_DEL_ITEM; +} + +DEL_ALL_ITEMS getFunction_DataConnector_DEL_ALL_ITEMS(int plugIn_id) +{ + int index = __findPlugIn_DataConnector(plugIn_id); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_set.pFunc_DEL_ALL_ITEMS; +} + +GET_ITEM getFunction_DataConnector_GET_ITEM(int plugIn_id) +{ + int index = __findPlugIn_DataConnector(plugIn_id); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_set.pFunc_GET_ITEM; +} + +ADD_FOLDER getFunction_DataConnector_ADD_FOLDER(int plugIn_id) +{ + int index = __findPlugIn_DataConnector(plugIn_id); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_set.pFunc_ADD_FOLDER; +} + +DEL_FOLDER getFunction_DataConnector_DEL_FOLDER(int plugIn_id) +{ + int index = __findPlugIn_DataConnector(plugIn_id); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_set.pFunc_DEL_FOLDER; +} + +GET_FOLDER getFunction_DataConnector_GET_FOLDER(int plugIn_id) +{ + int index = __findPlugIn_DataConnector(plugIn_id); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_set.pFunc_GET_FOLDER; +} + +EXECUTE getFunction_DataConnector_EXECUTE(int plugIn_id) +{ + int index = __findPlugIn_DataConnector(plugIn_id); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_set.pFunc_EXECUTE; +} + +GET_USED_ITEM_COUNT getFunction_DataConnector_GET_USED_ITEM_COUNT(int plugIn_id) +{ + int index = __findPlugIn_DataConnector(plugIn_id); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_set.pFunc_GET_USED_ITEM_CNT; + +} + +GET_USED_COUNT_FOR_FOLDER getFunction_DataConnector_GET_USED_COUNT_FOR_FOLDER(int plugIn_id) +{ + int index = __findPlugIn_DataConnector(plugIn_id); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_set.pFunc_GET_USED_CNT_FOR_FOLDER; + +} + +GET_FOLDER_ID_LIST getFunction_DataConnector_GET_FOLDER_ID_LIST(int plugIn_id) +{ + int index = __findPlugIn_DataConnector(plugIn_id); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_set.pFunc_GET_FOLDER_ID_LIST; +} + +GET_ACCOUNT_ID_LIST getFunction_DataConnector_GET_ACCOUNT_ID_LIST(int plugIn_id) +{ + int index = __findPlugIn_DataConnector(plugIn_id); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_set.pFunc_GET_ACCOUNT_ID_LIST; +} + +WRITE_ITEMS_TO_FILE getFunction_DataConnector_WRITE_ITEMS_TO_FILE(int plugIn_id) +{ + int index = __findPlugIn_DataConnector(plugIn_id); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_set.pFunc_WRITE_ITEMS_TO_FILE; +} + +ADD_FILE_WROTE_ITEMS_TO_DATASTORE getFunction_DataConnector_ADD_FILE_WROTE_ITEM_TO_DATASTORE(int plugIn_id) +{ + int index = __findPlugIn_DataConnector(plugIn_id); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_set.pFunc_ADD_FILE_WROTE_ITEMS_TO_DATASTORE; +} + +GET_CHANED_ITEM_FOR_FOLDER_ADD getFunction_DataConnector_GET_CHANED_ITEM_FOR_FOLDER_ADD(int plugIn_id) +{ + int index = __findPlugIn_DataConnector(plugIn_id); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_set.pFunc_GET_CHANED_ITEM_FOR_FOLDER_ADD; +} + +GET_CHANED_ITEM_FOR_FOLDER_DEL getFunction_DataConnector_GET_CHANED_ITEM_FOR_FOLDER_DEL(int plugIn_id) +{ + int index = __findPlugIn_DataConnector(plugIn_id); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_set.pFunc_GET_CHANED_ITEM_FOR_FOLDER_DEL; +} + +GET_CHANED_ITEM_FOR_FOLDER_UPDATE getFunction_DataConnector_GET_CHANED_ITEM_FOR_FOLDER_UPDATE(int plugIn_id) +{ + int index = __findPlugIn_DataConnector(plugIn_id); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_set.pFunc_GET_CHANED_ITEM_FOR_FOLDER_UPDATE; +} + +GET_LAST_CHANGEPOINT getFunction_DataConnector_GET_LAST_CHANGEPOINT(int plugIn_id) +{ + int index = __findPlugIn_DataConnector(plugIn_id); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_set.pFunc_GET_LAST_CHANGEPOINT; +} + +StartListening_ChangeNoti getFunction_DataConnector_StartListening_ChangeNoti(int plugIn_id) +{ + int index = __findPlugIn_DataConnector(plugIn_id); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_set.pFunc_StartListening_ChangeNoti; +} + +SetCallBack_AddItem getFunction_DataConnector_SetCallBack_AddItem(int plugIn_id) +{ + int index = __findPlugIn_DataConnector(plugIn_id); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_set.pFunc_SetCallBack_AddItem; +} + +SetCallBack_DeleteItem getFunction_DataConnector_SetCallBack_DeleteItem(int plugIn_id) +{ + int index = __findPlugIn_DataConnector(plugIn_id); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_set.pFunc_setCallBack_DeleteItem; +} + +SetCallBack_UpdateItem getFunction_DataConnector_SetCallBack_UpdateItem(int plugIn_id) +{ + int index = __findPlugIn_DataConnector(plugIn_id); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_set.pFunc_setCallBack_UpdateItem; +} + +SetCallBack_GetAccountIDList getFunction_DataConnector_SetCallBack_GetAccountIDList(int plugIn_id) +{ + int index = __findPlugIn_DataConnector(plugIn_id); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_set.pFunc_SetCallBack_GetAccountIDList; +} + +GET_MAX_ITEM_COUNT getFunction_DataConnector_GET_MAX_ITEM_COUNT(int plugIn_id) +{ + int index = __findPlugIn_DataConnector(plugIn_id); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_set.pFunc_GET_MAX_ITEM_COUNT; +} + +GET_MAX_FIELD_LENGTH getFunction_DataConnector_GET_MAX_FIELD_LENGTH(int plugIn_id) +{ + int index = __findPlugIn_DataConnector(plugIn_id); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_set.pFunc_GET_MAX_FIELD_LENGTH; +} + +GET_MAX_FIELD_COUNT getFunction_DataConnector_GET_MAX_FIELD_COUNT(int plugIn_id) +{ + int index = __findPlugIn_DataConnector(plugIn_id); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_set.pFunc_GET_MAX_FIELD_COUNT; +} + +GET_FIELD_VALUE getFunction_DataConnector_GET_FIELD_VALUE(int plugIn_id) +{ + int index = __findPlugIn_DataConnector(plugIn_id); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_set.pFunc_GET_FIELD_VALUE; +} + +GET_IS_SUPPORT_FEATURE getFunction_DataConnector_GET_IS_SUPPORT_FEATURE(int plugIn_id) +{ + int index = __findPlugIn_DataConnector(plugIn_id); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_set.pFunc_GET_IS_SUPPORT_FEATURE; +} + +static int __findPlugIn_DataConnector(int plugIn_id) +{ + int i = 0; + for (; i < current_PlugIn_count_DataConnector; i++) { + if (plugIn_repository[i].plugIn_info.plugIn_id == plugIn_id) { + return i; + } + } + + return -1; +} diff --git a/framework/src/PlugIn/PlugIn_DataConverter.c b/framework/src/PlugIn/PlugIn_DataConverter.c new file mode 100755 index 0000000..e91021a --- /dev/null +++ b/framework/src/PlugIn/PlugIn_DataConverter.c @@ -0,0 +1,181 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu , + */ + +#include + +#include "Utility/fw_log.h" +#include "PlugIn/PlugIn_DataConverter.h" + +#define LOG_TAG "AF_PlugIn" + +static int current_PlugIn_count_DataConverter = 0; + +static PlugIn_DataConverter plugIn_repository[MAX_PLUGIN_DATACONVERTER]; + +static int __findPlugIn_DataConverter(int plugIn_id); + +DataConverter_Func_Set getDataConverter_Func_Set(void *plugIn_handle, PLUGIN_ERROR * error_code) +{ + *error_code = PLUGIN_SUCCESS; + + DataConverter_Func_Set func_Set; + + func_Set.pFunc_Converter = dlsym(plugIn_handle, "Converter"); + func_Set.pFunc_Replace_Converter = dlsym(plugIn_handle, "Replace_Converter"); + func_Set.pFunc_Reverse_Converter = dlsym(plugIn_handle, "Reverse_Converter"); + func_Set.pFunc_Alloc_Object = dlsym(plugIn_handle, "Alloc_Object"); + func_Set.pFunc_Free_Object = dlsym(plugIn_handle, "Free_Object"); + func_Set.pFunc_Set_Value = dlsym(plugIn_handle, "Set_Value_To_Object"); + func_Set.pFunc_Get_Value = dlsym(plugIn_handle, "Get_Value_To_Object"); + func_Set.pFunc_Get_Obj_Info = dlsym(plugIn_handle, "Get_Obj_Info"); + func_Set.pFunc_Free_Obj_Info = dlsym(plugIn_handle, "Free_Obj_Info"); + + return func_Set; +} + +PLUGIN_ERROR registerPlugIn_DataConverter(PlugIn_DataConverter plugIn) +{ + if (current_PlugIn_count_DataConverter >= MAX_PLUGIN_DATACONVERTER) { + return PLUGIN_FULL_CAPACITY; + } + + plugIn_repository[current_PlugIn_count_DataConverter] = plugIn; + + current_PlugIn_count_DataConverter++; + + return PLUGIN_SUCCESS; +} + +Converter getFunction_DataConverter_Converter(int plugIn_id) +{ + int index = __findPlugIn_DataConverter(plugIn_id); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_Set.pFunc_Converter; +} + +Replace_Converter getFunction_DataConverter_Replace_Converter(int plugIn_id) +{ + int index = __findPlugIn_DataConverter(plugIn_id); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_Set.pFunc_Replace_Converter; +} + +Reverse_Converter getFunction_DataConverter_Reverse_Converter(int plugIn_id) +{ + int index = __findPlugIn_DataConverter(plugIn_id); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_Set.pFunc_Reverse_Converter; +} + +Alloc_Object getFunction_DataConverter_Alloc_Object(int plugIn_id) +{ + int index = __findPlugIn_DataConverter(plugIn_id); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_Set.pFunc_Alloc_Object; +} + +Free_Object getFunction_DataConverter_Free_Object(int plugIn_id) +{ + int index = __findPlugIn_DataConverter(plugIn_id); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_Set.pFunc_Free_Object; +} + +Set_Value getFunction_DataConverter_Set_Value_To_Object(int plugIn_id) +{ + int index = __findPlugIn_DataConverter(plugIn_id); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_Set.pFunc_Set_Value; +} + +Get_Value getFunction_DataConverter_Get_Value_To_Object(int plugIn_id) +{ + int index = __findPlugIn_DataConverter(plugIn_id); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_Set.pFunc_Get_Value; +} + +Get_Obj_Info getFunction_DataConverter_Get_Obj_Info(int plugIn_id) +{ + int index = __findPlugIn_DataConverter(plugIn_id); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_Set.pFunc_Get_Obj_Info; +} + +Free_Obj_Info getFunction_DataConverter_Free_Obj_Info(int plugIn_id) +{ + int index = __findPlugIn_DataConverter(plugIn_id); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_Set.pFunc_Free_Obj_Info; +} + +static int __findPlugIn_DataConverter(int plugIn_id) +{ + int i = 0; + for (; i < current_PlugIn_count_DataConverter; i++) { + if (plugIn_repository[i].plugIn_info.plugIn_id == plugIn_id) { + return i; + } + } + + return -1; +} diff --git a/framework/src/PlugIn/PlugIn_DeviceInfo.c b/framework/src/PlugIn/PlugIn_DeviceInfo.c new file mode 100755 index 0000000..9fdbd66 --- /dev/null +++ b/framework/src/PlugIn/PlugIn_DeviceInfo.c @@ -0,0 +1,148 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Seokgil Kang + */ + +#include + +#include "Utility/fw_log.h" +#include "PlugIn/PlugIn_DeviceInfo.h" + +#define LOG_TAG "AF_PlugIn" + +static int current_PlugIn_count_DeviceInfo = 0; + +static PlugIn_DeviceInfo plugIn_repository[MAX_PLUGIN_DEVICEINFO]; + +static int __findPlugIn_DeviceInfo(int plugIn_id); + +DeviceInfo_Func_Set getDeviceInfo_Func_Set(void *plugIn_handle, PLUGIN_ERROR * error_code) +{ + *error_code = PLUGIN_SUCCESS; + + DeviceInfo_Func_Set func_Set; + + func_Set.pFunc_Load_DevInfo = dlsym(plugIn_handle, "Load_DevInfo"); + func_Set.pFunc_Get_DevInfo = dlsym(plugIn_handle, "Get_DevInfo"); + func_Set.pFunc_Clear_DevInfo = dlsym(plugIn_handle, "Clear_DevInfo"); + func_Set.pFunc_PM_Lock_State = dlsym(plugIn_handle, "PM_Lock_State"); + func_Set.pFunc_PM_Unlock_State = dlsym(plugIn_handle, "PM_Unlock_State"); + + return func_Set; +} + +PLUGIN_ERROR registerPlugIn_DeviceInfo(PlugIn_DeviceInfo plugIn) +{ + if (current_PlugIn_count_DeviceInfo >= MAX_PLUGIN_DEVICEINFO) { + return PLUGIN_FULL_CAPACITY; + } + + plugIn_repository[current_PlugIn_count_DeviceInfo] = plugIn; + + current_PlugIn_count_DeviceInfo++; + + return PLUGIN_SUCCESS; +} + +int isExsist_DeviceInfo_PlugIn(int *plugIn_id) +{ + if (current_PlugIn_count_DeviceInfo < 1) { + return 0; + } + + *plugIn_id = plugIn_repository[0].plugIn_info.plugIn_id; + + return 1; +} + +Load_DevInfo getFunction_DeviceInfo_Load_DevInfo(int plugIn_id) +{ + int index = __findPlugIn_DeviceInfo(plugIn_id); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_Set.pFunc_Load_DevInfo; +} + +Get_DevInfo getFunction_DeviceInfo_Get_DevInfo(int plugIn_id) +{ + int index = __findPlugIn_DeviceInfo(plugIn_id); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_Set.pFunc_Get_DevInfo; +} + +Clear_DevInfo getFunction_DeviceInfo_Clear_DevInfo(int plugIn_id) +{ + int index = __findPlugIn_DeviceInfo(plugIn_id); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_Set.pFunc_Clear_DevInfo; +} + +PM_Lock_State getFunction_PM_Lock_State(int plugIn_id) +{ + int index = __findPlugIn_DeviceInfo(plugIn_id); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_Set.pFunc_PM_Lock_State; +} + +PM_Unlock_State getFunction_PM_Unlock_State(int plugIn_id) +{ + int index = __findPlugIn_DeviceInfo(plugIn_id); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_Set.pFunc_PM_Unlock_State; +} + +static int __findPlugIn_DeviceInfo(int plugIn_id) +{ + int i = 0; + for (; i < current_PlugIn_count_DeviceInfo; i++) { + if (plugIn_repository[i].plugIn_info.plugIn_id == plugIn_id) { + return i; + } + } + + return -1; +} diff --git a/framework/src/PlugIn/PlugIn_Mgr.c b/framework/src/PlugIn/PlugIn_Mgr.c new file mode 100755 index 0000000..ee9a625 --- /dev/null +++ b/framework/src/PlugIn/PlugIn_Mgr.c @@ -0,0 +1,60 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu , + */ + +#include + +#include "Utility/fw_log.h" + +#include "PlugIn/PlugIn_Mgr.h" + +#define LOG_TAG "AF_PlugIn" + +void *load_PlugIn(const char *plugin_path, PLUGIN_ERROR * error) +{ + *error = PLUGIN_SUCCESS; + + void *handler = dlopen(plugin_path, RTLD_LAZY); + if (handler == 0) { + FW_LOGE("dlopen error msg : %s", dlerror()); + *error = PLUGIN_LOAD_FAIL; + } + + return handler; +} + +PLUGIN_ERROR unLoad_PlugIn(PLUGIN_DOMAIN domain, const char *plugin_name) +{ + return PLUGIN_SUCCESS; +} diff --git a/framework/src/PlugIn/PlugIn_NetworkAccess.c b/framework/src/PlugIn/PlugIn_NetworkAccess.c new file mode 100755 index 0000000..d11e2a2 --- /dev/null +++ b/framework/src/PlugIn/PlugIn_NetworkAccess.c @@ -0,0 +1,241 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Seokgil Kang + */ + +#include +#include + +#include "PlugIn/PlugIn_NetworkAccess.h" + +#include "Utility/fw_log.h" + +#define LOG_TAG "AF_PlugIn" + +static int current_PlugIn_count_NetworkAccess = 0; + +static PlugIn_NetworkAccess plugIn_repository[MAX_PLUGIN_NETWORKACCESS]; + +static int __findPlugIn_NetworkAccess(int plugIn_id); + +NetworkAccess_Func_Set getNetworkAccess_Func_Set(void *plugIn_handle, PLUGIN_ERROR * error_code) +{ + *error_code = PLUGIN_SUCCESS; + + NetworkAccess_Func_Set func_Set; + + func_Set.pFunc_Open_Connection = dlsym(plugIn_handle, "Open_Connection"); + func_Set.pFunc_Header_Binding = dlsym(plugIn_handle, "Header_Binding"); + func_Set.pFunc_Send_Message = dlsym(plugIn_handle, "Send_Message"); + func_Set.pFunc_Header_Unbinding = dlsym(plugIn_handle, "Header_Unbinding"); + func_Set.pFunc_Close_Connection = dlsym(plugIn_handle, "Close_Connection"); + func_Set.pFunc_Cancel_Message = dlsym(plugIn_handle, "Cancel_Message"); + func_Set.pFunc_Just_Send_Message = dlsym(plugIn_handle, "Just_Send_Message"); + func_Set.pFunc_Get_Header_Info = dlsym(plugIn_handle, "Get_Header_Info"); + func_Set.pFunc_Set_Data_Down_Info = dlsym(plugIn_handle, "Set_Data_Download_Info"); + func_Set.pFunc_Get_Data_Down_Info = dlsym(plugIn_handle, "Get_Data_Download_Info"); + func_Set.pFunc_Add_Authentication_Info = dlsym(plugIn_handle, "Add_Authentication_Info"); + + return func_Set; +} + +PLUGIN_ERROR registerPlugIn_NetworkAccess(PlugIn_NetworkAccess plugIn) +{ + if (current_PlugIn_count_NetworkAccess >= MAX_PLUGIN_NETWORKACCESS) { + return PLUGIN_FULL_CAPACITY; + } + + plugIn_repository[current_PlugIn_count_NetworkAccess] = plugIn; + + current_PlugIn_count_NetworkAccess++; + + return PLUGIN_SUCCESS; +} + +int use_Network(int plugIn_id) +{ + int index = __findPlugIn_NetworkAccess(plugIn_id); + if (index == -1) { + return -1; + } + + return plugIn_repository[index].use_network; +} + +int get_NetworkAccess_PlugIn_ID_List(int **plugIn_id_list) +{ + if (current_PlugIn_count_NetworkAccess <= 0) { + return 0; + } + + *plugIn_id_list = (int *)calloc(current_PlugIn_count_NetworkAccess, sizeof(int)); + + int i = 0; + for (; i < current_PlugIn_count_NetworkAccess; i++) { + (*plugIn_id_list)[i] = plugIn_repository[i].plugIn_info.plugIn_id; + } + + return current_PlugIn_count_NetworkAccess; +} + +Open_Connection getFunction_NetworkAccess_Open_Connection(int plugIn_id) +{ + int index = __findPlugIn_NetworkAccess(plugIn_id); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_Set.pFunc_Open_Connection; +} + +Header_Binding getFunction_NetworkAccess_Header_Binding(int plugIn_id) +{ + int index = __findPlugIn_NetworkAccess(plugIn_id); + FW_LOGI("index : %d", index); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_Set.pFunc_Header_Binding; +} + +Send_Message getFunction_NetworkAccess_Send_Message(int plugIn_id) +{ + int index = __findPlugIn_NetworkAccess(plugIn_id); + FW_LOGI("index : %d", index); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_Set.pFunc_Send_Message; +} + +Header_Unbinding getFunction_NetworkAccess_Header_Unbinding(int plugIn_id) +{ + int index = __findPlugIn_NetworkAccess(plugIn_id); + FW_LOGI("index : %d", index); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_Set.pFunc_Header_Unbinding; +} + +Close_Connection getFunction_NetworkAccess_Close_Connection(int plugIn_id) +{ + int index = __findPlugIn_NetworkAccess(plugIn_id); + FW_LOGI("index : %d", index); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_Set.pFunc_Close_Connection; +} + +Cancel_Message getFunction_NetworkAccess_Cancel_Message(int plugIn_id) +{ + int index = __findPlugIn_NetworkAccess(plugIn_id); + FW_LOGI("index : %d", index); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_Set.pFunc_Cancel_Message; +} + +Just_Send_Message getFunction_NetworkAccess_Just_Send_Message(int plugIn_id) +{ + int index = __findPlugIn_NetworkAccess(plugIn_id); + FW_LOGI("index : %d", index); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_Set.pFunc_Just_Send_Message; +} + +Get_Header_Info getFunction_NetworkAccess_Get_Header_Info(int plugIn_id) +{ + int index = __findPlugIn_NetworkAccess(plugIn_id); + FW_LOGI("index : %d", index); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_Set.pFunc_Get_Header_Info; +} + +Set_Data_Download_Info getFunction_NetworkAccess_Set_Data_Download_Info(int plugIn_id) +{ + int index = __findPlugIn_NetworkAccess(plugIn_id); + FW_LOGI("index : %d", index); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_Set.pFunc_Set_Data_Down_Info; +} + +Get_Data_Download_Info getFunction_NetworkAccess_Get_Data_Download_Info(int plugIn_id) +{ + int index = __findPlugIn_NetworkAccess(plugIn_id); + FW_LOGI("index : %d", index); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_Set.pFunc_Get_Data_Down_Info; +} + +Add_Authentication_Info getFunction_NetworkAccess_Add_Authentication_Info(int plugIn_id) +{ + int index = __findPlugIn_NetworkAccess(plugIn_id); + FW_LOGI("index : %d", index); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_Set.pFunc_Add_Authentication_Info; +} + +static int __findPlugIn_NetworkAccess(int plugIn_id) +{ + int i = 0; + for (; i < current_PlugIn_count_NetworkAccess; i++) { + if (plugIn_repository[i].plugIn_info.plugIn_id == plugIn_id) { + return i; + } + } + + return -1; +} diff --git a/framework/src/PlugIn/PlugIn_PlatformMonitor.c b/framework/src/PlugIn/PlugIn_PlatformMonitor.c new file mode 100755 index 0000000..f6192fa --- /dev/null +++ b/framework/src/PlugIn/PlugIn_PlatformMonitor.c @@ -0,0 +1,297 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Seokgil Kang + */ + +#include + +#include "PlugIn/PlugIn_PlatformMonitor.h" + +#include "Utility/fw_log.h" + +#define LOG_TAG "AF_PlugIn" + +static int current_PlugIn_count_PlatformMonitor = 0; + +static PlugIn_PlatformMonitor plugIn_repository[MAX_PLUGIN_PLATFORMMONITOR]; + +static int __findPlugIn_PlatformMonitor(int plugIn_id); + +PlatformMonitor_Func_Set getPlatformMonitor_Func_Set(void *plugIn_handle, PLUGIN_ERROR * error_code) +{ + PlatformMonitor_Func_Set func_Set; + func_Set.pFunc_Init_Network_Status_Noti_Handler = dlsym(plugIn_handle, "Init_Network_Status_Noti_Handler"); + func_Set.pFunc_Terminate_Network_Status_Noti_Handler = dlsym(plugIn_handle, "Terminate_Network_Status_Noti_Handler"); + + func_Set.pFunc_Init_Syncml_SAN_Noti_Handler = dlsym(plugIn_handle, "Init_Syncml_SAN_Noti_Handler"); + func_Set.pFunc_Terminate_Syncml_SAN_Noti_Handler = dlsym(plugIn_handle, "Terminate_Syncml_SAN_Noti_Handler"); + func_Set.pFunc_Add_Message = dlsym(plugIn_handle, "Add_Message"); + func_Set.pFunc_Remove_Message = dlsym(plugIn_handle, "Remove_Message"); + + func_Set.pFunc_Init_Alarm_Noti_Handler = dlsym(plugIn_handle, "Init_Alarm_Noti_Handler"); + func_Set.pFunc_Terminate_Alarm_Noti_Handler = dlsym(plugIn_handle, "Init_Alarm_Noti_Handler"); + func_Set.pFunc_Add_Alarm = dlsym(plugIn_handle, "Add_Alarm"); + func_Set.pFunc_Remove_Alarm = dlsym(plugIn_handle, "Remove_Alarm"); + func_Set.pFunc_Get_Alarm = dlsym(plugIn_handle, "Get_Alarm"); + + func_Set.pFunc_SetCallBack_NetworkStatus = dlsym(plugIn_handle, "SetCallBack_NetworkStatus"); + func_Set.pFunc_SetCallBack_NetworkAllCancel = dlsym(plugIn_handle, "SetCallBack_NetworkAllCancel"); + + func_Set.pFunc_SetCallBack_Syncml_SAN_Incoming = dlsym(plugIn_handle, "SetCallBack_Syncml_SAN_Incoming"); + func_Set.pFunc_SetCallBack_Syncml_SAN_Operation = dlsym(plugIn_handle, "SetCallBack_Syncml_SAN_Operation"); + + func_Set.pFunc_SetCallBack_Alarm = dlsym(plugIn_handle, "SetCallBack_Alarm"); + + func_Set.pFunc_SetCallBack_Network_On = dlsym(plugIn_handle, "SetCallBack_Network_On"); + func_Set.pFunc_SetCallBack_Network_Off = dlsym(plugIn_handle, "SetCallBack_Network_Off"); + + *error_code = PLUGIN_SUCCESS; /* todo */ + + return func_Set; +} + +PLUGIN_ERROR registerPlugIn_PlatformMonitor(PlugIn_PlatformMonitor plugIn) +{ + if (current_PlugIn_count_PlatformMonitor >= MAX_PLUGIN_PLATFORMMONITOR) { + return PLUGIN_FULL_CAPACITY; + } + + plugIn_repository[current_PlugIn_count_PlatformMonitor] = plugIn; + + current_PlugIn_count_PlatformMonitor++; + + return PLUGIN_SUCCESS; +} + +int get_PlatformMonitor_PlugIn_Id() +{ + if (current_PlugIn_count_PlatformMonitor < 1) { + return 0; + } + + return plugIn_repository[0].plugIn_info.plugIn_id; +} + +Init_Network_Status_Noti_Handler getFunction_PlatformMonitor_Init_Network_Status_Noti_Handler(int plugIn_id) +{ + int index = __findPlugIn_PlatformMonitor(plugIn_id); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_Set.pFunc_Init_Network_Status_Noti_Handler; +} + +Terminate_Network_Status_Noti_Handler getFunction_PlatformMonitor_Terminate_Network_Status_Noti_Handler(int plugIn_id) +{ + int index = __findPlugIn_PlatformMonitor(plugIn_id); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_Set.pFunc_Terminate_Network_Status_Noti_Handler; +} + +Init_Syncml_SAN_Noti_Handler getFunction_PlatformMonitor_Init_Syncml_SAN_Noti_Handler(int plugIn_id) +{ + int index = __findPlugIn_PlatformMonitor(plugIn_id); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_Set.pFunc_Init_Syncml_SAN_Noti_Handler; +} + +Terminate_Syncml_SAN_Noti_Handler getFunction_PlatformMonitor_Terminate_Symcml_SAN_Noti_Handler(int plugIn_id) +{ + int index = __findPlugIn_PlatformMonitor(plugIn_id); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_Set.pFunc_Terminate_Syncml_SAN_Noti_Handler; +} + +Add_Message getFunction_PlatformMonitor_Add_Message(int plugIn_id) +{ + int index = __findPlugIn_PlatformMonitor(plugIn_id); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_Set.pFunc_Add_Message; +} + +Remove_Message getFunction_PlatformMonitor_Remove_Message(int plugIn_id) +{ + int index = __findPlugIn_PlatformMonitor(plugIn_id); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_Set.pFunc_Remove_Message; +} + +Init_Alarm_Noti_Handler getFunction_PlatformMonitor_Init_Alarm_Noti_Handler(int plugIn_id) +{ + int index = __findPlugIn_PlatformMonitor(plugIn_id); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_Set.pFunc_Init_Alarm_Noti_Handler; +} + +Terminate_Alarm_Noti_Handler getFunction_PlatformMonitor_Terminate_Alarm_Noti_Handler(int plugIn_id) +{ + int index = __findPlugIn_PlatformMonitor(plugIn_id); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_Set.pFunc_Terminate_Alarm_Noti_Handler; +} + +Add_Alarm getFunction_PlatformMonitor_Add_Alarm(int plugIn_id) +{ + int index = __findPlugIn_PlatformMonitor(plugIn_id); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_Set.pFunc_Add_Alarm; +} + +Remove_Alarm getFunction_PlatformMonitor_Remove_Alarm(int plugIn_id) +{ + int index = __findPlugIn_PlatformMonitor(plugIn_id); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_Set.pFunc_Remove_Alarm; +} + +Get_Alarm getFunction_PlatformMonitor_Get_Alarm(int plugIn_id) +{ + int index = __findPlugIn_PlatformMonitor(plugIn_id); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_Set.pFunc_Get_Alarm; +} + +SetCallBack_NetworkStatus getFunction_PlatformMonitor_SetCallBack_NetworkStatus(int plugIn_id) +{ + int index = __findPlugIn_PlatformMonitor(plugIn_id); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_Set.pFunc_SetCallBack_NetworkStatus; +} + +SetCallBack_NetworkAllCancel getFunction_PlatformMonitor_SetCallBack_NetworkAllCancel(int plugIn_id) +{ + int index = __findPlugIn_PlatformMonitor(plugIn_id); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_Set.pFunc_SetCallBack_NetworkAllCancel; +} + +SetCallBack_Syncml_SAN_Incoming getFunction_PlatformMonitor_SetCallBack_Syncml_SAN_Incoming(int plugIn_id) +{ + int index = __findPlugIn_PlatformMonitor(plugIn_id); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_Set.pFunc_SetCallBack_Syncml_SAN_Incoming; +} + +SetCallBack_Syncml_SAN_Operation getFunction_PlatformMonitor_SetCallBack_Syncml_SAN_Operation(int plugIn_id) +{ + int index = __findPlugIn_PlatformMonitor(plugIn_id); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_Set.pFunc_SetCallBack_Syncml_SAN_Operation; +} + +SetCallBack_Alarm getFunction_PlatformMonitor_SetCallBack_Alarm(int plugIn_id) +{ + int index = __findPlugIn_PlatformMonitor(plugIn_id); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_Set.pFunc_SetCallBack_Alarm; +} + +SetCallBack_Network_On getFunction_PlatformMonitor_SetCallBack_Network_On(int plugIn_id) +{ + int index = __findPlugIn_PlatformMonitor(plugIn_id); + FW_LOGI("index : %d", index); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_Set.pFunc_SetCallBack_Network_On; +} + +SetCallBack_Network_Off getFunction_PlatformMonitor_SetCallBack_Network_Off(int plugIn_id) +{ + int index = __findPlugIn_PlatformMonitor(plugIn_id); + FW_LOGI("index : %d", index); + if (index == -1) { + return 0; + } + + return plugIn_repository[index].func_Set.pFunc_SetCallBack_Network_Off; +} + +static int __findPlugIn_PlatformMonitor(int plugIn_id) +{ + int i = 0; + for (; i < current_PlugIn_count_PlatformMonitor; i++) { + if (plugIn_repository[i].plugIn_info.plugIn_id == plugIn_id) { + return i; + } + } + + return -1; +} diff --git a/framework/src/Utility/fw_alloc.c b/framework/src/Utility/fw_alloc.c new file mode 100755 index 0000000..bccf929 --- /dev/null +++ b/framework/src/Utility/fw_alloc.c @@ -0,0 +1,352 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#ifndef NDEBUG + +#include +#include +#include +#include +#include +#include +#include "Utility/fw_thread.h" +#include "Utility/fw_alloc.h" +#include "Utility/fw_alloc_internal.h" +#include "Utility/fw_list.h" + +#include "Utility/fw_log.h" +#define LOG_TAG "AF_ALLOC" + +/* internal variable */ +static fw_list_node_t alloc_list_head = { &alloc_list_head, &alloc_list_head }; +static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; + +FW_STATIC FW_INLINE void *get_realbytes(void *pBytes) +{ + void *pRealbytes = NULL; + pRealbytes = pBytes - ALLOC_FRONT_REDZONE_SIZE - FW_ALIGN64(sizeof(alloc_debug_info_t)) - sizeof(fw_list_node_t); + return pRealbytes; +} + +FW_STATIC FW_INLINE alloc_debug_info_t *get_debug_info(void *pRealbytes) +{ + alloc_debug_info_t *pDebug_info = NULL; + pDebug_info = pRealbytes + sizeof(fw_list_node_t); + return pDebug_info; +} + +FW_STATIC FW_INLINE void *get_front_redzone(void *pRealbytes) +{ + void *pFront_redzone = NULL; + pFront_redzone = pRealbytes + sizeof(fw_list_node_t) + FW_ALIGN64(sizeof(alloc_debug_info_t)); + return pFront_redzone; +} + +FW_STATIC FW_INLINE void *get_bytes(void *pRealbytes) +{ + void *pBytes = NULL; + pBytes = pRealbytes + sizeof(fw_list_node_t) + FW_ALIGN64(sizeof(alloc_debug_info_t)) + ALLOC_FRONT_REDZONE_SIZE; + return pBytes; +} + +FW_STATIC FW_INLINE void *get_rear_redzone(void *pRealbytes, unsigned int bytes) +{ + void *pRear_redzone = NULL; + pRear_redzone = pRealbytes + sizeof(fw_list_node_t) + FW_ALIGN64(sizeof(alloc_debug_info_t)) + ALLOC_FRONT_REDZONE_SIZE + bytes; + return pRear_redzone; +} + +FW_STATIC FW_INLINE fw_list_node_t *get_my_list_node(void *pRealbytes) +{ + fw_list_node_t *my_list_node = NULL; + my_list_node = (fw_list_node_t *)pRealbytes; + return my_list_node; +} + +FW_STATIC FW_INLINE bool check_redzone(void *pRealbytes) +{ + FW_LOGV("start\n"); + bool pass = true; + pass = check_front_redzone(pRealbytes); + if (!pass) + goto return_part; + + pass = check_rear_redzone(pRealbytes); +return_part: + FW_LOGV("finished with pass = %d\n", pass); + return pass; +} + +FW_STATIC FW_INLINE bool check_redzone_with_pattern(char *redzone, char pattern, unsigned int pattern_size) +{ + bool different = false; + int i; + for (i = 0; i < pattern_size; i++) { + different |= (redzone[i] ^ pattern); + if (different) { + break; + } + } + return (!different); +} + +FW_STATIC FW_INLINE bool check_front_redzone(void *pRealbytes) +{ + void *pFront_redzone = get_front_redzone(pRealbytes); + bool pass = check_redzone_with_pattern(pFront_redzone, + ALLOC_FRONT_REDZONE_PATTERN, ALLOC_FRONT_REDZONE_SIZE); + + return pass; +} + +FW_STATIC FW_INLINE bool check_rear_redzone(void *pRealbytes) +{ + alloc_debug_info_t *pAlloc_debug_info = get_debug_info(pRealbytes); + + void *pRear_redzone = get_rear_redzone(pRealbytes, pAlloc_debug_info->size); + bool pass = check_redzone_with_pattern(pRear_redzone, + ALLOC_REAR_REDZONE_PATTERN, ALLOC_REAR_REDZONE_SIZE); + + return pass; +} + +/* + *@brief init already allocated debug info + *@param[in] debug_info : already allocated debug info structure + *@param[in] byte_size + *@param[in] file : file must be allocated already + *@param[in] line + */ +FW_STATIC FW_INLINE void _init_debug_info(alloc_debug_info_t *debug_info, unsigned int byte_size, const char *file, int line) +{ + /* TODO : assert debug_info != NULL */ + debug_info->file = file; + debug_info->line = line; + debug_info->size = byte_size; + debug_info->time = time(NULL); +} + +FW_STATIC bool init_realbytes(void *pRealbytes, unsigned int bytes, const char *file, int line) +{ + bool success = true; + void *pFront_redzone = NULL; + void *pRear_redzone = NULL; + alloc_debug_info_t *debug_info_ptr = NULL; + fw_list_node_t *pList_link = NULL; + + char *dup_file = NULL; + dup_file = strdup(file); + if (dup_file == NULL) { + success = false; + goto return_part; + } + + /* init list_link */ + pList_link = get_my_list_node(pRealbytes); + pList_link->next = 0; + pList_link->prev = 0; + + /* init_debug_info */ + debug_info_ptr = get_debug_info(pRealbytes); + _init_debug_info(debug_info_ptr, bytes, dup_file, line); + + /* init front redzone */ + pFront_redzone = get_front_redzone(pRealbytes); + memset(pFront_redzone, ALLOC_FRONT_REDZONE_PATTERN, ALLOC_FRONT_REDZONE_SIZE); + + /* init rear redzone */ + pRear_redzone = get_rear_redzone(pRealbytes, bytes); + memset(pRear_redzone, ALLOC_REAR_REDZONE_PATTERN, ALLOC_REAR_REDZONE_SIZE); + +return_part: + if (dup_file != NULL) { + free(dup_file); + } + return success; +} + +/* + *@brief alloc realbytes then init debug info, front and rear redzone + *@param[in] byte_size + *@param[in] file + *@param[in] line + */ +FW_STATIC void *_alloc_init_realbytes(unsigned int bytes, const char *file, int line) +{ + void *pRealbytes = NULL; + + unsigned int realbytes_len = 0; + bool success = true; + + /* get real byte size */ + realbytes_len = sizeof(fw_list_node_t) + FW_ALIGN64(sizeof(alloc_debug_info_t)) + bytes + ALLOC_FRONT_REDZONE_SIZE + ALLOC_REAR_REDZONE_SIZE; + + /* memory allocation : real byte memory & duplicate file */ + pRealbytes = malloc(realbytes_len); + if (pRealbytes == NULL) { + success = false; + goto return_part; + } + + success = init_realbytes(pRealbytes, bytes, file, line); + +return_part: + if (!success) { + if (pRealbytes != NULL) { + free(pRealbytes); + pRealbytes = NULL; + } + } + + return pRealbytes; +} + +FW_STATIC void _free_realbytes(void *pRealbytes) +{ + if (pRealbytes) { + alloc_debug_info_t *debug_info_ptr = NULL; + + debug_info_ptr = get_debug_info(pRealbytes); + if (debug_info_ptr->file != NULL) { + free((void *)(debug_info_ptr->file)); + } + free(pRealbytes); + } +} + +/* external interface */ + +void *_fw_malloc(unsigned int bytes, const char *file, int line) +{ + void *pRealbytes = NULL; + void *ret_ptr = NULL; + fw_list_node_t *pList_link = NULL; + + pRealbytes = _alloc_init_realbytes(bytes, file, line); + if (pRealbytes == NULL) { + goto return_part; + } + + /* put in list */ + pList_link = get_my_list_node(pRealbytes); + + pthread_mutex_lock(&mutex); + { + fw_list_add_node(pList_link, &alloc_list_head); + } + pthread_mutex_unlock(&mutex); + + ret_ptr = get_bytes(pRealbytes); + +return_part: + FW_LOGD("[%s] allocation done! return ptr = %p\n", __func__, ret_ptr); + return ret_ptr; +} + +void *_fw_calloc(unsigned int bytes, const char *file, int line) +{ + void *pBytes = NULL; + pBytes = _fw_malloc(bytes, file, line); + memset(pBytes, 0x00, bytes); + + return pBytes; +} + +void *_fw_realloc(void *ptr, unsigned int bytes, const char *file, int line) +{ + /* TODO */ + return 0; +} + +void _fw_free(void *ptr) +{ + void *pRealbytes = get_realbytes(ptr); + fw_list_node_t *pList_link = get_my_list_node(pRealbytes); + bool pass_redzone = false; + + /* remove in list */ + pthread_mutex_lock(&mutex); + { + fw_list_delete_node(pList_link); + } + pthread_mutex_unlock(&mutex); + + pass_redzone = check_redzone(pRealbytes); + if (!pass_redzone) { + alloc_debug_info_t *debug_info_ptr = NULL; + debug_info_ptr = get_debug_info(pRealbytes); + + char time_str[26]; + ctime_r(&(debug_info_ptr->time), (char *)(&time_str)); + + FW_LOGE("REDZONE CHECK ERROR. \n" "\tmalloc from:" "filename = %s, line = %d, size = %d\n at time = %s", debug_info_ptr->file, debug_info_ptr->line, debug_info_ptr->size, time_str); + + FW_LOGE("[%s] checking redzone failed in ptr = %p\n", __func__, ptr); + /* TODO : abort */ + } else { + FW_LOGD("[%s] checking redzone success in ptr = %p\n", __func__, ptr); + } + + _free_realbytes(pRealbytes); +} + +char *_fw_strdup(const char *src, const char *file, int line) +{ + if (src == NULL) { + goto error_part; + } + + unsigned int str_len = strlen(src); + char *pOut_string = _fw_malloc(str_len + 1, file, line); + if (pOut_string == NULL) { + goto error_part; + } + + memcpy(pOut_string, src, str_len); + pOut_string[str_len] = '\0'; + + return pOut_string; + +error_part: + return NULL; +} + +char *_fw_strndup(const char *src, unsigned int n, const char *file, int line) +{ + /* TODO */ + return 0; +} + +#endif diff --git a/framework/src/Utility/fw_async_queue.c b/framework/src/Utility/fw_async_queue.c new file mode 100755 index 0000000..7e2bda3 --- /dev/null +++ b/framework/src/Utility/fw_async_queue.c @@ -0,0 +1,111 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#include +#include "Utility/fw_async_queue.h" +#include "Utility/fw_log.h" + +#define LOG_TAG "AF_UTIL_FW_AYNC_QUEUE" + +fw_async_queue_t *fw_async_queue_alloc() +{ + if (!g_thread_supported()) { + g_thread_init(NULL); + } + + fw_async_queue_t *pQueue = (fw_async_queue_t *)calloc(1, sizeof(fw_async_queue_t)); + if (pQueue == NULL) { + goto return_part; + } + + pQueue->pQueue = g_async_queue_new(); + if (pQueue->pQueue == NULL) { + goto error_part; + } + +return_part: + return pQueue; + +error_part: + fw_async_queue_destroy(pQueue); + return NULL; +} + +void fw_async_queue_destroy(fw_async_queue_t *pQueue) +{ + if (pQueue != NULL) { + if (pQueue->pQueue != NULL) { + g_async_queue_unref(pQueue->pQueue); + } + free(pQueue); + } +} + +void fw_async_queue_lock(fw_async_queue_t *pQueue) +{ + if (pQueue != NULL && pQueue->pQueue != NULL) { + g_async_queue_lock(pQueue->pQueue); + } else { + FW_LOGW("Invalid fw_async_queue\n"); + } +} + +void fw_async_queue_unlock(fw_async_queue_t *pQueue) +{ + if (pQueue != NULL && pQueue->pQueue != NULL) { + g_async_queue_unlock(pQueue->pQueue); + } else { + FW_LOGW("Invalid fw_async_queue\n"); + } +} + +void *fw_async_queue_receive_msg(fw_async_queue_t *pQueue) +{ + return g_async_queue_pop(pQueue->pQueue); +} + +void fw_async_queue_send_msg(fw_async_queue_t *pQueue, void *msg) +{ + g_async_queue_push(pQueue->pQueue, msg); +} + +void fw_async_queue_send_msg_with_compare_priority(fw_async_queue_t *pQueue, void *msg, compare_priority_func cpf, void *user_data) +{ + if (cpf == NULL) { + g_async_queue_push(pQueue->pQueue, msg); + } else { + g_async_queue_push_sorted(pQueue->pQueue, msg, cpf, user_data); + } +} diff --git a/framework/src/Utility/fw_cache.c b/framework/src/Utility/fw_cache.c new file mode 100755 index 0000000..578596d --- /dev/null +++ b/framework/src/Utility/fw_cache.c @@ -0,0 +1,251 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#include +#include +#include +#include + +#include "Utility/fw_cache.h" +#include "Utility/fw_common.h" +#include "Utility/fw_thread.h" + +#include "Utility/fw_log.h" +#define LOG_TAG "AF_CACHE" + +typedef struct { + FW_THREAD_MUTEX_T mutex; /* Mutex to protect access to the structure */ + char *cache_name; /* cache name */ + void *value; /* object pointer in this cache */ + int ref_count; /* reference count for value */ +} cache_t; + +typedef struct { + cache_constructor_t *constructor; /* constructor to allocate memory for cache value */ + cache_destructor_t *destructor; /* destructor to free memory for cache value */ + cache_reloader_t *reloader; /* reloader to reload memory for cache value */ + FW_HASH_TABLE *cache_hash_table; + FW_THREAD_MUTEX_T hash_mutex; +} cache_manager_t; + +static cache_manager_t *cache_manager = 0; + +static cache_t *__alloc_cache(const char *cache_name); +static void __free_cache(cache_t *cache); + +int FW_Create_Cache(cache_constructor_t *constructor, cache_destructor_t *destructor, cache_reloader_t *reloader) +{ + FW_LOGV("Start !!"); + if (cache_manager != 0) { + FW_LOGE("cache_manager exist already !!"); + return 0; + } + + cache_manager = (cache_manager_t *) calloc(1, sizeof(cache_manager_t)); + pthread_mutex_init(&cache_manager->hash_mutex, 0); + cache_manager->constructor = constructor; + cache_manager->reloader = reloader; + cache_manager->destructor = destructor; + cache_manager->cache_hash_table = g_hash_table_new(g_int_hash, 0); + + FW_LOGV("End !!"); + return 1; +} + +int FW_Destroy_Cache() +{ + FW_LOGV("Start!!"); + if (cache_manager == 0) { + FW_LOGE("cache_manage is NULL. cache cannot free !!"); + return 0; + } + + g_hash_table_destroy(cache_manager->cache_hash_table); + pthread_mutex_destroy(&cache_manager->hash_mutex); + free(cache_manager); + cache_manager = 0; + + FW_LOGV("End !!"); + return 1; +} + +void *FW_Use_Cache_Info(const char *cache_name) +{ + FW_LOGV("Start !!"); + void *object = 0; + if (cache_name == 0 || cache_manager == 0 || cache_manager->cache_hash_table == 0) { + FW_LOGE("cache_name == 0 || cache_manager == 0 || cache_manager->cache_hash_table == 0"); + goto return_part; + } + + cache_t *cache = 0; + fw_thread_mutex_lock(&cache_manager->hash_mutex); + cache = g_hash_table_lookup(cache_manager->cache_hash_table, cache_name); + if (cache == 0) { + FW_LOGV("Cache Search Fail and add Cache Hash Table !!"); + cache = __alloc_cache(cache_name); + if (cache == 0) { + FW_LOGE("Failed to __alloc_cache()"); + fw_thread_mutex_unlock(&cache_manager->hash_mutex); + return 0; + } + g_hash_table_insert(cache_manager->cache_hash_table, (void *)cache_name, cache); + object = cache->value; + fw_thread_mutex_unlock(&cache_manager->hash_mutex); + goto return_part; + } + fw_thread_mutex_unlock(&cache_manager->hash_mutex); + + FW_LOGV("Cache Search Success !!"); + fw_thread_mutex_lock(&cache->mutex); + cache->ref_count++; + object = cache->value; + fw_thread_mutex_unlock(&cache->mutex); + +return_part: + FW_LOGV("End !!"); + return object; +} + +int FW_Return_Cache_Info(const char *cache_name) +{ + FW_LOGV("Start !!"); + int ret = 1; + + if (cache_name == 0 || cache_manager == 0 || cache_manager->cache_hash_table == 0) { + FW_LOGE("cache_name == 0 || cache_manager == 0 || cache_manager->cache_hash_table == 0"); + ret = 0; + goto return_part; + } + + cache_t *cache = 0; + fw_thread_mutex_lock(&cache_manager->hash_mutex); + cache = g_hash_table_lookup(cache_manager->cache_hash_table, cache_name); + if (cache == 0) { + FW_LOGE("Cache Search Fail"); + ret = 0; + goto mutex_unlock; + } + + FW_LOGV("Cache Search Success"); + fw_thread_mutex_lock(&cache->mutex); + (cache->ref_count)--; + fw_thread_mutex_unlock(&cache->mutex); + + if (cache->ref_count <= 0) { + g_hash_table_remove(cache_manager->cache_hash_table, cache_name); + __free_cache(cache); + } + +mutex_unlock: + fw_thread_mutex_unlock(&cache_manager->hash_mutex); +return_part: + FW_LOGV("End !!"); + return ret; +} + +void *FW_Reload_Cache_Info(const char *cache_name) +{ + FW_LOGV("Start !!"); + void *object = 0; + if (cache_name == 0 || cache_manager == 0 || cache_manager->cache_hash_table == 0) { + FW_LOGE("cache_name == 0 || cache_manager == 0 || cache_manager->cache_hash_table == 0"); + goto return_part; + } + + cache_t *cache = 0; + fw_thread_mutex_lock(&cache_manager->hash_mutex); + cache = g_hash_table_lookup(cache_manager->cache_hash_table, cache_name); + if (cache == 0) { + /* insert cache */ + FW_LOGV("Cache Search Fail and add Cache Hash Table !!"); + cache = __alloc_cache(cache_name); + if (cache == 0) { + FW_LOGE("Failed to __alloc_cache()"); + fw_thread_mutex_unlock(&cache_manager->hash_mutex); + return 0; + } + g_hash_table_insert(cache_manager->cache_hash_table, (void *)cache_name, cache); + object = cache->value; + fw_thread_mutex_unlock(&cache_manager->hash_mutex); + goto return_part; + } + fw_thread_mutex_unlock(&cache_manager->hash_mutex); + + FW_LOGV("Cache Search Success"); + fw_thread_mutex_lock(&cache->mutex); + + if (cache_manager->destructor != 0) + cache_manager->destructor(cache_name, cache->value); + if (cache_manager->reloader != 0) + cache->value = cache_manager->reloader(cache_name); + object = cache->value; + fw_thread_mutex_unlock(&cache->mutex); + +return_part: + FW_LOGV("End !!"); + return object; +} + +static cache_t *__alloc_cache(const char *cache_name) +{ + cache_t *cache = (cache_t *)calloc(1, sizeof(cache_t)); + if (cache == 0) + return 0; + + pthread_mutex_init(&cache->mutex, 0); + cache->cache_name = strdup(cache_name); + cache->ref_count = 1; + + if (cache_manager->constructor != 0) + cache->value = cache_manager->constructor(cache_name); + + return cache; +} + +static void __free_cache(cache_t *cache) +{ + if (cache != 0) { + + if (cache->cache_name != 0 && cache->value) { + if (cache_manager->destructor != 0) + cache_manager->destructor(cache->cache_name, cache->value); + free(cache->cache_name); + } + + pthread_mutex_destroy(&cache->mutex); + free(cache); + } +} diff --git a/framework/src/Utility/fw_compress.c b/framework/src/Utility/fw_compress.c new file mode 100755 index 0000000..aea7dc9 --- /dev/null +++ b/framework/src/Utility/fw_compress.c @@ -0,0 +1,170 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#include +#include +#include +#include +#include +#include + +#include "Utility/fw_log.h" +#include "Utility/fw_compress.h" + +#define LOG_TAG "AF_COMPRESS" + +FW_COMPRESS_RESULT FW_COMPRESS(FW_COMPRESS_TYPE type, const char *input_directory_path, const char *output_file_path) +{ + if (input_directory_path == 0 || output_file_path == 0) { + return FW_COMPRESS_FAIL; + } + + char *command = 0; + + switch (type) { + case FW_COMPRESS_TYPE_TAR: + { + command = (char *)calloc(strlen("tar cvzpf ") + strlen(output_file_path) + strlen(" ") + strlen(input_directory_path) + 1, sizeof(char)); + strcat(command, "tar cvzpf "); + strcat(command, output_file_path); + strcat(command, " "); + strcat(command, input_directory_path); + + int pid = fork(); + if (pid == -1) { + FW_LOGE("Fork failed to create a process"); + return FW_COMPRESS_FAIL; + } else if (pid == 0) { + char *argv[4]; + + argv[0] = "sh"; + argv[1] = "-c"; + argv[2] = command; + argv[3] = 0; + + execv("/bin/sh", argv); + + abort(); + } + + int status = 0; + do { + if (waitpid(pid, &status, 0) == -1) { + if (errno != EINTR) { + free(command); + return FW_COMPRESS_SUCCESS; + } else { + return FW_COMPRESS_FAIL; + } + } + } while (1); + } + break; + case FW_COMPRESS_TYPE_ZIP: + { + /* + * Not yet support + */ + } + break; + default: + FW_LOGE("Not support compress type!!"); + break; + } + + return FW_COMPRESS_FAIL; +} + +FW_COMPRESS_RESULT FW_UNCOMPRESS(FW_COMPRESS_TYPE type, const char *input_file_path, const char *output_direcory_path) +{ + if (input_file_path == 0 || output_direcory_path == 0) { + return FW_COMPRESS_FAIL; + } + + char *command = 0; + + switch (type) { + case FW_COMPRESS_TYPE_TAR: + { + command = (char *)calloc(strlen("tar xvf ") + strlen(input_file_path) + strlen(" -C ") + strlen(output_direcory_path) + 1, sizeof(char)); + strcat(command, "tar xvf "); + strcat(command, input_file_path); + strcat(command, " -C "); + strcat(command, output_direcory_path); + + int pid = fork(); + if (pid == -1) { + FW_LOGE("Fork failed to create a process"); + return FW_COMPRESS_FAIL; + } else if (pid == 0) { + char *argv[4]; + + argv[0] = "sh"; + argv[1] = "-c"; + argv[2] = command; + argv[3] = 0; + + execv("/bin/sh", argv); + + abort(); + } + + int status = 0; + do { + if (waitpid(pid, &status, 0) == -1) { + if (errno != EINTR) { + free(command); + return FW_COMPRESS_SUCCESS; + } else { + return FW_COMPRESS_FAIL; + } + } + } while (1); + } + break; + case FW_COMPRESS_TYPE_ZIP: + { + /* + * Not yet support + */ + } + break; + default: + FW_LOGE("Not support compress type!!"); + break; + } + + return FW_COMPRESS_FAIL; +} diff --git a/framework/src/Utility/fw_list.c b/framework/src/Utility/fw_list.c new file mode 100644 index 0000000..481c9e5 --- /dev/null +++ b/framework/src/Utility/fw_list.c @@ -0,0 +1,84 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#include "Utility/fw_log.h" + +#include "Utility/fw_list.h" + + +#define LOG_TAG "AF_UTIL_LIST" + + +void fw_list_add_node(fw_list_node_t *new_node, fw_list_node_t *head_ptr) +{ + *(volatile fw_list_node_t **)&new_node->next = head_ptr->next; + new_node->prev = head_ptr; + head_ptr->next->prev = new_node; + head_ptr->next = new_node; +} + +void fw_list_delete_node(fw_list_node_t *target_node) +{ + fw_list_node_t *prev = target_node->prev; + fw_list_node_t *next = target_node->next; + + next->prev = prev; + *(volatile fw_list_node_t **)&prev->next = next; +} + +void fw_list_move_node(fw_list_node_t *list, fw_list_node_t *head_ptr) +{ + fw_list_delete_node(list); + fw_list_add_node(list, head_ptr); +} + +int fw_list_node_count(const fw_list_node_t *head_ptr) +{ + int volatile count = 0; + + fw_list_node_t *cursor_ptr = head_ptr->next; + while (cursor_ptr != head_ptr) { + count++; + cursor_ptr = cursor_ptr->next; + } + + return count; +} + +void fw_list_init(fw_list_node_t *node_ptr) +{ + node_ptr->next = node_ptr; + node_ptr->prev = node_ptr; +} diff --git a/framework/src/Utility/fw_log.c b/framework/src/Utility/fw_log.c new file mode 100755 index 0000000..8c7f6c8 --- /dev/null +++ b/framework/src/Utility/fw_log.c @@ -0,0 +1,148 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#include +#include +#include +#include +#include +#include +#include +#include "Utility/fw_log.h" + +#define FW_LOG_FORMAT_MAX_SIZE 1024 +#define FW_BASENAME(file_path) (strrchr((file_path), '/') ? strrchr(file_path, '/') + 1 : (file_path)) + +#ifdef SLP_PLATFORM +#include +#endif /* SLP_PLATFORM */ + +#ifdef LINUX_PLATFORM +#endif /* LINUX_PLATFORM */ + +static const char *default_terminal_option = "\033[0m"; + +void _fw_log(int prio, const char *log_tag, const char *terminal_option, const char *file_path, const char *func_name, const unsigned int line, const char *format, ...) +{ + va_list ap; + va_start(ap, format); + + /* get new log format */ + /* new log format to be saved here */ + char new_log_format[FW_LOG_FORMAT_MAX_SIZE]; + int new_log_format_len = 0; + if (terminal_option == NULL) { + new_log_format_len = snprintf(new_log_format, FW_LOG_FORMAT_MAX_SIZE, "[File = %.60s, Func = %.60s, Line = %u] %s", FW_BASENAME(file_path), func_name, line, format); + } else { + new_log_format_len = snprintf(new_log_format, FW_LOG_FORMAT_MAX_SIZE, "[File = %.60s, Func = %.60s, Line = %u] %s%s%s", FW_BASENAME(file_path), func_name, line, terminal_option, format, default_terminal_option); + } + + if (new_log_format_len <= FW_LOG_FORMAT_MAX_SIZE) { + /* get right new log format case */ +#ifdef SLP_PLATFORM + switch (prio) { + case FW_LOG_UNKNOWN: + case FW_LOG_DEFAULT: + case FW_LOG_VERBOSE: + LOG_VA(LOG_VERBOSE, log_tag, new_log_format, ap); + break; + case FW_LOG_DEBUG: + LOG_VA(LOG_DEBUG, log_tag, new_log_format, ap); + break; + case FW_LOG_INFO: + LOG_VA(LOG_INFO, log_tag, new_log_format, ap); + break; + case FW_LOG_WARN: + LOG_VA(LOG_WARN, log_tag, new_log_format, ap); + break; + case FW_LOG_ERROR: + LOG_VA(LOG_ERROR, log_tag, new_log_format, ap); + break; + case FW_LOG_FATAL: + LOG_VA(LOG_FATAL, log_tag, new_log_format, ap); + break; + case FW_LOG_SILENT: + LOG_VA(LOG_SILENT, log_tag, new_log_format, ap); + break; + default: + assert(false); + } +#endif /* SLP_PLATFORM */ + +#ifdef LINUX_PLATFORM + /* TODO */ + vfprintf(stderr, new_log_format, ap); +#endif /* LINUX_PLATFORM */ + + } else { + /* may be new log format is greater than FW_LOG_FORMAT_MAX_SIZE case */ +#ifdef SLP_PLATFORM + switch (prio) { + case FW_LOG_UNKNOWN: + case FW_LOG_DEFAULT: + case FW_LOG_VERBOSE: + LOG_VA(LOG_VERBOSE, log_tag, format, ap); + break; + case FW_LOG_DEBUG: + LOG_VA(LOG_DEBUG, log_tag, format, ap); + break; + case FW_LOG_INFO: + LOG_VA(LOG_INFO, log_tag, format, ap); + break; + case FW_LOG_WARN: + LOG_VA(LOG_WARN, log_tag, format, ap); + break; + case FW_LOG_ERROR: + LOG_VA(LOG_ERROR, log_tag, format, ap); + break; + case FW_LOG_FATAL: + LOG_VA(LOG_FATAL, log_tag, format, ap); + break; + case FW_LOG_SILENT: + LOG_VA(LOG_SILENT, log_tag, format, ap); + break; + default: + assert(false); + } +#endif /* SLP_PLATFORM */ + +#ifdef LINUX_PLATFORM + /* TODO */ + vfprintf(stderr, format, ap); +#endif /* LINUX_PLATFORM */ + } + + va_end(ap); +} diff --git a/framework/src/Utility/fw_mainloop.c b/framework/src/Utility/fw_mainloop.c new file mode 100755 index 0000000..8ec5b91 --- /dev/null +++ b/framework/src/Utility/fw_mainloop.c @@ -0,0 +1,128 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#include +#include + +#include "Utility/fw_mainloop.h" + +#define MAX_CALLBACK 10 + +static pthread_t mainloop_thread_id; +static int callback_count = 0; + +static pthread_mutex_t loop_mutex; +static pthread_cond_t loop_cond; +static GMainLoop *loop = 0; +static Callback_Rutine callbackList[MAX_CALLBACK] = { 0 }; +static void *callbackDataList[MAX_CALLBACK] = { 0 }; + +static void *__mainloop_rutine(void *data); + +/* + * non thread safe function !! + */ +void register_Callback2MainLoop(Callback_Rutine callback, void *data) +{ + callbackList[callback_count] = callback; + callbackDataList[callback_count] = data; + + callback_count++; +} + +void run_MainLoop() +{ + int isRunning = isRunning_MainLoop(); + /* + * when main loop is not running !! + */ + if (isRunning != 1) { + pthread_mutex_init(&loop_mutex, NULL); /* TODO : error handling if return value is not 0, fail logic */ + pthread_cond_init(&loop_cond, NULL); /* TODO : error handling if return value is not 0, fail logic */ + + pthread_mutex_lock(&loop_mutex); + pthread_create(&mainloop_thread_id, 0, __mainloop_rutine, 0); + do { + pthread_cond_wait(&loop_cond, &loop_mutex); + } while (loop == NULL); + + pthread_mutex_unlock(&loop_mutex); + } +} + +void stop_MainLoop() +{ + int isRunning = isRunning_MainLoop(); + + if (isRunning) { + pthread_mutex_destroy(&loop_mutex); /* TODO : error handling if return value is not 0, fail logic */ + pthread_cond_destroy(&loop_cond); /* TODO : error handling if return value is not 0, fail logic */ + g_main_loop_quit(loop); + g_main_loop_unref(loop); + pthread_cancel(mainloop_thread_id); + } +} + +int isRunning_MainLoop() +{ + gboolean result = 0; + if (!loop) { + return result; + } + result = g_main_loop_is_running(loop); + + return result; +} + +static void *__mainloop_rutine(void *data) +{ + int i; + for (i = 0; i < callback_count; i++) { + if (callbackList[i] != 0) { + callbackList[i] (callbackDataList[i]); + } + } + + pthread_mutex_lock(&loop_mutex); + + loop = g_main_loop_new(0, 0); + + pthread_cond_signal(&loop_cond); + pthread_mutex_unlock(&loop_mutex); + + g_main_loop_run(loop); + + return 0; +} diff --git a/framework/src/Utility/fw_ref.c b/framework/src/Utility/fw_ref.c new file mode 100755 index 0000000..4a60bda --- /dev/null +++ b/framework/src/Utility/fw_ref.c @@ -0,0 +1,94 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#include "Utility/fw_ref.h" +#include +#include + +refObject_t *create_refObject(void *data, FREE_FUNCTION data_free_func) +{ + refObject_t *pRef = (refObject_t *)malloc(sizeof(refObject_t)); + if (pRef == NULL) { + goto error_part; + } + + pRef->refcount = 1; + pRef->data = data; + pRef->free_func = data_free_func; + + return pRef; + +error_part: + return NULL; +} + +refObject_t *getRef(refObject_t *object) +{ + if (object == NULL) { + return NULL; + } + + g_atomic_int_inc(&(object->refcount)); + + return object; +} + +void *getData(refObject_t *object) +{ + return object->data; +} + +bool same_ref(refObject_t *object1, refObject_t *object2) +{ + if ((object1->data) == (object2->data)) { + return true; + } else { + return false; + } +} + +void unref_refObject(refObject_t *pRef) +{ + if (pRef == NULL) { + return; + } + + if (g_atomic_int_dec_and_test(&(pRef->refcount))) { + if (pRef->free_func != 0) + pRef->free_func(pRef->data); + + free(pRef); + } +} diff --git a/framework/src/Utility/fw_sequential_id_provider.c b/framework/src/Utility/fw_sequential_id_provider.c new file mode 100755 index 0000000..3efb371 --- /dev/null +++ b/framework/src/Utility/fw_sequential_id_provider.c @@ -0,0 +1,1111 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#include +#include +#include +#include +#include "Utility/fw_list.h" +#include "Utility/fw_log.h" +#include "Utility/fw_sequential_id_provider_internal.h" +#include "DataAdapter/DACI_Agent_Handler_Manager.h" + +#define LOG_TAG "FW_UTIL_ID" + +/* internal interfaces */ +unsigned int __calculate_free_bit_cnt(char *bits, unsigned int bit_cnt) +{ + FW_LOGD("start"); + unsigned int cnt = 0; + + unsigned int i = 0; + for (i = 0; i < bit_cnt; i++) { + if (__is_bit_off(i, bits)) { + cnt++; + } + } + + FW_LOGD("end with free_bit_cnt = %u", cnt); + return cnt; +} + +inline bool __is_bit_on(unsigned int offset, char *bits) +{ + unsigned int q = offset / 8; + unsigned int r = offset % 8; + char mask = 1 << (7 - r); + return (bits[q] & mask); +} + +inline bool __is_bit_off(unsigned int offset, char *bits) +{ + return !__is_bit_on(offset, bits); +} + +inline void __set_bit_on(unsigned int offset, char *bits) +{ + unsigned int q = offset / 8; + unsigned int r = offset % 8; + char mask = 1 << (7 - r); + bits[q] |= mask; +} + +inline void __set_bit_off(unsigned int offset, char *bits) +{ + unsigned int q = offset / 8; + unsigned int r = offset % 8; + char mask = 1 << (7 - r); + bits[q] &= (~mask); +} + +id_page_t *id_page_alloc(id_page_flag_t flag, unsigned int page_index, unsigned int free_bit_cnt, unsigned int page_bit_cnt, char *bits) +{ + id_page_t *pId_page = (id_page_t *)malloc(sizeof(id_page_t)); + if (pId_page == NULL) { + goto return_part; + } + + pId_page->link.next = 0; + pId_page->link.prev = 0; + pId_page->flag = flag; + pId_page->page_index = page_index; + pId_page->free_bit_cnt = free_bit_cnt; + pId_page->page_bit_cnt = page_bit_cnt; + pId_page->bits = bits; + +return_part: + return pId_page; +} + +id_page_t *id_page_alloc_new_page(unsigned int page_index, unsigned int page_bit_cnt) +{ + unsigned int size = DIVIDE_INT_ROUND_UP(page_bit_cnt, 8); + char *bits = (char *)calloc(size, sizeof(char)); + + if (bits == NULL) { + return NULL; + } + + return id_page_alloc(ID_PAGE_FLAG_UNKNOWN, page_index, page_bit_cnt, page_bit_cnt, bits); +} + +id_page_t *id_page_load(unsigned int code, unsigned int page_index, unsigned int page_bit_cnt) +{ + id_page_t *pId_page = NULL; + + /* get bits from db */ + char *page_bit = NULL; + DACI_RETURN ret = DACI_Get_ID_Page(code, page_index, &page_bit); + if (ret != DACI_SUCCESS) { + FW_LOGD("Failed DACI_Get_ID_Page()\n"); + assert(false); + } else { + FW_LOGD("Success DACI_Get_ID_Page()\n"); + } + + if (page_bit != NULL) { + /* calculate free bit count */ + unsigned int free_bit_cnt = __calculate_free_bit_cnt(page_bit, page_bit_cnt); + + /* create page with bits from db */ + pId_page = id_page_alloc(ID_PAGE_FLAG_UNKNOWN, page_index, free_bit_cnt, page_bit_cnt, page_bit); + FW_LOGD("(page_index = %u, free_bit_cnt = %u, page_bit_cnt = %u", page_index, free_bit_cnt, page_bit_cnt); + + assert(pId_page != NULL); /* TODO : remove this part by change interface */ + } + + return pId_page; +} + +void id_page_free(id_page_t *pId_page) +{ + if (pId_page != NULL) { + if (pId_page->bits != NULL) { + free(pId_page->bits); + } + free(pId_page); + } +} + +inline bool id_page_is_empty(id_page_t *pId_page) +{ + if (pId_page->free_bit_cnt == pId_page->page_bit_cnt) { + return true; + } + return false; +} + +inline void id_page_set_flag(id_page_t *pId_page, id_page_flag_t flag) +{ + pId_page->flag = flag; +} + +inline id_page_flag_t id_page_get_flag(id_page_t *pId_page) +{ + return pId_page->flag; +} + +inline bool id_page_has_same_flag(id_page_t *pId_page, id_page_flag_t flag) +{ + if (id_page_get_flag(pId_page) == flag) { + return true; + } + return false; +} + +inline bool id_page_is_unknown_flag(id_page_t *pId_page) +{ + return id_page_has_same_flag(pId_page, ID_PAGE_FLAG_UNKNOWN); +} + +inline bool id_page_is_add_flag(id_page_t *pId_page) +{ + return id_page_has_same_flag(pId_page, ID_PAGE_FLAG_ADD); +} + +inline bool id_page_is_delete_flag(id_page_t *pId_page) +{ + return id_page_has_same_flag(pId_page, ID_PAGE_FLAG_DELETE); +} + +inline bool id_page_is_update_flag(id_page_t *pId_page) +{ + return id_page_has_same_flag(pId_page, ID_PAGE_FLAG_UPDATE); +} + +inline bool id_page_is_unchanged_flag(id_page_t *pId_page) +{ + return id_page_has_same_flag(pId_page, ID_PAGE_FLAG_UNCHANGED); +} + +inline unsigned int id_page_get_page_index(id_page_t *pId_page) +{ + return pId_page->page_index; +} + +inline void id_page_set_page_index(id_page_t *pId_page, unsigned int index) +{ + pId_page->page_index = index; +} + +inline bool id_page_is_bit_on(id_page_t *pId_page, unsigned int offset) +{ + return __is_bit_on(offset, pId_page->bits); +} + +inline bool id_page_is_bit_off(id_page_t *pId_page, unsigned int offset) +{ + return __is_bit_off(offset, pId_page->bits); +} + +inline bool id_page_set_bit_on(id_page_t *pId_page, unsigned int offset) +{ + bool success = false; + if (id_page_is_bit_off(pId_page, offset)) { + success = true; + __set_bit_on(offset, pId_page->bits); + (pId_page->free_bit_cnt)--; + } + + return success; +} + +inline bool id_page_set_bit_off(id_page_t *pId_page, unsigned int offset) +{ + bool success = false; + if (id_page_is_bit_on(pId_page, offset)) { + success = true; + __set_bit_off(offset, pId_page->bits); + (pId_page->free_bit_cnt)++; + } + + return success; +} + +bool id_page_find_next_free_offset(id_page_t *id_page, unsigned int search_start_offset, unsigned int *next_free_offset) +{ + bool found = false; + + unsigned int i = 0; + unsigned int end_offset = id_page->page_bit_cnt; + for (i = search_start_offset; i < end_offset; i++) { + if (id_page_is_bit_off(id_page, i)) { + found = true; + *next_free_offset = i; + break; + } + } + + return found; +} + +id_provider_change_tracking_t *id_provider_change_tracking_alloc() +{ + id_provider_change_tracking_t *pTracking = (id_provider_change_tracking_t *)malloc(sizeof(id_provider_change_tracking_t)); + + if (pTracking == NULL) { + goto error_part; + } + + fw_list_init(&(pTracking->id_page_add_list_head)); + fw_list_init(&(pTracking->id_page_update_list_head)); + fw_list_init(&(pTracking->id_page_delete_list_head)); + fw_list_init(&(pTracking->id_page_unchanged_list_head)); + + return pTracking; + +error_part: + return NULL; +} + +void id_provider_change_tracking_free(id_provider_change_tracking_t *pTracking) +{ + if (pTracking != NULL) { + /* Do not free pages linked with list. */ + free(pTracking); + } +} + +inline fw_list_node_t *id_provider_change_tracking_get_list(id_provider_change_tracking_t *pTracking, id_page_flag_t flag) +{ + fw_list_node_t *pHead = NULL; + + switch (flag) { + case ID_PAGE_FLAG_UNCHANGED: + pHead = &(pTracking->id_page_unchanged_list_head); + break; + case ID_PAGE_FLAG_ADD: + pHead = &(pTracking->id_page_add_list_head); + break; + case ID_PAGE_FLAG_DELETE: + pHead = &(pTracking->id_page_delete_list_head); + break; + case ID_PAGE_FLAG_UPDATE: + pHead = &(pTracking->id_page_update_list_head); + break; + default: + pHead = NULL; + } + + return pHead; +} + +id_provider_t *id_provider_create_internal(bool persistent_mode, unsigned int code, unsigned int total_free_bit_cnt, unsigned int id_max, unsigned int log2_page_size, bool support_thread_safety) +{ + if (!g_thread_supported()) { + g_thread_init(NULL); + } + + id_provider_t *pProvider = (id_provider_t *)calloc(1, sizeof(id_provider_t)); + if (pProvider == NULL) { + goto error_part; + } + + /* TODO : validation of input */ + pProvider->persistent_mode = persistent_mode; + pProvider->code = code; + + pProvider->tracking = false; + + pProvider->support_thread_safety = support_thread_safety; + + if (support_thread_safety) { + pProvider->mutex = g_mutex_new(); + if (pProvider->mutex == NULL) { + goto error_part; + } + } + + pProvider->id_max = id_max; + + pProvider->log2_page_size = log2_page_size; + pProvider->page_size = (1 << log2_page_size); + pProvider->bits_per_page = BITS_PER_PAGE(pProvider->page_size); + + pProvider->total_free_cnt = total_free_bit_cnt; + pProvider->last_id = id_max; /* To provide 0 for first id */ + + pProvider->id_page_cnt = ID_PAGE_CNT(id_max, pProvider->bits_per_page); + pProvider->id_page_array = (id_page_t **)calloc(pProvider->id_page_cnt, sizeof(id_page_t *)); + if (pProvider->id_page_array == NULL) { + goto error_part; + } + + pProvider->pTracking = id_provider_change_tracking_alloc(); + if (pProvider->pTracking == NULL) { + goto error_part; + } + + return pProvider; + +error_part: + id_provider_destroy(pProvider); + return NULL; +} + +inline void id_provider_init_routine() +{ + if (!g_thread_supported()) { + g_thread_init(NULL); + } +} + +inline void id_provider_lock(id_provider_t *pId_provider) +{ + if (pId_provider->support_thread_safety) { + g_mutex_lock(pId_provider->mutex); + } +} + +inline void id_provider_unlock(id_provider_t *pId_provider) +{ + if (pId_provider->support_thread_safety) { + g_mutex_unlock(pId_provider->mutex); + } +} + +inline bool id_provider_is_valid_id_range(id_provider_t *pId_provider, unsigned int id) +{ + if (id < 0 || id > pId_provider->id_max) { + return false; + } + return true; +} + +inline bool id_provider_is_valid_page_index(id_provider_t *pId_provider, unsigned int id_page_index) +{ + if (id_page_index < 0 || id_page_index >= pId_provider->id_page_cnt) { + return false; + } + return true; +} + +inline bool id_provider_is_last_page_index(id_provider_t *pId_provider, unsigned int id_page_index) +{ + if (id_page_index == pId_provider->id_page_cnt - 1) { + return true; + } + return false; +} + +inline unsigned int id_provider_calculate_offset_in_page(unsigned int id, unsigned int bits_per_page) +{ + return (id & BITS_PER_PAGE_MASK(bits_per_page)); +} + +inline unsigned int id_provider_calculate_id(id_provider_t *pProvider, unsigned int id_page_index, unsigned int offset) +{ + return id_page_index * pProvider->bits_per_page + offset; +} + +inline unsigned int id_provider_calculate_id_page_array_index(id_provider_t *pId_provider, unsigned int id) +{ + return id / pId_provider->bits_per_page; +} + +inline id_provider_error_t id_provider_calculate_page_cnt_for_id_page(id_provider_t *pId_provider, unsigned int id_page_index, unsigned int *page_cnt) +{ + id_provider_error_t error = ID_PROVIDER_OK; + unsigned int out_page_cnt = 0; + + if (!id_provider_is_valid_page_index(pId_provider, id_page_index)) { + error = ID_PROVIDER_NOT_EXIST_PAGE; + goto return_part; + } + + if (id_provider_is_last_page_index(pId_provider, id_page_index)) { + out_page_cnt = (pId_provider->id_max + 1) - ((pId_provider->id_page_cnt - 1) * (pId_provider->bits_per_page)); + } else { + out_page_cnt = pId_provider->bits_per_page; + } + +return_part: + if (error == ID_PROVIDER_OK) { + *page_cnt = out_page_cnt; + } + return error; +} + +inline id_provider_error_t id_provider_fetch_id_page_by_index(id_provider_t *pId_provider, unsigned int index, id_page_t **ppId_page) +{ + FW_LOGD("start with index = %u", index); + id_provider_error_t error = ID_PROVIDER_OK; + id_page_t *pId_page = NULL; + + if (!id_provider_is_valid_page_index(pId_provider, index)) { + error = ID_PROVIDER_NOT_EXIST_PAGE; + goto return_part; + } + + pId_page = pId_provider->id_page_array[index]; + if (pId_page == NULL) { + if (pId_provider->persistent_mode) { + /* load db page */ + id_provider_error_t load_error = id_provider_load_id_page(pId_provider, index, &pId_page); + if (load_error == ID_PROVIDER_OK) { + goto return_part; + } + + /* if db page does not exist, then add new page by below lines */ + assert(load_error == ID_PROVIDER_PERSISTENT_NOT_EXIST_PAGE); + } + + /* add new page */ + pId_page = id_provider_add_id_page(pId_provider, index); + if (pId_page == NULL) { + error = ID_PROVIDER_NOT_ENOUGH_MEMORY; + goto return_part; + } + } + +return_part: + if (error == ID_PROVIDER_OK) { + *ppId_page = pId_page; + } + + FW_LOGD("end with error = %d", error); + + return error; +} + +inline id_provider_error_t id_provider_fetch_id_page(id_provider_t *pId_provider, unsigned int id, id_page_t **ppId_page) +{ + FW_LOGD("start with id = %u", id); + id_provider_error_t error = ID_PROVIDER_OK; + + unsigned int id_page_array_index = 0; + id_page_t *pId_page = NULL; + + if (!id_provider_is_valid_id_range(pId_provider, id)) { + error = ID_PROVIDER_OUT_OF_ID_RANGE; + goto return_part; + } + + id_page_array_index = id_provider_calculate_id_page_array_index(pId_provider, id); + error = id_provider_fetch_id_page_by_index(pId_provider, id_page_array_index, &pId_page); + +return_part: + if (error == ID_PROVIDER_OK) { + *ppId_page = pId_page; + } + + FW_LOGD("end with error = %d", error); + + return error; +} + +inline id_provider_error_t id_provider_set_id_page_index(id_provider_t *pId_provider, id_page_t *pId_page, unsigned int index) +{ + id_provider_error_t id_error = ID_PROVIDER_OK; + bool valid_page_index = id_provider_is_valid_page_index(pId_provider, index); + + if (valid_page_index) { + id_page_set_page_index(pId_page, index); + pId_provider->id_page_array[index] = pId_page; + } else { + id_error = ID_PROVIDER_NOT_EXIST_PAGE; + } + + return id_error; +} + +void id_provider_move_id_page(id_provider_t *pId_provider, id_page_t *id_page, id_page_flag_t next) +{ + id_page_flag_t prev = id_page_get_flag(id_page); + if (prev == next) { + return; + } + + fw_list_node_t *pNextHead = id_provider_change_tracking_get_list(pId_provider->pTracking, next); + + /* move from previous list to next list */ + + if ((id_page->link.prev == NULL) && (id_page->link.next == NULL)) { + fw_list_add_node(&(id_page->link), pNextHead); + } else { + fw_list_move_node(&(id_page->link), pNextHead); + } + + /* set id_page_flag */ + id_page_set_flag(id_page, next); +} + +void id_provider_remove_id_page(id_provider_t *pId_provider, id_page_t *id_page) +{ + unsigned int id_page_index = 0; + + /* remove from list */ + if (!id_page_is_unknown_flag(id_page)) { + if ((id_page->link.prev == NULL) && (id_page->link.next == NULL)) { + /* DO NOTHING */ + } else { + fw_list_delete_node(&(id_page->link)); + } + } + + /* set id_page_array NULL */ + id_page_index = id_page_get_page_index(id_page); + pId_provider->id_page_array[id_page_index] = NULL; + + /* free id page */ + id_page_free(id_page); +} + +id_page_t *id_provider_add_id_page(id_provider_t *pId_provider, unsigned int page_index) +{ + FW_LOGD("start with page_index = %u", page_index); + id_page_t *pId_page = NULL; + unsigned int page_cnt_for_new_id_page = 0; + id_provider_error_t error = ID_PROVIDER_OK; + error = id_provider_calculate_page_cnt_for_id_page(pId_provider, page_index, &page_cnt_for_new_id_page); + assert(error == ID_PROVIDER_OK); + + /* validation */ + if (pId_provider->id_page_array[page_index] != NULL) { + goto return_part; + } + + /* get page */ + pId_page = id_page_alloc_new_page(page_index, page_cnt_for_new_id_page); + if (pId_page == NULL) { + goto return_part; + } + + /* set page at array */ + pId_provider->id_page_array[page_index] = pId_page; + + /* assign page to add list */ + id_provider_move_id_page(pId_provider, pId_page, ID_PAGE_FLAG_ADD); + +return_part: + FW_LOGD("end with pId_page = %x", pId_page); + return pId_page; +} + +id_provider_error_t id_provider_load_id_page(id_provider_t *pId_provider, unsigned int page_index, id_page_t **id_page) +{ + FW_LOGD("start with page_index = %u", page_index); + id_provider_error_t id_error = ID_PROVIDER_OK; + id_page_t *pId_page = NULL; + + /* get page bit cnt */ + unsigned int page_bit_cnt = 0; + id_error = id_provider_calculate_page_cnt_for_id_page(pId_provider, page_index, &page_bit_cnt); + assert(id_error == ID_PROVIDER_OK); + + /* load page */ + pId_page = id_page_load(pId_provider->code, page_index, page_bit_cnt); + + if (pId_page != NULL) { + /* set page at array */ + pId_provider->id_page_array[page_index] = pId_page; + + /* assign page to unchanged list */ + id_provider_move_id_page(pId_provider, pId_page, ID_PAGE_FLAG_UNCHANGED); + } else { + id_error = ID_PROVIDER_PERSISTENT_NOT_EXIST_PAGE; + } + + if (id_error == ID_PROVIDER_OK) { + *id_page = pId_page; + } + + FW_LOGD("end with id_error = %d", id_error); + return id_error; +} + +bool id_provider_set_id_page_bit_on(id_provider_t *pId_provider, id_page_t *id_page, unsigned int offset) +{ + bool bit_on_success = id_page_set_bit_on(id_page, offset); + + if (bit_on_success) { + assert(!id_page_is_unknown_flag(id_page)); + + /* If page is in add or update list, then DO NOTHING */ + + /* If page is in unchanged or delete list, then move page to update list */ + if (id_page_is_unchanged_flag(id_page) || id_page_is_delete_flag(id_page)) { + id_provider_move_id_page(pId_provider, id_page, ID_PAGE_FLAG_UPDATE); + } + + (pId_provider->total_free_cnt)--; + } + + return bit_on_success; +} + +bool id_provider_set_id_page_bit_off(id_provider_t *pId_provider, id_page_t *id_page, unsigned int offset) +{ + bool bit_off_success = id_page_set_bit_off(id_page, offset); + bool is_empty_page = false; + + if (bit_off_success) { + assert(!id_page_is_unknown_flag(id_page)); + assert(!id_page_is_delete_flag(id_page)); + + is_empty_page = id_page_is_empty(id_page); + if (is_empty_page) { + /* If page is in update or unchanged list, then move to delete list */ + if (id_page_is_update_flag(id_page) || id_page_is_unchanged_flag(id_page)) { + id_provider_move_id_page(pId_provider, id_page, ID_PAGE_FLAG_DELETE); + } + + /* If page is in add list, then remove in list & free page */ + if (id_page_is_add_flag(id_page)) { + id_provider_remove_id_page(pId_provider, id_page); + } + } else { + /* If page is in unchaged list, then move to update list */ + if (id_page_is_unchanged_flag(id_page)) { + id_provider_move_id_page(pId_provider, id_page, ID_PAGE_FLAG_UPDATE); + } + } + + (pId_provider->total_free_cnt)++; + } + + return bit_off_success; +} + +void id_provider_reset_tracking_info(id_provider_t *pId_provider) +{ + id_provider_change_tracking_t *pTracking = pId_provider->pTracking; + id_page_t *page = NULL; + fw_list_node_t *iter = NULL; + fw_list_node_t *add_page_list = &(pTracking->id_page_add_list_head); + fw_list_node_t *update_page_list = &(pTracking->id_page_update_list_head); + fw_list_node_t *delete_page_list = &(pTracking->id_page_delete_list_head); + + /* add list handling : move to unchaged list */ + for (iter = add_page_list; iter != add_page_list;) { + page = (id_page_t *)iter; + iter = iter->next; + id_provider_move_id_page(pId_provider, page, ID_PAGE_FLAG_UNCHANGED); + } + + /* update list handling : move to unchaged list */ + for (iter = update_page_list; iter != update_page_list;) { + page = (id_page_t *)iter; + iter = iter->next; + id_provider_move_id_page(pId_provider, page, ID_PAGE_FLAG_UNCHANGED); + } + + /* delete list handling : remove id page */ + for (iter = delete_page_list; iter != delete_page_list;) { + page = (id_page_t *)iter; + iter = iter->next; + id_provider_remove_id_page(pId_provider, page); + } +} + +void id_provider_destroy_id_page_array(unsigned int id_page_cnt, id_page_t **id_page_array) +{ + if (id_page_array != NULL) { + unsigned int i = 0; + id_page_t *id_page = NULL; + + for (i = 0; i < id_page_cnt; i++) { + id_page = id_page_array[i]; + if (id_page != NULL) { + id_page_free(id_page); + } + } + free(id_page_array); + } +} + +/* external interfaces */ +id_provider_error_t id_persistent_provider_create(unsigned int code, unsigned int id_max, unsigned int log2_page_size) +{ + id_provider_error_t id_error = ID_PROVIDER_OK; + + daci_id_provider id_provider; + id_provider.id_provider_code = code; + id_provider.id_capacity = id_max; + id_provider.bit_per_page = BITS_PER_PAGE(1 << log2_page_size); + id_provider.last_id = id_max; + id_provider.free_bit_cnt = id_max + 1; + + DACI_RETURN ret = DACI_Add_ID_Provider(&id_provider); + if (ret != DACI_SUCCESS) { + FW_LOGD("Failed DACI_Add_ID_Provider()\n"); + id_error = ID_PROVIDER_PERSISTENT_CREATE_ERROR; + } else { + FW_LOGD("Success DACI_Add_ID_Provider()\n"); + } + + return id_error; +} + +id_provider_t *id_persistent_provider_load(unsigned int code, bool support_thread_safety) +{ + id_provider_t *pProvider = NULL; + daci_id_provider *got_id_provider = NULL; + + /* get information from id provider DB */ + DACI_RETURN ret = DACI_Get_ID_Provider(code, &got_id_provider); + if (ret != DACI_SUCCESS) { + FW_LOGD("Failed DACI_Get_ID_Provider()\n"); + /* TODO : error handling */ + + goto return_part; + } else { + FW_LOGD("Success DACI_Get_ID_Provider()\n"); + } + + FW_LOGD("id_capacity : %d\n", got_id_provider->id_capacity); + FW_LOGD("bit_per_page : %d\n", got_id_provider->bit_per_page); + FW_LOGD("last_id : %d\n", got_id_provider->last_id); + FW_LOGD("free_bit_cnt : %d\n", got_id_provider->free_bit_cnt); + + unsigned int log2_page_size = (unsigned int)log2((got_id_provider->bit_per_page) / 8); + + pProvider = id_provider_create_internal(true, code, got_id_provider->free_bit_cnt, got_id_provider->id_capacity, log2_page_size, support_thread_safety); + +return_part: + if (got_id_provider != NULL) { + free(got_id_provider); + } + + return pProvider; +} + +id_provider_error_t id_persistent_provider_update(id_provider_t *pId_provider) +{ + FW_LOGD("started"); + id_provider_error_t id_error = ID_PROVIDER_OK; + + /* id_provider_tbl update */ + daci_id_provider da_id_provider; + da_id_provider.id_provider_code = pId_provider->code; + da_id_provider.last_id = pId_provider->last_id; + da_id_provider.free_bit_cnt = pId_provider->total_free_cnt; + + DACI_RETURN ret = DACI_Update_ID_Provider(&da_id_provider); + if (ret != DACI_SUCCESS) { + FW_LOGD("Failed DACI_Update_ID_Provider()"); + assert(false); + } else { + FW_LOGV("Success DACI_Update_ID_Provider()"); + } + + /* id_page_tbl update */ + id_provider_change_tracking_t *pTracking = pId_provider->pTracking; + id_page_t *page = NULL; + fw_list_node_t *iter = NULL; + fw_list_node_t *add_page_list = &(pTracking->id_page_add_list_head); + fw_list_node_t *update_page_list = &(pTracking->id_page_update_list_head); + fw_list_node_t *delete_page_list = &(pTracking->id_page_delete_list_head); + unsigned int page_byte_size = 0; + + daci_id_page id_page; + id_page.id_provider_code = pId_provider->code; + + /* add list handling */ +/* for (iter = add_page_list->next; iter != add_page_list; iter = iter->next) { */ + fw_list_iter(iter, add_page_list) { + page = (id_page_t *)iter; + id_page.page_index = page->page_index; + id_page.page_bit = page->bits; + + page_byte_size = DIVIDE_INT_ROUND_UP(page->page_bit_cnt, 8); + + /* add page to db */ + ret = DACI_Add_ID_Page(&id_page, page_byte_size); + if (ret != DACI_SUCCESS) { + FW_LOGD("Failed DACI_Add_ID_Page()\n"); + assert(false); + } else { + FW_LOGD("Success DACI_Add_ID_Page()\n"); + } + } + + /* update list handling */ +/* for (iter = add_page_list->next; iter != update_page_list; iter = iter->next) { */ + fw_list_iter(iter, update_page_list) { + page = (id_page_t *)iter; + id_page.page_index = page->page_index; + id_page.page_bit = page->bits; + + page_byte_size = DIVIDE_INT_ROUND_UP(page->page_bit_cnt, 8); + + /* update page to db */ + ret = DACI_Update_ID_Page(&id_page, page_byte_size); + if (ret != DACI_SUCCESS) { + FW_LOGD("Failed DACI_Update_ID_Page()\n"); + assert(false); + } else { + FW_LOGD("Success DACI_Update_ID_Page()\n"); + } + } + + /* delete list handling */ +/*for (iter = add_page_list->next; iter != delete_page_list; iter = iter->next) { */ + fw_list_iter(iter, delete_page_list) { + page = (id_page_t *)iter; + + /* delete page in db */ + ret = DACI_Delete_ID_Page(pId_provider->code, page->page_index); + if (ret != DACI_SUCCESS) { + FW_LOGD("Failed DACI_Delete_ID_Page()\n"); + assert(false); + } else { + FW_LOGD("Success DACI_Delete_ID_Page()\n"); + } + } + + FW_LOGD("ended"); + return id_error; +} + +id_provider_t *id_provider_create(unsigned int id_max, unsigned int log2_page_size, bool support_thread_safety) +{ + id_provider_init_routine(); + + unsigned int total_free_bit_cnt = id_max + 1; /* Since 0, 1, ..., id_max */ + return id_provider_create_internal(false, 0, total_free_bit_cnt, id_max, log2_page_size, support_thread_safety); +} + +void id_provider_destroy(id_provider_t *pId_provider) +{ + id_provider_init_routine(); + + if (pId_provider != NULL) { + if (pId_provider->support_thread_safety && pId_provider->mutex != NULL) { + g_mutex_free(pId_provider->mutex); + } + + id_provider_destroy_id_page_array(pId_provider->id_page_cnt, pId_provider->id_page_array); + + if (pId_provider->pTracking != NULL) { + id_provider_change_tracking_free(pId_provider->pTracking); + } + + free(pId_provider); + } +} + +id_provider_error_t id_provider_tracking_mode_on(id_provider_t *pId_provider) +{ + id_provider_error_t id_error = ID_PROVIDER_OK; + id_provider_init_routine(); + + if (pId_provider == NULL) { + FW_LOGD("Error. pId_provider == NULL\n"); + return ID_PROVIDER_NOT_EXIST_ID; + } + + if (pId_provider->support_thread_safety) { + id_provider_lock(pId_provider); + } + + if (pId_provider->tracking) { + id_error = ID_PROVIDER_ALREADY_TRACKING_MODE_ON; + } else { + pId_provider->tracking = true; + } + + if (pId_provider->support_thread_safety) { + id_provider_unlock(pId_provider); + } + + return id_error; +} + +id_provider_error_t id_provider_tracking_mode_off(id_provider_t *pId_provider) +{ + id_provider_error_t id_error = ID_PROVIDER_OK; + id_provider_init_routine(); + + if (pId_provider == NULL) { + FW_LOGD("Error. pId_provider == NULL\n"); + return ID_PROVIDER_NOT_EXIST_ID; + } + + if (pId_provider->support_thread_safety) { + id_provider_lock(pId_provider); + } + + if (!(pId_provider->tracking)) { + id_error = ID_PROVIDER_ALREADY_TRACKING_MODE_OFF; + } else { + pId_provider->tracking = false; + id_provider_reset_tracking_info(pId_provider); + } + + if (pId_provider->support_thread_safety) { + id_provider_unlock(pId_provider); + } + + return id_error; +} + +id_provider_error_t id_provider_provide_id(id_provider_t *pId_provider, unsigned int *new_id) +{ + FW_LOGD("start"); + id_provider_init_routine(); + + id_provider_error_t error = ID_PROVIDER_OK; + + unsigned int out_new_id = 0; + + unsigned int max_id = pId_provider->id_max; + unsigned int bits_per_page = pId_provider->bits_per_page; + + unsigned int offset = 0; + id_page_t *id_page = NULL; + unsigned int id_page_index = 0; + + id_provider_lock(pId_provider); + + assert(pId_provider->total_free_cnt >= 0); + if (pId_provider->total_free_cnt == 0) { + error = ID_PROVIDER_NOT_ENOUGH_ID; + goto error_part; + } + + /* find new id to provide */ + { + /* set first candidate as last id + 1 */ + out_new_id = (pId_provider->last_id + 1) % (max_id + 1); + + /* find id_page of first candidate */ + error = id_provider_fetch_id_page(pId_provider, out_new_id, &id_page); + if (error != ID_PROVIDER_OK) { + goto error_part; + } + assert(id_page != NULL); + assert(id_page->bits != NULL); + + /* calculate page_index & offset in id_page of first candidate */ + id_page_index = id_page_get_page_index(id_page); + offset = id_provider_calculate_offset_in_page(out_new_id, bits_per_page); + + /* note that below loop will be finished in the end, since pId_provider->total_free_cnt > 0, we must have one free id */ + while (true) { + + /* we have to look other page, since this page is full */ + if (id_page->free_bit_cnt == 0) { + if (id_provider_is_last_page_index(pId_provider, id_page_index)) { + id_page_index = 0; + } else { + id_page_index++; + } + + offset = 0; + error = id_provider_fetch_id_page_by_index(pId_provider, id_page_index, &id_page); + if (error != ID_PROVIDER_OK) { + goto error_part; + } + + continue; + } + + /* we can provide not reserved id in this page */ + if (id_page_is_bit_off(id_page, offset)) { + FW_LOGD("page_bit off at id_page = %u, offset = %u", id_page_index, offset); + /* DO NOTHING */ + } else { + FW_LOGD("page_bit on at id_page = %u, offset = %u", id_page_index, offset); + /* encounter already used id since we have once reached max id */ + /* in this case, find next free id */ + unsigned int next_offset = 0; + + bool find_next_free_offset_success = id_page_find_next_free_offset(id_page, offset, &next_offset); + assert(find_next_free_offset_success); + + offset = next_offset; + } + out_new_id = id_provider_calculate_id(pId_provider, id_page_index, offset); + break; + } + + bool set_bit_on_success = id_provider_set_id_page_bit_on(pId_provider, id_page, offset); + assert(set_bit_on_success); + + pId_provider->last_id = out_new_id; + *new_id = out_new_id; + } + +error_part: + if (error == ID_PROVIDER_OK && !(pId_provider->tracking)) { + id_provider_reset_tracking_info(pId_provider); + } + + id_provider_unlock(pId_provider); + FW_LOGD("end with error = %d, provided id = %u (page index = %u, offset = %u)", error, out_new_id, id_page_index, offset); + return error; +} + +id_provider_error_t id_provider_delete_id(id_provider_t *pId_provider, unsigned int id) +{ + id_provider_init_routine(); + + id_provider_error_t err = ID_PROVIDER_OK; + + unsigned int bits_per_page = pId_provider->bits_per_page; + id_page_t *id_page = NULL; + unsigned int offset = 0; + + id_provider_lock(pId_provider); + + if (!id_provider_is_valid_id_range(pId_provider, id)) { + err = ID_PROVIDER_OUT_OF_ID_RANGE; + goto error_part; + } + + offset = id_provider_calculate_offset_in_page(id, bits_per_page); + err = id_provider_fetch_id_page(pId_provider, id, &id_page); + if (err != ID_PROVIDER_OK) { + goto error_part; + } + + if (!id_provider_set_id_page_bit_off(pId_provider, id_page, offset)) { + /* bit already off case */ + err = ID_PROVIDER_NOT_EXIST_ID; + } + +error_part: + if (err == ID_PROVIDER_OK && !(pId_provider->tracking)) { + id_provider_reset_tracking_info(pId_provider); + } + id_provider_unlock(pId_provider); + return err; +} + +unsigned int id_provider_get_total_free_cnt(id_provider_t *pId_provider) +{ + return pId_provider->total_free_cnt; +} diff --git a/framework/src/Utility/fw_thread.c b/framework/src/Utility/fw_thread.c new file mode 100755 index 0000000..ff46b03 --- /dev/null +++ b/framework/src/Utility/fw_thread.c @@ -0,0 +1,86 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#include "Utility/fw_thread.h" +#include + +pthread_mutex_t *fw_alloc_init_mutex() +{ + pthread_mutex_t *mutex = (pthread_mutex_t *)malloc(sizeof(pthread_mutex_t)); + if (mutex == NULL) { + goto return_part; + } + if (0 != pthread_mutex_init(mutex, NULL)) { + free(mutex); + mutex = NULL; + goto return_part; + } + +return_part: + return mutex; +} + +void fw_free_mutex(pthread_mutex_t *mutex) +{ + if (mutex != NULL) { + pthread_mutex_destroy(mutex); + free(mutex); + } +} + +pthread_cond_t *fw_alloc_init_thread_cond() +{ + pthread_cond_t *thread_cond = (pthread_cond_t *)malloc(sizeof(pthread_cond_t)); + if (thread_cond == 0) { + goto return_part; + } + + if (0 != pthread_cond_init(thread_cond, 0)) { + free(thread_cond); + thread_cond = 0; + goto return_part; + } + +return_part: + return thread_cond; +} + +void fw_free_thread_cond(pthread_cond_t *thread_cond) +{ + if (thread_cond != 0) { + pthread_cond_destroy(thread_cond); + free(thread_cond); + } +} diff --git a/framework/src/Utility/fw_time.c b/framework/src/Utility/fw_time.c new file mode 100755 index 0000000..12696be --- /dev/null +++ b/framework/src/Utility/fw_time.c @@ -0,0 +1,71 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#include "Utility/fw_time.h" +#include "Utility/fw_log.h" +#define LOG_TAG "AF_TIME" + +static int get_time_zone_second(); +static int get_daylight_second(); + +int FW_Convert_Seconds_To_UTC(int seconds) +{ + seconds += get_time_zone_second(); + seconds += get_daylight_second(); + + return seconds; +} + +static int get_time_zone_second() +{ + int timeZone; + tzset(); + timeZone = timezone; + FW_LOGI("time zone : %d", timeZone); + timeZone = timeZone * -1; + return timeZone; +} + +static int get_daylight_second() +{ + int dayLight; + tzset(); + dayLight = daylight; + FW_LOGI("daylight = %d", dayLight); + if (dayLight == 0) { + return 0; + } + return 3600; +} diff --git a/framework/src/Utility/fw_timer.c b/framework/src/Utility/fw_timer.c new file mode 100755 index 0000000..ac0a9fe --- /dev/null +++ b/framework/src/Utility/fw_timer.c @@ -0,0 +1,175 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#include "Utility/fw_list.h" +#include "Utility/fw_timer.h" +#include "Utility/fw_log.h" + +#define LOG_TAG "AF_TIMER" + +#include +#include + +static fw_timer_element_t *fw_timer_element_alloc(char *label); +static void fw_timer_element_free(fw_timer_element_t *pElement); +static double calculate_diff_time(fw_timer_element_t *pElement); + +static fw_timer_element_t *fw_timer_element_alloc(char *label) +{ + fw_timer_element_t *pElement = NULL; + char *dest_label = NULL; + if (label == NULL) { + goto return_part; + } + + pElement = (fw_timer_element_t *)calloc(1, sizeof(fw_timer_element_t)); + if (pElement == NULL) { + FW_LOGE("fw_timer_element alloc failed because of out of memory"); + goto return_part; + } + dest_label = pElement->label; + + /* set label */ + strncpy(dest_label, label, FW_TIMER_MAX_LABEL_LEN + 1); + +return_part: + return pElement; +} + +static void fw_timer_element_free(fw_timer_element_t *pElement) +{ + if (pElement != NULL) { + free(pElement); + } +} + +fw_timer_t *fw_timer_alloc() +{ + fw_timer_t *pTimer = (fw_timer_t *)malloc(sizeof(fw_timer_t)); + + if (pTimer != NULL) { + fw_list_init(&(pTimer->element_head)); + } else { + FW_LOGE("fw_timer_alloc failed because of out of memory"); + } + + return pTimer; +} + +static double calculate_diff_time(fw_timer_element_t *pElement) +{ + double diff_time = 0.0; + double sTime = pElement->start_time.tv_sec + (pElement->start_time.tv_usec / 1000000.0); + double fTime = pElement->finish_time.tv_sec + (pElement->finish_time.tv_usec / 1000000.0); + diff_time = fTime - sTime; + + return diff_time; +} + +FW_ERROR fw_timer_start(fw_timer_t *pTimer, char *label) +{ + FW_ERROR err = FW_TIMER_OK; + if (pTimer == NULL) { + err = FW_TIMER_INVALID_TIMER; + goto return_part; + } + + fw_timer_element_t *pElement = fw_timer_element_alloc(label); + if (pElement == NULL) { + err = FW_TIMER_OUT_OF_MEMORY; + goto return_part; + } + + /* set timer start time */ + if (-1 == gettimeofday(&(pElement->start_time), NULL)) { + err = FW_TIMER_GETTIME_ERROR; + fw_timer_element_free(pElement); + goto return_part; + } + + /* add list */ + fw_list_add_node((fw_list_node_t *)pElement, &(pTimer->element_head)); + +return_part: + return err; +} + +FW_ERROR fw_timer_finish(fw_timer_t *pTimer, char *label, double *passed_sec) +{ + FW_ERROR err = FW_TIMER_OK; + fw_list_node_t *pIter = NULL; + fw_list_node_t *pHead = &(pTimer->element_head); + fw_timer_element_t *pElement = NULL; + + /* find list node */ + fw_list_iter(pIter, pHead) { + pElement = (fw_timer_element_t *)pIter; + + if (strncmp(label, pElement->label, FW_TIMER_MAX_LABEL_LEN) != 0) { + continue; + } + + if (-1 == gettimeofday(&(pElement->finish_time), NULL)) { + err = FW_TIMER_GETTIME_ERROR; + goto return_part; + } else { + /* calcuate passed_sec */ + if (passed_sec != NULL) { + *passed_sec = calculate_diff_time(pElement); + } + + break; + } + } + +return_part: + return err; +} + +/* TODO */ +FW_ERROR fw_timer_print(fw_timer_t *pTimer) +{ + FW_ERROR err = FW_TIMER_OK; + + return err; +} + +/* TODO */ +FW_ERROR fw_timer_free(fw_timer_t *pTimer) +{ + FW_ERROR err = FW_TIMER_OK; + + return err; +} diff --git a/framework/src/securityAssistant/EXT_SA_Encryption_Decryption.c b/framework/src/securityAssistant/EXT_SA_Encryption_Decryption.c new file mode 100755 index 0000000..755f3b7 --- /dev/null +++ b/framework/src/securityAssistant/EXT_SA_Encryption_Decryption.c @@ -0,0 +1,147 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Wook Choi + * Sooyi Kim + */ + +#include +#include + +#include "securityAssistant/EXT_SA_Encryption_Decryption.h" +#include "securityAssistant/IN_SA_MD5.h" +#include "securityAssistant/IN_SA_Cryptograhic_Hash_Function.h" + +#include "Utility/fw_log.h" + +#define LOG_TAG "AF_SA" + +static unsigned char *__encrypt_cryptograhic_hash(CRYPTOGRAHIC_HASH_FUNTION_TYPE type, const char *plain, int plain_len, const char *key, int key_len, CRYPTOGRAHIC_HASH_FUNTION_FLAGS flags); + +unsigned char *SA_Get_Encryption_Value(SA_ENCRYPTION_TYPE encryption_type, char *plain, int plain_length) +{ + unsigned char *encryption_text = 0; + + switch (encryption_type) { + case SA_ENCRYPTION_BASIC: + { + FW_LOGI("SA_ENCRYPTION_BASIC"); + } + break; + case SA_ENCRYPTION_MD5: + { + FW_LOGI("SA_ENCRYPTION_MD5"); + unsigned char *digest = (unsigned char *)calloc(16, sizeof(unsigned char)); + MD5GetDigest(plain, plain_length, digest); + + /* print */ + int i; + for (i = 0; i < strlen((const char *)digest); i++) { + FW_LOGI("%x", digest[i]); + } + FW_LOGI("\n"); + + encryption_text = digest; + + } + break; + default: + /* no case */ + break; + } + + FW_LOGI("plain_text = %s, length = %d", plain, plain_length); + FW_LOGI("encrption_text = %s", encryption_text); + return encryption_text; +} + +char *SA_Get_Decryption_Value(SA_ENCRYPTION_TYPE decryption_type, char *encryption_text) +{ + char *decyption_text = 0; + + switch (decryption_type) { + case SA_ENCRYPTION_BASIC: + { + FW_LOGI("SA_DECRYPTION_BASIC"); + } + break; + case SA_ENCRYPTION_MD5: + { + FW_LOGI("SA_DECRYPTION_MD5"); + } + break; + default: + /* no case */ + break; + } + + FW_LOGI("encryption_text = %s", encryption_text); + FW_LOGI("decyption_text = %s", decyption_text); + return decyption_text; +} + +unsigned char *SA_Encrypt_Cryptograhic_Hash(CRYPTOGRAHIC_HASH_FUNTION_TYPE type, const char *plain, int plain_len) +{ + return __encrypt_cryptograhic_hash(type, plain, plain_len, 0, 0, 0); +} + +unsigned char *SA_Encrypt_Cryptograhic_Hash_With_Flags(CRYPTOGRAHIC_HASH_FUNTION_TYPE type, const char *plain, int plain_len, const char *key, int key_len, CRYPTOGRAHIC_HASH_FUNTION_FLAGS flags) +{ + return __encrypt_cryptograhic_hash(type, plain, plain_len, key, key_len, flags); +} + +static unsigned char *__encrypt_cryptograhic_hash(CRYPTOGRAHIC_HASH_FUNTION_TYPE type, const char *plain, int plain_len, const char *key, int key_len, CRYPTOGRAHIC_HASH_FUNTION_FLAGS flags) +{ + unsigned char *crypt_data = 0; + + switch (type) { + case CRYPTOGRAHIC_HASH_FUNTION_MD5: + { + FW_LOGV("CRYPTOGRAHIC_HASH_FUNTION_MD5"); + crypt_data = crypt_MD5(flags, plain, plain_len, key, key_len); + } + break; + case CRYPTOGRAHIC_HASH_FUNTION_SHA1: + { + FW_LOGV("CRYPTOGRAHIC_HASH_FUNTION_SHA1"); + crypt_data = crypt_SHA1(flags, plain, plain_len, key, key_len); + } + break; + default: + { + FW_LOGV("default"); + } + break; + } + + return crypt_data; +} diff --git a/framework/src/securityAssistant/IN_SA_Cryptograhic_Hash_Function.c b/framework/src/securityAssistant/IN_SA_Cryptograhic_Hash_Function.c new file mode 100755 index 0000000..4178286 --- /dev/null +++ b/framework/src/securityAssistant/IN_SA_Cryptograhic_Hash_Function.c @@ -0,0 +1,158 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Wook Choi + * Sooyi Kim + */ + +#include "securityAssistant/IN_SA_Cryptograhic_Hash_Function.h" +#include +#include + +#include "Utility/fw_log.h" + +#define LOG_TAG "AF_SA" + +static unsigned char *__crypt_crytograhic_hash_function(int algo, const char *data, int data_len, const char *key, int key_len, int flags); +static unsigned char *__crypt_symmetric_cipher_function(const char *plain, int plain_len, const char *key, int key_len, int flags); + +unsigned char *crypt_DES(const char *plain, int plain_len, const char *key, int key_len) +{ + int flags = 0; + return __crypt_symmetric_cipher_function(plain, plain_len, key, key_len, flags); +} + +unsigned char *crypt_MD5(CRYPTOGRAHIC_HASH_FUNTION_FLAGS flags, const char *plain, int plain_len, const char *key, int key_len) +{ + unsigned char *crypt_data = 0; + + switch (flags) { + case CRYPTOGRAHIC_HASH_FUN_HMAC: + { + FW_LOGV("CRYPTOGRAHIC_HASH_FUN_HMAC"); + crypt_data = __crypt_crytograhic_hash_function(GCRY_MD_MD5, plain, plain_len, key, key_len, GCRY_MD_FLAG_HMAC); + } + break; + default: + { + FW_LOGV("default"); + crypt_data = __crypt_crytograhic_hash_function(GCRY_MD_MD5, plain, plain_len, 0, 0, 0); + } + break; + } + + return crypt_data; +} + +unsigned char *crypt_SHA1(CRYPTOGRAHIC_HASH_FUNTION_FLAGS flags, const char *plain, int plain_len, const char *key, int key_len) +{ + unsigned char *crypt_data = 0; + + switch (flags) { + case CRYPTOGRAHIC_HASH_FUN_HMAC: + { + FW_LOGV("CRYPTOGRAHIC_HASH_FUN_HMAC"); + crypt_data = __crypt_crytograhic_hash_function(GCRY_MD_SHA1, plain, plain_len, key, key_len, GCRY_MD_FLAG_HMAC); + } + break; + default: + { + FW_LOGV("default"); + crypt_data = __crypt_crytograhic_hash_function(GCRY_MD_SHA1, plain, plain_len, 0, 0, 0); + } + break; + } + + return crypt_data; +} + +static unsigned char *__crypt_crytograhic_hash_function(int algo, const char *data, int data_len, const char *key, int key_len, int flags) +{ + gcry_md_hd_t hd, hd2; + unsigned char *crypt_data = 0; + unsigned char *p = 0; + int crypt_data_len = 0; + int i; + gcry_error_t err = 0; + + err = gcry_md_open(&hd, algo, flags); + if (err) { + FW_LOGV("algo %d, grcy_md_open failed: %s\n", algo, gpg_strerror(err)); + return 0; + } + + crypt_data_len = gcry_md_get_algo_dlen(algo); + if (crypt_data_len < 1 || crypt_data_len > 500) { + FW_LOGV("algo %d, grcy_md_get_algo_dlen failed: %d\n", algo, crypt_data_len); + return 0; + } + + if (flags != 0) { + gcry_md_setkey(hd, key, key_len); + if (err) { + FW_LOGV("algo %d, grcy_md_setkey failed: %s\n", algo, gpg_strerror(err)); + return 0; + } + } + + if (*data == '!' && !data[1]) { /* hash one million times a "a" */ + char aaa[1000]; + + /* Write in odd size chunks so that we test the buffering. */ + memset(aaa, 'a', 1000); + for (i = 0; i < 1000; i++) + gcry_md_write(hd, aaa, 1000); + } else { + gcry_md_write(hd, data, data_len); + } + + err = gcry_md_copy(&hd2, hd); + if (err) { + FW_LOGV("algo %d, gcry_md_copy failed: %s\n", algo, gpg_strerror(err)); + } + + gcry_md_close(hd); + + p = gcry_md_read(hd2, algo); + if (p != 0) { + crypt_data = (unsigned char *)strdup((const char *)p); + } + + gcry_md_close(hd2); + + return crypt_data; +} + +static unsigned char *__crypt_symmetric_cipher_function(const char *plain, int plain_len, const char *key, int key_len, int flags) +{ + return NULL; +} diff --git a/framework/src/securityAssistant/IN_SA_MD5.c b/framework/src/securityAssistant/IN_SA_MD5.c new file mode 100755 index 0000000..783a473 --- /dev/null +++ b/framework/src/securityAssistant/IN_SA_MD5.c @@ -0,0 +1,233 @@ +/* +* $Id: md5.c,v 1.3 2004/04/14 21:06:23 mkern Exp $ +* This code implements the MD5 message-digest algorithm. +* The algorithm is due to Ron Rivest. This code was +* written by Colin Plumb in 1993, no copyright is claimed. +* This code is in the public domain; do with it what you wish. +* +* Equivalent code is available from RSA Data Security, Inc. +* This code has been tested against that, and is equivalent, +* except that you don't need to include two pages of legalese +* with every copy. +* +* To compute the message digest of a chunk of bytes, declare an +* MD5Context structure, pass it to MD5Init, call MD5Update as +* needed on buffers full of bytes, and then call MD5Final, which +* will fill a supplied 16-byte array with the digest. +*/ + + + +#include +#include "securityAssistant/IN_SA_MD5.h" + +static void MD5Transform(unsigned long int buf[4], const unsigned long int in[16]); +static void _byte_reverse(unsigned char *buf, unsigned int longs); + +void MD5GetDigest(const char *buffer, int buffer_size, unsigned char *digest) +{ + MD5Context ctx; + + MD5Init(&ctx); + MD5Update(&ctx, buffer, buffer_size); + MD5Final(&ctx, digest); + +} + +void MD5Init(MD5Context *ctx) +{ + ctx->buf[0] = 0x67452301; + ctx->buf[1] = 0xefcdab89; + ctx->buf[2] = 0x98badcfe; + ctx->buf[3] = 0x10325476; + + ctx->bits[0] = 0; + ctx->bits[1] = 0; + + if (IS_BIG_ENDIAN()) + ctx->doByteReverse = 1; + else + ctx->doByteReverse = 0; +} + +void MD5Update(MD5Context *ctx, const char *buf, unsigned long int len) +{ + unsigned int t; + + /* Update bitcount */ + + t = ctx->bits[0]; + if ((ctx->bits[0] = t + ((unsigned int)len << 3)) < t) + ctx->bits[1]++; /* Carry from low to high */ + ctx->bits[1] += len >> 29; + + t = (t >> 3) & 0x3f; /* Bytes already in shsInfo->data */ + + /* Handle any leading odd-sized chunks */ + + if (t) { + unsigned char *p = (unsigned char *)ctx->in + t; + + t = 64 - t; + if (len < t) { + memcpy(p, buf, len); + return; + } + memcpy(p, buf, t); + if (ctx->doByteReverse) + _byte_reverse(ctx->in, 16); + MD5Transform(ctx->buf, (const long unsigned int *)ctx->in); + buf += t; + len -= t; + } + /* Process data in 64-byte chunks */ + + while (len >= 64) { + memcpy(ctx->in, buf, 64); + if (ctx->doByteReverse) + _byte_reverse(ctx->in, 16); + MD5Transform(ctx->buf, (const long unsigned int *)ctx->in); + buf += 64; + len -= 64; + } + + /* Handle any remaining bytes of data. */ + + memcpy(ctx->in, buf, len); +} + +static void MD5Transform(unsigned long int buf[4], const unsigned long int in[16]) +{ + register unsigned int a, b, c, d; + + a = buf[0]; + b = buf[1]; + c = buf[2]; + d = buf[3]; + + MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7); + MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12); + MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17); + MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22); + MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7); + MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12); + MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17); + MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22); + MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7); + MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12); + MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17); + MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22); + MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7); + MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12); + MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17); + MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22); + + MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5); + MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9); + MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14); + MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20); + MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5); + MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9); + MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14); + MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20); + MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5); + MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9); + MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14); + MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20); + MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5); + MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9); + MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14); + MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20); + + MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4); + MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11); + MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16); + MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23); + MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4); + MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11); + MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16); + MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23); + MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4); + MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11); + MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16); + MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23); + MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4); + MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11); + MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16); + MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23); + + MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6); + MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10); + MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15); + MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21); + MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6); + MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10); + MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15); + MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21); + MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6); + MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10); + MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15); + MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21); + MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6); + MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10); + MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15); + MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21); + + buf[0] += a; + buf[1] += b; + buf[2] += c; + buf[3] += d; +} + +static void _byte_reverse(unsigned char *buf, unsigned int longs) +{ + unsigned int t; + do { + t = (unsigned int)((unsigned int)buf[3] << 8 | buf[2]) << 16 | ((unsigned int)buf[1] << 8 | buf[0]); + *(unsigned int *)buf = t; + buf += 4; + } while (--longs); +} + +void MD5Final(MD5Context *ctx, unsigned char *digest) +{ + unsigned int count; + unsigned char *p; + + /* Compute number of bytes mod 64 */ + count = (ctx->bits[0] >> 3) & 0x3F; + + /* Set the first char of padding to 0x80. This is safe since there is + always at least one byte free */ + p = ctx->in + count; + *p++ = 0x80; + + /* Bytes of padding needed to make 64 bytes */ + count = 64 - 1 - count; + + /* Pad out to 56 mod 64 */ + if (count < 8) { + /* Two lots of padding: Pad the first block to 64 bytes */ + memset(p, 0, count); + if (ctx->doByteReverse) + _byte_reverse(ctx->in, 16); + MD5Transform(ctx->buf, (const long unsigned int *)ctx->in); + + /* Now fill the next block with 56 bytes */ + memset(ctx->in, 0, 56); + } else { + /* Pad block to 56 bytes */ + memset(p, 0, count - 8); + } + if (ctx->doByteReverse) + _byte_reverse(ctx->in, 14); + + /* Append length in bits and transform */ + ((unsigned int *)ctx->in)[14] = ctx->bits[0]; + ((unsigned int *)ctx->in)[15] = ctx->bits[1]; + + MD5Transform(ctx->buf, (const long unsigned int *)ctx->in); + if (ctx->doByteReverse) + _byte_reverse((unsigned char *)ctx->buf, 4); + memcpy(digest, ctx->buf, 16); +} diff --git a/framework/test/include/suites/unit_test_fw_alloc_suite.h b/framework/test/include/suites/unit_test_fw_alloc_suite.h new file mode 100755 index 0000000..0884426 --- /dev/null +++ b/framework/test/include/suites/unit_test_fw_alloc_suite.h @@ -0,0 +1,15 @@ +/* + * unit_test_fw_alloc_suite.h + * + * Created on: 2011. 7. 28. + * Author: yangjoo.suh + */ + +#ifndef UNIT_TEST_FW_ALLOC_SUITE_H_ +#define UNIT_TEST_FW_ALLOC_SUITE_H_ + +#include "unit_test_common.h" + +Suite *fw_alloc_suite(void); + +#endif /* UNIT_TEST_FW_ALLOC_SUITE_H_ */ diff --git a/framework/test/include/suites/unit_test_fw_log_suite.h b/framework/test/include/suites/unit_test_fw_log_suite.h new file mode 100755 index 0000000..23d0ef1 --- /dev/null +++ b/framework/test/include/suites/unit_test_fw_log_suite.h @@ -0,0 +1,15 @@ +/* + * unit_test_fw_log_suite.h + * + * Created on: 2011. 9. 25. + * Author: yangjoo.suh + */ + +#ifndef UNIT_TEST_FW_LOG_SUITE_H_ +#define UNIT_TEST_FW_LOG_SUITE_H_ + +#include "unit_test_common.h" + +Suite *fw_log_suite(void); + +#endif /* UNIT_TEST_FW_LOG_SUITE_H_ */ diff --git a/framework/test/include/suites/unit_test_fw_sequential_id_provider_suite.h b/framework/test/include/suites/unit_test_fw_sequential_id_provider_suite.h new file mode 100755 index 0000000..c499f65 --- /dev/null +++ b/framework/test/include/suites/unit_test_fw_sequential_id_provider_suite.h @@ -0,0 +1,15 @@ +/* + * unit_test_fw_sequential_id_provider_suite.h + * + * Created on: 2011. 10. 18. + * Author: yangjoo.suh + */ + +#ifndef UNIT_TEST_FW_SEQUENTIAL_ID_PROVIDER_SUITE_H_ +#define UNIT_TEST_FW_SEQUENTIAL_ID_PROVIDER_SUITE_H_ + +#include "unit_test_common.h" + +Suite *fw_sequential_id_provider_suite(void); + +#endif /* UNIT_TEST_FW_SEQUENTIAL_ID_PROVIDER_SUITE_H_ */ diff --git a/framework/test/include/suites/unit_test_protocol_binder_suite.h b/framework/test/include/suites/unit_test_protocol_binder_suite.h new file mode 100755 index 0000000..3f45095 --- /dev/null +++ b/framework/test/include/suites/unit_test_protocol_binder_suite.h @@ -0,0 +1,15 @@ +/* + * unit_test_protocol_binder_suite.h + * + * Created on: 2011. 9. 21. + * Author: yangjoo.suh + */ + +#ifndef UNIT_TEST_PROTOCOL_BINDER_SUITE_H_ +#define UNIT_TEST_PROTOCOL_BINDER_SUITE_H_ + +#include "unit_test_common.h" + +Suite *protocol_binder_suite(void); + +#endif /* UNIT_TEST_PROTOCOL_BINDER_SUITE_H_ */ diff --git a/framework/test/include/suites/unit_test_sample_suite.h b/framework/test/include/suites/unit_test_sample_suite.h new file mode 100755 index 0000000..55774c4 --- /dev/null +++ b/framework/test/include/suites/unit_test_sample_suite.h @@ -0,0 +1,15 @@ +/* + * unit_test_sample_suite.h + * + * Created on: 2011. 7. 28. + * Author: yangjoo.suh + */ + +#ifndef UNIT_TEST_SUITE_H_ +#define UNIT_TEST_SUITE_H_ + +#include "unit_test_common.h" + +Suite *sample_suite(void); + +#endif /* UNIT_TEST_SUITE_H_ */ diff --git a/framework/test/include/unit_test_common.h b/framework/test/include/unit_test_common.h new file mode 100755 index 0000000..fdf0ee5 --- /dev/null +++ b/framework/test/include/unit_test_common.h @@ -0,0 +1,16 @@ +/* + * unit_test_common.h + * + * Created on: 2011. 7. 28. + * Author: yangjoo.suh + */ + +#ifndef UNIT_TEST_COMMON_H_ +#define UNIT_TEST_COMMON_H_ + +#include +#include +#include +#include + +#endif /* UNIT_TEST_COMMON_H_ */ diff --git a/framework/test/include/unit_test_run.h b/framework/test/include/unit_test_run.h new file mode 100755 index 0000000..fd9c075 --- /dev/null +++ b/framework/test/include/unit_test_run.h @@ -0,0 +1,22 @@ +/* + * unit_test.h + * + * Created on: 2011. 3. 29. + * Author: yangjoo + */ + +#ifndef UNIT_TEST_H_ +#define UNIT_TEST_H_ + +#include "unit_test_common.h" + +typedef enum run_unit_test_mode run_unit_test_mode_t; +enum run_unit_test_mode { + FUNCTION_MODE, /* unit test runs just like function */ + /* good for debugging */ + FORK_MODE +}; + +int unit_test_run(run_unit_test_mode_t mode); + +#endif /* UNIT_TEST_H_ */ diff --git a/framework/test/include/unit_test_suites.h b/framework/test/include/unit_test_suites.h new file mode 100755 index 0000000..2f26627 --- /dev/null +++ b/framework/test/include/unit_test_suites.h @@ -0,0 +1,28 @@ +/* + * unit_test_suites.h + * + * Created on: 2011. 7. 28. + * Author: yangjoo.suh + */ + +#ifndef UNIT_TEST_SUITES_H_ +#define UNIT_TEST_SUITES_H_ + +#include "unit_test_common.h" +#include "suites/unit_test_sample_suite.h" +#include "suites/unit_test_fw_alloc_suite.h" +#include "suites/unit_test_fw_log_suite.h" +#include "suites/unit_test_protocol_binder_suite.h" +#include "suites/unit_test_fw_sequential_id_provider_suite.h" + +/* define here suites to be tested */ +typedef Suite *(*SUITE_FUNCTION) (void); +static SUITE_FUNCTION suiteFunctions[] = { + sample_suite, + fw_alloc_suite, + fw_log_suite, + protocol_binder_suite, + fw_sequential_id_provider_suite +}; + +#endif /* UNIT_TEST_SUITES_H_ */ diff --git a/framework/test/src/fw_test_main.c b/framework/test/src/fw_test_main.c new file mode 100755 index 0000000..8537845 --- /dev/null +++ b/framework/test/src/fw_test_main.c @@ -0,0 +1,14 @@ +/* + * fw_test_main.c + * + * Created on: 2011. 7. 28. + * Author: yangjoo.suh + */ + +#include "unit_test_run.h" + +int main(void) +{ + int test_success = unit_test_run(FUNCTION_MODE); + return test_success; +} diff --git a/framework/test/src/suites/unit_test_fw_alloc_suite.c b/framework/test/src/suites/unit_test_fw_alloc_suite.c new file mode 100755 index 0000000..66649b2 --- /dev/null +++ b/framework/test/src/suites/unit_test_fw_alloc_suite.c @@ -0,0 +1,105 @@ +/* + * unit_test_fw_alloc_suite.c + * + * Created on: 2011. 7. 28. + * Author: yangjoo.suh + */ + +#include "unit_test_common.h" +#include "suites/unit_test_fw_alloc_suite.h" +#include "Utility/fw_alloc_internal.h" +#include "Utility/fw_alloc.h" + +#include + +/* test internal interfaces */ +#ifndef NDEBUG +START_TEST(_alloc_init_realbytes_test) +{ + bool success = false; + + unsigned int bytes = 10; + const char *file = "main.c"; + int line = 10; + + /* allocation */ + void *pRealbytes = _alloc_init_realbytes(bytes, file, line); + if (pRealbytes == NULL) { + fail(); + } + + /* test */ + /* check redzone */ + success = check_redzone(pRealbytes); + fail_unless(success); + + /* check debug info */ + alloc_debug_info_t *pAlloc_debug_info = get_debug_info(pRealbytes); + fail_unless(!strcmp(pAlloc_debug_info->file, file)); + fail_unless(pAlloc_debug_info->line == line); + fail_unless(pAlloc_debug_info->size == bytes); + + /* free allocated */ + _free_realbytes(pRealbytes); +} + +END_TEST +/* test external interfaces */ +START_TEST(_fw_malloc_and_fw_free_test) +{ + unsigned int bytes = 100; + void *ptr = NULL; + + /* allocation */ + ptr = _fw_malloc(bytes, __FILE__, __LINE__); + fail_unless(ptr != NULL); + + /* free */ + _fw_free(ptr); +} + +END_TEST START_TEST(_fw_calloc_and_fw_free_test) +{ + unsigned int bytes = 100; + void *ptr = NULL; + + /* allocation */ + ptr = _fw_calloc(bytes, __FILE__, __LINE__); + fail_unless(ptr != NULL); + + /* free */ + _fw_free(ptr); +} + +END_TEST +#endif /* NDEBUG */ +Suite *fw_alloc_suite(void) +{ + /* create test suite */ + Suite *s = suite_create("fw_allocation"); + +#ifndef NDEBUG + /* test case create and add in suite */ + { + TCase *tcase = tcase_create("_fw_malloc"); + + tcase_add_test(tcase, _alloc_init_realbytes_test); + tcase_add_test(tcase, _fw_malloc_and_fw_free_test); + tcase_set_timeout(tcase, 1); + + suite_add_tcase(s, tcase); + } + + /* test case create and add in suite */ + { + TCase *tcase = tcase_create("_fw_calloc"); + + tcase_add_test(tcase, _fw_calloc_and_fw_free_test); + tcase_set_timeout(tcase, 1); + + suite_add_tcase(s, tcase); + } +#endif /* NDEBUG */ + + return s; +} diff --git a/framework/test/src/suites/unit_test_fw_log_suite.c b/framework/test/src/suites/unit_test_fw_log_suite.c new file mode 100755 index 0000000..0dadd97 --- /dev/null +++ b/framework/test/src/suites/unit_test_fw_log_suite.c @@ -0,0 +1,49 @@ +/* + * unit_test_fw_log_suite.c + * + * Created on: 2011. 9. 25. + * Author: yangjoo.suh + */ + +#include "unit_test_common.h" +#include "suites/unit_test_fw_log_suite.h" +#include "Utility/fw_log.h" + +/* test external interfaces */ + +#define LOG_TAG "UNIT_TEST_FW_LOG" + +START_TEST(_color_logging_test) +{ + /* first example : logging with default option */ + FW_LOGV("print with default option !"); + + /* second example : logging with background color & word color */ + /* note that in below code, FW_TM_OPT_RED_WORD & FW_TM_OPT_WHITE_BACKGROUND is separated by space operator */ + /* and the order is not important */ + FW_LOGV_WITH_TERMINAL_OPTION(FW_TM_OPT_RED_WORD FW_TM_OPT_WHITE_BACKGROUND, "print red word in white background !"); + + /* third example : setting only word color */ + FW_LOGV_WITH_TERMINAL_OPTION(FW_TM_OPT_GREEN_WORD, "print green word in default background !"); + + /* second example : setting only background color */ + FW_LOGV_WITH_TERMINAL_OPTION(FW_TM_OPT_BLUE_BACKGROUND, "print default color word in blue background !"); +} + +END_TEST Suite *fw_log_suite(void) +{ + /* create test suite */ + Suite *s = suite_create("fw_logging"); + + /* test case create and add in suite */ + { + TCase *tcase = tcase_create("color logging test"); + + tcase_add_test(tcase, _color_logging_test); + tcase_set_timeout(tcase, 1); + + suite_add_tcase(s, tcase); + } + + return s; +} diff --git a/framework/test/src/suites/unit_test_fw_sequential_id_provider_suite.c b/framework/test/src/suites/unit_test_fw_sequential_id_provider_suite.c new file mode 100755 index 0000000..100c209 --- /dev/null +++ b/framework/test/src/suites/unit_test_fw_sequential_id_provider_suite.c @@ -0,0 +1,427 @@ +/* + * unit_test_fw_sequential_id_provider_suite.c + * + * Created on: 2011. 10. 18. + * Author: yangjoo.suh + */ + +#include +#include "unit_test_common.h" +#include "Utility/fw_sequential_id_provider.h" +#include "Utility/fw_sequential_id_provider_internal.h" +#include "suites/unit_test_fw_sequential_id_provider_suite.h" + +START_TEST(provide_id_without_delete_id_test1) +{ + unsigned int max_id = 100; + id_provider_t *pId_provider = id_provider_create(max_id, 12, true); + + fail_unless(pId_provider->total_free_cnt == max_id + 1); + + unsigned int i = 0; + unsigned int id = 0; + id_provider_error_t error = ID_PROVIDER_OK; + + for (i = 0; i <= max_id; i++) { + error = id_provider_provide_id(pId_provider, &id); + fail_unless(error == ID_PROVIDER_OK); + fail_unless(i == id); + fail_unless(pId_provider->total_free_cnt == (max_id + 1 - (i + 1))); + } + + error = id_provider_provide_id(pId_provider, &id); + fail_unless(error == ID_PROVIDER_NOT_ENOUGH_ID); + fail_unless(pId_provider->total_free_cnt == 0); + + id_provider_destroy(pId_provider); + fprintf(stderr, "provide_id_without_delete_id_test1 done\n"); +} + +END_TEST START_TEST(provide_id_without_delete_id_test2) +{ + unsigned int max_id = (1024 * 4) * 8; + id_provider_t *pId_provider = id_provider_create(max_id, 12, true); + + fail_unless(pId_provider->total_free_cnt == max_id + 1); + + unsigned int i = 0; + unsigned int id = 0; + id_provider_error_t error = ID_PROVIDER_OK; + for (i = 0; i <= max_id; i++) { + error = id_provider_provide_id(pId_provider, &id); + fail_unless(error == ID_PROVIDER_OK); + fail_unless(i == id); + + fail_unless(pId_provider->total_free_cnt == (max_id + 1 - (i + 1))); + } + + error = id_provider_provide_id(pId_provider, &id); + fail_unless(error == ID_PROVIDER_NOT_ENOUGH_ID); + fail_unless(pId_provider->total_free_cnt == 0); + + id_provider_destroy(pId_provider); + + fprintf(stderr, "provide_id_without_delete_id_test2 done\n"); +} + +END_TEST START_TEST(provide_id_without_delete_id_test3) +{ + unsigned int max_id = (1024 * 4) * 8 * 2; + id_provider_t *pId_provider = id_provider_create(max_id, 12, true); + + fail_unless(pId_provider->total_free_cnt == max_id + 1); + + unsigned int i = 0; + unsigned int id = 0; + id_provider_error_t error = ID_PROVIDER_OK; + for (i = 0; i <= max_id; i++) { + error = id_provider_provide_id(pId_provider, &id); + fail_unless(error == ID_PROVIDER_OK); + fail_unless(i == id); + + fail_unless(pId_provider->total_free_cnt == (max_id + 1 - (i + 1))); + } + + error = id_provider_provide_id(pId_provider, &id); + fail_unless(error == ID_PROVIDER_NOT_ENOUGH_ID); + fail_unless(pId_provider->total_free_cnt == 0); + + id_provider_destroy(pId_provider); + fprintf(stderr, "provide_id_without_delete_id_test3 done\n"); +} + +END_TEST START_TEST(provide_id_with_delete_id_test1) +{ + unsigned int max_id = 100; + id_provider_t *pId_provider = id_provider_create(max_id, 12, true); + + fail_unless(pId_provider->total_free_cnt == max_id + 1); + + unsigned int i = 0; + unsigned int j = 0; + unsigned int id = 0; + id_provider_error_t error = ID_PROVIDER_OK; + + for (i = 0; i <= max_id / 10; i++) { + error = id_provider_provide_id(pId_provider, &id); + fail_unless(error == ID_PROVIDER_OK); + fail_unless(i == id); + + fail_unless(pId_provider->total_free_cnt == (max_id + 1 - (i + 1))); + } + + for (j = 0; j <= max_id / 20; j++) { + fail_unless(ID_PROVIDER_OK == id_provider_delete_id(pId_provider, j)); + fail_unless(pId_provider->total_free_cnt == (max_id + 1 - (max_id / 10 + 1)) + j + 1); + } + + for (i = max_id / 10 + 1; i <= max_id; i++) { + error = id_provider_provide_id(pId_provider, &id); + fail_unless(error == ID_PROVIDER_OK); + fail_unless(i == id); + + fail_unless(pId_provider->total_free_cnt == (max_id + 1 - (i + 1)) + max_id / 20 + 1); + } + + for (j = 0; j <= max_id / 20; j++) { + error = id_provider_provide_id(pId_provider, &id); + fail_unless(error == ID_PROVIDER_OK); + fail_unless(j == id); + + fail_unless(pId_provider->total_free_cnt == (max_id / 20 - j)); + } + + error = id_provider_provide_id(pId_provider, &id); + fail_unless(error == ID_PROVIDER_NOT_ENOUGH_ID); + fail_unless(pId_provider->total_free_cnt == 0); + + fail_unless(ID_PROVIDER_OK == id_provider_delete_id(pId_provider, 50)); + fail_unless(pId_provider->total_free_cnt == 1); + + fail_unless(ID_PROVIDER_NOT_EXIST_ID == id_provider_delete_id(pId_provider, 50)); + fail_unless(pId_provider->total_free_cnt == 1); + + fail_unless(ID_PROVIDER_OUT_OF_ID_RANGE == id_provider_delete_id(pId_provider, 101)); + fail_unless(ID_PROVIDER_OUT_OF_ID_RANGE == id_provider_delete_id(pId_provider, 102)); + fail_unless(ID_PROVIDER_OUT_OF_ID_RANGE == id_provider_delete_id(pId_provider, 2000)); + + id_provider_destroy(pId_provider); + fprintf(stderr, "provide_id_with_delete_id_test1 done\n"); +} + +END_TEST START_TEST(provide_id_with_delete_id_test2) +{ + unsigned int max_id = (1024 * 4) * 8; + id_provider_t *pId_provider = id_provider_create(max_id, 12, true); + + fail_unless(pId_provider->total_free_cnt == max_id + 1); + + unsigned int i = 0; + unsigned int j = 0; + unsigned int id = 0; + id_provider_error_t error = ID_PROVIDER_OK; + + for (i = 0; i <= max_id / 10; i++) { + error = id_provider_provide_id(pId_provider, &id); + fail_unless(error == ID_PROVIDER_OK); + fail_unless(i == id); + + fail_unless(pId_provider->total_free_cnt == (max_id + 1 - (i + 1))); + } + + for (j = 0; j <= max_id / 20; j++) { + fail_unless(ID_PROVIDER_OK == id_provider_delete_id(pId_provider, j)); + fail_unless(pId_provider->total_free_cnt == (max_id + 1 - (max_id / 10 + 1)) + j + 1); + } + + for (i = max_id / 10 + 1; i <= max_id; i++) { + error = id_provider_provide_id(pId_provider, &id); + fail_unless(error == ID_PROVIDER_OK); + fail_unless(i == id); + + fail_unless(pId_provider->total_free_cnt == (max_id + 1 - (i + 1)) + max_id / 20 + 1); + } + + for (j = max_id / 2; j <= max_id; j++) { + fail_unless(ID_PROVIDER_OK == id_provider_delete_id(pId_provider, j)); + fail_unless(pId_provider->total_free_cnt == max_id / 20 + 1 + (j - max_id / 2) + 1); + } + + for (j = 0; j <= max_id / 20; j++) { + error = id_provider_provide_id(pId_provider, &id); + fail_unless(error == ID_PROVIDER_OK); + fail_unless(j == id); + + fail_unless(pId_provider->total_free_cnt == max_id / 20 + 1 + (max_id - max_id / 2) + 1 - (j + 1)); + } + + for (j = max_id / 2; j <= max_id; j++) { + error = id_provider_provide_id(pId_provider, &id); + fail_unless(error == ID_PROVIDER_OK); + fail_unless(j == id); + + fail_unless(pId_provider->total_free_cnt == max_id / 20 + 1 + (max_id - max_id / 2) + 1 - (max_id / 20 + 1) - (j - max_id / 2 + 1)); + } + + error = id_provider_provide_id(pId_provider, &id); + fail_unless(error == ID_PROVIDER_NOT_ENOUGH_ID); + fail_unless(pId_provider->total_free_cnt == 0); + + fail_unless(ID_PROVIDER_OK == id_provider_delete_id(pId_provider, 50)); + fail_unless(pId_provider->total_free_cnt == 1); + + fail_unless(ID_PROVIDER_NOT_EXIST_ID == id_provider_delete_id(pId_provider, 50)); + fail_unless(pId_provider->total_free_cnt == 1); + + fail_unless(ID_PROVIDER_OUT_OF_ID_RANGE == id_provider_delete_id(pId_provider, max_id + 1)); + fail_unless(ID_PROVIDER_OUT_OF_ID_RANGE == id_provider_delete_id(pId_provider, max_id + 2)); + fail_unless(ID_PROVIDER_OUT_OF_ID_RANGE == id_provider_delete_id(pId_provider, max_id + 1000)); + + id_provider_destroy(pId_provider); + fprintf(stderr, "provide_id_with_delete_id_test2 done\n"); +} + +END_TEST START_TEST(provide_id_without_unchanged_list) +{ + unsigned int page_bit_cnt = (1024 * 4) * 8; + unsigned int max_id = 3 * page_bit_cnt - 1; + id_provider_t *pId_provider = id_provider_create(max_id, 12, true); + + unsigned int i = 0; + unsigned int id = 0; + + id_provider_error_t error = ID_PROVIDER_OK; + fail_unless(pId_provider->total_free_cnt == max_id + 1); + + for (i = 0; i < page_bit_cnt; i++) { + error = id_provider_provide_id(pId_provider, &id); + fail_unless(error == ID_PROVIDER_OK); + fail_unless(i == id); + fail_unless(pId_provider->total_free_cnt == (max_id + 1 - (i + 1))); + + fail_unless(list_count(&(pId_provider->pTracking->id_page_add_list_head)) == 1); + fail_unless(list_count(&(pId_provider->pTracking->id_page_update_list_head)) == 0); + fail_unless(list_count(&(pId_provider->pTracking->id_page_delete_list_head)) == 0); + fail_unless(list_count(&(pId_provider->pTracking->id_page_unchanged_list_head)) == 0); + } + + for (i = page_bit_cnt; i < 2 * page_bit_cnt; i++) { + error = id_provider_provide_id(pId_provider, &id); + fail_unless(error == ID_PROVIDER_OK); + fail_unless(i == id); + fail_unless(pId_provider->total_free_cnt == (max_id + 1 - (i + 1))); + + fail_unless(list_count(&(pId_provider->pTracking->id_page_add_list_head)) == 2); + fail_unless(list_count(&(pId_provider->pTracking->id_page_update_list_head)) == 0); + fail_unless(list_count(&(pId_provider->pTracking->id_page_delete_list_head)) == 0); + fail_unless(list_count(&(pId_provider->pTracking->id_page_unchanged_list_head)) == 0); + } + + for (i = 2 * page_bit_cnt; i < 3 * page_bit_cnt; i++) { + error = id_provider_provide_id(pId_provider, &id); + fail_unless(error == ID_PROVIDER_OK); + fail_unless(i == id); + fail_unless(pId_provider->total_free_cnt == (max_id + 1 - (i + 1))); + + fail_unless(list_count(&(pId_provider->pTracking->id_page_add_list_head)) == 3); + fail_unless(list_count(&(pId_provider->pTracking->id_page_update_list_head)) == 0); + fail_unless(list_count(&(pId_provider->pTracking->id_page_delete_list_head)) == 0); + fail_unless(list_count(&(pId_provider->pTracking->id_page_unchanged_list_head)) == 0); + } + + for (i = 0; i < page_bit_cnt - 1; i++) { + error = id_provider_delete_id(pId_provider, i); + fail_unless(error == ID_PROVIDER_OK); + fail_unless(pId_provider->total_free_cnt == (i + 1)); + + fail_unless(list_count(&(pId_provider->pTracking->id_page_add_list_head)) == 3); + fail_unless(list_count(&(pId_provider->pTracking->id_page_update_list_head)) == 0); + fail_unless(list_count(&(pId_provider->pTracking->id_page_delete_list_head)) == 0); + fail_unless(list_count(&(pId_provider->pTracking->id_page_unchanged_list_head)) == 0); + } + + error = id_provider_delete_id(pId_provider, page_bit_cnt - 1); + fail_unless(error == ID_PROVIDER_OK); + fail_unless(pId_provider->total_free_cnt == page_bit_cnt); + + fail_unless(list_count(&(pId_provider->pTracking->id_page_add_list_head)) == 2); + fail_unless(list_count(&(pId_provider->pTracking->id_page_update_list_head)) == 0); + fail_unless(list_count(&(pId_provider->pTracking->id_page_delete_list_head)) == 0); + fail_unless(list_count(&(pId_provider->pTracking->id_page_unchanged_list_head)) == 0); + + id_provider_destroy(pId_provider); +} + +END_TEST START_TEST(provide_id_with_unchanged_list) +{ + unsigned int page_bit_cnt = (1024 * 4) * 8; + unsigned int max_id = 4 * page_bit_cnt - 1; + id_provider_t *pId_provider = id_provider_create(max_id, 12, true); + + unsigned int i = 0; + unsigned int id = 0; + + id_provider_error_t error = ID_PROVIDER_OK; + fail_unless(pId_provider->total_free_cnt == max_id + 1); + + /* prepare test */ + for (i = 0; i < page_bit_cnt; i++) { + error = id_provider_provide_id(pId_provider, &id); + fail_unless(error == ID_PROVIDER_OK); + fail_unless(i == id); + fail_unless(pId_provider->total_free_cnt == (max_id + 1 - (i + 1))); + + fail_unless(list_count(&(pId_provider->pTracking->id_page_add_list_head)) == 1); + fail_unless(list_count(&(pId_provider->pTracking->id_page_update_list_head)) == 0); + fail_unless(list_count(&(pId_provider->pTracking->id_page_delete_list_head)) == 0); + fail_unless(list_count(&(pId_provider->pTracking->id_page_unchanged_list_head)) == 0); + } + + for (i = page_bit_cnt; i < 2 * page_bit_cnt; i++) { + error = id_provider_provide_id(pId_provider, &id); + fail_unless(error == ID_PROVIDER_OK); + fail_unless(i == id); + fail_unless(pId_provider->total_free_cnt == (max_id + 1 - (i + 1))); + + fail_unless(list_count(&(pId_provider->pTracking->id_page_add_list_head)) == 2); + fail_unless(list_count(&(pId_provider->pTracking->id_page_update_list_head)) == 0); + fail_unless(list_count(&(pId_provider->pTracking->id_page_delete_list_head)) == 0); + fail_unless(list_count(&(pId_provider->pTracking->id_page_unchanged_list_head)) == 0); + } + + for (i = 2 * page_bit_cnt; i < 3 * page_bit_cnt; i++) { + error = id_provider_provide_id(pId_provider, &id); + fail_unless(error == ID_PROVIDER_OK); + fail_unless(i == id); + fail_unless(pId_provider->total_free_cnt == (max_id + 1 - (i + 1))); + + fail_unless(list_count(&(pId_provider->pTracking->id_page_add_list_head)) == 3); + fail_unless(list_count(&(pId_provider->pTracking->id_page_update_list_head)) == 0); + fail_unless(list_count(&(pId_provider->pTracking->id_page_delete_list_head)) == 0); + fail_unless(list_count(&(pId_provider->pTracking->id_page_unchanged_list_head)) == 0); + } + + /* move all add list to unchaged list for test */ + id_provider_move_id_page(pId_provider, pId_provider->id_page_array[0], ID_PAGE_FLAG_UNCHANGED); + id_provider_move_id_page(pId_provider, pId_provider->id_page_array[1], ID_PAGE_FLAG_UNCHANGED); + id_provider_move_id_page(pId_provider, pId_provider->id_page_array[2], ID_PAGE_FLAG_UNCHANGED); + + fail_unless(list_count(&(pId_provider->pTracking->id_page_add_list_head)) == 0); + fail_unless(list_count(&(pId_provider->pTracking->id_page_update_list_head)) == 0); + fail_unless(list_count(&(pId_provider->pTracking->id_page_delete_list_head)) == 0); + fail_unless(list_count(&(pId_provider->pTracking->id_page_unchanged_list_head)) == 3); + + /* test started from here */ + for (i = 0; i < page_bit_cnt - 1; i++) { + error = id_provider_delete_id(pId_provider, i); + fail_unless(error == ID_PROVIDER_OK); + fail_unless(pId_provider->total_free_cnt == page_bit_cnt + (i + 1)); + + fail_unless(list_count(&(pId_provider->pTracking->id_page_add_list_head)) == 0); + fail_unless(list_count(&(pId_provider->pTracking->id_page_update_list_head)) == 1); + fail_unless(list_count(&(pId_provider->pTracking->id_page_delete_list_head)) == 0); + fail_unless(list_count(&(pId_provider->pTracking->id_page_unchanged_list_head)) == 2); + } + + error = id_provider_delete_id(pId_provider, page_bit_cnt - 1); + fail_unless(error == ID_PROVIDER_OK); + fail_unless(pId_provider->total_free_cnt == 2 * page_bit_cnt); + + fail_unless(list_count(&(pId_provider->pTracking->id_page_add_list_head)) == 0); + fail_unless(list_count(&(pId_provider->pTracking->id_page_update_list_head)) == 0); + fail_unless(list_count(&(pId_provider->pTracking->id_page_delete_list_head)) == 1); + fail_unless(list_count(&(pId_provider->pTracking->id_page_unchanged_list_head)) == 2); + + for (i = 3 * page_bit_cnt; i < 4 * page_bit_cnt; i++) { + error = id_provider_provide_id(pId_provider, &id); + fail_unless(error == ID_PROVIDER_OK); + fail_unless(i == id); + fail_unless(pId_provider->total_free_cnt == (2 * page_bit_cnt - (i - 3 * page_bit_cnt + 1))); + + fail_unless(list_count(&(pId_provider->pTracking->id_page_add_list_head)) == 1); + fail_unless(list_count(&(pId_provider->pTracking->id_page_update_list_head)) == 0); + fail_unless(list_count(&(pId_provider->pTracking->id_page_delete_list_head)) == 1); + fail_unless(list_count(&(pId_provider->pTracking->id_page_unchanged_list_head)) == 2); + } + + id_provider_destroy(pId_provider); +} + +END_TEST Suite *fw_sequential_id_provider_suite(void) +{ + /* create test suite */ + Suite *s = suite_create("fw_sequential_id_provider_suite"); + + /* test case create and add in suite */ + { + TCase *tcase = tcase_create("provide_id_without_delete_id"); + + tcase_add_test(tcase, provide_id_without_delete_id_test1); + tcase_add_test(tcase, provide_id_without_delete_id_test2); + tcase_add_test(tcase, provide_id_without_delete_id_test3); + + tcase_set_timeout(tcase, 1); + + suite_add_tcase(s, tcase); + } + + /* create another test case and add to test suite just like above code */ + { + TCase *tcase = tcase_create("provide_id_with_delete_id"); + tcase_add_test(tcase, provide_id_with_delete_id_test1); + tcase_add_test(tcase, provide_id_with_delete_id_test2); + tcase_set_timeout(tcase, 1); + suite_add_tcase(s, tcase); + } + + /* create another test case and add to test suite just like above code */ + { + TCase *tcase = tcase_create("provide_id_tracking_mode"); + tcase_add_test(tcase, provide_id_without_unchanged_list); + tcase_add_test(tcase, provide_id_with_unchanged_list); + tcase_set_timeout(tcase, 1); + suite_add_tcase(s, tcase); + } + + return s; +} diff --git a/framework/test/src/suites/unit_test_protocol_binder.c b/framework/test/src/suites/unit_test_protocol_binder.c new file mode 100755 index 0000000..67de1d1 --- /dev/null +++ b/framework/test/src/suites/unit_test_protocol_binder.c @@ -0,0 +1,253 @@ +/* + * unit_test_protocol_binder.c + * + * Created on: 2011. 9. 21. + * Author: yangjoo.suh + */ + +#include "unit_test_common.h" +#include "suites/unit_test_protocol_binder_suite.h" +#include "protocol_binder.h" +#include "protocol_binder_util_internal.h" +#include "Utility/fw_log.h" + +#define LOG_TAG "TEST_FW_PROTOCOL_BINDER" + +typedef enum { + PE_UNDEF = 0, + PE_ADD, + PE_ALERT, + PE_ATOMIC_START, + PE_ATOMIC_END, + PE_COPY, + PE_DELETE, + PE_EXEC, + PE_GET, + PE_MAP, + PE_PUT_START, + PE_PUT_END, + PE_RESULTS_START, + PE_RESULTS_END, + PE_SEARCH, + PE_SEQUENCE_START, + PE_SEQUENCE_END, + PE_STATUS, + PE_SYNC_START, + PE_SYNC_END, + PE_REPLACE, + PE_HEADER, + PE_PUT_GET, + PE_CMD_GROUP, + PE_GENERIC, + PE_FINAL, + PE_DEVINF, + PE_SYNCML_START, + PE_SYNCML_END, + PE_BODY_START, + PE_BODY_END +} OMA_DS_Protocol_Element; + +static PROTOCOL_BINDER_ERROR oma_ds_binder_syncml_start_converter_function(protocol_binder *pBinder, Content_Ptr pContent, WBXMLTreeNode **ppWbxml_dom_node) +{ + FW_LOGI("start"); + PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK; + WBXMLTreeNode *syncml_node = create_wbxml_node_using_xml_name(pBinder, "SyncML"); + if (syncml_node == 0) + return PROTOCOL_BINDER_UNKNOWN_ERROR; + + switch (syncml_node->type) { + case WBXML_TREE_ELEMENT_NODE: + fprintf(stderr, "[%s] element node\n", __func__); + if (syncml_node->name->type == WBXML_VALUE_TOKEN) { + fprintf(stderr, "[%s] tag type value token", __func__); + } else if (syncml_node->name->type == WBXML_VALUE_LITERAL) { + fprintf(stderr, "[%s] tag type literal token", __func__); + } else { + fprintf(stderr, "[%s] tag type error", __func__); + } + break; + case WBXML_TREE_TEXT_NODE: + fprintf(stderr, "[%s] text node\n", __func__); + break; + case WBXML_TREE_CDATA_NODE: + fprintf(stderr, "[%s] cdata node\n", __func__); + break; + case WBXML_TREE_PI_NODE: + fprintf(stderr, "[%s] pi node\n", __func__); + break; + case WBXML_TREE_TREE_NODE: + fprintf(stderr, "[%s] tree node\n", __func__); + break; + } + + *ppWbxml_dom_node = syncml_node; + FW_LOGI("end"); + + return err; +} + +static PROTOCOL_BINDER_ERROR oma_ds_binder_header_converter_function(protocol_binder *pBinder, Content_Ptr pContent, WBXMLTreeNode **ppWbxml_dom_node) +{ + FW_LOGI("start"); + PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK; + + /* add SyncHdr, VerDTD, VerProto node */ + WBXMLTreeNode *synchdr_node = create_wbxml_node_using_xml_name(pBinder, "SyncHdr"); + + char *verDTD = "VerDTD"; + char *verProto = "VerProto"; + + char *verDTD_data = "1.2"; + char *verProto_data = "SyncML/1.2"; + + add_child_wbxml_node_using_xml_name_with_text(pBinder, synchdr_node, verDTD, verDTD_data, strlen(verDTD_data)); + add_child_wbxml_node_using_xml_name_with_text(pBinder, synchdr_node, verProto, verProto_data, strlen(verProto_data)); + + /* session ID */ + char *sessionId = "12345"; + add_child_wbxml_node_using_xml_name_with_text(pBinder, synchdr_node, "SessionID", sessionId, strlen(sessionId)); + + /* msgID */ + char *msgID_data = "1"; + add_child_wbxml_node_using_xml_name_with_text(pBinder, synchdr_node, "MsgID", msgID_data, strlen(msgID_data)); + + add_child_wbxml_node_using_xml_name(pBinder, synchdr_node, "Target"); + add_child_wbxml_node_using_xml_name(pBinder, synchdr_node, "Source"); + + *ppWbxml_dom_node = synchdr_node; + + FW_LOGI("end"); + return err; +} + +static PROTOCOL_BINDER_ERROR oma_ds_binder_body_start_converter_function(protocol_binder *pBinder, Content_Ptr pContent, WBXMLTreeNode **ppWbxml_dom_node) +{ + FW_LOGI("start"); + PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK; + + WBXMLTreeNode *syncbody_node = create_wbxml_node_using_xml_name(pBinder, "SyncBody"); + + *ppWbxml_dom_node = syncbody_node; + FW_LOGI("end"); + + return err; +} + +static PROTOCOL_BINDER_ERROR oma_ds_binder_final_converter_function(protocol_binder *pBinder, Content_Ptr pContent, WBXMLTreeNode **ppWbxml_dom_node) +{ + FW_LOGI("start"); + PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK; + + WBXMLTreeNode *final_node = create_wbxml_node_using_xml_name(pBinder, "Final"); + + *ppWbxml_dom_node = final_node; + + FW_LOGI("end"); + return err; +} + +static PROTOCOL_BINDER_ERROR oma_ds_binder_results_command_converter_function(protocol_binder *pBinder, Content_Ptr pContent, WBXMLTreeNode **ppWbxml_dom_node) +{ + + FW_LOGI("start"); + PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK; + + WBXMLTreeNode *results_node = create_wbxml_node_using_xml_name(pBinder, "Results"); + + char *str_cmdID = "1"; + add_child_wbxml_node_using_xml_name_with_text(pBinder, results_node, "CmdID", str_cmdID, strlen(str_cmdID)); + + char *str_msgRef = "2"; + add_child_wbxml_node_using_xml_name_with_text(pBinder, results_node, "MsgRef", str_msgRef, strlen(str_msgRef)); + + char *str_cmdRef = "3"; + add_child_wbxml_node_using_xml_name_with_text(pBinder, results_node, "CmdRef", str_cmdRef, strlen(str_cmdRef)); + + char *content_type = "application/vnd.syncml-devinf+xml"; + WBXMLTreeNode *meta_node = add_child_wbxml_node_using_xml_name(pBinder, results_node, "Meta"); + add_child_wbxml_node_using_xml_name_with_text(pBinder, meta_node, "Type", content_type, strlen(content_type)); + + char *target_ref_locUri = "./devinf12"; + add_child_wbxml_node_using_xml_name_with_text(pBinder, results_node, "TargetRef", target_ref_locUri, strlen(target_ref_locUri)); + + *ppWbxml_dom_node = results_node; + + FW_LOGI("end"); + return err; +} + +const Binder_function_info oma_ds_binder_function_info[8] = { + {PE_SYNCML_START, "SyncML", oma_ds_binder_syncml_start_converter_function, NULL, false}, + {PE_SYNCML_END, "/SyncML", NULL, NULL, false}, + {PE_HEADER, "SyncHdr", oma_ds_binder_header_converter_function, NULL, true}, + {PE_BODY_START, "SyncBody", oma_ds_binder_body_start_converter_function, NULL, false}, + {PE_BODY_END, "/SyncBody", NULL, NULL, false}, + {PE_FINAL, "Final", oma_ds_binder_final_converter_function, NULL, true}, + {PE_RESULTS_START, "Results", oma_ds_binder_results_command_converter_function, NULL, false}, + {PE_RESULTS_END, "/Results", NULL, NULL, false} +}; + +START_TEST(_protocol_binder_flow_mode_xml_output1) +{ + Binder_function_set *pFunction_set = NULL; + char *xml_output = NULL; + unsigned int xml_size = 0; + PROTOCOL_BINDER_ERROR err = init_binder_function_set(8, oma_ds_binder_function_info, + &pFunction_set); + fail_unless(err == PROTOCOL_BINDER_OK, "init_binder_function_set failed"); + fail_unless(pFunction_set != NULL, "pFunction_set != NULL" "after init_binder_function_set function successfully done"); + + protocol_binder *pBinder = protocol_binder_init(NULL, + PROTOCOL_SYNCML_SYNCML12, NULL, + ENCODING_WBXML_12, false, false, false, true, + NULL, NULL, + pFunction_set); + fail_unless(pBinder != NULL, "pBinder != NULL failed"); + + err = protocol_binder_append(pBinder, PE_SYNCML_START, NULL); +/* fail_unless(err == PROTOCOL_BINDER_OK, "protocol_binder_append PE_SYNCML_START failed"); */ + err = protocol_binder_append(pBinder, PE_HEADER, NULL); +/* fail_unless(err == PROTOCOL_BINDER_OK, "protocol_binder_append PE_HEADER failed"); */ + err = protocol_binder_append(pBinder, PE_BODY_START, NULL); +/* fail_unless(err == PROTOCOL_BINDER_OK, "protocol_binder_append PE_BODY_START failed"); */ + err = protocol_binder_append(pBinder, PE_RESULTS_START, NULL); +/* fail_unless(err == PROTOCOL_BINDER_OK, "protocol_binder_append PE_RESULTS_START failed"); */ + err = protocol_binder_append(pBinder, PE_RESULTS_END, NULL); +/* fail_unless(err == PROTOCOL_BINDER_OK, "protocol_binder_append PE_RESULTS_END failed"); */ + err = protocol_binder_append(pBinder, PE_BODY_END, NULL); +/* fail_unless(err == PROTOCOL_BINDER_OK, "protocol_binder_append PE_BODY_END failed"); */ + err = protocol_binder_append(pBinder, PE_SYNCML_END, NULL); +/* fail_unless(err == PROTOCOL_BINDER_OK, "protocol_binder_append PE_SYNCML_END failed"); */ + + err = protocol_binder_get_stream(pBinder, &xml_output, &xml_size); + /* + fail_unless(err != PROTOCOL_BINDER_OK, "protocol_binder_get_stream failed"); + + fail_unless(xml_output != NULL, "xml_output != NULL failed"); + fail_unless(xml_size != 0, "xml_size != 0 failed"); + */ + fprintf(stderr, "xml = %s\n", xml_output); + + if (xml_output) + free(xml_output); + if (pBinder) + protocol_binder_terminate(pBinder); +} + +END_TEST Suite *protocol_binder_suite(void) +{ + /* create test suite */ + Suite *s = suite_create("protocol binder"); + + /* test case create and add in suite */ + { + TCase *tcase = tcase_create("binder flow mode xml test cases"); + + tcase_add_test(tcase, _protocol_binder_flow_mode_xml_output1); + tcase_set_timeout(tcase, 1); + + suite_add_tcase(s, tcase); + } + + return s; +} diff --git a/framework/test/src/suites/unit_test_sample_suite.c b/framework/test/src/suites/unit_test_sample_suite.c new file mode 100755 index 0000000..ab71e6f --- /dev/null +++ b/framework/test/src/suites/unit_test_sample_suite.c @@ -0,0 +1,55 @@ +/* + * unit_test_sample_suite.c + * + * Created on: 2011. 3. 29. + * Author: yangjoo.suh + */ + +#include "unit_test_common.h" +#include "suites/unit_test_sample_suite.h" + +START_TEST(sample_test1) +{ + fail_unless(2 != 1, "2 != 1 failed"); + fail_unless(3 != 1, "3 != 1 failed"); +} + +END_TEST START_TEST(sample_test2) +{ + /* unit test code */ + fail_unless(10 != 5, "10 != 5 failed"); +} + +END_TEST Suite *sample_suite(void) +{ + /* create test suite */ + Suite *s = suite_create("Sample"); + + /* test case create and add in suite */ + { + TCase *tcase = tcase_create("SampleTestCase"); + /* TODO : explain following lines */ + /* + tcase_add_unchecked_fixture (tcase, setup, teardown); + tcase_add_checked_fixture (tcase, setup, teardown); + */ + + tcase_add_test(tcase, sample_test1); + tcase_add_test(tcase, sample_test2); + /* TODO : explain following lines */ + tcase_set_timeout(tcase, 1); + + suite_add_tcase(s, tcase); + } + + /* create another test case and add to test suite just like above code */ + { + TCase *tc_core2 = tcase_create("Sample2"); + tcase_add_test(tc_core2, sample_test1); + tcase_add_test(tc_core2, sample_test2); + tcase_set_timeout(tc_core2, 1); + suite_add_tcase(s, tc_core2); + } + + return s; +} diff --git a/framework/test/src/unit_test_run.c b/framework/test/src/unit_test_run.c new file mode 100755 index 0000000..01a1af8 --- /dev/null +++ b/framework/test/src/unit_test_run.c @@ -0,0 +1,121 @@ +/* + * unit_test_run.c + * + * Created on: 2011. 3. 29. + * Author: yangjoo.suh + */ + +#include "unit_test_common.h" +#include "unit_test_run.h" +#include "unit_test_suites.h" +#include +#include +#include + +/* introduction to unit test using check by yangsuh + * SRunner : runner of all test which belong to added suites + * Suite : container of test cases(TCase) + * TCase : container of tests + * test : container of many asserts + * + * SRunner has fork_status option. I will set this option to CK_FORK which means + * not stopping until all test finished. + * (Of course, when error like SIGSEGV occurs or test failed, current test will be stopped + * and goes to next test) + */ + +typedef enum fork_status fork_status_t; +int unit_test_main(fork_status_t fork_status) +{ + SRunner *sr = NULL; + + /* srunner build up by defined test suites */ + int suite_count = sizeof(suiteFunctions) / sizeof(SUITE_FUNCTION); + fprintf(stderr, "total test suites number = %d\n", suite_count); + + if (suite_count == 0) { + return 0; /* nothing to do */ + } else { /* suite_count > 0 */ + SUITE_FUNCTION suite_func = NULL; + + int i = 0; + for (i = 0; i < suite_count; i++) { + suite_func = suiteFunctions[i]; + Suite *s = suite_func(); + if (s != NULL) { + if (i == 0) { + sr = srunner_create(s); + } else { + srunner_add_suite(sr, s); + } + } else { + fprintf(stderr, "invalid suite function\n"); + } + } + } + + /* srunner setting */ + srunner_set_log(sr, "/tmp/test.log"); /* set log file */ + srunner_set_fork_status(sr, fork_status); /* set fork status of Runner */ + + srunner_run_all(sr, CK_VERBOSE); /* set print mode to verbose */ + srunner_free(sr); + + return 0; +} + +/* TODO : return handling */ +static inline int unit_test_run_fork_mode() +{ + pid_t pid_w; + pid_t pid; + int status = 0; + + pid = fork(); + if (pid == -1) + fprintf(stderr, "Error in call to fork\n"); + if (pid == 0) { + /* child process : run unit_test_main */ + unit_test_main(CK_FORK); + exit(EXIT_SUCCESS); + } else { + /* parent process */ + fprintf(stderr, "test process pid = %d", pid); + pid_w = waitpid(pid, &status, 0); + + if (pid_w == pid) { + fprintf(stderr, "test finished successfully\n"); + return 1; /* test finished */ + } else { + fprintf(stderr, "test failed\n"); + return 0; /* test error */ + } + } + + return status; +} + +/* running as main function will be need during debugging */ +/* TODO : return handling */ +static inline int unit_test_run_function_mode() +{ + return unit_test_main(CK_NOFORK); +} + +int unit_test_run(run_unit_test_mode_t mode) +{ + int success = 1; /* success */ + + switch (mode) { + case FORK_MODE: + success = unit_test_run_fork_mode(); + break; + case FUNCTION_MODE: + success = unit_test_run_function_mode(); + break; + default: + break; + } + + return success; +} diff --git a/fw-plugin/CMakeLists.txt b/fw-plugin/CMakeLists.txt new file mode 100755 index 0000000..8883594 --- /dev/null +++ b/fw-plugin/CMakeLists.txt @@ -0,0 +1,11 @@ +ADD_SUBDIRECTORY(account-plugIn) +ADD_SUBDIRECTORY(calendar-plugIn) +ADD_SUBDIRECTORY(contact-plugIn) +ADD_SUBDIRECTORY(memo-plugIn) +ADD_SUBDIRECTORY(vcalendar-plugIn) +ADD_SUBDIRECTORY(vcard-plugIn) +ADD_SUBDIRECTORY(plain-text-plugIn) +ADD_SUBDIRECTORY(http-plugIn) +ADD_SUBDIRECTORY(slp-device-plugIn) +ADD_SUBDIRECTORY(slp-sysnoti-plugIn) + diff --git a/fw-plugin/account-plugIn/.cproject b/fw-plugin/account-plugIn/.cproject new file mode 100755 index 0000000..3c36d31 --- /dev/null +++ b/fw-plugin/account-plugIn/.cproject @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/fw-plugin/account-plugIn/.project b/fw-plugin/account-plugIn/.project new file mode 100755 index 0000000..0912974 --- /dev/null +++ b/fw-plugin/account-plugIn/.project @@ -0,0 +1,78 @@ + + + account-plugIn + + + + + + com.samsung.slp2.SboxBuilder + + + com.samsung.slp2.SboxBuilder.needConfigure + true + + + org.eclipse.cdt.core.errorOutputParser + org.eclipse.cdt.core.MakeErrorParser;com.samsung.limo.SboxGCCErrorParser;org.eclipse.cdt.core.GLDErrorParser;org.eclipse.cdt.core.GASErrorParser; + + + org.eclipse.cdt.make.core.append_environment + true + + + org.eclipse.cdt.make.core.build.arguments + + + + org.eclipse.cdt.make.core.build.command + make + + + org.eclipse.cdt.make.core.build.target.auto + all + + + org.eclipse.cdt.make.core.build.target.clean + clean + + + org.eclipse.cdt.make.core.build.target.inc + all + + + org.eclipse.cdt.make.core.enableAutoBuild + true + + + org.eclipse.cdt.make.core.enableCleanBuild + true + + + org.eclipse.cdt.make.core.enableFullBuild + true + + + org.eclipse.cdt.make.core.enabledIncrementalBuild + true + + + org.eclipse.cdt.make.core.environment + + + + org.eclipse.cdt.make.core.stopOnError + true + + + org.eclipse.cdt.make.core.useDefaultBuildCmd + true + + + + + + org.eclipse.cdt.core.cnature + com.samsung.slp2.cnature + + diff --git a/fw-plugin/account-plugIn/CMakeLists.src b/fw-plugin/account-plugIn/CMakeLists.src new file mode 100755 index 0000000..04ce4aa --- /dev/null +++ b/fw-plugin/account-plugIn/CMakeLists.src @@ -0,0 +1 @@ +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src SRCS) diff --git a/fw-plugin/account-plugIn/CMakeLists.sub b/fw-plugin/account-plugIn/CMakeLists.sub new file mode 100755 index 0000000..9dfe8e0 --- /dev/null +++ b/fw-plugin/account-plugIn/CMakeLists.sub @@ -0,0 +1,38 @@ +################################################################################# +# THIS FILE IS CREATED AUTOMATICALLY. DO NOT DELETE OR MODIFY THIS FILE. +################################################################################# + +INCLUDE(CMakeLists.src) + +## PROJECT NAME +PROJECT(plugin-account C) + +## PACKAGE CONFIG +SET(SLP_PKGCONFIG_LIST "accounts-svc contacts-service glib-2.0 vconf") + +## INCLUDES +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../../framework/include) + + +## DEFINITIONS +ADD_DEFINITIONS("-DAPP_DIR=\"${CMAKE_INSTALL_PREFIX}\"") + +## LIBRARY PATH +SET(SLP_LD_PATH_FLAGS "") + +## LIBRARY +SET(SLP_LD_FLAGS "") + +## DEBUG +SET(SLP_DEBUG_FLAGS "-g") + +## OPTIMIZATION +SET(SLP_OPT_FLAGS "-O0") + +## COMPILER FLAGS +SET(SLP_COMPILER_FLAGS "") + +## LINKER FLAGS +SET(SLP_LINKER_FLAGS "") + diff --git a/fw-plugin/account-plugIn/CMakeLists.txt b/fw-plugin/account-plugIn/CMakeLists.txt new file mode 100755 index 0000000..d3139b9 --- /dev/null +++ b/fw-plugin/account-plugIn/CMakeLists.txt @@ -0,0 +1,33 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) + +# INCLUDE SUB CMAKELIST FILE +INCLUDE(CMakeLists.sub) + +SET(RESOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/res") + +INCLUDE(FindPkgConfig) +pkg_check_modules(pkgs_plugin_account REQUIRED ${SLP_PKGCONFIG_LIST}) + +FOREACH(flag ${pkgs_plugin_account_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(CMAKE_C_FLAGS "${SLP_DEBUG_FLAGS} ${SLP_OPT_FLAGS} ${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} ${SLP_COMPILER_FLAGS}") +SET(CMAKE_CXX_FLAGS "${SLP_DEBUG_FLAGS} ${SLP_OPT_FLAGS} ${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} ${SLP_COMPILER_FLAGS}") + +ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS}) + +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_plugin_account_LDFLAGS} ${SLP_LD_PATH_FLAGS} ${SLP_LD_FLAGS} ${SLP_LINKER_FLAGS} sync-agent-framework) + +# INSTALL +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION lib) +#INSTALL(DIRECTORY ${RESOURCE_DIR}/data DESTINATION share) + +#added by KTS for install to the system +#CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY) +#INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc DESTINATION lib/pkgconfig) + + +# INCLUDE LAYOUT DIRECTORY +# ADD_SUBDIRECTORY(layout) +#ADD_SUBDIRECTORY(res/locale) diff --git a/fw-plugin/account-plugIn/include/Account_Info.h b/fw-plugin/account-plugIn/include/Account_Info.h new file mode 100755 index 0000000..f0e7dce --- /dev/null +++ b/fw-plugin/account-plugIn/include/Account_Info.h @@ -0,0 +1,51 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#ifndef SLP_ACCOUNT_INFO_H_ +#define SLP_ACCOUNT_INFO_H_ + +typedef enum { + ACC_TYPE_LOCAL = 0, + ACC_TYPE_EAS, + ACC_TYPE_GOOGLE, + ACC_TYPE_NONE +} ACC_TYPE; + +typedef struct { + char *email; + ACC_TYPE type; +} Account_Info; + +#endif /* SLP_ACCOUNT_INFO_H_ */ diff --git a/fw-plugin/account-plugIn/src/PlugIn_Interface.c b/fw-plugin/account-plugIn/src/PlugIn_Interface.c new file mode 100755 index 0000000..3d7c938 --- /dev/null +++ b/fw-plugin/account-plugIn/src/PlugIn_Interface.c @@ -0,0 +1,426 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#include /*for debugging */ +#include + +#include +#include +#include "contacts-svc.h" + +#include "Account_Info.h" + +/* for log */ +#include "agent-framework/Utility/fw_log.h" + +#include "agent-framework/PlugIn/Account_Interface.h" + +#define LOG_TAG "PLUGIN_ACCOUNT" + +/* + * Key : db/Apps/AgentFramework/[Agent Name]/Service/[Service_Type]/[FW AccountID] + * Value : Service Account ID + */ +#define VCONF_KEY_ACCOUNT_ID_SERVICE_ACCOUNT_ID "db/Apps/AgentFramework/%s/Service/%d/%d" + +/* + * KEY : db/Apps/AgentFramework/[Agent Name]/FW/[Service_Type]/[Service AccountID]/[Index] + * Value : FW Account IDcat + */ +#define VCONF_KEY_ACCOUNT_ID_FW_ACCOUNT_ID "db/Apps/AgentFramework/%s/FW/%d/%d/%d" + +/* + * Key : db/Apps/AgentFramework/[Agent Name]/FW_Count/[Service_Type]/[Service AccountID] + * Value : FW Account Count Included in one service Account + */ +#define VCONF_KEY_ACCOUNT_ID_FW_ACCOUNT_COUNT "db/Apps/AgentFramework/%s/FW_Count/%d/%d" + +#define FW_CONTACT 0 +#define FW_CALENDAR 1 +#define FW_MEMO 2 +#define FW_CONTENT_COUNT 3 + +static const char *AGENT_NAME = 0; + +static void __setAccountID_Service(int service_type, int fw_account_id, int service_account_id); + +static void __setAccountID_FW(int service_type, int service_account_id, int count, int fw_account_id); + +static int __increaseAccountCount_FW(int service_type, int service_account_id); + +static int __getAccountCount_FW(int service_type, int service_account_id); + +static void __unSetAccountID_Service(int service_type, int fw_account_id); + +static void __unSetAccountID_FW(int service_type, int service_account_id, int index); + +static int __decreaseAccountCount_FW(int service_type, int service_account_id); + +static Account_Info *get_Account_Info(int service_account_id); + +void Set_AccountReposioryName(const char *agent_name) +{ + AGENT_NAME = agent_name; +} + +void Add_PlatformAccount(int fw_account_id, char *email, char *password, int create_mode) +{ + int slp_id = -1; + + int slp_contact_id = Get_Service_AccountID(FW_CONTACT, fw_account_id); + int slp_calendar_id = Get_Service_AccountID(FW_CALENDAR, fw_account_id); + int slp_memo_id = Get_Service_AccountID(FW_MEMO, fw_account_id); + + /* + * if not existed ? + */ + if (slp_contact_id == -100) { + __setAccountID_Service(FW_CONTACT, fw_account_id, slp_id); + int contact_index = __increaseAccountCount_FW(FW_CONTACT, slp_id); + __setAccountID_FW(FW_CONTACT, slp_id, contact_index, fw_account_id); + } + + if (slp_calendar_id == -100) { + __setAccountID_Service(FW_CALENDAR, fw_account_id, slp_id); + int calendar_index = __increaseAccountCount_FW(FW_CALENDAR, slp_id); + __setAccountID_FW(FW_CALENDAR, slp_id, calendar_index, fw_account_id); + } + + if (slp_memo_id == -100) { + __setAccountID_Service(FW_MEMO, fw_account_id, slp_id); + int memo_index = __increaseAccountCount_FW(FW_MEMO, slp_id); + __setAccountID_FW(FW_MEMO, slp_id, memo_index, fw_account_id); + } +} + +void Set_PlatformAccount_Service(int fw_account_id, int service_type, int service_account_id) +{ + __setAccountID_Service(service_type, fw_account_id, service_account_id); + + int service_index = __increaseAccountCount_FW(service_type, service_account_id); + + __setAccountID_FW(service_type, service_account_id, service_index, fw_account_id); +} + +void Del_PlatformAccount(int fw_account_id) +{ + FW_LOGV("[account_plugIn] Start \n"); + + int i = 0; + for (; i < FW_CONTENT_COUNT; i++) { + int service_account_id = Get_Service_AccountID(i, fw_account_id); + + __unSetAccountID_Service(i, fw_account_id); + + int count = __getAccountCount_FW(i, service_account_id); + int k = 0; + for (; k < count; k++) { + int target_fw_account_id = Get_FW_AccountID(i, service_account_id, k); + if (target_fw_account_id == fw_account_id) { + __unSetAccountID_FW(i, service_account_id, k); + __decreaseAccountCount_FW(i, service_account_id); + } + } + } +} + +void Del_PlatformAccount_Service(int fw_account_id, int service_type) +{ + __unSetAccountID_Service(service_type, fw_account_id); +} + +int Has_PlatformAccount_Service(int fw_account_id, int service_type) +{ + int result = Get_Service_AccountID(service_type, fw_account_id); + if (result == -100) { + return 0; + } + + return 1; +} + +int Get_Service_AccountID(int service_type, int fw_account_id) +{ + int service_account_id; + FW_LOGV("[account_plugIn] service_type : %d\n", service_type); + FW_LOGV("[account_plugIn] fw_account_id : %d\n", fw_account_id); + + char vConfKey[100]; + sprintf(vConfKey, VCONF_KEY_ACCOUNT_ID_SERVICE_ACCOUNT_ID, AGENT_NAME, service_type, fw_account_id); + + if (vconf_get_int(vConfKey, &service_account_id)) { + FW_LOGV("[account_plugIn] vconf_get_int FAIL\n"); + return -100; + } + + FW_LOGV("[account_plugIn] vConfKey : %s\n", vConfKey); + FW_LOGV("[account_plugIn] service_account_id : %d\n", service_account_id); + + return service_account_id; +} + +int Get_FW_AccountID(int service_type, int service_account_id, int index) +{ + char vConfKey[100]; + sprintf(vConfKey, VCONF_KEY_ACCOUNT_ID_FW_ACCOUNT_ID, AGENT_NAME, service_type, service_account_id, index); + + int fw_account_id; + if (vconf_get_int(vConfKey, &fw_account_id)) { + FW_LOGV("[account_plugIn] vconf_get_int FAIL\n"); + return -1; + } + + return fw_account_id; +} + +void *Get_Service_AccountInfo(int fw_account_id, int service_type) +{ + int service_account_id = Get_Service_AccountID(service_type, fw_account_id); + FW_LOGV("[account_plugIn] service_account_id : %d\n", service_account_id); + + if (service_account_id == -100) { + return 0; + } + + Account_Info *account_info = get_Account_Info(service_account_id); + + if (account_info != 0) { + FW_LOGV("[account_plugIn] account_info->type : %d\n", account_info->type); + FW_LOGV("[account_plugIn] account_info->email : %s\n", account_info->email); + } else { + FW_LOGV("[account_plugIn] account_info is empty\n"); + } + + return account_info; +} + +/******************************************* Impl static function ********************************************/ + +static void __setAccountID_Service(int service_type, int fw_account_id, int service_account_id) +{ + char vConfKey[100]; + sprintf(vConfKey, VCONF_KEY_ACCOUNT_ID_SERVICE_ACCOUNT_ID, AGENT_NAME, service_type, fw_account_id); + + if (vconf_set_int(vConfKey, service_account_id)) + FW_LOGV("[account_plugIn] vconf_set_id FAIL\n"); + + FW_LOGV("\n[account_plugIn] Sucess Vconf Set Id\n"); + FW_LOGV("[account_plugIn] service_type : %d, fw_account_id : %d, service_account_id : %d\n\n", service_type, fw_account_id, service_account_id); +} + +static void __setAccountID_FW(int service_type, int service_account_id, int count, int fw_account_id) +{ + FW_LOGV("count : %d", count); + + char vConfKey[100] = { 0 }; + + int index = 0; + for (; index < count; index++) { + int i = 0; + for (; i < 100; i++) { + vConfKey[i] = 0; + } + + int data; + sprintf(vConfKey, VCONF_KEY_ACCOUNT_ID_FW_ACCOUNT_ID, AGENT_NAME, service_type, service_account_id, index); + FW_LOGV("================== 01 [%s]\n", vConfKey); + if (vconf_get_int(vConfKey, &data)) { + FW_LOGV("================== 02\n"); + break; + } + } + + if (vconf_set_int(vConfKey, fw_account_id)) + FW_LOGV("[account_plugIn] vconf_set_id FAIL\n"); + + FW_LOGV("\n[account_plugIn] Sucess Vconf Set Id\n"); + FW_LOGV("[account_plugIn] service_type : %d, service_account_id : %d, fw_account_id[%d] : %d\n\n", service_type, service_account_id, index, fw_account_id); +} + +static int __increaseAccountCount_FW(int service_type, int service_account_id) +{ + char vConfKey[100]; + sprintf(vConfKey, VCONF_KEY_ACCOUNT_ID_FW_ACCOUNT_COUNT, AGENT_NAME, service_type, service_account_id); + + int fw_account_count; + if (vconf_get_int(vConfKey, &fw_account_count)) { + FW_LOGV("[account_plugIn] first added\n"); + if (vconf_set_int(vConfKey, 1)) + FW_LOGV("[account_plugIn] vconf_set_id FAIL\n"); + return 1; + } + + if (vconf_set_int(vConfKey, fw_account_count + 1)) + FW_LOGV("[account_plugIn] vconf_set_id FAIL\n"); + + return fw_account_count + 1; + +} + +static int __getAccountCount_FW(int service_type, int service_account_id) +{ + char vConfKey[100]; + sprintf(vConfKey, VCONF_KEY_ACCOUNT_ID_FW_ACCOUNT_COUNT, AGENT_NAME, service_type, service_account_id); + + int fw_account_count; + if (vconf_get_int(vConfKey, &fw_account_count)) { + FW_LOGV("[account_plugIn] empty\n"); + return 0; + } + + return fw_account_count; +} + +static void __unSetAccountID_Service(int service_type, int fw_account_id) +{ + char vConfKey[100]; + sprintf(vConfKey, VCONF_KEY_ACCOUNT_ID_SERVICE_ACCOUNT_ID, AGENT_NAME, service_type, fw_account_id); + + if (vconf_unset(vConfKey)) + FW_LOGV("[account_plugIn] vconf_unset FAIL\n"); +} + +static void __unSetAccountID_FW(int service_type, int service_account_id, int index) +{ + char vConfKey[100]; + sprintf(vConfKey, VCONF_KEY_ACCOUNT_ID_FW_ACCOUNT_ID, AGENT_NAME, service_type, service_account_id, index); + + if (vconf_unset(vConfKey)) { + FW_LOGV("[account_plugIn] vconf_unset FAIL : %s\n", vConfKey); + } +} + +static int __decreaseAccountCount_FW(int service_type, int service_account_id) +{ + char vConfKey[100]; + sprintf(vConfKey, VCONF_KEY_ACCOUNT_ID_FW_ACCOUNT_COUNT, AGENT_NAME, service_type, service_account_id); + + int fw_account_count = 0; + if (vconf_get_int(vConfKey, &fw_account_count)) { + FW_LOGV("[account_plugIn] attempt delete when empty\n"); + return 0; + } + + fw_account_count = fw_account_count - 1; + + if (fw_account_count == 0) { + if (vconf_unset(vConfKey)) { + FW_LOGV("[account_plugIn] vconf_unset FAIL : %s\n", vConfKey); + } + return 0; + } + + if (vconf_set_int(vConfKey, fw_account_count)) + FW_LOGV("[account_plugIn] vconf_set_id FAIL\n"); + + return fw_account_count; +} + +static Account_Info *get_Account_Info(int service_account_id) +{ + Account_Info *account_info = (Account_Info *) malloc(sizeof(Account_Info)); + if (account_info == 0) { + FW_LOGE("Failed to malloc()"); + return 0; + } + + if (service_account_id == -1) { + account_info->email = 0; + account_info->type = ACC_TYPE_LOCAL; + return account_info; + } + + int error_code = account_connect(); + if (error_code != ACCOUNT_ERROR_NONE) { + FW_LOGE("Failed to call account_connect()"); + return 0; + } + + account_h account_handle = 0; + account_create(&account_handle); + error_code = account_query_account_by_account_id(service_account_id, &account_handle); + if (error_code != ACCOUNT_ERROR_NONE) { + FW_LOGE("Failed to call account_query_account_by_account_id()"); + free(account_info); + account_destroy(account_handle); + account_disconnect(); + return 0; + } + + char *domain_name = 0; + error_code = account_get_domain_name(account_handle, &domain_name); + if (error_code != ACCOUNT_ERROR_NONE) { + FW_LOGE("Failed to call account_get_domain_name()"); + free(account_info); + account_destroy(account_handle); + account_disconnect(); + return 0; + } + + if (!strcmp(domain_name, "Gmail")) { + account_info->type = ACC_TYPE_GOOGLE; + } else if (!strcmp(domain_name, "exchange")) { + account_info->type = ACC_TYPE_EAS; + } else { + account_info->type = ACC_TYPE_NONE; + free(account_info); + account_destroy(account_handle); + account_disconnect(); + return 0; + } + + char *email = 0; + error_code = account_get_email_address(account_handle, &email); + if (error_code != ACCOUNT_ERROR_NONE) { + FW_LOGE("Failed to call account_get_email_address()"); + free(account_info); + account_destroy(account_handle); + account_disconnect(); + return 0; + } + + if (email != 0) { + account_info->email = strdup(email); + } + + account_destroy(account_handle); + error_code = account_disconnect(); + if (error_code != ACCOUNT_ERROR_NONE) { + FW_LOGE("Failed to call account_disconnect()"); + return 0; + } + + return account_info; +} diff --git a/fw-plugin/calendar-plugIn/.cproject b/fw-plugin/calendar-plugIn/.cproject new file mode 100755 index 0000000..3c36d31 --- /dev/null +++ b/fw-plugin/calendar-plugIn/.cproject @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/fw-plugin/calendar-plugIn/.project b/fw-plugin/calendar-plugIn/.project new file mode 100755 index 0000000..5e83784 --- /dev/null +++ b/fw-plugin/calendar-plugIn/.project @@ -0,0 +1,78 @@ + + + calendar-plugIn + + + + + + com.samsung.slp2.SboxBuilder + + + com.samsung.slp2.SboxBuilder.needConfigure + true + + + org.eclipse.cdt.core.errorOutputParser + org.eclipse.cdt.core.MakeErrorParser;com.samsung.limo.SboxGCCErrorParser;org.eclipse.cdt.core.GLDErrorParser;org.eclipse.cdt.core.GASErrorParser; + + + org.eclipse.cdt.make.core.append_environment + true + + + org.eclipse.cdt.make.core.build.arguments + + + + org.eclipse.cdt.make.core.build.command + make + + + org.eclipse.cdt.make.core.build.target.auto + all + + + org.eclipse.cdt.make.core.build.target.clean + clean + + + org.eclipse.cdt.make.core.build.target.inc + all + + + org.eclipse.cdt.make.core.enableAutoBuild + true + + + org.eclipse.cdt.make.core.enableCleanBuild + true + + + org.eclipse.cdt.make.core.enableFullBuild + true + + + org.eclipse.cdt.make.core.enabledIncrementalBuild + true + + + org.eclipse.cdt.make.core.environment + + + + org.eclipse.cdt.make.core.stopOnError + true + + + org.eclipse.cdt.make.core.useDefaultBuildCmd + true + + + + + + org.eclipse.cdt.core.cnature + com.samsung.slp2.cnature + + diff --git a/fw-plugin/calendar-plugIn/CMakeLists.src b/fw-plugin/calendar-plugIn/CMakeLists.src new file mode 100755 index 0000000..04ce4aa --- /dev/null +++ b/fw-plugin/calendar-plugIn/CMakeLists.src @@ -0,0 +1 @@ +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src SRCS) diff --git a/fw-plugin/calendar-plugIn/CMakeLists.sub b/fw-plugin/calendar-plugIn/CMakeLists.sub new file mode 100755 index 0000000..0ced611 --- /dev/null +++ b/fw-plugin/calendar-plugIn/CMakeLists.sub @@ -0,0 +1,37 @@ +################################################################################# +# THIS FILE IS CREATED AUTOMATICALLY. DO NOT DELETE OR MODIFY THIS FILE. +################################################################################# + +INCLUDE(CMakeLists.src) + +## PROJECT NAME +PROJECT(plugin-da-calendar C) + +## PACKAGE CONFIG +SET(SLP_PKGCONFIG_LIST "calendar glib-2.0 accounts-svc") + +## INCLUDES +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../../framework/include) + +## DEFINITIONS +ADD_DEFINITIONS("-DAPP_DIR=\"${CMAKE_INSTALL_PREFIX}\"") + +## LIBRARY PATH +SET(SLP_LD_PATH_FLAGS "") + +## LIBRARY +SET(SLP_LD_FLAGS "") + +## DEBUG +SET(SLP_DEBUG_FLAGS "-g") + +## OPTIMIZATION +SET(SLP_OPT_FLAGS "-O0") + +## COMPILER FLAGS +SET(SLP_COMPILER_FLAGS "-lpthread") + +## LINKER FLAGS +SET(SLP_LINKER_FLAGS "-lpthread") + diff --git a/fw-plugin/calendar-plugIn/CMakeLists.txt b/fw-plugin/calendar-plugIn/CMakeLists.txt new file mode 100755 index 0000000..cc82c7a --- /dev/null +++ b/fw-plugin/calendar-plugIn/CMakeLists.txt @@ -0,0 +1,33 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) + +# INCLUDE SUB CMAKELIST FILE +INCLUDE(CMakeLists.sub) + +SET(RESOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/res") + +INCLUDE(FindPkgConfig) +pkg_check_modules(pkgs_plugin_calendar REQUIRED ${SLP_PKGCONFIG_LIST}) + +FOREACH(flag ${pkgs_plugin_calendar_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(CMAKE_C_FLAGS "${SLP_DEBUG_FLAGS} ${SLP_OPT_FLAGS} ${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} ${SLP_COMPILER_FLAGS}") +SET(CMAKE_CXX_FLAGS "${SLP_DEBUG_FLAGS} ${SLP_OPT_FLAGS} ${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} ${SLP_COMPILER_FLAGS}") + +ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS}) + +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_plugin_calendar_LDFLAGS} ${SLP_LD_PATH_FLAGS} ${SLP_LD_FLAGS} ${SLP_LINKER_FLAGS} sync-agent-framework) + +# INSTALL +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION lib) +#INSTALL(DIRECTORY ${RESOURCE_DIR}/data DESTINATION share) + +#added by KTS for install to the system +#CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY) +#INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc DESTINATION lib/pkgconfig) + + +# INCLUDE LAYOUT DIRECTORY +# ADD_SUBDIRECTORY(layout) +#ADD_SUBDIRECTORY(res/locale) diff --git a/fw-plugin/calendar-plugIn/include/EXT_DataStore_Info_Calendar.h b/fw-plugin/calendar-plugIn/include/EXT_DataStore_Info_Calendar.h new file mode 100755 index 0000000..db6ade8 --- /dev/null +++ b/fw-plugin/calendar-plugIn/include/EXT_DataStore_Info_Calendar.h @@ -0,0 +1,72 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Wook Choi + */ + +#ifndef EXT_DATASTORE_INFO_CALENDAR_H_ +#define EXT_DATASTORE_INFO_CALENDAR_H_ + +typedef enum { + CALENDAR_FIELD_DB_INDEX = 1, + CALENDAR_FIELD_SUMMARY, + CALENDAR_FIELD_DESCRIPTION, + CALENDAR_FIELD_LOCATOIN, + CALENDAR_FIELD_YEAR, + CALENDAR_FIELD_MODEL, + CALENDAR_FIELD_MEMO, + CALENDAR_FIELD_TIMEZONE, + CALENDAR_FIELD_TYPE_MODEL +} CALENADR_FIELD; + +typedef enum { + CALENDAR_CHILD_FIELD_BIAS = 1, + CALENDAR_CHILD_FIELD_DAYLIGHT, + CALENDAR_CHILD_FIELD_DAYLIGHT_BIAS, + CALENDAR_CHILD_FIELD_DAYLIGHT_BEGIN, + CALENDAR_CHILD_FIELD_DAYLIGHT_END, + CALENDAR_CHILD_FIELD_STANDARD_TIMENAME, + CALENDAR_CHILD_FIELD_DAYLIGHT_TIMENAME +} CALENDAR_CHILD_FIELD; + +typedef enum { + CALENDAR_FEATURE_APPOINTMENT = 1, + CALENDAR_FEATURE_ANNIVERSARY, + CALENDAR_FEATURE_HOLIDAY, + CALENDAR_FEATURE_IMPORTANT, + CALENDAR_FEATURE_PRIVATE, + CALENDAR_FEATURE_MISCELLANEOUS, + CALENDAR_FEATURE_TASK, + CALENDAR_FEATURE_MEMO +} CALENDAR_FEATURE; + +#endif /* EXT_DATASTORE_INFO_CALENDAR_H_ */ diff --git a/fw-plugin/calendar-plugIn/include/Extern_Info.h b/fw-plugin/calendar-plugIn/include/Extern_Info.h new file mode 100755 index 0000000..4d6f7bc --- /dev/null +++ b/fw-plugin/calendar-plugIn/include/Extern_Info.h @@ -0,0 +1,44 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#ifndef EXTERN_INFO_H_ +#define EXTERN_INFO_H_ + +typedef enum { + DEFAULT_CALENDAR_FOLDER = 0, + USER_DEFINED_FOLDER +} CALENDAR_FOLDER_TYPE; + +#endif /* EXTERN_INFO_H_ */ diff --git a/fw-plugin/calendar-plugIn/include/IN_DataStore_Info_Calendar.h b/fw-plugin/calendar-plugIn/include/IN_DataStore_Info_Calendar.h new file mode 100755 index 0000000..8f291f1 --- /dev/null +++ b/fw-plugin/calendar-plugIn/include/IN_DataStore_Info_Calendar.h @@ -0,0 +1,80 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Wook Choi + */ + +#ifndef IN_DATASTORE_INFO_CALENDAR_H_ +#define IN_DATASTORE_INFO_CALENDAR_H_ + +/* ITEM COUNT */ +#define MAX_ITEM_COUNT_CALENDAR 65535 + +/* TIMEZONE FIELD */ +#define VAL_TZ_BIAS NULL +#define VAL_TZ_DAYLIGHT NULL +#define VAL_TZ_DAYLIGHT_BIAS NULL +#define VAL_TZ_DAYLIGHT_BEGIN NULL +#define VAL_TZ_DAYLIGHT_END NULL +#define VAL_TZ_STANDARD_TIMENAME NULL +#define VAL_TZ_DAYLIGHT_TIMENAME NULL + +/* CALENDAR INFO */ +#define MAX_LEN_SUMMARY 65535 +#define MAX_LEN_DESCRIPTION 65535 +#define MAX_LEN_LOCATION 65535 +#define MIN_PERIOD_YEAR 1902 +#define MAX_PERIOD_YEAR 2037 +#define MAX_LEN_MEMO FALSE +#define VAL_TYPE_MODEL "A" + +/* FEATURE */ +#define IF_SUPPORT_APPOINTMENT TRUE +#define IF_SUPPORT_ANNIVERSARY FALSE +#define IF_SUPPORT_HOLIDAY FALSE +#define IF_SUPPORT_IMPORTANT FALSE +#define IF_SUPPORT_PRIVATE FALSE +#define IF_SUPPORT_MISCELLANEOUS FALSE +#define IF_SUPPORT_TASK FALSE +#define IF_SUPPORT_MEMO TRUE + +/* FEATURE FIELD */ +#define VAL_DB_INDEX_APPOINTMENT 1 +#define VAL_DB_INDEX_ANNIVERSARY 2 +#define VAL_DB_INDEX_HOLIDAY 3 +#define VAL_DB_INDEX_IMPORTANT 4 +#define VAL_DB_INDEX_PRIVATE 5 +#define VAL_DB_INDEX_MISCELLANEOUS 6 +#define VAL_DB_INDEX_TASK 7 +#define VAL_DB_INDEX_MEMO 8 + +#endif /* IN_DATASTORE_INFO_CALENDAR_H_ */ diff --git a/fw-plugin/calendar-plugIn/include/Item_Change_Info.h b/fw-plugin/calendar-plugIn/include/Item_Change_Info.h new file mode 100755 index 0000000..9d57b0e --- /dev/null +++ b/fw-plugin/calendar-plugIn/include/Item_Change_Info.h @@ -0,0 +1,43 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#ifndef ITEM_CHANGE_INFO_H_ +#define ITEM_CHANGE_INFO_H_ + +int getCalendarTimeStamp(); + +int setCalendarTimeStamp(int settingTime); + +#endif /* ITEM_CHANGE_INFO_H_ */ diff --git a/fw-plugin/calendar-plugIn/src/Item_Change_Info.c b/fw-plugin/calendar-plugIn/src/Item_Change_Info.c new file mode 100755 index 0000000..cd9a332 --- /dev/null +++ b/fw-plugin/calendar-plugIn/src/Item_Change_Info.c @@ -0,0 +1,54 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#include + +#include "Item_Change_Info.h" + +static int calendarTimeStamp = 0; + +int getCalendarTimeStamp() +{ + return ((int)time(0) - 3); +} + +int setCalendarTimeStamp(int settingTime) +{ + /* Critical Sectioin Start */ + calendarTimeStamp = settingTime; + /* Critical Section End */ + + return settingTime; +} diff --git a/fw-plugin/calendar-plugIn/src/PlugIn_Interface.c b/fw-plugin/calendar-plugIn/src/PlugIn_Interface.c new file mode 100755 index 0000000..80376b9 --- /dev/null +++ b/fw-plugin/calendar-plugIn/src/PlugIn_Interface.c @@ -0,0 +1,1208 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#include +#include +#include +#include +#include + +#include "Extern_Info.h" +#include "Item_Change_Info.h" +#include "EXT_DataStore_Info_Calendar.h" +#include "IN_DataStore_Info_Calendar.h" + +/* for log */ +#include "agent-framework/Utility/fw_log.h" + +#include "agent-framework/PlugIn/DataConnector_Interface.h" + +#define LOG_TAG "PLUGIN_DA_CALENDAR" + +#define FW_CALENDAR 1 /* plugIn-Id */ + +static pthread_mutex_t lockx; + +static int isNotiFromMe = 0; + +static int isStorageChanged = 0; + +static CALLBACK_ADD_ITEM callback_add_item; + +static CALLBACK_DEL_ITEM callback_del_item; + +static CALLBACK_UPDATE_ITEM callback_update_item; + +static GET_ACCOUNTIDLIST callback_get_accountidlist; + +static void __set_IsNotiFromMe(int set_flag); + +static int __get_IsNotiFromMe(); + +static void __process_Calendar_Change(void *); + +static void *__rutine_Calendar_Change(void *); + +static DACI_RETURN __convert_service_error_to_common_error(cal_error err); + +static bool __get_account_id(account_h account, void *user_data); + +static bool __is_Calendar_ID(account_capability_type_e capability_type, account_capability_state_e capability_value, void *user_data); + +typedef struct Account_ID { + int account_id; + struct Account_ID *next; +} Account_ID_t; + +DACI_RETURN Service_Open() +{ + FW_LOGV("[da_calendar_plugIn] Start in Calendar\n"); + + DACI_RETURN ret = DACI_SUCCESS; + int err = calendar_svc_connect(); + if (err != CAL_SUCCESS) { + FW_LOGV("[da_calendar_plugIn] in calendar Fail!\n"); + ret = __convert_service_error_to_common_error(err); + } else { + FW_LOGV("[da_calendar_plugIn] in calendar Success!\n"); + } + + FW_LOGV("[da_calendar_plugIn] End in Calendar\n"); + return ret; +} + +DACI_RETURN Service_Close() +{ + FW_LOGV("[da_calendar_plugIn] Start in Calendar\n"); + + DACI_RETURN ret = DACI_SUCCESS; + int err = calendar_svc_close(); + if (err < CAL_SUCCESS) { + FW_LOGV("[da_calendar_plugIn] in calendar Fail!\n"); + ret = __convert_service_error_to_common_error(err); + } else { + FW_LOGV("[da_calendar_plugIn] in calendar Success!\n"); + } + + FW_LOGV("[da_calendar_plugIn] End in Calendar\n"); + return ret; +} + +DACI_RETURN Begin_Transaction() +{ + FW_LOGV("[da_calendar_plugIn] Start in Calendar\n"); + + DACI_RETURN ret = DACI_SUCCESS; + int err = calendar_svc_begin_trans(); + if (err != CAL_SUCCESS) { + FW_LOGV("[da_calendar_plugIn] in calendar Fail!\n"); + ret = __convert_service_error_to_common_error(err); + } else { + FW_LOGV("[da_calendar_plugIn] in calendar Success!\n"); + __set_IsNotiFromMe(1); + } + + FW_LOGV("[da_calendar_plugIn] End in Calendar\n"); + return ret; +} + +int End_Transaction(int is_success) +{ + FW_LOGV("[da_calendar_plugIn] Start in Calendar\n"); + FW_LOGV("[da_calendar_plugIn] SLP Calendar Service is not supported Rollback Operation!\n"); + + DACI_RETURN ret = DACI_SUCCESS; + int err = calendar_svc_end_trans(); + if (err != CAL_SUCCESS) { + FW_LOGV("[da_calendar_plugIn] in calendar Fail!\n"); + ret = __convert_service_error_to_common_error(err); + } else { + FW_LOGV("[da_calendar_plugIn] in calendar Success!\n"); + if (isStorageChanged == 0) { + FW_LOGV("calendar storaged was not Changed!!"); + __set_IsNotiFromMe(0); + } + isStorageChanged = 0; + } + + FW_LOGV("[da_calendar_plugIn] End in Calendar\n"); + return ret; +} + +DACI_RETURN Add_Item(int account_id, char *folder_id, void *data, char **item_id) +{ + FW_LOGV("[da_calendar_plugIn] Start in Calendar\n"); + + DACI_RETURN ret = DACI_SUCCESS; + int err = 0; + cal_struct *item = (cal_struct *) data; + + /* parameter check */ + if (folder_id == 0) { + /* memory free */ + if (item != 0) + calendar_svc_struct_free(&item); + + *item_id = 0; + + FW_LOGV("[da_calendar_plugIn] service id is null \n"); + return DACI_ERR_INVALID_CONTENT; + } + + /* setting account & folder id */ + calendar_svc_struct_set_int(item, CAL_VALUE_INT_ACCOUNT_ID, account_id); + calendar_svc_struct_set_int(item, CAL_VALUE_INT_CALENDAR_ID, atoi(folder_id)); + + /* add item */ + err = calendar_svc_insert(item); + if (err < CAL_SUCCESS) { + FW_LOGV("[da_calendar_plugIn] calendar_svc_insert() Fail!\n"); + ret = __convert_service_error_to_common_error(err); + *item_id = 0; + } else { + FW_LOGV("[da_calendar_plugIn] calendar_svc_insert() Success!"); + *item_id = g_strdup_printf("%d", err); + isStorageChanged = 1; + } + + /* memory free */ + if (item != 0) + calendar_svc_struct_free(&item); + + FW_LOGV("[da_calendar_plugIn] End in Calendar\n"); + return ret; +} + +DACI_RETURN Update_Item(int account_id, char *folder_id, char *item_id, void *data) +{ + FW_LOGV("[da_calendar_plugIn] Start in Calendar\n"); + + DACI_RETURN ret = DACI_SUCCESS; + int err = 0; + cal_struct *item = (cal_struct *) data; + + /* parameter check */ + if ((folder_id == 0) || (item_id == 0)) { + /* memory free */ + if (item != 0) + calendar_svc_struct_free(&item); + + FW_LOGV("[da_calendar_plugIn] service id is null \n"); + return DACI_ERR_INVALID_CONTENT; + } + + /* setting account & folder id */ + calendar_svc_struct_set_int(item, CAL_VALUE_INT_ACCOUNT_ID, account_id); + calendar_svc_struct_set_int(item, CAL_VALUE_INT_CALENDAR_ID, atoi(folder_id)); + calendar_svc_struct_set_int(item, CAL_VALUE_INT_INDEX, atoi(item_id)); + + /* update item */ + err = calendar_svc_update(item); + if (err < CAL_SUCCESS) { + FW_LOGV("[da_calendar_plugIn] calendar_svc_update() Fail!\n"); + ret = __convert_service_error_to_common_error(err); + } else { + FW_LOGV("[da_calendar_plugIn] calendar_svc_update() Success!"); + isStorageChanged = 1; + } + + /* memory free */ + if (item != 0) + calendar_svc_struct_free(&item); + + FW_LOGV("[da_calendar_plugIn] End in Calendar\n"); + return ret; +} + +DACI_RETURN Del_Item(int account_id, char *folder_id, char *item_id) +{ + FW_LOGV("[da_calendar_plugIn] Start in Calendar\n"); + + /* parameter check */ + if (item_id == 0) { + FW_LOGV("[da_calendar_plugIn] service id is null \n"); + return DACI_ERR_INVALID_CONTENT; + } + + /* delete item */ + DACI_RETURN ret = DACI_SUCCESS; + int err = calendar_svc_delete(CAL_STRUCT_SCHEDULE, atoi(item_id)); + + if (err != CAL_SUCCESS) { + FW_LOGV("[da_calendar_plugIn] calendar_svc_delete() Fail!"); + ret = __convert_service_error_to_common_error(err); + } else { + FW_LOGV("[da_calendar_plugIn] calendar_svc_delete() Success!"); + isStorageChanged = 1; + } + + FW_LOGV("[da_calendar_plugIn] End in Calendar\n"); + return ret; +} + +DACI_RETURN Del_All_Items(int account_id) +{ + FW_LOGV("[da_calendar_plugIn] Start in Calendar\n"); + + DACI_RETURN ret = DACI_SUCCESS; + int err = 1; + int folder_id_list_cnt = 0; + int *folder_type_list; + char **folder_id_list = 0; + cal_iter *iter = 0; + cal_struct *item = 0; + int item_id = 0; + + /* get folder id list for account id */ + folder_id_list = Get_Folder_ID_List(account_id, &folder_id_list_cnt, &folder_type_list); + if (folder_id_list == 0) { + FW_LOGV("[da_calendar_plugIn] folder id list cnt : %d\n", folder_id_list_cnt); + return DACI_ERR_NO_DATA; + } + + int cnt = 0; + for (; cnt < folder_id_list_cnt; cnt++) { + /* get item id list (iter) for each folder id */ + err = calendar_svc_get_all(account_id, atoi(folder_id_list[cnt]), CAL_STRUCT_SCHEDULE, &iter); + + if (err == CAL_SUCCESS) { + FW_LOGV("[da_calendar_plugIn] calendar_svc_get_all Success!! \n"); + + while (calendar_svc_iter_next(iter) == CAL_SUCCESS) { + /* get item */ + err = calendar_svc_iter_get_info(iter, &item); + if (err == CAL_SUCCESS) { + item_id = calendar_svc_struct_get_int(item, CAL_VALUE_INT_INDEX); + FW_LOGV("[da_calendar_plugIn] item id : %d\n", item_id); + + err = calendar_svc_delete(CAL_STRUCT_SCHEDULE, item_id); + if (err != CAL_SUCCESS) { + FW_LOGV("[da_calendar_plugIn] calendar_svc_delete(%d) Fail!\n", item_id); + ret = __convert_service_error_to_common_error(err); + goto DACI_FINISH; + } else { + FW_LOGV("[da_calendar_plugIn] calendar_svc_delete(%d) Success!\n", item_id); + isStorageChanged = 1; + } + + /* memory free */ + if (item != 0) { + calendar_svc_struct_free(&item); + item = 0; + } + item_id = 0; + + } else { + FW_LOGV("[da_calendar_plugIn] get item (item id : %d) Fail!\n", item_id); + ret = __convert_service_error_to_common_error(err); + goto DACI_FINISH; + } + } /* end while */ + + if (iter != 0) { + FW_LOGV("[da_calendar_plugIn] calendar_svc_iter_remove !! \n"); + calendar_svc_iter_remove(&iter); + iter = 0; + } + + } else { + FW_LOGV("[da_calendar_plugIn] get item id list (folder id : %d) Fail!\n", atoi(folder_id_list[cnt])); + ret = __convert_service_error_to_common_error(err); + goto DACI_FINISH; + } + } + +DACI_FINISH: + + /* memory free */ + if (item != 0) + calendar_svc_struct_free(&item); + + if (iter != 0) { + calendar_svc_iter_remove(&iter); + FW_LOGV("[da_calendar_plugIn] calendar_svc_iter_remove !! \n"); + } + if (folder_id_list != 0) { + for (cnt = 0; cnt < folder_id_list_cnt; cnt++) { + if (folder_id_list[cnt] != NULL) { + free(folder_id_list[cnt]); + FW_LOGV("[da_calendar_plugIn] folder id free !! \n"); + } + } + cfree(folder_id_list); + FW_LOGV("[da_calendar_plugIn] folder id list free !! \n"); + } + if (folder_type_list != 0) { + cfree(folder_type_list); + FW_LOGV("[da_calendar_plugIn] folder type list free !! \n"); + } + + FW_LOGV("[da_calendar_plugIn] End in Calendar\n"); + return ret; +} + +DACI_RETURN Get_Item(int account_id, char *folder_id, char *item_id, void **data) +{ + FW_LOGV("[da_calendar_plugIn] Start in Calendar\n"); + + DACI_RETURN ret = DACI_SUCCESS; + int err = 0; + cal_struct *item = 0; + + /* parameter check */ + if (item_id == 0) { + FW_LOGV("[da_calendar_plugIn] service id is null \n"); + return DACI_ERR_INVALID_CONTENT; + } + + /* get item */ + err = calendar_svc_get(CAL_STRUCT_SCHEDULE, atoi(item_id), 0, &item); + if (err < CAL_SUCCESS) { + FW_LOGV("[da_calendar_plugIn] calendar_svc_get() Fail!\n"); + ret = __convert_service_error_to_common_error(err); + *data = 0; + } else { + FW_LOGV("[da_calendar_plugIn] calendar_svc_get() Success!\n"); + *data = (void *)item; + } + + FW_LOGV("[da_calendar_plugIn] End in Calendar\n"); + return ret; +} + +DACI_RETURN Add_Folder(int account_id, char *folder_name, int folder_type, char **folder_id) +{ + FW_LOGV("[da_calendar_plugIn] Start in Calendar\n"); + + DACI_RETURN ret = DACI_SUCCESS; + int err = 0; + cal_struct *folder = 0; + + /* parameter check */ + if (folder_name == 0) { + FW_LOGV("[da_calendar_plugIn] service id is null \n"); + *folder_id = 0; + return DACI_ERR_INVALID_CONTENT; + } + + /* new service struct */ + folder = calendar_svc_struct_new(CAL_STRUCT_CALENDAR); + if (folder == 0) { + FW_LOGV("[da_calendar_plugIn] calendar_svc_struct_new() Fail!\n"); + *folder_id = 0; + return DACI_ERRORS; + } + + /* setting folder data */ + calendar_svc_struct_set_int(folder, CAL_TABLE_INT_ACCOUNT_ID, account_id); + calendar_svc_struct_set_int(folder, CAL_TABLE_INT_VISIBILITY, 1); + calendar_svc_struct_set_str(folder, CAL_TABLE_TXT_NAME, folder_name); + + /* add folder */ + err = calendar_svc_insert(folder); + if (err < CAL_SUCCESS) { + FW_LOGV("[da_calendar_plugIn] calendar_svc_insert() Fail!\n"); + ret = __convert_service_error_to_common_error(err); + *folder_id = 0; + } else { + FW_LOGV("[da_calendar_plugIn] calendar_svc_insert() Success!"); + *folder_id = g_strdup_printf("%d", err); + isStorageChanged = 1; + } + + /* memory free */ + if (folder != 0) + calendar_svc_struct_free(&folder); + + FW_LOGV("[da_calendar_plugIn] End in Calendar\n"); + return ret; +} + +DACI_RETURN Del_Folder(int account_id, char *folder_id) +{ + FW_LOGV("[da_calendar_plugIn] Start in Calendar\n"); + + DACI_RETURN ret = DACI_SUCCESS; + int err = 0; + + /* parameter check */ + if (folder_id == 0) { + FW_LOGV("[da_calendar_plugIn] service id is null \n"); + return DACI_ERR_INVALID_CONTENT; + } + + /* delete folder */ + err = calendar_svc_delete(CAL_STRUCT_CALENDAR, atoi(folder_id)); + if (err < CAL_SUCCESS) { + FW_LOGV("[da_calendar_plugIn] calendar_svc_delete() Fail!\n"); + ret = __convert_service_error_to_common_error(err); + } else { + FW_LOGV("[da_calendar_plugIn] calendar_svc_delete() Success!\n"); + calendar_svc_clean_after_sync(account_id); + isStorageChanged = 1; + } + + FW_LOGV("[da_calendar_plugIn] End in Calendar\n"); + return ret; +} + +DACI_RETURN Get_Folder(int account_id, char *folder_id, char **out_folder_name, int *out_folder_type) +{ + FW_LOGV("[da_calendar_plugIn] Start in Calendar\n"); + + DACI_RETURN ret = DACI_SUCCESS; + int err = 0; + cal_struct *folder = 0; + + /* parameter check */ + if (folder_id == 0) { + FW_LOGV("[da_calendar_plugIn] service id is null \n"); + *out_folder_name = 0; + *out_folder_type = -1; + return DACI_ERR_INVALID_CONTENT; + } + + /* get item */ + int calendar_folder_id = atoi(folder_id); + FW_LOGV("[da_calendar_plugIn] calendar_folder_id : %d\n", calendar_folder_id); + err = calendar_svc_get(CAL_STRUCT_CALENDAR, calendar_folder_id, 0, &folder); + if (err < CAL_SUCCESS) { + FW_LOGV("[da_contact_plugIn] contacts_svc_get_addressbook() Fail!\n"); + ret = __convert_service_error_to_common_error(err); + *out_folder_name = 0; + *out_folder_type = -1; + } else { + FW_LOGV("[da_contact_plugIn] contacts_svc_get_addressbook() Success!\n"); + *out_folder_name = calendar_svc_struct_get_str(folder, CAL_TABLE_TXT_NAME); + *out_folder_type = DEFAULT_CALENDAR_FOLDER; + } + + /* memory free */ + if (folder != 0) + calendar_svc_struct_free(&folder); + + FW_LOGV("[da_calendar_plugIn] End in Calendar\n"); + return ret; +} + +DACI_RETURN Execute(int account_ID, const char *execute_key, void *execute_values, void **result) +{ + FW_LOGV("[da_calendar_plugIn] Start in Calendar\n"); + FW_LOGV("[da_calendar_plugIn] service is not supported execute. \n"); + *result = 0; + FW_LOGV("[da_calendar_plugIn] End in Calendar\n"); + return DACI_SUCCESS; +} + +int Get_Used_Item_Count() +{ + FW_LOGV("[da_calendar_plugIn] Start in Calendar\n"); + + int ret = DACI_SUCCESS; + int used_cnt = calendar_svc_get_count(0, 0, CAL_STRUCT_SCHEDULE); + if (used_cnt < 0) { + FW_LOGV("[da_calendar_plugIn] calendar_svc_get_count() Fail\n"); + ret = __convert_service_error_to_common_error(used_cnt); + } else { + FW_LOGV("[da_calendar_plugIn] calendar_svc_get_count() Success\n"); + FW_LOGV("[da_calendar_plugIn] used_count = %d\n", used_cnt); + ret = used_cnt; + } + + FW_LOGV("[da_contact_plugIn] End in Calendar\n"); + return ret; +} + +int Get_Used_Item_Count_For_Folder(int account_id, char *folder_id) +{ + FW_LOGV("[da_calendar_plugIn] Start in Calendar\n"); + + /* parameter check */ + if (folder_id == 0) { + FW_LOGV("[da_calendar_plugIn] service id is null \n"); + return DACI_ERR_INVALID_CONTENT; + } + + int ret = DACI_SUCCESS; + int used_cnt = calendar_svc_get_count(account_id, atoi(folder_id), CAL_STRUCT_SCHEDULE); + if (used_cnt < 0) { + FW_LOGV("[da_calendar_plugIn] calendar_svc_get_count(%s) Fail\n", folder_id); + ret = __convert_service_error_to_common_error(used_cnt); + } else { + FW_LOGV("[da_calendar_plugIn] calendar_svc_get_count(%s) Success\n", folder_id); + FW_LOGV("[da_calendar_plugIn] used_count = %d\n", used_cnt); + ret = used_cnt; + } + + FW_LOGV("[da_contact_plugIn] End in Calendar\n"); + return ret; +} + +char **Get_Folder_ID_List(int account_id, int *folder_count, int **folder_type_list) +{ + FW_LOGV("[da_calendar_plugIn] Start in Calendar\n"); + + char **folder_id_list = 0; + int count = 0; + cal_iter *folder_Iter = 0; + cal_struct *folder = 0; + int err = 0; + int i = 0; + *folder_count = 0; + + count = calendar_svc_get_count(account_id, 0, CAL_STRUCT_CALENDAR); + if (count != 0) { + folder_id_list = (char **)calloc(count, sizeof(char *)); + *folder_type_list = (int *)calloc(count, sizeof(int)); + + /* find */ + err = calendar_svc_get_all(account_id, 0, CAL_STRUCT_CALENDAR, &folder_Iter); + + do { + /* get */ + err = calendar_svc_iter_get_info(folder_Iter, &folder); + if (err == CAL_SUCCESS) { + + /* check */ + folder_id_list[i] = g_strdup_printf("%d", calendar_svc_struct_get_int(folder, CAL_TABLE_INT_INDEX)); + (*folder_type_list)[i] = DEFAULT_CALENDAR_FOLDER; + i++; + *folder_count = i; + + if (folder != 0) + calendar_svc_struct_free(&folder); + } else { + FW_LOGV("[da_calendar_plugIn] calendar_svc_iter_get_info() Fail!\n"); + break; + } + } while (calendar_svc_iter_next(folder_Iter) == CAL_SUCCESS); + } + /* memory free */ + if (folder_Iter != 0) + calendar_svc_iter_remove(&folder_Iter); + + return folder_id_list; +} + +int *Get_Account_ID_List(int *count) +{ + FW_LOGV("[da_calendar_plugIn] start!!\n"); + + int error_code = account_connect(); + + Account_ID_t *account_info_list = (Account_ID_t *) calloc(1, sizeof(Account_ID_t)); + account_info_list->account_id = -1; + account_info_list->next = 0; + + account_foreach_account_from_db(__get_account_id, account_info_list); + + *count = 0; + Account_ID_t *cursor_ptr = account_info_list; + while (cursor_ptr != 0) { + cursor_ptr = cursor_ptr->next; + (*count)++; + } + + int *id_list = 0; + if ((*count) > 0) { + id_list = (int *)calloc(*count, sizeof(int)); + cursor_ptr = account_info_list; + int i = 0; + while (cursor_ptr != 0) { + id_list[i] = cursor_ptr->account_id; + cursor_ptr = cursor_ptr->next; + i++; + } + } + + free(account_info_list); + + error_code = account_disconnect(); + + FW_LOGV("[da_calendar_plugIn] end!!\n"); + + return id_list; +} + +Item_Node *Get_Changed_ITEM_For_Folder_Add(int account_id, const char *folder_id, int changepoint, int *changeCount) +{ + FW_LOGV("\n[da_calendar_plugIn] account_id : %d\n", account_id); + FW_LOGV("[da_calendar_plugIn] folder_id : %s\n", folder_id); + FW_LOGV("[da_calendar_plugIn] changepoint : %d\n", changepoint); + + int calendarTimeStamp = changepoint; + int temp_folder_id = atoi(folder_id); + int calendar_ret = 0; + cal_iter *iter = 0; + cal_struct *row_event = 0; + + Item_Node *root_ptr = 0; + Item_Node *cursor_ptr = 0; + int chagned_count = 0; + + calendar_svc_get_updated_event_list(account_id, calendarTimeStamp, &iter); + calendar_ret = calendar_svc_iter_next(iter); + FW_LOGV("[da_calendar_plugIn] calendar_ret : %d\n", calendar_ret); + + while (CAL_SUCCESS == calendar_ret) { + if ((calendar_svc_iter_get_info(iter, &row_event)) != CAL_SUCCESS) { + FW_LOGV("[da_calendar_plugIn] calendar_svc_iter_get_info() failed.\n"); + } else { + int type = calendar_svc_struct_get_int(row_event, CAL_VALUE_INT_SYNC_STATUS); + int calendar_folder_id = calendar_svc_struct_get_int(row_event, CAL_VALUE_INT_CALENDAR_ID); + + if ((type == CAL_SYNC_STATUS_NEW) && (calendar_folder_id == temp_folder_id)) { + int calendar_id = calendar_svc_struct_get_int(row_event, CAL_VALUE_INT_INDEX); + char *calendar_id_str = (char *)calloc(5, sizeof(char)); + sprintf(calendar_id_str, "%d", calendar_id); + FW_LOGV("[da_calendar_plugIn] CAL_SYNC_STATUS_NEW : [%s]\n", calendar_id_str); + + if (root_ptr == 0) { + root_ptr = (Item_Node *) calloc(1, sizeof(Item_Node)); + root_ptr->item_id = calendar_id_str; + root_ptr->next = 0; + cursor_ptr = root_ptr; + } else { + cursor_ptr->next = (Item_Node *) calloc(1, sizeof(Item_Node)); + cursor_ptr->next->item_id = calendar_id_str; + cursor_ptr->next->next = 0; + cursor_ptr = cursor_ptr->next; + } + + chagned_count++; + } + } + + if (row_event != 0) { + calendar_svc_struct_free(&row_event); + row_event = 0; + } + calendar_ret = calendar_svc_iter_next(iter); + } + + if (iter != 0) + calendar_svc_iter_remove(&iter); + + *changeCount = chagned_count; + return root_ptr; +} + +Item_Node *Get_Changed_ITEM_For_Folder_Del(int account_id, const char *folder_id, int changepoint, int *changeCount) +{ + FW_LOGV("\n[da_calendar_plugIn] account_id : %d\n", account_id); + FW_LOGV("[da_calendar_plugIn] folder_id : %s\n", folder_id); + FW_LOGV("[da_calendar_plugIn] changepoint : %d\n", changepoint); + + int calendarTimeStamp = changepoint; + int temp_folder_id = atoi(folder_id); + int calendar_ret = 0; + cal_iter *iter = 0; + cal_struct *row_event = 0; + + Item_Node *root_ptr = 0; + Item_Node *cursor_ptr = 0; + int chagned_count = 0; + + calendar_svc_get_updated_event_list(account_id, calendarTimeStamp, &iter); + calendar_ret = calendar_svc_iter_next(iter); + FW_LOGV("[da_calendar_plugIn] calendar_ret : %d\n", calendar_ret); + + while (CAL_SUCCESS == calendar_ret) { + if ((calendar_svc_iter_get_info(iter, &row_event)) != CAL_SUCCESS) { + FW_LOGV("[da_calendar_plugIn] calendar_svc_iter_get_info() failed.\n"); + } else { + int type = calendar_svc_struct_get_int(row_event, CAL_VALUE_INT_SYNC_STATUS); + int calendar_folder_id = calendar_svc_struct_get_int(row_event, CAL_VALUE_INT_CALENDAR_ID); + + if ((type == CAL_SYNC_STATUS_DELETED) && (calendar_folder_id == temp_folder_id)) { + int calendar_id = calendar_svc_struct_get_int(row_event, CAL_VALUE_INT_INDEX); + char *calendar_id_str = (char *)calloc(5, sizeof(char)); + sprintf(calendar_id_str, "%d", calendar_id); + FW_LOGV("[da_calendar_plugIn] CAL_SYNC_STATUS_DELETED : [%s]\n", calendar_id_str); + + if (root_ptr == 0) { + root_ptr = (Item_Node *) calloc(1, sizeof(Item_Node)); + root_ptr->item_id = calendar_id_str; + root_ptr->next = 0; + cursor_ptr = root_ptr; + } else { + cursor_ptr->next = (Item_Node *) calloc(1, sizeof(Item_Node)); + cursor_ptr->next->item_id = calendar_id_str; + cursor_ptr->next->next = 0; + cursor_ptr = cursor_ptr->next; + } + + chagned_count++; + } + } + + if (row_event != 0) { + calendar_svc_struct_free(&row_event); + row_event = 0; + } + calendar_ret = calendar_svc_iter_next(iter); + } + + if (iter != 0) + calendar_svc_iter_remove(&iter); + + *changeCount = chagned_count; + return root_ptr; +} + +Item_Node *Get_Changed_ITEM_For_Folder_Update(int account_id, const char *folder_id, int changepoint, int *changeCount) +{ + FW_LOGV("\n[da_calendar_plugIn] account_id : %d\n", account_id); + FW_LOGV("[da_calendar_plugIn] folder_id : %s\n", folder_id); + FW_LOGV("[da_calendar_plugIn] changepoint : %d\n", changepoint); + + int calendarTimeStamp = changepoint; + int temp_folder_id = atoi(folder_id); + int calendar_ret = 0; + cal_iter *iter = 0; + cal_struct *row_event = 0; + + Item_Node *root_ptr = 0; + Item_Node *cursor_ptr = 0; + int chagned_count = 0; + + calendar_svc_get_updated_event_list(account_id, calendarTimeStamp, &iter); + calendar_ret = calendar_svc_iter_next(iter); + FW_LOGV("[da_calendar_plugIn] calendar_ret : %d\n", calendar_ret); + + while (CAL_SUCCESS == calendar_ret) { + if ((calendar_svc_iter_get_info(iter, &row_event)) != CAL_SUCCESS) { + FW_LOGV("[da_calendar_plugIn] calendar_svc_iter_get_info() failed.\n"); + } else { + int type = calendar_svc_struct_get_int(row_event, CAL_VALUE_INT_SYNC_STATUS); + int calendar_folder_id = calendar_svc_struct_get_int(row_event, CAL_VALUE_INT_CALENDAR_ID); + + if ((type == CAL_SYNC_STATUS_UPDATED) && (calendar_folder_id == temp_folder_id)) { + int calendar_id = calendar_svc_struct_get_int(row_event, CAL_VALUE_INT_INDEX); + char *calendar_id_str = (char *)calloc(5, sizeof(char)); + sprintf(calendar_id_str, "%d", calendar_id); + FW_LOGV("[da_calendar_plugIn] CAL_SYNC_STATUS_UPDATED : [%s]\n", calendar_id_str); + + if (root_ptr == 0) { + root_ptr = (Item_Node *) calloc(1, sizeof(Item_Node)); + root_ptr->item_id = calendar_id_str; + root_ptr->next = 0; + cursor_ptr = root_ptr; + } else { + cursor_ptr->next = (Item_Node *) calloc(1, sizeof(Item_Node)); + cursor_ptr->next->item_id = calendar_id_str; + cursor_ptr->next->next = 0; + cursor_ptr = cursor_ptr->next; + } + + chagned_count++; + } + } + + if (row_event != 0) { + calendar_svc_struct_free(&row_event); + row_event = 0; + } + calendar_ret = calendar_svc_iter_next(iter); + } + + if (iter != 0) + calendar_svc_iter_remove(&iter); + + *changeCount = chagned_count; + return root_ptr; +} + +int Get_Last_ChangePoint() +{ + return (int)time(0); +} + +void StartListening_ChangeNoti(void *data) +{ + calendar_svc_subscribe_change(__process_Calendar_Change, 0); +} + +void SetCallBack_AddItem(CALLBACK_ADD_ITEM callback) +{ + callback_add_item = callback; +} + +void SetCallBack_DeleteItem(CALLBACK_DEL_ITEM callback) +{ + callback_del_item = callback; +} + +void SetCallBack_UpdateItem(CALLBACK_UPDATE_ITEM callback) +{ + callback_update_item = callback; +} + +void SetCallBack_GetAccountIDList(GET_ACCOUNTIDLIST callback) +{ + callback_get_accountidlist = callback; +} + +int Get_MAX_Item_Count(int folder_type) +{ + return MAX_ITEM_COUNT_CALENDAR; +} + +int Get_MAX_Field_Length(int field_name, int child_field_name) +{ + switch (field_name) { + case CALENDAR_FIELD_SUMMARY: + return MAX_LEN_SUMMARY; + case CALENDAR_FIELD_DESCRIPTION: + return MAX_LEN_DESCRIPTION; + case CALENDAR_FIELD_LOCATOIN: + return MAX_LEN_LOCATION; + case CALENDAR_FIELD_MEMO: + return MAX_LEN_MEMO; + default: + return -1; + } +} + +int Get_MAX_Field_Count(int field_name, int child_field_name) +{ + return -1; +} + +int Get_Field_Value(int field_name, int child_field_name, char **str_val, int *num_val1, int *num_val2) +{ + switch (field_name) { + case CALENDAR_FIELD_YEAR: + *num_val1 = MIN_PERIOD_YEAR; + *num_val2 = MAX_PERIOD_YEAR; + return 1; + case CALENDAR_FIELD_TYPE_MODEL: + *str_val = VAL_TYPE_MODEL; + return 1; + case CALENDAR_FIELD_DB_INDEX: + switch (child_field_name) { + case CALENDAR_FEATURE_APPOINTMENT: + *num_val1 = VAL_DB_INDEX_APPOINTMENT; + return 1; + case CALENDAR_FEATURE_ANNIVERSARY: + *num_val1 = VAL_DB_INDEX_ANNIVERSARY; + return 1; + case CALENDAR_FEATURE_HOLIDAY: + *num_val1 = VAL_DB_INDEX_HOLIDAY; + return 1; + case CALENDAR_FEATURE_IMPORTANT: + *num_val1 = VAL_DB_INDEX_IMPORTANT; + return 1; + case CALENDAR_FEATURE_PRIVATE: + *num_val1 = VAL_DB_INDEX_PRIVATE; + return 1; + case CALENDAR_FEATURE_MISCELLANEOUS: + *num_val1 = VAL_DB_INDEX_MISCELLANEOUS; + return 1; + case CALENDAR_FEATURE_TASK: + *num_val1 = VAL_DB_INDEX_TASK; + return 1; + case CALENDAR_FEATURE_MEMO: + *num_val1 = VAL_DB_INDEX_MEMO; + return 1; + default: + return -1; + } + case CALENDAR_FIELD_TIMEZONE: + switch (child_field_name) { + case CALENDAR_CHILD_FIELD_BIAS: + *num_val1 = (int)VAL_TZ_BIAS; + return 1; + case CALENDAR_CHILD_FIELD_DAYLIGHT: + *num_val1 = (int)VAL_TZ_DAYLIGHT; + return 1; + case CALENDAR_CHILD_FIELD_DAYLIGHT_BIAS: + *num_val1 = (int)VAL_TZ_DAYLIGHT_BIAS; + return 1; + case CALENDAR_CHILD_FIELD_DAYLIGHT_BEGIN: + *str_val = VAL_TZ_DAYLIGHT_BEGIN; + return 1; + case CALENDAR_CHILD_FIELD_DAYLIGHT_END: + *str_val = VAL_TZ_DAYLIGHT_END; + return 1; + case CALENDAR_CHILD_FIELD_STANDARD_TIMENAME: + *str_val = VAL_TZ_STANDARD_TIMENAME; + return 1; + case CALENDAR_CHILD_FIELD_DAYLIGHT_TIMENAME: + *str_val = VAL_TZ_DAYLIGHT_TIMENAME; + return 1; + default: + return -1; + } + default: + return -1; + } +} + +int Get_Is_Support_Feature(int feature) +{ + switch (feature) { + case CALENDAR_FEATURE_APPOINTMENT: + return IF_SUPPORT_APPOINTMENT; + case CALENDAR_FEATURE_ANNIVERSARY: + return IF_SUPPORT_ANNIVERSARY; + case CALENDAR_FEATURE_HOLIDAY: + return IF_SUPPORT_HOLIDAY; + case CALENDAR_FEATURE_IMPORTANT: + return IF_SUPPORT_IMPORTANT; + case CALENDAR_FEATURE_PRIVATE: + return IF_SUPPORT_PRIVATE; + case CALENDAR_FEATURE_MISCELLANEOUS: + return IF_SUPPORT_MISCELLANEOUS; + case CALENDAR_FEATURE_TASK: + return IF_SUPPORT_TASK; + case CALENDAR_FEATURE_MEMO: + return IF_SUPPORT_MEMO; + default: + return -1; + } +} + +/********************************** static function *******************************************/ + +static void __set_IsNotiFromMe(int set_flag) +{ + if (pthread_mutex_lock(&lockx)) { + FW_LOGV("[da_calendar_plugIn] pthread_mutex_lock error"); + } + + isNotiFromMe = set_flag; + + if (pthread_mutex_unlock(&lockx)) { + FW_LOGV("[da_calendar_plugIn] pthread_mutex_unlock error"); + } +} + +static int __get_IsNotiFromMe() +{ + return isNotiFromMe; +} + +void __process_Calendar_Change(void *data) +{ + FW_LOGV("[da_calendar_plugIn] detected calendar storage changed\n"); + + int from_Me = __get_IsNotiFromMe(); + if (from_Me == 1) { + __set_IsNotiFromMe(0); + FW_LOGV("[da_calendar_plugIn] This noti is from Me!! so will be ignored!!\n"); + return; + } + + pthread_t thread_process_change_id; + pthread_create(&thread_process_change_id, 0, __rutine_Calendar_Change, 0); +} + +static void *__rutine_Calendar_Change(void *data) +{ + FW_LOGV("[da_calendar_plugIn] Start __rutine_Calendar_Change (create thread)\n"); + + int calendarTimeStamp = getCalendarTimeStamp(); + + int count; + int *accountList = callback_get_accountidlist(FW_CALENDAR, &count); + if (accountList == 0) + return 0; + + cal_iter *iter = 0; + + int i = 0; + for (; i < count; i++) { + int calendar_account_id = accountList[i]; + FW_LOGV("[da_calendar_plugIn] calendar_account_id : %d, count : %d\n", calendar_account_id, count); + FW_LOGV("[da_calendar_plugIn] Before calendar_svc_get_updated_event_list : %d\n", calendarTimeStamp); + + calendar_svc_get_updated_event_list(calendar_account_id, calendarTimeStamp, &iter); + int calendar_ret = calendar_svc_iter_next(iter); + FW_LOGV("[da_calendar_plugIn] calendar_ret : %d\n", calendar_ret); + + while (CAL_SUCCESS == calendar_ret) { + cal_struct *row_event = 0; + + if ((calendar_svc_iter_get_info(iter, &row_event)) != CAL_SUCCESS) { + FW_LOGV("[da_calendar_plugIn] calendar_svc_iter_get_info() failed.\n"); + } else { + int calendar_id = calendar_svc_struct_get_int(row_event, CAL_VALUE_INT_INDEX); + char calendar_id_str[12]; + sprintf(calendar_id_str, "%d", calendar_id); + int type = calendar_svc_struct_get_int(row_event, CAL_VALUE_INT_SYNC_STATUS); + int calendar_folder_id = calendar_svc_struct_get_int(row_event, CAL_VALUE_INT_CALENDAR_ID); + char calendar_folder_id_str[12]; + sprintf(calendar_folder_id_str, "%d", calendar_folder_id); + switch (type) { + case CAL_SYNC_STATUS_NEW: + { + FW_LOGV("[da_calendar_plugIn] Calendar Inserted!\n"); + FW_LOGV("[da_calendar_plugIn] calendar folder id : %s\n", calendar_folder_id_str); + int result = callback_add_item(accountList[i], i, calendar_id_str, FW_CALENDAR, calendar_folder_id_str, 0); + if (!result) + FW_LOGV("[da_calendar_plugIn] Failed to call SA_EH_Add_Item() \n"); + else + FW_LOGV("[da_calendar_plugIn] Success to call SA_EH_Add_Item() \n"); + + } + break; + case CAL_SYNC_STATUS_UPDATED: + { + FW_LOGV("[da_calendar_plugIn] Calendar Updated!\n"); + int result = callback_update_item(accountList[i], i, calendar_id_str, FW_CALENDAR); + if (!result) + FW_LOGV("[da_calendar_plugIn] Failed to call callback_del_item() \n"); + } + break; + case CAL_SYNC_STATUS_DELETED: + { + FW_LOGV("[da_calendar_plugIn] Calendar Deleted!\n"); + int result = callback_del_item(accountList[i], i, calendar_id_str, FW_CALENDAR); + if (!result) + FW_LOGV("[da_calendar_plugIn] Failed to call callback_del_item() \n"); + } + break; + default: + FW_LOGV("[da_calendar_plugIn] cached Another Calendar Change Noti!\n"); + break; + } + } + + calendar_svc_struct_free(&row_event); + row_event = 0; + calendar_ret = calendar_svc_iter_next(iter); + } + } + + if (accountList != 0) { + free(accountList); + } + + calendar_svc_iter_remove(&iter); + + FW_LOGV("[da_calendar_plugIn] End __rutine_Calendar_Change (create thread)\n"); + + return 0; +} + +static DACI_RETURN __convert_service_error_to_common_error(cal_error err) +{ + DACI_RETURN ret = DACI_SUCCESS; + FW_LOGV("[da_calendar_plugIn] Error Code : %d\n", err); + + switch (err) { + case CAL_ERR_DB_LOCK: /* -204 */ + ret = DACI_ERR_LOCKED; + break; + case CAL_ERR_DB_RECORD_NOT_FOUND: /* -203 */ + case CAL_ERR_NO_DATA: /* -3 */ + ret = DACI_ERR_NO_DATA; + break; + case CAL_ERR_DB_NOT_OPENED: /* -201 */ + ret = DACI_ERR_OPEN_FAILED; + break; + case CAL_ERR_OUT_OF_MEMORY: /* -8 */ + ret = DACI_ERR_MEMORY_FULL; + break; + case CAL_ERR_ALREADY_EXIST: /* -7 */ + ret = DACI_ERR_ALREADY_EXIST; + break; + case CAL_ERR_EVENT_START_DATE: /* -405 */ + case CAL_ERR_EVENT_END_DATE: /* -404 */ + case CAL_ERR_EVENT_REPEAT_END_DATE: /* -403 */ + case CAL_ERR_EVENT_DURATION: /* -402 */ + case CAL_ERR_EVENT_REPEAT_DURATION_TOO_SHORT: /* -401 */ + case CAL_ERR_INVALID_DATA_TYPE: /* -301 */ + case CAL_ERR_ARG_NULL: /* -5 */ + case CAL_ERR_ARG_INVALID: /* -4 */ + ret = DACI_ERR_INVALID_CONTENT; + break; + case CAL_ERR_FINISH_ITER: /* -2 */ + case CAL_SUCCESS: /* 0 */ + case CAL_TRUE: /* 1 */ + ret = DACI_SUCCESS; + break; + /* + * CAL_ERR_DB_FAILED: -202, + * CAL_ERR_VCONF_FAILED: -102, + * CAL_ERR_VOBJECT_FAILED: -101, + * CAL_ERR_EXCEEDED_LIMIT: -9, + * CAL_ERR_ENV_INVALID: -6, CAL_ERR_FAIL: -1, + */ + default: + ret = DACI_ERRORS; + break; + } + + return ret; +} + +static bool __get_account_id(account_h account, void *user_data) +{ + Account_ID_t *account_info_list = user_data; + + bool has_contact = FALSE; + + account_get_capability(account, __is_Calendar_ID, &has_contact); + + if (has_contact == FALSE) { + /* DO Nothing */ + } else { + Account_ID_t *account_info = (Account_ID_t *) calloc(1, sizeof(Account_ID_t)); + account_get_account_id(account, &(account_info->account_id)); + FW_LOGV("Getted accont id : %d", account_info->account_id); + account_info->next = 0; + + Account_ID_t *cursor_ptr = account_info_list; + while (cursor_ptr->next != 0) { + cursor_ptr = cursor_ptr->next; + } + + cursor_ptr->next = account_info; + } + + return has_contact; +} + +static bool __is_Calendar_ID(account_capability_type_e capability_type, account_capability_state_e capability_value, void *user_data) +{ + bool *has_contact = user_data; + if (capability_type == ACCOUNT_CAPABILITY_CALENDAR) { + *has_contact = TRUE; + return FALSE; + } + return TRUE; +} diff --git a/fw-plugin/contact-plugIn/.cproject b/fw-plugin/contact-plugIn/.cproject new file mode 100755 index 0000000..3c36d31 --- /dev/null +++ b/fw-plugin/contact-plugIn/.cproject @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/fw-plugin/contact-plugIn/.project b/fw-plugin/contact-plugIn/.project new file mode 100755 index 0000000..8b2297c --- /dev/null +++ b/fw-plugin/contact-plugIn/.project @@ -0,0 +1,78 @@ + + + contact-plugIn + + + + + + com.samsung.slp2.SboxBuilder + + + com.samsung.slp2.SboxBuilder.needConfigure + true + + + org.eclipse.cdt.core.errorOutputParser + org.eclipse.cdt.core.MakeErrorParser;com.samsung.limo.SboxGCCErrorParser;org.eclipse.cdt.core.GLDErrorParser;org.eclipse.cdt.core.GASErrorParser; + + + org.eclipse.cdt.make.core.append_environment + true + + + org.eclipse.cdt.make.core.build.arguments + + + + org.eclipse.cdt.make.core.build.command + make + + + org.eclipse.cdt.make.core.build.target.auto + all + + + org.eclipse.cdt.make.core.build.target.clean + clean + + + org.eclipse.cdt.make.core.build.target.inc + all + + + org.eclipse.cdt.make.core.enableAutoBuild + true + + + org.eclipse.cdt.make.core.enableCleanBuild + true + + + org.eclipse.cdt.make.core.enableFullBuild + true + + + org.eclipse.cdt.make.core.enabledIncrementalBuild + true + + + org.eclipse.cdt.make.core.environment + + + + org.eclipse.cdt.make.core.stopOnError + true + + + org.eclipse.cdt.make.core.useDefaultBuildCmd + true + + + + + + org.eclipse.cdt.core.cnature + com.samsung.slp2.cnature + + diff --git a/fw-plugin/contact-plugIn/CMakeLists.src b/fw-plugin/contact-plugIn/CMakeLists.src new file mode 100755 index 0000000..04ce4aa --- /dev/null +++ b/fw-plugin/contact-plugIn/CMakeLists.src @@ -0,0 +1 @@ +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src SRCS) diff --git a/fw-plugin/contact-plugIn/CMakeLists.sub b/fw-plugin/contact-plugIn/CMakeLists.sub new file mode 100755 index 0000000..b7259d2 --- /dev/null +++ b/fw-plugin/contact-plugIn/CMakeLists.sub @@ -0,0 +1,37 @@ +################################################################################# +# THIS FILE IS CREATED AUTOMATICALLY. DO NOT DELETE OR MODIFY THIS FILE. +################################################################################# + +INCLUDE(CMakeLists.src) + +## PROJECT NAME +PROJECT(plugin-da-contact C) + +## PACKAGE CONFIG +SET(SLP_PKGCONFIG_LIST "contacts-service accounts-svc") + +## INCLUDES +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../../framework/include) + +## DEFINITIONS +ADD_DEFINITIONS("-DAPP_DIR=\"${CMAKE_INSTALL_PREFIX}\"") + +## LIBRARY PATH +SET(SLP_LD_PATH_FLAGS "") + +## LIBRARY +SET(SLP_LD_FLAGS "") + +## DEBUG +SET(SLP_DEBUG_FLAGS "-g") + +## OPTIMIZATION +SET(SLP_OPT_FLAGS "-O0") + +## COMPILER FLAGS +SET(SLP_COMPILER_FLAGS "-lpthread") + +## LINKER FLAGS +SET(SLP_LINKER_FLAGS "-lpthread") + diff --git a/fw-plugin/contact-plugIn/CMakeLists.txt b/fw-plugin/contact-plugIn/CMakeLists.txt new file mode 100755 index 0000000..2789562 --- /dev/null +++ b/fw-plugin/contact-plugIn/CMakeLists.txt @@ -0,0 +1,33 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) + +# INCLUDE SUB CMAKELIST FILE +INCLUDE(CMakeLists.sub) + +SET(RESOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/res") + +INCLUDE(FindPkgConfig) +pkg_check_modules(pkgs_plugin_contact REQUIRED ${SLP_PKGCONFIG_LIST}) + +FOREACH(flag ${pkgs_plugin_contact_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(CMAKE_C_FLAGS "${SLP_DEBUG_FLAGS} ${SLP_OPT_FLAGS} ${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} ${SLP_COMPILER_FLAGS}") +SET(CMAKE_CXX_FLAGS "${SLP_DEBUG_FLAGS} ${SLP_OPT_FLAGS} ${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} ${SLP_COMPILER_FLAGS}") + +ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS}) + +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_plugin_contact_LDFLAGS} ${SLP_LD_PATH_FLAGS} ${SLP_LD_FLAGS} ${SLP_LINKER_FLAGS} sync-agent-framework) + +# INSTALL +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION lib) +#INSTALL(DIRECTORY ${RESOURCE_DIR}/data DESTINATION share) + +#added by KTS for install to the system +#CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY) +#INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc DESTINATION lib/pkgconfig) + + +# INCLUDE LAYOUT DIRECTORY +# ADD_SUBDIRECTORY(layout) +#ADD_SUBDIRECTORY(res/locale) diff --git a/fw-plugin/contact-plugIn/include/EXT_DataStore_Info_Contact.h b/fw-plugin/contact-plugIn/include/EXT_DataStore_Info_Contact.h new file mode 100755 index 0000000..5b00e9a --- /dev/null +++ b/fw-plugin/contact-plugIn/include/EXT_DataStore_Info_Contact.h @@ -0,0 +1,80 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Wook Choi + */ + +#ifndef EXT_DATASTORE_INFO_CONTACT_H_ +#define EXT_DATASTORE_INFO_CONTACT_H_ + +typedef enum { + CONTACT_FIELD_NAME = 1, + CONTACT_FIELD_TEL, + CONTACT_FIELD_EMAIL, + CONTACT_FIELD_URL, + CONTACT_FIELD_ADDR, + CONTACT_FIELD_NOTE, + CONTACT_FIELD_COMPANY, + CONTACT_FIELD_DEPARTMENT, + CONTACT_FIELD_TITLE, + CONTACT_FIELD_HOBBY, + CONTACT_FIELD_PHOTO, + CONTACT_FIELD_YEAR +} CONTACT_FIELD; + +typedef enum { + CONTACT_CHILD_FIELD_FAMILY = 1, + CONTACT_CHILD_FIELD_GIVEN, + CONTACT_CHILD_FIELD_MIDDLE, + CONTACT_CHILD_FIELD_PREFIX, + CONTACT_CHILD_FIELD_SUFFIX, + CONTACT_CHILD_FIELD_FORMATTED, + CONTACT_CHILD_FIELD_NICKNAME, + CONTACT_CHILD_FIELD_READING_NAME, + CONTACT_CHILD_FIELD_READING_LAST_NAME, + CONTACT_CHILD_FIELD_TEL, + CONTACT_CHILD_FIELD_EMAIL, + CONTACT_CHILD_FIELD_URL, + CONTACT_CHILD_FIELD_POBOX, + CONTACT_CHILD_FIELD_EXT_ADDR, + CONTACT_CHILD_FIELD_STREET, + CONTACT_CHILD_FIELD_LOCALITY, + CONTACT_CHILD_FIELD_REGION, + CONTACT_CHILD_FIELD_POSTAL_CODE, + CONTACT_CHILD_FIELD_COUNTRY +} CONTACT_CHILD_FIELD; + +typedef enum { + CONTACT_FEATURE_GENDER = 1 +} CONTACT_FEATURE; + +#endif /* EXT_DATASTORE_INFO_CONTACT_H_ */ diff --git a/fw-plugin/contact-plugIn/include/Extern_Info.h b/fw-plugin/contact-plugIn/include/Extern_Info.h new file mode 100755 index 0000000..137503f --- /dev/null +++ b/fw-plugin/contact-plugIn/include/Extern_Info.h @@ -0,0 +1,44 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#ifndef EXTERN_INFO_H_ +#define EXTERN_INFO_H_ + +typedef enum { + DEFAULT_CONTACT_FOLDER = 0, + USER_DEFINED_FOLDER +} CONTACT_FOLDER_TYPE; + +#endif /* EXTERN_INFO_H_ */ diff --git a/fw-plugin/contact-plugIn/include/IN_DataStore_Info_Contact.h b/fw-plugin/contact-plugIn/include/IN_DataStore_Info_Contact.h new file mode 100755 index 0000000..be108ec --- /dev/null +++ b/fw-plugin/contact-plugIn/include/IN_DataStore_Info_Contact.h @@ -0,0 +1,99 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Wook Choi + */ + +#ifndef IN_DATASTORE_INFO_CONTACT_H_ +#define IN_DATASTORE_INFO_CONTACT_H_ + +/* ITEM COUNT */ +#define MAX_ITEM_COUNT_CONTACT 65535 + +/* FIELD COUNT */ +#define MAX_FIELD_COUNT_TEL 3 +#define MAX_FIELD_COUNT_EMAIL 2 +#define MAX_FIELD_COUNT_URL 1 +#define MAX_FIELD_COUNT_ADDR 2 + +/* NAME FIELD */ +#define MAX_LEN_FAMILY 2000 +#define MAX_LEN_GIVEN 2000 +#define MAX_LEN_MIDDLE 2000 +#define MAX_LEN_PREFIX FALSE +#define MAX_LEN_SUFFIX 2000 +#define MAX_LEN_FORMATTED FALSE +#define MAX_LEN_NICKNAME 2000 +#define MAX_LEN_READING_NAME FALSE +#define MAX_LEN_READING_LAST_NAME FALSE + +/* TEL FIELD */ +#define MAX_LEN_TEL 100 + +/* EMAIL FIELD */ +#define MAX_LEN_EMAIL 100 + +/* URL FIELD */ +#define MAX_LEN_URL 100 + +/* ADDR FIELD */ +#define MAX_LEN_POBOX FALSE +#define MAX_LEN_EXT_ADDR FALSE +#define MAX_LEN_STREET 50 +#define MAX_LEN_LOCALITY 50 +#define MAX_LEN_REGION 50 +#define MAX_LEN_POSTAL_CODE 50 +#define MAX_LEN_COUNTRY 20 + +/* DEVICE CONTACT */ +#define MAX_LEN_NOTE 100 +#define MAX_LEN_COMPANY 50 +#define MAX_LEN_DEPARTMENT FALSE +#define MAX_LEN_TITLE FALSE +#define MAX_LEN_HOBBY FALSE +#define MIN_PERIOD_YEAR 1970 +#define MAX_PERIOD_YEAR 2037 +#define MAX_LEN_PHOTO 46 + +/* FEATURE */ +#define IF_SUPPORT_GENDER FALSE + +/* SIM CONTACT */ +#define TYPE_SIM +#define MAX_LEN_NAME +#define MAX_LEN_NUMBER +#define MAX_COUNT_ANR +#define MAX_LEN_ANR +#define MAX_LEN_SNE +#define IF_USING_SIM + +#endif /* IN_DATASTORE_INFO_CONTACT_H_ */ diff --git a/fw-plugin/contact-plugIn/include/Item_Change_Info.h b/fw-plugin/contact-plugIn/include/Item_Change_Info.h new file mode 100755 index 0000000..b21182e --- /dev/null +++ b/fw-plugin/contact-plugIn/include/Item_Change_Info.h @@ -0,0 +1,43 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#ifndef ITEM_CHANGE_INFO_H_ +#define ITEM_CHANGE_INFO_H_ + +int getContactVersion(int mode); + +int setContactVersion(int settingTime); + +#endif /* ITEM_CHANGE_INFO_H_ */ diff --git a/fw-plugin/contact-plugIn/src/Item_Change_Info.c b/fw-plugin/contact-plugIn/src/Item_Change_Info.c new file mode 100755 index 0000000..a301c74 --- /dev/null +++ b/fw-plugin/contact-plugIn/src/Item_Change_Info.c @@ -0,0 +1,69 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#include + +#include "Item_Change_Info.h" + +static int contactVersion = 0; + +int getContactVersion(int mode) +{ +/* if (contactTimeStamp > 0) + return contactTimeStamp; + + return ((int)time(0) - 1);*/ + + if (mode == 0) { + return contactVersion; + } + +/* if (contactVersion > 0) + return contactVersion;*/ + + contacts_svc_begin_trans(); + contactVersion = contacts_svc_end_trans(1); + + return contactVersion; +} + +int setContactVersion(int settingTime) +{ + /* Critical Sectioin Start */ + contactVersion = settingTime; + /* Critical Section End */ + + return settingTime; +} diff --git a/fw-plugin/contact-plugIn/src/PlugIn_Interface.c b/fw-plugin/contact-plugIn/src/PlugIn_Interface.c new file mode 100755 index 0000000..c59df5c --- /dev/null +++ b/fw-plugin/contact-plugIn/src/PlugIn_Interface.c @@ -0,0 +1,1328 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#include +#include +#include +#include + +#include +#include + +#include "Extern_Info.h" +#include "Item_Change_Info.h" +#include "EXT_DataStore_Info_Contact.h" +#include "IN_DataStore_Info_Contact.h" + +/* for log */ +#include "agent-framework/Utility/fw_log.h" +#include "agent-framework/Utility/fw_async_queue.h" + +#include "agent-framework/PlugIn/DataConnector_Interface.h" + +#define LOG_TAG "PLUGIN_DA_CONTACT" + +#define FW_CONTACT 0 /* plugIn-Id */ + +static int latest_contact_version; + +static fw_async_queue_t *pQueue; + +static pthread_mutex_t lockx; + +static int isNotiFromMe = 0; + +static int isStorageChanged = 0; + +static CALLBACK_ADD_ITEM callback_add_item; + +static CALLBACK_DEL_ITEM callback_del_item; + +static CALLBACK_UPDATE_ITEM callback_update_item; + +static GET_ACCOUNTIDLIST callback_get_accountidlist; + +static void __set_IsNotiFromMe(int set_flag); + +static int __get_IsNotiFromMe(); + +static void __process_Contact_Change(void *); + +static void *__rutine_Contact_Change(void *); + +static DACI_RETURN __convert_service_error_to_common_error(cts_error err); + +static bool __get_account_id(account_h account, void *user_data); + +static bool __is_Contact_ID(account_capability_type_e capability_type, account_capability_state_e capability_value, void *user_data); + +typedef struct Account_ID { + int account_id; + struct Account_ID *next; +} Account_ID_t; + +DACI_RETURN Service_Open() +{ + FW_LOGV("[da_contact_plugIn] Start in Contact\n"); + + DACI_RETURN ret = DACI_SUCCESS; + int err = contacts_svc_connect(); + if (err < CTS_SUCCESS) { + FW_LOGV("[da_contact_plugIn] in contact Fail!\n"); + ret = __convert_service_error_to_common_error(err); + } else { + FW_LOGV("[da_contact_plugIn] in contact Success!\n"); + } + + FW_LOGV("[da_contact_plugIn] End in Contact\n"); + return ret; +} + +DACI_RETURN Service_Close() +{ + FW_LOGV("[da_contact_plugIn] Start in Contact\n"); + + DACI_RETURN ret = DACI_SUCCESS; + int err = contacts_svc_disconnect(); + if (err < CTS_SUCCESS) { + FW_LOGV("[da_contact_plugIn] in contact Fail!\n"); + ret = __convert_service_error_to_common_error(err); + } else { + FW_LOGV("[da_contact_plugIn] in contact Success!\n"); + } + + FW_LOGV("[da_contact_plugIn] End in Contact\n"); + return ret; +} + +DACI_RETURN Begin_Transaction() +{ + FW_LOGV("[da_contact_plugIn] Start Begin_Transaction\n"); + + DACI_RETURN ret = DACI_SUCCESS; + int err = contacts_svc_begin_trans(); + if (err < CTS_SUCCESS) { + FW_LOGV("[da_contact_plugIn] in contact Fail!\n"); + ret = __convert_service_error_to_common_error(err); + } else { + FW_LOGV("[da_contact_plugIn] in contact Success!\n"); + __set_IsNotiFromMe(1); + } + + FW_LOGV("[da_contact_plugIn] End Begin_Transaction\n"); + return ret; +} + +DACI_RETURN End_Transaction(int is_success) +{ + FW_LOGV("[da_contact_plugIn] Start End_Transaction\n"); + + DACI_RETURN ret = DACI_SUCCESS; + int err = contacts_svc_end_trans(is_success); + if (err < CTS_SUCCESS) { + FW_LOGV("[da_contact_plugIn] in contact Fail!"); + ret = __convert_service_error_to_common_error(err); + } else { + FW_LOGV("[da_contact_plugIn] in contact Success!"); + if (isStorageChanged == 0) { + FW_LOGV("contact storaged was not Changed!!"); + __set_IsNotiFromMe(0); + } + isStorageChanged = 0; + } + + FW_LOGV("[da_contact_plugIn] End End_Transaction\n"); + return ret; +} + +DACI_RETURN Add_Item(int account_id, char *folder_id, void *data, char **item_id) +{ + FW_LOGV("[da_contact_plugIn] Start in Contact\n"); + + DACI_RETURN ret = DACI_SUCCESS; + int err = 0; + CTSstruct *item = (CTSstruct *)data; + + /* parameter check */ + if (folder_id == 0) { + FW_LOGV("[da_contact_plugIn] service id is null \n"); + + /* memory free */ + if (item != 0) + contacts_svc_struct_free(item); + + *item_id = 0; + return DACI_ERR_INVALID_CONTENT; + } + + /* add item */ + err = contacts_svc_insert_contact(atoi(folder_id), (CTSstruct *)item); + if (err < CTS_SUCCESS) { + FW_LOGV("[da_contact_plugIn] contacts_svc_insert_contact() Fail!\n"); + ret = __convert_service_error_to_common_error(err); + *item_id = 0; + } else { + FW_LOGV("[da_contact_plugIn] contacts_svc_insert_contact() Success!\n"); + *item_id = g_strdup_printf("%d", err); + isStorageChanged = 1; + } + + /* memory free */ + if (item != 0) + contacts_svc_struct_free(item); + + FW_LOGV("[da_contact_plugIn] End in Contact\n"); + return ret; +} + +DACI_RETURN Update_Item(int account_id, char *folder_id, char *item_id, void *data) +{ + FW_LOGV("[da_contact_plugIn] Start in Contact\n"); + + DACI_RETURN ret = DACI_SUCCESS; + int err = 0; + CTSstruct *item = (CTSstruct *)data; + + /* parameter check */ + if ((folder_id == 0) || (item_id == 0)) { + FW_LOGV("[da_contact_plugIn] service id is null \n"); + + /* memory free */ + if (item != 0) + contacts_svc_struct_free(item); + + return DACI_ERR_INVALID_CONTENT; + } + + /* update item */ + err = contacts_svc_update_contact((CTSstruct *)item); + if (err < CTS_SUCCESS) { + FW_LOGV("[da_contact_plugIn] contacts_svc_update_contact() Fail!\n"); + ret = __convert_service_error_to_common_error(err); + } else { + FW_LOGV("[da_contact_plugIn] contacts_svc_update_contact() Success!\n"); + isStorageChanged = 1; + } + + /* memory free */ + if (item != 0) + contacts_svc_struct_free(item); + + FW_LOGV("[da_contact_plugIn] End in Contact\n"); + return ret; + +/*DACI_RETURN ret = DACI_SUCCESS; + int err = 0; + CTSstruct *item = (CTSstruct *)data; + + err = contacts_svc_update_contact(item); + if (err < CTS_SUCCESS) { + FW_LOGV("[da_contact_plugIn] contacts_svc_update_contact() Fail!\n"); + ret = __convert_service_error_to_common_error(err); + } else { + FW_LOGV("[da_contact_plugIn] contacts_svc_update_contact() Success!\n"); + } + + // memory free + if (item != 0) + contacts_svc_struct_free(item); + + FW_LOGV("[da_contact_plugIn] End in Contact\n"); + return ret;*/ +} + +DACI_RETURN Del_Item(int account_id, char *folder_id, char *item_id) +{ + FW_LOGV("[da_contact_plugIn] Start in Contact\n"); + + DACI_RETURN ret = DACI_SUCCESS; + int err = 0; + + /* parameter check */ + if (item_id == 0) { + FW_LOGV("[da_contact_plugIn] service id is null \n"); + return DACI_ERR_INVALID_CONTENT; + } + + /* delete item */ + err = contacts_svc_delete_contact(atoi(item_id)); + if (err < CTS_SUCCESS) { + FW_LOGV("[da_contact_plugIn] contacts_svc_delete_contact(%s) Fail!\n", item_id); + ret = __convert_service_error_to_common_error(err); + } else { + FW_LOGV("[da_contact_plugIn] contacts_svc_delete_contact(%s) Success!\n", item_id); + isStorageChanged = 1; + } + + FW_LOGV("[da_contact_plugIn] End in Contact\n"); + return ret; +} + +DACI_RETURN Del_All_Items(int account_id) +{ + FW_LOGV("[da_contact_plugIn] Start in Contact\n"); + + DACI_RETURN ret = DACI_SUCCESS; + int err = 0; + int folder_id_list_cnt = 0; + int *folder_type_list = 0; + char **folder_id_list = 0; + CTSiter *iter = 0; + CTSvalue *item = 0; + int item_id = 0; + + /* get folder id list for account id */ + folder_id_list = Get_Folder_ID_List(account_id, &folder_id_list_cnt, &folder_type_list); + if (folder_id_list == 0) { + FW_LOGV("[da_contact_plugIn] folder id list cnt : %d\n", folder_id_list_cnt); + return DACI_ERR_NO_DATA; + } + + int cnt = 0; + for (; cnt < folder_id_list_cnt; cnt++) { + /* get item id list (iter) for each folder id */ + err = contacts_svc_get_list_with_int(CTS_LIST_MEMBERS_OF_ADDRESSBOOK_ID, atoi(folder_id_list[cnt]), &iter); + + if (err == CTS_SUCCESS) { + FW_LOGV("[da_contact_plugIn] contacts_svc_get_list_with_int Success!! \n"); + + while (contacts_svc_iter_next(iter) == CTS_SUCCESS) { + /* get item */ + item = contacts_svc_iter_get_info(iter); + if (item != 0) { + item_id = contacts_svc_value_get_int(item, CTS_LIST_CONTACT_ID_INT); + FW_LOGV("[da_contact_plugIn] item id : %d\n", item_id); + + /* delete item */ + err = contacts_svc_delete_contact(item_id); + if (err != CTS_SUCCESS) { + FW_LOGV("[da_contact_plugIn] contacts_svc_delete_contact(%d) Fail!\n", item_id); + ret = __convert_service_error_to_common_error(err); + goto DACI_FINISH; + } else { + FW_LOGV("[da_contact_plugIn] contacts_svc_delete_contact(%d) Success!\n", item_id); + isStorageChanged = 1; + } + + /* memory free */ + contacts_svc_value_free(item); + item = 0; + item_id = 0; + } + } /* end while */ + + /* memory free */ + if (iter != 0) { + FW_LOGV("[da_contact_plugIn] contacts_svc_iter_remove !! \n"); + contacts_svc_iter_remove(iter); + iter = 0; + } + + } else { + FW_LOGV("[da_contact_plugIn] contacts_svc_get_list_with_int Fail !! \n"); + ret = __convert_service_error_to_common_error(err); + goto DACI_FINISH; + } + } + +DACI_FINISH: + + /* memory free */ + if (item != 0) + contacts_svc_value_free(item); + + if (iter != 0) { + contacts_svc_iter_remove(iter); + FW_LOGV("[da_contact_plugIn] contacts_svc_iter_remove !! \n"); + } + if (folder_id_list != 0) { + /* + for (cnt = 0; cnt < folder_id_list_cnt; cnt++) { + if (folder_id_list[cnt] != NULL) { + FW_LOGV("folder_id_list[%d] : %s\n", cnt, folder_id_list[cnt]); + free(folder_id_list[cnt]); + FW_LOGV("[da_calendar_plugIn] folder id free !! \n"); + } + } + */ + free(folder_id_list); + FW_LOGV("[da_contact_plugIn] folder id list free !! \n"); + } + if (folder_type_list != 0) { + free(folder_type_list); + FW_LOGV("[da_contact_plugIn] folder type list free !! \n"); + } + + FW_LOGV("[da_contact_plugIn] End in Contact\n"); + return ret; +} + +DACI_RETURN Get_Item(int account_id, char *folder_id, char *item_id, void **data) +{ + FW_LOGV("[da_contact_plugIn] Start in Contact\n"); + + DACI_RETURN ret = DACI_SUCCESS; + int err = 0; + CTSstruct *item = 0; + + /* parameter check */ + if (item_id == 0) { + FW_LOGV("[da_contact_plugIn] service id is null \n"); + return DACI_ERR_INVALID_CONTENT; + } + + /* get item */ + int contact_id = atoi(item_id); + FW_LOGV("[da_contact_plugIn] contact_id : %d\n", contact_id); + err = contacts_svc_get_contact(contact_id, &item); + if (err < CTS_SUCCESS) { + FW_LOGV("[da_contact_plugIn] contacts_svc_get_contact() Fail!\n"); + ret = __convert_service_error_to_common_error(err); + *data = 0; + } else { + FW_LOGV("[da_contact_plugIn] contacts_svc_get_contact() Success!\n"); + *data = (void *)item; + } + + FW_LOGV("[da_contact_plugIn] End in Contact\n"); + return ret; +} + +DACI_RETURN Add_Folder(int account_id, char *folder_name, int folder_type, char **folder_id) +{ + FW_LOGV("[da_contact_plugIn] Start in Contact\n"); + + DACI_RETURN ret = DACI_SUCCESS; + int err = 0; + CTSvalue *folder = 0; + + /* parameter check */ + if (folder_name == 0) { + FW_LOGV("[da_contact_plugIn] service id is null \n"); + *folder_id = 0; + return DACI_ERR_INVALID_CONTENT; + } + + /* new service struct */ + folder = contacts_svc_value_new(CTS_VALUE_ADDRESSBOOK); + + /* setting folder data */ + contacts_svc_value_set_int(folder, CTS_ADDRESSBOOK_VAL_ACC_ID_INT, account_id); + /* change value in contacts service : CTS_ADDRESSBOOK_TYPE_NONE --> CTS_ADDRESSBOOK_TYPE_OTHER + * + contacts_svc_value_set_int(folder, CTS_ADDRESSBOOK_VAL_ACC_TYPE_INT, CTS_ADDRESSBOOK_TYPE_NONE); + */ + contacts_svc_value_set_int(folder, CTS_ADDRESSBOOK_VAL_ACC_TYPE_INT, CTS_ADDRESSBOOK_TYPE_OTHER); + contacts_svc_value_set_int(folder, CTS_ADDRESSBOOK_VAL_MODE_INT, CTS_ADDRESSBOOK_MODE_NONE); + contacts_svc_value_set_str(folder, CTS_ADDRESSBOOK_VAL_NAME_STR, folder_name); + + /* add folder */ + err = contacts_svc_insert_addressbook(folder); + if (err < CTS_SUCCESS) { + FW_LOGV("[da_contact_plugIn] contacts_svc_insert_addressbook() Fail!\n"); + ret = __convert_service_error_to_common_error(err); + *folder_id = 0; + } else { + FW_LOGV("[da_contact_plugIn] contacts_svc_insert_addressbook() Success!\n"); + *folder_id = g_strdup_printf("%d", err); + isStorageChanged = 1; + } + + /* memory free */ + if (folder != 0) + contacts_svc_value_free(folder); + + FW_LOGV("[da_contact_plugIn] End in Contact\n"); + return ret; +} + +DACI_RETURN Del_Folder(int account_id, char *folder_id) +{ + FW_LOGV("[da_contact_plugIn] Start in Contact\n"); + + DACI_RETURN ret = DACI_SUCCESS; + int err = 0; + + /* parameter check */ + if (folder_id == 0) { + FW_LOGV("[da_contact_plugIn] service id is null \n"); + return DACI_ERR_INVALID_CONTENT; + } + + /* delete folder */ + err = contacts_svc_delete_addressbook(atoi(folder_id)); + if (err < CTS_SUCCESS) { + FW_LOGV("[da_contact_plugIn] contacts_svc_delete_addressbook(%s) Fail!\n", folder_id); + ret = __convert_service_error_to_common_error(err); + } else { + FW_LOGV("[da_contact_plugIn] contacts_svc_delete_addressbook(%s) Success!\n", folder_id); + isStorageChanged = 1; + } + + FW_LOGV("[da_contact_plugIn] End in Contact\n"); + return ret; +} + +DACI_RETURN Get_Folder(int account_id, char *folder_id, char **out_folder_name, int *out_folder_type) +{ + FW_LOGV("[da_contact_plugIn] Start in Contact\n"); + + DACI_RETURN ret = DACI_SUCCESS; + int err = 0; + CTSvalue *folder = 0; + + /* parameter check */ + if (folder_id == 0) { + FW_LOGV("[da_contact_plugIn] service id is null \n"); + *out_folder_name = 0; + *out_folder_type = -1; + return DACI_ERR_INVALID_CONTENT; + } + + /* get item */ + int contact_folder_id = atoi(folder_id); + FW_LOGV("[da_contact_plugIn] contact_folder_id : %d\n", contact_folder_id); + err = contacts_svc_get_addressbook(contact_folder_id, &folder); + if (err < CTS_SUCCESS) { + FW_LOGV("[da_contact_plugIn] contacts_svc_get_addressbook() Fail!\n"); + ret = __convert_service_error_to_common_error(err); + *out_folder_name = 0; + *out_folder_type = -1; + } else { + FW_LOGV("[da_contact_plugIn] contacts_svc_get_addressbook() Success!\n"); + const char *folder_name = contacts_svc_value_get_str(folder, CTS_ADDRESSBOOK_VAL_NAME_STR); + FW_LOGV("out_folder_name : %s", folder_name); + *out_folder_name = strdup(folder_name); + *out_folder_type = DEFAULT_CONTACT_FOLDER; + } + + /* memory free */ + if (folder != 0) + contacts_svc_value_free(folder); + + FW_LOGV("[da_contact_plugIn] End in Contact\n"); + return ret; +} + +DACI_RETURN Execute(int account_ID, const char *execute_key, void *execute_values, void **result) +{ + FW_LOGV("[da_contact_plugIn] Start in Contact\n"); + FW_LOGV("[da_contact_plugIn] service is not supported execute. \n"); + *result = 0; + FW_LOGV("[da_contact_plugIn] End in Contact\n"); + return DACI_SUCCESS; +} + +int Get_Used_Item_Count() +{ + FW_LOGV("[da_contact_plugIn] Start\n"); + + int ret = DACI_SUCCESS; + int used_cnt = contacts_svc_count(CTS_GET_ALL_CONTACT); + if (used_cnt < 0) { + FW_LOGV("[da_contact_plugIn] contact_svc_count() Fail\n"); + ret = __convert_service_error_to_common_error(used_cnt); + } else { + FW_LOGV("[da_contact_plugIn] contact_svc_count() Success\n"); + FW_LOGV("[da_contact_plugIn] used_count = %d\n", used_cnt); + ret = used_cnt; + } + + FW_LOGV("[da_contact_plugIn] End in Contact\n"); + return ret; +} + +int Get_Used_Item_Count_For_Folder(int account_id, char *folder_id) +{ + FW_LOGV("[da_contact_plugIn] Start\n"); + + /* parameter check */ + if (folder_id == 0) { + FW_LOGV("[da_contact_plugIn] service id is null \n"); + return DACI_ERR_INVALID_CONTENT; + } + + int ret = DACI_SUCCESS; + int used_cnt = contacts_svc_count_with_int(CTS_GET_COUNT_CONTACTS_IN_ADDRESSBOOK, atoi(folder_id)); + if (used_cnt < 0) { + FW_LOGV("[da_contact_plugIn] contacts_svc_count_with_int(%s) Fail\n", folder_id); + ret = __convert_service_error_to_common_error(used_cnt); + } else { + FW_LOGV("[da_contact_plugIn] contacts_svc_count_with_int(%s) Success\n", folder_id); + FW_LOGV("[da_contact_plugIn] used_count = %d\n", used_cnt); + ret = used_cnt; + } + + FW_LOGV("[da_contact_plugIn] End in Contact\n"); + return ret; +} + +char **Get_Folder_ID_List(int account_id, int *folder_count, int **folder_type_list) +{ + char **folder_id_list = 0; + *folder_count = 0; + CTSiter *iter_addressbook = 0; + CTSvalue *addressbook = 0; + + if (account_id == -1) { + folder_id_list = (char **)calloc(1, sizeof(char *)); + *folder_type_list = (int *)calloc(1, sizeof(int)); + + folder_id_list[0] = "0"; + *folder_count = 1; + (*folder_type_list)[0] = DEFAULT_CONTACT_FOLDER; + + return folder_id_list; + } + + folder_id_list = (char **)calloc(50, sizeof(char *)); + *folder_type_list = (int *)calloc(50, sizeof(int)); + + int err = contacts_svc_get_list_with_int(CTS_LIST_ADDRESSBOOKS_OF_ACCOUNT_ID, account_id, &iter_addressbook); + err = contacts_svc_iter_next(iter_addressbook); + while (err == CTS_SUCCESS) { + addressbook = contacts_svc_iter_get_info(iter_addressbook); + if (addressbook != 0) { + int addressbook_id = 0; + addressbook_id = contacts_svc_value_get_int(addressbook, CTS_LIST_ADDRESSBOOK_ID_INT); + char *str_addressbook_id = g_strdup_printf("%d", addressbook_id); + FW_LOGV("[da_contact_plugIn] addressbook_id : %d\n", addressbook_id); + + folder_id_list[*folder_count] = str_addressbook_id; + (*folder_type_list)[*folder_count] = DEFAULT_CONTACT_FOLDER; + *folder_count = *folder_count + 1; + + if (addressbook != 0) + contacts_svc_value_free(addressbook); + + err = contacts_svc_iter_next(iter_addressbook); + } else { + FW_LOGV("[da_contact_plugIn] contacts_svc_iter_get_info() Fail!\n"); + break; + } + } + + /* memory free */ + if (iter_addressbook != 0) { + contacts_svc_iter_remove(iter_addressbook); + FW_LOGV("[da_contact_plugIn] contacts_svc_iter_remove !! \n"); + } + + return folder_id_list; +} + +int *Get_Account_ID_List(int *count) +{ + FW_LOGV("[da_contact_plugIn] start!!\n"); + + int error_code = account_connect(); + + Account_ID_t *account_info_list = (Account_ID_t *) calloc(1, sizeof(Account_ID_t)); + account_info_list->account_id = -1; + account_info_list->next = 0; + + account_foreach_account_from_db(__get_account_id, account_info_list); + + *count = 0; + Account_ID_t *cursor_ptr = account_info_list; + while (cursor_ptr != 0) { + cursor_ptr = cursor_ptr->next; + (*count)++; + } + + int *id_list = 0; + if ((*count) > 0) { + id_list = (int *)calloc(*count, sizeof(int)); + cursor_ptr = account_info_list; + int i = 0; + while (cursor_ptr != 0) { + id_list[i] = cursor_ptr->account_id; + cursor_ptr = cursor_ptr->next; + i++; + } + } + + free(account_info_list); + + error_code = account_disconnect(); + + FW_LOGV("[da_calendar_plugIn] end!!\n"); + + return id_list; +} + +Item_Node *Get_Changed_ITEM_For_Folder_Add(int account_id, const char *folder_id, int changepoint, int *changeCount) +{ + FW_LOGV("\n[da_contact_plugIn] account_id : %d\n", account_id); + FW_LOGV("[da_contact_plugIn] folder_id : %s\n", folder_id); + FW_LOGV("[da_contact_plugIn] changepoint : %d\n", changepoint); + + Item_Node *root_ptr = 0; + Item_Node *cursor_ptr = 0; + int chagned_count = 0; + + int contactVersion = changepoint; + + int addressbook_id = atoi(folder_id); + CTSiter *iter = 0; + contacts_svc_get_updated_contacts(addressbook_id, contactVersion, &iter); + + int contact_ret = contacts_svc_iter_next(iter); + while (CTS_SUCCESS == contact_ret) { + CTSvalue *row_info = 0; + + if ((row_info = contacts_svc_iter_get_info(iter)) == CTS_SUCCESS) { + FW_LOGV("[da_contact_plugIn] contacts_svc_iter_get_info() failed.\n"); + } else { + int type = contacts_svc_value_get_int(row_info, CTS_LIST_CHANGE_TYPE_INT); + + switch (type) { + case CTS_OPERATION_INSERTED: + { + int contact_id = contacts_svc_value_get_int(row_info, CTS_LIST_CHANGE_ID_INT); + char *contact_id_str = (char *)calloc(5, sizeof(char)); + sprintf(contact_id_str, "%d", contact_id); + + FW_LOGV("[da_contact_plugIn] CTS_OPERATION_INSERTED : [%s]\n", contact_id_str); + + if (root_ptr == 0) { + root_ptr = (Item_Node *) calloc(1, sizeof(Item_Node)); + root_ptr->item_id = contact_id_str; + root_ptr->next = 0; + cursor_ptr = root_ptr; + } else { + cursor_ptr->next = (Item_Node *) calloc(1, sizeof(Item_Node)); + cursor_ptr->next->item_id = contact_id_str; + cursor_ptr->next->next = 0; + cursor_ptr = cursor_ptr->next; + } + + chagned_count++; + } + break; + default: +/* FW_LOGV("[da_contact_plugIn] Another Contact Change Noti");*/ + break; + } + } + + contacts_svc_value_free(row_info); /* next changing */ + row_info = 0; + contact_ret = contacts_svc_iter_next(iter); + } + + /* memory free */ + if (iter != 0) { + contacts_svc_iter_remove(iter); + iter = 0; + FW_LOGV("[da_contact_plugIn] contacts_svc_iter_remove !! \n"); + } + *changeCount = chagned_count; + return root_ptr; +} + +Item_Node *Get_Changed_ITEM_For_Folder_Del(int account_id, const char *folder_id, int changepoint, int *changeCount) +{ + FW_LOGV("\n[da_contact_plugIn] account_id : %d\n", account_id); + FW_LOGV("[da_contact_plugIn] folder_id : %s\n", folder_id); + FW_LOGV("[da_contact_plugIn] changepoint : %d\n", changepoint); + + Item_Node *root_ptr = 0; + Item_Node *cursor_ptr = 0; + int chagned_count = 0; + + int contactVersion = changepoint; + + int addressbook_id = atoi(folder_id); + CTSiter *iter = 0; + contacts_svc_get_updated_contacts(addressbook_id, contactVersion, &iter); + + int contact_ret = contacts_svc_iter_next(iter); + while (CTS_SUCCESS == contact_ret) { + CTSvalue *row_info = 0; + + if ((row_info = contacts_svc_iter_get_info(iter)) == CTS_SUCCESS) { + FW_LOGV("[da_contact_plugIn] contacts_svc_iter_get_info() failed.\n"); + } else { + int type = contacts_svc_value_get_int(row_info, CTS_LIST_CHANGE_TYPE_INT); + + switch (type) { + case CTS_OPERATION_DELETED: + { + int contact_id = contacts_svc_value_get_int(row_info, CTS_LIST_CHANGE_ID_INT); + char *contact_id_str = (char *)calloc(5, sizeof(char)); + sprintf(contact_id_str, "%d", contact_id); + FW_LOGV("[da_contact_plugIn] CTS_OPERATION_DELETED : [%s]\n", contact_id_str); + + if (root_ptr == 0) { + root_ptr = (Item_Node *) calloc(1, sizeof(Item_Node)); + root_ptr->item_id = contact_id_str; + root_ptr->next = 0; + cursor_ptr = root_ptr; + } else { + cursor_ptr->next = (Item_Node *) calloc(1, sizeof(Item_Node)); + cursor_ptr->next->item_id = contact_id_str; + cursor_ptr->next->next = 0; + cursor_ptr = cursor_ptr->next; + } + + chagned_count++; + } + break; + default: + break; + } + } + + contacts_svc_value_free(row_info); /* next changing */ + row_info = 0; + contact_ret = contacts_svc_iter_next(iter); + } + + /* memory free */ + if (iter != 0) { + contacts_svc_iter_remove(iter); + iter = 0; + FW_LOGV("[da_contact_plugIn] contacts_svc_iter_remove !! \n"); + } + + *changeCount = chagned_count; + return root_ptr; +} + +Item_Node *Get_Changed_ITEM_For_Folder_Update(int account_id, const char *folder_id, int changepoint, int *changeCount) +{ + FW_LOGV("\n[da_contact_plugIn] account_id : %d\n", account_id); + FW_LOGV("[da_contact_plugIn] folder_id : %s\n", folder_id); + FW_LOGV("[da_contact_plugIn] changepoint : %d\n", changepoint); + + Item_Node *root_ptr = 0; + Item_Node *cursor_ptr = 0; + int chagned_count = 0; + + int contactVersion = changepoint; + + int addressbook_id = atoi(folder_id); + CTSiter *iter = 0; + contacts_svc_get_updated_contacts(addressbook_id, contactVersion, &iter); + + int contact_ret = contacts_svc_iter_next(iter); + while (CTS_SUCCESS == contact_ret) { + CTSvalue *row_info = 0; + + if ((row_info = contacts_svc_iter_get_info(iter)) == CTS_SUCCESS) { + FW_LOGV("[da_contact_plugIn] contacts_svc_iter_get_info() failed.\n"); + } else { + int type = contacts_svc_value_get_int(row_info, CTS_LIST_CHANGE_TYPE_INT); + + switch (type) { + case CTS_OPERATION_UPDATED: + { + int contact_id = contacts_svc_value_get_int(row_info, CTS_LIST_CHANGE_ID_INT); + char *contact_id_str = (char *)calloc(5, sizeof(char)); + sprintf(contact_id_str, "%d", contact_id); + FW_LOGV("[da_contact_plugIn] CTS_OPERATION_UPDATED : [%s]\n", contact_id_str); + + if (root_ptr == 0) { + root_ptr = (Item_Node *) calloc(1, sizeof(Item_Node)); + root_ptr->item_id = contact_id_str; + root_ptr->next = 0; + cursor_ptr = root_ptr; + } else { + cursor_ptr->next = (Item_Node *) calloc(1, sizeof(Item_Node)); + cursor_ptr->next->item_id = contact_id_str; + cursor_ptr->next->next = 0; + cursor_ptr = cursor_ptr->next; + } + + chagned_count++; + } + break; + default: + break; + } + } + + contacts_svc_value_free(row_info); /* next changing */ + row_info = 0; + contact_ret = contacts_svc_iter_next(iter); + } + + /* memory free */ + if (iter != 0) { + contacts_svc_iter_remove(iter); + iter = 0; + FW_LOGV("[da_contact_plugIn] contacts_svc_iter_remove !! \n"); + } + + *changeCount = chagned_count; + return root_ptr; +} + +int Get_Last_ChangePoint() +{ + contacts_svc_begin_trans(); + int contactVersion = contacts_svc_end_trans(1); + + return contactVersion; +} + +void StartListening_ChangeNoti(void *data) +{ + contacts_svc_subscribe_change(CTS_SUBSCRIBE_CONTACT_CHANGE, __process_Contact_Change, 0); + + latest_contact_version = getContactVersion(1); + FW_LOGV("Current Latest Contact Version : %d", latest_contact_version); + + pthread_t thread_process_change_id; + if (pthread_create(&thread_process_change_id, 0, __rutine_Contact_Change, 0) < 0) { + FW_LOGE("Contact Change Noti Handling Thread Create Error"); + } +} + +void SetCallBack_AddItem(CALLBACK_ADD_ITEM callback) +{ + callback_add_item = callback; +} + +void SetCallBack_DeleteItem(CALLBACK_DEL_ITEM callback) +{ + callback_del_item = callback; +} + +void SetCallBack_UpdateItem(CALLBACK_UPDATE_ITEM callback) +{ + callback_update_item = callback; +} + +void SetCallBack_GetAccountIDList(GET_ACCOUNTIDLIST callback) +{ + callback_get_accountidlist = callback; +} + +int Get_MAX_Item_Count(int folder_type) +{ + return MAX_ITEM_COUNT_CONTACT; +} + +int Get_MAX_Field_Length(int field_name, int child_field_name) +{ + switch (field_name) { + case CONTACT_FIELD_NAME: + switch (child_field_name) { + case CONTACT_CHILD_FIELD_FAMILY: + return MAX_LEN_FAMILY; + case CONTACT_CHILD_FIELD_GIVEN: + return MAX_LEN_GIVEN; + case CONTACT_CHILD_FIELD_MIDDLE: + return MAX_LEN_MIDDLE; + case CONTACT_CHILD_FIELD_PREFIX: + return MAX_LEN_PREFIX; + case CONTACT_CHILD_FIELD_SUFFIX: + return MAX_LEN_SUFFIX; + case CONTACT_CHILD_FIELD_FORMATTED: + return MAX_LEN_FORMATTED; + case CONTACT_CHILD_FIELD_NICKNAME: + return MAX_LEN_NICKNAME; + case CONTACT_CHILD_FIELD_READING_NAME: + return MAX_LEN_READING_NAME; + case CONTACT_CHILD_FIELD_READING_LAST_NAME: + return MAX_LEN_READING_LAST_NAME; + default: + return -1; + } + case CONTACT_FIELD_TEL: + switch (child_field_name) { + case CONTACT_CHILD_FIELD_TEL: + return MAX_LEN_TEL; + default: + return -1; + } + case CONTACT_FIELD_EMAIL: + switch (child_field_name) { + case CONTACT_CHILD_FIELD_EMAIL: + return MAX_LEN_EMAIL; + default: + return -1; + } + case CONTACT_FIELD_URL: + switch (child_field_name) { + case CONTACT_CHILD_FIELD_URL: + return MAX_LEN_URL; + default: + return -1; + } + case CONTACT_FIELD_ADDR: + switch (child_field_name) { + case CONTACT_CHILD_FIELD_POBOX: + return MAX_LEN_POBOX; + case CONTACT_CHILD_FIELD_EXT_ADDR: + return MAX_LEN_EXT_ADDR; + case CONTACT_CHILD_FIELD_STREET: + return MAX_LEN_STREET; + case CONTACT_CHILD_FIELD_LOCALITY: + return MAX_LEN_LOCALITY; + case CONTACT_CHILD_FIELD_REGION: + return MAX_LEN_REGION; + case CONTACT_CHILD_FIELD_POSTAL_CODE: + return MAX_LEN_POSTAL_CODE; + case CONTACT_CHILD_FIELD_COUNTRY: + return MAX_LEN_COUNTRY; + default: + return -1; + } + case CONTACT_FIELD_NOTE: + return MAX_LEN_NOTE; + case CONTACT_FIELD_COMPANY: + return MAX_LEN_COMPANY; + case CONTACT_FIELD_DEPARTMENT: + return MAX_LEN_DEPARTMENT; + case CONTACT_FIELD_TITLE: + return MAX_LEN_TITLE; + case CONTACT_FIELD_HOBBY: + return MAX_LEN_HOBBY; + case CONTACT_FIELD_PHOTO: + return MAX_LEN_PHOTO; + default: + return -1; + } +} + +int Get_MAX_Field_Count(int field_name, int child_field_name) +{ + switch (field_name) { + case CONTACT_FIELD_TEL: + return MAX_FIELD_COUNT_TEL; + case CONTACT_FIELD_EMAIL: + return MAX_FIELD_COUNT_EMAIL; + case CONTACT_FIELD_URL: + return MAX_FIELD_COUNT_URL; + case CONTACT_FIELD_ADDR: + return MAX_FIELD_COUNT_ADDR; + default: + return -1; + } +} + +int Get_Field_Value(int field_name, int child_field_name, char **str_val, int *num_val1, int *num_val2) +{ + switch (field_name) { + case CONTACT_FIELD_YEAR: + *num_val1 = MIN_PERIOD_YEAR; + *num_val2 = MAX_PERIOD_YEAR; + return 1; + default: + return -1; + } +} + +int Get_Is_Support_Feature(int feature) +{ + switch (feature) { + case CONTACT_FEATURE_GENDER: + return IF_SUPPORT_GENDER; + default: + return -1; + } +} + +/********************************** static function *******************************************/ + +static void __set_IsNotiFromMe(int set_flag) +{ + if (pthread_mutex_lock(&lockx)) { + FW_LOGV("[da_contact_plugIn] pthread_mutex_lock error\n"); + } + + isNotiFromMe = set_flag; + + if (pthread_mutex_unlock(&lockx)) { + FW_LOGV("[da_contact_plugIn] pthread_mutex_unlock error\n"); + } +} + +static int __get_IsNotiFromMe() +{ + return isNotiFromMe; +} + +static void __process_Contact_Change(void *data) +{ + FW_LOGV("[da_contact_plugIn] detected contact storage changed!!\n"); + + int from_Me = __get_IsNotiFromMe(); + + if (from_Me == 1) { + FW_LOGV("[da_contact_plugIn] This noti has been sended from Me!! so will be ignored!!\n"); + __set_IsNotiFromMe(0); + return; + } + + int *contactVersion = (int *)calloc(1, sizeof(int)); + *contactVersion = latest_contact_version; + latest_contact_version++; + + fw_async_queue_send_msg(pQueue, (void *)contactVersion); +} + +static void *__rutine_Contact_Change(void *data) +{ + FW_LOGV("[da_contact_plugIn] Start __rutine_Contact_Change (create thread)\n"); + + /* + * Create Queue + */ + pQueue = fw_async_queue_alloc(); + if (pQueue == 0) { + FW_LOGE("Failed to call fw_async_quecontacts_svc_get_updated_contactsue_alloc()"); + return 0; + } + + while (1) { + int *contact_version = fw_async_queue_receive_msg(pQueue); + int contactVersion = *contact_version; + free(contact_version); + + FW_LOGV("Detected Change ContactVersion : %d", contactVersion); + + int count; + int *accountList = callback_get_accountidlist(FW_CONTACT, &count); + if (accountList == 0) + continue; + + int i = 0; + for (; i < count; i++) { + int contact_account_id = accountList[i]; + + FW_LOGV("[da_contact_plugIn] contact_account_id : %d, count : %d\n", contact_account_id, count); + FW_LOGV("[da_contact_plugIn] Before contacts_svc_get_updated_contacts : %d\n", contactVersion); + + CTSiter *iter_addressbook = 0; + CTSvalue *addressbook = 0; + + int err = contacts_svc_get_list_with_int(CTS_LIST_ADDRESSBOOKS_OF_ACCOUNT_ID, contact_account_id, &iter_addressbook); + err = contacts_svc_iter_next(iter_addressbook); + FW_LOGV("[da_contact_plugIn] err : %d\n", err); + + if (err != CTS_SUCCESS && contact_account_id == -1) { + err = CTS_SUCCESS; + } + + while (err == CTS_SUCCESS) { + if (contact_account_id != -1) + addressbook = contacts_svc_iter_get_info(iter_addressbook); + + if (addressbook != 0 || contact_account_id == -1) { + int addressbook_id = 0; + if (contact_account_id != -1) + addressbook_id = contacts_svc_value_get_int(addressbook, CTS_LIST_ADDRESSBOOK_ID_INT); + + char *str_addressbook_id = g_strdup_printf("%d", addressbook_id); + FW_LOGV("[da_contact_plugIn] addressbook_id : %d\n", addressbook_id); + + CTSiter *iter = 0; + contacts_svc_get_updated_contacts(addressbook_id, contactVersion, &iter); + + int contact_ret = contacts_svc_iter_next(iter); + while (CTS_SUCCESS == contact_ret) { + CTSvalue *row_info = 0; + + if ((row_info = contacts_svc_iter_get_info(iter)) == CTS_SUCCESS) { + FW_LOGV("[da_contact_plugIn] contacts_svc_iter_get_info() failed.\n"); + } else { + int contact_id = contacts_svc_value_get_int(row_info, CTS_LIST_CHANGE_ID_INT); + char contact_id_str[12]; + sprintf(contact_id_str, "%d", contact_id); + int type = contacts_svc_value_get_int(row_info, CTS_LIST_CHANGE_TYPE_INT); + FW_LOGV("[da_contact_plugIn] $$$$$$$ contact_id :%d\n", contact_id); + + switch (type) { + case CTS_OPERATION_INSERTED: + { + FW_LOGV("[da_contact_plugIn] CTS_OPERATION_INSERTED\n"); + + int result = callback_add_item(accountList[i], i, contact_id_str, FW_CONTACT, str_addressbook_id, 0); + FW_LOGV("[da_contact_plugIn] ===1\n"); + if (!result) + FW_LOGV("[da_contact_plugIn] Failed to call callback_add_item() \n"); + } + break; + case CTS_OPERATION_UPDATED: + { + FW_LOGV("[da_contact_plugIn] CTS_OPERATION_UPDATED\n"); + FW_LOGV("[da_contact_plugIn] contact_id : %s\n", contact_id_str); + + int result = callback_update_item(accountList[i], i, contact_id_str, FW_CONTACT); + if (!result) + FW_LOGV("[da_contact_plugIn] Failed to call callback_update_item() \n"); + } + break; + case CTS_OPERATION_DELETED: + { + FW_LOGV("[da_contact_plugIn] CTS_OPERATION_DELETED\n"); + int result = callback_del_item(accountList[i], i, contact_id_str, FW_CONTACT); + if (!result) + FW_LOGV("[da_contact_plugIn] Failed to call callback_del_item() \n"); + } + break; + default: + FW_LOGV("[da_contact_plugIn] Another Contact Change Noti\n"); + break; + } + } + + contacts_svc_value_free(row_info); /* next changing */ + row_info = NULL; + contact_ret = contacts_svc_iter_next(iter); + } + + if (contact_account_id == -1) + err = CTS_ERR_FINISH_ITER; + else + err = contacts_svc_iter_next(iter_addressbook); + + if (addressbook != 0) + contacts_svc_value_free(addressbook); + + if (iter != 0) + contacts_svc_iter_remove(iter); + + if (str_addressbook_id != 0) { + free(str_addressbook_id); + } + + } else { + FW_LOGV("[da_contact_plugIn] account : %d, contact folder does not exist \n", contact_account_id); + break; + } + } + + if (contact_account_id != -1) { + contacts_svc_iter_remove(iter_addressbook); + } + } + + /* memory free */ + if (accountList != 0) + free(accountList); + } + + FW_LOGV("[da_contact_plugIn] End __rutine_Contact_Change (create thread)\n"); + + return 0; +} + +static DACI_RETURN __convert_service_error_to_common_error(cts_error err) +{ + DACI_RETURN ret = DACI_SUCCESS; + FW_LOGV("[da_contact_plugIn] Error Code : %d\n", err); + + switch (err) { + case CTS_ERR_DB_LOCK: /* -204 */ + ret = DACI_ERR_LOCKED; + break; + case CTS_ERR_DB_RECORD_NOT_FOUND: /* -203 */ + case CTS_ERR_NO_DATA: /* -3 */ + ret = DACI_ERR_NO_DATA; + break; + case CTS_ERR_DB_NOT_OPENED: /* -201 */ + ret = DACI_ERR_OPEN_FAILED; + break; + case CTS_ERR_NO_SPACE: /* -13 */ + case CTS_ERR_OUT_OF_MEMORY: /* -8 */ + ret = DACI_ERR_MEMORY_FULL; + break; + case CTS_ERR_ALREADY_EXIST: /* -7 */ + ret = DACI_ERR_ALREADY_EXIST; + break; + case CTS_ERR_ARG_NULL: /* -5 */ + case CTS_ERR_ARG_INVALID: /* -4 */ + ret = DACI_ERR_INVALID_CONTENT; + break; + case CTS_ERR_FINISH_ITER: /* -2 */ + case CTS_SUCCESS: /* 0 */ + case CTS_TRUE: /* 1 */ + ret = DACI_SUCCESS; + break; + /* + * CTS_ERR_DB_FAILED: -202, CTS_ERR_VCONF_FAILED: -102, + * CTS_ERR_VOBJECT_FAILED: -101, CTS_ERR_IO_ERR: -12, + * CTS_ERR_ALREADY_RUNNING: -10, CTS_ERR_EXCEEDED_LIMIT: -9, + * CTS_ERR_ENV_INVALID: -6, CTS_ERR_FAIL: -1, + */ + default: + ret = DACI_ERRORS; + break; + } + + return ret; +} + +static bool __get_account_id(account_h account, void *user_data) +{ + Account_ID_t *account_info_list = user_data; + + bool has_contact = FALSE; + + account_get_capability(account, __is_Contact_ID, &has_contact); + + if (has_contact == FALSE) { + /* DO Nothing */ + } else { + Account_ID_t *account_info = (Account_ID_t *) calloc(1, sizeof(Account_ID_t)); + account_get_account_id(account, &(account_info->account_id)); + FW_LOGV("Getted accont id : %d", account_info->account_id); + account_info->next = 0; + + Account_ID_t *cursor_ptr = account_info_list; + while (cursor_ptr->next != 0) { + cursor_ptr = cursor_ptr->next; + } + + cursor_ptr->next = account_info; + } + + return has_contact; +} + +static bool __is_Contact_ID(account_capability_type_e capability_type, account_capability_state_e capability_value, void *user_data) +{ + bool *has_contact = user_data; + if (capability_type == ACCOUNT_CAPABILITY_CONTACT) { + *has_contact = TRUE; + return FALSE; + } + return TRUE; +} diff --git a/fw-plugin/http-plugIn/.cproject b/fw-plugin/http-plugIn/.cproject new file mode 100755 index 0000000..416c6e2 --- /dev/null +++ b/fw-plugin/http-plugIn/.cproject @@ -0,0 +1,293 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/fw-plugin/http-plugIn/.project b/fw-plugin/http-plugIn/.project new file mode 100755 index 0000000..dd521ff --- /dev/null +++ b/fw-plugin/http-plugIn/.project @@ -0,0 +1,145 @@ + + + http-plugIn + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + ?name? + + + + org.eclipse.cdt.make.core.append_environment + true + + + org.eclipse.cdt.make.core.autoBuildTarget + all + + + org.eclipse.cdt.make.core.buildArguments + + + + org.eclipse.cdt.make.core.buildCommand + make + + + org.eclipse.cdt.make.core.cleanBuildTarget + clean + + + org.eclipse.cdt.make.core.contents + org.eclipse.cdt.make.core.activeConfigSettings + + + org.eclipse.cdt.make.core.enableAutoBuild + false + + + org.eclipse.cdt.make.core.enableCleanBuild + true + + + org.eclipse.cdt.make.core.enableFullBuild + true + + + org.eclipse.cdt.make.core.fullBuildTarget + all + + + org.eclipse.cdt.make.core.stopOnError + true + + + org.eclipse.cdt.make.core.useDefaultBuildCmd + true + + + + + com.samsung.slp2.SboxBuilder + + + com.samsung.slp2.SboxBuilder.needConfigure + true + + + org.eclipse.cdt.core.errorOutputParser + org.eclipse.cdt.core.MakeErrorParser;com.samsung.limo.SboxGCCErrorParser;org.eclipse.cdt.core.GLDErrorParser;org.eclipse.cdt.core.GASErrorParser; + + + org.eclipse.cdt.make.core.append_environment + true + + + org.eclipse.cdt.make.core.build.arguments + + + + org.eclipse.cdt.make.core.build.command + make + + + org.eclipse.cdt.make.core.build.target.auto + all + + + org.eclipse.cdt.make.core.build.target.clean + clean + + + org.eclipse.cdt.make.core.build.target.inc + all + + + org.eclipse.cdt.make.core.enableAutoBuild + true + + + org.eclipse.cdt.make.core.enableCleanBuild + true + + + org.eclipse.cdt.make.core.enableFullBuild + true + + + org.eclipse.cdt.make.core.enabledIncrementalBuild + true + + + org.eclipse.cdt.make.core.environment + + + + org.eclipse.cdt.make.core.stopOnError + true + + + org.eclipse.cdt.make.core.useDefaultBuildCmd + true + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + org.eclipse.cdt.core.cnature + com.samsung.slp2.cnature + org.eclipse.cdt.core.ccnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + diff --git a/fw-plugin/http-plugIn/CMakeLists.src b/fw-plugin/http-plugIn/CMakeLists.src new file mode 100755 index 0000000..04ce4aa --- /dev/null +++ b/fw-plugin/http-plugIn/CMakeLists.src @@ -0,0 +1 @@ +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src SRCS) diff --git a/fw-plugin/http-plugIn/CMakeLists.sub b/fw-plugin/http-plugIn/CMakeLists.sub new file mode 100755 index 0000000..a1c395c --- /dev/null +++ b/fw-plugin/http-plugIn/CMakeLists.sub @@ -0,0 +1,37 @@ +################################################################################# +# THIS FILE IS CREATED AUTOMATICALLY. DO NOT DELETE OR MODIFY THIS FILE. +################################################################################# + +INCLUDE(CMakeLists.src) + +## PROJECT NAME +PROJECT(plugin-na-http C) + +## PACKAGE CONFIG +SET(SLP_PKGCONFIG_LIST "libsoup-2.4 dlog") + +## INCLUDES +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../../framework/include) + +## DEFINITIONS +ADD_DEFINITIONS("-DAPP_DIR=\"${CMAKE_INSTALL_PREFIX}\"") + +## LIBRARY PATH +SET(SLP_LD_PATH_FLAGS "") + +## LIBRARY +SET(SLP_LD_FLAGS "") + +## DEBUG +SET(SLP_DEBUG_FLAGS "-g") + +## OPTIMIZATION +SET(SLP_OPT_FLAGS "-O0") + +## COMPILER FLAGS +SET(SLP_COMPILER_FLAGS "-lpthread") + +## LINKER FLAGS +SET(SLP_LINKER_FLAGS "-lpthread") + diff --git a/fw-plugin/http-plugIn/CMakeLists.txt b/fw-plugin/http-plugIn/CMakeLists.txt new file mode 100755 index 0000000..811d8f0 --- /dev/null +++ b/fw-plugin/http-plugIn/CMakeLists.txt @@ -0,0 +1,33 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) + +# INCLUDE SUB CMAKELIST FILE +INCLUDE(CMakeLists.sub) + +SET(RESOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/res") + +INCLUDE(FindPkgConfig) +pkg_check_modules(pkgs_plugin_http REQUIRED ${SLP_PKGCONFIG_LIST}) + +FOREACH(flag ${pkgs_plugin_http_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(CMAKE_C_FLAGS "${SLP_DEBUG_FLAGS} ${SLP_OPT_FLAGS} ${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} ${SLP_COMPILER_FLAGS}") +SET(CMAKE_CXX_FLAGS "${SLP_DEBUG_FLAGS} ${SLP_OPT_FLAGS} ${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} ${SLP_COMPILER_FLAGS}") + +ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS}) + +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_plugin_http_LDFLAGS} ${SLP_LD_PATH_FLAGS} ${SLP_LD_FLAGS} ${SLP_LINKER_FLAGS} sync-agent-framework) + +# INSTALL +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION lib) +#INSTALL(DIRECTORY ${RESOURCE_DIR}/data DESTINATION share) + +#added by KTS for install to the system +#CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY) +#INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc DESTINATION lib/pkgconfig) + + +# INCLUDE LAYOUT DIRECTORY +# ADD_SUBDIRECTORY(layout) +#ADD_SUBDIRECTORY(res/locale) diff --git a/fw-plugin/http-plugIn/include/NA_External.h b/fw-plugin/http-plugIn/include/NA_External.h new file mode 100755 index 0000000..820a047 --- /dev/null +++ b/fw-plugin/http-plugIn/include/NA_External.h @@ -0,0 +1,44 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Seokgil Kang + */ + +#ifndef NA_EXTERNALL_H_ +#define NA_EXTERNAL_H_ + +typedef struct { + char *key; + char *value; +} common_header_info; + +#endif /* NA_EXTERNAL_H_ */ diff --git a/fw-plugin/http-plugIn/include/http_status.h b/fw-plugin/http-plugIn/include/http_status.h new file mode 100755 index 0000000..a4902cb --- /dev/null +++ b/fw-plugin/http-plugIn/include/http_status.h @@ -0,0 +1,135 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Seokgil Kang + */ + +#ifndef HTTP_STATUS_H_ +#define HTTP_STATUS_H_ + +typedef enum { + /* + * Transport Error + */ + SOUP_CANCELED = 1, + SOUP_CANT_RESOLVE, + SOUP_CANT_RESOLVE_PROXY, + SOUP_CANT_CONNECT, + SOUP_CANT_CONNECT_PROXY, + SOUP_SSL_FAILED, + SOUP_MALFORMED, + SOUP_TRY_AGAIN, + SOUP_TOO_MANY_REDIRECTS, + + /* + * Informational + */ + CONTINUE = 100, + SWITCHING_PROTOCOLS = 101, + PROCESSING = 102, /* WebDAV */ + CHECKPOINT = 103, + + /* + * Successful + */ + OK = 200, + CREATED = 201, + ACCEPTED = 202, + NON_AUTHORITATIVE_INFORMATION = 203, + NO_CONTENT = 204, + RESET_CONTENT = 205, + PARTIAL_CONTENT = 206, + MULTI_STATUS = 207, /* WebDAV */ + IM_USED = 208, + + /* + * Redirection + */ + MULTIPLE_CHOICES = 300, + MOVED_PERMANENTLY = 301, + FOUND = 302, + SEE_OTHER = 303, + NOT_MODIFIED = 304, + USE_PROXY = 305, + /* SWITCH_PROXY = 306, *//* Unused */ + TEMPORARY_REDIRECT = 307, + RESUME_INCOMPLETE = 308, + + /* + * Client Error + */ + BAD_REQUEST = 400, + UNAUTHORIZED = 401, + PAYMENT_REQUIRED = 402, + FORBIDDEN = 403, + NOT_FOUND = 404, + METHOD_NOT_ALLOWED = 405, + NOT_ACCEPTABLE = 406, + PROXY_AUTHENTICATION_REQUIRED = 407, + REQUEST_TIMEOUT = 408, + CONFLICT = 409, + GONE = 410, + LENGTH_REQUIRED = 411, + PRECONDITION_FAILED = 412, + REQUEST_ENTITY_TOO_LARGE = 413, + REQUEST_URI_TOO_LONG = 414, + UNSUPPORTED_MEDIA_TYPE = 415, + REQUESTED_RANGE_NOT_SATISFIABLE = 416, + EXPECTATION_FAILED = 417, + IM_A_TEAPOT = 418, + UNPROCESSABLE_ENTITY = 422, /* WebDAV */ + LOCKED = 423, /* WebDAV */ + FAILED_DEPENDENCY = 424, /* WebDAV */ + UNORDERED_COLLECTION = 425, + UPGRADE_REQUIRED = 426, + NO_RESPONSE = 444, + RETRY_WITH = 449, + BLOCKED_BY_WINDOWS_PARENTAL_CONTROLS = 450, + CLIENT_CLOSED_REQUEST = 499, + + /* + * Server Error + */ + INTERNAL_SERVER_ERROR = 500, + NOT_IMPLEMENTED = 501, + BAD_GATEWAY = 502, + SERVICE_UNAVAILABLE = 503, + GATEWAY_TIMEOUT = 504, + HTTP_VERSION_NOT_SUPPORTED = 505, + VARIANT_ALSO_NEGOTIATES = 506, + INSUFFICIENT_STORAGE = 507, /* WebDAV */ + BANDWIDTH_LIMIT_EXCEEDED = 509, /* Apache bw / timited extension */ + NOT_EXTENDED = 510, + +} HTTP_STATUS; + +#endif /* HTTP_STATUS_H_ */ diff --git a/fw-plugin/http-plugIn/src/PlugIn_Interface.c b/fw-plugin/http-plugIn/src/PlugIn_Interface.c new file mode 100755 index 0000000..a7d83ec --- /dev/null +++ b/fw-plugin/http-plugIn/src/PlugIn_Interface.c @@ -0,0 +1,859 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Seokgil Kang + */ + +#include +#include +#include + +#include +#include + +#include + +#include + +#include "NA_External.h" +#include "http_status.h" + +/* for log */ +#include "agent-framework/Utility/fw_log.h" + +#include "agent-framework/PlugIn/NetworkAccess_Interface.h" + +#define SEMI_COLON_LEN 1 +#define NULL_LEN 1 + + +#if !defined(LOG_TAG) +#define LOG_TAG "PLUGIN_NA_HTTP" +#else +#undef LOG_TAG +#define LOG_TAG "PLUGIN_NA_HTTP" +#endif + + +typedef struct { + SoupSession *session; + char *id; + char *password; +} Auth_Info; + +static int add_auth_info(SoupSession *session, char *user_id, char *user_pw); +/*static int remove_auth_info(SoupSession *session);*/ /* not used */ +static int find_auth_info(SoupSession *session, Auth_Info **auth_info); +static void authenticate_cb(SoupSession *session, SoupMessage *msg, SoupAuth *auth, gboolean retrying, gpointer user_data); + +static GList *auth_info_list = NULL; + +int Open_Connection(void **session, char *proxy, int timeout) +{ + FW_LOGV("[na_http_plugIn] Start !! \n"); + +#ifdef time_check + /* function Start Time */ + clock_t start_t, end_t; + double proc_t = 0.0; + start_t = clock(); +#endif + + int res = 1; + + /* + * create session + */ + SoupSession *ss = (SoupSession *)(*session); + SoupURI *proxy_uri = NULL; + + FW_LOGV("proxy : %s", proxy); + + /* + * proxy setting + */ + if (proxy != NULL) { + proxy_uri = soup_uri_new(proxy); + ss = soup_session_sync_new_with_options(SOUP_SESSION_PROXY_URI, proxy_uri, NULL); + } else { + ss = soup_session_sync_new(); + } + + g_object_set(ss, SOUP_SESSION_TIMEOUT, timeout, NULL); + FW_LOGV("[na_http_plugIn] set timeout : %d", timeout); + + FW_LOGV("[na_http_plugIn] session : %d\n", ss); + + if (ss != NULL) { + FW_LOGV("[na_http_plugIn] success !! \n"); + } else { + FW_LOGE("[na_http_plugIn] fail !! \n"); + res = 0; + } + + *session = ss; + +#ifdef time_check + /* function End Time */ + end_t = clock(); + proc_t = ((double)(end_t - start_t)) / CLOCKS_PER_SEC; + FW_LOGV("[na_http_plugIn] execute time : %0.2f\n", proc_t); +#endif + + FW_LOGV("[na_http_plugIn] End !! \n"); + + return res; +} + +int Header_Binding(GList *header_info, void **header_binding) +{ + FW_LOGV("[na_http_plugIn] Start !! \n"); + +#ifdef time_check + /* function Start Time */ + clock_t start_t, end_t; + double proc_t = 0.0; + start_t = clock(); +#endif + + int res = 1; + GList *iter = NULL; + char *method = NULL; + char *uri = NULL; + common_header_info *iter_data = NULL; + + if (header_info == NULL) { + FW_LOGE("[na_http_plugIn] Error !! ( not exist header information )\n"); + res = 0; + return res; + } + + SoupMessage *msg = (SoupMessage *)(*header_binding); + FW_LOGV("[na_http_plugIn] msg : %d\n", msg); + + for (iter = header_info; iter != NULL; iter = g_list_next(iter)) { + if (((common_header_info *) (iter->data))->key != NULL) { + if (!strcmp(((common_header_info *) (iter->data))->key, "method")) { + method = ((common_header_info *) (iter->data))->value; + break; + } + } + } + + if (iter == 0) { + FW_LOGE("[na_http_plugIn] Iteration is NULL\n"); + res = 0; + return res; + } + + iter_data = (common_header_info *) iter->data; + header_info = g_list_remove(header_info, iter_data); + free((common_header_info *) iter_data); + FW_LOGV("[na_http_plugIn] method : %s\n", method); + + iter = NULL; + iter_data = NULL; + for (iter = header_info; iter != NULL; iter = g_list_next(iter)) { + if (((common_header_info *) (iter->data))->key != NULL) { + if (!strcmp(((common_header_info *) (iter->data))->key, "uri")) { + uri = ((common_header_info *) (iter->data))->value; + break; + } + } + } + + if (iter == 0) { + FW_LOGE("[na_http_plugIn] Iteration is NULL\n"); + res = 0; + return res; + } + + iter_data = (common_header_info *) iter->data; + header_info = g_list_remove(header_info, iter_data); + free((common_header_info *) iter_data); + FW_LOGV("[na_http_plugIn] uri : %s\n", uri); + + if (!strcmp(method, "options")) { + msg = soup_message_new(SOUP_METHOD_OPTIONS, uri); + } else if (!strcmp(method, "get")) { + msg = soup_message_new(SOUP_METHOD_GET, uri); + } else if (!strcmp(method, "head")) { + msg = soup_message_new(SOUP_METHOD_HEAD, uri); + } else if (!strcmp(method, "post")) { + msg = soup_message_new(SOUP_METHOD_POST, uri); + } else if (!strcmp(method, "put")) { + msg = soup_message_new(SOUP_METHOD_PUT, uri); + } else if (!strcmp(method, "delete")) { + msg = soup_message_new(SOUP_METHOD_DELETE, uri); + } else if (!strcmp(method, "trace")) { + msg = soup_message_new(SOUP_METHOD_TRACE, uri); + } else if (!strcmp(method, "connect")) { + msg = soup_message_new(SOUP_METHOD_CONNECT, uri); + } + + if (msg == NULL) { + FW_LOGE("[na_http_plugIn] Error !! ( wrong uri : %s )\n", uri); + res = 0; + return res; + } + + /* + * perform soup_message_headers_append() using key-value in header_info + */ + iter = NULL; + iter_data = NULL; + for (iter = header_info; iter != NULL;) { + iter_data = ((common_header_info *) (iter->data)); + if (iter_data->key != NULL) { + soup_message_headers_append(msg->request_headers, iter_data->key, iter_data->value); + FW_LOGV("[na_http_plugIn] header append\n\t key : %s, value : %s\n", iter_data->key, iter_data->value); + iter = g_list_next(iter); + header_info = g_list_remove(header_info, iter_data); + free((common_header_info *) (iter_data)); + } + } + + *header_binding = msg; + FW_LOGV("[na_http_plugIn] msg : %d\n", msg); + + if (header_info != NULL) + g_list_free(header_info); + +#ifdef time_check + /* function End Time */ + end_t = clock(); + proc_t = ((double)(end_t - start_t)) / CLOCKS_PER_SEC; + FW_LOGV("[na_http_plugIn] execute time : %0.2f\n", proc_t); +#endif + + FW_LOGV("[na_http_plugIn] End !! \n"); + + return res; +} + +int Send_Message(void *session, void **header_binding, char *send_msg, unsigned int send_msg_length, unsigned int *recv_msg_size) +{ + FW_LOGV("[na_http_plugIn] Start !! \n"); + +#ifdef time_check + /* function Start Time */ + clock_t start_t, end_t; + double proc_t = 0.0; + start_t = clock(); +#endif + + int res = 1; + + SoupSession *ss = (SoupSession *)session; + FW_LOGV("[na_http_plugIn] session : %d\n", ss); + SoupMessage *msg = (SoupMessage *)(*header_binding); + FW_LOGV("[na_http_plugIn] msg : %d\n", msg); + +/* for test + SoupMessageHeadersIter iter; + const char *name, *value; + + soup_message_headers_iter_init (&iter, msg->request_headers); + FW_LOGV(stdout, "1\n"); + while (soup_message_headers_iter_next (&iter, &name, &value)) { + FW_LOGV(stdout, "header - name : %s value : %s", name, value); + FW_LOGV(stdout, "2\n"); + } + */ + + /* + * add message body to message header + */ + FW_LOGV("[na_http_plugIn] create whole msg (header + body)\n"); + soup_message_body_append(msg->request_body, SOUP_MEMORY_TEMPORARY, send_msg, send_msg_length); + + /* + * send & receive message + */ + FW_LOGV("[na_http_plugIn] send message & receive message to server \n"); + int http_status = soup_session_send_message(ss, msg); + + switch (http_status) { /* todo : Send Message return type must be defined */ + case REQUEST_TIMEOUT: + res = -408; + break; + case OK: + res = 1; + break; + case SOUP_CANCELED: + res = -1; + break; + case SOUP_TRY_AGAIN: + res = -8; + break; + default: + res = 0; + break; + } + + FW_LOGV("[na_http_plugIn] http status : %d\n", http_status); + +#ifdef time_check + /* function End Time */ + end_t = clock(); + proc_t = ((double)(end_t - start_t)) / CLOCKS_PER_SEC; + FW_LOGV("[na_http_plugIn] execute time : %0.2f\n", proc_t); +#endif + + FW_LOGV("[na_http_plugIn] End !! \n"); + + return res; +} + +int Header_Unbinding(void *msg, unsigned int msg_size, GList **recv_header, unsigned char **recv_msg, unsigned int *recv_msg_length) +{ + FW_LOGV("[na_http_plugIn] Start !! \n"); + +#ifdef time_check + /* function Start Time */ + clock_t start_t, end_t; + double proc_t = 0.0; + start_t = clock(); +#endif + + int res = 1; + SoupMessage *whole_msg = (SoupMessage *)msg; + FW_LOGV("[na_http_plugIn] msg : %d\n", whole_msg); + + SoupMessageHeadersIter iter; + const char *name, *value; + + *recv_header = NULL; + + /* + * separate header + */ + soup_message_headers_iter_init(&iter, whole_msg->response_headers); + common_header_info *header_info = NULL; + while (soup_message_headers_iter_next(&iter, &name, &value)) { + header_info = (common_header_info *) malloc(sizeof(common_header_info)); + if (header_info == NULL) { + FW_LOGE("[na_http_plugIn] header_info malloc fail !!"); + + if (*recv_header != NULL) + g_list_free(*recv_header); + + res = 0; + return res; + } + memset(header_info, 0x00, sizeof(common_header_info)); + + header_info->key = strdup(name); + header_info->value = strdup(value); + + *recv_header = g_list_append(*recv_header, header_info); + } + + /* for test */ + GList *g_iter = NULL; + for (g_iter = *recv_header; g_iter != NULL; g_iter = g_list_next(g_iter)) { + FW_LOGV("[na_http_plugIn] key : %s, value : %s", ((common_header_info *) (g_iter->data))->key, ((common_header_info *) (g_iter->data))->value); + } + + /* + * separate body + */ + if (whole_msg->response_body != NULL) { + if ((whole_msg->response_body->length > 0) && (whole_msg->response_body->data != NULL)) { + FW_LOGV("[na_http_plugIn] recv body length : %d\n", whole_msg->response_body->length); + *recv_msg = (unsigned char *)malloc(whole_msg->response_body->length + 1); + if (*recv_msg == 0) { + res = 0; + return res; + } + memset(*recv_msg, 0x00, whole_msg->response_body->length + 1); + memcpy(*recv_msg, whole_msg->response_body->data, whole_msg->response_body->length); + + *recv_msg_length = whole_msg->response_body->length; + FW_LOGV("[na_http_plugIn] recv_body : %s\n", *recv_msg); + } + } + + FW_LOGV("[na_http_plugIn] msg : %d\n", msg); + +#ifdef time_check + /* function End Time */ + end_t = clock(); + proc_t = ((double)(end_t - start_t)) / CLOCKS_PER_SEC; + FW_LOGV("[na_http_plugIn] execute time : %0.2f\n", proc_t); +#endif + + g_object_unref(G_OBJECT(msg)); + + FW_LOGV("[na_http_plugIn] End !! \n"); + + return res; +} + +int Close_Connection(void *session) +{ + FW_LOGV("[na_http_plugIn] Start !! \n"); + +#ifdef time_check + /* function Start Time */ + clock_t start_t, end_t; + double proc_t = 0.0; + start_t = clock(); +#endif + + int res = 1; + + SoupSession *ss = (SoupSession *)session; + + FW_LOGV("[na_http_plugIn] session : %d", session); + + Auth_Info *auth_info = NULL; + res = find_auth_info(ss, &auth_info); + if (res == 0) { + FW_LOGV("[na_http_plugIn] auth_info is NULL !!"); + + /*soup_session_cleanup_connections(ss, TRUE);*/ + soup_session_abort(ss); + FW_LOGV("[na_http_plugIn] session cleanup connections !!"); + + res = 1; + } else if (res == 1) { + FW_LOGV("[na_http_plugIn] fine_auth_info() is success !!"); + + /*soup_session_cleanup_connections(ss, TRUE);*/ + soup_session_abort(ss); + + FW_LOGV("[na_http_plugIn] session cleanup connections !!"); + + if (auth_info != NULL) { + auth_info_list = g_list_remove(auth_info_list, auth_info); + + if (auth_info->id != NULL) + free(auth_info->id); + if (auth_info->password != NULL) + free(auth_info->password); + free(auth_info); + + FW_LOGV("[na_http_plugIn] remove auth_info success !!"); + } + } else { /* res == -1 */ + FW_LOGV("[na_http_plugIn] auth_info_list is NULL !!"); + + /*soup_session_cleanup_connections(ss, TRUE);*/ + soup_session_abort(ss); + FW_LOGV("[na_http_plugIn] session cleanup connections !!"); + + res = 1; + } + +#ifdef time_check + /* function End Time */ + end_t = clock(); + proc_t = ((double)(end_t - start_t)) / CLOCKS_PER_SEC; + FW_LOGV("[na_http_plugIn] execute time : %0.2f\n", proc_t); +#endif + + FW_LOGV("[na_http_plugIn] End !! \n"); + + return res; +} + +int Cancel_Message(void *session) +{ + FW_LOGV("[na_http_plugIn] Start !! \n"); + +#ifdef time_check + /* function Start Time */ + clock_t start_t, end_t; + double proc_t = 0.0; + start_t = clock(); +#endif + + int res = 1; + + SoupSession *ss = (SoupSession *)session; + + FW_LOGV("[na_http_plugIn] session : %d", session); + + Auth_Info *auth_info = NULL; + res = find_auth_info(ss, &auth_info); + if (res == 0) { + FW_LOGV("[na_http_plugIn] auth_info is NULL !!"); + + soup_session_abort(ss); + FW_LOGV("[na_http_plugIn] session abort !! \n"); + + res = 1; + } else if (res == 1) { + FW_LOGV("[na_http_plugIn] fine_auth_info() is success !!"); + + /* cancel all pending requests & disconnect connection */ + soup_session_abort(ss); + FW_LOGV("[na_http_plugIn] session abort !! \n"); + + if (auth_info != NULL) { + auth_info_list = g_list_remove(auth_info_list, auth_info); + + if (auth_info->id != NULL) + free(auth_info->id); + if (auth_info->password != NULL) + free(auth_info->password); + free(auth_info); + + FW_LOGV("[na_http_plugIn] remove auth_info success !!"); + } + } else { /* res == -1 */ + FW_LOGV("[na_http_plugIn] auth_info_list is NULL !!"); + + /* cancel all pending requests & disconnect connection */ + soup_session_abort(ss); + FW_LOGV("[na_http_plugIn] session abort !! \n"); + + res = 1; + } + +#ifdef time_check + /* function End Time */ + end_t = clock(); + proc_t = ((double)(end_t - start_t)) / CLOCKS_PER_SEC; + FW_LOGV("[na_http_plugIn] execute time : %0.2f\n", proc_t); +#endif + + FW_LOGV("[na_http_plugIn] End !! \n"); + + return res; +} + +int Get_Header_Info(GList *header_info, char *key, char **value) +{ + FW_LOGV("[na_http_plugIn] Start !! \n"); + + int res = 1; + + GList *iter = NULL; + common_header_info *iter_data; + *value = NULL; + int value_len = 0; + + if (header_info == NULL) { + FW_LOGE("[na_http_plugIn] Error !! ( not exist header information )\n"); + res = 0; + return res; + } + + for (iter = header_info; iter != NULL; iter = g_list_next(iter)) { + iter_data = NULL; + iter_data = (common_header_info *) (iter->data); + if (iter_data->key != NULL) { + if (!strcmp(iter_data->key, key)) { + if (iter_data->value != NULL) { + /* if (*value == NULL) { *//* first 'key - value' pair */ + if (value_len == 0) { /* first 'key - value' pair */ + *value = (char *)malloc(strlen(iter_data->value) + NULL_LEN + SEMI_COLON_LEN); + if (*value == NULL) { + FW_LOGE("[na_http_plugIn] malloc error !!"); + res = 0; + return res; + } + + memset(*value, 0x00, strlen(iter_data->value) + NULL_LEN + SEMI_COLON_LEN); + memcpy(*value, iter_data->value, strlen(iter_data->value)); + FW_LOGV("[na_http_plugIn] key : %s, value : %s ( %d )", iter_data->key, *value, strlen(*value)); + + value_len += strlen(*value); + } else { /* after first 'key - value' pair */ + (*value)[value_len] = ';'; + value_len++; + value_len += (strlen(iter_data->value) + NULL_LEN + SEMI_COLON_LEN); + *value = (char *)realloc(*value, value_len); + if (*value == NULL) { + FW_LOGE("[na_http_plugIn] realloc error !!"); + res = 0; + return res; + } + + strcat(*value, iter_data->value); + FW_LOGV("[na_http_plugIn] key : %s, value : %s ( %d )", iter_data->key, *value, strlen(*value)); + } + } else { + FW_LOGE("[na_http_plugIn] value is NULL !! \n"); + res = 0; + return res; + } + } + } else { + FW_LOGE("[na_http_plugIn] key is NULL !! \n"); + res = 0; + return res; + } + } + + FW_LOGV("[na_http_plugIn] End !! \n"); + + return res; +} + +int Set_Data_Download_Info(void *http_info, char *current_download_range) +{ + FW_LOGV("[na_http_plugIn] start"); + int ret = 1; + + GList *iter = 0; + for (iter = (GList *)http_info; iter != NULL; iter = g_list_next(iter)) { + + if (((common_header_info *) (iter->data))->key != 0 && !strcmp(((common_header_info *) (iter->data))->key, "Range")) { + + char *value = ((common_header_info *) (iter->data))->value; + if (value != 0) { + free(value); + + ((common_header_info *) (iter->data))->value = g_strdup_printf("bytes=%s", current_download_range); + FW_LOGV("[After] key : %s, value : %s\n", ((common_header_info *) (iter->data))->key, ((common_header_info *) (iter->data))->value); + break; + } else { + FW_LOGE("[na_http_plugIn] value is NULL !! \n"); + ret = 0; + return ret; + } + } + } + + FW_LOGV("[na_http_plugIn] end"); + return ret; +} + +int Get_Data_Download_Info(void *http_info, int *total_doanload_size, char **current_download_range, char **download_file_name) +{ + FW_LOGV("[na_http_plugIn] start"); + int ret = 1; + + /* pasing file name */ + char *temp_file_name = 0; + Get_Header_Info((GList *)http_info, "Content-Disposition", &temp_file_name); + FW_LOGV("temp_file_name = %s\n", temp_file_name); + + char *ptr1 = strstr(temp_file_name, "attachment;"); + if (ptr1 != 0) { + ptr1 = strstr(ptr1, "fileName="); + if (ptr1 != 0) { + + char *temp = strdup(ptr1); + + char *del = "\""; + char *temp_ptr = strtok(temp, del); + temp_ptr = strtok(NULL, del); + + *download_file_name = strdup(temp_ptr); + FW_LOGV("*download_file_name = %s\n", *download_file_name); + + if (temp != 0) + free(temp); + } + } + + /* parsing data range info */ + char *temp_range_value = 0; + Get_Header_Info((GList *)http_info, "Content-Range", &temp_range_value); + char *temp = strdup(temp_range_value + strlen("bytes ")); + FW_LOGV("temp_range = %s\n", temp); + + char *del2 = "/"; + char *ptr2 = strtok(temp, del2); + if (ptr2 != 0) { + FW_LOGV("[na_http_plugIn] range = %s\n", ptr2); + *current_download_range = strdup(ptr2); + + ptr2 = strtok(NULL, del2); + FW_LOGV("[na_http_plugIn] total = %s\n", ptr2); + *total_doanload_size = atoi(ptr2); + } + + FW_LOGV("[na_http_plugIn] end"); + return ret; +} + +int Add_Authentication_Info(void *session, char *id, char *password) +{ + FW_LOGV("[na_http_plugIn] Start !! \n"); + + int res = 1; + + SoupSession *ss = (SoupSession *)session; + + res = add_auth_info(ss, id, password); + if (res != 1) { + FW_LOGE("[na_http_plugIn] add_auth_info() is fail !!"); + return res; + } else { + FW_LOGV("[na_http_plugIn] add_auth_info() is success !!"); + /* register user authentication callback (for EAS) */ + g_signal_connect(ss, "authenticate", G_CALLBACK(authenticate_cb), NULL); + } + + FW_LOGV("[na_http_plugIn] End !! \n"); + + return res; +} + +static int add_auth_info(SoupSession *session, char *user_id, char *user_pw) +{ + FW_LOGV("[na_http_plugIn] Start !!"); + + int res = 1; + + Auth_Info *auth_info; + + /* memory alloc - auth_info */ + auth_info = (Auth_Info *)calloc(1, sizeof(Auth_Info)); + if (auth_info == NULL) { + FW_LOGE("[na_http_plugIn] auth_info calloc fail !!"); + return 0; + } + FW_LOGV("[na_http_plugIn] auth_info calloc success !!"); + + auth_info->session = (void *)calloc(1, sizeof(auth_info->session)); + auth_info->session = session; + FW_LOGV("[na_http_plugIn] auth_info : sessoin ( %d )", auth_info->session); + auth_info->id = strdup(user_id); + FW_LOGV("[na_http_plugIn] auth_info : id ( %s )", auth_info->id); + auth_info->password = strdup(user_pw); + FW_LOGV("[na_http_plugIn] auth_info : password ( %s )", auth_info->password); + + /* append auth_info to auth_info_list */ + auth_info_list = g_list_append(auth_info_list, auth_info); + FW_LOGV("[na_http_plugIn] append auth_info"); + + FW_LOGV("[na_http_plugIn] End !!"); + + return res; +} + +/*static int remove_auth_info(SoupSession *session) +{ + FW_LOGV("[na_http_plugIn] Start !!"); + + int res = 1; + Auth_Info *auth_info = NULL; + + res = find_auth_info(session, &auth_info); + if (res == 0) { + FW_LOGE("[na_http_plugIn] find_auth_info() is fail !!"); + res = 0; + return res; + } else if (res == 1) { + FW_LOGV("[na_http_plugIn] fine_auth_info() is success !!"); + + if (auth_info->id != NULL) + free(auth_info->id); + + if (auth_info->password != NULL) + free(auth_info->password); + + if (auth_info != NULL) + free(auth_info); + } + + FW_LOGV("[na_http_plugIn] End !!"); + + return res; +}*/ + +static int find_auth_info(SoupSession *session, Auth_Info **auth_info) +{ + FW_LOGV("[na_http_plugIn] Start !!"); + + GList *iter = NULL; + Auth_Info *iter_data; + + int res = 1; + + if (auth_info_list != NULL) { + /* find auth_info for session */ + for (iter = auth_info_list; iter != NULL; iter = g_list_next(iter)) { + iter_data = NULL; + if (((Auth_Info *)(iter->data))->session != NULL) { + if (((Auth_Info *)(iter->data))->session == session) { + iter_data = (Auth_Info *)(iter->data); + FW_LOGV("[na_http_plugIn] find session : %d", session); + break; + } + } + } + } else { + FW_LOGE("[na_http_plugIn] auth_info_list is NULL !!"); + res = -1; + return res; + } + + if (iter_data != NULL) { + *auth_info = (Auth_Info *)iter_data; + } else { + FW_LOGE("[na_http_plugIn] iter_data is NULL !!"); + res = 0; + return res; + } + + FW_LOGV("[na_http_plugIn] End !!"); + + return res; +} + +static void authenticate_cb(SoupSession *session, SoupMessage *msg, SoupAuth *auth, gboolean retrying, gpointer user_data) +{ + FW_LOGV("[na_http_plugIn] Start !!"); + + int err = 1; + Auth_Info *auth_info = NULL; + + if (!retrying) { + err = find_auth_info(session, &auth_info); + if (err == 0) { + FW_LOGE("[na_http_plugIn] find_auth_info() is fail !!"); + /* todo : error handling */ + } else if (err == 1) { + FW_LOGV("[na_http_plugIn] find_auth_info() is success !!"); + /* first authentication */ + if (msg->status_code == SOUP_STATUS_UNAUTHORIZED) { + if (auth_info->id && auth_info->password) + soup_auth_authenticate(auth, auth_info->id, auth_info->password); + } + /* not implement - proxy authentication */ + } else { /* err == -1 */ + FW_LOGV("[na_http_plugIn] auth_info_list is NULL !!"); + } + } else { + /*retry */ + FW_LOGV("[na_http_plugIn] authentication Retry !!"); + } + + FW_LOGV("[na_http_plugIn] End !!"); +} diff --git a/fw-plugin/memo-plugIn/.cproject b/fw-plugin/memo-plugIn/.cproject new file mode 100755 index 0000000..3c36d31 --- /dev/null +++ b/fw-plugin/memo-plugIn/.cproject @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/fw-plugin/memo-plugIn/.project b/fw-plugin/memo-plugIn/.project new file mode 100755 index 0000000..9e88597 --- /dev/null +++ b/fw-plugin/memo-plugIn/.project @@ -0,0 +1,78 @@ + + + memo-plugIn + + + + + + com.samsung.slp2.SboxBuilder + + + com.samsung.slp2.SboxBuilder.needConfigure + true + + + org.eclipse.cdt.core.errorOutputParser + org.eclipse.cdt.core.MakeErrorParser;com.samsung.limo.SboxGCCErrorParser;org.eclipse.cdt.core.GLDErrorParser;org.eclipse.cdt.core.GASErrorParser; + + + org.eclipse.cdt.make.core.append_environment + true + + + org.eclipse.cdt.make.core.build.arguments + + + + org.eclipse.cdt.make.core.build.command + make + + + org.eclipse.cdt.make.core.build.target.auto + all + + + org.eclipse.cdt.make.core.build.target.clean + clean + + + org.eclipse.cdt.make.core.build.target.inc + all + + + org.eclipse.cdt.make.core.enableAutoBuild + true + + + org.eclipse.cdt.make.core.enableCleanBuild + true + + + org.eclipse.cdt.make.core.enableFullBuild + true + + + org.eclipse.cdt.make.core.enabledIncrementalBuild + true + + + org.eclipse.cdt.make.core.environment + + + + org.eclipse.cdt.make.core.stopOnError + true + + + org.eclipse.cdt.make.core.useDefaultBuildCmd + true + + + + + + org.eclipse.cdt.core.cnature + com.samsung.slp2.cnature + + diff --git a/fw-plugin/memo-plugIn/CMakeLists.src b/fw-plugin/memo-plugIn/CMakeLists.src new file mode 100755 index 0000000..04ce4aa --- /dev/null +++ b/fw-plugin/memo-plugIn/CMakeLists.src @@ -0,0 +1 @@ +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src SRCS) diff --git a/fw-plugin/memo-plugIn/CMakeLists.sub b/fw-plugin/memo-plugIn/CMakeLists.sub new file mode 100755 index 0000000..1a4fa07 --- /dev/null +++ b/fw-plugin/memo-plugIn/CMakeLists.sub @@ -0,0 +1,37 @@ +################################################################################# +# THIS FILE IS CREATED AUTOMATICALLY. DO NOT DELETE OR MODIFY THIS FILE. +################################################################################# + +INCLUDE(CMakeLists.src) + +## PROJECT NAME +PROJECT(plugin-da-memo C) + +## PACKAGE CONFIG +SET(SLP_PKGCONFIG_LIST "memo glib-2.0 accounts-svc") + +## INCLUDES +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../../framework/include) + +## DEFINITIONS +ADD_DEFINITIONS("-DAPP_DIR=\"${CMAKE_INSTALL_PREFIX}\"") + +## LIBRARY PATH +SET(SLP_LD_PATH_FLAGS "") + +## LIBRARY +SET(SLP_LD_FLAGS "") + +## DEBUG +SET(SLP_DEBUG_FLAGS "-g") + +## OPTIMIZATION +SET(SLP_OPT_FLAGS "-O0") + +## COMPILER FLAGS +SET(SLP_COMPILER_FLAGS "-lpthread") + +## LINKER FLAGS +SET(SLP_LINKER_FLAGS "-lpthread") + diff --git a/fw-plugin/memo-plugIn/CMakeLists.txt b/fw-plugin/memo-plugIn/CMakeLists.txt new file mode 100755 index 0000000..286ee30 --- /dev/null +++ b/fw-plugin/memo-plugIn/CMakeLists.txt @@ -0,0 +1,33 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) + +# INCLUDE SUB CMAKELIST FILE +INCLUDE(CMakeLists.sub) + +SET(RESOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/res") + +INCLUDE(FindPkgConfig) +pkg_check_modules(pkgs_plugin_memo REQUIRED ${SLP_PKGCONFIG_LIST}) + +FOREACH(flag ${pkgs_plugin_memo_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(CMAKE_C_FLAGS "${SLP_DEBUG_FLAGS} ${SLP_OPT_FLAGS} ${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} ${SLP_COMPILER_FLAGS}") +SET(CMAKE_CXX_FLAGS "${SLP_DEBUG_FLAGS} ${SLP_OPT_FLAGS} ${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} ${SLP_COMPILER_FLAGS}") + +ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS}) + +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_plugin_memo_LDFLAGS} ${SLP_LD_PATH_FLAGS} ${SLP_LD_FLAGS} ${SLP_LINKER_FLAGS} sync-agent-framework) + +# INSTALL +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION lib) +#INSTALL(DIRECTORY ${RESOURCE_DIR}/data DESTINATION share) + +#added by KTS for install to the system +#CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY) +#INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc DESTINATION lib/pkgconfig) + + +# INCLUDE LAYOUT DIRECTORY +# ADD_SUBDIRECTORY(layout) +#ADD_SUBDIRECTORY(res/locale) diff --git a/fw-plugin/memo-plugIn/include/Extern_Info.h b/fw-plugin/memo-plugIn/include/Extern_Info.h new file mode 100755 index 0000000..6a462ef --- /dev/null +++ b/fw-plugin/memo-plugIn/include/Extern_Info.h @@ -0,0 +1,44 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#ifndef EXTERN_INFO_H_ +#define EXTERN_INFO_H_ + +typedef enum { + DEFAULT_MEMO_FOLDER = 0, + USER_DEFINED_FOLDER +} MEMO_FOLDER_TYPE; + +#endif /* EXTERN_INFO_H_ */ diff --git a/fw-plugin/memo-plugIn/include/Item_Change_Info.h b/fw-plugin/memo-plugIn/include/Item_Change_Info.h new file mode 100755 index 0000000..c078584 --- /dev/null +++ b/fw-plugin/memo-plugIn/include/Item_Change_Info.h @@ -0,0 +1,43 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#ifndef ITEM_CHANGE_INFO_H_ +#define ITEM_CHANGE_INFO_H_ + +int getMemoTimeStamp(); + +int setMemoTimeStamp(int settingTime); + +#endif /* ITEM_CHANGE_INFO_H_ */ diff --git a/fw-plugin/memo-plugIn/src/Item_Change_Info.c b/fw-plugin/memo-plugIn/src/Item_Change_Info.c new file mode 100755 index 0000000..f4970e6 --- /dev/null +++ b/fw-plugin/memo-plugIn/src/Item_Change_Info.c @@ -0,0 +1,54 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#include + +#include "Item_Change_Info.h" + +static int memoTimeStamp = 0; + +int getMemoTimeStamp() +{ + return ((int)time(0) - 3); +} + +int setMemoTimeStamp(int settingTime) +{ + /* Critical Sectioin Start */ + memoTimeStamp = settingTime; + /* Critical Section End */ + + return settingTime; +} diff --git a/fw-plugin/memo-plugIn/src/PlugIn_Interface.c b/fw-plugin/memo-plugIn/src/PlugIn_Interface.c new file mode 100755 index 0000000..38cb31f --- /dev/null +++ b/fw-plugin/memo-plugIn/src/PlugIn_Interface.c @@ -0,0 +1,744 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#include +#include +#include +#include +#include + +#include + +#include "Extern_Info.h" +#include "Item_Change_Info.h" + +/* for log */ +#include "agent-framework/Utility/fw_log.h" + +#include "agent-framework/PlugIn/DataConnector_Interface.h" + +#define LOG_TAG "PLUGIN_DA_MEMO" + +#define FW_MEMO 2 /* plugIn-Id */ + +static pthread_mutex_t lockx; + +static int isNotiFromMe = 0; + +static int isStorageChanged = 0; + +static CALLBACK_ADD_ITEM callback_add_item; + +static CALLBACK_DEL_ITEM callback_del_item; + +static CALLBACK_UPDATE_ITEM callback_update_item; + +static GET_ACCOUNTIDLIST callback_get_accountidlist; + +static void __set_IsNotiFromMe(int set_flag); + +static int __get_IsNotiFromMe(); + +static void __process_Memo_Change(void *); + +static void *__rutine_Memo_Change(void *); + +static DACI_RETURN __convert_service_error_to_common_error(int err); + +DACI_RETURN Service_Open() +{ + FW_LOGV("[da_memo_plugIn] Start in Memo\n"); + + DACI_RETURN ret = DACI_SUCCESS; + int err = memo_init(0); + if (err < 0) { + FW_LOGV("[da_memo_plugIn] in memo Fail!\n"); + ret = DACI_ERR_OPEN_FAILED; + } else { + FW_LOGV("[da_memo_plugIn] in memo Success!"); + } + + FW_LOGV("[da_memo_plugIn] End in Memo\n"); + return ret; +} + +DACI_RETURN Service_Close() +{ + FW_LOGV("[da_memo_plugIn] Start in Memo\n"); + + DACI_RETURN ret = DACI_SUCCESS; + + /* memo service api does not return value */ + memo_fini(); + + FW_LOGV("[da_memo_plugIn] End in Memo\n"); + return ret; +} + +DACI_RETURN Begin_Transaction() +{ + FW_LOGV("[da_memo_plugIn] Start in Memo\n"); + + DACI_RETURN ret = DACI_SUCCESS; + + /* memo service api does not return value */ + /* real transaction is not for event notification */ + memo_begin_trans(); + __set_IsNotiFromMe(1); + + FW_LOGV("[da_memo_plugIn] End in Memo\n"); + return ret; +} + +DACI_RETURN End_Transaction(int is_success) +{ + FW_LOGV("[da_memo_plugIn] Start in Memo\n"); + + DACI_RETURN ret = DACI_SUCCESS; + + /* memo service api does not return value */ + /* real transaction is not for event notification */ + /* memo service is not supported rollback operation */ + memo_end_trans(); +/* __set_IsNotiFromMe(1);*/ + + if (isStorageChanged == 0) { + FW_LOGV("memo storaged was not Changed!!"); + __set_IsNotiFromMe(0); + } + isStorageChanged = 0; + + FW_LOGV("[da_memo_plugIn] End in Memo\n"); + return ret; +} + +DACI_RETURN Add_Item(int account_id, char *folder_id, void *data, char **item_id) +{ + FW_LOGV("[da_memo_plugIn] Start in Memo\n"); + + DACI_RETURN ret = DACI_SUCCESS; + int err = 0; + struct memo_data *item = (struct memo_data *)data; + + /* parameter check */ + if (item == 0) { + *item_id = 0; + FW_LOGV("[da_memo_plugIn] service data is null \n"); + return DACI_ERR_INVALID_CONTENT; + } + + /* configuration item */ + item->id = -1; + item->modi_time = time((time_t *)0); + item->font_size = 32; + item->font_color = 0xff000000; + + /* add item */ + err = memo_add_data(item); + if (err < 0) { + FW_LOGV("[da_memo_plugIn] memo_add_data() Fail!\n"); + ret = __convert_service_error_to_common_error(err); + *item_id = 0; + } else { + FW_LOGV("[da_memo_plugIn] memo_add_data() Success!\n"); + *item_id = g_strdup_printf("%d", err); + isStorageChanged = 1; + } + + /* memory free */ + if (item != 0) + memo_free_data(item); + + FW_LOGV("[da_memo_plugIn] End in Memo\n"); + return ret; +} + +DACI_RETURN Update_Item(int account_id, char *folder_id, char *item_id, void *data) +{ + FW_LOGV("[da_memo_plugIn] Start in Memo\n"); + + DACI_RETURN ret = DACI_SUCCESS; + int err = 0; + struct memo_data *item = (struct memo_data *)data; + + /* parameter check */ + if (item == 0) { + FW_LOGV("[da_memo_plugIn] service id is null \n"); + + /* memory free */ + if (item != 0) + memo_free_data(item); + + return DACI_ERR_INVALID_CONTENT; + } + + /* update item */ + err = memo_mod_data(item); + if (err < 0) { + FW_LOGV("[da_memo_plugIn] memo_mod_data() Fail!\n"); + ret = __convert_service_error_to_common_error(err); + } else { + FW_LOGV("[da_memo_plugIn] memo_mod_data() Success!\n"); + isStorageChanged = 1; + } + + /* memory free */ + if (item != 0) + memo_free_data(item); + + FW_LOGV("[da_memo_plugIn] End in Memo\n"); + return ret; +} + +DACI_RETURN Del_Item(int account_id, char *folder_id, char *item_id) +{ + FW_LOGV("[da_memo_plugIn] Start in Memo\n"); + + DACI_RETURN ret = DACI_SUCCESS; + int err = 0; + + /* parameter check */ + if (item_id == 0) { + FW_LOGV("[da_memo_plugIn] service id is null \n"); + return DACI_ERR_INVALID_CONTENT; + } + + /* delete item */ + err = memo_del_data(atoi(item_id)); + if (err < 0) { + FW_LOGV("[da_memo_plugIn] memo_del_data(%s) Fail!\n", item_id); + ret = __convert_service_error_to_common_error(err); + } else { + FW_LOGV("[da_memo_plugIn] memo_del_data(%s) Success!\n", item_id); + isStorageChanged = 1; + } + + FW_LOGV("[da_memo_plugIn] End in Memo\n"); + return ret; +} + +DACI_RETURN Del_All_Items(int account_id) +{ + FW_LOGV("[da_memo_plugIn] Start in Memo\n"); + + DACI_RETURN ret = DACI_SUCCESS; + int err = 1; + struct memo_data_list *item_list = NULL; + struct memo_data_list *first_item_list = NULL; + + /* get all data in memo db */ + item_list = memo_get_all_data_list(); + first_item_list = item_list; + + while (item_list != NULL) { + err = memo_del_data(item_list->md.id); + if (err < 0) { + FW_LOGV("[da_memo_plugIn] memo_del_data(%d) Fail!\n", item_list->md.id); + ret = __convert_service_error_to_common_error(err); + break; + } else { + FW_LOGV("[da_memo_plugIn] memo_del_data(%d) Success!\n", item_list->md.id); + isStorageChanged = 1; + } + + /* memory free */ + if (item_list->md.comment != 0) { + free(item_list->md.comment); + item_list->md.comment = 0; + } + + if (item_list->md.doodle_path != 0) { + free(item_list->md.doodle_path); + item_list->md.doodle_path = 0; + } + + item_list = item_list->next; + } + + /* memory free */ + if (first_item_list != NULL) { + memo_free_data_list(first_item_list); + FW_LOGV("[da_memo_plugIn] memo_free_data_list \n"); + } + + FW_LOGV("[da_memo_plugIn] End in Memo\n"); + return ret; +} + +DACI_RETURN Get_Item(int account_id, char *folder_id, char *item_id, void **data) +{ + FW_LOGV("[da_memo_plugIn] Start in Memo\n"); + + DACI_RETURN ret = DACI_SUCCESS; + struct memo_data *item = 0; + + /* parameter check */ + if (item_id == 0) { + FW_LOGV("[da_memo_plugIn] service id is null \n"); + return DACI_ERR_INVALID_CONTENT; + } + + if (item_id == 0) { + FW_LOGV("[da_memo_plugIn] service id is null \n"); + return DACI_ERR_INVALID_CONTENT; + } + + /* get item */ + item = memo_get_data(atoi(item_id)); + if (item == 0) { + FW_LOGV("[da_memo_plugIn] memo_get_data() Fail!\n"); + ret = DACI_ERRORS; + *data = 0; + } else { + FW_LOGV("[da_memo_plugIn] memo_get_data() Success!"); + *data = (void *)item; + } + + FW_LOGV("[da_memo_plugIn] End in Memo\n"); + return ret; +} + +DACI_RETURN Add_Folder(int account_id, char *folder_name, int folder_type, char **folder_id) +{ + FW_LOGV("[da_memo_plugIn] Start in Memo\n"); + FW_LOGV("[da_memo_plugIn] memo service is not supported folder\n"); + FW_LOGV("[da_memo_plugIn] End in Memo\n"); + return DACI_SUCCESS; +} + +DACI_RETURN Del_Folder(int account_id, char *folder_id) +{ + FW_LOGV("[da_memo_plugIn] Start in Memo\n"); + FW_LOGV("[da_memo_plugIn] memo service is not supported folder\n"); + FW_LOGV("[da_memo_plugIn] End in Memo\n"); + return DACI_SUCCESS; +} + +DACI_RETURN Get_Folder(int account_id, char *folder_id, char **out_folder_name, int *out_folder_type) +{ + FW_LOGV("[da_memo_plugIn] Start in Memo\n"); + FW_LOGV("[da_memo_plugIn] memo service is not supported folder\n"); + FW_LOGV("[da_memo_plugIn] End in Memo\n"); + return DACI_SUCCESS; +} + +DACI_RETURN Execute(int account_ID, const char *execute_key, void *execute_values, void **result) +{ + FW_LOGV("[da_memo_plugIn] Start in Memo\n"); + FW_LOGV("[da_memo_plugIn] memo service is not supported execute. \n"); + *result = 0; + FW_LOGV("[da_memo_plugIn] End in Memo\n"); + return DACI_SUCCESS; +} + +int Get_Used_Item_Count() +{ + FW_LOGV("[da_memo_plugIn] Start in Memo\n"); + + int ret = DACI_SUCCESS; + int used_cnt = 0; + int err = memo_get_count(&used_cnt); + if (err == -1) { + FW_LOGV("[da_memo_plugIn] memo_get_count() Fail\n"); + ret = __convert_service_error_to_common_error(err); + } else { + FW_LOGV("[da_memo_plugIn] memo_get_count() Success\n"); + FW_LOGV("[da_memo_plugIn] used_count = %d\n", used_cnt); + ret = used_cnt; + } + + FW_LOGV("[da_memo_plugIn] End in Memo\n"); + return ret; +} + +int Get_Used_Item_Count_For_Folder(int account_id, char *folder_id) +{ + FW_LOGV("[da_memo_plugIn] Memo plugIn is not supported this function\n"); + FW_LOGV("[da_memo_plugIn] Return all memo count \n"); + + return Get_Used_Item_Count(); +} + +char **Get_Folder_ID_List(int account_id, int *folder_count, int **folder_type_list) +{ + char **folder_id_list = (char **)calloc(1, sizeof(char *)); + *folder_type_list = (int *)calloc(1, sizeof(int)); + + folder_id_list[0] = "0"; + *folder_count = 1; + (*folder_type_list)[0] = DEFAULT_MEMO_FOLDER; + + return folder_id_list; +} + +int *Get_Account_ID_List(int *count) +{ + FW_LOGV("[da_memo_plugIn] start!!\n"); + + int *account_id_list = (int *)calloc(1, sizeof(int)); + + *count = 1; + account_id_list[0] = -1; + + return account_id_list; +} + +Item_Node *Get_Changed_ITEM_For_Folder_Add(int account_id, const char *folder_id, int changepoint, int *changeCount) +{ + FW_LOGV("\n[da_memo_plugIn] account_id : %d\n", account_id); + FW_LOGV("[da_memo_plugIn] folder_id : %s\n", folder_id); + FW_LOGV("[da_memo_plugIn] changepoint : %d\n", changepoint); + + int memoTimeStamp = changepoint; + struct memo_operation_list *item_list = 0; + + Item_Node *root_ptr = 0; + Item_Node *cursor_ptr = 0; + int chagned_count = 0; + + item_list = memo_get_operation_list(memoTimeStamp); + if (item_list == 0) + goto DACI_FINISH; + + while ((item_list != 0) && (item_list->id > -1)) { + if (item_list->operation == MEMO_OPERATION_ADD) { + char *str_item_id = (char *)calloc(5, sizeof(char)); + sprintf(str_item_id, "%d", item_list->id); + FW_LOGV("[da_memo_plugIn] MEMO_OPERATION_ADD : [%s]\n", str_item_id); + + if (root_ptr == 0) { + root_ptr = (Item_Node *) calloc(1, sizeof(Item_Node)); + root_ptr->item_id = str_item_id; + root_ptr->next = 0; + cursor_ptr = root_ptr; + } else { + cursor_ptr->next = (Item_Node *) calloc(1, sizeof(Item_Node)); + cursor_ptr->next->item_id = str_item_id; + cursor_ptr->next->next = 0; + cursor_ptr = cursor_ptr->next; + } + + chagned_count++; + } + item_list = item_list->next; + } + +DACI_FINISH: + + /* memory free */ + if (item_list != 0) { + memo_free_operation_list(item_list); + item_list = 0; + } + + *changeCount = chagned_count; + return root_ptr; +} + +Item_Node *Get_Changed_ITEM_For_Folder_Del(int account_id, const char *folder_id, int changepoint, int *changeCount) +{ + FW_LOGV("\n[da_memo_plugIn] account_id : %d\n", account_id); + FW_LOGV("[da_memo_plugIn] folder_id : %s\n", folder_id); + FW_LOGV("[da_memo_plugIn] changepoint : %d\n", changepoint); + + int memoTimeStamp = changepoint; + struct memo_operation_list *item_list = 0; + + Item_Node *root_ptr = 0; + Item_Node *cursor_ptr = 0; + int chagned_count = 0; + + item_list = memo_get_operation_list(memoTimeStamp); + if (item_list == 0) + goto DACI_FINISH; + + while ((item_list != 0) && (item_list->id > -1)) { + if (item_list->operation == MEMO_OPERATION_DELETE) { + char *str_item_id = (char *)calloc(5, sizeof(char)); + sprintf(str_item_id, "%d", item_list->id); + FW_LOGV("[da_memo_plugIn] MEMO_OPERATION_DELETE : [%s]\n", str_item_id); + + if (root_ptr == 0) { + root_ptr = (Item_Node *) calloc(1, sizeof(Item_Node)); + root_ptr->item_id = str_item_id; + root_ptr->next = 0; + cursor_ptr = root_ptr; + } else { + cursor_ptr->next = (Item_Node *) calloc(1, sizeof(Item_Node)); + cursor_ptr->next->item_id = str_item_id; + cursor_ptr->next->next = 0; + cursor_ptr = cursor_ptr->next; + } + + chagned_count++; + } + item_list = item_list->next; + } + +DACI_FINISH: + + /* memory free */ + if (item_list != 0) { + memo_free_operation_list(item_list); + item_list = 0; + } + + *changeCount = chagned_count; + return root_ptr; +} + +Item_Node *Get_Changed_ITEM_For_Folder_Update(int account_id, const char *folder_id, int changepoint, int *changeCount) +{ + FW_LOGV("\n[da_memo_plugIn] account_id : %d\n", account_id); + FW_LOGV("[da_memo_plugIn] folder_id : %s\n", folder_id); + FW_LOGV("[da_memo_plugIn] changepoint : %d\n", changepoint); + + int memoTimeStamp = changepoint; + struct memo_operation_list *item_list = 0; + + Item_Node *root_ptr = 0; + Item_Node *cursor_ptr = 0; + int chagned_count = 0; + + item_list = memo_get_operation_list(memoTimeStamp); + if (item_list == 0) + goto DACI_FINISH; + + while ((item_list != 0) && (item_list->id > -1)) { + if (item_list->operation == MEMO_OPERATION_UPDATE) { + char *str_item_id = (char *)calloc(5, sizeof(char)); + sprintf(str_item_id, "%d", item_list->id); + FW_LOGV("[da_memo_plugIn] MEMO_OPERATION_UPDATE : [%s]\n", str_item_id); + + if (root_ptr == 0) { + root_ptr = (Item_Node *) calloc(1, sizeof(Item_Node)); + root_ptr->item_id = str_item_id; + root_ptr->next = 0; + cursor_ptr = root_ptr; + } else { + cursor_ptr->next = (Item_Node *) calloc(1, sizeof(Item_Node)); + cursor_ptr->next->item_id = str_item_id; + cursor_ptr->next->next = 0; + cursor_ptr = cursor_ptr->next; + } + + chagned_count++; + } + item_list = item_list->next; + } + +DACI_FINISH: + + /* memory free */ + if (item_list != 0) { + memo_free_operation_list(item_list); + item_list = 0; + } + + *changeCount = chagned_count; + return root_ptr; +} + +int Get_Last_ChangePoint() +{ + return (int)time(0); +} + +void StartListening_ChangeNoti(void *data) +{ + memo_subscribe_change(__process_Memo_Change, 0); +} + +void SetCallBack_AddItem(CALLBACK_ADD_ITEM callback) +{ + callback_add_item = callback; +} + +void SetCallBack_DeleteItem(CALLBACK_DEL_ITEM callback) +{ + callback_del_item = callback; +} + +void SetCallBack_UpdateItem(CALLBACK_UPDATE_ITEM callback) +{ + callback_update_item = callback; +} + +void SetCallBack_GetAccountIDList(GET_ACCOUNTIDLIST callback) +{ + callback_get_accountidlist = callback; +} + +/********************************** static function *******************************************/ + +static void __set_IsNotiFromMe(int set_flag) +{ + if (pthread_mutex_lock(&lockx)) { + FW_LOGV("[da_memo_plugIn] pthread_mutex_lock error"); + } + + isNotiFromMe = set_flag; + + if (pthread_mutex_unlock(&lockx)) { + FW_LOGV("[da_memo_plugIn] pthread_mutex_unlock error"); + } +} + +static int __get_IsNotiFromMe() +{ + return isNotiFromMe; +} + +void __process_Memo_Change(void *data) +{ + FW_LOGV("[da_memo_plugIn] detected memo storage changed!!\n"); + + int from_Me = __get_IsNotiFromMe(); + if (from_Me == 1) { + __set_IsNotiFromMe(0); + FW_LOGV("[da_memo_plugIn] This noti is from Me!! so will be ignored!!\n"); + return; + } + + pthread_t thread_process_change_id; + pthread_create(&thread_process_change_id, 0, __rutine_Memo_Change, 0); +} + +static void *__rutine_Memo_Change(void *data) +{ + FW_LOGV("[da_memo_plugIn] Start __rutine_Memo_Change (create thread)\n"); + + int memoTimeStamp = getMemoTimeStamp(); + + int i = 0; + int count = 0; + int result = 0; + char *str_item_id = 0; + int *accountList = 0; + struct memo_operation_list *item_list = 0; + + accountList = callback_get_accountidlist(FW_MEMO, &count); + if (accountList == 0) + goto DACI_FINISH; + + item_list = memo_get_operation_list(memoTimeStamp); + if (item_list == 0) + goto DACI_FINISH; + + while ((item_list != 0) && (item_list->id > -1)) { + str_item_id = g_strdup_printf("%d", item_list->id); + + for (i = 0; i < count; i++) { + FW_LOGV("[da_memo_plugIn] memo_account_id : %d, count : %d\n", accountList[i], count); + FW_LOGV("[da_memo_plugIn] memo_get_operation_list : %d\n", memoTimeStamp); + + switch (item_list->operation) { + case MEMO_OPERATION_ADD: + { + /* memo service is not supported folder */ + FW_LOGV("[da_memo_plugIn] MEMO_OPERATION_ADD\n"); + result = callback_add_item(accountList[i], i, str_item_id, FW_MEMO, "0", 0); + if (!result) { + FW_LOGV("[da_memo_plugIn] Failed to call callback_add_item() \n"); + goto DACI_FINISH; + } + } + break; + case MEMO_OPERATION_UPDATE: + { + FW_LOGV("[da_memo_plugIn] MEMO_OPERATION_UPDATE\n"); + result = callback_update_item(accountList[i], i, str_item_id, FW_MEMO); + if (!result) { + FW_LOGV("[da_memo_plugIn] Failed to call callback_update_item() \n"); + goto DACI_FINISH; + } + } + break; + case MEMO_OPERATION_DELETE: + { + FW_LOGV("[da_memo_plugIn] MEMO_OPERATION_DELETE\n"); + result = callback_del_item(accountList[i], i, str_item_id, FW_MEMO); + if (!result) { + FW_LOGV("[da_memo_plugIn] Failed to call callback_del_item() \n"); + goto DACI_FINISH; + } + } + break; + default: + FW_LOGV("[da_memo_plugIn] Another Memo Change Noti\n"); + break; + } + } + item_list = item_list->next; + free(str_item_id); + str_item_id = 0; + } + +DACI_FINISH: + + /* memory free */ + if (item_list != 0) { + memo_free_operation_list(item_list); + item_list = 0; + } + + if (accountList != 0) { + free(accountList); + accountList = 0; + } + + if (str_item_id != 0) { + free(str_item_id); + str_item_id = 0; + } + + FW_LOGV("[da_memo_plugIn] End __rutine_Memo_Change (create thread)\n"); + + return 0; +} + +static DACI_RETURN __convert_service_error_to_common_error(int err) +{ + DACI_RETURN ret = DACI_SUCCESS; + FW_LOGV("[da_memo_plugIn] Error Code : %d\n", err); + + switch (err) { + default: + ret = DACI_ERRORS; + break; + } + + return ret; +} diff --git a/fw-plugin/plain-text-plugIn/.cproject b/fw-plugin/plain-text-plugIn/.cproject new file mode 100755 index 0000000..3c36d31 --- /dev/null +++ b/fw-plugin/plain-text-plugIn/.cproject @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/fw-plugin/plain-text-plugIn/.project b/fw-plugin/plain-text-plugIn/.project new file mode 100755 index 0000000..6a6b392 --- /dev/null +++ b/fw-plugin/plain-text-plugIn/.project @@ -0,0 +1,78 @@ + + + plain-text-plugIn + + + + + + com.samsung.slp2.SboxBuilder + + + com.samsung.slp2.SboxBuilder.needConfigure + true + + + org.eclipse.cdt.core.errorOutputParser + org.eclipse.cdt.core.MakeErrorParser;com.samsung.limo.SboxGCCErrorParser;org.eclipse.cdt.core.GLDErrorParser;org.eclipse.cdt.core.GASErrorParser; + + + org.eclipse.cdt.make.core.append_environment + true + + + org.eclipse.cdt.make.core.build.arguments + + + + org.eclipse.cdt.make.core.build.command + make + + + org.eclipse.cdt.make.core.build.target.auto + all + + + org.eclipse.cdt.make.core.build.target.clean + clean + + + org.eclipse.cdt.make.core.build.target.inc + all + + + org.eclipse.cdt.make.core.enableAutoBuild + true + + + org.eclipse.cdt.make.core.enableCleanBuild + true + + + org.eclipse.cdt.make.core.enableFullBuild + true + + + org.eclipse.cdt.make.core.enabledIncrementalBuild + true + + + org.eclipse.cdt.make.core.environment + + + + org.eclipse.cdt.make.core.stopOnError + true + + + org.eclipse.cdt.make.core.useDefaultBuildCmd + true + + + + + + org.eclipse.cdt.core.cnature + com.samsung.slp2.cnature + + diff --git a/fw-plugin/plain-text-plugIn/CMakeLists.src b/fw-plugin/plain-text-plugIn/CMakeLists.src new file mode 100755 index 0000000..04ce4aa --- /dev/null +++ b/fw-plugin/plain-text-plugIn/CMakeLists.src @@ -0,0 +1 @@ +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src SRCS) diff --git a/fw-plugin/plain-text-plugIn/CMakeLists.sub b/fw-plugin/plain-text-plugIn/CMakeLists.sub new file mode 100755 index 0000000..286276c --- /dev/null +++ b/fw-plugin/plain-text-plugIn/CMakeLists.sub @@ -0,0 +1,37 @@ +################################################################################# +# THIS FILE IS CREATED AUTOMATICALLY. DO NOT DELETE OR MODIFY THIS FILE. +################################################################################# + +INCLUDE(CMakeLists.src) + +## PROJECT NAME +PROJECT(plugin-dc-plain-text C) + +## PACKAGE CONFIG +SET(SLP_PKGCONFIG_LIST "memo glib-2.0") + +## INCLUDES +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../../framework/include) + +## DEFINITIONS +ADD_DEFINITIONS("-DAPP_DIR=\"${CMAKE_INSTALL_PREFIX}\"") + +## LIBRARY PATH +SET(SLP_LD_PATH_FLAGS "") + +## LIBRARY +SET(SLP_LD_FLAGS "") + +## DEBUG +SET(SLP_DEBUG_FLAGS "-g") + +## OPTIMIZATION +SET(SLP_OPT_FLAGS "-O0") + +## COMPILER FLAGS +SET(SLP_COMPILER_FLAGS "") + +## LINKER FLAGS +SET(SLP_LINKER_FLAGS "") + diff --git a/fw-plugin/plain-text-plugIn/CMakeLists.txt b/fw-plugin/plain-text-plugIn/CMakeLists.txt new file mode 100755 index 0000000..567bbf0 --- /dev/null +++ b/fw-plugin/plain-text-plugIn/CMakeLists.txt @@ -0,0 +1,33 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) + +# INCLUDE SUB CMAKELIST FILE +INCLUDE(CMakeLists.sub) + +SET(RESOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/res") + +INCLUDE(FindPkgConfig) +pkg_check_modules(pkgs_plugin_plain_text REQUIRED ${SLP_PKGCONFIG_LIST}) + +FOREACH(flag ${pkgs_plugin_plain_text_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(CMAKE_C_FLAGS "${SLP_DEBUG_FLAGS} ${SLP_OPT_FLAGS} ${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} ${SLP_COMPILER_FLAGS}") +SET(CMAKE_CXX_FLAGS "${SLP_DEBUG_FLAGS} ${SLP_OPT_FLAGS} ${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} ${SLP_COMPILER_FLAGS}") + +ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS}) + +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_plugin_plain_text_LDFLAGS} ${SLP_LD_PATH_FLAGS} ${SLP_LD_FLAGS} ${SLP_LINKER_FLAGS} sync-agent-framework) + +# INSTALL +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION lib) +#INSTALL(DIRECTORY ${RESOURCE_DIR}/data DESTINATION share) + +#added by KTS for install to the system +#CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY) +#INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc DESTINATION lib/pkgconfig) + + +# INCLUDE LAYOUT DIRECTORY +# ADD_SUBDIRECTORY(layout) +#ADD_SUBDIRECTORY(res/locale) diff --git a/fw-plugin/plain-text-plugIn/include/IN_DataStore_Info_Plain_Text.h b/fw-plugin/plain-text-plugIn/include/IN_DataStore_Info_Plain_Text.h new file mode 100755 index 0000000..2624692 --- /dev/null +++ b/fw-plugin/plain-text-plugIn/include/IN_DataStore_Info_Plain_Text.h @@ -0,0 +1,50 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#ifndef IN_DATASTORE_INFO_PLAIN_TEXT_H_ +#define IN_DATASTORE_INFO_PLAIN_TEXT_H_ + +#define PLAIN_TEXT_TYPE "text/plain" +#define PLAIN_TEXT_VERSION "1.0" + +typedef struct PLAIN_TEXT_FIELD_LIST PLAIN_TEXT_FIELD_LIST; +struct PLAIN_TEXT_FIELD_LIST { + int field_enum; + char *field_name; +}; + +static PLAIN_TEXT_FIELD_LIST plain_text_field_list[] = { }; + +#endif /* IN_DATASTORE_INFO_PLAIN_TEXT_H_ */ diff --git a/fw-plugin/plain-text-plugIn/src/PlugIn_Interface.c b/fw-plugin/plain-text-plugIn/src/PlugIn_Interface.c new file mode 100755 index 0000000..19cafed --- /dev/null +++ b/fw-plugin/plain-text-plugIn/src/PlugIn_Interface.c @@ -0,0 +1,244 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#include +#include + +#include + +#include "IN_DataStore_Info_Plain_Text.h" + +/* for log */ +#include "agent-framework/Utility/fw_log.h" + +#include "agent-framework/PlugIn/DataConverter_Interface.h" + +#define LOG_TAG "PLUGIN_DC_PLAIN_TEXT" + +static int __free_obj_field_info(Field_Info *field_list, int count); +static int __set_obj_field_info(Field_Info **field_list, int count, PLAIN_TEXT_FIELD_LIST * input_list); +/* +static void __print_obj_field_info(Field_Info *info, int count); +static DACI_RETURN __convert_service_error_to_common_error(int err); +*/ + +DACI_RETURN Converter(const void *agent_data, void **service_data) +{ + FW_LOGV("[dc_plain_text_plugIn] Start !!"); + + DACI_RETURN ret = DACI_SUCCESS; + struct memo_data *temp_service_data = 0; + char *temp_agent_data = (char *)agent_data; + + /* create item */ + temp_service_data = memo_create_data(); + if (temp_service_data == 0) { + FW_LOGV("[dc_plain_text_plugIn] memo_create_data() Fail!\n"); + ret = DACI_ERRORS; + *service_data = 0; + } else { + FW_LOGV("[dc_plain_text_plugIn] memo_create_data() Success!\n"); + temp_service_data->content = strdup(temp_agent_data); /* configuration item */ + *service_data = (void *)temp_service_data; + } + + FW_LOGV("[dc_plain_text_plugIn] End !!"); + return ret; +} + +DACI_RETURN Replace_Converter(void *old_service_data, const void *agent_data, void **new_service_data) +{ + FW_LOGV("[dc_plain_text_plugIn] Start !!"); + + DACI_RETURN ret = DACI_SUCCESS; + struct memo_data *temp_service_data = (struct memo_data *)old_service_data; + char *temp_agent_data = (char *)agent_data; + + /* set item */ + if (temp_service_data->has_doodle == 0) { + free(temp_service_data->content); + temp_service_data->content = strdup(temp_agent_data); + } else if (temp_service_data->comment != 0) { + free(temp_service_data->comment); + temp_service_data->comment = strdup(temp_agent_data); + } + *new_service_data = (void *)temp_service_data; + + FW_LOGV("[dc_plain_text_plugIn] End !!"); + return ret; +} + +DACI_RETURN Reverse_Converter(void *service_data, void **agent_data) +{ + FW_LOGV("[dc_plain_text_plugIn] Start !!"); + + DACI_RETURN ret = DACI_SUCCESS; + char *temp_agent_data = 0; + struct memo_data *temp_service_data = (struct memo_data *)service_data; + + /* deep copy */ + if (temp_service_data == 0) { + FW_LOGV("[dc_plain_text_plugIn] Fail : no data !\n"); + ret = DACI_ERRORS; + *agent_data = 0; + } else if (temp_service_data->has_doodle == 0) { + FW_LOGV("[dc_plain_text_plugIn] Success!\n"); + temp_agent_data = strdup(temp_service_data->content); + *agent_data = (void *)temp_agent_data; + } else if (temp_service_data->comment != 0) { + FW_LOGV("[dc_plain_text_plugIn] Success!\n"); + temp_agent_data = strdup(temp_service_data->comment); + *agent_data = (void *)temp_agent_data; + } + + /* memory free */ + if (temp_service_data != 0) + memo_free_data(temp_service_data); + + FW_LOGV("[dc_plain_text_plugIn] End !!"); + return ret; +} + +void *Alloc_Object() +{ + FW_LOGV("[da_memo_plugIn] not implement !!"); + return 0; +} + +int Free_Object(void *in_object) +{ + FW_LOGV("[da_memo_plugIn] not implement !!"); + return 0; +} + +void *Set_Value_To_Object(void *in_object, int key, char *extension_key, void *value) +{ + FW_LOGV("[da_memo_plugIn] not implement !!"); + return 0; +} + +void *Get_Value_To_Object(void *in_object, int key, char *extension_key) +{ + FW_LOGV("[da_memo_plugIn] not implement !!"); + return 0; +} + +Object_Info *Get_Obj_Info() +{ + Object_Info *obj_info = (Object_Info *)calloc(1, sizeof(Object_Info)); + + obj_info->type = PLAIN_TEXT_TYPE; + obj_info->version = PLAIN_TEXT_VERSION; + obj_info->field_cnt = sizeof(plain_text_field_list) / sizeof(PLAIN_TEXT_FIELD_LIST); + + if (obj_info->field_cnt > 0) + __set_obj_field_info(&(obj_info->field_list), obj_info->field_cnt, plain_text_field_list); + + return obj_info; +} + +int Free_Obj_Info(Object_Info *obj_info) +{ + if (obj_info) { + if (obj_info->field_cnt > 0) + if (__free_obj_field_info(obj_info->field_list, obj_info->field_cnt) == 0) + return 0; + + free(obj_info); + } + + return 1; +} + +static int __free_obj_field_info(Field_Info *field_list, int count) +{ + int field_count = 0; + Field_Info *child = NULL; + + if (field_list) { + for (field_count = 0; field_count < count; field_count++) { + child = field_list + field_count; + if (child->field_child_cnt > 0) + if (__free_obj_field_info(child->field_child_list, child->field_child_cnt) == 0) + return 0; + } + free(field_list); + } + + return 1; +} + +static int __set_obj_field_info(Field_Info **field_list, int count, PLAIN_TEXT_FIELD_LIST * input_list) +{ + int field_count = 0; + Field_Info *child = NULL; + + *field_list = (Field_Info *)calloc(count, sizeof(Field_Info)); + + for (field_count = 0; field_count < count; field_count++) { + child = (*field_list) + field_count; + child->field_name = input_list[field_count].field_name; + FW_LOGI("[%s]", child->field_name); + } + + return 1; +} + +/* +static void __print_obj_field_info(Field_Info *info, int count) +{ + int i = 0; + if (info) + for (i = 0; i < count; i++) { + printf("[%s]\n", info[i].field_name); + if (info[i].field_child_list) + print(info[i].field_child_list, info[i].field_child_cnt); + } +} + +static DACI_RETURN __convert_service_error_to_common_error(int err) +{ + DACI_RETURN ret = DACI_SUCCESS; + FW_LOGV("[da_memo_plugIn] Error Code : %d\n", err); + + switch (err) { + default: + ret = DACI_ERRORS; + break; + } + + return ret; +} +*/ diff --git a/fw-plugin/slp-device-plugIn/.cproject b/fw-plugin/slp-device-plugIn/.cproject new file mode 100755 index 0000000..a09bf93 --- /dev/null +++ b/fw-plugin/slp-device-plugIn/.cproject @@ -0,0 +1,376 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/fw-plugin/slp-device-plugIn/.project b/fw-plugin/slp-device-plugIn/.project new file mode 100755 index 0000000..eb56211 --- /dev/null +++ b/fw-plugin/slp-device-plugIn/.project @@ -0,0 +1,145 @@ + + + slp-device-plugIn + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + ?name? + + + + org.eclipse.cdt.make.core.append_environment + true + + + org.eclipse.cdt.make.core.autoBuildTarget + all + + + org.eclipse.cdt.make.core.buildArguments + + + + org.eclipse.cdt.make.core.buildCommand + make + + + org.eclipse.cdt.make.core.cleanBuildTarget + clean + + + org.eclipse.cdt.make.core.contents + org.eclipse.cdt.make.core.activeConfigSettings + + + org.eclipse.cdt.make.core.enableAutoBuild + false + + + org.eclipse.cdt.make.core.enableCleanBuild + true + + + org.eclipse.cdt.make.core.enableFullBuild + true + + + org.eclipse.cdt.make.core.fullBuildTarget + all + + + org.eclipse.cdt.make.core.stopOnError + true + + + org.eclipse.cdt.make.core.useDefaultBuildCmd + true + + + + + com.samsung.slp2.SboxBuilder + + + com.samsung.slp2.SboxBuilder.needConfigure + true + + + org.eclipse.cdt.core.errorOutputParser + org.eclipse.cdt.core.MakeErrorParser;com.samsung.limo.SboxGCCErrorParser;org.eclipse.cdt.core.GLDErrorParser;org.eclipse.cdt.core.GASErrorParser; + + + org.eclipse.cdt.make.core.append_environment + true + + + org.eclipse.cdt.make.core.build.arguments + + + + org.eclipse.cdt.make.core.build.command + make + + + org.eclipse.cdt.make.core.build.target.auto + all + + + org.eclipse.cdt.make.core.build.target.clean + clean + + + org.eclipse.cdt.make.core.build.target.inc + all + + + org.eclipse.cdt.make.core.enableAutoBuild + true + + + org.eclipse.cdt.make.core.enableCleanBuild + true + + + org.eclipse.cdt.make.core.enableFullBuild + true + + + org.eclipse.cdt.make.core.enabledIncrementalBuild + true + + + org.eclipse.cdt.make.core.environment + + + + org.eclipse.cdt.make.core.stopOnError + true + + + org.eclipse.cdt.make.core.useDefaultBuildCmd + true + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + org.eclipse.cdt.core.cnature + com.samsung.slp2.cnature + org.eclipse.cdt.core.ccnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + diff --git a/fw-plugin/slp-device-plugIn/CMakeLists.src b/fw-plugin/slp-device-plugIn/CMakeLists.src new file mode 100755 index 0000000..04ce4aa --- /dev/null +++ b/fw-plugin/slp-device-plugIn/CMakeLists.src @@ -0,0 +1 @@ +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src SRCS) diff --git a/fw-plugin/slp-device-plugIn/CMakeLists.sub b/fw-plugin/slp-device-plugIn/CMakeLists.sub new file mode 100755 index 0000000..d7426f2 --- /dev/null +++ b/fw-plugin/slp-device-plugIn/CMakeLists.sub @@ -0,0 +1,37 @@ +################################################################################# +# THIS FILE IS CREATED AUTOMATICALLY. DO NOT DELETE OR MODIFY THIS FILE. +################################################################################# + +INCLUDE(CMakeLists.src) + +## PROJECT NAME +PROJECT(plugin-di-slp-device C) + +## PACKAGE CONFIG +SET(SLP_PKGCONFIG_LIST "glib-2.0 vconf tapi") + +## INCLUDES +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../../framework/include) + +## DEFINITIONS +ADD_DEFINITIONS("-DAPP_DIR=\"${CMAKE_INSTALL_PREFIX}\"") + +## LIBRARY PATH +SET(SLP_LD_PATH_FLAGS "") + +## LIBRARY +SET(SLP_LD_FLAGS "") + +## DEBUG +SET(SLP_DEBUG_FLAGS "-g") + +## OPTIMIZATION +SET(SLP_OPT_FLAGS "-O0") + +## COMPILER FLAGS +SET(SLP_COMPILER_FLAGS "-lpthread") + +## LINKER FLAGS +SET(SLP_LINKER_FLAGS "-lpthread") + diff --git a/fw-plugin/slp-device-plugIn/CMakeLists.txt b/fw-plugin/slp-device-plugIn/CMakeLists.txt new file mode 100755 index 0000000..e8541a6 --- /dev/null +++ b/fw-plugin/slp-device-plugIn/CMakeLists.txt @@ -0,0 +1,32 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) + +# INCLUDE SUB CMAKELIST FILE +INCLUDE(CMakeLists.sub) + +SET(RESOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/res") + +INCLUDE(FindPkgConfig) +pkg_check_modules(pkgs_plugin_slp_device REQUIRED ${SLP_PKGCONFIG_LIST}) + +FOREACH(flag ${pkgs_plugin_slp_device_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(CMAKE_C_FLAGS "${SLP_DEBUG_FLAGS} ${SLP_OPT_FLAGS} ${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} ${SLP_COMPILER_FLAGS}") +SET(CMAKE_CXX_FLAGS "${SLP_DEBUG_FLAGS} ${SLP_OPT_FLAGS} ${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} ${SLP_COMPILER_FLAGS}") + +ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS}) + +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_plugin_slp_device_LDFLAGS} ${SLP_LD_PATH_FLAGS} ${SLP_LD_FLAGS} ${SLP_LINKER_FLAGS} sync-agent-framework) + +# INSTALL +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION lib) +#INSTALL(DIRECTORY ${RESOURCE_DIR}/data DESTINATION share) + +#added by KTS for install to the system +#CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY) +#INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc DESTINATION lib/pkgconfig) + +# INCLUDE LAYOUT DIRECTORY +# ADD_SUBDIRECTORY(layout) +#ADD_SUBDIRECTORY(res/locale) diff --git a/fw-plugin/slp-device-plugIn/include/PlugIn_DevExe_Error.h b/fw-plugin/slp-device-plugIn/include/PlugIn_DevExe_Error.h new file mode 100755 index 0000000..d0e2741 --- /dev/null +++ b/fw-plugin/slp-device-plugIn/include/PlugIn_DevExe_Error.h @@ -0,0 +1,66 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Seokgil Kang + * Sooyi Kim + */ + +#ifndef PLUGIN_DEVEXE_ERROR_H_ +#define PLUGIN_DEVEXE_ERROR_H_ + +typedef enum { + + EXE_SUCCESS = 1, + EXE_DEV_FAIL = -1, + + /* standard error */ + EXE_DEV_DATA_FAIL = -2, + EXE_DEV_OPER_NOT_PERFORMED = -3, + + /* vender specific error */ + + /*common */ + EXE_DEV_AMT_STATUS_OFF = -4, + EXEC_DEV_SCREEN_OFF = -5, + + /*wipe */ + EXE_DEV_WIPE_ALL_FAILED = -10, + EXE_DEV_EXTERNAL_MEMORY_FAILED = -11, + EXE_DEV_SIM_MEMORY_FAILED = -12, + + /*forwarding */ + EXE_DEV_FORWORDING_ALL_FAILED = -20, + EXE_DEV_FORWORDING_CALL_FAILED = -21, + EXE_DEV_FORWORDING_SMS_FAILED = -22 +} SLP_EXE_DEV_ERROR; + +#endif /* PLUGIN_DEVEXE_ERROR_H_ */ diff --git a/fw-plugin/slp-device-plugIn/include/slp_device_info.h b/fw-plugin/slp-device-plugIn/include/slp_device_info.h new file mode 100755 index 0000000..96b2918 --- /dev/null +++ b/fw-plugin/slp-device-plugIn/include/slp_device_info.h @@ -0,0 +1,57 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Seokgil Kang + * Sooyi Kim + */ + +#ifndef SAMSUNG_DEVICE_INFO_H_ +#define SAMSUNG_DEVICE_INFO_H_ + +char *slp_device_info_get_software_version(); +char *slp_device_info_get_hardware_version(); +char *slp_device_info_get_DTD_version(); +char *slp_device_info_get_modem_version(); +char *slp_device_info_get_kernel_version(); +char *slp_device_info_get_PDA_version(); +char *slp_device_info_get_CSC_version(); +char *__slp_device_info_get_PDA_version_for_fw(); +char *__slp_device_info_get_CSC_version_for_fw(); + +char *slp_device_info_get_deviceID(); +char *slp_device_info_get_device_type(); +char *slp_device_info_get_manufacturer_info(); +char *slp_device_info_get_Opco_info(); +char *slp_device_info_get_model_info(); +char *slp_device_info_get_OEM_info(); + +#endif /* SAMSUNG_DEVICE_INFO_H_ */ diff --git a/fw-plugin/slp-device-plugIn/include/slp_ref.h b/fw-plugin/slp-device-plugIn/include/slp_ref.h new file mode 100755 index 0000000..50c09db --- /dev/null +++ b/fw-plugin/slp-device-plugIn/include/slp_ref.h @@ -0,0 +1,54 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Seokgil Kang + */ + +#ifndef SLP_REF_H_ +#define SLP_REF_H_ + +/* + * list of device information on SLP + */ + +/* + * < OMA DS > + * - DevID : device id + * - Man : manufacture + * - Mod : model id or model number + * - SwV : software version + * - HwV : hardware version + * - OEM : original equipment manufacturer + * - DevTyp : device type + */ + +#endif /* SLP_REF_H_ */ diff --git a/fw-plugin/slp-device-plugIn/src/PlugIn_Interface_DevExe.c b/fw-plugin/slp-device-plugIn/src/PlugIn_Interface_DevExe.c new file mode 100755 index 0000000..572f689 --- /dev/null +++ b/fw-plugin/slp-device-plugIn/src/PlugIn_Interface_DevExe.c @@ -0,0 +1,130 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Seokgil Kang + * Sooyi Kim + */ + +#include "PlugIn_DevExe_Error.h" + +#include "agent-framework/Utility/fw_log.h" + +#include "agent-framework/Device/EXT_DCI_DevInfo.h" + +#include "pmapi.h" + +#include "agent-framework/PlugIn/DeviceInfo_Interface.h" + +#include "pmapi.h" + +#include "agent-framework/PlugIn/DeviceInfo_Interface.h" + +#define LOG_TAG "PLUGIN_DEVINFO_SLP" + +#define DELTA_FILE "delta_hash.txt" + +static unsigned int __convert_pm_state(int state); +static unsigned int __convert_pm_lock_flag(int flag); +static unsigned int __convert_pm_unlock_flag(int flag); + +int PM_Lock_State(PM_State state, PM_Lock_State_Flag flag, unsigned int timeout) +{ + return pm_lock_state(__convert_pm_state(state), __convert_pm_lock_flag(flag), timeout); +} + +int PM_Unlock_State(PM_State state, PM_Unlock_State_Flag flag) +{ + return pm_unlock_state(__convert_pm_state(state), __convert_pm_unlock_flag(flag)); +} + +static unsigned int __convert_pm_state(int state) +{ + unsigned int pm_state = -1; + + switch (state) { + case 0: + pm_state = LCD_NORMAL; + break; + case 1: + pm_state = LCD_DIM; + break; + case 2: + pm_state = LCD_OFF; + break; + case 3: + pm_state = SUSPEND; + break; + case 4: + pm_state = POWER_OFF; + break; + case 5: + pm_state = LCD_DIM | LCD_OFF | LCD_NORMAL; + break; + } + + return pm_state; +} + +static unsigned int __convert_pm_lock_flag(int flag) +{ + unsigned int pm_flag; + + switch (flag) { + case 0: + pm_flag = GOTO_STATE_NOW; + break; + case 1: + pm_flag = STAY_CUR_STATE; + break; + } + + return pm_flag; +} + +static unsigned int __convert_pm_unlock_flag(int flag) +{ + unsigned int pm_flag; + + switch (flag) { + case 0: + pm_flag = PM_SLEEP_MARGIN; + break; + case 1: + pm_flag = PM_RESET_TIMER; + break; + case 2: + pm_flag = PM_KEEP_TIMER; + break; + } + + return pm_flag; +} diff --git a/fw-plugin/slp-device-plugIn/src/PlugIn_Interface_DevInfo.c b/fw-plugin/slp-device-plugIn/src/PlugIn_Interface_DevInfo.c new file mode 100755 index 0000000..a210cef --- /dev/null +++ b/fw-plugin/slp-device-plugIn/src/PlugIn_Interface_DevInfo.c @@ -0,0 +1,362 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Seokgil Kang + */ + +#include +#include +#include + +#include +#include + +#include +#include + +#include "slp_device_info.h" + +/* for log */ +#include "agent-framework/Utility/fw_log.h" + +#include "agent-framework/PlugIn/DeviceInfo_Interface.h" + +#define LOG_TAG "PLUGIN_DEVINFO_SLP" + +#define IMEI_LEN 5 +#define FW_VERSION_LEN 20 +#define BUFF_SIZE 1000 + +/* todo : temporary definition */ +#define MAN "Tizen" +#define MOD "Tizen-v1.0" +#define HW_VERSION "1.0" +#define FW_VERSION "1.0" +#define DTD_VERSION "1.2" +#define OEM "Tizen" +#define DEV_TYPE "phone" +#define DS_DEFAULT_IMEI "000000000000001" + + +typedef struct { + char *info_name; + char *vconf_key; +} dici_name_key_map; + +dici_name_key_map dev_key_map[] = { + {"SwV", VCONFKEY_TELEPHONY_SWVERSION}, + {"HwV", VCONFKEY_TELEPHONY_HWVERSION}, + {"Lang", "db/menu_widget/language"}, + {NULL, NULL}, +}; + +/*static int find_key(const char *info_name, char *key);*/ + +int Load_DevInfo(GList **devInfo) +{ + FW_LOGV("[devInfo_slp_plugIn] Start !! \n"); + + int res = 1; + + *devInfo = NULL; + + int idx = 0; + /* get SwV, HwV, Lang */ + dici_dev_info *info = NULL; + while (dev_key_map[idx].info_name != NULL) { + info = (dici_dev_info *) malloc(sizeof(dici_dev_info)); + if (info == 0) + return 0; + + memset(info, 0x00, sizeof(dici_dev_info)); + info->info_name = strdup(dev_key_map[idx].info_name); + if (info->info_name == 0) + return 0; + FW_LOGV("[devInfo_slp_plugIn] info_name : %s\n", info->info_name); + + info->value = strdup(vconf_get_str(dev_key_map[idx].vconf_key)); + if (info->value == 0) + return 0; + + if (!strcmp(info->info_name, "HwV")) { + if ((info->value == NULL) || (!strcmp(info->value, "")) || (!strcmp(info->value, "REV__"))) { + free(info->value); + info->value = strdup(HW_VERSION); + } + } + + FW_LOGV("[devInfo_slp_plugIn] value : %s\n", info->value); + *devInfo = g_list_append(*devInfo, info); + + ++idx; + } + + /* get DevID */ + TelMiscSNIndexType_t type = TAPI_MISC_ME_IMEI; + TelMiscSNInformation sn = { 0, }; + char imei_value[30] = { 0, }; + + if (tel_init() != TAPI_API_SUCCESS) { + FW_LOGE("tel_init() fail !!"); + return 0; + } else { + FW_LOGV("tel_init() success !!"); + } + + int tapi_res = tel_get_misc_me_sn(type, &sn); + if (tapi_res != TAPI_API_SUCCESS) { + /* todo : for temporary */ + FW_LOGE("tel_get_misc_me_sn() fail !!, tapi_res : %d", tapi_res); + snprintf(imei_value, sizeof(imei_value), "%s:%s", "IMEI", DS_DEFAULT_IMEI); + FW_LOGV("default IMEI : %s", imei_value); + } else { + FW_LOGV("tel_get_misc_me_sn() success !!"); + snprintf(imei_value, sizeof(imei_value), "%s:%s", "IMEI", sn.szNumber); + FW_LOGV("IMEI length : %d, %s", sn.sn_len, imei_value); + } + + dici_dev_info *devId = (dici_dev_info *) malloc(sizeof(dici_dev_info)); + if (devId == 0) + return 0; + memset(devId, 0x00, sizeof(dici_dev_info)); + devId->info_name = strdup("DevID"); + devId->value = strdup(imei_value); + *devInfo = g_list_append(*devInfo, devId); + + tel_deinit(); + + FW_LOGV("mdi ============= \n"); + + /* get Manufacture */ + dici_dev_info *man = (dici_dev_info *) malloc(sizeof(dici_dev_info)); + if (man == 0) + return 0; + memset(man, 0x00, sizeof(dici_dev_info)); + man->info_name = strdup("Man"); + man->value = slp_device_info_get_manufacturer_info(); + *devInfo = g_list_append(*devInfo, man); + + /* get Model info */ + dici_dev_info *mod = (dici_dev_info *) malloc(sizeof(dici_dev_info)); + if (mod == 0) + return 0; + memset(mod, 0x00, sizeof(dici_dev_info)); + mod->info_name = strdup("Mod"); + mod->value = slp_device_info_get_model_info(); + *devInfo = g_list_append(*devInfo, mod); + + /* get OEM */ + dici_dev_info *oem = (dici_dev_info *) malloc(sizeof(dici_dev_info)); + if (oem == 0) + return 0; + memset(oem, 0x00, sizeof(dici_dev_info)); + oem->info_name = strdup("OEM"); + oem->value = slp_device_info_get_OEM_info(); + *devInfo = g_list_append(*devInfo, oem); + + /* get DevTyp */ + dici_dev_info *dev_type = (dici_dev_info *) malloc(sizeof(dici_dev_info)); + if (dev_type == 0) + return 0; + memset(dev_type, 0x00, sizeof(dici_dev_info)); + dev_type->info_name = strdup("DevTyp"); + dev_type->value = slp_device_info_get_device_type(); + *devInfo = g_list_append(*devInfo, dev_type); + + /* get kernel version */ + dici_dev_info *kernel_version = (dici_dev_info *) malloc(sizeof(dici_dev_info)); + if (kernel_version == 0) + return 0; + memset(kernel_version, 0x00, sizeof(dici_dev_info)); + kernel_version->info_name = strdup("KernelV"); + kernel_version->value = slp_device_info_get_kernel_version(); + *devInfo = g_list_append(*devInfo, kernel_version); + + /* get Modem version */ + dici_dev_info *modem_version = (dici_dev_info *) malloc(sizeof(dici_dev_info)); + if (modem_version == 0) + return 0; + memset(modem_version, 0x00, sizeof(dici_dev_info)); + modem_version->info_name = strdup("ModemV"); + modem_version->value = slp_device_info_get_modem_version(); + *devInfo = g_list_append(*devInfo, modem_version); + + /* get PDA version */ + dici_dev_info *pda_version = (dici_dev_info *) malloc(sizeof(dici_dev_info)); + if (pda_version == 0) + return 0; + memset(pda_version, 0x00, sizeof(dici_dev_info)); + pda_version->info_name = strdup("PDAV"); + pda_version->value = slp_device_info_get_PDA_version(); + *devInfo = g_list_append(*devInfo, pda_version); + + /* get CSC version */ + dici_dev_info *csc_version = (dici_dev_info *) malloc(sizeof(dici_dev_info)); + if (csc_version == 0) + return 0; + memset(csc_version, 0x00, sizeof(dici_dev_info)); + csc_version->info_name = strdup("CSCV"); + csc_version->value = slp_device_info_get_CSC_version(); + *devInfo = g_list_append(*devInfo, csc_version); + + /* get DTD version */ + dici_dev_info *dtd_version = (dici_dev_info *) malloc(sizeof(dici_dev_info)); + if (dtd_version == 0) + return 0; + memset(dtd_version, 0x00, sizeof(dici_dev_info)); + dtd_version->info_name = strdup("DTDV"); + dtd_version->value = slp_device_info_get_DTD_version(); + *devInfo = g_list_append(*devInfo, dtd_version); + + /* get OPCO info */ + dici_dev_info *opco_info = (dici_dev_info *) malloc(sizeof(dici_dev_info)); + if (opco_info == 0) + return 0; + memset(opco_info, 0x00, sizeof(dici_dev_info)); + opco_info->info_name = strdup("OPCO"); + opco_info->value = slp_device_info_get_Opco_info(); + *devInfo = g_list_append(*devInfo, opco_info); + + /* for test */ + int cnt = 0; + GList *iter = NULL; + for (iter = *devInfo; iter != NULL; iter = g_list_next(iter)) { + FW_LOGV("[devInfo_slp_plugIn] cnt : %d, info_name : %s, value : %s\n", cnt, ((dici_dev_info *) (iter->data))->info_name, ((dici_dev_info *) (iter->data))->value); + cnt++; + } + + FW_LOGV("[devInfo_slp_plugIn] End !! \n"); + + return res; +} + +int Get_DevInfo(GList *devInfo, char *info_name, char **value) +{ + FW_LOGV("[devInfo_slp_plugIn] Start !! \n"); + + int res = 1; + int is_exist = 0; + GList *iter = NULL; + dici_dev_info *iter_data; + + for (iter = devInfo; iter != NULL; iter = g_list_next(iter)) { + iter_data = NULL; + iter_data = (dici_dev_info *) (iter->data); + if (iter_data->info_name != NULL) { + if (!strcmp(iter_data->info_name, info_name)) { + if (iter_data->value != NULL) { + + *value = strdup(iter_data->value); + + is_exist = 1; + break; + } else { + FW_LOGV("[devInfo_slp_plugIn] %s value is NULL !!\n", info_name); + res = 0; + return res; + } + } + } + } + + if (is_exist != 1) { + FW_LOGV("[devInfo_slp_plugIn] not exist %s information !!\n", info_name); + res = -1; + return res; + } + + FW_LOGV("[devInfo_slp_plugIn] End !! \n"); + + return res; +} + +int Clear_DevInfo(GList **devInfo) +{ + FW_LOGV("[devInfo_slp_plugIn] Start !! \n"); + + int res = 1; + + GList *iter = NULL; + dici_dev_info *iter_data; + + if (*devInfo != NULL) { + for (iter = *devInfo; iter != NULL;) { + iter_data = NULL; + iter_data = ((dici_dev_info *) (iter->data)); + iter = g_list_next(iter); + *devInfo = g_list_remove(*devInfo, iter_data); + + if (iter_data != NULL) { + if (((dici_dev_info *) (iter_data))->info_name != NULL) + free(((dici_dev_info *) (iter_data))->info_name); + if (((dici_dev_info *) (iter_data))->value != NULL) + free(((dici_dev_info *) (iter_data))->value); + free((dici_dev_info *) (iter_data)); + } + } + + g_list_free(*devInfo); + } + + FW_LOGV("[devInfo_slp_plugIn] End !! \n"); + + return res; +} + +/*static int find_key(const char *info_name, char *key) +{ + FW_LOGV("[devInfo_slp_plugIn] Start !! \n"); + + int res = 1; + int idx = 0; + + while (dev_key_map[idx].info_name != NULL) { + if (!strcmp(dev_key_map[idx].info_name, info_name)) { + if (dev_key_map[idx].vconf_key != NULL) { + key = dev_key_map[idx].vconf_key; + break; + } else { + FW_LOGV("[devInfo_slp_plugIn] vconf_key is NULL ( %s )\n", info_name); + res = 0; + return res; + } + } + + ++idx; + } + + FW_LOGV("[devInfo_slp_plugIn] vconf_key : %s\n", key); + + FW_LOGV("[devInfo_slp_plugIn] End !! \n"); + + return res; +}*/ diff --git a/fw-plugin/slp-device-plugIn/src/slp_device_info.c b/fw-plugin/slp-device-plugIn/src/slp_device_info.c new file mode 100755 index 0000000..820e069 --- /dev/null +++ b/fw-plugin/slp-device-plugIn/src/slp_device_info.c @@ -0,0 +1,288 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Seokgil Kang + * Sooyi Kim + */ + +#include "slp_device_info.h" +#include +#include +#include +#include +#include +#include + +/* for log */ +#include "agent-framework/Utility/fw_log.h" +#define LOG_TAG "SLP_DEVICE_INFO" + +#define _D_MSC_FIRMWARE_MAXSTRING_ 40 +#define _D_SIZE_64_ 64 +#define _D_SIZE_128_ 128 + +/* todo : temporary definition */ +#define SW_VERSION "Tizen-v1.0" +#define HW_VERSION "Tizen-v1.0" +#define FW_VERSION "1.0" +#define DTD_VERSION "1.2" +#define MODEM_VERSION "M.IXXUI" +#define PDA_VERSION "P.IXXJI-" + +#define MANUFACTURE "Tizen" +#define MODEL "Tizen-1.0" +#define OPCO "UK" +#define OEM "Tizen" +#define DEV_TYPE "phone" + +#define PDA_BIN_VERSION "/usr/etc/info.ini" +#define CSC_DB_VERSION "/mnt/csc/info.ini" +#define _D_PDA_BUILD_INFO_MAJOR_ "Major=" +#define _D_PDA_BUILD_INFO_BUILD_ "Build=" + +#define PDA_VERSION_INFO_FILE "/etc/info.ini" + +/* ========================================*/ +/* version information + * software version + * hardware version + * DTD version + * modem version + * kernel version + * PDA version + * CSC version + * firmware version + */ +/* ========================================*/ +char *slp_device_info_get_software_version() +{ + char *SW_version = (char *)calloc(_D_SIZE_128_, sizeof(char)); + /*snprintf(SW_version, _D_SIZE_128_ - 1, SW_VERSION, strlen(SW_VERSION));*/ + snprintf(SW_version, _D_SIZE_128_ - 1, "%s", SW_VERSION); + FW_LOGV("SW version = %s\n", SW_version); + return SW_version; +} + +char *slp_device_info_get_hardware_version() +{ + char *HW_version = (char *)calloc(_D_SIZE_128_, sizeof(char)); + /*snprintf(HW_version, _D_SIZE_128_ - 1, HW_VERSION, strlen(HW_VERSION));*/ + snprintf(HW_version, _D_SIZE_128_ - 1, "%s", HW_VERSION); + FW_LOGV("HW version = %s\n", HW_version); + return HW_version; +} + +char *slp_device_info_get_DTD_version() +{ + char *dtd_version = (char *)calloc(_D_SIZE_128_, sizeof(char)); + /*snprintf(dtd_version, _D_SIZE_128_ - 1, DTD_VERSION, strlen(DTD_VERSION));*/ + snprintf(dtd_version, _D_SIZE_128_ - 1, "%s", DTD_VERSION); + FW_LOGV("DTD version = %s\n", dtd_version); + return dtd_version; +} + +char *slp_device_info_get_modem_version() +{ + char *get_str; + char str_key_name[_D_SIZE_128_ * 2] = { 0, }; + snprintf(str_key_name, _D_SIZE_128_ * 2, "%s", VCONFKEY_TELEPHONY_SWVERSION); + get_str = vconf_get_str(str_key_name); + FW_LOGV("Modem version = %s\n", get_str); + return get_str; +} + +char *slp_device_info_get_kernel_version() +{ + char *KernelVersion = (char *)calloc(_D_SIZE_128_, sizeof(char)); + + struct utsname buf; + uname(&buf); + + snprintf(KernelVersion, _D_SIZE_128_ - 1, "%s.%s", "K", buf.release); + + FW_LOGV("sysname[%s], nodename[%s], release[%s], version[%s], machine[%s] \n", buf.sysname, buf.nodename, buf.release, buf.version, buf.machine); + return KernelVersion; +} + +char *slp_device_info_get_PDA_version() +{ + char *PDAVersion = (char *)calloc(_D_SIZE_128_, sizeof(char)); + FILE *file_des; + file_des = fopen(PDA_BIN_VERSION, "rb"); + int i = 0; + + if (file_des == NULL) { + FW_LOGV("fopen fail - info.ini \n"); + snprintf(PDAVersion, _D_SIZE_128_ / 2, "%s", PDA_VERSION); + return 0; + } + + while (!feof(file_des)) { + char info_temp[20] = { 0, }; + int result = 1; + fseek(file_des, i, SEEK_SET); + i++; + + fread(info_temp, sizeof(char), strlen(_D_PDA_BUILD_INFO_BUILD_), file_des); /* 2011/10/05 SCM request _D_PDA_BUILD_INFO_MAJOR_ -> _D_PDA_BUILD_INFO_BUILD_ */ + result = memcmp(info_temp, _D_PDA_BUILD_INFO_BUILD_, strlen(_D_PDA_BUILD_INFO_BUILD_)); + if (!result) { + char PDAVersion_check[64] = { 0 }; + int read_pos = 0; + while (!feof(file_des)) { + fread(PDAVersion_check + read_pos, sizeof(char), 1, file_des); + if (PDAVersion_check[read_pos] == '_') + PDAVersion_check[read_pos] = '-'; + else if (PDAVersion_check[read_pos] == '\n') + break; + else if (PDAVersion_check[read_pos] == ';') { + /*PDAVersion_check[read_pos] = NULL;*/ + PDAVersion_check[read_pos] = 0; + break; + } + read_pos++; + } + + snprintf(PDAVersion, _D_SIZE_128_ / 2, "%s", PDAVersion_check); + FW_LOGV("fread PDAVersion - [%s]\n", PDAVersion); + break; + } + } + + if (file_des != NULL) + fclose(file_des); + + return PDAVersion; +} + +char *slp_device_info_get_CSC_version() +{ + char *CSCVersion = (char *)calloc(_D_SIZE_128_, sizeof(char)); + + FILE *file_des; + file_des = fopen(CSC_DB_VERSION, "rb"); + int i = 0; + if (file_des == NULL) { + FW_LOGV("fopen fail - info.ini \n"); + snprintf(CSCVersion, _D_SIZE_128_ / 2, "%s", "C."); + return 0; + } + while (!feof(file_des)) { + char info_temp[20] = { 0, }; + int result = 1; + fseek(file_des, i, SEEK_SET); + i++; + + fread(info_temp, sizeof(char), strlen(_D_PDA_BUILD_INFO_BUILD_), file_des); /* 2011/10/05 SCM request _D_PDA_BUILD_INFO_MAJOR_ -> _D_PDA_BUILD_INFO_BUILD_ */ + result = memcmp(info_temp, _D_PDA_BUILD_INFO_BUILD_, strlen(_D_PDA_BUILD_INFO_BUILD_)); + if (!result) { + char CSCVersion_check[64] = { 0 }; + int read_pos = 0; + while (!feof(file_des)) { + fread(CSCVersion_check + read_pos, sizeof(char), 1, file_des); + if (CSCVersion_check[read_pos] == '_') + CSCVersion_check[read_pos] = '-'; + else if (CSCVersion_check[read_pos] == '\n') + break; + else if (CSCVersion_check[read_pos] == ';') { + /*CSCVersion_check[read_pos] = NULL;*/ + CSCVersion_check[read_pos] = 0; + break; + } + read_pos++; + } + + snprintf(CSCVersion, _D_SIZE_128_ / 2, "%s", CSCVersion_check); + FW_LOGV("fread CSCVersion - [%s]\n", CSCVersion); + break; + } + } + + if (file_des != NULL) + fclose(file_des); + + return CSCVersion; +} + +/* ==================================== + * device etc information + * =====================================*/ +char *slp_device_info_get_device_type() +{ + char *dev_type = (char *)calloc(_D_SIZE_128_, sizeof(char)); + snprintf(dev_type, _D_SIZE_128_ - 1, "%s", DEV_TYPE); + FW_LOGV("Device Type = %s\n", DEV_TYPE); + return dev_type; +} + +char *slp_device_info_get_deviceID() +{ + char *DeviceID = (char *)calloc(_D_SIZE_128_, sizeof(char)); + if (vconf_get_str(VCONFKEY_TELEPHONY_IMEI) != NULL) + snprintf(DeviceID, _D_SIZE_128_ - 1, "IMEI:%s", vconf_get_str(VCONFKEY_TELEPHONY_IMEI)); + else + snprintf(DeviceID, _D_SIZE_128_ - 1, "IMEI:%s", "355310046608752"); + return DeviceID; +} + +char *slp_device_info_get_Opco_info() +{ + char *OpcoInfo = (char *)calloc(_D_SIZE_128_, sizeof(char)); + snprintf(OpcoInfo, _D_SIZE_128_ - 1, "%s", OPCO); + FW_LOGV("Opco Info = %s\n", OpcoInfo); + return OpcoInfo; /* prevent */ +} + +char *slp_device_info_get_model_info() +{ + char *ModelInfo = (char *)calloc(_D_SIZE_128_, sizeof(char)); + snprintf(ModelInfo, _D_SIZE_128_ - 1, "%s", MODEL); + FW_LOGV("Model info = %s\n", ModelInfo); + return ModelInfo; /* prevent */ +} + +char *slp_device_info_get_manufacturer_info() +{ + char *ManufacturerInfo = (char *)calloc(_D_SIZE_128_, sizeof(char)); + snprintf(ManufacturerInfo, _D_SIZE_128_ - 1, "%s", MANUFACTURE); /* prevent */ + + FW_LOGV("Manufacturer = %s\n", MANUFACTURE); + return ManufacturerInfo; +} + +char *slp_device_info_get_OEM_info() +{ + char *oem_info = (char *)calloc(_D_SIZE_128_, sizeof(char)); + snprintf(oem_info, _D_SIZE_128_ - 1, "%s", OEM); + + FW_LOGV("OEM = %s\n", OEM); + return oem_info; +} diff --git a/fw-plugin/slp-sysnoti-plugIn/.cproject b/fw-plugin/slp-sysnoti-plugIn/.cproject new file mode 100755 index 0000000..8801bdc --- /dev/null +++ b/fw-plugin/slp-sysnoti-plugIn/.cproject @@ -0,0 +1,293 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/fw-plugin/slp-sysnoti-plugIn/.project b/fw-plugin/slp-sysnoti-plugIn/.project new file mode 100755 index 0000000..14bf91f --- /dev/null +++ b/fw-plugin/slp-sysnoti-plugIn/.project @@ -0,0 +1,145 @@ + + + slp-sysnoti-plugIn + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + ?name? + + + + org.eclipse.cdt.make.core.append_environment + true + + + org.eclipse.cdt.make.core.autoBuildTarget + all + + + org.eclipse.cdt.make.core.buildArguments + + + + org.eclipse.cdt.make.core.buildCommand + make + + + org.eclipse.cdt.make.core.cleanBuildTarget + clean + + + org.eclipse.cdt.make.core.contents + org.eclipse.cdt.make.core.activeConfigSettings + + + org.eclipse.cdt.make.core.enableAutoBuild + false + + + org.eclipse.cdt.make.core.enableCleanBuild + true + + + org.eclipse.cdt.make.core.enableFullBuild + true + + + org.eclipse.cdt.make.core.fullBuildTarget + all + + + org.eclipse.cdt.make.core.stopOnError + true + + + org.eclipse.cdt.make.core.useDefaultBuildCmd + true + + + + + com.samsung.slp2.SboxBuilder + + + com.samsung.slp2.SboxBuilder.needConfigure + true + + + org.eclipse.cdt.core.errorOutputParser + org.eclipse.cdt.core.MakeErrorParser;com.samsung.limo.SboxGCCErrorParser;org.eclipse.cdt.core.GLDErrorParser;org.eclipse.cdt.core.GASErrorParser; + + + org.eclipse.cdt.make.core.append_environment + true + + + org.eclipse.cdt.make.core.build.arguments + + + + org.eclipse.cdt.make.core.build.command + make + + + org.eclipse.cdt.make.core.build.target.auto + all + + + org.eclipse.cdt.make.core.build.target.clean + clean + + + org.eclipse.cdt.make.core.build.target.inc + all + + + org.eclipse.cdt.make.core.enableAutoBuild + true + + + org.eclipse.cdt.make.core.enableCleanBuild + true + + + org.eclipse.cdt.make.core.enableFullBuild + true + + + org.eclipse.cdt.make.core.enabledIncrementalBuild + true + + + org.eclipse.cdt.make.core.environment + + + + org.eclipse.cdt.make.core.stopOnError + true + + + org.eclipse.cdt.make.core.useDefaultBuildCmd + true + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + org.eclipse.cdt.core.cnature + com.samsung.slp2.cnature + org.eclipse.cdt.core.ccnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + diff --git a/fw-plugin/slp-sysnoti-plugIn/CMakeLists.src b/fw-plugin/slp-sysnoti-plugIn/CMakeLists.src new file mode 100755 index 0000000..04ce4aa --- /dev/null +++ b/fw-plugin/slp-sysnoti-plugIn/CMakeLists.src @@ -0,0 +1 @@ +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src SRCS) diff --git a/fw-plugin/slp-sysnoti-plugIn/CMakeLists.sub b/fw-plugin/slp-sysnoti-plugIn/CMakeLists.sub new file mode 100755 index 0000000..f0c145b --- /dev/null +++ b/fw-plugin/slp-sysnoti-plugIn/CMakeLists.sub @@ -0,0 +1,37 @@ +################################################################################# +# THIS FILE IS CREATED AUTOMATICALLY. DO NOT DELETE OR MODIFY THIS FILE. +################################################################################# + +INCLUDE(CMakeLists.src) + +## PROJECT NAME +PROJECT(plugin-pm-slp-sysnoti C) + +## PACKAGE CONFIG +SET(SLP_PKGCONFIG_LIST "glib-2.0 vconf alarm-service msg-service") + +## INCLUDES +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../../framework/include) + +## DEFINITIONS +ADD_DEFINITIONS("-DAPP_DIR=\"${CMAKE_INSTALL_PREFIX}\"") + +## LIBRARY PATH +SET(SLP_LD_PATH_FLAGS "") + +## LIBRARY +SET(SLP_LD_FLAGS "") + +## DEBUG +SET(SLP_DEBUG_FLAGS "-g") + +## OPTIMIZATION +SET(SLP_OPT_FLAGS "-O0") + +## COMPILER FLAGS +SET(SLP_COMPILER_FLAGS "-lpthread") + +## LINKER FLAGS +SET(SLP_LINKER_FLAGS "-lpthread") + diff --git a/fw-plugin/slp-sysnoti-plugIn/CMakeLists.txt b/fw-plugin/slp-sysnoti-plugIn/CMakeLists.txt new file mode 100755 index 0000000..3a2fc56 --- /dev/null +++ b/fw-plugin/slp-sysnoti-plugIn/CMakeLists.txt @@ -0,0 +1,32 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) + +# INCLUDE SUB CMAKELIST FILE +INCLUDE(CMakeLists.sub) + +SET(RESOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/res") + +INCLUDE(FindPkgConfig) +pkg_check_modules(pkgs_plugin_slp_sysnoti REQUIRED ${SLP_PKGCONFIG_LIST}) + +FOREACH(flag ${pkgs_plugin_slp_sysnoti_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(CMAKE_C_FLAGS "${SLP_DEBUG_FLAGS} ${SLP_OPT_FLAGS} ${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} ${SLP_COMPILER_FLAGS}") +SET(CMAKE_CXX_FLAGS "${SLP_DEBUG_FLAGS} ${SLP_OPT_FLAGS} ${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} ${SLP_COMPILER_FLAGS}") + +ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS}) + +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_plugin_slp_sysnoti_LDFLAGS} ${SLP_LD_PATH_FLAGS} ${SLP_LD_FLAGS} ${SLP_LINKER_FLAGS} sync-agent-framework) + +# INSTALL +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION lib) +#INSTALL(DIRECTORY ${RESOURCE_DIR}/data DESTINATION share) + +#added by KTS for install to the system +#CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY) +#INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc DESTINATION lib/pkgconfig) + +# INCLUDE LAYOUT DIRECTORY +# ADD_SUBDIRECTORY(layout) +#ADD_SUBDIRECTORY(res/locale) diff --git a/fw-plugin/slp-sysnoti-plugIn/include/SLP_Alarm.h b/fw-plugin/slp-sysnoti-plugIn/include/SLP_Alarm.h new file mode 100755 index 0000000..de3cccf --- /dev/null +++ b/fw-plugin/slp-sysnoti-plugIn/include/SLP_Alarm.h @@ -0,0 +1,51 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Seokgil Kang + */ + +#ifndef SLP_ALARM_H_ +#define SLP_ALARM_H_ + +int init_alarm(const char *pkg_name); + +int set_alarm_callback(void *callback); + +int destory_alarm(); + +int add_alarm(void *add_item, int *out_add_item_id); + +int remove_alarm(int remove_item_id); + +int get_alarm(int get_item_id, void **out_item); + +#endif /* SLP_ALARM_H_ */ diff --git a/fw-plugin/slp-sysnoti-plugIn/include/SLP_CallBack.h b/fw-plugin/slp-sysnoti-plugIn/include/SLP_CallBack.h new file mode 100644 index 0000000..ccc76cb --- /dev/null +++ b/fw-plugin/slp-sysnoti-plugIn/include/SLP_CallBack.h @@ -0,0 +1,70 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Seokgil Kang + */ + +#ifndef SLP_CALLBACK_H_ +#define SLP_CALLBACK_H_ + +#include "agent-framework/PlugIn/PlatformMonitor_Interface.h" + +void setCallBack_NetworkStatus(CALLBACK_NETWORK_STATUS callback); + +void setCallBack_NetworkAllCancel(CALLBACK_NETWORK_CANCEL callback); + +void setCallBack_Syncml_SAN_Incoming(CALLBACK_SYNCML_SAN_INCOMING callback); + +void setCallBack_Syncml_SAN_Operation(CALLBACK_SYNCML_SAN_OPERATION callback); + +void setCallBack_Alarm(CALLBACK_ALARM callback); + +void setCallBack_Network_On(CALLBACK_NETWORK_ON callback); + +void setCallBack_Network_Off(CALLBACK_NETWORK_OFF callback); + +/* for network */ +void network_status_callback_fn(int protocol_type); + +void network_cancel_callback_fn(int protocol_type); + +/* for syncml san */ +void syncml_san_incoming_callback_fn(int item_id, void *user_data); + +void syncml_san_operation_callback_fn(int item_id, void *user_data); + +/* for service-agent network */ +void network_on_callback_fn(int item_id, void *user_data); + +void network_off_callback_fn(int item_id, void *user_data); + +#endif /* SLP_CALLBACK_H_ */ diff --git a/fw-plugin/slp-sysnoti-plugIn/include/SLP_ConnManager.h b/fw-plugin/slp-sysnoti-plugIn/include/SLP_ConnManager.h new file mode 100755 index 0000000..72b8f70 --- /dev/null +++ b/fw-plugin/slp-sysnoti-plugIn/include/SLP_ConnManager.h @@ -0,0 +1,61 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Seokgil Kang + */ + +#ifndef SLP_CONNMANAGER_H_ +#define SLP_CONNMANAGER_H_ + +#include +#include "vconf-keys.h" +#include "vconf.h" + +/* + * @brief check current network status + * @return operation result + * @retval 1 network is available + * @retval 0 network is unavailable + */ +int check_network(); + +void network_connection_cb(keynode_t *node, void *data); +void network_configuration_handler(keynode_t *node, void *data); +void init_network(); + +int get_net_status(); +int get_net_type(); + +char *get_ConnMan_proxy(); +char *get_ConnMan_ip(); + +#endif /* SLP_CONNMANAGER_H_ */ diff --git a/fw-plugin/slp-sysnoti-plugIn/include/SLP_SAN.h b/fw-plugin/slp-sysnoti-plugIn/include/SLP_SAN.h new file mode 100755 index 0000000..39e7795 --- /dev/null +++ b/fw-plugin/slp-sysnoti-plugIn/include/SLP_SAN.h @@ -0,0 +1,52 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Seokgil Kang + */ + +#ifndef SLP_SAN_H_ +#define SLP_SAN_H_ + +typedef enum { + SAN_VERSION_11 = 11, + SAN_VERSION_12 = 12, +} PM_SAN_VERSION; + +int start_san(); + +int end_san(); + +int add_san_message(void *add_item); + +int remove_san_message(int remove_item_id); + +#endif /* SLP_SAN_H_ */ diff --git a/fw-plugin/slp-sysnoti-plugIn/src/PlugIn_Interface.c b/fw-plugin/slp-sysnoti-plugIn/src/PlugIn_Interface.c new file mode 100755 index 0000000..6db129a --- /dev/null +++ b/fw-plugin/slp-sysnoti-plugIn/src/PlugIn_Interface.c @@ -0,0 +1,319 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Seokgil Kang + */ + +#include +#include +#include +#include "vconf-keys.h" +#include "vconf.h" + +#include "agent-framework/PlugIn/PlatformMonitor_Interface.h" + +#include "SLP_CallBack.h" + +#include "SLP_ConnManager.h" + +/* for alarm service */ +#include "SLP_Alarm.h" + +/* for SAN noti */ +#include "SLP_SAN.h" + +/* for log */ +#include "agent-framework/Utility/fw_log.h" + +#define LOG_TAG "PLUGIN_PM_SLP" + +static int __register_network_fw_internal_callback(); + +void Init_Network_Status_Noti_Handler(void *data) +{ + FW_LOGV("[pm_slp_sysnoti_plugIn] Start !!"); + + g_type_init(); + g_thread_init(NULL); + init_network(); + + int res = 1; + + network_status_callback_fn(1); + + res = __register_network_fw_internal_callback(); + if (res != 1) { + FW_LOGE("[pm_slp_sysnoti_plugIn] __register_network_fw_callback() fail !!"); + } else { + FW_LOGV("[pm_slp_sysnoti_plugIn] __register_network_fw_callback() success !!"); + } + + FW_LOGV("[pm_slp_sysnoti_plugIn] End !!"); +} + +int Terminate_Network_Status_Noti_Handler() +{ + FW_LOGV("[pm_slp_sysnoti_plugIn] Start !!"); + + int res = 1; + + res = vconf_ignore_key_changed(VCONFKEY_NETWORK_STATUS, network_connection_cb); + if (res < 0) { + FW_LOGE("[pm_slp_sysnoti_plugIn] vconf_ignore_key_changed ( VCONFKEY_NETWORK_STATUS ) fail !!"); + return res; + } else { + FW_LOGV("[pm_slp_sysnoti_plugIn] vconf_ignore_key_changed ( VCONFKEY_NETWORK_STATUS ) success !!"); + res = 1; + } + + res = vconf_ignore_key_changed(VCONFKEY_NETWORK_CONFIGURATION_CHANGE_IND, network_configuration_handler); + if (res < 0) { + FW_LOGE("[pm_slp_sysnoti_plugIn] vconf_ignore_key_changed ( VCONFKEY_NETWORK_CONFIGURATION_CHANGE_IND ) fail !!"); + return res; + } else { + FW_LOGV("[pm_slp_sysnoti_plugIn] vconf_ignore_key_changed ( VCONFKEY_NETWORK_CONFIGURATION_CHANGE_IND ) success !!"); + res = 1; + } + + FW_LOGV("[pm_slp_sysnoti_plugIn] End !!"); + + return res; +} + +void Init_Syncml_SAN_Noti_Handler(void *data) +{ + FW_LOGV("[pm_slp_sysnoti_plugIn] Start !!"); + + int res = 0; + + res = start_san(); + + if (res != 1) { + FW_LOGE("[pm_slp_sysnoti_plugIn] start_san() fail !!"); + } else { + FW_LOGV("[pm_slp_sysnoti_plugIn] start_san() success !!"); + } + + FW_LOGV("[pm_slp_sysnoti_plugIn] End !!"); +} + +int Terminate_Syncml_SAN_Noti_Handler() +{ + FW_LOGV("[pm_slp_sysnoti_plugIn] Start !!"); + + int res = 0; + + res = end_san(); + + if (res != 1) { + FW_LOGE("[pm_slp_sysnoti_plugIn] end_san() fail !!"); + return res; + } else { + FW_LOGV("[pm_slp_sysnoti_plugIn] end_san() success !!"); + } + + FW_LOGV("[pm_slp_sysnoti_plugIn] End !!"); + + return res; +} + +int Add_Message(void *add_item) +{ + FW_LOGV("[pm_slp_sysnoti_plugIn] Start!!"); + + int res = 0; + + res = add_san_message(add_item); + + if (res != 1) { + FW_LOGE("[pm_slp_sysnoti_plugIn] add_san_message() fail !!"); + return res; + } else { + FW_LOGV("[pm_slp_sysnoti_plugIn] add_san_message() success !!"); + } + + FW_LOGV("[pm_slp_sysnoti_plugIn] End !!"); + + return res; +} + +int Remove_Message(int remove_item_id) +{ + FW_LOGV("[pm_slp_sysnoti_plugIn] Start!!"); + + int res = 0; + + res = remove_san_message(remove_item_id); + + if (res != 1) { + FW_LOGE("[pm_slp_sysnoti_plugIn] remove_san_message() fail !!"); + return res; + } else { + FW_LOGV("[pm_slp_sysnoti_plugIn] remove_san_message() success !!"); + } + + FW_LOGV("[pm_slp_sysnoti_plugIn] End !!"); + + return res; +} + +void Init_Alarm_Noti_Handler(void *data) +{ + FW_LOGV("[pm_slp_sysnoti_plugIn] Start!!"); + + pm_register_data_t *reg_data = (pm_register_data_t *) data; + if (reg_data == NULL) { + FW_LOGE("[pm_slp_sysnoti_plugIn] data is NULL !!"); + goto free_part; + } + + FW_LOGV("pkg_name : %s", reg_data->pkg_name); + int ret = init_alarm(reg_data->pkg_name); + if (ret != 1) { + FW_LOGE("[pm_slp_sysnoti_plugIn] init_alarm() fail !!"); + } else { + FW_LOGV("[pm_slp_sysnoti_plugIn] init_alarm() success !!"); + } + +free_part: + if (reg_data != NULL) { + if (reg_data->pkg_name != NULL) + free(reg_data->pkg_name); + + free(reg_data); + + FW_LOGV("free pm_register_data_t !!"); + } + + FW_LOGV("[pm_slp_sysnoti_plugIn] End!!"); +} + +int Terminate_Alarm_Noti_Handler() +{ + FW_LOGV("[pm_slp_sysnoti_plugIn] Start!!"); + int ret = destory_alarm(); + FW_LOGV("[pm_slp_sysnoti_plugIn] End!!"); + + return ret; +} + +int Add_Alarm(void *add_item, int *out_add_item_id) +{ + FW_LOGV("[pm_slp_sysnoti_plugIn] Start!!"); + int ret = add_alarm(add_item, out_add_item_id); + FW_LOGV("[pm_slp_sysnoti_plugIn] End!!"); + + return ret; +} + +int Remove_Alarm(int remove_item_id) +{ + FW_LOGV("[pm_slp_sysnoti_plugIn] Start!!"); + int ret = remove_alarm(remove_item_id); + FW_LOGV("[pm_slp_sysnoti_plugIn] End!!"); + + return ret; +} + +int Get_Alarm(int get_item_id, void **out_get_item) +{ + FW_LOGV("[pm_slp_sysnoti_plugIn] Start!!"); + int ret = get_alarm(get_item_id, out_get_item); + FW_LOGV("[pm_slp_sysnoti_plugIn] End!!"); + + return ret; +} + +void SetCallBack_NetworkStatus(CALLBACK_NETWORK_STATUS callback) +{ + setCallBack_NetworkStatus(callback); +} + +void SetCallBack_NetworkAllCancel(CALLBACK_NETWORK_CANCEL callback) +{ + setCallBack_NetworkAllCancel(callback); +} + +void SetCallBack_Syncml_SAN_Incoming(CALLBACK_SYNCML_SAN_INCOMING callback) +{ + setCallBack_Syncml_SAN_Incoming(callback); +} + +void SetCallBack_Syncml_SAN_Operation(CALLBACK_SYNCML_SAN_OPERATION callback) +{ + setCallBack_Syncml_SAN_Operation(callback); +} + +void SetCallBack_Alarm(CALLBACK_ALARM callback) +{ + setCallBack_Alarm(callback); + set_alarm_callback(callback); +} + +void SetCallBack_Network_On(CALLBACK_NETWORK_ON callback) +{ + setCallBack_Network_On(callback); +} + +void SetCallBack_Network_Off(CALLBACK_NETWORK_OFF callback) +{ + setCallBack_Network_Off(callback); +} + +static int __register_network_fw_internal_callback() +{ + FW_LOGV("[pm_slp_sysnoti_plugIn] Start !!"); + + int res = 1; + + res = vconf_notify_key_changed(VCONFKEY_NETWORK_STATUS, network_connection_cb, NULL); + if (res < 0) { + FW_LOGE("[pm_slp_sysnoti_plugIn] vconf_notify_key_changed ( VCONFKEY_NETWORK_STATUS ) fail !!"); + return res; + } else { + FW_LOGV("[pm_slp_sysnoti_plugIn] vconf_notify_key_changed ( VCONFKEY_NETWORK_STATUS ) success !!"); + res = 1; + } + + res = vconf_notify_key_changed(VCONFKEY_NETWORK_CONFIGURATION_CHANGE_IND, network_configuration_handler, NULL); + if (res < 0) { + FW_LOGE("[pm_slp_sysnoti_plugIn] vconf_notify_key_changed ( VCONFKEY_NETWORK_CONFIGURATION_CHANGE_IND ) fail !!"); + return res; + } else { + FW_LOGV("[pm_slp_sysnoti_plugIn] vconf_notify_key_changed ( VCONFKEY_NETWORK_CONFIGURATION_CHANGE_IND ) success !!"); + res = 1; + } + + FW_LOGV("[pm_slp_sysnoti_plugIn] End !!"); + + return res; +} diff --git a/fw-plugin/slp-sysnoti-plugIn/src/SLP_Alarm.c b/fw-plugin/slp-sysnoti-plugIn/src/SLP_Alarm.c new file mode 100755 index 0000000..898bb90 --- /dev/null +++ b/fw-plugin/slp-sysnoti-plugIn/src/SLP_Alarm.c @@ -0,0 +1,449 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Seokgil Kang + */ +#include +#include +#include +#include +#include "SLP_Alarm.h" + +#include "SLP_CallBack.h" + +#include "agent-framework/PlatformMonitor/EXT_PMCI_Struct.h" +#include + +/* for log */ +#include "agent-framework/Utility/fw_log.h" +#define LOG_TAG "PLUGIN_PM_SLP_ALARM" + +static int __convert_service_time(char *temp_time, alarm_date_t *out_time); +static int __convert_fw_time(alarm_date_t *temp_time, char **out_time); + +int init_alarm(const char *pkg_name) +{ + int result = alarmmgr_init(pkg_name); + if (result != ALARMMGR_RESULT_SUCCESS) { + FW_LOGV("alarmmgr_init Fail: err_code = %d\n", result); + return 0; + } else { + FW_LOGV("alarmmgr_init Success\n"); + return 1; + } + + return 0; +} + +int set_alarm_callback(void *callback) +{ + int result = alarmmgr_set_cb(callback, 0); + if (result != ALARMMGR_RESULT_SUCCESS) { + FW_LOGV("alarmmgr_set_cb Fail: err_code = %d\n", result); + return 0; + } else { + FW_LOGV("alarmmgr_set_cb Success\n"); + return 1; + } + + return 0; +} + +int destory_alarm() +{ + /* not support destory alarm api */ + FW_LOGV("not support destory alarm api"); + return 0; +} + +int add_alarm(void *add_item, int *out_add_item_id) +{ + FW_LOGV("Start!!"); + int err = 0; + pmci_alarm_t *temp_add_item = (pmci_alarm_t *) add_item; + if (temp_add_item == 0) + goto return_part; + + /* allocate service alarm struct */ + alarm_entry_t *service_add_item = 0; + service_add_item = alarmmgr_create_alarm(); + if (service_add_item == 0) + goto return_part; + + /* convert fw struct to service struct */ + + /* setting start alarm time */ + if (temp_add_item->start_alarm_time != 0) { + + alarm_date_t expire_time; + memset(&expire_time, 0x00, sizeof(alarm_date_t)); + err = __convert_service_time(temp_add_item->start_alarm_time, &expire_time); + if (err != 1) + FW_LOGE("__convert_alarm_time() Fail: %d", err); + + err = alarmmgr_set_time(service_add_item, expire_time); + if (err != ALARMMGR_RESULT_SUCCESS) + FW_LOGE("alarmmgr_set_time() Fail: %d", err); + } + + /* setting repeat mode and repeat value */ + alarm_repeat_mode_t repeat_mode = 0; + if (temp_add_item->repeat_type != REPEAT_NO_TYPE) { + switch (temp_add_item->repeat_type) { + case ONCE: + repeat_mode = ALARM_REPEAT_MODE_ONCE; + break; + case REPEAT: + repeat_mode = ALARM_REPEAT_MODE_REPEAT; + break; + case REPEAT_WEEKLY: + repeat_mode = ALARM_REPEAT_MODE_WEEKLY; + break; + case REPEAT_MONTHLY: + repeat_mode = ALARM_REPEAT_MODE_MONTHLY; + break; + case REPEAT_ANNUALLY: + repeat_mode = ALARM_REPEAT_MODE_ANNUALLY; + break; + default: + break; + } + } + + alarm_day_of_week_t repeat_value = 0; + if (temp_add_item->repeat_value != DAY_NO_TYPE) { + switch (temp_add_item->repeat_type) { + case ONCE: + case REPEAT: + { + repeat_value = temp_add_item->repeat_value; + } + break; + case REPEAT_ANNUALLY: + case REPEAT_MONTHLY: + case REPEAT_WEEKLY: + { + int tmp; + int num = 1; + + int i; + for (i = 1; i <= DAY_CNT; i++) { + tmp = (temp_add_item->repeat_value >> i); + switch (tmp) { + case DAY_SUN: + repeat_value |= ALARM_WDAY_SUNDAY; + break; + case DAY_MON: + repeat_value |= ALARM_WDAY_MONDAY; + break; + case DAY_TUE: + repeat_value |= ALARM_WDAY_TUESDAY; + break; + case DAY_WED: + repeat_value |= ALARM_WDAY_WEDNESDAY; + break; + case DAY_THU: + repeat_value |= ALARM_WDAY_THURSDAY; + break; + case DAY_FRI: + repeat_value |= ALARM_WDAY_FRIDAY; + break; + case DAY_SAT: + repeat_value |= ALARM_WDAY_SATURDAY; + break; + default: + break; + } + + num *= 2; + } + } + break; + default: + break; + } + } + + err = alarmmgr_set_repeat_mode(service_add_item, repeat_mode, repeat_value); + if (err != ALARMMGR_RESULT_SUCCESS) + FW_LOGE("alarmmgr_set_repeat_mode() Fail: %d", err); + + /* set alarm type */ + int alarm_type = 0; + if (temp_add_item->isDisposable != 0) { + alarm_type = ALARM_TYPE_VOLATILE; + } else { + alarm_type = ALARM_TYPE_DEFAULT; + } + + err = alarmmgr_set_type(service_add_item, alarm_type); + if (err != ALARMMGR_RESULT_SUCCESS) + FW_LOGE("alarmmgr_set_type() Fail: %d", err); + + /* insert add alarm item */ + int alarm_id = 0; + int result = alarmmgr_add_alarm_with_localtime(service_add_item, 0, &alarm_id); + if (result != ALARMMGR_RESULT_SUCCESS) { + FW_LOGV("alarmmgr_add_alarm Fail: err_code = %d\n", result); + err = 0; + } else { + FW_LOGV("alarmmgr_add_alarm Success : alarm_id = %d\n", alarm_id); + *out_add_item_id = alarm_id; + err = 1; + } + + if (service_add_item != 0) + alarmmgr_free_alarm(service_add_item); + +return_part: + + FW_LOGV("End!!"); + return err; +} + +int remove_alarm(int remove_item_id) +{ + int result = alarmmgr_remove_alarm(remove_item_id); + if (result != ALARMMGR_RESULT_SUCCESS) { + FW_LOGV("alarmmgr_remove_alarm Fail: err_code = %d\n", result); + return 0; + } else { + FW_LOGV("alarmmgr_remove_alarm Success\n"); + return 1; + } + + return 0; +} + +int get_alarm(int get_item_id, void **out_item) +{ + alarm_entry_t *alarm = alarmmgr_create_alarm(); + int result = alarmmgr_get_info(get_item_id, alarm); + if (result != ALARMMGR_RESULT_SUCCESS) { + FW_LOGV("alarmmgr_get_info Fail: err_code = %d\n", result); + return 0; + } + + /* converting */ + pmci_alarm_t *agent_alarm_info = (pmci_alarm_t *) calloc(1, sizeof(pmci_alarm_t)); + + int alarm_type = 0; + result = alarmmgr_get_type(alarm, &alarm_type); + if (result != ALARMMGR_RESULT_SUCCESS) { + FW_LOGV("alarmmgr_get_type Fail: err_code = %d\n", result); + return 0; + } + FW_LOGV("alarm_type = %d", alarm_type); + if (alarm_type == ALARM_TYPE_DEFAULT) { + agent_alarm_info->isDisposable = false; + } else { + agent_alarm_info->isDisposable = true; + } + + alarm_repeat_mode_t repeat_mode; + alarm_day_of_week_t repeat_value; + result = alarmmgr_get_repeat_mode(alarm, &repeat_mode, (int *)(&repeat_value)); + if (result != ALARMMGR_RESULT_SUCCESS) { + FW_LOGV("alarmmgr_get_repeat_mode Fail: err_code = %d\n", result); + return 0; + } + FW_LOGV("repeat_mode = %d, repeat_value = %d", repeat_mode, repeat_value); + switch (repeat_mode) { + case ALARM_REPEAT_MODE_ONCE: + FW_LOGV("ALARM_REPEAT_ONCE"); + agent_alarm_info->repeat_type = ONCE; + agent_alarm_info->repeat_value = repeat_value; + break; + case ALARM_REPEAT_MODE_REPEAT: + FW_LOGV("ALARM_REPEAT_MODE_REPEAT"); + agent_alarm_info->repeat_type = REPEAT; + agent_alarm_info->repeat_value = repeat_value; + break; + case ALARM_REPEAT_MODE_WEEKLY: + case ALARM_REPEAT_MODE_MONTHLY: + case ALARM_REPEAT_MODE_ANNUALLY: + { + FW_LOGV("ALARM_REPEAT_MODE_WEEKLY, MONTHLY, ANNUALLY"); + int tmp; + int num = 1; + + int i; + for (i = 1; i <= DAY_CNT; i++) { + tmp = (repeat_value >> i); + switch (tmp) { + case DAY_SUN: + agent_alarm_info->repeat_value |= DAY_SUN; + break; + case DAY_MON: + agent_alarm_info->repeat_value |= DAY_MON; + break; + case DAY_TUE: + agent_alarm_info->repeat_value |= DAY_TUE; + break; + case DAY_WED: + agent_alarm_info->repeat_value |= DAY_WED; + break; + case DAY_THU: + agent_alarm_info->repeat_value |= DAY_THU; + break; + case DAY_FRI: + agent_alarm_info->repeat_value |= DAY_FRI; + break; + case DAY_SAT: + agent_alarm_info->repeat_value |= DAY_SAT; + break; + default: + break; + } + num *= 2; + } + } + break; + default: + break; + } + + alarm_date_t alarm_time; + result = alarmmgr_get_time(alarm, &alarm_time); + if (result != ALARMMGR_RESULT_SUCCESS) { + FW_LOGV("alarmmgr_get_info Fail: err_code = %d\n", result); + return 0; + } + + char *alarm_time_s = 0; + __convert_fw_time(&alarm_time, &alarm_time_s); + FW_LOGV("alarm_time_s = %s", alarm_time_s); + agent_alarm_info->start_alarm_time = alarm_time_s; + + *out_item = agent_alarm_info; + + if (alarm != 0) + alarmmgr_free_alarm(alarm); + + return 1; +} + +static int __convert_service_time(char *temp_time, alarm_date_t *out_time) +{ + if (temp_time == 0) + return 0; + FW_LOGV("temp_time = %s", temp_time); + + char *delimiter = "-"; + + char *day_ptr = strstr(temp_time, "T"); + FW_LOGV("Day_ptr = %s", day_ptr); + + int length1 = strlen(day_ptr); + FW_LOGV("length1 = %d", length1); + + char *day = (char *)calloc(length1 + 1, sizeof(char)); + if (day == NULL) { + FW_LOGE("calloc fail !!"); + return 0; + } + strncpy(day, temp_time, length1); + FW_LOGV("Day = %s", day); + + /* get year */ + char *ptr = strtok(day, delimiter); + if (ptr == 0) + return 0; + FW_LOGV("Year = %s\n", ptr); + (out_time)->year = atoi(ptr); + + /* get month */ + ptr = strtok(0, delimiter); + if (ptr == 0) + return 0; + FW_LOGV("Month = %s\n", ptr); + (out_time)->month = atoi(ptr); + + /* get day */ + ptr = strtok(0, delimiter); + if (ptr == 0) + return 0; + FW_LOGV("Day = %s\n", ptr); + (out_time)->day = atoi(ptr); + + if (day != 0) + free(day); + + char *time_ptr = strstr(day_ptr, "Z"); + FW_LOGV("time_ptr = %s", time_ptr); + + int length2 = strlen(temp_time) - strlen(day_ptr) - 2; + FW_LOGV("length2 = %d", length2); + + char *time = (char *)calloc(length2, sizeof(char)); + if (time == NULL) { + FW_LOGE("calloc fail !!"); + return 0; + } + strncpy(time, day_ptr + 1, length2); + FW_LOGV("Time = %s", time); + delimiter = ":"; + + /* get hour */ + ptr = strtok(time, delimiter); + if (ptr == 0) + return 0; + FW_LOGV("hour = %s\n", ptr); + (out_time)->hour = atoi(ptr); + + /* get min */ + ptr = strtok(0, delimiter); + if (ptr == 0) + return 0; + FW_LOGV("min = %s\n", ptr); + (out_time)->min = atoi(ptr); + + /* get sec */ + ptr = strtok(0, delimiter); + if (ptr == 0) + return 0; + FW_LOGV("sec = %s\n", ptr); + (out_time)->sec = atoi(ptr); + + if (time != 0) + free(time); + + return 1; +} + +static int __convert_fw_time(alarm_date_t *temp_time, char **out_time) +{ + *out_time = g_strdup_printf("%.2d-%.2d-%.2dT%.2d:%.2d:%.2dZ", temp_time->year, temp_time->month, temp_time->day, temp_time->hour, temp_time->min, temp_time->sec); + FW_LOGV("out_time = %s\n", *out_time); + + return 1; +} diff --git a/fw-plugin/slp-sysnoti-plugIn/src/SLP_CallBack.c b/fw-plugin/slp-sysnoti-plugIn/src/SLP_CallBack.c new file mode 100644 index 0000000..3f3c38b --- /dev/null +++ b/fw-plugin/slp-sysnoti-plugIn/src/SLP_CallBack.c @@ -0,0 +1,234 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Seokgil Kang + */ + +#include "SLP_CallBack.h" +#include "SLP_ConnManager.h" +#include "agent-framework/Utility/fw_log.h" + +#define LOG_TAG "PLUGIN_PM_SLP" + +static CALLBACK_NETWORK_STATUS callback_network_status = 0; +static CALLBACK_NETWORK_CANCEL callback_network_cancel = 0; +static CALLBACK_SYNCML_SAN_INCOMING callback_syncml_san_incoming = 0; +static CALLBACK_SYNCML_SAN_OPERATION callback_syncml_san_operation = 0; +static CALLBACK_ALARM callback_alarm = 0; +static CALLBACK_NETWORK_ON callback_network_on = 0; +static CALLBACK_NETWORK_OFF callback_network_off = 0; + +void setCallBack_NetworkStatus(CALLBACK_NETWORK_STATUS callback) +{ + callback_network_status = callback; +} + +void setCallBack_NetworkAllCancel(CALLBACK_NETWORK_CANCEL callback) +{ + callback_network_cancel = callback; +} + +void setCallBack_Syncml_SAN_Incoming(CALLBACK_SYNCML_SAN_INCOMING callback) +{ + callback_syncml_san_incoming = callback; +} + +void setCallBack_Syncml_SAN_Operation(CALLBACK_SYNCML_SAN_OPERATION callback) +{ + callback_syncml_san_operation = callback; +} + +void setCallBack_Alarm(CALLBACK_ALARM callback) +{ + callback_alarm = callback; +} + +void setCallBack_Network_On(CALLBACK_NETWORK_ON callback) +{ + callback_network_on = callback; +} + +void setCallBack_Network_Off(CALLBACK_NETWORK_OFF callback) +{ + callback_network_off = callback; +} + +void network_status_callback_fn(int protocol_type) +{ + FW_LOGV("[pm_slp_sysnoti_plugIn] Start !!"); + + int res = 1; + int net_status = 0; + int net_type = 0; + char *proxy = 0; + char *ip = 0; + + if (check_network() == 1) { + FW_LOGV("[pm_slp_sysnoti_plugIn] network is ON \n"); + proxy = get_ConnMan_proxy(); + ip = get_ConnMan_ip(); + } else { + FW_LOGV("[pm_slp_sysnoti_plugIn] network is OFF \n"); + } + + net_status = get_net_status(); + net_type = get_net_type(); + + FW_LOGV("[pm_slp_sysnoti_plugIn] protocol_type : %d, network status : %d, network type : %d, proxy : %s, ip : %s\n", protocol_type, net_status, net_type, proxy, ip); + + FW_LOGV("[pm_slp_sysnoti_plugIn] callback_network_status() Start !!"); + if (callback_network_status != 0) { + res = callback_network_status(protocol_type, net_status, net_type, proxy, ip); + } else { + FW_LOGE("[pm_slp_sysnoti_plugIn] callback_network_status is NULL!!"); + } + + FW_LOGV("[pm_slp_sysnoti_plugIn] callback_network_status() End !!"); + + if (res != 1) { + FW_LOGE("[pm_slp_sysnoti_plugIn] callback_network_status() fail !!"); + } else { + FW_LOGV("[pm_slp_sysnoti_plugIn] callback_network_status() success !!"); + } + + FW_LOGV("[pm_slp_sysnoti_plugIn] End !!"); +} + +void network_cancel_callback_fn(int protocol_type) +{ + FW_LOGV("[pm_slp_sysnoti_plugIn] Start !!"); + + int res = 1; + + if (callback_network_cancel != 0) { + FW_LOGV("[pm_slp_sysnoti_plugIn] call registered network cancel callback function !!"); + + res = callback_network_cancel(protocol_type); + if (res != 1) { + FW_LOGE("[pm_slp_sysnoti_plugIn] callback_network_cancel() fail !!"); + } else { + FW_LOGV("[pm_slp_sysnoti_plugIn] callback_network_cancel() success !!"); + } + } else { + FW_LOGE("[pm_slp_sysnoti_plugIn] network_cancel_callback is NULL !! (not registered network_cancel_callback function)"); + } + + FW_LOGV("[pm_slp_sysnoti_plugIn] End !!"); +} + +void syncml_san_incoming_callback_fn(int item_id, void *user_data) +{ + FW_LOGV("[pm_slp_sysnoti_plugIn] Start !!"); + + int res = 1; + + if (callback_syncml_san_incoming != 0) { + FW_LOGV("[pm_slp_sysnoti_plugIn] call registered user syncml_SAN_incoming_callback function !!"); + + res = callback_syncml_san_incoming(item_id, user_data); + if (res != 1) { + FW_LOGE("[pm_slp_sysnoti_plugIn] syncml_SAN_incoming_callback_fn() fail !!"); + } else { + FW_LOGV("[pm_slp_sysnoti_plugIn] syncml_SAN_incoming_callback_fn() success !!"); + } + } else { + FW_LOGE("[pm_slp_sysnoti_plugIn] user syncml_SAN_incoming_callback is NULL !! (not registered user syncml_SAN_incoming_callback function)"); + } + + FW_LOGV("[pm_slp_sysnoti_plugIn] End !!"); +} + +void syncml_san_operation_callback_fn(int item_id, void *user_data) +{ + FW_LOGV("[pm_slp_sysnoti_plugIn] Start !!"); + + int res = 1; + + if (callback_syncml_san_operation != 0) { + FW_LOGV("[pm_slp_sysnoti_plugIn] call registered user syncml_SAN_operation_callback function !!"); + + res = callback_syncml_san_operation(item_id, user_data); + if (res != 1) { + FW_LOGE("[pm_slp_sysnoti_plugIn] syncml_SAN_operation_callback_fn() fail !!"); + } else { + FW_LOGV("[pm_slp_sysnoti_plugIn] syncml_SAN_operation_callback_fn() success !!"); + } + } else { + FW_LOGE("[pm_slp_sysnoti_plugIn] user syncml_SAN_operation_callback is NULL !! (not registered user syncml_SAN_operation_callback function)"); + } + + FW_LOGV("[pm_slp_sysnoti_plugIn] End !!"); +} + +void network_on_callback_fn(int item_id, void *user_data) +{ + FW_LOGV("[pm_slp_sysnoti_plugIn] Start !!"); + + int res = 1; + + if (callback_network_on != 0) { + FW_LOGV("[pm_slp_sysnoti_plugIn] call registered user network_on_callback function !!"); + + res = callback_network_on(item_id, user_data); + if (res != 1) { + FW_LOGE("[pm_slp_sysnoti_plugIn] callback_network_on() fail !!"); + } else { + FW_LOGV("[pm_slp_sysnoti_plugIn] callback_network_on() success !!"); + } + } else { + FW_LOGE("[pm_slp_sysnoti_plugIn] user network_on_callback is NULL !! (not registered user network_on_callback function)"); + } + + FW_LOGV("[pm_slp_sysnoti_plugIn] End !!"); +} + +void network_off_callback_fn(int item_id, void *user_data) +{ + FW_LOGV("[pm_slp_sysnoti_plugIn] Start !!"); + + int res = 1; + + if (callback_network_on != 0) { + FW_LOGV("[pm_slp_sysnoti_plugIn] call registered user network_off_callback function !!"); + + res = callback_network_off(item_id, user_data); + if (res != 1) { + FW_LOGE("[pm_slp_sysnoti_plugIn] callback_network_off() fail !!"); + } else { + FW_LOGV("[pm_slp_sysnoti_plugIn] callback_network_off() success !!"); + } + } else { + FW_LOGE("[pm_slp_sysnoti_plugIn] user network_off_callback is NULL !! (not registered user network_off_callback function)"); + } + + FW_LOGV("[pm_slp_sysnoti_plugIn] End !!"); +} diff --git a/fw-plugin/slp-sysnoti-plugIn/src/SLP_ConnManager.c b/fw-plugin/slp-sysnoti-plugIn/src/SLP_ConnManager.c new file mode 100755 index 0000000..a86b3fe --- /dev/null +++ b/fw-plugin/slp-sysnoti-plugIn/src/SLP_ConnManager.c @@ -0,0 +1,390 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Seokgil Kang + */ + +#define ConnMan + +#ifdef ConnMan + +#include "SLP_CallBack.h" + +#include "SLP_ConnManager.h" +#include "agent-framework/NetworkAccess/EXT_NA_NetworkStatus.h" + +/* for log */ +#include "agent-framework/Utility/fw_log.h" +#define LOG_TAG "PLUGIN_PM_SLP_CM" + +static FW_NETWORK_STATUS fw_network_status; +static FW_NETWORK_TYPE fw_network_type; + +GStaticRecMutex session_lock_mutex = G_STATIC_REC_MUTEX_INIT; + +#define LOCK_SESSION \ +{\ + g_static_rec_mutex_lock(&session_lock_mutex);\ +} + +#define UNLOCK_SESSION \ +{\ + g_static_rec_mutex_unlock(&session_lock_mutex);\ +} + +int check_network() +{ + FW_LOGV("Start !!"); + + int res = 0; + int network_config = 0; + int network_status = 0; + int status_wifi = 0; + int status_3g = 0; + + if (vconf_get_int(VCONFKEY_NETWORK_CONFIGURATION_CHANGE_IND, &network_config) == -1) { + FW_LOGE("[connman] vconf_get_int ( VCONFKEY_NETWORK_CONFIGURATION_CHANGE_IND ) error !!"); + } else { + FW_LOGV("current network configuration : %d", network_config); + } + + if (network_config == 0) { + /*To do + * "0" means the network configuration is not set. + * It could be network connection is not open + * So, in this sample code, just check again more detail + */ + if (vconf_get_int(VCONFKEY_NETWORK_STATUS, &network_status) == -1) { + FW_LOGE("[connman] vconf_get_int( VCONFKEY_NETWORK_STATUS ) error !!"); + } else { + FW_LOGV("current network status : %d", network_status); + } + + if (network_status == VCONFKEY_NETWORK_OFF) { + FW_LOGV("[connman] current network connection is OFF !!"); + + if (vconf_get_int(VCONFKEY_NETWORK_WIFI_STATE, &status_wifi) == -1) { + FW_LOGE("[connman] vconf_get_int( VCONFKEY_NETWORK_WIFI_STATE ) error !!"); + } else { + FW_LOGV("wifi status : %d", status_wifi); + } + + if (vconf_get_int(VCONFKEY_NETWORK_CELLULAR_STATE, &status_3g) == -1) { + FW_LOGE("[connman] vconf_get_int( VCONFKEY_NETWORK_CELLULAR_STATE ) error !!"); + } else { + FW_LOGV("3G status : %d", status_3g); + } + + if (status_wifi == VCONFKEY_NETWORK_WIFI_NOT_CONNECTED) { + FW_LOGV("[connman] WIFI ON, but not connected !!"); + fw_network_status = NETWORK_OFF; + fw_network_type = NETWORK_WIFI_ON_NOT_CONNECTED; + res = 0; + } + + if (status_3g != VCONFKEY_NETWORK_CELLULAR_ON) { + FW_LOGV("[connman] 3g connection status is not available !!"); + fw_network_status = NETWORK_OFF; + fw_network_type = NETWORK_3G_OFF; + res = 0; + } + + else { + /* + * in this case, network connection will be connected sooner + * + * what ever you want to do + * in this sample code, wait until network connection open + * or just terminate the application in here! with popup! + */ + FW_LOGV("[connman] network connection is offline !!"); + fw_network_status = NETWORK_OFF; + fw_network_type = NETWORK_NONE; + } + } + } else { + /* network configuration is set */ + FW_LOGV("network configuration is set !!"); + + if (vconf_get_int(VCONFKEY_NETWORK_STATUS, &network_status) == -1) { + FW_LOGE("[connman] vconf_get_int( VCONFKEY_NETWORK_STATUS ) error !!"); + } else { + FW_LOGV("current network status : %d", network_status); + } + + if (network_status != VCONFKEY_NETWORK_OFF) { + fw_network_status = NETWORK_ON; + } else { + fw_network_status = NETWORK_OFF; + } + + if (vconf_get_int(VCONFKEY_NETWORK_WIFI_STATE, &status_wifi) == -1) { + FW_LOGE("[connman] vconf_get_int( VCONFKEY_NETWORK_WIFI_STATE ) error !!"); + } else { + FW_LOGV("wifi status : %d", status_wifi); + } + + if (vconf_get_int(VCONFKEY_NETWORK_CELLULAR_STATE, &status_3g) == -1) { + FW_LOGE("[connman] vconf_get_int( VCONFKEY_NETWORK_CELLULAR_STATE ) error !!"); + } else { + FW_LOGV("3G status : %d", status_3g); + } + + if ((status_wifi == VCONFKEY_NETWORK_WIFI_CONNECTED) || (status_3g == VCONFKEY_NETWORK_CELLULAR_ON)) { + fw_network_status = NETWORK_ON; + if ((status_wifi == VCONFKEY_NETWORK_WIFI_CONNECTED) && (status_3g == VCONFKEY_NETWORK_CELLULAR_ON)) { + fw_network_type = NETWORK_WIFI_3G_ON; + } else if ((status_wifi == VCONFKEY_NETWORK_WIFI_CONNECTED) && (status_3g != VCONFKEY_NETWORK_CELLULAR_ON)) { + fw_network_type = NETWORK_WIFI_ON; + } else if ((status_wifi != VCONFKEY_NETWORK_WIFI_CONNECTED) && (status_3g == VCONFKEY_NETWORK_CELLULAR_ON)) { + fw_network_type = NETWORK_3G_ON; + } + } + + FW_LOGV("fw_network_status : %d, fw_network_type : %d", fw_network_status, fw_network_type); + + res = 1; + } + + return res; +} + +void network_connection_cb(keynode_t *node, void *data) +{ + FW_LOGV("Start !!"); + + char *vkey = NULL; + int network_status = 0; + int status_3g = 0; + int status_wifi = 0; + + FW_NETWORK_STATUS prev_fw_network_status = fw_network_status; + + /* LOCK_SESSION */ + + /* get VCONFKEY */ + vkey = vconf_keynode_get_name(node); + FW_LOGV("vkey : %s", vkey); + + network_status = vconf_keynode_get_int(node); + FW_LOGV("network status : %d", network_status); + + switch (network_status) { + case VCONFKEY_NETWORK_OFF: + { + /* + * network connection is off + * halt the all action, for example reset socket, close application, just wait until connected + * in this sample, close the application + */ + FW_LOGV("network connection is off !!"); + + FW_LOGV("network_cancel_callback_fn() : Start !!"); + network_cancel_callback_fn(1); + FW_LOGV("network_cancel_callback_fn() : End !!"); + + if (fw_network_status == NETWORK_ON) { + network_off_callback_fn(0, NULL); + } + + fw_network_status = NETWORK_OFF; + fw_network_type = NETWORK_NONE; + + /* UNLOCK_SESSION */ + } + break; + case VCONFKEY_NETWORK_CELLULAR: + { + fw_network_status = NETWORK_ON; + + if (vconf_get_int(VCONFKEY_NETWORK_CELLULAR_STATE, &status_3g) == -1) { + FW_LOGE("[connman] vconf_get_int( VCONFKEY_NETWORK_CELLULAR_STATE ) error !!"); + } else { + FW_LOGV("3G status : %d", status_3g); + } + + if (status_3g != VCONFKEY_NETWORK_CELLULAR_ON) { + FW_LOGV("3g connection is off !!"); + + FW_LOGV("network_cancel_callback_fn() : Start !!"); + network_cancel_callback_fn(1); + FW_LOGV("network_cancel_callback_fn() : End !!"); + + fw_network_type = NETWORK_3G_OFF; + } else { + FW_LOGV("3g connection is on !!"); + + fw_network_type = NETWORK_3G_ON; + } + + /* UNLOCK_SESSION */ + } + break; + case VCONFKEY_NETWORK_WIFI: + { + fw_network_status = NETWORK_ON; + + if (vconf_get_int(VCONFKEY_NETWORK_WIFI_STATE, &status_wifi) == -1) { + FW_LOGE("[connman] vconf_get_int( VCONFKEY_NETWORK_WIFI_STATE ) error !!"); + } else { + FW_LOGV("WIFI status : %d", status_wifi); + } + + if (status_wifi == VCONFKEY_NETWORK_WIFI_CONNECTED) { + FW_LOGV("wifi connected !!"); + + fw_network_type = NETWORK_WIFI_ON; + /* todo : request re-sending message to engine */ + } else if (status_wifi == VCONFKEY_NETWORK_WIFI_NOT_CONNECTED) { + FW_LOGV("wifi on, but not connected !!"); + + fw_network_type = NETWORK_WIFI_ON_NOT_CONNECTED; + /* todo : send msg to user (connection retry) */ + } else { + FW_LOGV("wifi not connected !!"); + + FW_LOGV("network_cancel_callback_fn() : Start !!"); + network_cancel_callback_fn(1); + FW_LOGV("network_cancel_callback_fn() : End !!"); + + fw_network_type = NETWORK_WIFI_OFF; + } + + /* UNLOCK_SESSION */ + } + break; + default: + /* UNLOCK_SESSION */ + break; + } + + FW_LOGV("network connection is connected, type : %d", network_status); + + FW_LOGV("network_status_callback_fn() : Start !!"); + network_status_callback_fn(1); + FW_LOGV("network_status_callback_fn() : End !!"); + + if (prev_fw_network_status == NETWORK_OFF) { + if (fw_network_status == NETWORK_ON) { + network_on_callback_fn(0, NULL); + } + } else { /* prev_fw_network_status == NETWORK_ON */ + if (fw_network_status == NETWORK_OFF) { + network_off_callback_fn(0, NULL); + } + } + + FW_LOGV("End !!"); + + return; +} + +void network_configuration_handler(keynode_t *node, void *data) +{ + /* change ip/proxy value */ + FW_LOGV("[%s] Start !!", __func__); + + char *vkey = NULL; +/* char *ip = NULL; + char *proxy = NULL;*/ + int network_config = 0; + + /* LOCK_SESSION */ + + /* get VCONFKEY */ + vkey = vconf_keynode_get_name(node); + FW_LOGV("vkey : %s", __func__, vkey); + + network_config = vconf_keynode_get_int(node); + FW_LOGV("network configuration : %d", __func__, network_config); + + switch (network_config) { + case 1: /* connect network */ + { + FW_LOGV("network configuration is set !!"); + + FW_LOGV("network_status_callback_fn() : Start !!"); + network_status_callback_fn(1); + FW_LOGV("network_status_callback_fn() : End !!"); + + /* UNLOCK_SESSION */ + } + break; + case 0: /* disconnect network */ + { + FW_LOGV("network configuration is not set !!"); + + FW_LOGV("network_cancel_callback_fn() : Start !!"); + network_cancel_callback_fn(1); + FW_LOGV("network_cancel_callback_fn() : End !!"); + + FW_LOGV("network_status_callback_fn() : Start !!"); + network_status_callback_fn(1); + FW_LOGV("network_status_callback_fn() : End !!"); + + /* UNLOCK_SESSION */ + } + break; + default: + break; + } + + FW_LOGV("[%s] End !!", __func__); +} + +int get_net_status() +{ + return fw_network_status; +} + +int get_net_type() +{ + return fw_network_type; +} + +char *get_ConnMan_proxy() +{ + return vconf_get_str(VCONFKEY_NETWORK_PROXY); +} + +char *get_ConnMan_ip() +{ + return vconf_get_str(VCONFKEY_NETWORK_IP); +} + +void init_network() +{ + fw_network_status = NETWORK_UNKNOWN; + fw_network_type = NETWORK_NONE; +} + +#endif diff --git a/fw-plugin/slp-sysnoti-plugIn/src/SLP_SAN.c b/fw-plugin/slp-sysnoti-plugIn/src/SLP_SAN.c new file mode 100755 index 0000000..cbe9068 --- /dev/null +++ b/fw-plugin/slp-sysnoti-plugIn/src/SLP_SAN.c @@ -0,0 +1,394 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Seokgil Kang + */ + +#include +#include "MapiTransport.h" +#include "MapiControl.h" +#include "MapiMessage.h" +#include "MapiStorage.h" +#include "MsgTypes.h" +#include +#include + +#include "SLP_CallBack.h" + +#include "SLP_SAN.h" +#include "agent-framework/PlatformMonitor/EXT_PMCI_Struct.h" + +/* for log */ +#include "agent-framework/Utility/fw_log.h" +#define LOG_TAG "PLUGIN_PM_SLP_SAN" + +static int register_syncml_msg_callback(); + +static void check_msg_server_callback(keynode_t *node, void *data); + +static void incomming_syncml_msg_callback(MSG_HANDLE_T hMsgHandle, MSG_SYNCML_MESSAGE_TYPE_T msgType, const char *pPushBody, int PushBodyLen, const char *wspHeader, int wspHeaderLen, void *pUserParam); + +static void operation_syncml_msg_callback(MSG_HANDLE_T hMsgHandle, int msgId, int extId, void *pUserParam); + +static MSG_HANDLE_T msg_handle = NULL; + +int start_san() +{ + FW_LOGV("Start !!"); + + int res = 1; + int msg_key = 0; + + MSG_ERROR_T err = MSG_SUCCESS; + + if (vconf_get_bool(VCONFKEY_MSG_SERVER_READY, &msg_key) == 0) { + if (msg_key == 1) { + FW_LOGV("msg server is ready !!"); + + err = msg_open_msg_handle(&msg_handle); + if (err != MSG_SUCCESS) { + FW_LOGE("msg_open_msg_handle() fail [%d] !!", err); + res = -1; + goto return_part; + } else { + FW_LOGV("msg_open_msg_handle() success !!"); + + res = register_syncml_msg_callback(); + if (res != 1) { + FW_LOGE("register_syncml_msg_callback() fail !!"); + + err = msg_close_msg_handle(&msg_handle); + if (err != MSG_SUCCESS) { + FW_LOGE("msg_close_msg_handle() fail !!"); + res = -1; + goto return_part; + } else { + FW_LOGV("msg_close_msg_handle() success !!"); + msg_handle = NULL; + res = -1; + goto return_part; + } + } else { + FW_LOGV("register_syncml_msg_callback() success !!"); + } + } + } else { + FW_LOGE("msg server is not ready !!"); + + if (vconf_notify_key_changed((char *)VCONFKEY_MSG_SERVER_READY, check_msg_server_callback, NULL) != 0) { + FW_LOGE("vconf_notify_key_changed( VCONFKEY_MSG_SERVER_READY ) fail !!"); + res = -1; + goto return_part; + } else { + FW_LOGV("register vconf callback !!"); + } + } + } else { + FW_LOGE("vconf_get_bool ( VCONFKEY_MSG_SERVER_READY ) fail !!"); + res = -1; + goto return_part; + } + +return_part: + + FW_LOGV("End !!"); + + return res; +} + +int end_san() +{ + FW_LOGV("Start !!"); + + int res = 1; + MSG_ERROR_T err = MSG_SUCCESS; + + err = msg_close_msg_handle(&msg_handle); + if (err != MSG_SUCCESS) { + FW_LOGE("msg_close_msg_handle() fail !!"); + res = -1; + goto return_part; + } else { + FW_LOGV("msg_close_msg_handle() success !!"); + msg_handle = NULL; + } + +return_part: + + FW_LOGV("End !!"); + + return res; +} + +int add_san_message(void *add_item) +{ + FW_LOGV("Start !!"); + + int res = 1; + MSG_ERROR_T err = MSG_SUCCESS; + MSG_SYNCML_MESSAGE_S push_san_msg; + pmci_san_message_t *add_msg = (pmci_san_message_t *) add_item; + + push_san_msg.extId = add_msg->extId; + push_san_msg.pinCode = add_msg->pinCode; + push_san_msg.msg = msg_new_message(); + + msg_set_folder_id(push_san_msg.msg, MSG_INBOX_ID); + msg_set_message_type(push_san_msg.msg, MSG_TYPE_SMS_SYNCML); + msg_set_network_status(push_san_msg.msg, MSG_NETWORK_RECEIVED); + msg_set_direction_info(push_san_msg.msg, MSG_DIRECTION_TYPE_MT); + msg_add_address(push_san_msg.msg, "+1004", MSG_RECIPIENTS_TYPE_TO); + + /* received time */ + time_t t = time(NULL); + time_t recv_utf_time = time(&t); + msg_set_time(push_san_msg.msg, recv_utf_time); + + if (add_msg->msgData == NULL) { + FW_LOGE("msgData is NULL !!"); + res = -1; + goto return_part; + } + + err = msg_sms_set_message_body(push_san_msg.msg, add_msg->msgData, strlen(add_msg->msgData)); + if (err != MSG_SUCCESS) { + FW_LOGE("msg_sms_set_message_body() fail !!"); + res = -1; + goto return_part; + } else { + FW_LOGV("msg_sms_set_message_body() success !!"); + } + + if (msg_handle == NULL) { + FW_LOGE("msg_handle is NULL !!"); + res = -1; + goto return_part; + } + + err = msg_add_syncml_message(msg_handle, &push_san_msg); + if (err != MSG_SUCCESS) { + FW_LOGE("msg_add_syncml_message() fail !!"); + res = -1; + goto return_part; + } else { + FW_LOGV("msg_add_syncml_message() success !!"); + } + +return_part: + msg_release_message(&(push_san_msg.msg)); + + FW_LOGV("End !!"); + + return res; +} + +int remove_san_message(int remove_item_id) +{ + FW_LOGV("Start !!"); + + int res = 1; + MSG_ERROR_T err = MSG_SUCCESS; + + if (msg_handle == NULL) { + FW_LOGE("msg_handle is NULL !!"); + res = -1; + goto return_part; + } + + err = msg_delete_message(msg_handle, remove_item_id); + if (err != MSG_SUCCESS) { + FW_LOGE("msg_delete_message() fail !!"); + res = -1; + goto return_part; + } else { + FW_LOGV("msg_delete_message() success !!"); + } + +return_part: + + FW_LOGV("End !!"); + + return res; +} + +static int register_syncml_msg_callback() +{ + FW_LOGV("Start !!"); + + int res = 1; + MSG_ERROR_T err = MSG_SUCCESS; + + if (msg_handle == NULL) { + FW_LOGE("msg_handle is NULL !!"); + res = -1; + goto return_part; + } + + err = msg_reg_syncml_message_callback(msg_handle, incomming_syncml_msg_callback, NULL); + if (err != MSG_SUCCESS) { + FW_LOGE("Register SyncML Incoming Callback fail [%d] !!", err); + res = -1; + goto return_part; + } else { + FW_LOGV("Register SyncML Incoming Callback success !!"); + } + + err = msg_reg_syncml_message_operation_callback(msg_handle, operation_syncml_msg_callback, NULL); + if (err != MSG_SUCCESS) { + FW_LOGE("Register SyncML operation Callback fail [%d] !!", err); + res = -1; + goto return_part; + } else { + FW_LOGV("Register SyncML operation Callback success !!"); + } + +return_part: + + FW_LOGV("End !!"); + + return res; +} + +static void check_msg_server_callback(keynode_t *node, void *data) +{ + FW_LOGV("Start !!"); + + int res = 1; + int msg_key = 0; + MSG_ERROR_T err = MSG_SUCCESS; + + if (vconf_get_bool(VCONFKEY_MSG_SERVER_READY, &msg_key) == 0) { + if (msg_key == 1) { + FW_LOGV("msg server is ready !!"); + + if (msg_handle == NULL) { + err = msg_open_msg_handle(&msg_handle); + if (err != MSG_SUCCESS) { + FW_LOGE("msg_open_msg_handle() fail [%d] !!", err); + goto return_part; + } else { + FW_LOGV("msg_open_msg_handle() success !!"); + + res = register_syncml_msg_callback(); + if (res != 1) { + FW_LOGE("register_syncml_msg_callback() fail !!"); + goto return_part; + } else { + FW_LOGV("register_syncml_msg_callback() success !!"); + } + } + } else { + FW_LOGV("callback is already registered !!"); + } + } else { + FW_LOGV("msg server is not ready !!"); + } + } else { + FW_LOGE("vconf_get_bool ( VCONFKEY_MSG_SERVER_READY ) fail !!"); + goto return_part; + } + +return_part: + + FW_LOGV("End !!"); + + return; +} + +static void incomming_syncml_msg_callback(MSG_HANDLE_T hMsgHandle, MSG_SYNCML_MESSAGE_TYPE_T msgType, const char *pPushBody, int PushBodyLen, const char *wspHeader, int wspHeaderLen, void *pUserParam) +{ + FW_LOGV("Start !!"); + + pmci_san_incoming_t *san_incoming = (pmci_san_incoming_t *) calloc(1, sizeof(pmci_san_incoming_t)); + if (san_incoming == NULL) { + FW_LOGE("pmci_san_incomming_t calloc error !!"); + /* todo : exception handling */ + return; + } + FW_LOGV("push body : %s, push body len : %d", pPushBody, PushBodyLen); + FW_LOGV("wsp header : %s, wsp header len : %d", wspHeader, wspHeaderLen); + + if ((PushBodyLen > 0) && (pPushBody != NULL)) { + san_incoming->msgBody = strdup(pPushBody); + san_incoming->msgSize = PushBodyLen; + } else { + san_incoming->msgBody = 0; + san_incoming->msgSize = 0; + } + + switch (msgType) { + case DS_NOTIFICATION: + { + FW_LOGV("MsgNoti ( msgType = 3, DS_NOTIFICATION ) detected.\n"); + san_incoming->version = SAN_VERSION_12; + } + break; + case DS_WBXML: + { + FW_LOGV("MsgNoti ( msgType = 4, DS_WBXML ) detected.\n"); + san_incoming->version = SAN_VERSION_11; + } + break; + case OTHERS: + default: + FW_LOGV("Unknown MsgNoti ( %d ) detected.\n", msgType); + break; + } + + syncml_san_incoming_callback_fn(0, (void *)san_incoming); + + FW_LOGV("End !!"); +} + +static void operation_syncml_msg_callback(MSG_HANDLE_T hMsgHandle, int msgId, int extId, void *pUserParam) +{ + FW_LOGV("Start !!"); + + pmci_san_operation_t *san_operation = (pmci_san_operation_t *) calloc(1, sizeof(pmci_san_operation_t)); + if (san_operation == NULL) { + FW_LOGE("pmci_san_operation_t calloc error !!"); + /* todo : exception handling */ + return; + } + + san_operation->msgId = msgId; + FW_LOGV("msgId : %d", msgId); + + san_operation->extId = extId; + FW_LOGV("extId : %d", extId); + + san_operation->user_param = pUserParam; + + syncml_san_operation_callback_fn(0, (void *)san_operation); + + FW_LOGV("End !!"); +} diff --git a/fw-plugin/vcalendar-plugIn/.cproject b/fw-plugin/vcalendar-plugIn/.cproject new file mode 100755 index 0000000..3c36d31 --- /dev/null +++ b/fw-plugin/vcalendar-plugIn/.cproject @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/fw-plugin/vcalendar-plugIn/.project b/fw-plugin/vcalendar-plugIn/.project new file mode 100755 index 0000000..110bda3 --- /dev/null +++ b/fw-plugin/vcalendar-plugIn/.project @@ -0,0 +1,78 @@ + + + vcalendar-plugIn + + + + + + com.samsung.slp2.SboxBuilder + + + com.samsung.slp2.SboxBuilder.needConfigure + true + + + org.eclipse.cdt.core.errorOutputParser + org.eclipse.cdt.core.MakeErrorParser;com.samsung.limo.SboxGCCErrorParser;org.eclipse.cdt.core.GLDErrorParser;org.eclipse.cdt.core.GASErrorParser; + + + org.eclipse.cdt.make.core.append_environment + true + + + org.eclipse.cdt.make.core.build.arguments + + + + org.eclipse.cdt.make.core.build.command + make + + + org.eclipse.cdt.make.core.build.target.auto + all + + + org.eclipse.cdt.make.core.build.target.clean + clean + + + org.eclipse.cdt.make.core.build.target.inc + all + + + org.eclipse.cdt.make.core.enableAutoBuild + true + + + org.eclipse.cdt.make.core.enableCleanBuild + true + + + org.eclipse.cdt.make.core.enableFullBuild + true + + + org.eclipse.cdt.make.core.enabledIncrementalBuild + true + + + org.eclipse.cdt.make.core.environment + + + + org.eclipse.cdt.make.core.stopOnError + true + + + org.eclipse.cdt.make.core.useDefaultBuildCmd + true + + + + + + org.eclipse.cdt.core.cnature + com.samsung.slp2.cnature + + diff --git a/fw-plugin/vcalendar-plugIn/CMakeLists.src b/fw-plugin/vcalendar-plugIn/CMakeLists.src new file mode 100755 index 0000000..04ce4aa --- /dev/null +++ b/fw-plugin/vcalendar-plugIn/CMakeLists.src @@ -0,0 +1 @@ +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src SRCS) diff --git a/fw-plugin/vcalendar-plugIn/CMakeLists.sub b/fw-plugin/vcalendar-plugIn/CMakeLists.sub new file mode 100755 index 0000000..c8b177d --- /dev/null +++ b/fw-plugin/vcalendar-plugIn/CMakeLists.sub @@ -0,0 +1,37 @@ +################################################################################# +# THIS FILE IS CREATED AUTOMATICALLY. DO NOT DELETE OR MODIFY THIS FILE. +################################################################################# + +INCLUDE(CMakeLists.src) + +## PROJECT NAME +PROJECT(plugin-dc-vcalendar C) + +## PACKAGE CONFIG +SET(SLP_PKGCONFIG_LIST "calendar glib-2.0") + +## INCLUDES +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../../framework/include) + +## DEFINITIONS +ADD_DEFINITIONS("-DAPP_DIR=\"${CMAKE_INSTALL_PREFIX}\"") + +## LIBRARY PATH +SET(SLP_LD_PATH_FLAGS "") + +## LIBRARY +SET(SLP_LD_FLAGS "") + +## DEBUG +SET(SLP_DEBUG_FLAGS "-g") + +## OPTIMIZATION +SET(SLP_OPT_FLAGS "-O0") + +## COMPILER FLAGS +SET(SLP_COMPILER_FLAGS "") + +## LINKER FLAGS +SET(SLP_LINKER_FLAGS "") + diff --git a/fw-plugin/vcalendar-plugIn/CMakeLists.txt b/fw-plugin/vcalendar-plugIn/CMakeLists.txt new file mode 100755 index 0000000..711be71 --- /dev/null +++ b/fw-plugin/vcalendar-plugIn/CMakeLists.txt @@ -0,0 +1,33 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) + +# INCLUDE SUB CMAKELIST FILE +INCLUDE(CMakeLists.sub) + +SET(RESOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/res") + +INCLUDE(FindPkgConfig) +pkg_check_modules(pkgs_plugin_vcalendar REQUIRED ${SLP_PKGCONFIG_LIST}) + +FOREACH(flag ${pkgs_plugin_vcalendar_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(CMAKE_C_FLAGS "${SLP_DEBUG_FLAGS} ${SLP_OPT_FLAGS} ${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} ${SLP_COMPILER_FLAGS}") +SET(CMAKE_CXX_FLAGS "${SLP_DEBUG_FLAGS} ${SLP_OPT_FLAGS} ${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} ${SLP_COMPILER_FLAGS}") + +ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS}) + +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_plugin_vcalendar_LDFLAGS} ${SLP_LD_PATH_FLAGS} ${SLP_LD_FLAGS} ${SLP_LINKER_FLAGS} sync-agent-framework) + +# INSTALL +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION lib) +#INSTALL(DIRECTORY ${RESOURCE_DIR}/data DESTINATION share) + +#added by KTS for install to the system +#CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY) +#INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc DESTINATION lib/pkgconfig) + + +# INCLUDE LAYOUT DIRECTORY +# ADD_SUBDIRECTORY(layout) +#ADD_SUBDIRECTORY(res/locale) diff --git a/fw-plugin/vcalendar-plugIn/include/IN_DataStore_Info_Vcalendar.h b/fw-plugin/vcalendar-plugIn/include/IN_DataStore_Info_Vcalendar.h new file mode 100755 index 0000000..14e141c --- /dev/null +++ b/fw-plugin/vcalendar-plugIn/include/IN_DataStore_Info_Vcalendar.h @@ -0,0 +1,248 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Wook Choi + */ + +#ifndef IN_DATASTORE_INFO_VCALENDAR_H_ +#define IN_DATASTORE_INFO_VCALENDAR_H_ + +#define VCALENDAR_TYPE "text/x-vcalendar" +#define VCALENDAR_VERSION "1.0" + +typedef enum { + VCALENDAR_FIELD_BEGIN = 10, + VCALENDAR_FIELD_END, + VCALENDAR_FIELD_VERSION, + VCALENDAR_FIELD_AALARM, + VCALENDAR_FIELD_ACTION, + VCALENDAR_FIELD_ATTACH, + VCALENDAR_FIELD_ATTENDEE, + VCALENDAR_FIELD_CALSCALE, + VCALENDAR_FIELD_CATEGORIES, + VCALENDAR_FIELD_CLASS, + VCALENDAR_FIELD_COMMENT, + VCALENDAR_FIELD_COMPLETED, + VCALENDAR_FIELD_CONTACT, + VCALENDAR_FIELD_CREATED, + VCALENDAR_FIELD_DALARM, + VCALENDAR_FIELD_DAYLIGHT, + VCALENDAR_FIELD_DCREATED, + VCALENDAR_FIELD_DESCRIPTION, + VCALENDAR_FIELD_DTEND, + VCALENDAR_FIELD_DTSTAMP, + VCALENDAR_FIELD_DTSTART, + VCALENDAR_FIELD_DUE, + VCALENDAR_FIELD_DURATION, + VCALENDAR_FIELD_EXDATE, + VCALENDAR_FIELD_EXRULE, + VCALENDAR_FIELD_FREEBUSY, + VCALENDAR_FIELD_GEO, + VCALENDAR_FIELD_LAST_MODIFIED, + VCALENDAR_FIELD_LOCATION, + VCALENDAR_FIELD_MALARM, + VCALENDAR_FIELD_METHOD, + VCALENDAR_FIELD_ORGANIZER, + VCALENDAR_FIELD_PALARM, + VCALENDAR_FIELD_PERCENT_COMPLETE, + VCALENDAR_FIELD_PRIORITY, + VCALENDAR_FIELD_PRODID, + VCALENDAR_FIELD_RDATE, + VCALENDAR_FIELD_RECURRENCE_ID, + VCALENDAR_FIELD_RELATED_TO, + VCALENDAR_FIELD_REPEAT, + VCALENDAR_FIELD_REQUEST_STATUS, + VCALENDAR_FIELD_RESOURCES, + VCALENDAR_FIELD_RNUM, + VCALENDAR_FIELD_RRULE, + VCALENDAR_FIELD_SEQUENCE, + VCALENDAR_FIELD_STANDARD, + VCALENDAR_FIELD_STATUS, + VCALENDAR_FIELD_SUMMARY, + VCALENDAR_FIELD_TRANSP, + VCALENDAR_FIELD_TRIGGER, + VCALENDAR_FIELD_TZ, + VCALENDAR_FIELD_TZID, + VCALENDAR_FIELD_TZNAME, + VCALENDAR_FIELD_TZOFFSETFROM, + VCALENDAR_FIELD_TZOFFSETTO, + VCALENDAR_FIELD_TZURL, + VCALENDAR_FIELD_URL, + VCALENDAR_FIELD_UID, + VCALENDAR_FIELD_VALARM, + VCALENDAR_FIELD_VCALENDAR, + VCALENDAR_FIELD_VEVENT, + VCALENDAR_FIELD_VFREEBUSY, + VCALENDAR_FIELD_VJOURNAL, + VCALENDAR_FIELD_VTIMEZONE, + VCALENDAR_FIELD_VTODO, + VCALENDAR_FIELD_X_FUNAMBOL_ALLDAY, + +} VCALENDAR_FIELD; + +typedef enum { + VCALENDAR_FIELD_BEGIN_END_VCALENDAR = 100, + VCALENDAR_FIELD_BEGIN_END_VEVENT, + VCALENDAR_FIELD_BEGIN_END_VTODO, + VCALENDAR_FIELD_BEGIN_END_VJOURNAL, + VCALENDAR_FIELD_BEGIN_END_VFREEBUSY, + VCALENDAR_FIELD_BEGIN_END_VTIMEZONE, + VCALENDAR_FIELD_BEGIN_END_VALARM, + VCALENDAR_FIELD_BEGIN_END_STANDARD, + VCALENDAR_FIELD_BEGIN_END_DAYLIGHT, + +} VCALENDAR_FIELD_BEGIN_END_SUB; + +typedef enum { + VCALENDAR_FIELD_CATEGORIES_APPOINTMENT = 200, + VCALENDAR_FIELD_CATEGORIES_HOLIDAY, + VCALENDAR_FIELD_CATEGORIES_BUSINESS, + VCALENDAR_FIELD_CATEGORIES_SPECIAL_OCCASION, + VCALENDAR_FIELD_CATEGORIES_IMPORTANT, + VCALENDAR_FIELD_CATEGORIES_BIRTHDAY, + VCALENDAR_FIELD_CATEGORIES_MISSCELLANEOUS, + +} VCALENDAR_FIELD_CATEGORIES_SUB; + +typedef enum { + VCALENDAR_FIELD_STATUS_NEEDS_ACTION = 300, + VCALENDAR_FIELD_STATUS_COMPLETED, + +} VCALENDAR_FIELD_STATUS_SUB; + +typedef struct VCALENDAR_FIELD_LIST VCALENDAR_FIELD_LIST; +struct VCALENDAR_FIELD_LIST { + int field_enum; + char *field_name; +}; + +static VCALENDAR_FIELD_LIST vcalendar_field_list[] = { + {VCALENDAR_FIELD_BEGIN, "BEGIN"}, + {VCALENDAR_FIELD_END, "END"}, + {VCALENDAR_FIELD_VERSION, "VERSION"}, + {VCALENDAR_FIELD_AALARM, "AALARM"}, + {VCALENDAR_FIELD_ACTION, "ACTION"}, + {VCALENDAR_FIELD_ATTACH, "ATTACH"}, + {VCALENDAR_FIELD_ATTENDEE, "ATTENDEE"}, + {VCALENDAR_FIELD_CALSCALE, "CALSCALE"}, + {VCALENDAR_FIELD_CATEGORIES, "CATEGORIES"}, + {VCALENDAR_FIELD_CLASS, "CLASS"}, + {VCALENDAR_FIELD_COMMENT, "COMMENT"}, + {VCALENDAR_FIELD_COMPLETED, "COMPLETED"}, + {VCALENDAR_FIELD_CONTACT, "CONTACT"}, + {VCALENDAR_FIELD_CREATED, "CREATED"}, + {VCALENDAR_FIELD_DALARM, "DALARM"}, + {VCALENDAR_FIELD_DAYLIGHT, "DAYLIGHT"}, + {VCALENDAR_FIELD_DCREATED, "DCREATED"}, + {VCALENDAR_FIELD_DESCRIPTION, "DESCRIPTION"}, + {VCALENDAR_FIELD_DTEND, "DTEND"}, + {VCALENDAR_FIELD_DTSTAMP, "DTSTAMP"}, + {VCALENDAR_FIELD_DTSTART, "DTSTART"}, + {VCALENDAR_FIELD_DUE, "DUE"}, + {VCALENDAR_FIELD_DURATION, "DURATION"}, + {VCALENDAR_FIELD_EXDATE, "EXDATE"}, + {VCALENDAR_FIELD_EXRULE, "EXRULE"}, + {VCALENDAR_FIELD_FREEBUSY, "FREEBUSY"}, + {VCALENDAR_FIELD_GEO, "GEO"}, + {VCALENDAR_FIELD_LAST_MODIFIED, "LAST-MODIFIED"}, + {VCALENDAR_FIELD_LOCATION, "LOCATION"}, + {VCALENDAR_FIELD_MALARM, "MALARM"}, + {VCALENDAR_FIELD_METHOD, "METHOD"}, + {VCALENDAR_FIELD_ORGANIZER, "ORGANIZER"}, + {VCALENDAR_FIELD_PALARM, "PALARM"}, + {VCALENDAR_FIELD_PERCENT_COMPLETE, "PERCENT-COMPLETE"}, + {VCALENDAR_FIELD_PRIORITY, "PRIORITY"}, + {VCALENDAR_FIELD_PRODID, "PRODID"}, + {VCALENDAR_FIELD_RDATE, "RDATE"}, + {VCALENDAR_FIELD_RECURRENCE_ID, "RECURRENCE-ID"}, + {VCALENDAR_FIELD_RELATED_TO, "RELATED-TO"}, + {VCALENDAR_FIELD_REPEAT, "REPEAT"}, + {VCALENDAR_FIELD_REQUEST_STATUS, "REQUEST-STATUS"}, + {VCALENDAR_FIELD_RESOURCES, "RESOURCES"}, + {VCALENDAR_FIELD_RNUM, "RNUM"}, + {VCALENDAR_FIELD_RRULE, "RRULE"}, + {VCALENDAR_FIELD_SEQUENCE, "SEQUENCE"}, + {VCALENDAR_FIELD_STANDARD, "STANDARD"}, + {VCALENDAR_FIELD_STATUS, "STATUS"}, + {VCALENDAR_FIELD_SUMMARY, "SUMMARY"}, + {VCALENDAR_FIELD_TRANSP, "TRANSP"}, + {VCALENDAR_FIELD_TRIGGER, "TRIGGER"}, + {VCALENDAR_FIELD_TZ, "TZ"}, + {VCALENDAR_FIELD_TZID, "TZID"}, + {VCALENDAR_FIELD_TZNAME, "TZNAME"}, + {VCALENDAR_FIELD_TZOFFSETFROM, "TZOFFSETFROM"}, + {VCALENDAR_FIELD_TZOFFSETTO, "TZOFFSETTO"}, + {VCALENDAR_FIELD_TZURL, "TZURL"}, + {VCALENDAR_FIELD_URL, "URL"}, + {VCALENDAR_FIELD_UID, "UID"}, + {VCALENDAR_FIELD_VALARM, "VALARM"}, + {VCALENDAR_FIELD_VCALENDAR, "VCALENDAR"}, + {VCALENDAR_FIELD_VEVENT, "VEVENT"}, + {VCALENDAR_FIELD_VFREEBUSY, "VFREEBUSY"}, + {VCALENDAR_FIELD_VJOURNAL, "VJOURNAL"}, + {VCALENDAR_FIELD_VTIMEZONE, "VTIMEZONE"}, + {VCALENDAR_FIELD_VTODO, "VTODO"}, + {VCALENDAR_FIELD_X_FUNAMBOL_ALLDAY, "X-FUNAMBOL-ALLDAY"} +}; + +static VCALENDAR_FIELD_LIST vcalendar_field_list_begin_end[] = { + {VCALENDAR_FIELD_BEGIN_END_VCALENDAR, "VCALENDAR"}, + {VCALENDAR_FIELD_BEGIN_END_VEVENT, "VEVENT"}, + {VCALENDAR_FIELD_BEGIN_END_VTODO, "VTODO"}, + {VCALENDAR_FIELD_BEGIN_END_VJOURNAL, "VJOURNAL"}, + {VCALENDAR_FIELD_BEGIN_END_VFREEBUSY, "VFREEBUSY"}, + {VCALENDAR_FIELD_BEGIN_END_VTIMEZONE, "VTIMEZONE"}, + {VCALENDAR_FIELD_BEGIN_END_VALARM, "VALARM"}, + {VCALENDAR_FIELD_BEGIN_END_STANDARD, "STANDARD"}, + {VCALENDAR_FIELD_BEGIN_END_DAYLIGHT, "DAYLIGHT"} +}; + +static VCALENDAR_FIELD_LIST vcalendar_field_list_version[] = { + {-1, VCALENDAR_VERSION} +}; + +static VCALENDAR_FIELD_LIST vcalendar_field_list_categories[] = { + {VCALENDAR_FIELD_CATEGORIES_APPOINTMENT, "APPOINTMENT"}, + {VCALENDAR_FIELD_CATEGORIES_HOLIDAY, "HOLIDAY"}, + {VCALENDAR_FIELD_CATEGORIES_BUSINESS, "BUSINESS"}, + {VCALENDAR_FIELD_CATEGORIES_SPECIAL_OCCASION, "SPECIAL OCCASION"}, + {VCALENDAR_FIELD_CATEGORIES_IMPORTANT, "IMPORTANT"}, + {VCALENDAR_FIELD_CATEGORIES_BIRTHDAY, "BIRTHDAY"}, + {VCALENDAR_FIELD_CATEGORIES_MISSCELLANEOUS, "MISSCELLANEOUS"} +}; + +static VCALENDAR_FIELD_LIST vcalendar_field_list_status[] = { + {VCALENDAR_FIELD_STATUS_NEEDS_ACTION, "NEEDS ACTION"}, + {VCALENDAR_FIELD_STATUS_COMPLETED, "COMPLETED"} +}; + +#endif /* IN_DATASTORE_INFO_VCALENDAR_H_ */ diff --git a/fw-plugin/vcalendar-plugIn/include/encoding_util.h b/fw-plugin/vcalendar-plugIn/include/encoding_util.h new file mode 100755 index 0000000..ebab0ae --- /dev/null +++ b/fw-plugin/vcalendar-plugIn/include/encoding_util.h @@ -0,0 +1,255 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Seokgil Kang + */ + +#ifndef ENCODING_UTIL_H_ +#define ENCODING_UTIL_H_ + +#include +#include +#include + +#define QP_SIZE 76 +#define BASE64_SIZE 76 + +typedef enum { + EN_TYPE_NONE = 0, + EN_TYPE_QUOTED_PRINTABLE, + EN_TYPE_BASE64 +} ENCODING_TYPE; + +/* Quoted-Printable + * + * @example code +int main() +{ + char *src = "안녕하세요"; + char *encode_src; + int encode_src_len = 0; + char *decode_src; + int decode_src_len = 0; + + int res = encode_QP(src, strlen(src), &encode_src, &encode_src_len); + if (res != 0) + fprintf(stdout, "encode src : %s ( %d ) \n", encode_src, encode_src_len); + else + fprintf(stdout, "encode error !! \n"); + + res = decode_QP(encode_src, encode_src_len, &decode_src, &decode_src_len); + if (res != 0) + fprintf(stdout, "decode src : %s ( %d ) \n", decode_src, decode_src_len); + else + fprintf(stdout, "decode error !! \n"); + + return 0; +} + + */ + +/* + * @brief encode original source ( encoding type : quoted-printable ) + * @param[in] src original source + * @param[in] src_len length of original source + * @param[out] en_src encoded source + * @param[out] en_src_len length of encoded source + * @return operation result + * @retval 1 success + * @retval 0 fail + */ +int encode_QP(char *src, int src_len, char **en_src, int *en_src_len); + +/* + * @brief decode encoded source ( decoding type : quoted-printable ) + * @param[in] src encoded source + * @param[in] src_len length of encoded source + * @param[out] de_src decoded source ( original source ) + * @param[out] de_src_len length of decoded source + * @return operation result + * @retval 1 success + * @retval 0 fail + */ +int decode_QP(char *src, int src_len, char **de_src, int *de_src_len); + +/* Base64 + * + * @example code + + int main() +{ + char *src = "안녕하세요"; + char *encode_src; + int encode_src_len = 0; + char *decode_src; + int decode_src_len = 0; + + int res = encode_base64(src, strlen(src), &encode_src, &encode_src_len); + if (res != 0) + fprintf(stdout, "encode src : %s ( %d ) \n", encode_src, encode_src_len); + else + fprintf(stdout, "encode error !! \n"); + + res = decode_base64(encode_src, encode_src_len, &decode_src, &decode_src_len); + if (res != 0) + fprintf(stdout, "decode src : %s ( %d ) \n", decode_src, decode_src_len); + else + fprintf(stdout, "decode error !! \n"); + + return 0; +} + + */ + +/* + * @brief encode original source ( encoding type : base64 ) + * @param[in] src original source + * @param[in] src_len length of original source + * @param[out] en_src encoded source + * @param[out] en_src_len length of encoded source + * @return operation result + * @retval 1 success + * @retval 0 fail + */ +int encode_base64(char *src, int src_len, char **en_src, int *en_src_len); + +/* + * @brief decode encoded source ( decoding type : base64 ) + * @param[in] src encoded source + * @param[in] src_len length of encoded source + * @param[out] de_src decoded source ( original source ) + * @param[out] de_src_len length of decoded source + * @return operation result + * @retval 1 success + * @retval 0 fail + */ +int decode_base64(char *src, int src_len, char **de_src, int *de_src_len); + +/* + * @brief make the decoding process + * @param[in] src encoded source + * @param[in] src_len length of encoded source + * @param[out] de_src decoded source ( original source ) + * @param[out] de_src_len length of decoded source + * @return operation result + * @retval 1 success + * @retval 0 fail + * + * @example code + +int main() +{ + char *src = "..."; // decoded data + int src_len = strlen(src); + char *decode_src; + int decode_src_len = 0; + + int res = proc_decoding(src, src_len, &decode_src, &decode_src_len); + + if (res != 0) + fprintf(stdout, "decode src : \n%s\n", decode_src); + else + fprintf(stdout, "decode error !! \n"); + + if (decode_src != NULL) + free(decode_src); + + return 0; +} + */ +int proc_decoding(const char *src, int src_len, char **de_src, int *de_src_len); + +/* + * @brief encoded value is changed to the decoded value + * @param[in] type encoding type + * @param[in] value encoded value (end of string must be '\0' !!) + * ex) =EA=B9=80;=EC=B2=A0=EC=88=98;;;\0 + * @param[in] value_size length of encoded value + * @param[out] decode_str decoded string + * @param[out] decode_str_len length of decoded string + * @return operation result + * @ratval 1 success + * @retval 0 fail + * + * @example code + + int main() + { + char *data = "..."; // ex) ENCODING=QUOTED-PRINTABLE;CHARSET=UTF-8 + ENCODING_TYPE type = find_encoding_type((const char *)data); + + char *value = "..."; // ex) =EA=B9=80;=EC=B2=A0=EC=88=98;;;\0 + int value_size = strlen(value); + + int decode_str_len = 0; + char *decode_str = (char*)malloc(sizeof(char)*BUF_SIZE); // BUF_SIZE : user define + if (decode_str == NULL) { + // error process + } + memset(decode_str, 0x00, sizeof(char)*BUF_SIZE); + + int res = decode_value(type, value, data_size, &decode_str, &decode_str_len); + + if (res == 1) { + // success process + if (decode_str != NULL) + free(decode_str); + } else { + // error process + if (decode_str != NULL) + free(decode_str); + } + + return 0; + } + */ +int decode_value(ENCODING_TYPE type, const char *value, int value_size, char **decode_str, int *decode_str_len); + +/* + * @brief get encoding type for data + * @param[in] data vobject data + * @return encoding type + * @ratval >= 1 success + * @retval 0 fail + */ +ENCODING_TYPE find_encoding_type(const char *data); + +/* + * @brief check whether to exist this string, "ENCODING=" in the data + * @param[in] data vobject data + * @return operation result + * @retval 1 exist + * @retval 0 not exist + */ +int check_encoding_data(const char *data); + +#endif /* ENCODING_UTIL_H_ */ diff --git a/fw-plugin/vcalendar-plugIn/src/PlugIn_Interface.c b/fw-plugin/vcalendar-plugIn/src/PlugIn_Interface.c new file mode 100755 index 0000000..1d6c53c --- /dev/null +++ b/fw-plugin/vcalendar-plugIn/src/PlugIn_Interface.c @@ -0,0 +1,516 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#include +#include +#include + +#include "encoding_util.h" +#include "calendar-svc-provider.h" + +#include "IN_DataStore_Info_Vcalendar.h" + +/* for log */ +#include "agent-framework/Utility/fw_log.h" + +#include "agent-framework/PlugIn/DataConverter_Interface.h" + +#define LOG_TAG "PLUGIN_DC_VCALENDAR" + +static int __free_obj_field_info(Field_Info *field_list, int count); +static int __set_obj_field_info(Field_Info **field_list, int count, VCALENDAR_FIELD_LIST * input_list); +static DACI_RETURN __convert_service_error_to_common_error(cal_error err); +/* static void __print_obj_field_info(Field_Info *info, int count); */ + +DACI_RETURN Converter(const void *agent_data, void **service_data) +{ + FW_LOGV("[dc_vcalendar_plugIn] Start !!"); + + DACI_RETURN ret = DACI_SUCCESS; + int err = 0; + cal_struct *temp_service_data = 0; + const char *temp_agent_data = (const char *)agent_data; + + char *decoded_agent_data; + int decoded_agent_data_len = 0; + int agent_data_len = strlen(agent_data); + + /* Temporary fix for KIES vCalendar X-ALLDAY tag : START */ + int allday = 0; + if (strstr((char *)agent_data, "\r\nX-ALLDAY:SET")) + allday = 1; + /* Temporary fix for KIES vCalendar X-ALLDAY tag : END */ + + /* decoding */ + if (check_encoding_data(agent_data) == 1) { + err = proc_decoding(agent_data, agent_data_len, &decoded_agent_data, &decoded_agent_data_len); + if (err != 1) { + FW_LOGE("[dc_vcalendar_plugIn] proc_decoding() fail !!"); + return DACI_ERRORS; + } + + /* convert */ + err = calendar_svc_util_convert_vcs_to_event(decoded_agent_data, decoded_agent_data_len, &temp_service_data); + + /* free memory */ + if (decoded_agent_data != 0) + free(decoded_agent_data); + } else { + /* convert */ + err = calendar_svc_util_convert_vcs_to_event(temp_agent_data, strlen(temp_agent_data), &temp_service_data); + } + + if (err < CAL_SUCCESS) { + FW_LOGV("[dc_vcalendar_plugIn] calendar_svc_util_convert_vcs_to_event() Fail!\n"); + ret = __convert_service_error_to_common_error(err); + *service_data = 0; + } else { + /* Temporary fix for KIES vCalendar X-ALLDAY tag : START */ + if (allday) { + cal_struct *item = (cal_struct *) temp_service_data; + + FW_LOGI(" CAL_VALUE_INT_ALL_DAY_EVENT = %d ", calendar_svc_struct_get_int(item, CAL_VALUE_INT_ALL_DAY_EVENT)); + + if (!calendar_svc_struct_get_int(item, CAL_VALUE_INT_ALL_DAY_EVENT)) { + FW_LOGV("[Debug] X-ALLDAY flag set in vCalendar, but not in calendar service structure after conversion !!!"); + calendar_svc_struct_set_int(item, CAL_VALUE_INT_ALL_DAY_EVENT, 1); + } + } + /* Temporary fix for KIES vCalendar X-ALLDAY tag : END */ + + FW_LOGV("[dc_vcalendar_plugIn] calendar_svc_util_convert_vcs_to_event() Success!\n"); + *service_data = (void *)temp_service_data; + } + + FW_LOGV("[dc_vcalendar_plugIn] End !!"); + return ret; +} + +DACI_RETURN Replace_Converter(void *old_service_data, const void *agent_data, void **new_service_data) +{ + FW_LOGV("[dc_vcalendar_plugIn] Start !!"); + + DACI_RETURN ret = DACI_SUCCESS; + int err = 0; + cal_struct *temp_new_service_data = 0; + cal_struct *temp_old_service_data = (cal_struct *) old_service_data; + const char *temp_agent_data = (const char *)agent_data; + + /* Temporary fix for KIES vCalendar X-ALLDAY tag : START */ + int allday = 0; + + if (strstr((char *)agent_data, "\r\nX-ALLDAY:SET")) + allday = 1; + /* Temporary fix for KIES vCalendar X-ALLDAY tag : END */ + + /* convert */ + err = calendar_svc_util_convert_vcs_to_event(temp_agent_data, strlen(temp_agent_data), &temp_new_service_data); + if (err < CAL_SUCCESS) { + FW_LOGV("[dc_vcalendar_plugIn] calendar_svc_util_convert_vcs_to_event() Fail!\n"); + ret = __convert_service_error_to_common_error(err); + *new_service_data = 0; + } else { + /* Temporary fix for KIES vCalendar X-ALLDAY tag : START */ + if (allday) { + cal_struct *item = (cal_struct *) temp_new_service_data; + + FW_LOGI(" CAL_VALUE_INT_ALL_DAY_EVENT = %d ", calendar_svc_struct_get_int(item, CAL_VALUE_INT_ALL_DAY_EVENT)); + + if (!calendar_svc_struct_get_int(item, CAL_VALUE_INT_ALL_DAY_EVENT)) { + FW_LOGV("[Debug] X-ALLDAY flag set in vCalendar, but not in calendar service structure after conversion !!!"); + calendar_svc_struct_set_int(item, CAL_VALUE_INT_ALL_DAY_EVENT, 1); + } + } + /* Temporary fix for KIES vCalendar X-ALLDAY tag : END */ + + FW_LOGV("[dc_vcalendar_plugIn] calendar_svc_util_convert_vcs_to_event() Success!\n"); + *new_service_data = (void *)temp_new_service_data; + } + + /* memory free */ + if (temp_old_service_data != 0) + calendar_svc_struct_free(&temp_old_service_data); + + FW_LOGV("[dc_vcalendar_plugIn] End !!"); + return ret; +} + +DACI_RETURN Reverse_Converter(void *service_data, void **agent_data) +{ + FW_LOGV("[dc_vcalendar_plugIn] Start !!"); + + DACI_RETURN ret = DACI_SUCCESS; + int err = 0; + char *temp_agent_data = 0; + cal_struct *temp_service_data = (cal_struct *) service_data; + int size = 0; + + /* Temporary fix for KIES vCalendar X-ALLDAY/RRULE/LAST MODIFIED tag : START */ + int allday = 0; + char rrule[30]; + memset(rrule, 0, 30); + + cal_struct *item = (cal_struct *) temp_service_data; + + FW_LOGI(" CAL_VALUE_INT_ALL_DAY_EVENT = %d ", calendar_svc_struct_get_int(item, CAL_VALUE_INT_ALL_DAY_EVENT)); + + if (calendar_svc_struct_get_int(item, CAL_VALUE_INT_ALL_DAY_EVENT)) { + FW_LOGV("[Debug] Found X-ALLDAY flag set in calendar service structure before conversion !!!"); + allday = 1; + } + + FW_LOGI(" CAL_VALUE_INT_REPEAT_TERM = %d ", calendar_svc_struct_get_int(item, CAL_VALUE_INT_REPEAT_TERM)); + FW_LOGI(" CAL_VALUE_INT_REPEAT_INTERVAL = %d ", calendar_svc_struct_get_int(item, CAL_VALUE_INT_REPEAT_INTERVAL)); + + if (calendar_svc_struct_get_int(item, CAL_VALUE_INT_REPEAT_TERM) != CAL_REPEAT_NONE) { + + char repeat_end_date[16 + 1] = { 0 }; + char week_day_string[16 + 1] = { 0 }; + + struct tm *tm = calendar_svc_struct_get_tm(item, CAL_VALUE_GMT_REPEAT_END_DATE, CAL_TZ_FLAG_LOCAL); + + memset(repeat_end_date, 0, 17); + + sprintf(repeat_end_date, "%04ld%02d%02dT%02d%02d%02dZ", tm->tm_year + 1900L, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec); + + FW_LOGI(" repeat_end_date = %s ", repeat_end_date); + + char str[50]; + memset(str, 0, 50); + + switch (calendar_svc_struct_get_int(item, CAL_VALUE_INT_REPEAT_TERM)) { + case CAL_REPEAT_EVERY_DAY: + sprintf(str, "D%d %s", calendar_svc_struct_get_int(item, CAL_VALUE_INT_REPEAT_INTERVAL), repeat_end_date); + break; + + case CAL_REPEAT_EVERY_WEEK: + case CAL_REPEAT_EVERY_WEEKDAYS:{ + struct tm *tm_start = calendar_svc_struct_get_tm(item, CAL_VALUE_GMT_START_DATE_TIME, CAL_TZ_FLAG_LOCAL); + + char *date_string[7] = { "SU", "MO", "TU", "WE", "TH", "FR", "SA" }; + + struct tm temp; + time_t t = timegm(tm_start); + gmtime_r(&t, &temp); + + if (temp.tm_wday < 0 || temp.tm_wday > 6) { + } else { + snprintf(week_day_string, 3, date_string[temp.tm_wday]); + } + + sprintf(str, "W%d %s %s", calendar_svc_struct_get_int(item, CAL_VALUE_INT_REPEAT_INTERVAL), week_day_string, repeat_end_date); + } + break; + + case CAL_REPEAT_EVERY_MONTH: + case CAL_REPEAT_EVERY_MONTH_DAY: + sprintf(str, "MD%d %s", calendar_svc_struct_get_int(item, CAL_VALUE_INT_REPEAT_INTERVAL), repeat_end_date); + break; + + case CAL_REPEAT_EVERY_YEAR: + case CAL_REPEAT_EVERY_YEAR_DAY: + sprintf(str, "YM%d %s", calendar_svc_struct_get_int(item, CAL_VALUE_INT_REPEAT_INTERVAL), repeat_end_date); + break; + + default: + break; + } + + strcat(rrule, "\r\nRRULE:"); + strcat(rrule, str); + + FW_LOGI(" rrule = %s ", rrule); + } + int isModifiedTime = 0; + char sModifiedTime[16] = { 0, }; + if (calendar_svc_struct_get_int(item, CAL_VALUE_GMT_LAST_MODIFIED_TIME) != CAL_REPEAT_NONE) { + isModifiedTime = 1; + /* get the time value */ + time_t last_modified_time = 0; + last_modified_time = calendar_svc_struct_get_time(item, CAL_VALUE_GMT_LAST_MODIFIED_TIME, CAL_TZ_FLAG_GMT); + + struct tm *sometime = localtime(&last_modified_time); + if (sometime != 0) { + strftime(sModifiedTime, 20, "%Y%m%d%H%M%S", sometime); + FW_LOGI("Modified time = %s ", sModifiedTime); + } + } + /* Temporary fix for KIES vCalendar X-ALLDAY/RRULE/LAST MODIFIED tag : END */ + + /* Reverse_Converter */ + err = calendar_svc_util_convert_event_to_vcs(temp_service_data, &temp_agent_data, &size); + if (err < CAL_SUCCESS) { + FW_LOGV("[dc_vcalendar_plugIn] calendar_svc_util_convert_event_to_vcs() Fail!\n"); + ret = __convert_service_error_to_common_error(err); + *agent_data = 0; + } else { + /* Temporary fix for KIES vCalendar X-ALLDAY/RRULE tag : START */ + if (!strstr(temp_agent_data, "\r\nX-ALLDAY:SET") && allday) { + char *vevent_loc = strstr(temp_agent_data, "\r\nEND:VEVENT"); + if (vevent_loc != NULL) { + char *mod_data = (char *)calloc(strlen(temp_agent_data) + strlen("\r\nX-ALLDAY:SET") + 1, sizeof(char)); + + strncpy(mod_data, temp_agent_data, vevent_loc - temp_agent_data); + strcat(mod_data, "\r\nX-ALLDAY:SET"); + strcat(mod_data, vevent_loc); + + free(temp_agent_data); + temp_agent_data = mod_data; + } + char *dtstart_loc = strstr(temp_agent_data, "\r\nDTSTART:"); + if (dtstart_loc != NULL) { + char *dtstart_Z_loc = dtstart_loc + 25; + if (!strncmp(dtstart_Z_loc, "Z", 1)) + strncpy(dtstart_Z_loc, "\r\r\n", 3); + } + char *dtend_loc = strstr(temp_agent_data, "\r\nDTEND:"); + if (dtend_loc != NULL) { + char *dtend_z_loc = dtend_loc + 23; + if (!strncmp(dtend_z_loc, "Z", 1)) + strncpy(dtend_z_loc, "\r\r\n", 3); + } + } + + if (!strstr(temp_agent_data, "\r\nRRULE:") && rrule != NULL) { + char *category_loc = strstr(temp_agent_data, "\r\nCATEGORIES:"); + if (category_loc != NULL) { + char *mod_data = (char *)calloc(strlen(temp_agent_data) + strlen(rrule) + 1, sizeof(char)); + + strncpy(mod_data, temp_agent_data, category_loc - temp_agent_data); + strcat(mod_data, rrule); + strcat(mod_data, category_loc); + + free(temp_agent_data); + temp_agent_data = mod_data; + } + } + + if (!strstr(temp_agent_data, "\r\nLAST-MODIFIED:") && sModifiedTime != NULL) { + char *category_loc = strstr(temp_agent_data, "\r\nLAST-MODIFIED:"); + if (category_loc != NULL) { + char *mod_data = (char *)calloc(strlen(temp_agent_data) + strlen(sModifiedTime) + 1, sizeof(char)); + + strncpy(mod_data, temp_agent_data, category_loc - temp_agent_data); + strcat(mod_data, sModifiedTime); + strcat(mod_data, category_loc); + + free(temp_agent_data); + temp_agent_data = mod_data; + } + } + /* Temporary fix for KIES vCalendar X-ALLDAY/RRULE tag : END */ + FW_LOGV("[dc_vcalendar_plugIn] calendar_svc_util_convert_event_to_vcs() Success!\n"); + *agent_data = (void *)temp_agent_data; + } + + /* memory free */ + if (temp_service_data != 0) + calendar_svc_struct_free(&temp_service_data); + + FW_LOGV("[dc_vcalendar_plugIn] End !!"); + return ret; +} + +void *Alloc_Object() +{ + FW_LOGV("[dc_vcard_plugIn] not implement !!"); + return 0; +} + +int Free_Object(void *in_object) +{ + FW_LOGV("[dc_vcard_plugIn] not implement !!"); + return 0; +} + +void *Set_Value_To_Object(void *in_object, int key, char *extension_key, void *value) +{ + FW_LOGV("[dc_vcard_plugIn] not implement !!"); + return 0; +} + +void *Get_Value_To_Object(void *in_object, int key, char *extension_key) +{ + FW_LOGV("[dc_vcard_plugIn] not implement !!"); + return 0; +} + +Object_Info *Get_Obj_Info() +{ + Object_Info *obj_info = (Object_Info *)calloc(1, sizeof(Object_Info)); + + obj_info->type = VCALENDAR_TYPE; + obj_info->version = VCALENDAR_VERSION; + obj_info->field_cnt = sizeof(vcalendar_field_list) / sizeof(VCALENDAR_FIELD_LIST); + + if (obj_info->field_cnt > 0) + __set_obj_field_info(&(obj_info->field_list), obj_info->field_cnt, vcalendar_field_list); + + return obj_info; +} + +int Free_Obj_Info(Object_Info *obj_info) +{ + if (obj_info) { + if (obj_info->field_cnt > 0) + if (__free_obj_field_info(obj_info->field_list, obj_info->field_cnt) == 0) + return 0; + + free(obj_info); + } + + return 1; +} + +static int __free_obj_field_info(Field_Info *field_list, int count) +{ + int field_count = 0; + Field_Info *child = NULL; + + if (field_list) { + for (field_count = 0; field_count < count; field_count++) { + child = field_list + field_count; + if (child->field_child_cnt > 0) + if (__free_obj_field_info(child->field_child_list, child->field_child_cnt) == 0) + return 0; + } + free(field_list); + } + + return 1; +} + +static int __set_obj_field_info(Field_Info **field_list, int count, VCALENDAR_FIELD_LIST * input_list) +{ + int field_count = 0; + Field_Info *child = NULL; + + *field_list = (Field_Info *)calloc(count, sizeof(Field_Info)); + + for (field_count = 0; field_count < count; field_count++) { + child = (*field_list) + field_count; + child->field_name = input_list[field_count].field_name; + FW_LOGI("[%s]", child->field_name); + + if (input_list[field_count].field_enum == VCALENDAR_FIELD_BEGIN || input_list[field_count].field_enum == VCALENDAR_FIELD_END) { + child->field_child_cnt = sizeof(vcalendar_field_list_begin_end) / sizeof(VCALENDAR_FIELD_LIST); + FW_LOGI("----------"); + __set_obj_field_info(&(child->field_child_list), child->field_child_cnt, vcalendar_field_list_begin_end); + FW_LOGI("=========="); + } else if (input_list[field_count].field_enum == VCALENDAR_FIELD_VERSION) { + child->field_child_cnt = sizeof(vcalendar_field_list_version) / sizeof(VCALENDAR_FIELD_LIST); + FW_LOGI("----------"); + __set_obj_field_info(&(child->field_child_list), child->field_child_cnt, vcalendar_field_list_version); + FW_LOGI("=========="); + } else if (input_list[field_count].field_enum == VCALENDAR_FIELD_CATEGORIES) { + child->field_child_cnt = sizeof(vcalendar_field_list_categories) / sizeof(VCALENDAR_FIELD_LIST); + FW_LOGI("----------"); + __set_obj_field_info(&(child->field_child_list), child->field_child_cnt, vcalendar_field_list_categories); + FW_LOGI("=========="); + } else if (input_list[field_count].field_enum == VCALENDAR_FIELD_STATUS) { + child->field_child_cnt = sizeof(vcalendar_field_list_status) / sizeof(VCALENDAR_FIELD_LIST); + FW_LOGI("----------"); + __set_obj_field_info(&(child->field_child_list), child->field_child_cnt, vcalendar_field_list_status); + FW_LOGI("=========="); + } + } + + return 1; +} + +static DACI_RETURN __convert_service_error_to_common_error(cal_error err) +{ + DACI_RETURN ret = DACI_SUCCESS; + FW_LOGV("[da_calendar_plugIn] Error Code : %d\n", err); + + switch (err) { + case CAL_ERR_DB_LOCK: /* -204 */ + ret = DACI_ERR_LOCKED; + break; + case CAL_ERR_DB_RECORD_NOT_FOUND: /* -203 */ + case CAL_ERR_NO_DATA: /* -3 */ + ret = DACI_ERR_NO_DATA; + break; + case CAL_ERR_DB_NOT_OPENED: /* -201 */ + ret = DACI_ERR_OPEN_FAILED; + break; + case CAL_ERR_OUT_OF_MEMORY: /* -8 */ + ret = DACI_ERR_MEMORY_FULL; + break; + case CAL_ERR_ALREADY_EXIST: /* -7 */ + ret = DACI_ERR_ALREADY_EXIST; + break; + case CAL_ERR_EVENT_START_DATE: /* -405 */ + case CAL_ERR_EVENT_END_DATE: /* -404 */ + case CAL_ERR_EVENT_REPEAT_END_DATE: /* -403 */ + case CAL_ERR_EVENT_DURATION: /* -402 */ + case CAL_ERR_EVENT_REPEAT_DURATION_TOO_SHORT: /* -401 */ + case CAL_ERR_INVALID_DATA_TYPE: /* -301 */ + case CAL_ERR_ARG_NULL: /* -5 */ + case CAL_ERR_ARG_INVALID: /* -4 */ + ret = DACI_ERR_INVALID_CONTENT; + break; + case CAL_ERR_FINISH_ITER: /* -2 */ + case CAL_SUCCESS: /* 0 */ + case CAL_TRUE: /* 1 */ + ret = DACI_SUCCESS; + break; + /* + * CAL_ERR_DB_FAILED: -202, + * CAL_ERR_VCONF_FAILED: -102, + * CAL_ERR_VOBJECT_FAILED: -101, + * CAL_ERR_EXCEEDED_LIMIT: -9, + * CAL_ERR_ENV_INVALID: -6, CAL_ERR_FAIL: -1, + */ + default: + ret = DACI_ERRORS; + break; + } + + return ret; +} + +/* +static void __print_obj_field_info(Field_Info *info, int count) +{ + int i = 0; + if (info) + for (i = 0; i < count; i++) { + printf("[%s]\n", info[i].field_name); + if (info[i].field_child_list) + printf(info[i].field_child_list, info[i].field_child_cnt); + } +} +*/ diff --git a/fw-plugin/vcalendar-plugIn/src/encoding_util.c b/fw-plugin/vcalendar-plugIn/src/encoding_util.c new file mode 100755 index 0000000..7208106 --- /dev/null +++ b/fw-plugin/vcalendar-plugIn/src/encoding_util.c @@ -0,0 +1,775 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Seokgil Kang + */ + +#include "encoding_util.h" + +/* for log */ +#include "agent-framework/Utility/fw_log.h" +#define LOG_TAG "ENCODING_UTIL" + +#define TYPE_CHECK_BUF_SIZE 100 /* temporary definition */ + +/* BASE64 TABLE */ +static char base64_table[65] = { + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', + 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', + 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', + 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', + 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', + 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', + '2', '3', '4', '5', '6', '7', '8', '9', '+', + '/', '=' +}; + +/* Quoted-Printable */ +static char *__dec2hex(int dec); +static int __hex2dec(char *hex); + +/* Base64 */ +static int __find_base(char ch); + +/* + * Quoted-Printable + */ +int encode_QP(char *src, int src_len, char **en_src, int *en_src_len) +{ + char *en_hex; + int i = 0; + int j = 0; + int size_cnt = 0; + + if (src == NULL) { + FW_LOGE("[encoding_util] src is NULL\n"); + return 0; + } + + /*encoded string length is three times longer than existing maximum string length */ + int full_lenth = src_len * 3 + 1 + (int)(src_len * 3 / 76) * 3; + *en_src = (char *)malloc(sizeof(char) * full_lenth); + if (*en_src == 0x00) { + FW_LOGE("[encoding_util] malloc fail !!\n"); + return 0; + } + memset(*en_src, 0x00, src_len * 3 + 1); + + FW_LOGV("[encoding_util] src_len : %d\n", src_len); + for (i = 0; i < src_len; i++) { + /* FW_LOGV("[encoding_util] i : %d\n", i); */ + if (size_cnt >= QP_SIZE - 3) { + size_cnt = 0; + (*en_src)[j++] = 0x3D; + (*en_src)[j++] = 0x0D; + (*en_src)[j++] = 0x0A; + } + + if ((src[i] >= 33 && src[i] <= 126) || (src[i] == 0x0A) || (src[i] == 0x0D)) { + if (src[i] == 61 || src[i] == 0x0A || src[i] == 0x0D) { + en_hex = __dec2hex(src[i]); + (*en_src)[j++] = 0x3D; /* '=' */ + (*en_src)[j++] = en_hex[0]; + (*en_src)[j++] = en_hex[1]; + size_cnt += 3; + } else { + size_cnt++; + (*en_src)[j++] = src[i]; + } + } else if (src[i] == 9 || src[i] == 32) { + if (src[i + 1] == 0x0A || src[i + 1] == 0x00) { /* TAB or WhiteSpace */ + en_hex = __dec2hex(src[i]); + (*en_src)[j++] = 0x3D; /* '=' */ + (*en_src)[j++] = en_hex[0]; + (*en_src)[j++] = en_hex[1]; + size_cnt += 3; + } else { + size_cnt++; + (*en_src)[j++] = src[i]; + } + } else { + en_hex = __dec2hex(src[i]); + (*en_src)[j++] = 0x3D; /* '=' */ + (*en_src)[j++] = en_hex[0]; + (*en_src)[j++] = en_hex[1]; + FW_LOGV("[encoding_util] en_src : %s\n", *en_src); + size_cnt += 3; + } + } + + (*en_src)[j] = 0x00; + *en_src_len = size_cnt; + + return 1; +} + +int decode_QP(char *src, int src_len, char **de_src, int *de_src_len) +{ + char hex[3]; + char ch; + int dec = 0; + int i = 0; + int j = 0; + + if (src == NULL) { + FW_LOGE("[encoding_util] src is NULL\n"); + return 0; + } + + *de_src = (char *)malloc(sizeof(char) * (src_len + 1)); + if (*de_src == 0x00) { + FW_LOGE("[encoding_util] malloc is fail !!\n"); + return 0; + } + memset(*de_src, 0x00, sizeof(char) * (src_len + 1)); + + while (src[i] != '\0') { + if (src[i] == 0x3D) { /* '=' */ + /* check whiteSpace */ + ch = src[++i]; + + /* '=' skip if next character is a TAB or WhiteSpace */ + while (ch == 0x09 || ch == 0x20) { + ch = src[++i]; + continue; + } + + /* '=' skip if next character is 3D which means '=' (encoding error case ??)*/ + while (ch == '3') { + ch = src[++i]; + + if (ch == 'D') { + ch = src[++i]; + continue; + } + } + + /* if next character is LF after '=' do doft line break + * encoded QP string on one line 76 character is allowed + */ + if (ch == 0x0D) { /* LF */ + ch = src[++i]; + if (ch == 0x0A) { + ch = src[++i]; + continue; + } + } + + hex[0] = src[i++]; + hex[1] = src[i++]; + hex[2] = '\0'; + + dec = __hex2dec(hex); + + /* decoding error */ + if (dec < 0) { + /* when error occur, restore the previous encoding message */ + (*de_src)[j++] = 0x3D; /* '=' */ + (*de_src)[j++] = hex[0]; + (*de_src)[j++] = hex[1]; + } else { + (*de_src)[j++] = dec; + } + } else if (src[i] > 0x7E) { /* encoding error */ + i++; /* ignore that character */ + } else { + (*de_src)[j++] = src[i++]; + } + } + + (*de_src)[j] = '\0'; + *de_src_len = j; + + return 1; +} + +static char *__dec2hex(int dec) +{ + static char hex[3]; + int i; + int ch; + + for (i = 0; i < 2; i++) { + if (i == 0) { + ch = (dec & 0xF0) >> 4; + } else if (i == 1) { + ch = (dec & 0x0F); + } + + if (ch >= 10) { + hex[i] = 'A' + ch - 10; + } else { + hex[i] = '0' + ch; + } + } + + hex[i] = 0x00; + + FW_LOGV("[encoding_util] hex : %s\n", hex); + + return &hex[0]; +} + +static int __hex2dec(char *hex) +{ + int dec = 0; + int byte; + int i = 0; + + for (i = 0; i < 2; i++) { + if (hex[i] >= '0' && hex[i] <= '9') { + byte = hex[i] - '0'; + } else if (hex[i] >= 'A' && hex[i] <= 'F') { + byte = hex[i] - 'A' + 10; + } else if (hex[i] >= 'a' && hex[i] <= 'f') { + byte = hex[i] - 'a' + 10; + } else { + byte = -1; + } + + if (byte < 0) + return -1; + + dec += (i == 0) ? byte << 4 : byte; + } + + return dec; +} + +/* + * Base64 + */ +int encode_base64(char *src, int src_len, char **en_src, int *en_src_len) +{ + int i = 0; + int j = 0; + int cnt = 0; + int ch = 0; + int size_cnt = 0; + + if (src == NULL) { + FW_LOGE("[encoding_util] src is NULL\n"); + return 0; + } + + *en_src = (char *)malloc(sizeof(char) * (src_len * 2)); + if (*en_src == NULL) { + FW_LOGE("[encoding_util] malloc error !!"); + return 0; + } + memset(*en_src, 0x00, src_len * 2); + + if (*en_src == 0x00) { + FW_LOGE("[encoding_util] malloc fail !!\n"); + return 0; + } + + while (1) { + switch (cnt++) { + case 0: + { + if (i < src_len) { + ch = (src[i] & 0xFC) >> 2; + } else { + ch = -1; + } + } + break; + + case 1: + { + if (i < src_len) { + if (i + 1 < src_len) { + ch = ((src[i] & 0x03) << 4) | ((src[i + 1] & 0xF0) >> 4); + } else { + ch = ((src[i] & 0x03) << 4); + } + } else { + ch = -1; + } + i++; + break; + } + + case 2: + { + if (i < src_len) { + if (i + 1 < src_len) { + ch = ((src[i] & 0x0F) << 2) | ((src[i] & 0xC0) >> 6); + } else { + ch = ((src[i] & 0x0F) << 2); + } + } else { + ch = -1; + } + i++; + } + break; + + case 3: + { + if (i < src_len) { + ch = (src[i] & 0x3F); + } else { + ch = -1; + } + i++; + cnt = 0; + } + break; + } + + /* + if (ch >= 0 && ch <= 25) { // Upper Case Alphabet + (*en_src)[j++] = 'A' + ch; + } else if (ch >= 26 && ch <= 51) { // Lower Case Alphabet + (*en_src)[j++] = 'a' + ch - 26; + } else if (ch >= 52 && ch <= 61) { // Digit + (*en_src)[j++] = '0' + ch - 52; + } else if (ch == 62) { + (*en_src)[j++] = '+'; + } else if (ch == 63) { + (*en_src)[j++] = '/'; + } else if (ch == -1) { + (*en_src)[j++] = '='; // padding + } + */ + + if ((ch != -1) && (ch >= 0 && ch <= 64)) { + (*en_src)[j++] = base64_table[ch]; + } else { + (*en_src)[j++] = base64_table[64]; /* padding */ + } + + size_cnt++; + + if (j % 4 == 0) { + if (size_cnt == BASE64_SIZE) { + size_cnt = 0; + (*en_src)[j++] = 0x0A; /* soft line break */ + } + + if (i >= src_len) + break; + } + } + + (*en_src)[j] = 0x00; + *en_src_len = j; + + return 1; +} + +int decode_base64(char *src, int src_len, char **de_src, int *de_src_len) +{ + long tmp = 0; /* 4byte (using decoding) */ + int i = 0; + int j = 0; + int cnt = 0; + int pad_cnt = 0; + + if (src == NULL) { + FW_LOGE("[encoding_util] src is NULL\n"); + return 0; + } + + /* de_src is enough for the src_len 3/4 size */ + *de_src = (char *)malloc(sizeof(char) * (src_len)); + if (*de_src == NULL) { + FW_LOGE("malloc error !!"); + return 0; + } + memset(*de_src, 0x00, src_len); + + if (*de_src == 0x00) { + FW_LOGE("[encoding_util] malloc is fail !!\n"); + return 0; + } + + while (src[i] != '\0') { + /* + if (isupper(src[i])) { + tmp = (tmp << 6) | (src[i] - 'A'); // Upper case : 0 ~ 25 + } else if (islower(src[i])) { + tmp = (tmp << 6) | (src[i] - 'a' + 0x1A); // Lower case : 26(0x1A) ~ 51 + } else if (isdigit(src[i])) { + tmp = (tmp << 6) | (src[i] - '0' + 0x34); // Number : 52(0x34) ~ 61 + } else if (src[i] == '+') { + tmp = (tmp << 6) | 0x3E; // '+' : 62(0x3E) + } else if (src[i] == '/') { + tmp = (tmp << 6) | 0x3F; // '/' : 63(0x3F) + } else if (src[i] == '=') { + pad_cnt++; + tmp = (tmp << 6); // '=' : padding + } else { + tmp = (tmp << 6); // encoding error + fFW_LOGV(stdout, "encoding error !! \n"); + } + */ + + tmp = (tmp << 6) | (__find_base(src[i])); + if (tmp == 64) { + pad_cnt++; + } else if (tmp == -1) { + FW_LOGE("[encoding_util] encoding error \n"); + } + + if (++cnt >= 4) { + (*de_src)[j++] = (char)((tmp & 0x00FF0000) >> 16); + (*de_src)[j++] = (char)((tmp & 0x0000FF00) >> 8); + (*de_src)[j++] = (char)(tmp & 0x000000FF); + + cnt = 0; + tmp = 0; + + if (src[i + 1] == 0x0A) { /* soft line break */ + i++; + } + } + + i++; + } + + (*de_src)[j - pad_cnt] = '\0'; + *de_src_len = j - pad_cnt; + + return 1; +} + +int proc_decoding(const char *src, int src_len, char **de_src, int *de_src_len) +{ + FW_LOGV("[encoding_util] Start \n"); + + const char *reg_src = NULL; + reg_src = src; + + FW_LOGV("[encoding_util] << src >> \n%s\n", src); + + *de_src = (char *)malloc(sizeof(char) * (src_len + 1)); + if (*de_src == NULL) { + FW_LOGV("[encoding_util] malloc error !! \n"); + + return 0; + } + memset(*de_src, 0x00, sizeof(char) * (src_len + 1)); + + char colon[] = ":"; + char line_breaker[] = "\r\n"; + char *start_decoding = NULL; + int data_size = 0; + int res = 0; + int de_temp_len = 0; + + char *de_temp = (char *)malloc(sizeof(char) * src_len); /* todo : temporary */ + if (de_temp == NULL) { + FW_LOGE("[encoding_util] malloc error !!\n"); + + if (*de_src != NULL) + free(*de_src); + + return 0; + } + + while ((start_decoding = strstr(src, "ENCODING="))) { + char *charset_loc = strstr(src, "CHARSET="); + char *colon_loc = strstr(start_decoding, colon); /* find ':''s location */ + char *line_breaker_loc = 0; + + /*edited code for line beaker */ + char *colon_loc_temp = colon_loc; + while (line_breaker_loc == NULL) { + line_breaker_loc = strstr(colon_loc_temp, line_breaker); /* find "\r\n"'s location */ + if (line_breaker_loc > colon_loc_temp && !strncmp(line_breaker_loc - 1, "=", 1)) { + colon_loc_temp = line_breaker_loc + 1; + line_breaker_loc = 0; + } + } + + /* + * if find "ENCODING=" do strcat data until ":" to de_src + */ + if (charset_loc != NULL) { + if (start_decoding > charset_loc) { /* CHARSET=UTF-8;ENCODING=abcxx: */ + data_size = (charset_loc - 1) - src; + } else { /* ENCODING=abcxxx;CHARSET=UTF-8: */ + data_size = (start_decoding - 1) - src; + } + } else { + data_size = (start_decoding - 1) - src; + } + + char *temp = (char *)malloc(sizeof(char) * (data_size + 1)); + if (temp == NULL) { + FW_LOGE("[encoding_util] malloc error !!"); + + if (*de_src != NULL) + free(*de_src); + + if (de_temp != NULL) + free(de_temp); + + return 0; + } + memset(temp, 0x00, sizeof(char) * (data_size + 1)); + memcpy(temp, src, data_size); + + strcat(*de_src, temp); + (*de_src)[strlen(*de_src)] = ':'; + if (temp != NULL) + free(temp); + + FW_LOGV("[encoding_util] << *de_src >> \n %s\n", *de_src); + + /* + * copy data from ":" until "\r\n"(actual encoding stream) + */ + data_size = line_breaker_loc - colon_loc; /* from ':' until "\r\n" + '\0' */ + char *value = (char *)malloc(sizeof(char) * (data_size + 1)); + if (value == NULL) { + FW_LOGE("[encoding_util] malloc error !!\n"); + + if (*de_src != NULL) + free(*de_src); + + if (de_temp != NULL) + free(de_temp); + + return 0; + } + memset(value, 0x00, sizeof(char) * (data_size + 1)); + memcpy(value, ++colon_loc, data_size); /* from ':' until "\r\n" */ + value[data_size] = '\0'; + FW_LOGV("[encoding_util] data len is [%d] and value is [%s]\n\n", data_size, value); + /* + * Get encoding type using data from "ENCODING=" to ":" + */ + char type_check[TYPE_CHECK_BUF_SIZE] = { 0, }; + int type_check_size = colon_loc - start_decoding; + strncpy(type_check, start_decoding, type_check_size); + FW_LOGV("[encoding_util] type check : %s\n", type_check); + ENCODING_TYPE type = find_encoding_type((const char *)type_check); + + /* + * Process decoding by passing the actual value and encoding type to decode_value() + */ + de_temp_len = 0; + memset(de_temp, 0x00, sizeof(char) * src_len); /* todo : temporary */ + + res = decode_value(type, value, data_size, &de_temp, &de_temp_len); + + if (res != 1) { + FW_LOGE("[encoding_util] decode_value error !!\n"); + + if (*de_src != NULL) + free(*de_src); + + if (de_temp != NULL) + free(de_temp); + + return 0; + } + + /* + * Append decoded data to de_src + */ + FW_LOGV("[encoding_util] de_temp : %s\n", de_temp); + strcat(*de_src, de_temp); + + /* + * find "ENCODING=" since "\r\n" agina + */ + src = line_breaker_loc; + + if (value != NULL) + free(value); + } + + strcat(*de_src, src); /* Append remain character */ + *de_src_len = strlen(*de_src); + FW_LOGV("[encoding_util] changed src : \n%s ( %d ) \n", *de_src, *de_src_len); + + if (de_temp != NULL) + free(de_temp); + + FW_LOGV("[encoding_util] End \n"); + + return 1; +} + +int check_encoding_data(const char *data) +{ + if (strstr(data, "ENCODING=") != NULL) { + FW_LOGV("[encoding_util] exist encoding data !! \n"); + return 1; + } else { + FW_LOGV("[encoding_util] not exist encoding data !! \n"); + return 0; + } +} + +ENCODING_TYPE find_encoding_type(const char *data) +{ + FW_LOGV("[encoding_util] Start !! \n"); + + ENCODING_TYPE type = EN_TYPE_NONE; + if (strstr(data, "QUOTED-PRINTABLE") != NULL) { + FW_LOGV("[encoding_util] type : QP\n"); + type = EN_TYPE_QUOTED_PRINTABLE; + } else if (strstr(data, "BASE64") != NULL) { + FW_LOGV("[encoding_util] type : BASE64\n"); + type = EN_TYPE_BASE64; + } else { + FW_LOGV("[encoding_util] not supported type !! \n"); + } + + FW_LOGV("[encoding_util] End !! \n"); + + return type; +} + +int decode_value(ENCODING_TYPE type, const char *value, int value_size, char **decode_str, int *decode_str_len) +{ + FW_LOGV("[encoding_util] Start !! \n"); + + int res = 1; + const char *start_pos = NULL; + const char *cursor = NULL; + int semi_cnt = 0; + + /* + * ex> value - =EA=B9=80;=EC=B2=A0=EC=88=98;;;\0 + */ + cursor = value; + start_pos = value; + + while (*cursor != '\0') { + if ((*cursor != ';') && (*(cursor + 1) != '\0')) { + cursor++; + continue; + } else if (*cursor == ';') { + semi_cnt++; + } + + int data_size = 0; + if (*cursor == ';') + data_size = cursor - start_pos; + else /* case of [*(cursor+1)=='\0'] */ + data_size = cursor + 1 - start_pos; + + if (data_size == 0) { + cursor++; + start_pos++; + } else { + char *temp = (char *)malloc(sizeof(char) * (value_size + 1)); + if (temp == NULL) { + FW_LOGE("[encoding_util] malloc error !!"); + return 0; + } + memset(temp, 0x00, sizeof(char) * (value_size + 1)); + memcpy(temp, start_pos, data_size); + + FW_LOGV("[encoding_util] temp : %s \n", temp); + + char *decoding = 0; + int decoding_len = 0; + + switch (type) { + case EN_TYPE_QUOTED_PRINTABLE: + res = decode_QP(temp, data_size, &decoding, &decoding_len); + if (temp != NULL) + free(temp); + break; + case EN_TYPE_BASE64: + res = decode_base64(temp, data_size, &decoding, &decoding_len); + if (temp != NULL) + free(temp); + break; + default: + break; + } + + FW_LOGV("[encoding_util] decoding : %s ( %d )\n", decoding, decoding_len); + + if (res != 1) { + FW_LOGE("[encoding_util] decoding error !! \n"); + + if (decoding != NULL) + free(decoding); + + res = 0; + return res; + } + + strcat(*decode_str, decoding); + + FW_LOGV("[encoding_util] *decode_str : %s\n", *decode_str); + + if (decoding != NULL) + free(decoding); + + cursor++; + start_pos = cursor; + } + + if (semi_cnt > 0) { + int len = strlen(*decode_str); + (*decode_str)[len] = ';'; + FW_LOGV("[encoding_util] *decode_str : %s ( %d )\n", *decode_str, strlen(*decode_str)); + semi_cnt--; + } + } + + *decode_str_len = strlen(*decode_str); + + FW_LOGV("[encoding_util] *decode_str : %s ( %d )\n", *decode_str, *decode_str_len); + + FW_LOGV("[encoding_util] End !! \n"); + + return res; +} + +static int __find_base(char ch) +{ + FW_LOGV("[encoding_util] Start !! \n"); + + int i = 0; + for (i = 0; i < 65; i++) { + if (base64_table[i] == ch) { + FW_LOGV("[encoding_util] End !! \n"); + return i; + } + } + + FW_LOGV("[encoding_util] End !! \n"); + + return -1; +} diff --git a/fw-plugin/vcard-plugIn/.cproject b/fw-plugin/vcard-plugIn/.cproject new file mode 100755 index 0000000..3c36d31 --- /dev/null +++ b/fw-plugin/vcard-plugIn/.cproject @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/fw-plugin/vcard-plugIn/.project b/fw-plugin/vcard-plugIn/.project new file mode 100755 index 0000000..a133f37 --- /dev/null +++ b/fw-plugin/vcard-plugIn/.project @@ -0,0 +1,78 @@ + + + vcard-plugIn + + + + + + com.samsung.slp2.SboxBuilder + + + com.samsung.slp2.SboxBuilder.needConfigure + true + + + org.eclipse.cdt.core.errorOutputParser + org.eclipse.cdt.core.MakeErrorParser;com.samsung.limo.SboxGCCErrorParser;org.eclipse.cdt.core.GLDErrorParser;org.eclipse.cdt.core.GASErrorParser; + + + org.eclipse.cdt.make.core.append_environment + true + + + org.eclipse.cdt.make.core.build.arguments + + + + org.eclipse.cdt.make.core.build.command + make + + + org.eclipse.cdt.make.core.build.target.auto + all + + + org.eclipse.cdt.make.core.build.target.clean + clean + + + org.eclipse.cdt.make.core.build.target.inc + all + + + org.eclipse.cdt.make.core.enableAutoBuild + true + + + org.eclipse.cdt.make.core.enableCleanBuild + true + + + org.eclipse.cdt.make.core.enableFullBuild + true + + + org.eclipse.cdt.make.core.enabledIncrementalBuild + true + + + org.eclipse.cdt.make.core.environment + + + + org.eclipse.cdt.make.core.stopOnError + true + + + org.eclipse.cdt.make.core.useDefaultBuildCmd + true + + + + + + org.eclipse.cdt.core.cnature + com.samsung.slp2.cnature + + diff --git a/fw-plugin/vcard-plugIn/CMakeLists.src b/fw-plugin/vcard-plugIn/CMakeLists.src new file mode 100755 index 0000000..04ce4aa --- /dev/null +++ b/fw-plugin/vcard-plugIn/CMakeLists.src @@ -0,0 +1 @@ +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src SRCS) diff --git a/fw-plugin/vcard-plugIn/CMakeLists.sub b/fw-plugin/vcard-plugIn/CMakeLists.sub new file mode 100755 index 0000000..4f36946 --- /dev/null +++ b/fw-plugin/vcard-plugIn/CMakeLists.sub @@ -0,0 +1,37 @@ +################################################################################# +# THIS FILE IS CREATED AUTOMATICALLY. DO NOT DELETE OR MODIFY THIS FILE. +################################################################################# + +INCLUDE(CMakeLists.src) + +## PROJECT NAME +PROJECT(plugin-dc-vcard C) + +## PACKAGE CONFIG +SET(SLP_PKGCONFIG_LIST "contacts-service") + +## INCLUDES +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../../framework/include) + +## DEFINITIONS +ADD_DEFINITIONS("-DAPP_DIR=\"${CMAKE_INSTALL_PREFIX}\"") + +## LIBRARY PATH +SET(SLP_LD_PATH_FLAGS "") + +## LIBRARY +SET(SLP_LD_FLAGS "") + +## DEBUG +SET(SLP_DEBUG_FLAGS "-g") + +## OPTIMIZATION +SET(SLP_OPT_FLAGS "-O0") + +## COMPILER FLAGS +SET(SLP_COMPILER_FLAGS "") + +## LINKER FLAGS +SET(SLP_LINKER_FLAGS "") + diff --git a/fw-plugin/vcard-plugIn/CMakeLists.txt b/fw-plugin/vcard-plugIn/CMakeLists.txt new file mode 100755 index 0000000..7c63f08 --- /dev/null +++ b/fw-plugin/vcard-plugIn/CMakeLists.txt @@ -0,0 +1,33 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) + +# INCLUDE SUB CMAKELIST FILE +INCLUDE(CMakeLists.sub) + +SET(RESOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/res") + +INCLUDE(FindPkgConfig) +pkg_check_modules(pkgs_plugin_vcard REQUIRED ${SLP_PKGCONFIG_LIST}) + +FOREACH(flag ${pkgs_plugin_vcard_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(CMAKE_C_FLAGS "${SLP_DEBUG_FLAGS} ${SLP_OPT_FLAGS} ${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} ${SLP_COMPILER_FLAGS}") +SET(CMAKE_CXX_FLAGS "${SLP_DEBUG_FLAGS} ${SLP_OPT_FLAGS} ${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} ${SLP_COMPILER_FLAGS}") + +ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS}) + +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_plugin_vcard_LDFLAGS} ${SLP_LD_PATH_FLAGS} ${SLP_LD_FLAGS} ${SLP_LINKER_FLAGS} sync-agent-framework) + +# INSTALL +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION lib) +#INSTALL(DIRECTORY ${RESOURCE_DIR}/data DESTINATION share) + +#added by KTS for install to the system +#CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY) +#INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc DESTINATION lib/pkgconfig) + + +# INCLUDE LAYOUT DIRECTORY +# ADD_SUBDIRECTORY(layout) +#ADD_SUBDIRECTORY(res/locale) diff --git a/fw-plugin/vcard-plugIn/include/IN_DataStore_Info_Vcard.h b/fw-plugin/vcard-plugIn/include/IN_DataStore_Info_Vcard.h new file mode 100755 index 0000000..443ae58 --- /dev/null +++ b/fw-plugin/vcard-plugIn/include/IN_DataStore_Info_Vcard.h @@ -0,0 +1,174 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Wook Choi + */ + +#ifndef IN_DATASTORE_INFO_VCARD_H_ +#define IN_DATASTORE_INFO_VCARD_H_ + +#define VCARD_TYPE "text/x-vcard" +#define VCARD_VERSION "2.1" + +typedef enum { + VCARD_FIELD_BEGIN = 10, + VCARD_FIELD_END, + VCARD_FIELD_VERSION, + VCARD_FIELD_FN, + VCARD_FIELD_N, + VCARD_FIELD_NICKNAME, + VCARD_FIELD_PHOTO, + VCARD_FIELD_BDAY, + VCARD_FIELD_ADR, + VCARD_FIELD_LABEL, + VCARD_FIELD_TEL, + VCARD_FIELD_EMAIL, + VCARD_FIELD_TITLE, + VCARD_FIELD_ROLE, + VCARD_FIELD_ORG, + VCARD_FIELD_NOTE, + VCARD_FIELD_REV, + VCARD_FIELD_UID, + VCARD_FIELD_URL, + VCARD_FIELD_X_ANNIVERSARY, + VCARD_FIELD_X_IRMC_LUID, + +} VCARD_FIELD; + +typedef enum { + VCARD_FIELD_ADR_DOM = 100, + VCARD_FIELD_ADR_INTL, + VCARD_FIELD_ADR_HOME, + VCARD_FIELD_ADR_WORK, + VCARD_FIELD_ADR_POSTAL, + VCARD_FIELD_ADR_PARCEL, + VCARD_FIELD_ADR_PREF, + +} VCARD_FIELD_ADR_SUB; + +typedef enum { + VCARD_FIELD_TEL_HOME = 200, + VCARD_FIELD_TEL_MSG, + VCARD_FIELD_TEL_WORK, + VCARD_FIELD_TEL_VOICE, + VCARD_FIELD_TEL_FAX, + VCARD_FIELD_TEL_CELL, + VCARD_FIELD_TEL_VIDEO, + VCARD_FIELD_TEL_PAGER, + VCARD_FIELD_TEL_BBS, + VCARD_FIELD_TEL_MODEM, + VCARD_FIELD_TEL_CAR, + VCARD_FIELD_TEL_ISDN, + VCARD_FIELD_TEL_PCS, + VCARD_FIELD_TEL_PREF, + +} VCARD_FIELD_TEL_SUB; + +typedef enum { + VCARD_FIELD_EMAIL_HOME = 300, + VCARD_FIELD_EMAIL_WORK, + VCARD_FIELD_EMAIL_PREF, + +} VCARD_FIELD_EMAIL_SUB; + +typedef struct VCARD_FIELD_LIST VCARD_FIELD_LIST; +struct VCARD_FIELD_LIST { + int field_enum; + char *field_name; +}; + +static VCARD_FIELD_LIST vcard_field_list[] = { + {VCARD_FIELD_BEGIN, "BEGIN"}, + {VCARD_FIELD_END, "END"}, + {VCARD_FIELD_VERSION, "VERSION"}, + {VCARD_FIELD_FN, "FN"}, + {VCARD_FIELD_N, "N"}, + {VCARD_FIELD_NICKNAME, "NICKNAME"}, + {VCARD_FIELD_PHOTO, "PHOTO"}, + {VCARD_FIELD_BDAY, "BDAY"}, + {VCARD_FIELD_ADR, "ADR"}, + {VCARD_FIELD_LABEL, "LABEL"}, + {VCARD_FIELD_TEL, "TEL"}, + {VCARD_FIELD_EMAIL, "EMAIL"}, + {VCARD_FIELD_TITLE, "TITLE"}, + {VCARD_FIELD_ROLE, "ROLE"}, + {VCARD_FIELD_ORG, "ORG"}, + {VCARD_FIELD_NOTE, "NOTE"}, + {VCARD_FIELD_REV, "REV"}, + {VCARD_FIELD_UID, "UID"}, + {VCARD_FIELD_URL, "URL"}, + {VCARD_FIELD_X_ANNIVERSARY, "X-ANNIVERSARY"}, + {VCARD_FIELD_X_IRMC_LUID, "X-IRMC-LUID"} +}; + +static VCARD_FIELD_LIST vcard_field_list_adr[] = { + {VCARD_FIELD_ADR_DOM, "DOM"}, + {VCARD_FIELD_ADR_INTL, "INTL"}, + {VCARD_FIELD_ADR_HOME, "HOME"}, + {VCARD_FIELD_ADR_WORK, "WORK"}, + {VCARD_FIELD_ADR_POSTAL, "POSTAL"}, + {VCARD_FIELD_ADR_PARCEL, "PARCEL"}, + {VCARD_FIELD_ADR_PREF, "PREF"} +}; + +static VCARD_FIELD_LIST vcard_field_list_tel[] = { + {VCARD_FIELD_TEL_HOME, "HOME"}, + {VCARD_FIELD_TEL_MSG, "MSG"}, + {VCARD_FIELD_TEL_WORK, "WORK"}, + {VCARD_FIELD_TEL_VOICE, "VOICE"}, + {VCARD_FIELD_TEL_FAX, "FAX"}, + {VCARD_FIELD_TEL_CELL, "CELL"}, + {VCARD_FIELD_TEL_VIDEO, "VIDEO"}, + {VCARD_FIELD_TEL_PAGER, "PAGER"}, + {VCARD_FIELD_TEL_BBS, "BBS"}, + {VCARD_FIELD_TEL_MODEM, "MODEM"}, + {VCARD_FIELD_TEL_CAR, "CAR"}, + {VCARD_FIELD_TEL_ISDN, "ISDN"}, + {VCARD_FIELD_TEL_PCS, "PCS"}, + {VCARD_FIELD_TEL_PREF, "PREF"} +}; + +static VCARD_FIELD_LIST vcard_field_list_email[] = { + {VCARD_FIELD_EMAIL_HOME, "HOME"}, + {VCARD_FIELD_EMAIL_WORK, "WORK"}, + {VCARD_FIELD_EMAIL_PREF, "PREF"} +}; + +static VCARD_FIELD_LIST vcard_field_list_begin_end[] = { + {-1, "VCARD"} +}; + +static VCARD_FIELD_LIST vcard_field_list_version[] = { + {-1, VCARD_VERSION} +}; + +#endif /* IN_DATASTORE_INFO_VCARD_H_ */ diff --git a/fw-plugin/vcard-plugIn/include/PlugIn_Spec.h b/fw-plugin/vcard-plugIn/include/PlugIn_Spec.h new file mode 100755 index 0000000..6b8ca52 --- /dev/null +++ b/fw-plugin/vcard-plugIn/include/PlugIn_Spec.h @@ -0,0 +1,83 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#ifndef PLUGIN_SPEC_H_ +#define PLUGIN_SPEC_H_ + +typedef enum { + + VCARD_CONTENT_NO_TYPE = 0, + VCARD_CONTENT_EXTENSION = 1, + VCARD_CONTENT_FN = 2, + VCARD_CONTENT_N = 3, + VCARD_CONTENT_NICKNAME = 4, + VCARD_CONTENT_PHOTO = 5, + VCARD_CONTENT_BDAY = 6, + VCARD_CONTENT_ADR = 7, + VCARD_CONTENT_LABEL = 8, + VCARD_CONTENT_TEL = 9, + VCARD_CONTENT_EMAIL = 10, + VCARD_CONTENT_TITLE = 11, + VCARD_CONTENT_ROLE = 12, + VCARD_CONTENT_ORG = 13, + VCARD_CONTENT_NOTE = 14, + VCARD_CONTENT_REV = 15, + VCARD_CONTENT_UID = 16, + VCARD_CONTENT_URL = 17, + VCARD_CONTENT_X_ANNIVERSARY = 18, + VCARD_CONTENT_X_IRMC_LUID = 19, + +/* + VCARD_CONTENT_NAME, + VCARD_CONTENT_PROFILE, + VCARD_CONTENT_SOURCE, + VCARD_CONTENT_MAILER, + VCARD_CONTENT_TZ, + VCARD_CONTENT_GEO, + VCARD_CONTENT_LOGO, + VCARD_CONTENT_AGENT, + VCARD_CONTENT_CATEGORIES, + VCARD_CONTENT_PRODID, + VCARD_CONTENT_SORT-STRING, + VCARD_CONTENT_SOUND, + VCARD_CONTENT_VERSION, + VCARD_CONTENT_CLASS, + VCARD_CONTENT_KEY, + VCARD_CONTENT_X_CHILDREN, +*/ + +} VCARD_VALUE_TYPE; + +#endif /* PLUGIN_SPEC_H_ */ diff --git a/fw-plugin/vcard-plugIn/include/encoding_util.h b/fw-plugin/vcard-plugIn/include/encoding_util.h new file mode 100755 index 0000000..b6fcc22 --- /dev/null +++ b/fw-plugin/vcard-plugIn/include/encoding_util.h @@ -0,0 +1,255 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Seokgil Kang + */ + +#ifndef ENCODING_UTIL_H_ +#define ENCODING_UTIL_H_ + +#include +#include +#include + +#define QP_SIZE 76 +#define BASE64_SIZE 76 + +typedef enum { + EN_TYPE_NONE = 0, + EN_TYPE_QUOTED_PRINTABLE, + EN_TYPE_BASE64 +} ENCODING_TYPE; + +/* Quoted-Printable +* +* @example code +int main() +{ +char *src = "안녕하세요"; +char *encode_src; +int encode_src_len = 0; +char *decode_src; +int decode_src_len = 0; + +int res = encode_QP(src, strlen(src), &encode_src, &encode_src_len); +if (res != 0) +fprintf(stdout, "encode src : %s ( %d ) \n", encode_src, encode_src_len); +else +fprintf(stdout, "encode error !! \n"); + +res = decode_QP(encode_src, encode_src_len, &decode_src, &decode_src_len); +if (res != 0) +fprintf(stdout, "decode src : %s ( %d ) \n", decode_src, decode_src_len); +else +fprintf(stdout, "decode error !! \n"); + +return 0; +} + +*/ + +/* +* @brief encode original source ( encoding type : quoted-printable ) +* @param[in] src original source +* @param[in] src_len length of original source +* @param[out] en_src encoded source +* @param[out] en_src_len length of encoded source +* @return operation result +* @retval 1 success +* @retval 0 fail +*/ +int encode_QP(char *src, int src_len, char **en_src, int *en_src_len); + +/* +* @brief decode encoded source ( decoding type : quoted-printable ) +* @param[in] src encoded source +* @param[in] src_len length of encoded source +* @param[out] de_src decoded source ( original source ) +* @param[out] de_src_len length of decoded source +* @return operation result +* @retval 1 success +* @retval 0 fail +*/ +int decode_QP(char *src, int src_len, char **de_src, int *de_src_len); + +/* Base64 +* +* @example code + +int main() +{ +char *src = "안녕하세요"; +char *encode_src; +int encode_src_len = 0; +char *decode_src; +int decode_src_len = 0; + +int res = encode_base64(src, strlen(src), &encode_src, &encode_src_len); +if (res != 0) +fprintf(stdout, "encode src : %s ( %d ) \n", encode_src, encode_src_len); +else +fprintf(stdout, "encode error !! \n"); + +res = decode_base64(encode_src, encode_src_len, &decode_src, &decode_src_len); +if (res != 0) +fprintf(stdout, "decode src : %s ( %d ) \n", decode_src, decode_src_len); +else +fprintf(stdout, "decode error !! \n"); + +return 0; +} + +*/ + +/* +* @brief encode original source ( encoding type : base64 ) +* @param[in] src original source +* @param[in] src_len length of original source +* @param[out] en_src encoded source +* @param[out] en_src_len length of encoded source +* @return operation result +* @retval 1 success +* @retval 0 fail +*/ +int encode_base64(char *src, int src_len, char **en_src, int *en_src_len); + +/* +* @brief decode encoded source ( decoding type : base64 ) +* @param[in] src encoded source +* @param[in] src_len length of encoded source +* @param[out] de_src decoded source ( original source ) +* @param[out] de_src_len length of decoded source +* @return operation result +* @retval 1 success +* @retval 0 fail +*/ +int decode_base64(char *src, int src_len, char **de_src, int *de_src_len); + +/* +* @brief make the decoding process +* @param[in] src encoded source +* @param[in] src_len length of encoded source +* @param[out] de_src decoded source ( original source ) +* @param[out] de_src_len length of decoded source +* @return operation result +* @retval 1 success +* @retval 0 fail +* +* @example code + +int main() +{ +char *src = "..."; // decoded data +int src_len = strlen(src); +char *decode_src; +int decode_src_len = 0; + +int res = proc_decoding(src, src_len, &decode_src, &decode_src_len); + +if (res != 0) +fprintf(stdout, "decode src : \n%s\n", decode_src); +else +fprintf(stdout, "decode error !! \n"); + +if (decode_src != NULL) +free(decode_src); + +return 0; +} +*/ +int proc_decoding(const char *src, int src_len, char **de_src, int *de_src_len); + +/* +* @brief encoded value is changed to the decoded value +* @param[in] type encoding type +* @param[in] value encoded value (end of string must be '\0' !!) +* ex) =EA=B9=80;=EC=B2=A0=EC=88=98;;;\0 +* @param[in] value_size length of encoded value +* @param[out] decode_str decoded string +* @param[out] decode_str_len length of decoded string +* @return operation result +* @ratval 1 success +* @retval 0 fail +* +* @example code + +int main() +{ +char *data = "..."; // ex) ENCODING=QUOTED-PRINTABLE;CHARSET=UTF-8 +ENCODING_TYPE type = find_encoding_type((const char *)data); + +char *value = "..."; // ex) =EA=B9=80;=EC=B2=A0=EC=88=98;;;\0 +int value_size = strlen(value); + +int decode_str_len = 0; +char *decode_str = (char*)malloc(sizeof(char)*BUF_SIZE); // BUF_SIZE : user define +if (decode_str == NULL) { +// error process +} +memset(decode_str, 0x00, sizeof(char)*BUF_SIZE); + +int res = decode_value(type, value, data_size, &decode_str, &decode_str_len); + +if (res == 1) { +// success process +if (decode_str != NULL) +free(decode_str); +} else { +// error process +if (decode_str != NULL) +free(decode_str); +} + +return 0; +} +*/ +int decode_value(ENCODING_TYPE type, const char *value, int value_size, char **decode_str, int *decode_str_len); + +/* +* @brief get encoding type for data +* @param[in] data vobject data +* @return encoding type +* @ratval >= 1 success +* @retval 0 fail +*/ +ENCODING_TYPE find_encoding_type(const char *data); + +/* +* @brief check whether to exist this string, "ENCODING=" in the data +* @param[in] data vobject data +* @return operation result +* @retval 1 exist +* @retval 0 not exist +*/ +int check_encoding_data(const char *data); + +#endif /* ENCODING_UTIL_H_ */ diff --git a/fw-plugin/vcard-plugIn/src/PlugIn_Interface.c b/fw-plugin/vcard-plugIn/src/PlugIn_Interface.c new file mode 100755 index 0000000..2a0625c --- /dev/null +++ b/fw-plugin/vcard-plugIn/src/PlugIn_Interface.c @@ -0,0 +1,546 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * JungWook Ryu + */ + +#include +#include +#include + +#include "PlugIn_Spec.h" +#include "IN_DataStore_Info_Vcard.h" + +#include "encoding_util.h" + +/* for log */ +#include "agent-framework/Utility/fw_log.h" + +#include "agent-framework/PlugIn/DataConverter_Interface.h" + +#define LOG_TAG "PLUGIN_DC_VCARD" + +static int __free_obj_field_info(Field_Info *field_list, int count); +static int __set_obj_field_info(Field_Info **field_list, int count, VCARD_FIELD_LIST * input_list); +static char *__convert_key_name(int key); + +static int __get_content(const char *value, void *data); + +static DACI_RETURN __convert_service_error_to_common_error(cts_error err); +static void __remove_vcard_field(CTSstruct *contact); +static void __remove_vcard_gslist_field(gpointer data, gpointer user_data); + +DACI_RETURN Converter(const void *agent_data, void **service_data) +{ + FW_LOGV("[dc_vcard_plugIn] Start !!"); + + DACI_RETURN ret = DACI_SUCCESS; + int err = 0; + CTSstruct *temp_service_data = 0; + + /* decoding & convert */ + FW_LOGV("[dc_vcard_plugIn] agent data : %s\n", agent_data); + char *de_agent_data; + int src_len = strlen(agent_data); + int de_agent_data_len = 0; + + if (check_encoding_data(agent_data) == 1) { + err = proc_decoding(agent_data, src_len, &de_agent_data, &de_agent_data_len); + if (err == 0) { + FW_LOGE("[dc_vcard_plugIn] proc_decoding() Fail!\n"); + ret = DACI_ERRORS; + return ret; + } + + err = contacts_svc_get_contact_from_vcard((const void *)de_agent_data, &temp_service_data); + + /*memory free */ + if (de_agent_data != 0) + free(de_agent_data); + } else { + err = contacts_svc_get_contact_from_vcard(agent_data, &temp_service_data); + } + + if (err < CTS_SUCCESS) { + FW_LOGE("[dc_vcard_plugIn] contacts_svc_get_contact_from_vcard() Fail!\n"); + ret = __convert_service_error_to_common_error(err); + *service_data = 0; + } else { + FW_LOGV("[dc_vcard_plugIn] contacts_svc_get_contact_from_vcard() Success!\n"); + *service_data = (void *)temp_service_data; + } + + FW_LOGV("[dc_vcard_plugIn] End !!"); + return ret; +} + +DACI_RETURN Replace_Converter(void *old_service_data, const void *agent_data, void **new_service_data) +{ + FW_LOGV("[dc_vcard_plugIn] Start !!"); + + DACI_RETURN ret = DACI_SUCCESS; + int err = 0; + CTSstruct *temp_new_service_data = 0; + CTSstruct *temp_old_service_data = (CTSstruct *)old_service_data; + + /* 1. agent_data encoding check + * 2. decoding + * 3. new_service_data에 복사 + */ + /* decoding */ + char *de_agent_data; + int src_len = strlen(agent_data); + int de_agent_data_len = 0; + + if (check_encoding_data(agent_data) == 1) { + err = proc_decoding(agent_data, src_len, &de_agent_data, &de_agent_data_len); + if (err == 0) { + FW_LOGE("[dc_vcard_plugIn] proc_decoding() Fail!\n"); +/* ret = DACI_ERRORS; + return ret;*/ + err = contacts_svc_get_contact_from_vcard(agent_data, &temp_new_service_data); + } else { + FW_LOGV("[dc_vcard_plugIn] proc_decoding() Success l!\n"); + err = contacts_svc_get_contact_from_vcard((const void *)de_agent_data, &temp_new_service_data); + + /*memory free */ + if (de_agent_data != 0) + free(de_agent_data); + } + } else { + err = contacts_svc_get_contact_from_vcard(agent_data, &temp_new_service_data); + } + + if (err < CTS_SUCCESS) { + FW_LOGE("[dc_vcard_plugIn] contacts_svc_get_contact_from_vcard() Fail!\n"); + ret = __convert_service_error_to_common_error(err); + *new_service_data = 0; + + /* memory free */ + if (temp_old_service_data != 0) + contacts_svc_struct_free(temp_old_service_data); + + } else { + FW_LOGV("[dc_vcard_plugIn] contacts_svc_get_contact_from_vcard() Success!\n"); + __remove_vcard_field(temp_old_service_data); + err = contacts_svc_struct_merge(temp_old_service_data, temp_new_service_data); + if (err < CTS_SUCCESS) { + FW_LOGE("[dc_vcard_plugIn] contacts_svc_struct_merge() Fail!\n"); + ret = __convert_service_error_to_common_error(err); + *new_service_data = 0; + + /* memory free */ + if (temp_old_service_data != 0) + contacts_svc_struct_free(temp_old_service_data); + } else { + FW_LOGV("[dc_vcard_plugIn] contacts_svc_struct_merge() Success!\n"); + *new_service_data = (void *)temp_old_service_data; + } + } + + /* memory free */ + if (temp_new_service_data != 0) + contacts_svc_struct_free(temp_new_service_data); + + FW_LOGV("[dc_vcard_plugIn] End !!"); + return ret; +} + +DACI_RETURN Reverse_Converter(void *service_data, void **agent_data) +{ + FW_LOGV("[dc_vcard_plugIn] Start !!"); + + DACI_RETURN ret = DACI_SUCCESS; + int err = 0; + char *temp_agent_data = 0; + CTSstruct *temp_service_data = (CTSstruct *)service_data; + + /* Reverse_Converter */ + err = contacts_svc_get_vcard_from_contact(temp_service_data, &temp_agent_data); + if (err < CTS_SUCCESS) { + FW_LOGV("[dc_vcard_plugIn] contacts_svc_get_vcard_from_contact() Fail!\n"); + ret = __convert_service_error_to_common_error(err); + *agent_data = 0; + } else { + FW_LOGV("[dc_vcard_plugIn] contacts_svc_get_vcard_from_contact() Success!\n"); + *agent_data = (void *)temp_agent_data; + } + + /* memory free */ + if (temp_service_data != 0) + contacts_svc_struct_free(temp_service_data); + + FW_LOGV("[dc_vcard_plugIn] End !!"); + return ret; +} + +void *Alloc_Object() +{ + FW_LOGV("[dc_vcard_plugIn] Start !!"); + + char *agent_data = "BEGIN:VCARD\r\n\ +VERSION:2.1\r\n\ +END:VCARD"; + + FW_LOGV("[dc_vcard_plugIn] End !!"); + return (void *)agent_data; +} + +int Free_Object(void *in_object) +{ + FW_LOGV("[dc_vcard_plugIn] Start !!"); + FW_LOGV("[dc_vcard_plugIn] Do nothing\n"); + + return 1; +} + +void *Set_Value_To_Object(void *in_object, int key, char *extension_key, void *value) +{ + FW_LOGV("[dc_vcard_plugIn] Start !!"); + + char *new_agent_data = 0; + char *key_name = 0; + + if (key == VCARD_CONTENT_NO_TYPE) + return (void *)new_agent_data; + else if (key == VCARD_CONTENT_EXTENSION) + key_name = extension_key; + else + key_name = __convert_key_name(key); + + new_agent_data = contacts_svc_vcard_put_content((const char *)in_object, (const char *)key_name, (const char *)value); + + FW_LOGV("[dc_vcard_plugIn] End !!"); + return (void *)new_agent_data; +} + +void *Get_Value_To_Object(void *in_object, int key, char *extension_key) +{ + FW_LOGV("[dc_vcard_plugIn] Start !!"); + + char data[5000] = { 0, }; /* hard coding : size 1000 */ + char *key_name = 0; + + if (key == VCARD_CONTENT_NO_TYPE) + return 0; + else if (key == VCARD_CONTENT_EXTENSION) + key_name = extension_key; + else + key_name = __convert_key_name(key); + + contacts_svc_vcard_get_content((const char *)in_object, (const char *)key_name, __get_content, data); + + FW_LOGV("[dc_vcard_plugIn] End !!"); + + if (strlen(data) == 0) + return 0; + else + return strdup(data); +} + +Object_Info *Get_Obj_Info() +{ + Object_Info *obj_info = (Object_Info *)calloc(1, sizeof(Object_Info)); + + obj_info->type = VCARD_TYPE; + obj_info->version = VCARD_VERSION; + obj_info->field_cnt = sizeof(vcard_field_list) / sizeof(VCARD_FIELD_LIST); + + if (obj_info->field_cnt > 0) + __set_obj_field_info(&(obj_info->field_list), obj_info->field_cnt, vcard_field_list); + + return obj_info; +} + +int Free_Obj_Info(Object_Info *obj_info) +{ + if (obj_info) { + if (obj_info->field_cnt > 0) + if (__free_obj_field_info(obj_info->field_list, obj_info->field_cnt) == 0) + return 0; + + free(obj_info); + } + + return 1; +} + +static int __free_obj_field_info(Field_Info *field_list, int count) +{ + int field_count = 0; + Field_Info *child = NULL; + + if (field_list) { + for (field_count = 0; field_count < count; field_count++) { + child = field_list + field_count; + if (child->field_child_cnt > 0) + if (__free_obj_field_info(child->field_child_list, child->field_child_cnt) == 0) + return 0; + } + free(field_list); + } + + return 1; +} + +static int __set_obj_field_info(Field_Info **field_list, int count, VCARD_FIELD_LIST * input_list) +{ + int field_count = 0; + Field_Info *child = NULL; + + *field_list = (Field_Info *)calloc(count, sizeof(Field_Info)); + + for (field_count = 0; field_count < count; field_count++) { + child = (*field_list) + field_count; + child->field_name = input_list[field_count].field_name; + FW_LOGI("[%s]", child->field_name); + + if (input_list[field_count].field_enum == VCARD_FIELD_BEGIN || input_list[field_count].field_enum == VCARD_FIELD_END) { + child->field_child_cnt = sizeof(vcard_field_list_begin_end) / sizeof(VCARD_FIELD_LIST); + FW_LOGI("----------"); + __set_obj_field_info(&(child->field_child_list), child->field_child_cnt, vcard_field_list_begin_end); + FW_LOGI("=========="); + } else if (input_list[field_count].field_enum == VCARD_FIELD_VERSION) { + child->field_child_cnt = sizeof(vcard_field_list_version) / sizeof(VCARD_FIELD_LIST); + FW_LOGI("----------"); + __set_obj_field_info(&(child->field_child_list), child->field_child_cnt, vcard_field_list_version); + FW_LOGI("=========="); + } else if (input_list[field_count].field_enum == VCARD_FIELD_ADR) { + child->field_child_cnt = sizeof(vcard_field_list_adr) / sizeof(VCARD_FIELD_LIST); + FW_LOGI("----------"); + __set_obj_field_info(&(child->field_child_list), child->field_child_cnt, vcard_field_list_adr); + FW_LOGI("=========="); + } else if (input_list[field_count].field_enum == VCARD_FIELD_TEL) { + child->field_child_cnt = sizeof(vcard_field_list_tel) / sizeof(VCARD_FIELD_LIST); + FW_LOGI("----------"); + __set_obj_field_info(&(child->field_child_list), child->field_child_cnt, vcard_field_list_tel); + FW_LOGI("=========="); + } else if (input_list[field_count].field_enum == VCARD_FIELD_EMAIL) { + child->field_child_cnt = sizeof(vcard_field_list_email) / sizeof(VCARD_FIELD_LIST); + FW_LOGI("----------"); + __set_obj_field_info(&(child->field_child_list), child->field_child_cnt, vcard_field_list_email); + FW_LOGI("=========="); + } + } + + return 1; +} + +static char *__convert_key_name(int key) +{ + char *key_name = 0; + + switch (key) { + case VCARD_CONTENT_FN: + key_name = "FN"; + break; + case VCARD_CONTENT_N: + key_name = "N"; + break; + case VCARD_CONTENT_NICKNAME: + key_name = "NICKNAME"; + break; + case VCARD_CONTENT_PHOTO: + key_name = "PHOTO"; + break; + case VCARD_CONTENT_BDAY: + key_name = "BDAY"; + break; + case VCARD_CONTENT_ADR: + key_name = "ADR"; + break; + case VCARD_CONTENT_LABEL: + key_name = "LABEL"; + break; + case VCARD_CONTENT_TEL: + key_name = "TEL"; + break; + case VCARD_CONTENT_EMAIL: + key_name = "EMAIL"; + break; + case VCARD_CONTENT_TITLE: + key_name = "TITLE"; + break; + case VCARD_CONTENT_ROLE: + key_name = "ROLE"; + break; + case VCARD_CONTENT_ORG: + key_name = "ORG"; + break; + case VCARD_CONTENT_NOTE: + key_name = "NOTE"; + break; + case VCARD_CONTENT_REV: + key_name = "REV"; + break; + case VCARD_CONTENT_UID: + key_name = "UID"; + break; + case VCARD_CONTENT_URL: + key_name = "URL"; + break; + case VCARD_CONTENT_X_ANNIVERSARY: + key_name = "X-ANNIVERSARY"; + break; + case VCARD_CONTENT_X_IRMC_LUID: + key_name = "X-IRMC-LUID"; + break; + default: + break; + } + + return key_name; +} + +static int __get_content(const char *value, void *data) +{ + const char *line_breaker = "\r"; + char *colon_loc = 0; + char *line_breaker_loc = 0; + int data_size = 0; + + colon_loc = (char *)value; + line_breaker_loc = strstr(colon_loc, line_breaker); + data_size = line_breaker_loc - colon_loc; + FW_LOGV("[dc_vcard_plugIn] value : %s", value); + FW_LOGV("[dc_vcard_plugIn] colon_loc : %s", colon_loc); + FW_LOGV("[dc_vcard_plugIn] line_breaker_loc : %s", line_breaker_loc); + FW_LOGV("[dc_vcard_plugIn] data_size : %d", data_size); + + /* hard coding : size 5000 */ + memcpy((char *)data, colon_loc, data_size); + + return 1; +} + +static DACI_RETURN __convert_service_error_to_common_error(cts_error err) +{ + DACI_RETURN ret = DACI_SUCCESS; + FW_LOGV("[dc_vcard_plugIn] Error Code : %d\n", err); + + switch (err) { + case CTS_ERR_DB_LOCK: /* -204 */ + ret = DACI_ERR_LOCKED; + break; + case CTS_ERR_DB_RECORD_NOT_FOUND: /* -203 */ + case CTS_ERR_NO_DATA: /* -3 */ + ret = DACI_ERR_NO_DATA; + break; + case CTS_ERR_DB_NOT_OPENED: /* -201 */ + ret = DACI_ERR_OPEN_FAILED; + break; + case CTS_ERR_NO_SPACE: /* -13 */ + case CTS_ERR_OUT_OF_MEMORY: /* -8 */ + ret = DACI_ERR_MEMORY_FULL; + break; + case CTS_ERR_ALREADY_EXIST: /* -7 */ + ret = DACI_ERR_ALREADY_EXIST; + break; + case CTS_ERR_ARG_NULL: /* -5 */ + case CTS_ERR_ARG_INVALID: /* -4 */ + ret = DACI_ERR_INVALID_CONTENT; + break; + case CTS_ERR_FINISH_ITER: /* -2 */ + case CTS_SUCCESS: /* 0 */ + case CTS_TRUE: /* 1 */ + ret = DACI_SUCCESS; + break; + /* + * CTS_ERR_DB_FAILED: -202, CTS_ERR_VCONF_FAILED: -102, + * CTS_ERR_VOBJECT_FAILED: -101, CTS_ERR_IO_ERR: -12, + * CTS_ERR_ALREADY_RUNNING: -10, CTS_ERR_EXCEEDED_LIMIT: -9, + * CTS_ERR_ENV_INVALID: -6, CTS_ERR_FAIL: -1, + */ + default: + ret = DACI_ERRORS; + break; + } + + return ret; +} + +static void __remove_vcard_field(CTSstruct *contact) +{ + GSList *numbers = 0, *email = 0, *event = 0, *postal = 0, *web = 0, *nick = 0; + CTSvalue *name = 0, *company = 0, *base = 0; + + /* free name */ + contacts_svc_struct_get_value(contact, CTS_CF_NAME_VALUE, &name); + contacts_svc_value_set_str(name, CTS_NAME_VAL_FIRST_STR, 0); + contacts_svc_value_set_str(name, CTS_NAME_VAL_LAST_STR, 0); + contacts_svc_value_set_str(name, CTS_NAME_VAL_ADDITION_STR, 0); + contacts_svc_value_set_str(name, CTS_NAME_VAL_SUFFIX_STR, 0); + contacts_svc_value_set_str(name, CTS_NAME_VAL_PREFIX_STR, 0); + contacts_svc_value_set_str(name, CTS_NAME_VAL_DISPLAY_STR, 0); + + /* free company */ + contacts_svc_struct_get_value(contact, CTS_VALUE_COMPANY, &company); + contacts_svc_value_set_str(company, CTS_COMPANY_VAL_NAME_STR, 0); + contacts_svc_value_set_str(company, CTS_COMPANY_VAL_DEPARTMENT_STR, 0); + contacts_svc_value_set_str(company, CTS_COMPANY_VAL_JOB_TITLE_STR, 0); + contacts_svc_value_set_str(company, CTS_COMPANY_VAL_ROLE_STR, 0); + + /* free base */ + contacts_svc_struct_get_value(contact, CTS_CF_BASE_INFO_VALUE, &base); + contacts_svc_value_set_str(base, CTS_BASE_VAL_IMG_PATH_STR, 0); + contacts_svc_value_set_str(base, CTS_BASE_VAL_FULL_IMG_PATH_STR, 0); + contacts_svc_value_set_str(base, CTS_BASE_VAL_NOTE_STR, 0); + + /* free number */ + contacts_svc_struct_get_list(contact, CTS_CF_NUMBER_LIST, &numbers); + g_slist_foreach(numbers, __remove_vcard_gslist_field, (gpointer) CTS_NUM_VAL_DELETE_BOOL); + + /* free email */ + contacts_svc_struct_get_list(contact, CTS_CF_EMAIL_LIST, &email); + g_slist_foreach(email, __remove_vcard_gslist_field, (gpointer) CTS_EMAIL_VAL_DELETE_BOOL); + + /* free event */ + contacts_svc_struct_get_list(contact, CTS_CF_EVENT_LIST, &event); + g_slist_foreach(event, __remove_vcard_gslist_field, (gpointer) CTS_EVENT_VAL_DELETE_BOOL); + + /* free postal */ + contacts_svc_struct_get_list(contact, CTS_CF_POSTAL_ADDR_LIST, &postal); + g_slist_foreach(postal, __remove_vcard_gslist_field, (gpointer) CTS_POSTAL_VAL_DEFAULT_BOOL); + + /* free web */ + contacts_svc_struct_get_list(contact, CTS_CF_WEB_ADDR_LIST, &web); + g_slist_foreach(web, __remove_vcard_gslist_field, (gpointer) CTS_WEB_VAL_DELETE_BOOL); + + /* free nick */ + contacts_svc_struct_get_list(contact, CTS_CF_NICKNAME_LIST, &nick); + g_slist_foreach(nick, __remove_vcard_gslist_field, (gpointer) CTS_NICKNAME_VAL_DELETE_BOOL); +} + +static void __remove_vcard_gslist_field(gpointer data, gpointer user_data) +{ + contacts_svc_value_set_bool((CTSvalue *) data, (int)user_data, 1); +} diff --git a/fw-plugin/vcard-plugIn/src/encoding_util.c b/fw-plugin/vcard-plugIn/src/encoding_util.c new file mode 100755 index 0000000..12db548 --- /dev/null +++ b/fw-plugin/vcard-plugIn/src/encoding_util.c @@ -0,0 +1,758 @@ +/* + * sync-agent-framework + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: JuHak Park , + * JuneHyuk Lee , + * SunBong Ha + * + * 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. + * + */ + + + + +/* + * For any sort of issue you concern as to this software, + * you may use following point of contact. + * All resources contributed on this software + * are orinigally written by S-Core Inc., a member of Samsung Group. + * + * Seokgil Kang + */ + +#include "encoding_util.h" + +/* for log */ +#include "agent-framework/Utility/fw_log.h" +#define LOG_TAG "ENCODING_UTIL" + +#define TYPE_CHECK_BUF_SIZE 500 /* temporary definition */ + +/* BASE64 TABLE */ +static char base64_table[65] = { + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', + 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', + 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', + 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', + 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', + 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', + '2', '3', '4', '5', '6', '7', '8', '9', '+', + '/', '=' +}; + +/* Quoted-Printable */ +static char *__dec2hex(int dec); +static int __hex2dec(char *hex); + +/* Base64 */ +static int __find_base(char ch); + +/* + * Quoted-Printable + */ +int encode_QP(char *src, int src_len, char **en_src, int *en_src_len) +{ + char *en_hex; + int i = 0; + int j = 0; + int size_cnt = 0; + + if (src == NULL) { + FW_LOGE("[encoding_util] src is NULL\n"); + return 0; + } + + /*encoded string length is three times longer than existing maximum string length */ + int full_lenth = src_len * 3 + 1 + (int)(src_len * 3 / 76) * 3; + *en_src = (char *)malloc(sizeof(char) * full_lenth); + if (*en_src == 0x00) { + FW_LOGE("[encoding_util] malloc fail !!\n"); + return 0; + } + memset(*en_src, 0x00, src_len * 3 + 1); + + FW_LOGV("[encoding_util] src_len : %d\n", src_len); + for (i = 0; i < src_len; i++) { + /* FW_LOGV("[encoding_util] i : %d\n", i); */ + if (size_cnt >= QP_SIZE - 3) { + size_cnt = 0; + (*en_src)[j++] = 0x0A; + } + + if ((src[i] >= 33 && src[i] <= 126) || (src[i] == 0x0A)) { + if (src[i] == 61) { + en_hex = __dec2hex(src[i]); + (*en_src)[j++] = 0x3D; /* '=' */ + (*en_src)[j++] = en_hex[0]; + (*en_src)[j++] = en_hex[1]; + size_cnt += 3; + } else { + size_cnt++; + (*en_src)[j++] = src[i]; + } + } else if (src[i] == 9 || src[i] == 32) { + if (src[i + 1] == 0x0A || src[i + 1] == 0x00) { /* TAB or WhiteSpace */ + en_hex = __dec2hex(src[i]); + (*en_src)[j++] = 0x3D; /* '=' */ + (*en_src)[j++] = en_hex[0]; + (*en_src)[j++] = en_hex[1]; + size_cnt += 3; + } else { + size_cnt++; + (*en_src)[j++] = src[i]; + } + } else { + en_hex = __dec2hex(src[i]); + (*en_src)[j++] = 0x3D; /* '=' */ + (*en_src)[j++] = en_hex[0]; + (*en_src)[j++] = en_hex[1]; + FW_LOGV("[encoding_util] en_src : %s\n", *en_src); + size_cnt += 3; + } + } + + (*en_src)[j] = 0x00; + *en_src_len = size_cnt; + + return 1; +} + +int decode_QP(char *src, int src_len, char **de_src, int *de_src_len) +{ + char hex[3]; + char ch; + int dec = 0; + int is_space = 0; + int i = 0; + int j = 0; + + if (src == NULL) { + FW_LOGE("[encoding_util] src is NULL\n"); + return 0; + } + + *de_src = (char *)malloc(sizeof(char) * (src_len + 1)); + if (*de_src == 0x00) { + FW_LOGE("[encoding_util] malloc is fail !!\n"); + return 0; + } + memset(*de_src, 0x00, sizeof(char) * (src_len + 1)); + + while (src[i] != '\0') { + if (src[i] == 0x3D) { /* '=' */ + /* check whiteSpace */ + ch = src[++i]; + + /* '=' skip if next character is a TAB or WhiteSpace */ + while (ch == 0x09 || ch == 0x20) { + is_space = 1; + ch = src[++i]; + + if (is_space == 1) { + is_space = 0; + continue; + } + } + + /* '=' skip if next character is 3D which means '=' (encoding error case ??)*/ + while (ch == '3') { + ch = src[++i]; + + if (ch == 'D') { + ch = src[++i]; + continue; + } + } + + /* if next character is LF after '=' do doft line break + * encoded QP string on one line 76 character is allowed + */ + if (ch == 0x0A) { /* LF */ + i++; + continue; + } + + hex[0] = src[i++]; + hex[1] = src[i++]; + hex[2] = '\0'; + + dec = __hex2dec(hex); + + /* decoding error */ + if (dec < 0) { + /* when error occur, restore the previous encoding message */ + (*de_src)[j++] = 0x3D; /* '=' */ + (*de_src)[j++] = hex[0]; + (*de_src)[j++] = hex[1]; + } else { + (*de_src)[j++] = dec; + } + } else if (src[i] > 0x7E) { /* encoding error */ + i++; /* ignore that character */ + } else { + (*de_src)[j++] = src[i++]; + } + } + + (*de_src)[j] = '\0'; + *de_src_len = j; + + return 1; +} + +static char *__dec2hex(int dec) +{ + static char hex[3]; + int i; + int ch; + + for (i = 0; i < 2; i++) { + if (i == 0) { + ch = (dec & 0xF0) >> 4; + } else if (i == 1) { + ch = (dec & 0x0F); + } + + if (ch >= 10) { + hex[i] = 'A' + ch - 10; + } else { + hex[i] = '0' + ch; + } + } + + hex[i] = 0x00; + + FW_LOGV("[encoding_util] hex : %s\n", hex); + + return &hex[0]; +} + +static int __hex2dec(char *hex) +{ + int dec = 0; + int byte; + int i = 0; + + for (i = 0; i < 2; i++) { + if (hex[i] >= '0' && hex[i] <= '9') { + byte = hex[i] - '0'; + } else if (hex[i] >= 'A' && hex[i] <= 'F') { + byte = hex[i] - 'A' + 10; + } else if (hex[i] >= 'a' && hex[i] <= 'f') { + byte = hex[i] - 'a' + 10; + } else { + byte = -1; + } + + if (byte < 0) + return -1; + + dec += (i == 0) ? byte << 4 : byte; + } + + return dec; +} + +/* + * Base64 + */ +int encode_base64(char *src, int src_len, char **en_src, int *en_src_len) +{ + int i = 0; + int j = 0; + int cnt = 0; + int ch = 0; + int size_cnt = 0; + + if (src == NULL) { + FW_LOGE("[encoding_util] src is NULL\n"); + return 0; + } + + *en_src = (char *)malloc(sizeof(char) * (src_len * 2)); + if (*en_src == 0x00) { + FW_LOGE("[encoding_util] malloc fail !!\n"); + return 0; + } + memset(*en_src, 0x00, src_len * 2); + + while (1) { + switch (cnt++) { + case 0: + { + if (i < src_len) { + ch = (src[i] & 0xFC) >> 2; + } else { + ch = -1; + } + } + break; + + case 1: + { + if (i < src_len) { + if (i + 1 < src_len) { + ch = ((src[i] & 0x03) << 4) | ((src[i + 1] & 0xF0) >> 4); + } else { + ch = ((src[i] & 0x03) << 4); + } + } else { + ch = -1; + } + i++; + break; + } + + case 2: + { + if (i < src_len) { + if (i + 1 < src_len) { + ch = ((src[i] & 0x0F) << 2) | ((src[i] & 0xC0) >> 6); + } else { + ch = ((src[i] & 0x0F) << 2); + } + } else { + ch = -1; + } + i++; + } + break; + + case 3: + { + if (i < src_len) { + ch = (src[i] & 0x3F); + } else { + ch = -1; + } + i++; + cnt = 0; + } + break; + } + + /* + if (ch >= 0 && ch <= 25) { // Upper Case Alphabet + (*en_src)[j++] = 'A' + ch; + } else if (ch >= 26 && ch <= 51) { // Lower Case Alphabet + (*en_src)[j++] = 'a' + ch - 26; + } else if (ch >= 52 && ch <= 61) { // Digit + (*en_src)[j++] = '0' + ch - 52; + } else if (ch == 62) { + (*en_src)[j++] = '+'; + } else if (ch == 63) { + (*en_src)[j++] = '/'; + } else if (ch == -1) { + (*en_src)[j++] = '='; // padding + } + */ + + if ((ch != -1) && (ch >= 0 && ch <= 64)) { + (*en_src)[j++] = base64_table[ch]; + } else { + (*en_src)[j++] = base64_table[64]; /* padding */ + } + + size_cnt++; + + if (j % 4 == 0) { + if (size_cnt == BASE64_SIZE) { + size_cnt = 0; + (*en_src)[j++] = 0x0A; /* soft line break */ + } + + if (i >= src_len) + break; + } + } + + (*en_src)[j] = 0x00; + *en_src_len = j; + + return 1; +} + +int decode_base64(char *src, int src_len, char **de_src, int *de_src_len) +{ + long tmp = 0; /* 4byte (using decoding) */ + int i = 0; + int j = 0; + int cnt = 0; + int pad_cnt = 0; + + if (src == NULL) { + FW_LOGE("[encoding_util] src is NULL\n"); + return 0; + } + + /* de_src is enough for the src_len 3/4 size */ + *de_src = (char *)malloc(sizeof(char) * (src_len)); + if (*de_src == 0x00) { + FW_LOGE("[encoding_util] malloc is fail !!\n"); + return 0; + } + memset(*de_src, 0x00, src_len); + + while (src[i] != '\0') { + /* + if (isupper(src[i])) { + tmp = (tmp << 6) | (src[i] - 'A'); // Upper case : 0 ~ 25 + } else if (islower(src[i])) { + tmp = (tmp << 6) | (src[i] - 'a' + 0x1A); // Lower case : 26(0x1A) ~ 51 + } else if (isdigit(src[i])) { + tmp = (tmp << 6) | (src[i] - '0' + 0x34); // Number : 52(0x34) ~ 61 + } else if (src[i] == '+') { + tmp = (tmp << 6) | 0x3E; // '+' : 62(0x3E) + } else if (src[i] == '/') { + tmp = (tmp << 6) | 0x3F; // '/' : 63(0x3F) + } else if (src[i] == '=') { + pad_cnt++; + tmp = (tmp << 6); // '=' : padding + } else { + tmp = (tmp << 6); // encoding error + fFW_LOGV(stdout, "encoding error !! \n"); + } + */ + + tmp = (tmp << 6) | (__find_base(src[i])); + if (tmp == 64) { + pad_cnt++; + } else if (tmp == -1) { + FW_LOGE("[encoding_util] encoding error \n"); + } + + if (++cnt >= 4) { + (*de_src)[j++] = (char)((tmp & 0x00FF0000) >> 16); + (*de_src)[j++] = (char)((tmp & 0x0000FF00) >> 8); + (*de_src)[j++] = (char)(tmp & 0x000000FF); + + cnt = 0; + tmp = 0; + + if (src[i + 1] == 0x0A) { /* soft line break */ + i++; + } + } + + i++; + } + + (*de_src)[j - pad_cnt] = '\0'; + *de_src_len = j - pad_cnt; + + return 1; +} + +int proc_decoding(const char *src, int src_len, char **de_src, int *de_src_len) +{ + FW_LOGV("[encoding_util] Start \n"); + + const char *reg_src = NULL; + reg_src = src; + + FW_LOGV("[encoding_util] << src >> \n%s\n", src); + + *de_src = (char *)malloc(sizeof(char) * (src_len + 1)); + if (*de_src == NULL) { + FW_LOGV("[encoding_util] malloc error !! \n"); + + return 0; + } + memset(*de_src, 0x00, sizeof(char) * (src_len + 1)); + + char colon[] = ":"; + char line_breaker[] = "\r\n"; + char *start_decoding = NULL; + int data_size = 0; + int res = 0; + int de_temp_len = 0; + + FW_LOGV("src len : %d", src_len); + char *de_temp = (char *)malloc(sizeof(char) * src_len); /* todo : temporary */ + if (de_temp == NULL) { + FW_LOGE("[encoding_util] malloc error !!\n"); + + if (*de_src != NULL) + free(*de_src); + + return 0; + } + + while ((start_decoding = strstr(src, "ENCODING="))) { + char *colon_loc = strstr(start_decoding, colon);/* find ':''s location */ + char *line_breaker_loc = NULL; + if (colon_loc != NULL) { + line_breaker_loc = strstr(colon_loc, line_breaker); /* find "\r\n"'s location */ + } else { + if (*de_src != NULL) + free(*de_src); + + if (de_temp != NULL) + free(de_temp); + return 0; + } + + /* + * if find "ENCODING=" do strcat data until ":" to de_src + */ + data_size = (colon_loc + 1) - src; /* colon_loc + 1 ==> Until next character of ':'*/ + + FW_LOGV("data_size : %d", data_size); + char *temp = (char *)malloc(sizeof(char) * (data_size + 1)); + if (temp == NULL) { + FW_LOGE("[encoding_util] malloc error !!"); + + if (*de_src != NULL) + free(*de_src); + + if (de_temp != NULL) + free(de_temp); + + return 0; + } + memset(temp, 0x00, sizeof(char) * (data_size + 1)); + memcpy(temp, src, data_size); + strcat(*de_src, temp); + if (temp != NULL) + free(temp); + + FW_LOGV("[encoding_util] << *de_src >> \n %s\n", *de_src); + + /* + * copy data from ":" until "\r\n"(actual encoding stream) + */ + data_size = line_breaker_loc - colon_loc; /* from ':' until "\r\n" + '\0' */ + char *value = (char *)malloc(sizeof(char) * (data_size + 1)); + if (value == NULL) { + FW_LOGE("[encoding_util] malloc error !!\n"); + + if (*de_src != NULL) + free(*de_src); + + if (de_temp != NULL) + free(de_temp); + + return 0; + } + memset(value, 0x00, sizeof(char) * (data_size + 1)); + memcpy(value, ++colon_loc, data_size); /* from ':' until "\r\n" */ + value[data_size] = '\0'; + FW_LOGV("value : %s, value_len : %d", value, strlen(value)); + + /* + * Get encoding type using data from "ENCODING=" to ":" + */ + char type_check[TYPE_CHECK_BUF_SIZE] = { 0, }; + int type_check_size = colon_loc - start_decoding; + strncpy(type_check, start_decoding, type_check_size); + FW_LOGV("[encoding_util] type check : %s\n", type_check); + ENCODING_TYPE type = find_encoding_type((const char *)type_check); + + /* + * Process decoding by passing the actual value and encoding type to decode_value() + */ + de_temp_len = 0; + memset(de_temp, 0x00, sizeof(char) * src_len); /* todo : temporary */ + res = decode_value(type, value, data_size, &de_temp, &de_temp_len); + + if (res != 1) { + FW_LOGE("[encoding_util] decode_value error !!\n"); + + if (*de_src != NULL) + free(*de_src); + + if (de_temp != NULL) + free(de_temp); + + return 0; + } + + /* + * Append decoded data to de_src + */ + FW_LOGV("[encoding_util] de_temp : %s\n", de_temp); + strcat(*de_src, de_temp); + + /* + * find "ENCODING=" since "\r\n" agina + */ + src = line_breaker_loc; + + if (value != NULL) + free(value); + } + + strcat(*de_src, src); /* Append remain character */ + *de_src_len = strlen(*de_src); + FW_LOGV("[encoding_util] changed src : \n%s ( %d ) \n", *de_src, *de_src_len); + + if (de_temp != NULL) + free(de_temp); + + FW_LOGV("[encoding_util] End \n"); + + return 1; +} + +int check_encoding_data(const char *data) +{ + if (strstr(data, "ENCODING=") != NULL) { + FW_LOGV("[encoding_util] exist encoding data !! \n"); + return 1; + } else { + FW_LOGV("[encoding_util] not exist encoding data !! \n"); + return 0; + } +} + +ENCODING_TYPE find_encoding_type(const char *data) +{ + FW_LOGV("[encoding_util] Start !! \n"); + + ENCODING_TYPE type = EN_TYPE_NONE; + if (strstr(data, "QUOTED-PRINTABLE") != NULL) { + FW_LOGV("[encoding_util] type : QP\n"); + type = EN_TYPE_QUOTED_PRINTABLE; + } else if (strstr(data, "BASE64") != NULL) { + FW_LOGV("[encoding_util] type : BASE64\n"); + type = EN_TYPE_BASE64; + } else { + FW_LOGV("[encoding_util] not supported type !! \n"); + } + + FW_LOGV("[encoding_util] End !! \n"); + + return type; +} + +int decode_value(ENCODING_TYPE type, const char *value, int value_size, char **decode_str, int *decode_str_len) +{ + FW_LOGV("[encoding_util] Start !! \n"); + + int res = 1; + const char *start_pos = NULL; + const char *cursor = NULL; + int semi_cnt = 0; + + /* + * ex> value - =EA=B9=80;=EC=B2=A0=EC=88=98;;;\0 + */ + cursor = value; + start_pos = value; + + while (*cursor != '\0') { + if ((*cursor != ';') && (*cursor != '\r')) { + cursor++; + continue; + } else if (*cursor == ';') { + semi_cnt++; + } + + int data_size = 0; + data_size = cursor - start_pos; + + if (data_size == 0) { + cursor++; + start_pos++; + } else { + char *temp = (char *)malloc(sizeof(char) * (value_size + 1)); + if (temp == NULL) { + FW_LOGE("[encoding_util] malloc error !!"); + return 0; + } + memset(temp, 0x00, sizeof(char) * (value_size + 1)); + memcpy(temp, start_pos, data_size); + + FW_LOGV("[encoding_util] temp : %s \n", temp); + + char *decoding = 0; + int decoding_len = 0; + + switch (type) { + case EN_TYPE_QUOTED_PRINTABLE: + res = decode_QP(temp, data_size, &decoding, &decoding_len); + if (temp != NULL) + free(temp); + break; + case EN_TYPE_BASE64: + res = decode_base64(temp, data_size, &decoding, &decoding_len); + if (temp != NULL) + free(temp); + break; + default: + break; + } + + FW_LOGV("[encoding_util] decoding : %s ( %d )\n", decoding, decoding_len); + + if (res != 1) { + FW_LOGE("[encoding_util] decoding error !! \n"); + + if (decoding != NULL) + free(decoding); + + return 0; + } else { + FW_LOGV("[encoding_util] decoding success !!"); + if (decoding != NULL) { + strcat(*decode_str, decoding); + FW_LOGV("[encoding_util] *decode_str : %s\n", *decode_str); + } else { + FW_LOGE("[encoding_util] decoding is NULL !!"); + return 0; + } + } + + if (decoding != NULL) + free(decoding); + + cursor++; + start_pos = cursor; + } + + if (semi_cnt > 0) { + int len = strlen(*decode_str); + (*decode_str)[len] = ';'; + FW_LOGV("[encoding_util] *decode_str : %s ( %d )\n", *decode_str, strlen(*decode_str)); + semi_cnt--; + } + } + + *decode_str_len = strlen(*decode_str); + + FW_LOGV("[encoding_util] *decode_str : %s ( %d )\n", *decode_str, *decode_str_len); + + FW_LOGV("[encoding_util] End !! \n"); + + return res; +} + +static int __find_base(char ch) +{ + FW_LOGV("[encoding_util] Start !! \n"); + + int i = 0; + for (i = 0; i < 65; i++) { + if (base64_table[i] == ch) { + FW_LOGV("[encoding_util] End !! \n"); + return i; + } + } + + FW_LOGV("[encoding_util] End !! \n"); + + return -1; +} diff --git a/packaging/sync-agent-framework.spec b/packaging/sync-agent-framework.spec new file mode 100755 index 0000000..a14af5f --- /dev/null +++ b/packaging/sync-agent-framework.spec @@ -0,0 +1,88 @@ +Name: sync-agent-framework +Summary: Sync agent FW Library +Version: 0.1.9 +Release: 1 +Group: TO_BE/FILLED_IN +License: Samsung Proprietary License +Source0: sync-agent-framework-%{version}.tar.gz +Requires(post): /sbin/ldconfig +Requires(postun): /sbin/ldconfig +BuildRequires: pkgconfig(glib-2.0) +BuildRequires: pkgconfig(sqlite3) +BuildRequires: pkgconfig(libsoup-2.4) +BuildRequires: pkgconfig(vconf) +BuildRequires: pkgconfig(uuid) +BuildRequires: pkgconfig(msg-service) +BuildRequires: pkgconfig(drm-service) +BuildRequires: pkgconfig(libxml-2.0) +BuildRequires: pkgconfig(libwbxml2) +BuildRequires: pkgconfig(calendar) +BuildRequires: pkgconfig(pmapi) +BuildRequires: pkgconfig(accounts-svc) +#BuildRequires: pkgconfig(email-service) +BuildRequires: pkgconfig(contacts-service) +#BuildRequires: pkgconfig(kies_alarm) +#BuildRequires: pkgconfig(bookmark-service) +BuildRequires: pkgconfig(memo) +#BuildRequires: pkgconfig(push) +BuildRequires: pkgconfig(alarm-service) +#BuildRequires: pkgconfig(location) +BuildRequires: pkgconfig(tapi) +BuildRequires: pkgconfig(sysman) +BuildRequires: pkgconfig(capi-base-common) +#BuildRequires: pkgconfig(capi-messaging-push) +#BuildRequires: drm-bnr-devel +#BuildRequires: data-router-devel +#BuildRequires: liboauth-devel +BuildRequires: libgcrypt-devel +BuildRequires: cmake + +Requires(post): /sbin/ldconfig +Requires(postun): /sbin/ldconfig + + +%description +sync-agent-framework library (development headers) + + +%package devel +Summary: Development files for %{name} +Group: Development/Libraries +Requires: %{name} = %{version}-%{release} +%description devel +Development files for %{name} + + + + +%prep +%setup -q + + +%build +cmake . -DCMAKE_INSTALL_PREFIX=/usr + + +make %{?jobs:-j%jobs} + +%install +rm -rf %{buildroot} +%make_install + + +%post -p /sbin/ldconfig +%postun -p /sbin/ldconfig + + + + + +%files +%defattr(-,root,root,-) +%{_libdir}/*.so + +%files devel +%defattr(-,root,root,-) +%{_includedir}/agent-framework/* +%{_libdir}/*.so +%{_libdir}/pkgconfig/sync-agent-framework.pc diff --git a/pkg_build.sh b/pkg_build.sh new file mode 100755 index 0000000..3c043d5 --- /dev/null +++ b/pkg_build.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +sbs -e dpkg-buildpackage -b + diff --git a/pkg_clean.sh b/pkg_clean.sh new file mode 100755 index 0000000..58acc1f --- /dev/null +++ b/pkg_clean.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +find . -name CMakeFiles -exec rm -rf {} \; +find . -name CMakeCache.txt -exec rm -rf {} \; +find . -name Makefile -exec rm -rf {} \; +find . -name cmake_install.cmake -exec rm -rf {} \; +find . -name install_manifest.txt -exec rm -rf {} \; +find . -name *.pc -exec rm -rf {} \; + +find . -name *.so -exec rm -rf {} \; + +rm -rf ./framework/fw-test + +rm -rf ./debian/PKG +rm -rf ./debian/libsync-agent-framework +rm -rf ./debian/libsync-agent-framework-dbg +rm -rf ./debian/libsync-agent-framework-dev +rm -rf ./debian/tmp +rm -rf ./debian/files +rm -rf ./debian/*.log +rm -rf ./debian/*.debhelper +rm -rf ./debian/*.substvars + +rm -rf ../libsync-agent-framework-dbg_0.1.9_armel.deb +rm -rf ../libsync-agent-framework-dev_0.1.9_armel.deb +rm -rf ../libsync-agent-framework_0.1.9_armel.deb +rm -rf ../libsync-agent-framework_0.1.9_armel.changes + diff --git a/pkg_install.sh b/pkg_install.sh new file mode 100755 index 0000000..3e2e636 --- /dev/null +++ b/pkg_install.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +dpkg -i ../libsync-agent-framework_0.1.9_armel.deb +dpkg -i ../libsync-agent-framework-dev_0.1.9_armel.deb +dpkg -i ../libsync-agent-framework-dbg_0.1.9_armel.deb + diff --git a/pkg_uninstall.sh b/pkg_uninstall.sh new file mode 100755 index 0000000..56569cf --- /dev/null +++ b/pkg_uninstall.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +dpkg -P libsync-agent-framework-dbg +dpkg -P libsync-agent-framework-dev +dpkg -P libsync-agent-framework + diff --git a/sync-agent-framework.pc.in b/sync-agent-framework.pc.in new file mode 100755 index 0000000..562a61a --- /dev/null +++ b/sync-agent-framework.pc.in @@ -0,0 +1,19 @@ +prefix=@PREFIX@ +exec_prefix=@PREFIX@ +libdir=@PREFIX@/usr/lib +includedir=@PREFIX@/usr/include + +Name: libsync-agent-framework +Description: Integrated Framework Library Package +Requires: +Version: @VERSION@ +Libs: -L${libdir} -lsync-agent-framework +Cflags: -I${includedir}/agent-framework + + + + + + + + -- 2.7.4