From: Arvin Schnell Date: Wed, 2 May 2012 14:16:00 +0000 (+0200) Subject: - work on dbus interface X-Git-Tag: v0.1.3~231 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8d1097561c14c7358bc8ff081b18afdf2869ca22;p=thirdparty%2Fsnapper.git - work on dbus interface --- diff --git a/client/commands.cc b/client/commands.cc index a3345fe1..d21d89c7 100644 --- a/client/commands.cc +++ b/client/commands.cc @@ -217,3 +217,62 @@ command_get_xdiff(DBus::Connection& conn, const string& config_name, unsigned in return files; } + + +void +command_set_xundo(DBus::Connection& conn, const string& config_name, unsigned int number1, + unsigned int number2, const list& undos) +{ + DBus::MessageMethodCall call(SERVICE, OBJECT, INTERFACE, "SetUndo"); + + DBus::Hoho hoho(call); + hoho << config_name << number1 << number2 << undos; + + DBus::Message reply = conn.send_and_reply_and_block(call); +} + + +void +command_set_xundo_all(DBus::Connection& conn, const string& config_name, unsigned int number1, + unsigned int number2, bool undo) +{ + DBus::MessageMethodCall call(SERVICE, OBJECT, INTERFACE, "SetUndoAll"); + + DBus::Hoho hoho(call); + hoho << config_name << number1 << number2 << undo; + + DBus::Message reply = conn.send_and_reply_and_block(call); +} + + +XUndoStatistic +command_get_xundostatistic(DBus::Connection& conn, const string& config_name, unsigned int number1, + unsigned int number2) +{ + DBus::MessageMethodCall call(SERVICE, OBJECT, INTERFACE, "GetUndoStatistic"); + + DBus::Hoho hoho(call); + hoho << config_name << number1 << number2; + + DBus::Message reply = conn.send_and_reply_and_block(call); + + XUndoStatistic ret; + + DBus::Hihi hihi(reply); + hihi >> ret.numCreate >> ret.numModify >> ret.numDelete; + + return ret; +} + + +void +command_xcleanup(DBus::Connection& conn, const string& config_name, const string& algorithm) + +{ + DBus::MessageMethodCall call(SERVICE, OBJECT, INTERFACE, "Cleanup"); + + DBus::Hoho hoho(call); + hoho << config_name << algorithm; + + DBus::Message reply = conn.send_and_reply_and_block(call); +} diff --git a/client/commands.h b/client/commands.h index 52578dfe..aefbb9f3 100644 --- a/client/commands.h +++ b/client/commands.h @@ -80,3 +80,17 @@ vector command_get_xdiff(DBus::Connection& conn, const string& config_name, unsigned int number1, unsigned int number2, const string& filename, const string& options); +void +command_set_xundo(DBus::Connection& conn, const string& config_name, unsigned int number1, + unsigned int number2, const list& undos); + +void +command_set_xundo_all(DBus::Connection& conn, const string& config_name, unsigned int number1, + unsigned int number2, bool undo); + +XUndoStatistic +command_get_xundostatistic(DBus::Connection& conn, const string& config_name, unsigned int number1, + unsigned int number2); + +void +command_xcleanup(DBus::Connection& conn, const string& config_name, const string& algorithm); diff --git a/client/snapper.cc b/client/snapper.cc index 17b94dc7..b382ee09 100644 --- a/client/snapper.cc +++ b/client/snapper.cc @@ -22,7 +22,6 @@ #include #include -#include #include #include #include @@ -952,10 +951,7 @@ command_undo(DBus::Connection& conn) { if (getopts.numArgs() == 0) { - /* - for (Files::iterator it = files.begin(); it != files.end(); ++it) - it->setUndo(true); - */ + command_set_xundo_all(conn, config_name, nums.first, nums.second, true); } else { @@ -973,18 +969,19 @@ command_undo(DBus::Connection& conn) } } } - /* - UndoStatistic rs = comparison.getUndoStatistic(); - if (rs.empty()) + XUndoStatistic s = command_get_xundostatistic(conn, config_name, nums.first, nums.second); + + if (s.empty()) { cout << "nothing to do" << endl; return; } - cout << "create:" << rs.numCreate << " modify:" << rs.numModify << " delete:" << rs.numDelete + cout << "create:" << s.numCreate << " modify:" << s.numModify << " delete:" << s.numDelete << endl; + /* comparison.doUndo(); */ } @@ -1015,17 +1012,9 @@ command_cleanup(DBus::Connection& conn) string cleanup = getopts.popArg(); - if (cleanup == "number") + if (cleanup == "number" || cleanup == "timeline" || cleanup == "empty-pre-post") { - // sh->doCleanupNumber(); - } - else if (cleanup == "timeline") - { - // sh->doCleanupTimeline(); - } - else if (cleanup == "empty-pre-post") - { - // sh->doCleanupEmptyPrePost(); + command_xcleanup(conn, config_name, cleanup); } else { @@ -1112,8 +1101,6 @@ main(int argc, char** argv) setlocale(LC_ALL, ""); - initDefaultLogger(); - cmds["list-configs"] = command_list_configs; cmds["create-config"] = command_create_config; cmds["delete-config"] = command_delete_config; diff --git a/client/types.cc b/client/types.cc index f2a52751..2924b841 100644 --- a/client/types.cc +++ b/client/types.cc @@ -39,6 +39,13 @@ XSnapshots::findPost(const_iterator pre) const } +bool +XUndoStatistic::empty() const +{ + return numCreate == 0 && numModify == 0 && numDelete == 0; +} + + namespace DBus { const char* TypeInfo::signature = "(ss)"; diff --git a/client/types.h b/client/types.h index cb23ada6..fb77442d 100644 --- a/client/types.h +++ b/client/types.h @@ -98,6 +98,16 @@ struct XUndo }; +struct XUndoStatistic +{ + bool empty() const; + + unsigned int numCreate; + unsigned int numModify; + unsigned int numDelete; +}; + + namespace DBus { diff --git a/doc/dbus-protocol.txt b/doc/dbus-protocol.txt index 2fa870eb..a49da75c 100644 --- a/doc/dbus-protocol.txt +++ b/doc/dbus-protocol.txt @@ -19,10 +19,10 @@ lock the some config. method ListSnapshots config-name -method CreateSingleSnapshot config-name ... -> number -method CreatePreSnapshot config-name ... -> number -method CreatePostSnapshot config-name ... -> number -method ModifySnapshot config-name number ... +method CreateSingleSnapshot config-name description cleanup userdata -> number +method CreatePreSnapshot config-name pre-number description cleanup userdata -> number +method CreatePostSnapshot config-name description cleanup userdata -> number +method ModifySnapshot config-name number description cleanup userdata method DeleteSnapshot config-name number signal SnapshotCreated config-name number @@ -34,18 +34,21 @@ method UmountSnapshot config-name number - method CreateComparison config-name number1 number2 method DeleteComparison config-name number1 number2 The following commands require a successful CreateComparison in advance. method GetFiles config-name number1 number2 -> list(filename status undo) -method SetUndo config-name number1 number2 list(filename undo) method GetStatus config-name number1 number2 filename which -> string 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 UndoChange config-name number1 number2 + -method Undo config-name number1 number2 +method Cleanup config-name algorithm diff --git a/examples/python/comparison.py b/examples/python/comparison.py index ffb6f552..d75e4fa7 100755 --- a/examples/python/comparison.py +++ b/examples/python/comparison.py @@ -8,12 +8,14 @@ snapper = dbus.Interface(bus.get_object('org.opensuse.snapper', '/org/opensuse/s dbus_interface='org.opensuse.snapper') -num_files = snapper.CreateComparison("root", 1306, 1307) +config_name = "root" +num_pre = 52 +num_post = 53 -print num_files +snapper.CreateComparison(config_name, num_pre, num_post) -files = snapper.GetFiles("root", 1306, 1307) +files = snapper.GetFiles(config_name, num_pre, num_post) for file in files: print file[0], file[1], file[2] @@ -21,11 +23,16 @@ for file in files: undo = [ [ "/hello", False ], [ "/world", True ] ] -snapper.SetUndo("root", 1306, 1307, undo) +snapper.SetUndo(config_name, num_pre, num_post, undo) -files = snapper.GetFiles("root", 1306, 1307) +files = snapper.GetFiles("root", num_pre, num_post) for file in files: print file[0], file[1], file[2] + +(num_create, num_modify, num_delete) = snapper.GetUndoStatistic(config_name, num_pre, num_post) + +print num_create, num_modify, num_delete + diff --git a/server/snapperd.cc b/server/snapperd.cc index 2575d1bd..218778e8 100644 --- a/server/snapperd.cc +++ b/server/snapperd.cc @@ -142,6 +142,15 @@ reply_to_introspect(DBus::Connection& conn, DBus::Message& msg) " \n" " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" " \n" " \n" @@ -149,13 +158,25 @@ reply_to_introspect(DBus::Connection& conn, DBus::Message& msg) " \n" " \n" - " \n" + " \n" " \n" " \n" " \n" - " \n" - " \n" - " \n" + " \n" + " \n" + + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + + " \n" + " \n" + " \n" " \n" " \n" @@ -329,10 +350,9 @@ void reply_to_command_delete_config(DBus::Connection& conn, DBus::Message& msg) { string config_name; - string subvolume; DBus::Hihi hihi(msg); - hihi >> config_name >> subvolume; + hihi >> config_name; y2mil("DeleteConfig config_name:" << config_name); @@ -366,6 +386,7 @@ reply_to_command_lock_config(DBus::Connection& conn, DBus::Message& msg) it->add_lock(config_name); DBus::MessageMethodReturn reply(msg); + conn.send(reply); } @@ -388,6 +409,7 @@ reply_to_command_unlock_config(DBus::Connection& conn, DBus::Message& msg) it->remove_lock(config_name); DBus::MessageMethodReturn reply(msg); + conn.send(reply); } @@ -404,10 +426,10 @@ reply_to_command_list_snapshots(DBus::Connection& conn, DBus::Message& msg) check_permission(conn, msg, config_name); - DBus::MessageMethodReturn reply(msg); - Snapper* snapper = getSnapper(config_name); + DBus::MessageMethodReturn reply(msg); + DBus::Hoho hoho(reply); hoho << snapper->getSnapshots(); @@ -431,8 +453,6 @@ reply_to_command_create_single_snapshot(DBus::Connection& conn, DBus::Message& m check_permission(conn, msg, config_name); - DBus::MessageMethodReturn reply(msg); - Snapper* snapper = getSnapper(config_name); Snapshots::iterator snap1 = snapper->createSingleSnapshot(description); @@ -440,6 +460,8 @@ reply_to_command_create_single_snapshot(DBus::Connection& conn, DBus::Message& m snap1->setUserdata(userdata); snap1->flushInfo(); + DBus::MessageMethodReturn reply(msg); + DBus::Hoho hoho(reply); hoho << snap1->getNum(); @@ -465,8 +487,6 @@ reply_to_command_create_pre_snapshot(DBus::Connection& conn, DBus::Message& msg) check_permission(conn, msg, config_name); - DBus::MessageMethodReturn reply(msg); - Snapper* snapper = getSnapper(config_name); Snapshots::iterator snap1 = snapper->createPreSnapshot(description); @@ -474,6 +494,8 @@ reply_to_command_create_pre_snapshot(DBus::Connection& conn, DBus::Message& msg) snap1->setUserdata(userdata); snap1->flushInfo(); + DBus::MessageMethodReturn reply(msg); + DBus::Hoho hoho(reply); hoho << snap1->getNum(); @@ -500,8 +522,6 @@ reply_to_command_create_post_snapshot(DBus::Connection& conn, DBus::Message& msg check_permission(conn, msg, config_name); - DBus::MessageMethodReturn reply(msg); - Snapper* snapper = getSnapper(config_name); Snapshots& snapshots = snapper->getSnapshots(); @@ -513,6 +533,8 @@ reply_to_command_create_post_snapshot(DBus::Connection& conn, DBus::Message& msg snap2->setUserdata(userdata); snap2->flushInfo(); + DBus::MessageMethodReturn reply(msg); + DBus::Hoho hoho(reply); hoho << snap2->getNum(); @@ -639,8 +661,6 @@ reply_to_command_get_files(DBus::Connection& conn, DBus::Message& msg) string sender = msg.get_sender(); - DBus::MessageMethodReturn reply(msg); - Clients::iterator it = clients.find(sender); assert(it != clients.end()); @@ -648,6 +668,8 @@ reply_to_command_get_files(DBus::Connection& conn, DBus::Message& msg) const Files& files = comparison->getFiles(); + DBus::MessageMethodReturn reply(msg); + DBus::Hoho hoho(reply); hoho << files; @@ -655,15 +677,54 @@ reply_to_command_get_files(DBus::Connection& conn, DBus::Message& msg) } +void +reply_to_command_get_diff(DBus::Connection& conn, DBus::Message& msg) +{ + string config_name; + dbus_uint32_t num1, num2; + string filename; + string options; + + DBus::Hihi hihi(msg); + hihi >> config_name >> num1 >> num2 >> filename >> options; + + y2mil("GetDiff config_name:" << config_name << " num1:" << num1 << " num2:" << + num2 << " filename:" << filename << " options:" << options); + + 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); + + Files& files = comparison->getFiles(); + + Files::iterator it3 = files.find(filename); + assert(it3 != files.end()); + + vector d = it3->getDiff(options); + + DBus::MessageMethodReturn reply(msg); + + DBus::Hoho hoho(reply); + hoho << d; + + conn.send(reply); +} + + void reply_to_command_set_undo(DBus::Connection& conn, DBus::Message& msg) { string config_name; dbus_uint32_t num1, num2; - list u; + list undos; DBus::Hihi hihi(msg); - hihi >> config_name >> num1 >> num2 >> u; + hihi >> config_name >> num1 >> num2 >> undos; check_permission(conn, msg, config_name); @@ -672,8 +733,6 @@ reply_to_command_set_undo(DBus::Connection& conn, DBus::Message& msg) string sender = msg.get_sender(); - DBus::MessageMethodReturn reply(msg); - Clients::iterator it = clients.find(sender); assert(it != clients.end()); @@ -681,33 +740,34 @@ reply_to_command_set_undo(DBus::Connection& conn, DBus::Message& msg) Files& files = comparison->getFiles(); - for (list::const_iterator it2 = u.begin(); it2 != u.end(); ++it2) + for (list::const_iterator it2 = undos.begin(); it2 != undos.end(); ++it2) { Files::iterator it3 = files.find(it2->filename); if (it3 != files.end()) it3->setUndo(it2->undo); } + DBus::MessageMethodReturn reply(msg); + conn.send(reply); } void -reply_to_command_get_diff(DBus::Connection& conn, DBus::Message& msg) +reply_to_command_set_undo_all(DBus::Connection& conn, DBus::Message& msg) { string config_name; dbus_uint32_t num1, num2; - string filename; - string options; + bool undo; DBus::Hihi hihi(msg); - hihi >> config_name >> num1 >> num2 >> filename >> options; - - y2mil("GetDiff config_name:" << config_name << " num1:" << num1 << " num2:" << - num2 << " filename:" << filename << " options:" << options); + hihi >> config_name >> num1 >> num2 >> undo; check_permission(conn, msg, config_name); + y2mil("SetUndoAll config_name:" << config_name << " num1:" << num1 << " num2:" << + num2); + string sender = msg.get_sender(); Clients::iterator it = clients.find(sender); @@ -717,14 +777,80 @@ reply_to_command_get_diff(DBus::Connection& conn, DBus::Message& msg) Files& files = comparison->getFiles(); - Files::iterator it3 = files.find(filename); - assert(it3 != files.end()); + for (Files::iterator it2 = files.begin(); it2 != files.end(); ++it2) + { + it2->setUndo(undo); + } - vector d = it3->getDiff(options); + DBus::MessageMethodReturn reply(msg); + + conn.send(reply); +} + + +void +reply_to_command_get_undo_statistics(DBus::Connection& conn, DBus::Message& msg) +{ + string config_name; + dbus_uint32_t num1, num2; + + 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); + + string sender = msg.get_sender(); + + Clients::iterator it = clients.find(sender); + assert(it != clients.end()); + + Comparison* comparison = it->find_comparison(config_name, num1, num2); + + UndoStatistic statistic = comparison->getUndoStatistic(); DBus::MessageMethodReturn reply(msg); + DBus::Hoho hoho(reply); - hoho << d; + hoho << statistic.numCreate << statistic.numModify << statistic.numDelete; + + conn.send(reply); +} + + +void +reply_to_command_cleanup(DBus::Connection& conn, DBus::Message& msg) +{ + string config_name; + string algorithm; + + DBus::Hihi hihi(msg); + hihi >> config_name >> algorithm; + + y2mil("GetDiff config_name:" << config_name << " algorithm:" << algorithm); + + check_permission(conn, msg, config_name); + + Snapper* snapper = getSnapper(config_name); + + // TODO: at least the last algorithm must be in a seperate thread + + if (algorithm == "number") + { + snapper->doCleanupNumber(); + } + else if (algorithm == "timeline") + { + snapper->doCleanupTimeline(); + } + else if (algorithm == "empty-pre-post") + { + snapper->doCleanupEmptyPrePost(); + } + + DBus::MessageMethodReturn reply(msg); conn.send(reply); } @@ -796,9 +922,7 @@ dispatch(DBus::Connection& conn, DBus::Message& msg) { try { - if (msg.is_method_call(INTERFACE, "Debug")) - reply_to_command_debug(conn, msg); - else if (msg.is_method_call(INTERFACE, "ListConfigs")) + if (msg.is_method_call(INTERFACE, "ListConfigs")) reply_to_command_list_configs(conn, msg); else if (msg.is_method_call(INTERFACE, "CreateConfig")) reply_to_command_create_config(conn, msg); @@ -822,10 +946,23 @@ dispatch(DBus::Connection& conn, DBus::Message& msg) reply_to_command_create_comparison(conn, msg); else if (msg.is_method_call(INTERFACE, "GetFiles")) reply_to_command_get_files(conn, msg); - else if (msg.is_method_call(INTERFACE, "SetUndo")) - reply_to_command_set_undo(conn, msg); else if (msg.is_method_call(INTERFACE, "GetDiff")) reply_to_command_get_diff(conn, msg); + else if (msg.is_method_call(INTERFACE, "SetUndo")) + reply_to_command_set_undo(conn, msg); + else if (msg.is_method_call(INTERFACE, "SetUndoAll")) + 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, "Cleanup")) + reply_to_command_cleanup(conn, msg); + else if (msg.is_method_call(INTERFACE, "Debug")) + reply_to_command_debug(conn, msg); + else + { + DBus::MessageError reply(msg, "error.unknown", DBUS_ERROR_FAILED); + conn.send(reply); + } } catch (const DBus::MarshallingException& e) {