Skip to content

Commit 16c6daa

Browse files
committed
iox-#27 Implement stream operator for ClientSendError and ServerSendError
1 parent 4e24385 commit 16c6daa

File tree

4 files changed

+121
-0
lines changed

4 files changed

+121
-0
lines changed

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

+19
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,23 @@ enum class ClientSendError
3838
INVALID_REQUEST,
3939
};
4040

41+
/// @brief Converts the ClientSendError to a string literal
42+
/// @param[in] value to convert to a string literal
43+
/// @return pointer to a string literal
44+
inline constexpr const char* asStringLiteral(const ClientSendError value) noexcept;
45+
46+
/// @brief Convenience stream operator to easily use the `asStringLiteral` function with std::ostream
47+
/// @param[in] stream sink to write the message to
48+
/// @param[in] value to convert to a string literal
49+
/// @return the reference to `stream` which was provided as input parameter
50+
inline std::ostream& operator<<(std::ostream& stream, ClientSendError value) noexcept;
51+
52+
/// @brief Convenience stream operator to easily use the `asStringLiteral` function with iox::log::LogStream
53+
/// @param[in] stream sink to write the message to
54+
/// @param[in] value to convert to a string literal
55+
/// @return the reference to `stream` which was provided as input parameter
56+
inline log::LogStream& operator<<(log::LogStream& stream, ClientSendError value) noexcept;
57+
4158
/// @brief The ClientPortUser provides the API for accessing a client port from the user side. The client port
4259
/// is divided in the three parts ClientPortData, ClientPortRouDi and ClientPortUser. The ClientPortUser
4360
/// uses the functionality of a ChunkSender and ChunReceiver for sending requests and receiving responses.
@@ -137,4 +154,6 @@ class ClientPortUser : public BasePort
137154
} // namespace popo
138155
} // namespace iox
139156

157+
#include "iceoryx_posh/internal/popo/ports/client_port_user.inl"
158+
140159
#endif // IOX_POSH_POPO_PORTS_CLIENT_PORT_USER_HPP
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Copyright (c) 2022 by Apex.AI Inc. 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+
// SPDX-License-Identifier: Apache-2.0
16+
17+
#ifndef IOX_POSH_POPO_PORTS_CLIENT_PORT_USER_INL
18+
#define IOX_POSH_POPO_PORTS_CLIENT_PORT_USER_INL
19+
20+
#include "iceoryx_posh/internal/popo/ports/client_port_user.hpp"
21+
22+
namespace iox
23+
{
24+
namespace popo
25+
{
26+
inline constexpr const char* asStringLiteral(const ClientSendError value) noexcept
27+
{
28+
switch (value)
29+
{
30+
case ClientSendError::NO_CONNECT_REQUESTED:
31+
return "ClientSendError::NO_CONNECT_REQUESTED";
32+
case ClientSendError::SERVER_NOT_AVAILABLE:
33+
return "ClientSendError::SERVER_NOT_AVAILABLE";
34+
case ClientSendError::INVALID_REQUEST:
35+
return "ClientSendError::INVALID_REQUEST";
36+
}
37+
38+
return "[Undefined ClientSendError]";
39+
}
40+
41+
inline std::ostream& operator<<(std::ostream& stream, ClientSendError value) noexcept
42+
{
43+
stream << asStringLiteral(value);
44+
return stream;
45+
}
46+
47+
inline log::LogStream& operator<<(log::LogStream& stream, ClientSendError value) noexcept
48+
{
49+
stream << asStringLiteral(value);
50+
return stream;
51+
}
52+
53+
} // namespace popo
54+
} // namespace iox
55+
56+
#endif // IOX_POSH_POPO_PORTS_CLIENT_PORT_USER_INL

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

+17
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,23 @@ enum class ServerSendError
7474
INVALID_RESPONSE,
7575
};
7676

77+
/// @brief Converts the ServerSendError to a string literal
78+
/// @param[in] value to convert to a string literal
79+
/// @return pointer to a string literal
80+
inline constexpr const char* asStringLiteral(const ServerSendError value) noexcept;
81+
82+
/// @brief Convenience stream operator to easily use the `asStringLiteral` function with std::ostream
83+
/// @param[in] stream sink to write the message to
84+
/// @param[in] value to convert to a string literal
85+
/// @return the reference to `stream` which was provided as input parameter
86+
inline std::ostream& operator<<(std::ostream& stream, ServerSendError value) noexcept;
87+
88+
/// @brief Convenience stream operator to easily use the `asStringLiteral` function with iox::log::LogStream
89+
/// @param[in] stream sink to write the message to
90+
/// @param[in] value to convert to a string literal
91+
/// @return the reference to `stream` which was provided as input parameter
92+
inline log::LogStream& operator<<(log::LogStream& stream, ServerSendError value) noexcept;
93+
7794
/// @brief The ServerPortUser provides the API for accessing a server port from the user side. The server port
7895
/// is divided in the three parts ServerPortData, ServerPortRouDi and ServerPortUser. The ServerPortUser
7996
/// uses the functionality of a ChunkSender and ChunReceiver for receiving requests and sending responses.

iceoryx_posh/include/iceoryx_posh/internal/popo/ports/server_port_user.inl

+29
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#ifndef IOX_POSH_POPO_PORTS_SERVER_PORT_USER_INL
1818
#define IOX_POSH_POPO_PORTS_SERVER_PORT_USER_INL
1919

20+
#include "iceoryx_posh/internal/popo/ports/server_port_user.hpp"
21+
2022
namespace iox
2123
{
2224
namespace cxx
@@ -67,6 +69,33 @@ inline log::LogStream& operator<<(log::LogStream& stream, ServerRequestResult va
6769
return stream;
6870
}
6971

72+
inline constexpr const char* asStringLiteral(const ServerSendError value) noexcept
73+
{
74+
switch (value)
75+
{
76+
case ServerSendError::NOT_OFFERED:
77+
return "ServerSendError::NOT_OFFERED";
78+
case ServerSendError::CLIENT_NOT_AVAILABLE:
79+
return "ServerSendError::CLIENT_NOT_AVAILABLE";
80+
case ServerSendError::INVALID_RESPONSE:
81+
return "ServerSendError::INVALID_RESPONSE";
82+
}
83+
84+
return "[Undefined ServerSendError]";
85+
}
86+
87+
inline std::ostream& operator<<(std::ostream& stream, ServerSendError value) noexcept
88+
{
89+
stream << asStringLiteral(value);
90+
return stream;
91+
}
92+
93+
inline log::LogStream& operator<<(log::LogStream& stream, ServerSendError value) noexcept
94+
{
95+
stream << asStringLiteral(value);
96+
return stream;
97+
}
98+
7099
} // namespace popo
71100
} // namespace iox
72101

0 commit comments

Comments
 (0)