Some static/non-static fixes to procs/stream library, updated converter to make use of getOutputOf function instead of re-implementing this.

This commit is contained in:
Thulinma 2013-08-27 00:29:04 +02:00
parent d7e9029609
commit 6675b647b8
4 changed files with 10 additions and 25 deletions

View file

@ -61,12 +61,9 @@ namespace Converter {
}
JSON::Value Converter::queryPath(std::string myPath){
std::vector<char*> cmd;
cmd.reserve(3);
char const * cmd[3] = {0, 0, 0};
std::string mistPath = Util::getMyPath() + "MistInfo";
cmd.push_back((char*)mistPath.c_str());
cmd.push_back(NULL);
cmd.push_back(NULL);
cmd[0] = mistPath.c_str();
fprintf( stderr, "Querying %s\n", myPath.c_str());
JSON::Value result;
DIR * Dirp = opendir(myPath.c_str());
@ -82,20 +79,8 @@ namespace Converter {
}
std::string fileName = entry->d_name;
std::string mijnPad = std::string(myPath + (myPath[myPath.size()-1] == '/' ? "" : "/") + entry->d_name);
cmd[1] = (char*)mijnPad.c_str();
int outFD = -1;
Util::Procs::StartPiped("MistInfo", &cmd[0], 0, &outFD, 0);
while( Util::Procs::isActive("MistInfo")){ Util::sleep(10); }
FILE * outFile = fdopen( outFD, "r" );
char * fileBuf = 0;
size_t fileBufLen = 0;
getline(&fileBuf, &fileBufLen, outFile);
std::string line = fileBuf;
result[fileName] = JSON::fromString(std::string(fileBuf));
if ( !result[fileName]){
result.removeMember(fileName);
}
fclose( outFile );
cmd[1] = mijnPad.c_str();
result[fileName] = JSON::fromString(Util::Procs::getOutputOf((char* const*)cmd));
}
}
return result;

View file

@ -153,7 +153,7 @@ void Util::Procs::childsig_handler(int signum){
/// Runs the given command and returns the stdout output as a string.
std::string Util::Procs::getOutputOf(char * argv[]){
std::string Util::Procs::getOutputOf(char* const* argv){
std::string ret;
int fin = 0, fout = -1, ferr = 0;
StartPiped("output_getter", argv, &fin, &fout, &ferr);
@ -433,7 +433,7 @@ pid_t Util::Procs::Start(std::string name, std::string cmd, std::string cmd2, st
/// \arg fdin Standard input file descriptor. If null, /dev/null is assumed. Otherwise, if arg contains -1, a new fd is automatically allocated and written into this arg. Then the arg will be used as fd.
/// \arg fdout Same as fdin, but for stdout.
/// \arg fdout Same as fdin, but for stderr.
pid_t Util::Procs::StartPiped(std::string name, char * argv[], int * fdin, int * fdout, int * fderr){
pid_t Util::Procs::StartPiped(std::string name, char* const* argv, int * fdin, int * fdout, int * fderr){
if (isActive(name)){
#if DEBUG >= 1
std::cerr << name << " already active - skipping start" << std::endl;

View file

@ -23,12 +23,12 @@ namespace Util {
static void runCmd(std::string & cmd);
static void setHandler();
public:
static std::string getOutputOf(char * argv[]);
static std::string getOutputOf(char* const* argv);
static std::string getOutputOf(std::string cmd);
static pid_t Start(std::string name, std::string cmd);
static pid_t Start(std::string name, std::string cmd, std::string cmd2);
static pid_t Start(std::string name, std::string cmd, std::string cmd2, std::string cmd3);
static pid_t StartPiped(std::string name, char * argv[], int * fdin, int * fdout, int * fderr);
static pid_t StartPiped(std::string name, char* const* argv, int * fdin, int * fdout, int * fderr);
static pid_t StartPiped(std::string name, std::string cmd, int * fdin, int * fdout, int * fderr);
static pid_t StartPiped2(std::string name, std::string cmd1, std::string cmd2, int * fdin, int * fdout, int * fderr1, int * fderr2);
static void Stop(std::string name);

View file

@ -39,9 +39,9 @@ Socket::Connection Util::Stream::getLive(std::string streamname){
Socket::Connection Util::Stream::getVod(std::string filename){
std::string name = "MistPlayer " + filename;
std::string player_bin = Util::getMyPath() + "MistPlayer";
const char *argv[] = {player_bin.c_str(), filename.c_str(), NULL};
char* const argv[] = {(char*)player_bin.c_str(), (char*)filename.c_str(), NULL};
int fdin = -1, fdout = -1, fderr = fileno(stderr);
Util::Procs::StartPiped(name, (char **)argv, &fdin, &fdout, &fderr);
Util::Procs::StartPiped(name, argv, &fdin, &fdout, &fderr);
// if StartPiped fails then fdin and fdout will be unmodified (-1)
return Socket::Connection(fdin, fdout);
}