sdbus-c++ 2.3.0
High-level C++ D-Bus library based on systemd D-Bus implementation
Loading...
Searching...
No Matches
MethodResult.h
Go to the documentation of this file.
1
26
27#ifndef SDBUS_CXX_METHODRESULT_H_
28#define SDBUS_CXX_METHODRESULT_H_
29
30#include <sdbus-c++/Message.h>
31
32#include <cassert>
33
34// Forward declarations
35namespace sdbus {
36 class Error;
37} // namespace sdbus
38
39namespace sdbus {
40
41 /********************************************/
49 template <typename... Results>
50 class Result
51 {
52 public:
53 Result() = default;
54 explicit Result(MethodCall call);
55
56 Result(const Result&) = delete;
57 Result& operator=(const Result&) = delete;
58
59 Result(Result&& other) = default;
60 Result& operator=(Result&& other) = default;
61
62 ~Result() = default;
63
64 void returnResults(const Results&... results) const;
65 void returnError(const Error& error) const;
66
67 private:
68 MethodCall call_;
69 };
70
71 template <typename... Results>
72 inline Result<Results...>::Result(MethodCall call)
73 : call_(std::move(call))
74 {
75 }
76
77 template <typename... Results>
78 inline void Result<Results...>::returnResults(const Results&... results) const
79 {
80 assert(call_.isValid());
81 auto reply = call_.createReply();
82 (void)(reply << ... << results);
83 reply.send();
84 }
85
86 template <typename... Results>
87 inline void Result<Results...>::returnError(const Error& error) const
88 {
89 auto reply = call_.createErrorReply(error);
90 reply.send();
91 }
92
93} // namespace sdbus
94
95#endif /* SDBUS_CXX_METHODRESULT_H_ */
Definition Error.h:44
Definition Message.h:278