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