]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
- work on dbus interface
authorArvin Schnell <aschnell@suse.de>
Wed, 2 May 2012 14:16:00 +0000 (16:16 +0200)
committerArvin Schnell <aschnell@suse.de>
Wed, 2 May 2012 14:16:00 +0000 (16:16 +0200)
client/commands.cc
client/commands.h
client/snapper.cc
client/types.cc
client/types.h
doc/dbus-protocol.txt
examples/python/comparison.py
server/snapperd.cc

index a3345fe1038a5df46d2271ab74794c161fb31795..d21d89c7a631b0c94dfeb29d6ad5ec49930f55a8 100644 (file)
@@ -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<XUndo>& 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);
+}
index 52578dfefd45e80ac93633f42b98f5609a7fb129..aefbb9f351ab27de139c05a4726a8aa2dcb69247 100644 (file)
@@ -80,3 +80,17 @@ vector<string>
 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<XUndo>& 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);
index 17b94dc73c346b16efa49a6ca10f1b1a0641f468..b382ee0979e7cfb7f63cae925ece5fe08a90d81d 100644 (file)
@@ -22,7 +22,6 @@
 
 #include <stdlib.h>
 #include <string.h>
-#include <sys/types.h>
 #include <sys/stat.h>
 #include <iostream>
 #include <boost/algorithm/string.hpp>
@@ -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;
index f2a527519fb9b46468297f86434af29e5c9c547c..2924b841935be50addd2e52896411d19a6563e6e 100644 (file)
@@ -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<XConfigInfo>::signature = "(ss)";
index cb23ada67c6c302a16dc4d1042578e3e90421c8e..fb77442dbcac913c3dded88e8f982926eec97cf0 100644 (file)
@@ -98,6 +98,16 @@ struct XUndo
 };
 
 
+struct XUndoStatistic
+{
+    bool empty() const;
+
+    unsigned int numCreate;
+    unsigned int numModify;
+    unsigned int numDelete;
+};
+
+
 namespace DBus
 {
 
index 2fa870ebe7ec5ebc8f3d4290272b5a573fb8dd26..a49da75c86810a9c67db908d82e6558dfb2db2a4 100644 (file)
@@ -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
 
index ffb6f552136631463b73cb93a2cb2c78a8889384..d75e4fa7c41147ce00097928b359d9445b78b696 100755 (executable)
@@ -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
+
index 2575d1bdbff0ff4fbb3eb69c01931b53563cb35f..218778e8e3a3210243b370f82a6e937fa3af931a 100644 (file)
@@ -142,6 +142,15 @@ reply_to_introspect(DBus::Connection& conn, DBus::Message& msg)
        "      <arg name='files' type='v' direction='out'/>\n"
        "    </method>\n"
 
+       "    <method name='GetDiff'>\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"
+       "      <arg name='filename' type='s' direction='in'/>\n"
+       "      <arg name='options' type='s' direction='in'/>\n"
+       "      <arg name='diff' type='v' direction='out'/>\n"
+       "    </method>\n"
+
        "    <method name='SetUndo'>\n"
        "      <arg name='config-name' type='s' direction='in'/>\n"
        "      <arg name='number1' type='u' direction='in'/>\n"
@@ -149,13 +158,25 @@ reply_to_introspect(DBus::Connection& conn, DBus::Message& msg)
        "      <arg name='files' type='a(sb)' direction='in'/>\n"
        "    </method>\n"
 
-       "    <method name='GetDiff'>\n"
+       "    <method name='SetUndoAll'>\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"
-       "      <arg name='filename' type='s' direction='in'/>\n"
-       "      <arg name='options' type='s' direction='in'/>\n"
-       "      <arg name='diff' type='v' direction='out'/>\n"
+       "      <arg name='undo' type='b' direction='in'/>\n"
+       "    </method>\n"
+
+       "    <method name='GetUndoStatistic'>\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"
+       "      <arg name='number-create' type='u' direction='out'/>\n"
+       "      <arg name='number-modify' type='u' direction='out'/>\n"
+       "      <arg name='number-delete' type='u' direction='out'/>\n"
+       "    </method>\n"
+
+       "    <method name='Cleanup'>\n"
+       "      <arg name='config-name' type='s' direction='in'/>\n"
+       "      <arg name='algorithm' type='s' direction='in'/>\n"
        "    </method>\n"
 
        "  </interface>\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<string> 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<Undo> u;
+    list<Undo> 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<Undo>::const_iterator it2 = u.begin(); it2 != u.end(); ++it2)
+    for (list<Undo>::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<string> 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)
     {