Eddie James | 18e1e46 | 2018-12-11 13:24:36 -0600 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "ikvm_args.hpp" |
| 4 | #include "ikvm_input.hpp" |
| 5 | #include "ikvm_server.hpp" |
| 6 | #include "ikvm_video.hpp" |
| 7 | |
| 8 | #include <condition_variable> |
| 9 | #include <mutex> |
| 10 | |
| 11 | namespace ikvm |
| 12 | { |
Eddie James | 18e1e46 | 2018-12-11 13:24:36 -0600 | [diff] [blame] | 13 | /* |
| 14 | * @class Manager |
| 15 | * @brief Manages the VNC server by executing threaded loops of RFB operations |
| 16 | * and video device operations. |
| 17 | */ |
| 18 | class Manager |
| 19 | { |
| 20 | public: |
| 21 | /* |
| 22 | * @brief Constructs the Manager object |
| 23 | * |
| 24 | * @param[in] args - Reference to Args object |
| 25 | */ |
George Liu | d1711dd | 2023-08-16 14:10:39 +0800 | [diff] [blame] | 26 | explicit Manager(const Args& args); |
Eddie James | 18e1e46 | 2018-12-11 13:24:36 -0600 | [diff] [blame] | 27 | ~Manager() = default; |
| 28 | Manager(const Manager&) = default; |
| 29 | Manager& operator=(const Manager&) = default; |
| 30 | Manager(Manager&&) = default; |
| 31 | Manager& operator=(Manager&&) = default; |
| 32 | |
| 33 | /* @brief Begins operation of the VNC server */ |
| 34 | void run(); |
| 35 | |
| 36 | private: |
| 37 | /* |
| 38 | * @brief Thread function to loop the RFB update operations |
| 39 | * |
| 40 | * @param[in] manager - Pointer to the Manager object |
| 41 | */ |
| 42 | static void serverThread(Manager* manager); |
| 43 | |
| 44 | /* @brief Notifies thread waiters that RFB operations are complete */ |
| 45 | void setServerDone(); |
| 46 | /* @brief Notifies thread waiters that video operations are complete */ |
| 47 | void setVideoDone(); |
| 48 | /* @brief Blocks until RFB operations complete */ |
| 49 | void waitServer(); |
| 50 | /* @brief Blocks until video operations are complete */ |
| 51 | void waitVideo(); |
| 52 | |
| 53 | /* |
| 54 | * @brief Boolean to indicate whether the application should continue |
| 55 | * running |
| 56 | */ |
| 57 | bool continueExecuting; |
| 58 | /* @brief Boolean to indicate that RFB operations are complete */ |
| 59 | bool serverDone; |
| 60 | /* @brief Boolean to indicate that video operations are complete */ |
| 61 | bool videoDone; |
| 62 | /* @brief Input object */ |
| 63 | Input input; |
| 64 | /* @brief Video object */ |
| 65 | Video video; |
| 66 | /* @brief RFB server object */ |
| 67 | Server server; |
| 68 | /* @brief Condition variable to enable waiting for thread completion */ |
| 69 | std::condition_variable sync; |
| 70 | /* @brief Mutex for waiting on condition variable safely */ |
| 71 | std::mutex lock; |
| 72 | }; |
| 73 | |
| 74 | } // namespace ikvm |