Skip to content

Commit

Permalink
Merge remote-tracking branch 'zenoh/master' into freertos
Browse files Browse the repository at this point in the history
  • Loading branch information
bjsowa committed Aug 11, 2023
2 parents 71654ba + b68364f commit 95ff561
Show file tree
Hide file tree
Showing 20 changed files with 312 additions and 40 deletions.
24 changes: 24 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# .readthedocs.yaml
# Read the Docs configuration file
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details

# Required
version: 2

# Set the version of Python and other tools you might need
build:
os: ubuntu-22.04
tools:
python: "3.11"
apt_packages:
- libclang-dev

# Build documentation in the docs/ directory with Sphinx
sphinx:
configuration: docs/conf.py

# We recommend specifying your dependencies to enable reproducible builds:
# https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html
python:
install:
- requirements: docs/requirements.txt
1 change: 0 additions & 1 deletion BSDmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ crossbuild: check-docker
cmake $(CMAKE_OPT) -DPACKAGING=DEB,RPM -DDEBARCH=$(DEBARCH) -DRPMARCH=$(RPMARCH) -B$(CROSSBUILD_DIR)/$(CROSSIMG) && \
make VERBOSE=1 -C$(CROSSBUILD_DIR)/$(CROSSIMG) all package"
docker rmi $(CROSSIMG_PREFIX)$(CROSSIMG)
docker rmi dockcross/$(CROSSIMG)

linux-armv5:
CROSSIMG=$@ DEBARCH=arm RPMARCH=arm make crossbuild
Expand Down
49 changes: 43 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
# Contributors:
# ZettaScale Zenoh Team, <[email protected]>
#
cmake_minimum_required(VERSION 3.8)
cmake_minimum_required(VERSION 3.13)

project(libzenohpico VERSION 0.10.0.0 LANGUAGES C)
project(zenohpico VERSION 0.10.0.0 LANGUAGES C)

include(CMakePackageConfigHelpers)

option(BUILD_SHARED_LIBS "Build shared libraries if ON, otherwise build static libraries" ON)
option(ZENOH_DEBUG "Use this to set the ZENOH_DEBUG variable." 0)
Expand Down Expand Up @@ -62,8 +64,14 @@ if(NOT CMAKE_BUILD_TYPE)
endif()
string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE)


set(CHECK_THREADS "ON")

if(CMAKE_SYSTEM_NAME MATCHES "Linux")
add_definition(ZENOH_LINUX)
elseif(POSIX_COMPATIBLE)
add_definition(ZENOH_LINUX)
set(CHECK_THREADS "OFF")
elseif(CMAKE_SYSTEM_NAME MATCHES "BSD")
add_definition(ZENOH_BSD)
elseif(CMAKE_SYSTEM_NAME MATCHES "Darwin")
Expand Down Expand Up @@ -103,7 +111,9 @@ if(SKBUILD)
endif()

set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
if(CHECK_THREADS)
find_package(Threads REQUIRED)
endif()

if(CMAKE_BUILD_TYPE MATCHES "DEBUG")
if(UNIX)
Expand Down Expand Up @@ -167,7 +177,7 @@ if(WITH_ZEPHYR)
elseif(WITH_FREERTOS_PLUS_TCP)
file (GLOB Sources_Freertos_Plus_TCP "src/system/freertos_plus_tcp/*.c")
list(APPEND Sources ${Sources_Freertos_Plus_TCP})
elseif(CMAKE_SYSTEM_NAME MATCHES "Linux" OR CMAKE_SYSTEM_NAME MATCHES "Darwin" OR CMAKE_SYSTEM_NAME MATCHES "BSD")
elseif(CMAKE_SYSTEM_NAME MATCHES "Linux" OR CMAKE_SYSTEM_NAME MATCHES "Darwin" OR CMAKE_SYSTEM_NAME MATCHES "BSD" OR POSIX_COMPATIBLE)
file (GLOB Sources_Unix "src/system/unix/*.c")
list(APPEND Sources ${Sources_Unix})
elseif(CMAKE_SYSTEM_NAME MATCHES "Emscripten")
Expand All @@ -183,7 +193,9 @@ link_directories(${LIBRARY_OUTPUT_PATH})

target_sources(${Libname} PRIVATE ${Sources})

target_link_libraries(${Libname} Threads::Threads)
if(CHECK_THREADS)
target_link_libraries(${Libname} Threads::Threads)
endif()

if(CMAKE_SYSTEM_NAME MATCHES "Linux")
target_link_libraries(${Libname} rt)
Expand Down Expand Up @@ -224,6 +236,31 @@ install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/zenoh-pico
COMPONENT Headers
)

set(CMAKE_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/zenohpico")
# Generate <Package>Config.cmake
configure_package_config_file(
"PackageConfig.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/zenohpicoConfig.cmake"
INSTALL_DESTINATION "${CMAKE_INSTALL_CMAKEDIR}")

# Generate <Package>Version.cmake
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/zenohpicoConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion)

install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/zenohpicoConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/zenohpicoConfigVersion.cmake"
DESTINATION "${CMAKE_INSTALL_CMAKEDIR}"
CONFIGURATIONS ${configurations}
COMPONENT dev)

if(UNIX)
configure_file("${CMAKE_SOURCE_DIR}/zenohpico.pc.in" "${CMAKE_SOURCE_DIR}/zenohpico.pc" @ONLY)
install(FILES "${CMAKE_SOURCE_DIR}/zenohpico.pc" CONFIGURATIONS Release RelWithDebInfo DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
endif()

if(BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
Expand Down Expand Up @@ -370,4 +407,4 @@ if(PACKAGING)
include(CPack)
endif()

endif()
endif()
1 change: 0 additions & 1 deletion GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ crossbuild: check-docker
cmake $(CMAKE_OPT) -DPACKAGING=DEB,RPM -DDEBARCH=$(DEBARCH) -DRPMARCH=$(RPMARCH) -B$(CROSSBUILD_DIR)/$(CROSSIMG) && \
make VERBOSE=1 -C$(CROSSBUILD_DIR)/$(CROSSIMG) all package"
docker rmi $(CROSSIMG_PREFIX)$(CROSSIMG)
docker rmi dockcross/$(CROSSIMG)

linux-armv5:
CROSSIMG=$@ DEBARCH=arm RPMARCH=arm make crossbuild
Expand Down
28 changes: 28 additions & 0 deletions PackageConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#
# Copyright (c) 2023 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, <[email protected]>
#

@PACKAGE_INIT@

add_library(__zenohpico_static STATIC IMPORTED GLOBAL)
add_library(zenohpico::static ALIAS __zenohpico_static)
set_property(TARGET __zenohpico_static PROPERTY IMPORTED_LOCATION "@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@/@STATICLIB@")

add_library(__zenohpico_lib SHARED IMPORTED GLOBAL)
add_library(zenohpico::lib ALIAS __zenohpico_lib)
set_target_properties(__zenohpico_lib PROPERTIES IMPORTED_NO_SONAME TRUE)
set_property(TARGET __zenohpico_lib PROPERTY IMPORTED_LOCATION "@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@/@DYLIB@")
if(NOT ("@IMPLIB@" STREQUAL ""))
set_property(TARGET __zenohpico_lib PROPERTY IMPORTED_IMPLIB "@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@/@IMPLIB@")
endif()
target_include_directories(__zenohpico_lib INTERFACE "@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_INCLUDEDIR@")
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@
raise ValueError("Windows not supported yet for building docs.")

else:
Config.set_library_file('/usr/lib/llvm-6.0/lib/libclang.so.1') # Required for readthedocs
Config.set_library_file('/usr/lib/llvm-14/lib/libclang.so.1') # Required for readthedocs
29 changes: 27 additions & 2 deletions examples/unix/c11/z_ping.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,32 @@ int main(int argc, char** argv) {
_z_condvar_init(&cond);
z_owned_config_t config = z_config_default();
z_owned_session_t session = z_open(z_move(config));
if (!z_check(session)) {
printf("Unable to open session!\n");
return -1;
}

if (zp_start_read_task(z_loan(session), NULL) < 0 || zp_start_lease_task(z_loan(session), NULL) < 0) {
printf("Unable to start read and lease tasks");
return -1;
}

z_keyexpr_t ping = z_keyexpr_unchecked("test/ping");
z_keyexpr_t pong = z_keyexpr_unchecked("test/pong");

z_owned_publisher_t pub = z_declare_publisher(z_loan(session), ping, NULL);
z_owned_closure_sample_t respond = z_closure(callback, drop, (void*)(&pub));
if (!z_check(pub)) {
printf("Unable to declare publisher for key expression!\n");
return -1;
}

z_owned_closure_sample_t respond = z_closure(callback, drop, NULL);
z_owned_subscriber_t sub = z_declare_subscriber(z_loan(session), pong, z_move(respond), NULL);
if (!z_check(sub)) {
printf("Unable to declare subscriber for key expression.\n");
return -1;
}

uint8_t* data = z_malloc(args.size);
for (unsigned int i = 0; i < args.size; i++) {
data[i] = i % 10;
Expand Down Expand Up @@ -79,8 +100,12 @@ int main(int argc, char** argv) {
_z_mutex_unlock(&mutex);
z_free(results);
z_free(data);
z_drop(z_move(sub));
z_drop(z_move(pub));
z_drop(z_move(sub));

zp_stop_read_task(z_loan(session));
zp_stop_lease_task(z_loan(session));

z_close(z_move(session));
}

Expand Down
27 changes: 26 additions & 1 deletion examples/unix/c11/z_pong.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,38 @@ int main(int argc, char** argv) {
(void)argv;
z_owned_config_t config = z_config_default();
z_owned_session_t session = z_open(z_move(config));
z_keyexpr_t ping = z_keyexpr_unchecked("test/ping");
if (!z_check(session)) {
printf("Unable to open session!\n");
return -1;
}

if (zp_start_read_task(z_loan(session), NULL) < 0 || zp_start_lease_task(z_loan(session), NULL) < 0) {
printf("Unable to start read and lease tasks");
return -1;
}

z_keyexpr_t pong = z_keyexpr_unchecked("test/pong");
z_owned_publisher_t pub = z_declare_publisher(z_loan(session), pong, NULL);
if (!z_check(pub)) {
printf("Unable to declare publisher for key expression!\n");
return -1;
}

z_keyexpr_t ping = z_keyexpr_unchecked("test/ping");
z_owned_closure_sample_t respond = z_closure(callback, drop, (void*)z_move(pub));
z_owned_subscriber_t sub = z_declare_subscriber(z_loan(session), ping, z_move(respond), NULL);
if (!z_check(sub)) {
printf("Unable to declare subscriber for key expression.\n");
return -1;
}

while (getchar() != 'q') {
}

z_drop(z_move(sub));

zp_stop_read_task(z_loan(session));
zp_stop_lease_task(z_loan(session));

z_close(z_move(session));
}
40 changes: 33 additions & 7 deletions examples/unix/c99/z_ping.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,34 @@ int main(int argc, char** argv) {
_z_mutex_init(&mutex);
_z_condvar_init(&cond);
z_owned_config_t config = z_config_default();
z_owned_session_t session = z_open(z_move(config));
z_owned_session_t session = z_open(z_config_move(&config));
if (!z_session_check(&session)) {
printf("Unable to open session!\n");
return -1;
}

if (zp_start_read_task(z_session_loan(&session), NULL) < 0 ||
zp_start_lease_task(z_session_loan(&session), NULL) < 0) {
printf("Unable to start read and lease tasks");
return -1;
}

z_keyexpr_t ping = z_keyexpr_unchecked("test/ping");
z_keyexpr_t pong = z_keyexpr_unchecked("test/pong");
z_owned_publisher_t pub = z_declare_publisher(z_session_loan(&session), ping, NULL);
z_owned_closure_sample_t respond = z_closure(callback, drop, (void*)(&pub));
z_owned_subscriber_t sub = z_declare_subscriber(z_session_loan(&session), pong, z_move(respond), NULL);
if (!z_publisher_check(&pub)) {
printf("Unable to declare publisher for key expression!\n");
return -1;
}

z_keyexpr_t pong = z_keyexpr_unchecked("test/pong");
z_owned_closure_sample_t respond = z_closure_sample(callback, drop, NULL);
z_owned_subscriber_t sub =
z_declare_subscriber(z_session_loan(&session), pong, z_closure_sample_move(&respond), NULL);
if (!z_subscriber_check(&sub)) {
printf("Unable to declare subscriber for key expression.\n");
return -1;
}

uint8_t* data = z_malloc(args.size);
for (unsigned int i = 0; i < args.size; i++) {
data[i] = i % 10;
Expand Down Expand Up @@ -78,9 +100,13 @@ int main(int argc, char** argv) {
_z_mutex_unlock(&mutex);
z_free(results);
z_free(data);
z_undeclare_subscriber(z_move(sub));
z_undeclare_publisher(z_move(pub));
z_close(z_move(session));
z_undeclare_subscriber(z_subscriber_move(&sub));
z_undeclare_publisher(z_publisher_move(&pub));

zp_stop_read_task(z_session_loan(&session));
zp_stop_lease_task(z_session_loan(&session));

z_close(z_session_move(&session));
}

char* getopt(int argc, char** argv, char option) {
Expand Down
39 changes: 33 additions & 6 deletions examples/unix/c99/z_pong.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,41 @@ int main(int argc, char** argv) {
(void)argc;
(void)argv;
z_owned_config_t config = z_config_default();
z_owned_session_t session = z_open(z_move(config));
z_keyexpr_t ping = z_keyexpr_unchecked("test/ping");
z_owned_session_t session = z_open(z_config_move(&config));
if (!z_session_check(&session)) {
printf("Unable to open session!\n");
return -1;
}

if (zp_start_read_task(z_session_loan(&session), NULL) < 0 ||
zp_start_lease_task(z_session_loan(&session), NULL) < 0) {
printf("Unable to start read and lease tasks");
return -1;
}

z_keyexpr_t pong = z_keyexpr_unchecked("test/pong");
z_owned_publisher_t pub = z_declare_publisher(z_session_loan(&session), pong, NULL);
z_owned_closure_sample_t respond = z_closure(callback, drop, (void*)z_move(pub));
z_owned_subscriber_t sub = z_declare_subscriber(z_session_loan(&session), ping, z_move(respond), NULL);
if (!z_publisher_check(&pub)) {
printf("Unable to declare publisher for key expression!\n");
return -1;
}

z_keyexpr_t ping = z_keyexpr_unchecked("test/ping");
z_owned_closure_sample_t respond = z_closure_sample(callback, drop, (void*)z_publisher_move(&pub));
z_owned_subscriber_t sub =
z_declare_subscriber(z_session_loan(&session), ping, z_closure_sample_move(&respond), NULL);
if (!z_subscriber_check(&sub)) {
printf("Unable to declare subscriber for key expression.\n");
return -1;
}

while (getchar() != 'q') {
}
z_undeclare_subscriber(z_move(sub));
z_close(z_move(session));

z_undeclare_subscriber(z_subscriber_move(&sub));

zp_stop_read_task(z_session_loan(&session));
zp_stop_lease_task(z_session_loan(&session));

z_close(z_session_move(&session));
}
Loading

0 comments on commit 95ff561

Please sign in to comment.