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