Files

57 lines
1.5 KiB
C++
Raw Permalink Normal View History

2018-08-29 20:36:39 +02:00
#pragma once
#include <dbus-status-notifier-watcher.h>
#include <giomm.h>
#include <glibmm/refptr.h>
2018-08-29 20:36:39 +02:00
namespace waybar::modules::SNI {
class Watcher {
private:
Watcher();
public:
~Watcher();
2018-08-29 20:36:39 +02:00
using singleton = std::shared_ptr<Watcher>;
static singleton getInstance() {
static std::weak_ptr<Watcher> weak;
std::shared_ptr<Watcher> strong = weak.lock();
if (!strong) {
strong = std::shared_ptr<Watcher>(new Watcher());
weak = strong;
}
return strong;
}
private:
typedef enum { GF_WATCH_TYPE_HOST, GF_WATCH_TYPE_ITEM } GfWatchType;
2018-08-29 20:36:39 +02:00
typedef struct {
GfWatchType type;
2026-02-04 09:24:14 +01:00
Watcher* watcher;
gchar* service;
gchar* bus_name;
gchar* object_path;
2022-04-06 08:37:19 +02:00
guint watch_id;
} GfWatch;
2018-08-29 20:36:39 +02:00
2026-02-04 09:24:14 +01:00
void busAcquired(const Glib::RefPtr<Gio::DBus::Connection>&, Glib::ustring);
static gboolean handleRegisterHost(Watcher*, GDBusMethodInvocation*, const gchar*);
static gboolean handleRegisterItem(Watcher*, GDBusMethodInvocation*, const gchar*);
static GfWatch* gfWatchFind(GSList* list, const gchar* bus_name, const gchar* object_path);
static GfWatch* gfWatchNew(GfWatchType, const gchar*, const gchar*, const gchar*, Watcher*);
static void nameVanished(GDBusConnection* connection, const char* name, gpointer data);
2022-04-06 08:37:19 +02:00
static void gfWatchFree(gpointer data);
2018-08-29 20:36:39 +02:00
2026-02-04 09:24:14 +01:00
void updateRegisteredItems(SnWatcher* obj);
2022-04-06 08:37:19 +02:00
uint32_t bus_name_id_;
2026-02-04 09:24:14 +01:00
GSList* hosts_ = nullptr;
GSList* items_ = nullptr;
SnWatcher* watcher_ = nullptr;
2018-08-29 20:36:39 +02:00
};
} // namespace waybar::modules::SNI