summaryrefslogtreecommitdiff
path: root/ofAsterisk/src/Asterisk.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'ofAsterisk/src/Asterisk.cpp')
-rwxr-xr-xofAsterisk/src/Asterisk.cpp33
1 files changed, 13 insertions, 20 deletions
diff --git a/ofAsterisk/src/Asterisk.cpp b/ofAsterisk/src/Asterisk.cpp
index f5e7705..7c4f050 100755
--- a/ofAsterisk/src/Asterisk.cpp
+++ b/ofAsterisk/src/Asterisk.cpp
@@ -13,30 +13,14 @@ std::vector<std::string> &split(const std::string &s, char delim, std::vector<st
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()
+Asterisk::Asterisk(string passcode)
{
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 "+passcode+"\"'");
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(){
@@ -70,6 +54,11 @@ gameQ has 1 calls (max unlimited) in 'rrmemory' strategy (8s holdtime, 50s talkt
1. SIP/sip_proxy-00000045 (wait: 0:06, prio: 0)
*/
+void Asterisk::requestStatus(){
+ cmd("ssh 80.93.22.22 'sudo /usr/sbin/asterisk -rx \"queue show gameQ\"'");
+ state=WAITING;
+}
+
int Asterisk::update(){
//capture stdin response from popen
@@ -82,14 +71,18 @@ 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");
state=PLAYING;
}
else if (msg.compare(0,5,"gameQ")==0) {
- //queue status message
+ vector<std::string> lines;
+ split(msg,'\n',lines);
+ queued=0;
+ for (int i=4;i<lines.size();i++) {
+ if (lines[i].compare(0,6," ")==0&&lines[i].compare(7,1,".")==0) queued++;
+ }
}
else {
printf("stdin says: %s\n",buf);