1 // SALOME_LoggerClient : CORBA distributed log
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SALOME_Loggerclient.hxx
25 // Author : Vasily Rusyaev, Paul RASCLE, EDF
34 #include "SALOME_Log.hxx"
36 #include <SALOMEconfig.h>
37 #include CORBA_CLIENT_HEADER(Logger)
39 // class SALOME_LoggerClient : public SALOME_Log
42 // SALOME_Logger::Logger_var m_pInterfaceLogger; // object reference on Logger server
45 SALOME_Logger::Logger_ptr m_pInterfaceLogger; // object reference on Logger server
47 SALOME_Log::SALOME_Log()
49 cout << "SALOME_LoggerClient: constructor" << endl;
50 //get reference on object reference from NS
51 //and initialize m_pInterfaceLogger
54 char* argv[1] = {"application"};
57 //NB. You can't use SALOME_NamingService class because it uses MESSAGE macro
58 //Otherwise, you will get segmentation fault.
61 CORBA::ORB_var orb = CORBA::ORB_init(argc,argv);
62 long TIMESleep = 250000000;
63 int NumberOfTries = 40;
66 ts_req.tv_nsec=TIMESleep;
71 CosNaming::NamingContext_var inc;
72 CORBA::Object_var theObj;
73 CORBA::Object_var obj;
76 name[0].id = CORBA::string_dup("Logger");
77 for (int i = 1; i<=NumberOfTries; i++)
80 a=nanosleep(&ts_req,&ts_rem);
83 if(!CORBA::is_nil(orb))
84 theObj = orb->resolve_initial_references("NameService");
85 if (!CORBA::is_nil(theObj))
86 inc = CosNaming::NamingContext::_narrow(theObj);
88 catch( CORBA::COMM_FAILURE& )
90 cout<<"SALOME_LoggerClient: CORBA::COMM_FAILURE: Unable to contact the Naming Service"<<endl;
94 cout<<"SALOME_LoggerClient: Unknown exception dealing with Naming Service"<<endl;
97 if(!CORBA::is_nil(inc))
99 obj = inc->resolve(name);
100 m_pInterfaceLogger = SALOME_Logger::Logger::_narrow(obj);
101 if (!CORBA::is_nil(m_pInterfaceLogger))
102 cout<<"SALOME_LoggerClient: Logger Server was found"<<endl;
107 catch (const CosNaming::NamingContext::NotFound&)
109 // cout << "Caught exception: Naming Service can't found Logger";
111 catch (CORBA::COMM_FAILURE&)
113 // cout << "Caught CORBA::SystemException CommFailure.";
115 catch (CORBA::SystemException&)
117 // cout << "Caught CORBA::SystemException.";
119 catch (CORBA::Exception&)
121 // cout << "Caught CORBA::Exception.";
125 // cout << "Caught unknown exception.";
127 //cerr << "-----SALOME_Trace::SALOME_Trace----"<<endl;
130 SALOME_Log::~SALOME_Log()
134 SALOME_Log& SALOME_Log::Instance()
136 static SALOME_Log instance;
140 void SALOME_Log::putMessage(std::ostream& msg)
142 //write resulting string into Logger CORBA server
145 CORBA::String_var LogMsg = CORBA::string_dup(adt);
146 rdbuf()->freeze(false);
149 if (CORBA::is_nil(m_pInterfaceLogger))
150 cout << LogMsg << std::flush;
152 m_pInterfaceLogger-> putMessage (LogMsg) ;