Salome HOME
PR: merge from branch BR_UnitTests tag mergeto_trunk_17oct05
[modules/yacs.git] / src / SALOMEDS / SALOMEDS_GenericAttribute.cxx
1 //  File   : SALOMEDS_GenericAttribute.cxx
2 //  Author : Sergey RUIN
3 //  Module : SALOME
4
5
6
7 #include <string>
8 #include <TCollection_AsciiString.hxx> 
9
10 #include "SALOMEDS_GenericAttribute.hxx"
11 #include "SALOMEDSImpl_SObject.hxx"
12 #include "SALOMEDS_SObject.hxx"
13 #include "SALOMEDS_ClientAttributes.hxx"
14
15 #ifdef WIN32
16 #include <process.h>
17 #else
18 #include <sys/types.h>
19 #include <unistd.h>
20 #endif
21
22 #include "OpUtil.hxx"
23
24 using namespace std; 
25
26 SALOMEDS_GenericAttribute::SALOMEDS_GenericAttribute(const Handle(SALOMEDSImpl_GenericAttribute)& theGA)
27 {
28   _isLocal = true;
29   _local_impl = theGA;
30   _corba_impl = SALOMEDS::GenericAttribute::_nil();
31 }
32
33 SALOMEDS_GenericAttribute::SALOMEDS_GenericAttribute(SALOMEDS::GenericAttribute_ptr theGA)
34 {
35 #ifdef WIN32
36   long pid =  (long)_getpid();
37 #else
38   long pid =  (long)getpid();
39 #endif  
40
41   long addr = theGA->GetLocalImpl(GetHostname().c_str(), pid, _isLocal);
42   if(_isLocal) {
43     _local_impl = ((SALOMEDSImpl_GenericAttribute*)(addr));
44     _corba_impl = SALOMEDS::GenericAttribute::_nil();
45   }
46   else {
47     _local_impl = NULL;
48     _corba_impl = SALOMEDS::GenericAttribute::_duplicate(theGA);
49   }
50 }
51
52 SALOMEDS_GenericAttribute::~SALOMEDS_GenericAttribute() 
53 {
54   if (!_isLocal) {
55     _corba_impl->Destroy();
56   }
57 }
58
59 void SALOMEDS_GenericAttribute::CheckLocked() 
60 {
61   if(_isLocal) {
62     try {
63       _local_impl->CheckLocked();
64     }
65     catch(...) {
66       throw SALOMEDS::GenericAttribute::LockProtection();
67     }
68   }
69   else {
70     _corba_impl->CheckLocked();
71   }
72 }
73
74 std::string SALOMEDS_GenericAttribute::Type()
75 {
76   std::string aType;
77   if(_isLocal) {
78     aType = _local_impl->Type().ToCString();
79   }
80   else {
81     aType = _corba_impl->Type();
82   }
83   return aType;
84 }
85
86 std::string SALOMEDS_GenericAttribute::GetClassType()
87 {
88   std::string aType;
89   if(_isLocal) {
90     aType = _local_impl->GetClassType().ToCString();
91   }
92   else {
93     aType = _corba_impl->GetClassType();
94   }
95   return aType;
96 }
97
98 _PTR(SObject) SALOMEDS_GenericAttribute::GetSObject()
99 {
100   SALOMEDSClient_SObject* aSO = NULL;
101   if(_isLocal) {
102     aSO = new SALOMEDS_SObject(_local_impl->GetSObject());
103   }
104   else {
105     aSO = new SALOMEDS_SObject(_corba_impl->GetSObject());
106   }
107
108   return _PTR(SObject)(aSO);
109 }
110
111
112 SALOMEDS_GenericAttribute* SALOMEDS_GenericAttribute::CreateAttribute(const Handle(SALOMEDSImpl_GenericAttribute)& theGA)
113 {
114   SALOMEDS_GenericAttribute* aGA = NULL;
115   std::string aTypeOfAttribute = theGA->GetClassType().ToCString();
116   __CreateGenericClientAttributeLocal
117   return aGA;  
118 }
119
120 SALOMEDS_GenericAttribute* SALOMEDS_GenericAttribute::CreateAttribute(SALOMEDS::GenericAttribute_ptr theGA)
121 {
122   SALOMEDS_GenericAttribute* aGA = NULL;
123   std::string aTypeOfAttribute = theGA->GetClassType();
124   __CreateGenericClientAttributeCORBA
125   return aGA;  
126 }
127