SharedEngineNode.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 _SHAREDENGINENODE_H
00050 #define _SHAREDENGINENODE_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 #include <shared/shared.hh>
00059 
00068 namespace ot {
00069 
00070 class CORBAModule;
00071 
00072 class OPENTRACKER_API SharedEngineNode : public Node
00073 {
00074 // Members
00075 public:
00077   CosEventChannelAdmin::EventChannel_var channel;
00078   CosEventChannelAdmin::SupplierAdmin_var supplier_admin;
00079   CosEventChannelAdmin::ProxyPushConsumer_var proxy_consumer;
00080   CosEventComm::PushSupplier_var sptr;
00081   Supplier_i* supplier;
00082   int cycle;
00083     
00084 
00085 // Methods
00086 protected:
00090     SharedEngineNode( CosEventChannelAdmin::EventChannel_var channel_) :
00091         Node(), 
00092         channel( channel_ ),
00093         cycle ( 0 )
00094     {
00095       supplier = new Supplier_i();
00096       supplier_admin = CORBAUtils::getSupplierAdmin(channel);
00097       proxy_consumer = CORBAUtils::getProxyPushConsumer(supplier_admin);
00098       CosEventComm::PushSupplier_var sptr = supplier->_this();
00099       CORBAUtils::connectPushSupplier(proxy_consumer, sptr);
00100     }
00101     virtual ~SharedEngineNode() {
00102       CORBAUtils::disconnectPushSupplier(proxy_consumer);
00103       delete supplier;
00104     }
00105 
00106 public:
00110     virtual int isEventGenerator()
00111     {
00112       return 1;
00113       //return 0;
00114     }
00115     
00125     virtual void onEventGenerated( Event& event, Node& generator)
00126     {
00127       cycle++;
00128       Shared::FieldUpdate shared_event;// = new Shared::FieldUpdate;
00129       try {
00130         shared_event.supplier = CosEventComm::PushSupplier::_duplicate(sptr);
00131         shared_event.value.length(2);
00132         char s1[100];
00133         char s2[100];
00134         std::vector<float> position = event.getPosition();
00135         std::vector<float> quaternion = event.getOrientation();
00136         std::vector<float> orientation(4);
00137         MathUtils::quaternionToAxisAngle(quaternion, orientation);
00138         sprintf(s1,"%f %f %f %f", orientation[0], orientation[1], orientation[2], orientation[3]);
00139         //sprintf(s1,"%f %f %f %f", quaternion[0], quaternion[1], quaternion[2], quaternion[3]);
00140         sprintf(s2,"%f %f %f", position[0], position[1], position[2]);
00141         shared_event.value[0] = CORBA::string_dup((const char*) s2);
00142         shared_event.value[1] = CORBA::string_dup((const char*) s1);
00143         CORBA::Any any;
00144         any <<= shared_event;
00145         proxy_consumer->push(any);
00146       }
00147       catch (CORBA::COMM_FAILURE) {
00148         logPrintE("Caught CORBA::COMM_FAILURE\n");
00149       }
00150       catch (CORBA::TRANSIENT) {
00151         logPrintE("Caught CORBA::TRANSIENT\n");
00152       }
00153       updateObservers( event );
00154       //delete corba_event;
00155     }
00156     
00157     friend class CORBAModule;
00158 };
00159 
00160 }
00161 
00162 #endif

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