[banshee] DBusConnection: avoid code duplication in GrabDefaultName()
- From: Andrés Aragoneses <aaragoneses src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [banshee] DBusConnection: avoid code duplication in GrabDefaultName()
- Date: Sun, 23 Feb 2014 12:23:05 +0000 (UTC)
commit 380b4787d451034cb7312afa90a58aa589323cc5
Author: Andrés G. Aragoneses <knocte gmail com>
Date: Sun Feb 23 13:22:55 2014 +0100
DBusConnection: avoid code duplication in GrabDefaultName()
The GrabDefaultName() method [1] was super similar to the
Connect(serviceName) [2] one when it was introduced [3].
The former returns a bool value that tells you if the app
being launched is the primary instance or not (therefore
it returns true if DBus is not enabled, or if it can connect
to DBus and there is no other instance running).
However, the latter returns true if it's the primary instance
*and* DBus is enabled (so for the case in which DBus is disabled
GrabDefaultName() returns true while Connect() returns false),
so you may think that both similar methods are needed.
But Connect() method thankfully informs us if DBus connection
failed by mutating the 'enabled' field to false, so we have
extra info besides its return value. Thanks to this, we can
implement GrabDefaultName() in a way in which there is no code
duplication with Connect().
[1]
https://git.gnome.org/browse/banshee/tree/src/Core/Banshee.Services/Banshee.ServiceStack/DBusConnection.cs?id=2.9.0#n129
[2]
https://git.gnome.org/browse/banshee/tree/src/Core/Banshee.Services/Banshee.ServiceStack/DBusConnection.cs?id=2.9.0#n97
[3] https://git.gnome.org/browse/banshee/commit/?id=b780ebced90e5aae3464e16fb686f25ddd21fd9b
.../Banshee.ServiceStack/DBusConnection.cs | 22 +++++++++----------
1 files changed, 10 insertions(+), 12 deletions(-)
---
diff --git a/src/Core/Banshee.Services/Banshee.ServiceStack/DBusConnection.cs
b/src/Core/Banshee.Services/Banshee.ServiceStack/DBusConnection.cs
index 33f91cb..ae2760d 100644
--- a/src/Core/Banshee.Services/Banshee.ServiceStack/DBusConnection.cs
+++ b/src/Core/Banshee.Services/Banshee.ServiceStack/DBusConnection.cs
@@ -1,10 +1,14 @@
//
// DBusConnection.cs
//
-// Author:
+// Authors:
// Aaron Bockover <abockover novell com>
+// Bertrand Lorentz <bertrand lorentz gmail com>
+// Andrés G. Aragoneses <knocte gmail com>
//
// Copyright (C) 2008 Novell, Inc.
+// Copyright (C) 2012 Bertrand Lorentz
+// Copyright (C) 2014 Andrés G. Aragoneses
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
@@ -33,7 +37,6 @@ using DBus;
using org.freedesktop.DBus;
using Hyena;
-using Banshee.Base;
namespace Banshee.ServiceStack
{
@@ -134,19 +137,14 @@ namespace Banshee.ServiceStack
return primary_instance;
}
- connect_tried = true;
+ bool enabled_and_primary_owner = Connect (DefaultServiceName);
- try {
- if (Connect (DefaultServiceName, true) == RequestNameReply.PrimaryOwner) {
- active_connections.Add (DefaultServiceName);
- } else {
- primary_instance = false;
- }
- } catch (Exception e) {
- Log.Exception ("DBus support could not be started. Disabling for this session.", e);
- enabled = false;
+ // if DBus failed, enabled field has mutated from true to false during Connect()
+ if (!enabled) {
+ return primary_instance;
}
+ primary_instance = enabled_and_primary_owner;
return primary_instance;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]