upload tizen1.0 source
[framework/system/sync-agent.git] / framework / src / Initialization / initialize.c
1 /*
2  * sync-agent-framework
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: JuHak Park <juhaki.park@samsung.com>,
7  *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
8  *          SunBong Ha <sunbong.ha@samsung.com>
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  */
23
24
25
26
27 /*
28  * For any sort of issue you concern as to this software,
29  * you may use following point of contact.
30  * All resources contributed on this software
31  * are orinigally written by S-Core Inc., a member of Samsung Group.
32  *
33  * JungWook Ryu <jungwook.ryu@samsung.com>,
34  */
35
36 #include "Utility/fw_log.h"
37 #include "Utility/fw_mainloop.h"
38
39 #include "Account/Account_Util.h"
40
41 #include "PlugIn/PlugIn_DataConnector.h"
42 #include "PlugIn/PlugIn_Account.h"
43 #include "PlugIn/PlugIn_PlatformMonitor.h"
44 #include "PlugIn/PlugIn_NetworkAccess.h"
45 #include "PlugIn/PlugIn_DeviceInfo.h"
46
47 #include "DataAdapter/DACI_Service.h"
48 #include "DataAdapter/DACI_ChangeLog.h"
49
50 #include "NetworkAccess/NACI.h"
51
52 #include "Device/EXT_DCI_Errors.h"
53 #include "Device/EXT_DCI_DevInfo.h"
54
55 #include "PlatformMonitor/EXT_PMCI_Errors.h"
56
57 #include "Initialization/initialize_parser.h"
58 #include "Initialization/initialize.h"
59
60 #define LOG_TAG "AF_INIT"
61
62 INIT_ERROR Init_Framework(const char *init_config_path)
63 {
64         INIT_ERROR init_error = parse_Init_config(init_config_path);
65
66         if (init_error != INIT_SUCCESS) {
67                 return init_error;
68         }
69
70         const char *agent_key = get_AgentKey();
71         FW_LOGV("Agent KEY : %s", agent_key);
72
73         int plugIn_dc_count = 0;
74         const PlugIn_DataConnector *plugIn_dc_repository = getDataConnector_PlugInRepository(&plugIn_dc_count);
75
76         /*
77          * Account
78          */
79         if (plugIn_dc_count != 0) {
80                 int plugIn_acc_id = getAccount_PlugIn_ID();
81                 Set_AccountReposioryName pFunc_Set_AccountReposioryName = getFunction_Set_AccountReposioryName(plugIn_acc_id);
82                 if (pFunc_Set_AccountReposioryName != 0) {
83                         pFunc_Set_AccountReposioryName(agent_key);
84                 }
85         }
86
87         /*
88          * DataConnector Process ChangeNoti
89          */
90         int i = 0;
91         for (; i < plugIn_dc_count; i++) {
92                 if (plugIn_dc_repository[i].handle_changenoti) {
93                         int plugIn_id = plugIn_dc_repository[i].plugIn_info.plugIn_id;
94
95                         SetCallBack_AddItem setCallBack_AddItem = getFunction_DataConnector_SetCallBack_AddItem(plugIn_id);
96                         SetCallBack_DeleteItem setCallBack_DeleteItem = getFunction_DataConnector_SetCallBack_DeleteItem(plugIn_id);
97                         SetCallBack_UpdateItem setCallBack_UpdateItem = getFunction_DataConnector_SetCallBack_UpdateItem(plugIn_id);
98                         SetCallBack_GetAccountIDList setCallBack_GetAccountIDList = getFunction_DataConnector_SetCallBack_GetAccountIDList(plugIn_id);
99                         StartListening_ChangeNoti startListening_ChangeNoti = getFunction_DataConnector_StartListening_ChangeNoti(plugIn_id);
100
101                         DACI_RETURN da_error = DACI_Service_Open(plugIn_id);
102                         if (da_error != DACI_SUCCESS) {
103                                 FW_LOGE("DACI_Service_Open(%d) Failed!!", plugIn_id);
104                                 return INIT_SERVICE_DB_FAIL;
105                         } else {
106                                 FW_LOGV("DACI_Service_Open(%d) Success!!", plugIn_id);
107                         }
108                         setCallBack_AddItem(handle_ADD_ITEM);
109                         setCallBack_DeleteItem(handle_DEL_ITEM);
110                         setCallBack_UpdateItem(handle_UPDATE_ITEM);
111                         setCallBack_GetAccountIDList(getAccountIDList_Service);
112
113                         if (plugIn_dc_repository[i].use_mainloop) {
114                                 register_Callback2MainLoop(startListening_ChangeNoti, 0);
115                         }
116                 }
117         }
118
119         /*
120          * NetworkAccess
121          */
122         int *na_plugIn_id_list = 0;
123         int na_plugIn_cnt = get_NetworkAccess_PlugIn_ID_List(&na_plugIn_id_list);
124
125         if (na_plugIn_id_list != 0) {
126                 i = 0;
127                 for (; i < na_plugIn_cnt; i++) {
128                         NACI_RESULT res = NACI_Init(na_plugIn_id_list[i]);
129                         if (res == NACI_SUCCESS) {
130                                 FW_LOGI("Success NACI_init() : %d", na_plugIn_id_list[i]);
131                         } else {
132                                 FW_LOGE("Failed NACI_init() : %d, %d", res, na_plugIn_id_list[i]);
133                                 if (na_plugIn_id_list != 0) {
134                                         free(na_plugIn_id_list);
135                                 }
136                                 return INIT_NETWORK_FAIL;
137                         }
138                 }
139                 free(na_plugIn_id_list);
140         }
141
142         /*
143          * Device Initialization
144          */
145         int plugIn_device_id;
146         if (isExsist_DeviceInfo_PlugIn(&plugIn_device_id)) {
147                 DCI_RETURN res = DCI_Init(plugIn_device_id);
148                 if (res == DCI_SUCCESS) {
149                         FW_LOGI("Success DCI_init() : %d", plugIn_device_id);
150                 } else {
151                         FW_LOGI("Failed DCI_init() : %d, %d", res, plugIn_device_id);
152                         return INIT_DEVICE_FAIL;
153                 }
154         }
155
156         if (use_MainLoop()) {
157                 FW_LOGV("Run Main Loop!!");
158                 run_MainLoop();
159         }
160
161         return INIT_SUCCESS;
162 }