controller.h 1.01 KB
Newer Older
1
2
3
4
5
#ifndef CONTROLLER_H
#define CONTROLLER_H

#include <atomic>
#include <thread>
Leander Schulten's avatar
Leander Schulten committed
6
7
#include <mutex>
#include <condition_variable>
Leander Schulten's avatar
Leander Schulten committed
8
#include "programms/programblock.h"
9
10
11

namespace Modules {

12
13
14
/**
 * @brief The Controller class controlls the whole Module system. Its load and execute it
 */
15
16
17
18
19
20
class Controller
{
    std::atomic_bool run_;
    std::thread thread;
    std::mutex mutex;
    std::condition_variable wait;
Leander Schulten's avatar
Leander Schulten committed
21
22
    std::vector<std::shared_ptr<ProgramBlock>> runningProgramms;
    std::mutex vectorLock;
23
24
25
26
27
28
29
30
31
32
33
34
    void run() noexcept;
public:
    Controller();
    void start(){
        if(!run_){
            run_=true;
            thread = std::thread([this](){
                run();
            });
        }
    }
    void stop(){run_=false;}
35
    ~Controller(){run_ = false;if(thread.joinable())thread.join();}
Leander Schulten's avatar
Leander Schulten committed
36
37
    void runProgramm(std::shared_ptr<ProgramBlock> pb);
    void stopProgramm(std::shared_ptr<ProgramBlock> pb);
Leander Schulten's avatar
Leander Schulten committed
38
    void stopProgramm(ProgramBlock* pb);
39
    bool isProgramRunning(ProgramBlock * pb);
40
41
42
43
};
}

#endif // CONTROLLER_H