📄 mgrinstancemgr.c
字号:
pInstanceInfo = (InstanceInfoPtr_t)id; // ID is the instance info pointer if (pInstanceInfo==NULL) return SML_ERR_MGR_INVALID_INSTANCE_INFO; // set max outgoing message size pInstanceInfo->maxOutgoingSize = maxOutgoingSize; return SML_ERR_OK;}/** * FUNCTION: smlSetOutgoingBegin * * marks the current write pointer position as beginning of a new outgoing * message. This is used to track outgoing message size while writing it * * IN: InstanceID_t * ID of the Instance * * RETURN: Return value, * SML_ERR_OK if successful */SML_API Ret_t smlSetOutgoingBegin(InstanceID_t id){ InstanceInfoPtr_t pInstanceInfo; pInstanceInfo = (InstanceInfoPtr_t)id; // ID is the instance info pointer if (pInstanceInfo==NULL) return SML_ERR_MGR_INVALID_INSTANCE_INFO; // remember current write pointer pInstanceInfo->outgoingMsgStart=pInstanceInfo->writePointer; return SML_ERR_OK;}#endif/** * FUNCTION: smlLockWriteBuffer * * Locks the workspace buffer, which is assigned to the given * instance for writing. After this function is called, the * application has access to the workspace buffer, beginning * at the address pWritePosition which is returned by this * function. SyncML will not change the workspace buffer until * smlUnlockWriteBuffer is called. * pWritePosition returns a pointer to a valid position in the * SyncML workspace buffer. The pointer can be used by the application * for copying incoming synchronization data from some transport * layer into the buffer. freeSize retrieves the maximum usable * size of the workspace buffer beginning from the address to * which pWritePosition points to. This information is needed by * the application when copying XML code into the buffer (while * receiving synchronization data) * * IN: InstanceID_t * ID of the Instance * * OUT: MemPtr_t * Workspace Pointer to which data can be written * * OUT: MemSize_t * Max free Size of available space for data * * RETURN: Return value, * SML_ERR_OK if successful */SML_API Ret_t smlLockWriteBuffer(InstanceID_t id, MemPtr_t *pWritePosition, MemSize_t *freeSize){ #ifdef NOWSM InstanceInfoPtr_t pInstanceInfo; pInstanceInfo = (InstanceInfoPtr_t)id; // ID is the instance info pointer if (pInstanceInfo==NULL) return SML_ERR_MGR_INVALID_INSTANCE_INFO; // must not be already locked here if (pInstanceInfo->writeLocked) return SML_ERR_WRONG_USAGE; // return current write pointer *pWritePosition = pInstanceInfo->writePointer; // free portion is either determined by actual room in buffer, or maximum outgoing size if set if ( pInstanceInfo->maxOutgoingSize && pInstanceInfo->outgoingMsgStart && pInstanceInfo->outgoingMsgStart<pInstanceInfo->writePointer ) { // calculate what is allowed according to maxOutgoingSize *freeSize = (pInstanceInfo->maxOutgoingSize) - // maximum outgoing size (pInstanceInfo->writePointer-pInstanceInfo->outgoingMsgStart); // size of outgoing message so far if (pInstanceInfo->writePointer+*freeSize > pInstanceInfo->instanceBuffer+pInstanceInfo->instanceBufSiz) { // actual space in buffer is smaller *freeSize = (pInstanceInfo->instanceBuffer+pInstanceInfo->instanceBufSiz) - // end of buffer pInstanceInfo->writePointer; // current write position } } else { // simply return available size in buffer *freeSize = (pInstanceInfo->instanceBuffer+pInstanceInfo->instanceBufSiz) - // end of buffer pInstanceInfo->writePointer; // current write position } // lock pInstanceInfo->writeLocked=1; #else Ret_t rc; /* --- Lock Workspace exclusively for writing and get a "Write" pointer --- */ LOCKTOOLKIT("smlLockWriteBuffer"); rc = wsmLockH(id, SML_FIRST_FREE_ITEM, pWritePosition); RELEASETOOLKIT("smlLockWriteBuffer"); if (rc!=SML_ERR_OK) return rc; /* --- Check, how much free space is available for writing --- */ LOCKTOOLKIT("smlLockWriteBuffer"); rc = wsmGetFreeSize(id, freeSize); RELEASETOOLKIT("smlLockWriteBuffer"); if (rc!=SML_ERR_OK) return rc; #endif return SML_ERR_OK;}/** * FUNCTION: smlUnlockWriteBuffer * * End the write access of the application to the workspace buffer. * SyncML is now owner of the buffer again and is able to manipulate its * contents. writtenBytes passes the number of bytes which have been * written into the workspace buffer (e.g. when the application has copied * incoming synchronization data from a communication module into the * workspace). This information is needed by SyncML when processing received * synchronization data. * * IN: InstanceID_t * ID of the Instance * * IN: MemSize_t * Actually written bytes * * RETURN: Return value, * SML_ERR_OK if successful */SML_API Ret_t smlUnlockWriteBuffer(InstanceID_t id, MemSize_t writtenBytes){ #ifdef NOWSM InstanceInfoPtr_t pInstanceInfo; pInstanceInfo = (InstanceInfoPtr_t)id; // ID is the instance info pointer if (pInstanceInfo==NULL) return SML_ERR_MGR_INVALID_INSTANCE_INFO; // must be already locked here if (!pInstanceInfo->writeLocked) return SML_ERR_WRONG_USAGE; if (writtenBytes > 0) { // advance write pointer by number of bytes written if (pInstanceInfo->writePointer+writtenBytes>pInstanceInfo->instanceBuffer+pInstanceInfo->instanceBufSiz) return SML_ERR_WRONG_USAGE; // too many bytes written // update write pointer pInstanceInfo->writePointer+=writtenBytes; } // unlock pInstanceInfo->writeLocked=0; #else Ret_t rc; if (writtenBytes > 0) { /* --- Pass the number of bytes which have been written --- */ LOCKTOOLKIT("smlUnlockWriteBuffer"); rc = wsmSetUsedSize(id,writtenBytes); RELEASETOOLKIT("smlUnlockWriteBuffer"); if (rc!=SML_ERR_OK) return rc; } /* --- Unlock Workspace --- */ LOCKTOOLKIT("smlUnlockWriteBuffer"); rc = wsmUnlockH(id); RELEASETOOLKIT("smlUnlockWriteBuffer"); if (rc!=SML_ERR_OK) return rc; #endif return SML_ERR_OK;}/************************************************************************* * SyncML internal functions *************************************************************************//** * FUNCTION: mgrResetWorkspace * Reset the Workspace Buffer position to the beginning of the workspace * (clears all data in the buffer) * * IN: InstanceID_t * ID of the Instance * RETURN: Return value, * SML_ERR_OK if successful */Ret_t mgrResetWorkspace (InstanceID_t id) { #ifdef NOWSM InstanceInfoPtr_t pInstanceInfo; pInstanceInfo = (InstanceInfoPtr_t)id; // ID is the instance info pointer if (pInstanceInfo==NULL) return SML_ERR_MGR_INVALID_INSTANCE_INFO; pInstanceInfo->readPointer=pInstanceInfo->instanceBuffer; pInstanceInfo->writePointer=pInstanceInfo->instanceBuffer; pInstanceInfo->outgoingMsgStart=NULL; // no outgoing message in the buffer return SML_ERR_OK; // ok #else Ret_t rc; LOCKTOOLKIT("mgrResetWorkspace"); rc=wsmReset (id); RELEASETOOLKIT("mgrResetWorkspace"); return rc; #endif}/** * FUNCTION: setInstanceOptions * * the options settings of an instance are set to a new value * * IN: InstanceID_t * Instance ID assigned to the instance * * IN: SmlInstanceOptionsPtr_t * New option settings of that particular SyncML instance * NOTE: only the encoding can be changed during life-time * of an instance * The other parameters of the instance options * (workspace size and name cannot be changed) * * RETURN: Ret_t * Error Code */Ret_t setInstanceOptions (InstanceID_t id, SmlInstanceOptionsPtr_t pOptions){ /* --- Definitions --- */ InstanceInfoPtr_t pInstanceInfo; SmlInstanceOptionsPtr_t pOptionsCopy; #ifdef NOWSM /* --- Ckeck pOptions, which have been passed by the application --- */ if (!pOptions || (pOptions->encoding==SML_UNDEF)) return SML_ERR_WRONG_USAGE; pInstanceInfo = (InstanceInfoPtr_t)id; // ID is the instance info pointer #else /* --- Ckeck pOptions, which have been passed by the application --- */ if (!pOptions || !pOptions->workspaceName|| (pOptions->encoding==SML_UNDEF)) return SML_ERR_WRONG_USAGE; /* --- Find that instance --- */ #ifdef __SML_LITE__ /* Only ONE instance is supported in the Toolkit lite version */ pInstanceInfo = mgrGetInstanceListAnchor(); #else pInstanceInfo = (InstanceInfoPtr_t) findInfo(id); #endif #endif if (pInstanceInfo==NULL) return SML_ERR_MGR_INVALID_INSTANCE_INFO; /* --- free old instance options ---*/ freeInstanceOptions(pInstanceInfo); /* --- Use a copy of pOptionsCopy --- */ pOptionsCopy = (SmlInstanceOptionsPtr_t)smlLibMalloc((MemSize_t)sizeof(SmlInstanceOptions_t)); if (pOptionsCopy==NULL) return SML_ERR_NOT_ENOUGH_SPACE; smlLibMemcpy(pOptionsCopy,pOptions,(MemSize_t)sizeof(SmlInstanceOptions_t)); #ifndef NOWSM pOptionsCopy->workspaceName=smlLibStrdup(pOptions->workspaceName); if (pOptionsCopy->workspaceName == NULL) { pInstanceInfo->instanceOptions=NULL; smlLibFree(pOptionsCopy); return SML_ERR_NOT_ENOUGH_SPACE; } #endif /* --- Assign the new options --- */ pInstanceInfo->instanceOptions=pOptionsCopy; /* --- Let the new settingds take effect --- */ /* --- Adjust workspace size ---*/ /* --- Change workspace name ---*/ // NOT SUPPORTED FOR YELLOW return SML_ERR_OK;}/** * FUNCTION: freeInstanceOptions * Free Instances Options * * RETURN: InstanceInfoPtr_t * Pointer to the pInstance Info, which options should be freed */Ret_t freeInstanceOptions (InstanceInfoPtr_t pInfo) { /* --- Delete instance options (if there are any) --- */ if (pInfo->instanceOptions!=NULL) { #ifndef NOWSM if (pInfo->instanceOptions->workspaceName!=NULL) smlLibFree(pInfo->instanceOptions->workspaceName); // don't forget the substructures #endif smlLibFree(pInfo->instanceOptions); } return SML_ERR_OK; }/** * FUNCTION: * Free the memory of an removed Instance Info (including referenced sub structures) * * IN: InstanceID_t * ID of the InstanceInfo structure to be freed */static Ret_t freeInstanceInfo(InstanceInfoPtr_t pInfo) { if (pInfo) { #ifdef NOWSM // return the instance buffer if (pInfo->instanceBuffer) smlLibFree(pInfo->instanceBuffer); #else if (pInfo->workspaceState) smlLibFree(pInfo->workspaceState); #endif if (pInfo->encoderState) smlLibFree(pInfo->encoderState); if (pInfo->decoderState) smlLibFree(pInfo->decoderState); if (pInfo->callbacks) smlLibFree(pInfo->callbacks); freeInstanceOptions(pInfo); smlLibFree(pInfo); } return SML_ERR_OK;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -