import 'dart:io'; import 'package:dbus/dbus.dart'; class ComExampleTest extends DBusObject { /// Creates a new object to expose on [path]. ComExampleTest({DBusObjectPath path = const DBusObjectPath.unchecked('/')}) : super(path); /// Gets value of property com.example.Test.ReadProperty Future getReadProperty() async { return DBusMethodErrorResponse.failed('Get com.example.Test.ReadProperty not implemented'); } /// Sets property com.example.Test.WriteProperty Future setWriteProperty(int value) async { return DBusMethodErrorResponse.failed('Set com.example.Test.WriteProperty not implemented'); } /// Gets value of property com.example.Test.ReadWriteProperty Future getReadWriteProperty() async { return DBusMethodErrorResponse.failed('Get com.example.Test.ReadWriteProperty not implemented'); } /// Sets property com.example.Test.ReadWriteProperty Future setReadWriteProperty(int value) async { return DBusMethodErrorResponse.failed('Set com.example.Test.ReadWriteProperty not implemented'); } @override List introspect() { return [DBusIntrospectInterface('com.example.Test', properties: [DBusIntrospectProperty('ReadProperty', DBusSignature('i'), access: DBusPropertyAccess.read), DBusIntrospectProperty('WriteProperty', DBusSignature('i'), access: DBusPropertyAccess.write), DBusIntrospectProperty('ReadWriteProperty', DBusSignature('i'), access: DBusPropertyAccess.readwrite)])]; } @override Future handleMethodCall(DBusMethodCall methodCall) async { if (methodCall.interface == 'com.example.Test') { return DBusMethodErrorResponse.unknownMethod(); } else { return DBusMethodErrorResponse.unknownInterface(); } } @override Future getProperty(String interface, String name) async { if (interface == 'com.example.Test') { if (name == 'ReadProperty') { return getReadProperty(); } else if (name == 'WriteProperty') { return DBusMethodErrorResponse.propertyWriteOnly(); } else if (name == 'ReadWriteProperty') { return getReadWriteProperty(); } else { return DBusMethodErrorResponse.unknownProperty(); } } else { return DBusMethodErrorResponse.unknownProperty(); } } @override Future setProperty(String interface, String name, DBusValue value) async { if (interface == 'com.example.Test') { if (name == 'ReadProperty') { return DBusMethodErrorResponse.propertyReadOnly(); } else if (name == 'WriteProperty') { if (value.signature != DBusSignature('i')) { return DBusMethodErrorResponse.invalidArgs(); } return setWriteProperty(value.asInt32()); } else if (name == 'ReadWriteProperty') { if (value.signature != DBusSignature('i')) { return DBusMethodErrorResponse.invalidArgs(); } return setReadWriteProperty(value.asInt32()); } else { return DBusMethodErrorResponse.unknownProperty(); } } else { return DBusMethodErrorResponse.unknownProperty(); } } @override Future getAllProperties(String interface) async { var properties = {}; if (interface == 'com.example.Test') { properties['ReadProperty'] = (await getReadProperty()).returnValues[0]; properties['ReadWriteProperty'] = (await getReadWriteProperty()).returnValues[0]; } return DBusMethodSuccessResponse([DBusDict.stringVariant(properties)]); } }