Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added windows support #273

Open
wants to merge 8 commits into
base: rolling
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ For information about the Design please visit [design](docs/design.md) page.
## Requirements
- [ROS 2](https://docs.ros.org): Rolling/Jazzy/Iron

### Windows

```bash
choco install -y rust mingw
```

## Setup

Expand Down
11 changes: 11 additions & 0 deletions rmw_zenoh_cpp/src/detail/rmw_data_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,17 @@ class rmw_client_data_t final
bool is_shutdown_{false};
size_t num_in_flight_{0};
};

///=============================================================================
template<typename T, typename H>
T make_z_closure(void * context, void (*call)(H *, void *), void (*drop)(void *))
{
T closure;
closure.context = context;
closure.call = call;
closure.drop = drop;
return closure;
}
} // namespace rmw_zenoh_cpp

#endif // DETAIL__RMW_DATA_TYPES_HPP_
31 changes: 19 additions & 12 deletions rmw_zenoh_cpp/src/detail/zenoh_router_check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,35 @@

#include "logging_macros.hpp"
#include "liveliness_utils.hpp"
#include "rmw_data_types.hpp"

namespace rmw_zenoh_cpp
{
// Define callback
void callback_id(const struct z_id_t * id, void * ctx)
{
const std::string id_str = liveliness::zid_to_str(*id);
RMW_ZENOH_LOG_INFO_NAMED(
"rmw_zenoh_cpp",
"Successfully connected to a Zenoh router with id %s.", id_str.c_str());
// Note: Callback is guaranteed to never be called
// concurrently according to z_info_routers_zid docstring
(*(static_cast<int *>(ctx)))++;
}
///=============================================================================
rmw_ret_t zenoh_router_check(z_session_t session)
{
// Initialize context for callback
int context = 0;

// Define callback
auto callback = [](const struct z_id_t * id, void * ctx) {
const std::string id_str = liveliness::zid_to_str(*id);
RMW_ZENOH_LOG_INFO_NAMED(
"rmw_zenoh_cpp",
"Successfully connected to a Zenoh router with id %s.", id_str.c_str());
// Note: Callback is guaranteed to never be called
// concurrently according to z_info_routers_zid docstring
(*(static_cast<int *>(ctx)))++;
};

rmw_ret_t ret = RMW_RET_OK;
z_owned_closure_zid_t router_callback = z_closure(callback, nullptr /* drop */, &context);

z_owned_closure_zid_t router_callback =
rmw_zenoh_cpp::make_z_closure<z_owned_closure_zid_t, const z_id_t>(
static_cast<void *>(&context),
&callback_id,
nullptr);

if (z_info_routers_zid(session, z_move(router_callback))) {
RMW_ZENOH_LOG_ERROR_NAMED(
"rmw_zenoh_cpp",
Expand Down
24 changes: 21 additions & 3 deletions rmw_zenoh_cpp/src/rmw_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,24 @@ rmw_init(const rmw_init_options_t * options, rmw_context_t * context)
// If not already defined, set the logging environment variable for Zenoh sessions
// to warning level by default.
// TODO(Yadunund): Switch to rcutils_get_env once it supports not overwriting values.
if (setenv(ZENOH_LOG_ENV_VAR_STR, ZENOH_LOG_WARN_LEVEL_STR, 0) != 0) {
RMW_SET_ERROR_MSG("Error configuring Zenoh logging.");

const char * value;
const char * error_message = rcutils_get_env(ZENOH_LOG_ENV_VAR_STR, &value);
if (error_message != NULL) {
RMW_SET_ERROR_MSG_WITH_FORMAT_STRING(
"Error configuring Zenoh logging. Unable to get %s environment variable: %s",
ZENOH_LOG_ENV_VAR_STR,
error_message);
return RMW_RET_ERROR;
}
if (value == nullptr) {
if (!rcutils_set_env(ZENOH_LOG_ENV_VAR_STR, ZENOH_LOG_WARN_LEVEL_STR)) {
RMW_SET_ERROR_MSG_WITH_FORMAT_STRING(
"Error configuring Zenoh logging. Unable to set %s environment variable.",
ZENOH_LOG_ENV_VAR_STR);
return RMW_RET_ERROR;
}
}

// Initialize the zenoh configuration.
z_owned_config_t config;
Expand Down Expand Up @@ -359,7 +373,11 @@ rmw_init(const rmw_init_options_t * options, rmw_context_t * context)
// z_move(callback),
// &sub_options);
auto sub_options = zc_liveliness_subscriber_options_null();
z_owned_closure_sample_t callback = z_closure(graph_sub_data_handler, nullptr, context->impl);
z_owned_closure_sample_t callback =
rmw_zenoh_cpp::make_z_closure<z_owned_closure_sample_t, const z_sample_t>(
static_cast<void *>(context->impl), graph_sub_data_handler, nullptr
);

context->impl->graph_subscriber = zc_liveliness_declare_subscriber(
z_loan(context->impl->session),
z_keyexpr(liveliness_str.c_str()),
Expand Down
24 changes: 18 additions & 6 deletions rmw_zenoh_cpp/src/rmw_zenoh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1415,7 +1415,7 @@ rmw_create_subscription(
allocator->deallocate(type_hash_c_str, allocator->state);
});

// Everything above succeeded and is setup properly. Now declare a subscriber
// Everything above succeeded and is setup properly. Now declare a subscriber
// with Zenoh; after this, callbacks may come in at any time.
sub_data->entity = rmw_zenoh_cpp::liveliness::Entity::make(
z_info_zid(z_loan(node->context->impl->session)),
Expand All @@ -1439,7 +1439,13 @@ rmw_create_subscription(
rmw_subscription->topic_name);
return nullptr;
}
z_owned_closure_sample_t callback = z_closure(rmw_zenoh_cpp::sub_data_handler, nullptr, sub_data);

z_owned_closure_sample_t callback =
rmw_zenoh_cpp::make_z_closure<z_owned_closure_sample_t, const z_sample_t>(
static_cast<void *>(sub_data),
rmw_zenoh_cpp::sub_data_handler,
nullptr);

z_owned_keyexpr_t keyexpr = z_keyexpr_new(sub_data->entity->topic_info()->topic_keyexpr_.c_str());
auto always_free_ros_keyexpr = rcpputils::make_scope_exit(
[&keyexpr]() {
Expand Down Expand Up @@ -2499,8 +2505,12 @@ rmw_send_request(
// and any number.
opts.consolidation = z_query_consolidation_latest();
opts.value.payload = z_bytes_t{data_length, reinterpret_cast<const uint8_t *>(request_bytes)};

z_owned_closure_reply_t zn_closure_reply =
z_closure(rmw_zenoh_cpp::client_data_handler, rmw_zenoh_cpp::client_data_drop, client_data);
rmw_zenoh_cpp::make_z_closure<z_owned_closure_reply_t, z_owned_reply_t>(
static_cast<void *>(client_data),
&rmw_zenoh_cpp::client_data_handler,
rmw_zenoh_cpp::client_data_drop);
z_get(
z_loan(context_impl->session),
z_loan(client_data->keyexpr), "",
Expand Down Expand Up @@ -2888,9 +2898,11 @@ rmw_create_service(
return nullptr;
}

z_owned_closure_query_t callback = z_closure(
rmw_zenoh_cpp::service_data_handler, nullptr,
service_data);
z_owned_closure_query_t callback =
rmw_zenoh_cpp::make_z_closure<z_owned_closure_query_t, const z_query_t>(
static_cast<void *>(service_data),
&rmw_zenoh_cpp::service_data_handler,
nullptr);
// Configure the queryable to process complete queries.
z_queryable_options_t qable_options = z_queryable_options_default();
qable_options.complete = true;
Expand Down
21 changes: 18 additions & 3 deletions rmw_zenoh_cpp/src/zenohd/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "../detail/zenoh_config.hpp"
#include "../detail/liveliness_utils.hpp"

#include "rcutils/env.h"
#include "rmw/error_handling.h"

#include "rcpputils/scope_exit.hpp"
Expand Down Expand Up @@ -63,9 +64,23 @@ int main(int argc, char ** argv)
// If not already defined, set the logging environment variable for Zenoh router
// to info level by default.
// TODO(Yadunund): Switch to rcutils_get_env once it supports not overwriting values.
if (setenv(ZENOH_LOG_ENV_VAR_STR, ZENOH_LOG_INFO_LEVEL_STR, 0) != 0) {
RMW_SET_ERROR_MSG("Error configuring Zenoh logging.");
return 1;

const char * value;
const char * error_message = rcutils_get_env(ZENOH_LOG_ENV_VAR_STR, &value);
if (error_message != NULL) {
RMW_SET_ERROR_MSG_WITH_FORMAT_STRING(
"Error configuring Zenoh logging. Unable to get %s environment variable: %s",
ZENOH_LOG_ENV_VAR_STR,
error_message);
return RMW_RET_ERROR;
}
if (value == nullptr) {
if (!rcutils_set_env(ZENOH_LOG_ENV_VAR_STR, ZENOH_LOG_INFO_LEVEL_STR)) {
RMW_SET_ERROR_MSG_WITH_FORMAT_STRING(
"Error configuring Zenoh logging. Unable to set %s environment variable.",
ZENOH_LOG_ENV_VAR_STR);
return RMW_RET_ERROR;
}
}

// Initialize the zenoh configuration for the router.
Expand Down
Loading