Skip to content

Commit 6784d01

Browse files
author
Poehnl Michael (CC-AD/ESW1)
committed
iox-eclipse-iceoryx#27-1: client port user skeleton
Signed-off-by: Poehnl Michael (CC-AD/ESW1) <[email protected]>
1 parent 4416528 commit 6784d01

File tree

7 files changed

+238
-12
lines changed

7 files changed

+238
-12
lines changed

iceoryx_posh/CMakeLists.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ add_library(iceoryx_posh
8484
source/popo/ports/subscriber_port_multi_producer.cpp
8585
source/popo/ports/subscriber_port_data.cpp
8686
source/popo/ports/client_port_data.cpp
87-
source/popo/ports/client_port_roudi.cpp
87+
source/popo/ports/client_port_roudi.cpp
88+
source/popo/ports/client_port_user.cpp
8889
source/popo/ports/server_port_data.cpp
8990
source/popo/ports/server_port_roudi.cpp
9091
source/popo/building_blocks/chunk_queue_types.cpp
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
// Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
#ifndef IOX_POSH_POPO_PORTS_CLIENT_PORT_USER_HPP
15+
#define IOX_POSH_POPO_PORTS_CLIENT_PORT_USER_HPP
16+
17+
#include "iceoryx_posh/internal/popo/building_blocks/chunk_receiver.hpp"
18+
#include "iceoryx_posh/internal/popo/building_blocks/chunk_sender.hpp"
19+
#include "iceoryx_posh/internal/popo/ports/base_port.hpp"
20+
#include "iceoryx_posh/internal/popo/ports/client_port_data.hpp"
21+
#include "iceoryx_posh/mepoo/chunk_header.hpp"
22+
#include "iceoryx_utils/cxx/expected.hpp"
23+
#include "iceoryx_utils/cxx/helplets.hpp"
24+
#include "iceoryx_utils/cxx/optional.hpp"
25+
#include "iceoryx_utils/error_handling/error_handling.hpp"
26+
27+
namespace iox
28+
{
29+
namespace popo
30+
{
31+
/// @brief The ClientPortUser provides the API for accessing a client port from the user side. The client port
32+
/// is divided in the three parts ClientPortData, ClientPortRouDi and ClientPortUser. The ClientPortUser
33+
/// uses the functionality of a ChunkSender and ChunReceiver for sending requests and receiving responses.
34+
/// Additionally it provides the connect / disconnect API which controls whether the client port shall connect to the
35+
/// server
36+
class ClientPortUser : public BasePort
37+
{
38+
public:
39+
using MemberType_t = ClientPortData;
40+
41+
explicit ClientPortUser(cxx::not_null<MemberType_t* const> clientPortDataPtr) noexcept;
42+
43+
ClientPortUser(const ClientPortUser& other) = delete;
44+
ClientPortUser& operator=(const ClientPortUser&) = delete;
45+
ClientPortUser(ClientPortUser&& rhs) = default;
46+
ClientPortUser& operator=(ClientPortUser&& rhs) = default;
47+
~ClientPortUser() = default;
48+
49+
/// @brief Allocate a chunk, the ownerhip of the SharedChunk remains in the ClientPortUser for being able to
50+
/// cleanup if the user process disappears
51+
/// @param[in] payloadSize, size of the user paylaod without additional headers
52+
/// @return on success pointer to a ChunkHeader which can be used to access the payload and header fields, error if
53+
/// not
54+
cxx::expected<mepoo::ChunkHeader*, AllocationError> allocateRequestChunk(const uint32_t payloadSize) noexcept;
55+
56+
/// @brief Free an allocated chunk without sending it
57+
/// @param[in] chunkHeader, pointer to the ChunkHeader to free
58+
void freeRequestChunk(mepoo::ChunkHeader* const chunkHeader) noexcept;
59+
60+
/// @brief Send an allocated request chunk to the server port
61+
/// @param[in] chunkHeader, pointer to the ChunkHeader to send
62+
void sendRequestChunk(mepoo::ChunkHeader* const chunkHeader) noexcept;
63+
64+
/// @brief try to connect to the server
65+
void connect() noexcept;
66+
67+
/// @brief disconnect from the server
68+
void disconnect() noexcept;
69+
70+
/// @brief get the current connection state. Caution: There can be delays between calling connect and a change
71+
/// in the conenction state. The connection state can also change without user interaction if the server comes
72+
/// and goes
73+
/// @return ConnectionState
74+
ConnectionState getConnectionState() const noexcept;
75+
76+
/// @brief Tries to get the next response from the queue. If there is a new one, the ChunkHeader of the oldest
77+
/// response in the queue is returned (FiFo queue)
78+
/// @return optional that has a new chunk header or no value if there are no new responses in the underlying queue,
79+
/// ChunkReceiveError on error
80+
cxx::expected<cxx::optional<const mepoo::ChunkHeader*>, ChunkReceiveError> getResponseChunk() noexcept;
81+
82+
/// @brief Release a response that was obtained with getResponseChunk
83+
/// @param[in] chunkHeader, pointer to the ChunkHeader to release
84+
void releaseResponseChunk(const mepoo::ChunkHeader* chunkHeader) noexcept;
85+
86+
/// @brief check if there are responses in the queue
87+
/// @return if there are responses in the queue return true, otherwise false
88+
bool hasNewResponseChunks() noexcept;
89+
90+
/// @brief check if there was a queue overflow since the last call of hasLostResponseChunks
91+
/// @return true if the underlying queue overflowed since last call of this method, otherwise false
92+
bool hasLostResponseChunks() noexcept;
93+
94+
/// @brief set a condition variable (via its pointer) to the client
95+
/// @return true if attachment worked, otherwise false
96+
bool setConditionVariable(ConditionVariableData* conditionVariableDataPtr) noexcept;
97+
98+
/// @brief unset a condition variable from the client
99+
/// @return true if detachment worked, otherwise false
100+
bool unsetConditionVariable() noexcept;
101+
102+
/// @brief check if there's a condition variable set
103+
/// @return true if a condition variable attached, otherwise false
104+
bool isConditionVariableSet() noexcept;
105+
106+
private:
107+
const MemberType_t* getMembers() const noexcept;
108+
MemberType_t* getMembers() noexcept;
109+
110+
ChunkSender<ClientChunkSenderData_t> m_chunkSender;
111+
ChunkReceiver<ClientChunkReceiverData_t> m_chunkReceiver;
112+
};
113+
114+
} // namespace popo
115+
} // namespace iox
116+
117+
#endif // IOX_POSH_POPO_PORTS_PUBLISHER_PORT_USER_HPP

iceoryx_posh/include/iceoryx_posh/internal/popo/ports/subscriber_port_user.hpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#define IOX_POPO_SUBSCRIBER_PORT_USER_HPP_
1717

1818
#include "iceoryx_posh/internal/popo/building_blocks/chunk_receiver.hpp"
19+
#include "iceoryx_posh/internal/popo/ports/base_port.hpp"
1920
#include "iceoryx_posh/internal/popo/ports/subscriber_port_data.hpp"
2021
#include "iceoryx_posh/mepoo/chunk_header.hpp"
2122
#include "iceoryx_utils/cxx/expected.hpp"
@@ -32,7 +33,7 @@ namespace popo
3233
/// The SubscriberPortUser uses the functionality of a ChunkReceiver for receiving shared memory chunks. Additionally it
3334
/// provides the subscribe / unsubscribe API which controls whether the subscriber ports shall try to subscribe to
3435
/// matching publisher ports
35-
class SubscriberPortUser
36+
class SubscriberPortUser : public BasePort
3637
{
3738
public:
3839
using MemberType_t = SubscriberPortData;
@@ -96,8 +97,6 @@ class SubscriberPortUser
9697
const MemberType_t* getMembers() const noexcept;
9798
MemberType_t* getMembers() noexcept;
9899

99-
MemberType_t* m_subscriberPortDataPtr;
100-
101100
ChunkReceiver<SubscriberPortData::ChunkReceiverData_t> m_chunkReceiver;
102101
};
103102

iceoryx_posh/source/popo/ports/client_port_roudi.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,17 @@ ClientPortRouDi::MemberType_t* ClientPortRouDi::getMembers() noexcept
3838

3939
cxx::optional<capro::CaproMessage> ClientPortRouDi::getCaProMessage() noexcept
4040
{
41+
/// @todo
42+
4143
// nothing to change
4244
return cxx::nullopt_t();
4345
}
4446

4547
cxx::optional<capro::CaproMessage>
4648
ClientPortRouDi::dispatchCaProMessage(const capro::CaproMessage& caProMessage) noexcept
4749
{
50+
/// @todo
51+
4852
capro::CaproMessage responseMessage(
4953
capro::CaproMessageType::NACK, this->getCaProServiceDescription(), capro::CaproMessageSubType::NOSUBTYPE);
5054

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
// Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License
14+
15+
#include "iceoryx_posh/internal/popo/ports/client_port_user.hpp"
16+
17+
namespace iox
18+
{
19+
namespace popo
20+
{
21+
ClientPortUser::ClientPortUser(cxx::not_null<MemberType_t* const> clientPortDataPtr) noexcept
22+
: BasePort(clientPortDataPtr)
23+
, m_chunkSender(&getMembers()->m_chunkSenderData)
24+
, m_chunkReceiver(&getMembers()->m_chunkReceiverData)
25+
26+
{
27+
}
28+
29+
const ClientPortUser::MemberType_t* ClientPortUser::getMembers() const noexcept
30+
{
31+
return reinterpret_cast<const MemberType_t*>(BasePort::getMembers());
32+
}
33+
34+
ClientPortUser::MemberType_t* ClientPortUser::getMembers() noexcept
35+
{
36+
return reinterpret_cast<MemberType_t*>(BasePort::getMembers());
37+
}
38+
39+
cxx::expected<mepoo::ChunkHeader*, AllocationError>
40+
ClientPortUser::allocateRequestChunk(const uint32_t payloadSize) noexcept
41+
{
42+
return m_chunkSender.allocate(payloadSize, getUniqueID());
43+
}
44+
45+
void ClientPortUser::freeRequestChunk(mepoo::ChunkHeader* const chunkHeader) noexcept
46+
{
47+
m_chunkSender.release(chunkHeader);
48+
}
49+
50+
void ClientPortUser::sendRequestChunk(mepoo::ChunkHeader* const chunkHeader) noexcept
51+
{
52+
/// @todo
53+
}
54+
55+
void ClientPortUser::connect() noexcept
56+
{
57+
/// @todo
58+
}
59+
60+
void ClientPortUser::disconnect() noexcept
61+
{
62+
/// @todo
63+
}
64+
65+
ConnectionState ClientPortUser::getConnectionState() const noexcept
66+
{
67+
return getMembers()->m_connectionState;
68+
}
69+
70+
cxx::expected<cxx::optional<const mepoo::ChunkHeader*>, ChunkReceiveError> ClientPortUser::getResponseChunk() noexcept
71+
{
72+
return m_chunkReceiver.get();
73+
}
74+
75+
void ClientPortUser::releaseResponseChunk(const mepoo::ChunkHeader* chunkHeader) noexcept
76+
{
77+
m_chunkReceiver.release(chunkHeader);
78+
}
79+
80+
bool ClientPortUser::hasNewResponseChunks() noexcept
81+
{
82+
return !m_chunkReceiver.empty();
83+
}
84+
85+
bool ClientPortUser::hasLostResponseChunks() noexcept
86+
{
87+
return m_chunkReceiver.hasOverflown();
88+
}
89+
90+
bool ClientPortUser::setConditionVariable(ConditionVariableData* conditionVariableDataPtr) noexcept
91+
{
92+
return m_chunkReceiver.attachConditionVariable(conditionVariableDataPtr);
93+
}
94+
95+
bool ClientPortUser::unsetConditionVariable() noexcept
96+
{
97+
return m_chunkReceiver.detachConditionVariable();
98+
}
99+
100+
bool ClientPortUser::isConditionVariableSet() noexcept
101+
{
102+
return m_chunkReceiver.isConditionVariableAttached();
103+
}
104+
105+
} // namespace popo
106+
} // namespace iox

iceoryx_posh/source/popo/ports/publisher_port_user.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,19 @@ namespace popo
2020
{
2121
PublisherPortUser::PublisherPortUser(cxx::not_null<MemberType_t* const> publisherPortDataPtr) noexcept
2222
: BasePort(publisherPortDataPtr)
23-
, m_publisherPortDataPtr(publisherPortDataPtr)
24-
, m_chunkSender(&m_publisherPortDataPtr->m_chunkSenderData)
23+
, m_chunkSender(&getMembers()->m_chunkSenderData)
2524

2625
{
2726
}
2827

2928
const PublisherPortUser::MemberType_t* PublisherPortUser::getMembers() const noexcept
3029
{
31-
return m_publisherPortDataPtr;
30+
return reinterpret_cast<const MemberType_t*>(BasePort::getMembers());
3231
}
3332

3433
PublisherPortUser::MemberType_t* PublisherPortUser::getMembers() noexcept
3534
{
36-
return m_publisherPortDataPtr;
35+
return reinterpret_cast<MemberType_t*>(BasePort::getMembers());
3736
}
3837

3938
cxx::expected<mepoo::ChunkHeader*, AllocationError>

iceoryx_posh/source/popo/ports/subscriber_port_user.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,20 @@ namespace iox
2020
namespace popo
2121
{
2222
SubscriberPortUser::SubscriberPortUser(cxx::not_null<MemberType_t* const> subscriberPortDataPtr) noexcept
23-
: m_subscriberPortDataPtr(subscriberPortDataPtr)
24-
, m_chunkReceiver(&m_subscriberPortDataPtr->m_chunkReceiverData)
23+
: BasePort(subscriberPortDataPtr)
24+
, m_chunkReceiver(&getMembers()->m_chunkReceiverData)
2525

2626
{
2727
}
2828

2929
const SubscriberPortUser::MemberType_t* SubscriberPortUser::getMembers() const noexcept
3030
{
31-
return m_subscriberPortDataPtr;
31+
return reinterpret_cast<const MemberType_t*>(BasePort::getMembers());
3232
}
3333

3434
SubscriberPortUser::MemberType_t* SubscriberPortUser::getMembers() noexcept
3535
{
36-
return m_subscriberPortDataPtr;
36+
return reinterpret_cast<MemberType_t*>(BasePort::getMembers());
3737
}
3838

3939

0 commit comments

Comments
 (0)