Salome HOME
[EDF29852] : Mecanism of fault tolerant in SALOME_Container to resist against emitted...
[modules/kernel.git] / src / Notification / NOTIFICATION.cxx
1 // Copyright (C) 2007-2024  CEA, EDF, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  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, or (at your option) any later version.
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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  SALOME Notification : wrapping of Notification service services
24 //  File   : NOTIFICATION.cxx
25 //  Author : Laurent DADA / Francis KLOSS
26 //  Module : SALOME
27 //
28 #include "NOTIFICATION.hxx"
29
30 #include "OpUtil.hxx"
31
32 CosNA_EventChannel_ptr NOTIFICATION_channel() {
33     CORBA::ORB_ptr orb  = KERNEL::GetRefToORB();
34
35     CosNA_EventChannel_ptr       channel = CosNA_EventChannel::_nil();
36     CosNaming::NamingContext_var name_context;
37     CosNaming::Name              name;
38     CORBA::Object_var            name_service;
39
40     try {
41         name_service = orb->resolve_initial_references("NameService");
42         name_context = CosNaming::NamingContext::_narrow(name_service);
43         if (CORBA::is_nil(name_context)) {
44             MESSAGE("NOTIFICATION Error : failed to obtain context for NameService");
45             return(channel);
46         };
47     } catch(CORBA::ORB::InvalidName& ) {
48         MESSAGE("NOTIFICATION Error : service required is invalid [does not exist]");
49         return(channel);
50     } catch (CORBA::SystemException& ) {
51         MESSAGE("NOTIFICATION Error : caught system exception COMM_FAILURE");
52         return(channel);
53     } catch (...) {
54         MESSAGE("NOTIFICATION Error : caught exception while resolving the naming service");
55         return(channel);
56     }
57
58     name.length(1);
59     name[0].id   = CORBA::string_dup((const char*)NOTIFICATION_ChannelName);
60     name[0].kind = CORBA::string_dup((const char*)NOTIFICATION_ChannelName);
61
62     try {
63         CORBA::Object_var channel_ref = name_context->resolve(name);
64         channel = CosNA_EventChannel::_narrow(channel_ref);
65         if (CORBA::is_nil(channel)) {
66             MESSAGE("NOTIFICATION Error : failed to narrow object found in naming service");
67         };
68     } catch(CORBA::ORB::InvalidName& ) {
69         MESSAGE("NOTIFICATION Error : invalid name");
70     } catch (CORBA::SystemException& ) {
71         MESSAGE("NOTIFICATION Error : caught system exception COMM_FAILURE while resolving event channel name");
72     } catch (...) {
73         MESSAGE("NOTIFICATION Error : caught exception while resolving event channel name");
74     }
75
76     return(channel);
77 }
78
79 #include <time.h>
80 #include <stdio.h>
81
82 static char JourSemaine[7][4] = {"Sun", "Mon", "Tue", "Wed", "Thu" , "Fri", "Sat"};
83
84 static char Mois[12][4] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
85
86 static char NOTIFICATION_DATE[50];
87
88 char* NOTIFICATION_date() {
89 #ifndef WIN32
90     time_t aTime;
91     time(&aTime);
92     struct tm* temps = localtime(&aTime);
93
94     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);
95 #else 
96         SYSTEMTIME    st;
97         GetLocalTime(&st);
98         sprintf(NOTIFICATION_DATE, "%4d %3d %3s %2d %3s %02d:%02d:%02d", st.wYear, st.wMonth, Mois[st.wMonth-1], st.wDay, JourSemaine[st.wDay], st.wHour, st.wMinute, st.wSecond);
99 #endif
100     return(NOTIFICATION_DATE);
101 }