[omniORB] how to identify when client gets disconnected from server?

Vladimir Panov gbr@netel.bg
Wed Oct 9 12:52:00 2002


Sveta Shasharina wrote:

>Hi,
>
>I am very interested in controlling the lifecycle of the objects
>from the client side.  I would like to be able to send a signal 
>from a client and tell the server to kill the objects and itself.
>In orbacus, we used EventHandler and Reactor API for that (I think).
>Is there anything similar in omniORB?  I could not find
>info on installing handlers in the documentation.
>
>Thanks,
>
>Sveta Shasharina
>
>  
>
It can be done this simple way (it is C++ mapping specific and portable 
between ORBs):

// Base is an IDL interface, it may have a single method die() using 
which the client may instruct the servant to destroy itself.
class Base_i : public virtual BasePOA
{

// the following variable must be initialized before constructing the 
first servant
static PortableServer::POA_var poa;

CORBA::ULong refCount;
PortableServer::ObjectId_var objID;

protected:

// automatically activates the servant
Base_i(void)
{
this->refCount = 1;
this->objID = Base_i::poa->activate_object(this);
// upon activation, the POA calls _add_ref() once
_remove_ref();
}

public:

virtual ~Base_i(void)
{
}

virtual void _add_ref(void)
{
this->refCount++;
}

virtual void _remove_ref(void)
{
if (this->refCount == 1)
{
this->refCount--;
// after the servant is deactivated, the POA will call _remove_ref() 
once again (see below)
Base_i::poa->deactivate_object((const 
PortableServer::ObjectId_var)this->objID);
}
else if (this->refCount == 0)
delete this;
else
this->refCount--;
}

// this may be called remotely (i.e. it is a method of the Base IDL 
interface)
virtual void die(void)
{
_remove_ref();
}
};