views:

69

answers:

1

Here's the task: Imagine, we have an applications and a plug-in for it (dynamic library). Interface between the application and the plug-in is completely defined. Now I need to run the application and the plug-in on different computers. I wrote a stub for the plug-in on a computer where the real applications is running. And the application loads it and calls its functions like if it were a native plug-in. On the other computer there's a stub instead of the real application, which loads the native plug-in. Now I need to organize RPCs between my stubs over the network, regardless the very transport. Usually, it's not difficult. But there're some restrictions:

  1. Application-plug-in interaction can be reenterable (e.g. application calls f1() from plug-in, in f1() plug-in calls g1() from application, in g1() application calls f2() from plug-in and so on...)
  2. Any such reenteration should be executed exactly by the same thread, which started the sequence

Where can I find a cross-platform C++ RPC library with such features?

A: 

Restriction #1 is perfectly reasonable, so long as none of the functions on either machine do anything like locking a mutex across an RPC.

I'm not entirely sure #2 is possible -- let's assume that your calls are blocking; when g1() calls f2(), the RPC mechanism can't execute f2() on the same thread as f1(), as f1() is blocked indirectly waiting on its result!

If your calls are instead asynchronous, it is possible to poll the RPC system while waiting for f1() to complete, and have it execute f2() in the same thread. You shouldn't do this, though; it means that any async call waiting for an RPC completion can suddenly "block" when the invoked RPC is pushed onto the callstack.

Is there a specific reason you want this behaviour?

In any case, Googling "cross platform rpc" comes up with quite a few results; I imagine any of them would fit your bill if you ignore the second restriction. XML-RPC was one of the top results, and there are a number of C++ implementations:

http://www.xmlrpc.com/directory/1568/implementations

EDIT: After some Googling I can't find a single library that does precisely what you're asking. They all appear to be either blocking or asynchronous multithreaded. If you really need to implement restriction #2, you're going to have to do it by hand. Use of boost::asio would be a good starting point for cross-platform communication. I still don't see the difference between what you want to do and calling the handler function in a second thread while the first one is blocking, however...

Blair Holloway
Of course, I understand that the major problem will be with the second restriction. And I really need it be conformed. AFAIK, the DCOM technology implements that in its STA mechanism.The first thread, which has been blocked waiting for g1(), can be woken up to process a new request of f2() and then return to waiting.
iUm
For example, Netscape plug-ins work with browsers only on the main thread. So if I use them for my purposes, I had to conform the second restriction. Netscape plug-in API is not alone in the programming world...
iUm
Fair point. Still, I haven't been able to find a library that matches this requirement. Much as it's better to take an off-the-shelf solution, it may be better to roll your own here.
Blair Holloway