Salome HOME
Updated copyright comment
[samples/component.git] / src / DataStreamComponent / DataStreamComponent_Impl.cxx
1 // Copyright (C) 2007-2024  CEA, EDF, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  SuperVisionTest DataStreamComponent : example
24 //  File   : DataStreamComponent_Impl.cxx
25 //  Author : Jean Rahuel
26 //  Module : SuperVisionTest
27 //
28 #include <stdio.h>
29 #ifndef WIN32
30 #include <unistd.h>
31 #else
32 #include <process.h>
33 #endif
34 #include <fstream>
35 #include <sstream>
36 #include <string>
37
38 #include "COMPONENT_version.h"
39 #include "DataStreamComponent_Impl.hxx"
40
41 using namespace std;
42
43 DataStreamFactory_Impl::DataStreamFactory_Impl( CORBA::ORB_ptr orb,
44                                                 PortableServer::POA_ptr poa,
45                                                 PortableServer::ObjectId * contId, 
46                                                 const char *instanceName,
47                                                 const char *interfaceName, bool withRegistry) :
48   Engines_Component_i(orb, poa, contId, instanceName, interfaceName,1,withRegistry) {
49   MESSAGE("DataStreamFactory_Impl::DataStreamFactory_Impl this " << hex << this << dec
50           << "activate object instanceName("
51           << instanceName << ") interfaceName(" << interfaceName << ")" );
52   _thisObj = this ;
53   _id = _poa->activate_object(_thisObj);
54 }
55
56 DataStreamFactory_Impl::DataStreamFactory_Impl() {
57 }
58
59 DataStreamFactory_Impl::~DataStreamFactory_Impl() {
60 }
61
62 char* DataStreamFactory_Impl::getVersion()
63 {
64 #if COMPONENT_DEVELOPMENT
65   return CORBA::string_dup(COMPONENT_VERSION_STR"dev");
66 #else
67   return CORBA::string_dup(COMPONENT_VERSION_STR);
68 #endif
69 }
70
71 void DataStreamFactory_Impl::Setxy( CORBA::Long x , CORBA::Long y ) {
72   _x = x ;
73   _y = y ;
74 }
75
76 void DataStreamFactory_Impl::Getxy( CORBA::Long & x , CORBA::Long & y ) {
77   x = _x ;
78   y = _y ;
79 }
80
81 void DataStreamFactory_Impl::Add( CORBA::Long x , CORBA::Long y , CORBA::Long & z ) {
82   z = x+y ;
83 }
84 void DataStreamFactory_Impl::Sub( CORBA::Long x , CORBA::Long y , CORBA::Long & z ) {
85   z = x-y ;
86 }
87 void DataStreamFactory_Impl::Mul( CORBA::Long x , CORBA::Long y , CORBA::Long & z ) {
88   z = x*y ;
89 }
90 void DataStreamFactory_Impl::Div( CORBA::Long x , CORBA::Long y , CORBA::Long & z ) {
91   z = x/y ;
92 }
93
94 DataStreamComponent::DataStream_ptr DataStreamFactory_Impl::NewDataStream() {
95   beginService( "DataStreamFactory_Impl::NewDataStream" );
96   sendMessage(NOTIF_STEP, "DataStreamFactory_Impl creates DataStream_Impl");
97   DataStream_Impl * myDataStream = nullptr;
98   Engines::Container_var cont = this->GetContainerRef();
99   if( cont->is_SSL_mode() )
100   {
101     myDataStream = new DataStream_Impl_SSL( _orb , _poa, _contId,
102                                       instanceName() , interfaceName() ,
103                                       graphName() , nodeName() ) ;
104   }
105   else
106   {
107     myDataStream = new DataStream_Impl_No_SSL( _orb , _poa, _contId,
108                                       instanceName() , interfaceName() ,
109                                       graphName() , nodeName() ) ;
110   }
111   DataStreamComponent::DataStream_var iobject ;
112   PortableServer::ObjectId * id = myDataStream->getId() ;
113   CORBA::Object_var obj = _poa->id_to_reference(*id);
114   iobject = DataStreamComponent::DataStream::_narrow(obj) ;
115   endService( "DataStreamFactory_Impl::NewDataStream" );
116   return DataStreamComponent::DataStream::_duplicate(iobject) ;
117 }
118
119 extern "C"
120 {
121   PortableServer::ObjectId * DataStreamFactoryEngine_factory
122      (CORBA::ORB_ptr orb,
123       PortableServer::POA_ptr poa, 
124       PortableServer::ObjectId * contId,
125       const char *instanceName,
126       const char *interfaceName)
127   {
128 #ifndef WIN32
129     MESSAGE("DataStreamFactoryEngine_factory DataStreamFactoryEngine ("
130             << instanceName << "," << interfaceName << "," << getpid() << ")");
131 #else
132     MESSAGE("DataStreamFactoryEngine_factory DataStreamFactoryEngine ("
133             << instanceName << "," << interfaceName << "," << _getpid() << ")");
134 #endif
135     DataStreamFactory_Impl * myDataStreamFactory = nullptr;
136     CORBA::Object_var o = poa->id_to_reference(*contId);
137     Engines::Container_var cont = Engines::Container::_narrow(o);    
138     if(cont->is_SSL_mode())
139     {
140       myDataStreamFactory = new DataStreamFactory_Impl_SSL(orb, poa, contId, instanceName, interfaceName);
141     }
142     else
143     {
144       myDataStreamFactory = new DataStreamFactory_Impl_No_SSL(orb, poa, contId, instanceName, interfaceName);
145     }
146     return myDataStreamFactory->getId() ;
147   }
148 }
149
150 DataStream_Impl::DataStream_Impl( CORBA::ORB_ptr orb ,
151                                   PortableServer::POA_ptr poa ,
152                                   PortableServer::ObjectId * contId , 
153                                   const char * instanceName ,
154                                   const char * interfaceName , 
155                                   const char * graphName ,
156                                   const char * nodeName , bool withRegistry) :
157   Engines_Component_i(orb, poa, contId, instanceName, interfaceName,1,withRegistry) {
158   Names( graphName , nodeName ) ;
159   MESSAGE("DataStream_Impl::DataStream_Impl activate object instanceName("
160           << instanceName << ") interfaceName(" << interfaceName << ") --> "
161           << hex << (void *) this << dec );
162   beginService( "DataStream_Impl::DataStream_Impl" );
163   _thisObj = this ;
164   _id = _poa->activate_object(_thisObj);
165   sendMessage(NOTIF_STEP, "DataStream_Impl is Created");
166   endService( "DataStream_Impl::DataStream_Impl" );
167 }
168
169 DataStream_Impl::DataStream_Impl() {
170 }
171
172 DataStream_Impl::~DataStream_Impl() {
173   beginService( "DataStream_Impl::~DataStream_Impl" );
174   endService( "DataStream_Impl::~DataStream_Impl" );
175 }
176
177 char* DataStream_Impl::getVersion()
178 {
179 #if COMPONENT_DEVELOPMENT
180   return CORBA::string_dup(COMPONENT_VERSION_STR"dev");
181 #else
182   return CORBA::string_dup(COMPONENT_VERSION_STR);
183 #endif
184 }
185
186 void DataStream_Impl::StreamSetxy( CORBA::Long x , CORBA::Long y ) {
187   _x = x ;
188   _y = y ;
189 }
190
191 void DataStream_Impl::StreamGetxy( CORBA::Long & x , CORBA::Long & y ) {
192   x = _x ;
193   y = _y ;
194 }
195
196 void DataStream_Impl::StreamAdd( CORBA::Long x , CORBA::Long y , CORBA::Long & z ) {
197   z = x+y ;
198 }
199 void DataStream_Impl::StreamSub( CORBA::Long x , CORBA::Long y , CORBA::Long & z ) {
200   z = x-y ;
201 }
202 void DataStream_Impl::StreamMul( CORBA::Long x , CORBA::Long y , CORBA::Long & z ) {
203   z = x*y ;
204 }
205 void DataStream_Impl::StreamDiv( CORBA::Long x , CORBA::Long y , CORBA::Long & z ) {
206   z = x/y ;
207 }
208