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-#1036 move creation pattern to dust #1852

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 63 additions & 1 deletion doc/website/release-notes/iceoryx-unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,22 @@

```

42. Move `static_storage` from `iceoryx_hoofs` to `iceoryx_dust`
42. Move multiple classes from `iceoryx_hoofs` to `iceoryx_dust`

```cpp
// before
#include "iceoryx_hoofs/cxx/forward_list.hpp"

#include "iceoryx_dust/cxx/forward_list.hpp"
```

```cpp
// before
#include "iceoryx_hoofs/design_pattern/creation.hpp"

// after
#include "iceoryx_dust/design/creation.hpp"
```

```cpp
// before
Expand All @@ -822,3 +837,50 @@
#include "iceoryx_dust/internal/cxx/static_storage.hpp"
```

```cpp
// before
#include "iceoryx_hoofs/internal/file_reader/file_reader.hpp"

// after
#include "iceoryx_dust/cxx/file_reader.hpp"
```

```cpp
// before
#include "iceoryx_hoofs/internal/objectpool/objectpool.hpp"

// after
#include "iceoryx_dust/cxx/objectpool.hpp"
```

```cpp
// before
#include "iceoryx_hoofs/internal/relocatable_pointer/relocatable_ptr.hpp"

// after
#include "iceoryx_dust/relocatable_pointer/relocatable_ptr.hpp"
```

```cpp
// before
#include "iceoryx_hoofs/posix_wrapper/internal/message_queue.hpp"

// after
#include "iceoryx_dust/posix_wrapper/message_queue.hpp"
```

```cpp
// before
#include "iceoryx_hoofs/posix_wrapper/named_pipe.hpp"

// after
#include "iceoryx_dust/posix_wrapper/named_pipe.hpp"
```

```cpp
// before
#include "iceoryx_hoofs/posix_wrapper/signal_watcher.hpp"

// after
#include "iceoryx_dust/posix_wrapper/signal_watcher.hpp"
```
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
// limitations under the License.
//
// SPDX-License-Identifier: Apache-2.0
#ifndef IOX_HOOFS_DESIGN_PATTERN_CREATION_HPP
#define IOX_HOOFS_DESIGN_PATTERN_CREATION_HPP
#ifndef IOX_DUST_DESIGN_CREATION_HPP
#define IOX_DUST_DESIGN_CREATION_HPP

// NOLINTJUSTIFICATION iox-#1036 will be replaced by builder pattern
// NOLINTBEGIN
Expand Down Expand Up @@ -144,7 +144,7 @@ class Creation

} // namespace DesignPattern

#include "iceoryx_hoofs/internal/design_pattern/creation.inl"
#include "iceoryx_dust/internal/design/creation.inl"
// NOLINTEND

#endif // IOX_HOOFS_DESIGN_PATTERN_CREATION_HPP
#endif // IOX_HOOFS_DESIGN_CREATION_HPP
elBoberido marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
// limitations under the License.
//
// SPDX-License-Identifier: Apache-2.0
#ifndef IOX_HOOFS_DESIGN_PATTERN_CREATION_INL
#define IOX_HOOFS_DESIGN_PATTERN_CREATION_INL
#ifndef IOX_DUST_DESIGN_CREATION_INL
#define IOX_DUST_DESIGN_CREATION_INL

namespace DesignPattern
{
template <typename DerivedClass, typename ErrorType>
Expand Down Expand Up @@ -81,4 +82,5 @@ inline iox::expected<ErrorType> Creation<DerivedClass, ErrorType>::placementCrea


} // namespace DesignPattern
#endif

#endif // IOX_DUST_DESIGN_CREATION_INL
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#ifndef IOX_DUST_POSIX_WRAPPER_MESSAGE_QUEUE_HPP
#define IOX_DUST_POSIX_WRAPPER_MESSAGE_QUEUE_HPP

#include "iceoryx_hoofs/design_pattern/creation.hpp"
#include "iceoryx_dust/design/creation.hpp"
#include "iceoryx_hoofs/internal/posix_wrapper/ipc_channel.hpp"
#include "iceoryx_hoofs/internal/units/duration.hpp"
#include "iceoryx_platform/fcntl.hpp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
#ifndef IOX_DUST_POSIX_WRAPPER_NAMED_PIPE_HPP
#define IOX_DUST_POSIX_WRAPPER_NAMED_PIPE_HPP

#include "iceoryx_dust/design/creation.hpp"
#include "iceoryx_hoofs/concurrent/lockfree_queue.hpp"
#include "iceoryx_hoofs/design_pattern/creation.hpp"
#include "iceoryx_hoofs/internal/posix_wrapper/ipc_channel.hpp"
#include "iceoryx_hoofs/internal/posix_wrapper/shared_memory_object.hpp"
#include "iceoryx_hoofs/internal/units/duration.hpp"
Expand Down
1 change: 0 additions & 1 deletion iceoryx_examples/iceperf/mq.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

#include "base.hpp"

#include "iceoryx_hoofs/design_pattern/creation.hpp"
#include "iceoryx_hoofs/internal/posix_wrapper/ipc_channel.hpp"
#include "iceoryx_hoofs/internal/units/duration.hpp"
#include "iceoryx_platform/fcntl.hpp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#ifndef IOX_HOOFS_POSIX_WRAPPER_UNIX_DOMAIN_SOCKET_HPP
#define IOX_HOOFS_POSIX_WRAPPER_UNIX_DOMAIN_SOCKET_HPP

#include "iceoryx_hoofs/design_pattern/creation.hpp"
#include "iceoryx_hoofs/internal/posix_wrapper/ipc_channel.hpp"
#include "iceoryx_hoofs/internal/units/duration.hpp"
#include "iceoryx_platform/fcntl.hpp"
Expand All @@ -32,7 +31,7 @@ namespace iox
namespace posix
{
/// @brief Wrapper class for unix domain socket
class UnixDomainSocket : public DesignPattern::Creation<UnixDomainSocket, IpcChannelError>
class UnixDomainSocket
{
public:
struct NoPathPrefix_t
Expand All @@ -47,8 +46,8 @@ class UnixDomainSocket : public DesignPattern::Creation<UnixDomainSocket, IpcCha
using UdsName_t = string<LONGEST_VALID_NAME>;
using Message_t = string<MAX_MESSAGE_SIZE>;

/// @brief for calling private constructor in create method
friend class DesignPattern::Creation<UnixDomainSocket, IpcChannelError>;
using result_t = expected<UnixDomainSocket, IpcChannelError>;
using errorType_t = IpcChannelError;

/// @brief default constructor. The result is an invalid UnixDomainSocket object which can be reassigned later by
/// using the
Expand All @@ -62,6 +61,18 @@ class UnixDomainSocket : public DesignPattern::Creation<UnixDomainSocket, IpcCha

~UnixDomainSocket() noexcept;

/// @brief factory method which guarantees that either a working object is produced
/// or an error value describing the error during construction
/// @tparam Targs the argument types which will be forwarded to the ctor
/// @param[in] args the argument values which will be forwarded to the ctor
/// @return returns an expected which either contains the object in a valid
/// constructed state or an error value stating why the construction failed.
template <typename... Targs>
static expected<UnixDomainSocket, IpcChannelError> create(Targs&&... args) noexcept;

/// @brief returns true if the object was constructed successfully, otherwise false
bool isInitialized() const noexcept;

/// @brief unlink the provided unix domain socket
/// @param name of the unix domain socket to unlink
/// @return true if the unix domain socket could be unlinked, false otherwise, IpcChannelError if error occured
Expand Down Expand Up @@ -117,12 +128,29 @@ class UnixDomainSocket : public DesignPattern::Creation<UnixDomainSocket, IpcCha
static constexpr int32_t ERROR_CODE = -1;
static constexpr int32_t INVALID_FD = -1;

bool m_isInitialized{false};
IpcChannelError m_errorValue;

UdsName_t m_name;
IpcChannelSide m_channelSide = IpcChannelSide::CLIENT;
int32_t m_sockfd{INVALID_FD};
sockaddr_un m_sockAddr{};
size_t m_maxMessageSize{MAX_MESSAGE_SIZE};
};


template <typename... Targs>
expected<UnixDomainSocket, IpcChannelError> UnixDomainSocket::create(Targs&&... args) noexcept
{
UnixDomainSocket newObject{std::forward<Targs>(args)...};
if (!newObject.m_isInitialized)
{
return iox::error<IpcChannelError>(newObject.m_errorValue);
}

return iox::success<UnixDomainSocket>(std::move(newObject));
}
dkroenke marked this conversation as resolved.
Show resolved Hide resolved

} // namespace posix
} // namespace iox

Expand Down
14 changes: 8 additions & 6 deletions iceoryx_hoofs/source/posix_wrapper/unix_domain_socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,24 +122,26 @@ UnixDomainSocket& UnixDomainSocket::operator=(UnixDomainSocket&& other) noexcept
<< "\" in the move constructor/move assignment operator";
}

CreationPattern_t::operator=(std::move(other));

// @todo iox-#1036
// NOLINTJUSTIFICATION will be fixed with refactoring in #1036
// NOLINTBEGIN(bugprone-use-after-move, hicpp-invalid-access-moved)
m_isInitialized = other.m_isInitialized;
m_errorValue = other.m_errorValue;
m_name = std::move(other.m_name);
m_channelSide = other.m_channelSide;
m_sockfd = other.m_sockfd;
m_sockAddr = other.m_sockAddr;
m_maxMessageSize = other.m_maxMessageSize;
// NOLINTEND(bugprone-use-after-move, hicpp-invalid-access-moved)

other.m_isInitialized = false;
other.m_sockfd = INVALID_FD;
}

return *this;
}

bool UnixDomainSocket::isInitialized() const noexcept
{
return m_isInitialized;
}

expected<bool, IpcChannelError> UnixDomainSocket::unlinkIfExists(const UdsName_t& name) noexcept
{
if (!cxx::isValidPathToFile(name))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#ifndef IOX_POSH_MEPOO_SHARED_POINTER_HPP
#define IOX_POSH_MEPOO_SHARED_POINTER_HPP

#include "iceoryx_hoofs/design_pattern/creation.hpp"
#include "iceoryx_dust/design/creation.hpp"
#include "iceoryx_posh/internal/mepoo/shared_chunk.hpp"
#include "iceoryx_posh/mepoo/chunk_header.hpp"

Expand Down