了解RProperty IPC通信

understanding RProperty IPC communication

本文关键字:通信 IPC RProperty 了解      更新时间:2023-10-16

我正在研究这个源库。基本上,这是Symbian第三版的Anim服务器客户端,目的是在不可靠的情况下获取输入事件。

如果你看到服务器的这一行,这里基本上是在设置RProperty值(显然是递增计数器);似乎没有对输入进行实际处理。

在这个客户端行中,客户端应该接收通知数据,但它只调用Attach。

我的理解是Attach只需要调用一次,但在客户端中不清楚每次服务器设置RProperty 时会触发什么事件

客户端应该如何(以及在哪里)访问RProperty值?

Attach之后,客户端将在Subscribe的某个位置传递TRequestStatus引用。当异步事件发生时(在您的情况下,属性已更改),服务器将通过内核发出请求状态属性的信号。如果示例源代码以正确的方式实现,您将发现一个活动对象(AO;CActive派生类)挂在周围,并且该AO的iStatus将传递给RProperty API。在这种情况下,属性发生更改时,将调用AO的RunL函数。

在Symbian中,理解活动对象框架是至关重要的,而实际上很少有人这样做。不幸的是,我并没有在网上找到一个很好的描述(Symbian操作系统内部的书中对它们进行了很好的解释),但这个页面至少给了你一个快速的例子。

示例

CActive的CMyActive子类的ConstructL中:

CKeyEventsClient* iClient;
RProperty         iProperty;
// ...
void CMyActive::ConstructL() 
    {
    RProcess myProcess;
    TSecureId propertyCategory = myProcess.SecureId();
        // avoid interference with other properties by defining the category
        // as a secure ID of your process (perhaps it's the only allowed value)
    TUint propertyKey = 1; // whatever you want
    iClient = CKeyEventsClient::NewL(propertyCategory, propertyKey, ...);
    iClient->OpenNotificationPropertyL(&iProperty);
    // ...
    CActiveScheduler::Add(this);
    iProperty.Subscribe(iStatus);
    SetActive();
    }

属性更改后将调用您的RunL:

void CMyActive::RunL()
    {
    if (iStatus.Int() != KErrCancel) User::LeaveIfError(iStatus.Int());
         // forward the error to RunError
    // "To ensure that the subscriber does not miss updates, it should
    // re-issue a subscription request before retrieving the current value 
    // and acting on it." (from docs)
    iProperty.Subscribe(iStatus);
    TInt value; // this type is passed to RProperty::Define() in the client
    TInt err = iProperty.Get(value);
    if (err != KErrNotFound) User::LeaveIfError(err);
    SetActive();
    }