From 0e1bafa9bf50ec9088ed1f5889de57b0478916e9 Mon Sep 17 00:00:00 2001 From: Darius Maitia Date: Wed, 18 Sep 2024 17:04:50 -0300 Subject: [PATCH 1/4] Session info: creating SessionInfo, implementing peersZid() and routersZid() --- examples/build.gradle.kts | 1 + examples/src/main/kotlin/io.zenoh/ZInfo.kt | 59 +++++++++++++++++++ zenoh-jni/src/session.rs | 56 +++++++++++++++++- .../src/commonMain/kotlin/io/zenoh/Session.kt | 13 ++++ .../commonMain/kotlin/io/zenoh/SessionInfo.kt | 32 ++++++++++ .../kotlin/io/zenoh/jni/JNISession.kt | 16 +++++ 6 files changed, 175 insertions(+), 2 deletions(-) create mode 100644 examples/src/main/kotlin/io.zenoh/ZInfo.kt create mode 100644 zenoh-kotlin/src/commonMain/kotlin/io/zenoh/SessionInfo.kt diff --git a/examples/build.gradle.kts b/examples/build.gradle.kts index a27450a87..ab8d93a5a 100644 --- a/examples/build.gradle.kts +++ b/examples/build.gradle.kts @@ -34,6 +34,7 @@ tasks { "ZBytes", "ZDelete", "ZGet", + "ZInfo", "ZPub", "ZPubThr", "ZPut", diff --git a/examples/src/main/kotlin/io.zenoh/ZInfo.kt b/examples/src/main/kotlin/io.zenoh/ZInfo.kt new file mode 100644 index 000000000..6aa8d9cbe --- /dev/null +++ b/examples/src/main/kotlin/io.zenoh/ZInfo.kt @@ -0,0 +1,59 @@ +// +// Copyright (c) 2023 ZettaScale Technology +// +// This program and the accompanying materials are made available under the +// terms of the Eclipse Public License 2.0 which is available at +// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 +// which is available at https://www.apache.org/licenses/LICENSE-2.0. +// +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// +// Contributors: +// ZettaScale Zenoh Team, +// + +package io.zenoh + +import com.github.ajalt.clikt.core.CliktCommand +import com.github.ajalt.clikt.parameters.options.* + +class ZInfo(private val emptyArgs: Boolean) : CliktCommand( + help = "Zenoh Info example" +) { + override fun run() { + val config = loadConfig(emptyArgs, configFile, connect, listen, noMulticastScouting, mode) + + Zenoh.initLogFromEnvOr("error") + + println("Opening session...") + Zenoh.open(config).onSuccess { session -> + session.use { + val info = session.info() + + println("routers zid: ${info.routersId()}") + + println("peers zid: ${info.peersId()}") + } + }.onFailure { exception -> println(exception.message) } + } + + + private val configFile by option("-c", "--config", help = "A configuration file.", metavar = "config") + private val connect: List by option( + "-e", "--connect", help = "Endpoints to connect to.", metavar = "connect" + ).multiple() + private val listen: List by option( + "-l", "--listen", help = "Endpoints to listen on.", metavar = "listen" + ).multiple() + private val mode by option( + "-m", + "--mode", + help = "The session mode. Default: peer. Possible values: [peer, client, router]", + metavar = "mode" + ).default("peer") + private val noMulticastScouting: Boolean by option( + "--no-multicast-scouting", help = "Disable the multicast-based scouting mechanism." + ).flag(default = false) +} + +fun main(args: Array) = ZInfo(args.isEmpty()).main(args) diff --git a/zenoh-jni/src/session.rs b/zenoh-jni/src/session.rs index e52db1880..ff7682b91 100644 --- a/zenoh-jni/src/session.rs +++ b/zenoh-jni/src/session.rs @@ -15,8 +15,8 @@ use std::{mem, ops::Deref, ptr::null, sync::Arc, time::Duration}; use jni::{ - objects::{GlobalRef, JByteArray, JClass, JObject, JString, JValue}, - sys::{jboolean, jint, jlong}, + objects::{GlobalRef, JByteArray, JClass, JList, JObject, JString, JValue}, + sys::{jboolean, jint, jlong, jobject}, JNIEnv, }; use zenoh::{ @@ -1036,3 +1036,55 @@ fn on_reply_error( }; result } + +#[no_mangle] +#[allow(non_snake_case)] +pub unsafe extern "C" fn Java_io_zenoh_jni_JNISession_getPeersZidViaJNI( + mut env: JNIEnv, + _class: JClass, + session_ptr: *const Session, +) -> jobject { + let session = Arc::from_raw(session_ptr); + let ids = || -> Result { + let peers_zid = session.info().peers_zid().wait(); + let ids = peers_zid.collect::>(); + ids_to_java_list(&mut env, ids).map_err(|err| jni_error!(err)) + }() + .unwrap_or_else(|err| { + throw_exception!(env, err); + JObject::default().as_raw() + }); + std::mem::forget(session); + ids +} + +#[no_mangle] +#[allow(non_snake_case)] +pub unsafe extern "C" fn Java_io_zenoh_jni_JNISession_getRoutersZidViaJNI( + mut env: JNIEnv, + _class: JClass, + session_ptr: *const Session, +) -> jobject { + let session = Arc::from_raw(session_ptr); + let ids = || -> Result { + let peers_zid = session.info().routers_zid().wait(); + let ids = peers_zid.collect::>(); + ids_to_java_list(&mut env, ids).map_err(|err| jni_error!(err)) + }() + .unwrap_or_else(|err| { + throw_exception!(env, err); + JObject::default().as_raw() + }); + std::mem::forget(session); + ids +} + +fn ids_to_java_list(env: &mut JNIEnv, ids: Vec) -> jni::errors::Result { + let array_list = env.new_object("java/util/ArrayList", "()V", &[])?; + let jlist = JList::from_env(env, &array_list)?; + for id in ids { + let value = &mut env.byte_array_from_slice(&id.to_le_bytes())?; + jlist.add(env, value)?; + } + Ok(array_list.as_raw()) +} diff --git a/zenoh-kotlin/src/commonMain/kotlin/io/zenoh/Session.kt b/zenoh-kotlin/src/commonMain/kotlin/io/zenoh/Session.kt index 3bdd23d15..9cb647928 100644 --- a/zenoh-kotlin/src/commonMain/kotlin/io/zenoh/Session.kt +++ b/zenoh-kotlin/src/commonMain/kotlin/io/zenoh/Session.kt @@ -24,6 +24,7 @@ import io.zenoh.prelude.Encoding import io.zenoh.prelude.QoS import io.zenoh.protocol.IntoZBytes import io.zenoh.protocol.ZBytes +import io.zenoh.protocol.ZenohID import io.zenoh.publication.Delete import io.zenoh.publication.Publisher import io.zenoh.publication.Put @@ -802,6 +803,10 @@ class Session private constructor(private val config: Config) : AutoCloseable { return jniSession != null } + fun info(): SessionInfo { + return SessionInfo(this) + } + private fun resolvePublisher(keyExpr: KeyExpr, qos: QoS, reliability: Reliability): Result { return jniSession?.run { declarePublisher(keyExpr, qos, reliability).onSuccess { declarations.add(it) } @@ -867,6 +872,14 @@ class Session private constructor(private val config: Config) : AutoCloseable { jniSession?.run { performDelete(keyExpr, delete) } } + internal fun getPeersId(): List { + return jniSession?.peersZid() ?: emptyList() + } + + internal fun getRoutersId(): List { + return jniSession?.routersZid() ?: emptyList() + } + /** Launches the session through the jni session, returning the [Session] on success. */ private fun launch(): Result = runCatching { jniSession = JNISession() diff --git a/zenoh-kotlin/src/commonMain/kotlin/io/zenoh/SessionInfo.kt b/zenoh-kotlin/src/commonMain/kotlin/io/zenoh/SessionInfo.kt new file mode 100644 index 000000000..21149c91b --- /dev/null +++ b/zenoh-kotlin/src/commonMain/kotlin/io/zenoh/SessionInfo.kt @@ -0,0 +1,32 @@ +// +// Copyright (c) 2023 ZettaScale Technology +// +// This program and the accompanying materials are made available under the +// terms of the Eclipse Public License 2.0 which is available at +// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 +// which is available at https://www.apache.org/licenses/LICENSE-2.0. +// +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// +// Contributors: +// ZettaScale Zenoh Team, +// + +package io.zenoh + +import io.zenoh.protocol.ZenohID + +class SessionInfo(private val session: Session) { + + fun id(): ZenohID { + TODO() + } + + fun peersId(): List { + return session.getPeersId() + } + + fun routersId(): List { + return session.getRoutersId() + } +} \ No newline at end of file diff --git a/zenoh-kotlin/src/commonMain/kotlin/io/zenoh/jni/JNISession.kt b/zenoh-kotlin/src/commonMain/kotlin/io/zenoh/jni/JNISession.kt index 690ef9203..e14d4d869 100644 --- a/zenoh-kotlin/src/commonMain/kotlin/io/zenoh/jni/JNISession.kt +++ b/zenoh-kotlin/src/commonMain/kotlin/io/zenoh/jni/JNISession.kt @@ -251,6 +251,22 @@ internal class JNISession { ) } + @Throws(Exception::class) + fun peersZid(): List { + return getPeersZidViaJNI(sessionPtr.get()).map { ZenohID(it) } + } + + @Throws(Exception::class) + fun routersZid(): List { + return getRoutersZidViaJNI(sessionPtr.get()).map { ZenohID(it) } + } + + @Throws(Exception::class) + private external fun getPeersZidViaJNI(ptr: Long): List + + @Throws(Exception::class) + private external fun getRoutersZidViaJNI(ptr: Long): List + @Throws(Exception::class) private external fun openSessionViaJNI(configPtr: Long): Long From 7167e889e966572558c60fff25545255aa3e0155 Mon Sep 17 00:00:00 2001 From: Darius Maitia Date: Wed, 18 Sep 2024 21:08:27 -0300 Subject: [PATCH 2/4] Session info: adding id() function, returning Results. --- examples/src/main/kotlin/io.zenoh/ZInfo.kt | 5 +- zenoh-jni/src/session.rs | 24 +++- .../src/commonMain/kotlin/io/zenoh/Session.kt | 12 +- .../commonMain/kotlin/io/zenoh/SessionInfo.kt | 8 +- .../kotlin/io/zenoh/jni/JNISession.kt | 17 ++- .../kotlin/io/zenoh/SessionInfoTest.kt | 109 ++++++++++++++++++ 6 files changed, 158 insertions(+), 17 deletions(-) create mode 100644 zenoh-kotlin/src/commonTest/kotlin/io/zenoh/SessionInfoTest.kt diff --git a/examples/src/main/kotlin/io.zenoh/ZInfo.kt b/examples/src/main/kotlin/io.zenoh/ZInfo.kt index 6aa8d9cbe..1a2b098a0 100644 --- a/examples/src/main/kotlin/io.zenoh/ZInfo.kt +++ b/examples/src/main/kotlin/io.zenoh/ZInfo.kt @@ -29,10 +29,11 @@ class ZInfo(private val emptyArgs: Boolean) : CliktCommand( Zenoh.open(config).onSuccess { session -> session.use { val info = session.info() + println("zid: ${info.id().getOrThrow()}") - println("routers zid: ${info.routersId()}") + println("routers zid: ${info.routersId().getOrThrow()}") - println("peers zid: ${info.peersId()}") + println("peers zid: ${info.peersId().getOrThrow()}") } }.onFailure { exception -> println(exception.message) } } diff --git a/zenoh-jni/src/session.rs b/zenoh-jni/src/session.rs index ff7682b91..9829dd3b9 100644 --- a/zenoh-jni/src/session.rs +++ b/zenoh-jni/src/session.rs @@ -16,7 +16,7 @@ use std::{mem, ops::Deref, ptr::null, sync::Arc, time::Duration}; use jni::{ objects::{GlobalRef, JByteArray, JClass, JList, JObject, JString, JValue}, - sys::{jboolean, jint, jlong, jobject}, + sys::{jboolean, jbyteArray, jint, jlong, jobject}, JNIEnv, }; use zenoh::{ @@ -1079,6 +1079,28 @@ pub unsafe extern "C" fn Java_io_zenoh_jni_JNISession_getRoutersZidViaJNI( ids } +#[no_mangle] +#[allow(non_snake_case)] +pub unsafe extern "C" fn Java_io_zenoh_jni_JNISession_getZidViaJNI( + mut env: JNIEnv, + _class: JClass, + session_ptr: *const Session, +) -> jbyteArray { + let session = Arc::from_raw(session_ptr); + let ids = || -> Result { + let zid = session.info().zid().wait(); + env.byte_array_from_slice(&zid.to_le_bytes()) + .map(|x| x.as_raw()) + .map_err(|err| jni_error!(err)) + }() + .unwrap_or_else(|err| { + throw_exception!(env, err); + JByteArray::default().as_raw() + }); + std::mem::forget(session); + ids +} + fn ids_to_java_list(env: &mut JNIEnv, ids: Vec) -> jni::errors::Result { let array_list = env.new_object("java/util/ArrayList", "()V", &[])?; let jlist = JList::from_env(env, &array_list)?; diff --git a/zenoh-kotlin/src/commonMain/kotlin/io/zenoh/Session.kt b/zenoh-kotlin/src/commonMain/kotlin/io/zenoh/Session.kt index 9cb647928..dc69eb350 100644 --- a/zenoh-kotlin/src/commonMain/kotlin/io/zenoh/Session.kt +++ b/zenoh-kotlin/src/commonMain/kotlin/io/zenoh/Session.kt @@ -872,12 +872,16 @@ class Session private constructor(private val config: Config) : AutoCloseable { jniSession?.run { performDelete(keyExpr, delete) } } - internal fun getPeersId(): List { - return jniSession?.peersZid() ?: emptyList() + internal fun zid(): Result { + return jniSession?.zid() ?: Result.failure(sessionClosedException) } - internal fun getRoutersId(): List { - return jniSession?.routersZid() ?: emptyList() + internal fun getPeersId(): Result> { + return jniSession?.peersZid() ?: Result.failure(sessionClosedException) + } + + internal fun getRoutersId(): Result> { + return jniSession?.routersZid() ?: Result.failure(sessionClosedException) } /** Launches the session through the jni session, returning the [Session] on success. */ diff --git a/zenoh-kotlin/src/commonMain/kotlin/io/zenoh/SessionInfo.kt b/zenoh-kotlin/src/commonMain/kotlin/io/zenoh/SessionInfo.kt index 21149c91b..b6cffb3e0 100644 --- a/zenoh-kotlin/src/commonMain/kotlin/io/zenoh/SessionInfo.kt +++ b/zenoh-kotlin/src/commonMain/kotlin/io/zenoh/SessionInfo.kt @@ -18,15 +18,15 @@ import io.zenoh.protocol.ZenohID class SessionInfo(private val session: Session) { - fun id(): ZenohID { - TODO() + fun id(): Result { + return session.zid() } - fun peersId(): List { + fun peersId(): Result> { return session.getPeersId() } - fun routersId(): List { + fun routersId(): Result> { return session.getRoutersId() } } \ No newline at end of file diff --git a/zenoh-kotlin/src/commonMain/kotlin/io/zenoh/jni/JNISession.kt b/zenoh-kotlin/src/commonMain/kotlin/io/zenoh/jni/JNISession.kt index e14d4d869..f212b013b 100644 --- a/zenoh-kotlin/src/commonMain/kotlin/io/zenoh/jni/JNISession.kt +++ b/zenoh-kotlin/src/commonMain/kotlin/io/zenoh/jni/JNISession.kt @@ -251,16 +251,21 @@ internal class JNISession { ) } - @Throws(Exception::class) - fun peersZid(): List { - return getPeersZidViaJNI(sessionPtr.get()).map { ZenohID(it) } + fun zid(): Result = runCatching { + ZenohID(getZidViaJNI(sessionPtr.get())) } - @Throws(Exception::class) - fun routersZid(): List { - return getRoutersZidViaJNI(sessionPtr.get()).map { ZenohID(it) } + fun peersZid(): Result> = runCatching { + getPeersZidViaJNI(sessionPtr.get()).map { ZenohID(it) } + } + + fun routersZid(): Result> = runCatching { + getRoutersZidViaJNI(sessionPtr.get()).map { ZenohID(it) } } + @Throws(Exception::class) + private external fun getZidViaJNI(ptr: Long): ByteArray + @Throws(Exception::class) private external fun getPeersZidViaJNI(ptr: Long): List diff --git a/zenoh-kotlin/src/commonTest/kotlin/io/zenoh/SessionInfoTest.kt b/zenoh-kotlin/src/commonTest/kotlin/io/zenoh/SessionInfoTest.kt new file mode 100644 index 000000000..e5595aa80 --- /dev/null +++ b/zenoh-kotlin/src/commonTest/kotlin/io/zenoh/SessionInfoTest.kt @@ -0,0 +1,109 @@ +// +// Copyright (c) 2023 ZettaScale Technology +// +// This program and the accompanying materials are made available under the +// terms of the Eclipse Public License 2.0 which is available at +// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 +// which is available at https://www.apache.org/licenses/LICENSE-2.0. +// +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// +// Contributors: +// ZettaScale Zenoh Team, +// + +package io.zenoh + +import org.junit.jupiter.api.Test +import kotlin.test.assertEquals +import kotlin.test.assertTrue + +class SessionInfoTest { + + @Test + fun `peersZid test`() { + val jsonConfig = """ + { + mode: "peer", + connect: { + endpoints: ["tcp/localhost:7450"], + }, + } + """.trimIndent() + + val listenConfig = Config.fromJson(""" + { + mode: "peer", + listen: { + endpoints: ["tcp/localhost:7450"], + }, + } + """.trimIndent()).getOrThrow() + + val sessionC = Zenoh.open(listenConfig).getOrThrow() + val sessionA = Zenoh.open(Config.fromJson(jsonConfig).getOrThrow()).getOrThrow() + val sessionB = Zenoh.open(Config.fromJson(jsonConfig).getOrThrow()).getOrThrow() + + val idA = sessionA.info().id().getOrThrow() + val idB = sessionB.info().id().getOrThrow() + val peers = sessionC.info().peersId().getOrThrow() + assertTrue(peers.contains(idA)) + assertTrue(peers.contains(idB)) + + sessionA.close() + sessionB.close() + sessionC.close() + } + + + @Test + fun `routersZid test`() { + val jsonConfig = """ + { + mode: "router", + connect: { + endpoints: ["tcp/localhost:7450"], + }, + listen: { + endpoints: ["tcp/localhost:7452"], + }, + } + """.trimIndent() + + val listenConfig = Config.fromJson(""" + { + mode: "router", + listen: { + endpoints: ["tcp/localhost:7450"], + }, + } + """.trimIndent()).getOrThrow() + + val sessionC = Zenoh.open(listenConfig).getOrThrow() + val sessionA = Zenoh.open(Config.fromJson(jsonConfig).getOrThrow()).getOrThrow() + val sessionB = Zenoh.open(Config.fromJson(jsonConfig).getOrThrow()).getOrThrow() + + val idA = sessionA.info().id().getOrThrow() + val idB = sessionB.info().id().getOrThrow() + val routers = sessionC.info().routersId().getOrThrow() + assertTrue(routers.contains(idA)) + assertTrue(routers.contains(idB)) + + sessionA.close() + sessionB.close() + sessionC.close() + } + + @Test + fun `zid test`() { + val jsonConfig = """ + { + id: "123456", + } + """.trimIndent() + + val session = Zenoh.open(Config.fromJson(jsonConfig).getOrThrow()).getOrThrow() + assertEquals("123456", session.info().id().getOrThrow().toString()) + session.close() + } +} From 40550e37ae7eddffb450f61a6bcde0dcddc458e7 Mon Sep 17 00:00:00 2001 From: Darius Maitia Date: Wed, 18 Sep 2024 21:26:26 -0300 Subject: [PATCH 3/4] Session info: adding kdocs + cargo clippy --- zenoh-jni/src/session.rs | 17 +++++++++++------ .../commonMain/kotlin/io/zenoh/SessionInfo.kt | 12 ++++++++++++ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/zenoh-jni/src/session.rs b/zenoh-jni/src/session.rs index 9829dd3b9..0231e8468 100644 --- a/zenoh-jni/src/session.rs +++ b/zenoh-jni/src/session.rs @@ -1037,6 +1037,8 @@ fn on_reply_error( result } +/// Returns a list of zenoh ids as byte arrays corresponding to the peers connected to the session provided. +/// #[no_mangle] #[allow(non_snake_case)] pub unsafe extern "C" fn Java_io_zenoh_jni_JNISession_getPeersZidViaJNI( @@ -1045,11 +1047,11 @@ pub unsafe extern "C" fn Java_io_zenoh_jni_JNISession_getPeersZidViaJNI( session_ptr: *const Session, ) -> jobject { let session = Arc::from_raw(session_ptr); - let ids = || -> Result { + let ids = { let peers_zid = session.info().peers_zid().wait(); let ids = peers_zid.collect::>(); ids_to_java_list(&mut env, ids).map_err(|err| jni_error!(err)) - }() + } .unwrap_or_else(|err| { throw_exception!(env, err); JObject::default().as_raw() @@ -1058,6 +1060,8 @@ pub unsafe extern "C" fn Java_io_zenoh_jni_JNISession_getPeersZidViaJNI( ids } +/// Returns a list of zenoh ids as byte arrays corresponding to the routers connected to the session provided. +/// #[no_mangle] #[allow(non_snake_case)] pub unsafe extern "C" fn Java_io_zenoh_jni_JNISession_getRoutersZidViaJNI( @@ -1066,11 +1070,11 @@ pub unsafe extern "C" fn Java_io_zenoh_jni_JNISession_getRoutersZidViaJNI( session_ptr: *const Session, ) -> jobject { let session = Arc::from_raw(session_ptr); - let ids = || -> Result { + let ids = { let peers_zid = session.info().routers_zid().wait(); let ids = peers_zid.collect::>(); ids_to_java_list(&mut env, ids).map_err(|err| jni_error!(err)) - }() + } .unwrap_or_else(|err| { throw_exception!(env, err); JObject::default().as_raw() @@ -1079,6 +1083,7 @@ pub unsafe extern "C" fn Java_io_zenoh_jni_JNISession_getRoutersZidViaJNI( ids } +/// Returns the Zenoh ID as a byte array of the session. #[no_mangle] #[allow(non_snake_case)] pub unsafe extern "C" fn Java_io_zenoh_jni_JNISession_getZidViaJNI( @@ -1087,12 +1092,12 @@ pub unsafe extern "C" fn Java_io_zenoh_jni_JNISession_getZidViaJNI( session_ptr: *const Session, ) -> jbyteArray { let session = Arc::from_raw(session_ptr); - let ids = || -> Result { + let ids = { let zid = session.info().zid().wait(); env.byte_array_from_slice(&zid.to_le_bytes()) .map(|x| x.as_raw()) .map_err(|err| jni_error!(err)) - }() + } .unwrap_or_else(|err| { throw_exception!(env, err); JByteArray::default().as_raw() diff --git a/zenoh-kotlin/src/commonMain/kotlin/io/zenoh/SessionInfo.kt b/zenoh-kotlin/src/commonMain/kotlin/io/zenoh/SessionInfo.kt index b6cffb3e0..b01c7f258 100644 --- a/zenoh-kotlin/src/commonMain/kotlin/io/zenoh/SessionInfo.kt +++ b/zenoh-kotlin/src/commonMain/kotlin/io/zenoh/SessionInfo.kt @@ -16,16 +16,28 @@ package io.zenoh import io.zenoh.protocol.ZenohID +/** + * Class allowing to obtain the information of a [Session]. + */ class SessionInfo(private val session: Session) { + /** + * Return the [ZenohID] of the current Zenoh [Session] + */ fun id(): Result { return session.zid() } + /** + * Return the [ZenohID] of the zenoh peers the session is currently connected to. + */ fun peersId(): Result> { return session.getPeersId() } + /** + * Return the [ZenohID] of the zenoh routers the session is currently connected to. + */ fun routersId(): Result> { return session.getRoutersId() } From 57abe17eb26733cc8fc6bab3afc83a371ca28cf2 Mon Sep 17 00:00:00 2001 From: Darius Maitia Date: Thu, 19 Sep 2024 11:14:03 -0300 Subject: [PATCH 4/4] Session info: renaming functions --- examples/src/main/kotlin/io.zenoh/ZInfo.kt | 6 +++--- .../src/commonMain/kotlin/io/zenoh/SessionInfo.kt | 8 ++++---- .../commonTest/kotlin/io/zenoh/SessionInfoTest.kt | 14 +++++++------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/examples/src/main/kotlin/io.zenoh/ZInfo.kt b/examples/src/main/kotlin/io.zenoh/ZInfo.kt index 1a2b098a0..1bf3e7ea8 100644 --- a/examples/src/main/kotlin/io.zenoh/ZInfo.kt +++ b/examples/src/main/kotlin/io.zenoh/ZInfo.kt @@ -29,11 +29,11 @@ class ZInfo(private val emptyArgs: Boolean) : CliktCommand( Zenoh.open(config).onSuccess { session -> session.use { val info = session.info() - println("zid: ${info.id().getOrThrow()}") + println("zid: ${info.zid().getOrThrow()}") - println("routers zid: ${info.routersId().getOrThrow()}") + println("routers zid: ${info.routersZid().getOrThrow()}") - println("peers zid: ${info.peersId().getOrThrow()}") + println("peers zid: ${info.peersZid().getOrThrow()}") } }.onFailure { exception -> println(exception.message) } } diff --git a/zenoh-kotlin/src/commonMain/kotlin/io/zenoh/SessionInfo.kt b/zenoh-kotlin/src/commonMain/kotlin/io/zenoh/SessionInfo.kt index b01c7f258..468a43792 100644 --- a/zenoh-kotlin/src/commonMain/kotlin/io/zenoh/SessionInfo.kt +++ b/zenoh-kotlin/src/commonMain/kotlin/io/zenoh/SessionInfo.kt @@ -24,21 +24,21 @@ class SessionInfo(private val session: Session) { /** * Return the [ZenohID] of the current Zenoh [Session] */ - fun id(): Result { + fun zid(): Result { return session.zid() } /** * Return the [ZenohID] of the zenoh peers the session is currently connected to. */ - fun peersId(): Result> { + fun peersZid(): Result> { return session.getPeersId() } /** * Return the [ZenohID] of the zenoh routers the session is currently connected to. */ - fun routersId(): Result> { + fun routersZid(): Result> { return session.getRoutersId() } -} \ No newline at end of file +} diff --git a/zenoh-kotlin/src/commonTest/kotlin/io/zenoh/SessionInfoTest.kt b/zenoh-kotlin/src/commonTest/kotlin/io/zenoh/SessionInfoTest.kt index e5595aa80..125a139fa 100644 --- a/zenoh-kotlin/src/commonTest/kotlin/io/zenoh/SessionInfoTest.kt +++ b/zenoh-kotlin/src/commonTest/kotlin/io/zenoh/SessionInfoTest.kt @@ -44,9 +44,9 @@ class SessionInfoTest { val sessionA = Zenoh.open(Config.fromJson(jsonConfig).getOrThrow()).getOrThrow() val sessionB = Zenoh.open(Config.fromJson(jsonConfig).getOrThrow()).getOrThrow() - val idA = sessionA.info().id().getOrThrow() - val idB = sessionB.info().id().getOrThrow() - val peers = sessionC.info().peersId().getOrThrow() + val idA = sessionA.info().zid().getOrThrow() + val idB = sessionB.info().zid().getOrThrow() + val peers = sessionC.info().peersZid().getOrThrow() assertTrue(peers.contains(idA)) assertTrue(peers.contains(idB)) @@ -83,9 +83,9 @@ class SessionInfoTest { val sessionA = Zenoh.open(Config.fromJson(jsonConfig).getOrThrow()).getOrThrow() val sessionB = Zenoh.open(Config.fromJson(jsonConfig).getOrThrow()).getOrThrow() - val idA = sessionA.info().id().getOrThrow() - val idB = sessionB.info().id().getOrThrow() - val routers = sessionC.info().routersId().getOrThrow() + val idA = sessionA.info().zid().getOrThrow() + val idB = sessionB.info().zid().getOrThrow() + val routers = sessionC.info().routersZid().getOrThrow() assertTrue(routers.contains(idA)) assertTrue(routers.contains(idB)) @@ -103,7 +103,7 @@ class SessionInfoTest { """.trimIndent() val session = Zenoh.open(Config.fromJson(jsonConfig).getOrThrow()).getOrThrow() - assertEquals("123456", session.info().id().getOrThrow().toString()) + assertEquals("123456", session.info().zid().getOrThrow().toString()) session.close() } }