Browse Source

Added an optional thread name parameter to the OSCReceiver constructor

tags/2021-05-28
jules 7 years ago
parent
commit
7b736feb2a
2 changed files with 19 additions and 13 deletions
  1. +15
    -12
      modules/juce_osc/osc/juce_OSCReceiver.cpp
  2. +4
    -1
      modules/juce_osc/osc/juce_OSCReceiver.h

+ 15
- 12
modules/juce_osc/osc/juce_OSCReceiver.cpp View File

@@ -101,9 +101,9 @@ namespace
if (input.getNumBytesRemaining() < 4) if (input.getNumBytesRemaining() < 4)
throw OSCFormatError ("OSC input stream exhausted while reading string"); throw OSCFormatError ("OSC input stream exhausted while reading string");
const size_t posBegin = (size_t) getPosition();
String s (input.readString());
const size_t posEnd = (size_t) getPosition();
auto posBegin = (size_t) getPosition();
auto s = input.readString();
auto posEnd = (size_t) getPosition();
if (static_cast<const char*> (getData()) [posEnd - 1] != '\0') if (static_cast<const char*> (getData()) [posEnd - 1] != '\0')
throw OSCFormatError ("OSC input stream exhausted before finding null terminator of string"); throw OSCFormatError ("OSC input stream exhausted before finding null terminator of string");
@@ -119,14 +119,14 @@ namespace
if (input.getNumBytesRemaining() < 4) if (input.getNumBytesRemaining() < 4)
throw OSCFormatError ("OSC input stream exhausted while reading blob"); throw OSCFormatError ("OSC input stream exhausted while reading blob");
const size_t blobDataSize = (size_t) input.readIntBigEndian();
auto blobDataSize = (size_t) input.readIntBigEndian();
if ((size_t) input.getNumBytesRemaining() < (blobDataSize + 3) % 4) if ((size_t) input.getNumBytesRemaining() < (blobDataSize + 3) % 4)
throw OSCFormatError ("OSC input stream exhausted before reaching end of blob"); throw OSCFormatError ("OSC input stream exhausted before reaching end of blob");
MemoryBlock blob; MemoryBlock blob;
const size_t bytesRead = input.readIntoMemoryBlock (blob, (ssize_t) blobDataSize);
auto bytesRead = input.readIntoMemoryBlock (blob, (ssize_t) blobDataSize);
readPaddingZeros (bytesRead); readPaddingZeros (bytesRead);
return blob; return blob;
@@ -203,8 +203,8 @@ namespace
//============================================================================== //==============================================================================
OSCMessage readMessage() OSCMessage readMessage()
{ {
OSCAddressPattern ap = readAddressPattern();
OSCTypeList types = readTypeTagString();
auto ap = readAddressPattern();
auto types = readTypeTagString();
OSCMessage msg (ap); OSCMessage msg (ap);
@@ -321,7 +321,7 @@ namespace
struct OSCReceiver::Pimpl : private Thread, struct OSCReceiver::Pimpl : private Thread,
private MessageListener private MessageListener
{ {
Pimpl() : Thread ("JUCE OSC server")
Pimpl (const String& threadName) : Thread (threadName)
{ {
} }
@@ -387,8 +387,7 @@ struct OSCReceiver::Pimpl : private Thread,
addListenerWithAddress (listenerToAdd, addressToMatch, listenersWithAddress); addListenerWithAddress (listenerToAdd, addressToMatch, listenersWithAddress);
} }
void addListener (ListenerWithOSCAddress<RealtimeCallback>* listenerToAdd,
OSCAddress addressToMatch)
void addListener (ListenerWithOSCAddress<RealtimeCallback>* listenerToAdd, OSCAddress addressToMatch)
{ {
addListenerWithAddress (listenerToAdd, addressToMatch, realtimeListenersWithAddress); addListenerWithAddress (listenerToAdd, addressToMatch, realtimeListenersWithAddress);
} }
@@ -429,7 +428,7 @@ struct OSCReceiver::Pimpl : private Thread,
try try
{ {
OSCBundle::Element content = inStream.readElementWithKnownSize (dataSize);
auto content = inStream.readElementWithKnownSize (dataSize);
// realtime listeners should receive the OSC content first - and immediately // realtime listeners should receive the OSC content first - and immediately
// on this thread: // on this thread:
@@ -587,7 +586,11 @@ private:
}; };
//============================================================================== //==============================================================================
OSCReceiver::OSCReceiver() : pimpl (new Pimpl())
OSCReceiver::OSCReceiver (const String& threadName) : pimpl (new Pimpl (threadName))
{
}
OSCReceiver::OSCReceiver() : OSCReceiver ("JUCE OSC server")
{ {
} }


+ 4
- 1
modules/juce_osc/osc/juce_OSCReceiver.h View File

@@ -42,9 +42,12 @@ class JUCE_API OSCReceiver
{ {
public: public:
//============================================================================== //==============================================================================
/** Constructs a new OSCReceiver. */
/** Creates an OSCReceiver. */
OSCReceiver(); OSCReceiver();
/** Creates an OSCReceiver with a specific name for its thread. */
OSCReceiver (const String& threadName);
/** Destructor. */ /** Destructor. */
~OSCReceiver(); ~OSCReceiver();


Loading…
Cancel
Save