Skip to content

Commit

Permalink
Add feature flag
Browse files Browse the repository at this point in the history
  • Loading branch information
sashacmc committed Dec 18, 2024
1 parent b632bca commit b6c7473
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 12 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ set(Z_FEATURE_LOCAL_SUBSCRIBER 0 CACHE STRING "Toggle local subscriptions")
set(Z_FEATURE_PUBLISHER_SESSION_CHECK 1 CACHE STRING "Toggle publisher session check")
set(Z_FEATURE_BATCHING 1 CACHE STRING "Toggle batching")
set(Z_FEATURE_RX_CACHE 0 CACHE STRING "Toggle RX_CACHE")
set(Z_FEATURE_AUTO_RECONNECT 1 CACHE STRING "Toggle automatic reconnection")

# Add a warning message if someone tries to enable Z_FEATURE_LINK_SERIAL_USB directly
if(Z_FEATURE_LINK_SERIAL_USB AND NOT Z_FEATURE_UNSTABLE_API)
Expand All @@ -261,6 +262,7 @@ message(STATUS "Building with feature confing:\n\
* QUERYABLE: ${Z_FEATURE_QUERYABLE}\n\
* LIVELINESS: ${Z_FEATURE_LIVELINESS}\n\
* INTEREST: ${Z_FEATURE_INTEREST}\n\
* AUTO_RECONNECT: ${Z_FEATURE_AUTO_RECONNECT}\n\
* RAWETH: ${Z_FEATURE_RAWETH_TRANSPORT}")

configure_file(
Expand Down
3 changes: 2 additions & 1 deletion include/zenoh-pico/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#define Z_FEATURE_SUBSCRIPTION 1
#define Z_FEATURE_QUERY 1
#define Z_FEATURE_QUERYABLE 1
#define Z_FEATURE_LIVELINESS 0
#define Z_FEATURE_LIVELINESS 1
#define Z_FEATURE_RAWETH_TRANSPORT 0
#define Z_FEATURE_INTEREST 1
#define Z_FEATURE_DYNAMIC_MEMORY_ALLOCATION 0
Expand All @@ -48,6 +48,7 @@
#define Z_FEATURE_PUBLISHER_SESSION_CHECK 1
#define Z_FEATURE_BATCHING 1
#define Z_FEATURE_RX_CACHE 0
#define Z_FEATURE_AUTO_RECONNECT 1
// End of CMake generation

/*------------------ Runtime configuration properties ------------------*/
Expand Down
1 change: 1 addition & 0 deletions include/zenoh-pico/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#define Z_FEATURE_PUBLISHER_SESSION_CHECK @Z_FEATURE_PUBLISHER_SESSION_CHECK@
#define Z_FEATURE_BATCHING @Z_FEATURE_BATCHING@
#define Z_FEATURE_RX_CACHE @Z_FEATURE_RX_CACHE@
#define Z_FEATURE_AUTO_RECONNECT @Z_FEATURE_AUTO_RECONNECT@
// End of CMake generation

/*------------------ Runtime configuration properties ------------------*/
Expand Down
7 changes: 4 additions & 3 deletions include/zenoh-pico/net/session.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ extern "C" {
typedef struct _z_session_t {
#if Z_FEATURE_MULTI_THREAD == 1
_z_mutex_t _mutex_inner;
z_task_attr_t *_lease_task_attr;
z_task_attr_t *_read_task_attr;
#endif // Z_FEATURE_MULTI_THREAD == 1

// Zenoh-pico is considering a single transport per session.
Expand All @@ -58,10 +56,13 @@ typedef struct _z_session_t {
_z_resource_list_t *_local_resources;
_z_resource_list_t *_remote_resources;

#if Z_FEATURE_AUTO_RECONNECT == 1
// Information for session restoring
// Empty _config means session is not restorable
_z_config_t _config;
_z_network_message_list_t *_decalaration_cache;
z_task_attr_t *_lease_task_attr;
z_task_attr_t *_read_task_attr;
#endif

// Session subscriptions
#if Z_FEATURE_SUBSCRIPTION == 1
Expand Down
14 changes: 8 additions & 6 deletions src/api/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -702,13 +702,15 @@ z_result_t z_open(z_owned_session_t *zs, z_moved_config_t *config, const z_open_
z_config_drop(config);
return ret;
}

// Clean up
if (/* session is restorable*/ true) {
_Z_OWNED_RC_IN_VAL(zs)->_config = config->_this._val;
z_internal_config_null(&config->_this);
} else {
z_config_drop(config);
}
#if Z_FEATURE_AUTO_RECONNECT == 1
_Z_OWNED_RC_IN_VAL(zs)->_config = config->_this._val;
z_internal_config_null(&config->_this);
#else
z_config_drop(config);
#endif

return _Z_RES_OK;
}

Expand Down
8 changes: 8 additions & 0 deletions src/net/primitives.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,26 @@
static z_result_t _z_send_decalre(_z_session_t *zn, const _z_network_message_t *n_msg) {
z_result_t ret = _Z_RES_OK;
ret = _z_send_n_msg(zn, n_msg, Z_RELIABILITY_RELIABLE, Z_CONGESTION_CONTROL_BLOCK);

#if Z_FEATURE_AUTO_RECONNECT == 1
if (ret == _Z_RES_OK) {
_z_cache_declaration(zn, n_msg);
}
#endif

return ret;
}

static z_result_t _z_send_undecalre(_z_session_t *zn, const _z_network_message_t *n_msg) {
z_result_t ret = _Z_RES_OK;
ret = _z_send_n_msg(zn, n_msg, Z_RELIABILITY_RELIABLE, Z_CONGESTION_CONTROL_BLOCK);

#if Z_FEATURE_AUTO_RECONNECT == 1
if (ret == _Z_RES_OK) {
_z_prune_declaration(zn, n_msg);
}
#endif

return ret;
}
/*------------------ Scouting ------------------*/
Expand Down
7 changes: 7 additions & 0 deletions src/net/session.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ z_result_t _z_open(_z_session_rc_t *zn, _z_config_t *config, const _z_id_t *zid)
return ret;
}

#if Z_FEATURE_AUTO_RECONNECT == 1

z_result_t _z_reopen(_z_session_rc_t *zn) {
z_result_t ret = _Z_RES_OK;
_z_session_t *zs = _Z_RC_IN_VAL(zn);
Expand Down Expand Up @@ -260,6 +262,7 @@ void _z_prune_declaration(_z_session_t *zs, const _z_network_message_t *n_msg) {
assert(cnt_before == cnt_after + 1);
#endif
}
#endif // Z_FEATURE_AUTO_RECONNECT == 1

void _z_close(_z_session_t *zn) { _z_session_close(zn, _Z_CLOSE_GENERIC); }

Expand Down Expand Up @@ -329,8 +332,10 @@ z_result_t _zp_start_read_task(_z_session_t *zn, z_task_attr_t *attr) {
// Free task if operation failed
if (ret != _Z_RES_OK) {
z_free(task);
#if Z_FEATURE_AUTO_RECONNECT == 1
} else {
zn->_read_task_attr = attr;
#endif
}
return ret;
}
Expand Down Expand Up @@ -360,8 +365,10 @@ z_result_t _zp_start_lease_task(_z_session_t *zn, z_task_attr_t *attr) {
// Free task if operation failed
if (ret != _Z_RES_OK) {
z_free(task);
#if Z_FEATURE_AUTO_RECONNECT == 1
} else {
zn->_lease_task_attr = attr;
#endif
}
return ret;
}
Expand Down
5 changes: 5 additions & 0 deletions src/session/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ z_result_t _z_session_init(_z_session_t *zn, const _z_id_t *zid) {
zn->_resource_id = 1;
zn->_query_id = 1;

#if Z_FEATURE_AUTO_RECONNECT == 1
_z_config_init(&zn->_config);
zn->_decalaration_cache = NULL;
#endif

// Initialize the data structs
zn->_local_resources = NULL;
Expand Down Expand Up @@ -108,8 +111,10 @@ void _z_session_clear(_z_session_t *zn) {
_zp_stop_lease_task(zn);
#endif

#if Z_FEATURE_AUTO_RECONNECT == 1
_z_config_clear(&zn->_config);
_z_network_message_list_free(&zn->_decalaration_cache);
#endif

_z_close(zn);
// Clear Zenoh PID
Expand Down
8 changes: 7 additions & 1 deletion src/transport/multicast/lease.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "zenoh-pico/session/utils.h"
#include "zenoh-pico/transport/multicast/lease.h"
#include "zenoh-pico/utils/logging.h"
#include "zenoh-pico/utils/result.h"

#if Z_FEATURE_MULTICAST_TRANSPORT == 1 || Z_FEATURE_RAWETH_TRANSPORT == 1

Expand Down Expand Up @@ -55,7 +56,12 @@ z_result_t _zp_multicast_send_keep_alive(_z_transport_multicast_t *ztm) {

#if Z_FEATURE_MULTI_THREAD == 1 && (Z_FEATURE_MULTICAST_TRANSPORT == 1 || Z_FEATURE_RAWETH_TRANSPORT == 1)

static void _zp_multicast_failed(_z_transport_multicast_t *ztm) { _z_reopen(ztm->_common._session); }
static void _zp_multicast_failed(_z_transport_multicast_t *ztm) {
_ZP_UNUSED(ztm);
#if Z_FEATURE_AUTO_RECONNECT == 1
_z_reopen(ztm->_common._session);
#endif
}

static _z_zint_t _z_get_minimum_lease(_z_transport_peer_entry_list_t *peers, _z_zint_t local_lease) {
_z_zint_t ret = local_lease;
Expand Down
5 changes: 4 additions & 1 deletion src/transport/unicast/lease.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,13 @@ z_result_t _zp_unicast_send_keep_alive(_z_transport_unicast_t *ztu) {
#if Z_FEATURE_MULTI_THREAD == 1 && Z_FEATURE_UNICAST_TRANSPORT == 1

static void _zp_unicast_failed(_z_transport_unicast_t *ztu) {
_z_session_rc_ref_t *zs = ztu->_common._session;
_z_unicast_transport_close(ztu, _Z_CLOSE_EXPIRED);
_z_unicast_transport_clear(ztu, true);

#if Z_FEATURE_AUTO_RECONNECT == 1
_z_session_rc_ref_t *zs = ztu->_common._session;
_z_reopen(zs);
#endif
}

void *_zp_unicast_lease_task(void *ztu_arg) {
Expand Down

0 comments on commit b6c7473

Please sign in to comment.