]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
actually call DBus
authorMartin Vidner <mvidner@suse.cz>
Tue, 29 Oct 2019 12:25:06 +0000 (13:25 +0100)
committerMartin Vidner <mvidner@suse.cz>
Thu, 12 Dec 2019 12:44:52 +0000 (13:44 +0100)
using the Hihi library

zypp-plugin/Makefile.am
zypp-plugin/snapper_zypp_plugin.cc

index 9148332a47e218b35a86e8b7160aa5b437da4393..0c2c437aad57416862e4e2f189245609ead815d6 100644 (file)
@@ -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
index 17a2d6d786ce4564a8203c7e26284ec661765cf1..8d1cad0d6b76962a66bada1147cf59988589f00f 100644 (file)
@@ -14,6 +14,8 @@ using boost::format;
 #include <string>
 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<string>&, bool& found, bool& i
     important = true;
 }
 
-unsigned int SnapperZyppPlugin::create_pre_snapshot(string config_name, string description, string cleanup, map<string, string> 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<string, string>& 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() {