Turi Create
4.0
|
(If you have not seen the CPPIPC Basic Concepts section, you should. we will continue extending the basic_counter object defined in the previous section.)
Now, while the CPPIPC system is kind of nice for basic stuff, what should be done in situations when I need to define a function which takes another remote object as input (For instance, say I want to add two basic counters together)? Or how do I create functions which return new remote objects ( for instance, if I want to "clone" a counter) ?
To handle this case, we perform some magic which are explained in in the Technical Details page. But in short, you simply pass and return pointers to objects.
For instance, to implement a "clone" function, we simply extend the interface with a clone function that returns a new base object (it must be a base, since to the server, it is an implementation object, and to the client, it is a proxy object)
On the server-side, we implement the clone() function. This just creates a new basic_counter object, and returns it. The returned object will automatically be registered and managed by the comm_server.
Now, to use this function on the client side,
To take remote objects as arguments is similar. Here, we add a new "add_counter" function which adds the value of another counter to the current counter. Once again, it must take a pointer to base as the argument.
While on the client side, the function is called with a pointer to a proxy object, it is resurrected as a pointer to an implementation object on the server side.
Now, to use this function on the client side,