robotology-playground / paramHelp

Classes for simplifying the management of the parameters of YARP modules.
0 stars 1 forks source link

RPC setters and getters #2

Open francesco-romano opened 10 years ago

francesco-romano commented 10 years ago

During the last weeks I have been thinking about the new implementation of the parameters setting and getting through RPC. In my opinion the most flexible way (and also safest) is through the definition of real setters and getters instead of accessing directly the memory of an object. Unfortunately C++ does not offer native support to dynamic object creations...but here is where thrift comes into play. I am thinking of something similar to Objective C 2.0 properties. We can define in thrift a new ''command'' property which takes the type of variable and some attributes and it generates automatically setters and getters. This methods are (public) virtual thus allowing overriding by the derived classes in case the user wants to implement a more sophisticated behaviour.

So this is just a sketch... I use a vector as an example even if there are some issues still open.

property (nonatomic) Eigen::VectorXd myVariable

It generates a couple of accessor methods:

Eigen::VectorXd myVariable();
void setMyVariable(Eigen::VectorXd myVariable);

And a variable named a_myVariable (a_ stands for automatic.. just an idea)

We can use the attributes to customize the generation of the methods. I thought about the following attributes:

About the issue I was mentioning before: object construction. If (and I would like to do this) we add automatically creation of instance variables we should also call a constructor for them. Which constructor we should call? (for example Eigen::VectorXd has an empty constructor, but to be completely automatic we should call its constructor with the size of the vector specified).

@traversaro @lornat75

traversaro commented 10 years ago

+100

lornat75 commented 10 years ago

Thanks Francesco for thinking about this. I think it is in a good direction.

For object allocation. Another possibility could be to let the user allocate memory and then link them with specific methods. E.g.

Thirft could generate:

void setMyVariable(Eigen::VectorXd myVariable);

and

void bindMyVariable(Eigen::VectorXd *myVariable);

The user would then allocate

Eigen::VectorXd myVariable;

and bind it with the proxy that handles the rpc:

void proxy.bindMyVariable(&myVariable);

But we still have to decided if we want thirft to pass default initializers to objects, in this case allocation would have to be inside the proxy.