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