ClientSession::ClientSession(QTcpSocket *associatedSocket, QObject *parent) : AbstractIdentifiable(parent), _fragment(NULL), _socket(associatedSocket), _blockSize(0) { connect(_socket, &QTcpSocket::readyRead, this, &ClientSession::slot_processReadyRead); connect(_socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(slot_disconnect())); initializeStateMachine(); }
BfVM::BfVM(QObject *parent) : QThread(parent), m_DP(0), m_IP(0), m_programSize(0), m_runDelay(200), m_memory(new Memtype[MAX_MEM_ADDR+1]), m_jmps(new BiHash<IPType,IPType>()), m_program(NULL), m_runTimer(new QTimer(this)), m_inputBuffer(new QQueue<Memtype>()), m_breakpoints(new QList<IPType>()), m_stateMachine(new QStateMachine(this)), ///// STATE INITIALIZATIONS m_stateGroup(new QState()), m_runGroup(new QState(m_stateGroup)), m_emptySt(new QState(m_stateGroup)), m_initializedSt(new QState(m_stateGroup)), m_steppingSt(new QState(m_runGroup)), m_runningSt(new QState(m_runGroup)), m_finishedSt(new QState(m_stateGroup)), m_waitingForInpSt(new QState(m_stateGroup)), m_breakpointSt(new QState(m_runGroup)), m_runHistorySt(new QHistoryState(m_runGroup)), m_clearSt(new QState(m_stateGroup))///// END OF STATE INITIALIZATION { qDebug() << "BfVM::BfVM()\nLargest address:" << MAX_MEM_ADDR; // initialize memory to all 0 clearMemory(); initializeStateMachine(); m_stateMachine->start(); ///////////////////////////////////////////////////////////////////////////////////// //// TIMER SETUP //////////////// m_runTimer->setInterval(m_runDelay); // running a program is just "single-stepping by the clock." connect(m_runTimer, SIGNAL(timeout()), this, SLOT(step())); }
int StateMachine::Run() { //initialize database ptDb->init(); connectionCount = false; int statusCode = 0; // Run the program until SIG_KILL is not received do { //initialize the state machine statusCode = initializeStateMachine(); //set next state setNextState(statusCode); if(statusCode == SUCCESS) { //turn the timer off --- as here objects will reconstruct themselves StateMachine::isTimerEvent = false; // Run the program until connection is alive. do { // poll for bro events. PollData tempQueue = waitForEvents(); if(signalHandler->gotExitSignal()) { broker::message temp; currentEvent = SIG_KILL_EVENT; //pass kill signal to clean up the resources extractAndProcessEvents(currentEvent,temp); } else if(!ptBCM->isConnectionAlive()) { broker::message temp; extractAndProcessEvents(CONNECTION_BROKEN_EVENT,temp); } // bro events processing else if(!tempQueue.empty()) { for(auto& msg : tempQueue) { if(signalHandler->gotExitSignal()) { currentEvent = SIG_KILL_EVENT; extractAndProcessEvents(currentEvent,msg); break; } else { auto ev = broker::to_string(msg[0]); statusCode = extractAndProcessEvents( stringToEvent(ev),msg); if(statusCode == SIG_KILL_EVENT) { break; } } } } // if timer is up. else if(isTimerEvent) { broker::message temp; extractAndProcessEvents(TIMER_EVENT,temp); } }while(ptBCM->isConnectionAlive() && !signalHandler->gotExitSignal()); //if disconnected then break the connection. LOG(WARNING) <<"Connection Broken"; if(signalHandler->gotExitSignal()) { doActionsForKillSignalEvent(); } } }while(!signalHandler->gotExitSignal()); return SUCCESS; }