cannam@147
|
1 // Copyright (c) 2013-2014 Sandstorm Development Group, Inc. and contributors
|
cannam@147
|
2 // Licensed under the MIT License:
|
cannam@147
|
3 //
|
cannam@147
|
4 // Permission is hereby granted, free of charge, to any person obtaining a copy
|
cannam@147
|
5 // of this software and associated documentation files (the "Software"), to deal
|
cannam@147
|
6 // in the Software without restriction, including without limitation the rights
|
cannam@147
|
7 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
cannam@147
|
8 // copies of the Software, and to permit persons to whom the Software is
|
cannam@147
|
9 // furnished to do so, subject to the following conditions:
|
cannam@147
|
10 //
|
cannam@147
|
11 // The above copyright notice and this permission notice shall be included in
|
cannam@147
|
12 // all copies or substantial portions of the Software.
|
cannam@147
|
13 //
|
cannam@147
|
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
cannam@147
|
15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
cannam@147
|
16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
cannam@147
|
17 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
cannam@147
|
18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
cannam@147
|
19 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
cannam@147
|
20 // THE SOFTWARE.
|
cannam@147
|
21
|
cannam@147
|
22 // This file contains a bunch of internal declarations that must appear before rpc.h can start.
|
cannam@147
|
23 // We don't define these directly in rpc.h because it makes the file hard to read.
|
cannam@147
|
24
|
cannam@147
|
25 #ifndef CAPNP_RPC_PRELUDE_H_
|
cannam@147
|
26 #define CAPNP_RPC_PRELUDE_H_
|
cannam@147
|
27
|
cannam@147
|
28 #if defined(__GNUC__) && !defined(CAPNP_HEADER_WARNINGS)
|
cannam@147
|
29 #pragma GCC system_header
|
cannam@147
|
30 #endif
|
cannam@147
|
31
|
cannam@147
|
32 #include "capability.h"
|
cannam@147
|
33 #include "persistent.capnp.h"
|
cannam@147
|
34
|
cannam@147
|
35 namespace capnp {
|
cannam@147
|
36
|
cannam@147
|
37 class OutgoingRpcMessage;
|
cannam@147
|
38 class IncomingRpcMessage;
|
cannam@147
|
39
|
cannam@147
|
40 template <typename SturdyRefHostId>
|
cannam@147
|
41 class RpcSystem;
|
cannam@147
|
42
|
cannam@147
|
43 namespace _ { // private
|
cannam@147
|
44
|
cannam@147
|
45 class VatNetworkBase {
|
cannam@147
|
46 // Non-template version of VatNetwork. Ignore this class; see VatNetwork in rpc.h.
|
cannam@147
|
47
|
cannam@147
|
48 public:
|
cannam@147
|
49 class Connection;
|
cannam@147
|
50
|
cannam@147
|
51 struct ConnectionAndProvisionId {
|
cannam@147
|
52 kj::Own<Connection> connection;
|
cannam@147
|
53 kj::Own<OutgoingRpcMessage> firstMessage;
|
cannam@147
|
54 Orphan<AnyPointer> provisionId;
|
cannam@147
|
55 };
|
cannam@147
|
56
|
cannam@147
|
57 class Connection {
|
cannam@147
|
58 public:
|
cannam@147
|
59 virtual kj::Own<OutgoingRpcMessage> newOutgoingMessage(uint firstSegmentWordSize) = 0;
|
cannam@147
|
60 virtual kj::Promise<kj::Maybe<kj::Own<IncomingRpcMessage>>> receiveIncomingMessage() = 0;
|
cannam@147
|
61 virtual kj::Promise<void> shutdown() = 0;
|
cannam@147
|
62 virtual AnyStruct::Reader baseGetPeerVatId() = 0;
|
cannam@147
|
63 };
|
cannam@147
|
64 virtual kj::Maybe<kj::Own<Connection>> baseConnect(AnyStruct::Reader vatId) = 0;
|
cannam@147
|
65 virtual kj::Promise<kj::Own<Connection>> baseAccept() = 0;
|
cannam@147
|
66 };
|
cannam@147
|
67
|
cannam@147
|
68 class SturdyRefRestorerBase {
|
cannam@147
|
69 public:
|
cannam@147
|
70 virtual Capability::Client baseRestore(AnyPointer::Reader ref) = 0;
|
cannam@147
|
71 };
|
cannam@147
|
72
|
cannam@147
|
73 class BootstrapFactoryBase {
|
cannam@147
|
74 // Non-template version of BootstrapFactory. Ignore this class; see BootstrapFactory in rpc.h.
|
cannam@147
|
75 public:
|
cannam@147
|
76 virtual Capability::Client baseCreateFor(AnyStruct::Reader clientId) = 0;
|
cannam@147
|
77 };
|
cannam@147
|
78
|
cannam@147
|
79 class RpcSystemBase {
|
cannam@147
|
80 // Non-template version of RpcSystem. Ignore this class; see RpcSystem in rpc.h.
|
cannam@147
|
81
|
cannam@147
|
82 public:
|
cannam@147
|
83 RpcSystemBase(VatNetworkBase& network, kj::Maybe<Capability::Client> bootstrapInterface,
|
cannam@147
|
84 kj::Maybe<RealmGateway<>::Client> gateway);
|
cannam@147
|
85 RpcSystemBase(VatNetworkBase& network, BootstrapFactoryBase& bootstrapFactory,
|
cannam@147
|
86 kj::Maybe<RealmGateway<>::Client> gateway);
|
cannam@147
|
87 RpcSystemBase(VatNetworkBase& network, SturdyRefRestorerBase& restorer);
|
cannam@147
|
88 RpcSystemBase(RpcSystemBase&& other) noexcept;
|
cannam@147
|
89 ~RpcSystemBase() noexcept(false);
|
cannam@147
|
90
|
cannam@147
|
91 private:
|
cannam@147
|
92 class Impl;
|
cannam@147
|
93 kj::Own<Impl> impl;
|
cannam@147
|
94
|
cannam@147
|
95 Capability::Client baseBootstrap(AnyStruct::Reader vatId);
|
cannam@147
|
96 Capability::Client baseRestore(AnyStruct::Reader vatId, AnyPointer::Reader objectId);
|
cannam@147
|
97 void baseSetFlowLimit(size_t words);
|
cannam@147
|
98
|
cannam@147
|
99 template <typename>
|
cannam@147
|
100 friend class capnp::RpcSystem;
|
cannam@147
|
101 };
|
cannam@147
|
102
|
cannam@147
|
103 template <typename T> struct InternalRefFromRealmGateway_;
|
cannam@147
|
104 template <typename InternalRef, typename ExternalRef, typename InternalOwner,
|
cannam@147
|
105 typename ExternalOwner>
|
cannam@147
|
106 struct InternalRefFromRealmGateway_<RealmGateway<InternalRef, ExternalRef, InternalOwner,
|
cannam@147
|
107 ExternalOwner>> {
|
cannam@147
|
108 typedef InternalRef Type;
|
cannam@147
|
109 };
|
cannam@147
|
110 template <typename T>
|
cannam@147
|
111 using InternalRefFromRealmGateway = typename InternalRefFromRealmGateway_<T>::Type;
|
cannam@147
|
112 template <typename T>
|
cannam@147
|
113 using InternalRefFromRealmGatewayClient = InternalRefFromRealmGateway<typename T::Calls>;
|
cannam@147
|
114
|
cannam@147
|
115 template <typename T> struct ExternalRefFromRealmGateway_;
|
cannam@147
|
116 template <typename InternalRef, typename ExternalRef, typename InternalOwner,
|
cannam@147
|
117 typename ExternalOwner>
|
cannam@147
|
118 struct ExternalRefFromRealmGateway_<RealmGateway<InternalRef, ExternalRef, InternalOwner,
|
cannam@147
|
119 ExternalOwner>> {
|
cannam@147
|
120 typedef ExternalRef Type;
|
cannam@147
|
121 };
|
cannam@147
|
122 template <typename T>
|
cannam@147
|
123 using ExternalRefFromRealmGateway = typename ExternalRefFromRealmGateway_<T>::Type;
|
cannam@147
|
124 template <typename T>
|
cannam@147
|
125 using ExternalRefFromRealmGatewayClient = ExternalRefFromRealmGateway<typename T::Calls>;
|
cannam@147
|
126
|
cannam@147
|
127 } // namespace _ (private)
|
cannam@147
|
128 } // namespace capnp
|
cannam@147
|
129
|
cannam@147
|
130 #endif // CAPNP_RPC_PRELUDE_H_
|