libsaria: Create functions for opening and closing pipes
I'm going to use the pipe with shell scripts for remote-controlling ocarina (possibly through a web interface). Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
parent
463cef95dd
commit
8f1de2745e
|
@ -30,6 +30,10 @@ namespace libsaria
|
|||
void read(string, void (*)(ifstream &));
|
||||
void read_now(string, void (*)(ifstream &));
|
||||
|
||||
void open_pipe();
|
||||
void close_pipe();
|
||||
string pipe_file();
|
||||
|
||||
} /* Namespace: app */
|
||||
|
||||
} /* Namespace: libsaria */
|
||||
|
|
|
@ -10,6 +10,7 @@ namespace libsaria
|
|||
char **argv;
|
||||
string name;
|
||||
bool enable_idle;
|
||||
bool enable_pipe;
|
||||
};
|
||||
|
||||
void init(struct initdata *);
|
||||
|
|
|
@ -11,6 +11,7 @@ using namespace std;
|
|||
|
||||
static string appdir;
|
||||
static mode_t dirmode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
|
||||
static bool pipe_opened = false;
|
||||
|
||||
static void make_dir(string path)
|
||||
{
|
||||
|
@ -145,4 +146,30 @@ namespace libsaria
|
|||
stream.close();
|
||||
}
|
||||
|
||||
void app::open_pipe()
|
||||
{
|
||||
string file = appdir + "/pipe";
|
||||
if (!exists(file)) {
|
||||
mkfifo(file.c_str(), 0644);
|
||||
pipe_opened = true;
|
||||
} else {
|
||||
println("Pipe file: %s already exists, pipe not opened!",
|
||||
file.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void app::close_pipe()
|
||||
{
|
||||
string file = appdir + "/pipe";
|
||||
if (pipe_opened && exists(file))
|
||||
rm("pipe");
|
||||
}
|
||||
|
||||
string app::pipe_file()
|
||||
{
|
||||
if (pipe_opened)
|
||||
return appdir + "/pipe";
|
||||
return "";
|
||||
}
|
||||
|
||||
} /* Namespace: libsaria */
|
||||
|
|
|
@ -28,19 +28,22 @@ namespace libsaria
|
|||
idle::enable();
|
||||
|
||||
audio::init(init->argc, init->argv);
|
||||
|
||||
libsaria::deck::init();
|
||||
libsaria::library::init();
|
||||
libsaria::deck::load_all();
|
||||
|
||||
if (init->enable_pipe)
|
||||
app::open_pipe();
|
||||
|
||||
}
|
||||
|
||||
void quit()
|
||||
{
|
||||
println("Quitting libsaria");
|
||||
app::close_pipe();
|
||||
audio::quit();
|
||||
print_format_stats();
|
||||
Index::print_stats();
|
||||
/*close_pipes();*/
|
||||
}
|
||||
|
||||
void play_outside_song(string &filepath)
|
||||
|
|
|
@ -80,6 +80,7 @@ int main(int argc, char **argv)
|
|||
argv,
|
||||
"ocarina", /* app name */
|
||||
true, /* Use idle queue? */
|
||||
true, /* Use global pipe? */
|
||||
};
|
||||
println("Ocarina " + vers_str());
|
||||
set_path_prefix(argv[0]);
|
||||
|
|
Loading…
Reference in New Issue