Back to index

salome-kernel  6.5.0
Classes | Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes
SALOME_Trace Class Reference

#include <SALOME_Trace.hxx>

Inheritance diagram for SALOME_Trace:
Inheritance graph
[legend]
Collaboration diagram for SALOME_Trace:
Collaboration graph
[legend]

List of all members.

Classes

class  SALOME_Trace

Public Member Functions

virtual ~SALOME_Trace ()
int Initialize (CORBA::ORB_ptr theOrb)
Standard_EXPORT void putMessage (std::ostream &msg)

Static Public Member Functions

static Standard_EXPORT
SALOME_Trace
Instance ()

Public Attributes

string trace = "local"

Protected Member Functions

 SALOME_Trace ()

Protected Attributes

SALOME_Logger::Logger_var m_pInterfaceLogger
int isInitialized

Detailed Description

Definition at line 66 of file SALOME_Trace.hxx.


Constructor & Destructor Documentation

Definition at line 48 of file SALOME_Trace.cxx.

{
}
SALOME_Trace::SALOME_Trace ( ) [protected]

Definition at line 43 of file SALOME_Trace.cxx.

{
  isInitialized = 0;
}

Member Function Documentation

int SALOME_Trace::Initialize ( CORBA::ORB_ptr  theOrb)

Definition at line 58 of file SALOME_Trace.cxx.

                                                {
  //get reference on object reference from NS
  //and initialize m_pInterfaceLogger 
  if (isInitialized && !CORBA::is_nil(m_pInterfaceLogger))
    return 1;

  const long TIMESleep = 250000000;
  const int NumberOfTries = 40;
  int i;
  timespec ts_req = {0, TIMESleep};
  timespec ts_rem = {0, 0};

  CosNaming::NamingContext_var inc;
  CORBA::Object_var theObj;
  CORBA::Object_var obj;

  // searchin for naming service for 0.25*40=10 seconds
  for (i = 1; i <= NumberOfTries; i++) {
#ifndef WIN32
    if (i != 1) nanosleep(&ts_req,&ts_rem);
#else
        if (i != 1) Sleep(TIMESleep / 1000000);
#endif
    try{ 
      if(CORBA::is_nil(obj))
        obj = theOrb->resolve_initial_references("RootPOA");
      if(CORBA::is_nil(theObj))
        theObj = theOrb->resolve_initial_references("NameService"); 
      if (!CORBA::is_nil(theObj))
        inc = CosNaming::NamingContext::_narrow(theObj);
      if (!CORBA::is_nil(inc)) break;
    } catch( CORBA::SystemException& ) {
    } catch (...) {
    }
  }
  
  if (CORBA::is_nil(inc)) {
    std::cout<<"SALOME_Trace can not find NameService"<<std::endl;
    return 0;
  }
  
  //cout<<"SALOME_Trace : NameService was found"<<endl;
  
  const char * Env = getenv("USE_LOGGER");
  int EnvL = (Env != NULL && strlen(Env))?1:0;
  
  // the try to get Logger server if it is necessary
  if(EnvL) {
    CosNaming::Name name;
    name.length(1);
    name[0].id=CORBA::string_dup("Logger");    
    
    for(i = 1; i <= NumberOfTries; i++){
#ifndef WIN32
      if (i != 1) nanosleep(&ts_req, &ts_rem);
#else
          if (i != 1) Sleep(TIMESleep / 1000000);
#endif
      try {
        obj = inc->resolve(name);
        if (!CORBA::is_nil(obj)) m_pInterfaceLogger = SALOME_Logger::Logger::_narrow(obj);
      } catch(CosNaming::NamingContext::NotFound) {
      } catch(...) {
      }
      if (!CORBA::is_nil(m_pInterfaceLogger)) {
        //cout<<"SALOME_Trace : Logger Server was found"<<endl;
        m_pInterfaceLogger->ping();
        break;
      }
    }
    if (CORBA::is_nil(m_pInterfaceLogger)) {
      std::cout<<"SALOME_Trace can not find Logger"<<std::endl;
      return 0;
    }
  }
  isInitialized = 1;
  return 1;
}

Definition at line 52 of file SALOME_Trace.cxx.

{
        static SALOME_Trace instance;
        return instance;
}
void SALOME_Trace::putMessage ( std::ostream &  msg)

Definition at line 137 of file SALOME_Trace.cxx.

{
  //if (!isInitialized) std::cout<<"!!! SALOME_Trace is used without initialising !!!"<<std::endl;
  //write resulting string into Logger CORBA server
  //concatenate string from passing parameters for transfering into Logger CORBA server

  //std::cerr << "-+- " << msg << " ";

  //   CORBA::String_var LogMsg = CORBA::string_dup( str() );
  //Allow automatic deletion of ostrstream content 
  const char* adt = str().c_str();
  CORBA::String_var LogMsg = CORBA::string_dup( adt );
  //rdbuf()->freeze(false);
  //rdbuf()->sync(); // problem with gcc3.2
  seekp(0);

  if (CORBA::is_nil(m_pInterfaceLogger))
    std::cout << LogMsg;
  else
    m_pInterfaceLogger-> putMessage (LogMsg) ;
}

Member Data Documentation

int SALOME_Trace::isInitialized [protected]

Definition at line 78 of file SALOME_Trace.hxx.

SALOME_Logger::Logger_var SALOME_Trace::m_pInterfaceLogger [protected]

Definition at line 77 of file SALOME_Trace.hxx.

string SALOME_Trace.trace = "local"

Definition at line 35 of file SALOME_Trace.py.


The documentation for this class was generated from the following files: