Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate code with unix fds #352

Merged
merged 1 commit into from
Aug 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions lib/src/dbus_dart_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ DBusDartType getDartType(DBusSignature signature) {
return DBusSignatureType();
} else if (value == 'v') {
return DBusVariantType();
} else if (value == 'h') {
return DBusUnixFdType();
} else if (value.startsWith('(') && value.endsWith(')')) {
return DBusStructType();
} else if (value.startsWith('a{') && value.endsWith('}')) {
Expand Down Expand Up @@ -259,6 +261,24 @@ class DBusVariantType extends DBusDartType {
}
}

/// Generates Dart code for the Unix FD D-Bus type.
class DBusUnixFdType extends DBusDartType {
@override
String get nativeType {
return 'ResourceHandle';
}

@override
String nativeToDBus(String name) {
return 'DBusUnixFd($name)';
}

@override
String dbusToNative(String name) {
return '$name.asUnixFd()';
}
}

/// Generates Dart code for the struct D-Bus type.
class DBusStructType extends DBusDartType {
@override
Expand Down Expand Up @@ -318,6 +338,8 @@ class DBusArrayType extends DBusDartType {
return 'DBusArray.signature($name)';
case 'v':
return 'DBusArray.variant($name)';
case 'h':
return 'DBusArray.unixFd($name)';
default:
var childType = getDartType(childSignature);
var convertedValue = childType.nativeToDBus('child');
Expand Down Expand Up @@ -354,6 +376,8 @@ class DBusArrayType extends DBusDartType {
return '$name.asSignatureArray().toList()';
case 'v':
return '$name.asVariantArray().toList()';
case 'h':
return '$name.asUnixFdArray().toList()';
default:
var childType = getDartType(childSignature);
var convertedValue = childType.dbusToNative('child');
Expand Down
4 changes: 2 additions & 2 deletions test/generated-code/method-multiple-inputs.client.out
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class ComExampleTest extends DBusRemoteObject {
ComExampleTest(DBusClient client, String destination, DBusObjectPath path) : super(client, name: destination, path: path);

/// Invokes com.example.Test.Hello()
Future<void> callHello(int byte_value, bool boolean_value, int int16_value, int uint16_value, int int32_value, int uint32_value, int int64_value, int uint64_value, double double_value, String string_value, String object_path_value, DBusSignature signature_value, DBusValue variant_value, DBusStruct struct_value, List<int> array_value_y, List<bool> array_value_b, List<int> array_value_n, List<int> array_value_q, List<int> array_value_u, List<int> array_value_n, List<int> array_value_x, List<int> array_value_t, List<double> array_value_d, List<String> array_value_s, List<String> array_value_o, List<DBusSignature> array_value_g, List<DBusValue> array_value_v, List<DBusStruct> array_value_struct, List<List<String>> array_value_array, Map<String, DBusValue> dict_value_sv, Map<int, String> dict_value_us, Map<String, Map<String, DBusValue>> dict_value_dict, {bool noAutoStart = false, bool allowInteractiveAuthorization = false}) async {
await callMethod('com.example.Test', 'Hello', [DBusByte(byte_value), DBusBoolean(boolean_value), DBusInt16(int16_value), DBusUint16(uint16_value), DBusInt32(int32_value), DBusUint32(uint32_value), DBusInt64(int64_value), DBusUint64(uint64_value), DBusDouble(double_value), DBusString(string_value), DBusObjectPath(object_path_value), signature_value, DBusVariant(variant_value), struct_value, DBusArray.byte(array_value_y), DBusArray.boolean(array_value_b), DBusArray.int16(array_value_n), DBusArray.uint16(array_value_q), DBusArray.int32(array_value_u), DBusArray.uint32(array_value_n), DBusArray.int64(array_value_x), DBusArray.uint64(array_value_t), DBusArray.double(array_value_d), DBusArray.string(array_value_s), DBusArray.objectPath(array_value_o), DBusArray.signature(array_value_g), DBusArray.variant(array_value_v), DBusArray(DBusSignature('(si)'), array_value_struct.map((child) => child)), DBusArray(DBusSignature('as'), array_value_array.map((child) => DBusArray.string(child))), DBusDict.stringVariant(dict_value_sv), DBusDict(DBusSignature('u'), DBusSignature('s'), dict_value_us.map((key, value) => MapEntry(DBusUint32(key), DBusString(value)))), DBusDict(DBusSignature('s'), DBusSignature('a{sv}'), dict_value_dict.map((key, value) => MapEntry(DBusString(key), DBusDict.stringVariant(value))))], replySignature: DBusSignature(''), noAutoStart: noAutoStart, allowInteractiveAuthorization: allowInteractiveAuthorization);
Future<void> callHello(int byte_value, bool boolean_value, int int16_value, int uint16_value, int int32_value, int uint32_value, int int64_value, int uint64_value, double double_value, String string_value, String object_path_value, DBusSignature signature_value, DBusValue variant_value, ResourceHandle unix_fd_value, DBusStruct struct_value, List<int> array_value_y, List<bool> array_value_b, List<int> array_value_n, List<int> array_value_q, List<int> array_value_u, List<int> array_value_n, List<int> array_value_x, List<int> array_value_t, List<double> array_value_d, List<String> array_value_s, List<String> array_value_o, List<DBusSignature> array_value_g, List<DBusValue> array_value_v, List<ResourceHandle> array_value_h, List<DBusStruct> array_value_struct, List<List<String>> array_value_array, Map<String, DBusValue> dict_value_sv, Map<int, String> dict_value_us, Map<String, Map<String, DBusValue>> dict_value_dict, {bool noAutoStart = false, bool allowInteractiveAuthorization = false}) async {
await callMethod('com.example.Test', 'Hello', [DBusByte(byte_value), DBusBoolean(boolean_value), DBusInt16(int16_value), DBusUint16(uint16_value), DBusInt32(int32_value), DBusUint32(uint32_value), DBusInt64(int64_value), DBusUint64(uint64_value), DBusDouble(double_value), DBusString(string_value), DBusObjectPath(object_path_value), signature_value, DBusVariant(variant_value), DBusUnixFd(unix_fd_value), struct_value, DBusArray.byte(array_value_y), DBusArray.boolean(array_value_b), DBusArray.int16(array_value_n), DBusArray.uint16(array_value_q), DBusArray.int32(array_value_u), DBusArray.uint32(array_value_n), DBusArray.int64(array_value_x), DBusArray.uint64(array_value_t), DBusArray.double(array_value_d), DBusArray.string(array_value_s), DBusArray.objectPath(array_value_o), DBusArray.signature(array_value_g), DBusArray.variant(array_value_v), DBusArray.unixFd(array_value_h), DBusArray(DBusSignature('(si)'), array_value_struct.map((child) => child)), DBusArray(DBusSignature('as'), array_value_array.map((child) => DBusArray.string(child))), DBusDict.stringVariant(dict_value_sv), DBusDict(DBusSignature('u'), DBusSignature('s'), dict_value_us.map((key, value) => MapEntry(DBusUint32(key), DBusString(value)))), DBusDict(DBusSignature('s'), DBusSignature('a{sv}'), dict_value_dict.map((key, value) => MapEntry(DBusString(key), DBusDict.stringVariant(value))))], replySignature: DBusSignature(''), noAutoStart: noAutoStart, allowInteractiveAuthorization: allowInteractiveAuthorization);
}
}
2 changes: 2 additions & 0 deletions test/generated-code/method-multiple-inputs.in
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<arg name="object_path_value" type="o" direction="in"/>
<arg name="signature_value" type="g" direction="in"/>
<arg name="variant_value" type="v" direction="in"/>
<arg name="unix_fd_value" type="h" direction="in"/>
<arg name="struct_value" type="(si)" direction="in"/>
<arg name="array_value_y" type="ay" direction="in"/>
<arg name="array_value_b" type="ab" direction="in"/>
Expand All @@ -28,6 +29,7 @@
<arg name="array_value_o" type="ao" direction="in"/>
<arg name="array_value_g" type="ag" direction="in"/>
<arg name="array_value_v" type="av" direction="in"/>
<arg name="array_value_h" type="ah" direction="in"/>
<arg name="array_value_struct" type="a(si)" direction="in"/>
<arg name="array_value_array" type="aas" direction="in"/>
<arg name="dict_value_sv" type="a{sv}" direction="in"/>
Expand Down
8 changes: 4 additions & 4 deletions test/generated-code/method-multiple-inputs.server.out
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@ class ComExampleTest extends DBusObject {
ComExampleTest({DBusObjectPath path = const DBusObjectPath.unchecked('/')}) : super(path);

/// Implementation of com.example.Test.Hello()
Future<DBusMethodResponse> doHello(int byte_value, bool boolean_value, int int16_value, int uint16_value, int int32_value, int uint32_value, int int64_value, int uint64_value, double double_value, String string_value, String object_path_value, DBusSignature signature_value, DBusValue variant_value, DBusStruct struct_value, List<int> array_value_y, List<bool> array_value_b, List<int> array_value_n, List<int> array_value_q, List<int> array_value_u, List<int> array_value_n, List<int> array_value_x, List<int> array_value_t, List<double> array_value_d, List<String> array_value_s, List<String> array_value_o, List<DBusSignature> array_value_g, List<DBusValue> array_value_v, List<DBusStruct> array_value_struct, List<List<String>> array_value_array, Map<String, DBusValue> dict_value_sv, Map<int, String> dict_value_us, Map<String, Map<String, DBusValue>> dict_value_dict) async {
Future<DBusMethodResponse> doHello(int byte_value, bool boolean_value, int int16_value, int uint16_value, int int32_value, int uint32_value, int int64_value, int uint64_value, double double_value, String string_value, String object_path_value, DBusSignature signature_value, DBusValue variant_value, ResourceHandle unix_fd_value, DBusStruct struct_value, List<int> array_value_y, List<bool> array_value_b, List<int> array_value_n, List<int> array_value_q, List<int> array_value_u, List<int> array_value_n, List<int> array_value_x, List<int> array_value_t, List<double> array_value_d, List<String> array_value_s, List<String> array_value_o, List<DBusSignature> array_value_g, List<DBusValue> array_value_v, List<ResourceHandle> array_value_h, List<DBusStruct> array_value_struct, List<List<String>> array_value_array, Map<String, DBusValue> dict_value_sv, Map<int, String> dict_value_us, Map<String, Map<String, DBusValue>> dict_value_dict) async {
return DBusMethodErrorResponse.failed('com.example.Test.Hello() not implemented');
}

@override
List<DBusIntrospectInterface> introspect() {
return [DBusIntrospectInterface('com.example.Test', methods: [DBusIntrospectMethod('Hello', args: [DBusIntrospectArgument(DBusSignature('y'), DBusArgumentDirection.in_, name: 'byte_value'), DBusIntrospectArgument(DBusSignature('b'), DBusArgumentDirection.in_, name: 'boolean_value'), DBusIntrospectArgument(DBusSignature('n'), DBusArgumentDirection.in_, name: 'int16_value'), DBusIntrospectArgument(DBusSignature('q'), DBusArgumentDirection.in_, name: 'uint16_value'), DBusIntrospectArgument(DBusSignature('i'), DBusArgumentDirection.in_, name: 'int32_value'), DBusIntrospectArgument(DBusSignature('u'), DBusArgumentDirection.in_, name: 'uint32_value'), DBusIntrospectArgument(DBusSignature('x'), DBusArgumentDirection.in_, name: 'int64_value'), DBusIntrospectArgument(DBusSignature('t'), DBusArgumentDirection.in_, name: 'uint64_value'), DBusIntrospectArgument(DBusSignature('d'), DBusArgumentDirection.in_, name: 'double_value'), DBusIntrospectArgument(DBusSignature('s'), DBusArgumentDirection.in_, name: 'string_value'), DBusIntrospectArgument(DBusSignature('o'), DBusArgumentDirection.in_, name: 'object_path_value'), DBusIntrospectArgument(DBusSignature('g'), DBusArgumentDirection.in_, name: 'signature_value'), DBusIntrospectArgument(DBusSignature('v'), DBusArgumentDirection.in_, name: 'variant_value'), DBusIntrospectArgument(DBusSignature('(si)'), DBusArgumentDirection.in_, name: 'struct_value'), DBusIntrospectArgument(DBusSignature('ay'), DBusArgumentDirection.in_, name: 'array_value_y'), DBusIntrospectArgument(DBusSignature('ab'), DBusArgumentDirection.in_, name: 'array_value_b'), DBusIntrospectArgument(DBusSignature('an'), DBusArgumentDirection.in_, name: 'array_value_n'), DBusIntrospectArgument(DBusSignature('aq'), DBusArgumentDirection.in_, name: 'array_value_q'), DBusIntrospectArgument(DBusSignature('ai'), DBusArgumentDirection.in_, name: 'array_value_u'), DBusIntrospectArgument(DBusSignature('au'), DBusArgumentDirection.in_, name: 'array_value_n'), DBusIntrospectArgument(DBusSignature('ax'), DBusArgumentDirection.in_, name: 'array_value_x'), DBusIntrospectArgument(DBusSignature('at'), DBusArgumentDirection.in_, name: 'array_value_t'), DBusIntrospectArgument(DBusSignature('ad'), DBusArgumentDirection.in_, name: 'array_value_d'), DBusIntrospectArgument(DBusSignature('as'), DBusArgumentDirection.in_, name: 'array_value_s'), DBusIntrospectArgument(DBusSignature('ao'), DBusArgumentDirection.in_, name: 'array_value_o'), DBusIntrospectArgument(DBusSignature('ag'), DBusArgumentDirection.in_, name: 'array_value_g'), DBusIntrospectArgument(DBusSignature('av'), DBusArgumentDirection.in_, name: 'array_value_v'), DBusIntrospectArgument(DBusSignature('a(si)'), DBusArgumentDirection.in_, name: 'array_value_struct'), DBusIntrospectArgument(DBusSignature('aas'), DBusArgumentDirection.in_, name: 'array_value_array'), DBusIntrospectArgument(DBusSignature('a{sv}'), DBusArgumentDirection.in_, name: 'dict_value_sv'), DBusIntrospectArgument(DBusSignature('a{us}'), DBusArgumentDirection.in_, name: 'dict_value_us'), DBusIntrospectArgument(DBusSignature('a{sa{sv}}'), DBusArgumentDirection.in_, name: 'dict_value_dict')])])];
return [DBusIntrospectInterface('com.example.Test', methods: [DBusIntrospectMethod('Hello', args: [DBusIntrospectArgument(DBusSignature('y'), DBusArgumentDirection.in_, name: 'byte_value'), DBusIntrospectArgument(DBusSignature('b'), DBusArgumentDirection.in_, name: 'boolean_value'), DBusIntrospectArgument(DBusSignature('n'), DBusArgumentDirection.in_, name: 'int16_value'), DBusIntrospectArgument(DBusSignature('q'), DBusArgumentDirection.in_, name: 'uint16_value'), DBusIntrospectArgument(DBusSignature('i'), DBusArgumentDirection.in_, name: 'int32_value'), DBusIntrospectArgument(DBusSignature('u'), DBusArgumentDirection.in_, name: 'uint32_value'), DBusIntrospectArgument(DBusSignature('x'), DBusArgumentDirection.in_, name: 'int64_value'), DBusIntrospectArgument(DBusSignature('t'), DBusArgumentDirection.in_, name: 'uint64_value'), DBusIntrospectArgument(DBusSignature('d'), DBusArgumentDirection.in_, name: 'double_value'), DBusIntrospectArgument(DBusSignature('s'), DBusArgumentDirection.in_, name: 'string_value'), DBusIntrospectArgument(DBusSignature('o'), DBusArgumentDirection.in_, name: 'object_path_value'), DBusIntrospectArgument(DBusSignature('g'), DBusArgumentDirection.in_, name: 'signature_value'), DBusIntrospectArgument(DBusSignature('v'), DBusArgumentDirection.in_, name: 'variant_value'), DBusIntrospectArgument(DBusSignature('h'), DBusArgumentDirection.in_, name: 'unix_fd_value'), DBusIntrospectArgument(DBusSignature('(si)'), DBusArgumentDirection.in_, name: 'struct_value'), DBusIntrospectArgument(DBusSignature('ay'), DBusArgumentDirection.in_, name: 'array_value_y'), DBusIntrospectArgument(DBusSignature('ab'), DBusArgumentDirection.in_, name: 'array_value_b'), DBusIntrospectArgument(DBusSignature('an'), DBusArgumentDirection.in_, name: 'array_value_n'), DBusIntrospectArgument(DBusSignature('aq'), DBusArgumentDirection.in_, name: 'array_value_q'), DBusIntrospectArgument(DBusSignature('ai'), DBusArgumentDirection.in_, name: 'array_value_u'), DBusIntrospectArgument(DBusSignature('au'), DBusArgumentDirection.in_, name: 'array_value_n'), DBusIntrospectArgument(DBusSignature('ax'), DBusArgumentDirection.in_, name: 'array_value_x'), DBusIntrospectArgument(DBusSignature('at'), DBusArgumentDirection.in_, name: 'array_value_t'), DBusIntrospectArgument(DBusSignature('ad'), DBusArgumentDirection.in_, name: 'array_value_d'), DBusIntrospectArgument(DBusSignature('as'), DBusArgumentDirection.in_, name: 'array_value_s'), DBusIntrospectArgument(DBusSignature('ao'), DBusArgumentDirection.in_, name: 'array_value_o'), DBusIntrospectArgument(DBusSignature('ag'), DBusArgumentDirection.in_, name: 'array_value_g'), DBusIntrospectArgument(DBusSignature('av'), DBusArgumentDirection.in_, name: 'array_value_v'), DBusIntrospectArgument(DBusSignature('ah'), DBusArgumentDirection.in_, name: 'array_value_h'), DBusIntrospectArgument(DBusSignature('a(si)'), DBusArgumentDirection.in_, name: 'array_value_struct'), DBusIntrospectArgument(DBusSignature('aas'), DBusArgumentDirection.in_, name: 'array_value_array'), DBusIntrospectArgument(DBusSignature('a{sv}'), DBusArgumentDirection.in_, name: 'dict_value_sv'), DBusIntrospectArgument(DBusSignature('a{us}'), DBusArgumentDirection.in_, name: 'dict_value_us'), DBusIntrospectArgument(DBusSignature('a{sa{sv}}'), DBusArgumentDirection.in_, name: 'dict_value_dict')])])];
}

@override
Future<DBusMethodResponse> handleMethodCall(DBusMethodCall methodCall) async {
if (methodCall.interface == 'com.example.Test') {
if (methodCall.name == 'Hello') {
if (methodCall.signature != DBusSignature('ybnqiuxtdsogv(si)ayabanaqaiauaxatadasaoagava(si)aasa{sv}a{us}a{sa{sv}}')) {
if (methodCall.signature != DBusSignature('ybnqiuxtdsogvh(si)ayabanaqaiauaxatadasaoagavaha(si)aasa{sv}a{us}a{sa{sv}}')) {
return DBusMethodErrorResponse.invalidArgs();
}
return doHello(methodCall.values[0].asByte(), methodCall.values[1].asBoolean(), methodCall.values[2].asInt16(), methodCall.values[3].asUint16(), methodCall.values[4].asInt32(), methodCall.values[5].asUint32(), methodCall.values[6].asInt64(), methodCall.values[7].asUint64(), methodCall.values[8].asDouble(), methodCall.values[9].asString(), methodCall.values[10].asObjectPath(), methodCall.values[11].asSignature(), methodCall.values[12].asVariant(), methodCall.values[13].asStruct(), methodCall.values[14].asByteArray().toList(), methodCall.values[15].asBooleanArray().toList(), methodCall.values[16].asInt16Array().toList(), methodCall.values[17].asUint16Array().toList(), methodCall.values[18].asInt32Array().toList(), methodCall.values[19].asUint32Array().toList(), methodCall.values[20].asInt64Array().toList(), methodCall.values[21].asUint64Array().toList(), methodCall.values[22].asDoubleArray().toList(), methodCall.values[23].asStringArray().toList(), methodCall.values[24].asObjectPathArray().toList(), methodCall.values[25].asSignatureArray().toList(), methodCall.values[26].asVariantArray().toList(), methodCall.values[27].asArray().map((child) => child.asStruct()).toList(), methodCall.values[28].asArray().map((child) => child.asStringArray().toList()).toList(), methodCall.values[29].asStringVariantDict(), methodCall.values[30].asDict().map((key, value) => MapEntry(key.asUint32(), value.asString())), methodCall.values[31].asDict().map((key, value) => MapEntry(key.asString(), value.asStringVariantDict())));
return doHello(methodCall.values[0].asByte(), methodCall.values[1].asBoolean(), methodCall.values[2].asInt16(), methodCall.values[3].asUint16(), methodCall.values[4].asInt32(), methodCall.values[5].asUint32(), methodCall.values[6].asInt64(), methodCall.values[7].asUint64(), methodCall.values[8].asDouble(), methodCall.values[9].asString(), methodCall.values[10].asObjectPath(), methodCall.values[11].asSignature(), methodCall.values[12].asVariant(), methodCall.values[13].asUnixFd(), methodCall.values[14].asStruct(), methodCall.values[15].asByteArray().toList(), methodCall.values[16].asBooleanArray().toList(), methodCall.values[17].asInt16Array().toList(), methodCall.values[18].asUint16Array().toList(), methodCall.values[19].asInt32Array().toList(), methodCall.values[20].asUint32Array().toList(), methodCall.values[21].asInt64Array().toList(), methodCall.values[22].asUint64Array().toList(), methodCall.values[23].asDoubleArray().toList(), methodCall.values[24].asStringArray().toList(), methodCall.values[25].asObjectPathArray().toList(), methodCall.values[26].asSignatureArray().toList(), methodCall.values[27].asVariantArray().toList(), methodCall.values[28].asUnixFdArray().toList(), methodCall.values[29].asArray().map((child) => child.asStruct()).toList(), methodCall.values[30].asArray().map((child) => child.asStringArray().toList()).toList(), methodCall.values[31].asStringVariantDict(), methodCall.values[32].asDict().map((key, value) => MapEntry(key.asUint32(), value.asString())), methodCall.values[33].asDict().map((key, value) => MapEntry(key.asString(), value.asStringVariantDict())));
} else {
return DBusMethodErrorResponse.unknownMethod();
}
Expand Down
Loading