You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
119 lines
1.4 KiB
119 lines
1.4 KiB
// TerminalManager source file. We will be using this class
|
|
|
|
// as an example for Object Oriented Programming in C.
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#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;
|
|
|
|
}
|
|
|
|
}
|