ocarina: Tell gtk to look for data coming in over the pipe

This gives me a chance to read it without needing to poll for changes.

Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
Bryan Schumaker 2012-05-15 11:33:29 -04:00
parent 8f1de2745e
commit a7570cc80a
2 changed files with 10 additions and 22 deletions

View File

@ -70,6 +70,7 @@ static void init(int argc, char **argv)
ocarina::window::init();
ocarina::body::init();
ocarina::playlist::init();
ocarina::init_pipe();
gtk_timeout_add(100, timeout_poll, NULL);
}

View File

@ -1,46 +1,33 @@
// Copyright (c) Bryan Schumaker 2012.
#include <libsaria/path.h>
#include <libsaria/print.h>
#include <libsaria/audio.h>
#include <ocarina/ocarina.h>
#include <libsaria/fs.h>
#include <glib.h>
#include <string>
using namespace std;
static GIOChannel *pipe_in;
void perform_action(string action)
{
/* if (action == "play")
libsaria::audio::play();
else if (action == "pause")
libsaria::audio::pause();
else if (action == "stop")
libsaria::audio::stop();
else if (action == "next")
libsaria::next();*/
}
string pipe_read_text(GIOChannel *source)
void pipe_read_text(GIOChannel *source, string &text)
{
gchar *str = NULL;
GError *error = NULL;
gsize size, end;
string text;
g_io_channel_read_line(source, &str, &size, &end, &error);
text = str;
/* Strip newline character */
text = text.substr(0, text.size() - 1);
/* g_io_channel_read_line allocates memory */
g_free(str);
return text.substr(0, size-1);
}
gboolean pipe_read(GIOChannel *source, GIOCondition condition, gpointer data)
{
string action = pipe_read_text(source);
perform_action(action);
string text;
pipe_read_text(source, text);
println("Piped text: %s", text.c_str());
return TRUE;
}
@ -49,7 +36,7 @@ namespace ocarina
void init_pipe()
{
GError *error = NULL;
string pipe = open_pipe("ocarina.pipe");
string pipe = libsaria::app::pipe_file();
if (pipe == "")
return;