⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mgrinstancemgr.c

📁 SyncML ToolKits,学习syncml的参考工具包.非常好用.
💻 C
📖 第 1 页 / 共 3 页
字号:
  #ifdef NOWSM    pInstanceInfo = (InstanceInfoPtr_t)id; // ID is the instance info pointer  #else      /* --- 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    if (pInstanceInfo==NULL) return SML_ERR_MGR_INVALID_INSTANCE_INFO;  #endif  /* --- free old callback structure ---*/  smlLibFree(pInstanceInfo->callbacks);  /* --- Use a copy of pCallbacksCopy --- */  pCallbacksCopy = (SmlCallbacksPtr_t)smlLibMalloc((MemSize_t)sizeof(SmlCallbacks_t));  if (pCallbacksCopy==NULL) return SML_ERR_NOT_ENOUGH_SPACE;  smlLibMemcpy(pCallbacksCopy,pCallbacks,(MemSize_t)sizeof(SmlCallbacks_t));  	/* --- set new Callbacks --- */	pInstanceInfo->callbacks = pCallbacksCopy;  	return SML_ERR_OK;}/** * FUNCTION:  smlSetUserData * * Sets a new Pointer to application specific user data,  * which is passed to all invoked callback functions * * IN:        InstanceID_t               *            ID of the Instance * * IN:        VoidPtr_t *            UserData is a pointer to a void structure the application  *            can pass into the SyncML Toolkit instance info.  *            It will be returned to the application with every called  *            callback function call! *            NOTE: This is only a pointer, the memory object itself  *            remains within the responsibility of the calling application. *            The memory object will not be copied, moved or freed by the  *            Toolkit. * * RETURN:    Return value,             *            SML_ERR_OK if successful */SML_API Ret_t smlSetUserData(InstanceID_t id, VoidPtr_t pUserData){  /* --- Definitions --- */  InstanceInfoPtr_t	pInstanceInfo;  #ifdef NOWSM    pInstanceInfo = (InstanceInfoPtr_t)id; // ID is the instance info pointer  #else      /* --- 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;  /* --- set new user data pointer ---*/  pInstanceInfo->userData=pUserData;	return SML_ERR_OK;}/** * FUNCTION:  smlGetUserData  (added by luz %%%) * * Returns Pointer to application specific user data,  * which is passed to all invoked callback functions * * IN:        InstanceID_t               *            ID of the Instance * * IN:        *VoidPtr_t *            Receives current Userdata pointer * * RETURN:    Return value,             *            SML_ERR_OK if successful */SML_API Ret_t smlGetUserData(InstanceID_t id, VoidPtr_t *ppUserData){  /* --- Definitions --- */  InstanceInfoPtr_t	pInstanceInfo;  #ifdef NOWSM    pInstanceInfo = (InstanceInfoPtr_t)id; // ID is the instance info pointer  #else      /* --- 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;  /* --- get userdata pointer ---*/  *ppUserData = pInstanceInfo->userData;	return SML_ERR_OK;} // smlGetUserData/** * FUNCTION:  smlGetEncoding (added by luz %%%) * * Returns Currently set encoding type * * IN:        InstanceID_t               *            ID of the Instance * * IN:        *SmlEncoding_t *            Receives current encoding * * RETURN:    Return value,             *            SML_ERR_OK if successful */SML_API Ret_t smlGetEncoding(InstanceID_t id, SmlEncoding_t *pEncoding){  /* --- Definitions --- */  InstanceInfoPtr_t	pInstanceInfo;  #ifdef NOWSM    pInstanceInfo = (InstanceInfoPtr_t)id; // ID is the instance info pointer  #else      /* --- 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;  /* --- get encoding ---*/  *pEncoding = pInstanceInfo->instanceOptions->encoding;	return SML_ERR_OK;} // smlGetEncoding/** * FUNCTION:  smlSetEncoding * * Sets new encoding type for this Instance * * IN:        InstanceID_t               *            ID of the Instance * * IN:        SmlEncoding_t *            Type of Encoding to be used within this Instance * * RETURN:    Return value,             *            SML_ERR_OK if successful */#ifndef __SML_LITE__  /* these API calls are NOT included in the Toolkit lite version */SML_API Ret_t smlSetEncoding(InstanceID_t id, SmlEncoding_t encoding){  /* --- Definitions --- */  InstanceInfoPtr_t	pInstanceInfo;  /* --- Check pCallbacks, which have been passed by the application --- */  if (encoding==SML_UNDEF)    return SML_ERR_WRONG_USAGE;  #ifdef NOWSM    pInstanceInfo = (InstanceInfoPtr_t)id; // ID is the instance info pointer  #else      /* --- 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 callback structure ---*/  pInstanceInfo->instanceOptions->encoding = encoding;	return SML_ERR_OK;}#endif/** * FUNCTION:  smlLockReadBuffer * * Locks the workspace buffer, which is assigned to the given instance * for reading. After this function is called, the application has  * access to the workspace buffer, beginning at the address pReadPosition which  * is returned by this function. SyncML will not change the workspace  * buffer until smlUnlockReadBuffer is called. * pReadPosition returns a pointer to a valid position in the SyncML workspace  * buffer. The pointer can be used by the application for copying outgoing  * synchronization data from the buffer into some transport layer. usedSize  * retrieves the size of synchronization data currently stored in the  * workspace buffer beginning from the address to which pReadPosition points to.  * This information is needed by the application when copying XML code out  * of the buffer (while sending synchronization data) * * IN:        InstanceID_t               *            ID of the Instance * * OUT:       MemPtr_t               *            Workspace Pointer from which data can be read * * OUT:       MemSize_t               *            Size of used data in workspace which may be read * * RETURN:    Return value,             *            SML_ERR_OK if successful */SML_API Ret_t smlLockReadBuffer(InstanceID_t id, MemPtr_t *pReadPosition, MemSize_t *usedSize){    #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->readLocked)      return SML_ERR_WRONG_USAGE;    // everything that is already written can also be read    *pReadPosition = pInstanceInfo->readPointer;    // used portion is what is between read and write pointers    *usedSize = pInstanceInfo->writePointer-pInstanceInfo->readPointer;    // lock    pInstanceInfo->readLocked=1;  #else    Ret_t rc;        LOCKTOOLKIT("smlLockReadBuffer");    /* --- Lock Workspace exclusively for reading and get a "Read" pointer --- */    rc = wsmLockH(id, SML_FIRST_DATA_ITEM, pReadPosition);    RELEASETOOLKIT("smlLockReadBuffer");    if (rc!=SML_ERR_OK) return rc;        /* --- Check, how much data has to be read ---*/    LOCKTOOLKIT("smlLockReadBuffer");    rc = wsmGetUsedSize(id,usedSize);      RELEASETOOLKIT("smlLockReadBuffer");    if (rc!=SML_ERR_OK) return rc;  #endif    return SML_ERR_OK;}/** * FUNCTION:  smlUnlockReadBuffer * * End the read access of the application to the workspace buffer.  * SyncML is now owner of the buffer again and is able to manipulate its contents.  * processedBytes passes the number of bytes, which the application has  * successfully read and processed (e.g. when the application has copied  * outgoing synchronization data from the workspace into a communication module).  * SyncML removes the given number of bytes from the workspace! * * IN:        InstanceID_t               *            ID of the Instance * * IN:        MemSize_t               *            Actually read and processed bytes * * RETURN:    Return value,             *            SML_ERR_OK if successful */SML_API Ret_t smlUnlockReadBuffer(InstanceID_t id, MemSize_t processedBytes){  #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->readLocked)      return SML_ERR_WRONG_USAGE;    // advance read pointer by number of bytes processed    if (pInstanceInfo->readPointer+processedBytes>pInstanceInfo->writePointer)      return SML_ERR_WRONG_USAGE; // too many bytes processed    // update read pointer    pInstanceInfo->readPointer+=processedBytes;    // auto-reset pointers if we have now read everything    if (pInstanceInfo->readPointer ==  pInstanceInfo->writePointer) {      // clear the buffer      mgrResetWorkspace(pInstanceInfo);    }    // unlock    pInstanceInfo->readLocked=0;  #else    Ret_t rc;        /* --- Pass the number of bytes which have been read --- */    LOCKTOOLKIT("smlUnlockReadBuffer");    rc = wsmProcessedBytes (id,processedBytes);    RELEASETOOLKIT("smlUnlockReadBuffer");    if (rc!=SML_ERR_OK) return rc;    /* --- Unlock Workspace --- */    LOCKTOOLKIT("smlUnlockReadBuffer");    rc = wsmUnlockH(id);    RELEASETOOLKIT("smlUnlockReadBuffer");    if (rc!=SML_ERR_OK) return rc;  #endif  return SML_ERR_OK;}#ifdef NOWSM/** * FUNCTION:  smlSetMaxOutgoingSize * * 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 * * IN:        MemSize_t               *            maximum size of outgoing message (0=no limit except buffer size) * * RETURN:    Return value,             *            SML_ERR_OK if successful */SML_API Ret_t smlSetMaxOutgoingSize(InstanceID_t id, MemSize_t maxOutgoingSize){  InstanceInfoPtr_t	pInstanceInfo;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -