62 Rpc

RpcCaller

RpcCaller is implemented by the cxRpc framework in order to support a stub of type ptr<I> for recording method calls for a certain interface I.


$adt+ RpcCaller final
{
    void Close();
    void GetBuffer(xvector& buffer);
    AnyInterface GetStub();
};


AnyInterface GetStub()

Retrieves the stub to be used to record method invocations. This untyped interface pointer can be used to initialise a ptr<I> where I is the interface for which the RpcCaller was created.

Free functions


RpcCaller* CreateRpcCaller(ConstStringZ qualifiedInterfaceName)

Create an RpcCaller allowing for recording invocations on a stub that implements the interface with the given fully qualified name.

The RpcCaller must be closed when it is no longer needed.

Returns nullptr if no stub factory with the given qualified name has been registered.


template <typename I> RpcCaller* CreateRpcCaller()

Create an RpcCaller for the given interface.


template <typename I> ptr<I> GetStub(RpcCaller* c)

Create a stub for the given interface from the given RpcCaller.

RpcCallee


$adt+ RpcCallee final
{
    void Close();
    bool PlayMessages(const void* buffer, ssize_t size);
};


bool PlayMessages(const void* buffer, ssize_t size)

Deserialise and invoke all the recorded method invocations in the given buffer of the given size. The implementation tends to emphasises performance over safety, this function should not be used if the buffer might be erroneous. In some limited cases an error causes this function to return false - e.g. if an invalid method index was read from the buffer

Free functions


RpcCallee* CreateRpcCallee(ConstStringZ qualifiedInterfaceName, AnyInterface receiver)

Create an RpcCallee allowing for incoming messages of an interface with the given fully qualified name to be forwarded onto receiver. The RpcCallee must be closed when it is no longer needed. Returns nullptr if no skeleton factory with the given qualified name has been registered.

Rpc.h

todo: Split this into RpcCaller.h and RpcCallee.h

// Rpc.h
//
// Author David Barrett-Lennard
// (C)opyright Cedanet Pty Ltd 2020

@import "cxRpc.h"
@import "Stub.h"
@import "Skeleton.h"
@import "Ceda/cxObject/Object.h"
#include "Ceda/cxUtils/IException.h"

namespace ceda
{
///////////////////////////////////////////////////////////////////////////////////////////////////
// RpcCaller

$adt+ RpcCaller final
{
    void Close();
    void GetBuffer(xvector<uint8>& buffer);
    AnyInterface GetStub();
};

@api RpcCaller* CreateRpcCaller(ConstStringZ qualifiedInterfaceName);

template <typename I>
RpcCaller* CreateRpcCaller()
{
    return CreateRpcCaller(GetIpcInterfaceName<I>());
}

template <typename I>
ptr<I> GetStub(RpcCaller* c)
{
    cxAssert(c != nullptr);
    AnyInterface a = GetStub(c);
    return ptr<I>(a.m_self, a.m_table);
}

///////////////////////////////////////////////////////////////////////////////////////////////////
// RpcCallee

$adt+ RpcCallee final
{
    void Close();
    bool PlayMessages(const void* buffer, ssize_t size);
};

@api RpcCallee* CreateRpcCallee(
    ConstStringZ qualifiedInterfaceName,    // Interface implemented by 'receiver'
    AnyInterface receiver);                 // Must implement interface ri.  Must not be null.

template <typename I>
RpcCallee* CreateRpcCallee(ptr<I> receiver)
{
    return CreateRpcCallee(GetIpcInterfaceName<I>(), receiver);
}

} // namespace ceda