×
Namespaces

Variants
Actions
(Difference between revisions)

Archived:Using RProperty for publishing

From Nokia Developer Wiki
Jump to: navigation, search
hamishwillee (Talk | contribs)
m (Hamishwillee - Bot change of template (Template:CodeSnippet) - now using Template:ArticleMetaData)
debjit.roy (Talk | contribs)
(Debjit.roy -)
Line 1: Line 1:
 +
[[Category:Symbian C++]][[Category:Code Examples]][[Category:Files/Data]][[Category:S60 3rd Edition]][[Category:Code Snippet]]
 
__NOTOC__
 
__NOTOC__
 
__NOEDITSECTION__
 
__NOEDITSECTION__
Line 20: Line 21:
 
}}
 
}}
  
 +
{{Archived|timestamp=20120314040206|user=roy.debjit| }}
 
==Overview==
 
==Overview==
  
Line 145: Line 147:
 
==See also==
 
==See also==
 
[[CS000909 - Publish and Subscribe: Using RProperty for subscribing]]
 
[[CS000909 - Publish and Subscribe: Using RProperty for subscribing]]
 
[[Category:Symbian C++]][[Category:Code Examples]][[Category:Files/Data]]
 
[[Category:S60 3rd Edition]][[Category:Code Snippet]]
 

Revision as of 07:02, 14 March 2012

Template:KBCS

Article Metadata
Tested with
Devices(s): Nokia N93
CompatibilityPlatform Security
Capabilities: )
Article
Keywords: RProperty, RProperty::Define(), RProperty::Delete(), RProperty::Attach(), RProperty::Set(), RProperty::Close()
Created: aknyman (22 Apr 2008)
Last edited: debjit.roy (14 Mar 2012)

Archived.pngArchived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.

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 CS000909 - Publish and Subscribe: 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

CS000909 - Publish and Subscribe: Using RProperty for subscribing

130 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×