Skip to content

Commit

Permalink
Making Session.open(config) internal, exposing it through Zenoh.open(…
Browse files Browse the repository at this point in the history
…config)
  • Loading branch information
DariusIMP committed Sep 13, 2024
1 parent cc56928 commit a113cc2
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 9 deletions.
2 changes: 1 addition & 1 deletion examples/src/main/kotlin/io.zenoh/ZDelete.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ZDelete(private val emptyArgs: Boolean) : CliktCommand(
val config = loadConfig(emptyArgs, configFile, connect, listen, noMulticastScouting, mode)

println("Opening session...")
Session.open(config).onSuccess { session ->
Zenoh.open(config).onSuccess { session ->
session.use {
key.intoKeyExpr().onSuccess { keyExpr ->
println("Deleting resources matching '$keyExpr'...")
Expand Down
2 changes: 1 addition & 1 deletion examples/src/main/kotlin/io.zenoh/ZGet.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ZGet(private val emptyArgs: Boolean) : CliktCommand(
override fun run() {
val config = loadConfig(emptyArgs, configFile, connect, listen, noMulticastScouting, mode)

Session.open(config).onSuccess { session ->
Zenoh.open(config).onSuccess { session ->
session.use {
selector.intoSelector().onSuccess { selector ->
session.get(selector,
Expand Down
2 changes: 1 addition & 1 deletion examples/src/main/kotlin/io.zenoh/ZPub.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ZPub(private val emptyArgs: Boolean) : CliktCommand(
val config = loadConfig(emptyArgs, configFile, connect, listen, noMulticastScouting, mode)

println("Opening session...")
Session.open(config).onSuccess { session ->
Zenoh.open(config).onSuccess { session ->
session.use {
key.intoKeyExpr().onSuccess { keyExpr ->
println("Declaring publisher on '$keyExpr'...")
Expand Down
2 changes: 1 addition & 1 deletion examples/src/main/kotlin/io.zenoh/ZPubThr.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class ZPubThr(private val emptyArgs: Boolean) : CliktCommand(
priority = priorityInput?.let { Priority.entries[it] } ?: Priority.DATA,
)

Session.open(config).onSuccess {
Zenoh.open(config).onSuccess {
it.use { session ->
session.declarePublisher("test/thr".intoKeyExpr().getOrThrow(), qos = qos).onSuccess { pub ->
println("Publisher declared on test/thr.")
Expand Down
2 changes: 1 addition & 1 deletion examples/src/main/kotlin/io.zenoh/ZPut.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class ZPut(private val emptyArgs: Boolean) : CliktCommand(
val config = loadConfig(emptyArgs, configFile, connect, listen, noMulticastScouting, mode)

println("Opening Session...")
Session.open(config).onSuccess { session ->
Zenoh.open(config).onSuccess { session ->
session.use {
key.intoKeyExpr().onSuccess { keyExpr ->
keyExpr.use {
Expand Down
2 changes: 1 addition & 1 deletion examples/src/main/kotlin/io.zenoh/ZQueryable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ZQueryable(private val emptyArgs: Boolean) : CliktCommand(
override fun run() {
val config = loadConfig(emptyArgs, configFile, connect, listen, noMulticastScouting, mode)

Session.open(config).onSuccess { session ->
Zenoh.open(config).onSuccess { session ->
session.use {
key.intoKeyExpr().onSuccess { keyExpr ->
println("Declaring Queryable on $key...")
Expand Down
2 changes: 1 addition & 1 deletion examples/src/main/kotlin/io.zenoh/ZSub.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ZSub(private val emptyArgs: Boolean) : CliktCommand(
val config = loadConfig(emptyArgs, configFile, connect, listen, noMulticastScouting, mode)

println("Opening session...")
Session.open(config).onSuccess { session ->
Zenoh.open(config).onSuccess { session ->
session.use {
key.intoKeyExpr().onSuccess { keyExpr ->
keyExpr.use {
Expand Down
2 changes: 1 addition & 1 deletion examples/src/main/kotlin/io.zenoh/ZSubThr.kt
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class ZSubThr(private val emptyArgs: Boolean) : CliktCommand(
"test/thr".intoKeyExpr().onSuccess { keyExpr ->
keyExpr.use {
println("Opening Session")
Session.open(config).onSuccess { session ->
Zenoh.open(config).onSuccess { session ->
session.use {
println("Press CTRL-C to quit...")
subscriber =
Expand Down
4 changes: 3 additions & 1 deletion zenoh-kotlin/src/commonMain/kotlin/io/zenoh/Session.kt
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,12 @@ class Session private constructor(private val config: Config) : AutoCloseable {
/**
* Open a [Session] with the provided [Config].
*
* Note: Use [Zenoh.open] to launch a session.
*
* @param config The configuration for the session.
* @return A [Result] with the [Session] on success.
*/
fun open(config: Config): Result<Session> {
internal fun open(config: Config): Result<Session> {
val session = Session(config)
return session.launch()
}
Expand Down
10 changes: 10 additions & 0 deletions zenoh-kotlin/src/commonMain/kotlin/io/zenoh/Zenoh.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ import kotlinx.coroutines.channels.Channel

object Zenoh {

/**
* Open a [Session] with the provided [Config].
*
* @param config The configuration for the session.
* @return A [Result] with the [Session] on success.
*/
fun open(config: Config): Result<Session> {
return Session.open(config)
}

/**
* Scout for routers and/or peers.
*
Expand Down

0 comments on commit a113cc2

Please sign in to comment.