Chris@47: // Copyright (c) 2013-2014 Sandstorm Development Group, Inc. and contributors Chris@47: // Licensed under the MIT License: Chris@47: // Chris@47: // Permission is hereby granted, free of charge, to any person obtaining a copy Chris@47: // of this software and associated documentation files (the "Software"), to deal Chris@47: // in the Software without restriction, including without limitation the rights Chris@47: // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell Chris@47: // copies of the Software, and to permit persons to whom the Software is Chris@47: // furnished to do so, subject to the following conditions: Chris@47: // Chris@47: // The above copyright notice and this permission notice shall be included in Chris@47: // all copies or substantial portions of the Software. Chris@47: // Chris@47: // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR Chris@47: // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, Chris@47: // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE Chris@47: // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER Chris@47: // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, Chris@47: // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN Chris@47: // THE SOFTWARE. Chris@47: Chris@47: // This file contains a bunch of internal declarations that must appear before rpc.h can start. Chris@47: // We don't define these directly in rpc.h because it makes the file hard to read. Chris@47: Chris@47: #ifndef CAPNP_RPC_PRELUDE_H_ Chris@47: #define CAPNP_RPC_PRELUDE_H_ Chris@47: Chris@47: #if defined(__GNUC__) && !defined(CAPNP_HEADER_WARNINGS) Chris@47: #pragma GCC system_header Chris@47: #endif Chris@47: Chris@47: #include "capability.h" Chris@47: #include "persistent.capnp.h" Chris@47: Chris@47: namespace capnp { Chris@47: Chris@47: class OutgoingRpcMessage; Chris@47: class IncomingRpcMessage; Chris@47: Chris@47: template Chris@47: class RpcSystem; Chris@47: Chris@47: namespace _ { // private Chris@47: Chris@47: class VatNetworkBase { Chris@47: // Non-template version of VatNetwork. Ignore this class; see VatNetwork in rpc.h. Chris@47: Chris@47: public: Chris@47: class Connection; Chris@47: Chris@47: struct ConnectionAndProvisionId { Chris@47: kj::Own connection; Chris@47: kj::Own firstMessage; Chris@47: Orphan provisionId; Chris@47: }; Chris@47: Chris@47: class Connection { Chris@47: public: Chris@47: virtual kj::Own newOutgoingMessage(uint firstSegmentWordSize) = 0; Chris@47: virtual kj::Promise>> receiveIncomingMessage() = 0; Chris@47: virtual kj::Promise shutdown() = 0; Chris@47: virtual AnyStruct::Reader baseGetPeerVatId() = 0; Chris@47: }; Chris@47: virtual kj::Maybe> baseConnect(AnyStruct::Reader vatId) = 0; Chris@47: virtual kj::Promise> baseAccept() = 0; Chris@47: }; Chris@47: Chris@47: class SturdyRefRestorerBase { Chris@47: public: Chris@47: virtual Capability::Client baseRestore(AnyPointer::Reader ref) = 0; Chris@47: }; Chris@47: Chris@47: class BootstrapFactoryBase { Chris@47: // Non-template version of BootstrapFactory. Ignore this class; see BootstrapFactory in rpc.h. Chris@47: public: Chris@47: virtual Capability::Client baseCreateFor(AnyStruct::Reader clientId) = 0; Chris@47: }; Chris@47: Chris@47: class RpcSystemBase { Chris@47: // Non-template version of RpcSystem. Ignore this class; see RpcSystem in rpc.h. Chris@47: Chris@47: public: Chris@47: RpcSystemBase(VatNetworkBase& network, kj::Maybe bootstrapInterface, Chris@47: kj::Maybe::Client> gateway); Chris@47: RpcSystemBase(VatNetworkBase& network, BootstrapFactoryBase& bootstrapFactory, Chris@47: kj::Maybe::Client> gateway); Chris@47: RpcSystemBase(VatNetworkBase& network, SturdyRefRestorerBase& restorer); Chris@47: RpcSystemBase(RpcSystemBase&& other) noexcept; Chris@47: ~RpcSystemBase() noexcept(false); Chris@47: Chris@47: private: Chris@47: class Impl; Chris@47: kj::Own impl; Chris@47: Chris@47: Capability::Client baseBootstrap(AnyStruct::Reader vatId); Chris@47: Capability::Client baseRestore(AnyStruct::Reader vatId, AnyPointer::Reader objectId); Chris@47: void baseSetFlowLimit(size_t words); Chris@47: Chris@47: template Chris@47: friend class capnp::RpcSystem; Chris@47: }; Chris@47: Chris@47: template struct InternalRefFromRealmGateway_; Chris@47: template Chris@47: struct InternalRefFromRealmGateway_> { Chris@47: typedef InternalRef Type; Chris@47: }; Chris@47: template Chris@47: using InternalRefFromRealmGateway = typename InternalRefFromRealmGateway_::Type; Chris@47: template Chris@47: using InternalRefFromRealmGatewayClient = InternalRefFromRealmGateway; Chris@47: Chris@47: template struct ExternalRefFromRealmGateway_; Chris@47: template Chris@47: struct ExternalRefFromRealmGateway_> { Chris@47: typedef ExternalRef Type; Chris@47: }; Chris@47: template Chris@47: using ExternalRefFromRealmGateway = typename ExternalRefFromRealmGateway_::Type; Chris@47: template Chris@47: using ExternalRefFromRealmGatewayClient = ExternalRefFromRealmGateway; Chris@47: Chris@47: } // namespace _ (private) Chris@47: } // namespace capnp Chris@47: Chris@47: #endif // CAPNP_RPC_PRELUDE_H_