Added FileDescriptor support
Some DBus methods return file descriptors, such as "org.freedesktop.login1.Manager.Inhibit". This commit adds support for these. I followed the same enum type defining pattern I've seen in the code, such as with InterfaceNames and BusNames, to prevent integers and fileDescriptors implicitly casting to each other. Note that it is kinda hard to test with reading and writing fileDescriptors, as DBus will duplicate the file descriptor when reading, leading to relatively unpredicatable behaviour. I also must admit I focussed most of my attention to reading file descriptors and less to writing file descriptors, as I don't know a good way to test those.
This commit is contained in:
parent
ab994acdb3
commit
3b1cc9b453
3 changed files with 31 additions and 5 deletions
|
@ -55,7 +55,7 @@ template allCanDBus(TS...) {
|
|||
+/
|
||||
package // Don't add to the API yet, 'cause I intend to move it later
|
||||
alias BasicTypes = AliasSeq!(bool, byte, short, ushort, int, uint, long, ulong,
|
||||
double, string, ObjectPath, InterfaceName, BusName);
|
||||
double, string, ObjectPath, InterfaceName, BusName, FileDescriptor);
|
||||
|
||||
template basicDBus(T) {
|
||||
static if (staticIndexOf!(T, BasicTypes) >= 0) {
|
||||
|
@ -104,6 +104,7 @@ unittest {
|
|||
(canDBus!(Tuple!(int[], bool, Variant!short))).assertTrue();
|
||||
(canDBus!(Tuple!(int[], int[string]))).assertTrue();
|
||||
(canDBus!(int[string])).assertTrue();
|
||||
(canDBus!FileDescriptor).assertTrue();
|
||||
}
|
||||
|
||||
string typeSig(T)()
|
||||
|
@ -116,6 +117,8 @@ string typeSig(T)()
|
|||
return "n";
|
||||
} else static if (is(T == ushort)) {
|
||||
return "q";
|
||||
} else static if (is(T == FileDescriptor)) {
|
||||
return "h";
|
||||
} else static if (is(T == int)) {
|
||||
return "i";
|
||||
} else static if (is(T == uint)) {
|
||||
|
@ -217,6 +220,7 @@ unittest {
|
|||
typeSig!bool().assertEqual("b");
|
||||
typeSig!string().assertEqual("s");
|
||||
typeSig!(Variant!int)().assertEqual("v");
|
||||
typeSig!FileDescriptor().assertEqual("h");
|
||||
// enums
|
||||
enum E : byte {
|
||||
a,
|
||||
|
@ -256,9 +260,10 @@ unittest {
|
|||
string d;
|
||||
S1 e;
|
||||
uint f;
|
||||
FileDescriptor g;
|
||||
}
|
||||
|
||||
typeSig!S2.assertEqual("(vs(ids)u)");
|
||||
typeSig!S2.assertEqual("(vs(ids)uh)");
|
||||
// arrays
|
||||
typeSig!(int[]).assertEqual("ai");
|
||||
typeSig!(Variant!int[]).assertEqual("av");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue