1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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, or (at your option) any later version.
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.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SALOME Notification : wrapping of Notification service services
24 // File : NOTIFICATION_Consumer.cxx
25 // Author : Laurent DADA / Francis KLOSS
28 #include "NOTIFICATION.hxx"
30 NOTIFICATION_Consumer::NOTIFICATION_Consumer():
34 CosNA_EventChannel_ptr channel = NOTIFICATION_channel();
35 if (CORBA::is_nil(channel)) {
36 MESSAGE("NOTIFICATION Error : failed to get channel for consumer");
38 CosNA_ConsumerAdmin_ptr consumerAdmin = channel->default_consumer_admin();
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");
45 proxy_supplier = CosNA_StructuredProxyPullSupplier::_narrow(supplier);
46 if (CORBA::is_nil(proxy_supplier)) {
47 MESSAGE("NOTIFICATION Error : failed to _narrow proxy pull supplier");
50 proxy_supplier->connect_structured_pull_consumer(_this());
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");
58 MESSAGE("NOTIFICATION Error : pull consumer failed to connect");
65 NOTIFICATION_Consumer::~NOTIFICATION_Consumer() {
68 CosNA_StructuredProxyPullSupplier_var proxy = proxy_supplier;
69 proxy_supplier = CosNA_StructuredProxyPullSupplier::_nil();
72 if (!CORBA::is_nil(proxy)) {
73 proxy->disconnect_structured_pull_supplier();
76 MESSAGE("NOTIFICATION Error : while disconnecting proxy pull supplier");
81 bool NOTIFICATION_Consumer::Receive(char** graph, char** node, char** type, char** message, char** sender, long* counter, char** date, long* stamp) {
83 CORBA::Boolean has_event;
84 CosN_StructuredEvent* event;
88 event = proxy_supplier->try_pull_structured_event(has_event);
91 MESSAGE("NOTIFICATION Error : while calling try_pull_structured_event");
95 //omniORB 4.1.x requiries using only CORBA types instead C types
99 CORBA::ULong Acounter;
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;
126 void NOTIFICATION_Consumer::disconnect_structured_pull_consumer() {
129 void NOTIFICATION_Consumer::offer_change(const CosN_EventTypeSeq& added, const CosN_EventTypeSeq& deled) {