From da7c3307d5601e61195949a61ef296caae6f7d0c Mon Sep 17 00:00:00 2001 From: Jean-Roland Date: Mon, 13 Nov 2023 14:59:11 +0100 Subject: [PATCH] refactor: apply header changes to source files --- src/net/session.c | 10 +- src/session/tx.c | 3 +- src/transport/common/join.c | 4 +- src/transport/common/lease.c | 5 +- src/transport/common/read.c | 5 +- src/transport/common/rx.c | 3 +- src/transport/common/tx.c | 3 +- src/transport/manager.c | 4 +- src/transport/multicast.c | 69 +++++++++++ .../multicast/{link/task => }/join.c | 4 +- .../multicast/{link/task => }/lease.c | 44 ++++++- .../multicast/{link/task => }/read.c | 36 +++++- src/transport/multicast/{link => }/rx.c | 2 +- .../multicast/{multicast.c => transport.c} | 109 ++---------------- src/transport/multicast/{link => }/tx.c | 3 +- src/transport/transport.c | 10 +- src/transport/unicast.c | 60 ++++++++++ src/transport/unicast/{link/task => }/lease.c | 37 +++++- src/transport/unicast/{link/task => }/read.c | 35 +++++- src/transport/unicast/{link => }/rx.c | 2 +- .../unicast/{unicast.c => transport.c} | 100 ++-------------- src/transport/unicast/{link => }/tx.c | 3 +- 22 files changed, 323 insertions(+), 228 deletions(-) create mode 100644 src/transport/multicast.c rename src/transport/multicast/{link/task => }/join.c (92%) rename src/transport/multicast/{link/task => }/lease.c (78%) rename src/transport/multicast/{link/task => }/read.c (78%) rename src/transport/multicast/{link => }/rx.c (99%) rename src/transport/multicast/{multicast.c => transport.c} (68%) rename src/transport/multicast/{link => }/tx.c (98%) create mode 100644 src/transport/unicast.c rename src/transport/unicast/{link/task => }/lease.c (72%) rename src/transport/unicast/{link/task => }/read.c (77%) rename src/transport/unicast/{link => }/rx.c (99%) rename src/transport/unicast/{unicast.c => transport.c} (79%) rename src/transport/unicast/{link => }/tx.c (98%) diff --git a/src/net/session.c b/src/net/session.c index 6e4296d3f..f0e2f3b30 100644 --- a/src/net/session.c +++ b/src/net/session.c @@ -24,11 +24,15 @@ #include "zenoh-pico/net/memory.h" #include "zenoh-pico/protocol/core.h" #include "zenoh-pico/session/utils.h" -#include "zenoh-pico/transport/link/task/join.h" -#include "zenoh-pico/transport/link/task/lease.h" -#include "zenoh-pico/transport/link/task/read.h" +#include "zenoh-pico/transport/common/join.h" +#include "zenoh-pico/transport/common/lease.h" +#include "zenoh-pico/transport/common/read.h" #include "zenoh-pico/transport/multicast.h" +#include "zenoh-pico/transport/multicast/lease.h" +#include "zenoh-pico/transport/multicast/read.h" #include "zenoh-pico/transport/unicast.h" +#include "zenoh-pico/transport/unicast/lease.h" +#include "zenoh-pico/transport/unicast/read.h" #include "zenoh-pico/utils/logging.h" #include "zenoh-pico/utils/uuid.h" diff --git a/src/session/tx.c b/src/session/tx.c index 0694b04d0..b00c072f2 100644 --- a/src/session/tx.c +++ b/src/session/tx.c @@ -12,8 +12,9 @@ // ZettaScale Zenoh Team, // -#include "zenoh-pico/transport/link/tx.h" +#include "zenoh-pico/transport/multicast/tx.h" +#include "zenoh-pico/transport/unicast/tx.h" #include "zenoh-pico/utils/logging.h" int8_t _z_send_n_msg(_z_session_t *zn, const _z_network_message_t *z_msg, z_reliability_t reliability, diff --git a/src/transport/common/join.c b/src/transport/common/join.c index 97214d3f2..4d3c8498a 100644 --- a/src/transport/common/join.c +++ b/src/transport/common/join.c @@ -12,7 +12,9 @@ // ZettaScale Zenoh Team, // -#include "zenoh-pico/transport/link/task/join.h" +#include "zenoh-pico/transport/common/join.h" + +#include "zenoh-pico/transport/multicast/join.h" int8_t _z_send_join(_z_transport_t *zt) { int8_t ret = _Z_RES_OK; diff --git a/src/transport/common/lease.c b/src/transport/common/lease.c index 26f467fef..8e337f497 100644 --- a/src/transport/common/lease.c +++ b/src/transport/common/lease.c @@ -12,10 +12,13 @@ // ZettaScale Zenoh Team, // -#include "zenoh-pico/transport/link/task/lease.h" +#include "zenoh-pico/transport/common/lease.h" #include +#include "zenoh-pico/transport/multicast/lease.h" +#include "zenoh-pico/transport/unicast/lease.h" + int8_t _z_send_keep_alive(_z_transport_t *zt) { int8_t ret = _Z_RES_OK; switch (zt->_type) { diff --git a/src/transport/common/read.c b/src/transport/common/read.c index a4cae9ee3..a9e2485a4 100644 --- a/src/transport/common/read.c +++ b/src/transport/common/read.c @@ -12,10 +12,13 @@ // ZettaScale Zenoh Team, // -#include "zenoh-pico/transport/link/task/read.h" +#include "zenoh-pico/transport/common/read.h" #include +#include "zenoh-pico/transport/multicast/read.h" +#include "zenoh-pico/transport/unicast/read.h" + int8_t _z_read(_z_transport_t *zt) { int8_t ret = _Z_RES_OK; switch (zt->_type) { diff --git a/src/transport/common/rx.c b/src/transport/common/rx.c index 5a7d2e45a..67692eb3c 100644 --- a/src/transport/common/rx.c +++ b/src/transport/common/rx.c @@ -12,11 +12,12 @@ // ZettaScale Zenoh Team, // -#include "zenoh-pico/transport/link/rx.h" +#include "zenoh-pico/transport/multicast/rx.h" #include #include "zenoh-pico/protocol/codec/transport.h" +#include "zenoh-pico/transport/unicast/rx.h" #include "zenoh-pico/utils/logging.h" /*------------------ Reception helper ------------------*/ diff --git a/src/transport/common/tx.c b/src/transport/common/tx.c index c61e6629b..f0d68eb6c 100644 --- a/src/transport/common/tx.c +++ b/src/transport/common/tx.c @@ -12,12 +12,13 @@ // ZettaScale Zenoh Team, // -#include "zenoh-pico/transport/link/tx.h" +#include "zenoh-pico/transport/multicast/tx.h" #include "zenoh-pico/api/constants.h" #include "zenoh-pico/protocol/codec/core.h" #include "zenoh-pico/protocol/codec/transport.h" #include "zenoh-pico/protocol/definitions/transport.h" +#include "zenoh-pico/transport/unicast/tx.h" #include "zenoh-pico/utils/logging.h" /*------------------ Transmission helper ------------------*/ diff --git a/src/transport/manager.c b/src/transport/manager.c index bfeb6f3a0..06662e513 100644 --- a/src/transport/manager.c +++ b/src/transport/manager.c @@ -17,8 +17,8 @@ #include #include -#include "zenoh-pico/transport/multicast.h" -#include "zenoh-pico/transport/unicast.h" +#include "zenoh-pico/transport/multicast/transport.h" +#include "zenoh-pico/transport/unicast/transport.h" int8_t _z_new_transport_client(_z_transport_t *zt, char *locator, _z_id_t *local_zid) { int8_t ret = _Z_RES_OK; diff --git a/src/transport/multicast.c b/src/transport/multicast.c new file mode 100644 index 000000000..8cb6c3dc7 --- /dev/null +++ b/src/transport/multicast.c @@ -0,0 +1,69 @@ +// +// Copyright (c) 2022 ZettaScale Technology +// +// This program and the accompanying materials are made available under the +// terms of the Eclipse Public License 2.0 which is available at +// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 +// which is available at https://www.apache.org/licenses/LICENSE-2.0. +// +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// +// Contributors: +// ZettaScale Zenoh Team, + +#include "zenoh-pico/transport/multicast.h" + +#include +#include +#include +#include +#include + +#include "zenoh-pico/link/link.h" +#include "zenoh-pico/transport/common/lease.h" +#include "zenoh-pico/transport/common/read.h" +#include "zenoh-pico/transport/common/tx.h" +#include "zenoh-pico/transport/multicast/rx.h" +#include "zenoh-pico/transport/multicast/tx.h" +#include "zenoh-pico/transport/unicast/rx.h" +#include "zenoh-pico/transport/utils.h" +#include "zenoh-pico/utils/logging.h" + +#if Z_FEATURE_MULTICAST_TRANSPORT == 1 +bool _zp_is_multicast_here(void) { return true; } + +void _zp_multicast_fetch_zid(const _z_transport_t *zt, z_owned_closure_zid_t *callback) { + void *ctx = callback->context; + _z_transport_peer_entry_list_t *l = zt->_transport._multicast._peers; + for (; l != NULL; l = _z_transport_peer_entry_list_tail(l)) { + _z_transport_peer_entry_t *val = _z_transport_peer_entry_list_head(l); + z_id_t id = val->_remote_zid; + + callback->call(&id, ctx); + } +} + +void _zp_multicast_info_session(const _z_transport_t *zt, _z_config_t *ps) { + _z_transport_peer_entry_list_t *xs = zt->_transport._multicast._peers; + while (xs != NULL) { + _z_transport_peer_entry_t *peer = _z_transport_peer_entry_list_head(xs); + _z_bytes_t remote_zid = _z_bytes_wrap(peer->_remote_zid.id, _z_id_len(peer->_remote_zid)); + _zp_config_insert(ps, Z_INFO_PEER_PID_KEY, _z_string_from_bytes(&remote_zid)); + + xs = _z_transport_peer_entry_list_tail(xs); + } +} + +#else +bool _zp_is_multicast_here(void) { return false; } + +void _zp_multicast_fetch_zid(const _z_transport_t *zt, z_owned_closure_zid_t *callback) { + _ZP_UNUSED(zt); + _ZP_UNUSED(callback); +} + +void _zp_multicast_info_session(const _z_transport_t *zt, _z_config_t *ps) { + _ZP_UNUSED(zt); + _ZP_UNUSED(ps); +} +#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 \ No newline at end of file diff --git a/src/transport/multicast/link/task/join.c b/src/transport/multicast/join.c similarity index 92% rename from src/transport/multicast/link/task/join.c rename to src/transport/multicast/join.c index 9c437f83c..d577db1da 100644 --- a/src/transport/multicast/link/task/join.c +++ b/src/transport/multicast/join.c @@ -12,10 +12,10 @@ // ZettaScale Zenoh Team, // -#include "zenoh-pico/transport/link/task/join.h" +#include "zenoh-pico/transport/multicast/join.h" #include "zenoh-pico/session/utils.h" -#include "zenoh-pico/transport/link/tx.h" +#include "zenoh-pico/transport/multicast/tx.h" #if Z_FEATURE_MULTICAST_TRANSPORT == 1 diff --git a/src/transport/multicast/link/task/lease.c b/src/transport/multicast/lease.c similarity index 78% rename from src/transport/multicast/link/task/lease.c rename to src/transport/multicast/lease.c index 3f748716b..dd861644b 100644 --- a/src/transport/multicast/link/task/lease.c +++ b/src/transport/multicast/lease.c @@ -12,20 +12,21 @@ // ZettaScale Zenoh Team, // -#include "zenoh-pico/transport/link/task/lease.h" +#include "zenoh-pico/transport/multicast/lease.h" #include #include "zenoh-pico/config.h" #include "zenoh-pico/session/utils.h" -#include "zenoh-pico/transport/link/task/join.h" -#include "zenoh-pico/transport/link/tx.h" -#include "zenoh-pico/transport/multicast.h" +#include "zenoh-pico/transport/common/join.h" +#include "zenoh-pico/transport/multicast/join.h" +#include "zenoh-pico/transport/multicast/transport.h" +#include "zenoh-pico/transport/multicast/tx.h" #include "zenoh-pico/utils/logging.h" #if Z_FEATURE_MULTICAST_TRANSPORT == 1 -_z_zint_t _z_get_minimum_lease(_z_transport_peer_entry_list_t *peers, _z_zint_t local_lease) { +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; _z_transport_peer_entry_list_t *it = peers; @@ -42,7 +43,7 @@ _z_zint_t _z_get_minimum_lease(_z_transport_peer_entry_list_t *peers, _z_zint_t return ret; } -_z_zint_t _z_get_next_lease(_z_transport_peer_entry_list_t *peers) { +static _z_zint_t _z_get_next_lease(_z_transport_peer_entry_list_t *peers) { _z_zint_t ret = SIZE_MAX; _z_transport_peer_entry_list_t *it = peers; @@ -68,6 +69,25 @@ int8_t _zp_multicast_send_keep_alive(_z_transport_multicast_t *ztm) { return ret; } +int _zp_multicast_start_lease_task(_z_transport_t *zt, _z_task_attr_t *attr, _z_task_t *task) { + // Init memory + (void)memset(task, 0, sizeof(_z_task_t)); + // Attach task + zt->_transport._multicast._lease_task = task; + zt->_transport._multicast._lease_task_running = true; + // Init task + if (_z_task_init(task, attr, _zp_multicast_lease_task, &zt->_transport._multicast) != _Z_RES_OK) { + zt->_transport._multicast._lease_task_running = false; + return _Z_ERR_SYSTEM_TASK_FAILED; + } + return _Z_RES_OK; +} + +int _zp_multicast_stop_lease_task(_z_transport_t *zt) { + zt->_transport._multicast._lease_task_running = false; + return _Z_RES_OK; +} + void *_zp_multicast_lease_task(void *ztm_arg) { #if Z_FEATURE_MULTI_THREAD == 1 _z_transport_multicast_t *ztm = (_z_transport_multicast_t *)ztm_arg; @@ -169,6 +189,18 @@ int8_t _zp_multicast_send_keep_alive(_z_transport_multicast_t *ztm) { return _Z_ERR_TRANSPORT_NOT_AVAILABLE; } +int _zp_multicast_start_lease_task(_z_transport_t *zt, _z_task_attr_t *attr, _z_task_t *task) { + _ZP_UNUSED(zt); + _ZP_UNUSED(attr); + _ZP_UNUSED(task); + return _Z_ERR_TRANSPORT_NOT_AVAILABLE; +} + +int _zp_multicast_stop_lease_task(_z_transport_t *zt) { + _ZP_UNUSED(zt); + return _Z_ERR_TRANSPORT_NOT_AVAILABLE; +} + void *_zp_multicast_lease_task(void *ztm_arg) { _ZP_UNUSED(ztm_arg); return NULL; diff --git a/src/transport/multicast/link/task/read.c b/src/transport/multicast/read.c similarity index 78% rename from src/transport/multicast/link/task/read.c rename to src/transport/multicast/read.c index 2b4b24d4f..896f07081 100644 --- a/src/transport/multicast/link/task/read.c +++ b/src/transport/multicast/read.c @@ -12,14 +12,15 @@ // ZettaScale Zenoh Team, // -#include "zenoh-pico/transport/link/task/read.h" +#include "zenoh-pico/transport/multicast/read.h" #include #include "zenoh-pico/config.h" #include "zenoh-pico/protocol/codec/transport.h" #include "zenoh-pico/protocol/iobuf.h" -#include "zenoh-pico/transport/link/rx.h" +#include "zenoh-pico/transport/multicast/rx.h" +#include "zenoh-pico/transport/unicast/rx.h" #include "zenoh-pico/utils/logging.h" #if Z_FEATURE_MULTICAST_TRANSPORT == 1 @@ -38,6 +39,25 @@ int8_t _zp_multicast_read(_z_transport_multicast_t *ztm) { return ret; } +int _zp_multicast_start_read_task(_z_transport_t *zt, _z_task_attr_t *attr, _z_task_t *task) { + // Init memory + (void)memset(task, 0, sizeof(_z_task_t)); + // Attach task + zt->_transport._multicast._read_task = task; + zt->_transport._multicast._read_task_running = true; + // Init task + if (_z_task_init(task, attr, _zp_multicast_read_task, &zt->_transport._multicast) != _Z_RES_OK) { + zt->_transport._multicast._read_task_running = false; + return _Z_ERR_SYSTEM_TASK_FAILED; + } + return _Z_RES_OK; +} + +int _zp_multicast_stop_read_task(_z_transport_t *zt) { + zt->_transport._multicast._read_task_running = false; + return _Z_RES_OK; +} + void *_zp_multicast_read_task(void *ztm_arg) { #if Z_FEATURE_MULTI_THREAD == 1 _z_transport_multicast_t *ztm = (_z_transport_multicast_t *)ztm_arg; @@ -123,6 +143,18 @@ int8_t _zp_multicast_read(_z_transport_multicast_t *ztm) { return _Z_ERR_TRANSPORT_NOT_AVAILABLE; } +int _zp_multicast_start_read_task(_z_transport_t *zt, _z_task_attr_t *attr, _z_task_t *task) { + _ZP_UNUSED(zt); + _ZP_UNUSED(attr); + _ZP_UNUSED(task); + return _Z_ERR_TRANSPORT_NOT_AVAILABLE; +} + +int _zp_multicast_stop_read_task(_z_transport_t *zt) { + _ZP_UNUSED(zt); + return _Z_ERR_TRANSPORT_NOT_AVAILABLE; +} + void *_zp_multicast_read_task(void *ztm_arg) { _ZP_UNUSED(ztm_arg); return NULL; diff --git a/src/transport/multicast/link/rx.c b/src/transport/multicast/rx.c similarity index 99% rename from src/transport/multicast/link/rx.c rename to src/transport/multicast/rx.c index 1a63b5951..6d73c10f8 100644 --- a/src/transport/multicast/link/rx.c +++ b/src/transport/multicast/rx.c @@ -12,7 +12,7 @@ // ZettaScale Zenoh Team, // -#include "zenoh-pico/transport/link/rx.h" +#include "zenoh-pico/transport/multicast/rx.h" #include #include diff --git a/src/transport/multicast/multicast.c b/src/transport/multicast/transport.c similarity index 68% rename from src/transport/multicast/multicast.c rename to src/transport/multicast/transport.c index 678b0880a..7622012b6 100644 --- a/src/transport/multicast/multicast.c +++ b/src/transport/multicast/transport.c @@ -11,8 +11,6 @@ // Contributors: // ZettaScale Zenoh Team, -#include "zenoh-pico/transport/multicast.h" - #include #include #include @@ -20,75 +18,17 @@ #include #include "zenoh-pico/link/link.h" -#include "zenoh-pico/transport/link/rx.h" -#include "zenoh-pico/transport/link/task/lease.h" -#include "zenoh-pico/transport/link/task/read.h" -#include "zenoh-pico/transport/link/tx.h" +#include "zenoh-pico/transport/common/lease.h" +#include "zenoh-pico/transport/common/read.h" +#include "zenoh-pico/transport/common/tx.h" +#include "zenoh-pico/transport/multicast.h" +#include "zenoh-pico/transport/multicast/rx.h" +#include "zenoh-pico/transport/multicast/tx.h" +#include "zenoh-pico/transport/unicast/rx.h" #include "zenoh-pico/transport/utils.h" #include "zenoh-pico/utils/logging.h" #if Z_FEATURE_MULTICAST_TRANSPORT == 1 -bool _zp_is_multicast_here(void) { return true; } - -void _zp_multicast_fetch_zid(const _z_transport_t *zt, z_owned_closure_zid_t *callback) { - void *ctx = callback->context; - _z_transport_peer_entry_list_t *l = zt->_transport._multicast._peers; - for (; l != NULL; l = _z_transport_peer_entry_list_tail(l)) { - _z_transport_peer_entry_t *val = _z_transport_peer_entry_list_head(l); - z_id_t id = val->_remote_zid; - - callback->call(&id, ctx); - } -} - -void _zp_multicast_info_session(const _z_transport_t *zt, _z_config_t *ps) { - _z_transport_peer_entry_list_t *xs = zt->_transport._multicast._peers; - while (xs != NULL) { - _z_transport_peer_entry_t *peer = _z_transport_peer_entry_list_head(xs); - _z_bytes_t remote_zid = _z_bytes_wrap(peer->_remote_zid.id, _z_id_len(peer->_remote_zid)); - _zp_config_insert(ps, Z_INFO_PEER_PID_KEY, _z_string_from_bytes(&remote_zid)); - - xs = _z_transport_peer_entry_list_tail(xs); - } -} - -int _zp_multicast_start_read_task(_z_transport_t *zt, _z_task_attr_t *attr, _z_task_t *task) { - // Init memory - (void)memset(task, 0, sizeof(_z_task_t)); - // Attach task - zt->_transport._multicast._read_task = task; - zt->_transport._multicast._read_task_running = true; - // Init task - if (_z_task_init(task, attr, _zp_multicast_read_task, &zt->_transport._multicast) != _Z_RES_OK) { - zt->_transport._multicast._read_task_running = false; - return _Z_ERR_SYSTEM_TASK_FAILED; - } - return _Z_RES_OK; -} - -int _zp_multicast_start_lease_task(_z_transport_t *zt, _z_task_attr_t *attr, _z_task_t *task) { - // Init memory - (void)memset(task, 0, sizeof(_z_task_t)); - // Attach task - zt->_transport._multicast._lease_task = task; - zt->_transport._multicast._lease_task_running = true; - // Init task - if (_z_task_init(task, attr, _zp_multicast_lease_task, &zt->_transport._multicast) != _Z_RES_OK) { - zt->_transport._multicast._lease_task_running = false; - return _Z_ERR_SYSTEM_TASK_FAILED; - } - return _Z_RES_OK; -} - -int _zp_multicast_stop_read_task(_z_transport_t *zt) { - zt->_transport._multicast._read_task_running = false; - return _Z_RES_OK; -} - -int _zp_multicast_stop_lease_task(_z_transport_t *zt) { - zt->_transport._multicast._lease_task_running = false; - return _Z_RES_OK; -} int8_t _z_multicast_transport_create(_z_transport_t *zt, _z_link_t *zl, _z_transport_multicast_establish_param_t *param) { @@ -247,41 +187,6 @@ void _z_multicast_transport_clear(_z_transport_t *zt) { } #else -bool _zp_is_multicast_here(void) { return false; } - -void _zp_multicast_fetch_zid(const _z_transport_t *zt, z_owned_closure_zid_t *callback) { - _ZP_UNUSED(zt); - _ZP_UNUSED(callback); -} - -void _zp_multicast_info_session(const _z_transport_t *zt, _z_config_t *ps) { - _ZP_UNUSED(zt); - _ZP_UNUSED(ps); -} - -int _zp_multicast_start_read_task(_z_transport_t *zt, _z_task_attr_t *attr, _z_task_t *task) { - _ZP_UNUSED(zt); - _ZP_UNUSED(attr); - _ZP_UNUSED(task); - return _Z_ERR_TRANSPORT_NOT_AVAILABLE; -} - -int _zp_multicast_start_lease_task(_z_transport_t *zt, _z_task_attr_t *attr, _z_task_t *task) { - _ZP_UNUSED(zt); - _ZP_UNUSED(attr); - _ZP_UNUSED(task); - return _Z_ERR_TRANSPORT_NOT_AVAILABLE; -} - -int _zp_multicast_stop_read_task(_z_transport_t *zt) { - _ZP_UNUSED(zt); - return _Z_ERR_TRANSPORT_NOT_AVAILABLE; -} - -int _zp_multicast_stop_lease_task(_z_transport_t *zt) { - _ZP_UNUSED(zt); - return _Z_ERR_TRANSPORT_NOT_AVAILABLE; -} int8_t _z_multicast_transport_create(_z_transport_t *zt, _z_link_t *zl, _z_transport_multicast_establish_param_t *param) { diff --git a/src/transport/multicast/link/tx.c b/src/transport/multicast/tx.c similarity index 98% rename from src/transport/multicast/link/tx.c rename to src/transport/multicast/tx.c index e82806daf..c2f665a19 100644 --- a/src/transport/multicast/link/tx.c +++ b/src/transport/multicast/tx.c @@ -12,11 +12,12 @@ // ZettaScale Zenoh Team, // -#include "zenoh-pico/transport/link/tx.h" +#include "zenoh-pico/transport/multicast/tx.h" #include "zenoh-pico/config.h" #include "zenoh-pico/protocol/codec/network.h" #include "zenoh-pico/protocol/codec/transport.h" +#include "zenoh-pico/transport/common/tx.h" #include "zenoh-pico/transport/utils.h" #include "zenoh-pico/utils/logging.h" diff --git a/src/transport/transport.c b/src/transport/transport.c index bcaeefc68..27170233c 100644 --- a/src/transport/transport.c +++ b/src/transport/transport.c @@ -21,10 +21,12 @@ #include "zenoh-pico/config.h" #include "zenoh-pico/link/link.h" #include "zenoh-pico/protocol/core.h" -#include "zenoh-pico/transport/link/rx.h" -#include "zenoh-pico/transport/link/tx.h" -#include "zenoh-pico/transport/multicast.h" -#include "zenoh-pico/transport/unicast.h" +#include "zenoh-pico/transport/multicast/rx.h" +#include "zenoh-pico/transport/multicast/transport.h" +#include "zenoh-pico/transport/multicast/tx.h" +#include "zenoh-pico/transport/unicast/rx.h" +#include "zenoh-pico/transport/unicast/transport.h" +#include "zenoh-pico/transport/unicast/tx.h" #include "zenoh-pico/transport/utils.h" #include "zenoh-pico/utils/logging.h" diff --git a/src/transport/unicast.c b/src/transport/unicast.c new file mode 100644 index 000000000..a637eb74c --- /dev/null +++ b/src/transport/unicast.c @@ -0,0 +1,60 @@ +// +// Copyright (c) 2022 ZettaScale Technology +// +// This program and the accompanying materials are made available under the +// terms of the Eclipse Public License 2.0 which is available at +// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 +// which is available at https://www.apache.org/licenses/LICENSE-2.0. +// +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// +// Contributors: +// ZettaScale Zenoh Team, + +#include "zenoh-pico/transport/unicast.h" + +#include +#include +#include +#include +#include + +#include "zenoh-pico/link/link.h" +#include "zenoh-pico/transport/common/rx.h" +#include "zenoh-pico/transport/common/tx.h" +#include "zenoh-pico/transport/multicast/rx.h" +#include "zenoh-pico/transport/unicast/lease.h" +#include "zenoh-pico/transport/unicast/read.h" +#include "zenoh-pico/transport/unicast/rx.h" +#include "zenoh-pico/transport/unicast/tx.h" +#include "zenoh-pico/transport/utils.h" +#include "zenoh-pico/utils/logging.h" + +#if Z_FEATURE_UNICAST_TRANSPORT == 1 +bool _zp_is_unicast_here(void) { return true; } + +void _zp_unicast_fetch_zid(const _z_transport_t *zt, z_owned_closure_zid_t *callback) { + void *ctx = callback->context; + z_id_t id = zt->_transport._unicast._remote_zid; + callback->call(&id, ctx); +} + +void _zp_unicast_info_session(const _z_transport_t *zt, _z_config_t *ps) { + _z_id_t remote_zid = zt->_transport._unicast._remote_zid; + _z_bytes_t remote_zidbytes = _z_bytes_wrap(remote_zid.id, _z_id_len(remote_zid)); + _zp_config_insert(ps, Z_INFO_ROUTER_PID_KEY, _z_string_from_bytes(&remote_zidbytes)); +} + +#else +bool _zp_is_unicast_here(void) { return false; } + +void _zp_unicast_fetch_zid(const _z_transport_t *zt, z_owned_closure_zid_t *callback) { + _ZP_UNUSED(zt); + _ZP_UNUSED(callback); +} + +void _zp_unicast_info_session(const _z_transport_t *zt, _z_config_t *ps) { + _ZP_UNUSED(zt); + _ZP_UNUSED(ps); +} +#endif // Z_FEATURE_UNICAST_TRANSPORT == 1 \ No newline at end of file diff --git a/src/transport/unicast/link/task/lease.c b/src/transport/unicast/lease.c similarity index 72% rename from src/transport/unicast/link/task/lease.c rename to src/transport/unicast/lease.c index a0faea956..b54ffe139 100644 --- a/src/transport/unicast/link/task/lease.c +++ b/src/transport/unicast/lease.c @@ -12,10 +12,10 @@ // ZettaScale Zenoh Team, // -#include "zenoh-pico/transport/link/task/lease.h" +#include "zenoh-pico/transport/unicast/lease.h" -#include "zenoh-pico/transport/link/tx.h" -#include "zenoh-pico/transport/unicast.h" +#include "zenoh-pico/transport/unicast/transport.h" +#include "zenoh-pico/transport/unicast/tx.h" #include "zenoh-pico/utils/logging.h" #if Z_FEATURE_UNICAST_TRANSPORT == 1 @@ -29,6 +29,25 @@ int8_t _zp_unicast_send_keep_alive(_z_transport_unicast_t *ztu) { return ret; } +int _zp_unicast_start_lease_task(_z_transport_t *zt, _z_task_attr_t *attr, _z_task_t *task) { + // Init memory + (void)memset(task, 0, sizeof(_z_task_t)); + // Attach task + zt->_transport._unicast._lease_task = task; + zt->_transport._unicast._lease_task_running = true; + // Init task + if (_z_task_init(task, attr, _zp_unicast_lease_task, &zt->_transport._unicast) != _Z_RES_OK) { + zt->_transport._unicast._lease_task_running = false; + return _Z_ERR_SYSTEM_TASK_FAILED; + } + return _Z_RES_OK; +} + +int _zp_unicast_stop_lease_task(_z_transport_t *zt) { + zt->_transport._unicast._lease_task_running = false; + return _Z_RES_OK; +} + void *_zp_unicast_lease_task(void *ztu_arg) { #if Z_FEATURE_MULTI_THREAD == 1 _z_transport_unicast_t *ztu = (_z_transport_unicast_t *)ztu_arg; @@ -94,6 +113,18 @@ int8_t _zp_unicast_send_keep_alive(_z_transport_unicast_t *ztu) { return _Z_ERR_TRANSPORT_NOT_AVAILABLE; } +int _zp_unicast_start_lease_task(_z_transport_t *zt, _z_task_attr_t *attr, _z_task_t *task) { + _ZP_UNUSED(zt); + _ZP_UNUSED(attr); + _ZP_UNUSED(task); + return _Z_ERR_TRANSPORT_NOT_AVAILABLE; +} + +int _zp_unicast_stop_lease_task(_z_transport_t *zt) { + _ZP_UNUSED(zt); + return _Z_ERR_TRANSPORT_NOT_AVAILABLE; +} + void *_zp_unicast_lease_task(void *ztu_arg) { _ZP_UNUSED(ztu_arg); return NULL; diff --git a/src/transport/unicast/link/task/read.c b/src/transport/unicast/read.c similarity index 77% rename from src/transport/unicast/link/task/read.c rename to src/transport/unicast/read.c index 649272d68..4dc7433ec 100644 --- a/src/transport/unicast/link/task/read.c +++ b/src/transport/unicast/read.c @@ -12,13 +12,13 @@ // ZettaScale Zenoh Team, // -#include "zenoh-pico/transport/link/task/read.h" +#include "zenoh-pico/transport/unicast/read.h" #include #include "zenoh-pico/config.h" #include "zenoh-pico/protocol/codec/transport.h" -#include "zenoh-pico/transport/link/rx.h" +#include "zenoh-pico/transport/unicast/rx.h" #include "zenoh-pico/utils/logging.h" #if Z_FEATURE_UNICAST_TRANSPORT == 1 @@ -36,6 +36,25 @@ int8_t _zp_unicast_read(_z_transport_unicast_t *ztu) { return ret; } +int _zp_unicast_start_read_task(_z_transport_t *zt, _z_task_attr_t *attr, _z_task_t *task) { + // Init memory + (void)memset(task, 0, sizeof(_z_task_t)); + // Attach task + zt->_transport._unicast._read_task = task; + zt->_transport._unicast._read_task_running = true; + // Init task + if (_z_task_init(task, attr, _zp_unicast_read_task, &zt->_transport._unicast) != _Z_RES_OK) { + zt->_transport._unicast._read_task_running = false; + return _Z_ERR_SYSTEM_TASK_FAILED; + } + return _Z_RES_OK; +} + +int _zp_unicast_stop_read_task(_z_transport_t *zt) { + zt->_transport._unicast._read_task_running = false; + return _Z_RES_OK; +} + void *_zp_unicast_read_task(void *ztu_arg) { #if Z_FEATURE_MULTI_THREAD == 1 _z_transport_unicast_t *ztu = (_z_transport_unicast_t *)ztu_arg; @@ -117,6 +136,18 @@ int8_t _zp_unicast_read(_z_transport_unicast_t *ztu) { return _Z_ERR_TRANSPORT_NOT_AVAILABLE; } +int _zp_unicast_start_read_task(_z_transport_t *zt, _z_task_attr_t *attr, _z_task_t *task) { + _ZP_UNUSED(zt); + _ZP_UNUSED(attr); + _ZP_UNUSED(task); + return _Z_ERR_TRANSPORT_NOT_AVAILABLE; +} + +int _zp_unicast_stop_read_task(_z_transport_t *zt) { + _ZP_UNUSED(zt); + return _Z_ERR_TRANSPORT_NOT_AVAILABLE; +} + void *_zp_unicast_read_task(void *ztu_arg) { _ZP_UNUSED(ztu_arg); return NULL; diff --git a/src/transport/unicast/link/rx.c b/src/transport/unicast/rx.c similarity index 99% rename from src/transport/unicast/link/rx.c rename to src/transport/unicast/rx.c index d23daf832..965ec58c1 100644 --- a/src/transport/unicast/link/rx.c +++ b/src/transport/unicast/rx.c @@ -12,7 +12,7 @@ // ZettaScale Zenoh Team, // -#include "zenoh-pico/transport/link/rx.h" +#include "zenoh-pico/transport/unicast/rx.h" #include diff --git a/src/transport/unicast/unicast.c b/src/transport/unicast/transport.c similarity index 79% rename from src/transport/unicast/unicast.c rename to src/transport/unicast/transport.c index 134fa5854..185608173 100644 --- a/src/transport/unicast/unicast.c +++ b/src/transport/unicast/transport.c @@ -11,8 +11,6 @@ // Contributors: // ZettaScale Zenoh Team, -#include "zenoh-pico/transport/unicast.h" - #include #include #include @@ -20,65 +18,18 @@ #include #include "zenoh-pico/link/link.h" -#include "zenoh-pico/transport/link/rx.h" -#include "zenoh-pico/transport/link/task/lease.h" -#include "zenoh-pico/transport/link/task/read.h" -#include "zenoh-pico/transport/link/tx.h" +#include "zenoh-pico/transport/common/rx.h" +#include "zenoh-pico/transport/common/tx.h" +#include "zenoh-pico/transport/multicast/rx.h" +#include "zenoh-pico/transport/unicast.h" +#include "zenoh-pico/transport/unicast/lease.h" +#include "zenoh-pico/transport/unicast/read.h" +#include "zenoh-pico/transport/unicast/rx.h" +#include "zenoh-pico/transport/unicast/tx.h" #include "zenoh-pico/transport/utils.h" #include "zenoh-pico/utils/logging.h" #if Z_FEATURE_UNICAST_TRANSPORT == 1 -bool _zp_is_unicast_here(void) { return true; } - -void _zp_unicast_fetch_zid(const _z_transport_t *zt, z_owned_closure_zid_t *callback) { - void *ctx = callback->context; - z_id_t id = zt->_transport._unicast._remote_zid; - callback->call(&id, ctx); -} - -void _zp_unicast_info_session(const _z_transport_t *zt, _z_config_t *ps) { - _z_id_t remote_zid = zt->_transport._unicast._remote_zid; - _z_bytes_t remote_zidbytes = _z_bytes_wrap(remote_zid.id, _z_id_len(remote_zid)); - _zp_config_insert(ps, Z_INFO_ROUTER_PID_KEY, _z_string_from_bytes(&remote_zidbytes)); -} - -int _zp_unicast_start_read_task(_z_transport_t *zt, _z_task_attr_t *attr, _z_task_t *task) { - // Init memory - (void)memset(task, 0, sizeof(_z_task_t)); - // Attach task - zt->_transport._unicast._read_task = task; - zt->_transport._unicast._read_task_running = true; - // Init task - if (_z_task_init(task, attr, _zp_unicast_read_task, &zt->_transport._unicast) != _Z_RES_OK) { - zt->_transport._unicast._read_task_running = false; - return _Z_ERR_SYSTEM_TASK_FAILED; - } - return _Z_RES_OK; -} - -int _zp_unicast_start_lease_task(_z_transport_t *zt, _z_task_attr_t *attr, _z_task_t *task) { - // Init memory - (void)memset(task, 0, sizeof(_z_task_t)); - // Attach task - zt->_transport._unicast._lease_task = task; - zt->_transport._unicast._lease_task_running = true; - // Init task - if (_z_task_init(task, attr, _zp_unicast_lease_task, &zt->_transport._unicast) != _Z_RES_OK) { - zt->_transport._unicast._lease_task_running = false; - return _Z_ERR_SYSTEM_TASK_FAILED; - } - return _Z_RES_OK; -} - -int _zp_unicast_stop_read_task(_z_transport_t *zt) { - zt->_transport._unicast._read_task_running = false; - return _Z_RES_OK; -} - -int _zp_unicast_stop_lease_task(_z_transport_t *zt) { - zt->_transport._unicast._lease_task_running = false; - return _Z_RES_OK; -} int8_t _z_unicast_transport_create(_z_transport_t *zt, _z_link_t *zl, _z_transport_unicast_establish_param_t *param) { int8_t ret = _Z_RES_OK; @@ -324,41 +275,6 @@ void _z_unicast_transport_clear(_z_transport_t *zt) { } #else -bool _zp_is_unicast_here(void) { return false; } - -void _zp_unicast_fetch_zid(const _z_transport_t *zt, z_owned_closure_zid_t *callback) { - _ZP_UNUSED(zt); - _ZP_UNUSED(callback); -} - -void _zp_unicast_info_session(const _z_transport_t *zt, _z_config_t *ps) { - _ZP_UNUSED(zt); - _ZP_UNUSED(ps); -} - -int _zp_unicast_start_read_task(_z_transport_t *zt, _z_task_attr_t *attr, _z_task_t *task) { - _ZP_UNUSED(zt); - _ZP_UNUSED(attr); - _ZP_UNUSED(task); - return _Z_ERR_TRANSPORT_NOT_AVAILABLE; -} - -int _zp_unicast_start_lease_task(_z_transport_t *zt, _z_task_attr_t *attr, _z_task_t *task) { - _ZP_UNUSED(zt); - _ZP_UNUSED(attr); - _ZP_UNUSED(task); - return _Z_ERR_TRANSPORT_NOT_AVAILABLE; -} - -int _zp_unicast_stop_read_task(_z_transport_t *zt) { - _ZP_UNUSED(zt); - return _Z_ERR_TRANSPORT_NOT_AVAILABLE; -} - -int _zp_unicast_stop_lease_task(_z_transport_t *zt) { - _ZP_UNUSED(zt); - return _Z_ERR_TRANSPORT_NOT_AVAILABLE; -} int8_t _z_unicast_transport_create(_z_transport_t *zt, _z_link_t *zl, _z_transport_unicast_establish_param_t *param) { _ZP_UNUSED(zt); diff --git a/src/transport/unicast/link/tx.c b/src/transport/unicast/tx.c similarity index 98% rename from src/transport/unicast/link/tx.c rename to src/transport/unicast/tx.c index 631245c88..6e7ea4f85 100644 --- a/src/transport/unicast/link/tx.c +++ b/src/transport/unicast/tx.c @@ -12,7 +12,7 @@ // ZettaScale Zenoh Team, // -#include "zenoh-pico/transport/link/tx.h" +#include "zenoh-pico/transport/unicast/tx.h" #include @@ -20,6 +20,7 @@ #include "zenoh-pico/protocol/codec/network.h" #include "zenoh-pico/protocol/codec/transport.h" #include "zenoh-pico/protocol/iobuf.h" +#include "zenoh-pico/transport/common/tx.h" #include "zenoh-pico/transport/utils.h" #include "zenoh-pico/utils/logging.h"