Salome HOME
Merge from V6_main 01/04/2013
[samples/component.git] / src / DataStreamComponent / DataStreamComponent_Impl.cxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, 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.
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 #include <unistd.h>
30 #include <fstream>
31 #include <sstream>
32 #include <string>
33
34 #include "COMPONENT_version.h"
35 #include "DataStreamComponent_Impl.hxx"
36
37 using namespace std;
38
39 DataStreamFactory_Impl::DataStreamFactory_Impl( CORBA::ORB_ptr orb,
40                                                 PortableServer::POA_ptr poa,
41                                                 PortableServer::ObjectId * contId, 
42                                                 const char *instanceName,
43                                                 const char *interfaceName) :
44   Engines_Component_i(orb, poa, contId, instanceName, interfaceName,1,true) {
45   MESSAGE("DataStreamFactory_Impl::DataStreamFactory_Impl this " << hex << this << dec
46           << "activate object instanceName("
47           << instanceName << ") interfaceName(" << interfaceName << ")" )
48   _thisObj = this ;
49   _id = _poa->activate_object(_thisObj);
50 }
51
52 DataStreamFactory_Impl::DataStreamFactory_Impl() {
53 }
54
55 DataStreamFactory_Impl::~DataStreamFactory_Impl() {
56 }
57
58 char* DataStreamFactory_Impl::getVersion()
59 {
60 #if COMPONENT_DEVELOPMENT
61   return CORBA::string_dup(COMPONENT_VERSION_STR"dev");
62 #else
63   return CORBA::string_dup(COMPONENT_VERSION_STR);
64 #endif
65 }
66
67 void DataStreamFactory_Impl::Setxy( CORBA::Long x , CORBA::Long y ) {
68   _x = x ;
69   _y = y ;
70 }
71
72 void DataStreamFactory_Impl::Getxy( CORBA::Long & x , CORBA::Long & y ) {
73   x = _x ;
74   y = _y ;
75 }
76
77 void DataStreamFactory_Impl::Add( CORBA::Long x , CORBA::Long y , CORBA::Long & z ) {
78   z = x+y ;
79 }
80 void DataStreamFactory_Impl::Sub( CORBA::Long x , CORBA::Long y , CORBA::Long & z ) {
81   z = x-y ;
82 }
83 void DataStreamFactory_Impl::Mul( CORBA::Long x , CORBA::Long y , CORBA::Long & z ) {
84   z = x*y ;
85 }
86 void DataStreamFactory_Impl::Div( CORBA::Long x , CORBA::Long y , CORBA::Long & z ) {
87   z = x/y ;
88 }
89
90 DataStreamComponent::DataStream_ptr DataStreamFactory_Impl::NewDataStream() {
91   beginService( "DataStreamFactory_Impl::NewDataStream" );
92   sendMessage(NOTIF_STEP, "DataStreamFactory_Impl creates DataStream_Impl");
93   DataStream_Impl * myDataStream ;
94   myDataStream = new DataStream_Impl( _orb , _poa, _contId,
95                                       instanceName() , interfaceName() ,
96                                       graphName() , nodeName() ) ;
97   DataStreamComponent::DataStream_var iobject ;
98   PortableServer::ObjectId * id = myDataStream->getId() ;
99   CORBA::Object_var obj = _poa->id_to_reference(*id);
100   iobject = DataStreamComponent::DataStream::_narrow(obj) ;
101   endService( "DataStreamFactory_Impl::NewDataStream" );
102   return DataStreamComponent::DataStream::_duplicate(iobject) ;
103 }
104
105 extern "C"
106 {
107   PortableServer::ObjectId * DataStreamFactoryEngine_factory
108      (CORBA::ORB_ptr orb,
109       PortableServer::POA_ptr poa, 
110       PortableServer::ObjectId * contId,
111       const char *instanceName,
112       const char *interfaceName)
113   {
114     MESSAGE("DataStreamFactoryEngine_factory DataStreamFactoryEngine ("
115             << instanceName << "," << interfaceName << "," << getpid() << ")");
116     DataStreamFactory_Impl * myDataStreamFactory 
117       = new DataStreamFactory_Impl(orb, poa, contId, instanceName, interfaceName);
118     return myDataStreamFactory->getId() ;
119   }
120 }
121
122 DataStream_Impl::DataStream_Impl( CORBA::ORB_ptr orb ,
123                                   PortableServer::POA_ptr poa ,
124                                   PortableServer::ObjectId * contId , 
125                                   const char * instanceName ,
126                                   const char * interfaceName , 
127                                   const char * graphName ,
128                                   const char * nodeName ) :
129   Engines_Component_i(orb, poa, contId, instanceName, interfaceName,1,true) {
130   Names( graphName , nodeName ) ;
131   MESSAGE("DataStream_Impl::DataStream_Impl activate object instanceName("
132           << instanceName << ") interfaceName(" << interfaceName << ") --> "
133           << hex << (void *) this << dec )
134   beginService( "DataStream_Impl::DataStream_Impl" );
135   _thisObj = this ;
136   _id = _poa->activate_object(_thisObj);
137   sendMessage(NOTIF_STEP, "DataStream_Impl is Created");
138   endService( "DataStream_Impl::DataStream_Impl" );
139 }
140
141 DataStream_Impl::DataStream_Impl() {
142 }
143
144 DataStream_Impl::~DataStream_Impl() {
145   beginService( "DataStream_Impl::~DataStream_Impl" );
146   endService( "DataStream_Impl::~DataStream_Impl" );
147 }
148
149 char* DataStream_Impl::getVersion()
150 {
151 #if COMPONENT_DEVELOPMENT
152   return CORBA::string_dup(COMPONENT_VERSION_STR"dev");
153 #else
154   return CORBA::string_dup(COMPONENT_VERSION_STR);
155 #endif
156 }
157
158 void DataStream_Impl::StreamSetxy( CORBA::Long x , CORBA::Long y ) {
159   _x = x ;
160   _y = y ;
161 }
162
163 void DataStream_Impl::StreamGetxy( CORBA::Long & x , CORBA::Long & y ) {
164   x = _x ;
165   y = _y ;
166 }
167
168 void DataStream_Impl::StreamAdd( CORBA::Long x , CORBA::Long y , CORBA::Long & z ) {
169   z = x+y ;
170 }
171 void DataStream_Impl::StreamSub( CORBA::Long x , CORBA::Long y , CORBA::Long & z ) {
172   z = x-y ;
173 }
174 void DataStream_Impl::StreamMul( CORBA::Long x , CORBA::Long y , CORBA::Long & z ) {
175   z = x*y ;
176 }
177 void DataStream_Impl::StreamDiv( CORBA::Long x , CORBA::Long y , CORBA::Long & z ) {
178   z = x/y ;
179 }
180