libsaria: Allow different UIs to use a different pipe
The UI now passes in a string to use as the filename. In addition, I store the filename and remove it when the application is closed. If the pipe already exists, then I return the path without creating a new one. Pipes will only be removed by the application that creates them. Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
parent
0aa8b950a9
commit
280baa7572
|
@ -19,6 +19,7 @@ string get_saria_dir();
|
|||
void make_saria_dir();
|
||||
bool exists(string);
|
||||
sid_t lookup_songid(string &);
|
||||
string get_pipe_file();
|
||||
string open_pipe(string);
|
||||
void close_pipes();
|
||||
|
||||
#endif /* LIBSARIA_PATH_H */
|
||||
|
|
|
@ -31,6 +31,7 @@ namespace libsaria
|
|||
println("Quitting libsaria");
|
||||
print_format_stats();
|
||||
index::print_stats();
|
||||
close_pipes();
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include <libsaria/path.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <list>
|
||||
using namespace std;
|
||||
|
||||
/* I want to use the d_type field in a dirent */
|
||||
|
@ -63,12 +64,22 @@ sid_t lookup_songid(string &filepath)
|
|||
return stat.st_ino;
|
||||
}
|
||||
|
||||
string get_pipe_file()
|
||||
{
|
||||
struct stat stat;
|
||||
string file = get_saria_dir() + "/saria.pipe";
|
||||
static list<string> open_pipes;
|
||||
|
||||
if (lstat(file.c_str(), &stat) != 0)
|
||||
return "";
|
||||
string open_pipe(string filename)
|
||||
{
|
||||
string file = get_saria_dir() + "/" + filename;
|
||||
|
||||
if (!exists(file)) {
|
||||
open_pipes.push_back(file);
|
||||
mkfifo(file.c_str(), 0644);
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
void close_pipes()
|
||||
{
|
||||
list<string>::iterator it;
|
||||
for (it = open_pipes.begin(); it != open_pipes.end(); it++)
|
||||
unlink((*it).c_str());
|
||||
}
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
#include <ocarina/ocarina.h>
|
||||
|
||||
#include <glib.h>
|
||||
#include <string>
|
||||
using namespace std;
|
||||
|
||||
static GIOChannel *pipe_in;
|
||||
|
||||
|
@ -46,7 +48,7 @@ namespace ocarina
|
|||
void init_pipe()
|
||||
{
|
||||
GError *error = NULL;
|
||||
string pipe = get_pipe_file();
|
||||
string pipe = open_pipe("ocarina.pipe");
|
||||
if (pipe == "")
|
||||
return;
|
||||
|
||||
|
|
Loading…
Reference in New Issue