Namespaces
Variants
Actions
(Difference between revisions)

Archived:Using RProperty for publishing

Jump to: navigation, search
m (Hamishwillee - Adding missing translation link)
 
(16 intermediate revisions by 6 users not shown)
Line 1: Line 1:
__NOTOC__
+
[[Category:Symbian C++]][[Category:Files/Data]][[Category:Code Snippet]]
__NOEDITSECTION__
+
{{ArticleMetaData <!-- v1.2 -->
 
+
|sourcecode= <!-- Link to example source code (e.g. [[Media:The Code Example ZIP.zip]]) -->
{|style="background:#eceff2" width="660px" border="1" cellpadding="5" cellspacing="0"
+
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
|-
+
|devices= Nokia N93
|'''ID''' || &nbsp;
+
|sdk= <!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Nokia Qt SDK 1.1]) -->
|'''Creation date''' || April 15, 2008
+
|platform= S60 3rd Edition FP1 and later
|-
+
|devicecompatability= <!-- Compatible devices (e.g.: All* (must have GPS) ) -->
|'''Platform''' || S60 3rd Edition, FP1
+
|dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 -->
|'''Tested on devices''' || Nokia N93
+
|signing= <!-- Empty or one of Self-Signed, DevCert, Manufacturer -->
|-
+
|capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. -->
|'''Category''' || Symbian C++
+
|keywords= RProperty, RProperty::Define(), RProperty::Delete(), RProperty::Attach(), RProperty::Set(), RProperty::Close()
|'''Subcategory''' || Files/Data
+
|language= <!-- Language category code for non-English topics - e.g. Lang-Chinese -->
|}
+
|translated-by= <!-- [[User:XXXX]] -->
 
+
|translated-from-title= <!-- Title only -->
 
+
|translated-from-id= <!-- Id of translated revision -->
{|style="background:#eceff2" width="660px" border="1" cellpadding="5" cellspacing="0"
+
|review-by= <!-- After re-review: [[User:username]] -->
|-
+
|review-timestamp= <!-- After re-review: YYYYMMDD -->
|'''Keywords (APIs, classes, methods, functions):''' RProperty, RProperty::Define(), RProperty::Delete(), RProperty::Attach(), RProperty::Set(), RProperty::Close()
+
|update-by= <!-- After significant update: [[User:username]]-->
|}
+
|update-timestamp= <!-- After significant update: YYYYMMDD -->
 +
|creationdate= 20080415
 +
|author= [[User:Aknyman]]
 +
<!-- The following are not in current metadata -->
 +
|id= CS000908
 +
}}
  
 
==Overview==
 
==Overview==
  
This snippet shows how the class RProperty can be used to publish user defined properties with Symbian's IPC Publish and Subscribe mechanism.
+
{{Abstract|This code snippet shows how the class RProperty can be used to publish user-defined properties with Symbian's IPC Publish and Subscribe mechanism.}}
  
A property is published using the RProperty::Set() function. This means that the value of property is updated. Whenever a property is published, all outstanding subscriptions are completed.
+
A property is published using the {{Icode|RProperty::Set()}} function. This means that the value of the property is updated. Whenever a property is published, all outstanding subscriptions are completed.
  
There is also an another snippet "Publish and Subscribe: Using RProperty for subscribing" to subscribe these user defined properties. The property definitions are shared between a publisher and a subscriber through the common header file ExampleProperties.h
+
The code snippet [[Archived:Using RProperty for subscribing]] shows how to subscribe these user-defined properties. The property definitions are shared between a publisher and a subscriber through the common header file {{Icode|ExampleProperties.h}}.
  
 
<code cpp>
 
<code cpp>
Line 46: Line 51:
  
 
<code>
 
<code>
LIBRARY euser.lib
+
LIBRARY euser.lib
 
</code>
 
</code>
  
 
==Preconditions==
 
==Preconditions==
  
The publisher or the subscriber thread can be the one to define properties, by calling RProperty::Define(). The user defined properties persist in the kernel until the operating system reboots or the properties are deleted.
+
The publisher or the subscriber thread can be the one to define properties by calling {{Icode|RProperty::Define()}}. The user-defined properties persist in the kernel until the operating system reboots or the properties are deleted.
  
 
<code cpp>
 
<code cpp>
Line 124: Line 129:
 
Two example properties are published using the class RProperty.
 
Two example properties are published using the class RProperty.
  
If the publisher thread was the one that defined properties it is also capable of deleting properties by using the RProperty::Delete(), as follows:
+
If the publisher thread has defined the properties, it is also capable of deleting properties by using {{Icode|RProperty::Delete()}} as follows:
  
 
<code cpp>
 
<code cpp>
Line 144: Line 149:
  
 
==See also==
 
==See also==
[[Publish and Subscribe: Using RProperty for subscribing]]
+
[[Using RProperty for subscribing]]
  
[[Category:Symbian C++]][[Category:Code Examples]][[Category:Files/Data]]
+
{{VersionHint}}
 +
[[Category:S60 3rd Edition FP1]] [[Category:S60 3rd Edition FP2]]
 +
[[Category:S60 5th Edition]]
 +
[[Category:Symbian^3]] [[Category:Symbian Anna]] [[Category:Nokia Belle]]
 +
<!-- Translation --> [[zh-hans:Publish及Subscribe:使用RProperty进行publish操作]]

Latest revision as of 08:58, 18 September 2012

Article Metadata

Tested with
Devices(s): Nokia N93

Compatibility
Platform(s): S60 3rd Edition FP1 and later

Article
Keywords: RProperty, RProperty::Define(), RProperty::Delete(), RProperty::Attach(), RProperty::Set(), RProperty::Close()
Created: aknyman (15 Apr 2008)
Last edited: hamishwillee (18 Sep 2012)

Contents

Overview

This code snippet shows how the class RProperty can be used to publish user-defined properties with Symbian's IPC Publish and Subscribe mechanism.

A property is published using the RProperty::Set() function. This means that the value of the property is updated. Whenever a property is published, all outstanding subscriptions are completed.

The code snippet Archived:Using RProperty for subscribing shows how to subscribe these user-defined properties. The property definitions are shared between a publisher and a subscriber through the common header file ExampleProperties.h.

#ifndef EXAMPLEPROPERTIES_H_
#define EXAMPLEPROPERTIES_H_
 
const TInt KMaxStrLen = 10;
const TUid KExampleProperty = {0xED1917A8};
enum TExamplePropertyKeys { EIntProperty, EStrProperty };
 
#endif /*EXAMPLEPROPERTIES_H_*/

This snippet can be self-signed.

MMP file

The following libraries are required:

LIBRARY euser.lib

Preconditions

The publisher or the subscriber thread can be the one to define properties by calling RProperty::Define(). The user-defined properties persist in the kernel until the operating system reboots or the properties are deleted.

TInt ret=RProperty::Define(KExampleProperty,EIntProperty,RProperty::EInt);
if (ret != KErrAlreadyExists)
{
User::LeaveIfError(ret);
}
 
ret= RProperty::Define(KExampleProperty,EStrProperty,RProperty::EByteArray,KMaxStrLen);
if (ret != KErrAlreadyExists)
{
User::LeaveIfError(ret);
}


Source file

#include <e32base.h>
#include <e32property.h>
 
#include "exampleproperties.h"
 
LOCAL_C void SetExamplePropertiesL()
{
TInt err(KErrNone);
 
// Use handle to publish EIntProperty
RProperty intProperty;
err = intProperty.Attach(KExampleProperty, EIntProperty, EOwnerThread);
User::LeaveIfError(err);
err = intProperty.Set(123);
User::LeaveIfError(err);
intProperty.Close();
 
// Use category and key to publish EStrProperty
err=RProperty::Set(KExampleProperty,EStrProperty,_L("321"));
User::LeaveIfError(err);
}
 
// Global Functions
GLDEF_C TInt E32Main()
{
// Create cleanup stack
__UHEAP_MARK;
CTrapCleanup* cleanup = CTrapCleanup::New();
 
// Run application code inside TRAP harness
TRAPD(mainError, SetExamplePropertiesL());
if (mainError)
{
//SetExamplePropertiesL leaves...
}
else
{
//Properties updated ok
}
delete cleanup;
__UHEAP_MARKEND;
return KErrNone;
}

Postconditions

Two example properties are published using the class RProperty.

If the publisher thread has defined the properties, it is also capable of deleting properties by using RProperty::Delete() as follows:

TInt err(KErrNone);
 
err = RProperty::Delete(KExampleProperty,EIntProperty);
if (err != KErrNotFound)
{
User::LeaveIfError(err);
}
err = RProperty::Delete(KExampleProperty,EStrProperty);
if (err != KErrNotFound)
{
User::LeaveIfError(err);
}

When properties are deleted, any outstanding subscriptions will be completed with KErrNotFound.

See also

Using RProperty for subscribing

This page was last modified on 18 September 2012, at 08:58.
276 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved