Skip to content

Commit

Permalink
refactor: apply header changes to source files
Browse files Browse the repository at this point in the history
  • Loading branch information
jean-roland committed Nov 13, 2023
1 parent 7bb8d16 commit da7c330
Show file tree
Hide file tree
Showing 22 changed files with 323 additions and 228 deletions.
10 changes: 7 additions & 3 deletions src/net/session.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
3 changes: 2 additions & 1 deletion src/session/tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
// ZettaScale Zenoh Team, <zenoh@zettascale.tech>
//

#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,
Expand Down
4 changes: 3 additions & 1 deletion src/transport/common/join.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
// ZettaScale Zenoh Team, <zenoh@zettascale.tech>
//

#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;
Expand Down
5 changes: 4 additions & 1 deletion src/transport/common/lease.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@
// ZettaScale Zenoh Team, <zenoh@zettascale.tech>
//

#include "zenoh-pico/transport/link/task/lease.h"
#include "zenoh-pico/transport/common/lease.h"

#include <stddef.h>

#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) {
Expand Down
5 changes: 4 additions & 1 deletion src/transport/common/read.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@
// ZettaScale Zenoh Team, <zenoh@zettascale.tech>
//

#include "zenoh-pico/transport/link/task/read.h"
#include "zenoh-pico/transport/common/read.h"

#include <stddef.h>

#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) {
Expand Down
3 changes: 2 additions & 1 deletion src/transport/common/rx.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
// ZettaScale Zenoh Team, <zenoh@zettascale.tech>
//

#include "zenoh-pico/transport/link/rx.h"
#include "zenoh-pico/transport/multicast/rx.h"

#include <stddef.h>

#include "zenoh-pico/protocol/codec/transport.h"
#include "zenoh-pico/transport/unicast/rx.h"
#include "zenoh-pico/utils/logging.h"

/*------------------ Reception helper ------------------*/
Expand Down
3 changes: 2 additions & 1 deletion src/transport/common/tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
// ZettaScale Zenoh Team, <zenoh@zettascale.tech>
//

#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 ------------------*/
Expand Down
4 changes: 2 additions & 2 deletions src/transport/manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
#include <stddef.h>
#include <stdlib.h>

#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;
Expand Down
69 changes: 69 additions & 0 deletions src/transport/multicast.c
Original file line number Diff line number Diff line change
@@ -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, <zenoh@zettascale.tech>

#include "zenoh-pico/transport/multicast.h"

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>

#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
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
// ZettaScale Zenoh Team, <zenoh@zettascale.tech>
//

#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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,21 @@
// ZettaScale Zenoh Team, <zenoh@zettascale.tech>
//

#include "zenoh-pico/transport/link/task/lease.h"
#include "zenoh-pico/transport/multicast/lease.h"

#include <stddef.h>

#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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
// ZettaScale Zenoh Team, <zenoh@zettascale.tech>
//

#include "zenoh-pico/transport/link/task/read.h"
#include "zenoh-pico/transport/multicast/read.h"

#include <stddef.h>

#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
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// ZettaScale Zenoh Team, <zenoh@zettascale.tech>
//

#include "zenoh-pico/transport/link/rx.h"
#include "zenoh-pico/transport/multicast/rx.h"

#include <stddef.h>
#include <stdint.h>
Expand Down
Loading

0 comments on commit da7c330

Please sign in to comment.