summaryrefslogtreecommitdiff
path: root/ofAsterisk/src
diff options
context:
space:
mode:
authorComment <tim@gray.(none)>2012-11-30 13:30:48 +0000
committerComment <tim@gray.(none)>2012-11-30 13:30:48 +0000
commitbbeed54d2c0572d9fc12edab14781dd544dc149a (patch)
treeeec54a5a9741513c545abec4c750a85e1eb7e259 /ofAsterisk/src
parent7ae1f870faebb65e9ee3a064fc43ef2fc6955a84 (diff)
demo v0.9
Diffstat (limited to 'ofAsterisk/src')
-rwxr-xr-xofAsterisk/src/Asterisk.cpp42
1 files changed, 25 insertions, 17 deletions
diff --git a/ofAsterisk/src/Asterisk.cpp b/ofAsterisk/src/Asterisk.cpp
index ae85269..46957cd 100755
--- a/ofAsterisk/src/Asterisk.cpp
+++ b/ofAsterisk/src/Asterisk.cpp
@@ -10,12 +10,12 @@ Asterisk::Asterisk()
udpConnection.Bind(5000);
udpConnection.SetNonBlocking(true);
cmd("ssh 80.93.22.22 'sudo /usr/sbin/asterisk -rx \"database put GAME passcode 1234\"'");
- state=WAITING;
+ state=WAITING; //for acknowledge
printf("Asterisk: created socket and connected to server\n");
}
void Asterisk::startGame(){
- if (state!=PLAYING) {
+ if (state==IDLE) {
cmd("ssh 80.93.22.22 'sudo /usr/sbin/asterisk -rx \"devstate change Custom:GAME NOT_INUSE\"'");
printf("Asterisk: attempting to dequeue\n");
state=STARTING;
@@ -32,31 +32,39 @@ void Asterisk::endGame(string score){
}
}
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
+ 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
}
int Asterisk::update(){
- //how to capture stdin response from popen
- /*
+ //capture stdin response from popen
if (state==WAITING||state==STARTING) {
- char buf[100];
- ssize_t r = read(filenum, buf, 100);
+ char buf[1000];
+ ssize_t r = read(filenum, buf, 1000);
//if (r == -1 && errno == EAGAIN)
//no data yet
//else
- if (r > 0)
- //received data
- printf("%s\n",buf);
+ if (r > 0) {
pclose(file);
- state=IDLE;
- ///else
- //pipe closed
+ string msg=string(buf);
+ //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 messages and pipes, returns new keypresses
+
+ //check udp messages, return new keypresses
char udpMessage[10000];
udpConnection.Receive(udpMessage,10000);
string msg=udpMessage;