Skip to content
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
uses: actions/checkout@v4
with:
repository: ZettaScaleLabs/zenoh-flat-jni
ref: 757cc6ad7e346f428ffc5e3252ba01ff4d19ba9b
ref: 249fe9e34ac5d05bc442355fd216a324114e2621
path: zenoh-flat-jni

- name: Check out zenoh-flat
Expand Down
12 changes: 6 additions & 6 deletions zenoh-java/src/commonMain/kotlin/io/zenoh/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class Config internal constructor(internal val zConfig: JniConfig) {
*/
@JvmStatic
@Throws(ZError::class)
fun fromFile(path: Path): Config = Config(JniConfig.newFromFile(path.toString(), throwZError))
fun fromFile(path: Path): Config = Config(JniConfig.newFromFile(path.toString(), throwZError0, throwZError))

/**
* Loads the configuration from json-formatted string.
Expand All @@ -85,7 +85,7 @@ class Config internal constructor(internal val zConfig: JniConfig) {
*/
@JvmStatic
@Throws(ZError::class)
fun fromJson(config: String): Config = Config(JniConfig.newFromJson(config, throwZError))
fun fromJson(config: String): Config = Config(JniConfig.newFromJson(config, throwZError0, throwZError))

/**
* Loads the configuration from json5-formatted string.
Expand All @@ -98,7 +98,7 @@ class Config internal constructor(internal val zConfig: JniConfig) {
*/
@JvmStatic
@Throws(ZError::class)
fun fromJson5(config: String): Config = Config(JniConfig.newFromJson5(config, throwZError))
fun fromJson5(config: String): Config = Config(JniConfig.newFromJson5(config, throwZError0, throwZError))

/**
* Loads the configuration from yaml-formatted string.
Expand All @@ -111,7 +111,7 @@ class Config internal constructor(internal val zConfig: JniConfig) {
*/
@JvmStatic
@Throws(ZError::class)
fun fromYaml(config: String): Config = Config(JniConfig.newFromYaml(config, throwZError))
fun fromYaml(config: String): Config = Config(JniConfig.newFromYaml(config, throwZError0, throwZError))

/**
* Loads the configuration from the env variable [CONFIG_ENV].
Expand All @@ -134,12 +134,12 @@ class Config internal constructor(internal val zConfig: JniConfig) {
* The json value associated to the [key].
*/
@Throws(ZError::class)
fun getJson(key: String): String = zConfig.getJson(key, throwZError)
fun getJson(key: String): String = zConfig.getJson(key, throwZError0, throwZError)

/**
* Inserts a json5 value associated to the [key] into the Config.
*/
@Throws(ZError::class)
fun insertJson5(key: String, value: String) =
zConfig.insertJson5(key, value, throwZError)
zConfig.insertJson5(key, value, throwZError0, throwZError)
}
26 changes: 13 additions & 13 deletions zenoh-java/src/commonMain/kotlin/io/zenoh/Session.kt
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ class Session private constructor(private val config: Config) : AutoCloseable {
// The one place a KeyExpr carries a native handle: the wire
// declaration attached here makes sends through this session
// compact, so the handle is worth holding.
KeyExpr(keyExpr, zSession.declareKeyexpr(keyExpr, throwZError))
KeyExpr(keyExpr, zSession.declareKeyexpr(keyExpr, throwZError0, throwZError))
}
strongDeclarations.add(keyexpr)
return keyexpr
Expand All @@ -422,7 +422,7 @@ class Session private constructor(private val config: Config) : AutoCloseable {
throw ZError("Attempting to undeclare a non declared key expression.")
}
try {
zSession.undeclareKeyexpr(handle, throwZError)
zSession.undeclareKeyexpr(handle, throwZError0, throwZError)
} finally {
// The generated wrapper consumes the handle even when the native
// undeclare fails (the Rust side takes it by value) — detach it
Expand Down Expand Up @@ -614,7 +614,7 @@ class Session private constructor(private val config: Config) : AutoCloseable {
options.priority.jni,
options.express,
options.reliability.jni,
throwZError
throwZError0, throwZError
)
Publisher(
keyExpr,
Expand All @@ -638,7 +638,7 @@ class Session private constructor(private val config: Config) : AutoCloseable {
keyExpr.jniSel, keyExpr.jniStr, keyExpr.cloneHandle(),
sampleCallbackOf { handler.handle(it) },
{ handler.onClose() },
throwZError
throwZError0, throwZError
)
HandlerSubscriber(keyExpr, zSubscriber, handler.receiver())
}
Expand All @@ -656,7 +656,7 @@ class Session private constructor(private val config: Config) : AutoCloseable {
keyExpr.jniSel, keyExpr.jniStr, keyExpr.cloneHandle(),
sampleCallbackOf { callback.run(it) },
{ },
throwZError
throwZError0, throwZError
)
CallbackSubscriber(keyExpr, zSubscriber)
}
Expand All @@ -675,7 +675,7 @@ class Session private constructor(private val config: Config) : AutoCloseable {
options.complete,
queryCallbackOf { handler.handle(it) },
{ handler.onClose() },
throwZError
throwZError0, throwZError
)
HandlerQueryable(keyExpr, zQueryable, handler.receiver())
}
Expand All @@ -694,7 +694,7 @@ class Session private constructor(private val config: Config) : AutoCloseable {
options.complete,
queryCallbackOf { callback.run(it) },
{ },
throwZError
throwZError0, throwZError
)
CallbackQueryable(keyExpr, zQueryable)
}
Expand All @@ -718,7 +718,7 @@ class Session private constructor(private val config: Config) : AutoCloseable {
options.express,
options.timeout.toMillis(),
options.acceptReplies.toFlat(),
throwZError
throwZError0, throwZError
)
Querier(
keyExpr,
Expand Down Expand Up @@ -758,7 +758,7 @@ class Session private constructor(private val config: Config) : AutoCloseable {
options.attachment?.into()?.bytes,
replyCallbackOf { handler.handle(it) },
{ handler.onClose() },
throwZError
throwZError0, throwZError
)
handler.receiver()
}
Expand Down Expand Up @@ -788,7 +788,7 @@ class Session private constructor(private val config: Config) : AutoCloseable {
options.attachment?.into()?.bytes,
replyCallbackOf { callback.run(it) },
{ },
throwZError
throwZError0, throwZError
)
}
}
Expand All @@ -807,7 +807,7 @@ class Session private constructor(private val config: Config) : AutoCloseable {
putOptions.express,
putOptions.attachment?.into()?.bytes,
putOptions.reliability.jni,
throwZError
throwZError0, throwZError
)
}
}
Expand All @@ -823,7 +823,7 @@ class Session private constructor(private val config: Config) : AutoCloseable {
deleteOptions.express,
deleteOptions.attachment?.into()?.bytes,
deleteOptions.reliability.jni,
throwZError
throwZError0, throwZError
)
}
}
Expand Down Expand Up @@ -853,7 +853,7 @@ class Session private constructor(private val config: Config) : AutoCloseable {
private fun launch(): Session {
this.zSession = io.zenoh.jni.session.Session.open(
config.zConfig.newClone(throwZError0),
throwZError,
throwZError0, throwZError,
)
return this
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,24 @@ import io.zenoh.jni.errors.ErrorHandler
/**
* Error-callback handlers passed to the generated flat-jni wrappers. In the
* canonical model a wrapper never throws from native code — on failure it
* invokes its trailing `onError` handler (a generated typed `fun interface`).
* These handlers throw [ZError] directly, so the SDK no longer needs a
* `try/catch` translation layer.
* invokes an error handler (a generated typed `fun interface`). These handlers
* throw [ZError] directly, so the SDK no longer needs a `try/catch` layer.
*
* `je` is the binding-layer error (UTF-8 decode, closed handle, …); `ze` is the
* library (zenoh) error message. Exactly one is set. The handlers bind the
* interface's `out R` to [Nothing], which is a subtype of every `R`, so a
* single instance satisfies every wrapper's `onError` regardless of its
* return type (declaration-site covariance).
* The generated protocol has two independent channels (prebindgen #45): a
* fallible wrapper takes `onBindingError` (a [JniErrorHandler], any
* binding-layer failure — UTF-8 decode, closed handle, …) followed by
* `onError` (the typed domain [ErrorHandler], the decomposed zenoh error);
* an infallible wrapper takes only the binding [JniErrorHandler]. The handlers
* bind the interface's `out R` to [Nothing], a subtype of every `R`, so a
* single instance satisfies every wrapper regardless of its return type
* (declaration-site covariance).
*/

/** Handler for a fallible wrapper (`Result<_, ZError>`): `run(je, message)`.
* `message` is builder-typed (non-null) — on a binding error (`je != null`)
* the native side fills it with the default `""`. */
/** Domain handler for a fallible wrapper (`Result<_, ZError>`): `run(message)`. */
internal val throwZError: ErrorHandler<Nothing> =
ErrorHandler { je, message -> throw ZError(je ?: message) }
ErrorHandler { message -> throw ZError(message) }

/** Handler for an infallible wrapper (binding errors only): `run(je)`. */
/** Binding handler — the `onBindingError` of a fallible wrapper AND the sole
* `onError` of an infallible one: `run(je)`. */
internal val throwZError0: JniErrorHandler<Nothing> =
JniErrorHandler { je -> throw ZError(je ?: "native binding error") }
14 changes: 7 additions & 7 deletions zenoh-java/src/commonMain/kotlin/io/zenoh/keyexpr/KeyExpr.kt
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class KeyExpr internal constructor(
private inline fun <R> withHandle(body: (JniKeyExpr) -> R): R {
val h = handle
if (h != null) return body(h)
val tmp = JniKeyExpr.newTryFrom(keyExprString, throwZError)
val tmp = JniKeyExpr.newTryFrom(keyExprString, throwZError0, throwZError)
try {
return body(tmp)
} finally {
Expand Down Expand Up @@ -110,7 +110,7 @@ class KeyExpr internal constructor(
@JvmStatic
@Throws(ZError::class)
fun tryFrom(keyExpr: String): KeyExpr {
JniKeyExpr.newTryFrom(keyExpr, throwZError).close()
JniKeyExpr.newTryFrom(keyExpr, throwZError0, throwZError).close()
return KeyExpr(keyExpr)
}

Expand All @@ -127,7 +127,7 @@ class KeyExpr internal constructor(
@JvmStatic
@Throws(ZError::class)
fun autocanonize(keyExpr: String): KeyExpr {
val probe = JniKeyExpr.newAutocanonize(keyExpr, throwZError)
val probe = JniKeyExpr.newAutocanonize(keyExpr, throwZError0, throwZError)
try {
return KeyExpr(probe.getStr(throwZError0))
} finally {
Expand Down Expand Up @@ -178,8 +178,8 @@ class KeyExpr internal constructor(
fun join(other: String): KeyExpr {
// The companion factory validates and joins natively; the result is a
// fresh (declaration-less) handle — keep its canonical string only.
val probe = handle?.let { JniKeyExpr.newJoin(it, other, throwZError) }
?: JniKeyExpr.newJoin(keyExprString, other, throwZError)
val probe = handle?.let { JniKeyExpr.newJoin(it, other, throwZError0, throwZError) }
?: JniKeyExpr.newJoin(keyExprString, other, throwZError0, throwZError)
try {
return KeyExpr(probe.getStr(throwZError0))
} finally {
Expand All @@ -193,8 +193,8 @@ class KeyExpr internal constructor(
*/
@Throws(ZError::class)
fun concat(other: String): KeyExpr {
val probe = handle?.let { JniKeyExpr.newConcat(it, other, throwZError) }
?: JniKeyExpr.newConcat(keyExprString, other, throwZError)
val probe = handle?.let { JniKeyExpr.newConcat(it, other, throwZError0, throwZError) }
?: JniKeyExpr.newConcat(keyExprString, other, throwZError0, throwZError)
try {
return KeyExpr(probe.getStr(throwZError0))
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import io.zenoh.replyCallbackOf
import io.zenoh.sampleCallbackOf
import io.zenoh.exceptions.ZError
import io.zenoh.exceptions.throwZError
import io.zenoh.exceptions.throwZError0
import io.zenoh.handlers.BlockingQueueHandler
import io.zenoh.handlers.Callback
import io.zenoh.handlers.Handler
Expand Down Expand Up @@ -54,7 +55,7 @@ class Liveliness internal constructor(private val session: Session) {
@Throws(ZError::class)
fun declareToken(keyExpr: KeyExpr): LivelinessToken {
val zSession = session.zSession ?: throw Session.sessionClosedException
return LivelinessToken(zSession.livelinessDeclareToken(keyExpr.jniSel, keyExpr.jniStr, keyExpr.cloneHandle(), throwZError))
return LivelinessToken(zSession.livelinessDeclareToken(keyExpr.jniSel, keyExpr.jniStr, keyExpr.cloneHandle(), throwZError0, throwZError))
}

/**
Expand All @@ -76,7 +77,7 @@ class Liveliness internal constructor(private val session: Session) {
timeout.toMillis(),
replyCallbackOf { handler.handle(it) },
{ handler.onClose() },
throwZError
throwZError0, throwZError
)
return handler.receiver()
}
Expand All @@ -99,7 +100,7 @@ class Liveliness internal constructor(private val session: Session) {
timeout.toMillis(),
replyCallbackOf { callback.run(it) },
{ },
throwZError
throwZError0, throwZError
)
}

Expand All @@ -122,7 +123,7 @@ class Liveliness internal constructor(private val session: Session) {
timeout.toMillis(),
replyCallbackOf { handler.handle(it) },
{ handler.onClose() },
throwZError
throwZError0, throwZError
)
return handler.receiver()
}
Expand All @@ -146,7 +147,7 @@ class Liveliness internal constructor(private val session: Session) {
options.history,
sampleCallbackOf { handler.handle(it) },
{ handler.onClose() },
throwZError
throwZError0, throwZError
)
return HandlerSubscriber(keyExpr, zSubscriber, handler.receiver())
}
Expand All @@ -171,7 +172,7 @@ class Liveliness internal constructor(private val session: Session) {
options.history,
sampleCallbackOf { callback.run(it) },
{ },
throwZError
throwZError0, throwZError
)
return CallbackSubscriber(keyExpr, zSubscriber)
}
Expand All @@ -197,7 +198,7 @@ class Liveliness internal constructor(private val session: Session) {
options.history,
sampleCallbackOf { handler.handle(it) },
{ handler.onClose() },
throwZError
throwZError0, throwZError
)
return HandlerSubscriber(keyExpr, zSubscriber, handler.receiver())
}
Expand Down
5 changes: 3 additions & 2 deletions zenoh-java/src/commonMain/kotlin/io/zenoh/pubsub/Publisher.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import io.zenoh.bytes.IntoZBytes
import io.zenoh.bytes.ZBytes
import io.zenoh.exceptions.ZError
import io.zenoh.exceptions.throwZError
import io.zenoh.exceptions.throwZError0
import io.zenoh.jni.pubsub.Publisher as JniPublisher
import io.zenoh.keyexpr.KeyExpr
import io.zenoh.qos.CongestionControl
Expand Down Expand Up @@ -112,7 +113,7 @@ class Publisher internal constructor(
@Throws(ZError::class)
fun delete(options: DeleteOptions = DeleteOptions()) {
val p = zPublisher ?: throw publisherNotValid
p.delete(options.attachment?.into()?.bytes, throwZError)
p.delete(options.attachment?.into()?.bytes, throwZError0, throwZError)
}

/**
Expand Down Expand Up @@ -142,7 +143,7 @@ class Publisher internal constructor(
payload.into().bytes,
encoding.jniSel, encoding.jniId, encoding.jniSchema, encoding.jniHandle,
attachment?.into()?.bytes,
throwZError,
throwZError0, throwZError,
)
}
}
5 changes: 3 additions & 2 deletions zenoh-java/src/commonMain/kotlin/io/zenoh/query/Querier.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import io.zenoh.bytes.IntoZBytes
import io.zenoh.bytes.ZBytes
import io.zenoh.exceptions.ZError
import io.zenoh.exceptions.throwZError
import io.zenoh.exceptions.throwZError0
import io.zenoh.handlers.BlockingQueueHandler
import io.zenoh.handlers.Callback
import io.zenoh.handlers.Handler
Expand Down Expand Up @@ -154,7 +155,7 @@ class Querier internal constructor(val keyExpr: KeyExpr, val qos: QoS, private v
options.attachment?.into()?.bytes,
replyCallbackOf { callback.run(it) },
{ },
throwZError
throwZError0, throwZError
)
}

Expand All @@ -167,7 +168,7 @@ class Querier internal constructor(val keyExpr: KeyExpr, val qos: QoS, private v
options.attachment?.into()?.bytes,
replyCallbackOf { handler.handle(it) },
{ handler.onClose() },
throwZError
throwZError0, throwZError
)
return handler.receiver()
}
Expand Down
Loading
Loading