4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: JuHak Park <juhaki.park@samsung.com>,
7 * JuneHyuk Lee <junhyuk7.lee@samsung.com>,
8 * SunBong Ha <sunbong.ha@samsung.com>
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
14 * http://www.apache.org/licenses/LICENSE-2.0
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.
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.
33 * SeongWon Shim <seongwon.shim@samsung.com>
37 * @Common_Define_Internal.c
39 * @brief This file is the source file of implementation of defined Common structure
42 #include "agent-framework/Utility/fw_log.h"
43 #include "Common/Common_Define.h"
45 #define LOG_TAG "OMA_DS_COMMON"
47 Datastore *datastoreinfo_per_content_type[4];
50 DatastoreInfo *create_datastoreinfo(char *target, char *source)
54 DatastoreInfo *datastoreInfo = (DatastoreInfo *)calloc(1, sizeof(DatastoreInfo));
55 if (datastoreInfo == NULL) {
56 FW_LOGV("datastoreInfo is NULL");
61 datastoreInfo->target = strdup(target);
63 datastoreInfo->source = strdup(source);
70 void free_datastoreinfos(GList *pDatastoreInfos)
74 if (!pDatastoreInfos) {
75 FW_LOGV("List is null");
80 for (iter = pDatastoreInfos; iter != NULL; iter = g_list_next(iter))
81 free_datastoreinfo(iter->data);
83 g_list_free(pDatastoreInfos);
88 void free_datastoreinfo(DatastoreInfo *pDatastoreInfo)
92 if (!pDatastoreInfo) {
93 FW_LOGV("pDatastoreInfo is NULL");
97 if (pDatastoreInfo->target) {
98 free(pDatastoreInfo->target);
99 pDatastoreInfo->target = NULL;
102 if (pDatastoreInfo->source) {
103 free(pDatastoreInfo->source);
104 pDatastoreInfo->source = NULL;
107 if (pDatastoreInfo->lastAnchor) {
108 free(pDatastoreInfo->lastAnchor);
109 pDatastoreInfo->lastAnchor = NULL;
112 if (pDatastoreInfo->nextAnchor) {
113 free(pDatastoreInfo->nextAnchor);
114 pDatastoreInfo->nextAnchor = NULL;
117 free(pDatastoreInfo);
122 void set_datastoreInfo_synctype(DatastoreInfo *datastoreInfo, AlertType syncType)
125 datastoreInfo->syncType = syncType;
128 void set_datastoreinfo_lastanchor(DatastoreInfo *datastoreInfo, char *lastAnchor)
131 datastoreInfo->lastAnchor = strdup(lastAnchor);
134 void set_datastoreinfo_nextanchor(DatastoreInfo *datastoreInfo, char *nextAnchor)
137 datastoreInfo->nextAnchor = strdup(nextAnchor);
140 void set_datastoreinfo_maxobjsize(DatastoreInfo *datastoreInfo, unsigned int maxObjSize)
143 datastoreInfo->maxObjSize = maxObjSize;
146 ChangedItem *create_changeditem(ChangeType type, char *luid)
149 ChangedItem *changedItem = (ChangedItem *)calloc(1, sizeof(ChangedItem));
150 if (changedItem == NULL) {
151 FW_LOGV("changedItem is NULL");
155 changedItem->changeType = type;
158 changedItem->luid = strdup(luid);
160 changedItem->content_type = NULL;
167 void set_changeditem_contenttype(ChangedItem *pChangedItem, char *content_type)
169 FW_LOGV("start content_type = %s", content_type);
172 FW_LOGV("pChangedItem is NULL");
176 if (content_type != NULL)
177 pChangedItem->content_type = strdup(content_type);
180 void free_changeditem(ChangedItem *pChangedItem)
185 FW_LOGV("pChangedItem is NULL");
189 if (pChangedItem->luid) {
190 free(pChangedItem->luid);
191 pChangedItem->luid = NULL;
194 if (pChangedItem->content_type) {
195 free(pChangedItem->content_type);
196 pChangedItem->content_type = NULL;
199 if (pChangedItem->data) {
200 free(pChangedItem->data);
201 pChangedItem->data = NULL;
210 void set_changeditem_data(ChangedItem *changedItem, char *data)
213 FW_LOGV("changedItem is NULL");
218 changedItem->data = strdup(data);
221 void set_changedItem_indexofdatastore(ChangedItem *changedItem, unsigned int indexOfDatastore)
224 FW_LOGV("changedItem is NULL");
228 changedItem->indexOfDatastore = indexOfDatastore;
231 ChangedDatastore *create_changeddatastore(char *source, char *target, int hasNumberOfChanges, unsigned int numberOfChanges)
235 ChangedDatastore *changedDatastore = (ChangedDatastore *)calloc(1, sizeof(ChangedDatastore));
237 if (changedDatastore == NULL) {
238 FW_LOGV("changedDatastore is NULL");
243 changedDatastore->source = strdup(source);
245 changedDatastore->target = strdup(target);
247 changedDatastore->needSyncCommand = 1;
248 changedDatastore->numberOfChanges = numberOfChanges;
249 changedDatastore->hasNumberOfChanges = hasNumberOfChanges;
253 return changedDatastore;
256 void free_changeddatastores(GList *pChangedDatastores)
260 if (!pChangedDatastores) {
261 FW_LOGV("List is NULL");
266 for (iter = pChangedDatastores; iter != NULL; iter = g_list_next(iter))
267 free_changeddatastore(iter->data);
269 g_list_free(pChangedDatastores);
274 void free_changeddatastore(ChangedDatastore *pChangedDatastore)
276 FW_LOGV("pChangedDatastore = %p", pChangedDatastore);
279 if (!pChangedDatastore) {
280 FW_LOGV("pChangedDatastore is NULL");
284 if (pChangedDatastore->source) {
285 free(pChangedDatastore->source);
286 pChangedDatastore->source = NULL;
289 if (pChangedDatastore->target) {
290 free(pChangedDatastore->target);
291 pChangedDatastore->target = NULL;
295 for (iter = pChangedDatastore->changeItem; iter != NULL; iter = g_list_next(iter))
296 free_changeditem(iter->data);
298 g_list_free(pChangedDatastore->changeItem);
299 pChangedDatastore->changeItem = NULL;
301 for (iter = pChangedDatastore->sentItem; iter != NULL; iter = g_list_next(iter))
302 free_changeditem(iter->data);
304 g_list_free(pChangedDatastore->sentItem);
305 pChangedDatastore->sentItem = NULL;
307 if (pChangedDatastore)
308 free(pChangedDatastore);
313 void set_changeddatastore_changeditem(ChangedDatastore *changedDatastore, GList *changeItem)
315 if (changedDatastore)
316 changedDatastore->changeItem = changeItem;
319 void add_changeddatastore_changeditem(ChangedDatastore *changedDatastore, ChangedItem *changedItem)
321 if (!changedDatastore) {
322 FW_LOGV("changedDatastore is NULL");
326 changedDatastore->changeItem = g_list_append(changedDatastore->changeItem, changedItem);
329 AppliedStatus *create_appliedstatus(char *luid, ChangeType changeType, int status)
333 AppliedStatus *appliedStatus = (AppliedStatus *)calloc(1, sizeof(AppliedStatus));
334 if (appliedStatus == NULL) {
335 FW_LOGV("appliedStatus is NULL");
340 appliedStatus->luid = strdup(luid);
342 appliedStatus->changeType = changeType;
343 appliedStatus->status = status;
347 return appliedStatus;
350 void free_appliedstatuses(GList *pAppliedStatuses)
354 if (!pAppliedStatuses) {
355 FW_LOGV("List is NULL");
360 for (iter = pAppliedStatuses; iter != NULL; iter = g_list_next(iter))
361 free_appliedstatus(iter->data);
363 g_list_free(pAppliedStatuses);
368 void free_appliedstatus(AppliedStatus *pAppliedStatus)
372 if (!pAppliedStatus) {
373 FW_LOGV("pAppliedStatus is NULL");
377 if (pAppliedStatus->luid) {
378 free(pAppliedStatus->luid);
379 pAppliedStatus->luid = NULL;
382 free(pAppliedStatus);
387 SendingStatus *create_sendingstatus(char *source, char *target)
391 SendingStatus *sendingStatus = (SendingStatus *)calloc(1, sizeof(SendingStatus));
392 if (sendingStatus == NULL) {
393 FW_LOGV("sendingStatus is NULL");
398 sendingStatus->source = strdup(source);
401 sendingStatus->target = strdup(target);
405 return sendingStatus;
408 void free_sendingstatuses(GList *pSendingStatuses)
412 if (!pSendingStatuses) {
413 FW_LOGV("List is NULL");
418 for (iter = pSendingStatuses; iter != NULL; iter = g_list_next(iter))
419 free_sendingstatus(iter->data);
421 g_list_free(pSendingStatuses);
426 void free_sendingstatus(SendingStatus *pSendingStatus)
430 if (!pSendingStatus) {
431 FW_LOGV("pAppliedStatus is NULL");
435 if (pSendingStatus->source) {
436 free(pSendingStatus->source);
437 pSendingStatus->source = NULL;
440 if (pSendingStatus->target) {
441 free(pSendingStatus->target);
442 pSendingStatus->target = NULL;
446 for (iter = pSendingStatus->items; iter != NULL; iter = g_list_next(iter))
447 free_appliedstatus(iter->data);
449 g_list_free(pSendingStatus->items);
451 free(pSendingStatus);
455 void add_sendingstatus_appliedstatus(SendingStatus *sendingStatus, AppliedStatus *appliedStatus)
457 if (!sendingStatus) {
458 FW_LOGV("sendingStatus is NULL");
462 sendingStatus->items = g_list_append(sendingStatus->items, appliedStatus);
465 Datastore *create_datastore(char *target, char *source)
469 Datastore *datastore = (Datastore *)calloc(1, sizeof(Datastore));
470 if (datastore == NULL) {
471 FW_LOGV("datastore is NULL");
476 datastore->target = strdup(target);
479 datastore->source = strdup(source);
486 void set_datastore_contenttype_info(Datastore *datastore, int datastore_id, int folder_type_id)
489 datastore->datastore_id = datastore_id;
491 datastore->folder_type_id = folder_type_id;
494 void set_datastore_account_info(Datastore *datastore, char *account_id, char *account_pw)
497 datastore->id = strdup(account_id);
499 datastore->pw = strdup(account_pw);
502 void set_datastore_client_sync_type(Datastore *datastore, AlertType syncType)
505 datastore->clientSyncType = syncType ;
508 void set_datastore_server_sync_type(Datastore *datastore, AlertType syncType)
511 datastore->serverSyncType = syncType ;
514 void set_datastore_client_anchor(Datastore *datastore, char *lastAnchor, char *nextAnchor)
517 datastore->lastAnchorClient = strdup(lastAnchor);
519 datastore->nextAnchorClient = strdup(nextAnchor);
522 void set_datastore_server_anchor(Datastore *datastore, char *lastAnchor, char *nextAnchor)
525 datastore->lastAnchorServer = strdup(lastAnchor);
527 datastore->nextAnchorServer = strdup(nextAnchor);
530 SyncResult *create_sync_result()
534 SyncResult *syncResult = calloc(1, sizeof(SyncResult));
535 if (syncResult == NULL) {
536 FW_LOGV("syncResult is NULL");
545 SyncResult *dup_syncresult(SyncResult *orgSyncResult)
549 SyncResult *syncResult = calloc(1, sizeof(SyncResult));
550 if (syncResult == NULL) {
551 FW_LOGV("syncResult is NULL");
555 syncResult->sessionResult = orgSyncResult->sessionResult;
556 syncResult->numberOfChange = orgSyncResult->numberOfChange;
557 syncResult->received_count = orgSyncResult->received_count;
558 syncResult->add_count = orgSyncResult->add_count;
559 syncResult->replace_count = orgSyncResult->replace_count;
560 syncResult->delete_count = orgSyncResult->delete_count;
568 void set_numberofchange(SyncResult *syncResult, unsigned int numberOfChange)
571 syncResult->numberOfChange = numberOfChange;
574 void add_add_count(SyncResult *syncResult, unsigned int add_cnt)
577 syncResult->add_count += add_cnt;
580 void add_receive_count(SyncResult *syncResult, unsigned int received_count)
583 syncResult->received_count += received_count;
586 void add_replace_count(SyncResult *syncResult, unsigned int replace_cnt)
589 syncResult->replace_count += replace_cnt;
592 void add_delete_count(SyncResult *syncResult, unsigned int delete_cnt)
595 syncResult->delete_count += delete_cnt;
598 void free_presyncreturnobj(PreSyncReturnObj *pPreSyncReturnObj)
602 if (pPreSyncReturnObj == NULL) {
603 FW_LOGV("pPreSyncReturnObj is NULL");
608 for (iter = pPreSyncReturnObj->datastoreInfo; iter != NULL; iter = g_list_next(iter))
609 free_datastoreinfo(iter->data);
610 g_list_free(pPreSyncReturnObj->datastoreInfo);
611 pPreSyncReturnObj->datastoreInfo = NULL;
613 if (pPreSyncReturnObj->devID != NULL) {
614 free(pPreSyncReturnObj->devID);
615 pPreSyncReturnObj->devID = NULL;
618 free(pPreSyncReturnObj);
619 pPreSyncReturnObj = NULL;
624 void free_syncobj(SyncObj *pSyncObj)
628 if (pSyncObj == NULL) {
629 FW_LOGV("pSyncObj is NULL");
634 for (iter = pSyncObj->changedDatastore; iter != NULL; iter = g_list_next(iter))
635 free_changeddatastore(iter->data);
636 g_list_free(pSyncObj->changedDatastore);
637 pSyncObj->changedDatastore = NULL;
639 for (iter = pSyncObj->sendingStatus; iter != NULL; iter = g_list_next(iter))
640 free_sendingstatus(iter->data);
641 g_list_free(pSyncObj->sendingStatus);
642 pSyncObj->sendingStatus = NULL;
650 void free_syncreturnobj(SyncReturnObj *pSyncReturnObj)
654 if (pSyncReturnObj == NULL) {
655 FW_LOGV("pSyncReturnObj is NULL");
660 for (iter = pSyncReturnObj->changedDatastore; iter != NULL; iter = g_list_next(iter))
661 free_changeddatastore(iter->data);
662 g_list_free(pSyncReturnObj->changedDatastore);
663 pSyncReturnObj->changedDatastore = NULL;
665 for (iter = pSyncReturnObj->status; iter != NULL; iter = g_list_next(iter))
666 free_appliedstatus(iter->data);
667 g_list_free(pSyncReturnObj->status);
668 pSyncReturnObj->status = NULL;
670 free(pSyncReturnObj);
671 pSyncReturnObj = NULL;
676 void free_datastore(Datastore *pDatastore)
680 if (pDatastore == NULL)
683 if (pDatastore->target != NULL) {
684 free(pDatastore->target);
685 pDatastore->target = NULL;
688 if (pDatastore->source != NULL) {
689 free(pDatastore->source);
690 pDatastore->source = NULL;
693 if (pDatastore->id != NULL) {
694 free(pDatastore->id);
695 pDatastore->id = NULL;
698 if (pDatastore->pw != NULL) {
699 free(pDatastore->pw);
700 pDatastore->pw = NULL;
703 if (pDatastore->lastAnchorClient != NULL) {
704 free(pDatastore->lastAnchorClient);
705 pDatastore->lastAnchorClient = NULL;
708 if (pDatastore->nextAnchorClient != NULL) {
709 free(pDatastore->nextAnchorClient);
710 pDatastore->nextAnchorClient = NULL;
713 if (pDatastore->lastAnchorServer != NULL) {
714 free(pDatastore->lastAnchorServer);
715 pDatastore->lastAnchorServer = NULL;
718 if (pDatastore->nextAnchorServer != NULL) {
719 free(pDatastore->nextAnchorServer);
720 pDatastore->nextAnchorServer = NULL;
723 if (pDatastore->clientSyncResult != NULL)
724 free(pDatastore->clientSyncResult);
726 if (pDatastore->serverSyncResult != NULL)
727 free(pDatastore->serverSyncResult);