[omniORB] Does omniORB support smart proxies?
Tuyen Chau
tchau at verano.com
Tue Oct 10 18:48:00 BST 2006
Duncan Grisby wrote:
> You can register your own factories for proxy objects to do what you
> want. I'm afraid it's not documented, however, so you'll have to read
> the stub code to see how proxies are registered. You'll probably want to
> use the -Wbvirtual_objref flag to omniidl's C++ backend so you can
> override the object references' methods.
>
> Cheers,
>
> Duncan.
>
>
Many thanks to Duncan, I finally got the client proxies working.
To help the next person with the same question as mine, I thought I'd
write this up as a list of instructions you need to follow to create
your client proxies. Let's say you want to create proxies for Echo
interface, here are the steps you should follow,
1. Derive from the default proxy class, _objref_Echo. The tricky part
here is the constructor. You can't just assume the constructor of the
super class will do the right things for you by invoking it. You have
to copy the stub code, or your proxy class will not work and you will
get a nil pointer back at run time. So here's what the code should look
like,
class ProxyEcho : public virtual _objref_Echo {
public:
ProxyEcho(omniIOR* ior, omniIdentity* ident) :
omniObjRef(::Echo::_PD_repoId, ior, ident, 1),
_objref_Echo(ior, ident) {
_PR_setobj(this);
}
2. Derive from the default proxy object factory class, _pof_Echo and
override the newObjRef() function to instantiate your proxy class,
instead of the default proxy class. Here's what the code should look like,
class EchoProxyFactoryClass : public virtual _pof_Echo {
public:
virtual omniObjRef* newObjRef(omniIOR* ior, omniIdentity* ident) {
return new ProxyEcho(ior, ident, -1);
}
};
3. Create a new proxy object factory instance. The trick here is you
have to create it after the default one in the stub code gets created.
With Orbix, you can just create it by defining a global instance. With
omniORB, there's still a chance your global object gets instantiated
before the default one in the stubs, so you should create yours with the
"new" operator somewhere in your initialization, ie.
EchoProxyFactoryClass *myEchoProxyFactory = new EchoProxyFactoryClass();
4. Compile the IDL with -Wbvirtual_objref. This option declares all
object reference functions as virtual so your proxy class can override them.
5. If you compile your client code on Windows like I do, use -GR option
to the compiler to enable RTTI. This will allow you to use dynamic_cast
operator to convert a pointer to the default proxy class to a pointer to
your proxy class.
That's it. Enjoy your proxies!
More information about the omniORB-list
mailing list