Salome HOME
sources v1.2
[modules/kernel.git] / src / Notification / NOTIFICATION.cxx
1 //  SALOME Notification : wrapping of Notification service services
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
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. 
10 // 
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. 
15 // 
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 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : NOTIFICATION.cxx
25 //  Author : Laurent DADA / Francis KLOSS
26 //  Module : SALOME
27
28 using namespace std;
29 #include "NOTIFICATION.hxx"
30
31 using namespace std;
32 #include "Utils_ORB_INIT.hxx"
33 #include "Utils_SINGLETON.hxx"
34
35 CosNA_EventChannel_ptr NOTIFICATION_channel() {
36     ORB_INIT&      init = *SINGLETON_<ORB_INIT>::Instance(); ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
37     CORBA::ORB_ptr orb  = init(0, 0);
38
39     CosNA_EventChannel_ptr       channel = CosNA_EventChannel::_nil();
40     CosNaming::NamingContext_var name_context;
41     CosNaming::Name              name;
42     CORBA::Object_var            name_service;
43
44     try {
45         name_service = orb->resolve_initial_references("NameService");
46         name_context = CosNaming::NamingContext::_narrow(name_service);
47         if (CORBA::is_nil(name_context)) {
48             MESSAGE("NOTIFICATION Error : failed to obtain context for NameService");
49             return(channel);
50         };
51     } catch(CORBA::ORB::InvalidName& ex) {
52         MESSAGE("NOTIFICATION Error : service required is invalid [does not exist]");
53         return(channel);
54     } catch (CORBA::COMM_FAILURE& ex) {
55         MESSAGE("NOTIFICATION Error : caught system exception COMM_FAILURE");
56         return(channel);
57     } catch (...) {
58         MESSAGE("NOTIFICATION Error : caught exception while resolving the naming service");
59         return(channel);
60     }
61
62     name.length(1);
63     name[0].id   = CORBA::string_dup((const char*)NOTIFICATION_ChannelName);
64     name[0].kind = CORBA::string_dup((const char*)NOTIFICATION_ChannelName);
65
66     try {
67         CORBA::Object_var channel_ref = name_context->resolve(name);
68         channel = CosNA_EventChannel::_narrow(channel_ref);
69         if (CORBA::is_nil(channel)) {
70             MESSAGE("NOTIFICATION Error : failed to narrow object found in naming service");
71         };
72     } catch(CORBA::ORB::InvalidName& ex) {
73         MESSAGE("NOTIFICATION Error : invalid name");
74     } catch (CORBA::COMM_FAILURE& ex) {
75         MESSAGE("NOTIFICATION Error : caught system exception COMM_FAILURE while resolving event channel name");
76     } catch (...) {
77         MESSAGE("NOTIFICATION Error : caught exception while resolving event channel name");
78     }
79
80     return(channel);
81 }
82
83 #include <time.h>
84 #include <stdio.h>
85
86 static char JourSemaine[7][4] = {"Sun", "Mon", "Tue", "Wed", "Thu" , "Fri", "Sat"};
87
88 static char Mois[12][4] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
89
90 static char NOTIFICATION_DATE[50];
91
92 char* NOTIFICATION_date() {
93     time_t aTime;
94     time(&aTime);
95     struct tm* temps = localtime(&aTime);
96
97     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);
98
99     return(NOTIFICATION_DATE);
100 }