Salome HOME
updated copyright message
[modules/med.git] / src / MEDCouplingCorba / MEDCouplingRefCountServant.cxx
1 // Copyright (C) 2007-2023  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Author : Anthony Geay (CEA/DEN)
20
21 #include "MEDCouplingRefCountServant.hxx"
22 #include "InterpKernelException.hxx"
23 #include "MEDCouplingRefCountObject.hxx"
24 #include "MEDCouplingTimeLabel.hxx"
25
26 #include <iostream>
27
28 using namespace MEDCoupling;
29
30 MEDCouplingRefCountServant::MEDCouplingRefCountServant(const RefCountObject *pointer, const TimeLabel *pointer2):_ref_counter(1),
31                                                                                                                  _cpp_pointer(pointer),
32                                                                                                                  _tl_pointer(pointer2)
33 {
34   if(_cpp_pointer)
35     _cpp_pointer->incrRef();
36   else
37     throw INTERP_KERNEL::Exception("Null pointer not valid !");
38 }
39
40 MEDCouplingRefCountServant::~MEDCouplingRefCountServant()
41 {
42 }
43
44
45 CORBA::Long MEDCouplingRefCountServant::getTimeLabel()
46 {
47   if(_tl_pointer)
48     {
49       _tl_pointer->updateTime();
50       return _tl_pointer->getTimeOfThis();
51     }
52   return -1;
53 }
54
55 char *MEDCouplingRefCountServant::versionStr()
56 {
57   return CORBA::string_dup(MEDCouplingVersionStr());
58 }
59
60 void MEDCouplingRefCountServant::versionMajMinRel(CORBA::Long_out maj, CORBA::Long_out minor, CORBA::Long_out releas)
61 {
62   int _maj,_minor,_releas;
63   MEDCouplingVersionMajMinRel(_maj,_minor,_releas);
64   maj = _maj;
65   minor = _minor;
66   releas = _releas;
67 }
68
69 SALOME::StringSeq *MEDCouplingRefCountServant::GetExportableFormats()
70 {
71   SALOME::StringSeq *ret=new SALOME::StringSeq;
72   ret->length(1);
73   (*ret)[0]=CORBA::string_dup("MEDCorba");
74   return ret;
75 }
76
77 void MEDCouplingRefCountServant::Register()
78 {
79   if(_cpp_pointer)
80     _cpp_pointer->incrRef();
81   _ref_counter++;
82 }
83
84 void MEDCouplingRefCountServant::UnRegister()
85 {
86   if(_cpp_pointer)
87     const_cast<RefCountObject *>(_cpp_pointer)->decrRef();
88   _ref_counter--;
89   if(_ref_counter<=0)
90     {
91       if(_ref_counter<0)
92         std::cerr << "Counter < 0 detected .... ???? " << std::endl;
93       PortableServer::ObjectId_var oid = _default_POA()->servant_to_id(this);
94       _default_POA()->deactivate_object(oid);
95       _remove_ref();
96     }
97 }
98
99 void MEDCouplingRefCountServant::Destroy()
100 {
101   std::cerr << "WARNING SALOME::GenericObj::Destroy() function is obsolete! Use UnRegister() instead." << std::endl;
102   UnRegister();
103 }