Exemplo n.º 1
0
void ThreadGroup::executeTask(const TaskPtr& task)
{
    try {
        std::unique_lock<std::recursive_mutex> state_lock(execution_mtx_);
        ProfilerPtr profiler = getProfiler();
        Trace::Ptr interlude;
        if (profiler && profiler->isEnabled()) {
            TimerPtr timer = profiler->getTimer(getName());
            interlude.reset(new Trace(timer, task->getName()));
        }

        task->execute();

    } catch (const std::exception& e) {
        TaskGenerator* gen = task->getParent();
        if (gen) {
            gen->setError(e.what());
        }
    } catch (const std::string& s) {
        std::cerr << "Uncaught exception (string) exception: " << s << std::endl;

    } catch (const csapex::Failure& assertion) {
        handler_.handleAssertionFailure(assertion);

    } catch (...) {
        std::cerr << "Uncaught exception of unknown type and origin in execution of task " << task->getName() << "!" << std::endl;
        throw;
    }
}
Exemplo n.º 2
0
void TaskManager::addTask(TaskPtr task)
{
    std::list<TaskPtr>::iterator it = tasks_.begin();
    // attempt to find task
    std::list<TaskPtr>::iterator found = std::find_if(tasks_.begin(), 
                                tasks_.end(),
                                std::bind2nd(TaskNameEq(), task->getName()) );
                                
    // if found task (meaning task w/ same name exists) throw exception
    if(found != tasks_.end())
    {
        throw PreconditionException("Attempted to add duplicate task \"" +  
                                    task->getName() + "\".");
    }
    
    task->onStart();    // called whenever a task is being started
    
    // find the first task in the list with a lower priority
    while(it != tasks_.end() && (*it)->getPriority() <= task->getPriority())
    {
        ++it;
    }
    tasks_.insert(it, task);    // insert task after iterator
}
Exemplo n.º 3
0
bool TaskManager::TaskNameEq::operator()(const TaskPtr& lhs, 
                                    const std::string& rhs) const
{
    return lhs->getName() == rhs;
}