]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
- work on dbus interface
authorArvin Schnell <aschnell@suse.de>
Mon, 2 Jul 2012 15:59:15 +0000 (17:59 +0200)
committerArvin Schnell <aschnell@suse.de>
Mon, 2 Jul 2012 15:59:15 +0000 (17:59 +0200)
client/commands.cc
client/commands.h
client/snapper.cc
server/snapperd.cc

index 16550b7099f0ba1abb02c1ad6448b611f4b6856f..42ed3776f389c94c8ff0cc2ea0179cf477538610 100644 (file)
@@ -210,6 +210,32 @@ command_delete_xsnapshots(DBus::Connection& conn, const string& config_name,
 }
 
 
+void
+command_mount_xsnapshots(DBus::Connection& conn, const string& config_name,
+                        unsigned int num)
+{
+    DBus::MessageMethodCall call(SERVICE, OBJECT, INTERFACE, "MountSnapshot");
+
+    DBus::Hoho hoho(call);
+    hoho << config_name << num;
+
+    DBus::Message reply = conn.send_and_reply_and_block(call);
+}
+
+
+void
+command_umount_xsnapshots(DBus::Connection& conn, const string& config_name,
+                         unsigned int num)
+{
+    DBus::MessageMethodCall call(SERVICE, OBJECT, INTERFACE, "UmountSnapshot");
+
+    DBus::Hoho hoho(call);
+    hoho << config_name << num;
+
+    DBus::Message reply = conn.send_and_reply_and_block(call);
+}
+
+
 void
 command_create_xcomparison(DBus::Connection& conn, const string& config_name, unsigned int number1,
                           unsigned int number2)
@@ -234,8 +260,9 @@ command_get_xfiles(DBus::Connection& conn, const string& config_name, unsigned i
 
     DBus::Message reply = conn.send_and_reply_and_block(call);
 
-    DBus::Hihi hihi(reply);
     list<XFile> files;
+
+    DBus::Hihi hihi(reply);
     hihi >> files;
 
     return files;
@@ -253,8 +280,9 @@ command_get_xdiff(DBus::Connection& conn, const string& config_name, unsigned in
 
     DBus::Message reply = conn.send_and_reply_and_block(call);
 
-    DBus::Hihi hihi(reply);
     vector<string> files;
+
+    DBus::Hihi hihi(reply);
     hihi >> files;
 
     return files;
index cdf58cd4a43c89f225312dfb948efcb8b6345d64..40fa138524a000fe8901ff246a4f9e5c8e3f1409 100644 (file)
@@ -75,6 +75,14 @@ void
 command_delete_xsnapshots(DBus::Connection& conn, const string& config_name,
                          list<unsigned int> nums);
 
+void
+command_mount_xsnapshots(DBus::Connection& conn, const string& config_name,
+                        unsigned int num);
+
+void
+command_umount_xsnapshots(DBus::Connection& conn, const string& config_name,
+                         unsigned int num);
+
 void
 command_create_xcomparison(DBus::Connection& conn, const string& config_name, unsigned int number1,
                           unsigned int number2);
index 8492907a5caff56496d908627b4f95ce27ab0f23..2d17d155932cea9744b89af96502a2080eab8bcd 100644 (file)
@@ -636,10 +636,11 @@ command_modify(DBus::Connection& conn)
     {
        while (getopts.hasArgs())
        {
-           Snapshots::iterator snapshot; // = read_num(getopts.popArg());
+           unsigned int num = read_num(getopts.popArg());
 
            GetOpts::parsed_opts::const_iterator opt;
 
+           /*
            if ((opt = opts.find("description")) != opts.end())
                snapshot->setDescription(opt->second);
 
@@ -650,6 +651,7 @@ command_modify(DBus::Connection& conn)
                snapshot->setUserdata(read_userdata(opt->second, snapshot->getUserdata()));
 
            snapshot->flushInfo();
+           */
        }
     }
     catch (const IllegalSnapshotException& e)
@@ -724,9 +726,9 @@ command_mount(DBus::Connection& conn)
     {
        while (getopts.hasArgs())
        {
-           Snapshots::iterator snapshot; // = read_num(getopts.popArg());
+           unsigned int num = read_num(getopts.popArg());
 
-           snapshot->mountFilesystemSnapshot();
+           command_mount_xsnapshots(conn, config_name, num);
        }
     }
     catch (const IllegalSnapshotException& e)
@@ -760,9 +762,9 @@ command_umount(DBus::Connection& conn)
     {
        while (getopts.hasArgs())
        {
-           Snapshots::iterator snapshot; // = read_num(getopts.popArg());
+           unsigned int num = read_num(getopts.popArg());
 
-           snapshot->umountFilesystemSnapshot();
+           command_umount_xsnapshots(conn, config_name, num);
        }
     }
     catch (const IllegalSnapshotException& e)
index 0a0cb1308f241ffb26f04cdeffba30038b82c871..f85c251d2adcf76de313e1be137e8a9557a9ad3f 100644 (file)
@@ -135,6 +135,16 @@ reply_to_introspect(DBus::Connection& conn, DBus::Message& msg)
        "      <arg name='numbers' type='au' direction='in'/>\n"
        "    </method>\n"
 
+       "    <method name='MountSnapshot'>\n"
+       "      <arg name='config-name' type='s' direction='in'/>\n"
+       "      <arg name='number' type='u' direction='in'/>\n"
+       "    </method>\n"
+
+       "    <method name='UmountSnapshot'>\n"
+       "      <arg name='config-name' type='s' direction='in'/>\n"
+       "      <arg name='number' type='u' direction='in'/>\n"
+       "    </method>\n"
+
        "    <method name='CreateComparison'>\n"
        "      <arg name='config-name' type='s' direction='in'/>\n"
        "      <arg name='number1' type='u' direction='in'/>\n"
@@ -625,6 +635,60 @@ reply_to_command_delete_snapshots(DBus::Connection& conn, DBus::Message& msg)
 }
 
 
+void
+reply_to_command_mount_snapshot(DBus::Connection& conn, DBus::Message& msg)
+{
+    string config_name;
+    dbus_uint32_t num;
+
+    DBus::Hihi hihi(msg);
+    hihi >> config_name >> num;
+
+    y2mil("MountSnapshot config_name:" << config_name << " num:" << num);
+
+    check_permission(conn, msg, config_name);
+
+    Snapper* snapper = getSnapper(config_name);
+
+    Snapshots& snapshots = snapper->getSnapshots();
+
+    Snapshots::iterator snap = snapshots.find(num);
+
+    snap->mountFilesystemSnapshot();
+
+    DBus::MessageMethodReturn reply(msg);
+
+    conn.send(reply);
+}
+
+
+void
+reply_to_command_umount_snapshot(DBus::Connection& conn, DBus::Message& msg)
+{
+    string config_name;
+    dbus_uint32_t num;
+
+    DBus::Hihi hihi(msg);
+    hihi >> config_name >> num;
+
+    y2mil("UmountSnapshot config_name:" << config_name << " num:" << num);
+
+    check_permission(conn, msg, config_name);
+
+    Snapper* snapper = getSnapper(config_name);
+
+    Snapshots& snapshots = snapper->getSnapshots();
+
+    Snapshots::iterator snap = snapshots.find(num);
+
+    snap->umountFilesystemSnapshot();
+
+    DBus::MessageMethodReturn reply(msg);
+
+    conn.send(reply);
+}
+
+
 struct Comparing : public Job
 {
     DBus::Connection* conn;
@@ -1028,6 +1092,10 @@ dispatch(DBus::Connection& conn, DBus::Message& msg)
            reply_to_command_create_post_snapshot(conn, msg);
        else if (msg.is_method_call(INTERFACE, "DeleteSnapshots"))
            reply_to_command_delete_snapshots(conn, msg);
+       else if (msg.is_method_call(INTERFACE, "MountSnapshot"))
+           reply_to_command_mount_snapshot(conn, msg);
+       else if (msg.is_method_call(INTERFACE, "UmountSnapshot"))
+           reply_to_command_umount_snapshot(conn, msg);
        else if (msg.is_method_call(INTERFACE, "CreateComparison"))
            reply_to_command_create_comparison(conn, msg);
        else if (msg.is_method_call(INTERFACE, "GetFiles"))
@@ -1046,7 +1114,7 @@ dispatch(DBus::Connection& conn, DBus::Message& msg)
            reply_to_command_debug(conn, msg);
        else
        {
-           DBus::MessageError reply(msg, "error.unknown", DBUS_ERROR_FAILED);
+           DBus::MessageError reply(msg, "error.unknown_method", DBUS_ERROR_FAILED);
            conn.send(reply);
        }
     }