Salome HOME
Copyright update 2021
[samples/component.git] / src / SubComponent / SubComponent.cxx
1 // Copyright (C) 2007-2021  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, 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 SubComponent : example of component that sunstracts one number from another
24 //  File   : SubComponentEngine.cxx
25 //  Author : MARC TAJCHMAN, CEA
26 //  Module : SuperVisionTest
27 //
28 #include <stdio.h>
29 #ifndef WIN32
30 #include <unistd.h>
31 #endif
32 #include <fstream>
33 #include <sstream>
34 #include <string>
35
36 #include "COMPONENT_version.h"
37 #include "SubComponent.hxx"
38
39 using namespace std;
40
41 SubComponentEngine::SubComponentEngine( CORBA::ORB_ptr orb,
42                                     PortableServer::POA_ptr poa,
43                                     PortableServer::ObjectId * contId, 
44                                     const char *instanceName,
45                                     const char *interfaceName) :
46   Engines_Component_i(orb, poa, contId, instanceName, interfaceName,1,true)
47 {
48 //  MESSAGE("SubComponentEngine::SubComponentEngine activate object instanceName("
49 //          << instanceName << ") interfaceName(" << interfaceName << ")" )
50   _thisObj = this ;
51   _id = _poa->activate_object(_thisObj);
52   _nexec = 0 ;
53 }
54
55 SubComponentEngine::SubComponentEngine()
56 {
57 }
58
59 SubComponentEngine::~SubComponentEngine()
60 {
61 }
62
63 char* SubComponentEngine::getVersion()
64 {
65 #if COMPONENT_DEVELOPMENT
66   return CORBA::string_dup(COMPONENT_VERSION_STR"dev");
67 #else
68   return CORBA::string_dup(COMPONENT_VERSION_STR);
69 #endif
70 }
71
72 void SubComponentEngine::Sub( double x , double y , double & z ) {
73   beginService( " SubComponentEngine::Sub" );
74   z = x - y ;
75   int S;
76   
77   sendMessage(NOTIF_STEP, "Sub is Computing");
78 //  S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
79   S = 5 ;
80 #ifndef WIN32
81   while ( S ) {
82     S = sleep( S ) ;
83   }
84 #else
85   Sleep(S*1000);
86 #endif
87   MESSAGE( "SubComponentEngine::Sub( " <<  x << " , " << y << " , " << z
88        << " ) after " << S << " seconds" )
89   endService( " SubComponentEngine::Sub"  );
90 }
91
92 extern "C"
93 {
94   PortableServer::ObjectId * SubComponentEngine_factory
95      (CORBA::ORB_ptr orb,
96       PortableServer::POA_ptr poa, 
97       PortableServer::ObjectId * contId,
98       const char *instanceName,
99       const char *interfaceName)
100   {
101     MESSAGE("SubComponentEngine_factory SubComponentEngine ("
102             << instanceName << "," << interfaceName << ")");
103     SubComponentEngine * mySubComponent 
104       = new SubComponentEngine(orb, poa, contId, instanceName, interfaceName);
105     return mySubComponent->getId() ;
106   }
107 }
108
109