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
12 #include "SALOME_Trace.hxx"
19 //////////////////////////////////////////////////////////////////////
20 // Construction/Destruction
21 //////////////////////////////////////////////////////////////////////
23 SALOME_Trace::SALOME_Trace()
25 //get reference on object reference from NS
26 //and initialize m_pInterfaceLogger
29 char* argv[1] = {"application"};
32 //NB. You can't use SALOME_NamingService class because it uses MESSAGE macro
33 //Otherwise, you will get segmentation fault.
36 CORBA::ORB_var orb = CORBA::ORB_init(argc,argv) ;
37 long TIMESleep = 250000000;
38 int NumberOfTries = 40;
41 ts_req.tv_nsec=TIMESleep;
46 CosNaming::NamingContext_var inc;
47 CORBA::Object_var theObj;
48 CORBA::Object_var obj;
51 name[0].id = CORBA::string_dup("Logger");
52 for (int i = 1; i<=NumberOfTries; i++){
54 a=nanosleep(&ts_req,&ts_rem);
56 if(!CORBA::is_nil(orb))
57 theObj = orb->resolve_initial_references("NameService");
58 if (!CORBA::is_nil(theObj))
59 inc = CosNaming::NamingContext::_narrow(theObj);
61 catch( CORBA::COMM_FAILURE& )
63 cout<<"SALOME_TRACE: CORBA::COMM_FAILURE: Unable to contact the Naming Service" <<endl;
65 catch(...){ cout<< "SALOME_TRACE: Unknown exception dealed with Naming Service" <<endl; }
67 if(!CORBA::is_nil(inc)) {
68 obj = inc->resolve(name);
69 m_pInterfaceLogger = SALOME_Logger::Logger::_narrow(obj);
70 if (!CORBA::is_nil(m_pInterfaceLogger))
71 cout<<"SALOME_TRACE: Logger Server was found"<<endl;
78 catch (const CosNaming::NamingContext::NotFound&)
80 // cout << "Caught exception: Naming Service can't found Logger";
82 catch (CORBA::COMM_FAILURE&)
84 // cout << "Caught CORBA::SystemException CommFailure.";
86 catch (CORBA::SystemException&)
88 // cout << "Caught CORBA::SystemException.";
90 catch (CORBA::Exception&)
92 // cout << "Caught CORBA::Exception.";
96 // cout << "Caught unknown exception.";
98 //cerr << "-----SALOME_Trace::SALOME_Trace----"<<endl;
101 SALOME_Trace::~SALOME_Trace()
105 SALOME_Trace& SALOME_Trace::Instance()
107 static SALOME_Trace instance;
111 void SALOME_Trace::putMessage(ostream& msg)
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) ;