added command line option to choose the screen name. also now
using the hostname as the default name. this is on both client and server.
This commit is contained in:
parent
c357180530
commit
7ca4804667
|
@ -32,6 +32,7 @@ static bool s_daemon = true;
|
||||||
static bool s_install = false;
|
static bool s_install = false;
|
||||||
static bool s_uninstall = false;
|
static bool s_uninstall = false;
|
||||||
static const char* s_logFilter = NULL;
|
static const char* s_logFilter = NULL;
|
||||||
|
static CString s_name;
|
||||||
static CNetworkAddress s_serverAddress;
|
static CNetworkAddress s_serverAddress;
|
||||||
|
|
||||||
|
|
||||||
|
@ -74,7 +75,7 @@ static int realMain(CMutex* mutex)
|
||||||
bool locked = true;
|
bool locked = true;
|
||||||
try {
|
try {
|
||||||
// create client
|
// create client
|
||||||
s_client = new CClient("secondary"); // FIXME
|
s_client = new CClient(s_name);
|
||||||
|
|
||||||
// run client
|
// run client
|
||||||
if (mutex != NULL) {
|
if (mutex != NULL) {
|
||||||
|
@ -164,8 +165,9 @@ static void help()
|
||||||
{
|
{
|
||||||
log((CLOG_PRINT
|
log((CLOG_PRINT
|
||||||
"Usage: %s"
|
"Usage: %s"
|
||||||
" [--debug <level>]"
|
|
||||||
" [--"DAEMON"|--no-"DAEMON"]"
|
" [--"DAEMON"|--no-"DAEMON"]"
|
||||||
|
" [--debug <level>]"
|
||||||
|
" [--name <screen-name>]"
|
||||||
" [--restart|--no-restart]"
|
" [--restart|--no-restart]"
|
||||||
" [--install]"
|
" [--install]"
|
||||||
" <server-address>\n"
|
" <server-address>\n"
|
||||||
|
@ -178,6 +180,8 @@ static void help()
|
||||||
" DEBUG, DEBUG1, DEBUG2.\n"
|
" DEBUG, DEBUG1, DEBUG2.\n"
|
||||||
" -f, --no-"DAEMON" run the client in the foreground.\n"
|
" -f, --no-"DAEMON" run the client in the foreground.\n"
|
||||||
"* --"DAEMON" run the client as a "DAEMON".\n"
|
"* --"DAEMON" run the client as a "DAEMON".\n"
|
||||||
|
" -n, --name <screen-name> use screen-name instead the hostname to identify\n"
|
||||||
|
" ourself to the server.\n"
|
||||||
" -1, --no-restart do not try to restart the client if it fails for\n"
|
" -1, --no-restart do not try to restart the client if it fails for\n"
|
||||||
" some reason.\n"
|
" some reason.\n"
|
||||||
"* --restart restart the client automatically if it fails.\n"
|
"* --restart restart the client automatically if it fails.\n"
|
||||||
|
@ -225,6 +229,12 @@ static void parse(int argc, const char** argv)
|
||||||
assert(argv != NULL);
|
assert(argv != NULL);
|
||||||
assert(argc >= 1);
|
assert(argc >= 1);
|
||||||
|
|
||||||
|
// set defaults
|
||||||
|
char hostname[256];
|
||||||
|
if (CNetwork::gethostname(hostname, sizeof(hostname)) != CNetwork::Error) {
|
||||||
|
s_name = hostname;
|
||||||
|
}
|
||||||
|
|
||||||
// parse options
|
// parse options
|
||||||
int i;
|
int i;
|
||||||
for (i = 1; i < argc; ++i) {
|
for (i = 1; i < argc; ++i) {
|
||||||
|
@ -233,6 +243,11 @@ static void parse(int argc, const char** argv)
|
||||||
s_logFilter = argv[++i];
|
s_logFilter = argv[++i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else if (isArg(i, argc, argv, "-n", "--name", 1)) {
|
||||||
|
// save screen name
|
||||||
|
s_name = argv[++i];
|
||||||
|
}
|
||||||
|
|
||||||
else if (isArg(i, argc, argv, "-f", "--no-"DAEMON)) {
|
else if (isArg(i, argc, argv, "-f", "--no-"DAEMON)) {
|
||||||
// not a daemon
|
// not a daemon
|
||||||
s_daemon = false;
|
s_daemon = false;
|
||||||
|
|
|
@ -47,7 +47,9 @@ else { wait(0); exit(1); }
|
||||||
|
|
||||||
const SInt32 CServer::s_httpMaxSimultaneousRequests = 3;
|
const SInt32 CServer::s_httpMaxSimultaneousRequests = 3;
|
||||||
|
|
||||||
CServer::CServer() : m_cleanupSize(&m_mutex, 0),
|
CServer::CServer(const CString& serverName) :
|
||||||
|
m_name(serverName),
|
||||||
|
m_cleanupSize(&m_mutex, 0),
|
||||||
m_primary(NULL),
|
m_primary(NULL),
|
||||||
m_active(NULL),
|
m_active(NULL),
|
||||||
m_primaryInfo(NULL),
|
m_primaryInfo(NULL),
|
||||||
|
@ -81,6 +83,12 @@ void CServer::run()
|
||||||
log((CLOG_INFO "failed to open screen. waiting to retry."));
|
log((CLOG_INFO "failed to open screen. waiting to retry."));
|
||||||
CThread::sleep(3.0);
|
CThread::sleep(3.0);
|
||||||
}
|
}
|
||||||
|
catch (XUnknownClient& e) {
|
||||||
|
// can't open screen yet. wait a few seconds to retry.
|
||||||
|
log((CLOG_CRIT "unknown screen name `%s'", e.getName().c_str()));
|
||||||
|
log((CLOG_NOTE "stopping server"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// start listening for new clients
|
// start listening for new clients
|
||||||
|
@ -222,8 +230,7 @@ bool CServer::setConfig(const CConfig& config)
|
||||||
|
|
||||||
CString CServer::getPrimaryScreenName() const
|
CString CServer::getPrimaryScreenName() const
|
||||||
{
|
{
|
||||||
CLock lock(&m_mutex);
|
return m_name;
|
||||||
return (m_primaryInfo == NULL) ? "" : m_primaryInfo->m_name;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServer::getConfig(CConfig* config) const
|
void CServer::getConfig(CConfig* config) const
|
||||||
|
@ -1337,7 +1344,10 @@ void CServer::openPrimaryScreen()
|
||||||
// reset sequence number
|
// reset sequence number
|
||||||
m_seqNum = 0;
|
m_seqNum = 0;
|
||||||
|
|
||||||
CString primary = m_config.getCanonicalName("primary"); // FIXME
|
CString primary = m_config.getCanonicalName(m_name);
|
||||||
|
if (primary.empty()) {
|
||||||
|
throw XUnknownClient(m_name);
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
// add connection
|
// add connection
|
||||||
m_active = addConnection(primary, NULL);
|
m_active = addConnection(primary, NULL);
|
||||||
|
@ -1380,7 +1390,7 @@ void CServer::closePrimaryScreen()
|
||||||
assert(m_primary != NULL);
|
assert(m_primary != NULL);
|
||||||
|
|
||||||
// remove connection
|
// remove connection
|
||||||
CString primary = m_config.getCanonicalName("primary"); // FIXME
|
CString primary = m_config.getCanonicalName(m_name);
|
||||||
removeConnection(primary);
|
removeConnection(primary);
|
||||||
|
|
||||||
// close the primary screen
|
// close the primary screen
|
||||||
|
|
|
@ -24,7 +24,7 @@ class CHTTPServer;
|
||||||
|
|
||||||
class CServer {
|
class CServer {
|
||||||
public:
|
public:
|
||||||
CServer();
|
CServer(const CString& serverName);
|
||||||
~CServer();
|
~CServer();
|
||||||
|
|
||||||
// manipulators
|
// manipulators
|
||||||
|
@ -220,6 +220,8 @@ private:
|
||||||
|
|
||||||
CMutex m_mutex;
|
CMutex m_mutex;
|
||||||
|
|
||||||
|
CString m_name;
|
||||||
|
|
||||||
double m_bindTimeout;
|
double m_bindTimeout;
|
||||||
|
|
||||||
ISocketFactory* m_socketFactory;
|
ISocketFactory* m_socketFactory;
|
||||||
|
|
|
@ -39,6 +39,7 @@ static bool s_install = false;
|
||||||
static bool s_uninstall = false;
|
static bool s_uninstall = false;
|
||||||
static const char* s_configFile = NULL;
|
static const char* s_configFile = NULL;
|
||||||
static const char* s_logFilter = NULL;
|
static const char* s_logFilter = NULL;
|
||||||
|
static CString s_name;
|
||||||
static CNetworkAddress s_synergyAddress;
|
static CNetworkAddress s_synergyAddress;
|
||||||
static CNetworkAddress s_httpAddress;
|
static CNetworkAddress s_httpAddress;
|
||||||
static CConfig s_config;
|
static CConfig s_config;
|
||||||
|
@ -69,7 +70,6 @@ static void logLock(bool lock)
|
||||||
|
|
||||||
static CServer* s_server = NULL;
|
static CServer* s_server = NULL;
|
||||||
|
|
||||||
#include <signal.h>
|
|
||||||
static int realMain(CMutex* mutex)
|
static int realMain(CMutex* mutex)
|
||||||
{
|
{
|
||||||
// s_serverLock should have mutex locked on entry
|
// s_serverLock should have mutex locked on entry
|
||||||
|
@ -88,7 +88,7 @@ static int realMain(CMutex* mutex)
|
||||||
// if configuration has no screens then add this system
|
// if configuration has no screens then add this system
|
||||||
// as the default
|
// as the default
|
||||||
if (s_config.begin() == s_config.end()) {
|
if (s_config.begin() == s_config.end()) {
|
||||||
s_config.addScreen("primary");
|
s_config.addScreen(s_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
// set the contact address, if provided, in the config.
|
// set the contact address, if provided, in the config.
|
||||||
|
@ -107,7 +107,7 @@ static int realMain(CMutex* mutex)
|
||||||
}
|
}
|
||||||
|
|
||||||
// create server
|
// create server
|
||||||
s_server = new CServer();
|
s_server = new CServer(s_name);
|
||||||
|
|
||||||
// run server (unlocked)
|
// run server (unlocked)
|
||||||
if (mutex != NULL) {
|
if (mutex != NULL) {
|
||||||
|
@ -200,12 +200,14 @@ static void help()
|
||||||
|
|
||||||
log((CLOG_PRINT
|
log((CLOG_PRINT
|
||||||
"Usage: %s"
|
"Usage: %s"
|
||||||
|
" [--address <address>]"
|
||||||
" [--config <pathname>]"
|
" [--config <pathname>]"
|
||||||
" [--debug <level>]"
|
|
||||||
" [--"DAEMON"|--no-"DAEMON"]"
|
" [--"DAEMON"|--no-"DAEMON"]"
|
||||||
|
" [--debug <level>]"
|
||||||
|
" [--name <screen-name>]"
|
||||||
" [--restart|--no-restart]\n"
|
" [--restart|--no-restart]\n"
|
||||||
|
" [--install]\n"
|
||||||
"or\n"
|
"or\n"
|
||||||
" --install\n"
|
|
||||||
" --uninstall\n"
|
" --uninstall\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Start the synergy mouse/keyboard sharing server.\n"
|
"Start the synergy mouse/keyboard sharing server.\n"
|
||||||
|
@ -218,6 +220,8 @@ static void help()
|
||||||
" DEBUG, DEBUG1, DEBUG2.\n"
|
" DEBUG, DEBUG1, DEBUG2.\n"
|
||||||
" -f, --no-"DAEMON" run the server in the foreground.\n"
|
" -f, --no-"DAEMON" run the server in the foreground.\n"
|
||||||
"* --"DAEMON" run the server as a "DAEMON".\n"
|
"* --"DAEMON" run the server as a "DAEMON".\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 the server if it fails for\n"
|
" -1, --no-restart do not try to restart the server if it fails for\n"
|
||||||
" some reason.\n"
|
" some reason.\n"
|
||||||
"* --restart restart the server automatically if it fails.\n"
|
"* --restart restart the server automatically if it fails.\n"
|
||||||
|
@ -279,6 +283,12 @@ static void parse(int argc, const char** argv)
|
||||||
assert(argv != NULL);
|
assert(argv != NULL);
|
||||||
assert(argc >= 1);
|
assert(argc >= 1);
|
||||||
|
|
||||||
|
// set defaults
|
||||||
|
char hostname[256];
|
||||||
|
if (CNetwork::gethostname(hostname, sizeof(hostname)) != CNetwork::Error) {
|
||||||
|
s_name = hostname;
|
||||||
|
}
|
||||||
|
|
||||||
// parse options
|
// parse options
|
||||||
int i;
|
int i;
|
||||||
for (i = 1; i < argc; ++i) {
|
for (i = 1; i < argc; ++i) {
|
||||||
|
@ -313,6 +323,11 @@ static void parse(int argc, const char** argv)
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else if (isArg(i, argc, argv, "-n", "--name", 1)) {
|
||||||
|
// save screen name
|
||||||
|
s_name = argv[++i];
|
||||||
|
}
|
||||||
|
|
||||||
else if (isArg(i, argc, argv, "-c", "--config", 1)) {
|
else if (isArg(i, argc, argv, "-c", "--config", 1)) {
|
||||||
// save configuration file path
|
// save configuration file path
|
||||||
s_configFile = argv[++i];
|
s_configFile = argv[++i];
|
||||||
|
|
Loading…
Reference in New Issue