00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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
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
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
00114 }
00115
00125 virtual void onEventGenerated( Event& event, Node& generator)
00126 {
00127 cycle++;
00128 Shared::FieldUpdate shared_event;
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
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
00155 }
00156
00157 friend class CORBAModule;
00158 };
00159
00160 }
00161
00162 #endif