[omniORB] Implementing multiple interfaces in one servant

Duncan Grisby dgrisby@uk.research.att.com
Tue, 19 Sep 2000 11:48:04 +0100


On Monday 18 September, Chris Newbold wrote:

> I have a servant which I'd like to use to implement two unrelated
> interfaces. My first attempt went something like this:

You cannot do this with the inheritance approach. The C++ mapping
specification specifically prohibits it. You might be able to use ties
to do what you want, but I suspect that what you really want is Gary's
suggestion of declaring an interface which derived from the two
interfaces.

The reason that ties are probably not what you want is that if you
declare:

  interface A { void a_op(); };
  interface B { void b_op(); };

and then write an implementation class

  class A_and_B_i {
  public:
    void a_op() { ... }
    void b_op() { ... }
  };

You can now use a tie to create an object reference:

  A_and_B_i* impl = new A_and_B_i;
  POA_A_tie<A_and_B_i> servant(impl);
  A_ptr a_obj = servant._this()

But you cannot narrow the object reference to a B:

  B_ptr b_obj = B::_narrow(a_obj);  // Returns nil


Given that you can't have an object supporting more than one interface
at a time, there isn't much point to implementing more than one
interface in a servant class.


> 	omniORB: Assertion failed.  This indicates a bug in omniORB.

Hmm. omniORB is being a bit over-keen to blame itself. :-)

Cheers,

Duncan.

-- 
 -- Duncan Grisby  \  Research Engineer  --
  -- AT&T Laboratories Cambridge          --
   -- http://www.uk.research.att.com/~dpg1 --