Salome HOME
Copyright update 2021
[samples/component.git] / src / SIGNALSComponent / SIGNALSComponent_Impl.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 SIGNALSComponent : example of component that devides two numbers
24 //  File   : SIGNALSComponent.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 "utilities.h"
37 #include "SIGNALSComponent_Impl.hxx"
38 #include "COMPONENT_version.h"
39
40 using namespace std;
41
42 SIGNALSComponent_Impl::SIGNALSComponent_Impl( CORBA::ORB_ptr orb,
43                                     PortableServer::POA_ptr poa,
44                                     PortableServer::ObjectId * contId, 
45                                     const char *instanceName,
46                                     const char *interfaceName) :
47   Engines_Component_i(orb, poa, contId, instanceName, interfaceName,1,true)
48 {
49   MESSAGE("SIGNALSComponent_Impl::SIGNALSComponent_Impl activate object instanceName("
50           << instanceName << ") interfaceName(" << interfaceName << ")" )
51   _thisObj = this ;
52   _id = _poa->activate_object(_thisObj);
53   NULLPTR = NULL ;
54 }
55
56 SIGNALSComponent_Impl::SIGNALSComponent_Impl() :
57   Engines_Component_i()
58 {
59   NULLPTR = NULL ;
60 }
61
62 SIGNALSComponent_Impl::~SIGNALSComponent_Impl()
63 {
64 }
65
66 char* SIGNALSComponent_Impl::getVersion()
67 {
68 #if COMPONENT_DEVELOPMENT
69   return CORBA::string_dup(COMPONENT_VERSION_STR"dev");
70 #else
71   return CORBA::string_dup(COMPONENT_VERSION_STR);
72 #endif
73 }
74
75 CORBA::Long SIGNALSComponent_Impl::SIGSEGVfunc() {
76   beginService( " SIGNALSComponent_Impl::SIGSEGVfunc" );
77 #ifndef WIN32
78   cout << pthread_self() << "SIGNALSComponent_Impl::SIGSEGVfunc" << endl ;
79 #else
80   cout << pthread_self().p << "SIGNALSComponent_Impl::SIGSEGVfunc" << endl ;
81 #endif
82   int S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
83
84 #ifndef WIN32
85   while ( S ) {
86     S = sleep( S ) ;
87   }
88 #else
89   Sleep(S*1000);
90 #endif
91   long _nullptr = *NULLPTR ;
92   endService( " SIGNALSComponent_Impl::SIGSEGVfunc"  );
93   return _nullptr ;
94 }
95
96 CORBA::Long SIGNALSComponent_Impl::SIGFPEfunc( CORBA::Long a , CORBA::Long b ) {
97   beginService( " SIGNALSComponent_Impl::SIGFPEfunc" );
98 #ifndef WIN32
99   cout << pthread_self() << "SIGNALSComponent_Impl::SIGFPEfunc" << endl ;
100 #else 
101   cout << pthread_self().p << "SIGNALSComponent_Impl::SIGFPEfunc" << endl ;
102 #endif
103   int S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
104 #ifndef WIN32
105   while ( S ) {
106     S = sleep( S ) ;
107   }
108 #else
109   Sleep(S*1000);
110 #endif
111   long c = a/b ;
112   endService( " SIGNALSComponent_Impl::SIGFPEfunc"  );
113   return c ;
114 }
115
116 void SIGNALSComponent_Impl::MethodToKill() {
117   beginService( " SIGNALSComponent_Impl::MethodToKill" );
118   while ( 1 ) {
119 #ifndef WIN32
120     sleep(1);
121 #else
122     Sleep(1000);
123 #endif
124
125   }
126   endService( " SIGNALSComponent_Impl::MethodToKill"  );
127   return ;
128 }
129
130 void * RunMethodToKill( void * ptr ) {
131   SIGNALSComponent_Impl * mySIGNALSComponent ;
132   mySIGNALSComponent = ( SIGNALSComponent_Impl * ) ptr ;
133   mySIGNALSComponent->MethodToKill() ;
134   return ptr ;
135 }
136
137 void SIGNALSComponent_Impl::WaitKill() {
138   pthread_t T;
139   pthread_create( &T , NULL , RunMethodToKill , this ) ;
140   pthread_join( T , NULL ) ;
141 }
142
143 extern "C"
144 {
145   PortableServer::ObjectId * SIGNALSComponentEngine_factory
146      (CORBA::ORB_ptr orb,
147       PortableServer::POA_ptr poa, 
148       PortableServer::ObjectId * contId,
149       const char *instanceName,
150       const char *interfaceName)
151   {
152     MESSAGE("SIGNALSComponentEngine_factory SIGNALSComponent_Impl("
153             << instanceName << "," << interfaceName << ")");
154     SIGNALSComponent_Impl * mySIGNALSComponent 
155       = new SIGNALSComponent_Impl(orb, poa, contId, instanceName, interfaceName);
156     return mySIGNALSComponent->getId() ;
157   }
158 }
159
160