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