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.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // File : NOTIFICATION_Supplier.cxx
25 // Author : Laurent DADA / Francis KLOSS
28 #include "NOTIFICATION.hxx"
31 long NOTIFICATION_Supplier::_stamp = 0;
33 NOTIFICATION_Supplier::NOTIFICATION_Supplier(const char* instanceName, bool notif):
34 _sender(instanceName),
40 CosNA_EventChannel_ptr channel = NOTIFICATION_channel();
41 if (CORBA::is_nil(channel)) {
42 MESSAGE("NOTIFICATION Error : failed to get channel for supplier");
44 CosNA_SupplierAdmin_var supplierAdmin = channel->default_supplier_admin();
46 CosNA_ProxyID proxyId;
47 CosNotifyChannelAdmin::ProxyConsumer_ptr consumer = supplierAdmin->obtain_notification_push_consumer(CosNA_STRUCTURED_EVENT, proxyId);
48 if (CORBA::is_nil(consumer)) {
49 MESSAGE("NOTIFICATION Error : failed to get proxy push consumer");
51 proxy_consumer = CosNA_StructuredProxyPushConsumer::_narrow(consumer);
52 if ( CORBA::is_nil(proxy_consumer)) {
53 MESSAGE("NOTIFICATION Error : failed to _narrow proxy push consumer");
56 proxy_consumer->connect_structured_push_supplier(_this());
58 MESSAGE("NOTIFICATION Info : successfully connection for push supplier notification");
59 } catch (CORBA::BAD_PARAM& ex) {
60 MESSAGE("NOTIFICATION Error : push supplier BAD_PARAM Exception while connecting");
61 } catch (CosEventChannelAdmin::AlreadyConnected& ex) {
62 MESSAGE("NOTIFICATION Error : push supplier already connected");
64 MESSAGE("NOTIFICATION Error : push supplier failed to connect");
72 NOTIFICATION_Supplier::~NOTIFICATION_Supplier() {
75 CosNA_StructuredProxyPushConsumer_var proxy = proxy_consumer;
76 proxy_consumer = CosNA_StructuredProxyPushConsumer::_nil();
79 if (!CORBA::is_nil(proxy)) {
80 proxy->disconnect_structured_push_consumer();
83 MESSAGE("NOTIFICATION Error : while disconnecting proxy push consumer");
88 void NOTIFICATION_Supplier::Send(const char* graph, const char* node, const char* type, const char* message) {
92 CosN_StructuredEvent* event = new CosN_StructuredEvent;
94 event->header.fixed_header.event_type.domain_name = CORBA::string_dup("SALOME");
95 event->header.fixed_header.event_type.type_name = CORBA::string_dup("ComponentMessage");
97 event->header.variable_header.length(0);
99 event->filterable_data.length(7);
100 event->filterable_data[0].name = CORBA::string_dup("SenderName");
101 event->filterable_data[0].value <<= _sender;
102 event->filterable_data[1].name = CORBA::string_dup("DestinationGroup");
103 event->filterable_data[1].value <<= graph;
104 event->filterable_data[2].name = CORBA::string_dup("EventType");
105 event->filterable_data[2].value <<= type;
106 event->filterable_data[3].name = CORBA::string_dup("EventNumber");
107 event->filterable_data[3].value <<= (CORBA::ULong)_counter;
108 event->filterable_data[4].name = CORBA::string_dup("SendingDate");
109 event->filterable_data[4].value <<= (const char*)NOTIFICATION_date();
110 event->filterable_data[5].name = CORBA::string_dup("DepartGroup");
111 event->filterable_data[5].value <<= node;
112 event->filterable_data[6].name = CORBA::string_dup("Stamp");
113 event->filterable_data[6].value <<= (CORBA::ULong)_stamp;
114 event->remainder_of_body <<= message;
117 proxy_consumer->push_structured_event(*event);
119 MESSAGE("NOTIFICATION Error : can't send a message with the component instance : " << _sender);
124 void NOTIFICATION_Supplier::disconnect_structured_push_supplier() {
127 void NOTIFICATION_Supplier::subscription_change(const CosN_EventTypeSeq& added, const CosN_EventTypeSeq& deled) {