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]; l@270: sprintf (name, "OSCRecieveTask %i", port); l@270: OSCRecieveTask = BeagleRT_createAuxiliaryTask(OSCServer::checkMessages, BEAGLERT_AUDIO_PRIORITY-5, name, this, true); l@270: } l@270: l@270: void OSCServer::messageCheck(){ l@270: if (socket.waitUntilReady(true, UDP_RECIEVE_TIMEOUT_MS)){ l@270: int msgLength = socket.read(&inBuffer, UDP_RECIEVE_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: l@270: void OSCServer::recieveMessageNow(int timeout){ l@270: if (socket.waitUntilReady(true, timeout)){ l@270: int msgLength = socket.read(&inBuffer, UDP_RECIEVE_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: