Back to index

salome-kernel  6.5.0
SALOME_GenericObj_i.cc
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  File   : SALOME_GenericObj_i.cc
00024 //  Author : Alexey PETROV, Open CASCADE S.A.S. (alexey.petrov@opencascade.com)
00025 
00026 #include "SALOME_GenericObj_i.hh"
00027 #include "utilities.h"
00028 
00029 #ifdef _DEBUG_
00030 static int MYDEBUG = 0;
00031 #else
00032 static int MYDEBUG = 0;
00033 #endif
00034 
00035 namespace SALOME
00036 {
00037 
00061   GenericObj_i::GenericObj_i(PortableServer::POA_ptr thePOA): myRefCounter(1)
00062   {
00063     if(MYDEBUG) 
00064       MESSAGE("GenericObj_i::GenericObj_i() - this = "<<this<<
00065              "; CORBA::is_nil(thePOA) = "<<CORBA::is_nil(thePOA));
00066     if(CORBA::is_nil(thePOA)) {
00067 #ifndef WIN32
00068       myPOA = PortableServer::ServantBase::_default_POA();
00069 #else
00070       myPOA = ServantBase::_default_POA();
00071 #endif
00072     }
00073     else {
00074       myPOA = PortableServer::POA::_duplicate(thePOA);
00075     }
00076   }
00077 
00086   PortableServer::POA_ptr GenericObj_i::_default_POA()
00087   {
00088     return PortableServer::POA::_duplicate(myPOA);
00089   }
00090 
00094   void GenericObj_i::Register()
00095   {
00096     if(MYDEBUG)
00097       MESSAGE("GenericObj_i::Register "<<this<<"; myRefCounter = "<<myRefCounter);
00098     ++myRefCounter;
00099   }
00100 
00107   void GenericObj_i::UnRegister()
00108   {
00109     if(MYDEBUG)
00110       MESSAGE("GenericObj_i::UnRegister "<<this<<"; myRefCounter = "<<myRefCounter);
00111     if(--myRefCounter <= 0){
00112       PortableServer::ObjectId_var anObjectId = myPOA->servant_to_id(this);
00113       myPOA->deactivate_object(anObjectId.in());
00114       _remove_ref();
00115     }
00116   }
00117 
00122   void GenericObj_i::Destroy()
00123   {
00124     MESSAGE("WARNING SALOME::GenericObj::Destroy() function is obsolete! Use UnRegister() instead.");
00125     UnRegister();
00126   }
00127 
00128 }; // end of namespace SALOME