#include "Asterisk.h" //there is no notification that there is someone in the queue //but there is a status message you can check periodically... std::vector &split(const std::string &s, char delim, std::vector &elems) { std::stringstream ss(s); std::string item; while(std::getline(ss, item, delim)) { elems.push_back(item); } return elems; } std::vector split(const std::string &s, char delim) { std::vector elems; return split(s, delim, elems); } Asterisk::Asterisk() { udpConnection.Create(); udpConnection.Bind(5000); udpConnection.SetNonBlocking(true); //cmd("ssh 80.93.22.22 'sudo /usr/sbin/asterisk -rx \"database put GAME passcode 1234\"'"); state=WAITING; //for acknowledge printf("Asterisk: created socket and connected to server\n"); string test=string("gameQ has 1 calls (max unlimited) in 'rrmemory' strategy (8s holdtime, 50s talktime), W:0, C:38, A:26, SL:36.8% within 0s\ Members: \ Game AGI (Local/9999@default) with penalty 1 (In use) has taken 31 calls (last was 5333 secs ago)\ Callers: \ 1. SIP/sip_proxy-00000045 (wait: 0:06, prio: 0)"); vector lines=split(test,'\n'); for (int i=0;i 0) { pclose(file); string msg=string(buf); vector lines=split(msg,'\n'); //received data is always a command ACKNOWLEDGEMENT if (msg.compare("Changing GAME to NOT_INUSE")==0) { printf("player dequeued\n"); state=PLAYING; } else if (msg.compare(0,5,"gameQ")==0) { //queue status message } else { printf("stdin says: %s\n",buf); state=IDLE; } } } //check udp messages, return new keypresses char udpMessage[10000]; udpConnection.Receive(udpMessage,10000); string msg=udpMessage; if(msg!=""){ printf("Asterisk: %s\n",msg.c_str()); if (msg.length()>3) { //printf("status msg: %s\n",msg.c_str()); if (msg.substr(0,5)=="Local") { state=PLAYING; playerCode=msg.substr(0,msg.length()-1); printf("Asterisk: game started: code %s\n",playerCode.c_str()); return 1000; } return 0; } else { return ofToInt(msg); } } else return 0; } Asterisk::~Asterisk() { pclose(file); //dtor }