VRPNModule.cxx
Go to the documentation of this file.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
00027
00028
00029
00030
00031
00032
00033
00034
00035
00042
00043
00044 #include "VRPNModule.h"
00045 #include "VRPNSource.h"
00046 #include "VRPNSink.h"
00047
00048 #ifdef USE_VRPN
00049
00050 #ifdef WIN32
00051 #pragma comment(lib,"vrpn.lib")
00052 #endif
00053
00054
00055
00056 #include <ace/Log_Msg.h>
00057
00058 #include <vrpn_Connection.h>
00059
00060 using namespace std;
00061 using namespace ot;
00062
00063 VRPNModule::VRPNModule() :
00064 Module(),
00065 NodeFactory()
00066 {
00067 }
00068
00069 VRPNModule::~VRPNModule()
00070 {
00071 VRPNSourceVector::iterator it;
00072 for( it = sources.begin(); it != sources.end(); it++ )
00073 {
00074 delete (*it);
00075 }
00076 sources.clear();
00077 VRPNSinkVector::iterator it2;
00078 for( it2 = sinks.begin(); it2 != sinks.end(); it2++ )
00079 {
00080 delete (*it2);
00081 }
00082 sinks.clear();
00083 }
00084
00085 void VRPNModule::init(StringTable & attributes, ConfigNode * localTree)
00086 {
00087 Module::init( attributes, localTree );
00088 if( attributes.get("port", &port ) != 1 )
00089 port = vrpn_DEFAULT_LISTEN_PORT_NO;
00090 ip = attributes.get("interface");
00091 }
00092
00093
00094
00095 ot::Node * VRPNModule::createNode( const std::string& name, StringTable& attributes)
00096 {
00097 ACE_TRACE(ACE_TEXT("VRPNModule::createNode"));
00098 if( name.compare("VRPNSource") == 0 )
00099 {
00100 const string & nameVal = attributes.get("name");
00101 VRPNSource::Type typeVal = VRPNSource::TRACKER;;
00102 if( attributes.get("type").compare("button") == 0 )
00103 typeVal = VRPNSource::BUTTON;
00104 int stationVal = 0;
00105 attributes.get("station", &stationVal);
00106 VRPNSource * source = new VRPNSource;
00107 source->name = nameVal;
00108 source->type = typeVal;
00109 source->station = stationVal;
00110 sources.push_back( source );
00111 return source;
00112 }
00113 else if( name.compare("VRPNSink") == 0 )
00114 {
00115 const string & nameVal = attributes.get("name");
00116 VRPNSink::Type typeVal = VRPNSink::TRACKER;
00117 if( attributes.get("type").compare("button") == 0 )
00118 typeVal = VRPNSink::BUTTON;
00119 int stationVal = 0;
00120 attributes.get("station", &stationVal);
00121 VRPNSink * sink = new VRPNSink;
00122 sink->name = nameVal;
00123 sink->type = typeVal;
00124 sink->station = stationVal;
00125 sinks.push_back( sink );
00126 return sink;
00127 }
00128 return NULL;
00129 }
00130
00131 void VRPNModule::start()
00132 {
00133 ACE_TRACE(ACE_TEXT("VRPNModule::start"));
00134 VRPNSourceVector::iterator it;
00135 for( it = sources.begin(); it != sources.end(); it++ )
00136 {
00137 (*it)->start();
00138 }
00139
00140 if( ip.compare("") == 0 )
00141 connection = new vrpn_Connection( port );
00142 else
00143 connection = new vrpn_Connection( port, NULL, NULL, ip.c_str() );
00144
00145 VRPNSinkVector::iterator it2;
00146 for( it2 = sinks.begin(); it2 != sinks.end(); it2++ )
00147 {
00148 (*it2)->start(connection);
00149 }
00150 }
00151
00152 void VRPNModule::pushEvent()
00153 {
00154 VRPNSourceVector::iterator it;
00155 for( it = sources.begin(); it != sources.end(); it++ )
00156 {
00157 (*it)->mainloop();
00158 }
00159 }
00160
00161 void VRPNModule::pullEvent()
00162 {
00163 ACE_TRACE(ACE_TEXT("VRPNModule::pullEvent"));
00164 VRPNSinkVector::iterator it;
00165 for( it = sinks.begin(); it != sinks.end(); it++ )
00166 {
00167 (*it)->mainloop();
00168 }
00169 connection->mainloop();
00170 }
00171
00172 #else
00173 #pragma message(">>> no VRPN support")
00174 #endif
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190