2013-07-29 19:03:59 +00:00
|
|
|
#include "fifoconsole.h"
|
|
|
|
|
|
|
|
#include <engine/shared/config.h>
|
|
|
|
|
|
|
|
#include <fstream>
|
|
|
|
|
|
|
|
#include <pthread.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
|
|
FifoConsole::FifoConsole(IConsole *pConsole)
|
|
|
|
{
|
2013-08-03 15:22:50 +00:00
|
|
|
void *m_pFifoThread = thread_create(ListenFifoThread, pConsole);
|
2013-07-29 19:03:59 +00:00
|
|
|
#if defined(CONF_FAMILY_UNIX)
|
2013-08-03 15:22:50 +00:00
|
|
|
pthread_detach((pthread_t)m_pFifoThread);
|
2013-07-29 19:03:59 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-08-03 15:22:50 +00:00
|
|
|
FifoConsole::~FifoConsole()
|
|
|
|
{
|
|
|
|
thread_destroy(m_pFifoThread);
|
|
|
|
}
|
|
|
|
|
2013-07-29 19:03:59 +00:00
|
|
|
void FifoConsole::ListenFifoThread(void *pUser)
|
|
|
|
{
|
|
|
|
IConsole *pConsole = (IConsole *)pUser;
|
|
|
|
|
|
|
|
if (str_comp(g_Config.m_SvInputFifo, "") == 0)
|
|
|
|
return;
|
|
|
|
|
2013-07-30 01:16:02 +00:00
|
|
|
mkfifo(g_Config.m_SvInputFifo, 0600);
|
2013-07-29 19:03:59 +00:00
|
|
|
|
|
|
|
std::ifstream f;
|
|
|
|
char aBuf[256];
|
|
|
|
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
f.open(g_Config.m_SvInputFifo);
|
|
|
|
while (f.getline(aBuf, 256))
|
|
|
|
{
|
|
|
|
pConsole->ExecuteLineFlag(aBuf, CFGFLAG_SERVER, -1);
|
|
|
|
}
|
|
|
|
f.close();
|
|
|
|
}
|
|
|
|
}
|