2 // File : NOTIFICATION_Supplier.cxx
3 // Created : 1 Avril 2002
4 // Author : Laurent DADA / Francis KLOSS
6 // Module : Notification Supplier
7 // Copyright : CEA / Open CASCADE
9 #include "NOTIFICATION.hxx"
11 long NOTIFICATION_Supplier::_stamp = 0;
13 NOTIFICATION_Supplier::NOTIFICATION_Supplier(const char* instanceName, bool notif):
14 _sender(instanceName),
20 CosNA_EventChannel_ptr channel = NOTIFICATION_channel();
21 if (CORBA::is_nil(channel)) {
22 MESSAGE("NOTIFICATION Error : failed to get channel for supplier");
24 CosNA_SupplierAdmin_var supplierAdmin = channel->default_supplier_admin();
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");
31 proxy_consumer = CosNA_StructuredProxyPushConsumer::_narrow(consumer);
32 if ( CORBA::is_nil(proxy_consumer)) {
33 MESSAGE("NOTIFICATION Error : failed to _narrow proxy push consumer");
36 proxy_consumer->connect_structured_push_supplier(_this());
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");
44 MESSAGE("NOTIFICATION Error : push supplier failed to connect");
52 NOTIFICATION_Supplier::~NOTIFICATION_Supplier() {
55 CosNA_StructuredProxyPushConsumer_var proxy = proxy_consumer;
56 proxy_consumer = CosNA_StructuredProxyPushConsumer::_nil();
59 if (!CORBA::is_nil(proxy)) {
60 proxy->disconnect_structured_push_consumer();
63 MESSAGE("NOTIFICATION Error : while disconnecting proxy push consumer");
68 void NOTIFICATION_Supplier::Send(const char* graph, const char* node, const char* type, const char* message) {
72 CosN_StructuredEvent* event = new CosN_StructuredEvent;
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");
77 event->header.variable_header.length(0);
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;
97 proxy_consumer->push_structured_event(*event);
99 MESSAGE("NOTIFICATION Error : can't send a message with the component instance : " << _sender);
104 void NOTIFICATION_Supplier::disconnect_structured_push_supplier() {
107 void NOTIFICATION_Supplier::subscription_change(const CosN_EventTypeSeq& added, const CosN_EventTypeSeq& deled) {