[omniORB] How to handle making copies of CORBA object.

Mark Johnson mark.johnson@onfiber.com
Thu, 30 Aug 2001 09:01:06 -0500


I have defined two interfaces Event and Controller.  The Controller has a
method called EventNotify( Event_ptr ).  In that method, I create a thread
to process the event, but I need to make a copy of the event since the
sender might no longer be available after sending the event.  

I tried dong the following:
   void Controller_i::EventNotify( Event_ptr aEvent )
   {
      omni_thread::create( theThreadFunc, (void*)Event::duplicate(aEvent),
omni_thread::PRIORITY_HIGH );
   }
But if the caller of controller->EventNotify() runs its course and exits,
the callee will core dump.  


However, if I change Event to a struct and new the event everything works
great event if the caller exits:
   void Controller_i::EventNotify( const Event& aEvent )
   {
      Event * event = new Event;
      CopyEvent( event, aEvent );
      omni_thread::create( theThreadFunc, (void*)event,
omni_thread::PRIORITY_HIGH );
   }

Which is the correct way of doing this.  Is it possible to create a copy of
the Event interface such that when the servant exits the objects recieved at
the client are still valid?  I would expect that I should have to use an
Event_var to take advantage of the reference counting, but the idl compiler
generated an Event_ptr for EventNotify().  I'm sure that somewhere between
the invokation of EventNotify() and the spawning of the thread I need to
create an Event_var but I don't understand the process of how to do that.

thanks for your help....