Skip to content

Commit

Permalink
Merge branch 'BehaviorTree:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
GregoryLeMasurier authored Nov 20, 2024
2 parents e525e28 + 2bc72fd commit 99ed2b0
Show file tree
Hide file tree
Showing 174 changed files with 6,521 additions and 9,075 deletions.
17 changes: 17 additions & 0 deletions 3rdparty/cppzmq/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
196 changes: 196 additions & 0 deletions 3rdparty/cppzmq/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
[![CI](https://github.com/zeromq/cppzmq/actions/workflows/ci.yml/badge.svg)](https://github.com/zeromq/cppzmq/actions)
[![Coverage Status](https://coveralls.io/repos/github/zeromq/cppzmq/badge.svg?branch=master)](https://coveralls.io/github/zeromq/cppzmq?branch=master)
[![License](https://img.shields.io/github/license/zeromq/cppzmq.svg)](https://github.com/zeromq/cppzmq/blob/master/LICENSE)

Introduction & Design Goals
===========================

cppzmq is a C++ binding for libzmq. It has the following design goals:
- cppzmq maps the libzmq C API to C++ concepts. In particular:
- it is type-safe (the libzmq C API exposes various class-like concepts as void*)
- it provides exception-based error handling (the libzmq C API provides errno-based error handling)
- it provides RAII-style classes that automate resource management (the libzmq C API requires the user to take care to free resources explicitly)
- cppzmq is a light-weight, header-only binding. You only need to include the header file zmq.hpp (and maybe zmq_addon.hpp) to use it.
- zmq.hpp is meant to contain direct mappings of the abstractions provided by the libzmq C API, while zmq_addon.hpp provides additional higher-level abstractions.

There are other C++ bindings for ZeroMQ with different design goals. In particular, none of the following bindings are header-only:
- [zmqpp](https://github.com/zeromq/zmqpp) is a high-level binding to libzmq.
- [czmqpp](https://github.com/zeromq/czmqpp) is a binding based on the high-level czmq API.
- [fbzmq](https://github.com/facebook/fbzmq) is a binding that integrates with Apache Thrift and provides higher-level abstractions in addition. It requires C++14.

Supported platforms
===================

- Only a subset of the platforms that are supported by libzmq itself are supported. Some features already require a compiler supporting C++11. In the future, probably all features will require C++11. To build and run the tests, CMake and Catch are required.
- Any libzmq 4.x version is expected to work. DRAFT features may only work for the most recent tested version. Currently explicitly tested libzmq versions are
- 4.2.0 (without DRAFT API)
- 4.3.4 (with and without DRAFT API)
- Platforms with full support (i.e. CI executing build and tests)
- Ubuntu 18.04 x64 (with gcc 4.8.5, 5.5.0, 7.5.0)
- Ubuntu 20.04 x64 (with gcc 9.3.0, 10.3.0 and clang 12)
- Visual Studio 2017 x64
- Visual Studio 2019 x64
- macOS 10.15 (with clang 12, without DRAFT API)
- Additional platforms that are known to work:
- We have no current reports on additional platforms that are known to work yet. Please add your platform here. If CI can be provided for them with a cloud-based CI service working with GitHub, you are invited to add CI, and make it possible to be included in the list above.
- Additional platforms that probably work:
- Any platform supported by libzmq that provides a sufficiently recent gcc (4.8.1 or newer) or clang (3.4.1 or newer)
- Visual Studio 2012+ x86/x64

Examples
========
These examples require at least C++11.
```c++
#include <zmq.hpp>

int main()
{
zmq::context_t ctx;
zmq::socket_t sock(ctx, zmq::socket_type::push);
sock.bind("inproc://test");
sock.send(zmq::str_buffer("Hello, world"), zmq::send_flags::dontwait);
}
```
This a more complex example where we send and receive multi-part messages over TCP with a wildcard port.
```c++
#include <iostream>
#include <zmq_addon.hpp>

int main()
{
zmq::context_t ctx;
zmq::socket_t sock1(ctx, zmq::socket_type::push);
zmq::socket_t sock2(ctx, zmq::socket_type::pull);
sock1.bind("tcp://127.0.0.1:*");
const std::string last_endpoint =
sock1.get(zmq::sockopt::last_endpoint);
std::cout << "Connecting to "
<< last_endpoint << std::endl;
sock2.connect(last_endpoint);

std::array<zmq::const_buffer, 2> send_msgs = {
zmq::str_buffer("foo"),
zmq::str_buffer("bar!")
};
if (!zmq::send_multipart(sock1, send_msgs))
return 1;

std::vector<zmq::message_t> recv_msgs;
const auto ret = zmq::recv_multipart(
sock2, std::back_inserter(recv_msgs));
if (!ret)
return 1;
std::cout << "Got " << *ret
<< " messages" << std::endl;
return 0;
}
```

See the `examples` directory for more examples. When the project is compiled with tests enabled, each example gets compiled to an executable.


API Overview
============

For an extensive overview of the `zmq.hpp` API in use, see this [Tour of CPPZMQ by @brettviren](https://brettviren.github.io/cppzmq-tour/index.html).

Bindings for libzmq in `zmq.hpp`:

Types:
* class `zmq::context_t`
* enum `zmq::ctxopt`
* class `zmq::socket_t`
* class `zmq::socket_ref`
* enum `zmq::socket_type`
* enum `zmq::sockopt`
* enum `zmq::send_flags`
* enum `zmq::recv_flags`
* class `zmq::message_t`
* class `zmq::const_buffer`
* class `zmq::mutable_buffer`
* struct `zmq::recv_buffer_size`
* alias `zmq::send_result_t`
* alias `zmq::recv_result_t`
* alias `zmq::recv_buffer_result_t`
* class `zmq::error_t`
* class `zmq::monitor_t`
* struct `zmq_event_t`,
* alias `zmq::free_fn`,
* alias `zmq::pollitem_t`,
* alias `zmq::fd_t`
* class `zmq::poller_t` DRAFT
* enum `zmq::event_flags` DRAFT
* enum `zmq::poller_event` DRAFT

Functions:
* `zmq::version`
* `zmq::poll`
* `zmq::proxy`
* `zmq::proxy_steerable`
* `zmq::buffer`
* `zmq::str_buffer`

Extra high-level types and functions `zmq_addon.hpp`:

Types:
* class `zmq::multipart_t`
* class `zmq::active_poller_t` DRAFT

Functions:
* `zmq::recv_multipart`
* `zmq::send_multipart`
* `zmq::send_multipart_n`
* `zmq::encode`
* `zmq::decode`

Compatibility Guidelines
========================

The users of cppzmq are expected to follow the guidelines below to ensure not to break when upgrading cppzmq to newer versions (non-exhaustive list):

* Do not depend on any macros defined in cppzmq unless explicitly declared public here.

The following macros may be used by consumers of cppzmq: `CPPZMQ_VERSION`, `CPPZMQ_VERSION_MAJOR`, `CPPZMQ_VERSION_MINOR`, `CPPZMQ_VERSION_PATCH`.

Contribution policy
===================

The contribution policy is at: http://rfc.zeromq.org/spec:22

Build instructions
==================

Build steps:

1. Build [libzmq](https://github.com/zeromq/libzmq) via cmake. This does an out of source build and installs the build files
- download and unzip the lib, cd to directory
- mkdir build
- cd build
- cmake ..
- sudo make -j4 install

2. Build cppzmq via cmake. This does an out of source build and installs the build files
- download and unzip the lib, cd to directory
- mkdir build
- cd build
- cmake ..
- sudo make -j4 install

3. Build cppzmq via [vcpkg](https://github.com/Microsoft/vcpkg/). This does an out of source build and installs the build files
- git clone https://github.com/Microsoft/vcpkg.git
- cd vcpkg
- ./bootstrap-vcpkg.sh # bootstrap-vcpkg.bat for Powershell
- ./vcpkg integrate install
- ./vcpkg install cppzmq

Using this:

A cmake find package scripts is provided for you to easily include this library.
Add these lines in your CMakeLists.txt to include the headers and library files of
cpp zmq (which will also include libzmq for you).

```
#find cppzmq wrapper, installed by make of cppzmq
find_package(cppzmq)
target_link_libraries(*Your Project Name* cppzmq)
```
48 changes: 47 additions & 1 deletion 3rdparty/cppzmq/zmq.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@

/* Version macros for compile-time API version detection */
#define CPPZMQ_VERSION_MAJOR 4
#define CPPZMQ_VERSION_MINOR 9
#define CPPZMQ_VERSION_MINOR 10
#define CPPZMQ_VERSION_PATCH 0

#define CPPZMQ_VERSION \
Expand Down Expand Up @@ -538,6 +538,11 @@ class message_t
throw error_t();
memcpy(data(), data_, size_);
}

void rebuild(const std::string &str)
{
rebuild(str.data(), str.size());
}

void rebuild(void *data_, size_t size_, free_fn *ffn_, void *hint_ = ZMQ_NULLPTR)
{
Expand Down Expand Up @@ -1477,6 +1482,9 @@ ZMQ_DEFINE_INTEGRAL_BOOL_UNIT_OPT(ZMQ_CURVE_SERVER, curve_server, int);
#ifdef ZMQ_CURVE_SERVERKEY
ZMQ_DEFINE_ARRAY_OPT_BIN_OR_Z85(ZMQ_CURVE_SERVERKEY, curve_serverkey);
#endif
#ifdef ZMQ_DISCONNECT_MSG
ZMQ_DEFINE_ARRAY_OPT_BINARY(ZMQ_DISCONNECT_MSG, disconnect_msg);
#endif
#ifdef ZMQ_EVENTS
ZMQ_DEFINE_INTEGRAL_OPT(ZMQ_EVENTS, events, int);
#endif
Expand Down Expand Up @@ -1517,6 +1525,9 @@ ZMQ_DEFINE_INTEGRAL_OPT(ZMQ_HEARTBEAT_TIMEOUT, heartbeat_timeout, int);
#ifdef ZMQ_HEARTBEAT_TTL
ZMQ_DEFINE_INTEGRAL_OPT(ZMQ_HEARTBEAT_TTL, heartbeat_ttl, int);
#endif
#ifdef ZMQ_HELLO_MSG
ZMQ_DEFINE_ARRAY_OPT_BINARY(ZMQ_HELLO_MSG, hello_msg);
#endif
#ifdef ZMQ_IMMEDIATE
ZMQ_DEFINE_INTEGRAL_BOOL_UNIT_OPT(ZMQ_IMMEDIATE, immediate, int);
#endif
Expand Down Expand Up @@ -1562,6 +1573,9 @@ ZMQ_DEFINE_ARRAY_OPT(ZMQ_PLAIN_PASSWORD, plain_password);
#ifdef ZMQ_PLAIN_USERNAME
ZMQ_DEFINE_ARRAY_OPT(ZMQ_PLAIN_USERNAME, plain_username);
#endif
#ifdef ZMQ_PRIORITY
ZMQ_DEFINE_INTEGRAL_OPT(ZMQ_PRIORITY, priority, int);
#endif
#ifdef ZMQ_USE_FD
ZMQ_DEFINE_INTEGRAL_OPT(ZMQ_USE_FD, use_fd, int);
#endif
Expand Down Expand Up @@ -1589,6 +1603,9 @@ ZMQ_DEFINE_INTEGRAL_OPT(ZMQ_RECONNECT_IVL, reconnect_ivl, int);
#ifdef ZMQ_RECONNECT_IVL_MAX
ZMQ_DEFINE_INTEGRAL_OPT(ZMQ_RECONNECT_IVL_MAX, reconnect_ivl_max, int);
#endif
#ifdef ZMQ_RECONNECT_STOP
ZMQ_DEFINE_INTEGRAL_OPT(ZMQ_RECONNECT_STOP, reconnect_stop, int);
#endif
#ifdef ZMQ_RECOVERY_IVL
ZMQ_DEFINE_INTEGRAL_OPT(ZMQ_RECOVERY_IVL, recovery_ivl, int);
#endif
Expand Down Expand Up @@ -1619,9 +1636,15 @@ ZMQ_DEFINE_INTEGRAL_OPT(ZMQ_SNDHWM, sndhwm, int);
#ifdef ZMQ_SNDTIMEO
ZMQ_DEFINE_INTEGRAL_OPT(ZMQ_SNDTIMEO, sndtimeo, int);
#endif
#ifdef ZMQ_SOCKS_PASSWORD
ZMQ_DEFINE_ARRAY_OPT(ZMQ_SOCKS_PASSWORD, socks_password);
#endif
#ifdef ZMQ_SOCKS_PROXY
ZMQ_DEFINE_ARRAY_OPT(ZMQ_SOCKS_PROXY, socks_proxy);
#endif
#ifdef ZMQ_SOCKS_USERNAME
ZMQ_DEFINE_ARRAY_OPT(ZMQ_SOCKS_USERNAME, socks_username);
#endif
#ifdef ZMQ_STREAM_NOTIFY
ZMQ_DEFINE_INTEGRAL_BOOL_UNIT_OPT(ZMQ_STREAM_NOTIFY, stream_notify, int);
#endif
Expand Down Expand Up @@ -1679,6 +1702,9 @@ ZMQ_DEFINE_INTEGRAL_BOOL_UNIT_OPT(ZMQ_XPUB_VERBOSER, xpub_verboser, int);
#ifdef ZMQ_XPUB_MANUAL
ZMQ_DEFINE_INTEGRAL_BOOL_UNIT_OPT(ZMQ_XPUB_MANUAL, xpub_manual, int);
#endif
#ifdef ZMQ_XPUB_MANUAL_LAST_VALUE
ZMQ_DEFINE_INTEGRAL_BOOL_UNIT_OPT(ZMQ_XPUB_MANUAL_LAST_VALUE, xpub_manual_last_value, int);
#endif
#ifdef ZMQ_XPUB_NODROP
ZMQ_DEFINE_INTEGRAL_BOOL_UNIT_OPT(ZMQ_XPUB_NODROP, xpub_nodrop, int);
#endif
Expand Down Expand Up @@ -2637,6 +2663,17 @@ template<typename T = no_user_data> class poller_t
add_impl(socket, events, nullptr);
}

template<
typename Dummy = void,
typename =
typename std::enable_if<!std::is_same<T, no_user_data>::value, Dummy>::type>
void add(fd_t fd, event_flags events, T *user_data)
{
add_impl(fd, events, user_data);
}

void add(fd_t fd, event_flags events) { add_impl(fd, events, nullptr); }

void remove(zmq::socket_ref socket)
{
if (0 != zmq_poller_remove(poller_ptr.get(), socket.handle())) {
Expand Down Expand Up @@ -2703,6 +2740,15 @@ template<typename T = no_user_data> class poller_t
throw error_t();
}
}

void add_impl(fd_t fd, event_flags events, T *user_data)
{
if (0
!= zmq_poller_add_fd(poller_ptr.get(), fd, user_data,
static_cast<short>(events))) {
throw error_t();
}
}
};
#endif // defined(ZMQ_BUILD_DRAFT_API) && defined(ZMQ_CPP11) && defined(ZMQ_HAVE_POLLER)

Expand Down
16 changes: 8 additions & 8 deletions 3rdparty/cppzmq/zmq_addon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ inline bool is_little_endian()
inline void write_network_order(unsigned char *buf, const uint32_t value)
{
if (is_little_endian()) {
ZMQ_CONSTEXPR_VAR uint32_t mask = std::numeric_limits<std::uint8_t>::max();
ZMQ_CONSTEXPR_VAR uint32_t mask = (std::numeric_limits<std::uint8_t>::max)();
*buf++ = static_cast<unsigned char>((value >> 24) & mask);
*buf++ = static_cast<unsigned char>((value >> 16) & mask);
*buf++ = static_cast<unsigned char>((value >> 8) & mask);
Expand Down Expand Up @@ -224,12 +224,12 @@ message_t encode(const Range &parts)
// First pass check sizes
for (const auto &part : parts) {
const size_t part_size = part.size();
if (part_size > std::numeric_limits<std::uint32_t>::max()) {
if (part_size > (std::numeric_limits<std::uint32_t>::max)()) {
// Size value must fit into uint32_t.
throw std::range_error("Invalid size, message part too large");
}
const size_t count_size =
part_size < std::numeric_limits<std::uint8_t>::max() ? 1 : 5;
part_size < (std::numeric_limits<std::uint8_t>::max)() ? 1 : 5;
mmsg_size += part_size + count_size;
}

Expand All @@ -240,12 +240,12 @@ message_t encode(const Range &parts)
const unsigned char *part_data =
static_cast<const unsigned char *>(part.data());

if (part_size < std::numeric_limits<std::uint8_t>::max()) {
if (part_size < (std::numeric_limits<std::uint8_t>::max)()) {
// small part
*buf++ = (unsigned char) part_size;
} else {
// big part
*buf++ = std::numeric_limits<uint8_t>::max();
*buf++ = (std::numeric_limits<uint8_t>::max)();
detail::write_network_order(buf, part_size);
buf += sizeof(part_size);
}
Expand Down Expand Up @@ -279,7 +279,7 @@ template<class OutputIt> OutputIt decode(const message_t &encoded, OutputIt out)

while (source < limit) {
size_t part_size = *source++;
if (part_size == std::numeric_limits<std::uint8_t>::max()) {
if (part_size == (std::numeric_limits<std::uint8_t>::max)()) {
if (static_cast<size_t>(limit - source) < sizeof(uint32_t)) {
throw std::out_of_range(
"Malformed encoding, overflow in reading size");
Expand Down Expand Up @@ -343,10 +343,10 @@ class multipart_t
multipart_t(message_t &&message) { add(std::move(message)); }

// Move constructor
multipart_t(multipart_t &&other) { m_parts = std::move(other.m_parts); }
multipart_t(multipart_t &&other) ZMQ_NOTHROW { m_parts = std::move(other.m_parts); }

// Move assignment operator
multipart_t &operator=(multipart_t &&other)
multipart_t &operator=(multipart_t &&other) ZMQ_NOTHROW
{
m_parts = std::move(other.m_parts);
return *this;
Expand Down
Loading

0 comments on commit 99ed2b0

Please sign in to comment.