PCB Environment 2

Loading...
Searching...
No Matches
Application.hpp
1
2#ifndef GYM_PCB_UI_APPLICATION_H
3#define GYM_PCB_UI_APPLICATION_H
4
5#include <thread>
6#include <mutex>
7#include <semaphore>
8#include <future>
9#include <cassert>
10
11// FIXME: We can't include the Log.hpp file here because of Qt. Why?
12
13 class Agent;
14 class PCBoard;
15
16 class IUIApplication
17{
18 public:
19 static IUIApplication *create();
20 public:
21 virtual ~IUIApplication();
22 virtual std::future<bool> runAsync() { return std::future<bool>(); }
23 virtual void show() { }
24 virtual void hide() { }
25 virtual void wait(); // NOTE: This is on by default by reacts to the Lock setting in the UI.
26 virtual void quit(int code) { } // This may terminate Python.
27 virtual void setPCB(const std::shared_ptr<PCBoard>&, bool wait = true) { }
28 virtual void setAutonomousAgent(const std::shared_ptr<Agent>&, const std::shared_ptr<PCBoard>&) { }
29 void startExclusiveTask(const char *warn = 0);
30 bool tryStartExclusiveTask(const char *name = 0);
31 bool endExclusiveTask(bool rv = true, const char *reason = 0);
32 protected:
33 std::shared_ptr<PCBoard> mPCB;
34 std::unique_ptr<Agent> mUserAgent;
35 std::shared_ptr<Agent> mAutoAgent;
36 private:
37 std::binary_semaphore mTaskLock{1};
38};
39
40 class UIApplication : public IUIApplication
41{
42 public:
44 Agent *getUserAgent() const { return mUserAgent.get(); }
45 Agent *getAutoAgent() const { return mAutoAgent.get(); }
46 PCBoard *getPCB() const { return mPCB.get(); }
47};
48
49#endif // GYM_PCB_UI_APPLICATION_H
Agent
Definition Agent.hpp:31
IUIApplication
Definition Application.hpp:17
PCBoard
Definition PCBoard.hpp:36
UIApplication
Definition Application.hpp:41
UIApplication::getUserAgent
Agent * getUserAgent() const
These are not available outside the UI as it wouldn't be thread-safe.
Definition Application.hpp:44