Okay, get rid of WvAutoCast.iter() altogether; use GetEnumerator().
[versaplex.git] / versaplexd / vxdbusutils.cs
blobcf6199dd7c37e4a9df5cb9cc361e89d49958e413
1 using System;
2 using Wv;
4 // Utility methods for dealing with DBus
5 class VxDbusUtils
7 static string DbusConnName = "vx.versaplexd";
8 static string DbusInterface = "vx.db";
9 static readonly ObjectPath DbusObjPath;
11 static VxDbusUtils()
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)
20 object errname;
21 if (!reply.Header.Fields.TryGetValue(FieldCode.ErrorName, out errname))
22 return new Exception("Could not find error name in DBus message.");
24 object errsig;
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
37 // interface
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();
49 msg.Connection = bus;
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);
64 return msg;