Have a single global instance of `sessiond_context` 80/321680/2
authorMichal Bloch <m.bloch@samsung.com>
Wed, 26 Mar 2025 13:55:54 +0000 (14:55 +0100)
committerMichal Bloch <m.bloch@samsung.com>
Thu, 27 Mar 2025 11:29:41 +0000 (12:29 +0100)
This is the de facto state of affairs
and makes the plugin interface cleaner.

Change-Id: I24cb1625945fae2ef4a7dbb5b4e5e232edb6c911

src/service/src/main.cpp
src/service/src/main_context.hpp

index 6be66415a4d930c0ab913b0effdfb2dfa9e5831b..19a0c73da4b20ee5932e9ddced71865a5feb8dd6 100644 (file)
 #include "main_context.hpp"
 #include <stdexcept>
 
+std::unique_ptr <sessiond_context> g_sessiond_context;
+
 int main() try {
-       sessiond_context().run();
+       g_sessiond_context = std::make_unique <sessiond_context> ();
+       g_sessiond_context->run();
 } catch (const std::exception &ex) {
        LOGE("Exception %s caught in top scope! Bailing out...", ex.what());
        return EXIT_FAILURE;
index 7ab23d6be9363ac412f140194fdec9b9b7bc7300..eee6751ed7219d9c34701702b220b7f541f4c2f7 100644 (file)
@@ -27,6 +27,7 @@
 #include <dlog.h>
 
 #include <algorithm>
+#include <memory>
 #include <unordered_map>
 
 #include <gio/gio.h>
@@ -616,3 +617,7 @@ struct sessiond_context {
        main_loop loop;
        GDBusConnection *connection = nullptr;
 };
+
+/* The struct is effectively a singleton, but all the usual code (getter etc)
+ * are missing because this was a change late in development. */
+extern std::unique_ptr <sessiond_context> g_sessiond_context;