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 #include "utilities.h"
41 // class SALOME_LoggerClient : public SALOME_Log
44 // SALOME_Logger::Logger_var m_pInterfaceLogger; // object reference on Logger server
47 SALOME_Logger::Logger_ptr m_pInterfaceLogger; // object reference on Logger server
49 SALOME_Log::SALOME_Log()
51 MESSAGE("SALOME_LoggerClient: constructor");
52 //get reference on object reference from NS
53 //and initialize m_pInterfaceLogger
56 char* argv[1] = {"application"};
59 //NB. You can't use SALOME_NamingService class because it uses MESSAGE macro
60 //Otherwise, you will get segmentation fault.
63 CORBA::ORB_var orb = CORBA::ORB_init(argc,argv);
64 long TIMESleep = 250000000;
65 int NumberOfTries = 40;
68 ts_req.tv_nsec=TIMESleep;
73 CosNaming::NamingContext_var inc;
74 CORBA::Object_var theObj;
75 CORBA::Object_var obj;
78 name[0].id = CORBA::string_dup("Logger");
79 for (int i = 1; i<=NumberOfTries; i++)
82 a=nanosleep(&ts_req,&ts_rem);
85 if(!CORBA::is_nil(orb))
86 theObj = orb->resolve_initial_references("NameService");
87 if (!CORBA::is_nil(theObj))
88 inc = CosNaming::NamingContext::_narrow(theObj);
90 catch( CORBA::COMM_FAILURE& )
92 MESSAGE("SALOME_LoggerClient: CORBA::COMM_FAILURE: Unable to contact the Naming Service");
96 MESSAGE("SALOME_LoggerClient: Unknown exception dealing with Naming Service");
99 if(!CORBA::is_nil(inc))
101 obj = inc->resolve(name);
102 m_pInterfaceLogger = SALOME_Logger::Logger::_narrow(obj);
103 if (!CORBA::is_nil(m_pInterfaceLogger))
104 MESSAGE("SALOME_LoggerClient: Logger Server was found");
109 catch (const CosNaming::NamingContext::NotFound&)
111 // MESSAGE("Caught exception: Naming Service can't found Logger");
113 catch (CORBA::COMM_FAILURE&)
115 // MESSAGE("Caught CORBA::SystemException CommFailure.");
117 catch (CORBA::SystemException&)
119 // MESSAGE("Caught CORBA::SystemException.");
121 catch (CORBA::Exception&)
123 // MESSAGE("Caught CORBA::Exception.");
127 // MESSAGE("Caught unknown exception.");
129 //cerr << "-----SALOME_Trace::SALOME_Trace----"<<endl;
132 SALOME_Log::~SALOME_Log()
136 SALOME_Log& SALOME_Log::Instance()
138 static SALOME_Log instance;
142 void SALOME_Log::putMessage(std::ostream& msg)
144 //write resulting string into Logger CORBA server
147 CORBA::String_var LogMsg = CORBA::string_dup(adt);
148 rdbuf()->freeze(false);
151 if (CORBA::is_nil(m_pInterfaceLogger))
152 cout << LogMsg << std::flush;
154 m_pInterfaceLogger-> putMessage (LogMsg) ;