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

Add rmw_*_event_init() functions #354

Merged
merged 7 commits into from
Mar 19, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions rmw_fastrtps_cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ add_library(rmw_fastrtps_cpp
src/rmw_client.cpp
src/rmw_compare_gids_equal.cpp
src/rmw_count.cpp
src/rmw_event.cpp
src/rmw_get_gid_for_publisher.cpp
src/rmw_get_implementation_identifier.cpp
src/rmw_get_serialization_format.cpp
Expand Down
50 changes: 50 additions & 0 deletions rmw_fastrtps_cpp/src/rmw_event.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "rmw/rmw.h"

#include "rmw_fastrtps_shared_cpp/rmw_common.hpp"

#include "rmw_fastrtps_cpp/identifier.hpp"

extern "C"
{
rmw_ret_t
rmw_publisher_event_init(
rmw_event_t * rmw_event,
const rmw_publisher_t * publisher,
rmw_event_type_t event_type)
{
return rmw_fastrtps_shared_cpp::__rmw_init_event(
eprosima_fastrtps_identifier,
rmw_event,
publisher->implementation_identifier,
publisher->data,
event_type);
}

rmw_ret_t
rmw_subscription_event_init(
rmw_event_t * rmw_event,
const rmw_subscription_t * subscription,
rmw_event_type_t event_type)
{
return rmw_fastrtps_shared_cpp::__rmw_init_event(
eprosima_fastrtps_identifier,
rmw_event,
subscription->implementation_identifier,
subscription->data,
event_type);
}
} // extern "C"
1 change: 1 addition & 0 deletions rmw_fastrtps_dynamic_cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ add_library(rmw_fastrtps_dynamic_cpp
src/rmw_client.cpp
src/rmw_compare_gids_equal.cpp
src/rmw_count.cpp
src/rmw_event.cpp
src/rmw_get_gid_for_publisher.cpp
src/rmw_get_implementation_identifier.cpp
src/rmw_get_serialization_format.cpp
Expand Down
50 changes: 50 additions & 0 deletions rmw_fastrtps_dynamic_cpp/src/rmw_event.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "rmw/rmw.h"

#include "rmw_fastrtps_shared_cpp/rmw_common.hpp"

#include "rmw_fastrtps_dynamic_cpp/identifier.hpp"

extern "C"
{
rmw_ret_t
rmw_publisher_event_init(
rmw_event_t * rmw_event,
const rmw_publisher_t * publisher,
rmw_event_type_t event_type)
{
return rmw_fastrtps_shared_cpp::__rmw_init_event(
eprosima_fastrtps_identifier,
rmw_event,
publisher->implementation_identifier,
publisher->data,
event_type);
}

rmw_ret_t
rmw_subscription_event_init(
rmw_event_t * rmw_event,
const rmw_subscription_t * subscription,
rmw_event_type_t event_type)
{
return rmw_fastrtps_shared_cpp::__rmw_init_event(
eprosima_fastrtps_identifier,
rmw_event,
subscription->implementation_identifier,
subscription->data,
event_type);
}
} // extern "C"
1 change: 1 addition & 0 deletions rmw_fastrtps_shared_cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ add_library(rmw_fastrtps_shared_cpp
src/rmw_client.cpp
src/rmw_compare_gids_equal.cpp
src/rmw_count.cpp
src/rmw_event.cpp
src/rmw_get_gid_for_publisher.cpp
src/rmw_get_topic_endpoint_info.cpp
src/rmw_guard_condition.cpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,15 @@ __rmw_get_node_names(
rcutils_string_array_t * node_names,
rcutils_string_array_t * node_namespaces);

RMW_FASTRTPS_SHARED_CPP_PUBLIC
rmw_ret_t
__rmw_init_event(
const char * identifier,
rmw_event_t * rmw_event,
const char * topic_endpoint_impl_identifier,
void * data,
rmw_event_type_t event_type);

RMW_FASTRTPS_SHARED_CPP_PUBLIC
rmw_ret_t
__rmw_publish(
Expand Down
3 changes: 3 additions & 0 deletions rmw_fastrtps_shared_cpp/src/custom_publisher_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

#include "rmw_fastrtps_shared_cpp/custom_publisher_info.hpp"
#include "types/event_types.hpp"

EventListenerInterface *
CustomPublisherInfo::getListener() const
Expand Down Expand Up @@ -59,6 +60,7 @@ void PubListener::on_liveliness_lost(

bool PubListener::hasEvent(rmw_event_type_t event_type) const
{
assert(is_event_supported(event_type));
switch (event_type) {
case RMW_EVENT_LIVELINESS_LOST:
return liveliness_changes_.load(std::memory_order_relaxed);
Expand All @@ -72,6 +74,7 @@ bool PubListener::hasEvent(rmw_event_type_t event_type) const

bool PubListener::takeNextEvent(rmw_event_type_t event_type, void * event_info)
{
assert(is_event_supported(event_type));
std::lock_guard<std::mutex> lock(internalMutex_);
switch (event_type) {
case RMW_EVENT_LIVELINESS_LOST:
Expand Down
3 changes: 3 additions & 0 deletions rmw_fastrtps_shared_cpp/src/custom_subscriber_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

#include "rmw_fastrtps_shared_cpp/custom_subscriber_info.hpp"
#include "types/event_types.hpp"

EventListenerInterface *
CustomSubscriberInfo::getListener() const
Expand Down Expand Up @@ -61,6 +62,7 @@ void SubListener::on_liveliness_changed(

bool SubListener::hasEvent(rmw_event_type_t event_type) const
{
assert(is_event_supported(event_type));
switch (event_type) {
case RMW_EVENT_LIVELINESS_CHANGED:
return liveliness_changes_.load(std::memory_order_relaxed);
Expand All @@ -74,6 +76,7 @@ bool SubListener::hasEvent(rmw_event_type_t event_type) const

bool SubListener::takeNextEvent(rmw_event_type_t event_type, void * event_info)
{
assert(is_event_supported(event_type));
std::lock_guard<std::mutex> lock(internalMutex_);
switch (event_type) {
case RMW_EVENT_LIVELINESS_CHANGED:
Expand Down
66 changes: 66 additions & 0 deletions rmw_fastrtps_shared_cpp/src/rmw_event.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <unordered_set>

#include "rmw/impl/cpp/macros.hpp"

#include "rmw_fastrtps_shared_cpp/rmw_common.hpp"
#include "types/event_types.hpp"

static const std::unordered_set<rmw_event_type_t> g_rmw_event_type_set{
RMW_EVENT_LIVELINESS_CHANGED,
RMW_EVENT_REQUESTED_DEADLINE_MISSED,
RMW_EVENT_LIVELINESS_LOST,
RMW_EVENT_OFFERED_DEADLINE_MISSED
};

bool is_event_supported(rmw_event_type_t event_type)
{
return g_rmw_event_type_set.count(event_type) > 0;
wjwwood marked this conversation as resolved.
Show resolved Hide resolved
}

namespace rmw_fastrtps_shared_cpp
{

rmw_ret_t
__rmw_init_event(
const char * identifier,
rmw_event_t * rmw_event,
const char * topic_endpoint_impl_identifier,
void * data,
rmw_event_type_t event_type)
{
RMW_CHECK_ARGUMENT_FOR_NULL(identifier, RMW_RET_INVALID_ARGUMENT);
RMW_CHECK_ARGUMENT_FOR_NULL(rmw_event, RMW_RET_INVALID_ARGUMENT);
RMW_CHECK_ARGUMENT_FOR_NULL(topic_endpoint_impl_identifier, RMW_RET_INVALID_ARGUMENT);
RMW_CHECK_ARGUMENT_FOR_NULL(data, RMW_RET_INVALID_ARGUMENT);
RMW_CHECK_TYPE_IDENTIFIERS_MATCH(
topic endpoint,
topic_endpoint_impl_identifier,
identifier,
return RMW_RET_INCORRECT_RMW_IMPLEMENTATION);
if (!::is_event_supported(event_type)) {
RMW_SET_ERROR_MSG("provided event_type is not supported by rmw_fastrtps_cpp");
return RMW_RET_UNSUPPORTED;
}

rmw_event->implementation_identifier = topic_endpoint_impl_identifier;
rmw_event->data = data;
rmw_event->event_type = event_type;

return RMW_RET_OK;
}

} // namespace rmw_fastrtps_shared_cpp
22 changes: 22 additions & 0 deletions rmw_fastrtps_shared_cpp/src/types/event_types.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef TYPES__EVENT_TYPES_HPP_
#define TYPES__EVENT_TYPES_HPP_

#include "rmw/event.h"

bool is_event_supported(rmw_event_type_t event_type);
wjwwood marked this conversation as resolved.
Show resolved Hide resolved

#endif // TYPES__EVENT_TYPES_HPP_