2010-05-31 21:30:29 +00:00
|
|
|
/*
|
2011-01-15 04:01:31 +00:00
|
|
|
* synergy -- mouse and keyboard sharing utility
|
|
|
|
* Copyright (C) 2002 Chris Schoeneman, Nick Bolton, Sorin Sbarnea
|
2010-06-20 17:38:51 +00:00
|
|
|
*
|
|
|
|
* This package is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* found in the file COPYING that should have accompanied this file.
|
|
|
|
*
|
|
|
|
* This package 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 <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2010-05-31 21:30:29 +00:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
#include "CString.h"
|
|
|
|
|
|
|
|
class IArchTaskBarReceiver;
|
|
|
|
class CBufferedLogOutputter;
|
|
|
|
class ILogOutputter;
|
2010-06-05 13:13:07 +00:00
|
|
|
class CFileLogOutputter;
|
2010-06-05 18:54:51 +00:00
|
|
|
class CScreen;
|
2010-05-31 21:30:29 +00:00
|
|
|
|
|
|
|
typedef IArchTaskBarReceiver* (*CreateTaskBarReceiverFunc)(const CBufferedLogOutputter*);
|
|
|
|
typedef int (*StartupFunc)(int, char**);
|
|
|
|
|
|
|
|
class CApp {
|
|
|
|
public:
|
|
|
|
class CArgsBase {
|
|
|
|
public:
|
|
|
|
CArgsBase();
|
|
|
|
virtual ~CArgsBase();
|
|
|
|
bool m_daemon;
|
|
|
|
bool m_backend;
|
|
|
|
bool m_restartable;
|
|
|
|
bool m_noHooks;
|
|
|
|
const char* m_pname;
|
|
|
|
const char* m_logFilter;
|
|
|
|
const char* m_logFile;
|
|
|
|
const char* m_display;
|
|
|
|
CString m_name;
|
2010-06-13 00:06:11 +00:00
|
|
|
bool m_disableTray;
|
2010-06-05 12:52:30 +00:00
|
|
|
#if SYSAPI_WIN32
|
2010-06-05 18:54:51 +00:00
|
|
|
bool m_relaunchMode;
|
2010-06-05 12:52:30 +00:00
|
|
|
bool m_debugServiceWait;
|
2010-06-12 17:20:54 +00:00
|
|
|
bool m_pauseOnExit;
|
2011-01-17 00:41:14 +00:00
|
|
|
#endif
|
|
|
|
#if WINAPI_XWINDOWS
|
|
|
|
bool m_disableXInitThreads;
|
2010-06-05 12:52:30 +00:00
|
|
|
#endif
|
2010-05-31 21:30:29 +00:00
|
|
|
};
|
|
|
|
|
2010-06-12 17:20:54 +00:00
|
|
|
CApp(CreateTaskBarReceiverFunc createTaskBarReceiver, CArgsBase* args);
|
2010-05-31 21:30:29 +00:00
|
|
|
virtual ~CApp();
|
|
|
|
|
|
|
|
// Returns args that are common between server and client.
|
|
|
|
CArgsBase& argsBase() const { return *m_args; }
|
|
|
|
|
|
|
|
// Prints the current compiled version.
|
|
|
|
virtual void version();
|
|
|
|
|
|
|
|
// Prints help specific to client or server.
|
|
|
|
virtual void help() = 0;
|
|
|
|
|
|
|
|
// Parse command line arguments.
|
|
|
|
virtual void parseArgs(int argc, const char* const* argv) = 0;
|
|
|
|
|
2010-06-12 17:20:54 +00:00
|
|
|
int run(int argc, char** argv);
|
2010-05-31 21:30:29 +00:00
|
|
|
|
|
|
|
int daemonMainLoop(int, const char**);
|
|
|
|
|
|
|
|
virtual void loadConfig() = 0;
|
|
|
|
virtual bool loadConfig(const CString& pathname) = 0;
|
|
|
|
virtual int mainLoop() = 0;
|
|
|
|
virtual int foregroundStartup(int argc, char** argv) = 0;
|
|
|
|
virtual int standardStartup(int argc, char** argv) = 0;
|
2010-06-12 17:20:54 +00:00
|
|
|
virtual int runInner(int argc, char** argv, ILogOutputter* outputter, StartupFunc startup) = 0;
|
2010-05-31 21:30:29 +00:00
|
|
|
|
|
|
|
// Name of the daemon (used for Unix and Windows).
|
|
|
|
virtual const char* daemonName() const = 0;
|
|
|
|
|
|
|
|
// A description of the daemon (used only on Windows).
|
|
|
|
virtual const char* daemonInfo() const = 0;
|
|
|
|
|
|
|
|
// Function pointer for function to exit immediately.
|
|
|
|
// TODO: this is old C code - use inheritance to normalize
|
|
|
|
void (*m_bye)(int);
|
|
|
|
|
|
|
|
// Returns true if argv[argi] is equal to name1 or name2.
|
|
|
|
bool isArg(int argi, int argc, const char* const* argv,
|
|
|
|
const char* name1, const char* name2,
|
|
|
|
int minRequiredParameters = 0);
|
|
|
|
|
|
|
|
static CApp& instance() { assert(s_instance != nullptr); return *s_instance; }
|
|
|
|
|
2010-06-12 17:20:54 +00:00
|
|
|
bool m_suspended;
|
|
|
|
IArchTaskBarReceiver* m_taskBarReceiver;
|
2010-05-31 21:30:29 +00:00
|
|
|
|
2010-06-05 13:13:07 +00:00
|
|
|
// If --log was specified in args, then add a file logger.
|
|
|
|
void setupFileLogging();
|
|
|
|
|
2010-06-05 13:17:35 +00:00
|
|
|
// If messages will be hidden (to improve performance), warn user.
|
|
|
|
void loggingFilterWarning();
|
|
|
|
|
2010-06-05 14:20:19 +00:00
|
|
|
// Parses args, sets up file logging, and loads the config.
|
2010-06-05 18:54:51 +00:00
|
|
|
void initApp(int argc, const char** argv);
|
2010-06-05 14:20:19 +00:00
|
|
|
|
|
|
|
// HACK: accept non-const, but make it const anyway
|
2010-06-05 18:54:51 +00:00
|
|
|
void initApp(int argc, char** argv) { initApp(argc, (const char**)argv); }
|
|
|
|
|
|
|
|
// Start the server or client.
|
|
|
|
virtual void startNode() = 0;
|
|
|
|
|
|
|
|
virtual CScreen* createScreen() = 0;
|
2010-06-05 14:20:19 +00:00
|
|
|
|
2010-05-31 21:30:29 +00:00
|
|
|
protected:
|
|
|
|
virtual void parseArgs(int argc, const char* const* argv, int &i);
|
|
|
|
virtual bool parseArg(const int& argc, const char* const* argv, int& i);
|
|
|
|
|
|
|
|
private:
|
|
|
|
CArgsBase* m_args;
|
|
|
|
static CApp* s_instance;
|
2010-06-05 13:13:07 +00:00
|
|
|
CFileLogOutputter* m_fileLog;
|
2010-06-12 17:20:54 +00:00
|
|
|
CreateTaskBarReceiverFunc m_createTaskBarReceiver;
|
2010-05-31 21:30:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#define BYE "\nTry `%s --help' for more information."
|
|
|
|
|
|
|
|
#if WINAPI_MSWINDOWS
|
|
|
|
#define DAEMON_RUNNING(running_) CArchMiscWindows::daemonRunning(running_)
|
|
|
|
#else
|
|
|
|
#define DAEMON_RUNNING(running_)
|
|
|
|
#endif
|
2010-06-04 23:33:30 +00:00
|
|
|
|
|
|
|
#define HELP_COMMON_INFO_1 \
|
2010-06-20 19:59:21 +00:00
|
|
|
" -d, --debug <level> filter out log messages with priority below level.\n" \
|
2010-06-04 23:33:30 +00:00
|
|
|
" level may be: FATAL, ERROR, WARNING, NOTE, INFO,\n" \
|
|
|
|
" DEBUG, DEBUGn (1-5).\n" \
|
|
|
|
" -n, --name <screen-name> use screen-name instead the hostname to identify\n" \
|
|
|
|
" this screen in the configuration.\n" \
|
|
|
|
" -1, --no-restart do not try to restart on failure.\n" \
|
|
|
|
"* --restart restart the server automatically if it fails.\n" \
|
|
|
|
" -l --log <file> write log messages to file.\n"
|
|
|
|
|
|
|
|
#define HELP_COMMON_INFO_2 \
|
|
|
|
" -h, --help display this help and exit.\n" \
|
|
|
|
" --version display version information and exit.\n"
|
|
|
|
|
|
|
|
#define HELP_COMMON_ARGS \
|
|
|
|
" [--name <screen-name>]" \
|
|
|
|
" [--restart|--no-restart]" \
|
|
|
|
" [--debug <level>]"
|
|
|
|
|
|
|
|
// system args (windows/unix)
|
|
|
|
#if SYSAPI_UNIX
|
|
|
|
|
|
|
|
// unix daemon mode args
|
|
|
|
# define HELP_SYS_ARGS \
|
|
|
|
" [--daemon|--no-daemon]"
|
2011-01-15 02:20:14 +00:00
|
|
|
# define HELP_SYS_INFO \
|
2011-01-17 20:56:04 +00:00
|
|
|
" -f, --no-daemon run in the foreground.\n" \
|
|
|
|
"* --daemon run as a daemon.\n"
|
2010-06-04 23:33:30 +00:00
|
|
|
|
|
|
|
#elif SYSAPI_WIN32
|
|
|
|
|
|
|
|
// windows service management args
|
|
|
|
# define HELP_SYS_ARGS \
|
|
|
|
" [--service <action>]"
|
|
|
|
# define HELP_SYS_INFO \
|
|
|
|
" --service <action> manage the windows service, valid options are:\n" \
|
2010-06-05 18:54:51 +00:00
|
|
|
" install/uninstall/start/stop\n" \
|
|
|
|
" --relaunch persistently relaunches process in current user \n" \
|
2010-06-12 17:20:54 +00:00
|
|
|
" 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"
|
2010-06-04 23:33:30 +00:00
|
|
|
|
|
|
|
#endif
|