Generate path configuration file
All checks were successful
Build / build (push) Successful in 18s

This commit is contained in:
Eugen Wissner 2024-06-18 11:19:44 +02:00
parent 7b5fe4b9d1
commit 9dc8fb2640
Signed by: belka
GPG Key ID: A27FDC1E8EE902C0
6 changed files with 16 additions and 13 deletions

View File

@ -1,5 +1,7 @@
find_program(SED sed)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/resources.h.in" "resources.h")
add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/org.freedesktop.timedate1.service
COMMAND ${SED} -e s|@LIBEXECDIR@|${CMAKE_INSTALL_FULL_LIBEXECDIR}| ${CMAKE_CURRENT_SOURCE_DIR}/org.freedesktop.timedate1.service.in > ${PROJECT_BINARY_DIR}/org.freedesktop.timedate1.service
MAIN_DEPENDENCY org.freedesktop.timedate1.service.in

1
data/resources.h.in Normal file
View File

@ -0,0 +1 @@
#define DATADIR_INTERFACES "@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_DATADIR@/dbus-1/interfaces"

View File

@ -4,7 +4,7 @@ pkg_check_modules(GDBUS REQUIRED gio-2.0 dbus-1 glibmm-2.4 giomm-2.4)
add_executable(slack-timedate main.cpp
timedate.cpp timedate.h
)
target_include_directories(slack-timedate PRIVATE ${GDBUS_INCLUDE_DIRS})
target_include_directories(slack-timedate PRIVATE ${CMAKE_BINARY_DIR}/data ${GDBUS_INCLUDE_DIRS})
target_link_libraries(slack-timedate ${GDBUS_LIBRARIES})
install(TARGETS slack-timedate DESTINATION ${CMAKE_INSTALL_LIBEXECDIR})

View File

@ -30,7 +30,8 @@ int main(int argc, char **argv)
Gio::init();
auto timedate1 = std::make_unique<dlackware::timedate::timedate1>();
guint owner_id = Gio::DBus::own_name(Gio::DBus::BUS_TYPE_SYSTEM, BUS_NAME,
guint owner_id = Gio::DBus::own_name(Gio::DBus::BUS_TYPE_SYSTEM,
Glib::ustring(dlackware::timedate::bus_name.cbegin(), dlackware::timedate::bus_name.cend()),
std::bind(&dlackware::timedate::timedate1::on_bus_acquired, timedate1.get(),
std::placeholders::_1, std::placeholders::_2),
Gio::DBus::SlotNameAcquired(),

View File

@ -120,6 +120,9 @@ static void slack_get_property(Glib::VariantBase& result, const Glib::RefPtr<Gio
namespace dlackware::timedate
{
constexpr const std::int32_t usec_per_sec = 1000000ULL;
constexpr const std::int32_t nsec_per_usec = 1000ULL;
timedate1::timedate1()
: interface_vtable{ &slack_method_call, &slack_get_property }
{
@ -134,11 +137,11 @@ namespace dlackware::timedate
void timedate1::on_bus_acquired(const Glib::RefPtr<Gio::DBus::Connection>& connection, const Glib::ustring& name)
{
Glib::RefPtr<Gio::DBus::NodeInfo> introspection_data;
try
{
auto introspection_xml = Glib::file_get_contents(dlackware::timedate::introspection_xml);
auto introspection_xml = Glib::file_get_contents(
(std::filesystem::path(DATADIR_INTERFACES) / dlackware::timedate::bus_name).concat(".xml")
);
introspection_data = Gio::DBus::NodeInfo::create_for_xml(introspection_xml);
}
catch (Glib::Error& slack_err)
@ -194,7 +197,7 @@ namespace dlackware::timedate
{
return nullptr;
}
return Glib::ustring{ zone_copied_from.get() + strlen(zoneinfo_database) + 1 };
return Glib::ustring{ zone_copied_from.get() + zoneinfo_database.size() + 1 };
}
void set_timezone(const Glib::ustring& zone, bool)

View File

@ -20,17 +20,13 @@
#include <dbus/dbus.h>
#include <glibmm.h>
#include <giomm.h>
#define BUS_NAME "org.freedesktop.timedate1"
#include "resources.h"
namespace dlackware::timedate
{
constexpr const char *bus_path = "/org/freedesktop/timedate1";
constexpr const char *zoneinfo_database = "/usr/share/zoneinfo";
constexpr const char *introspection_xml = "/usr/share/dbus-1/interfaces/org.freedesktop.timedate1.xml";
constexpr const gint32 usec_per_sec = 1000000ULL;
constexpr const gint32 nsec_per_usec = 1000ULL;
constexpr const std::string_view bus_name = "org.freedesktop.timedate1";
constexpr const std::string_view zoneinfo_database = "/usr/share/zoneinfo";
// Returns the system time zone.
Glib::ustring timezone();