Mercurial > hg > beaglert
view core/OSCServer.cpp @ 464:8fcfbfb32aa0 prerelease
Examples reorder with subdirectories. Added header to each project. Moved Doxygen to bottom of render.cpp.
author | Robert Jack <robert.h.jack@gmail.com> |
---|---|
date | Mon, 20 Jun 2016 16:20:38 +0100 |
parents | 421a69d42943 |
children | efc9a9f8e63d |
line wrap: on
line source
/***** OSCServer.cpp *****/ #include <OSCServer.h> // constructor OSCServer::OSCServer(){} // static method for checking messages // called by messageCheckTask with pointer to OSCServer instance as argument void OSCServer::checkMessages(void* ptr){ OSCServer *instance = (OSCServer*)ptr; instance->messageCheck(); } void OSCServer::setup(int _port){ port = _port; if(!socket.init(port)) rt_printf("socket not initialised\n"); createAuxTasks(); } void OSCServer::createAuxTasks(){ char name [30]; sprintf (name, "OSCRecieveTask %i", port); OSCRecieveTask = Bela_createAuxiliaryTask(OSCServer::checkMessages, BELA_AUDIO_PRIORITY-5, name, this, true); } void OSCServer::messageCheck(){ if (socket.waitUntilReady(true, UDP_RECIEVE_TIMEOUT_MS)){ int msgLength = socket.read(&inBuffer, UDP_RECIEVE_MAX_LENGTH, false); pr.init(inBuffer, msgLength); oscpkt::Message *inmsg; while (pr.isOk() && (inmsg = pr.popMessage()) != 0) { inQueue.push(*inmsg); } } } bool OSCServer::messageWaiting(){ return !inQueue.empty(); } oscpkt::Message OSCServer::popMessage(){ if (!inQueue.empty()){ poppedMessage = inQueue.front(); inQueue.pop(); } else { poppedMessage.init("/error"); } return poppedMessage; } void OSCServer::recieveMessageNow(int timeout){ if (socket.waitUntilReady(true, timeout)){ int msgLength = socket.read(&inBuffer, UDP_RECIEVE_MAX_LENGTH, false); pr.init(inBuffer, msgLength); oscpkt::Message *inmsg; while (pr.isOk() && (inmsg = pr.popMessage()) != 0) { inQueue.push(*inmsg); } } }