controller.cpp 900 Bytes
Newer Older
1
2
3
4
5
#include "controller.h"
#include <mutex>

namespace Modules {

Leander Schulten's avatar
Leander Schulten committed
6
Controller::Controller():run_(false)
7
8
9
10
11
12
13
{

}

void Controller::run() noexcept{
    while (run_) {
        std::this_thread::sleep_for(std::chrono::milliseconds(1));
Leander Schulten's avatar
Leander Schulten committed
14
15
16
17
18
19
20
21
        std::unique_lock<std::mutex> l(vectorLock);
        for(auto pb = runningProgramms.begin() ; pb != runningProgramms.end();){
            if((*pb)->doStep(1)){
                pb = runningProgramms.erase(pb);
            }else{
                ++pb;
            }
        }
22
23
24
    }
}

Leander Schulten's avatar
Leander Schulten committed
25
26
27
28
29
30
31
32
33
34
void Controller::runProgramm(std::shared_ptr<ProgramBlock> pb){
    std::unique_lock<std::mutex> l(vectorLock);
    runningProgramms.push_back(pb);
}

void Controller::stopProgramm(std::shared_ptr<ProgramBlock> pb){
    std::unique_lock<std::mutex> l(vectorLock);
    runningProgramms.erase(std::remove(runningProgramms.begin(),runningProgramms.end(),pb),runningProgramms.end());
}

35
}