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