Salome HOME
Revert "Synchronize adm files"
[modules/kernel.git] / src / Notification / NOTIFICATION_Supplier.cxx
1 // Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  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, or (at your option) any later version.
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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  SALOME Notification : wrapping of Notification service services
24 //  File   : NOTIFICATION_Supplier.cxx
25 //  Author : Laurent DADA / Francis KLOSS
26 //  Module : SALOME
27 //
28 #include "NOTIFICATION.hxx"
29
30 long NOTIFICATION_Supplier::_stamp = 0;
31
32 NOTIFICATION_Supplier::NOTIFICATION_Supplier(const char* instanceName, bool notif):
33     _sender(instanceName),
34     _counter(0),
35     proxy_consumer(0),
36     _ok(false)
37 {
38     if (notif) {
39         CosNA_EventChannel_ptr channel = NOTIFICATION_channel();
40         if (CORBA::is_nil(channel)) {
41             MESSAGE("NOTIFICATION Error : failed to get channel for supplier");
42         } else {
43             CosNA_SupplierAdmin_var supplierAdmin = channel->default_supplier_admin();
44
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");
49             } else {
50                 proxy_consumer = CosNA_StructuredProxyPushConsumer::_narrow(consumer);
51                 if ( CORBA::is_nil(proxy_consumer)) {
52                     MESSAGE("NOTIFICATION Error : failed to _narrow proxy push consumer");
53                 } else {
54                     try {
55                         proxy_consumer->connect_structured_push_supplier(_this());
56                         _ok = true;
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");
62                     } catch (...) {
63                         MESSAGE("NOTIFICATION Error : push supplier failed to connect");
64                     }
65                 };
66             };
67         };
68     };
69 }
70
71 NOTIFICATION_Supplier::~NOTIFICATION_Supplier() {
72     if (_ok) {
73         _ok = false;
74         CosNA_StructuredProxyPushConsumer_var proxy = proxy_consumer;
75         proxy_consumer = CosNA_StructuredProxyPushConsumer::_nil();
76
77         try {
78             if (!CORBA::is_nil(proxy)) {
79                 proxy->disconnect_structured_push_consumer();
80             };
81         } catch(...) {
82             MESSAGE("NOTIFICATION Error : while disconnecting proxy push consumer");
83         }
84     };
85 }
86
87 void NOTIFICATION_Supplier::Send(const char* graph, const char* node, const char* type, const char* message) {
88     if (_ok) {
89         _stamp++;
90         _counter++;
91         CosN_StructuredEvent* event = new CosN_StructuredEvent;
92
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");
95
96         event->header.variable_header.length(0);
97
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;
114
115         try {
116             proxy_consumer->push_structured_event(*event);
117         } catch (...) {
118             MESSAGE("NOTIFICATION Error : can't send a message with the component instance : " << _sender);
119         }
120     };
121 }
122
123 void NOTIFICATION_Supplier::disconnect_structured_push_supplier() {
124 }
125
126 void NOTIFICATION_Supplier::subscription_change(const CosN_EventTypeSeq& added, const CosN_EventTypeSeq& deled) {
127 }