sdbus-c++: include/sdbus-c++/MethodResult.h Source File

sdbus-c++ 1.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
27#ifndef SDBUS_CXX_METHODRESULT_H_
28#define SDBUS_CXX_METHODRESULT_H_
29
30#include <sdbus-c++/Message.h>
31#include <cassert>
32
33// Forward declaration
34namespace sdbus {
35 class Error;
36}
37
38namespace sdbus {
39
40 /********************************************/
48 template <typename... _Results>
49 class Result
50 {
51 public:
52 Result() = default;
53 Result(MethodCall call);
54
55 Result(const Result&) = delete;
56 Result& operator=(const Result&) = delete;
57
58 Result(Result&& other) = default;
59 Result& operator=(Result&& other) = default;
60
61 void returnResults(const _Results&... results) const;
62 void returnError(const Error& error) const;
63
64 private:
65 MethodCall call_;
66 };
67
68 template <typename... _Results>
69 inline Result<_Results...>::Result(MethodCall call)
70 : call_(std::move(call))
71 {
72 }
73
74 template <typename... _Results>
75 inline void Result<_Results...>::returnResults(const _Results&... results) const
76 {
77 assert(call_.isValid());
78 auto reply = call_.createReply();
79 (void)(reply << ... << results);
80 reply.send();
81 }
82
83 template <typename... _Results>
84 inline void Result<_Results...>::returnError(const Error& error) const
85 {
86 auto reply = call_.createErrorReply(error);
87 reply.send();
88 }
89
90}
91
92#endif /* SDBUS_CXX_METHODRESULT_H_ */
Message.h
sdbus::Error
Definition Error.h:44
sdbus::MethodCall
Definition Message.h:232
sdbus::Result
Definition MethodResult.h:50