From: Arvin Schnell Date: Mon, 2 Jul 2012 15:59:15 +0000 (+0200) Subject: - work on dbus interface X-Git-Tag: v0.1.3~218 X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=d3cb778d6d1fae1bdaed6fc0760f130fd77c3edb;p=thirdparty%2Fsnapper.git - work on dbus interface --- diff --git a/client/commands.cc b/client/commands.cc index 16550b70..42ed3776 100644 --- a/client/commands.cc +++ b/client/commands.cc @@ -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 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 files; + + DBus::Hihi hihi(reply); hihi >> files; return files; diff --git a/client/commands.h b/client/commands.h index cdf58cd4..40fa1385 100644 --- a/client/commands.h +++ b/client/commands.h @@ -75,6 +75,14 @@ void command_delete_xsnapshots(DBus::Connection& conn, const string& config_name, list 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); diff --git a/client/snapper.cc b/client/snapper.cc index 8492907a..2d17d155 100644 --- a/client/snapper.cc +++ b/client/snapper.cc @@ -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) diff --git a/server/snapperd.cc b/server/snapperd.cc index 0a0cb130..f85c251d 100644 --- a/server/snapperd.cc +++ b/server/snapperd.cc @@ -135,6 +135,16 @@ reply_to_introspect(DBus::Connection& conn, DBus::Message& msg) " \n" " \n" + " \n" + " \n" + " \n" + " \n" + + " \n" + " \n" + " \n" + " \n" + " \n" " \n" " \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); } }