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

RemoteStatusPublisher Class Reference

#include <Remote_Status_Publisher.h>

List of all members.


Detailed Description

Publish subscriber pattern when the publisher and subscriber are on different processors and can communicate only via messages.

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 Patterns

LocalStatusPublisher

Definition at line 63 of file Remote_Status_Publisher.h.

Public Member Functions

void PublishStatus (int unitId, int unitStatus)
 PublishStatus() notifies subscribers about status change by sending a message.

void HandleRegisterRequest (const RegisterRequestMessage *pMsg)
 This method handles the registration request message from remote entities.

void HandleDeregisterRequest (const DeregisterRequestMessage *pMsg)
 This method handles the deregistration request and responds back with the status.


Private Types

enum  { FREE_ENTRY = 0, NOT_FOUND = -1, MAX_SUBSCRIBERS = 100 }

Private Member Functions

int Find (SubscriberAddress subscriberAddress) const
 Find() searches for an entry that matches the subscriber Address.

void SendRequestStatus (SubscriberAddress subscriberAddress, AckType ackType, OperationStatus registrationStatus)
 Send a response to the registration or deregistration request.

void SendStatusChange (SubscriberAddress subscriberAddress, int unitId, int unitStatus)
 Inform the subscribed units about status change.


Private Attributes

SubscriberAddress m_subscriberAddress [MAX_SUBSCRIBERS]
 Array to keep track of the subscribers.


Member Enumeration Documentation

anonymous enum [private]
 

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

Definition at line 65 of file Remote_Status_Publisher.h.

00065          {
00066 
00068         FREE_ENTRY = 0,
00069 
00071         NOT_FOUND = -1, 
00072 
00074         MAX_SUBSCRIBERS = 100
00075     };


Member Function Documentation

int RemoteStatusPublisher::Find SubscriberAddress subscriberAddress  ) const [inline, private]
 

Find() searches for an entry that matches the subscriber Address.

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

Parameters:
subscriberAddress Address of the subscriber to be searched.

Definition at line 87 of file Remote_Status_Publisher.h.

00088     {
00089        int index = NOT_FOUND;
00090        for (int i=0; i < MAX_SUBSCRIBERS; i++)
00091        {
00092            if (m_subscriberAddress[i] == subscriberAddress)
00093            {
00094                index = i;
00095                break;
00096            }
00097        }       
00098        return index;     
00099     } 

void RemoteStatusPublisher::PublishStatus int unitId,
int unitStatus
[inline]
 

PublishStatus() notifies subscribers about status change by sending a message.

A message is sent to all subscribers of the status information.

Parameters:
unitId Id of the unit that has undergone a status change.
unitStatus New status value for the unitId

Definition at line 119 of file Remote_Status_Publisher.h.

00120     {
00121        for (int i=0; i < MAX_SUBSCRIBERS; i++)
00122        {
00123            // A valid subscriber exists only when the pointer is non NULL
00124            if (m_subscriberAddress[i]!= FREE_ENTRY)
00125            {
00126                SendStatusChange(m_subscriberAddress[i], unitId, unitStatus);
00127            }
00128        }
00129     }

void RemoteStatusPublisher::HandleRegisterRequest const RegisterRequestMessagepMsg  ) [inline]
 

This method handles the registration request message from remote entities.

The source address of the requester is saved for notification. The requester is also notified of the registration status.

Parameters:
pMsg Pointer to the received subscription request.

Definition at line 138 of file Remote_Status_Publisher.h.

00139     {
00140         OperationStatus status = FAILURE;
00141         // First check if the subscriber is already present
00142         // in the list
00143         int index = Find(pMsg->subscriberAddress);
00144                 
00145         if (index == NOT_FOUND)
00146         {
00147             // Subscriber was not found, so this is not a duplicate request
00148             // Now look for a free entry by finding FREE_ENTRY
00149             index = Find(FREE_ENTRY);
00150             if (index != NOT_FOUND)
00151             {
00152                // A free entry has been found
00153                m_subscriberAddress[index] = pMsg->subscriberAddress;
00154                status = SUCCESS;
00155                SendRequestStatus(pMsg->subscriberAddress, REGISTRATION_ACK , status);
00156             }
00157         }      
00158     }

void RemoteStatusPublisher::HandleDeregisterRequest const DeregisterRequestMessagepMsg  ) [inline]
 

This method handles the deregistration request and responds back with the status.

Parameters:
pMsg Pointer to the received unsubscribe request.

Definition at line 165 of file Remote_Status_Publisher.h.

00166     {
00167         OperationStatus status = FAILURE;
00168         // Search for the entry
00169         int index = Find(pMsg->subscriberAddress);
00170         if (index != NOT_FOUND)
00171         {
00172            // Free the entry by marking as FREE_ENTRY
00173            m_subscriberAddress[index] = FREE_ENTRY;
00174            status = SUCCESS;
00175         }
00176 
00177         // Inform the requester with an acknowledgement.
00178         SendRequestStatus(pMsg->subscriberAddress, DEREGISTRATION_ACK,status);
00179     }


Member Data Documentation

SubscriberAddress RemoteStatusPublisher::m_subscriberAddress[MAX_SUBSCRIBERS] [private]
 

Array to keep track of the subscribers.

Any entry that is not marked FREE_ENTRY is valid and subscribed to the published status.

Definition at line 79 of file Remote_Status_Publisher.h.


The documentation for this class was generated from the following file:
Generated on Sun Feb 13 21:30:36 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.