Information
We are currently investigating an issue with the editor of some pages. Please save your work and avoid to create new pages until this banner is gone.
...
It is possible to use this approach both for stack and heap variables with the same restrictions:
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 | ||||||
---|---|---|---|---|---|---|
| ||||||
MyCBImpl cb;
ACS::OffShoot_var offshoot = getContainerServices().activateOffShoot(&cb);
examples::MyCallback_var cbObj = examples::MyCallback::_narrow(offshoot.in());
...
//Deactivate the Offshoot servant
getContainerServices().deactivateOffShoot(&cb); |
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 | ||||||
---|---|---|---|---|---|---|
| ||||||
MyCBImpl* cb = new MyCBImpl();
ACS::OffShoot_var offshoot = getContainerServices().activateOffShoot(cb);
examples::MyCallback_var cbObj = examples::MyCallback::_narrow(offshoot.in());
...
//Deactivate the Offshoot servant
getContainerServices().deactivateOffShoot(cb);
// Make sure to delete the OffShoot servant instance after deactivating the CORBA object
delete cb; |