Skip to content

Commit

Permalink
feat: store whatami mode in session
Browse files Browse the repository at this point in the history
  • Loading branch information
jean-roland committed Jan 13, 2025
1 parent 3eed5a5 commit 82f8512
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions include/zenoh-pico/net/session.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ typedef struct _z_session_t {
#endif // Z_FEATURE_MULTI_THREAD == 1

// Zenoh-pico is considering a single transport per session.
z_whatami_t _mode;
_z_transport_t _tp;

// Zenoh PID
Expand Down
10 changes: 8 additions & 2 deletions src/api/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,9 @@ z_result_t z_close(z_loaned_session_t *zs, const z_close_options_t *options) {
bool z_session_is_closed(const z_loaned_session_t *zs) { return _z_session_is_closed(_Z_RC_IN_VAL(zs)); }

z_result_t z_info_peers_zid(const z_loaned_session_t *zs, z_moved_closure_zid_t *callback) {
if (_Z_RC_IN_VAL(zs)->_mode != Z_WHATAMI_PEER) {
return _Z_RES_OK;
}
// Call transport function
switch (_Z_RC_IN_VAL(zs)->_tp._type) {
case _Z_TRANSPORT_MULTICAST_TYPE:
Expand All @@ -745,10 +748,13 @@ z_result_t z_info_peers_zid(const z_loaned_session_t *zs, z_moved_closure_zid_t
callback->_this._val.drop(ctx);
}
z_internal_closure_zid_null(&callback->_this);
return 0;
return _Z_RES_OK;
}

z_result_t z_info_routers_zid(const z_loaned_session_t *zs, z_moved_closure_zid_t *callback) {
if (_Z_RC_IN_VAL(zs)->_mode != Z_WHATAMI_CLIENT) {
return _Z_RES_OK;
}
// Call transport function
switch (_Z_RC_IN_VAL(zs)->_tp._type) {
case _Z_TRANSPORT_UNICAST_TYPE:
Expand All @@ -765,7 +771,7 @@ z_result_t z_info_routers_zid(const z_loaned_session_t *zs, z_moved_closure_zid_
callback->_this._val.drop(ctx);
}
z_internal_closure_zid_null(&callback->_this);
return 0;
return _Z_RES_OK;
}

z_id_t z_info_zid(const z_loaned_session_t *zs) { return _Z_RC_IN_VAL(zs)->_local_zid; }
Expand Down
4 changes: 1 addition & 3 deletions src/net/session.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ static z_result_t _z_open_inner(_z_session_rc_t *zn, _z_string_t *locator, const

_z_transport_get_common(&zt)->_session = zn;
_Z_RC_IN_VAL(zn)->_tp = zt;
_Z_RC_IN_VAL(zn)->_mode = mode;
return ret;
}

Expand All @@ -153,9 +154,6 @@ z_result_t _z_open(_z_session_rc_t *zn, _z_config_t *config, const _z_id_t *zid)
ret = _Z_RES_OK;

_z_string_t *locator = _z_string_svec_get(&locators, i);
// @TODO: check invalid configurations
// For example, client mode in multicast links

ret = _z_open_inner(zn, locator, zid, mode, peer_op);
if (ret == _Z_RES_OK) {
break;
Expand Down

0 comments on commit 82f8512

Please sign in to comment.