Salome HOME
ENV: Windows porting.
authorenv <env@opencascade.com>
Wed, 13 Jul 2005 06:54:30 +0000 (06:54 +0000)
committerenv <env@opencascade.com>
Wed, 13 Jul 2005 06:54:30 +0000 (06:54 +0000)
src/Container/Component_i.cxx
src/Container/Container_i.cxx
src/Container/SALOME_Component_i.hxx
src/Container/SALOME_ContainerManager.cxx
src/Container/SALOME_ContainerManager.hxx
src/Container/SALOME_Container_i.hxx

index 86763cb89a40a181e5621de73ec2024586b554d8..01ad220b835d8e84bec6f8388e9ccad276b39ed8 100644 (file)
 #include "RegistryConnexion.hxx"
 #include "OpUtil.hxx"
 #include <stdio.h>
+#ifndef WNT
 #include <dlfcn.h>
+#endif
 #include <cstdlib>
 #include "utilities.h"
 
+#ifndef WNT
 #include <sys/time.h>
 #include <sys/resource.h>
 #include <unistd.h>
+#else
+#include <sys/timeb.h>
+int SIGUSR11 = 1000;
+#endif
+
 
 using namespace std;
 
@@ -322,11 +330,21 @@ bool Engines_Component_i::Kill_impl()
 //          << dec ) ;
 
   bool RetVal = false ;
+#ifndef WNT
   if ( _ThreadId > 0 && pthread_self() != _ThreadId )
     {
       RetVal = Killer( _ThreadId , 0 ) ;
       _ThreadId = (pthread_t ) -1 ;
     }
+
+#else
+  if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
+    {
+      RetVal = Killer( *_ThreadId , 0 ) ;
+      _ThreadId = (pthread_t* ) 0 ;
+    }
+
+#endif
   return RetVal ;
 }
 
@@ -346,11 +364,19 @@ bool Engines_Component_i::Stop_impl()
   
 
   bool RetVal = false ;
+#ifndef WNT
   if ( _ThreadId > 0 && pthread_self() != _ThreadId )
     {
       RetVal = Killer( _ThreadId , 0 ) ;
       _ThreadId = (pthread_t ) -1 ;
     }
+#else
+  if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
+    {
+      RetVal = Killer( *_ThreadId , 0 ) ;
+      _ThreadId = (pthread_t* ) 0 ;
+    }
+#endif
   return RetVal ;
 }
 
@@ -369,7 +395,11 @@ bool Engines_Component_i::Suspend_impl()
           << dec << " _ThreadId " << _ThreadId );
 
   bool RetVal = false ;
+#ifndef WNT
   if ( _ThreadId > 0 && pthread_self() != _ThreadId )
+#else
+  if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
+#endif
     {
       if ( _Sleeping )
        {
@@ -377,7 +407,12 @@ bool Engines_Component_i::Suspend_impl()
        }
     else 
       {
+#ifndef WNT
        RetVal = Killer( _ThreadId ,SIGINT ) ;
+#else
+       RetVal = Killer( *_ThreadId ,SIGINT ) ;
+#endif
+
       }
     }
   return RetVal ;
@@ -397,7 +432,11 @@ bool Engines_Component_i::Resume_impl()
           << " machineName " << GetHostname().c_str()<< " _id " << hex << _id
           << dec << " _ThreadId " << _ThreadId );
   bool RetVal = false ;
+#ifndef WNT
   if ( _ThreadId > 0 && pthread_self() != _ThreadId )
+#else
+  if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
+#endif
     {
     if ( _Sleeping ) 
       {
@@ -425,7 +464,11 @@ CORBA::Long Engines_Component_i::CpuUsed_impl()
     {
     if ( _ThreadId > 0 )
       {
+#ifndef WNT
       if ( pthread_self() != _ThreadId )
+#else
+      if ( pthread_self().p != _ThreadId->p )
+#endif
        {
         if ( _Sleeping )
          {
@@ -434,7 +477,11 @@ CORBA::Long Engines_Component_i::CpuUsed_impl()
          {
            // Get Cpu in the appropriate thread with that object !...
            theEngines_Component = this ;
+#ifndef WNT
            Killer( _ThreadId ,SIGUSR1 ) ;
+#else
+           Killer( *_ThreadId ,SIGUSR11 ) ;
+#endif
          }
         cpu = _ThreadCpuUsed ;
        }
@@ -508,7 +555,13 @@ void Engines_Component_i::beginService(const char *serviceName)
 {
   MESSAGE(pthread_self() << "Send BeginService notification for " <<serviceName
          << endl << "Component instance : " << _instanceName << endl << endl);
+#ifndef WNT
   _ThreadId = pthread_self() ;
+#else
+  _ThreadId = new pthread_t;
+  _ThreadId->p = pthread_self().p ;
+  _ThreadId->x = pthread_self().x ;
+#endif
   _StartUsed = 0 ;
   _StartUsed = CpuUsed_impl() ;
   _ThreadCpuUsed = 0 ;
@@ -602,7 +655,11 @@ char* Engines_Component_i::nodeName()
 
 bool Engines_Component_i::Killer( pthread_t ThreadId , int signum )
 {
+#ifndef WNT
   if ( ThreadId )
+#else
+  if ( ThreadId.p )
+#endif
     {
       if ( signum == 0 )
        {
@@ -667,6 +724,7 @@ void Engines_Component_i::SetCurCpu()
 long Engines_Component_i::CpuUsed()
 {
   long cpu = 0 ;
+#ifndef WNT
   struct rusage usage ;
   if ( _ThreadId || _Executed )
     {
@@ -686,6 +744,11 @@ long Engines_Component_i::CpuUsed()
       //      << _ThreadId << " " << _serviceName<< " _StartUsed " 
       //      << _StartUsed << endl ;
     }
+#else
+       // NOT implementet yet
+#endif
+
+
   return cpu ;
 }
 
index d1f27369a4239958065783e72a533f76300eeae2..681532b539c790d5360475e6e3af91a7006fe9f6 100644 (file)
 
 //#define private public
 #include <SALOMEconfig.h>
+#ifndef WNT
 #include CORBA_SERVER_HEADER(SALOME_Component)
+#else
+#include <SALOME_Component.hh>
+#endif
 #include "SALOME_Container_i.hxx"
 #include "SALOME_Component_i.hxx"
 #include "SALOME_NamingService.hxx"
 #include "OpUtil.hxx"
 #include <string.h>
 #include <stdio.h>
+#ifndef WNT
 #include <dlfcn.h>
 #include <unistd.h>
+#else
+#include "../../adm/win32/SALOME_WNT.hxx"
+#include <signal.h>
+#include <process.h>
+int SIGUSR1 = 1000;
+#endif
 #include <Python.h>
 #include "Container_init_python.hxx"
 
@@ -54,7 +65,12 @@ char ** _ArgV ;
 // Other Containers are started via start_impl of FactoryServer
 
 extern "C" {void ActSigIntHandler() ; }
+#ifndef WNT
 extern "C" {void SigIntHandler(int, siginfo_t *, void *) ; }
+#else
+  extern "C" {void SigIntHandler( int ) ; }
+#endif
+
 
 const char *Engines_Container_i::_defaultContainerName="FactoryServer";
 map<std::string, int> Engines_Container_i::_cntInstances_map;
@@ -277,7 +293,11 @@ Engines_Container_i::load_component_Library(const char* componentName)
     }
   
   void* handle;
+#ifndef WNT
   handle = dlopen( impl_name.c_str() , RTLD_LAZY ) ;
+#else
+  handle = dlopen( impl_name.c_str() , 0 ) ;
+#endif
   if ( handle )
     {
       _library_map[impl_name] = handle;
@@ -528,6 +548,7 @@ bool Engines_Container_i::Kill_impl()
   INFOS("===============================================================");
   //exit( 0 ) ;
   ASSERT(0);
+  return false;
 }
 
 //=============================================================================
@@ -787,11 +808,15 @@ string Engines_Container_i::BuildContainerNameForNS(const char *ContainerName,
 
 void ActSigIntHandler()
 {
+#ifndef WNT
   struct sigaction SigIntAct ;
   SigIntAct.sa_sigaction = &SigIntHandler ;
   SigIntAct.sa_flags = SA_SIGINFO ;
-  // DEBUG 03.02.2005 : the first parameter of sigaction is not a mask of signals (SIGINT | SIGUSR1) :
-  // it must be only one signal ===> one call for SIGINT and an other one for SIGUSR1
+#endif
+
+// DEBUG 03.02.2005 : the first parameter of sigaction is not a mask of signals (SIGINT | SIGUSR1) :
+// it must be only one signal ===> one call for SIGINT and an other one for SIGUSR1
+#ifndef WNT
   if ( sigaction( SIGINT , &SigIntAct, NULL ) ) {
     perror("SALOME_Container main ") ;
     exit(0) ;
@@ -801,10 +826,16 @@ void ActSigIntHandler()
     exit(0) ;
   }
   INFOS(pthread_self() << "SigIntHandler activated") ;
+#else  
+  signal( SIGINT, SigIntHandler );
+  signal( SIGUSR1, SigIntHandler );
+#endif
+
 }
 
 void SetCpuUsed() ;
 
+#ifndef WNT
 void SigIntHandler(int what , siginfo_t * siginfo ,
                                         void * toto )
 {
@@ -835,6 +866,33 @@ void SigIntHandler(int what , siginfo_t * siginfo ,
     return ;
   }
 }
+#else // Case WNT
+void SigIntHandler( int what ) {
+  MESSAGE( pthread_self() << "SigIntHandler what     " << what << endl );
+  if ( _Sleeping ) {
+    _Sleeping = false ;
+    MESSAGE("SigIntHandler END sleeping.") ;
+    return ;
+  }
+  else {
+    ActSigIntHandler() ;
+    if ( what == SIGUSR1 ) {
+      SetCpuUsed() ;
+    }
+    else {
+      _Sleeping = true ;
+      MESSAGE("SigIntHandler BEGIN sleeping.") ;
+      int count = 0 ;
+      while( _Sleeping ) {
+        Sleep( 1000 ) ;
+        count += 1 ;
+      }
+      MESSAGE("SigIntHandler LEAVE sleeping after " << count << " s.") ;
+    }
+    return ;
+  }
+}
+#endif
 
 //=============================================================================
 /*! 
index 205eabd75795a44bef13e71ae56bf9f68ef80754..b30f87aa40747479fcefbc10f99929bcf6310220 100644 (file)
@@ -32,7 +32,9 @@
 #include <iostream>
 #include <signal.h>
 #include <stdlib.h>
+#ifndef WNT
 #include <unistd.h>
+#endif
 #include <sys/types.h>
 #include <string>
 #include <map>
 
 class RegistryConnexion;
 
-class Engines_Component_i: public virtual POA_Engines::Component,
+#if defined CONTAINER_EXPORTS
+#if defined WIN32
+#define CONTAINER_EXPORT __declspec( dllexport )
+#else
+#define CONTAINER_EXPORT
+#endif
+#else
+#if defined WNT
+#define CONTAINER_EXPORT __declspec( dllimport )
+#else
+#define CONTAINER_EXPORT
+#endif
+#endif
+
+class CONTAINER_EXPORT Engines_Component_i: public virtual POA_Engines::Component,
                           public virtual PortableServer::RefCountServantBase
 {
 public:
@@ -121,7 +137,11 @@ protected:
   std::map<std::string,CORBA::Any>_fieldsDict;
 
 private:
+#ifndef WNT
   pthread_t _ThreadId ;
+#else
+  pthread_t* _ThreadId ;
+#endif
   long      _StartUsed ;
   long      _ThreadCpuUsed ;
   bool      _Executed ;
index 77cebf354f276ab3fdf1011c6f677b222330fcbb..8d4aaaa34efac70ee425af0aa2d93c5a952e1480 100644 (file)
@@ -2,7 +2,9 @@
 #include "SALOME_NamingService.hxx"
 #include "OpUtil.hxx"
 #include <sys/types.h>
+#ifndef WNT
 #include <unistd.h>
+#endif
 #include <vector>
 
 #define TIME_OUT_TO_LAUNCH_CONT 21
@@ -83,7 +85,11 @@ Engines::Container_ptr SALOME_ContainerManager::FindOrStartContainer(const char
   else {
     int count=TIME_OUT_TO_LAUNCH_CONT;
     while ( CORBA::is_nil(ret) && count ) {
+#ifndef WNT
       sleep( 1 ) ;
+#else
+         Sleep(1000);
+#endif
       count-- ;
       if ( count != 10 )
        MESSAGE( count << ". Waiting for FactoryServer on " << theMachine);
index 9293f18814e7624fb78eab6f0b1f758838dec24d..a34b6b467ac55ce5047baf0af509bbb1d1f6fca0 100644 (file)
 
 class SALOME_NamingService;
 
-class SALOME_ContainerManager: public POA_Engines::ContainerManager,
+#if defined CONTAINER_EXPORTS
+#if defined WIN32
+#define CONTAINER_EXPORT __declspec( dllexport )
+#else
+#define CONTAINER_EXPORT
+#endif
+#else
+#if defined WNT
+#define CONTAINER_EXPORT __declspec( dllimport )
+#else
+#define CONTAINER_EXPORT
+#endif
+#endif
+
+class CONTAINER_EXPORT SALOME_ContainerManager: public POA_Engines::ContainerManager,
                               public PortableServer::RefCountServantBase {
 private:
   SALOME_ResourcesManager _ResManager;
index 06e1f1aa88f28e50a455f20f6fc3a6d09f9f0d74..b1dc79e8007d958ac1d907c80510016dc8c370bb 100644 (file)
@@ -35,7 +35,9 @@
 #include <iostream>
 #include <signal.h>
 #include <stdlib.h>
+#ifndef WNT
 #include <unistd.h>
+#endif
 #include <sys/types.h>
 #include <omnithread.h>
 #include <map>
 
 class SALOME_NamingService;
 
-class Engines_Container_i: public virtual POA_Engines::Container,
+
+#if defined CONTAINER_EXPORTS
+#if defined WIN32
+#define CONTAINER_EXPORT __declspec( dllexport )
+#else
+#define CONTAINER_EXPORT
+#endif
+#else
+#if defined WNT
+#define CONTAINER_EXPORT __declspec( dllimport )
+#else
+#define CONTAINER_EXPORT
+#endif
+#endif
+
+class CONTAINER_EXPORT Engines_Container_i: public virtual POA_Engines::Container,
                           public virtual PortableServer::RefCountServantBase
 {
 public: