From: Arvin Schnell Date: Wed, 30 May 2012 15:29:43 +0000 (+0200) Subject: - work on dbus interface X-Git-Tag: v0.1.3~226 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=487683aef48aa7be5f43915112a2ab891fd0c019;p=thirdparty%2Fsnapper.git - work on dbus interface --- diff --git a/client/commands.cc b/client/commands.cc index e8c3bbec..16550b70 100644 --- a/client/commands.cc +++ b/client/commands.cc @@ -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); +} diff --git a/client/commands.h b/client/commands.h index bbb552f5..cdf58cd4 100644 --- a/client/commands.h +++ b/client/commands.h @@ -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); diff --git a/client/snapper.cc b/client/snapper.cc index df7b0fdc..87c25fc4 100644 --- a/client/snapper.cc +++ b/client/snapper.cc @@ -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); } diff --git a/doc/dbus-protocol.txt b/doc/dbus-protocol.txt index 47401ab1..10fdd118 100644 --- a/doc/dbus-protocol.txt +++ b/doc/dbus-protocol.txt @@ -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. diff --git a/server/snapperd.cc b/server/snapperd.cc index 0f7c2dc7..6c8780f2 100644 --- a/server/snapperd.cc +++ b/server/snapperd.cc @@ -142,6 +142,12 @@ reply_to_introspect(DBus::Connection& conn, DBus::Message& msg) " \n" " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" " \n" " \n" @@ -181,6 +187,12 @@ reply_to_introspect(DBus::Connection& conn, DBus::Message& msg) " \n" " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" "\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