Mercurial > hg > beaglert
diff core/OSCClient.cpp @ 270:de37582ce6f3 prerelease
Added OSCServer and OSCClient
author | Liam Donovan <l.b.donovan@qmul.ac.uk> |
---|---|
date | Tue, 17 May 2016 15:56:18 +0100 |
parents | |
children | e4392164b458 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core/OSCClient.cpp Tue May 17 15:56:18 2016 +0100 @@ -0,0 +1,79 @@ +/***** OSCClient.cpp *****/ +#include <OSCClient.h> + +OSCClient::OSCClient(){} + +void OSCClient::sendQueue(void* ptr){ + OSCClient *instance = (OSCClient*)ptr; + instance->queueSend(); +} + +void OSCClient::setup(int _port, const char* _address, bool scheduleTask){ + address = _address; + port = _port; + + socket.setServer(address); + socket.setPort(port); + + if (scheduleTask) + createAuxTasks(); +} + +void OSCClient::createAuxTasks(){ + char name [30]; + sprintf (name, "OSCSendTask %i", port); + OSCSendTask = BeagleRT_createAuxiliaryTask(sendQueue, BEAGLERT_AUDIO_PRIORITY-5, name, this, true); +} + +void OSCClient::queueMessage(oscpkt::Message msg){ + outQueue.push(msg); +} + +void OSCClient::queueSend(){ + if (!outQueue.empty()){ + pw.init().startBundle(); + while(!outQueue.empty()){ + pw.addMessage(outQueue.front()); + outQueue.pop(); + } + pw.endBundle(); + outBuffer = pw.packetData(); + socket.send(outBuffer, pw.packetSize()); + } +} + +void OSCClient::sendMessageNow(oscpkt::Message msg){ + pw.init().addMessage(msg); + outBuffer = pw.packetData(); + socket.send(outBuffer, pw.packetSize()); +} + +// OSCMessageFactory +OSCMessageFactory& OSCMessageFactory::to(std::string addr){ + msg.init(addr); + return *this; +} + +OSCMessageFactory& OSCMessageFactory::add(std::string in){ + msg.pushStr(in); + return *this; +} +OSCMessageFactory& OSCMessageFactory::add(int in){ + msg.pushInt32(in); + return *this; +} +OSCMessageFactory& OSCMessageFactory::add(float in){ + msg.pushFloat(in); + return *this; +} +OSCMessageFactory& OSCMessageFactory::add(bool in){ + msg.pushBool(in); + return *this; +} +OSCMessageFactory& OSCMessageFactory::add(void *ptr, int size){ + msg.pushBlob(ptr, size); + return *this; +} +oscpkt::Message OSCMessageFactory::end(){ + return msg; +} \ No newline at end of file