Merge 1.4.1 into trunk

This commit is contained in:
Nick Bolton
2010-06-12 17:20:54 +00:00
parent 1698161945
commit a8eb2a3bfd
27 changed files with 841 additions and 351 deletions

View File

@@ -666,9 +666,9 @@ CArch::app() const
}
int
CArch::run(int argc, char** argv, CreateTaskBarReceiverFunc createTaskBarReceiver)
CArch::run(int argc, char** argv)
{
return m_appUtil->run(argc, argv, createTaskBarReceiver);
return m_appUtil->run(argc, argv);
}
void

View File

@@ -186,7 +186,7 @@ public:
virtual bool parseArg(const int& argc, const char* const* argv, int& i);
virtual void adoptApp(CApp* app);
virtual CApp& app() const;
virtual int run(int argc, char** argv, CreateTaskBarReceiverFunc createTaskBarReceiver);
virtual int run(int argc, char** argv);
virtual void beforeAppExit();
// expose util so we don't need to re-implement all the functions

View File

@@ -44,10 +44,13 @@ CArchAppUtilWindows::~CArchAppUtilWindows()
BOOL WINAPI CArchAppUtilWindows::consoleHandler(DWORD CEvent)
{
// HACK: it would be nice to delete the s_taskBarReceiver object, but
// this is best done by the CApp destructor; however i don't feel like
// opening up that can of worms today... i need sleep.
instance().app().s_taskBarReceiver->cleanup();
if (instance().app().m_taskBarReceiver)
{
// HACK: it would be nice to delete the s_taskBarReceiver object, but
// this is best done by the CApp destructor; however i don't feel like
// opening up that can of worms today... i need sleep.
instance().app().m_taskBarReceiver->cleanup();
}
ExitProcess(kExitTerminated);
return TRUE;
@@ -83,8 +86,17 @@ CArchAppUtilWindows::parseArg(const int& argc, const char* const* argv, int& i)
app().argsBase().m_debugServiceWait = true;
}
else if (app().isArg(i, argc, argv, NULL, "--relaunch")) {
app().argsBase().m_relaunchMode = true;
}
else if (app().isArg(i, argc, argv, NULL, "--exit-pause")) {
app().argsBase().m_pauseOnExit = true;
}
else if (app().isArg(i, argc, argv, NULL, "--no-tray")) {
app().argsBase().m_disableTray = true;
}
else {
// option not supported here
return false;
@@ -258,20 +270,17 @@ foregroundStartupStatic(int argc, char** argv)
void
CArchAppUtilWindows::beforeAppExit()
{
CString name;
CArchMiscWindows::getParentProcessName(name);
// if the user did not launch from the command prompt (i.e. it was launched
// by double clicking, or through a debugger), allow user to read any error
// messages (instead of the window closing automatically).
if (name != "cmd.exe") {
// this can be handy for debugging, since the application is launched in
// a new console window, and will normally close on exit (making it so
// that we can't see error messages).
if (app().argsBase().m_pauseOnExit) {
std::cout << std::endl << "Press any key to exit..." << std::endl;
int c = _getch();
}
}
int
CArchAppUtilWindows::run(int argc, char** argv, CreateTaskBarReceiverFunc createTaskBarReceiver)
CArchAppUtilWindows::run(int argc, char** argv)
{
// record window instance for tray icon, etc
CArchMiscWindows::setInstanceWin32(GetModuleHandle(NULL));
@@ -287,7 +296,7 @@ CArchAppUtilWindows::run(int argc, char** argv, CreateTaskBarReceiverFunc create
app().argsBase().m_daemon = false;
}
return app().runInner(argc, argv, NULL, startup, createTaskBarReceiver);
return app().runInner(argc, argv, NULL, startup);
}
CArchAppUtilWindows&

View File

@@ -58,7 +58,7 @@ public:
void debugServiceWait();
int run(int argc, char** argv, CreateTaskBarReceiverFunc createTaskBarReceiver);
int run(int argc, char** argv);
void exitApp(int code);

View File

@@ -25,7 +25,7 @@ public:
virtual bool parseArg(const int& argc, const char* const* argv, int& i) = 0;
virtual void adoptApp(CApp* app) = 0;
virtual CApp& app() const = 0;
virtual int run(int argc, char** argv, CreateTaskBarReceiverFunc createTaskBarReceiver) = 0;
virtual int run(int argc, char** argv) = 0;
virtual void beforeAppExit() = 0;
virtual void startNode() = 0;
};

View File

@@ -30,7 +30,7 @@ CMSWindowsRelauncher::startAsync()
void
CMSWindowsRelauncher::startThread(void*)
{
LOG((CLOG_DEBUG "starting relaunch loop"));
LOG((CLOG_NOTE "starting relaunch service"));
int ret = relaunchLoop();
// HACK: this actually throws an exception to exit with 0 (nasty)

View File

@@ -30,11 +30,12 @@
CApp* CApp::s_instance = nullptr;
CApp::CApp(CArgsBase* args) :
CApp::CApp(CreateTaskBarReceiverFunc createTaskBarReceiver, CArgsBase* args) :
m_createTaskBarReceiver(createTaskBarReceiver),
m_args(args),
m_bye(&exit),
s_taskBarReceiver(NULL),
s_suspended(false)
m_taskBarReceiver(NULL),
m_suspended(false)
{
assert(s_instance == nullptr);
s_instance = this;
@@ -50,6 +51,8 @@ CApp::CArgsBase::CArgsBase() :
m_daemon(false), // daemon mode not supported on windows (use --service)
m_debugServiceWait(false),
m_relaunchMode(false),
m_pauseOnExit(false),
m_disableTray(false),
#else
m_daemon(true), // backward compatibility for unix (daemon by default)
#endif
@@ -232,7 +235,7 @@ CApp::version()
}
int
CApp::run(int argc, char** argv, CreateTaskBarReceiverFunc createTaskBarReceiver)
CApp::run(int argc, char** argv)
{
#if SYSAPI_WIN32
// record window instance for tray icon, etc
@@ -251,7 +254,7 @@ CApp::run(int argc, char** argv, CreateTaskBarReceiverFunc createTaskBarReceiver
int result = kExitFailed;
try {
result = ARCH->run(argc, argv, createTaskBarReceiver);
result = ARCH->run(argc, argv);
}
catch (XExitApp& e) {
// instead of showing a nasty error, just exit with the error code.
@@ -322,4 +325,16 @@ CApp::initApp(int argc, const char** argv)
// load configuration
loadConfig();
if (!argsBase().m_disableTray) {
// create a log buffer so we can show the latest message
// as a tray icon tooltip
CBufferedLogOutputter* logBuffer = new CBufferedLogOutputter(1000);
CLOG->insert(logBuffer, true);
// make the task bar receiver. the user can control this app
// through the task bar.
m_taskBarReceiver = m_createTaskBarReceiver(logBuffer);
}
}

View File

@@ -44,10 +44,12 @@ public:
#if SYSAPI_WIN32
bool m_relaunchMode;
bool m_debugServiceWait;
bool m_pauseOnExit;
bool m_disableTray;
#endif
};
CApp(CArgsBase* args);
CApp(CreateTaskBarReceiverFunc createTaskBarReceiver, CArgsBase* args);
virtual ~CApp();
// Returns args that are common between server and client.
@@ -62,7 +64,7 @@ public:
// Parse command line arguments.
virtual void parseArgs(int argc, const char* const* argv) = 0;
int run(int argc, char** argv, CreateTaskBarReceiverFunc createTaskBarReceiver);
int run(int argc, char** argv);
int daemonMainLoop(int, const char**);
@@ -71,7 +73,7 @@ public:
virtual int mainLoop() = 0;
virtual int foregroundStartup(int argc, char** argv) = 0;
virtual int standardStartup(int argc, char** argv) = 0;
virtual int runInner(int argc, char** argv, ILogOutputter* outputter, StartupFunc startup, CreateTaskBarReceiverFunc createTaskBarReceiver) = 0;
virtual int runInner(int argc, char** argv, ILogOutputter* outputter, StartupFunc startup) = 0;
// Name of the daemon (used for Unix and Windows).
virtual const char* daemonName() const = 0;
@@ -90,8 +92,8 @@ public:
static CApp& instance() { assert(s_instance != nullptr); return *s_instance; }
bool s_suspended;
IArchTaskBarReceiver* s_taskBarReceiver;
bool m_suspended;
IArchTaskBarReceiver* m_taskBarReceiver;
// If --log was specified in args, then add a file logger.
void setupFileLogging();
@@ -118,6 +120,7 @@ private:
CArgsBase* m_args;
static CApp* s_instance;
CFileLogOutputter* m_fileLog;
CreateTaskBarReceiverFunc m_createTaskBarReceiver;
};
#define BYE "\nTry `%s --help' for more information."
@@ -166,6 +169,9 @@ private:
" --service <action> manage the windows service, valid options are:\n" \
" install/uninstall/start/stop\n" \
" --relaunch persistently relaunches process in current user \n" \
" session (useful for vista and upward).\n"
" session (useful for vista and upward).\n" \
" --exit-pause wait for key press on exit, can be useful for\n" \
" reading error messages that occur on exit.\n" \
" --no-tray disable the system tray icon.\n"
#endif

View File

@@ -49,8 +49,8 @@
#define RETRY_TIME 1.0
CClientApp::CClientApp() :
CApp(new CArgs()),
CClientApp::CClientApp(CreateTaskBarReceiverFunc createTaskBarReceiver) :
CApp(createTaskBarReceiver, new CArgs()),
s_client(NULL),
s_clientScreen(NULL)
{
@@ -168,6 +168,7 @@ CClientApp::help()
"Usage: %s"
" [--yscroll <delta>]"
WINAPI_ARG
HELP_SYS_ARGS
HELP_COMMON_ARGS
" <server-address>"
"\n\n"
@@ -175,6 +176,7 @@ CClientApp::help()
"\n"
HELP_COMMON_INFO_1
WINAPI_INFO
HELP_SYS_INFO
" --yscroll <delta> defines the vertical scrolling delta, which is\n"
HELP_COMMON_INFO_2
"\n"
@@ -224,14 +226,17 @@ CClientApp::createScreen()
void
CClientApp::updateStatus()
{
s_taskBarReceiver->updateStatus(s_client, "");
updateStatus("");
}
void
CClientApp::updateStatus(const CString& msg)
{
s_taskBarReceiver->updateStatus(s_client, msg);
if (m_taskBarReceiver)
{
m_taskBarReceiver->updateStatus(s_client, msg);
}
}
@@ -343,7 +348,7 @@ CClientApp::handleClientFailed(const CEvent& e, void*)
}
else {
LOG((CLOG_WARN "failed to connect to server: %s", info->m_what.c_str()));
if (!s_suspended) {
if (!m_suspended) {
scheduleClientRestart(nextRestartTimeout());
}
}
@@ -358,7 +363,7 @@ CClientApp::handleClientDisconnected(const CEvent&, void*)
if (!args().m_restartable) {
EVENTQUEUE->addEvent(CEvent(CEvent::kQuit));
}
else if (!s_suspended) {
else if (!m_suspended) {
s_client->connect();
}
updateStatus();
@@ -530,7 +535,7 @@ CClientApp::standardStartup(int argc, char** argv)
}
int
CClientApp::runInner(int argc, char** argv, ILogOutputter* outputter, StartupFunc startup, CreateTaskBarReceiverFunc createTaskBarReceiver)
CClientApp::runInner(int argc, char** argv, ILogOutputter* outputter, StartupFunc startup)
{
// general initialization
args().m_serverAddress = new CNetworkAddress;
@@ -541,15 +546,6 @@ CClientApp::runInner(int argc, char** argv, ILogOutputter* outputter, StartupFun
CLOG->insert(outputter);
}
// save log messages
// use heap memory because CLog deletes outputters on destruction
CBufferedLogOutputter* logBuffer = new CBufferedLogOutputter(1000);
CLOG->insert(logBuffer, true);
// make the task bar receiver. the user can control this app
// through the task bar.
s_taskBarReceiver = createTaskBarReceiver(logBuffer);
int result;
try
{
@@ -558,8 +554,11 @@ CClientApp::runInner(int argc, char** argv, ILogOutputter* outputter, StartupFun
}
catch (...)
{
// done with task bar receiver
delete s_taskBarReceiver;
if (m_taskBarReceiver)
{
// done with task bar receiver
delete m_taskBarReceiver;
}
delete args().m_serverAddress;

View File

@@ -33,7 +33,7 @@ public:
CNetworkAddress* m_serverAddress;
};
CClientApp();
CClientApp(CreateTaskBarReceiverFunc createTaskBarReceiver);
virtual ~CClientApp();
// Parse client specific command line arguments.
@@ -54,7 +54,7 @@ public:
int foregroundStartup(int argc, char** argv);
int standardStartup(int argc, char** argv);
int runInner(int argc, char** argv, ILogOutputter* outputter, StartupFunc startup, CreateTaskBarReceiverFunc createTaskBarReceiver);
int runInner(int argc, char** argv, ILogOutputter* outputter, StartupFunc startup);
CScreen* createScreen();
void updateStatus();
void updateStatus(const CString& msg);

View File

@@ -50,8 +50,8 @@
CEvent::Type CServerApp::s_reloadConfigEvent = CEvent::kUnknown;
CServerApp::CServerApp() :
CApp(new CArgs()),
CServerApp::CServerApp(CreateTaskBarReceiverFunc createTaskBarReceiver) :
CApp(createTaskBarReceiver, new CArgs()),
s_server(NULL),
s_forceReconnectEvent(CEvent::kUnknown),
s_resetServerEvent(CEvent::kUnknown),
@@ -370,12 +370,15 @@ CServerApp::stopRetryTimer()
void
CServerApp::updateStatus()
{
s_taskBarReceiver->updateStatus(s_server, "");
updateStatus("");
}
void CServerApp::updateStatus( const CString& msg )
{
s_taskBarReceiver->updateStatus(s_server, msg);
if (m_taskBarReceiver)
{
m_taskBarReceiver->updateStatus(s_server, msg);
}
}
void
@@ -657,20 +660,20 @@ CServerApp::handleScreenError(const CEvent&, void*)
void
CServerApp::handleSuspend(const CEvent&, void*)
{
if (!s_suspended) {
if (!m_suspended) {
LOG((CLOG_INFO "suspend"));
stopServer();
s_suspended = true;
m_suspended = true;
}
}
void
CServerApp::handleResume(const CEvent&, void*)
{
if (s_suspended) {
if (m_suspended) {
LOG((CLOG_INFO "resume"));
startServer();
s_suspended = false;
m_suspended = false;
}
}
@@ -796,7 +799,7 @@ void CServerApp::resetServer(const CEvent&, void*)
}
int
CServerApp::runInner(int argc, char** argv, ILogOutputter* outputter, StartupFunc startup, CreateTaskBarReceiverFunc createTaskBarReceiver)
CServerApp::runInner(int argc, char** argv, ILogOutputter* outputter, StartupFunc startup)
{
// general initialization
args().m_synergyAddress = new CNetworkAddress;
@@ -808,20 +811,14 @@ CServerApp::runInner(int argc, char** argv, ILogOutputter* outputter, StartupFun
CLOG->insert(outputter);
}
// save log messages
// use heap memory because CLog deletes outputters on destruction
CBufferedLogOutputter* logBuffer = new CBufferedLogOutputter(1000);
CLOG->insert(logBuffer, true);
// make the task bar receiver. the user can control this app
// through the task bar.
s_taskBarReceiver = createTaskBarReceiver(logBuffer);
// run
int result = startup(argc, argv);
// done with task bar receiver
delete s_taskBarReceiver;
if (m_taskBarReceiver)
{
// done with task bar receiver
delete m_taskBarReceiver;
}
delete args().m_config;
delete args().m_synergyAddress;

View File

@@ -49,7 +49,7 @@ public:
CConfig* m_config;
};
CServerApp();
CServerApp(CreateTaskBarReceiverFunc createTaskBarReceiver);
virtual ~CServerApp();
// Parse server specific command line arguments.
@@ -99,7 +99,7 @@ public:
void handleNoClients(const CEvent&, void*);
bool startServer();
int mainLoop();
int runInner(int argc, char** argv, ILogOutputter* outputter, StartupFunc startup, CreateTaskBarReceiverFunc createTaskBarReceiver);
int runInner(int argc, char** argv, ILogOutputter* outputter, StartupFunc startup);
int standardStartup(int argc, char** argv);
int foregroundStartup(int argc, char** argv);
void startNode();