-// Copyright (C) 2007-2014 CEA/DEN, EDF R&D
+// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
#include "SALOMESDS_Exception.hxx"
+#include "omniORB4/CORBA.h"
+
namespace SALOMESDS
{
+ class POAHolder : public virtual PortableServer::ServantBase
+ {
+ public:
+ virtual PortableServer::POA_var getPOA() const = 0;
+ CORBA::Object_var activate()
+ {
+ PortableServer::POA_var poa(getPOA());
+ PortableServer::ObjectId_var id(poa->activate_object(this));
+ CORBA::Object_var ret(poa->id_to_reference(id));
+ return ret;
+ }
+
+ void enforcedRelease()
+ {
+ PortableServer::POA_var poa(getPOA());
+ PortableServer::ObjectId_var oid(poa->servant_to_id(this));
+ poa->deactivate_object(oid);
+ _remove_ref();
+ }
+ };
+
template<class T>
class AutoRefCountPtr
{
ptr->incrRef();
return ret;
}
+
+ template<class T>// T is expected to be a POAHolder subclass
+ class AutoServantPtr
+ {
+ public:
+ AutoServantPtr(T *ptr=0):_ptr(ptr) { }
+ ~AutoServantPtr() { destroyPtr(); }
+ bool operator==(const AutoServantPtr& other) const { return _ptr==other._ptr; }
+ bool operator==(const T *other) const { return _ptr==other; }
+ AutoServantPtr &operator=(T *ptr) { if(_ptr!=ptr) { destroyPtr(); _ptr=ptr; } return *this; }
+ T *operator->() { return _ptr ; }
+ const T *operator->() const { return _ptr; }
+ T& operator*() { return *_ptr; }
+ const T& operator*() const { return *_ptr; }
+ operator T *() { return _ptr; }
+ operator const T *() const { return _ptr; }
+ private:
+ void destroyPtr()
+ {
+ if(!_ptr)
+ return;
+ _ptr->enforcedRelease();
+ }
+ private:
+ T *_ptr;
+ };
}
#endif