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

Terminal_Manager Class Reference

#include <Terminal_Manager.h>

List of all members.


Detailed Description

Terminal Manager demonstrates the Manager design pattern using the STL map.

Here a collection of terminals is being managed by the Terminal Manager. Management involves routing messages, creating and deleting terminals

Definition at line 46 of file Terminal_Manager.h.

Public Member Functions

Status Add_Terminal (int terminal_Id, int type)
 A new terminal is added by inserting it into the STL map.

Status Remove_Terminal (int terminal_Id)
 Remove a terminal from the database.

TerminalFind_Terminal (int terminal_Id)
 Find the terminal for a given terminal id.

void Handle_Message (const Terminal_Message *pMsg)
 Message handler for the Terminal_Manager.


Private Types

typedef map< int, Terminal * > Terminal_Map
 The map is keyed with the terminal id and stores pointers to Terminals.


Private Attributes

Terminal_Map m_terminal_Map
 Terminal map maintains a mapping between the terminal id and pointers to terminal objects.


Member Typedef Documentation

typedef map<int, Terminal *> Terminal_Manager::Terminal_Map [private]
 

The map is keyed with the terminal id and stores pointers to Terminals.

terminal id is an integer, terminal ids can be in the entire range for an integer and they will still be efficiently stored inside a map.

Definition at line 51 of file Terminal_Manager.h.


Member Function Documentation

Status Terminal_Manager::Add_Terminal int terminal_Id,
int type
[inline]
 

A new terminal is added by inserting it into the STL map.

The method takes the following steps:

  • Check if the terminal being added already exists in the map. This is done using the count call to determine the number of terminals that match the specified terminal_id
  • If the terminal does not exist, create a Terminal object with the requested attribites.
  • Add the object into the terminal map. The Terminal is inserted into the STL map using an array indexing type of sytax. Since map overloads the array operator [ ], it gives the illusion of indexing into an array

Parameters:
terminal_Id Id of the terminal that needs to be added to the system
type Type of the terminal being added.
Return values:
Status Status of terminal addition is returned as SUCCESS or FAILURE

Definition at line 75 of file Terminal_Manager.h.

00076    {
00077       Status status;
00078       
00079       // Check if the terminal is already present in the map. count()
00080       // returns the total number of entries that are keyed by terminal_Id
00081       if(m_terminal_Map.count(terminal_Id) == 0)
00082       {
00083          // count() returned zero, so no entries are present in the map
00084          Terminal *pTerm = new Terminal(terminal_Id, type);
00085  
00086          // Since map overloads the array operator [ ], it gives 
00087          // the illusion of indexing into an array. The following
00088          // line makes an entry into the map
00089          m_terminal_Map[terminal_Id] = pTerm;
00090          
00091          status = SUCCESS;
00092       }
00093       else
00094       {
00095          // count() returned a non zero value, so the terminal is already
00096          // present.
00097          status = FAILURE;
00098       }
00099       
00100       return status;
00101    }

Status Terminal_Manager::Remove_Terminal int terminal_Id  ) [inline]
 

Remove a terminal from the database.

The method takes the following steps:

  • Check if the terminal is present in the STL map.
  • If the terminal is present, get a pointer to the terminal using an array access syntax. Note that the [ ] operator has been overloaded to provide intuitive array type syntax.
  • Remove the entry corresponding to the terminal from the terminal pointer map.
  • Delete the terminal object.

Note:
Removing the terminal entry from the map just deletes the pointer. The terminal object still needs to be deleted.
Return values:
Status Status of terminal deletion is returned as SUCCESS or FAILURE.

Definition at line 117 of file Terminal_Manager.h.

00118    {
00119       Status status;
00120       // Check if the terminal is present
00121       if (m_terminal_Map.count(terminal_Id) == 1)
00122       {
00123          // Save the pointer that is being deleted from the map
00124          Terminal *pTerm = m_terminal_Map[terminal_Id]; 
00125          
00126          // Erase the entry from the map. This just frees up the memory for
00127          // the pointer. The actual object is freed up using delete
00128          m_terminal_Map.erase(terminal_Id);
00129          delete pTerm;
00130          
00131          status = SUCCESS;
00132       }
00133       else
00134       {
00135          status = FAILURE;
00136       }
00137       
00138       return status;
00139    }

Terminal* Terminal_Manager::Find_Terminal int terminal_Id  ) [inline]
 

Find the terminal for a given terminal id.

Return NULL if terminal is not found.

Parameters:
terminal_Id Terminal Id
Return values:
Terminal* Pointer to the terminal. NULL is returned if no terminal matches the terminal id.

Definition at line 148 of file Terminal_Manager.h.

00149   {
00150      Terminal *pTerm;
00151      if (m_terminal_Map.count(terminal_Id) == 1)
00152      {
00153         pTerm = m_terminal_Map[terminal_Id];
00154      }
00155      else
00156      {
00157          pTerm = NULL;
00158      }
00159      
00160      return pTerm;
00161   } 

void Terminal_Manager::Handle_Message const Terminal_Message * pMsg  ) [inline]
 

Message handler for the Terminal_Manager.

This method first finds the terminal. If the terminal is found, the message is passed to the appropriate Terminal object.

Parameters:
pMsg Pointer to a terminal specific message.

Definition at line 169 of file Terminal_Manager.h.

00170   {
00171      int terminal_Id = pMsg->Get_Terminal_Id();
00172      
00173      Terminal *pTerm;
00174      
00175      pTerm = Find_Terminal(terminal_Id);
00176      
00177      if (pTerm)
00178      {
00179         pTerm->Handle_Message(pMsg);
00180      }
00181   }


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