Salome HOME
PR: mergefrom_PAL_OCC_21Oct04
[modules/yacs.git] / src / Notification / NOTIFICATION_Consumer.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_Consumer.cxx
25 //  Author : Laurent DADA / Francis KLOSS
26 //  Module : SALOME
27
28 using namespace std;
29 #include "NOTIFICATION.hxx"
30
31 NOTIFICATION_Consumer::NOTIFICATION_Consumer():
32     proxy_supplier(0),
33     _ok(false)
34 {
35     CosNA_EventChannel_ptr channel = NOTIFICATION_channel();
36     if (CORBA::is_nil(channel)) {
37         MESSAGE("NOTIFICATION Error : failed to get channel for consumer");
38     } else {
39         CosNA_ConsumerAdmin_ptr consumerAdmin = channel->default_consumer_admin();
40
41         CosNA_ProxyID proxyId;
42         CosNotifyChannelAdmin::ProxySupplier_ptr supplier = consumerAdmin->obtain_notification_pull_supplier(CosNA_STRUCTURED_EVENT, proxyId);
43         if (CORBA::is_nil(supplier)) {
44             MESSAGE("NOTIFICATION Error : failed to get proxy pull supplier");
45         } else {
46             proxy_supplier = CosNA_StructuredProxyPullSupplier::_narrow(supplier);
47             if (CORBA::is_nil(proxy_supplier)) {
48                 MESSAGE("NOTIFICATION Error : failed to _narrow proxy pull supplier");
49             } else {
50                 try {
51                     proxy_supplier->connect_structured_pull_consumer(_this());
52                     _ok = true;
53                     MESSAGE("NOTIFICATION Info : successfully connection for pull consumer notification");
54                 } catch (CORBA::BAD_PARAM& ex) {
55                     MESSAGE("NOTIFICATION Error : pull consumer BAD_PARAM exception while connecting");
56                 } catch (CosEventChannelAdmin::AlreadyConnected& ex) {
57                     MESSAGE("NOTIFICATION Error : pull consumer already connected");
58                 } catch (...) {
59                     MESSAGE("NOTIFICATION Error : pull consumer failed to connect");
60                 }
61             };
62         };
63     };
64 }
65
66 NOTIFICATION_Consumer::~NOTIFICATION_Consumer() {
67     if (_ok) {
68         _ok = false;
69         CosNA_StructuredProxyPullSupplier_var proxy = proxy_supplier;
70         proxy_supplier = CosNA_StructuredProxyPullSupplier::_nil();
71
72         try {
73             if (!CORBA::is_nil(proxy)) {
74                 proxy->disconnect_structured_pull_supplier();
75             };
76         } catch(...) {
77             MESSAGE("NOTIFICATION Error : while disconnecting proxy pull supplier");
78         }
79     };
80 }
81
82 bool NOTIFICATION_Consumer::Receive(char** graph, char** node, char** type, char** message, char** sender, long* counter, char** date, long* stamp) {
83     bool                  status = false;
84     CORBA::Boolean        has_event;
85     CosN_StructuredEvent* event;
86
87     if (_ok) {
88         try {
89             event  = proxy_supplier->try_pull_structured_event(has_event);
90             status = has_event;
91         } catch (...) {
92             MESSAGE("NOTIFICATION Error : while calling try_pull_structured_event");
93         };
94
95         if (status) {
96             char*        Asender;
97             char*        Agraph;
98             char*        Atype;
99             CORBA::ULong Acounter;
100             CORBA::ULong Astamp;
101             char*        Adate;
102             char*        Anode;
103             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 }