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
00052 #ifndef _PHANTOMMIDDLEWARESOURCE_H
00053 #define _PHANTOMMIDDLEWARESOURCE_H
00054
00055 #include <cmath>
00056
00057 #include <OpenTracker/OpenTracker.h>
00058 #include <OpenTracker/tool/OT_ACE_Log.h>
00059 #include <ace/Thread_Mutex.h>
00060 #include <phantom/MulticastSocket.hh>
00061 #include <phantom/PhantomMessageV1.hh>
00062
00071 namespace ot {
00072
00073 class PhantomMiddlewareModule;
00074
00075 class OPENTRACKER_API PhantomMiddlewareSource : public Node
00076 {
00077
00078 public:
00081 Event event;
00082
00083 int pid;
00084 short eid;
00085 std::string source;
00086
00087
00088
00089
00090 protected:
00094 PhantomMiddlewareSource( const char* multicast_group, int pid_, short eid_, const std::string& source_) :
00095 Node(),
00096 pid( pid_ ),
00097 eid( eid_ ),
00098 source( source_ )
00099 {
00100 mu = new ACE_Thread_Mutex("phantommiddlewaresource");
00101 }
00102
00103
00104 PhantomMiddlewareSource( const char* multicast_group, int pid_, short eid_) :
00105 Node(),
00106 pid( pid_ ),
00107 eid( eid_ )
00108 {
00109 mu = new ACE_Thread_Mutex("phantommiddlewaresource");
00110 source = "";
00111 }
00112
00113
00114 virtual ~PhantomMiddlewareSource() {
00115
00116 delete mu;
00117 logPrintE("PhantomMiddlewareSource destructor\n");
00118 }
00119 private:
00120 ACE_Thread_Mutex* mu;
00121 bool modified;
00122
00123 public:
00124 void lock() { mu->acquire(); };
00125 void unlock() { mu->release(); };
00126 bool isModified() {return modified;};
00127 void setEvent(float x, float y, float z, float theta, int t1, int t2, short event_id, char* event_source) {
00128
00129 setEvent(x, y, z, theta, t1, t2, event_id);
00130
00131 };
00132
00133 void setEvent(float x, float y, float z, float alpha, int t1, int t2, short event_id) {
00134
00135 std::vector<float> position(3);
00136 std::vector<float> orientation(4);
00137 position[0] = x; position[1] = z; position[2] = -y;
00138 float theta = 180.0f - alpha;
00139 float thetaby2 = theta * MathUtils::GradToRad / 2.0;
00140 orientation[0] = 0.0;
00141 orientation[1] = sin(thetaby2);
00142 orientation[2] = 0.0;
00143 orientation[3] = cos(thetaby2);
00144 lock();
00145 event.setPosition(position);
00146 event.setOrientation(orientation);
00147 event.time = (double) t1 + ((double) t2)/1000000.0;
00148 modified=true;
00149 unlock();
00150
00151 };
00152
00153
00154 int getEventId() {
00155 return eid;
00156 }
00157
00158 void push()
00159 {
00160 lock();
00161 if (modified) {
00162 updateObservers( event );
00163 modified = false;
00164 }
00165 unlock();
00166 }
00170 virtual int isEventGenerator()
00171 {
00172 return 1;
00173 }
00174
00175 friend class PhantomMiddlewareModule;
00176 friend class PhantomListener;
00177 };
00178
00179 }
00180
00181 #endif