l@270: /***** OSCServer.cpp *****/ l@270: #include l@270: l@270: // constructor l@270: OSCServer::OSCServer(){} l@270: l@270: // static method for checking messages l@270: // called by messageCheckTask with pointer to OSCServer instance as argument l@270: void OSCServer::checkMessages(void* ptr){ l@270: OSCServer *instance = (OSCServer*)ptr; l@270: instance->messageCheck(); l@270: } l@270: l@270: void OSCServer::setup(int _port){ l@270: port = _port; l@270: if(!socket.init(port)) l@270: rt_printf("socket not initialised\n"); l@270: createAuxTasks(); l@270: } l@270: l@270: void OSCServer::createAuxTasks(){ l@270: char name [30]; giuliomoro@474: sprintf (name, "OSCReceiveTask %i", port); giuliomoro@474: OSCReceiveTask = Bela_createAuxiliaryTask(OSCServer::checkMessages, BELA_AUDIO_PRIORITY-5, name, this, true); l@270: } l@270: l@270: void OSCServer::messageCheck(){ giuliomoro@474: if (socket.waitUntilReady(true, UDP_RECEIVE_TIMEOUT_MS)){ giuliomoro@474: int msgLength = socket.read(&inBuffer, UDP_RECEIVE_MAX_LENGTH, false); l@270: pr.init(inBuffer, msgLength); l@270: oscpkt::Message *inmsg; l@270: while (pr.isOk() && (inmsg = pr.popMessage()) != 0) { l@270: inQueue.push(*inmsg); l@270: } l@270: } l@270: } l@270: l@270: bool OSCServer::messageWaiting(){ l@270: return !inQueue.empty(); l@270: } l@270: l@270: oscpkt::Message OSCServer::popMessage(){ l@270: if (!inQueue.empty()){ l@270: poppedMessage = inQueue.front(); l@270: inQueue.pop(); l@270: } else { l@270: poppedMessage.init("/error"); l@270: } l@270: return poppedMessage; l@270: } l@270: giuliomoro@474: void OSCServer::receiveMessageNow(int timeout){ l@270: if (socket.waitUntilReady(true, timeout)){ giuliomoro@474: int msgLength = socket.read(&inBuffer, UDP_RECEIVE_MAX_LENGTH, false); l@270: pr.init(inBuffer, msgLength); l@270: oscpkt::Message *inmsg; l@270: while (pr.isOk() && (inmsg = pr.popMessage()) != 0) { l@270: inQueue.push(*inmsg); l@270: } l@270: } l@270: } l@270: l@270: l@270: l@270: