Skip to content

Commit

Permalink
Implement new rmw functions needed for iron (#99)
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Hoinkis <simon.hoinkis@apex.ai>
  • Loading branch information
mossmaurice committed Oct 25, 2023
1 parent 91080ff commit 46a43ea
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 4 deletions.
1 change: 1 addition & 0 deletions rmw_iceoryx_cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ add_library(rmw_iceoryx_cpp SHARED
src/rmw_trigger_guard_condition.cpp
src/rmw_wait.cpp
src/rmw_wait_set.cpp
src/rmw_dynamic_type_support.cpp
)
ament_target_dependencies(rmw_iceoryx_cpp
"rcutils"
Expand Down
4 changes: 3 additions & 1 deletion rmw_iceoryx_cpp/src/iceoryx_generate_gid.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) 2019 by Robert Bosch GmbH. All rights reserved.
// Copyright (c) 2022 by Apex.AI Inc. All rights reserved.
// Copyright (c) 2022 - 2023 by Apex.AI Inc. 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.
Expand All @@ -19,7 +19,9 @@
#include "rmw/types.h"

#include "iceoryx_posh/popo/untyped_publisher.hpp"
#include "iceoryx_posh/popo/untyped_client.hpp"

rmw_gid_t generate_publisher_gid(iox::popo::UntypedPublisher * const publisher);
rmw_gid_t generate_client_gid(iox::popo::UntypedClient * const client);

#endif // ICEORYX_GENERATE_GID_HPP_
25 changes: 23 additions & 2 deletions rmw_iceoryx_cpp/src/internal/iceoryx_generate_gid.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) 2019 by Robert Bosch GmbH. All rights reserved.
// Copyright (c) 2022 by Apex.AI Inc. All rights reserved.
// Copyright (c) 2022 - 2023 by Apex.AI Inc. 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.
Expand All @@ -18,6 +18,7 @@
#include "rmw/impl/cpp/macros.hpp"

#include "iceoryx_posh/popo/untyped_publisher.hpp"
#include "iceoryx_posh/popo/untyped_client.hpp"

rmw_gid_t generate_publisher_gid(iox::popo::UntypedPublisher * const publisher)
{
Expand All @@ -31,7 +32,27 @@ rmw_gid_t generate_publisher_gid(iox::popo::UntypedPublisher * const publisher)
size_t size = sizeof(uid);

if (!typed_uid.isValid() || size > RMW_GID_STORAGE_SIZE) {
RMW_SET_ERROR_MSG("Could not generated gid");
RMW_SET_ERROR_MSG("Could not generated client gid");
return gid;
}
memcpy(gid.data, &uid, size);

return gid;
}

rmw_gid_t generate_client_gid(iox::popo::UntypedClient * const client)
{
rmw_gid_t gid;
gid.implementation_identifier = rmw_get_implementation_identifier();
memset(gid.data, 0, RMW_GID_STORAGE_SIZE);

iox::popo::UniquePortId typed_uid = client->getUid();
iox::popo::UniquePortId::value_type uid =
static_cast<iox::popo::UniquePortId::value_type>(typed_uid);
size_t size = sizeof(uid);

if (!typed_uid.isValid() || size > RMW_GID_STORAGE_SIZE) {
RMW_SET_ERROR_MSG("Could not generated publisher gid");
return gid;
}
memcpy(gid.data, &uid, size);
Expand Down
22 changes: 22 additions & 0 deletions rmw_iceoryx_cpp/src/rmw_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,4 +203,26 @@ rmw_ret_t rmw_client_set_on_new_response_callback(

return RMW_RET_UNSUPPORTED;
}

rmw_ret_t
rmw_get_gid_for_client(const rmw_client_t * client, rmw_gid_t * gid)
{
RCUTILS_CHECK_ARGUMENT_FOR_NULL(client, RMW_RET_INVALID_ARGUMENT);
RCUTILS_CHECK_ARGUMENT_FOR_NULL(gid, RMW_RET_INVALID_ARGUMENT);

RMW_CHECK_TYPE_IDENTIFIERS_MATCH(
rmw_get_gid_for_client
: client, client->implementation_identifier,
rmw_get_implementation_identifier(),
return RMW_RET_INCORRECT_RMW_IMPLEMENTATION);

IceoryxClient * iceoryx_client_abstraction = static_cast<IceoryxClient *>(client->data);

if (!iceoryx_client_abstraction) {
RMW_SET_ERROR_MSG("client info handle is null");
return RMW_RET_INVALID_ARGUMENT;
}
*gid = iceoryx_client_abstraction->gid_;
return RMW_RET_OK;
}
} // extern "C"
67 changes: 67 additions & 0 deletions rmw_iceoryx_cpp/src/rmw_dynamic_type_support.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Copyright (c) 2023 by Apex.AI Inc. 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/impl/cpp/macros.hpp"
#include "rmw/rmw.h"

extern "C"
{
rmw_ret_t
rmw_take_dynamic_message(
const rmw_subscription_t * subscription,
rosidl_dynamic_typesupport_dynamic_data_t * dynamic_message,
bool * taken,
rmw_subscription_allocation_t * allocation)
{
RCUTILS_CHECK_ARGUMENT_FOR_NULL(subscription, RMW_RET_ERROR);
RCUTILS_CHECK_ARGUMENT_FOR_NULL(dynamic_message, RMW_RET_ERROR);
RCUTILS_CHECK_ARGUMENT_FOR_NULL(taken, RMW_RET_ERROR);
RCUTILS_CHECK_ARGUMENT_FOR_NULL(allocation, RMW_RET_ERROR);

RMW_SET_ERROR_MSG("rmw_take_dynamic_message is not supported in iceoryx");
return RMW_RET_UNSUPPORTED;
}

rmw_ret_t
rmw_take_dynamic_message_with_info(
const rmw_subscription_t * subscription,
rosidl_dynamic_typesupport_dynamic_data_t * dynamic_message,
bool * taken,
rmw_message_info_t * message_info,
rmw_subscription_allocation_t * allocation)
{
RCUTILS_CHECK_ARGUMENT_FOR_NULL(subscription, RMW_RET_ERROR);
RCUTILS_CHECK_ARGUMENT_FOR_NULL(dynamic_message, RMW_RET_ERROR);
RCUTILS_CHECK_ARGUMENT_FOR_NULL(taken, RMW_RET_ERROR);
RCUTILS_CHECK_ARGUMENT_FOR_NULL(message_info, RMW_RET_ERROR);
RCUTILS_CHECK_ARGUMENT_FOR_NULL(allocation, RMW_RET_ERROR);

RMW_SET_ERROR_MSG("rmw_take_dynamic_message_with_info is not supported in iceoryx");
return RMW_RET_UNSUPPORTED;
}

rmw_ret_t
rmw_serialization_support_init(
const char * serialization_lib_name,
rcutils_allocator_t * allocator,
rosidl_dynamic_typesupport_serialization_support_t * serialization_support)
{
RCUTILS_CHECK_ARGUMENT_FOR_NULL(serialization_lib_name, RMW_RET_ERROR);
RCUTILS_CHECK_ARGUMENT_FOR_NULL(allocator, RMW_RET_ERROR);
RCUTILS_CHECK_ARGUMENT_FOR_NULL(serialization_support, RMW_RET_ERROR);

RMW_SET_ERROR_MSG("rmw_serialization_support_init is not supported in iceoryx");
return RMW_RET_UNSUPPORTED;
}
} // extern "C"
6 changes: 5 additions & 1 deletion rmw_iceoryx_cpp/src/types/iceoryx_client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#ifndef TYPES__ICEORYX_CLIENT_HPP_
#define TYPES__ICEORYX_CLIENT_HPP_

#include "../iceoryx_generate_gid.hpp"

#include "iceoryx_posh/popo/untyped_client.hpp"

#include "rmw/rmw.h"
Expand All @@ -30,14 +32,16 @@ struct IceoryxClient
: type_supports_(*type_supports),
iceoryx_client_(iceoryx_client),
is_fixed_size_(rmw_iceoryx_cpp::iceoryx_is_fixed_size(type_supports)),
request_size_(rmw_iceoryx_cpp::iceoryx_get_request_size(type_supports))
request_size_(rmw_iceoryx_cpp::iceoryx_get_request_size(type_supports)),
gid_(generate_client_gid(iceoryx_client_))
{}

rosidl_service_type_support_t type_supports_;
iox::popo::UntypedClient * const iceoryx_client_;
bool is_fixed_size_{false};
size_t request_size_{0};
int64_t sequence_id_{0};
rmw_gid_t gid_;
};

#endif // TYPES__ICEORYX_CLIENT_HPP_

0 comments on commit 46a43ea

Please sign in to comment.