summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authorRyan Lortie <desrt@desrt.ca>2010-07-19 13:52:33 -0400
committerRyan Lortie <desrt@desrt.ca>2010-07-19 13:52:33 -0400
commit1e93f987b56bd157f74808e0d0eb4d274437ba68 (patch)
tree1add3f5ba93fe1555d6d51c2d6868b111b20527a /client
parent78084a0dbfd705f214f79f8e254a54f8cb1a391f (diff)
downloaddconf-1e93f987b56bd157f74808e0d0eb4d274437ba68.tar.gz
bring service API in line with the client
also, cache GDBusConnections in the client since GDBus doesn't keep them alive for us.
Diffstat (limited to 'client')
-rw-r--r--client/dconf-client.vala48
1 files changed, 33 insertions, 15 deletions
diff --git a/client/dconf-client.vala b/client/dconf-client.vala
index 0e71b7c..5db8767 100644
--- a/client/dconf-client.vala
+++ b/client/dconf-client.vala
@@ -3,22 +3,26 @@ namespace DConf {
public delegate void WatchFunc (DConf.Client client, string path, string[] items, string tag);
public class Client : Object {
- Engine engine;
+ DBusConnection? session;
+ DBusConnection? system;
WatchFunc watch_func;
-
- static BusType get_bus_type (EngineMessage dcem) {
- switch (dcem.bus_type) {
- case 'e':
- return BusType.SESSION;
- case 'y':
- return BusType.SYSTEM;
- default:
- assert_not_reached ();
- }
- }
+ Engine engine;
void call_sync (EngineMessage dcem, out string tag, Cancellable? cancellable) throws Error {
- var connection = Bus.get_sync (get_bus_type (dcem), cancellable);
+ DBusConnection connection;
+
+ if (dcem.bus_type == 'e') {
+ if (session == null) {
+ session = Bus.get_sync (BusType.SESSION, cancellable);
+ }
+ connection = session;
+ } else {
+ assert (dcem.bus_type == 'y');
+ if (system == null) {
+ system = Bus.get_sync (BusType.SYSTEM, cancellable);
+ }
+ connection = system;
+ }
foreach (var message in dcem.body) {
var reply = connection.call_sync (dcem.destination, dcem.object_path, dcem.@interface, dcem.method,
@@ -30,7 +34,20 @@ namespace DConf {
}
async void call_async (EngineMessage dcem, out string tag, Cancellable? cancellable) throws Error {
- var connection = yield Bus.get (get_bus_type (dcem), cancellable);
+ DBusConnection connection;
+
+ if (dcem.bus_type == 'e') {
+ if (session == null) {
+ session = yield Bus.get (BusType.SESSION, cancellable);
+ }
+ connection = session;
+ } else {
+ assert (dcem.bus_type == 'y');
+ if (system == null) {
+ system = yield Bus.get (BusType.SYSTEM, cancellable);
+ }
+ connection = system;
+ }
foreach (var message in dcem.body) {
var reply = yield connection.call (dcem.destination, dcem.object_path, dcem.@interface, dcem.method,
@@ -104,7 +121,8 @@ namespace DConf {
static Variant? service_func (EngineMessage dcem) {
try {
- var connection = Bus.get_sync (get_bus_type (dcem), null);
+ assert (dcem.bus_type == 'e');
+ var connection = Bus.get_sync (BusType.SESSION, null);
return connection.call_sync (dcem.destination, dcem.object_path, dcem.@interface, dcem.method,
dcem.body, dcem.reply_type, DBusCallFlags.NONE, -1, null);
} catch {