fifoconsole cleanup

This commit is contained in:
def 2014-08-29 19:42:34 +02:00
parent 1cf476c1f6
commit 9f4ac93d90
4 changed files with 17 additions and 28 deletions

View file

@ -68,8 +68,6 @@
#undef main
#endif
bool IsClient = true;
void CGraph::Init(float Min, float Max)
{
m_Min = Min;
@ -3129,7 +3127,7 @@ int main(int argc, const char **argv) // ignore_convention
pClient->Engine()->InitLogfile();
#if defined(CONF_FAMILY_UNIX)
FifoConsole *fifoConsole = new FifoConsole(pConsole);
FifoConsole *fifoConsole = new FifoConsole(pConsole, g_Config.m_ClInputFifo, CFGFLAG_CLIENT);
#endif
// run the client

View file

@ -42,8 +42,6 @@
#include <windows.h>
#endif
bool IsClient = false;
static const char *StrLtrim(const char *pStr)
{
while(*pStr)
@ -2032,7 +2030,7 @@ int main(int argc, const char **argv) // ignore_convention
pEngine->InitLogfile();
#if defined(CONF_FAMILY_UNIX)
FifoConsole *fifoConsole = new FifoConsole(pConsole);
FifoConsole *fifoConsole = new FifoConsole(pConsole, g_Config.m_SvInputFifo, CFGFLAG_SERVER);
#endif
// run the server

View file

@ -10,31 +10,26 @@
#include <sys/types.h>
#include <sys/stat.h>
extern bool IsClient;
FifoConsole::FifoConsole(IConsole *pConsole)
FifoConsole::FifoConsole(IConsole *pConsole, char *pFifoFile, int flag)
{
void *m_pFifoThread = thread_create(ListenFifoThread, pConsole);
void *m_pFifoThread = thread_create(ListenFifoThread, this);
m_pConsole = pConsole;
m_pFifoFile = pFifoFile;
m_flag = flag;
pthread_detach((pthread_t)m_pFifoThread);
}
void FifoConsole::ListenFifoThread(void *pUser)
{
IConsole *pConsole = (IConsole *)pUser;
FifoConsole *pData = (FifoConsole *)pUser;
char *fifofile;
if (IsClient)
fifofile = g_Config.m_ClInputFifo;
else
fifofile = g_Config.m_SvInputFifo;
if (str_comp(fifofile, "") == 0)
if (str_comp(pData->m_pFifoFile, "") == 0)
return;
mkfifo(fifofile, 0600);
mkfifo(pData->m_pFifoFile, 0600);
struct stat attribute;
stat(fifofile, &attribute);
stat(pData->m_pFifoFile, &attribute);
if(!S_ISFIFO(attribute.st_mode))
return;
@ -44,14 +39,9 @@ void FifoConsole::ListenFifoThread(void *pUser)
while (true)
{
f.open(fifofile);
f.open(pData->m_pFifoFile);
while (f.getline(aBuf, sizeof(aBuf)))
{
if (IsClient)
pConsole->ExecuteLineFlag(aBuf, CFGFLAG_CLIENT, -1);
else
pConsole->ExecuteLineFlag(aBuf, CFGFLAG_SERVER, -1);
}
pData->m_pConsole->ExecuteLineFlag(aBuf, pData->m_flag, -1);
f.close();
}
}

View file

@ -8,10 +8,13 @@
class FifoConsole
{
static void ListenFifoThread(void *pUser);
IConsole *m_pConsole;
void *m_pFifoThread;
char *m_pFifoFile;
int m_flag;
public:
FifoConsole(IConsole *pConsole);
FifoConsole(IConsole *pConsole, char *pFifoFile, int flag);
};
#endif