{
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;
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;
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);
}
DBus::Hoho hoho(call);
hoho << config_name;
- conn.send_and_reply_and_block(call);
+ conn.send_with_reply_and_block(call);
}
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;
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;
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);
}
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;
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;
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;
DBus::Hoho hoho(call);
hoho << config_name << nums;
- conn.send_and_reply_and_block(call);
+ conn.send_with_reply_and_block(call);
}
DBus::Hoho hoho(call);
hoho << config_name << num;
- conn.send_and_reply_and_block(call);
+ conn.send_with_reply_and_block(call);
}
DBus::Hoho hoho(call);
hoho << config_name << num;
- conn.send_and_reply_and_block(call);
+ conn.send_with_reply_and_block(call);
}
DBus::Hoho hoho(call);
hoho << config_name << number1 << number2;
- conn.send_and_reply_and_block(call);
+ conn.send_with_reply_and_block(call);
}
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;
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;
DBus::Hoho hoho(call);
hoho << config_name << number1 << number2 << undos;
- conn.send_and_reply_and_block(call);
+ conn.send_with_reply_and_block(call);
}
DBus::Hoho hoho(call);
hoho << config_name << number1 << number2 << undo;
- conn.send_and_reply_and_block(call);
+ conn.send_with_reply_and_block(call);
}
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;
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;
{
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;
void
Connection::request_name(const char* name, unsigned int flags)
{
+ boost::lock_guard<boost::mutex> lock(mutex);
+
DBusError err;
dbus_error_init(&err);
void
Connection::read_write(int timeout)
{
+ // TODO
+
dbus_connection_read_write(conn, timeout);
}
void
Connection::send(Message& m)
{
+ boost::lock_guard<boost::mutex> lock(mutex);
+
if (!dbus_connection_send(conn, m.get_message(), NULL))
{
throw FatalException();
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);
void
Connection::add_match(const char* rule)
{
+ boost::lock_guard<boost::mutex> lock(mutex);
+
DBusError err;
dbus_error_init(&err);
unsigned long
Connection::get_unix_userid(const Message& m)
{
+ boost::lock_guard<boost::mutex> lock(mutex);
+
string sender = m.get_sender();
if (sender.empty())
{
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)
#include <dbus/dbus.h>
#include <boost/noncopyable.hpp>
+#include <boost/thread.hpp>
#include "DBusMessage.h"
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:
void
Client::add_task(DBus::Connection& conn, DBus::Message& msg)
{
-#if 1
-
if (!t)
t = new boost::thread(boost::bind(&Client::worker, this));
l.unlock();
c->notify_one();
-
-#else
-
- dispatch(conn, msg);
-
-#endif
}
Clients::iterator
Clients::add(const string& name)
{
+ assert(find(name) == entries.end());
+
entries.push_back(Client(name));
return --entries.end();
}
{
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);
Clients clients;
-boost::mutex dbus_mutex;
-
-
void
reply_to_introspect(DBus::Connection& conn, DBus::Message& msg)
{
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())
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");
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");
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");
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");
{
y2mil("ListConfigs");
- boost::unique_lock<boost::mutex> dbus_lock(dbus_mutex);
-
list<ConfigInfo> config_infos = Snapper::getConfigs();
DBus::MessageMethodReturn reply(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);
conn.send(reply);
- send_signal_config_created(conn, config_name);
+ signal_config_created(conn, config_name);
}
conn.send(reply);
- send_signal_config_deleted(conn, config_name);
+ signal_config_deleted(conn, config_name);
}
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);
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);
conn.send(reply);
- send_signal_snapshot_created(conn, config_name, snap1->getNum());
+ signal_snapshot_created(conn, config_name, snap1->getNum());
}
conn.send(reply);
- send_signal_snapshot_created(conn, config_name, snap1->getNum());
+ signal_snapshot_created(conn, config_name, snap1->getNum());
}
conn.send(reply);
- send_signal_snapshot_created(conn, config_name, snap2->getNum());
+ signal_snapshot_created(conn, config_name, snap2->getNum());
}
conn.send(reply);
- send_signal_snapshots_deleted(conn, config_name, nums);
+ signal_snapshots_deleted(conn, config_name, nums);
}
{
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