Back to index

salome-kernel  6.5.0
NOTIFICATION.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  SALOME Notification : wrapping of Notification service services
00024 //  File   : NOTIFICATION.cxx
00025 //  Author : Laurent DADA / Francis KLOSS
00026 //  Module : SALOME
00027 //
00028 #include "NOTIFICATION.hxx"
00029 
00030 #include "Utils_ORB_INIT.hxx"
00031 #include "Utils_SINGLETON.hxx"
00032 
00033 CosNA_EventChannel_ptr NOTIFICATION_channel() {
00034     ORB_INIT&      init = *SINGLETON_<ORB_INIT>::Instance(); ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
00035     CORBA::ORB_ptr orb  = init(0, 0);
00036 
00037     CosNA_EventChannel_ptr       channel = CosNA_EventChannel::_nil();
00038     CosNaming::NamingContext_var name_context;
00039     CosNaming::Name              name;
00040     CORBA::Object_var            name_service;
00041 
00042     try {
00043         name_service = orb->resolve_initial_references("NameService");
00044         name_context = CosNaming::NamingContext::_narrow(name_service);
00045         if (CORBA::is_nil(name_context)) {
00046             MESSAGE("NOTIFICATION Error : failed to obtain context for NameService");
00047             return(channel);
00048         };
00049     } catch(CORBA::ORB::InvalidName& ) {
00050         MESSAGE("NOTIFICATION Error : service required is invalid [does not exist]");
00051         return(channel);
00052     } catch (CORBA::SystemException& ) {
00053         MESSAGE("NOTIFICATION Error : caught system exception COMM_FAILURE");
00054         return(channel);
00055     } catch (...) {
00056         MESSAGE("NOTIFICATION Error : caught exception while resolving the naming service");
00057         return(channel);
00058     }
00059 
00060     name.length(1);
00061     name[0].id   = CORBA::string_dup((const char*)NOTIFICATION_ChannelName);
00062     name[0].kind = CORBA::string_dup((const char*)NOTIFICATION_ChannelName);
00063 
00064     try {
00065         CORBA::Object_var channel_ref = name_context->resolve(name);
00066         channel = CosNA_EventChannel::_narrow(channel_ref);
00067         if (CORBA::is_nil(channel)) {
00068             MESSAGE("NOTIFICATION Error : failed to narrow object found in naming service");
00069         };
00070     } catch(CORBA::ORB::InvalidName& ) {
00071         MESSAGE("NOTIFICATION Error : invalid name");
00072     } catch (CORBA::SystemException& ) {
00073         MESSAGE("NOTIFICATION Error : caught system exception COMM_FAILURE while resolving event channel name");
00074     } catch (...) {
00075         MESSAGE("NOTIFICATION Error : caught exception while resolving event channel name");
00076     }
00077 
00078     return(channel);
00079 }
00080 
00081 #include <time.h>
00082 #include <stdio.h>
00083 
00084 static char JourSemaine[7][4] = {"Sun", "Mon", "Tue", "Wed", "Thu" , "Fri", "Sat"};
00085 
00086 static char Mois[12][4] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
00087 
00088 static char NOTIFICATION_DATE[50];
00089 
00090 char* NOTIFICATION_date() {
00091     time_t aTime;
00092     time(&aTime);
00093     struct tm* temps = localtime(&aTime);
00094 
00095     sprintf(NOTIFICATION_DATE, "%4d %3d %3s %2d %3s %02d:%02d:%02d", 1900+temps->tm_year, temps->tm_mon+1, Mois[temps->tm_mon], temps->tm_mday, JourSemaine[temps->tm_wday], temps->tm_hour, temps->tm_min, temps->tm_sec);
00096 
00097     return(NOTIFICATION_DATE);
00098 }