pubsub: Using the Publish and Subscribe IPC Mechanism

This example demonstrates the Publish and Subscribe IPC mechanisms using the RProperty class.

Download

Click on the following link to download the example: pubsub.zip .

Click: browse to view the example code.

Description

This example demonstrates three types of usage pattern for Publish and Subscribe:

  • Standard State Publishing

    • Publisher: The publisher defines a byte-array property and pre-allocates memory to it. It interactively updates and re-publishes the value of the property.

    • Subscriber: The subscriber gets the value of the property defined by the publisher by subscribing to it. It displays an error and stops running if it fails to get the value of the property.

  • Pure Event Distribution

    • Publisher: The publisher defines an integer property and publishes a random integer value periodically. This value has no significance to the subscriber.

    • Subscriber: The subscriber gets a notification when the publisher publishes a value. It exits when the property is deleted by the publisher.

  • Speculative Publishing

    • Publisher: The publisher does not define the property. It ignores the KErrNotFound error when it publishes the value of the property.

    • Subscriber: The subscriber defines and subscribes to the property. It ignores the KErrAlreadyExists error.

Class summary

  • RProperty - User side interface to Publish & Subscribe.

  • CActive - The core class of the active object abstraction.

Build

The Symbian build process describes how to build this example.

This example builds the following binaries in the standard location ( \epoc32\release\winscw\<build_variant> ) for Carbide.c++:

  • publishstd.exe : The publisher process for the Standard State pattern.

  • subscribestd.exe : The subscriber process for the Standard State pattern.

  • publishpe.exe : The publisher process for the Pure Event Distribution pattern.

  • subscribepe.exe : The subscriber process for the Pure Event Distribution pattern.

  • publishspec.exe : The publisher process for the Speculative Publishing pattern.

  • subscribespec.exe : The subscriber process for the Speculative Publishing pattern.

Running the example

To run the example, perform the following steps on each usage pattern:

  1. Open two eshells.

  2. Run the publisher executable file in one eshell.

  3. Run the subscriber executable file in another eshell.

Note : Switch between eshells by pressing CTRL+ALT+SHIFT+T .

See also

For more information, see Publish and Subscribe in Using User Library (E32) .