From f3b7df8e1a44be946bbc0cf4c2b89e2920d6d7ee Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Tue, 13 Nov 2012 15:07:39 +0000 Subject: initial asterisk hookup --- vfg/src/Asterisk.cpp | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100755 vfg/src/Asterisk.cpp (limited to 'vfg/src/Asterisk.cpp') diff --git a/vfg/src/Asterisk.cpp b/vfg/src/Asterisk.cpp new file mode 100755 index 0000000..8a2309e --- /dev/null +++ b/vfg/src/Asterisk.cpp @@ -0,0 +1,70 @@ +#include "Asterisk.h" + + +//there is no notification that there is someone in the queue + +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; +} + +void Asterisk::startGame(){ + //if (state=IDLE) { + cmd("ssh 80.93.22.22 'sudo /usr/sbin/asterisk -rx \"devstate change Custom:GAME NOT_INUSE\"'"); + state=STARTING; + //} +} +void Asterisk::cmd(string s) { + file = popen(s.c_str(), "r"); + int filenum=fileno(file); + //fcntl(filenum, F_SETFL, O_NONBLOCK); //doesn't seem to work, still pauses + //pclose(file); //discard the pipe THIS IS BLOCKING +} + +int Asterisk::update(){ + /* + if (state==WAITING||state==STARTING) { + char buf[100]; + ssize_t r = read(filenum, buf, 100); + //if (r == -1 && errno == EAGAIN) + //no data yet + //else + if (r > 0) + //received data + printf("%s\n",buf); + pclose(file); + state=IDLE; + ///else + //pipe closed + } + */ + //check messages and pipes, returns new keypresses + char udpMessage[10000]; + udpConnection.Receive(udpMessage,10000); + string msg=udpMessage; + if(msg!=""){ + if (msg.length()>2) { + //printf("status msg: %s\n",msg.c_str()); + if (msg.substr(0,5)=="Local") { + state=PLAYING; + return 1000; + } + return 0; + } + else { + //printf("cmd: %s\n",msg.c_str()); + return ofToInt(msg); + } + } + else return 0; +} + +Asterisk::~Asterisk() +{ + pclose(file); + //dtor +} -- cgit v1.2.3