Salome HOME
NRI : Add Loader.
[modules/kernel.git] / src / Notification / NOTIFICATION_Supplier.cxx
1 using namespace std;
2 //  File      : NOTIFICATION_Supplier.cxx
3 //  Created   : 1 Avril 2002
4 //  Author    : Laurent DADA / Francis KLOSS
5 //  Project   : SALOME
6 //  Module    : Notification Supplier
7 //  Copyright : CEA / Open CASCADE
8
9 #include "NOTIFICATION.hxx"
10
11 long NOTIFICATION_Supplier::_stamp = 0;
12
13 NOTIFICATION_Supplier::NOTIFICATION_Supplier(const char* instanceName, bool notif):
14     _sender(instanceName),
15     _counter(0),
16     proxy_consumer(0),
17     _ok(false)
18 {
19     if (notif) {
20         CosNA_EventChannel_ptr channel = NOTIFICATION_channel();
21         if (CORBA::is_nil(channel)) {
22             MESSAGE("NOTIFICATION Error : failed to get channel for supplier");
23         } else {
24             CosNA_SupplierAdmin_var supplierAdmin = channel->default_supplier_admin();
25
26             CosNA_ProxyID proxyId;
27             CosNotifyChannelAdmin::ProxyConsumer_ptr consumer = supplierAdmin->obtain_notification_push_consumer(CosNA_STRUCTURED_EVENT, proxyId);
28             if (CORBA::is_nil(consumer)) {
29                 MESSAGE("NOTIFICATION Error : failed to get proxy push consumer");
30             } else {
31                 proxy_consumer = CosNA_StructuredProxyPushConsumer::_narrow(consumer);
32                 if ( CORBA::is_nil(proxy_consumer)) {
33                     MESSAGE("NOTIFICATION Error : failed to _narrow proxy push consumer");
34                 } else {
35                     try {
36                         proxy_consumer->connect_structured_push_supplier(_this());
37                         _ok = true;
38                         MESSAGE("NOTIFICATION Info : successfully connection for push supplier notification");
39                     } catch (CORBA::BAD_PARAM& ex) {
40                         MESSAGE("NOTIFICATION Error : push supplier BAD_PARAM Exception while connecting");
41                     } catch (CosEventChannelAdmin::AlreadyConnected& ex) {
42                         MESSAGE("NOTIFICATION Error : push supplier already connected");
43                     } catch (...) {
44                         MESSAGE("NOTIFICATION Error : push supplier failed to connect");
45                     }
46                 };
47             };
48         };
49     };
50 }
51
52 NOTIFICATION_Supplier::~NOTIFICATION_Supplier() {
53     if (_ok) {
54         _ok = false;
55         CosNA_StructuredProxyPushConsumer_var proxy = proxy_consumer;
56         proxy_consumer = CosNA_StructuredProxyPushConsumer::_nil();
57
58         try {
59             if (!CORBA::is_nil(proxy)) {
60                 proxy->disconnect_structured_push_consumer();
61             };
62         } catch(...) {
63             MESSAGE("NOTIFICATION Error : while disconnecting proxy push consumer");
64         }
65     };
66 }
67
68 void NOTIFICATION_Supplier::Send(const char* graph, const char* node, const char* type, const char* message) {
69     if (_ok) {
70         _stamp++;
71         _counter++;
72         CosN_StructuredEvent* event = new CosN_StructuredEvent;
73
74         event->header.fixed_header.event_type.domain_name = CORBA::string_dup("SALOME");
75         event->header.fixed_header.event_type.type_name   = CORBA::string_dup("ComponentMessage");
76
77         event->header.variable_header.length(0);
78
79         event->filterable_data.length(7);
80         event->filterable_data[0].name    = CORBA::string_dup("SenderName");
81         event->filterable_data[0].value <<= _sender;
82         event->filterable_data[1].name    = CORBA::string_dup("DestinationGroup");
83         event->filterable_data[1].value <<= graph;
84         event->filterable_data[2].name    = CORBA::string_dup("EventType");
85         event->filterable_data[2].value <<= type;
86         event->filterable_data[3].name    = CORBA::string_dup("EventNumber");
87         event->filterable_data[3].value <<= (CORBA::ULong)_counter;
88         event->filterable_data[4].name    = CORBA::string_dup("SendingDate");
89         event->filterable_data[4].value <<= (const char*)NOTIFICATION_date();
90         event->filterable_data[5].name    = CORBA::string_dup("DepartGroup");
91         event->filterable_data[5].value <<= node;
92         event->filterable_data[6].name    = CORBA::string_dup("Stamp");
93         event->filterable_data[6].value <<= (CORBA::ULong)_stamp;
94         event->remainder_of_body        <<= message;
95
96         try {
97             proxy_consumer->push_structured_event(*event);
98         } catch (...) {
99             MESSAGE("NOTIFICATION Error : can't send a message with the component instance : " << _sender);
100         }
101     };
102 }
103
104 void NOTIFICATION_Supplier::disconnect_structured_push_supplier() {
105 }
106
107 void NOTIFICATION_Supplier::subscription_change(const CosN_EventTypeSeq& added, const CosN_EventTypeSeq& deled) {
108 }