]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
- work on dbus interface
authorArvin Schnell <aschnell@suse.de>
Fri, 20 Jul 2012 11:17:46 +0000 (13:17 +0200)
committerArvin Schnell <aschnell@suse.de>
Fri, 20 Jul 2012 11:17:46 +0000 (13:17 +0200)
client/commands.cc
dbus/DBusConnection.cc
dbus/DBusConnection.h
server/Client.cc
server/Client.h
server/snapperd.cc

index 0583a5e1ff04dd883bb4c76297935ff931f47c3c..3b15c7637c91f9667e7525f75db93b0dfd2cb095 100644 (file)
@@ -33,7 +33,7 @@ command_list_xconfigs(DBus::Connection& conn)
 {
     DBus::MessageMethodCall call(SERVICE, OBJECT, INTERFACE, "ListConfigs");
 
-    DBus::Message reply = conn.send_and_reply_and_block(call);
+    DBus::Message reply = conn.send_with_reply_and_block(call);
 
     list<XConfigInfo> ret;
 
@@ -52,7 +52,7 @@ command_get_xconfig(DBus::Connection& conn, const string& config_name)
     DBus::Hoho hoho(call);
     hoho << config_name;
 
-    DBus::Message reply = conn.send_and_reply_and_block(call);
+    DBus::Message reply = conn.send_with_reply_and_block(call);
 
     XConfigInfo ret;
 
@@ -72,7 +72,7 @@ command_create_xconfig(DBus::Connection& conn, const string& config_name, const
     DBus::Hoho hoho(call);
     hoho << config_name << subvolume << fstype << template_name;
 
-    conn.send_and_reply_and_block(call);
+    conn.send_with_reply_and_block(call);
 }
 
 
@@ -84,7 +84,7 @@ command_delete_xconfig(DBus::Connection& conn, const string& config_name)
     DBus::Hoho hoho(call);
     hoho << config_name;
 
-    conn.send_and_reply_and_block(call);
+    conn.send_with_reply_and_block(call);
 }
 
 
@@ -96,7 +96,7 @@ command_list_xsnapshots(DBus::Connection& conn, const string& config_name)
     DBus::Hoho hoho(call);
     hoho << config_name;
 
-    DBus::Message reply = conn.send_and_reply_and_block(call);
+    DBus::Message reply = conn.send_with_reply_and_block(call);
 
     XSnapshots ret;
 
@@ -115,7 +115,7 @@ command_get_xsnapshot(DBus::Connection& conn, const string& config_name, unsigne
     DBus::Hoho hoho(call);
     hoho << config_name << num;
 
-    DBus::Message reply = conn.send_and_reply_and_block(call);
+    DBus::Message reply = conn.send_with_reply_and_block(call);
 
     XSnapshot ret;
 
@@ -135,7 +135,7 @@ command_set_xsnapshot(DBus::Connection& conn, const string& config_name, unsigne
     DBus::Hoho hoho(call);
     hoho << config_name << num << data.description << data.cleanup << data.userdata;
 
-    conn.send_and_reply_and_block(call);
+    conn.send_with_reply_and_block(call);
 }
 
 
@@ -149,7 +149,7 @@ command_create_single_xsnapshot(DBus::Connection& conn, const string& config_nam
     DBus::Hoho hoho(call);
     hoho << config_name << description << cleanup << userdata;
 
-    DBus::Message reply = conn.send_and_reply_and_block(call);
+    DBus::Message reply = conn.send_with_reply_and_block(call);
 
     unsigned int number;
 
@@ -170,7 +170,7 @@ command_create_pre_xsnapshot(DBus::Connection& conn, const string& config_name,
     DBus::Hoho hoho(call);
     hoho << config_name << description << cleanup << userdata;
 
-    DBus::Message reply = conn.send_and_reply_and_block(call);
+    DBus::Message reply = conn.send_with_reply_and_block(call);
 
     unsigned int number;
 
@@ -191,7 +191,7 @@ command_create_post_xsnapshot(DBus::Connection& conn, const string& config_name,
     DBus::Hoho hoho(call);
     hoho << config_name << prenum << description << cleanup << userdata;
 
-    DBus::Message reply = conn.send_and_reply_and_block(call);
+    DBus::Message reply = conn.send_with_reply_and_block(call);
 
     unsigned int number;
 
@@ -211,7 +211,7 @@ command_delete_xsnapshots(DBus::Connection& conn, const string& config_name,
     DBus::Hoho hoho(call);
     hoho << config_name << nums;
 
-    conn.send_and_reply_and_block(call);
+    conn.send_with_reply_and_block(call);
 }
 
 
@@ -224,7 +224,7 @@ command_mount_xsnapshots(DBus::Connection& conn, const string& config_name,
     DBus::Hoho hoho(call);
     hoho << config_name << num;
 
-    conn.send_and_reply_and_block(call);
+    conn.send_with_reply_and_block(call);
 }
 
 
@@ -237,7 +237,7 @@ command_umount_xsnapshots(DBus::Connection& conn, const string& config_name,
     DBus::Hoho hoho(call);
     hoho << config_name << num;
 
-    conn.send_and_reply_and_block(call);
+    conn.send_with_reply_and_block(call);
 }
 
 
@@ -250,7 +250,7 @@ command_create_xcomparison(DBus::Connection& conn, const string& config_name, un
     DBus::Hoho hoho(call);
     hoho << config_name << number1 << number2;
 
-    conn.send_and_reply_and_block(call);
+    conn.send_with_reply_and_block(call);
 }
 
 
@@ -263,7 +263,7 @@ command_get_xfiles(DBus::Connection& conn, const string& config_name, unsigned i
     DBus::Hoho hoho(call);
     hoho << config_name << number1 << number2;
 
-    DBus::Message reply = conn.send_and_reply_and_block(call);
+    DBus::Message reply = conn.send_with_reply_and_block(call);
 
     list<XFile> files;
 
@@ -283,7 +283,7 @@ command_get_xdiff(DBus::Connection& conn, const string& config_name, unsigned in
     DBus::Hoho hoho(call);
     hoho << config_name << number1 << number2 << name << options;
 
-    DBus::Message reply = conn.send_and_reply_and_block(call);
+    DBus::Message reply = conn.send_with_reply_and_block(call);
 
     vector<string> files;
 
@@ -303,7 +303,7 @@ command_set_xundo(DBus::Connection& conn, const string& config_name, unsigned in
     DBus::Hoho hoho(call);
     hoho << config_name << number1 << number2 << undos;
 
-    conn.send_and_reply_and_block(call);
+    conn.send_with_reply_and_block(call);
 }
 
 
@@ -316,7 +316,7 @@ command_set_xundo_all(DBus::Connection& conn, const string& config_name, unsigne
     DBus::Hoho hoho(call);
     hoho << config_name << number1 << number2 << undo;
 
-    conn.send_and_reply_and_block(call);
+    conn.send_with_reply_and_block(call);
 }
 
 
@@ -329,7 +329,7 @@ command_get_xundo_steps(DBus::Connection& conn, const string& config_name, unsig
     DBus::Hoho hoho(call);
     hoho << config_name << number1 << number2;
 
-    DBus::Message reply = conn.send_and_reply_and_block(call);
+    DBus::Message reply = conn.send_with_reply_and_block(call);
 
     vector<XUndoStep> undo_steps;
 
@@ -349,7 +349,7 @@ command_do_xundo_step(DBus::Connection& conn, const string& config_name, unsigne
     DBus::Hoho hoho(call);
     hoho << config_name << number1 << number2 << undo_step;
 
-    DBus::Message reply = conn.send_and_reply_and_block(call);
+    DBus::Message reply = conn.send_with_reply_and_block(call);
 
     bool ret;
 
@@ -365,7 +365,7 @@ command_xdebug(DBus::Connection& conn)
 {
     DBus::MessageMethodCall call(SERVICE, OBJECT, INTERFACE, "Debug");
 
-    DBus::Message reply = conn.send_and_reply_and_block(call);
+    DBus::Message reply = conn.send_with_reply_and_block(call);
 
     vector<string> lines;
 
index ef492eca0043695136ef0b523cb733a86cd35fe9..05430c298cf987ce21ba84f79b3a62859a1b9606 100644 (file)
@@ -58,6 +58,8 @@ namespace DBus
     void
     Connection::request_name(const char* name, unsigned int flags)
     {
+       boost::lock_guard<boost::mutex> lock(mutex);
+
        DBusError err;
        dbus_error_init(&err);
 
@@ -78,6 +80,8 @@ namespace DBus
     void
     Connection::read_write(int timeout)
     {
+       // TODO
+
        dbus_connection_read_write(conn, timeout);
     }
 
@@ -85,6 +89,8 @@ namespace DBus
     void
     Connection::send(Message& m)
     {
+       boost::lock_guard<boost::mutex> lock(mutex);
+
        if (!dbus_connection_send(conn, m.get_message(), NULL))
        {
            throw FatalException();
@@ -93,8 +99,10 @@ namespace DBus
 
 
     Message
-    Connection::send_and_reply_and_block(Message& m)
+    Connection::send_with_reply_and_block(Message& m)
     {
+       boost::lock_guard<boost::mutex> lock(mutex);
+
        DBusError err;
        dbus_error_init(&err);
 
@@ -113,6 +121,8 @@ namespace DBus
     void
     Connection::add_match(const char* rule)
     {
+       boost::lock_guard<boost::mutex> lock(mutex);
+
        DBusError err;
        dbus_error_init(&err);
 
@@ -128,6 +138,8 @@ namespace DBus
     unsigned long
     Connection::get_unix_userid(const Message& m)
     {
+       boost::lock_guard<boost::mutex> lock(mutex);
+
        string sender = m.get_sender();
        if (sender.empty())
        {
@@ -149,10 +161,8 @@ namespace DBus
 
 
     string
-    Connection::get_unix_username(const Message& m)
+    Connection::get_unix_username(unsigned long userid)
     {
-       unsigned long userid = get_unix_userid(m);
-
        long bufsize = sysconf(_SC_GETPW_R_SIZE_MAX);
        char* buf = (char*) malloc(bufsize);
        if (!buf)
index d4a3c531a3643495d9917345c4f96cd08d09adde..0f77a3030ccfdb7cd7375d04bbf199a852406f84 100644 (file)
@@ -27,6 +27,7 @@
 #include <dbus/dbus.h>
 
 #include <boost/noncopyable.hpp>
+#include <boost/thread.hpp>
 
 #include "DBusMessage.h"
 
@@ -49,12 +50,14 @@ namespace DBus
 
        void send(Message& m);
 
-       Message send_and_reply_and_block(Message& m);
+       Message send_with_reply_and_block(Message& m);
 
        void add_match(const char* rule);
 
        unsigned long get_unix_userid(const Message& m);
-       string get_unix_username(const Message& m);
+       static string get_unix_username(unsigned long userid); // TODO
+
+       boost::mutex mutex;
 
     private:
 
index 723833de4ded99e9c44ba4de18a2f4acd739d330..9f29c4d353c1ffed8e5c586bf62310dfc5394a76 100644 (file)
@@ -96,8 +96,6 @@ Client::has_lock(const string& config_name) const
 void
 Client::add_task(DBus::Connection& conn, DBus::Message& msg)
 {
-#if 1
-
     if (!t)
        t = new boost::thread(boost::bind(&Client::worker, this));
 
@@ -106,12 +104,6 @@ Client::add_task(DBus::Connection& conn, DBus::Message& msg)
     l.unlock();
 
     c->notify_one();
-
-#else
-
-    dispatch(conn, msg);
-
-#endif
 }
 
 
@@ -149,6 +141,8 @@ Clients::find(const string& name)
 Clients::iterator
 Clients::add(const string& name)
 {
+    assert(find(name) == entries.end());
+
     entries.push_back(Client(name));
     return --entries.end();
 }
index e3f7c3c4219aa439e932d2b14c7e2b4e14d2d5e3..b85cdf4f912623e1936d3d24fff613588f44a8da 100644 (file)
@@ -53,6 +53,13 @@ class Commands
 {
 public:
 
+    void signal_config_created(DBus::Connection& conn, const string& config_name);
+    void signal_config_deleted(DBus::Connection& conn, const string& config_name);
+    void signal_snapshot_created(DBus::Connection& conn, const string& config_name,
+                                unsigned int num);
+    void signal_snapshots_deleted(DBus::Connection& conn, const string& config_name,
+                                 list<dbus_uint32_t> nums);
+
     void list_configs(DBus::Connection& conn, DBus::Message& msg);
     void get_config(DBus::Connection& conn, DBus::Message& msg);
     void create_config(DBus::Connection& conn, DBus::Message& msg);
index bc43cbc991bd00355f69eaf198a4df23f82ba7c4..3af7bac026307d8fc98013f87b543830e23e12ad 100644 (file)
@@ -57,9 +57,6 @@ using namespace snapper;
 Clients clients;
 
 
-boost::mutex dbus_mutex;
-
-
 void
 reply_to_introspect(DBus::Connection& conn, DBus::Message& msg)
 {
@@ -269,7 +266,7 @@ check_permission(DBus::Connection& conn, DBus::Message& msg, const string& confi
            if (uid == 0)
                return;
 
-           string username = conn.get_unix_username(msg);
+           string username = DBus::Connection::get_unix_username(uid);
 
            map<string, string>::const_iterator pos = it->raw.find("USERS");
            if (pos == it->raw.end())
@@ -315,7 +312,7 @@ check_lock(DBus::Connection& conn, DBus::Message& msg, const string& config_name
 
 
 void
-send_signal_config_created(DBus::Connection& conn, const string& config_name)
+Commands::signal_config_created(DBus::Connection& conn, const string& config_name)
 {
     DBus::MessageSignal msg(PATH, INTERFACE, "ConfigCreated");
 
@@ -327,7 +324,7 @@ send_signal_config_created(DBus::Connection& conn, const string& config_name)
 
 
 void
-send_signal_config_deleted(DBus::Connection& conn, const string& config_name)
+Commands::signal_config_deleted(DBus::Connection& conn, const string& config_name)
 {
     DBus::MessageSignal msg(PATH, INTERFACE, "ConfigDeleted");
 
@@ -339,8 +336,8 @@ send_signal_config_deleted(DBus::Connection& conn, const string& config_name)
 
 
 void
-send_signal_snapshot_created(DBus::Connection& conn, const string& config_name,
-                            unsigned int num)
+Commands::signal_snapshot_created(DBus::Connection& conn, const string& config_name,
+                                 unsigned int num)
 {
     DBus::MessageSignal msg(PATH, INTERFACE, "SnapshotCreated");
 
@@ -352,8 +349,8 @@ send_signal_snapshot_created(DBus::Connection& conn, const string& config_name,
 
 
 void
-send_signal_snapshots_deleted(DBus::Connection& conn, const string& config_name,
-                             list<dbus_uint32_t> nums)
+Commands::signal_snapshots_deleted(DBus::Connection& conn, const string& config_name,
+                                  list<dbus_uint32_t> nums)
 {
     DBus::MessageSignal msg(PATH, INTERFACE, "SnapshotsDeleted");
 
@@ -369,8 +366,6 @@ Commands::list_configs(DBus::Connection& conn, DBus::Message& msg)
 {
     y2mil("ListConfigs");
 
-    boost::unique_lock<boost::mutex> dbus_lock(dbus_mutex);
-
     list<ConfigInfo> config_infos = Snapper::getConfigs();
 
     DBus::MessageMethodReturn reply(msg);
@@ -392,8 +387,6 @@ Commands::get_config(DBus::Connection& conn, DBus::Message& msg)
 
     y2mil("GetConfig config_name:" << config_name);
 
-    boost::unique_lock<boost::mutex> dbus_lock(dbus_mutex);
-
     check_permission(conn, msg, config_name);
 
     Snapper* snapper = getSnapper(config_name);
@@ -432,7 +425,7 @@ Commands::create_config(DBus::Connection& conn, DBus::Message& msg)
 
     conn.send(reply);
 
-    send_signal_config_created(conn, config_name);
+    signal_config_created(conn, config_name);
 }
 
 
@@ -454,7 +447,7 @@ Commands::delete_config(DBus::Connection& conn, DBus::Message& msg)
 
     conn.send(reply);
 
-    send_signal_config_deleted(conn, config_name);
+    signal_config_deleted(conn, config_name);
 }
 
 
@@ -514,8 +507,6 @@ Commands::list_snapshots(DBus::Connection& conn, DBus::Message& msg)
 
     y2mil("ListSnapshots config_name:" << config_name);
 
-    boost::unique_lock<boost::mutex> dbus_lock(dbus_mutex);
-
     check_permission(conn, msg, config_name);
 
     Snapper* snapper = getSnapper(config_name);
@@ -540,8 +531,6 @@ Commands::get_snapshot(DBus::Connection& conn, DBus::Message& msg)
 
     y2mil("GetSnapshot config_name:" << config_name << " num:" << num);
 
-    boost::unique_lock<boost::mutex> dbus_lock(dbus_mutex);
-
     check_permission(conn, msg, config_name);
 
     Snapper* snapper = getSnapper(config_name);
@@ -622,7 +611,7 @@ Commands::create_single_snapshot(DBus::Connection& conn, DBus::Message& msg)
 
     conn.send(reply);
 
-    send_signal_snapshot_created(conn, config_name, snap1->getNum());
+    signal_snapshot_created(conn, config_name, snap1->getNum());
 }
 
 
@@ -656,7 +645,7 @@ Commands::create_pre_snapshot(DBus::Connection& conn, DBus::Message& msg)
 
     conn.send(reply);
 
-    send_signal_snapshot_created(conn, config_name, snap1->getNum());
+    signal_snapshot_created(conn, config_name, snap1->getNum());
 }
 
 
@@ -695,7 +684,7 @@ Commands::create_post_snapshot(DBus::Connection& conn, DBus::Message& msg)
 
     conn.send(reply);
 
-    send_signal_snapshot_created(conn, config_name, snap2->getNum());
+    signal_snapshot_created(conn, config_name, snap2->getNum());
 }
 
 
@@ -728,7 +717,7 @@ Commands::delete_snapshots(DBus::Connection& conn, DBus::Message& msg)
 
     conn.send(reply);
 
-    send_signal_snapshots_deleted(conn, config_name, nums);
+    signal_snapshots_deleted(conn, config_name, nums);
 }
 
 
@@ -1201,7 +1190,7 @@ listen(DBus::Connection& conn)
     {
        boost::this_thread::sleep(boost::posix_time::milliseconds(100)); // TODO
 
-       boost::unique_lock<boost::mutex> dbus_lock(dbus_mutex);
+       boost::unique_lock<boost::mutex> dbus_lock(conn.mutex);
 
        conn.read_write(10);    // TODO