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

Local_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 
00033 
00034 class LocalStatusPublisher
00035 {
00036     enum {
00038           NOT_FOUND = -1, 
00039 
00041           MAX_SUBSCRIBERS = 100
00042          };
00043 
00045 
00046     Subscriber *m_pSubscriber[MAX_SUBSCRIBERS];
00047     
00056 
00057     int Find(Subscriber *pSubscriber) const
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     }
00070             
00071 public:
00072 
00074     enum OperationStatus {SUCCESS, FAILURE};
00075 
00084 
00085     void PublishStatus(int unitId, int status)
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     }
00096     
00107 
00108     OperationStatus Register(Subscriber *pSubscriber)
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     }
00129     
00137 
00138     OperationStatus Deregister(Subscriber *pSubscriber)
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     }
00151     
00152 };    

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