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

📄 syncbmr.c

📁 SyncML手册及其编程
💻 C
📖 第 1 页 / 共 2 页
字号:
   MemPtrSetOwner( docP, 0 );   docP->cbLength = exgSocketP->length;   STR_COPY( docP->docName,  exgSocketP->name );   STR_COPY( docP->mimeType, exgSocketP->description );   if ( exgSocketP->length )      bufferSize = exgSocketP->length;  // if set, assume it's the max size   else      bufferSize = ChunkSize;           // allocate in pre-deteremined chunks   // could use data size from header if available   dataH = MemHandleNew( bufferSize );   ErrFatalDisplayIf( !dataH, "memory allocation" );   // This block needs to belong to the system since it could be disposed when apps switch   MemHandleSetOwner( dataH, 0 );   // accept will open a progress dialog and wait for your receive commands   error = ExgAccept( exgSocketP );   if ( !error ) {      dataP = MemHandleLock( dataH );      do {         bytesReceived = ExgReceive( exgSocketP, &dataP[ dataSize ], bufferSize - dataSize, &error );         if ( ( bytesReceived > 0 ) && !error ) {            dataSize += bytesReceived;            // resize block when we reach the limit of this one...            if ( dataSize >= bufferSize ) {  // Note: dataSize > bufferSize is an error!               MemHandleUnlock( dataH );               error = MemHandleResize( dataH, bufferSize + ChunkSize );               dataP = MemHandleLock( dataH );               if ( !error ) bufferSize += ChunkSize;            } // end if         } // end if      } while ( !error && ( bytesReceived > 0 ) );     // reading 0 bytes means EOF      MemHandleUnlock( dataH );      error = MemHandleResize( dataH, dataSize + 1 );  // shrink data buffer, if needed      ExgDisconnect( exgSocketP, error );              // closes transfer dialog      docP->cbLength = dataSize;                       // update length field with bytes received   } // end if   if ( error ) {      // MHB: Handle error case      ErrFatalDisplayIf( true, "SyncBmr Error..." );   } // end else   newEvent.eType = firstUserEvent;        // fire off a user event   eventDataP = (SyncBmrEventData_t *)&newEvent.data;  // pointer to event data area   eventDataP->dataH = dataH;              // save handle to document body   eventDataP->docP  = docP;               // save pointer to document info   EvtAddEventToQueue( &newEvent );        // add to event queue to signal end of processing   return error;} // ReceiveData()/*********************************************************************** *                                                                     * * FUNCTION:     AppHandleEvent                                        * *                                                                     * * DESCRIPTION:  Handles processing of events for the application.     * *                                                                     * * PARAMETERS:   event   - the most recent event.                      * *                                                                     * * RETURNED:     True if the event is handled, false otherwise.        * *                                                                     * ***********************************************************************/static Boolean AppHandleEvent( EventPtr eventP ) {   Boolean handled = false;   VoidHand dataH;   char    *dataP;   EventType newEvent;   SyncBmrData_t      *syncP;   SyncBmrResponse_t  *respP;   SyncBmrEventData_t *eventDataP;   XptCommunicationInfo_t *docP;   switch ( eventP->eType ) {      case firstUserEvent:         eventDataP = (SyncBmrEventData_t *)&eventP->data;    // pointer to event data area         dataH = (VoidHand)eventDataP->dataH;                  // get handle to document body         docP  = (XptCommunicationInfo_t *)eventDataP->docP;  // get pointer to document info         if ( dataH && docP ) {            // Create a response object            respP = (SyncBmrResponse_t *)MEM_ALLOC( sizeof( SyncBmrResponse_t ) );            ErrFatalDisplayIf( !respP, "memory allocation" );            MemPtrSetOwner( respP, 0 );            // Create a buffer to contain document body            respP->data = (void *)MEM_ALLOC( MemHandleSize( dataH ) );            ErrFatalDisplayIf( !respP->data, "memory allocation" );            MemPtrSetOwner( respP->data, 0 );            // Copy document body to response block            dataP = MemHandleLock( dataH );            MEM_COPY( respP->data, dataP, MemHandleSize( dataH ) );            respP->length = docP->cbLength;            STR_COPY( respP->name, docP->docName );            STR_COPY( respP->type, docP->mimeType );            MemHandleUnlock( dataH );  // unlock the storage first ...            MemHandleFree( dataH );    // ... then get rid of it            MEM_FREE( docP );          // Get rid of temporary doc info            syncP = (SyncBmrData_t *)globalDataP;  // retrieve the sync block from global storage            syncP->responseP = respP;               // point to the new response block         } // end if         else {            // MHB: Handle error case            ErrFatalDisplayIf( true, "SyncBmr Error..." );         } // end else         newEvent.eType = appStopEvent;    // tell the app it's time to exit         EvtAddEventToQueue( &newEvent );  // add to event queue to signal end of processing         handled = true;         break;      default:         break;   } // end switch   return handled;} // AppHandleEvent()/*********************************************************************** *                                                                     * * FUNCTION:     AppEventLoop                                          * *                                                                     * * DESCRIPTION:  A simple loop that obtains events from the Event      * *               Manager and passes them on to various applications    * *               and system event handlers before passing them on to   * *               FrmHandleEvent for default processing.                * *                                                                     * * PARAMETERS:   None.                                                 * *                                                                     * * RETURNED:     Nothing.                                              * *                                                                     * ***********************************************************************/static void AppEventLoop( void ) {   EventType event;   Word      error;   do {      // Get the next available event.      EvtGetEvent( &event, evtWaitForever );      // Give the system a chance to handle the event.      if ( !SysHandleEvent( &event ) )         // Give the menu a chance to handle the event         if ( !MenuHandleEvent( 0, &event, &error ) )            // Give the application a chance to handle the event.            if ( !AppHandleEvent( &event ) )               // Let the form object provide default handling of the event.               FrmHandleEvent( FrmGetActiveForm(), &event );   } while ( event.eType != appStopEvent );} // AppEventLoop()/*********************************************************************** *                                                                     * * FUNCTION:        PilotMain                                          * *                                                                     * * DESCRIPTION: This function is the equivalent of a main() function   * *              in standard "C". It is called by the Emulator to begin * *              execution of this application.                         * *                                                                     * * PARAMETERS:  cmd         - cmd specifying how to launch the app.    * *              cmdPBP      - parameter block for the command.         * *              launchFlags - flags used to configure the launch.      * *                                                                     * * RETURNED:    Any applicable error code.                             * *                                                                     * ***********************************************************************/DWord PilotMain( Word cmd, Ptr cmdPBP, Word launchFlags ) {   Err error = 0;   // This app makes use of PalmOS 3.0 features.  It will crash if   // run on an earlier version of PalmOS.  Detect and warn if   // this happens, then exit.   error = RomVersionCompatible( Version30, launchFlags );   if ( !error ) {      if ( cmd == sysAppLaunchCmdNormalLaunch ) {         FrmAlert( ErrorAlert );//       StartApplication();//       AppEventLoop();//       StopApplication();      } // end if      else if ( cmd == sysAppLaunchCmdSyncNotify ) {         // register our extension on syncNotify so we do         // not need to be run before we can receive data.         ExgRegisterData( SYNC_BMR_ID, exgRegExtensionID, NULL );      } // end else if      else if ( cmd == sysAppLaunchCmdExgAskUser ) {         ((ExgAskParamPtr)cmdPBP)->result = exgAskOk;      } // end else if      else if ( cmd == sysAppLaunchCmdExgReceiveData ) {         // MHB: Handle spurious data conditions...         error = ReceiveData( (ExgSocketPtr)cmdPBP );      } // end else if      else if ( cmd == sysAppLaunchSyncBmrSend ) {         SyncBmrData_t *dataP = (SyncBmrData_t *)cmdPBP;         StartApplication();         error = SyncBmrSendData( dataP );         if ( !error ) {            if ( dataP->waitForResponse ) {               globalDataP   = dataP;  // save until response received               globalWaiting = true;   // indicate waiting for response               AppEventLoop();         // wait until response received               globalWaiting = false;  // no longer waiting for response            } // end if            else {               // MHB: Anything need to be done here?            } // end else         } // end if         else {            if ( dataP->waitForResponse ) {               // MHB: Anything need to be done here?            } // end if            else {               // MHB: Anything need to be done here?            } // end else         } // end else         StopApplication();      } // end else if      else if ( cmd == sysAppLaunchSyncBmrReceive ) {         SyncBmrData_t *dataP = (SyncBmrData_t *)cmdPBP;         StartApplication();         error = SyncBmrReceiveData( dataP );         StopApplication();      } // end else if   } // end if   return error;} // end PilotMain()

⌨️ 快捷键说明

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