Fixed issue 506 - plus some quite major refactoring
This commit is contained in:
parent
a19e800b99
commit
24765e6891
|
@ -200,21 +200,8 @@ mainLoopStatic()
|
|||
int
|
||||
CArchAppUtilWindows::daemonNTMainLoop(int argc, const char** argv)
|
||||
{
|
||||
app().parseArgs(argc, argv);
|
||||
|
||||
if (app().argsBase().m_debugServiceWait)
|
||||
{
|
||||
while(true)
|
||||
{
|
||||
// this code is only executed when the process is launched via the
|
||||
// windows service controller (and --debug-service-wait arg is
|
||||
// used). to debug, set a breakpoint on this line so that
|
||||
// execution is delayed until the debugger is attached.
|
||||
ARCH->sleep(1);
|
||||
LOG((CLOG_INFO "waiting for debugger to attach"));
|
||||
}
|
||||
}
|
||||
|
||||
app().initialize(argc, argv);
|
||||
debugServiceWait();
|
||||
app().argsBase().m_backend = false;
|
||||
app().loadConfig();
|
||||
return CArchMiscWindows::runDaemon(mainLoopStatic);
|
||||
|
@ -301,3 +288,20 @@ CArchAppUtilWindows::instance()
|
|||
{
|
||||
return (CArchAppUtilWindows&)CArchAppUtil::instance();
|
||||
}
|
||||
|
||||
void
|
||||
CArchAppUtilWindows::debugServiceWait()
|
||||
{
|
||||
if (app().argsBase().m_debugServiceWait)
|
||||
{
|
||||
while(true)
|
||||
{
|
||||
// this code is only executed when the process is launched via the
|
||||
// windows service controller (and --debug-service-wait arg is
|
||||
// used). to debug, set a breakpoint on this line so that
|
||||
// execution is delayed until the debugger is attached.
|
||||
ARCH->sleep(1);
|
||||
LOG((CLOG_INFO "waiting for debugger to attach"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,6 +56,8 @@ public:
|
|||
|
||||
int daemonNTMainLoop(int argc, const char** argv);
|
||||
|
||||
void debugServiceWait();
|
||||
|
||||
int run(int argc, char** argv, CreateTaskBarReceiverFunc createTaskBarReceiver);
|
||||
|
||||
void exitApp(int code);
|
||||
|
|
|
@ -255,27 +255,22 @@ CBufferedLogOutputter::write(ELevel, const char* message)
|
|||
CFileLogOutputter::CFileLogOutputter(const char* logFile)
|
||||
{
|
||||
assert(logFile != NULL);
|
||||
|
||||
m_handle.open(logFile, std::fstream::app);
|
||||
// open file handle
|
||||
m_fileName = logFile;
|
||||
}
|
||||
|
||||
CFileLogOutputter::~CFileLogOutputter()
|
||||
{
|
||||
// close file handle
|
||||
if (m_handle.is_open())
|
||||
m_handle.close();
|
||||
}
|
||||
|
||||
bool
|
||||
CFileLogOutputter::write(ILogOutputter::ELevel level, const char *message)
|
||||
{
|
||||
std::ofstream m_handle;
|
||||
m_handle.open(m_fileName.c_str(), std::fstream::app);
|
||||
if (m_handle.is_open() && m_handle.fail() != true) {
|
||||
m_handle << message << std::endl;
|
||||
|
||||
// write buffer to file
|
||||
m_handle.flush();
|
||||
}
|
||||
m_handle.close();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -77,7 +77,7 @@ public:
|
|||
virtual void show(bool showIfEmpty);
|
||||
virtual bool write(ELevel level, const char* message);
|
||||
private:
|
||||
std::ofstream m_handle;
|
||||
std::string m_fileName;
|
||||
};
|
||||
|
||||
//! Write log to system log
|
||||
|
|
|
@ -43,9 +43,6 @@ s_suspended(false)
|
|||
CApp::~CApp()
|
||||
{
|
||||
delete m_args;
|
||||
|
||||
CLOG->remove(m_fileLog);
|
||||
delete m_fileLog;
|
||||
}
|
||||
|
||||
CApp::CArgsBase::CArgsBase() :
|
||||
|
@ -214,12 +211,6 @@ CApp::parseArgs(int argc, const char* const* argv, int& i)
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// increase default filter level for daemon. the user must
|
||||
// explicitly request another level for a daemon.
|
||||
if (argsBase().m_daemon && argsBase().m_logFilter == NULL) {
|
||||
argsBase().m_logFilter = "NOTE";
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -318,3 +309,16 @@ CApp::loggingFilterWarning()
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
CApp::initialize(int argc, const char** argv)
|
||||
{
|
||||
// parse command line
|
||||
parseArgs(argc, argv);
|
||||
|
||||
// setup file logging after parsing args
|
||||
setupFileLogging();
|
||||
|
||||
// load configuration
|
||||
loadConfig();
|
||||
}
|
||||
|
|
|
@ -97,6 +97,12 @@ public:
|
|||
// If messages will be hidden (to improve performance), warn user.
|
||||
void loggingFilterWarning();
|
||||
|
||||
// Parses args, sets up file logging, and loads the config.
|
||||
void initialize(int argc, const char** argv);
|
||||
|
||||
// HACK: accept non-const, but make it const anyway
|
||||
void initialize(int argc, char** argv) { initialize(argc, (const char**)argv); }
|
||||
|
||||
protected:
|
||||
virtual void parseArgs(int argc, const char* const* argv, int &i);
|
||||
virtual bool parseArg(const int& argc, const char* const* argv, int& i);
|
||||
|
|
|
@ -412,8 +412,7 @@ CClientApp::closeClient(CClient* client)
|
|||
int
|
||||
CClientApp::foregroundStartup(int argc, char** argv)
|
||||
{
|
||||
// parse command line
|
||||
parseArgs(argc, argv);
|
||||
initialize(argc, argv);
|
||||
|
||||
// never daemonize
|
||||
return mainLoop();
|
||||
|
@ -477,11 +476,6 @@ CClientApp::stopClient()
|
|||
int
|
||||
CClientApp::mainLoop()
|
||||
{
|
||||
// logging to files
|
||||
CFileLogOutputter* fileLog = NULL;
|
||||
|
||||
setupFileLogging();
|
||||
|
||||
// create socket multiplexer. this must happen after daemonization
|
||||
// on unix because threads evaporate across a fork().
|
||||
CSocketMultiplexer multiplexer;
|
||||
|
@ -528,12 +522,7 @@ daemonMainLoopStatic(int argc, const char** argv)
|
|||
int
|
||||
CClientApp::standardStartup(int argc, char** argv)
|
||||
{
|
||||
if (!args().m_daemon) {
|
||||
ARCH->showConsole(false);
|
||||
}
|
||||
|
||||
// parse command line
|
||||
parseArgs(argc, argv);
|
||||
initialize(argc, argv);
|
||||
|
||||
// daemonize if requested
|
||||
if (args().m_daemon) {
|
||||
|
|
|
@ -717,8 +717,6 @@ int CServerApp::mainLoop()
|
|||
// create the event queue
|
||||
CEventQueue eventQueue;
|
||||
|
||||
setupFileLogging();
|
||||
|
||||
// if configuration has no screens then add this system
|
||||
// as the default
|
||||
if (args().m_config->begin() == args().m_config->end()) {
|
||||
|
@ -841,11 +839,7 @@ int daemonMainLoopStatic(int argc, const char** argv) {
|
|||
int
|
||||
CServerApp::standardStartup(int argc, char** argv)
|
||||
{
|
||||
// parse command line
|
||||
parseArgs(argc, argv);
|
||||
|
||||
// load configuration
|
||||
loadConfig();
|
||||
initialize(argc, argv);
|
||||
|
||||
// daemonize if requested
|
||||
if (args().m_daemon) {
|
||||
|
@ -859,11 +853,7 @@ CServerApp::standardStartup(int argc, char** argv)
|
|||
int
|
||||
CServerApp::foregroundStartup(int argc, char** argv)
|
||||
{
|
||||
// parse command line
|
||||
parseArgs(argc, argv);
|
||||
|
||||
// load configuration
|
||||
loadConfig();
|
||||
initialize(argc, argv);
|
||||
|
||||
// never daemonize
|
||||
return mainLoop();
|
||||
|
|
Loading…
Reference in New Issue