00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <debug.h>
00024 #include <corbainit.h>
00025 #include <segfaulthandler.h>
00026 #include <dwarfutil.h>
00027 #include <ErrorVisualizerService.h>
00028 #include <algorithm>
00029 #include <ubitrack/EasyPoseData.h>
00030
00031 using std::string;
00032 using namespace DWARF;
00033
00034
00035 ErrorVisualizerService::ErrorVisualizerService()
00036 : m_ViewerNeed( this )
00037 {
00038 DEBUGSTREAM( 5, "Constructor called." );
00039 }
00040
00041
00042 ErrorVisualizerService::~ErrorVisualizerService()
00043 {
00044 DEBUGSTREAM( 5, "Destructor called." );
00045 }
00046
00047
00048 CORBA::Object_ptr ErrorVisualizerService::createNeedObject( DWARF::NeedDescription_ptr needDescr )
00049 {
00050 if ( needDescr->getName() == string( "Viewer" ) )
00051 return m_ViewerNeed._this();
00052 else
00053
00054 return PoseService::createNeedObject( needDescr );
00055 }
00056
00057
00058 void ErrorVisualizerService::onImport( DWARF::ViewerControl_ptr pInterface,
00059 ObjrefImporterNeed<DWARF::ViewerControl>* pImporter )
00060 {
00061 DEBUGSTREAM( 5, "Got a viewer" );
00062 omni_mutex_lock l( m_Mutex );
00063
00064
00065 for ( auto_vector< ErrorPoseAbility >::iterator it = m_Abilities.begin();
00066 it != m_Abilities.end(); it++ )
00067 (*it)->SetViewer( m_ViewerNeed.getInterface() );
00068 }
00069
00070
00071 void ErrorVisualizerService::onEvent( PoseData& P )
00072 {
00073 if ( !EasyPoseData::isSane( P ) )
00074 {
00075 DEBUGSTREAM( 5, "Got insane pose - check sender!" );
00076 return;
00077 }
00078
00079 omni_mutex_lock l( m_Mutex );
00080
00081
00082 string sID = string( P.source ) + "&" + string( P.target );
00083 AbilityMapT::iterator it = m_AbilityMap.find( sID );
00084 DEBUGSTREAM( 20, "Got event: " << sID );
00085
00086 if ( it != m_AbilityMap.end() )
00087
00088 if ( m_ViewerNeed.hasInterface() )
00089 it->second->TransformAndSendEvent( P );
00090 else;
00091 else
00092 {
00093
00094 ActiveServiceDescription_var ServiceDesc( getServiceDesc() );
00095 m_Abilities.push_back( std::auto_ptr<ErrorPoseAbility>(
00096 new ErrorPoseAbility( P.source, P.target, ServiceDesc ) ) );
00097 m_AbilityMap[ sID ] = m_Abilities.back();
00098
00099
00100 if ( m_ViewerNeed.hasInterface() )
00101 m_Abilities.back()->SetViewer( m_ViewerNeed.getInterface() );
00102
00103
00104 }
00105 }
00106
00107
00108 void ErrorVisualizerService::run()
00109 {
00110 while( m_shouldRun )
00111 sleep( 1 );
00112 }
00113
00114
00115 int main( int argc, char** argv )
00116 {
00117 registerSegFaultHandler();
00118
00119
00120 CorbaInit *myOrbConnection = CorbaInit::initializeOrb( argc, argv );
00121 ErrorVisualizerService MyService;
00122 myOrbConnection->registerService( "ErrorVisualizer", MyService._this() );
00123 myOrbConnection->run();
00124 myOrbConnection->destroy();
00125
00126 return 0;
00127 }
00128