Tizen 2.0 Release
[framework/system/oma-dm-agent.git] / src / agent / dm-engine / bootstrap / factory_bootstrap.c
1 /*
2  * oma-dm-agent
3  * Copyright (c) 2012 Samsung Electronics Co., Ltd.
4  *
5  * Licensed under the Apache License, Version 2.0 (the License);
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 /*sync-agent*/
19 #include <sync_agent.h>
20
21 /*dm-agent*/
22 #include "common/dm_common.h"
23 #include "mo-handler/dm_mo_handler.h"
24 #include "mo-handler/dm_mo_common.h"
25 #include "dm-engine/bootstrap/factory_bootstrap.h"
26
27 #ifndef OMADM_AGENT_LOG
28 #undef LOG_TAG
29 #define LOG_TAG "OMA_DM_BOOTSTRAP"
30 #endif
31
32 static DM_ERROR _completed_bootstrap();
33 static DM_ERROR _start_ddf_mo(GSList * seg_list);
34
35 static DM_ERROR _completed_bootstrap()
36 {
37         _INNER_FUNC_ENTER;
38
39         DM_ERROR ret = DM_OK;
40         ENGINE_STATUS status = DM_IDLE;
41
42         ret = Update_Engine_Status_Column(IDLE_ENGINE, VALUE_ENGINE_STATUS, &status);
43         _DEBUG_TRACE("update engine status : %d", ret);
44         if (ret != DM_OK)
45                 goto error;
46
47         _INNER_FUNC_EXIT;
48         return ret;
49  error:
50         _DEBUG_TRACE(" end!! error : %d \n", ret);
51         _INNER_FUNC_EXIT;
52         return ret;
53 }
54
55 static DM_ERROR _start_ddf_mo(GSList * seg_list)
56 {
57         _INNER_FUNC_ENTER;
58
59         DM_ERROR ret = DM_OK;
60
61         GSList *ddf_iter = NULL;
62         sync_agent_dm_mo_error_e err_code;
63         ddf_spec *ddf_content;
64
65         retvm_if((seg_list) == NULL, COMMON_ERR_IS_NULL, "seg_list is NULL!!");
66
67         for (ddf_iter = seg_list; ddf_iter != NULL; ddf_iter = g_slist_next(ddf_iter)) {
68                 ddf_content = (ddf_spec *) (ddf_iter->data);
69
70                 _DEBUG_TRACE(" mo_type : %d schema : %s sevice_ddf : %d server_type : %d\n", ddf_content->mo_type, ddf_content->schema_file, ddf_content->service_ddf, ddf_content->server_type);
71                 err_code = sync_agent_construct_mo_table(ddf_content->mo_type, ddf_content->schema_file, ddf_content->service_ddf, ddf_content->server_type);
72
73                 if (err_code == SYNC_AGENT_DM_MO_SUCCESS) {
74                         _DEBUG_TRACE("Success to sync_agent_construct_mo_table()\n");
75                 } else {
76                         _DEBUG_TRACE("Failed to sync_agent_construct_mo_table()\n");
77                         ret = DM_ERR_DDF_PROCCESS;
78                         goto error;
79                 }
80         }
81
82         _INNER_FUNC_EXIT;
83         return ret;
84  error:
85         _DEBUG_TRACE(" end!! error : %d \n", ret);
86         _INNER_FUNC_EXIT;
87         return ret;
88 }
89
90 DM_ERROR factory_bootstrap(SERVICE_SERVER_TYPE server_type)
91 {
92         _INNER_FUNC_EXIT;
93
94         DM_ERROR ret = DM_OK;
95
96         /*dm acc */
97         //pre_define_mo();
98
99         /*change css value for test */
100         int file_ret = 0;
101         char *file_path = NULL;
102         unsigned long required_length = 0;
103         char *required_contents = NULL;
104         int is_exist = 0;
105
106         switch (server_type) {
107         case SAMSUNG_FUMO_TYPE:
108                 {
109                         ret = is_exist_dmacc(SAMSUNG_FUMO_TYPE, &is_exist);
110                         if (ret != DM_OK) {
111                                 _DEBUG_TRACE("is exist dmacc error : %d or not exist dm acc : %d", ret, is_exist);
112                                 goto error;
113                         }
114                         if (is_exist == 1) {
115                                 ret = remove_dm_acc(DM_DMACC_MSCTESTSERVER);
116                                 if (ret != DM_OK) {
117                                         _DEBUG_VERBOSE("remove dm acc error :%d", ret);
118                                         goto error;
119                                 } else {
120                                         _DEBUG_VERBOSE("remove fumo dm acc");
121                                 }
122                         } else {
123                                 _DEBUG_VERBOSE("samsung fumo dm acc");
124                         }
125
126                         file_path = DDF_MSCFUMO_DMACC_FILE;
127                 }
128                 break;
129         case SAMSUNG_FMM_TYPE:
130                 {
131                         ret = is_exist_dmacc(SAMSUNG_FMM_TYPE, &is_exist);
132                         if (ret != DM_OK) {
133                                 _DEBUG_TRACE("is exist dmacc error : %d or not exist dm acc : %d", ret, is_exist);
134                                 goto error;
135                         }
136                         if (is_exist == 1) {
137                                 ret = remove_dm_acc(DM_DMACC_MSCSERVER);
138                                 if (ret != DM_OK) {
139                                         _DEBUG_VERBOSE("remove dm acc error :%d", ret);
140                                         goto error;
141                                 } else {
142                                         _DEBUG_VERBOSE("remove fumo dm acc");
143                                 }
144                         } else {
145                                 _DEBUG_VERBOSE("samsung fmm dm acc");
146                         }
147
148                         file_path = DDF_MSCLAWMO_DMACC_FILE;
149                 }
150                 break;
151         case GCF_TYPE:
152                 {
153                         ret = is_exist_dmacc(GCF_TYPE, &is_exist);
154                         if (ret != DM_OK) {
155                                 _DEBUG_TRACE("is exist dmacc error : %d or not exist dm acc : %d", ret, is_exist);
156                                 goto error;
157                         }
158                         if (is_exist == 1) {
159                                 ret = remove_dm_acc(DM_DMACC_MSCSERVER);
160                                 if (ret != DM_OK) {
161                                         _DEBUG_VERBOSE("remove dm acc error :%d", ret);
162                                         goto error;
163                                 } else {
164                                         _DEBUG_VERBOSE("remove fumo dm acc");
165                                 }
166                         } else {
167                                 _DEBUG_VERBOSE("product dm acc");
168                         }
169                         file_path = DDF_GCF_DMACC_FILE;
170                 }
171                 break;
172         default:
173                 {
174                         file_path = DDF_FILES;
175                         _DEBUG_INFO("the first factory bootstrap");
176                 }
177                 break;
178         }
179
180         file_ret = sync_agent_read_whole_file(file_path, &required_contents, &required_length);
181         if (file_ret != 1) {
182                 ret = DM_ERR_DDF_PROCCESS;
183                 goto error;
184         }
185         _DEBUG_INFO(" file read is %d, required_length is %d \n", ret, required_length);
186
187         GSList *seg_list = NULL;
188         char *check_segment = NULL;
189         ddf_spec ddf_contents[DDF_SPEC_COUNT] = { {0}, };
190         int i = 0;
191         if (required_contents != NULL) {
192                 check_segment = strtok(required_contents, "\n");
193                 _DEBUG_INFO(" check_segment : %s\n", check_segment);
194         } else {
195                 ret = DM_ERR_DDF_PROCCESS;
196                 goto error;
197         }
198
199         if (check_segment != NULL) {
200                 sscanf(check_segment, "%d %s %d %d", (int *)(&(ddf_contents[i].mo_type)), (ddf_contents[i].schema_file), &(ddf_contents[i].service_ddf), &(ddf_contents[i].server_type));
201                 seg_list = g_slist_append(seg_list, &(ddf_contents[i]));
202
203                 _DEBUG_INFO(" mo_type: %d\n", ddf_contents[i].mo_type);
204                 _DEBUG_INFO(" schema_file : %s\n", ddf_contents[i].schema_file);
205                 _DEBUG_INFO(" service_ddf : %d\n", ddf_contents[i].service_ddf);
206                 _DEBUG_INFO(" server_type : %d\n", ddf_contents[i].server_type);
207                 ++i;
208
209                 while (check_segment != NULL) {
210                         check_segment = strtok(NULL, "\n");
211                         if (check_segment == NULL)
212                                 break;
213                         _DEBUG_INFO(" check_segment : %s\n", check_segment);
214
215                         sscanf(check_segment, "%d %s %d %d", (int *)(&(ddf_contents[i].mo_type)), (ddf_contents[i].schema_file), &(ddf_contents[i].service_ddf), &(ddf_contents[i].server_type));
216                         seg_list = g_slist_append(seg_list, &(ddf_contents[i]));
217
218                         _DEBUG_INFO(" mo_type: %d\n", ddf_contents[i].mo_type);
219                         _DEBUG_INFO(" schema_file : %s\n", ddf_contents[i].schema_file);
220                         _DEBUG_INFO(" service_ddf : %d\n", ddf_contents[i].service_ddf);
221                         _DEBUG_INFO(" server_type : %d\n", ddf_contents[i].server_type);
222                         ++i;
223                 }
224
225                 ret = _start_ddf_mo(seg_list);
226                 if (ret != DM_OK)
227                         goto error;
228
229                 file_ret = sync_agent_free_file(&required_contents);
230                 required_contents = NULL;
231                 if (file_ret != 1) {
232                         ret = DM_ERR_DDF_PROCCESS;
233                         goto error;
234                 }
235
236                 ret = _completed_bootstrap();
237                 if (ret != DM_OK) {
238                         goto error;
239                 }
240
241         } else {
242                 ret = DM_ERR_DDF_PROCCESS;
243                 goto error;
244         }
245
246         _EXTERN_FUNC_EXIT;
247
248         return ret;
249  error:
250
251         file_ret = sync_agent_free_file(&required_contents);
252         if (file_ret != 1) {
253                 ret = DM_ERR_DDF_PROCCESS;
254         }
255
256         _DEBUG_INFO(" end!! error : %d \n", ret);
257         _EXTERN_FUNC_EXIT;
258         return ret;
259
260 }
261
262 /*
263 void    ddf_parser() {
264
265         sync_agent_dm_mo_type_e mo_type_devdetail = SYNC_AGENT_DM_MO_TYPE_DEVDETAIL;
266         sync_agent_dm_mo_type_e mo_type_devinfo = SYNC_AGENT_DM_MO_TYPE_DEVINFO;
267         sync_agent_dm_mo_type_e mo_type_fumo = SYNC_AGENT_DM_MO_TYPE_FUMO;
268         sync_agent_dm_mo_type_e mo_type_gcf = SYNC_AGENT_DM_MO_TYPE_DMACC;
269         sync_agent_dm_mo_type_e mo_type_mscserver = SYNC_AGENT_DM_MO_TYPE_DMACC;
270         sync_agent_dm_mo_type_e mo_type_msctestserver = SYNC_AGENT_DM_MO_TYPE_DMACC;
271
272         const char *schema_file_devdetail = "/usr/share/oma-dm/ddf/slp/slp_DEVDETAIL_DDF.xml";
273         const char *schema_file_devinfo = "/usr/share/oma-dm/ddf/slp/slp_DEVINF_DDF.xml";
274         const char *schema_file_fumo = "/usr/share/oma-dm/ddf/slp/slp_FUMO_DDF.xml";
275         const char *schema_file_gcf = "/usr/share/oma-dm/ddf/slp/slp_gcf_DMACC_DDF_1.2.xml";
276         const char *schema_file_mscserver = "/usr/share/oma-dm/ddf/slp/slp_MSCserver_DMACC_DDF_1.2.xml";
277         const char *schema_file_msctestserver = "/usr/share/oma-dm/ddf/slp/slp_MSCTestserver_DMACC_DDF_1.2.xml";
278
279         sync_agent_dm_mo_error_e err_code = sync_agent_construct_mo_table(mo_type_devdetail, schema_file_devdetail , "devdetail");
280         if (err_code == SYNC_AGENT_DM_MO_SUCCESS) {
281                 printf("Success to sync_agent_construct_mo_table()\n");
282         } else {
283                 printf("Failed to sync_agent_construct_mo_table()\n");
284         }
285
286         err_code = sync_agent_construct_mo_table(mo_type_devinfo, schema_file_devinfo , "devinf");
287         if (err_code == SYNC_AGENT_DM_MO_SUCCESS) {
288                 printf("Success to sync_agent_construct_mo_table()\n");
289         } else {
290                 printf("Failed to sync_agent_construct_mo_table()\n");
291         }
292
293         err_code = sync_agent_construct_mo_table(mo_type_fumo, schema_file_fumo , "fumo");
294         if (err_code == SYNC_AGENT_DM_MO_SUCCESS) {
295                 printf("Success to sync_agent_construct_mo_table()\n");
296         } else {
297                 printf("Failed to sync_agent_construct_mo_table()\n");
298         }
299                 err_code = sync_agent_construct_mo_table(mo_type_gcf, schema_file_gcf , "dmacc_gcf");
300         if (err_code == SYNC_AGENT_DM_MO_SUCCESS) {
301                 printf("Success to sync_agent_construct_mo_table()\n");
302         } else {
303                 printf("Failed to sync_agent_construct_mo_table()\n");
304         }
305         err_code = sync_agent_construct_mo_table(mo_type_mscserver, schema_file_mscserver , "dmacc_MSCserver");
306         if (err_code == SYNC_AGENT_DM_MO_SUCCESS) {
307                 printf("Success to sync_agent_construct_mo_table()\n");
308         } else {
309                 printf("Failed to sync_agent_construct_mo_table()\n");
310         }
311         err_code = sync_agent_construct_mo_table(mo_type_msctestserver, schema_file_msctestserver , "dmacc_MSCTestserver");
312         if (err_code == SYNC_AGENT_DM_MO_SUCCESS) {
313                 printf("Success to sync_agent_construct_mo_table()\n");
314         } else {
315                 printf("Failed to sync_agent_construct_mo_table()\n");
316         }
317 */