在Attach
之後,客戶將在某處Subscribe
到達其通過TRequestStatus
參考的屬性。當異步事件發生時,服務器將通過內核通知內核的請求狀態屬性(在您的情況下屬性發生變化)。如果您的示例源代碼以正確的方式實現,您會發現掛起的活動對象(AO; CActive
派生類),此AO的iStatus
將傳遞給RProperty API。在這種情況下,AO屬性的RunL
函數將在屬性更改時調用。
在Symbian中,瞭解活動對象框架是非常重要的,而且實際上很少有人這樣做。不幸的是,我沒有在網上找到很好的描述(他們在Symbian OS Internals書中解釋得很好),但至少可以給你一個快速的例子。
例
在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();
}
是啊,在這源項目訂閱沒有被調用到任何地方,所以它看起來不起作用。謝謝你的例子,看看那裏,看看他們是否可以幫助我訪問屬性值。所以你認爲在那個實現(除了訂閱)中缺少什麼能夠通過RProperty接收通信? – lurscher 2012-03-22 16:29:01
我添加了一些草案示例。 – MrTJ 2012-03-22 17:15:33
現在我發現你必須爲你的DLL提供ProtServ功能。如果您計劃一旦發佈軟件,諾基亞可能會有一些問題,您爲什麼需要它... http://www.developer.nokia.com/Community/Wiki/Capabilities_%28Symbian_Signed%29/ProtServ_Capability – MrTJ 2012-03-22 17:20:52