-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add rmw_*_event_init() functions (#354)
Signed-off-by: Miaofei <[email protected]>
- Loading branch information
Showing
10 changed files
with
218 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// 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 | ||
}; | ||
|
||
namespace rmw_fastrtps_shared_cpp | ||
{ | ||
namespace internal | ||
{ | ||
|
||
bool is_event_supported(rmw_event_type_t event_type) | ||
{ | ||
return g_rmw_event_type_set.count(event_type) == 1; | ||
} | ||
|
||
} // namespace internal | ||
|
||
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 (!internal::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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// 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" | ||
|
||
namespace rmw_fastrtps_shared_cpp | ||
{ | ||
namespace internal | ||
{ | ||
|
||
bool is_event_supported(rmw_event_type_t event_type); | ||
|
||
} // namespace internal | ||
} // namespace rmw_fastrtps_shared_cpp | ||
|
||
#endif // TYPES__EVENT_TYPES_HPP_ |