Salome HOME
Updated copyright comment
[modules/kernel.git] / src / Notification / NOTIFICATION_Consumer.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_Consumer.cxx
25 //  Author : Laurent DADA / Francis KLOSS
26 //  Module : SALOME
27 //
28 #include "NOTIFICATION.hxx"
29
30 NOTIFICATION_Consumer::NOTIFICATION_Consumer():
31     _ok(false),
32     proxy_supplier(0)
33 {
34     CosNA_EventChannel_ptr channel = NOTIFICATION_channel();
35     if (CORBA::is_nil(channel)) {
36         MESSAGE("NOTIFICATION Error : failed to get channel for consumer");
37     } else {
38         CosNA_ConsumerAdmin_ptr consumerAdmin = channel->default_consumer_admin();
39
40         CosNA_ProxyID proxyId;
41         CosNotifyChannelAdmin::ProxySupplier_ptr supplier = consumerAdmin->obtain_notification_pull_supplier(CosNA_STRUCTURED_EVENT, proxyId);
42         if (CORBA::is_nil(supplier)) {
43             MESSAGE("NOTIFICATION Error : failed to get proxy pull supplier");
44         } else {
45             proxy_supplier = CosNA_StructuredProxyPullSupplier::_narrow(supplier);
46             if (CORBA::is_nil(proxy_supplier)) {
47                 MESSAGE("NOTIFICATION Error : failed to _narrow proxy pull supplier");
48             } else {
49                 try {
50                     proxy_supplier->connect_structured_pull_consumer(_this());
51                     _ok = true;
52                     MESSAGE("NOTIFICATION Info : successfully connection for pull consumer notification");
53                 } catch (CORBA::BAD_PARAM&) {
54                     MESSAGE("NOTIFICATION Error : pull consumer BAD_PARAM exception while connecting");
55                 } catch (CosEventChannelAdmin::AlreadyConnected&) {
56                     MESSAGE("NOTIFICATION Error : pull consumer already connected");
57                 } catch (...) {
58                     MESSAGE("NOTIFICATION Error : pull consumer failed to connect");
59                 }
60             };
61         };
62     };
63 }
64
65 NOTIFICATION_Consumer::~NOTIFICATION_Consumer() {
66     if (_ok) {
67         _ok = false;
68         CosNA_StructuredProxyPullSupplier_var proxy = proxy_supplier;
69         proxy_supplier = CosNA_StructuredProxyPullSupplier::_nil();
70
71         try {
72             if (!CORBA::is_nil(proxy)) {
73                 proxy->disconnect_structured_pull_supplier();
74             };
75         } catch(...) {
76             MESSAGE("NOTIFICATION Error : while disconnecting proxy pull supplier");
77         }
78     };
79 }
80
81 bool NOTIFICATION_Consumer::Receive(char** graph, char** node, char** type, char** message, char** sender, long* counter, char** date, long* stamp) {
82     bool                  status = false;
83     CORBA::Boolean        has_event;
84     CosN_StructuredEvent* event;
85
86     if (_ok) {
87         try {
88             event  = proxy_supplier->try_pull_structured_event(has_event);
89             status = has_event;
90         } catch (...) {
91             MESSAGE("NOTIFICATION Error : while calling try_pull_structured_event");
92         };
93
94         if (status) {
95             //omniORB 4.1.x requiries using only CORBA types instead C types
96             const char* Asender;
97             const char* Agraph;
98             const char* Atype;
99             CORBA::ULong      Acounter;
100             CORBA::ULong      Astamp;
101             const char* Adate;
102             const char* Anode;
103             const char* Amessage;           
104             event->filterable_data[0].value >>= Asender;
105             event->filterable_data[1].value >>= Agraph;
106             event->filterable_data[2].value >>= Atype;
107             event->filterable_data[3].value >>= Acounter;
108             event->filterable_data[4].value >>= Adate;
109             event->filterable_data[5].value >>= Anode;
110             event->filterable_data[6].value >>= Astamp;
111             event->remainder_of_body        >>= Amessage;
112             *graph   = CORBA::string_dup(Agraph);
113             *node    = CORBA::string_dup(Anode);
114             *type    = CORBA::string_dup(Atype);
115             *message = CORBA::string_dup(Amessage);
116             *sender  = CORBA::string_dup(Asender);
117             *counter = (long)Acounter;
118             *date    = CORBA::string_dup(Adate);
119             *stamp   = (long)Astamp;
120         };
121     };
122
123     return(status);
124 }
125
126 void NOTIFICATION_Consumer::disconnect_structured_pull_consumer() {
127 }
128
129 void NOTIFICATION_Consumer::offer_change(const CosN_EventTypeSeq& /*added*/, const CosN_EventTypeSeq& /*deled*/) {
130 }