#pragma once #include #include #include #include #include "playback.h" #include "dbus.hpp" class UIBackend { protected: std::vector args; Playback *playback; public: DBusAPI *dbus_api; virtual std::string get_id(); virtual std::string get_name(); UIBackend() = default; virtual void add_licenses() { // Don't add any here, but leave this specified. That way, licenses specific to UI frontends are only added per UI frontend. } virtual int run(std::vector realArgs, int argc, char **argv); static std::map backends; static inline std::optional get_backend(std::string id) { if (backends.contains(id)) { return backends[id]; } else { return {}; } } static inline UIBackend* get_first_backend() { if (backends.empty()) { return nullptr; } return (*backends.begin()).second; } template static void register_backend() { UIBackend *backend = new T(); std::string backend_id = backend->get_id(); if (backends.contains(backend_id)) { // Guard against potential memory leak due to reassigning a new pointer without deallocating the previous one delete backend; return; } backends[backend_id] = backend; } static void deinit_backends(); virtual ~UIBackend(); }; void init_backends();