Skip to content

Commit

Permalink
Merge pull request #1110 from eclipse-iceoryx/iox-#27-preparations-fo…
Browse files Browse the repository at this point in the history
…r-typed-client-and-server-api

Iox #27 preparations for typed client and server api [stacked PR #4.5]
  • Loading branch information
elBoberido authored Feb 22, 2022
2 parents 10cda9d + 2afc558 commit 26c7310
Show file tree
Hide file tree
Showing 16 changed files with 343 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ namespace iox
error(POSH__SENDERPORT_ALLOCATE_FAILED) \
error(POSH__SENDERPORT_SUBSCRIBER_LIST_OVERFLOW) \
error(POSH__PUBLISHING_EMPTY_SAMPLE) \
error(POSH__SENDING_EMPTY_REQUEST) \
error(POSH__SENDING_EMPTY_RESPONSE) \
error(POSH__SHM_APP_BASEADDRESS_VIOLATES_SPECIFICATION) \
error(POSH__SHM_APP_SEGMENT_BASEADDRESS_VIOLATES_SPECIFICATION) \
error(POSH__SHM_APP_MAPP_ERR) \
Expand Down
12 changes: 11 additions & 1 deletion iceoryx_posh/include/iceoryx_posh/internal/popo/request.inl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#ifndef IOX_POSH_POPO_REQUEST_INL
#define IOX_POSH_POPO_REQUEST_INL

#include "iceoryx_posh/popo/request.hpp"

namespace iox
{
namespace popo
Expand All @@ -25,7 +27,15 @@ template <typename T>
template <typename S, typename>
inline void Request<T>::send() noexcept
{
BaseType::publish();
if (BaseType::m_members.smartChunkUniquePtr)
{
BaseType::m_members.producerRef.get().send(std::move(*(this)));
}
else
{
LogError() << "Tried to send empty Request! Might be an already sent or moved Request!";
errorHandler(Error::kPOSH__SENDING_EMPTY_REQUEST, nullptr, ErrorLevel::MODERATE);
}
}

template <typename T>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright (c) 2021 - 2022 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.
//
// SPDX-License-Identifier: Apache-2.0

#ifndef IOX_POSH_POPO_REQUEST_DELETER_HPP
#define IOX_POSH_POPO_REQUEST_DELETER_HPP

#include "iceoryx_posh/mepoo/chunk_header.hpp"
#include "iceoryx_posh/popo/rpc_header.hpp"

namespace iox
{
namespace popo
{
///
/// @brief The RequestDeleter struct is a custom deleter in functor form which releases loans to a request's
/// underlying memory chunk via the corresponding port.
/// Each port should create its own instance of this deleter struct.
/// @tparam Port is either the ClientPortUser or ServerPortUser and need to have a `releaseResponse` method
template <typename Port>
struct RequestDeleter
{
public:
explicit RequestDeleter(Port& port) noexcept;

/// @brief Handles deletion of the request.
/// @param[in] payload The pointer to the payload of the request.
template <typename T>
void operator()(T* const payload) noexcept;

/// @brief Handles deletion of the request.
/// @param[in] payload The pointer to the user-payload of the request.
template <typename T>
void operator()(const T* const payload) const noexcept;

private:
Port* m_port;
};

} // namespace popo
} // namespace iox

#include "iceoryx_posh/internal/popo/request_deleter.inl"

#endif // IOX_POSH_POPO_REQUEST_DELETER_HPP
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright (c) 2021 - 2022 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.
//
// SPDX-License-Identifier: Apache-2.0

#ifndef IOX_POSH_POPO_REQUEST_DELETER_INL
#define IOX_POSH_POPO_REQUEST_DELETER_INL

#include "iceoryx_posh/internal/popo/request_deleter.hpp"

namespace iox
{
namespace popo
{
template <typename Port>
RequestDeleter<Port>::RequestDeleter(Port& port) noexcept
: m_port(&port)
{
}

template <typename Port>
template <typename T>
void RequestDeleter<Port>::operator()(T* const payload) noexcept
{
auto* requestHeader = iox::popo::RequestHeader::fromPayload(payload);
m_port->releaseRequest(requestHeader);
}

template <typename Port>
template <typename T>
void RequestDeleter<Port>::operator()(const T* const payload) const noexcept
{
const auto* requestHeader = iox::popo::RequestHeader::fromPayload(payload);
m_port->releaseRequest(requestHeader);
}

} // namespace popo
} // namespace iox

#endif // IOX_POSH_POPO_REQUEST_DELETER_INL
12 changes: 11 additions & 1 deletion iceoryx_posh/include/iceoryx_posh/internal/popo/response.inl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#ifndef IOX_POSH_POPO_RESPONSE_INL
#define IOX_POSH_POPO_RESPONSE_INL

#include "iceoryx_posh/popo/response.hpp"

namespace iox
{
namespace popo
Expand All @@ -25,7 +27,15 @@ template <typename T>
template <typename S, typename>
inline void Response<T>::send() noexcept
{
BaseType::publish();
if (BaseType::m_members.smartChunkUniquePtr)
{
BaseType::m_members.producerRef.get().send(std::move(*(this)));
}
else
{
LogError() << "Tried to send empty Response! Might be an already sent or moved Response!";
errorHandler(Error::kPOSH__SENDING_EMPTY_RESPONSE, nullptr, ErrorLevel::MODERATE);
}
}

template <typename T>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright (c) 2021 - 2022 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.
//
// SPDX-License-Identifier: Apache-2.0

#ifndef IOX_POSH_POPO_RESPONSE_DELETER_HPP
#define IOX_POSH_POPO_RESPONSE_DELETER_HPP

#include "iceoryx_posh/mepoo/chunk_header.hpp"
#include "iceoryx_posh/popo/rpc_header.hpp"

namespace iox
{
namespace popo
{
///
/// @brief The ResponseDeleter struct is a custom deleter in functor form which releases loans to a response's
/// underlying memory chunk via the corresponding port..
/// Each port should create its own instance of this deleter struct.
/// @tparam Port is either the ClientPortUser or ServerPortUser and need to have a `releaseResponse` method
template <typename Port>
struct ResponseDeleter
{
public:
explicit ResponseDeleter(Port& port) noexcept;

/// @brief Handles deletion of the response.
/// @param[in] payload The pointer to the payload of the response.
template <typename T>
void operator()(T* const payload) noexcept;

/// @brief Handles deletion of the response.
/// @param[in] payload The pointer to the user-payload of the response.
template <typename T>
void operator()(const T* const payload) const noexcept;

private:
Port* m_port;
};

} // namespace popo
} // namespace iox

#include "iceoryx_posh/internal/popo/response_deleter.inl"

#endif // IOX_POSH_POPO_RESPONSE_DELETER_HPP
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright (c) 2021 - 2022 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.
//
// SPDX-License-Identifier: Apache-2.0

#ifndef IOX_POSH_POPO_RESPONSE_DELETER_INL
#define IOX_POSH_POPO_RESPONSE_DELETER_INL

#include "iceoryx_posh/internal/popo/response_deleter.hpp"

namespace iox
{
namespace popo
{
template <typename Port>
ResponseDeleter<Port>::ResponseDeleter(Port& port) noexcept
: m_port(&port)
{
}

template <typename Port>
template <typename T>
void ResponseDeleter<Port>::operator()(T* const payload) noexcept
{
auto* responseHeader = iox::popo::ResponseHeader::fromPayload(payload);
m_port->releaseResponse(responseHeader);
}

template <typename Port>
template <typename T>
void ResponseDeleter<Port>::operator()(const T* const payload) const noexcept
{
const auto* responseHeader = iox::popo::ResponseHeader::fromPayload(payload);
m_port->releaseResponse(responseHeader);
}

} // namespace popo
} // namespace iox

#endif // IOX_POSH_POPO_RESPONSE_DELETER_INL
43 changes: 43 additions & 0 deletions iceoryx_posh/include/iceoryx_posh/internal/popo/rpc_interface.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright (c) 2022 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.
//
// SPDX-License-Identifier: Apache-2.0

#ifndef IOX_POSH_RPC_INTERFACE_HPP
#define IOX_POSH_RPC_INTERFACE_HPP

namespace iox
{
namespace popo
{
/// @brief The RpcInterface class defines the request/response interface used by the Request/Response
/// classes to make them generic. This allows any client or server specialization to be stored as a reference
/// by the Request/Response class. It is also needed to avoid circular dependencies between Request/Response
/// and Client/Sever.
/// @tparam RpcType is either Request<T> for the client or Response<T> for the server
template <typename RpcType>
class RpcInterface
{
public:
/// @brief Sends the given Request<T> or Response<T> via the type which implements this interface
/// @param[in] rpcData is the actual Request<T> or Response<T> instance
virtual void send(RpcType&& rpcData) noexcept = 0;

protected:
RpcInterface() = default;
};
} // namespace popo
} // namespace iox

#endif // IOX_POSH_RPC_INTERFACE_HPP
12 changes: 11 additions & 1 deletion iceoryx_posh/include/iceoryx_posh/internal/popo/sample.inl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#ifndef IOX_POSH_POPO_SAMPLE_INL
#define IOX_POSH_POPO_SAMPLE_INL

#include "iceoryx_posh/popo/sample.hpp"

namespace iox
{
namespace popo
Expand All @@ -25,7 +27,15 @@ template <typename T, typename H>
template <typename S, typename>
void Sample<T, H>::publish() noexcept
{
BaseType::deliver();
if (BaseType::m_members.smartChunkUniquePtr)
{
BaseType::m_members.producerRef.get().publish(std::move(*(this)));
}
else
{
LogError() << "Tried to publish empty Sample! Might be an already published or moved Sample!";
errorHandler(Error::kPOSH__PUBLISHING_EMPTY_SAMPLE, nullptr, ErrorLevel::MODERATE);
}
}
} // namespace popo
} // namespace iox
Expand Down
Loading

0 comments on commit 26c7310

Please sign in to comment.