From 03ac9b695631a247ab78a005046eed238b96e65c Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Sat, 30 Oct 2021 19:30:19 +0200 Subject: [PATCH] various cleanups, slight update to dbus --- .idea/libraries/KotlinJavaRuntime__2_.xml | 15 ------ .idea/libraries/KotlinJavaRuntime__3_.xml | 15 ------ .idea/libraries/github_hypfvieh_dbus_java.xml | 22 ++++---- codeOptimizers/codeOptimizers.iml | 2 +- compiler/build.gradle | 4 -- compilerInterfaces/compilerInterfaces.iml | 2 +- dbusCompilerService/build.gradle | 8 +-- dbusCompilerService/dbusCompilerService.iml | 1 + .../src/prog8/dbus/IrmenDbusTest.kt | 8 ++- .../src/prog8/dbus/clientmain.kt | 52 ++++++++++++++++--- .../src/prog8/dbus/dbusserver.kt | 24 +++++++++ .../src/prog8/dbus/testdbus.kt | 18 ------- httpCompilerService/build.gradle | 4 -- 13 files changed, 93 insertions(+), 82 deletions(-) delete mode 100644 .idea/libraries/KotlinJavaRuntime__2_.xml delete mode 100644 .idea/libraries/KotlinJavaRuntime__3_.xml create mode 100644 dbusCompilerService/src/prog8/dbus/dbusserver.kt delete mode 100644 dbusCompilerService/src/prog8/dbus/testdbus.kt diff --git a/.idea/libraries/KotlinJavaRuntime__2_.xml b/.idea/libraries/KotlinJavaRuntime__2_.xml deleted file mode 100644 index 45205327d..000000000 --- a/.idea/libraries/KotlinJavaRuntime__2_.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/KotlinJavaRuntime__3_.xml b/.idea/libraries/KotlinJavaRuntime__3_.xml deleted file mode 100644 index 6cfba67ce..000000000 --- a/.idea/libraries/KotlinJavaRuntime__3_.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/github_hypfvieh_dbus_java.xml b/.idea/libraries/github_hypfvieh_dbus_java.xml index 3e0ea4abc..4d41a0e67 100644 --- a/.idea/libraries/github_hypfvieh_dbus_java.xml +++ b/.idea/libraries/github_hypfvieh_dbus_java.xml @@ -1,22 +1,22 @@ - + - - - + + + - - - - - + + + + + - - + + diff --git a/codeOptimizers/codeOptimizers.iml b/codeOptimizers/codeOptimizers.iml index 45621612e..589fe3d9b 100644 --- a/codeOptimizers/codeOptimizers.iml +++ b/codeOptimizers/codeOptimizers.iml @@ -9,7 +9,7 @@ - + diff --git a/compiler/build.gradle b/compiler/build.gradle index 543209b9c..228d18773 100644 --- a/compiler/build.gradle +++ b/compiler/build.gradle @@ -11,10 +11,6 @@ java { } } -repositories { - maven { url "https://kotlin.bintray.com/kotlinx" } -} - def prog8version = rootProject.file('compiler/res/version.txt').text.trim() dependencies { diff --git a/compilerInterfaces/compilerInterfaces.iml b/compilerInterfaces/compilerInterfaces.iml index 31645176c..dd702955a 100644 --- a/compilerInterfaces/compilerInterfaces.iml +++ b/compilerInterfaces/compilerInterfaces.iml @@ -9,7 +9,7 @@ - + diff --git a/dbusCompilerService/build.gradle b/dbusCompilerService/build.gradle index 19a69e094..9313391e7 100644 --- a/dbusCompilerService/build.gradle +++ b/dbusCompilerService/build.gradle @@ -12,15 +12,11 @@ java { } } -repositories { - maven { url "https://kotlin.bintray.com/kotlinx" } -} - dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" // implementation "org.jetbrains.kotlin:kotlin-reflect" implementation 'org.jetbrains.kotlinx:kotlinx-cli:0.3.3' - implementation "com.github.hypfvieh:dbus-java:3.3.0" + implementation "com.github.hypfvieh:dbus-java:3.3.1" implementation "org.slf4j:slf4j-simple:1.7.30" testImplementation "org.jetbrains.kotlin:kotlin-test-junit5" @@ -53,7 +49,7 @@ sourceSets { startScripts.enabled = true application { - mainClass = 'prog8.dbus.TestdbusKt' + mainClass = 'prog8.dbus.DbusserverKt' applicationName = 'prog8compilerservicedbus' } diff --git a/dbusCompilerService/dbusCompilerService.iml b/dbusCompilerService/dbusCompilerService.iml index 3b8cb3996..6cadef558 100644 --- a/dbusCompilerService/dbusCompilerService.iml +++ b/dbusCompilerService/dbusCompilerService.iml @@ -11,5 +11,6 @@ + \ No newline at end of file diff --git a/dbusCompilerService/src/prog8/dbus/IrmenDbusTest.kt b/dbusCompilerService/src/prog8/dbus/IrmenDbusTest.kt index 0788f1b33..999c4261a 100644 --- a/dbusCompilerService/src/prog8/dbus/IrmenDbusTest.kt +++ b/dbusCompilerService/src/prog8/dbus/IrmenDbusTest.kt @@ -1,15 +1,21 @@ package prog8.dbus +import org.freedesktop.dbus.annotations.IntrospectionDescription import org.freedesktop.dbus.interfaces.DBusInterface +const val serviceObjectPath = "/razorvine/TestService" + + interface IrmenDbusTest: DBusInterface { + @IntrospectionDescription("return some sort of status") fun Status(address: String): Map } internal class TestService: IrmenDbusTest { + override fun Status(address: String): Map { return mapOf( 5 to "hello", @@ -18,5 +24,5 @@ internal class TestService: IrmenDbusTest { } override fun isRemote() = true - override fun getObjectPath() = "/razorvine/TestService" + override fun getObjectPath() = serviceObjectPath } diff --git a/dbusCompilerService/src/prog8/dbus/clientmain.kt b/dbusCompilerService/src/prog8/dbus/clientmain.kt index 994daa0c3..a41d7a804 100644 --- a/dbusCompilerService/src/prog8/dbus/clientmain.kt +++ b/dbusCompilerService/src/prog8/dbus/clientmain.kt @@ -2,16 +2,56 @@ package prog8.dbus import org.freedesktop.dbus.connections.impl.DBusConnection +import org.freedesktop.dbus.exceptions.DBusExecutionException +import org.freedesktop.dbus.interfaces.DBusInterface + +/* + +Inspect the dbus services interactively via the qdbusviewer tool. + + +Command line access is also possible with: + +$ dbus-send --session --dest=local.net.razorvine.prog8.dbus --type=method_call --print-reply /razorvine/TestService prog8.dbus.IrmenDbusTest.Status string:"hello world" + +$ qdbus --literal local.net.razorvine.prog8.dbus /razorvine/TestService Status string:"hello world" + +$ gdbus call --session -d local.net.razorvine.prog8.dbus -o /razorvine/TestService --method prog8.dbus.IrmenDbusTest.Status string:"hello world" + +Or with the dasbus python library: + + from dasbus.connection import SessionMessageBus + from dasbus.identifier import DBusServiceIdentifier + + PROG8_SERVICE = DBusServiceIdentifier( + namespace=("local", "net", "razorvine", "prog8", "dbus"), + message_bus=SessionMessageBus() + ) + + proxy = PROG8_SERVICE.get_proxy("/razorvine/TestService") + print(proxy.Status("hello world")) + + + */ + +inline fun DBusConnection.getRemote(busname: String, objectpath: String): I = + this.getRemoteObject(busname, objectpath, I::class.java) + +inline fun DBusConnection.getPeerRemote(busname: String, objectpath: String): I = + this.getPeerRemoteObject(busname, objectpath, I::class.java) fun main() { DBusConnection.getConnection(DBusConnection.DBusBusType.SESSION).use { - println(it.names.toList()) - println(it.uniqueName) - println(it.address) - println(it.machineId) - val obj = it.getRemoteObject("local.net.razorvine.dbus.test", "/razorvine/TestService", IrmenDbusTest::class.java) - println(obj.Status("irmen")) + + try { + + val obj = it.getRemote("local.net.razorvine.prog8.dbus", serviceObjectPath) + println(obj.Status("irmen")) + + } catch (dx: DBusExecutionException) { + println("DBUS ERROR! $dx") + } } } diff --git a/dbusCompilerService/src/prog8/dbus/dbusserver.kt b/dbusCompilerService/src/prog8/dbus/dbusserver.kt new file mode 100644 index 000000000..397fcef2c --- /dev/null +++ b/dbusCompilerService/src/prog8/dbus/dbusserver.kt @@ -0,0 +1,24 @@ +package prog8.dbus + +import org.freedesktop.dbus.connections.impl.DBusConnection + + +fun main() { + val busname = "local.net.razorvine.prog8.dbus" + + DBusConnection.getConnection(DBusConnection.DBusBusType.SESSION).use { + it.requestBusName(busname) + println("connection names : ${it.names.toList()}") + println("connection unique name : ${it.uniqueName}") + println("connection address : ${it.address}") + println("connection machine id : ${it.machineId}") + println("bus name for clients : $busname") + println("object path for clients : $serviceObjectPath") + + val service = TestService() + it.exportObject(service.objectPath, service) + + Thread.sleep(100000) + it.releaseBusName(busname) + } +} diff --git a/dbusCompilerService/src/prog8/dbus/testdbus.kt b/dbusCompilerService/src/prog8/dbus/testdbus.kt deleted file mode 100644 index 382cc2d02..000000000 --- a/dbusCompilerService/src/prog8/dbus/testdbus.kt +++ /dev/null @@ -1,18 +0,0 @@ -package prog8.dbus - -import org.freedesktop.dbus.connections.impl.DBusConnection - - -fun main() { - DBusConnection.getConnection(DBusConnection.DBusBusType.SESSION).use { - it.requestBusName("local.net.razorvine.dbus.test") - println(it.names.toList()) - println(it.uniqueName) - println(it.address) - println(it.machineId) - val service = TestService() - it.exportObject(service.objectPath, service) - - Thread.sleep(100000) - } -} diff --git a/httpCompilerService/build.gradle b/httpCompilerService/build.gradle index e3cf85838..0cfa8cc33 100644 --- a/httpCompilerService/build.gradle +++ b/httpCompilerService/build.gradle @@ -12,10 +12,6 @@ java { } } -repositories { - maven { url "https://kotlin.bintray.com/kotlinx" } -} - dependencies { implementation project(':compilerInterfaces') implementation project(':compiler')