Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Backend::Backend(const QString &executable, QObject *parent) :
- QThread(parent),
- _executable(executable),
- _process(new QProcess(this)),
- _requestType(Backend::NoRequest),
- _running(false)
- {
- connect(_process, SIGNAL(readyReadStandardOutput()),
- SLOT(handleOutput()));
- }
- Backend::~Backend()
- {
- delete _process;
- }
- void Backend::startStimulation()
- {
- _process->start(_executable, argsForStimulation(), QProcess::ReadOnly);
- _running = true;
- }
- void Backend::endStimulation()
- {
- _requestType = Backend::NoRequest;
- _running = false;
- emit stimulationEnd();
- }
- void Backend::handleOutput()
- {
- QString output = _process->readAll();
- switch (_requestType) {
- case Backend::StimulateRequest:
- if (output.split('\n').first().simplified() == "end") {
- endStimulation();
- }
- }
- }
- void Backend::run()
- {
- for (;;) {
- if (!_running) {
- switch (_requestType)
- {
- case Backend::StimulateRequest:
- startStimulation();
- break;
- default:
- QCoreApplication::instance()->processEvents();
- }
- } else {
- QCoreApplication::instance()->processEvents();
- }
- }
- }
- Backend::ErrorType Backend::stimulate(const QHash<QString, QVariant> ¶ms)
- {
- if (_running || _requestType != Backend::NoRequest) {
- return Backend::AlreadyRunningError;
- }
- if (!supportedFeatures().contains("stimulation")) {
- return Backend::NotSupportedFeatureError;
- }
- _params = params;
- _requestType = Backend::StimulateRequest;
- return Backend::Success;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement