Simplify remote commands

- Read a command from the pipe, rather than reading a file with a
  command in it.
- Use a single ocarina script for all commands, rather than several two
  line scripts.
- Change ocarina.bin to point to ocarina instead of ocarina-player for
  convenience.

Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
Bryan Schumaker 2012-09-13 20:57:59 -04:00
parent 4bf66921df
commit 8a08967a48
14 changed files with 45 additions and 112 deletions

View File

@ -17,7 +17,7 @@ namespace libsaria
void quit();
void play_outside_song(string &);
void read_piped_file(string &);
void run_cmd(string &);
}
#endif /* LIBSARIA_H */

View File

@ -7,11 +7,8 @@
#include <fstream>
using namespace std;
static void run_cmd(ifstream &in, string &file)
void libsaria::run_cmd(string &cmd)
{
string cmd;
in >> cmd;
if (cmd == "play")
libsaria::audio::play();
else if (cmd == "pause")
@ -25,16 +22,3 @@ static void run_cmd(ifstream &in, string &file)
else if (cmd == "prev")
libsaria::deck::prev();
}
void libsaria::read_piped_file(string &file)
{
ifstream in;
string cmd;
if (!exists(file))
return;
in.open(file.c_str());
run_cmd(in, file);
in.close();
}

View File

@ -4,15 +4,24 @@ from config import *
env.ParseConfig('pkg-config --cflags --libs gtk+-2.0')
env.ParseConfig('pkg-config --cflags --libs gmodule-export-2.0')
files = get_cpp_files()
def script(target, source, env):
f = open(str(target[0]), 'w')
for line in open(str(source[0])):
line = line.replace("%DEBUG", str(DEBUG))
f.write(line)
f.close()
os.chmod(str(target[0]), 0755)
extra_files = [
("../bin/ocarina-player", "../ocarina.bin", symlink),
("ocarina.xml", "../lib/ocarina/ocarina.xml", copy),
("images/ocarina.png", "../lib/ocarina/ocarina.png", copy),
("scripts/ocarina", "../bin/ocarina", script),
("../bin/ocarina", "../ocarina.bin", symlink),
]
build = [env.Program("../bin/ocarina-player", libsaria + files)]
build = [env.Program("../bin/ocarina-player", libsaria + get_cpp_files())]
for (src, dst, func) in extra_files:
build.append(env.Command(dst, src, func))

View File

@ -29,7 +29,7 @@ static gboolean pipe_read(GIOChannel *source, GIOCondition condition, gpointer d
{
string text;
pipe_read_text(source, text);
libsaria::read_piped_file(text);
libsaria::run_cmd(text);
return TRUE;
}

30
ocarina/scripts/ocarina Normal file
View File

@ -0,0 +1,30 @@
#!/bin/bash
APPDIR="$HOME/.ocarina"
if [ "%DEBUG" == "True" ]; then
APPDIR="$APPDIR-debug"
fi
function write_to_pipe
{
pipe=$APPDIR/pipe
if [ -p $pipe ]; then
echo "$*" > $pipe
fi
}
case $1 in
next|pause|play|prev|stop|toggle)
write_to_pipe $1
exit 0
;;
esac
cmd=`which ocarina-$1 2>/dev/null`
args="${@: +2}"
if [ "$cmd" ]; then
$cmd "$args"
else
cmd=`readlink -f $0`
`dirname $cmd`/ocarina-player "$*"
fi

View File

@ -1,9 +0,0 @@
#!/bin/bash
cmd=`which %APP-$1 2>/dev/null`
args="${@: +2}"
if [ "$cmd" ]; then
$cmd "$args"
else
%APP-player "$*"
fi

View File

@ -1,3 +0,0 @@
#!/bin/bash
. %LIB/functions
write_to_pipe "next"

View File

@ -1,3 +0,0 @@
#!/bin/bash
. %LIB/functions
write_to_pipe "pause"

View File

@ -1,3 +0,0 @@
#!/bin/bash
. %LIB/functions
write_to_pipe "play"

View File

@ -1,3 +0,0 @@
#!/bin/bash
. %LIB/functions
write_to_pipe "prev"

View File

@ -1,3 +0,0 @@
#!/bin/bash
. %LIB/functions
write_to_pipe "stop"

View File

@ -1,3 +0,0 @@
#!/bin/bash
. %LIB/functions
write_to_pipe "toggle"

View File

@ -1,38 +0,0 @@
#!/usr/bin/python
import os, re
from config import *
bin = "../bin/%s"
lib = "../lib/" + application + "/%s"
LIBDIR="`dirname $0`/../lib/" + application
def create_script(target, source, env):
dst = str(target[0].rfile())
src = str(source[0].rfile())
f = open(dst, "w");
for line in open(src):
line = line.replace("%APP", application)
line = line.replace("%LIB", LIBDIR)
line = line.replace("%DEBUG", str(DEBUG))
f.write(line)
f.close()
os.chmod(dst, 0755)
files = []
for file in os.listdir("."):
# SConscript swap files and stuff
if re.search("Sconscript", file):
continue
elif file[0] == ".":
continue
dir = bin
if file == "functions":
dir = lib
dst = (dir % file).replace("%APP", application)
files.append(env.Command(dst, file, create_script))
Return('files')

View File

@ -1,25 +0,0 @@
#!/bin/bash
DEBUG=%DEBUG
function get_app_dir
{
dir="$HOME/.%APP"
if [ "$DEBUG" == "True" ]; then
dir="$dir-debug"
fi
echo $dir
}
function write_to_pipe
{
pipe=`get_app_dir`/pipe
if [ ! -p $pipe ]; then
exit 0
fi
file=`mktemp`
echo "$*" > $file
echo $file > $pipe
rm -f $file
}