Support old sdbus-c++, for Debian and other stable distros
This commit is contained in:
parent
5244a7dd83
commit
cf4643e1b3
4 changed files with 53 additions and 29 deletions
|
@ -422,11 +422,19 @@ else()
|
|||
endif()
|
||||
if (ENABLE_DBUS)
|
||||
find_package(sdbus-c++ 2.0)
|
||||
if(NOT ${sdbus-c++_FOUND})
|
||||
if(${sdbus-c++_FOUND})
|
||||
set(OLD_SDBUS OFF)
|
||||
else()
|
||||
find_package(sdbus-c++)
|
||||
if (${sdbus-c++_FOUND})
|
||||
set(OLD_SDBUS ON)
|
||||
else()
|
||||
set(OLD_SDBUS ON)
|
||||
set(ENABLE_DBUS OFF)
|
||||
message("Warning: Dbus support not found - Not enabling DBus. This program requires version 2.0 or later.")
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
set(SDL2_TARGET SDL2::SDL2)
|
||||
if (TARGET SDL2-static)
|
||||
set(SDL2_TARGET SDL2-static)
|
||||
|
@ -436,12 +444,7 @@ endif()
|
|||
if(BUILD_PROTOBUF)
|
||||
add_subdirectory(subprojects/protobuf)
|
||||
else()
|
||||
if (CMAKE_SYSTEM_NAME STREQUAL "Haiku")
|
||||
find_package(Protobuf REQUIRED)
|
||||
else()
|
||||
find_package(protobuf REQUIRED)
|
||||
find_package(absl CONFIG REQUIRED)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (${ENABLE_DBUS})
|
||||
|
@ -571,7 +574,7 @@ if(DEFINED EMSCRIPTEN)
|
|||
copy_to_bindir(assets/ForkAwesome/css/fork-awesome.min.css.map fork-awesome.min.css.map)
|
||||
endif()
|
||||
target_link_libraries(${TARGET_NAME} PUBLIC liblooper ${UI_BACKENDS} ${PLAYBACK_BACKENDS})
|
||||
install(TARGETS ${TARGET_NAME} ${EXTRA_LIBS})
|
||||
install(TARGETS ${TARGET_NAME} ${EXTRA_LIBS} ${UI_BACKENDS} ${PLAYBACK_BACKENDS})
|
||||
if (${BUILD_SDL2})
|
||||
install(EXPORT SDL2-static SDL2main)
|
||||
endif()
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define TAG "@TAG@"
|
||||
#define LOCALE_DIR "@LOCALE_DIR@"
|
||||
#cmakedefine01 DEBUG_MODE_VALUE
|
||||
#cmakedefine01 OLD_SDBUS
|
||||
#if DEBUG_MODE_VALUE==1
|
||||
#define DEBUG_MODE
|
||||
#endif
|
||||
|
|
26
dbus.cpp
26
dbus.cpp
|
@ -6,7 +6,7 @@
|
|||
#include <fmt/format.h>
|
||||
#ifdef DBUS_ENABLED
|
||||
MprisAPI::MprisAPI(sdbus::IConnection &connection, std::string objectPath, DBusAPI *dbus_api)
|
||||
: AdaptorInterfaces(connection, sdbus::ObjectPath{objectPath})
|
||||
: AdaptorInterfaces(connection, OBJECT_PATH(objectPath))
|
||||
, dbus_api(dbus_api)
|
||||
, connection(connection)
|
||||
{
|
||||
|
@ -57,12 +57,12 @@ void MprisAPI::Rate(const double &value) {
|
|||
std::map<std::string, sdbus::Variant> MprisAPI::Metadata() {
|
||||
std::map<std::string, sdbus::Variant> output;
|
||||
if (!dbus_api->IsStopped()) {
|
||||
output["mpris:length"] = sdbus::Variant{(int64_t)(dbus_api->Length() * 1000000)};
|
||||
output["mpris:trackid"] = sdbus::Variant{playing_track_id};
|
||||
output["xesam:title"] = sdbus::Variant{dbus_api->FileTitle()};
|
||||
output["xesam:url"] = sdbus::Variant{dbus_api->FilePath()};
|
||||
output["mpris:length"] = VARIANT((int64_t)(dbus_api->Length() * 1000000));
|
||||
output["mpris:trackid"] = VARIANT(playing_track_id);
|
||||
output["xesam:title"] = VARIANT(dbus_api->FileTitle());
|
||||
output["xesam:url"] = VARIANT(dbus_api->FilePath());
|
||||
} else {
|
||||
output["mpris:trackid"] = sdbus::Variant{empty_track_id};
|
||||
output["mpris:trackid"] = VARIANT(empty_track_id);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
@ -93,8 +93,8 @@ std::vector<meta_t> MprisAPI::GetTracksMetadata(const std::vector<track_id_t> &T
|
|||
int i = 0;
|
||||
for (auto stream : streams) {
|
||||
std::map<std::string, sdbus::Variant> meta;
|
||||
meta["mpris:trackid"] = sdbus::Variant{fmt::format("{}{}", streamPrefix, i)};
|
||||
meta["xesam:title"] = sdbus::Variant{stream.name};
|
||||
meta["mpris:trackid"] = VARIANT(fmt::format("{}{}", streamPrefix, i));
|
||||
meta["xesam:title"] = VARIANT(stream.name);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
@ -123,7 +123,7 @@ std::vector<track_id_t> MprisAPI::Tracks() {
|
|||
auto streams = dbus_api->playback->get_streams();
|
||||
int i = 0;
|
||||
for (auto stream : streams) {
|
||||
output.push_back(sdbus::ObjectPath{fmt::format("{}{}", streamPrefix, i)});
|
||||
output.push_back(OBJECT_PATH(fmt::format("{}{}", streamPrefix, i)));
|
||||
i++;
|
||||
}
|
||||
return output;
|
||||
|
@ -143,14 +143,14 @@ DBusAPI::DBusAPI(Playback *playback, bool daemon)
|
|||
}
|
||||
#else
|
||||
DBusAPI::DBusAPI(Playback *playback, sdbus::IConnection &connection, std::string objectPath, bool daemon)
|
||||
: AdaptorInterfaces(connection, sdbus::ObjectPath{objectPath})
|
||||
: AdaptorInterfaces(connection, OBJECT_PATH(objectPath))
|
||||
, daemon(daemon)
|
||||
, playback(playback)
|
||||
, connection(connection)
|
||||
{
|
||||
registerAdaptor();
|
||||
playback->register_handle(this);
|
||||
auto mprisConnection = sdbus::createSessionBusConnection(sdbus::ServiceName{"org.mpris.MediaPlayer2.Looper"});
|
||||
auto mprisConnection = sdbus::createSessionBusConnection(SERVICE_NAME("org.mpris.MediaPlayer2.Looper"));
|
||||
auto &mprisConRef = *mprisConnection.release();
|
||||
mpris = new MprisAPI(mprisConRef, "/org/mpris/MediaPlayer2", this);
|
||||
threadFunc = std::thread([this]() {
|
||||
|
@ -166,7 +166,7 @@ const char *DBusAPI::objectPath = "/com/complecwaft/looper";
|
|||
const char *DBusAPI::busName = "com.complecwaft.looper";
|
||||
DBusAPI *DBusAPI::Create(Playback *playback, bool daemon) {
|
||||
#ifdef DBUS_ENABLED
|
||||
auto connection = sdbus::createSessionBusConnection(sdbus::ServiceName{busName});
|
||||
auto connection = sdbus::createSessionBusConnection(sdbus::ServiceName(busName));
|
||||
auto &con_ref = *connection.release();
|
||||
return new DBusAPI(playback, con_ref, objectPath, daemon);
|
||||
#else
|
||||
|
@ -590,7 +590,7 @@ DBusAPISender *DBusAPISender::Create() {
|
|||
}
|
||||
#ifdef DBUS_ENABLED
|
||||
DBusAPISender::DBusAPISender(sdbus::IConnection &connection, std::string busName, std::string objectPath)
|
||||
: ProxyInterfaces(connection, sdbus::BusName{busName}, sdbus::ObjectPath{objectPath}) {
|
||||
: ProxyInterfaces(connection, BUS_NAME(busName), OBJECT_PATH(objectPath)) {
|
||||
registerProxy();
|
||||
DEBUG.writeln("Pinging DBus API to check for its existance.");
|
||||
Ping();
|
||||
|
|
28
dbus.hpp
28
dbus.hpp
|
@ -12,6 +12,26 @@
|
|||
#include <random>
|
||||
#include <thread>
|
||||
#ifdef DBUS_ENABLED
|
||||
#ifdef OLD_SDBUS
|
||||
#define OBJECT_PATH(path) path
|
||||
#define VARIANT(value) value
|
||||
#define BUS_NAME(name) name
|
||||
#define SERVICE_NAME(name) name
|
||||
#define MEMBER_NAME(name) name
|
||||
#define INTERFACE_NAME(name) name
|
||||
namespace sdbus {
|
||||
typedef std::string MemberName;
|
||||
typedef std::string ServiceName;
|
||||
}
|
||||
#else
|
||||
#define OBJECT_PATH(path) sdbus::ObjectPath{path}
|
||||
#define VARIANT(value) sdbus::Variant{value}
|
||||
#define BUS_NAME(name) sdbus::BusName{name}
|
||||
#define SERVICE_NAME(name) sdbus::ServiceName{name}
|
||||
#define MEMBER_NAME(name) sdbus::MemberName{name}
|
||||
#define INTERFACE_NAME(name) sdbus::InterfaceName{name}
|
||||
#endif
|
||||
|
||||
class DBusAPI;
|
||||
class MprisAPI : public sdbus::AdaptorInterfaces<org::mpris::MediaPlayer2_adaptor, org::mpris::MediaPlayer2::Player_adaptor, org::mpris::MediaPlayer2::TrackList_adaptor, sdbus::Properties_adaptor> {
|
||||
friend class DBusAPI;
|
||||
|
@ -25,15 +45,15 @@ class MprisAPI : public sdbus::AdaptorInterfaces<org::mpris::MediaPlayer2_adapto
|
|||
inline void sendPropertiesChanged(const std::string interface, const std::initializer_list<std::string> properties) {
|
||||
std::vector<sdbus::MemberName> property_vec;
|
||||
for (auto property : properties) {
|
||||
property_vec.push_back(sdbus::MemberName{property});
|
||||
property_vec.push_back(MEMBER_NAME(property));
|
||||
}
|
||||
emitPropertiesChangedSignal(sdbus::InterfaceName{interface}, property_vec);
|
||||
emitPropertiesChangedSignal(INTERFACE_NAME(interface), property_vec);
|
||||
}
|
||||
public:
|
||||
#define meta_t std::map<std::string, sdbus::Variant>
|
||||
#define track_id_t sdbus::ObjectPath
|
||||
const sdbus::ObjectPath playing_track_id = sdbus::ObjectPath{"/com/complecwaft/Looper/PlayingTrack"};
|
||||
const sdbus::ObjectPath empty_track_id = sdbus::ObjectPath{"/org/mpris/MediaPlayer2/TrackList/NoTrack"};
|
||||
const sdbus::ObjectPath playing_track_id = OBJECT_PATH("/com/complecwaft/Looper/PlayingTrack");
|
||||
const sdbus::ObjectPath empty_track_id = OBJECT_PATH("/org/mpris/MediaPlayer2/TrackList/NoTrack");
|
||||
|
||||
inline void Raise() override { }
|
||||
void Quit() override;
|
||||
|
|
Loading…
Reference in a new issue