1/*************************************************************************/ 2/* module: List of SyncML Instances */ 3/* */ 4/* file: mgrinstancelist.c */ 5/* target system: all */ 6/* target OS: all */ 7/* */ 8/* Description: */ 9/* This module handles an element list of type InstanceInfo. Each */ 10/* element is identified by the InstanceID. There are functions provided */ 11/* to add, find and remove InstanceInfo elements. */ 12/* This file is private to the core module. The InstanceInfo list is */ 13/* used by the Modules MGR, MGRCmdDispatcher, MGRCmdBuilder */ 14/* and MGRInstanceMgr. */ 15/*************************************************************************/ 16 17/* 18 * Copyright Notice 19 * Copyright (c) Ericsson, IBM, Lotus, Matsushita Communication 20 * Industrial Co., Ltd., Motorola, Nokia, Openwave Systems, Inc., 21 * Palm, Inc., Psion, Starfish Software, Symbian, Ltd. (2001). 22 * All Rights Reserved. 23 * Implementation of all or part of any Specification may require 24 * licenses under third party intellectual property rights, 25 * including without limitation, patent rights (such a third party 26 * may or may not be a Supporter). The Sponsors of the Specification 27 * are not responsible and shall not be held responsible in any 28 * manner for identifying or failing to identify any or all such 29 * third party intellectual property rights. 30 * 31 * THIS DOCUMENT AND THE INFORMATION CONTAINED HEREIN ARE PROVIDED 32 * ON AN "AS IS" BASIS WITHOUT WARRANTY OF ANY KIND AND ERICSSON, IBM, 33 * LOTUS, MATSUSHITA COMMUNICATION INDUSTRIAL CO. LTD, MOTOROLA, 34 * NOKIA, PALM INC., PSION, STARFISH SOFTWARE AND ALL OTHER SYNCML 35 * SPONSORS DISCLAIM ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING 36 * BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION 37 * HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF 38 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT 39 * SHALL ERICSSON, IBM, LOTUS, MATSUSHITA COMMUNICATION INDUSTRIAL CO., 40 * LTD, MOTOROLA, NOKIA, PALM INC., PSION, STARFISH SOFTWARE OR ANY 41 * OTHER SYNCML SPONSOR BE LIABLE TO ANY PARTY FOR ANY LOSS OF 42 * PROFITS, LOSS OF BUSINESS, LOSS OF USE OF DATA, INTERRUPTION OF 43 * BUSINESS, OR FOR DIRECT, INDIRECT, SPECIAL OR EXEMPLARY, INCIDENTAL, 44 * PUNITIVE OR CONSEQUENTIAL DAMAGES OF ANY KIND IN CONNECTION WITH 45 * THIS DOCUMENT OR THE INFORMATION CONTAINED HEREIN, EVEN IF ADVISED 46 * OF THE POSSIBILITY OF SUCH LOSS OR DAMAGE. 47 * 48 * The above notice and this paragraph must be included on all copies 49 * of this document that are made. 50 * 51 */ 52 53 54 55 56/************************************************************************* 57 * Definitions 58 *************************************************************************/ 59 60 61/* Include Headers */ 62#include <smlerr.h> 63#include "libmem.h" 64#include "liblock.h" 65#include "mgr.h" 66 67#ifndef __SML_LITE__ /* Only ONE instance is supported in the Toolkit lite version */ 68 69#ifndef NOWSM /* only need if we are using workspace manager */ 70 71 72/* Used external functions */ 73SyncMLInfoPtr_t mgrGetSyncMLAnchor(void); 74InstanceInfoPtr_t mgrGetInstanceListAnchor(void); 75void mgrSetInstanceListAnchor(InstanceInfoPtr_t newListAnchor); 76 77 78/* SyncML internal function prototypes */ 79Ret_t addInfo(InstanceInfoPtr_t pInfo); 80InstanceInfoPtr_t findInfo(InstanceID_t id); 81Ret_t removeInfo(InstanceID_t id); 82 83 84/* Private function prototypes */ 85 86 87 88 89 90 91/************************************************************************* 92 * SyncML internal functions 93 *************************************************************************/ 94 95 96/** 97 * FUNCTION: 98 * Adds a new element to the list 99 * 100 * IN: InstanceInfoPtr_t 101 * pointer to the structure to be be added to list 102 * 103 * RETURN: Return value, 104 * SML_ERR_OK if element was added successfully 105 */ 106Ret_t addInfo(InstanceInfoPtr_t pInfo) 107{ 108 109 if (pInfo!=NULL) 110 { 111 InstanceInfoPtr_t _pTmp; 112 113 LOCKTOOLKIT("addInfo"); 114 /* Remember old beginning of the list */ 115 _pTmp=mgrGetInstanceListAnchor(); 116 117 /* insert element immediately after anchor */ 118 mgrSetInstanceListAnchor(pInfo); // anchor of list points now to new info element 119 pInfo->nextInfo=_pTmp; // Next info element is the prior first one. 120 RELEASETOOLKIT("addInfo"); 121 return SML_ERR_OK; 122 123 } else { // Invalid InstanceInfo pointer was used (NULL) 124 125 return SML_ERR_MGR_INVALID_INSTANCE_INFO; 126 } 127 128} 129 130 131 132 133 134/** 135 * FUNCTION: 136 * Searches an element with the given InstanceID in the list 137 * 138 * IN: InstanceID_t 139 * ID of the InstanceInfo structure to be retrieved 140 * 141 * RETURN: InstanceInfoPtr_t 142 * Pointer to the InstanceInfo structure with the given ID 143 * NULL, if no InstanceInfo with the given ID has been found 144 */ 145InstanceInfoPtr_t findInfo(InstanceID_t id) 146{ 147 148 InstanceInfoPtr_t _pTmp; // A helper pointer 149 150 /* go through the list until end */ 151 LOCKTOOLKIT("findInfo"); 152 for (_pTmp=mgrGetInstanceListAnchor(); _pTmp!=NULL; _pTmp=_pTmp->nextInfo) 153 { 154 if (_pTmp->id == id) { 155 RELEASETOOLKIT("findInfo"); 156 return _pTmp; // STOP, we've found the info, return! 157 } 158 } 159 RELEASETOOLKIT("findInfo"); 160 return NULL; // Info was not found, return NULL 161 162} 163 164 165 166 167 168/** 169 * FUNCTION: 170 * Removes an element with the given InstanceID from the list 171 * 172 * IN: InstanceID_t 173 * ID of the InstanceInfo structure to be removed 174 * 175 * RETURN: Return value, 176 * SML_ERR_OK if element was removed successfully 177 */ 178Ret_t removeInfo(InstanceID_t id) 179{ 180 181 InstanceInfoPtr_t _pTmp; // A helper pointer 182 InstanceInfoPtr_t _pRemember; // A helper pointer 183 184 185 LOCKTOOLKIT("removeInfo"); 186 /* Remember current anchor */ 187 _pRemember=mgrGetInstanceListAnchor(); 188 189 /* special check, if list is empty */ 190 if (_pRemember==NULL ) { 191 RELEASETOOLKIT("removeInfo"); 192 return SML_ERR_MGR_INVALID_INSTANCE_INFO; 193 } 194 195 /* special check, if first element should be removed */ 196 if (_pRemember->id == id) 197 { 198 // It's the first element, update anchor! 199 mgrSetInstanceListAnchor(_pRemember->nextInfo); 200 //freeInfo(_pRemember); // Delete structure, free memory 201 RELEASETOOLKIT("removeInfo"); 202 return SML_ERR_OK; // return 203 } 204 205 206 /* go through the list until end */ 207 for (_pTmp=_pRemember->nextInfo; _pTmp!=NULL; _pTmp=_pTmp->nextInfo) 208 { 209 if (_pTmp->id == id) // STOP, we've found the info 210 { 211 _pRemember->nextInfo=_pTmp->nextInfo; 212 //freeInfo(_pTmp); // Delete structure, free memory 213 RELEASETOOLKIT("removeInfo"); 214 return SML_ERR_OK; // return 215 216 } else { 217 218 _pRemember=_pTmp; // update helper pointer 219 } 220 } 221 222 RELEASETOOLKIT("removeInfo"); 223 return SML_ERR_MGR_INVALID_INSTANCE_INFO; // Info wasn't found 224 225} 226 227 228 229 230#endif // !defined(NOWSM) 231 232 233#endif 234