2020-02-03 22:31:44 +00:00
|
|
|
#pragma once
|
2020-07-06 17:31:40 +00:00
|
|
|
#ifndef MANGOHUD_DBUS_INFO_H
|
|
|
|
#define MANGOHUD_DBUS_INFO_H
|
|
|
|
|
2020-04-21 10:29:27 +00:00
|
|
|
#include <array>
|
2020-02-03 22:31:44 +00:00
|
|
|
#include <stdexcept>
|
|
|
|
#include <thread>
|
|
|
|
#include <functional>
|
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
|
|
|
#include <map>
|
2020-04-13 00:02:52 +00:00
|
|
|
#include <unordered_map>
|
2020-02-03 22:31:44 +00:00
|
|
|
#include <mutex>
|
2020-04-04 20:47:48 +00:00
|
|
|
#include "loaders/loader_dbus.h"
|
2020-02-03 22:31:44 +00:00
|
|
|
|
2020-06-30 00:03:28 +00:00
|
|
|
typedef std::unordered_map<std::string, std::string> string_map;
|
|
|
|
|
2020-02-03 22:31:44 +00:00
|
|
|
struct metadata {
|
2020-04-04 20:47:48 +00:00
|
|
|
//std::vector<std::string> artists;
|
|
|
|
std::string artists; // pre-concatenate
|
2020-02-03 22:31:44 +00:00
|
|
|
std::string title;
|
|
|
|
std::string album;
|
|
|
|
std::string something;
|
|
|
|
std::string artUrl;
|
|
|
|
bool playing = false;
|
2020-04-04 20:47:48 +00:00
|
|
|
struct {
|
|
|
|
float pos;
|
|
|
|
float longest;
|
|
|
|
int dir = -1;
|
|
|
|
bool needs_recalc;
|
|
|
|
|
|
|
|
float tw0;
|
|
|
|
float tw1;
|
|
|
|
float tw2;
|
|
|
|
} ticker;
|
2020-02-03 22:31:44 +00:00
|
|
|
|
|
|
|
bool valid = false;
|
|
|
|
std::mutex mutex;
|
2020-05-22 12:00:35 +00:00
|
|
|
|
|
|
|
void clear()
|
|
|
|
{
|
|
|
|
artists.clear();
|
|
|
|
title.clear();
|
|
|
|
album.clear();
|
|
|
|
artUrl.clear();
|
|
|
|
ticker = {};
|
|
|
|
ticker.dir = -1;
|
|
|
|
valid = false;
|
|
|
|
}
|
2020-02-03 22:31:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum SignalType
|
|
|
|
{
|
|
|
|
ST_NAMEOWNERCHANGED,
|
|
|
|
ST_PROPERTIESCHANGED,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-05-11 19:01:40 +00:00
|
|
|
extern struct metadata main_metadata;
|
2020-02-03 22:31:44 +00:00
|
|
|
|
|
|
|
namespace dbusmgr {
|
2020-06-30 14:24:49 +00:00
|
|
|
|
|
|
|
class dbus_manager;
|
|
|
|
using signal_handler_func = bool (dbus_manager::*)(DBusMessage*, const char*);
|
|
|
|
|
|
|
|
struct DBusSignal
|
|
|
|
{
|
|
|
|
const char * intf;
|
|
|
|
const char * signal;
|
|
|
|
signal_handler_func handler;
|
|
|
|
};
|
|
|
|
|
2020-02-03 22:31:44 +00:00
|
|
|
using callback_func = std::function<void(/*metadata*/)>;
|
|
|
|
|
|
|
|
enum CBENUM {
|
|
|
|
CB_CONNECTED,
|
|
|
|
CB_DISCONNECTED,
|
|
|
|
CB_NEW_METADATA,
|
|
|
|
};
|
|
|
|
|
|
|
|
class dbus_manager
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
dbus_manager()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
~dbus_manager();
|
|
|
|
|
2020-06-30 00:03:28 +00:00
|
|
|
bool init(const std::string& requested_player);
|
2020-04-10 19:33:27 +00:00
|
|
|
void deinit();
|
2020-06-30 00:03:28 +00:00
|
|
|
bool get_media_player_metadata(metadata& meta, std::string name = "");
|
2020-02-03 22:31:44 +00:00
|
|
|
void add_callback(CBENUM type, callback_func func);
|
|
|
|
void connect_to_signals();
|
|
|
|
void disconnect_from_signals();
|
|
|
|
DBusConnection* get_conn() const {
|
|
|
|
return m_dbus_conn;
|
|
|
|
}
|
|
|
|
|
2020-04-04 20:47:48 +00:00
|
|
|
libdbus_loader& dbus() {
|
|
|
|
return m_dbus_ldr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-02-03 22:31:44 +00:00
|
|
|
protected:
|
|
|
|
void stop_thread();
|
|
|
|
void start_thread();
|
2020-06-30 00:03:28 +00:00
|
|
|
void dbus_thread();
|
|
|
|
|
|
|
|
bool dbus_list_name_to_owner();
|
|
|
|
bool select_active_player();
|
2020-02-03 22:31:44 +00:00
|
|
|
|
2020-06-30 14:24:49 +00:00
|
|
|
static DBusHandlerResult filter_signals(DBusConnection*, DBusMessage*, void*);
|
|
|
|
|
|
|
|
bool handle_properties_changed(DBusMessage*, const char*);
|
|
|
|
bool handle_name_owner_changed(DBusMessage*, const char*);
|
|
|
|
|
2020-02-03 22:31:44 +00:00
|
|
|
DBusError m_error;
|
|
|
|
DBusConnection * m_dbus_conn = nullptr;
|
|
|
|
DBusMessage * m_dbus_msg = nullptr;
|
|
|
|
DBusMessage * m_dbus_reply = nullptr;
|
|
|
|
bool m_quit = false;
|
|
|
|
bool m_inited = false;
|
|
|
|
std::thread m_thread;
|
|
|
|
std::map<CBENUM, callback_func> m_callbacks;
|
2020-04-04 20:47:48 +00:00
|
|
|
libdbus_loader m_dbus_ldr;
|
2020-04-13 00:02:52 +00:00
|
|
|
std::unordered_map<std::string, std::string> m_name_owners;
|
2020-06-30 00:03:28 +00:00
|
|
|
std::string m_requested_player;
|
|
|
|
std::string m_active_player;
|
|
|
|
|
|
|
|
|
2020-02-03 22:31:44 +00:00
|
|
|
|
|
|
|
const std::array<DBusSignal, 2> m_signals {{
|
2020-06-30 14:24:49 +00:00
|
|
|
{ "org.freedesktop.DBus", "NameOwnerChanged", &dbus_manager::handle_name_owner_changed },
|
|
|
|
{ "org.freedesktop.DBus.Properties", "PropertiesChanged", &dbus_manager::handle_properties_changed },
|
2020-02-03 22:31:44 +00:00
|
|
|
}};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
extern dbus_manager dbus_mgr;
|
|
|
|
}
|
|
|
|
|
2020-06-30 00:03:28 +00:00
|
|
|
<<<<<<< HEAD
|
2020-05-22 12:00:35 +00:00
|
|
|
bool get_media_player_metadata(dbusmgr::dbus_manager& dbus, const std::string& name, metadata& meta);
|
2020-07-06 17:31:40 +00:00
|
|
|
|
|
|
|
#endif //MANGOHUD_DBUS_INFO_H
|
2020-06-30 00:03:28 +00:00
|
|
|
=======
|
|
|
|
//bool get_media_player_metadata(dbusmgr::dbus_manager& dbus, const std::string& name, metadata& meta);
|
|
|
|
>>>>>>> 9c064df... Change the media player functionality to allow changing active media
|