diff options
Diffstat (limited to 'ofAsterisk/src')
| -rwxr-xr-x | ofAsterisk/src/Asterisk.cpp | 40 | ||||
| -rwxr-xr-x | ofAsterisk/src/Asterisk.h | 30 |
2 files changed, 37 insertions, 33 deletions
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<std::string> &split(const std::string &s, char delim, std::vector<std::string> &elems) {
+ std::stringstream ss(s);
+ std::string item;
+ while(std::getline(ss, item, delim)) {
+ elems.push_back(item);
+ }
+ return elems;
+}
+
+std::vector<std::string> split(const std::string &s, char delim) {
+ std::vector<std::string> 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<std::string> lines=split(test,'\n');
+ for (int i=0;i<test.size();i++) {
+ string s=ofToString(i)+": '"+lines[i]+"'\n";
+ printf(s.c_str());
+ }
}
void Asterisk::startGame(){
@@ -34,10 +59,18 @@ void Asterisk::endGame(string score){ void Asterisk::cmd(string s) {
file = popen(s.c_str(), "re");
filenum=fileno(file);
- fcntl(filenum, F_SETFL, O_NONBLOCK); //doesn't seem to work, still pauses
- //pclose(file); //discard the pipe THIS IS BLOCKING
+ fcntl(filenum, F_SETFL, O_NONBLOCK);
}
+/*
+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)
+*/
+
+
int Asterisk::update(){
//capture stdin response from popen
if (state==WAITING||state==STARTING) {
@@ -49,6 +82,7 @@ int Asterisk::update(){ if (r > 0) {
pclose(file);
string msg=string(buf);
+ vector<std::string> 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
{
|
