Skip to content

Commit 099859f

Browse files
committed
Support interfaces for RPC generated code (#5622)
* Refs #22722. Add RpcException class. Signed-off-by: Miguel Company <[email protected]> * Refs #22722. Add RpcTimeoutException class. Signed-off-by: Miguel Company <[email protected]> * Refs #22722. Add RpcBrokenPipeException class. * Refs #22722. Add RpcOperationError class. Signed-off-by: Miguel Company <[email protected]> * Refs #22722. Add utility include for exceptions. Signed-off-by: Miguel Company <[email protected]> * Refs #22722. Add RpcServerReader template interface. Signed-off-by: Miguel Company <[email protected]> * Refs #22722. Add RpcClientReader template interface. Signed-off-by: Miguel Company <[email protected]> * Refs #22722. Add RpcServerWriter template interface. Signed-off-by: Miguel Company <[email protected]> * Refs #22722. Add RpcClientWriter template interface. Signed-off-by: Miguel Company <[email protected]> * Refs #22722. Add RpcInputFeedCancelledException. Signed-off-by: Miguel Company <[email protected]> * Refs #22722. Add RpcFuture template. Signed-off-by: Miguel Company <[email protected]> * Refs #22722. Rename `RpcInputFeedCancelledException` -> `RpcFeedCancelledException` Signed-off-by: Miguel Company <[email protected]> * Refs #22722. `RpcServerWriter` operations can throw `RpcFeedCancelledException` Signed-off-by: Miguel Company <[email protected]> * Refs #22722. Improve documentation of `RpcClientReader` Signed-off-by: Miguel Company <[email protected]> * Refs #22722. Improve documentation of `RpcClientWriter` Signed-off-by: Miguel Company <[email protected]> * Refs #22722. Avoid DSO export warning on Windows Signed-off-by: Miguel Company <[email protected]> * Refs #22722. Add utility include for interfaces. Signed-off-by: Miguel Company <[email protected]> * Refs #22722. Add missing argument on doxygen documentation. Signed-off-by: Miguel Company <[email protected]> --------- Signed-off-by: Miguel Company <[email protected]>
1 parent e63742b commit 099859f

13 files changed

+887
-0
lines changed
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2025 Proyectos y Sistemas de Mantenimiento SL (eProsima).
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+
/**
16+
* @file exceptions.hpp
17+
*/
18+
19+
#ifndef FASTDDS_DDS_RPC__EXCEPTIONS_HPP
20+
#define FASTDDS_DDS_RPC__EXCEPTIONS_HPP
21+
22+
#include <fastdds/dds/rpc/exceptions/RpcBrokenPipeException.hpp>
23+
#include <fastdds/dds/rpc/exceptions/RpcException.hpp>
24+
#include <fastdds/dds/rpc/exceptions/RpcFeedCancelledException.hpp>
25+
#include <fastdds/dds/rpc/exceptions/RpcOperationError.hpp>
26+
#include <fastdds/dds/rpc/exceptions/RpcTimeoutException.hpp>
27+
28+
#endif // FASTDDS_DDS_RPC__EXCEPTIONS_HPP
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Copyright 2025 Proyectos y Sistemas de Mantenimiento SL (eProsima).
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+
/**
16+
* @file RpcBrokenPipeException.hpp
17+
*/
18+
19+
#ifndef FASTDDS_DDS_RPC_EXCEPTIONS__RPCBROKENPIPEEXCEPTION_HPP
20+
#define FASTDDS_DDS_RPC_EXCEPTIONS__RPCBROKENPIPEEXCEPTION_HPP
21+
22+
#include <fastdds/fastdds_dll.hpp>
23+
#include <fastdds/dds/rpc/exceptions/RpcException.hpp>
24+
25+
namespace eprosima {
26+
namespace fastdds {
27+
namespace dds {
28+
namespace rpc {
29+
30+
/**
31+
* Exception thrown by the RPC API when the communication with the remote endpoint breaks.
32+
*/
33+
class FASTDDS_EXPORTED_API RpcBrokenPipeException : public RpcException
34+
{
35+
36+
public:
37+
38+
/**
39+
* Constructor.
40+
*/
41+
RpcBrokenPipeException(
42+
bool local_is_server)
43+
: RpcException(local_is_server ? "Communication lost with the client" : "Communication lost with the server")
44+
{
45+
}
46+
47+
/**
48+
* Copy constructor.
49+
*/
50+
RpcBrokenPipeException(
51+
const RpcBrokenPipeException& other) noexcept = default;
52+
53+
/**
54+
* Copy assignment.
55+
*/
56+
RpcBrokenPipeException& operator =(
57+
const RpcBrokenPipeException& other) noexcept = default;
58+
59+
/**
60+
* Destructor.
61+
*/
62+
virtual ~RpcBrokenPipeException() noexcept = default;
63+
64+
};
65+
66+
} // namespace rpc
67+
} // namespace dds
68+
} // namespace fastdds
69+
} // namespace eprosima
70+
71+
#endif // FASTDDS_DDS_RPC_EXCEPTIONS__RPCBROKENPIPEEXCEPTION_HPP
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
// Copyright 2025 Proyectos y Sistemas de Mantenimiento SL (eProsima).
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+
/**
16+
* @file RpcException.hpp
17+
*/
18+
19+
#ifndef FASTDDS_DDS_RPC_EXCEPTIONS__RPCEXCEPTION_HPP
20+
#define FASTDDS_DDS_RPC_EXCEPTIONS__RPCEXCEPTION_HPP
21+
22+
#include <stdexcept>
23+
#include <string>
24+
25+
#include <fastdds/fastdds_dll.hpp>
26+
27+
namespace eprosima {
28+
namespace fastdds {
29+
namespace dds {
30+
namespace rpc {
31+
32+
/**
33+
* Base class for all exceptions thrown by the RPC API.
34+
*/
35+
class FASTDDS_EXPORTED_API RpcException
36+
{
37+
38+
public:
39+
40+
/**
41+
* Constructor.
42+
*
43+
* @param message The exception message.
44+
*/
45+
explicit RpcException(
46+
const std::string& message)
47+
: logic_error_(message)
48+
{
49+
}
50+
51+
/**
52+
* Constructor.
53+
*
54+
* @param message The exception message.
55+
*/
56+
explicit RpcException(
57+
const char* message)
58+
: logic_error_(message)
59+
{
60+
}
61+
62+
/**
63+
* Copy constructor.
64+
*/
65+
RpcException(
66+
const RpcException& other) noexcept = default;
67+
68+
/**
69+
* Copy assignment.
70+
*/
71+
RpcException& operator =(
72+
const RpcException& other) noexcept = default;
73+
74+
/**
75+
* Destructor.
76+
*/
77+
virtual ~RpcException() noexcept = default;
78+
79+
/**
80+
* Returns the explanatory string.
81+
*/
82+
const char* what() const noexcept
83+
{
84+
return logic_error_.what();
85+
}
86+
87+
private:
88+
89+
std::logic_error logic_error_;
90+
91+
};
92+
93+
} // namespace rpc
94+
} // namespace dds
95+
} // namespace fastdds
96+
} // namespace eprosima
97+
98+
#endif // FASTDDS_DDS_RPC_EXCEPTIONS__RPCEXCEPTION_HPP
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// Copyright 2025 Proyectos y Sistemas de Mantenimiento SL (eProsima).
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+
/**
16+
* @file RpcFeedCancelledException.hpp
17+
*/
18+
19+
#ifndef FASTDDS_DDS_RPC_EXCEPTIONS__RPCINPUTFEEDCANCELLEDEXCEPTION_HPP
20+
#define FASTDDS_DDS_RPC_EXCEPTIONS__RPCINPUTFEEDCANCELLEDEXCEPTION_HPP
21+
22+
#include <string>
23+
24+
#include <fastdds/fastdds_dll.hpp>
25+
#include <fastdds/dds/rpc/exceptions/RpcException.hpp>
26+
#include <fastdds/dds/rpc/interfaces/RpcStatusCode.hpp>
27+
28+
namespace eprosima {
29+
namespace fastdds {
30+
namespace dds {
31+
namespace rpc {
32+
33+
/**
34+
* Exception thrown by the RPC API when the client cancels an input feed.
35+
*/
36+
class FASTDDS_EXPORTED_API RpcFeedCancelledException : public RpcException
37+
{
38+
39+
public:
40+
41+
/**
42+
* Constructor.
43+
*/
44+
RpcFeedCancelledException(
45+
RpcStatusCode reason)
46+
: RpcException("Input feed cancelled with reason '" + std::to_string(reason) + "'")
47+
{
48+
}
49+
50+
/**
51+
* Copy constructor.
52+
*/
53+
RpcFeedCancelledException(
54+
const RpcFeedCancelledException& other) noexcept = default;
55+
56+
/**
57+
* Copy assignment.
58+
*/
59+
RpcFeedCancelledException& operator =(
60+
const RpcFeedCancelledException& other) noexcept = default;
61+
62+
/**
63+
* Destructor.
64+
*/
65+
virtual ~RpcFeedCancelledException() noexcept = default;
66+
67+
};
68+
69+
} // namespace rpc
70+
} // namespace dds
71+
} // namespace fastdds
72+
} // namespace eprosima
73+
74+
#endif // FASTDDS_DDS_RPC_EXCEPTIONS__RPCINPUTFEEDCANCELLEDEXCEPTION_HPP
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// Copyright 2025 Proyectos y Sistemas de Mantenimiento SL (eProsima).
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+
/**
16+
* @file RpcOperationError.hpp
17+
*/
18+
19+
#ifndef FASTDDS_DDS_RPC_EXCEPTIONS__RPCOPERATIONERROR_HPP
20+
#define FASTDDS_DDS_RPC_EXCEPTIONS__RPCOPERATIONERROR_HPP
21+
22+
#include <string>
23+
24+
#include <fastdds/fastdds_dll.hpp>
25+
#include <fastdds/dds/rpc/exceptions/RpcException.hpp>
26+
27+
namespace eprosima {
28+
namespace fastdds {
29+
namespace dds {
30+
namespace rpc {
31+
32+
/**
33+
* Base class for exceptions thrown by the RPC API when the server communicates an error.
34+
*/
35+
class FASTDDS_EXPORTED_API RpcOperationError : public RpcException
36+
{
37+
38+
public:
39+
40+
/**
41+
* Constructor.
42+
*/
43+
RpcOperationError(
44+
const std::string& message)
45+
: RpcException(message)
46+
{
47+
}
48+
49+
/**
50+
* Constructor.
51+
*/
52+
RpcOperationError(
53+
const char* message)
54+
: RpcException(message)
55+
{
56+
}
57+
58+
/**
59+
* Copy constructor.
60+
*/
61+
RpcOperationError(
62+
const RpcOperationError& other) noexcept = default;
63+
64+
/**
65+
* Copy assignment.
66+
*/
67+
RpcOperationError& operator =(
68+
const RpcOperationError& other) noexcept = default;
69+
70+
/**
71+
* Destructor.
72+
*/
73+
virtual ~RpcOperationError() noexcept = default;
74+
75+
};
76+
77+
} // namespace rpc
78+
} // namespace dds
79+
} // namespace fastdds
80+
} // namespace eprosima
81+
82+
#endif // FASTDDS_DDS_RPC_EXCEPTIONS__RPCOPERATIONERROR_HPP

0 commit comments

Comments
 (0)