Browse Source

Added OSC send message functions. Also fixed oscpack address string size check.

tags/0.2
Ludwig Frühschütz 3 years ago
parent
commit
3b36d8b689
3 changed files with 36 additions and 2 deletions
  1. +31
    -0
      OSC2AHK/dllmain.cpp
  2. +3
    -0
      OSC2AHK/dllmain.h
  3. +2
    -2
      oscpack/osc/OscOutboundPacketStream.cpp

+ 31
- 0
OSC2AHK/dllmain.cpp View File

@ -6,6 +6,7 @@
#include <thread> #include <thread>
#include "osc/OscReceivedElements.h" #include "osc/OscReceivedElements.h"
#include "osc/OscPacketListener.h" #include "osc/OscPacketListener.h"
#include "osc/OscOutboundPacketStream.h"
#include "ip/UdpSocket.h" #include "ip/UdpSocket.h"
//Class from OSC library (oscpack). This calls our handleOscMsg() on every new message. //Class from OSC library (oscpack). This calls our handleOscMsg() on every new message.
@ -169,6 +170,36 @@ DLLEXPORT char* getStringData(char* targetString, unsigned int targetSize, unsig
return targetString; return targetString;
} }
DLLEXPORT void sendOscMessageInt(char* ip, unsigned int port, char* address, int payload)
{
UdpTransmitSocket transmitSocket(IpEndpointName(ip, port));
char buffer[1024];
osc::OutboundPacketStream p(buffer, 1024);
p << osc::BeginMessage(address) << payload << osc::EndMessage;
transmitSocket.Send(p.Data(), p.Size());
}
DLLEXPORT void sendOscMessageFloat(char* ip, unsigned int port, char* address, float payload)
{
UdpTransmitSocket transmitSocket(IpEndpointName(ip, port));
char buffer[1024];
osc::OutboundPacketStream p(buffer, 1024);
p << osc::BeginMessage(address) << payload << osc::EndMessage;
transmitSocket.Send(p.Data(), p.Size());
}
DLLEXPORT void sendOscMessageString(char* ip, unsigned int port, char* address, char* payload)
{
UdpTransmitSocket transmitSocket(IpEndpointName(ip, port));
char buffer[1024];
osc::OutboundPacketStream p(buffer, 1024);
p << osc::BeginMessage(address) << payload << osc::EndMessage;
transmitSocket.Send(p.Data(), p.Size());
}
void removeStoredString(int stringId) void removeStoredString(int stringId)
{ {
for (UINT i = 0; i < storedStrings.size(); i++) for (UINT i = 0; i < storedStrings.size(); i++)


+ 3
- 0
OSC2AHK/dllmain.h View File

@ -24,6 +24,9 @@ extern "C" DLLEXPORT int close(unsigned int clearListeners = 1);
extern "C" DLLEXPORT int addListener(LPCSTR address, unsigned int messageID, unsigned int dataType = OSC_TYPE_ALL); extern "C" DLLEXPORT int addListener(LPCSTR address, unsigned int messageID, unsigned int dataType = OSC_TYPE_ALL);
extern "C" DLLEXPORT int removeListener(LPCSTR address); extern "C" DLLEXPORT int removeListener(LPCSTR address);
extern "C" DLLEXPORT char* getStringData(char* targetString, unsigned int targetSize, unsigned int StringID); extern "C" DLLEXPORT char* getStringData(char* targetString, unsigned int targetSize, unsigned int StringID);
extern "C" DLLEXPORT void sendOscMessageInt(char* ip, unsigned int port, char* address, int payload);
extern "C" DLLEXPORT void sendOscMessageFloat(char* ip, unsigned int port, char* address, float payload);
extern "C" DLLEXPORT void sendOscMessageString(char* ip, unsigned int port, char* address, char* payload);
int handleOscMsg(const osc::ReceivedMessage& m); int handleOscMsg(const osc::ReceivedMessage& m);
bool isMatchingOscType(unsigned int msgType, unsigned int listenerTypeField); bool isMatchingOscType(unsigned int msgType, unsigned int listenerTypeField);
bool isMatchingOSCAddress(const char* address, const char* pattern); bool isMatchingOSCAddress(const char* address, const char* pattern);


+ 2
- 2
oscpack/osc/OscOutboundPacketStream.cpp View File

@ -362,7 +362,7 @@ OutboundPacketStream& OutboundPacketStream::operator<<( const BeginMessage& rhs
//std::strcpy( messageCursor_, rhs.addressPattern ); //std::strcpy( messageCursor_, rhs.addressPattern );
std::size_t rhsLength = std::strlen(rhs.addressPattern); std::size_t rhsLength = std::strlen(rhs.addressPattern);
strcpy_s(messageCursor_, rhsLength, rhs.addressPattern);
strcpy_s(messageCursor_, rhsLength+1, rhs.addressPattern); //Size check is done manually earlier
messageCursor_ += rhsLength + 1; messageCursor_ += rhsLength + 1;
// zero pad to 4-byte boundary // zero pad to 4-byte boundary
@ -605,7 +605,7 @@ OutboundPacketStream& OutboundPacketStream::operator<<( const char *rhs )
*(--typeTagsCurrent_) = STRING_TYPE_TAG; *(--typeTagsCurrent_) = STRING_TYPE_TAG;
//std::strcpy( argumentCurrent_, rhs ); //std::strcpy( argumentCurrent_, rhs );
std::size_t rhsLength = std::strlen(rhs); std::size_t rhsLength = std::strlen(rhs);
strcpy_s(argumentCurrent_, rhsLength, rhs);
strcpy_s(argumentCurrent_, rhsLength+1, rhs);
argumentCurrent_ += rhsLength + 1; argumentCurrent_ += rhsLength + 1;
// zero pad to 4-byte boundary // zero pad to 4-byte boundary


Loading…
Cancel
Save