Salome HOME
NRI : Add Loader.
[modules/kernel.git] / src / Notification / NOTIFICATION_Consumer.cxx
1 using namespace std;
2 //  File      : NOTIFICATION_Consumer.cxx
3 //  Created   : 1 Avril 2002
4 //  Author    : Laurent DADA / Francis KLOSS
5 //  Project   : SALOME
6 //  Module    : Notification Consumer
7 //  Copyright : CEA / Open CASCADE
8
9 #include "NOTIFICATION.hxx"
10
11 NOTIFICATION_Consumer::NOTIFICATION_Consumer():
12     proxy_supplier(0),
13     _ok(false)
14 {
15     CosNA_EventChannel_ptr channel = NOTIFICATION_channel();
16     if (CORBA::is_nil(channel)) {
17         MESSAGE("NOTIFICATION Error : failed to get channel for consumer");
18     } else {
19         CosNA_ConsumerAdmin_ptr consumerAdmin = channel->default_consumer_admin();
20
21         CosNA_ProxyID proxyId;
22         CosNotifyChannelAdmin::ProxySupplier_ptr supplier = consumerAdmin->obtain_notification_pull_supplier(CosNA_STRUCTURED_EVENT, proxyId);
23         if (CORBA::is_nil(supplier)) {
24             MESSAGE("NOTIFICATION Error : failed to get proxy pull supplier");
25         } else {
26             proxy_supplier = CosNA_StructuredProxyPullSupplier::_narrow(supplier);
27             if (CORBA::is_nil(proxy_supplier)) {
28                 MESSAGE("NOTIFICATION Error : failed to _narrow proxy pull supplier");
29             } else {
30                 try {
31                     proxy_supplier->connect_structured_pull_consumer(_this());
32                     _ok = true;
33                     MESSAGE("NOTIFICATION Info : successfully connection for pull consumer notification");
34                 } catch (CORBA::BAD_PARAM& ex) {
35                     MESSAGE("NOTIFICATION Error : pull consumer BAD_PARAM exception while connecting");
36                 } catch (CosEventChannelAdmin::AlreadyConnected& ex) {
37                     MESSAGE("NOTIFICATION Error : pull consumer already connected");
38                 } catch (...) {
39                     MESSAGE("NOTIFICATION Error : pull consumer failed to connect");
40                 }
41             };
42         };
43     };
44 }
45
46 NOTIFICATION_Consumer::~NOTIFICATION_Consumer() {
47     if (_ok) {
48         _ok = false;
49         CosNA_StructuredProxyPullSupplier_var proxy = proxy_supplier;
50         proxy_supplier = CosNA_StructuredProxyPullSupplier::_nil();
51
52         try {
53             if (!CORBA::is_nil(proxy)) {
54                 proxy->disconnect_structured_pull_supplier();
55             };
56         } catch(...) {
57             MESSAGE("NOTIFICATION Error : while disconnecting proxy pull supplier");
58         }
59     };
60 }
61
62 bool NOTIFICATION_Consumer::Receive(char** graph, char** node, char** type, char** message, char** sender, long* counter, char** date, long* stamp) {
63     bool                  status = false;
64     CORBA::Boolean        has_event;
65     CosN_StructuredEvent* event;
66
67     if (_ok) {
68         try {
69             event  = proxy_supplier->try_pull_structured_event(has_event);
70             status = has_event;
71         } catch (...) {
72             MESSAGE("NOTIFICATION Error : while calling try_pull_structured_event");
73         };
74
75         if (status) {
76             char*        Asender;
77             char*        Agraph;
78             char*        Atype;
79             CORBA::ULong Acounter;
80             CORBA::ULong Astamp;
81             char*        Adate;
82             char*        Anode;
83             char*        Amessage;
84             event->filterable_data[0].value >>= Asender;
85             event->filterable_data[1].value >>= Agraph;
86             event->filterable_data[2].value >>= Atype;
87             event->filterable_data[3].value >>= Acounter;
88             event->filterable_data[4].value >>= Adate;
89             event->filterable_data[5].value >>= Anode;
90             event->filterable_data[6].value >>= Astamp;
91             event->remainder_of_body        >>= Amessage;
92             *graph   = strdup(Agraph);
93             *node    = strdup(Anode);
94             *type    = strdup(Atype);
95             *message = strdup(Amessage);
96             *sender  = strdup(Asender);
97             *counter = (long)Acounter;
98             *date    = strdup(Adate);
99             *stamp   = (long)Astamp;
100         };
101     };
102
103     return(status);
104 }
105
106 void NOTIFICATION_Consumer::disconnect_structured_pull_consumer() {
107 }
108
109 void NOTIFICATION_Consumer::offer_change(const CosN_EventTypeSeq& added, const CosN_EventTypeSeq& deled) {
110 }