dschatz
dschatz

Reputation: 1218

Lightweight Reflection in C++

I have a distributed c++ application and one machine wants the other machine to invoke a specific function on a specific object. The sender knows the type of the object and the pointer of it on the receiver. I can send a member function pointer to the receiver but I'm not sure how to send the type to enable a cast of the this pointer to the appropriate type.

Ideally the mapping could be done statically (is there a way using boost::mpl and boost::variant)? I know the set of types that could be invoked at compile time (both machines run the exact same binary as well). Also the signature of the function is fixed (let's say it returns void and takes an int always, regardless of type).

Upvotes: 0

Views: 719

Answers (2)

Asaf
Asaf

Reputation: 4407

As said in the comments, you can use RPC (remote procedure call) for that.

The idea is to define a protocol for which both sides agree how a call, parameters and return values are represented over the network.

Depending on your environment, you can choose an existing RPC library (see a list in the wiki article linked), or write something simple on your own while using existing serialization and communication modules (see for example google protobufs, or boost asio).

Upvotes: 3

Yury Schkatula
Yury Schkatula

Reputation: 5369

COM remote activation seems to be pretty good for that. The only possible issue is security restrictions on a given network.

Upvotes: -1

Related Questions