4 // Utility methods for dealing with DBus
7 static string DbusConnName
= "vx.versaplexd";
8 static string DbusInterface
= "vx.db";
9 static readonly ObjectPath DbusObjPath
;
13 DbusObjPath
= new ObjectPath("/db");
16 // Fishes an error name and error message out of a DBus message and
17 // returns them in an exception.
18 public static Exception
GetDbusException(Message reply
)
21 if (!reply
.Header
.Fields
.TryGetValue(FieldCode
.ErrorName
, out errname
))
22 return new Exception("Could not find error name in DBus message.");
25 if (!reply
.Header
.Fields
.TryGetValue(FieldCode
.Signature
, out errsig
) ||
26 errsig
.ToString() != "s")
27 return new DbusError(errname
.ToString());
29 MessageReader mr
= new MessageReader(reply
);
31 string errmsg
= mr
.ReadString();
33 return new DbusError(errname
.ToString() + ": " + errmsg
.ToString());
36 // Create a method call using the default connection, object path, and
38 public static Message
CreateMethodCall(Bus bus
,
39 string member
, string signature
)
41 return CreateMethodCall(bus
, DbusConnName
, DbusObjPath
,
42 DbusInterface
, member
, signature
);
45 public static Message
CreateMethodCall(Bus bus
, string destination
,
46 ObjectPath path
, string iface
, string member
, string signature
)
48 Message msg
= new Message();
50 msg
.Header
.MessageType
= MessageType
.MethodCall
;
51 msg
.Header
.Flags
= HeaderFlag
.None
;
52 msg
.Header
.Fields
[FieldCode
.Path
] = path
;
53 msg
.Header
.Fields
[FieldCode
.Member
] = member
;
55 if (destination
!= null && destination
!= "")
56 msg
.Header
.Fields
[FieldCode
.Destination
] = destination
;
58 if (iface
!= null && iface
!= "")
59 msg
.Header
.Fields
[FieldCode
.Interface
] = iface
;
61 if (signature
!= null && signature
!= "")
62 msg
.Header
.Fields
[FieldCode
.Signature
] = new Signature(signature
);