annotate core/OSCServer.cpp @ 553:e545ce04cf2c prerelease

Updated Makefile to take LDFLAGS=, LDLIBS=, CFLAGS=, CPPFLAGS=
author Giulio Moro <giuliomoro@yahoo.it>
date Fri, 24 Jun 2016 17:13:45 +0100
parents efc9a9f8e63d
children
rev   line source
l@270 1 /***** OSCServer.cpp *****/
l@270 2 #include <OSCServer.h>
l@270 3
l@270 4 // constructor
l@270 5 OSCServer::OSCServer(){}
l@270 6
l@270 7 // static method for checking messages
l@270 8 // called by messageCheckTask with pointer to OSCServer instance as argument
l@270 9 void OSCServer::checkMessages(void* ptr){
l@270 10 OSCServer *instance = (OSCServer*)ptr;
l@270 11 instance->messageCheck();
l@270 12 }
l@270 13
l@270 14 void OSCServer::setup(int _port){
l@270 15 port = _port;
l@270 16 if(!socket.init(port))
l@270 17 rt_printf("socket not initialised\n");
l@270 18 createAuxTasks();
l@270 19 }
l@270 20
l@270 21 void OSCServer::createAuxTasks(){
l@270 22 char name [30];
giuliomoro@474 23 sprintf (name, "OSCReceiveTask %i", port);
giuliomoro@474 24 OSCReceiveTask = Bela_createAuxiliaryTask(OSCServer::checkMessages, BELA_AUDIO_PRIORITY-5, name, this, true);
l@270 25 }
l@270 26
l@270 27 void OSCServer::messageCheck(){
giuliomoro@474 28 if (socket.waitUntilReady(true, UDP_RECEIVE_TIMEOUT_MS)){
giuliomoro@474 29 int msgLength = socket.read(&inBuffer, UDP_RECEIVE_MAX_LENGTH, false);
l@270 30 pr.init(inBuffer, msgLength);
l@270 31 oscpkt::Message *inmsg;
l@270 32 while (pr.isOk() && (inmsg = pr.popMessage()) != 0) {
l@270 33 inQueue.push(*inmsg);
l@270 34 }
l@270 35 }
l@270 36 }
l@270 37
l@270 38 bool OSCServer::messageWaiting(){
l@270 39 return !inQueue.empty();
l@270 40 }
l@270 41
l@270 42 oscpkt::Message OSCServer::popMessage(){
l@270 43 if (!inQueue.empty()){
l@270 44 poppedMessage = inQueue.front();
l@270 45 inQueue.pop();
l@270 46 } else {
l@270 47 poppedMessage.init("/error");
l@270 48 }
l@270 49 return poppedMessage;
l@270 50 }
l@270 51
giuliomoro@474 52 void OSCServer::receiveMessageNow(int timeout){
l@270 53 if (socket.waitUntilReady(true, timeout)){
giuliomoro@474 54 int msgLength = socket.read(&inBuffer, UDP_RECEIVE_MAX_LENGTH, false);
l@270 55 pr.init(inBuffer, msgLength);
l@270 56 oscpkt::Message *inmsg;
l@270 57 while (pr.isOk() && (inmsg = pr.popMessage()) != 0) {
l@270 58 inQueue.push(*inmsg);
l@270 59 }
l@270 60 }
l@270 61 }
l@270 62
l@270 63
l@270 64
l@270 65