Download ORBACUS, this manual

Transcript
CORBA Objects
5.3.1
Creating Servants using C++
Here is how to create servants using C++:
1 // C++
2 I_impl* servant_pointer = new I_impl;
3 I_impl* another_servant_pointer = new I_impl;
2,3
Two servants are created with new. Note that this merely instantiates the servants but does
not inform the ORB that these servants exist yet. The ORB server-side run time only
learns of the existence of the servants once you activate them.
In case the servant class was written using the delegation approach, an object of the class
implementing I’s operations must be passed to the servant’s constructor:
1 // C++
2 I_impl_tie* impl = new I_impl_tie;
3 POA_I_tie< I_impl_tie >* tie_pointer =
4
new POA_I_tie< I_impl_tie >(impl, 1);
2
3,4
A new I_impl_tie is created with new.
An instance of POA_I_tie parameterized with I_impl_tie is created, taking impl as a
parameter. All operation calls to tie will then be delegated to impl.
In this example, the lifetime of impl is coupled to the lifetime of the servant tie. That is,
when the tie is destroyed, delete impl is called by the tie’s destructor. In case you don’t
want the lifetime of impl to be coupled to the lifetime of the tie, for example, because you
want to create a servant on the stack and not on the heap (making it illegal to call delete
on the tie), use the following code:
1 // C++
2 I_impl_tie impl;
3 POA_I_tie< I_impl_tie >* tie =
4
new POA_I_tie< I_impl_tie >(&impl, 0);
2
3,4
A new I_impl_tie is created, this time on the stack, not on the heap.
An instance of POA_I_tie is created. The 0 parameter tells tie not to call delete on
impl.
1. You can also instantiate servants on the stack. However, this only works only for some POA policies, so servants are usually instantiated on the heap.
84
ORBacus