From f7bee21ada14851da8626a3784821ded25333fe6 Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Mon, 3 Dec 2012 17:04:02 +0000 Subject: working on train --- ofAsterisk/src/Asterisk.cpp | 40 +++++++++++++++++++++++++++++++++++++--- ofAsterisk/src/Asterisk.h | 30 ------------------------------ 2 files changed, 37 insertions(+), 33 deletions(-) (limited to 'ofAsterisk') diff --git a/ofAsterisk/src/Asterisk.cpp b/ofAsterisk/src/Asterisk.cpp index 46957cd..f5e7705 100755 --- a/ofAsterisk/src/Asterisk.cpp +++ b/ofAsterisk/src/Asterisk.cpp @@ -4,14 +4,39 @@ //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\"'"); + //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"); diff --git a/ofAsterisk/src/Asterisk.h b/ofAsterisk/src/Asterisk.h index c9ce864..3acdb6e 100755 --- a/ofAsterisk/src/Asterisk.h +++ b/ofAsterisk/src/Asterisk.h @@ -9,36 +9,6 @@ #define STARTING 2 #define PLAYING 3 -// http://stackoverflow.com/questions/1735781/non-blocking-pipe-using-popen - -/* - -Commands for game to control PBX - -Game ready - -ssh 10.10.10.1 'sudo /usr/sbin/asterisk -rx "devstate change Custom:GAME NOT_INUSE"' - -change daily access 4 digit code - -ssh 10.10.10.1 'sudo /usr/sbin/asterisk -rx "database put GAME passcode 1234"' - - - -Set status code for current game - -ssh 10.10.10.1 'sudo /usr/sbin/asterisk -rx "database put GAME statuscode 1234"' - -Gameover Hangup Call - -ssh 10.10.10.1 'sudo /usr/sbin/asterisk -rx "hangup request Local/9999@default-00000039;2" - -Local/9999@default-00000039;2 is a channel identifier and will be send to game when AGI script connects to game controller. The channel ID is unique for each call - - -can we have a message that someone has joined the queue? -can we have a message if someone hangs up? -*/ class Asterisk { -- cgit v1.2.3