Skip to content

Commit

Permalink
Support Windows
Browse files Browse the repository at this point in the history
Signed-off-by: Alejandro Hernandez Cordero <[email protected]>

Removed some warnings

Signed-off-by: Alejandro Hernandez Cordero <[email protected]>

Removed C4099 Windows warning

Signed-off-by: Alejandro Hernandez Cordero <[email protected]>

Support Windows

Signed-off-by: Yadunund <[email protected]>

undo changes

Signed-off-by: Yadunund <[email protected]>
  • Loading branch information
ahcorde authored and Yadunund committed Dec 9, 2024
1 parent 7fcd074 commit 26360a8
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 48 deletions.
5 changes: 3 additions & 2 deletions rmw_zenoh_cpp/src/detail/graph_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

#include <algorithm>
#include <array>
#include <functional>
#include <memory>
#include <mutex>
Expand Down Expand Up @@ -233,7 +234,7 @@ void GraphCache::handle_matched_events_for_put(
update_event_counters(
topic_info.name_,
ZENOH_EVENT_PUBLICATION_MATCHED,
match_count_for_entity);
static_cast<int32_t>(match_count_for_entity));
if (is_entity_local(*entity) && match_count_for_entity > 0) {
local_entities_with_events[entity].insert(ZENOH_EVENT_PUBLICATION_MATCHED);
}
Expand All @@ -260,7 +261,7 @@ void GraphCache::handle_matched_events_for_put(
update_event_counters(
topic_info.name_,
ZENOH_EVENT_SUBSCRIPTION_MATCHED,
match_count_for_entity);
static_cast<int32_t>(match_count_for_entity));
if (is_entity_local(*entity) && match_count_for_entity > 0) {
local_entities_with_events[entity].insert(ZENOH_EVENT_SUBSCRIPTION_MATCHED);
}
Expand Down
60 changes: 30 additions & 30 deletions rmw_zenoh_cpp/src/detail/rmw_context_impl_s.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ class rmw_context_impl_s::Data final
}

// Check if shm is enabled.
z_owned_string_t shm_enabled;
zc_config_get_from_str(z_loan(config), Z_CONFIG_SHARED_MEMORY_KEY, &shm_enabled);
auto always_free_shm_enabled = rcpputils::make_scope_exit(
[&shm_enabled]() {
z_drop(z_move(shm_enabled));
});
// z_owned_string_t shm_enabled;
// zc_config_get_from_str(z_loan(config), Z_CONFIG_SHARED_MEMORY_KEY, &shm_enabled);
// auto always_free_shm_enabled = rcpputils::make_scope_exit(
// [&shm_enabled]() {
// z_drop(z_move(shm_enabled));
// });

// Initialize the zenoh session.
if (z_open(&session_, z_move(config), NULL) != Z_OK) {
Expand Down Expand Up @@ -166,29 +166,29 @@ class rmw_context_impl_s::Data final

// Initialize the shm manager if shared_memory is enabled in the config.
shm_provider_ = std::nullopt;
if (strncmp(
z_string_data(z_loan(shm_enabled)),
"true",
z_string_len(z_loan(shm_enabled))) == 0)
{
// TODO(yuyuan): determine the default alignment of SHM
z_alloc_alignment_t alignment = {5};
z_owned_memory_layout_t layout;
z_memory_layout_new(&layout, SHM_BUFFER_SIZE_MB * 1024 * 1024, alignment);

z_owned_shm_provider_t provider;
if (z_posix_shm_provider_new(&provider, z_loan(layout)) != Z_OK) {
RMW_ZENOH_LOG_ERROR_NAMED("rmw_zenoh_cpp", "Unable to create an SHM provider.");
throw std::runtime_error("Unable to create an SHM provider.");
}
shm_provider_ = provider;
}
auto free_shm_provider = rcpputils::make_scope_exit(
[this]() {
if (shm_provider_.has_value()) {
z_drop(z_move(shm_provider_.value()));
}
});
// if (strncmp(
// z_string_data(z_loan(shm_enabled)),
// "true",
// z_string_len(z_loan(shm_enabled))) == 0)
// {
// // TODO(yuyuan): determine the default alignment of SHM
// z_alloc_alignment_t alignment = {5};
// z_owned_memory_layout_t layout;
// z_memory_layout_new(&layout, SHM_BUFFER_SIZE_MB * 1024 * 1024, alignment);

// z_owned_shm_provider_t provider;
// if (z_posix_shm_provider_new(&provider, z_loan(layout)) != Z_OK) {
// RMW_ZENOH_LOG_ERROR_NAMED("rmw_zenoh_cpp", "Unable to create an SHM provider.");
// throw std::runtime_error("Unable to create an SHM provider.");
// }
// shm_provider_ = provider;
// }
// auto free_shm_provider = rcpputils::make_scope_exit(
// [this]() {
// if (shm_provider_.has_value()) {
// z_drop(z_move(shm_provider_.value()));
// }
// });

graph_guard_condition_ = std::make_unique<rmw_guard_condition_t>();
graph_guard_condition_->implementation_identifier = rmw_zenoh_cpp::rmw_zenoh_identifier;
Expand Down Expand Up @@ -216,7 +216,7 @@ class rmw_context_impl_s::Data final
});

close_session.cancel();
free_shm_provider.cancel();
// free_shm_provider.cancel();
undeclare_z_sub.cancel();
}

Expand Down
8 changes: 7 additions & 1 deletion rmw_zenoh_cpp/src/detail/rmw_context_impl_s.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
#include "rmw/ret_types.h"
#include "rmw/types.h"

#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4099)
#endif
///=============================================================================
class rmw_context_impl_s final
{
Expand Down Expand Up @@ -95,6 +99,8 @@ class rmw_context_impl_s final
private:
std::shared_ptr<Data> data_{nullptr};
};

#ifdef _MSC_VER
#pragma warning(pop)
#endif

#endif // DETAIL__RMW_CONTEXT_IMPL_S_HPP_
2 changes: 1 addition & 1 deletion rmw_zenoh_cpp/src/detail/zenoh_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ std::optional<uint64_t> zenoh_router_check_attempts()
}
// If the environment variable contains a value, handle it accordingly.
if (envar_value[0] != '\0') {
const auto read_value = std::strtol(envar_value, nullptr, 10);
const auto read_value = std::strtoll(envar_value, nullptr, 10);
if (read_value > 0) {
return read_value;
} else if (read_value < 0) {
Expand Down
12 changes: 6 additions & 6 deletions rmw_zenoh_cpp/src/rmw_event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,16 +220,16 @@ rmw_take_event(
case rmw_zenoh_cpp::ZENOH_EVENT_REQUESTED_QOS_INCOMPATIBLE: {
auto ei = static_cast<rmw_requested_qos_incompatible_event_status_t *>(event_info);
RMW_CHECK_ARGUMENT_FOR_NULL(ei, RMW_RET_INVALID_ARGUMENT);
ei->total_count = st->total_count;
ei->total_count_change = st->total_count_change;
ei->total_count = static_cast<int32_t>(st->total_count);
ei->total_count_change = static_cast<int32_t>(st->total_count_change);
*taken = true;
return RMW_RET_OK;
}
case rmw_zenoh_cpp::ZENOH_EVENT_MESSAGE_LOST: {
auto ei = static_cast<rmw_message_lost_status_t *>(event_info);
RMW_CHECK_ARGUMENT_FOR_NULL(ei, RMW_RET_INVALID_ARGUMENT);
ei->total_count = st->total_count;
ei->total_count_change = st->total_count_change;
ei->total_count = static_cast<int32_t>(st->total_count);
ei->total_count_change = static_cast<int32_t>(st->total_count_change);
*taken = true;
return RMW_RET_OK;
}
Expand All @@ -247,8 +247,8 @@ rmw_take_event(
case rmw_zenoh_cpp::ZENOH_EVENT_OFFERED_QOS_INCOMPATIBLE: {
auto ei = static_cast<rmw_offered_qos_incompatible_event_status_t *>(event_info);
RMW_CHECK_ARGUMENT_FOR_NULL(ei, RMW_RET_INVALID_ARGUMENT);
ei->total_count = st->total_count;
ei->total_count_change = st->total_count_change;
ei->total_count = static_cast<int32_t>(st->total_count);
ei->total_count_change = static_cast<int32_t>(st->total_count_change);
*taken = true;
return RMW_RET_OK;
}
Expand Down
5 changes: 1 addition & 4 deletions rmw_zenoh_cpp/src/rmw_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,7 @@ 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) {
if (!rcutils_set_env_overwrite(ZENOH_LOG_ENV_VAR_STR, ZENOH_LOG_WARN_LEVEL_STR, 0)) {
RMW_SET_ERROR_MSG("Error configuring Zenoh logging.");
return RMW_RET_ERROR;
}
Expand Down
6 changes: 2 additions & 4 deletions rmw_zenoh_cpp/src/zenohd/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "rmw/error_handling.h"

#include "rcpputils/scope_exit.hpp"
#include "rcutils/env.h"

static bool running = true;
static std::mutex run_mutex;
Expand Down Expand Up @@ -60,10 +61,7 @@ int main(int argc, char ** argv)
(void)argc;
(void)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) {
if (!rcutils_set_env_overwrite(ZENOH_LOG_ENV_VAR_STR, ZENOH_LOG_INFO_LEVEL_STR, 0)) {
RMW_SET_ERROR_MSG("Error configuring Zenoh logging.");
return 1;
}
Expand Down

0 comments on commit 26360a8

Please sign in to comment.