Back to index

salome-med  6.5.0
MEDCouplingRefCountServant.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 #include "MEDCouplingRefCountServant.hxx"
00021 #include "InterpKernelException.hxx"
00022 #include "MEDCouplingRefCountObject.hxx"
00023 #include "MEDCouplingTimeLabel.hxx"
00024 
00025 #include <iostream>
00026 
00027 using namespace ParaMEDMEM;
00028 
00029 MEDCouplingRefCountServant::MEDCouplingRefCountServant(const RefCountObject *pointer, const TimeLabel *pointer2):_ref_counter(1),
00030                                                                                                                  _cpp_pointer(pointer),
00031                                                                                                                  _tl_pointer(pointer2)
00032 {
00033   if(_cpp_pointer)
00034     _cpp_pointer->incrRef();
00035   else
00036     throw INTERP_KERNEL::Exception("Null pointer not valid !");
00037 }
00038 
00039 MEDCouplingRefCountServant::~MEDCouplingRefCountServant()
00040 {
00041 }
00042 
00043 
00044 CORBA::Long MEDCouplingRefCountServant::getTimeLabel()
00045 {
00046   if(_tl_pointer)
00047     {
00048       _tl_pointer->updateTime();
00049       return _tl_pointer->getTimeOfThis();
00050     }
00051   return -1;
00052 }
00053 
00054 SALOME::StringSeq *MEDCouplingRefCountServant::GetExportableFormats()
00055 {
00056   SALOME::StringSeq *ret=new SALOME::StringSeq;
00057   ret->length(1);
00058   (*ret)[0]=CORBA::string_dup("MEDCorba");
00059   return ret;
00060 }
00061 
00062 void MEDCouplingRefCountServant::Register()
00063 {
00064   if(_cpp_pointer)
00065     _cpp_pointer->incrRef();
00066   _ref_counter++;
00067 }
00068 
00069 void MEDCouplingRefCountServant::UnRegister()
00070 {
00071   if(_cpp_pointer)
00072     ((RefCountObject *)_cpp_pointer)->decrRef();
00073   _ref_counter--;
00074   if(_ref_counter<=0)
00075     {
00076       if(_ref_counter<0)
00077         std::cerr << "Counter < 0 detected .... ???? " << std::endl;
00078       PortableServer::ObjectId_var oid = _default_POA()->servant_to_id(this);
00079       _default_POA()->deactivate_object(oid);
00080       _remove_ref();
00081     }
00082 }
00083 
00084 void MEDCouplingRefCountServant::Destroy()
00085 {
00086   std::cerr << "WARNING SALOME::GenericObj::Destroy() function is obsolete! Use UnRegister() instead." << std::endl;
00087   UnRegister();
00088 }