[omniORB] IDL for callback-object
Stefan Seefeld
seefeld@sympatico.ca
Fri, 18 May 2001 09:12:57 -0400
henning.schmidt@philips.com wrote:
>I am trying to come up with an IDL for a CallbackObject with similar semantics to the VkCallbackObject. (see below)
>
That's not related to omniORB. You may want to post to comp.object.corba
for this kind of questions.
>
>Has anyone been able to come up with something clever that is generic enough so that I don't need to know the function to be called in the IDL where I define the rest of the Framework. I don't seem to be able to find a nice way to do what a pointer to
>object-function does in C++.
>
I don't think this is something IDL should be concerned about at all.
Just use an abstract factory and you
should be fine:
interface Callback
{
void execute(in Any a);
};
interface CallbackFactory
{
Callback foo_callback();
Callback bar_callback();
};
and then in the servant:
template <typename T>
class CallbackImpl : public virtual POA_Callback
{
typedef void (*T::method)();
public:
CallbackImpl(T *t, method m) : _t(t), _m(m) {}
void execute() { (t->*m)();}
private:
T *_t;
method _m;
};
class CallbackFactoryImpl : public virtual POA_CallbackFactory
{
Callback_ptr foo_callback()
{
Foo *foo = ...;
CallbackImpl<Foo> *callback = new CallbackImpl<Foo>(foo,
&foo::whatever);
return callback->_this();
}
// and so on...
};
a number of variations are possible based on the same theme, passing
parameters to the
factory methods that serve as discriminator to determine the exact
callback to instantiate.
Regards, Stefan