capnproto

FORK: Cap'n Proto serialization/RPC system - core tools and C++ library
git clone https://git.neptards.moe/neptards/capnproto.git
Log | Files | Refs | README | LICENSE

rpc-prelude.h (3705B)


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