// TerminalManager source file. We will be using this class // as an example for Object Oriented Programming in C. #include #include "TerminalManager.hpp" #include "Msg.hpp" TerminalManager::TerminalManager() { //... } TerminalManager::~TerminalManager() { } void TerminalManager::HandleMessage(Msg* pMsg) { int status, status1; int terminalId = pMsg->GetTerminalId(); Terminal *pTerm = FindTerminal(terminalId); Terminal *pOtherTerm = NULL; if (pTerm != NULL) { switch (pMsg->GetType()) { case CREATE_TERMINAL: pTerm->Activate((const TerminalCreateMsg *)pMsg); break; case DELETE_TERMINAL: pTerm->Deactivate((const TerminalDeleteMsg *) pMsg); break; case RUN_DIAGNOSTICS: status = pTerm->HandleRunDiagnostics((const RunDiagnosticsMsg *) pMsg); break; case PERFORM_SWITCHOVER: pOtherTerm = FindTerminal(pMsg->GetOtherTerminalId()); status = pTerm->HandleOutOfService(); status1 = pOtherTerm->HandleInService(); break; } } delete pMsg; } Terminal *TerminalManager::FindTerminal(int terminalId) { if (terminalId < MAX_TERMINALS) { return (&terminals[terminalId]); } else { return NULL; } }