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

iox #27 Sample class Refactoring #871

Closed
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,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
72 changes: 72 additions & 0 deletions iceoryx_posh/include/iceoryx_posh/internal/popo/request.inl
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved.
// Copyright (c) 2021 by Apex.AI Inc. All rights reserved.
// Copyright (c) 2021 by AVIN Systems Private Limited 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_INL
#define IOX_POSH_POPO_REQUEST_INL

namespace iox
{
namespace popo
{
template <typename T, typename H>
template <typename S, typename>
inline Request<T, H>::Request(cxx::unique_ptr<T>&& requestUniquePtr, RpcInterface<T, H>& producer) noexcept
: Base_t(std::move(requestUniquePtr), producer)
{
}

template <typename T, typename H>
template <typename S, typename>
inline Request<T, H>::Request(cxx::unique_ptr<T>&& requestUniquePtr) noexcept
: Base_t(std::move(requestUniquePtr))
{
}

template <typename T, typename H>
template <typename R, typename>
inline R& Request<T, H>::getRequestHeader() noexcept
{
return *static_cast<R*>(mepoo::ChunkHeader::fromUserPayload(m_members.smartchunkUniquePtr.get())->userHeader());
}

template <typename T, typename H>
template <typename R, typename>
inline const R& Request<T, H>::getRequestHeader() const noexcept
{
return const_cast<Request<T, H>*>(this)->getRequestHeader();
}

template <typename T, typename H>
template <typename S, typename>
inline void Request<T, H>::send() noexcept
{
if (m_members.smartchunkUniquePtr)
{
m_members.transmitterRef.get().sendRequest(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);
}
}

} // namespace popo
} // namespace iox

#endif // IOX_POSH_POPO_REQUEST_INL
72 changes: 72 additions & 0 deletions iceoryx_posh/include/iceoryx_posh/internal/popo/response.inl
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved.
// Copyright (c) 2021 by Apex.AI Inc. All rights reserved.
// Copyright (c) 2021 by AVIN Systems Private Limited 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_INL
#define IOX_POSH_POPO_RESPONSE_INL

namespace iox
{
namespace popo
{
template <typename T, typename H>
template <typename S, typename>
inline Response<T, H>::Response(cxx::unique_ptr<T>&& responseUniquePtr, RpcInterface<T, H>& producer) noexcept
: Base_t(std::move(responseUniquePtr), producer)
{
}

template <typename T, typename H>
template <typename S, typename>
inline Response<T, H>::Response(cxx::unique_ptr<T>&& responseUniquePtr) noexcept
: Base_t(std::move(responseUniquePtr))
{
}

template <typename T, typename H>
template <typename R, typename>
inline R& Response<T, H>::getResponseHeader() noexcept
{
return *static_cast<R*>(mepoo::ChunkHeader::fromUserPayload(m_members.smartchunkUniquePtr.get())->userHeader());
}

template <typename T, typename H>
template <typename R, typename>
inline const R& Response<T, H>::getResponseHeader() const noexcept
{
return const_cast<Response<T, H>*>(this)->getResponseHeader();
}

template <typename T, typename H>
template <typename S, typename>
inline void Response<T, H>::send() noexcept
{
if (m_members.smartchunkUniquePtr)
{
m_members.transmitterRef.get().sendResponse(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);
}
}

} // namespace popo
} // namespace iox

#endif // IOX_POSH_POPO_RESPONSE_INL
88 changes: 6 additions & 82 deletions iceoryx_posh/include/iceoryx_posh/internal/popo/sample.inl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved.
// Copyright (c) 2021 by Apex.AI Inc. All rights reserved.
// Copyright (c) 2021 by AVIN Systems Private Limited 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 @@ -22,96 +23,25 @@ namespace iox
{
namespace popo
{
namespace internal
{
template <typename T, typename H>
inline SamplePrivateData<T, H>::SamplePrivateData(cxx::unique_ptr<T>&& sampleUniquePtr,
PublisherInterface<T, H>& publisher) noexcept
: sampleUniquePtr(std::move(sampleUniquePtr))
, publisherRef(publisher)
{
}

template <typename T, typename H>
inline SamplePrivateData<const T, H>::SamplePrivateData(cxx::unique_ptr<const T>&& sampleUniquePtr) noexcept
: sampleUniquePtr(std::move(sampleUniquePtr))
{
}
} // namespace internal

template <typename T, typename H>
template <typename S, typename>
inline Sample<T, H>::Sample(cxx::unique_ptr<T>&& sampleUniquePtr, PublisherInterface<T, H>& publisher) noexcept
: m_members({std::move(sampleUniquePtr), publisher})
: Base_t(std::move(sampleUniquePtr), publisher)
{
}

template <typename T, typename H>
template <typename S, typename>
inline Sample<T, H>::Sample(cxx::unique_ptr<T>&& sampleUniquePtr) noexcept
: m_members(std::move(sampleUniquePtr))
{
}

template <typename T, typename H>
inline T* Sample<T, H>::operator->() noexcept
{
return get();
}

template <typename T, typename H>
inline const T* Sample<T, H>::operator->() const noexcept
{
return get();
}

template <typename T, typename H>
inline T& Sample<T, H>::operator*() noexcept
{
return *get();
}

template <typename T, typename H>
inline const T& Sample<T, H>::operator*() const noexcept
: Base_t(std::move(sampleUniquePtr))
{
return *get();
}

template <typename T, typename H>
inline Sample<T, H>::operator bool() const noexcept
{
return get() != nullptr;
}

template <typename T, typename H>
inline T* Sample<T, H>::get() noexcept
{
return m_members.sampleUniquePtr.get();
}

template <typename T, typename H>
inline const T* Sample<T, H>::get() const noexcept
{
return m_members.sampleUniquePtr.get();
}

template <typename T, typename H>
inline typename Sample<T, H>::ConditionalConstChunkHeader_t* Sample<T, H>::getChunkHeader() noexcept
{
return mepoo::ChunkHeader::fromUserPayload(m_members.sampleUniquePtr.get());
}

template <typename T, typename H>
inline const mepoo::ChunkHeader* Sample<T, H>::getChunkHeader() const noexcept
{
return mepoo::ChunkHeader::fromUserPayload(m_members.sampleUniquePtr.get());
}

template <typename T, typename H>
template <typename R, typename>
inline R& Sample<T, H>::getUserHeader() noexcept
{
return *static_cast<R*>(mepoo::ChunkHeader::fromUserPayload(m_members.sampleUniquePtr.get())->userHeader());
return *static_cast<R*>(mepoo::ChunkHeader::fromUserPayload(Base_t::m_members.smartchunkUniquePtr.get())->userHeader());
}

template <typename T, typename H>
Expand All @@ -125,9 +55,9 @@ template <typename T, typename H>
template <typename S, typename>
inline void Sample<T, H>::publish() noexcept
{
if (m_members.sampleUniquePtr)
if (Base_t::m_members.smartchunkUniquePtr)
{
m_members.publisherRef.get().publish(std::move(*this));
Base_t::m_members.transmitterRef.get().publish(std::move(*this));
}
else
{
Expand All @@ -136,12 +66,6 @@ inline void Sample<T, H>::publish() noexcept
}
}

template <typename T, typename H>
inline T* Sample<T, H>::release() noexcept
{
return m_members.sampleUniquePtr.release();
}

} // namespace popo
} // namespace iox

Expand Down
Loading