-
Notifications
You must be signed in to change notification settings - Fork 528
Expand file tree
/
Copy pathforward_message_channel.h
More file actions
100 lines (75 loc) · 2.46 KB
/
Copy pathforward_message_channel.h
File metadata and controls
100 lines (75 loc) · 2.46 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/**
******************************************************************************
Copyright (c) 2015 Particle Industries, Inc. All rights reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation, either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, see <http://www.gnu.org/licenses/>.
******************************************************************************
*/
#pragma once
#include "message_channel.h"
namespace particle { namespace protocol {
/**
* A message handler that forwards to another handler.
*/
class ForwardMessageChannel : public MessageChannel
{
MessageChannel* channel;
public:
ForwardMessageChannel() : channel(nullptr) {}
ForwardMessageChannel(MessageChannel& channel_) : channel(&channel_) {}
bool is_unreliable() override { return true; }
void setForward(MessageChannel* channel)
{
this->channel = channel;
}
ProtocolError send(Message& msg) override
{
return channel->send(msg);
}
ProtocolError receive(Message& msg) override
{
return channel->receive(msg);
}
ProtocolError create(Message& msg, size_t size) override
{
return channel->create(msg, size);
}
virtual ProtocolError establish() override
{
return channel->establish();
}
virtual ProtocolError response(Message& original, Message& response, size_t required) override
{
return channel->response(original, response, required);
}
virtual ProtocolError command(Command cmd, void* arg=nullptr) override {
return IO_ERROR_FORWARD_MESSAGE_CHANNEL;
}
virtual ProtocolError notify_established() override { return NO_ERROR; }
virtual void notify_client_messages_processed() override
{
channel->notify_client_messages_processed();
}
virtual bool has_pending_client_messages() const override
{
return channel->has_pending_client_messages();
}
virtual AppStateDescriptor cached_app_state_descriptor() const override
{
return AppStateDescriptor();
}
virtual void reset() override
{
}
void set_debug_enabled(bool enabled) override {
}
};
}}