Tizen 2.0 Release
[pkgs/o/oma-ds-service.git] / src / agent / service-adapter / sa_devinf.c
1 /*
2  * oma-ds-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 /**
19  *   @SA_DevInf.c
20  *   @version                                                                   0.1
21  *   @brief                                                                             This file is the source file of implementation of functions for device information structure which is used in Service Adapter
22  */
23
24 #include <sync_agent.h>
25
26 #include "service-adapter/sa_devinf.h"
27 #include "service-adapter/sa_devinf_internal.h"
28 #include "service-adapter/sa_session_internal.h"
29 #include "common/common_define.h"
30
31 #ifndef OMADS_AGENT_LOG
32 #undef LOG_TAG
33 #define LOG_TAG "OMA_DS_SA"
34 #endif
35
36 static sa_error_type_e _create_devinf_new(char *devid, devinf_devtyp_e devtyp, devinf_s ** devinf);
37 static sa_error_type_e _create_devinf_contenttype(char *cttype, char *verct, devinf_content_type_s ** devinf_content_type);
38 static sa_error_type_e _create_devinf_ctcap(devinf_content_type_s * devinf_content_type, devinf_ct_cap_s ** devinf_ctcap);
39 static sa_error_type_e _create_devinf_property(char *prop_name, devinf_property_s ** devinf_property);
40 static sa_error_type_e _create_devinf_datastore(char *datastore, devinf_datastore_s ** devinf_datastore);
41
42 static void _free_devinf_datastores(GList * devinf_datastores);
43 static void __free_devinf_datastore(devinf_datastore_s * devinf_datastore);
44 static void ___free_devinf_contenttype(devinf_content_type_s * devinf_content_type);
45 static void ___free_devinf_ctcaps(devinf_ct_cap_s * devinf_ctcap);
46 static void ___free_devinf_property(devinf_property_s * devinf_property);
47 static void ___free_devinf_propparam(devinf_prop_param_s * devinf_prop_param);
48
49 static void _set_devinf_version(devinf_s * devinf, devinf_version_e version);
50 static void _set_devinf_manufacturer(devinf_s * devinf, char *manufacturer);
51 static void _set_devinf_model(devinf_s * devinf, char *model);
52 static void _set_devinf_oem(devinf_s * devinf, char *oem);
53 static void _set_devinf_software_version(devinf_s * devinf, char *software_version);
54 static void _set_devinf_hardware_version(devinf_s * devinf, char *hardware_version);
55 static void _set_devinf_firmware_version(devinf_s * devinf, char *firmware_version);
56 static void _set_devinf_datastore(devinf_s * devinf, devinf_datastore_s * devinf_datastore);
57 static void _set_devinf_datastore_rxpref(devinf_datastore_s * devinf_datastore, devinf_content_type_s * devinf_content_type);
58 static void _set_devinf_datastore_txpref(devinf_datastore_s * devinf_datastore, devinf_content_type_s * devinf_content_type);
59 static void _set_devinf_datastore_ctcap(devinf_datastore_s * devinf_datastore, devinf_ct_cap_s * devinf_ctcap);
60 static void _set_devinf_datastore_sharedmem(devinf_datastore_s * devinf_datastore, int shared_mem);
61 static void _set_devinf_datastore_maxmem(devinf_datastore_s * devinf_datastore, unsigned int max_mem);
62 static void _set_devinf_datastore_maxid(devinf_datastore_s * devinf_datastore, unsigned int max_id);
63 static void _set_devinf_ctcap_property(devinf_ct_cap_s * devinf_ctcap, devinf_property_s * devinf_property);
64 static void _set_devinf_property_valenums(devinf_property_s * devinf_property, char *val_enum);
65 static devinf_devtyp_e _convert_devtyp(char *dev_typ);
66
67 /* unused function
68  *  keep for in case
69  */
70 /*
71 static ErrorType create_DevInfPropParam(char *paramName, DevInfPropParam **devinfPropParam);
72 static void set_DevInfDataStoreDisplayname(DevInfDataStore* devinf_datastore, char *displayname);
73 static void set_DevInfDataStoreRx(DevInfDataStore *devinf_datastore, DevInfContentType *devinf_content_type);
74 static void set_DevInfDataStoreTx(DevInfDataStore *devinf_datastore, DevInfContentType *devinf_content_type);
75 static void set_DevInfPropertyDataType(DevInfProperty *devinfProperty, char *dataType);
76 static void set_DevInfPropertyMaxOccur(DevInfProperty *devinfProperty, unsigned int maxOccur);
77 static void set_DevInfPropertyMaxSize(DevInfProperty *devinfProperty, unsigned int maxSize);
78 static void set_DevInfPropertyNoTruncate(DevInfProperty *devinfProperty, int noTruncate);
79 static void set_DevInfPropertyDisplayName(DevInfProperty *devinfProperty, char *displayName);
80 static void set_DevInfPropertyPropParam(DevInfProperty *devinfProperty, DevInfPropParam *devinfPropParam);
81 static void set_DevInfPropParamDataType(DevInfPropParam *devinfPropParam, char *dataType);
82 static void set_DevInfPropParamDisplayName(DevInfPropParam *devinfPropParam, char *displayName);
83 static void set_DevInfPropParamValEnums(DevInfPropParam *devinfPropParam, char *valEnum);
84 */
85
86 static sa_error_type_e _create_devinf_new(char *devid, devinf_devtyp_e devtyp, devinf_s ** devinf)
87 {
88         _INNER_FUNC_ENTER;
89
90         sa_error_type_e errorType = SA_INTERNAL_OK;
91
92         if (devid == NULL) {
93                 errorType = SA_INTERNAL_NOT_DEFINED;
94                 goto error;
95         }
96
97         if (!devtyp) {
98                 errorType = SA_INTERNAL_NOT_DEFINED;
99                 goto error;
100         }
101
102         *devinf = (devinf_s *) calloc(1, sizeof(devinf_s));
103         if (*devinf == NULL) {
104                 errorType = SA_INTERNAL_NO_MEMORY;
105                 goto error;
106         }
107
108         if (devid != NULL)
109                 (*devinf)->dev_id = strdup(devid);
110         (*devinf)->devtyp = devtyp;
111
112  error:
113
114         _INNER_FUNC_EXIT;
115         return errorType;
116 }
117
118 static sa_error_type_e _create_devinf_contenttype(char *cttype, char *verct, devinf_content_type_s ** devinf_content_type)
119 {
120         _INNER_FUNC_ENTER;
121
122         sa_error_type_e errorType = SA_INTERNAL_OK;
123
124         if (cttype == NULL) {
125                 errorType = SA_INTERNAL_NOT_DEFINED;
126                 goto error;
127         }
128
129         if (verct == NULL) {
130                 errorType = SA_INTERNAL_NOT_DEFINED;
131                 goto error;
132         }
133
134         *devinf_content_type = (devinf_content_type_s *) calloc(1, sizeof(devinf_content_type_s));
135         if (*devinf_content_type == NULL) {
136                 errorType = SA_INTERNAL_NO_MEMORY;
137                 goto error;
138         }
139
140         (*devinf_content_type)->ct_type = strdup(cttype);
141         (*devinf_content_type)->verct = strdup(verct);
142
143  error:
144
145         _INNER_FUNC_EXIT;
146         return errorType;
147 }
148
149 static sa_error_type_e _create_devinf_ctcap(devinf_content_type_s * devinf_content_type, devinf_ct_cap_s ** devinf_ctcap)
150 {
151         _INNER_FUNC_ENTER;
152
153         sa_error_type_e errorType = SA_INTERNAL_OK;
154
155         if (devinf_content_type == NULL) {
156                 errorType = SA_INTERNAL_NOT_DEFINED;
157                 goto error;
158         }
159
160         *devinf_ctcap = (devinf_ct_cap_s *) calloc(1, sizeof(devinf_ct_cap_s));
161         if (*devinf_ctcap == NULL) {
162                 errorType = SA_INTERNAL_NO_MEMORY;
163                 goto error;
164         }
165
166         (*devinf_ctcap)->ct = devinf_content_type;
167
168  error:
169
170         _INNER_FUNC_EXIT;
171         return errorType;
172
173 }
174
175 static sa_error_type_e _create_devinf_property(char *prop_name, devinf_property_s ** devinf_property)
176 {
177         _INNER_FUNC_ENTER;
178
179         sa_error_type_e errorType = SA_INTERNAL_OK;
180
181         if (prop_name == NULL) {
182                 errorType = SA_INTERNAL_NOT_DEFINED;
183                 goto error;
184         }
185
186         *devinf_property = (devinf_property_s *) calloc(1, sizeof(devinf_property_s));
187         if (*devinf_property == NULL) {
188                 errorType = SA_INTERNAL_NO_MEMORY;
189                 goto error;
190         }
191
192         (*devinf_property)->prop_name = strdup(prop_name);
193
194  error:
195
196         _INNER_FUNC_EXIT;
197         return errorType;
198 }
199
200 static sa_error_type_e _create_devinf_datastore(char *datastore, devinf_datastore_s ** devinf_datastore)
201 {
202         _INNER_FUNC_ENTER;
203
204         sa_error_type_e errorType = SA_INTERNAL_OK;
205
206         if (datastore == NULL) {
207                 errorType = SA_INTERNAL_NOT_DEFINED;
208                 goto error;
209         }
210
211         *devinf_datastore = (devinf_datastore_s *) calloc(1, sizeof(devinf_datastore_s));
212         if (*devinf_datastore == NULL) {
213                 errorType = SA_INTERNAL_NO_MEMORY;
214                 goto error;
215         }
216
217         (*devinf_datastore)->source_ref = strdup(datastore);
218
219  error:
220
221         _INNER_FUNC_EXIT;
222         return errorType;
223 }
224
225 static void _free_devinf_datastores(GList * devinf_datastores)
226 {
227         _INNER_FUNC_ENTER;
228
229         retm_if(devinf_datastores == NULL, "List is NULL");
230
231         GList *iter = NULL;
232         for (iter = devinf_datastores; iter != NULL; iter = g_list_next(iter))
233                 __free_devinf_datastore(iter->data);
234
235         g_list_free(devinf_datastores);
236
237         _INNER_FUNC_EXIT;
238 }
239
240 static void __free_devinf_datastore(devinf_datastore_s * devinf_datastore)
241 {
242         _INNER_FUNC_ENTER;
243
244         retm_if(devinf_datastore == NULL, "devinf_datastore is NULL");
245
246         if (devinf_datastore->source_ref != NULL) {
247                 free(devinf_datastore->source_ref);
248                 devinf_datastore->source_ref = NULL;
249         }
250
251         if (devinf_datastore->display_name != NULL) {
252                 free(devinf_datastore->display_name);
253                 devinf_datastore->display_name = NULL;
254         }
255
256         ___free_devinf_contenttype(devinf_datastore->rx_pref);
257         devinf_datastore->rx_pref = NULL;
258
259         ___free_devinf_contenttype(devinf_datastore->tx_pref);
260         devinf_datastore->tx_pref = NULL;
261
262         /*free_FilterRx(filter_rx); */
263         /*free_FilterCap(filterCap); */
264
265         GList *iter = NULL;
266         for (iter = devinf_datastore->rx; iter != NULL; iter = g_list_next(iter))
267                 ___free_devinf_contenttype(iter->data);
268         g_list_free(devinf_datastore->rx);
269
270         for (iter = devinf_datastore->tx; iter != NULL; iter = g_list_next(iter))
271                 ___free_devinf_contenttype(iter->data);
272         g_list_free(devinf_datastore->tx);
273
274         for (iter = devinf_datastore->ct_caps; iter != NULL; iter = g_list_next(iter))
275                 ___free_devinf_ctcaps(iter->data);
276         g_list_free(devinf_datastore->ct_caps);
277
278         free(devinf_datastore);
279
280         _INNER_FUNC_EXIT;
281 }
282
283 static void ___free_devinf_contenttype(devinf_content_type_s * devinf_content_type)
284 {
285         _INNER_FUNC_ENTER;
286
287         retm_if(devinf_content_type == NULL, "devinf_content_type is NULL");
288
289         if (devinf_content_type->ct_type != NULL) {
290                 free(devinf_content_type->ct_type);
291                 devinf_content_type->ct_type = NULL;
292         }
293
294         if (devinf_content_type->verct != NULL) {
295                 free(devinf_content_type->verct);
296                 devinf_content_type->verct = NULL;
297         }
298
299         free(devinf_content_type);
300
301         _INNER_FUNC_EXIT;
302 }
303
304 static void ___free_devinf_ctcaps(devinf_ct_cap_s * devinf_ctcap)
305 {
306         _INNER_FUNC_ENTER;
307
308         retm_if(devinf_ctcap == NULL, "devinf_ctcap is NULL");
309
310         ___free_devinf_contenttype(devinf_ctcap->ct);
311         devinf_ctcap->ct = NULL;
312
313         GList *iter = NULL;
314         for (iter = devinf_ctcap->properties; iter != NULL; iter = g_list_next(iter))
315                 ___free_devinf_property(iter->data);
316
317         g_list_free(devinf_ctcap->properties);
318
319         free(devinf_ctcap);
320
321         _INNER_FUNC_EXIT;
322 }
323
324 static void ___free_devinf_property(devinf_property_s * devinf_property)
325 {
326         _INNER_FUNC_ENTER;
327
328         retm_if(devinf_property == NULL, "devinf_property is NULL");
329
330         if (devinf_property->prop_name != NULL) {
331                 free(devinf_property->prop_name);
332                 devinf_property->prop_name = NULL;
333         }
334
335         if (devinf_property->data_type != NULL) {
336                 free(devinf_property->data_type);
337                 devinf_property->data_type = NULL;
338         }
339
340         if (devinf_property->display_name != NULL) {
341                 free(devinf_property->display_name);
342                 devinf_property->display_name = NULL;
343         }
344
345         GList *iter = NULL;
346         for (iter = devinf_property->val_enums; iter != NULL; iter = g_list_next(iter))
347                 free(iter->data);
348
349         g_list_free(devinf_property->val_enums);
350
351         for (iter = devinf_property->prop_params; iter != NULL; iter = g_list_next(iter))
352                 ___free_devinf_propparam(iter->data);
353
354         g_list_free(devinf_property->prop_params);
355
356         free(devinf_property);
357
358         _INNER_FUNC_EXIT;
359 }
360
361 static void ___free_devinf_propparam(devinf_prop_param_s * devinf_prop_param)
362 {
363         _INNER_FUNC_ENTER;
364
365         retm_if(devinf_prop_param == NULL, "devinfPropParam is NULL");
366
367         if (devinf_prop_param->param_name != NULL) {
368                 free(devinf_prop_param->param_name);
369                 devinf_prop_param->param_name = NULL;
370         }
371
372         if (devinf_prop_param->data_type != NULL) {
373                 free(devinf_prop_param->data_type);
374                 devinf_prop_param->data_type = NULL;
375         }
376
377         if (devinf_prop_param->display_name != NULL) {
378                 free(devinf_prop_param->display_name);
379                 devinf_prop_param->display_name = NULL;
380         }
381
382         GList *iter = NULL;
383         for (iter = devinf_prop_param->val_enums; iter != NULL; iter = g_list_next(iter))
384                 free(iter->data);
385
386         g_list_free(devinf_prop_param->val_enums);
387
388         free(devinf_prop_param);
389
390         _INNER_FUNC_EXIT;
391 }
392
393 static void _set_devinf_version(devinf_s * devinf, devinf_version_e version)
394 {
395         _INNER_FUNC_ENTER;
396
397         retm_if(devinf == NULL, "devinf is NULL");
398
399         devinf->version = version;
400
401         _INNER_FUNC_EXIT;
402 }
403
404 static void _set_devinf_manufacturer(devinf_s * devinf, char *manufacturer)
405 {
406         _INNER_FUNC_ENTER;
407
408         retm_if(devinf == NULL, "devinf is NULL");
409
410         if (manufacturer != NULL)
411                 devinf->manufacturer = strdup(manufacturer);
412
413         _INNER_FUNC_EXIT;
414 }
415
416 static void _set_devinf_model(devinf_s * devinf, char *model)
417 {
418         _INNER_FUNC_ENTER;
419
420         retm_if(devinf == NULL, "devinf is NULL");
421
422         if (model != NULL)
423                 devinf->model = strdup(model);
424
425         _INNER_FUNC_EXIT;
426 }
427
428 static void _set_devinf_oem(devinf_s * devinf, char *oem)
429 {
430         _INNER_FUNC_ENTER;
431
432         retm_if(devinf == NULL, "devinf is NULL");
433
434         if (oem != NULL)
435                 devinf->oem = strdup(oem);
436
437         _INNER_FUNC_EXIT;
438 }
439
440 static void _set_devinf_software_version(devinf_s * devinf, char *software_version)
441 {
442         _INNER_FUNC_ENTER;
443
444         retm_if(devinf == NULL, "devinf is NULL");
445
446         if (software_version != NULL)
447                 devinf->software_version = strdup(software_version);
448
449         _INNER_FUNC_EXIT;
450 }
451
452 static void _set_devinf_hardware_version(devinf_s * devinf, char *hardware_version)
453 {
454         _INNER_FUNC_ENTER;
455
456         retm_if(devinf == NULL, "devinf is NULL");
457
458         if (hardware_version != NULL)
459                 devinf->hardware_version = strdup(hardware_version);
460
461         _INNER_FUNC_EXIT;
462 }
463
464 static void _set_devinf_firmware_version(devinf_s * devinf, char *firmware_version)
465 {
466         _INNER_FUNC_ENTER;
467
468         retm_if(devinf == NULL, "devinf is NULL");
469
470         if (firmware_version != NULL)
471                 devinf->firmware_version = strdup(firmware_version);
472
473         _INNER_FUNC_EXIT;
474 }
475
476 static void _set_devinf_datastore(devinf_s * devinf, devinf_datastore_s * devinf_datastore)
477 {
478         _INNER_FUNC_ENTER;
479
480         retm_if(devinf == NULL, "devinf is NULL");
481
482         devinf->datastores = g_list_append(devinf->datastores, devinf_datastore);
483
484         _INNER_FUNC_EXIT;
485 }
486
487 static void _set_devinf_datastore_rxpref(devinf_datastore_s * devinf_datastore, devinf_content_type_s * devinf_content_type)
488 {
489         _INNER_FUNC_ENTER;
490
491         retm_if(devinf_datastore == NULL, "devinf_datastore is NULL");
492
493         devinf_datastore->rx_pref = devinf_content_type;
494
495         _INNER_FUNC_EXIT;
496 }
497
498 static void _set_devinf_datastore_txpref(devinf_datastore_s * devinf_datastore, devinf_content_type_s * devinf_content_type)
499 {
500         _INNER_FUNC_ENTER;
501
502         retm_if(devinf_datastore == NULL, "devinf_datastore is NULL");
503
504         devinf_datastore->tx_pref = devinf_content_type;
505
506         _INNER_FUNC_EXIT;
507 }
508
509 static void _set_devinf_datastore_ctcap(devinf_datastore_s * devinf_datastore, devinf_ct_cap_s * devinf_ctcap)
510 {
511         _INNER_FUNC_ENTER;
512
513         retm_if(devinf_datastore == NULL, "devinf_datastore is NULL");
514
515         devinf_datastore->ct_caps = g_list_append(devinf_datastore->ct_caps, devinf_ctcap);
516
517         _INNER_FUNC_EXIT;
518 }
519
520 static void _set_devinf_datastore_sharedmem(devinf_datastore_s * devinf_datastore, int shared_mem)
521 {
522         _INNER_FUNC_ENTER;
523
524         retm_if(devinf_datastore == NULL, "devinf_datastore is NULL");
525
526         devinf_datastore->shared_mem = shared_mem;
527
528         _INNER_FUNC_EXIT;
529 }
530
531 static void _set_devinf_datastore_maxmem(devinf_datastore_s * devinf_datastore, unsigned int max_mem)
532 {
533         _INNER_FUNC_ENTER;
534
535         retm_if(devinf_datastore == NULL, "devinf_datastore is NULL");
536
537         devinf_datastore->max_mem = max_mem;
538
539         _INNER_FUNC_EXIT;
540 }
541
542 static void _set_devinf_datastore_maxid(devinf_datastore_s * devinf_datastore, unsigned int max_id)
543 {
544         _INNER_FUNC_ENTER;
545
546         retm_if(devinf_datastore == NULL, "devinf_datastore is NULL");
547
548         devinf_datastore->max_id = max_id;
549
550         _INNER_FUNC_EXIT;
551 }
552
553 static void _set_devinf_ctcap_property(devinf_ct_cap_s * devinf_ctcap, devinf_property_s * devinf_property)
554 {
555         _INNER_FUNC_ENTER;
556
557         retm_if(devinf_ctcap == NULL, "devinfCTCap is NULL");
558
559         devinf_ctcap->properties = g_list_append(devinf_ctcap->properties, devinf_property);
560
561         _INNER_FUNC_EXIT;
562 }
563
564 static void _set_devinf_property_valenums(devinf_property_s * devinf_property, char *val_enum)
565 {
566         _INNER_FUNC_ENTER;
567
568         retm_if(devinf_property == NULL, "devinfCTCap is NULL");
569
570         if (val_enum != NULL)
571                 devinf_property->val_enums = g_list_append(devinf_property->val_enums, strdup(val_enum));
572
573         _INNER_FUNC_EXIT;
574 }
575
576 static devinf_devtyp_e _convert_devtyp(char *dev_typ)
577 {
578         _INNER_FUNC_ENTER;
579
580         devinf_devtyp_e devinfDevTyp = DEVINF_DEVTYPE_UNKNOWN;
581
582         if (strcmp(dev_typ, DEFINE_DEVICE_TYPE_PAGER) == 0)
583                 devinfDevTyp = DEVINF_DEVTYPE_PAGER;
584         else if (strcmp(dev_typ, DEFINE_DEVICE_TYPE_HANDHELD) == 0)
585                 devinfDevTyp = DEVINF_DEVTYPE_HANDHELD;
586         else if (strcmp(dev_typ, DEFINE_DEVICE_TYPE_PDA) == 0)
587                 devinfDevTyp = DEVINF_DEVTYPE_PDA;
588         else if (strcmp(dev_typ, DEFINE_DEVICE_TYPE_PHONE) == 0)
589                 devinfDevTyp = DEVINF_DEVTYPE_PHONE;
590         else if (strcmp(dev_typ, DEFINE_DEVICE_TYPE_SMARTPHONE) == 0)
591                 devinfDevTyp = DEVINF_DEVTYPE_SMARTPHONE;
592         else if (strcmp(dev_typ, DEFINE_DEVICE_TYPE_SERVER) == 0)
593                 devinfDevTyp = DEVINF_DEVTYPE_SERVER;
594         else if (strcmp(dev_typ, DEFINE_DEVICE_TYPE_WORKSTATION) == 0)
595                 devinfDevTyp = DEVINF_DEVTYPE_WORKSTATION;
596
597         _INNER_FUNC_EXIT;
598         return devinfDevTyp;
599 }
600
601 sa_error_type_e create_devinf(session_s * session, devinf_s ** devinf)
602 {
603         _EXTERN_FUNC_ENTER;
604
605         sa_error_type_e errorType = SA_INTERNAL_OK;
606         sync_agent_dev_return_e err = SYNC_AGENT_DEV_RETURN_SUCCESS;
607
608         char *devID = NULL;
609         char *devTyp = NULL;
610         char *man = NULL;
611         char *model = NULL;
612         char *oem = NULL;
613         char *swv = NULL;
614         char *hwv = NULL;
615         char *fwv = "1.0";
616
617         devinf_s *temp_devinf = NULL;
618         devinf_datastore_s *devInfDataStore = NULL;
619         devinf_ct_cap_s *devInfCTCap = NULL;
620         devinf_property_s *devInfProperty = NULL;
621
622         err = sync_agent_get_devinfo(DEFINE_PLATFORM, "DevID", &devID);
623         if (err != SYNC_AGENT_DEV_RETURN_SUCCESS) {
624                 errorType = SA_INTERNAL_ERROR;
625                 goto error;
626         }
627
628         err = sync_agent_get_devinfo(DEFINE_PLATFORM, "DevTyp", &devTyp);
629         if (err != SYNC_AGENT_DEV_RETURN_SUCCESS) {
630                 errorType = SA_INTERNAL_ERROR;
631                 goto error;
632         }
633
634         devinf_devtyp_e devInfDevTyp = DEVINF_DEVTYPE_UNKNOWN;
635         if (devTyp != NULL)
636                 devInfDevTyp = _convert_devtyp(devTyp);
637
638         devinf_version_e devInfVersion = DEVINF_VERSION_UNKNOWN;
639         if (session->protocol_version == VERSION_10)
640                 devInfVersion = DEVINF_VERSION_10;
641         else if (session->protocol_version == VERSION_11)
642                 devInfVersion = DEVINF_VERSION_11;
643         else if (session->protocol_version == VERSION_12)
644                 devInfVersion = DEVINF_VERSION_12;
645
646         err = sync_agent_get_devinfo(DEFINE_PLATFORM, "Man", &man);
647         if (err != SYNC_AGENT_DEV_RETURN_SUCCESS) {
648                 errorType = SA_INTERNAL_ERROR;
649                 goto error;
650         }
651
652         err = sync_agent_get_devinfo(DEFINE_PLATFORM, "Mod", &model);
653         if (err != SYNC_AGENT_DEV_RETURN_SUCCESS) {
654                 errorType = SA_INTERNAL_ERROR;
655                 goto error;
656         }
657
658         err = sync_agent_get_devinfo(DEFINE_PLATFORM, "OEM", &oem);
659         if (err != SYNC_AGENT_DEV_RETURN_SUCCESS) {
660                 errorType = SA_INTERNAL_ERROR;
661                 goto error;
662         }
663
664         err = sync_agent_get_devinfo(DEFINE_PLATFORM, "SwV", &swv);
665         if (err != SYNC_AGENT_DEV_RETURN_SUCCESS) {
666                 errorType = SA_INTERNAL_ERROR;
667                 goto error;
668         }
669
670         err = sync_agent_get_devinfo(DEFINE_PLATFORM, "HwV", &hwv);
671         if (err != SYNC_AGENT_DEV_RETURN_SUCCESS) {
672                 errorType = SA_INTERNAL_ERROR;
673                 goto error;
674         }
675
676         /*
677            err = sync_agent_get_devinfo(DEFINE_PLATFORM, "FwV", &fwv);
678            if (err != SYNC_AGENT_DEV_RETURN_SUCCESS) {
679            errorType = ERROR_INTERNAL_ERROR;
680            goto error;
681            }
682          */
683
684         _DEBUG_INFO("devID = %s", devID);
685         _DEBUG_INFO("devTyp = %s", devTyp);
686         _DEBUG_INFO("man = %s", man);
687         _DEBUG_INFO("model = %s", model);
688         _DEBUG_INFO("oem = %s", oem);
689         _DEBUG_INFO("swv = %s", swv);
690         _DEBUG_INFO("hwv = %s", hwv);
691         _DEBUG_INFO("fwv = %s", fwv);
692
693         errorType = _create_devinf_new(devID, devInfDevTyp, &temp_devinf);
694         if (errorType != SA_INTERNAL_OK) {
695                 _DEBUG_ERROR("failed to create devInf New");
696                 goto error;
697         }
698
699         _set_devinf_version(temp_devinf, devInfVersion);
700         _set_devinf_manufacturer(temp_devinf, man);
701         _set_devinf_model(temp_devinf, model);
702         _set_devinf_oem(temp_devinf, oem);
703         _set_devinf_software_version(temp_devinf, swv);
704         _set_devinf_hardware_version(temp_devinf, hwv);
705         _set_devinf_firmware_version(temp_devinf, fwv);
706
707         temp_devinf->supports_large_objs = 1;
708         temp_devinf->supports_utc = 1;
709         temp_devinf->supports_number_of_changes = 1;
710
711         /*TODO Implements call log datastore's datastore for device info */
712         /* TYPE_CONTENT_COUNT -1 -> not include calllog datastore */
713         int content_type;
714         for (content_type = 0; content_type < TYPE_SERVICE_COUNT - 1; content_type++) {
715
716                 if (datastoreinfo_per_content_type[content_type] != NULL) {
717                         if (datastoreinfo_per_content_type[content_type]->source != NULL) {
718                                 errorType = _create_devinf_datastore(datastoreinfo_per_content_type[content_type]->source, &devInfDataStore);
719                                 if (errorType != SA_INTERNAL_OK) {
720                                         _DEBUG_ERROR("failed to create devInfDataStore");
721                                         goto error;
722                                 }
723
724                                 sync_agent_plugin_object_info_s *datastore = sync_agent_get_obj_info(content_type);
725
726                                 _DEBUG_INFO("datastore->type = %s", datastore->type);
727                                 _DEBUG_INFO("datastore->version = %s", datastore->version);
728                                 _DEBUG_INFO("datastore->field_cnt = %d", datastore->field_cnt);
729
730                                 devinf_content_type_s *devInfContentTypeRxPref = NULL;
731                                 errorType = _create_devinf_contenttype(datastore->type, datastore->version, &devInfContentTypeRxPref);
732                                 if (errorType != SA_INTERNAL_OK) {
733                                         _DEBUG_ERROR("failed to create devInfContentType");
734                                         goto error;
735                                 }
736                                 _set_devinf_datastore_rxpref(devInfDataStore, devInfContentTypeRxPref);
737
738                                 devinf_content_type_s *devInfContentTypeTxPref = NULL;
739                                 errorType = _create_devinf_contenttype(datastore->type, datastore->version, &devInfContentTypeTxPref);
740                                 if (errorType != SA_INTERNAL_OK) {
741                                         _DEBUG_ERROR("failed to create devInfContentType");
742                                         goto error;
743                                 }
744                                 _set_devinf_datastore_txpref(devInfDataStore, devInfContentTypeTxPref);
745
746                                 devinf_content_type_s *devInfContentTypeCTCap = NULL;
747                                 errorType = _create_devinf_contenttype(datastore->type, datastore->version, &devInfContentTypeCTCap);
748                                 if (errorType != SA_INTERNAL_OK) {
749                                         _DEBUG_ERROR("failed to create devInfContentType");
750                                         goto error;
751                                 }
752
753                                 errorType = _create_devinf_ctcap(devInfContentTypeCTCap, &devInfCTCap);
754                                 if (errorType != SA_INTERNAL_OK) {
755                                         _DEBUG_ERROR("failed to create devInfCTCap");
756                                         goto error;
757                                 }
758
759                                 sync_agent_plugin_field_info_s field_list;
760                                 int i;
761                                 for (i = 0; i < datastore->field_cnt; i++) {
762                                         field_list = datastore->field_list[i];
763                                         errorType = _create_devinf_property(field_list.field_name, &devInfProperty);
764                                         if (errorType != SA_INTERNAL_OK) {
765                                                 _DEBUG_ERROR("failed to create devInfProperty");
766                                                 goto error;
767                                         }
768
769                                         sync_agent_plugin_field_info_s children_field_list;
770                                         int j;
771                                         for (j = 0; j < field_list.field_child_cnt; j++) {
772                                                 children_field_list = field_list.field_child_list[j];
773                                                 _set_devinf_property_valenums(devInfProperty, children_field_list.field_name);
774                                         }
775                                         _set_devinf_ctcap_property(devInfCTCap, devInfProperty);
776                                         devInfProperty = NULL;
777                                 }
778
779                                 _set_devinf_datastore_ctcap(devInfDataStore, devInfCTCap);
780                                 devInfCTCap = NULL;
781
782                                 /* TODO Get information about static memory for each datastore
783                                  * It will be used to fill DSMem and children element(SharedMem, MaxMem, MaxID) */
784                                 /* Set SharedMem */
785                                 _set_devinf_datastore_sharedmem(devInfDataStore, 0);
786                                 /* Set MaxMem */
787                                 _set_devinf_datastore_maxmem(devInfDataStore, 0);
788                                 /* Set MaxID */
789                                 _set_devinf_datastore_maxid(devInfDataStore, 0);
790
791                                 set_devinf_datastore_sync_cap(devInfDataStore, DEVINF_SYNCTYPE_TWO_WAY, 1);
792                                 set_devinf_datastore_sync_cap(devInfDataStore, DEVINF_SYNCTYPE_SLOW_SYNC, 1);
793                                 set_devinf_datastore_sync_cap(devInfDataStore, DEVINF_SYNCTYPE_ONE_WAY_FROM_CLIENT, 1);
794                                 set_devinf_datastore_sync_cap(devInfDataStore, DEVINF_SYNCTYPE_REFRESH_FROM_CLIENT, 1);
795                                 set_devinf_datastore_sync_cap(devInfDataStore, DEVINF_SYNCTYPE_ONE_WAY_FROM_SERVER, 1);
796                                 set_devinf_datastore_sync_cap(devInfDataStore, DEVINF_SYNCTYPE_REFRESH_FROM_SERVER, 1);
797                                 set_devinf_datastore_sync_cap(devInfDataStore, DEVINF_SYNCTYPE_SERVER_ALERTED_SYNC, 1);
798
799                                 _set_devinf_datastore(temp_devinf, devInfDataStore);
800                                 devInfDataStore = NULL;
801
802                                 /*free datastore */
803                                 sync_agent_free_obj_info(content_type, datastore);
804                         }
805                 }
806         }
807
808         *devinf = temp_devinf;
809         temp_devinf = NULL;
810
811  error:
812
813         if (temp_devinf != NULL)
814                 free(temp_devinf);
815
816         __free_devinf_datastore(devInfDataStore);
817         ___free_devinf_ctcaps(devInfCTCap);
818         ___free_devinf_property(devInfProperty);
819
820         if (devID != NULL)
821                 free(devID);
822         if (devTyp != NULL)
823                 free(devTyp);
824         if (man != NULL)
825                 free(man);
826         if (model != NULL)
827                 free(model);
828         if (oem != NULL)
829                 free(oem);
830         if (swv != NULL)
831                 free(swv);
832         if (hwv != NULL)
833                 free(hwv);
834 /*      if (fwv != NULL)
835                 free(fwv);*/
836
837         _EXTERN_FUNC_EXIT;
838         return errorType;
839 }
840
841 void free_devinf(devinf_s * devinf)
842 {
843         _EXTERN_FUNC_ENTER;
844
845         retm_if(devinf == NULL, "devinf is NULL");
846
847         if (devinf->manufacturer != NULL) {
848                 free(devinf->manufacturer);
849                 devinf->manufacturer = NULL;
850         }
851
852         if (devinf->model != NULL) {
853                 free(devinf->model);
854                 devinf->model = NULL;
855         }
856
857         if (devinf->oem != NULL) {
858                 free(devinf->oem);
859                 devinf->oem = NULL;
860         }
861
862         if (devinf->software_version != NULL) {
863                 free(devinf->software_version);
864                 devinf->software_version = NULL;
865         }
866
867         if (devinf->hardware_version != NULL) {
868                 free(devinf->hardware_version);
869                 devinf->hardware_version = NULL;
870         }
871
872         if (devinf->firmware_version != NULL) {
873                 free(devinf->firmware_version);
874                 devinf->firmware_version = NULL;
875         }
876
877         if (devinf->dev_id != NULL) {
878                 free(devinf->dev_id);
879                 devinf->dev_id = NULL;
880         }
881
882         _free_devinf_datastores(devinf->datastores);
883         devinf->datastores = NULL;
884
885         free(devinf);
886
887         _EXTERN_FUNC_EXIT;
888 }
889
890 void set_devinf_datastore_sync_cap(devinf_datastore_s * devinf_datastore, devinf_sync_cap_e cap, int supported)
891 {
892         _EXTERN_FUNC_ENTER;
893
894         if (supported)
895                 devinf_datastore->sync_cap = devinf_datastore->sync_cap | cap;
896         else
897                 devinf_datastore->sync_cap = devinf_datastore->sync_cap & ~cap;
898
899         _EXTERN_FUNC_EXIT;
900 }
901
902 int get_devinf_datastore_sync_cap(const devinf_datastore_s * devinf_datastore, devinf_sync_cap_e cap)
903 {
904         _EXTERN_FUNC_ENTER;
905
906         int data;
907         data = devinf_datastore->sync_cap & cap ? 1 : 0;
908
909         _EXTERN_FUNC_EXIT;
910         return data;
911 }
912
913 devinf_sync_cap_e convert_devinf_synccap(unsigned int id)
914 {
915         _EXTERN_FUNC_ENTER;
916
917         devinf_sync_cap_e result = DEVINF_SYNCTYPE_UNKNOWN;
918
919         switch (id) {
920         case DEVINF_SYNCTYPE_TWO_WAY:
921                 result = DEVINF_SYNCTYPE_TWO_WAY;
922                 break;
923         case DEVINF_SYNCTYPE_SLOW_SYNC:
924                 result = DEVINF_SYNCTYPE_SLOW_SYNC;
925                 break;
926         case DEVINF_SYNCTYPE_ONE_WAY_FROM_CLIENT:
927                 result = DEVINF_SYNCTYPE_ONE_WAY_FROM_CLIENT;
928                 break;
929         case DEVINF_SYNCTYPE_REFRESH_FROM_CLIENT:
930                 result = DEVINF_SYNCTYPE_REFRESH_FROM_CLIENT;
931                 break;
932         case DEVINF_SYNCTYPE_ONE_WAY_FROM_SERVER:
933                 result = DEVINF_SYNCTYPE_ONE_WAY_FROM_SERVER;
934                 break;
935         case DEVINF_SYNCTYPE_REFRESH_FROM_SERVER:
936                 result = DEVINF_SYNCTYPE_REFRESH_FROM_SERVER;
937                 break;
938         case DEVINF_SYNCTYPE_SERVER_ALERTED_SYNC:
939                 result = DEVINF_SYNCTYPE_SERVER_ALERTED_SYNC;
940                 break;
941         default:
942                 return DEVINF_SYNCTYPE_UNKNOWN;
943                 break;
944         }
945
946         _EXTERN_FUNC_EXIT;
947         return result;
948 }
949
950 /*
951 static ErrorType create_DevInfPropParam(char *paramName, DevInfPropParam **devinfPropParam)
952 {
953         _EXTERN_FUNC_ENTER;
954
955         ErrorType errorType = ERROR_INTERNAL_OK;
956
957         if (!paramName) {
958                 errorType = ERROR_INTERNAL_NOT_DEFINED;
959                 goto error;
960         }
961
962         *devinfPropParam = (DevInfPropParam *)calloc(1, sizeof(DevInfPropParam));
963         if (*devinfPropParam == NULL) {
964                 errorType = ERROR_INTERNAL_NO_MEMORY;
965                 goto error;
966         }
967
968         (*devinfPropParam)->paramName = strdup(paramName);
969
970 error:
971
972         _EXTERN_FUNC_EXIT;
973         return errorType;
974 }
975
976 static void set_DevInfDataStoreDisplayname(DevInfDataStore* devinf_datastore, char *displayname) {
977
978         if (!devinf_datastore)
979                 return;
980
981         devinf_datastore->displayname = strdup(displayname);
982 }
983
984 static void set_DevInfDataStoreRx(DevInfDataStore *devinf_datastore, DevInfContentType *devinf_content_type) {
985         if (!devinf_datastore)
986                         return;
987
988         devinf_datastore->rx = g_list_append(devinf_datastore->rx, devinf_content_type);
989 }
990
991 static void set_DevInfDataStoreTx(DevInfDataStore *devinf_datastore, DevInfContentType *devinf_content_type) {
992         if (!devinf_datastore)
993                         return;
994
995         devinf_datastore->tx = g_list_append(devinf_datastore->tx, devinf_content_type);
996 }
997
998 static void set_DevInfPropertyDataType(DevInfProperty *devinfProperty, char *dataType) {
999
1000         if (!devinfProperty)
1001                 return;
1002
1003         devinfProperty->dataType = strdup(dataType);
1004 }
1005
1006 static void set_DevInfPropertyMaxOccur(DevInfProperty *devinfProperty, unsigned int maxOccur) {
1007
1008         if (!devinfProperty)
1009                 return;
1010
1011         devinfProperty->maxOccur = maxOccur;
1012 }
1013
1014 static void set_DevInfPropertyMaxSize(DevInfProperty *devinfProperty, unsigned int maxSize) {
1015
1016         if (!devinfProperty)
1017                 return;
1018
1019         devinfProperty->maxSize = maxSize;
1020 }
1021
1022 static void set_DevInfPropertyNoTruncate(DevInfProperty *devinfProperty, int noTruncate) {
1023
1024         if (!devinfProperty)
1025                 return;
1026
1027         devinfProperty->noTruncate = noTruncate;
1028 }
1029
1030 static void set_DevInfPropertyDisplayName(DevInfProperty *devinfProperty, char *displayName) {
1031
1032         if (!devinfProperty)
1033                 return;
1034
1035         devinfProperty->displayName = strdup(displayName);
1036 }
1037
1038 static void set_DevInfPropertyPropParam(DevInfProperty *devinfProperty, DevInfPropParam *devinfPropParam) {
1039
1040         if (!devinfProperty)
1041                 return;
1042
1043         devinfProperty->propParams = g_list_append(devinfProperty->propParams, devinfPropParam);
1044 }
1045
1046 static void set_DevInfPropParamDataType(DevInfPropParam *devinfPropParam, char *dataType) {
1047
1048         if (!devinfPropParam)
1049                 return;
1050
1051         devinfPropParam->dataType = strdup(dataType);
1052 }
1053
1054 static void set_DevInfPropParamDisplayName(DevInfPropParam *devinfPropParam, char *displayName) {
1055
1056         if (!devinfPropParam)
1057                 return;
1058
1059         devinfPropParam->displayName = strdup(displayName);
1060 }
1061
1062 static void set_DevInfPropParamValEnums(DevInfPropParam *devinfPropParam, char *valEnum) {
1063
1064         if (!devinfPropParam)
1065                 return;
1066
1067         devinfPropParam->valEnums = g_list_append(devinfPropParam->valEnums, strdup(valEnum));
1068  }
1069 */