Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. Manual activation/deactivation of the CORBA object
  2. Manual activation with automatic deactivation of the CORBA object through the POA cleanup process

Manual OffShoot activation/deactivation

This approach is valid both for stack and heap instances of an OffShoot:

Stack OffShoot

For the OffShoot servant instance on the stack, you need to make sure to deactivate the OffShoot servant before cb variable goes out of scope. Here you will get compilation issues if you try to deactivate it after going out of scope.

Code Block
languagecpp
linenumberstrue
collapsetrue
MyCBImpl cb;
examples::MyCallback_var cbObj = cb._this();
...
//Deactivate the Offshoot servant
PortableServer::POA_var poa = cb._default_POA();
PortableServer::ObjectId_var id = poa->servant_to_id(&cb);
poa->deactivate_object(id.in());
Heap OffShoot

For the OffShoot servant instance on the heap, you need to make sure to deactivate the OffShoot servant before destroying the cb variable. Doing it in the reverse order has undefined behavior, usually ending in segmentation fault.

Code Block
languagecpp
linenumberstrue
collapsetrue
MyCBImpl* cb = new MyCBImpl();
examples::MyCallback_var cbObj = cb->_this();
...
//Deactivate the Offshoot servant
PortableServer::POA_var poa = cb->_default_POA();
PortableServer::ObjectId_var id = poa->servant_to_id(cb);
poa->deactivate_object(id.in());

// Make sure to delete the OffShoot servant instance after deactivating the CORBA object
delete cb;

Manual OffShoot activation with automatic deactivation

This approach is valid both for stack and heap instances of an OffShoot:

Stack OffShoot

For the OffShoot servant instance on the stack, you need to make sure ORB is stopped before cb variable goes out of scope. The variable going out of scope before stopping the ORB is undefined behavior resulting in segmentation fault in most implementations due to trying to access a memory address in a different stack.

Code Block
languagecpp
linenumberstrue
collapsetrue
{
    MyCBImpl cb;
    examples::MyCallback_var cbObj = cb._this();
    ...
    // Stop ORB
    ...
}
Heap OffShoot

For the OffShoot servant instance on the heap, you need to make sure to delete the OffShoot servant instance after ORB is stopped. If the variable is deleted before stopping the ORB has undefined behavior, regularly resulting in segmentation fault due to using a destroyed instance.

Code Block
languagecpp
linenumberstrue
collapsetrue
MyCBImpl* cb = new MyCBImpl();
examples::MyCallback_var cbObj = cb->_this();
...
// Stop ORB
... 
// Delete the heap OffShoot servant instance
delete cb;

Component Client

When working with standalone clients, we need to handle the servant lifecycle of the offshoots/callbacks. There are three approaches:

  1. Manual activation/deactivation of the CORBA object
  2. Manual activation with automatic deactivation of the CORBA object through the POA cleanup process
  3. Manual activation/deactivation of the CORBA object through the container services