Back to index

salome-kernel  6.5.0
NOTIFICATION_Supplier.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  SALOME Notification : wrapping of Notification service services
00024 //  File   : NOTIFICATION_Supplier.cxx
00025 //  Author : Laurent DADA / Francis KLOSS
00026 //  Module : SALOME
00027 //
00028 #include "NOTIFICATION.hxx"
00029 
00030 long NOTIFICATION_Supplier::_stamp = 0;
00031 
00032 NOTIFICATION_Supplier::NOTIFICATION_Supplier(const char* instanceName, bool notif):
00033     _sender(instanceName),
00034     _counter(0),
00035     proxy_consumer(0),
00036     _ok(false)
00037 {
00038     if (notif) {
00039         CosNA_EventChannel_ptr channel = NOTIFICATION_channel();
00040         if (CORBA::is_nil(channel)) {
00041             MESSAGE("NOTIFICATION Error : failed to get channel for supplier");
00042         } else {
00043             CosNA_SupplierAdmin_var supplierAdmin = channel->default_supplier_admin();
00044 
00045             CosNA_ProxyID proxyId;
00046             CosNotifyChannelAdmin::ProxyConsumer_ptr consumer = supplierAdmin->obtain_notification_push_consumer(CosNA_STRUCTURED_EVENT, proxyId);
00047             if (CORBA::is_nil(consumer)) {
00048                 MESSAGE("NOTIFICATION Error : failed to get proxy push consumer");
00049             } else {
00050                 proxy_consumer = CosNA_StructuredProxyPushConsumer::_narrow(consumer);
00051                 if ( CORBA::is_nil(proxy_consumer)) {
00052                     MESSAGE("NOTIFICATION Error : failed to _narrow proxy push consumer");
00053                 } else {
00054                     try {
00055                         proxy_consumer->connect_structured_push_supplier(_this());
00056                         _ok = true;
00057                         MESSAGE("NOTIFICATION Info : successfully connection for push supplier notification");
00058                     } catch (CORBA::BAD_PARAM&) {
00059                         MESSAGE("NOTIFICATION Error : push supplier BAD_PARAM Exception while connecting");
00060                     } catch (CosEventChannelAdmin::AlreadyConnected&) {
00061                         MESSAGE("NOTIFICATION Error : push supplier already connected");
00062                     } catch (...) {
00063                         MESSAGE("NOTIFICATION Error : push supplier failed to connect");
00064                     }
00065                 };
00066             };
00067         };
00068     };
00069 }
00070 
00071 NOTIFICATION_Supplier::~NOTIFICATION_Supplier() {
00072     if (_ok) {
00073         _ok = false;
00074         CosNA_StructuredProxyPushConsumer_var proxy = proxy_consumer;
00075         proxy_consumer = CosNA_StructuredProxyPushConsumer::_nil();
00076 
00077         try {
00078             if (!CORBA::is_nil(proxy)) {
00079                 proxy->disconnect_structured_push_consumer();
00080             };
00081         } catch(...) {
00082             MESSAGE("NOTIFICATION Error : while disconnecting proxy push consumer");
00083         }
00084     };
00085 }
00086 
00087 void NOTIFICATION_Supplier::Send(const char* graph, const char* node, const char* type, const char* message) {
00088     if (_ok) {
00089         _stamp++;
00090         _counter++;
00091         CosN_StructuredEvent* event = new CosN_StructuredEvent;
00092 
00093         event->header.fixed_header.event_type.domain_name = CORBA::string_dup("SALOME");
00094         event->header.fixed_header.event_type.type_name   = CORBA::string_dup("ComponentMessage");
00095 
00096         event->header.variable_header.length(0);
00097 
00098         event->filterable_data.length(7);
00099         event->filterable_data[0].name    = CORBA::string_dup("SenderName");
00100         event->filterable_data[0].value <<= _sender;
00101         event->filterable_data[1].name    = CORBA::string_dup("DestinationGroup");
00102         event->filterable_data[1].value <<= graph;
00103         event->filterable_data[2].name    = CORBA::string_dup("EventType");
00104         event->filterable_data[2].value <<= type;
00105         event->filterable_data[3].name    = CORBA::string_dup("EventNumber");
00106         event->filterable_data[3].value <<= (CORBA::ULong)_counter;
00107         event->filterable_data[4].name    = CORBA::string_dup("SendingDate");
00108         event->filterable_data[4].value <<= (const char*)NOTIFICATION_date();
00109         event->filterable_data[5].name    = CORBA::string_dup("DepartGroup");
00110         event->filterable_data[5].value <<= node;
00111         event->filterable_data[6].name    = CORBA::string_dup("Stamp");
00112         event->filterable_data[6].value <<= (CORBA::ULong)_stamp;
00113         event->remainder_of_body        <<= message;
00114 
00115         try {
00116             proxy_consumer->push_structured_event(*event);
00117         } catch (...) {
00118             MESSAGE("NOTIFICATION Error : can't send a message with the component instance : " << _sender);
00119         }
00120     };
00121 }
00122 
00123 void NOTIFICATION_Supplier::disconnect_structured_push_supplier() {
00124 }
00125 
00126 void NOTIFICATION_Supplier::subscription_change(const CosN_EventTypeSeq& added, const CosN_EventTypeSeq& deled) {
00127 }