Turi Create  4.0
cppipc::object_proxy< T > Class Template Reference

#include <core/system/cppipc/client/object_proxy.hpp>

Public Member Functions

 object_proxy (comm_client &comm, bool auto_create=true, size_t object_id=(size_t)(-1))
 
void remote_delete ()
 
void set_object_id (size_t object_id)
 
size_t get_object_id () const
 
comm_clientget_comm ()
 
template<typename S >
void register_object (S *object)
 
template<typename MemFn >
void register_function (MemFn f, std::string function_string)
 
template<typename MemFn , typename... Args>
detail::member_function_return_type< MemFn >::type call (MemFn f, const Args &... args)
 

Detailed Description

template<typename T>
class cppipc::object_proxy< T >

Refers to a remote object and allows function calls to be issued across a communication link.

The object_proxy object internally maintains an object ID which identifies an object on the other side of a communication link established by the comm_client. The object_proxy is templatized over a type T which must have an identical object interface as the remote object. T must also provide the registration callbacks which match the registration callbacks on the remote end. For that reason, it is easiest if T defines an interface and implements the register callbacks. And the remote object then inherits from T.

The recommended pattern is as follows: Given the following base class with an implementation on the server side

class object_base {
public:
virtual ~object_base() { }
virtual int add(int, int) = 0;
};

We implement a proxy object which has the object_proxy as a member, and inherits from the object_base. Each function call is then forwarded to the remote machine.

class object_proxy: public object_base {
public:
// proxy must be provided with the comm_client object on construction
test_object_proxy(cppipc::comm_client& comm):proxy(comm){ }
int add(int a, int b) {
// forward the call to the remote machine
return proxy.call(&object_base::add,a, b);
}
};

Definition at line 58 of file object_proxy.hpp.

Constructor & Destructor Documentation

◆ object_proxy()

template<typename T>
cppipc::object_proxy< T >::object_proxy ( comm_client comm,
bool  auto_create = true,
size_t  object_id = (size_t)(-1) 
)
inline

Creates an object_proxy object using the communication client provided for communication. If auto_create is set to true, a new remote object is created on the remote machine. Otherwise, no remote object ID is specified, and set_object_id() must be called to set the remote object ID.

Parameters
commThe comm client object to use for communication
auto_createIf true, will create the remote object on construction of the object proxy.
object_idThe object ID to use in the proxy. Only valid when auto_create is false.

Definition at line 72 of file object_proxy.hpp.

Member Function Documentation

◆ call()

template<typename T>
template<typename MemFn , typename... Args>
detail::member_function_return_type<MemFn>::type cppipc::object_proxy< T >::call ( MemFn  f,
const Args &...  args 
)
inline

Calls a remote function returning the result. The remote function's return is forwarded and returned here. An exception is raised of type reply_status if there is an error.

Definition at line 149 of file object_proxy.hpp.

◆ get_comm()

template<typename T>
comm_client& cppipc::object_proxy< T >::get_comm ( )
inline

Returns a reference to the communication object used.

Definition at line 123 of file object_proxy.hpp.

◆ get_object_id()

template<typename T>
size_t cppipc::object_proxy< T >::get_object_id ( ) const
inline

Gets the object ID managed by this proxy.

Definition at line 116 of file object_proxy.hpp.

◆ register_function()

template<typename T>
template<typename MemFn >
void cppipc::object_proxy< T >::register_function ( MemFn  f,
std::string  function_string 
)
inline

do not use Registers a member function of T, associating it with a string name

Definition at line 138 of file object_proxy.hpp.

◆ register_object()

template<typename T>
template<typename S >
void cppipc::object_proxy< T >::register_object ( S *  object)
inline

do not use

Definition at line 129 of file object_proxy.hpp.

◆ remote_delete()

template<typename T>
void cppipc::object_proxy< T >::remote_delete ( )
inline

Deletes the remote object referred to by this proxy. The object ID in the proxy will be cleared.

Definition at line 98 of file object_proxy.hpp.

◆ set_object_id()

template<typename T>
void cppipc::object_proxy< T >::set_object_id ( size_t  object_id)
inline

Assigns the object ID managed by this proxy.

Definition at line 108 of file object_proxy.hpp.


The documentation for this class was generated from the following file: