Collection Contents 上一页 下一页 PDF

MobiLink 服务器启动同步用户指南

MobiLink 监听器 SDK

Palm 监听器 SDK

设备相关函数

PalmLsnSpecialLaunch

功能 

响应可能与设备相关的启动代码。

原型 

Err PalmLsnSpecialLaunch(
    UInt16       cmd,
    MemPtr       cmdPBP,
    UInt16      launchFlags
)

参数 
返回值 

Palm OS 错误代码。errNone 表示操作成功。

注释 

该函数响应未定义为 sysAppLaunchCmdNormalLaunch 的设备相关的或标准的启动代码。

示例 

下面的示例(用于 Treo 600 smartphone 实现)使用 PalmLsnSpecialLaunch 处理监听器事件。

Err PalmLsnSpecialLaunch( 
/***********************/
    UInt16 cmd,
    MemPtr cmdPBP,
    UInt16 /*launchFlags*/ )
{
switch( cmd ) {

  case sysAppLaunchCmdSystemReset: 
    // Fall through
  case phnLibLaunchCmdRegister:
   break;
case phnLibLaunchCmdEvent: {
   if( !IsFeatureOn( PalmLsnGetFeature(), Listening ) ) {
      return( errNone );
   }
 PhnEventPtr phoneEventP = (PhnEventPtr)cmdPBP;
 if( phoneEventP->eventType == phnEvtMessageInd ) {
      // handle the message
      return( handleMessage( phoneEventP->data.params.id, &phoneEventP->acknowledge ) );
    }
  }
 default:
   break;
}
return( errNone );
}

如果检测到消息,则使用 handleMessage 以相应的操作处理消息。

static Err handleMessage( PhnDatabaseID id, Boolean * handled )
/*************************************************************/
// This routine will construct a_palm_msg and then call
// PalmLsnProcess to process it.
{
 
  a_palm_msg *     ulMsg;
  Err              ret;
  Boolean          newlyLoaded;
  PhnAddressList   addrList;
  PhnAddressHandle addrH;
  MemHandle        msgBodyH;
  Char *           msgSender;
  Char *           msgBody;
  UInt32           msgTime;
  Char             configDb[ dmDBNameLength ];
  UInt16           libRef   = 0;
  // CDMA workaround recommended by Handspring
  DmOpenRef        openRef   = 0;
  *handled = false;
  // Allocate a message structure for passing over
  // to PalmLsnProcess later
    
  ulMsg = PalmLsnAllocate();
  if( ulMsg == NULL ) {
    return( sysErrNoFreeRAM );
   }
  // Load the phone library
   
  ret = findOrLoadPhoneLibrary( &libRef, &newlyLoaded );
  if( ret != errNone ) {
   goto done;
  }
  openRef = PhnLibGetDBRef( libRef );
  // Retrieve sender of the message
    
  ret = PhnLibGetAddresses( libRef, id, &addrList );
  if( ret != errNone ) {
      goto done;
  }
  ret = PhnLibGetNth( libRef, addrList, 1, &addrH );
 if( ret != errNone ) {
    PhnLibDisposeAddressList( libRef, addrList );
    goto done;
  }
 
  msgSender = PhnLibGetField( libRef, addrH, phnAddrFldPhone );
  if( msgSender != NULL ) {
    ret = PalmLsnDupSender( ulMsg, msgSender );
    MemPtrFree( msgSender );
  }
  PhnLibDisposeAddressList( libRef, addrList );
  if( ret != errNone ) {
    goto done;
  }
 
  // Retrieve message time
    
  ret = PhnLibGetDate( libRef, id, &msgTime );
  if( ret != errNone ) {
   goto done;
  }
  ret = PalmLsnDupTime( ulMsg, msgTime );
  if( ret != errNone ) {
    goto done;
  }    
  // Retrieve the entire message body
    
  ret = PhnLibGetText( libRef, id, &msgBodyH );
  if( ret != errNone ) {
      goto done;      }
  msgBody = (Char *)MemHandleLock( msgBodyH );
  ret = PalmLsnDupMessage( ulMsg, msgBody );
 
  // msgBodyH must be disposed of by the caller
    
  MemHandleUnlock( msgBodyH );
  MemHandleFree( msgBodyH );
  if( ret != errNone ) {
    goto done;
  }
  // Get the configuration database name
    
  PalmLsnGetConfigFileName( configDb );
  // Call PalmLsnProcess to process the message
    
  ret = PalmLsnProcess( ulMsg, configDb, NULL, handled );
done:
  if( ulMsg != NULL ) {
    PalmLsnFree( ulMsg );
  }
  PhnLibReleaseDBRef( libRef, openRef );
  // Unload the phone library before any possible application switch
    
  if( newlyLoaded ) {
    unloadPhoneLibrary( libRef );
    newlyLoaded = false;
  }
  return( ret );
}

Collection Contents 上一页 下一页 PDF