00001
00002
00003
00004
00005
00006
00007
00008
00009 #include <map>
00010 using namespace std;
00011
00012
00013 class Terminal_Message
00014 {
00015 public:
00016 int Get_Terminal_Id() const;
00017 };
00018
00022
00023 class Terminal
00024 {
00025 public:
00026
00030
00031 Terminal(int terminal_Id, int type);
00032
00035 void Handle_Message(const Terminal_Message *pMsg);
00036
00039 int Get_Terminal_Id() const;
00040 };
00041
00045
00046 class Terminal_Manager
00047 {
00051 typedef map<int, Terminal *> Terminal_Map;
00052
00055 Terminal_Map m_terminal_Map;
00056
00057 public:
00058
00059 enum Status {FAILURE, SUCCESS};
00060
00074
00075 Status Add_Terminal(int terminal_Id, int type)
00076 {
00077 Status status;
00078
00079
00080
00081 if(m_terminal_Map.count(terminal_Id) == 0)
00082 {
00083
00084 Terminal *pTerm = new Terminal(terminal_Id, type);
00085
00086
00087
00088
00089 m_terminal_Map[terminal_Id] = pTerm;
00090
00091 status = SUCCESS;
00092 }
00093 else
00094 {
00095
00096
00097 status = FAILURE;
00098 }
00099
00100 return status;
00101 }
00102
00116
00117 Status Remove_Terminal(int terminal_Id)
00118 {
00119 Status status;
00120
00121 if (m_terminal_Map.count(terminal_Id) == 1)
00122 {
00123
00124 Terminal *pTerm = m_terminal_Map[terminal_Id];
00125
00126
00127
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 }
00140
00147
00148 Terminal *Find_Terminal(int terminal_Id)
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 }
00162
00168
00169 void Handle_Message(const Terminal_Message *pMsg)
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 }
00182 };