Salome HOME
This commit was generated by cvs2git to track changes on a CVS vendor
[modules/kernel.git] / src / Notification / NOTIFICATION.cxx
1 using namespace std;
2 //  File      : NOTIFICATION.cxx
3 //  Created   : 1 Avril 2002
4 //  Author    : Laurent DADA / Francis KLOSS
5 //  Project   : SALOME
6 //  Module    : Notification General
7 //  Copyright : CEA / Open CASCADE
8
9 #include "NOTIFICATION.hxx"
10
11 using namespace std;
12 #include "Utils_ORB_INIT.hxx"
13 #include "Utils_SINGLETON.hxx"
14
15 CosNA_EventChannel_ptr NOTIFICATION_channel() {
16     ORB_INIT&      init = *SINGLETON_<ORB_INIT>::Instance(); ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
17     CORBA::ORB_ptr orb  = init(0, 0);
18
19     CosNA_EventChannel_ptr       channel = CosNA_EventChannel::_nil();
20     CosNaming::NamingContext_var name_context;
21     CosNaming::Name              name;
22     CORBA::Object_var            name_service;
23
24     try {
25         name_service = orb->resolve_initial_references("NameService");
26         name_context = CosNaming::NamingContext::_narrow(name_service);
27         if (CORBA::is_nil(name_context)) {
28             MESSAGE("NOTIFICATION Error : failed to obtain context for NameService");
29             return(channel);
30         };
31     } catch(CORBA::ORB::InvalidName& ex) {
32         MESSAGE("NOTIFICATION Error : service required is invalid [does not exist]");
33         return(channel);
34     } catch (CORBA::COMM_FAILURE& ex) {
35         MESSAGE("NOTIFICATION Error : caught system exception COMM_FAILURE");
36         return(channel);
37     } catch (...) {
38         MESSAGE("NOTIFICATION Error : caught exception while resolving the naming service");
39         return(channel);
40     }
41
42     name.length(1);
43     name[0].id   = CORBA::string_dup((const char*)NOTIFICATION_ChannelName);
44     name[0].kind = CORBA::string_dup((const char*)NOTIFICATION_ChannelName);
45
46     try {
47         CORBA::Object_var channel_ref = name_context->resolve(name);
48         channel = CosNA_EventChannel::_narrow(channel_ref);
49         if (CORBA::is_nil(channel)) {
50             MESSAGE("NOTIFICATION Error : failed to narrow object found in naming service");
51         };
52     } catch(CORBA::ORB::InvalidName& ex) {
53         MESSAGE("NOTIFICATION Error : invalid name");
54     } catch (CORBA::COMM_FAILURE& ex) {
55         MESSAGE("NOTIFICATION Error : caught system exception COMM_FAILURE while resolving event channel name");
56     } catch (...) {
57         MESSAGE("NOTIFICATION Error : caught exception while resolving event channel name");
58     }
59
60     return(channel);
61 }
62
63 #include <time.h>
64 #include <stdio.h>
65
66 static char JourSemaine[7][4] = {"Sun", "Mon", "Tue", "Wed", "Thu" , "Fri", "Sat"};
67
68 static char Mois[12][4] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
69
70 static char NOTIFICATION_DATE[50];
71
72 char* NOTIFICATION_date() {
73     time_t aTime;
74     time(&aTime);
75     struct tm* temps = localtime(&aTime);
76
77     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);
78
79     return(NOTIFICATION_DATE);
80 }