Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 11.0.1 (中文) » MobiLink - 服务器启动的同步 » 用于 Palm 设备的 MobiLink 监听器 C API

 

PalmLsnSpecialLaunch 方法

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

语法
Err PalmLsnSpecialLaunch(
    UInt16   cmd,
    MemPtr   cmdPBP,
    UInt16  launchFlags
)
参数
  • cmd   Palm OS 应用程序启动代码。

  • cmdPBP   指向包含启动代码参数的结构的指针。如果应用程序不具有任何启动命令特有的参数,该值为 NULL。

  • launchFlags   指示应用程序状态信息的标志。

返回值

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

注释

此方法响应未定义为 sysAppLaunchCmdNormalLaunch 的设备相关的或标准的启动代码。

示例

以下示例(用于 Treo 650 smartphone 实现)使用 PalmLsnSpecialLaunch 处理监听器事件:

Err PalmLsnSpecialLaunch( UInt16 cmd, MemPtr cmdPBP, UInt16 /*launchFlags*/ ) {
    switch(cmd) {
        case sysAppLaunchCmdSystemReset:
            // Fall through
        case sysAppLaunchCmdSyncNotify:
            // Fall through
        case phnLibLaunchCmdRegister:
            return registerListener();
        case phnLibLaunchCmdEvent: {
            if (!IsFeatureOn(PalmLsnGetFeature(), Listening)) {
                return(errNone);
            }
            PhnEventPtr phoneEventP = (PhnEventPtr) cmdPBP;
            if (phoneEventP->eventType == phnEvtMessageInd) {
                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);
}