forked from solidoss/solidframe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathipccontext.hpp
213 lines (155 loc) · 4.13 KB
/
ipccontext.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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
// solid/frame/ipc/ipccontext.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.
//
#ifndef SOLID_FRAME_IPC_IPC_CONTEXT_HPP
#define SOLID_FRAME_IPC_IPC_CONTEXT_HPP
#include "solid/system/socketaddress.hpp"
#include "solid/utility/dynamicpointer.hpp"
#include "solid/utility/any.hpp"
#include <ostream>
#include "solid/frame/common.hpp"
namespace solid{
namespace frame{
namespace ipc{
//! A structure to uniquely indetify an IPC connection pool
/*!
<b>Overview:</b><br>
<b>Usage:</b><br>
*/
struct ConnectionPoolId: UniqueId{
ConnectionPoolId(
const size_t _idx = InvalidIndex(),
const uint32_t _uid = InvalidIndex()
):UniqueId(_idx, _uid){}
};
struct RecipientId{
RecipientId(){}
RecipientId(
const RecipientId &_rid
): poolid(_rid.poolid), connectionid(_rid.connectionid){}
explicit RecipientId(
const ObjectIdT &_rconid
):connectionid(_rconid){}
bool isInvalid()const{
return isInvalidConnection() || isInvalidPool();
}
bool isInvalidConnection()const{
return connectionid.isInvalid();
}
bool isValidConnection()const{
return connectionid.isValid();
}
bool isInvalidPool()const{
return poolid.isInvalid();
}
bool isValidPool()const{
return poolid.isValid();
}
ConnectionPoolId const& poolId()const{
return poolid;
}
ObjectIdT const& connectionId()const{
return connectionid;
}
private:
friend class Service;
friend class Connection;
friend struct ConnectionContext;
RecipientId(
const ConnectionPoolId &_rpoolid,
const ObjectIdT &_rconid
):poolid(_rpoolid), connectionid(_rconid){}
ConnectionPoolId poolid;
ObjectIdT connectionid;
};
std::ostream& operator<<(std::ostream &_ros, RecipientId const &_rec_id);
struct RequestId{
uint32_t index;
uint32_t unique;
RequestId(
const uint32_t _idx = InvalidIndex(),
const uint32_t _uid = InvalidIndex()
):index(_idx), unique(_uid){}
};
std::ostream& operator<<(std::ostream &_ros, RequestId const &_msguid);
struct MessageId{
MessageId(): index(InvalidIndex()), unique(0){}
MessageId(MessageId const &_rmsguid): index(_rmsguid.index), unique(_rmsguid.unique){}
MessageId(RequestId const &_rrequid): index(_rrequid.index), unique(_rrequid.unique){}
bool isInvalid()const{
return index == InvalidIndex();
}
bool isValid()const{
return !isInvalid();
}
void clear(){
index = InvalidIndex();
unique = 0;
}
private:
friend class Service;
friend class Connection;
friend class MessageWriter;
friend struct ConnectionPoolStub;
friend std::ostream& operator<<(std::ostream &_ros, MessageId const &_msguid);
size_t index;
uint32_t unique;
MessageId(
const size_t _idx,
const uint32_t _uid
):index(_idx), unique(_uid){}
};
std::ostream& operator<<(std::ostream &_ros, MessageId const &_msguid);
class Service;
class Connection;
struct ConnectionContext{
Service& service()const{
return rservice;
}
ObjectIdT connectionId()const;
RecipientId recipientId()const;
const std::string& recipientName()const;
SocketDevice const & device()const;
bool isConnectionActive()const;
ulong messageFlags()const{
return message_flags;
}
MessageId const& localMessageId()const{
return message_id;
}
//! Keep any connection data
Any<>& any();
const ErrorConditionT& error() const;
const ErrorCodeT& systemError()const;
private:
//not used for now
RequestId const& requestId()const{
return request_id;
}
private:
friend class Connection;
friend class MessageWriter;
friend struct Message;
friend class TestEntryway;
Service &rservice;
Connection &rconnection;
ulong message_flags;
uint8_t message_state;
RequestId request_id;
MessageId message_id;
ConnectionContext(
Service &_rsrv, Connection &_rcon
):rservice(_rsrv), rconnection(_rcon), message_flags(0), message_state(0){}
ConnectionContext(ConnectionContext const&);
ConnectionContext& operator=(ConnectionContext const&);
};
}//namespace ipc
}//namespace frame
}//namespace solid
#endif