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_uninstall = false;
|
||||
static const char* s_logFilter = NULL;
|
||||
static CString s_name;
|
||||
static CNetworkAddress s_serverAddress;
|
||||
|
||||
|
||||
|
@ -74,7 +75,7 @@ static int realMain(CMutex* mutex)
|
|||
bool locked = true;
|
||||
try {
|
||||
// create client
|
||||
s_client = new CClient("secondary"); // FIXME
|
||||
s_client = new CClient(s_name);
|
||||
|
||||
// run client
|
||||
if (mutex != NULL) {
|
||||
|
@ -164,8 +165,9 @@ static void help()
|
|||
{
|
||||
log((CLOG_PRINT
|
||||
"Usage: %s"
|
||||
" [--debug <level>]"
|
||||
" [--"DAEMON"|--no-"DAEMON"]"
|
||||
" [--debug <level>]"
|
||||
" [--name <screen-name>]"
|
||||
" [--restart|--no-restart]"
|
||||
" [--install]"
|
||||
" <server-address>\n"
|
||||
|
@ -178,6 +180,8 @@ static void help()
|
|||
" DEBUG, DEBUG1, DEBUG2.\n"
|
||||
" -f, --no-"DAEMON" run the client in the foreground.\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"
|
||||
" some reason.\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(argc >= 1);
|
||||
|
||||
// set defaults
|
||||
char hostname[256];
|
||||
if (CNetwork::gethostname(hostname, sizeof(hostname)) != CNetwork::Error) {
|
||||
s_name = hostname;
|
||||
}
|
||||
|
||||
// parse options
|
||||
int i;
|
||||
for (i = 1; i < argc; ++i) {
|
||||
|
@ -233,6 +243,11 @@ static void parse(int argc, const char** argv)
|
|||
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)) {
|
||||
// not a daemon
|
||||
s_daemon = false;
|
||||
|
|
|
@ -47,7 +47,9 @@ else { wait(0); exit(1); }
|
|||
|
||||
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_active(NULL),
|
||||
m_primaryInfo(NULL),
|
||||
|
@ -81,6 +83,12 @@ void CServer::run()
|
|||
log((CLOG_INFO "failed to open screen. waiting to retry."));
|
||||
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
|
||||
|
@ -222,8 +230,7 @@ bool CServer::setConfig(const CConfig& config)
|
|||
|
||||
CString CServer::getPrimaryScreenName() const
|
||||
{
|
||||
CLock lock(&m_mutex);
|
||||
return (m_primaryInfo == NULL) ? "" : m_primaryInfo->m_name;
|
||||
return m_name;
|
||||
}
|
||||
|
||||
void CServer::getConfig(CConfig* config) const
|
||||
|
@ -1337,7 +1344,10 @@ void CServer::openPrimaryScreen()
|
|||
// reset sequence number
|
||||
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 {
|
||||
// add connection
|
||||
m_active = addConnection(primary, NULL);
|
||||
|
@ -1380,7 +1390,7 @@ void CServer::closePrimaryScreen()
|
|||
assert(m_primary != NULL);
|
||||
|
||||
// remove connection
|
||||
CString primary = m_config.getCanonicalName("primary"); // FIXME
|
||||
CString primary = m_config.getCanonicalName(m_name);
|
||||
removeConnection(primary);
|
||||
|
||||
// close the primary screen
|
||||
|
|
|
@ -24,7 +24,7 @@ class CHTTPServer;
|
|||
|
||||
class CServer {
|
||||
public:
|
||||
CServer();
|
||||
CServer(const CString& serverName);
|
||||
~CServer();
|
||||
|
||||
// manipulators
|
||||
|
@ -220,6 +220,8 @@ private:
|
|||
|
||||
CMutex m_mutex;
|
||||
|
||||
CString m_name;
|
||||
|
||||
double m_bindTimeout;
|
||||
|
||||
ISocketFactory* m_socketFactory;
|
||||
|
|
|
@ -39,6 +39,7 @@ static bool s_install = false;
|
|||
static bool s_uninstall = false;
|
||||
static const char* s_configFile = NULL;
|
||||
static const char* s_logFilter = NULL;
|
||||
static CString s_name;
|
||||
static CNetworkAddress s_synergyAddress;
|
||||
static CNetworkAddress s_httpAddress;
|
||||
static CConfig s_config;
|
||||
|
@ -69,7 +70,6 @@ static void logLock(bool lock)
|
|||
|
||||
static CServer* s_server = NULL;
|
||||
|
||||
#include <signal.h>
|
||||
static int realMain(CMutex* mutex)
|
||||
{
|
||||
// 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
|
||||
// as the default
|
||||
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.
|
||||
|
@ -107,7 +107,7 @@ static int realMain(CMutex* mutex)
|
|||
}
|
||||
|
||||
// create server
|
||||
s_server = new CServer();
|
||||
s_server = new CServer(s_name);
|
||||
|
||||
// run server (unlocked)
|
||||
if (mutex != NULL) {
|
||||
|
@ -200,12 +200,14 @@ static void help()
|
|||
|
||||
log((CLOG_PRINT
|
||||
"Usage: %s"
|
||||
" [--address <address>]"
|
||||
" [--config <pathname>]"
|
||||
" [--debug <level>]"
|
||||
" [--"DAEMON"|--no-"DAEMON"]"
|
||||
" [--debug <level>]"
|
||||
" [--name <screen-name>]"
|
||||
" [--restart|--no-restart]\n"
|
||||
" [--install]\n"
|
||||
"or\n"
|
||||
" --install\n"
|
||||
" --uninstall\n"
|
||||
"\n"
|
||||
"Start the synergy mouse/keyboard sharing server.\n"
|
||||
|
@ -218,6 +220,8 @@ static void help()
|
|||
" DEBUG, DEBUG1, DEBUG2.\n"
|
||||
" -f, --no-"DAEMON" run the server in the foreground.\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"
|
||||
" some reason.\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(argc >= 1);
|
||||
|
||||
// set defaults
|
||||
char hostname[256];
|
||||
if (CNetwork::gethostname(hostname, sizeof(hostname)) != CNetwork::Error) {
|
||||
s_name = hostname;
|
||||
}
|
||||
|
||||
// parse options
|
||||
int i;
|
||||
for (i = 1; i < argc; ++i) {
|
||||
|
@ -313,6 +323,11 @@ static void parse(int argc, const char** argv)
|
|||
++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)) {
|
||||
// save configuration file path
|
||||
s_configFile = argv[++i];
|
||||
|
|
Loading…
Reference in New Issue