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

📄 syncbmr.c

📁 SyncML ToolKits,学习syncml的参考工具包.非常好用.
💻 C
📖 第 1 页 / 共 2 页
字号:
/*************************************************************************//* module:                                                               *//* file:                                                                 *//* target system:   Palm                                                 *//* target OS:       PalmOS 3.0                                           *//*************************************************************************//* * Copyright Notice * Copyright (c) Ericsson, IBM, Lotus, Matsushita Communication  * Industrial Co., Ltd., Motorola, Nokia, Openwave Systems, Inc.,  * Palm, Inc., Psion, Starfish Software, Symbian, Ltd. (2001). * All Rights Reserved. * Implementation of all or part of any Specification may require  * licenses under third party intellectual property rights,  * including without limitation, patent rights (such a third party  * may or may not be a Supporter). The Sponsors of the Specification  * are not responsible and shall not be held responsible in any  * manner for identifying or failing to identify any or all such  * third party intellectual property rights. *  * THIS DOCUMENT AND THE INFORMATION CONTAINED HEREIN ARE PROVIDED  * ON AN "AS IS" BASIS WITHOUT WARRANTY OF ANY KIND AND ERICSSON, IBM,  * LOTUS, MATSUSHITA COMMUNICATION INDUSTRIAL CO. LTD, MOTOROLA,  * NOKIA, PALM INC., PSION, STARFISH SOFTWARE AND ALL OTHER SYNCML  * SPONSORS DISCLAIM ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING  * BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION  * HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF  * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT  * SHALL ERICSSON, IBM, LOTUS, MATSUSHITA COMMUNICATION INDUSTRIAL CO.,  * LTD, MOTOROLA, NOKIA, PALM INC., PSION, STARFISH SOFTWARE OR ANY  * OTHER SYNCML SPONSOR BE LIABLE TO ANY PARTY FOR ANY LOSS OF  * PROFITS, LOSS OF BUSINESS, LOSS OF USE OF DATA, INTERRUPTION OF  * BUSINESS, OR FOR DIRECT, INDIRECT, SPECIAL OR EXEMPLARY, INCIDENTAL,  * PUNITIVE OR CONSEQUENTIAL DAMAGES OF ANY KIND IN CONNECTION WITH  * THIS DOCUMENT OR THE INFORMATION CONTAINED HEREIN, EVEN IF ADVISED  * OF THE POSSIBILITY OF SUCH LOSS OR DAMAGE. *  * The above notice and this paragraph must be included on all copies  * of this document that are made. *  */#include "syncml_tk_prefix_file.h" // %%% luz: needed for precompiled headers in eVC++#ifdef USE_SDK_35   #include <PalmOS.h>#else   #include <Pilot.h>#endif#include <sys_types.h>          /* For size_t */#include <ExgMgr.h>#include <StringMgr.h>#include <SysEvtMgr.h>#include "SyncBmr.h"#include "obexbinding.h"/*********************************************************************** *                                                                     * *   Internal Constants                                                * *                                                                     * ***********************************************************************/#define Version30  0x03000000   // PalmOS 3.0 required to run SyncBmr#define ChunkSize  128          // default block size for Receive/*********************************************************************** *                                                                     * *   Global Variables                                                  * *                                                                     * ***********************************************************************/Boolean globalWaiting = false;void   *globalDataP   = NULL;char globalTest[] = "Testing...";/*********************************************************************** *                                                                     * * FUNCTION:    RomVersionCompatible                                   * *                                                                     * * DESCRIPTION: Check that the ROM version meets your minimum          * *              requirement.  Warn if the app was switched to.         * *                                                                     * * PARAMETERS:  requiredVersion - minimum rom version required         * *                                (see sysFtrNumROMVersion in          * *                                SystemMgr.h for format)              * *              launchFlags - flags indicating how the application     * *                            was launched.  A warning is displayed    * *                            only if these flags indicate that the    * *                            app is launched normally.                * *                                                                     * * RETURNED:    zero if rom is compatible else an error code           * *                                                                     * ***********************************************************************/static Err RomVersionCompatible( DWord requiredVersion, Word launchFlags ) {   DWord romVersion;   // See if we're on in minimum required version of the ROM or later.   // The system records the version number in a feature.  A feature is a   // piece of information which can be looked up by a creator and feature   // number.   FtrGet( sysFtrCreator, sysFtrNumROMVersion, &romVersion );   if ( romVersion < requiredVersion ) {      // If the user launched the app from the launcher, explain      // why the app shouldn't run.  If the app was contacted for something      // else, like it was asked to find a string by the system find, then      // don't bother the user with a warning dialog.  These flags tell how      // the app was launched to decided if a warning should be displayed.      if ( ( launchFlags & ( sysAppLaunchFlagNewGlobals | sysAppLaunchFlagUIApp ) ) ==           ( sysAppLaunchFlagNewGlobals | sysAppLaunchFlagUIApp ) ) {         /************************************/         /***** Notify ROM Incompatible! *****/         /************************************/         // Pilot 1.0 will continuously relaunch this app unless we switch to         // another safe one.  The sysFileCDefaultApp is considered "safe".         if ( romVersion < 0x02000000 )            AppLaunchWithCommand( sysFileCDefaultApp, sysAppLaunchCmdNormalLaunch, NULL );      } // end if      return( sysErrRomIncompatible );   } // end if   return 0;} // RomVersionCompatible()/*********************************************************************** *                                                                     * * FUNCTION:     StartApplication                                      * *                                                                     * * DESCRIPTION:  Set up the initial state of the application.          * *                                                                     * * PARAMETERS:   None.                                                 * *                                                                     * * RETURNED:     Error Code.  Zero indicates no error.                 * *                                                                     * ***********************************************************************/static Err StartApplication( void ) {   globalWaiting = false;   globalDataP   = NULL;// ExgRegisterData( SYNC_BMR_ID, exgRegExtensionID, NULL );   return 0;} // StartApplication()/*********************************************************************** *                                                                     * * FUNCTION:     StopApplication                                       * *                                                                     * * DESCRIPTION:                                                        * *                                                                     * * PARAMETERS:   None.                                                 * *                                                                     * * RETURNED:     Error Code.  Zero indicates no error.                 * *                                                                     * ***********************************************************************/static Err StopApplication( void ) {   globalWaiting = false;   globalDataP   = NULL;// ExgRegisterData( SYNC_BMR_ID, exgRegExtensionID, NULL );   return 0;} // StopApplication()/*********************************************************************** *                                                                     * * FUNCTION:                                                           * *                                                                     * * DESCRIPTION:                                                        * *                                                                     * * PARAMETERS:                                                         * *                                                                     * * RETURNED:                                                           * *                                                                     * ***********************************************************************/static Err SyncBmrSendData( SyncBmrData_t *dataP ) {   ExgSocketType exgSocket;   SyncBmrRequest_t *reqP;   unsigned long bytesSent = 0;   Err errPut = 0, errSend = 0, errDisc = 0, errApp = 0;   if ( !dataP ) return SyncBmrErrorDataPtr;   reqP = dataP->requestP;   if ( !reqP ) return SyncBmrErrorRequestPtr;   // Important to init structure to zeros...   MemSet( &exgSocket, sizeof( exgSocket ), 0 );   exgSocket.target      = SYNC_BMR_ID;   exgSocket.name        = reqP->name;   exgSocket.description = reqP->type;   exgSocket.type        = reqP->type;   exgSocket.length      = reqP->length;   errPut = ExgPut( &exgSocket );   // put data to destination   if ( !errPut ) {      bytesSent = ExgSend( &exgSocket, reqP->data, reqP->length, &errSend );      errDisc   = ExgDisconnect( &exgSocket, errApp );   } // end if   return( errPut + errSend + errDisc + errApp ) ? SyncBmrErrorExgMgr : 0;} // SyncBmrSendData()/*********************************************************************** *                                                                     * * FUNCTION:                                                           * *                                                                     * * DESCRIPTION:                                                        * *                                                                     * * PARAMETERS:                                                         * *                                                                     * * RETURNED:                                                           * *                                                                     * ***********************************************************************/static Err SyncBmrReceiveData( SyncBmrData_t *dataP ) {   globalDataP   = dataP;  // save until response received   globalWaiting = true;   // indicate waiting for response   AppEventLoop();         // wait until response received   globalWaiting = false;  // indicate waiting for response   return 0;} // SyncBmrSendResponse()/*********************************************************************** *                                                                     * * FUNCTION:     ReceiveData                                           * *                                                                     * * DESCRIPTION:  Receives data using the Exg API                       * *                                                                     * * PARAMETERS:   exgSocketP, socket from the app code                  * *                           sysAppLaunchCmdExgReceiveData             * *                                                                     * * RETURNED:     error code or zero for no error.                      * *                                                                     * ***********************************************************************/static Err ReceiveData( ExgSocketPtr exgSocketP ) {   EventType newEvent;   VoidHand dataH;   char    *dataP;   XptCommunicationInfo_t *docP;   SyncBmrEventData_t     *eventDataP;   unsigned long dataSize      = 0;   unsigned long bufferSize    = 0;   unsigned long bytesReceived = 0;   Err error = 0;   docP = (XptCommunicationInfo_t *)MEM_ALLOC( sizeof( XptCommunicationInfo_t ) );   ErrFatalDisplayIf( !docP, "memory allocation" );   // This block needs to belong to the system since it could be disposed when apps switch

⌨️ 快捷键说明

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