libsaria: Read file from pipe
Scripts should write commands to a temporary file and then write the path to that file to the application pipe. I can then write results of the command to this file before exiting. Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
parent
a7570cc80a
commit
ea7b66ae6d
|
@ -17,6 +17,7 @@ namespace libsaria
|
|||
void quit();
|
||||
|
||||
void play_outside_song(string &);
|
||||
void read_piped_file(string &);
|
||||
}
|
||||
|
||||
#endif /* LIBSARIA_H */
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
// Copyright (c) Bryan Schumaker 2012.
|
||||
#include <libsaria/libsaria.h>
|
||||
#include <libsaria/print.h>
|
||||
#include <libsaria/audio.h>
|
||||
|
||||
#include <fstream>
|
||||
using namespace std;
|
||||
|
||||
static void run_cmd(ifstream &in, string &file)
|
||||
{
|
||||
string cmd;
|
||||
in >> cmd;
|
||||
|
||||
if (cmd == "play")
|
||||
libsaria::audio::play();
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
// Copyright (c) Bryan Schumaker 2012.
|
||||
#include <libsaria/libsaria.h>
|
||||
#include <libsaria/print.h>
|
||||
#include <libsaria/fs.h>
|
||||
|
||||
#include <glib.h>
|
||||
#include <string>
|
||||
using namespace std;
|
||||
|
@ -27,7 +29,7 @@ gboolean pipe_read(GIOChannel *source, GIOCondition condition, gpointer data)
|
|||
{
|
||||
string text;
|
||||
pipe_read_text(source, text);
|
||||
println("Piped text: %s", text.c_str());
|
||||
libsaria::read_piped_file(text);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue