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

Remote_Status_Publisher.h

Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 #include "Subscriber.h"
00010 #include <stdio.h>
00011 
00013 typedef unsigned long SubscriberAddress;
00014 
00016 struct RegisterRequestMessage
00017 {
00019     int opcode;
00020 
00022     SubscriberAddress subscriberAddress;
00023 };
00024 
00026 struct DeregisterRequestMessage
00027 {
00029     int opcode;
00030 
00032     SubscriberAddress subscriberAddress;
00033 };
00034 
00036 enum OperationStatus {SUCCESS, FAILURE};
00037 
00039 enum AckType {REGISTRATION_ACK, DEREGISTRATION_ACK};
00040 
00062 
00063 class RemoteStatusPublisher
00064 {
00065     enum {
00066 
00068         FREE_ENTRY = 0,
00069 
00071         NOT_FOUND = -1, 
00072 
00074         MAX_SUBSCRIBERS = 100
00075     };
00076 
00079     SubscriberAddress m_subscriberAddress[MAX_SUBSCRIBERS];
00080     
00086 
00087     int Find(SubscriberAddress subscriberAddress) const
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     } 
00100     
00102 
00103     void SendRequestStatus(SubscriberAddress subscriberAddress, AckType ackType, 
00104                         OperationStatus registrationStatus);
00105 
00107 
00108     void SendStatusChange(SubscriberAddress subscriberAddress, int unitId, int unitStatus);
00109 
00110 public:
00111 
00118 
00119     void PublishStatus(int unitId, int unitStatus)
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     }
00130     
00137 
00138     void HandleRegisterRequest(const RegisterRequestMessage *pMsg)
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     }
00159     
00164   
00165   void HandleDeregisterRequest(const DeregisterRequestMessage *pMsg)
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     }
00180     
00181 };    

Generated on Sun Feb 13 21:30:17 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.