1 // SALOME Logger : CORBA server managing trace output
3 // Copyright (C) 2003 CEA/DEN, EDF R&D
7 // File : SALOME_Logger.cxx
8 // Author : Vasily Rusyaev
11 #include "SALOME_Trace.hxx"
19 //////////////////////////////////////////////////////////////////////
20 // Construction/Destruction
21 //////////////////////////////////////////////////////////////////////
23 SALOME_Trace::SALOME_Trace()
28 SALOME_Trace::~SALOME_Trace()
32 SALOME_Trace& SALOME_Trace::Instance()
34 static SALOME_Trace instance;
38 int SALOME_Trace::Initialize(CORBA::ORB_ptr theOrb) {
39 //get reference on object reference from NS
40 //and initialize m_pInterfaceLogger
41 if (isInitialized && !CORBA::is_nil(m_pInterfaceLogger))
44 const long TIMESleep = 250000000;
45 const int NumberOfTries = 40;
47 timespec ts_req = {0, TIMESleep};
48 timespec ts_rem = {0, 0};
50 CosNaming::NamingContext_var inc;
51 CORBA::Object_var theObj;
52 CORBA::Object_var obj;
54 // searchin for naming service for 0.25*40=10 seconds
55 for (i = 1; i <= NumberOfTries; i++) {
56 if (i != 1) nanosleep(&ts_req,&ts_rem);
58 if(CORBA::is_nil(obj))
59 obj = theOrb->resolve_initial_references("RootPOA");
60 if(CORBA::is_nil(theObj))
61 theObj = theOrb->resolve_initial_references("NameService");
62 if (!CORBA::is_nil(theObj))
63 inc = CosNaming::NamingContext::_narrow(theObj);
64 if (!CORBA::is_nil(inc)) break;
65 } catch( CORBA::SystemException& ) {
70 if (CORBA::is_nil(inc)) {
71 cout<<"SALOME_Trace can not find NameService"<<endl;
75 //cout<<"SALOME_Trace : NameService was found"<<endl;
77 const char * Env = getenv("USE_LOGGER");
78 int EnvL = (Env != NULL && strlen(Env))?1:0;
80 // the try to get Logger server if it is necessary
84 name[0].id=CORBA::string_dup("Logger");
86 for(i = 1; i <= NumberOfTries; i++){
87 if (i != 1) nanosleep(&ts_req, &ts_rem);
89 obj = inc->resolve(name);
90 if (!CORBA::is_nil(obj)) m_pInterfaceLogger = SALOME_Logger::Logger::_narrow(obj);
91 } catch(CosNaming::NamingContext::NotFound) {
94 if (!CORBA::is_nil(m_pInterfaceLogger)) {
95 //cout<<"SALOME_Trace : Logger Server was found"<<endl;
96 m_pInterfaceLogger->ping();
100 if (CORBA::is_nil(m_pInterfaceLogger)) {
101 cout<<"SALOME_Trace can not find Logger"<<endl;
109 void SALOME_Trace::putMessage(ostream& msg)
111 //if (!isInitialized) cout<<"!!! SALOME_Trace is used without initialising !!!"<<endl;
112 //write resulting string into Logger CORBA server
113 //concatenate string from passing parameters for transfering into Logger CORBA server
115 //cerr << "-+- " << msg << " ";
117 // CORBA::String_var LogMsg = CORBA::string_dup( str() );
118 //Allow automatic deletion of ostrstream content
120 CORBA::String_var LogMsg = CORBA::string_dup( adt );
121 rdbuf()->freeze(false);
122 //rdbuf()->sync(); // problem with gcc3.2
125 if (CORBA::is_nil(m_pInterfaceLogger))
128 m_pInterfaceLogger-> putMessage (LogMsg) ;