Skip to content

Commit

Permalink
iox-eclipse-iceoryx#218 Clean up comments.
Browse files Browse the repository at this point in the history
Signed-off-by: Ithier Jeff (CC-AD/EYF1) <[email protected]>
  • Loading branch information
orecham committed Aug 11, 2020
1 parent cb18950 commit a44bb56
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,16 @@ template<typename T, typename port_t>
inline cxx::expected<AllocationError>
Publisher<T, port_t>::publishCopyOf(const T& val) noexcept
{
std::cout << "publishCopyOf()" << std::endl;
return iox::cxx::success<>();
loan()
.and_then([&](Sample<T>& sample){
sample.emplace(val);
publish(std::move(sample));
});
}

template<typename T, typename port_t>
inline cxx::expected<ChunkRecallError>
Publisher<T, port_t>::previous() const noexcept
Publisher<T, port_t>::previousSample() const noexcept
{
assert(false && "Not yet supported");
return iox::cxx::error<ChunkRecallError>(ChunkRecallError::NO_PREVIOUS_CHUNK);
Expand All @@ -130,7 +133,7 @@ template<typename T, typename port_t>
inline bool
Publisher<T, port_t>::isOffered() noexcept
{
//return m_port.isOffered();
assert(false && "Not yet supported");
}

template<typename T, typename port_t>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,16 @@ class Sample
{
if(m_samplePtr != nullptr)
{
new (m_samplePtr.get()) T(std::forward<Arg>(arg), std::forward<Args>(args)...);
new (allocation()) T(std::forward<Arg>(arg), std::forward<Args>(args)...);
m_isEmpty = false;
}
}
void publish() noexcept
{
if(m_isValid && !m_isEmpty)
{
m_publisher.publish(*this); // Only delivers chunk, doesn't modify pointer.
m_samplePtr.release(); // Release pointer, no deletion required.
m_publisher.publish(*this);
m_samplePtr.release(); // Release ownership of the sample since it has been published.
m_isValid = false; // Mark as invalid to prevent re-use.
}
else
Expand All @@ -95,7 +95,7 @@ class Sample
Publisher<T>& m_publisher;
};

enum class ChunkRecallError : uint8_t
enum class SampleRecallError : uint8_t
{
NO_PREVIOUS_CHUNK,
CHUNK_ALREADY_CLAIMED
Expand Down Expand Up @@ -165,10 +165,10 @@ class Publisher
cxx::expected<AllocationError> publishCopyOf(const T& val) noexcept;

///
/// @brief previous Reclaims ownership of a previously published sample if it has not yet been accessed by subscribers.
/// @brief previousSample Reclaims ownership of a previously published sample if it has not yet been accessed by subscribers.
/// @return The previously published sample if one exists and is unclaimed, otherwise an error.
///
cxx::expected<ChunkRecallError> previous() const noexcept;
cxx::expected<SampleRecallError> previousSample() const noexcept;

/// @todo Make these const by changing the equivalent port methods.
void offer() noexcept;
Expand Down
80 changes: 19 additions & 61 deletions iceoryx_posh/test/moduletests/test_popo_publisher_experimental.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,64 +44,22 @@ TEST_F(ExperimentalPublisherTest, OffersWhenPublishingOnUnofferedPublisher)

}

//TEST_F(ExperimentalPublisherTest, BasicUidRetrieval)
//{
// struct Position {
// double_t x = 0.0;
// double_t y = 0.0;
// double_t z = 0.0;
// } position;

// iox::popo::Publisher<Position> publisher{};

// auto uid = publisher.uid();
// std::cout << "Publisher UID: " << uid << std::endl;

//}

//TEST_F(ExperimentalPublisherTest, BasicAllocateWriteAndPublish)
//{
// struct Position {
// double_t x = 0.0;
// double_t y = 0.0;
// double_t z = 0.0;
// };

// iox::popo::Publisher<Position> publisher{};
// publisher.allocate()
// .and_then([&](Position* chunk){
// auto position = new (chunk) Position();
// position->x = 42.42;
// position->y = 77.77;
// position->z = 00.15;
// publisher.publish(std::move(chunk));
// });
//}

//TEST_F(ExperimentalPublisherTest, BasicCopiedPublish)
//{
// struct Position {
// double_t x = 0.0;
// double_t y = 0.0;
// double_t z = 0.0;
// } position;

// iox::popo::Publisher<Position> publisher{};
// publisher.publishCopyOf(position);

//}

//TEST_F(ExperimentalPublisherTest, BasicAllocateThenPublish)
//{
// struct Position {
// double_t x = 0.0;
// double_t y = 0.0;
// double_t z = 0.0;
// } position;

// iox::popo::Publisher<Position> publisher{};
// publisher.allocate([&](Position* chunk){
// std::cout << "Lambda called with passed chunk." << std::endl;
// });

//}
TEST_F(ExperimentalPublisherTest, BasicUidRetrieval)
{

}

TEST_F(ExperimentalPublisherTest, BasicAllocateWriteAndPublish)
{

}

TEST_F(ExperimentalPublisherTest, BasicCopiedPublish)
{

}

TEST_F(ExperimentalPublisherTest, BasicAllocateThenPublish)
{

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright (c) 2020 by Robert Bosch GmbH. 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 "iceoryx_posh/experimental/popo/publisher.hpp"
#include "iceoryx_posh/capro/service_description.hpp"

#include "test.hpp"

#include <iostream>

using namespace ::testing;

class ExperimentalPublisherTest : public Test {

public:
ExperimentalPublisherTest()
{

}

void SetUp()
{
}

void TearDown()
{
}

};

TEST_F(ExperimentalPublisherTest, OffersIfTryingToPublishBeforeOffer)
{

}

TEST_F(ExperimentalPublisherTest, )
{

}

TEST_F(ExperimentalPublisherTest, BasicCopiedPublish)
{

}

TEST_F(ExperimentalPublisherTest, BasicAllocateThenPublish)
{

}
28 changes: 14 additions & 14 deletions iceoryx_utils/include/iceoryx_utils/cxx/unique_ptr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@ class unique_ptr{

unique_ptr() = delete;

// ///
// /// @brief An empty pointer that does nothing.
// ///
// unique_ptr(std::nullptr_t) noexcept
// {};

///
/// @brief operator = Reset to empty pointer when setting to nullptr.
/// @return An empty unique pointer.
Expand All @@ -52,24 +46,24 @@ class unique_ptr{
}

///
/// @brief unique_ptr Creates an empty unique ptr that owns nothing. Can be passed ownership later.
/// @brief unique_ptr Creates an empty unique ptr that owns nothing. Can be passed ownership later via reset.
///
unique_ptr(std::function<void(T*)>&& deleter) noexcept;

///
/// @brief unique_ptr Creates a unique pointer that takes ownership of an object.
/// @details A deleter must always be provided as no heap is used. The unique_ptr needs to know how to delete
/// the managed object when the reference is out of scope.
/// @details A deleter must always be provided as no default can be provided given that no head is used.
/// The unique_ptr must know how to delete the managed object when pointer out of scope.
/// @param ptr The raw pointer to the object to be managed.
/// @param deleter The deleter function for cleaning up the managed object.
///
unique_ptr(ptr_t ptr, std::function<void(T*)>&& deleter) noexcept;

///
/// @brief unique_ptr Creates an empty unique pointer that points to an allocated memory location.
/// @details The managed object is initially undefined thus must be defined before accessing.
/// @details The contents of the pointeris initially undefined thus must be defined before accessing.
/// @param allocation The allocation of memory where managed object will reside once created.
/// @param deleter The deleter function for cleaning up the managed object.
/// @param deleter The deleter function for cleaning up the allocated memory.
///
unique_ptr(void* allocation, std::function<void(T*)>&& deleter) noexcept;

Expand All @@ -85,12 +79,19 @@ class unique_ptr{
///
~unique_ptr() noexcept;

///
/// Dereference the stored pointer.
///
T operator*() noexcept;

///
/// Return the stored pointer.
///
ptr_t operator->() noexcept;

///
/// @brief operator bool Returns true if it points to something.
///
explicit operator bool() const noexcept
{ return get() == ptr_t() ? false : true; }

Expand All @@ -102,15 +103,14 @@ class unique_ptr{
ptr_t get() const noexcept;

///
/// @brief release Releases ownership of the underlying pointer.
/// @brief release Release ownership of the underlying pointer.
/// @return Pointer to the managed object or nullptr if none owned.
///
ptr_t release() noexcept;

///
/// @brief reset Reset the unique_ptr instance's owned object to the one given.
/// @brief reset Reset the unique pointer to take ownership of the given pointer.
/// @details Any previously owned objects will be deleted. If no pointer given then points to nullptr.
/// Deleter provided on instantiation will remain.
/// @param ptr Pointer to object to take ownership on.
///
void reset(ptr_t ptr = nullptr) noexcept;
Expand Down

0 comments on commit a44bb56

Please sign in to comment.