1 // SALOME Notification : wrapping of Notification service services
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : NOTIFICATION_Consumer.cxx
25 // Author : Laurent DADA / Francis KLOSS
29 #include "NOTIFICATION.hxx"
31 NOTIFICATION_Consumer::NOTIFICATION_Consumer():
35 CosNA_EventChannel_ptr channel = NOTIFICATION_channel();
36 if (CORBA::is_nil(channel)) {
37 MESSAGE("NOTIFICATION Error : failed to get channel for consumer");
39 CosNA_ConsumerAdmin_ptr consumerAdmin = channel->default_consumer_admin();
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");
46 proxy_supplier = CosNA_StructuredProxyPullSupplier::_narrow(supplier);
47 if (CORBA::is_nil(proxy_supplier)) {
48 MESSAGE("NOTIFICATION Error : failed to _narrow proxy pull supplier");
51 proxy_supplier->connect_structured_pull_consumer(_this());
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");
59 MESSAGE("NOTIFICATION Error : pull consumer failed to connect");
66 NOTIFICATION_Consumer::~NOTIFICATION_Consumer() {
69 CosNA_StructuredProxyPullSupplier_var proxy = proxy_supplier;
70 proxy_supplier = CosNA_StructuredProxyPullSupplier::_nil();
73 if (!CORBA::is_nil(proxy)) {
74 proxy->disconnect_structured_pull_supplier();
77 MESSAGE("NOTIFICATION Error : while disconnecting proxy pull supplier");
82 bool NOTIFICATION_Consumer::Receive(char** graph, char** node, char** type, char** message, char** sender, long* counter, char** date, long* stamp) {
84 CORBA::Boolean has_event;
85 CosN_StructuredEvent* event;
89 event = proxy_supplier->try_pull_structured_event(has_event);
92 MESSAGE("NOTIFICATION Error : while calling try_pull_structured_event");
99 CORBA::ULong Acounter;
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 = strdup(Agraph);
113 *node = strdup(Anode);
114 *type = strdup(Atype);
115 *message = strdup(Amessage);
116 *sender = strdup(Asender);
117 *counter = (long)Acounter;
118 *date = strdup(Adate);
119 *stamp = (long)Astamp;
126 void NOTIFICATION_Consumer::disconnect_structured_pull_consumer() {
129 void NOTIFICATION_Consumer::offer_change(const CosN_EventTypeSeq& added, const CosN_EventTypeSeq& deled) {