Skip to content

Commit 2d48599

Browse files
committed
made zenoh_flat calls template-ready
1 parent 1fa32f2 commit 2d48599

2 files changed

Lines changed: 33 additions & 34 deletions

File tree

zenoh-flat/src/session.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ pub fn declare_querier(
9696
query_target: QueryTarget,
9797
consolidation: ConsolidationMode,
9898
congestion_control: CongestionControl,
99-
express: bool,
10099
priority: Priority,
100+
express: bool,
101101
timeout: Duration,
102102
reply_key_expr: ReplyKeyExpr,
103103
) -> ZResult<Querier<'static>> {
@@ -154,8 +154,8 @@ pub fn put(
154154
congestion_control: CongestionControl,
155155
priority: Priority,
156156
express: bool,
157-
reliability: Reliability,
158157
attachment: Option<Vec<u8>>,
158+
reliability: Reliability,
159159
) -> ZResult<()> {
160160
let key_expr_string = key_expr.to_string();
161161
let mut put_builder = session
@@ -188,8 +188,8 @@ pub fn delete(
188188
congestion_control: CongestionControl,
189189
priority: Priority,
190190
express: bool,
191-
reliability: Reliability,
192191
attachment: Option<Vec<u8>>,
192+
reliability: Reliability,
193193
) -> ZResult<()> {
194194
let key_expr_string = key_expr.to_string();
195195
let mut delete_builder = session

zenoh-jni/src/session.rs

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,15 @@ pub unsafe extern "C" fn Java_io_zenoh_jni_JNISession_openSessionViaJNI(
6464
_class: JClass,
6565
config_ptr: *const Config,
6666
) -> *const Session {
67-
let config = unsafe { OwnedObject::from_raw(config_ptr) };
68-
let session = zenoh_flat::session::open_session(&config);
69-
match session {
70-
Ok(session) => Arc::into_raw(Arc::new(session)),
71-
Err(err) => {
72-
tracing::error!("Unable to open session: {}", err);
73-
throw_exception!(env, zerror!(err));
74-
null()
75-
}
76-
}
67+
let config = OwnedObject::from_raw(config_ptr);
68+
|| -> ZResult<*const Session> {
69+
let session = zenoh_flat::session::open_session(&config)?;
70+
Ok(Arc::into_raw(Arc::new(session)))
71+
}()
72+
.unwrap_or_else(|err| {
73+
throw_exception!(env, err);
74+
null()
75+
})
7776
}
7877

7978
/// Closes a Zenoh session via JNI.
@@ -97,9 +96,10 @@ pub unsafe extern "C" fn Java_io_zenoh_jni_JNISession_closeSessionViaJNI(
9796
session_ptr: *const Session,
9897
) {
9998
let session = Arc::from_raw(session_ptr);
100-
if let Err(err) = zenoh_flat::session::close_session(&session) {
101-
throw_exception!(env, err);
102-
}
99+
let _ = || -> ZResult<()> {
100+
zenoh_flat::session::close_session(&session)
101+
}()
102+
.map_err(|err| throw_exception!(env, err));
103103
}
104104

105105
/// Declare a Zenoh publisher via JNI.
@@ -145,13 +145,14 @@ pub unsafe extern "C" fn Java_io_zenoh_jni_JNISession_declarePublisherViaJNI(
145145
let key_expr = process_kotlin_key_expr(&mut env, &key_expr_str, key_expr_ptr)?;
146146
let congestion_control = decode_congestion_control(congestion_control)?;
147147
let priority = decode_priority(priority)?;
148+
let is_express = is_express != 0;
148149
let reliability = decode_reliability(reliability)?;
149150
let publisher = zenoh_flat::session::declare_publisher(
150151
&session,
151152
key_expr,
152153
congestion_control,
153154
priority,
154-
is_express != 0,
155+
is_express,
155156
reliability,
156157
)?;
157158
Ok(Arc::into_raw(Arc::new(publisher)))
@@ -212,13 +213,13 @@ pub unsafe extern "C" fn Java_io_zenoh_jni_JNISession_putViaJNI(
212213
let encoding = decode_encoding(&mut env, encoding_id, &encoding_schema)?;
213214
let congestion_control = decode_congestion_control(congestion_control)?;
214215
let priority = decode_priority(priority)?;
215-
let reliability = decode_reliability(reliability)?;
216-
216+
let is_express = is_express != 0;
217217
let attachment = if !attachment.is_null() {
218218
Some(decode_byte_array(&env, attachment)?)
219219
} else {
220220
None
221221
};
222+
let reliability = decode_reliability(reliability)?;
222223

223224
zenoh_flat::session::put(
224225
&session,
@@ -227,9 +228,9 @@ pub unsafe extern "C" fn Java_io_zenoh_jni_JNISession_putViaJNI(
227228
encoding,
228229
congestion_control,
229230
priority,
230-
is_express != 0,
231-
reliability,
231+
is_express,
232232
attachment,
233+
reliability,
233234
)
234235
}()
235236
.map_err(|err| throw_exception!(env, err));
@@ -278,22 +279,22 @@ pub unsafe extern "C" fn Java_io_zenoh_jni_JNISession_deleteViaJNI(
278279
let key_expr = process_kotlin_key_expr(&mut env, &key_expr_str, key_expr_ptr)?;
279280
let congestion_control = decode_congestion_control(congestion_control)?;
280281
let priority = decode_priority(priority)?;
281-
let reliability = decode_reliability(reliability)?;
282-
282+
let is_express = is_express != 0;
283283
let attachment = if !attachment.is_null() {
284284
Some(decode_byte_array(&env, attachment)?)
285285
} else {
286286
None
287287
};
288+
let reliability = decode_reliability(reliability)?;
288289

289290
zenoh_flat::session::delete(
290291
&session,
291292
key_expr,
292293
congestion_control,
293294
priority,
294-
is_express != 0,
295-
reliability,
295+
is_express,
296296
attachment,
297+
reliability,
297298
)
298299
}()
299300
.map_err(|err| throw_exception!(env, err));
@@ -344,8 +345,7 @@ pub unsafe extern "C" fn Java_io_zenoh_jni_JNISession_declareSubscriberViaJNI(
344345
&session,
345346
key_expr,
346347
callback,
347-
)
348-
.map_err(|err| zerror!("Unable to declare subscriber: {}", err))?;
348+
)?;
349349

350350
Ok(Arc::into_raw(Arc::new(subscriber)))
351351
}()
@@ -394,8 +394,9 @@ pub unsafe extern "C" fn Java_io_zenoh_jni_JNISession_declareQuerierViaJNI(
394394
let query_target = decode_query_target(target)?;
395395
let consolidation = decode_consolidation(consolidation)?;
396396
let congestion_control = decode_congestion_control(congestion_control)?;
397-
let timeout = Duration::from_millis(timeout_ms as u64);
398397
let priority = decode_priority(priority)?;
398+
let is_express = is_express != 0;
399+
let timeout = Duration::from_millis(timeout_ms as u64);
399400
let reply_key_expr = decode_reply_key_expr(accept_replies)?;
400401

401402
let querier = zenoh_flat::session::declare_querier(
@@ -404,12 +405,11 @@ pub unsafe extern "C" fn Java_io_zenoh_jni_JNISession_declareQuerierViaJNI(
404405
query_target,
405406
consolidation,
406407
congestion_control,
407-
is_express != 0,
408408
priority,
409+
is_express,
409410
timeout,
410411
reply_key_expr,
411-
)
412-
.map_err(|err| zerror!("Unable to declare querier: {}", err))?;
412+
)?;
413413

414414
Ok(Arc::into_raw(Arc::new(querier)))
415415
}()
@@ -462,11 +462,10 @@ pub unsafe extern "C" fn Java_io_zenoh_jni_JNISession_declareQueryableViaJNI(
462462
let session = OwnedObject::from_raw(session_ptr);
463463
|| -> ZResult<*const Queryable<()>> {
464464
let key_expr = process_kotlin_key_expr(&mut env, &key_expr_str, key_expr_ptr)?;
465-
let complete = complete != 0;
466465
let callback = process_kotlin_query_callback(&mut env, callback, on_close)?;
466+
let complete = complete != 0;
467467

468-
let queryable = zenoh_flat::session::declare_queryable(&session, key_expr, callback, complete)
469-
.map_err(|err| zerror!("Unable to declare queryable: {}", err))?;
468+
let queryable = zenoh_flat::session::declare_queryable(&session, key_expr, callback, complete)?;
470469

471470
Ok(Arc::into_raw(Arc::new(queryable)))
472471
}()

0 commit comments

Comments
 (0)