1 /*************************************************************************/ 2 /* module: Managing SyncML */ 3 /* */ 4 /* file: mgr.c */ 5 /* target system: all */ 6 /* target OS: all */ 7 /* */ 8 /* Description: */ 9 /* Core Module managing the life-cycle of a syncML Process itself */ 10 /*************************************************************************/ 11 12 13 /* 14 * Copyright Notice 15 * Copyright (c) Ericsson, IBM, Lotus, Matsushita Communication 16 * Industrial Co., Ltd., Motorola, Nokia, Openwave Systems, Inc., 17 * Palm, Inc., Psion, Starfish Software, Symbian, Ltd. (2001). 18 * All Rights Reserved. 19 * Implementation of all or part of any Specification may require 20 * licenses under third party intellectual property rights, 21 * including without limitation, patent rights (such a third party 22 * may or may not be a Supporter). The Sponsors of the Specification 23 * are not responsible and shall not be held responsible in any 24 * manner for identifying or failing to identify any or all such 25 * third party intellectual property rights. 26 * 27 * THIS DOCUMENT AND THE INFORMATION CONTAINED HEREIN ARE PROVIDED 28 * ON AN "AS IS" BASIS WITHOUT WARRANTY OF ANY KIND AND ERICSSON, IBM, 29 * LOTUS, MATSUSHITA COMMUNICATION INDUSTRIAL CO. LTD, MOTOROLA, 30 * NOKIA, PALM INC., PSION, STARFISH SOFTWARE AND ALL OTHER SYNCML 31 * SPONSORS DISCLAIM ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING 32 * BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION 33 * HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF 34 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT 35 * SHALL ERICSSON, IBM, LOTUS, MATSUSHITA COMMUNICATION INDUSTRIAL CO., 36 * LTD, MOTOROLA, NOKIA, PALM INC., PSION, STARFISH SOFTWARE OR ANY 37 * OTHER SYNCML SPONSOR BE LIABLE TO ANY PARTY FOR ANY LOSS OF 38 * PROFITS, LOSS OF BUSINESS, LOSS OF USE OF DATA, INTERRUPTION OF 39 * BUSINESS, OR FOR DIRECT, INDIRECT, SPECIAL OR EXEMPLARY, INCIDENTAL, 40 * PUNITIVE OR CONSEQUENTIAL DAMAGES OF ANY KIND IN CONNECTION WITH 41 * THIS DOCUMENT OR THE INFORMATION CONTAINED HEREIN, EVEN IF ADVISED 42 * OF THE POSSIBILITY OF SUCH LOSS OR DAMAGE. 43 * 44 * The above notice and this paragraph must be included on all copies 45 * of this document that are made. 46 * 47 */ 48 49 50 51 52 /************************************************************************* 53 * Definitions 54 *************************************************************************/ 55 56 57 /* Include Headers */ 58 #include <sml.h> 59 #include <smldef.h> 60 #include <smlerr.h> 61 62 #if defined(NOWSM) && !__LINK_TOOLKIT_STATIC__ 63 // we need dummies of these as they are listed in the SyncML.def file 64 SML_API_DEF Ret_t smlInit(SmlOptionsPtr_t pOptions) { return SML_ERR_OK; } 65 SML_API_DEF Ret_t smlSetSyncMLOptions (SmlOptionsPtr_t pOptions) { return SML_ERR_OK; } 66 SML_API_DEF Ret_t smlTerminate(void) { return SML_ERR_OK; } 67 #endif 68 69 #ifndef NOWSM 70 71 #include "libmem.h" 72 #include "liblock.h" 73 #include "wsm.h" 74 #include "mgr.h" 75 76 #ifdef __EPOC_OS__ 77 #include "core_globals_epoc.h" 78 #endif 79 80 /* Prototypes of exported SyncML API functions */ 81 SML_API Ret_t smlInit(SmlOptionsPtr_t pOptions); 82 SML_API Ret_t smlSetSyncMLOptions (SmlOptionsPtr_t pOptions); 83 SML_API Ret_t smlTerminate(void); 84 85 /* SyncML internal function prototypes */ 86 InstanceInfoPtr_t mgrGetInstanceListAnchor(void); 87 void mgrSetInstanceListAnchor(InstanceInfoPtr_t newListAnchor); 88 SyncMLInfoPtr_t mgrGetSyncMLAnchor(void); 89 90 91 /** 92 * Anchor of the global syncML info structure 93 */ 94 #ifndef __EPOC_OS__ 95 static SyncMLInfoPtr_t pGlobalAnchor=NULL; // this global pointer is used to access ALL globals within syncml 96 #endif // This is the ONLY global varible of SyncML! 97 98 #ifdef __EPOC_OS__ 99 #define pGlobalAnchor TheCoreGlobalsEpoc()->pGlobalAnchor 100 #endif 101 102 /************************************************************************* 103 * Exported SyncML API functions 104 *************************************************************************/ 105 106 107 108 109 /** 110 * FUNCTION: smlInit 111 * 112 * Initializes the SyncML Reference Tookit. This is required, before any 113 * other function can be used. 114 * 115 * IN: SyncMLOptionsPtr_t 116 * options to be applied for the toolkit 117 * 118 * RETURN: Ret_t 119 * Return Code 120 */ 121 SML_API Ret_t smlInit(SmlOptionsPtr_t pCoreOptions) 122 { 123 124 /* ---- Definitions --- */ 125 WsmOptions_t* pWorkspaceOptions; 126 Ret_t rc; 127 128 129 /* --- check, if SyncML has already been initialized --- */ 130 if (pGlobalAnchor!=NULL) return SML_ERR_ALREADY_INITIALIZED; 131 132 /* --- Check pOptions, which have been passed by the application --- */ 133 if (!pCoreOptions) 134 return SML_ERR_WRONG_USAGE; 135 136 137 /* --- Create a SyncML info memory object to store all globals --- */ 138 TOOLKITLOCK_INIT("smlInit"); 139 pGlobalAnchor = (SyncMLInfoPtr_t)smlLibMalloc((MemSize_t)sizeof(SyncMLInfo_t)); 140 if (pGlobalAnchor==NULL) return SML_ERR_NOT_ENOUGH_SPACE; 141 smlLibMemset(pGlobalAnchor,0,(MemSize_t)sizeof(SyncMLInfo_t)); 142 143 144 /* --- Set SyncML settings and options --- */ 145 pGlobalAnchor->instanceListAnchor = NULL; // no instance exists at the beginning 146 rc = smlSetSyncMLOptions (pCoreOptions); // store the options in the global structure 147 if (rc!=SML_ERR_OK){ 148 smlLibFree(pGlobalAnchor); 149 pGlobalAnchor = NULL; 150 return rc; 151 } 152 153 pGlobalAnchor->tokTbl = (TokenInfoPtr_t)smlLibMalloc(sizeof(TokenInfo_t)); 154 if (pGlobalAnchor->tokTbl == NULL) 155 { 156 smlLibFree(pGlobalAnchor); 157 return SML_ERR_NOT_ENOUGH_SPACE; 158 } 159 smlLibMemset(pGlobalAnchor->tokTbl, 0, sizeof(TokenInfo_t)); 160 /* --- Init all modules ---*/ 161 162 /* Init Workspace Module */ 163 pWorkspaceOptions=(WsmOptions_t*)smlLibMalloc((MemSize_t)sizeof(WsmOptions_t)); // create workspace options 164 if (pWorkspaceOptions == NULL) { 165 smlLibFree(pGlobalAnchor->syncmlOptions); 166 smlLibFree(pGlobalAnchor->tokTbl); 167 smlLibFree(pGlobalAnchor); 168 pGlobalAnchor = NULL; 169 return SML_ERR_NOT_ENOUGH_SPACE; 170 } 171 172 smlLibMemset(pWorkspaceOptions,0,(MemSize_t)sizeof(WsmOptions_t)); 173 pWorkspaceOptions->maxAvailMem=(MemSize_t)pGlobalAnchor->syncmlOptions->maxWorkspaceAvailMem; 174 175 rc = wsmInit (pWorkspaceOptions); 176 if (rc!=SML_ERR_OK){ 177 smlLibFree(pGlobalAnchor->syncmlOptions); 178 smlLibFree(pGlobalAnchor->tokTbl); 179 smlLibFree(pGlobalAnchor); 180 pGlobalAnchor = NULL; 181 smlLibFree(pWorkspaceOptions); 182 return rc; 183 } 184 smlLibFree(pWorkspaceOptions); 185 return SML_ERR_OK; 186 } 187 188 189 /** 190 * FUNCTION: smlTerminate 191 * 192 * Terminate SyncML. Frees all memory and other ressources used by 193 * SyncML. This function must be called when terminating SyncML 194 * 195 * PRE-Condition: All instances must have been terminated 196 * 197 * RETURN: Ret_t 198 * Return Code 199 */ 200 SML_API Ret_t smlTerminate(void) { 201 // Have all Instances been terminated? 202 if (pGlobalAnchor->instanceListAnchor!=NULL) 203 return SML_ERR_WRONG_USAGE; 204 205 /* --- Make sure, the workspace is destroyed --*/ 206 LOCKTOOLKIT("smlTerminate"); 207 wsmTerminate(); 208 209 /* --- Free the global structure --*/ 210 smlLibFree(pGlobalAnchor->tokTbl->SyncML); 211 smlLibFree(pGlobalAnchor->tokTbl->MetInf); 212 smlLibFree(pGlobalAnchor->tokTbl->DevInf); 213 smlLibFree(pGlobalAnchor->tokTbl->DmTnd); 214 smlLibFree(pGlobalAnchor->tokTbl); 215 smlLibFree(pGlobalAnchor->syncmlOptions); 216 smlLibFree(pGlobalAnchor); 217 pGlobalAnchor=NULL; 218 219 TOOLKITLOCK_FREE("smlTerminate"); 220 221 return SML_ERR_OK; 222 223 } 224 225 226 227 /** 228 * FUNCTION: smlSetSyncMLOptions 229 * 230 * change the option settings for syncML 231 * 232 * IN: SyncMLOptionsPtr_t 233 * options to be applied for the toolkit 234 * 235 * RETURN: Ret_t 236 * Return Code 237 */ 238 SML_API Ret_t smlSetSyncMLOptions(SmlOptionsPtr_t pCoreOptions) { 239 240 241 /* ---- Definitions --- */ 242 SmlOptionsPtr_t pCoreOptionsCopy; 243 244 245 /* --- Check pOptions, which have been passed by the application --- */ 246 if (!pCoreOptions) 247 return SML_ERR_WRONG_USAGE; 248 249 250 /* --- free SyncML options --- */ 251 smlLibFree(pGlobalAnchor->syncmlOptions); 252 pGlobalAnchor->syncmlOptions = NULL; 253 /* --- Use a copy of pCoreOptions --- */ 254 pCoreOptionsCopy = (SmlOptionsPtr_t)smlLibMalloc((MemSize_t)sizeof(SmlOptions_t)); 255 if (pCoreOptionsCopy==NULL) return SML_ERR_NOT_ENOUGH_SPACE; 256 smlLibMemcpy(pCoreOptionsCopy,pCoreOptions,(MemSize_t)sizeof(SmlOptions_t)); 257 258 259 /* --- set new SyncML options --- */ 260 pGlobalAnchor->syncmlOptions = pCoreOptionsCopy; // set the options,passed from the application 261 262 return SML_ERR_OK; 263 264 } 265 266 /************************************************************************* 267 * SyncML internal functions 268 *************************************************************************/ 269 /** 270 * FUNCTION: mgrGetSyncMLInfo 271 * Retrieves a pointer to the structure holding all global informations within SyncML 272 * 273 * RETURN: SyncMLInfoPtr_t 274 * Pointer to the pGlobalAnchor 275 */ 276 SyncMLInfoPtr_t mgrGetSyncMLAnchor(void) 277 { 278 return pGlobalAnchor; 279 } 280 281 /** 282 * FUNCTION: mgrGetInstanceListAnchor 283 * Retrieves a pointer to the list holding all instance informations 284 * 285 * RETURN: InstanceInfoPtr_t 286 * Pointer to the pInstanceListAnchor 287 */ 288 InstanceInfoPtr_t mgrGetInstanceListAnchor(void) 289 { 290 return pGlobalAnchor->instanceListAnchor; 291 } 292 293 /** 294 * FUNCTION: mgrSetInstanceListAnchor 295 * Set the pointer to the list holding all instance informations 296 * 297 * IN: InstanceInfoPtr_t 298 * Pointer to the pInstanceListAnchor 299 */ 300 void mgrSetInstanceListAnchor(InstanceInfoPtr_t newListAnchor) 301 { 302 pGlobalAnchor->instanceListAnchor=newListAnchor; 303 } 304 305 306 #endif // !defined(NOWSM) 307