Skip to content

Commit

Permalink
Update to zenoh-c 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
alerei committed Oct 25, 2024
1 parent 49f714a commit 8c51293
Show file tree
Hide file tree
Showing 13 changed files with 571 additions and 326 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
cmake --build build/test
- name: "CMake: Test"
run: |
cmake --build build/test --target test
ctest --test-dir build/test --verbose
- name: "CMake: Coverage"
run: |
cmake --build build/test --target coverage
14 changes: 13 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,18 @@
"variant": "cpp",
"codecvt": "cpp",
"ranges": "cpp",
"valarray": "cpp"
"valarray": "cpp",
"strstream": "cpp",
"cfenv": "cpp",
"complex": "cpp",
"coroutine": "cpp",
"source_location": "cpp",
"shared_mutex": "cpp",
"stdfloat": "cpp",
"text_encoding": "cpp",
"typeindex": "cpp",
"*.ipp": "cpp",
"variable.h": "c",
"hash_map": "cpp"
}
}
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ include(${CMAKE_SOURCE_DIR}/flecs-build/cmake/flecs-build.cmake)
project(flunder VERSION 3.0.0)

if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
set(FLECS_NEED_ZENOHC TRUE)
add_subdirectory(flecs-external)
endif()

Expand All @@ -39,13 +40,15 @@ set(SRC_LIB
src/to_string.cpp
src/variable.cpp
src/impl/client.cpp
src/impl/to_bytes.cpp
)

set(HEADER_LIB
include/flunder/client.h
include/flunder/to_string.h
include/flunder/variable.h
include/flunder/impl/client.h
include/flunder/impl/to_bytes.h
)

add_library(flunder OBJECT ${SRC_LIB} ${HEADER_LIB})
Expand Down
2 changes: 1 addition & 1 deletion flecs-external
4 changes: 4 additions & 0 deletions include/flunder/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@
#endif // FLECS_EXPORT

#ifndef __cplusplus
#ifndef FLECS_FLUNDER_HOST
#define FLECS_FLUNDER_HOST "flecs-flunder"
#endif // FLECS_FLUNDER_HOST
#ifndef FLECS_FLUNDER_PORT
#define FLECS_FLUNDER_PORT 7447
#endif // FLECS_FLUNDER_PORT
#endif // __cplusplus

#include "flunder/variable.h"
Expand Down
71 changes: 58 additions & 13 deletions include/flunder/impl/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,27 +56,72 @@ class client_t
FLECS_EXPORT auto disconnect() //
-> int;

FLECS_EXPORT auto publish(
std::string_view topic,
z_owned_bytes_t value,
std::string_view encoding) const //
-> int;

FLECS_EXPORT auto publish_bool(
std::string_view topic,
const std::string& value) const //
z_owned_bytes_t value) const //
-> int;

FLECS_EXPORT auto publish_int(
FLECS_EXPORT auto publish_int8(
std::string_view topic,
z_owned_bytes_t value) const //
-> int;
FLECS_EXPORT auto publish_int16(
std::string_view topic,
size_t size,
bool is_signed,
const std::string& value) const //
z_owned_bytes_t value) const //
-> int;
FLECS_EXPORT auto publish_int32(
std::string_view topic,
z_owned_bytes_t value) const //
-> int;
FLECS_EXPORT auto publish_int64(
std::string_view topic,
z_owned_bytes_t value) const //
-> int;
FLECS_EXPORT auto publish_int128(
std::string_view topic,
z_owned_bytes_t value) const //
-> int;

FLECS_EXPORT auto publish_uint8(
std::string_view topic,
z_owned_bytes_t value) const //
-> int;
FLECS_EXPORT auto publish_uint16(
std::string_view topic,
z_owned_bytes_t value) const //
-> int;
FLECS_EXPORT auto publish_uint32(
std::string_view topic,
z_owned_bytes_t value) const //
-> int;
FLECS_EXPORT auto publish_uint64(
std::string_view topic,
z_owned_bytes_t value) const //
-> int;
FLECS_EXPORT auto publish_uint128(
std::string_view topic,
z_owned_bytes_t value) const //
-> int;

FLECS_EXPORT auto publish_float(
std::string_view topic,
size_t size,
const std::string& value) const //
z_owned_bytes_t value) const //
-> int;

FLECS_EXPORT auto publish_double(
std::string_view topic,
z_owned_bytes_t value) const //
-> int;

FLECS_EXPORT auto publish_string(
std::string_view topic,
const std::string& value) const //
z_owned_bytes_t value) const //
-> int;

FLECS_EXPORT auto publish_raw(
Expand Down Expand Up @@ -133,13 +178,13 @@ class client_t
};

private:
FLECS_EXPORT auto publish(
FLECS_EXPORT auto do_publish(
std::string_view topic,
z_encoding_t encoding,
const std::string& value) const //
z_owned_encoding_t encoding,
z_owned_bytes_t value) const //
-> int;

FLECS_EXPORT auto subscribe(
FLECS_EXPORT auto do_subscribe(
flunder::client_t* client,
std::string_view topic,
subscribe_cbk_var_t cbk,
Expand All @@ -157,7 +202,7 @@ class client_t
std::map<std::string, subscribe_ctx_t> _subscriptions;
};

auto to_string(z_encoding_prefix_t prefix, std::string_view suffix) //
auto to_string(const z_loaned_encoding_t* encoding) //
-> std::string;

auto ntp64_to_unix_time(std::uint64_t ntp_time) //
Expand Down
44 changes: 44 additions & 0 deletions include/flunder/impl/to_bytes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#pragma once

#include <zenoh.h>

#include <cinttypes>
#include <string>
#include <type_traits>

namespace flunder {
namespace impl {

auto to_bytes(std::int8_t val) //
-> z_owned_bytes_t;
auto to_bytes(std::int16_t val) //
-> z_owned_bytes_t;
auto to_bytes(std::int32_t val) //
-> z_owned_bytes_t;
auto to_bytes(std::int64_t val) //
-> z_owned_bytes_t;

auto to_bytes(std::uint8_t val) //
-> z_owned_bytes_t;
auto to_bytes(std::uint16_t val) //
-> z_owned_bytes_t;
auto to_bytes(std::uint32_t val) //
-> z_owned_bytes_t;
auto to_bytes(std::uint64_t val) //
-> z_owned_bytes_t;

auto to_bytes(float val) //
-> z_owned_bytes_t;
auto to_bytes(double val) //
-> z_owned_bytes_t;

auto to_bytes(bool val) //
-> z_owned_bytes_t;

auto to_bytes(const char* val) //
-> z_owned_bytes_t;
auto to_bytes(std::string_view val) //
-> z_owned_bytes_t;

} // namespace impl
} // namespace flunder
61 changes: 15 additions & 46 deletions src/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "flunder/client.h"

#include "flunder/impl/client.h"
#include "flunder/impl/to_bytes.h"
#include "flunder/to_string.h"

namespace flunder {
Expand Down Expand Up @@ -74,107 +75,75 @@ auto client_t::disconnect() //
auto client_t::publish(std::string_view topic, bool value) const //
-> int
{
return _impl->publish_bool(topic, flunder::to_string(value));
return _impl->publish_bool(topic, impl::to_bytes(value));
}
/* integer-types */
auto client_t::publish(std::string_view topic, std::int8_t value) const //
-> int
{
return _impl->publish_int(
topic,
sizeof(value),
std::is_signed_v<decltype(value)>,
flunder::to_string(value));
return _impl->publish_int8(topic, impl::to_bytes(value));
}
auto client_t::publish(std::string_view topic, std::int16_t value) const //
-> int
{
return _impl->publish_int(
topic,
sizeof(value),
std::is_signed_v<decltype(value)>,
flunder::to_string(value));
return _impl->publish_int16(topic, impl::to_bytes(value));
}
auto client_t::publish(std::string_view topic, std::int32_t value) const //
-> int
{
return _impl->publish_int(
topic,
sizeof(value),
std::is_signed_v<decltype(value)>,
flunder::to_string(value));
return _impl->publish_int32(topic, impl::to_bytes(value));
}
auto client_t::publish(std::string_view topic, std::int64_t value) const //
-> int
{
return _impl->publish_int(
topic,
sizeof(value),
std::is_signed_v<decltype(value)>,
flunder::to_string(value));
return _impl->publish_int64(topic, impl::to_bytes(value));
}
auto client_t::publish(std::string_view topic, std::uint8_t value) const //
-> int
{
return _impl->publish_int(
topic,
sizeof(value),
std::is_signed_v<decltype(value)>,
flunder::to_string(value));
return _impl->publish_uint8(topic, impl::to_bytes(value));
}
auto client_t::publish(std::string_view topic, std::uint16_t value) const //
-> int
{
return _impl->publish_int(
topic,
sizeof(value),
std::is_signed_v<decltype(value)>,
flunder::to_string(value));
return _impl->publish_uint16(topic, impl::to_bytes(value));
}
auto client_t::publish(std::string_view topic, std::uint32_t value) const //
-> int
{
return _impl->publish_int(
topic,
sizeof(value),
std::is_signed_v<decltype(value)>,
flunder::to_string(value));
return _impl->publish_uint32(topic, impl::to_bytes(value));
}
auto client_t::publish(std::string_view topic, std::uint64_t value) const //
-> int
{
return _impl->publish_int(
topic,
sizeof(value),
std::is_signed_v<decltype(value)>,
flunder::to_string(value));
return _impl->publish_uint64(topic, impl::to_bytes(value));
}
/* floating-point-types */
auto client_t::publish(std::string_view topic, float value) const //
-> int
{
return _impl->publish_float(topic, sizeof(value), flunder::to_string(value));
return _impl->publish_float(topic, impl::to_bytes(value));
}
auto client_t::publish(std::string_view topic, double value) const //
-> int
{
return _impl->publish_float(topic, sizeof(value), flunder::to_string(value));
return _impl->publish_double(topic, impl::to_bytes(value));
}
/* string-types */
auto client_t::publish(std::string_view topic, const std::string& value) const //
-> int
{
return _impl->publish_string(topic, value);
return _impl->publish_string(topic, impl::to_bytes(value));
}
auto client_t::publish(std::string_view topic, const std::string_view& value) const //
-> int
{
return _impl->publish_string(topic, flunder::to_string(value));
return _impl->publish_string(topic, impl::to_bytes(value));
}
auto client_t::publish(std::string_view topic, const char* value) const //
-> int
{
return _impl->publish_string(topic, flunder::to_string(value));
return _impl->publish_string(topic, impl::to_bytes(value));
}

auto client_t::publish(std::string_view topic, const void* data, size_t len) const //
Expand Down
Loading

0 comments on commit 8c51293

Please # to comment.