/* * File: NamedPipe.cpp * * Author: Jacob Dekel * Created on: Aug 7, 2009 * * Copyright (c) 2009-2013 Jacob Dekel * $Id$ * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * */ #include "HerculesStudio.h" #include "SystemUtils.h" #include "NamedPipe.h" #include #include #include #include #include #include #include #include #ifndef hFramework #include #include #include #endif #define MAXIMUM_SETS 20 NamedPipe NamedPipe::sInstance; NamedPipe::NamedPipe() { } NamedPipe& NamedPipe::getInstance() { return sInstance; } NamedPipe::~NamedPipe() { } int NamedPipe::recover() { #ifndef hFramework int set = 0; mRecovery = false; char * home = getenv("HOME"); std::string hercstudioDir = home; hercstudioDir += "/.hercstudio"; std::string setPath; int rc = mkdir(hercstudioDir.c_str(), 0777); if (rc<0 && errno != EEXIST) { perror(hercstudioDir.c_str()); hOutDebug(1,"rc=" << errno); return -1; } for (int pipeSet=0; pipeSetopen(QIODevice::ReadOnly); } return *mStdoutInput; } FILE * NamedPipe::getHerculesStderr() { if (mStderr == NULL) { mStderr = fopen(mFifo2.c_str(),"w"); } return mStderr; } QFile& NamedPipe::getHerculesStatus() { if (mStderrInput == NULL) { mStderrInput = new QFile(mFifo2.c_str()); mStderrInput->open(QIODevice::ReadOnly); } return *mStderrInput; } std::string NamedPipe::getHerculesCommandline() { std::stringstream procPath; procPath << "/proc/" << mHerculesPid << "/cmdline"; FILE * f = fopen(procPath.str().c_str(),"r"); if (f==NULL) return ""; char buff[255]; int len = fread(buff,sizeof(char), 255,f); if (len == -1) { fclose(f); return ""; } for (int i=0; i