EventHelix.com: CASE Tools; Real-time and Embedded System Design; Object Oriented Design EventStudio 2.0: System Engineering CASE ToolEventStudio 2.5
Sequence diagram based system design and modeling
Home   What's New   EventStudio 2.5   Real-time Mantra   Thought Projects   Contact Us
Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

LocalStatusPublisher Class Reference

#include <Local_Status_Publisher.h>

Collaboration diagram for LocalStatusPublisher:

Collaboration graph
[legend]
List of all members.

Detailed Description

Publish subscriber pattern when the publisher and subscriber are objects in the same thread or task.

While developing embedded system, one frequently encounters a situation where many entities are interested in occurrence of a particular event. This introduces a strong coupling between the publisher and subscriber of this event change notification. Thus whenever a new entity needs the information, code for the publisher of the information also needs to be modified to accommodate the new request.

The Publish-Subscribe Pattern solves the tight coupling problem. Here the coupling is removed by the publisher of information supporting a generic interface for subscribers. Entities interested in the information subscribe to the publisher by registering for the information. With this interface, the publisher code does not need to be modified every time a subscriber is introduced.

This class can be used as a helper class when this generic subscribe-publish interface is desired. The following important public methods are supported:

See also:
Publish Subscribe Design Pattern

RemoteStatusPublisher

Definition at line 34 of file Local_Status_Publisher.h.

Public Types

enum  OperationStatus
 Status of an operation.


Public Member Functions

void PublishStatus (int unitId, int status)
 PublishStatus() notifies subscribers about status change.

OperationStatus Register (Subscriber *pSubscriber)
 Register() is invoked by objects inheriting from Subscriber.

OperationStatus Deregister (Subscriber *pSubscriber)
 Deregister() removes a subscriber.


Private Types

enum  { NOT_FOUND = -1, MAX_SUBSCRIBERS = 100 }

Private Member Functions

int Find (Subscriber *pSubscriber) const
 This method searches for an entry that matches the pointer.


Private Attributes

Subscriberm_pSubscriber [MAX_SUBSCRIBERS]
 Subscribers being tracked by the publisher. The entire list should be scanned for non NULL subscriber pointers.


Member Enumeration Documentation

anonymous enum [private]
 

Enumeration values:
NOT_FOUND Return when an entry is not found.
MAX_SUBSCRIBERS Maximum number of subscribers.

Definition at line 36 of file Local_Status_Publisher.h.

00036          {
00038           NOT_FOUND = -1, 
00039 
00041           MAX_SUBSCRIBERS = 100
00042          };


Member Function Documentation

int LocalStatusPublisher::Find SubscriberpSubscriber  ) const [inline, private]
 

This method searches for an entry that matches the pointer.

It returns the index of the entry. If the entry is not found, it returns NOT_FOUND.

Parameters:
pSubscriber Pointer to the subscriber to be found.
See also:
Publish Subscribe Design Patterns

Definition at line 57 of file Local_Status_Publisher.h.

00058     {
00059        int index = NOT_FOUND;
00060        for (int i=0; i < MAX_SUBSCRIBERS; i++)
00061        {
00062            if (m_pSubscriber[i] == pSubscriber)
00063            {
00064                index = i;
00065                break;
00066            }
00067        }       
00068        return index;     
00069     }

void LocalStatusPublisher::PublishStatus int unitId,
int status
[inline]
 

PublishStatus() notifies subscribers about status change.

Invoke this method whenever you need to update the status to all the subscribers of the status information.

Parameters:
unitId Id of the unit that needs a status publication.
status The status that needs to be published.
See also:
Publish Subscribe Design Patterns

Definition at line 85 of file Local_Status_Publisher.h.

00086     {
00087        for (int i=0; i < MAX_SUBSCRIBERS; i++)
00088        {
00089            // A valid subscriber exists only when the pointer is non NULL
00090            if (m_pSubscriber[i])
00091            {
00092                m_pSubscriber[i]->HandleStatusChange(unitId, status);
00093            }
00094        }
00095     }

OperationStatus LocalStatusPublisher::Register SubscriberpSubscriber  ) [inline]
 

Register() is invoked by objects inheriting from Subscriber.

Once registered, the object is notified whenever status change is detected. The method returns FAILURE in the following cases:

Parameters:
pSubscriber Subscriber being registered for the service.
See also:
Publish Subscribe Design Patterns

Definition at line 108 of file Local_Status_Publisher.h.

00109     {
00110         OperationStatus status = FAILURE;
00111         // First check if the subscriber is already present
00112         // in the list
00113         int index = Find(pSubscriber);
00114                 
00115         if (index == NOT_FOUND)
00116         {
00117             // Subscriber was not found, so this is not a duplicate request
00118             // Now look for a free entry by finding NULL
00119             index = Find(NULL);
00120             if (index != NOT_FOUND)
00121             {
00122                // A free entry has been found
00123                m_pSubscriber[index] = pSubscriber;
00124                status = SUCCESS;
00125             }
00126         }      
00127         return status;
00128     }

OperationStatus LocalStatusPublisher::Deregister SubscriberpSubscriber  ) [inline]
 

Deregister() removes a subscriber.

Returns FAILURE if the subscriber was not registered in the first place.

Parameters:
pSubscriber Pointer to the subscriber that needs to be deregistered.
See also:
Publish Subscribe Design Patterns

Definition at line 138 of file Local_Status_Publisher.h.

00139     {
00140         OperationStatus status = FAILURE;
00141         // Search for the entry
00142         int index = Find(pSubscriber);
00143         if (index != NOT_FOUND)
00144         {
00145            // Free the entry by marking as NULL
00146            m_pSubscriber[index] = NULL;
00147            status = SUCCESS;
00148         }
00149         return SUCCESS;
00150     }


The documentation for this class was generated from the following file:
Generated on Sun Feb 13 21:30:33 2005 for Object Oriented Design Examples by doxygen 1.3.4
 Home   What's New   EventStudio 2.5   Real-time Mantra   Thought Projects   Contact Us
Copyright © 2000-2005 EventHelix.com Inc. All Rights Reserved.