From: Martin Vidner Date: Tue, 29 Oct 2019 12:25:06 +0000 (+0100) Subject: actually call DBus X-Git-Tag: v0.8.7^2~40 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=777efe9d8e10dfbef7e285c34490cd774cf32f37;p=thirdparty%2Fsnapper.git actually call DBus using the Hihi library --- diff --git a/zypp-plugin/Makefile.am b/zypp-plugin/Makefile.am index 9148332a..0c2c437a 100644 --- a/zypp-plugin/Makefile.am +++ b/zypp-plugin/Makefile.am @@ -1,6 +1,7 @@ plugindir = /usr/lib/zypp/plugins/commit plugin_PROGRAMS = snapper-zypp-plugin +AM_CPPFLAGS = $(DBUS_CFLAGS) AM_CXXFLAGS = -Wsuggest-override snapper_zypp_plugin_SOURCES = snapper_zypp_plugin.cc -snapper_zypp_plugin_LDFLAGS = -lboost_regex +snapper_zypp_plugin_LDFLAGS = ../snapper/libsnapper.la ../dbus/libdbus.la -lboost_regex diff --git a/zypp-plugin/snapper_zypp_plugin.cc b/zypp-plugin/snapper_zypp_plugin.cc index 17a2d6d7..8d1cad0d 100644 --- a/zypp-plugin/snapper_zypp_plugin.cc +++ b/zypp-plugin/snapper_zypp_plugin.cc @@ -14,6 +14,8 @@ using boost::format; #include using namespace std; +#include "client/commands.h" + class Logging { public: void debug(const string& s) { cerr << s << endl; } @@ -169,7 +171,8 @@ public: logging.info("creating pre snapshot"); string description = "zypp(%s)"; // % basename(readlink("/proc/%d/exe" % getppid())) - pre_snapshot_num = create_pre_snapshot("root", description, cleanup_algorithm, + DBus::Connection conn(DBUS_BUS_SYSTEM); + pre_snapshot_num = command_create_pre_snapshot(conn, "root", description, cleanup_algorithm, userdata); logging.debug(str(format("created pre snapshot %u") % pre_snapshot_num)); } @@ -218,10 +221,30 @@ void SnapperZyppPlugin::match_solvables(const set&, bool& found, bool& i important = true; } -unsigned int SnapperZyppPlugin::create_pre_snapshot(string config_name, string description, string cleanup, map userdata) { - // call DBus; - unsigned int snapshot_num = 0; - return snapshot_num; +// this is copied from command.cc + +#define SERVICE "org.opensuse.Snapper" +#define OBJECT "/org/opensuse/Snapper" +#define INTERFACE "org.opensuse.Snapper" + +unsigned int +command_create_pre_snapshot(DBus::Connection& conn, const string& config_name, + const string& description, const string& cleanup, + const map& userdata) +{ + DBus::MessageMethodCall call(SERVICE, OBJECT, INTERFACE, "CreatePreSnapshot"); + + DBus::Hoho hoho(call); + hoho << config_name << description << cleanup << userdata; + + DBus::Message reply = conn.send_with_reply_and_block(call); + + unsigned int number; + + DBus::Hihi hihi(reply); + hihi >> number; + + return number; } int main() {