PushSupp.h

Go to the documentation of this file.
00001 /* ======================================================================== 
00002  * Copyright (C) 2006  Graz University of Technology
00003  *
00004  * This framework is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License as published by
00006  * the Free Software Foundation; either version 2 of the License, or
00007  * (at your option) any later version.
00008  *
00009  * This framework is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this framework; if not, write to the Free Software
00016  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017  *
00018  * For further information please contact 
00019  * Dieter Schmalstieg
00020  * <schmalstieg@icg.tu-graz.ac.at>
00021  * Graz University of Technology, 
00022  * Institut for Computer Graphics and Vision,
00023  * Inffeldgasse 16a, 8010 Graz, Austria.
00024  * ========================================================================
00025  * PROJECT: OpenTracker
00026  * ======================================================================== */
00033  /* ======================================================================= */
00034 
00049 #ifndef _PUSHSUPP_H
00050 #define _PUSHSUPP_H
00051 
00052 #include <OpenTracker/OpenTracker.h>
00053 #include <OpenTracker/tool/OT_ACE_Log.h>
00054 #include <OpenTracker/skeletons/OT_CORBA.hh>
00055 #include <OpenTracker/network/CORBAUtils.h>
00056 #include <omniEvents/CosEventComm.hh>
00057 #include <omniEvents/CosEventChannelAdmin.hh>
00058 
00067 namespace ot {
00068 
00069 class CORBAModule;
00070 
00071 class Supplier_i : virtual public POA_CosEventComm::PushSupplier {
00072 public:
00073   Supplier_i () {};
00074   void disconnect_push_supplier () {
00075     logPrintI("Push Supplier: disconnected.\n");
00076   };
00077 };
00078 
00079 class OPENTRACKER_API PushSupp : public Node
00080 {
00081 // Members
00082 public:
00084   CosEventChannelAdmin::EventChannel_var channel;
00085   CosEventChannelAdmin::SupplierAdmin_var supplier_admin;
00086   CosEventChannelAdmin::ProxyPushConsumer_var proxy_consumer;
00087   CosEventComm::PushSupplier_var sptr;
00088   Supplier_i* supplier;
00089   int cycle;
00090     
00091 
00092 // Methods
00093 protected:
00097     PushSupp( CosEventChannelAdmin::EventChannel_var channel_) :
00098         Node(), 
00099         channel( channel_ ),
00100         cycle ( 0 )
00101     {
00102       supplier = new Supplier_i();
00103       try {
00104         supplier_admin = CORBAUtils::getSupplierAdmin(channel);
00105       } catch (CORBA::INV_OBJREF) {
00106         LOG_ACE_ERROR("Object reference of event channel is internally malformed. Exiting....\n");
00107         exit(-1);
00108       } 
00109       proxy_consumer = CORBAUtils::getProxyPushConsumer(supplier_admin);
00110       CosEventComm::PushSupplier_var sptr = supplier->_this();
00111       CORBAUtils::connectPushSupplier(proxy_consumer, sptr);
00112     }
00113     virtual ~PushSupp() {
00114       CORBAUtils::disconnectPushSupplier(proxy_consumer);
00115       delete supplier;
00116       logPrintI("PushSupp destructor");
00117     }
00118 
00119 public:
00123     virtual int isEventGenerator()
00124     {
00125       return 1;
00126       //return 0;
00127     }
00128     
00138     virtual void onEventGenerated( Event& event, Node& generator)
00139     {
00140       cycle++;
00141       //OT_CORBA::Event* corba_event = new OT_CORBA::Event;
00142       //CORBAUtils::convertToCORBAEvent(event, *corba_event);
00143       OT_CORBA::Event corba_event = event.getCORBAEvent();
00144       try {
00145         CORBA::Any any;
00146         any <<= corba_event;
00147         proxy_consumer->push(any);
00148       }
00149       catch (CORBA::COMM_FAILURE) {
00150         logPrintE("Caught CORBA::COMM_FAILURE\n");
00151       }
00152       catch (CORBA::TRANSIENT) {
00153         logPrintE("Caught CORBA::TRANSIENT\n");
00154       }
00155       updateObservers( event );
00156     }
00157     
00158     friend class CORBAModule;
00159 };
00160 
00161 }
00162 
00163 #endif

Generated on Wed Feb 28 15:18:51 2007 for NaviTrack by  doxygen 1.4.6