void Receiver::ProcessMessage( const osc::ReceivedMessage &m, const osc::IpEndpointName& remoteEndpoint ) { // convert the m to a Message, return at the end to other main thread Message message; // set the address message.setAddress( m.AddressPattern() ); // set the sender ip/host char endpoint_host[ osc::IpEndpointName::ADDRESS_STRING_LENGTH ]; remoteEndpoint.AddressAsString( endpoint_host ); message.setRemoteEndpoint( endpoint_host, remoteEndpoint.port ); // transfer the arguments for ( osc::ReceivedMessage::const_iterator arg = m.ArgumentsBegin(); arg != m.ArgumentsEnd(); ++arg ) { if ( arg->IsInt32() ) { message.addIntArg( arg->AsInt32Unchecked() ); } else if ( arg->IsFloat() ) { message.addFloatArg( arg->AsFloatUnchecked() ); } else if ( arg->IsString() ) { message.addStringArg( arg->AsStringUnchecked() ); } else { assert( false && "message argument is not int, float, or string" ); } } // at this point we are running inside the thread created by start() // since we are returning a copy no shared memory management for(unsigned int i=0; i<_oscHandlers.size(); ++i) { _oscHandlers[i]->oscReceive( message ); } }
void ofxOscReceiver::ProcessMessage( const osc::ReceivedMessage &m, const osc::IpEndpointName& remoteEndpoint ) { // convert the message to an ofxOscMessage ofxOscMessage msg; // set the address msg.setAddress( m.AddressPattern() ); // set the sender ip/host char endpoint_host[ osc::IpEndpointName::ADDRESS_STRING_LENGTH ]; remoteEndpoint.AddressAsString( endpoint_host ); msg.setRemoteEndpoint( endpoint_host, remoteEndpoint.port ); // transfer the arguments for ( osc::ReceivedMessage::const_iterator arg = m.ArgumentsBegin(); arg != m.ArgumentsEnd(); ++arg ) { if ( arg->IsInt32() ) msg.addIntArg( arg->AsInt32Unchecked() ); else if ( arg->IsInt64() ) msg.addInt64Arg( arg->AsInt64Unchecked() ); else if ( arg->IsFloat() ) msg.addFloatArg( arg->AsFloatUnchecked() ); else if ( arg->IsDouble() ) msg.addDoubleArg( arg->AsDoubleUnchecked() ); else if ( arg->IsString() ) msg.addStringArg( arg->AsStringUnchecked() ); else if ( arg->IsSymbol() ) msg.addSymbolArg( arg->AsSymbolUnchecked() ); else if ( arg->IsChar() ) msg.addCharArg( arg->AsCharUnchecked() ); else if ( arg->IsMidiMessage() ) msg.addMidiMessageArg( arg->AsMidiMessageUnchecked() ); else if ( arg->IsBool()) msg.addBoolArg( arg->AsBoolUnchecked() ); else if ( arg->IsInfinitum() ) msg.addTriggerArg(); else if ( arg->IsTimeTag() ) msg.addTimetagArg( arg->AsTimeTagUnchecked() ); else if ( arg->IsRgbaColor() ) msg.addRgbaColorArg( arg->AsRgbaColorUnchecked() ); else if ( arg->IsBlob() ){ const char * dataPtr; osc::osc_bundle_element_size_t len = 0; arg->AsBlobUnchecked((const void*&)dataPtr, len); ofBuffer buffer(dataPtr, len); msg.addBlobArg( buffer ); } else { ofLogError("ofxOscReceiver") << "ProcessMessage: argument in message " << m.AddressPattern() << " is not an int, float, or string"; } } // send msg to main thread messagesChannel.send( std::move(msg) ); }