]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
- work on dbus interface
authorArvin Schnell <aschnell@suse.de>
Wed, 30 May 2012 15:29:43 +0000 (17:29 +0200)
committerArvin Schnell <aschnell@suse.de>
Wed, 30 May 2012 15:29:43 +0000 (17:29 +0200)
client/commands.cc
client/commands.h
client/snapper.cc
doc/dbus-protocol.txt
server/snapperd.cc

index e8c3bbec45bccac0c373d88519aa3d9af2d6a089..16550b7099f0ba1abb02c1ad6448b611f4b6856f 100644 (file)
@@ -305,3 +305,16 @@ command_get_xundostatistic(DBus::Connection& conn, const string& config_name, un
 
     return ret;
 }
+
+
+void
+command_xundo_changes(DBus::Connection& conn, const string& config_name, unsigned int number1,
+                     unsigned int number2)
+{
+    DBus::MessageMethodCall call(SERVICE, OBJECT, INTERFACE, "UndoChanges");
+
+    DBus::Hoho hoho(call);
+    hoho << config_name << number1 << number2;
+
+    DBus::Message reply = conn.send_and_reply_and_block(call);
+}
index bbb552f517dc35390e110cfc65adc1d3389e6304..cdf58cd4a43c89f225312dfb948efcb8b6345d64 100644 (file)
@@ -98,3 +98,7 @@ command_set_xundo_all(DBus::Connection& conn, const string& config_name, unsigne
 XUndoStatistic
 command_get_xundostatistic(DBus::Connection& conn, const string& config_name, unsigned int number1,
                           unsigned int number2);
+
+void
+command_xundo_changes(DBus::Connection& conn, const string& config_name, unsigned int number1,
+                     unsigned int number2);
index df7b0fdc1dec4fde57d2d78dc454e666c5279805..87c25fc46264d2a5aa8d5ecaba75066aa626b2c1 100644 (file)
@@ -1000,9 +1000,7 @@ command_undo(DBus::Connection& conn)
 
     cout << sformat(_("create:%d modify:%d delete:%d"), s.numCreate, s.numModify, s.numDelete) << endl;
 
-    /*
-    comparison.doUndo();
-    */
+    command_xundo_changes(conn, config_name, nums.first, nums.second);
 }
 
 
index 47401ab12b9afa46fa489f52d730368accde0b52..10fdd118fc88dd90b957fdeb740eed2344d0c242 100644 (file)
@@ -46,12 +46,9 @@ method GetDiff config-name number1 number2 filename which -> list(string)
 
 method SetUndo config-name number1 number2 list(filename undo)
 method SetUndoAll config-name number1 number2 bool
-method UndoChangeStatistic config-name number1 number2
+method GetUndoStatistic config-name number1 number2
 method UndoChange config-name number1 number2
 
 
-method Cleanup config-name algorithm
-
-
 Filenames do not include the subvolume.
 
index 0f7c2dc767ac1d0e74836bfa1f9c4a8f58bc030b..6c8780f2bb54e868cee25e2778379e5fed097905 100644 (file)
@@ -142,6 +142,12 @@ reply_to_introspect(DBus::Connection& conn, DBus::Message& msg)
        "      <arg name='num-files' type='u' direction='out'/>\n"
        "    </method>\n"
 
+       "    <method name='DeleteComparison'>\n"
+       "      <arg name='config-name' type='s' direction='in'/>\n"
+       "      <arg name='number1' type='u' direction='in'/>\n"
+       "      <arg name='number2' type='u' direction='in'/>\n"
+       "    </method>\n"
+
        "    <method name='GetFiles'>\n"
        "      <arg name='config-name' type='s' direction='in'/>\n"
        "      <arg name='number1' type='u' direction='in'/>\n"
@@ -181,6 +187,12 @@ reply_to_introspect(DBus::Connection& conn, DBus::Message& msg)
        "      <arg name='number-delete' type='u' direction='out'/>\n"
        "    </method>\n"
 
+       "    <method name='UndoChanges'>\n"
+       "      <arg name='config-name' type='s' direction='in'/>\n"
+       "      <arg name='number1' type='u' direction='in'/>\n"
+       "      <arg name='number2' type='u' direction='in'/>\n"
+       "    </method>\n"
+
        "  </interface>\n"
        "</node>\n";
 
@@ -758,11 +770,11 @@ reply_to_command_set_undo(DBus::Connection& conn, DBus::Message& msg)
     DBus::Hihi hihi(msg);
     hihi >> config_name >> num1 >> num2 >> undos;
 
-    check_permission(conn, msg, config_name);
-
     y2mil("SetUndo config_name:" << config_name << " num1:" << num1 << " num2:" <<
          num2);
 
+    check_permission(conn, msg, config_name);
+
     string sender = msg.get_sender();
 
     Clients::iterator it = clients.find(sender);
@@ -797,11 +809,11 @@ reply_to_command_set_undo_all(DBus::Connection& conn, DBus::Message& msg)
     DBus::Hihi hihi(msg);
     hihi >> config_name >> num1 >> num2 >> undo;
 
-    check_permission(conn, msg, config_name);
-
     y2mil("SetUndoAll config_name:" << config_name << " num1:" << num1 << " num2:" <<
          num2);
 
+    check_permission(conn, msg, config_name);
+
     string sender = msg.get_sender();
 
     Clients::iterator it = clients.find(sender);
@@ -831,11 +843,11 @@ reply_to_command_get_undo_statistics(DBus::Connection& conn, DBus::Message& msg)
     DBus::Hihi hihi(msg);
     hihi >> config_name >> num1 >> num2;
 
-    check_permission(conn, msg, config_name);
-
     y2mil("GetUndoStatistic config_name:" << config_name << " num1:" << num1 << " num2:" <<
          num2);
 
+    check_permission(conn, msg, config_name);
+
     string sender = msg.get_sender();
 
     Clients::iterator it = clients.find(sender);
@@ -854,6 +866,73 @@ reply_to_command_get_undo_statistics(DBus::Connection& conn, DBus::Message& msg)
 }
 
 
+struct Undoing : public Job
+{
+    DBus::Connection* conn;
+    DBus::MessageMethodReturn* reply;
+
+    Comparison* comparison;
+
+    void done();
+
+protected:
+
+    virtual void operator()();
+
+};
+
+
+void
+reply_to_command_undo_changes(DBus::Connection& conn, DBus::Message& msg)
+{
+    string config_name;
+    dbus_uint32_t num1, num2;
+
+    DBus::Hihi hihi(msg);
+    hihi >> config_name >> num1 >> num2;
+
+    y2mil("UndoChanges config_name:" << config_name << " num1:" << num1 << " num2:" <<
+         num2);
+
+    check_permission(conn, msg, config_name);
+
+    string sender = msg.get_sender();
+
+    Clients::iterator it = clients.find(sender);
+    assert(it != clients.end());
+
+    Comparison* comparison = it->find_comparison(config_name, num1, num2);
+
+    Undoing* job = new Undoing;
+    job->conn = &conn;
+    job->reply = new DBus::MessageMethodReturn(msg);
+    job->comparison = comparison;
+
+    jobs.add(job);
+}
+
+
+void
+Undoing::operator()()
+{
+    boost::this_thread::sleep(seconds(2));
+
+    comparison->doUndo();
+
+    boost::this_thread::sleep(seconds(2));
+}
+
+
+void
+Undoing::done()
+{
+    DBus::Hoho hoho(*reply);
+    conn->send(*reply);
+
+    delete reply;
+}
+
+
 void
 reply_to_command_debug(DBus::Connection& conn, DBus::Message& msg)
 {
@@ -954,6 +1033,8 @@ dispatch(DBus::Connection& conn, DBus::Message& msg)
            reply_to_command_set_undo_all(conn, msg);
        else if (msg.is_method_call(INTERFACE, "GetUndoStatistic"))
            reply_to_command_get_undo_statistics(conn, msg);
+       else if (msg.is_method_call(INTERFACE, "UndoChanges"))
+           reply_to_command_undo_changes(conn, msg);
        else if (msg.is_method_call(INTERFACE, "Debug"))
            reply_to_command_debug(conn, msg);
        else