static void unlockMutex(void) { udebug("Unlocking mutex"); int status = pthread_mutex_unlock(&mutex); if (status) { LOG_ERRNUM0(status, "Couldn't unlock mutex"); abortProcess(); } }
void Application::addWorker(Controller *controller, Worker *worker) { addToBackend(worker); connect(controller, SIGNAL(abort()), worker, SLOT(abortProcess())); connect(worker, SIGNAL(processAborted()), controller, SLOT(processAborted())); connect(worker, SIGNAL(processOver(QString)), controller, SLOT(processOver(QString))); connect(worker, SIGNAL(progress(int)), controller, SLOT(activityProgressReceived(int))); connect(worker, SIGNAL(errorDuringProcess(QString)), controller, SLOT(errorDuringProcess(QString))); }
static void waitUntilDone(void) { struct sigaction newAction; (void)sigemptyset(&newAction.sa_mask); newAction.sa_flags = 0; newAction.sa_handler = termSigHandler; struct sigaction oldAction; if (setTermSigHandling(&newAction, &oldAction)) { LOG_SERROR0("Couldn't set termination signal handling"); abortProcess(); } waitForDoneCondition(); if (setTermSigHandling(&oldAction, NULL)) { LOG_SERROR0("Couldn't reset termination signal handling"); abortProcess(); } }
static void setDoneCondition(void) { lockMutex(); done = 1; udebug("Signaling condition variable"); int status = pthread_cond_broadcast(&cond); if (status) { LOG_ERRNUM0(status, "Couldn't signal condition variable"); abortProcess(); } unlockMutex(); }
static void waitForDoneCondition(void) { lockMutex(); while (!done) { udebug("Waiting on condition variable"); int status = pthread_cond_wait(&cond, &mutex); if (status) { LOG_ERRNUM0(status, "Couldn't wait on condition variable"); abortProcess(); } } unlockMutex(); }
bool SpecificCore::commandMinimum(std::shared_ptr<SPICE::BIG::ICommandCallback> commandCallback) { // --- example: typical working cycle --- // start process here startProcess(); bool active = true; while(active) { // wait on end of process and check for interupts from the ServiceConsumer if(!processIsActive()) { active = false; } else if(commandCallback->hasToReset()) { return false; } else if(commandCallback->hasToAbort()) { return abortProcess(); } else if(commandCallback->hasToPause()) { pauseProcess(); commandCallback->enterPause(); continueProcess(); } else { std::this_thread::sleep_for(std::chrono::milliseconds(20)); } } // --- example: how to get a value from the parameters or configurations --- bool boolParameter = _resourceProvider->getParameterSet()->getFirstDataEntryByName("BoolParameter")->getValueAsString() == "true"; int intParameter = std::stoi(_resourceProvider->getParameterSet()->getFirstDataEntryByName("IntParameter")->getValueAsString()); unsigned int uintParameter = (unsigned int)std::stoul(_resourceProvider->getParameterSet()->getFirstDataEntryByName("UnsignedIntParameter")->getValueAsString()); // --- example: how to throw errors // -> fatal error { std::shared_ptr<SPICE::BIG::CommandError> error(new SPICE::BIG::CommandError("the error message", "EnterInError", "Enters the inError state. A SiLA-Reset is needed.", SPICE::BIG::ContinuationTask::TaskTypes::fatalError)); commandCallback->throwError(error); return false; } // -> error with selection, the given continuation task at the CommandError-constructor is the default continuation task { std::shared_ptr<SPICE::BIG::CommandError> error(new SPICE::BIG::CommandError("the error message", "EnterInError", "Enters the inError state. A SiLA-Reset is needed.", SPICE::BIG::ContinuationTask::TaskTypes::fatalError)); error->addContinuationTask("AbortAll", "Aborts this command and empty the command buffer", SPICE::BIG::ContinuationTask::TaskTypes::abortAllCommands); error->addContinuationTask("AbortThis", "Aborts / Ends this command", SPICE::BIG::ContinuationTask::TaskTypes::abortCurrentCommand); error->addContinuationTask("Retry", "Tries to continue the command", SPICE::BIG::ContinuationTask::TaskTypes::continueCommand); commandCallback->throwError(error); if(error->getSelectedTaskType() == SPICE::BIG::ContinuationTask::TaskTypes::continueCommand) { // do something to acknowledge the command and continue } else { // do something else, like things to abort return false; } } return true; }