MeshLib C++ Docs
Loading...
Searching...
No Matches
MRCommandLoop.h
Go to the documentation of this file.
1#pragma once
2#include "exports.h"
3#include <queue>
4#include <functional>
5#include <condition_variable>
6#include <mutex>
7#include <thread>
8
9namespace MR
10{
13
14
17{
18public:
19 using CommandFunc = std::function<void()>;
20
30
32 MRVIEWER_API static void setMainThreadId( const std::thread::id& id );
33 MRVIEWER_API static std::thread::id getMainThreadId();
35 MRVIEWER_API static void setState( StartPosition state );
36
41
44 MRVIEWER_API static void runCommandFromGUIThread( CommandFunc func );
45
47 MRVIEWER_API static void processCommands();
48
50 MRVIEWER_API static bool empty();
51
54 MRVIEWER_API static void removeCommands( bool closeLoop );
55
56private:
57 CommandLoop() = default;
59
60 static CommandLoop& instance_();
61
62 static void addCommand_( CommandFunc func, bool blockThread, StartPosition state );
63
64 struct Command
65 {
68 std::condition_variable callerThreadCV;
69 std::thread::id threadId;
70 };
71
73
75 bool queueClosed_{ false };
76 std::thread::id mainThreadId_;
77 std::queue<std::shared_ptr<Command>> commands_;
78 std::mutex mutex_;
79};
80
81}
Additional command loop for external app control.
Definition MRCommandLoop.h:17
static MRVIEWER_API void runCommandFromGUIThread(CommandFunc func)
StartPosition
Specify execution in specific time of application start.
Definition MRCommandLoop.h:23
static MRVIEWER_API void processCommands()
Execute all commands from loop.
std::thread::id threadId
Definition MRCommandLoop.h:69
CommandFunc func
Definition MRCommandLoop.h:66
static MRVIEWER_API bool empty()
Return true if loop is empty.
std::function< void()> CommandFunc
Definition MRCommandLoop.h:19
static MRVIEWER_API void setMainThreadId(const std::thread::id &id)
This function setups main thread id, it should be called before any command.
StartPosition state
Definition MRCommandLoop.h:67
static MRVIEWER_API void setState(StartPosition state)
Update state of command loop, only can rise.
std::condition_variable callerThreadCV
Definition MRCommandLoop.h:68
static MRVIEWER_API std::thread::id getMainThreadId()
static MRVIEWER_API void appendCommand(CommandFunc func, StartPosition state=StartPosition::BeforeWindowAppear)
static MRVIEWER_API void removeCommands(bool closeLoop)
@ AfterPluginInit
executes after splash appeared
@ BeforeWindowAppear
executes during splash, after plugins init)
@ AfterWindowAppear
executes after splash is going to close, and just before main window is shown and have valid main win...
@ AfterSplashAppear
executes right after window is initialized
only for bindings generation
Definition MRCameraOrientationPlugin.h:8