mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-15 09:31:45 +00:00
Update FairMQStateMachine & introduce FairMQChannels
Organize sockets as a map of vectors of FairMQChannels. Update FairMQStateMachine by removing SETTINGINPUT, SETTINGOUTPUT, BIND and CONNECT states and by adding INITIALIZING_TASK, RESETTING_TASK and RESETTING_DEVICE states. Run states functions in their own thread.
This commit is contained in:
@@ -16,7 +16,13 @@
|
||||
#include "FairMQLogger.h"
|
||||
|
||||
FairMQStateMachine::FairMQStateMachine()
|
||||
: fRunningFinished(false)
|
||||
: fInitializingFinished(false)
|
||||
, fInitializingCondition()
|
||||
, fInitializingMutex()
|
||||
, fInitializingTaskFinished(false)
|
||||
, fInitializingTaskCondition()
|
||||
, fInitializingTaskMutex()
|
||||
, fRunningFinished(false)
|
||||
, fRunningCondition()
|
||||
, fRunningMutex()
|
||||
{
|
||||
@@ -39,20 +45,17 @@ bool FairMQStateMachine::ChangeState(int event)
|
||||
{
|
||||
switch (event)
|
||||
{
|
||||
case INIT:
|
||||
process_event(FairMQFSM::INIT());
|
||||
case INIT_DEVICE:
|
||||
process_event(FairMQFSM::INIT_DEVICE());
|
||||
return true;
|
||||
case SETOUTPUT:
|
||||
process_event(FairMQFSM::SETOUTPUT());
|
||||
case DEVICE_READY:
|
||||
process_event(FairMQFSM::DEVICE_READY());
|
||||
return true;
|
||||
case SETINPUT:
|
||||
process_event(FairMQFSM::SETINPUT());
|
||||
case INIT_TASK:
|
||||
process_event(FairMQFSM::INIT_TASK());
|
||||
return true;
|
||||
case BIND:
|
||||
process_event(FairMQFSM::BIND());
|
||||
return true;
|
||||
case CONNECT:
|
||||
process_event(FairMQFSM::CONNECT());
|
||||
case READY:
|
||||
process_event(FairMQFSM::READY());
|
||||
return true;
|
||||
case RUN:
|
||||
process_event(FairMQFSM::RUN());
|
||||
@@ -60,15 +63,27 @@ bool FairMQStateMachine::ChangeState(int event)
|
||||
case PAUSE:
|
||||
process_event(FairMQFSM::PAUSE());
|
||||
return true;
|
||||
case RESUME:
|
||||
process_event(FairMQFSM::RESUME());
|
||||
return true;
|
||||
case STOP:
|
||||
process_event(FairMQFSM::STOP());
|
||||
return true;
|
||||
case RESET_DEVICE:
|
||||
process_event(FairMQFSM::RESET_DEVICE());
|
||||
return true;
|
||||
case RESET_TASK:
|
||||
process_event(FairMQFSM::RESET_TASK());
|
||||
return true;
|
||||
case IDLE:
|
||||
process_event(FairMQFSM::IDLE());
|
||||
return true;
|
||||
case END:
|
||||
process_event(FairMQFSM::END());
|
||||
return true;
|
||||
default:
|
||||
LOG(ERROR) << "Requested unsupported state: " << event;
|
||||
LOG(ERROR) << "Supported are: INIT, SETOUTPUT, SETINPUT, BIND, CONNECT, RUN, PAUSE, STOP, END";
|
||||
LOG(ERROR) << "Requested unsupported state: " << event << std::endl
|
||||
<< "Supported are: INIT_DEVICE, INIT_TASK, RUN, PAUSE, RESUME, STOP, RESET_TASK, RESET_DEVICE, END";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -80,25 +95,21 @@ bool FairMQStateMachine::ChangeState(int event)
|
||||
|
||||
bool FairMQStateMachine::ChangeState(std::string event)
|
||||
{
|
||||
if (event == "INIT")
|
||||
if (event == "INIT_DEVICE")
|
||||
{
|
||||
return ChangeState(INIT);
|
||||
return ChangeState(INIT_DEVICE);
|
||||
}
|
||||
else if (event == "SETOUTPUT")
|
||||
if (event == "DEVICE_READY")
|
||||
{
|
||||
return ChangeState(SETOUTPUT);
|
||||
return ChangeState(DEVICE_READY);
|
||||
}
|
||||
else if (event == "SETINPUT")
|
||||
if (event == "INIT_TASK")
|
||||
{
|
||||
return ChangeState(SETINPUT);
|
||||
return ChangeState(INIT_TASK);
|
||||
}
|
||||
else if (event == "BIND")
|
||||
if (event == "READY")
|
||||
{
|
||||
return ChangeState(BIND);
|
||||
}
|
||||
else if (event == "CONNECT")
|
||||
{
|
||||
return ChangeState(CONNECT);
|
||||
return ChangeState(READY);
|
||||
}
|
||||
else if (event == "RUN")
|
||||
{
|
||||
@@ -108,18 +119,146 @@ bool FairMQStateMachine::ChangeState(std::string event)
|
||||
{
|
||||
return ChangeState(PAUSE);
|
||||
}
|
||||
else if (event == "RESUME")
|
||||
{
|
||||
return ChangeState(RESUME);
|
||||
}
|
||||
else if (event == "STOP")
|
||||
{
|
||||
return ChangeState(STOP);
|
||||
}
|
||||
if (event == "RESET_DEVICE")
|
||||
{
|
||||
return ChangeState(RESET_DEVICE);
|
||||
}
|
||||
if (event == "RESET_TASK")
|
||||
{
|
||||
return ChangeState(RESET_TASK);
|
||||
}
|
||||
else if (event == "IDLE")
|
||||
{
|
||||
return ChangeState(IDLE);
|
||||
}
|
||||
else if (event == "END")
|
||||
{
|
||||
return ChangeState(END);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(ERROR) << "Requested unsupported state: " << event;
|
||||
LOG(ERROR) << "Supported are: INIT, SETOUTPUT, SETINPUT, BIND, CONNECT, RUN, PAUSE, STOP, END";
|
||||
LOG(ERROR) << "Requested unsupported state: " << event << std::endl
|
||||
<< "Supported are: INIT_DEVICE, INIT_TASK, RUN, PAUSE, RESUME, STOP, RESET_TASK, RESET_DEVICE, END";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void FairMQStateMachine::WaitForEndOfState(int event)
|
||||
{
|
||||
switch (event)
|
||||
{
|
||||
case INIT_DEVICE:
|
||||
{
|
||||
boost::unique_lock<boost::mutex> lock(fInitializingMutex);
|
||||
while (!fInitializingFinished)
|
||||
{
|
||||
fInitializingCondition.wait(lock);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case INIT_TASK:
|
||||
{
|
||||
boost::unique_lock<boost::mutex> initTaskLock(fInitializingTaskMutex);
|
||||
while (!fInitializingTaskFinished)
|
||||
{
|
||||
fInitializingTaskCondition.wait(initTaskLock);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case RUN:
|
||||
{
|
||||
boost::unique_lock<boost::mutex> runLock(fRunningMutex);
|
||||
while (!fRunningFinished)
|
||||
{
|
||||
fRunningCondition.wait(runLock);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case RESET_TASK:
|
||||
{
|
||||
boost::unique_lock<boost::mutex> runLock(fResetTaskMutex);
|
||||
while (!fResetTaskFinished)
|
||||
{
|
||||
fResetTaskCondition.wait(runLock);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case RESET_DEVICE:
|
||||
{
|
||||
boost::unique_lock<boost::mutex> runLock(fResetMutex);
|
||||
while (!fResetFinished)
|
||||
{
|
||||
fResetCondition.wait(runLock);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
LOG(ERROR) << "Requested state is either synchronous or does not exist.";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void FairMQStateMachine::WaitForEndOfState(std::string event)
|
||||
{
|
||||
if (event == "INIT_DEVICE")
|
||||
{
|
||||
return WaitForEndOfState(INIT_DEVICE);
|
||||
}
|
||||
if (event == "DEVICE_READY")
|
||||
{
|
||||
return WaitForEndOfState(DEVICE_READY);
|
||||
}
|
||||
if (event == "INIT_TASK")
|
||||
{
|
||||
return WaitForEndOfState(INIT_TASK);
|
||||
}
|
||||
if (event == "READY")
|
||||
{
|
||||
return WaitForEndOfState(READY);
|
||||
}
|
||||
else if (event == "RUN")
|
||||
{
|
||||
return WaitForEndOfState(RUN);
|
||||
}
|
||||
else if (event == "PAUSE")
|
||||
{
|
||||
return WaitForEndOfState(PAUSE);
|
||||
}
|
||||
else if (event == "RESUME")
|
||||
{
|
||||
return WaitForEndOfState(RESUME);
|
||||
}
|
||||
else if (event == "STOP")
|
||||
{
|
||||
return WaitForEndOfState(STOP);
|
||||
}
|
||||
if (event == "RESET_DEVICE")
|
||||
{
|
||||
return WaitForEndOfState(RESET_DEVICE);
|
||||
}
|
||||
if (event == "RESET_TASK")
|
||||
{
|
||||
return WaitForEndOfState(RESET_TASK);
|
||||
}
|
||||
else if (event == "IDLE")
|
||||
{
|
||||
return WaitForEndOfState(IDLE);
|
||||
}
|
||||
else if (event == "END")
|
||||
{
|
||||
return WaitForEndOfState(END);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(ERROR) << "Requested unsupported state: " << event << std::endl
|
||||
<< "Supported are: INIT_DEVICE, INIT_TASK, RUN, PAUSE, RESUME, STOP, RESET_TASK, RESET_DEVICE, END";
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user