1 // Copyright 2006 Alp Toker <alp@atoker.com>
2 // This software is made available under the MIT License
3 // See COPYING for details
6 using System
.Collections
.Generic
;
7 using org
.freedesktop
.DBus
;
13 public sealed class Bus
: Connection
15 static Bus systemBus
= null;
16 public static Bus System
19 if (systemBus
== null) {
21 if (Address
.StarterBusType
== "system")
24 systemBus
= Bus
.Open (Address
.System
);
25 } catch (Exception e
) {
26 throw new Exception ("Unable to open the system message bus.", e
);
34 static Bus sessionBus
= null;
35 public static Bus Session
38 if (sessionBus
== null) {
40 if (Address
.StarterBusType
== "session")
43 sessionBus
= Bus
.Open (Address
.Session
);
44 } catch (Exception e
) {
45 throw new Exception ("Unable to open the session message bus.", e
);
53 //TODO: parsing of starter bus type, or maybe do this another way
54 static Bus starterBus
= null;
55 public static Bus Starter
58 if (starterBus
== null) {
60 starterBus
= Bus
.Open (Address
.Starter
);
61 } catch (Exception e
) {
62 throw new Exception ("Unable to open the starter message bus.", e
);
70 //public static readonly Bus Session = null;
72 //TODO: use the guid, not the whole address string
73 //TODO: consider what happens when a connection has been closed
74 static Dictionary
<string,Bus
> buses
= new Dictionary
<string,Bus
> ();
76 //public static Connection Open (string address)
77 public static new Bus
Open (string address
)
80 throw new ArgumentNullException ("address");
82 if (buses
.ContainsKey (address
))
83 return buses
[address
];
85 Bus bus
= new Bus (address
);
93 static readonly string DBusName
= "org.freedesktop.DBus";
94 static readonly ObjectPath DBusPath
= new ObjectPath ("/org/freedesktop/DBus");
96 public Bus (string address
) : base (address
)
98 bus
= GetObject
<IBus
> (DBusName
, DBusPath
);
102 public Bus (Transport trans
) : base (trans
)
106 bus
= GetObject
<IBus
> (DBusName
, DBusPath
);
110 //should this be public?
111 //as long as Bus subclasses Connection, having a Register with a completely different meaning is bad
114 if (unique_name
!= null)
115 throw new Exception ("Bus already has a unique name");
117 unique_name
= bus
.Hello ();
120 public string GetUnixUserName (string name
)
122 return bus
.GetConnectionUnixUserName (name
);
125 public ulong GetUnixUser (string name
)
127 return bus
.GetConnectionUnixUser (name
);
130 public string GetCert (string name
)
132 return bus
.GetConnectionCert (name
);
135 public string GetCertFingerprint (string name
)
137 return bus
.GetConnectionCertFingerprint (name
);
140 public RequestNameReply
RequestName (string name
)
142 return RequestName (name
, NameFlag
.None
);
145 public RequestNameReply
RequestName (string name
, NameFlag flags
)
147 return bus
.RequestName (name
, flags
);
150 public ReleaseNameReply
ReleaseName (string name
)
152 return bus
.ReleaseName (name
);
155 public bool NameHasOwner (string name
)
157 return bus
.NameHasOwner (name
);
160 public StartReply
StartServiceByName (string name
)
162 return StartServiceByName (name
, 0);
165 public StartReply
StartServiceByName (string name
, uint flags
)
167 return bus
.StartServiceByName (name
, flags
);
170 internal protected override void AddMatch (string rule
)
175 internal protected override void RemoveMatch (string rule
)
177 bus
.RemoveMatch (rule
);
180 string unique_name
= null;
181 public string UniqueName
186 if (unique_name
!= null)
187 throw new Exception ("Unique name can only be set once");