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"
17 #include "SALOME_Trace.hxx"
20 //////////////////////////////////////////////////////////////////////
21 // Construction/Destruction
22 //////////////////////////////////////////////////////////////////////
24 SALOME_Trace::SALOME_Trace()
29 SALOME_Trace::~SALOME_Trace()
33 SALOME_Trace& SALOME_Trace::Instance()
35 static SALOME_Trace instance;
39 int SALOME_Trace::Initialize(CORBA::ORB_ptr theOrb) {
40 //get reference on object reference from NS
41 //and initialize m_pInterfaceLogger
42 if (isInitialized && !CORBA::is_nil(m_pInterfaceLogger))
45 const long TIMESleep = 250000000;
46 const int NumberOfTries = 40;
48 timespec ts_req = {0, TIMESleep};
49 timespec ts_rem = {0, 0};
51 CosNaming::NamingContext_var inc;
52 CORBA::Object_var theObj;
53 CORBA::Object_var obj;
55 // searchin for naming service for 0.25*40=10 seconds
56 for (i = 1; i <= NumberOfTries; i++) {
57 if (i != 1) nanosleep(&ts_req,&ts_rem);
59 if(CORBA::is_nil(obj))
60 obj = theOrb->resolve_initial_references("RootPOA");
61 if(CORBA::is_nil(theObj))
62 theObj = theOrb->resolve_initial_references("NameService");
63 if (!CORBA::is_nil(theObj))
64 inc = CosNaming::NamingContext::_narrow(theObj);
65 if (!CORBA::is_nil(inc)) break;
66 } catch( CORBA::COMM_FAILURE& ) {
71 if (CORBA::is_nil(inc)) {
72 cout<<"SALOME_Trace can not find NameService"<<endl;
76 //cout<<"SALOME_Trace : NameService was found"<<endl;
78 const char * Env = getenv("USE_LOGGER");
79 int EnvL = (Env != NULL && strlen(Env))?1:0;
81 // the try to get Logger server if it is necessary
85 name[0].id=CORBA::string_dup("Logger");
87 for(i = 1; i <= NumberOfTries; i++){
88 if (i != 1) nanosleep(&ts_req, &ts_rem);
90 obj = inc->resolve(name);
91 if (!CORBA::is_nil(obj)) m_pInterfaceLogger = SALOME_Logger::Logger::_narrow(obj);
92 } catch(CosNaming::NamingContext::NotFound) {
95 if (!CORBA::is_nil(m_pInterfaceLogger)) {
96 //cout<<"SALOME_Trace : Logger Server was found"<<endl;
97 m_pInterfaceLogger->ping();
101 if (CORBA::is_nil(m_pInterfaceLogger)) {
102 cout<<"SALOME_Trace can not find Logger"<<endl;
110 void SALOME_Trace::putMessage(ostream& msg)
112 //if (!isInitialized) cout<<"!!! SALOME_Trace is used without initialising !!!"<<endl;
113 //write resulting string into Logger CORBA server
114 //concatenate string from passing parameters for transfering into Logger CORBA server
116 //cerr << "-+- " << msg << " ";
118 // CORBA::String_var LogMsg = CORBA::string_dup( str() );
119 //Allow automatic deletion of ostrstream content
121 CORBA::String_var LogMsg = CORBA::string_dup( adt );
122 rdbuf()->freeze(false);
123 //rdbuf()->sync(); // problem with gcc3.2
126 if (CORBA::is_nil(m_pInterfaceLogger))
129 m_pInterfaceLogger-> putMessage (LogMsg) ;