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 SALOME_Logger::Logger_ptr m_pInterfaceLogger; // object reference on Logger server
41 SALOME_Log* SALOME_Log::_singleton = 0;
43 // log line size: if too short, log line is truncated, without crash...
44 char SALOME_LogStr[1024];
46 SALOME_Log::SALOME_Log(): ostrstream(SALOME_LogStr,sizeof(SALOME_LogStr))
48 cout << "SALOME_LoggerClient: constructor" << endl;
49 //get reference on object reference from NS
50 //and initialize m_pInterfaceLogger
53 char* argv[1] = {"application"};
56 //NB. You can't use SALOME_NamingService class because it uses MESSAGE macro
57 //Otherwise, you will get segmentation fault.
60 CORBA::ORB_var orb = CORBA::ORB_init(argc,argv);
61 long TIMESleep = 250000000;
62 int NumberOfTries = 40;
65 ts_req.tv_nsec=TIMESleep;
70 CosNaming::NamingContext_var inc;
71 CORBA::Object_var theObj;
72 CORBA::Object_var obj;
75 name[0].id = CORBA::string_dup("Logger");
76 for (int i = 1; i<=NumberOfTries; i++)
79 a=nanosleep(&ts_req,&ts_rem);
82 if(!CORBA::is_nil(orb))
83 theObj = orb->resolve_initial_references("NameService");
84 if (!CORBA::is_nil(theObj))
85 inc = CosNaming::NamingContext::_narrow(theObj);
87 catch( CORBA::COMM_FAILURE& )
89 cout<<"SALOME_LoggerClient: CORBA::COMM_FAILURE: Unable to contact the Naming Service"<<endl;
93 cout<<"SALOME_LoggerClient: Unknown exception dealing with Naming Service"<<endl;
96 if(!CORBA::is_nil(inc))
98 obj = inc->resolve(name);
99 m_pInterfaceLogger = SALOME_Logger::Logger::_narrow(obj);
100 if (!CORBA::is_nil(m_pInterfaceLogger))
101 cout<<"SALOME_LoggerClient: Logger Server was found"<<endl;
106 catch (const CosNaming::NamingContext::NotFound&)
108 // cout << "Caught exception: Naming Service can't found Logger";
110 catch (CORBA::COMM_FAILURE&)
112 // cout << "Caught CORBA::SystemException CommFailure.";
114 catch (CORBA::SystemException&)
116 // cout << "Caught CORBA::SystemException.";
118 catch (CORBA::Exception&)
120 // cout << "Caught CORBA::Exception.";
124 // cout << "Caught unknown exception.";
126 //cerr << "-----SALOME_Trace::SALOME_Trace----"<<endl;
129 SALOME_Log::~SALOME_Log()
133 SALOME_Log* SALOME_Log::Instance()
135 if (_singleton == 0) _singleton = new SALOME_Log();
139 void SALOME_Log::putMessage(std::ostream& msg)
141 //write resulting string into Logger CORBA server
144 CORBA::String_var LogMsg = CORBA::string_dup(adt);
145 // rdbuf()->freeze(false);
148 if (CORBA::is_nil(m_pInterfaceLogger))
149 cout << LogMsg << std::flush;
151 m_pInterfaceLogger-> putMessage (LogMsg) ;