add option: set target index = -1 to send the message to all targets

This commit is contained in:
monsieurgustav
2014-11-23 12:59:03 +01:00
parent c29becea88
commit 72fc81ce3e
2 changed files with 20 additions and 7 deletions
@@ -47,7 +47,7 @@ class UOscFunctionLibrary : public UBlueprintFunctionLibrary
* @brief Send an OSC message.
* @param Address OSC address.
* @param Data result of successive PushFloat/Int/String/etc.
* @param Index index of the destination. (SendTarget list of the plugin settings)
* @param Index index of the destination, -1 for all destinations. (SendTarget list of the plugin settings)
*/
UFUNCTION(BlueprintCallable, Category=OSC)
static void SendOsc(const FString & Address, const FOscDataStruct & Data, int32 TargetIndex);
+19 -6
View File
@@ -38,19 +38,32 @@ void UOscSettings::UpdateSendAddresses()
}
}
static void SendImpl(FSocket *socket, const uint8 *buffer, int32 length, const FInternetAddr & target)
{
int32 bytesSent = 0;
while(length > 0)
{
socket->SendTo(buffer, length, bytesSent, target);
length -= bytesSent;
buffer += bytesSent;
}
}
void UOscSettings::Send(const uint8 *buffer, int32 length, int32 targetIndex)
{
if(targetIndex < _sendAddresses.Num())
if(targetIndex == -1)
{
int32 bytesSent = 0;
while(length > 0)
for(const auto & address : _sendAddresses)
{
_sendSocket->SendTo(buffer, length, bytesSent, *_sendAddresses[targetIndex].second);
length -= bytesSent;
buffer += bytesSent;
SendImpl(&_sendSocket.Get(), buffer, length, *address.second);
}
UE_LOG(LogOSC, Verbose, TEXT("OSC sent"));
}
else if(targetIndex < _sendAddresses.Num())
{
SendImpl(&_sendSocket.Get(), buffer, length, *_sendAddresses[targetIndex].second);
UE_LOG(LogOSC, Verbose, TEXT("OSC sent"));
}
else
{
UE_LOG(LogOSC, Warning, TEXT("Cannot send OSC: invalid targetIndex %d"), targetIndex);