-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmprpccontext.hpp
174 lines (135 loc) · 4.02 KB
/
mprpccontext.hpp
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
// solid/frame/mprpc/mprpccontext.hpp
//
// Copyright (c) 2015 Valentin Palade (vipalade @ gmail . com)
//
// This file is part of SolidFrame framework.
//
// Distributed under the Boost Software License, Version 1.0.
// See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.
//
#pragma once
#include <ostream>
#include "solid/system/log.hpp"
#include "solid/system/socketaddress.hpp"
#include "solid/utility/any.hpp"
#include "solid/frame/mprpc/mprpcid.hpp"
#include "solid/frame/mprpc/mprpcmessage.hpp"
#include "solid/frame/mprpc/mprpcmessageflags.hpp"
#include "solid/reflection/reflection.hpp"
namespace solid {
namespace frame {
namespace aio {
class ReactorContext;
} // namespace aio
namespace mprpc {
struct Message;
class Service;
struct MessageHeader;
struct MessageRelayHeader;
namespace relay {
class EngineCore;
}
const LoggerT& service_logger();
class Service;
class Connection;
class Configuration;
struct ConnectionProxy {
ConnectionProxy& operator=(const ConnectionProxy&) = delete;
private:
friend class SocketStub;
ConnectionProxy() {}
private:
friend struct ConnectionContext;
Service& service(frame::aio::ReactorContext& _rctx) const;
Connection& connection(frame::aio::ReactorContext& _rctx) const;
};
class ConnectionContext : NonCopyable {
frame::aio::ReactorContext& rreactor_context_;
Service& rservice_;
Connection& rconnection_;
MessageHeader* pmessage_header_{nullptr};
MessageFlagsT message_flags_{0};
RequestId request_id_;
MessageId message_id_;
MessageRelayHeader* pmessage_relay_header_{nullptr}; // we cannot make it const - serializer constraint
public:
ConnectionContext(
frame::aio::ReactorContext& _rctx,
const ConnectionProxy& _rccs)
: rreactor_context_(_rctx)
, rservice_(_rccs.service(_rctx))
, rconnection_(_rccs.connection(_rctx))
, message_flags_(0)
{
}
Service& service() const
{
return rservice_;
}
Configuration const& configuration() const;
ActorIdT connectionId() const;
const UniqueId& relayId() const;
RecipientId recipientId() const;
const std::string& recipientName() const;
SocketDevice const& device() const;
bool isConnectionActive() const;
bool isConnectionServer() const;
const MessageFlagsT& messageFlags() const
{
return message_flags_;
}
MessageId const& localMessageId() const
{
return message_id_;
}
MessagePointerT<> fetchRequest(Message const& _rmsg) const;
//! Keep any connection data
Any<>& any();
const ErrorConditionT& error() const;
const ErrorCodeT& systemError() const;
void stop(const ErrorConditionT& _err);
void pauseRead();
void resumeRead();
private:
// not used for now
RequestId const& requestId() const
{
return request_id_;
}
void relayId(const UniqueId& _relay_id) const;
private:
friend class Connection;
friend class RelayConnection;
friend class MessageWriter;
friend class MessageReader;
friend struct MessageHeader;
friend struct MessageRelayHeader;
friend struct Message;
friend class TestEntryway;
friend class relay::EngineCore;
friend class Service;
template <class Ctx>
friend struct ConnectionSenderResponse;
ConnectionContext(
frame::aio::ReactorContext& _rctx,
Service& _rsvc,
Connection& _rcon)
: rreactor_context_(_rctx)
, rservice_(_rsvc)
, rconnection_(_rcon)
{
}
ConnectionContext(ConnectionContext const&) = delete;
ConnectionContext& operator=(ConnectionContext const&) = delete;
Connection& connection()
{
return rconnection_;
}
auto& reactorContext()
{
return rreactor_context_;
}
};
} // namespace mprpc
} // namespace frame
} // namespace solid