MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
Runtime.cpp
Go to the documentation of this file.
1#include "Runtime.hpp"
2
4#include "Lila/Lila.hpp"
5
7
8#ifdef MAYAFLUX_PLATFORM_WINDOWS
10#endif
11
13
14namespace {
15 std::mutex g_mutex;
16 std::unique_ptr<Lila::Lila> g_instance;
17 uint16_t g_port {};
18}
19
20bool start_lila(uint16_t port)
21{
22 std::lock_guard<std::mutex> guard(g_mutex);
23
24 if (g_instance) {
25 LILA_WARN(Lila::Emitter::SYSTEM,
26 "start_lila: already running on port " + std::to_string(g_port));
27 return false;
28 }
29
30 auto instance = std::make_unique<Lila::Lila>();
31
32 if (!instance->initialize(Lila::OperationMode::Both, static_cast<int>(port), true)) {
33 LILA_ERROR(Lila::Emitter::SYSTEM,
34 "start_lila: initialization failed: " + instance->get_last_error());
35 return false;
36 }
37
38 g_instance = std::move(instance);
39 g_port = port;
40
41#ifdef MAYAFLUX_PLATFORM_WINDOWS
42 g_instance->set_main_thread_id(static_cast<uint32_t>(GetCurrentThreadId()));
43#endif
44
45 LILA_INFO(Lila::Emitter::SYSTEM,
46 "start_lila: running on port " + std::to_string(port));
47 return true;
48}
49
50void stop_lila(bool clear_persistent_store)
51{
52 std::lock_guard<std::mutex> guard(g_mutex);
53
54 if (!g_instance) {
55 return;
56 }
57
58 LILA_INFO(Lila::Emitter::SYSTEM,
59 "stop_lila: stopping on port " + std::to_string(g_port));
60
61 g_instance->stop_server();
62 g_instance.reset();
63 g_port = 0;
64
65 if (clear_persistent_store) {
67 LILA_DEBUG(Lila::Emitter::SYSTEM, "stop_lila: cleared persistent store");
68 }
69}
70
72{
73 std::lock_guard<std::mutex> guard(g_mutex);
74 return static_cast<bool>(g_instance);
75}
76
77uint16_t lila_port()
78{
79 std::lock_guard<std::mutex> guard(g_mutex);
80 return g_instance ? g_port : uint16_t {};
81}
82
83} // namespace MayaFlux::Host::Live
#define LILA_WARN(emitter, msg)
#define LILA_ERROR(emitter, msg)
#define LILA_DEBUG(emitter, msg)
#define LILA_INFO(emitter, msg)
bool lila_active()
True if a Lila instance is currently running in this process.
Definition Runtime.cpp:71
void stop_lila(bool clear_persistent_store)
Stop the running Lila interpreter and TCP server.
Definition Runtime.cpp:50
bool start_lila(uint16_t port)
Start a Lila interpreter and TCP server inside this process.
Definition Runtime.cpp:20
uint16_t lila_port()
TCP port of the running Lila instance, or 0 if none is running.
Definition Runtime.cpp:77
void cleanup_persistent_store()
Definition Persist.hpp:14