1 // Copyright (C) 2007-2024 CEA, EDF, 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_Supplier.cxx
25 // Author : Laurent DADA / Francis KLOSS
28 #include "NOTIFICATION.hxx"
30 long NOTIFICATION_Supplier::_stamp = 0;
32 NOTIFICATION_Supplier::NOTIFICATION_Supplier(const char* instanceName, bool notif):
34 _sender(instanceName),
39 CosNA_EventChannel_ptr channel = NOTIFICATION_channel();
40 if (CORBA::is_nil(channel)) {
41 MESSAGE("NOTIFICATION Error : failed to get channel for supplier");
43 CosNA_SupplierAdmin_var supplierAdmin = channel->default_supplier_admin();
45 CosNA_ProxyID proxyId;
46 CosNotifyChannelAdmin::ProxyConsumer_ptr consumer = supplierAdmin->obtain_notification_push_consumer(CosNA_STRUCTURED_EVENT, proxyId);
47 if (CORBA::is_nil(consumer)) {
48 MESSAGE("NOTIFICATION Error : failed to get proxy push consumer");
50 proxy_consumer = CosNA_StructuredProxyPushConsumer::_narrow(consumer);
51 if ( CORBA::is_nil(proxy_consumer)) {
52 MESSAGE("NOTIFICATION Error : failed to _narrow proxy push consumer");
55 proxy_consumer->connect_structured_push_supplier(_this());
57 MESSAGE("NOTIFICATION Info : successfully connection for push supplier notification");
58 } catch (CORBA::BAD_PARAM&) {
59 MESSAGE("NOTIFICATION Error : push supplier BAD_PARAM Exception while connecting");
60 } catch (CosEventChannelAdmin::AlreadyConnected&) {
61 MESSAGE("NOTIFICATION Error : push supplier already connected");
63 MESSAGE("NOTIFICATION Error : push supplier failed to connect");
71 NOTIFICATION_Supplier::~NOTIFICATION_Supplier() {
74 CosNA_StructuredProxyPushConsumer_var proxy = proxy_consumer;
75 proxy_consumer = CosNA_StructuredProxyPushConsumer::_nil();
78 if (!CORBA::is_nil(proxy)) {
79 proxy->disconnect_structured_push_consumer();
82 MESSAGE("NOTIFICATION Error : while disconnecting proxy push consumer");
87 void NOTIFICATION_Supplier::Send(const char* graph, const char* node, const char* type, const char* message) {
91 CosN_StructuredEvent* event = new CosN_StructuredEvent;
93 event->header.fixed_header.event_type.domain_name = CORBA::string_dup("SALOME");
94 event->header.fixed_header.event_type.type_name = CORBA::string_dup("ComponentMessage");
96 event->header.variable_header.length(0);
98 event->filterable_data.length(7);
99 event->filterable_data[0].name = CORBA::string_dup("SenderName");
100 event->filterable_data[0].value <<= _sender;
101 event->filterable_data[1].name = CORBA::string_dup("DestinationGroup");
102 event->filterable_data[1].value <<= graph;
103 event->filterable_data[2].name = CORBA::string_dup("EventType");
104 event->filterable_data[2].value <<= type;
105 event->filterable_data[3].name = CORBA::string_dup("EventNumber");
106 event->filterable_data[3].value <<= (CORBA::ULong)_counter;
107 event->filterable_data[4].name = CORBA::string_dup("SendingDate");
108 event->filterable_data[4].value <<= (const char*)NOTIFICATION_date();
109 event->filterable_data[5].name = CORBA::string_dup("DepartGroup");
110 event->filterable_data[5].value <<= node;
111 event->filterable_data[6].name = CORBA::string_dup("Stamp");
112 event->filterable_data[6].value <<= (CORBA::ULong)_stamp;
113 event->remainder_of_body <<= message;
116 proxy_consumer->push_structured_event(*event);
118 MESSAGE("NOTIFICATION Error : can't send a message with the component instance : " << _sender);
123 void NOTIFICATION_Supplier::disconnect_structured_push_supplier() {
126 void NOTIFICATION_Supplier::subscription_change(const CosN_EventTypeSeq& /*added*/, const CosN_EventTypeSeq& /*deled*/) {