blob: 4b8fbe3fa264aaca6b24c921ea76973d6453a173 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
#include "error.h"
#include "message.h"
#include <memory>
namespace mbus {
/**
* A Result object is used as return value when trying to send a
* Message on a SourceSession. It says whether messagebus has accepted
* the message or not. If messagebus accepts the message an
* asynchronous reply will be delivered at a later time. If messagebus
* does not accept the message, the returned Result will indicate why
* the message was not accepted. A Result indication an error will
* also contain the message that did not get accepted, passing it back
* to the application. Note that Result objects have destructive copy
* of the pointer to the Message that is handed back to the
* application.
**/
class Result
{
private:
bool _accepted;
Error _error;
std::unique_ptr<Message> _msg;
public:
/**
* Create a Result indicating that messagebus has accepted the
* Message.
**/
Result();
/**
* Create a Result indicating that messagebus has not accepted the
* Message.
*
* @param err the reason for not accepting the Message
* @param msg the message that did not get accepted
**/
Result(const Error &err, std::unique_ptr<Message> msg);
Result(Result &&rhs) = default;
Result &operator=(Result &&rhs) = default;
~Result();
/**
* Check if the message was accepted.
*
* @return true if the Message was accepted
**/
bool isAccepted() const { return _accepted; }
/**
* Obtain the error causing the message not to be accepted.
*
* @return error
**/
const Error &getError() const { return _error; }
/**
* If the message was not accepted, this method may be used to get
* the Message back out. Note that this method hands the Message
* over to the caller. Also note that copying the Result will
* transfer the ownership of the Message to the new copy.
*
* @return the Message that was not accepted
**/
std::unique_ptr<Message> getMessage() { return std::move(_msg); }
};
} // namespace mbus
|