Back to index

salome-kernel  6.5.0
NOTIFICATION_Consumer.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_Consumer.cxx
00025 //  Author : Laurent DADA / Francis KLOSS
00026 //  Module : SALOME
00027 //
00028 #include "NOTIFICATION.hxx"
00029 
00030 NOTIFICATION_Consumer::NOTIFICATION_Consumer():
00031     proxy_supplier(0),
00032     _ok(false)
00033 {
00034     CosNA_EventChannel_ptr channel = NOTIFICATION_channel();
00035     if (CORBA::is_nil(channel)) {
00036         MESSAGE("NOTIFICATION Error : failed to get channel for consumer");
00037     } else {
00038         CosNA_ConsumerAdmin_ptr consumerAdmin = channel->default_consumer_admin();
00039 
00040         CosNA_ProxyID proxyId;
00041         CosNotifyChannelAdmin::ProxySupplier_ptr supplier = consumerAdmin->obtain_notification_pull_supplier(CosNA_STRUCTURED_EVENT, proxyId);
00042         if (CORBA::is_nil(supplier)) {
00043             MESSAGE("NOTIFICATION Error : failed to get proxy pull supplier");
00044         } else {
00045             proxy_supplier = CosNA_StructuredProxyPullSupplier::_narrow(supplier);
00046             if (CORBA::is_nil(proxy_supplier)) {
00047                 MESSAGE("NOTIFICATION Error : failed to _narrow proxy pull supplier");
00048             } else {
00049                 try {
00050                     proxy_supplier->connect_structured_pull_consumer(_this());
00051                     _ok = true;
00052                     MESSAGE("NOTIFICATION Info : successfully connection for pull consumer notification");
00053                 } catch (CORBA::BAD_PARAM&) {
00054                     MESSAGE("NOTIFICATION Error : pull consumer BAD_PARAM exception while connecting");
00055                 } catch (CosEventChannelAdmin::AlreadyConnected&) {
00056                     MESSAGE("NOTIFICATION Error : pull consumer already connected");
00057                 } catch (...) {
00058                     MESSAGE("NOTIFICATION Error : pull consumer failed to connect");
00059                 }
00060             };
00061         };
00062     };
00063 }
00064 
00065 NOTIFICATION_Consumer::~NOTIFICATION_Consumer() {
00066     if (_ok) {
00067         _ok = false;
00068         CosNA_StructuredProxyPullSupplier_var proxy = proxy_supplier;
00069         proxy_supplier = CosNA_StructuredProxyPullSupplier::_nil();
00070 
00071         try {
00072             if (!CORBA::is_nil(proxy)) {
00073                 proxy->disconnect_structured_pull_supplier();
00074             };
00075         } catch(...) {
00076             MESSAGE("NOTIFICATION Error : while disconnecting proxy pull supplier");
00077         }
00078     };
00079 }
00080 
00081 bool NOTIFICATION_Consumer::Receive(char** graph, char** node, char** type, char** message, char** sender, long* counter, char** date, long* stamp) {
00082     bool                  status = false;
00083     CORBA::Boolean        has_event;
00084     CosN_StructuredEvent* event;
00085 
00086     if (_ok) {
00087         try {
00088             event  = proxy_supplier->try_pull_structured_event(has_event);
00089             status = has_event;
00090         } catch (...) {
00091             MESSAGE("NOTIFICATION Error : while calling try_pull_structured_event");
00092         };
00093 
00094         if (status) {
00095             //omniORB 4.1.x requiries using only CORBA types instead C types
00096             const char* Asender;
00097             const char* Agraph;
00098             const char* Atype;
00099             CORBA::ULong      Acounter;
00100             CORBA::ULong      Astamp;
00101             const char* Adate;
00102             const char* Anode;
00103             const char* Amessage;           
00104             event->filterable_data[0].value >>= Asender;
00105             event->filterable_data[1].value >>= Agraph;
00106             event->filterable_data[2].value >>= Atype;
00107             event->filterable_data[3].value >>= Acounter;
00108             event->filterable_data[4].value >>= Adate;
00109             event->filterable_data[5].value >>= Anode;
00110             event->filterable_data[6].value >>= Astamp;
00111             event->remainder_of_body        >>= Amessage;
00112             *graph   = CORBA::string_dup(Agraph);
00113             *node    = CORBA::string_dup(Anode);
00114             *type    = CORBA::string_dup(Atype);
00115             *message = CORBA::string_dup(Amessage);
00116             *sender  = CORBA::string_dup(Asender);
00117             *counter = (long)Acounter;
00118             *date    = CORBA::string_dup(Adate);
00119             *stamp   = (long)Astamp;
00120         };
00121     };
00122 
00123     return(status);
00124 }
00125 
00126 void NOTIFICATION_Consumer::disconnect_structured_pull_consumer() {
00127 }
00128 
00129 void NOTIFICATION_Consumer::offer_change(const CosN_EventTypeSeq& added, const CosN_EventTypeSeq& deled) {
00130 }