fixed name prefix in ServerApp and ClientApp.

removed testing code.
This commit is contained in:
jerry 2014-04-22 10:56:30 +00:00
parent 506cae9a63
commit c5e551ccae
4 changed files with 91 additions and 100 deletions

View File

@ -62,8 +62,8 @@
CClientApp::CClientApp(IEventQueue* events, CreateTaskBarReceiverFunc createTaskBarReceiver) : CClientApp::CClientApp(IEventQueue* events, CreateTaskBarReceiverFunc createTaskBarReceiver) :
CApp(events, createTaskBarReceiver, new CArgs()), CApp(events, createTaskBarReceiver, new CArgs()),
s_client(NULL), m_client(NULL),
s_clientScreen(NULL) m_clientScreen(NULL)
{ {
} }
@ -255,7 +255,7 @@ CClientApp::updateStatus(const CString& msg)
{ {
if (m_taskBarReceiver) if (m_taskBarReceiver)
{ {
m_taskBarReceiver->updateStatus(s_client, msg); m_taskBarReceiver->updateStatus(m_client, msg);
} }
} }
@ -353,14 +353,6 @@ CClientApp::handleClientConnected(const CEvent&, void*)
LOG((CLOG_NOTE "connected to server")); LOG((CLOG_NOTE "connected to server"));
resetRestartTimeout(); resetRestartTimeout();
updateStatus(); updateStatus();
/*
// TODO: remove testing code for relase
CString fileFullDir = getFileTransferSrc();
if (!fileFullDir.empty()) {
s_client->sendFileToServer(getFileTransferSrc().c_str());
}
*/
} }
@ -393,7 +385,7 @@ CClientApp::handleClientDisconnected(const CEvent&, void*)
m_events->addEvent(CEvent(CEvent::kQuit)); m_events->addEvent(CEvent(CEvent::kQuit));
} }
else if (!m_suspended) { else if (!m_suspended) {
s_client->connect(); m_client->connect();
} }
updateStatus(); updateStatus();
} }
@ -465,15 +457,15 @@ CClientApp::startClient()
double retryTime; double retryTime;
CScreen* clientScreen = NULL; CScreen* clientScreen = NULL;
try { try {
if (s_clientScreen == NULL) { if (m_clientScreen == NULL) {
clientScreen = openClientScreen(); clientScreen = openClientScreen();
s_client = openClient(args().m_name, m_client = openClient(args().m_name,
*args().m_serverAddress, clientScreen, args().m_crypto); *args().m_serverAddress, clientScreen, args().m_crypto);
s_clientScreen = clientScreen; m_clientScreen = clientScreen;
LOG((CLOG_NOTE "started client")); LOG((CLOG_NOTE "started client"));
} }
s_client->connect(); m_client->connect();
updateStatus(); updateStatus();
return true; return true;
@ -509,10 +501,10 @@ CClientApp::startClient()
void void
CClientApp::stopClient() CClientApp::stopClient()
{ {
closeClient(s_client); closeClient(m_client);
closeClientScreen(s_clientScreen); closeClientScreen(m_clientScreen);
s_client = NULL; m_client = NULL;
s_clientScreen = NULL; m_clientScreen = NULL;
} }
@ -534,7 +526,7 @@ CClientApp::mainLoop()
} }
// load all available plugins. // load all available plugins.
ARCH->plugin().init(s_clientScreen->getEventTarget(), m_events); ARCH->plugin().init(m_clientScreen->getEventTarget(), m_events);
// run event loop. if startClient() failed we're supposed to retry // run event loop. if startClient() failed we're supposed to retry
// later. the timer installed by startClient() will take care of // later. the timer installed by startClient() will take care of
@ -550,7 +542,7 @@ CClientApp::mainLoop()
// wait until carbon loop is ready // wait until carbon loop is ready
COSXScreen* screen = dynamic_cast<COSXScreen*>( COSXScreen* screen = dynamic_cast<COSXScreen*>(
s_clientScreen->getPlatformScreen()); m_clientScreen->getPlatformScreen());
screen->waitForCarbonLoop(); screen->waitForCarbonLoop();
runCocoaApp(); runCocoaApp();

View File

@ -83,12 +83,12 @@ public:
static CClientApp& instance() { return (CClientApp&)CApp::instance(); } static CClientApp& instance() { return (CClientApp&)CApp::instance(); }
CClient* getClientPtr() { return s_client; } CClient* getClientPtr() { return m_client; }
private: private:
virtual bool parseArg(const int& argc, const char* const* argv, int& i); virtual bool parseArg(const int& argc, const char* const* argv, int& i);
private: private:
CClient* s_client; CClient* m_client;
CScreen* s_clientScreen; CScreen* m_clientScreen;
}; };

View File

@ -64,12 +64,12 @@
CServerApp::CServerApp(IEventQueue* events, CreateTaskBarReceiverFunc createTaskBarReceiver) : CServerApp::CServerApp(IEventQueue* events, CreateTaskBarReceiverFunc createTaskBarReceiver) :
CApp(events, createTaskBarReceiver, new CArgs()), CApp(events, createTaskBarReceiver, new CArgs()),
s_server(NULL), m_server(NULL),
s_serverState(kUninitialized), m_serverState(kUninitialized),
s_serverScreen(NULL), m_serverScreen(NULL),
s_primaryClient(NULL), m_primaryClient(NULL),
s_listener(NULL), m_listener(NULL),
s_timer(NULL) m_timer(NULL)
{ {
} }
@ -221,8 +221,8 @@ CServerApp::reloadConfig(const CEvent&, void*)
{ {
LOG((CLOG_DEBUG "reload configuration")); LOG((CLOG_DEBUG "reload configuration"));
if (loadConfig(args().m_configFile)) { if (loadConfig(args().m_configFile)) {
if (s_server != NULL) { if (m_server != NULL) {
s_server->setConfig(*args().m_config); m_server->setConfig(*args().m_config);
} }
LOG((CLOG_NOTE "reloaded configuration")); LOG((CLOG_NOTE "reloaded configuration"));
} }
@ -301,8 +301,8 @@ CServerApp::loadConfig(const CString& pathname)
void void
CServerApp::forceReconnect(const CEvent&, void*) CServerApp::forceReconnect(const CEvent&, void*)
{ {
if (s_server != NULL) { if (m_server != NULL) {
s_server->disconnect(); m_server->disconnect();
} }
} }
@ -312,7 +312,7 @@ CServerApp::handleClientConnected(const CEvent&, void* vlistener)
CClientListener* listener = reinterpret_cast<CClientListener*>(vlistener); CClientListener* listener = reinterpret_cast<CClientListener*>(vlistener);
CClientProxy* client = listener->getNextClient(); CClientProxy* client = listener->getNextClient();
if (client != NULL) { if (client != NULL) {
s_server->adoptClient(client); m_server->adoptClient(client);
updateStatus(); updateStatus();
} }
} }
@ -354,10 +354,10 @@ CServerApp::closeServer(CServer* server)
void void
CServerApp::stopRetryTimer() CServerApp::stopRetryTimer()
{ {
if (s_timer != NULL) { if (m_timer != NULL) {
m_events->deleteTimer(s_timer); m_events->deleteTimer(m_timer);
m_events->removeHandler(CEvent::kTimer, NULL); m_events->removeHandler(CEvent::kTimer, NULL);
s_timer = NULL; m_timer = NULL;
} }
} }
@ -371,7 +371,7 @@ void CServerApp::updateStatus( const CString& msg )
{ {
if (m_taskBarReceiver) if (m_taskBarReceiver)
{ {
m_taskBarReceiver->updateStatus(s_server, msg); m_taskBarReceiver->updateStatus(m_server, msg);
} }
} }
@ -387,19 +387,19 @@ CServerApp::closeClientListener(CClientListener* listen)
void void
CServerApp::stopServer() CServerApp::stopServer()
{ {
if (s_serverState == kStarted) { if (m_serverState == kStarted) {
closeClientListener(s_listener); closeClientListener(m_listener);
closeServer(s_server); closeServer(m_server);
s_server = NULL; m_server = NULL;
s_listener = NULL; m_listener = NULL;
s_serverState = kInitialized; m_serverState = kInitialized;
} }
else if (s_serverState == kStarting) { else if (m_serverState == kStarting) {
stopRetryTimer(); stopRetryTimer();
s_serverState = kInitialized; m_serverState = kInitialized;
} }
assert(s_server == NULL); assert(m_server == NULL);
assert(s_listener == NULL); assert(m_listener == NULL);
} }
void void
@ -425,32 +425,32 @@ CServerApp::closeServerScreen(CScreen* screen)
void CServerApp::cleanupServer() void CServerApp::cleanupServer()
{ {
stopServer(); stopServer();
if (s_serverState == kInitialized) { if (m_serverState == kInitialized) {
closePrimaryClient(s_primaryClient); closePrimaryClient(m_primaryClient);
closeServerScreen(s_serverScreen); closeServerScreen(m_serverScreen);
s_primaryClient = NULL; m_primaryClient = NULL;
s_serverScreen = NULL; m_serverScreen = NULL;
s_serverState = kUninitialized; m_serverState = kUninitialized;
} }
else if (s_serverState == kInitializing || else if (m_serverState == kInitializing ||
s_serverState == kInitializingToStart) { m_serverState == kInitializingToStart) {
stopRetryTimer(); stopRetryTimer();
s_serverState = kUninitialized; m_serverState = kUninitialized;
} }
assert(s_primaryClient == NULL); assert(m_primaryClient == NULL);
assert(s_serverScreen == NULL); assert(m_serverScreen == NULL);
assert(s_serverState == kUninitialized); assert(m_serverState == kUninitialized);
} }
void void
CServerApp::retryHandler(const CEvent&, void*) CServerApp::retryHandler(const CEvent&, void*)
{ {
// discard old timer // discard old timer
assert(s_timer != NULL); assert(m_timer != NULL);
stopRetryTimer(); stopRetryTimer();
// try initializing/starting the server again // try initializing/starting the server again
switch (s_serverState) { switch (m_serverState) {
case kUninitialized: case kUninitialized:
case kInitialized: case kInitialized:
case kStarted: case kStarted:
@ -459,7 +459,7 @@ CServerApp::retryHandler(const CEvent&, void*)
case kInitializing: case kInitializing:
LOG((CLOG_DEBUG1 "retry server initialization")); LOG((CLOG_DEBUG1 "retry server initialization"));
s_serverState = kUninitialized; m_serverState = kUninitialized;
if (!initServer()) { if (!initServer()) {
m_events->addEvent(CEvent(CEvent::kQuit)); m_events->addEvent(CEvent(CEvent::kQuit));
} }
@ -467,11 +467,11 @@ CServerApp::retryHandler(const CEvent&, void*)
case kInitializingToStart: case kInitializingToStart:
LOG((CLOG_DEBUG1 "retry server initialization")); LOG((CLOG_DEBUG1 "retry server initialization"));
s_serverState = kUninitialized; m_serverState = kUninitialized;
if (!initServer()) { if (!initServer()) {
m_events->addEvent(CEvent(CEvent::kQuit)); m_events->addEvent(CEvent(CEvent::kQuit));
} }
else if (s_serverState == kInitialized) { else if (m_serverState == kInitialized) {
LOG((CLOG_DEBUG1 "starting server")); LOG((CLOG_DEBUG1 "starting server"));
if (!startServer()) { if (!startServer()) {
m_events->addEvent(CEvent(CEvent::kQuit)); m_events->addEvent(CEvent(CEvent::kQuit));
@ -481,7 +481,7 @@ CServerApp::retryHandler(const CEvent&, void*)
case kStarting: case kStarting:
LOG((CLOG_DEBUG1 "retry starting server")); LOG((CLOG_DEBUG1 "retry starting server"));
s_serverState = kInitialized; m_serverState = kInitialized;
if (!startServer()) { if (!startServer()) {
m_events->addEvent(CEvent(CEvent::kQuit)); m_events->addEvent(CEvent(CEvent::kQuit));
} }
@ -492,7 +492,7 @@ CServerApp::retryHandler(const CEvent&, void*)
bool CServerApp::initServer() bool CServerApp::initServer()
{ {
// skip if already initialized or initializing // skip if already initialized or initializing
if (s_serverState != kUninitialized) { if (m_serverState != kUninitialized) {
return true; return true;
} }
@ -503,9 +503,9 @@ bool CServerApp::initServer()
CString name = args().m_config->getCanonicalName(args().m_name); CString name = args().m_config->getCanonicalName(args().m_name);
serverScreen = openServerScreen(); serverScreen = openServerScreen();
primaryClient = openPrimaryClient(name, serverScreen); primaryClient = openPrimaryClient(name, serverScreen);
s_serverScreen = serverScreen; m_serverScreen = serverScreen;
s_primaryClient = primaryClient; m_primaryClient = primaryClient;
s_serverState = kInitialized; m_serverState = kInitialized;
updateStatus(); updateStatus();
return true; return true;
} }
@ -531,12 +531,12 @@ bool CServerApp::initServer()
if (args().m_restartable) { if (args().m_restartable) {
// install a timer and handler to retry later // install a timer and handler to retry later
assert(s_timer == NULL); assert(m_timer == NULL);
LOG((CLOG_DEBUG "retry in %.0f seconds", retryTime)); LOG((CLOG_DEBUG "retry in %.0f seconds", retryTime));
s_timer = m_events->newOneShotTimer(retryTime, NULL); m_timer = m_events->newOneShotTimer(retryTime, NULL);
m_events->adoptHandler(CEvent::kTimer, s_timer, m_events->adoptHandler(CEvent::kTimer, m_timer,
new TMethodEventJob<CServerApp>(this, &CServerApp::retryHandler)); new TMethodEventJob<CServerApp>(this, &CServerApp::retryHandler));
s_serverState = kInitializing; m_serverState = kInitializing;
return true; return true;
} }
else { else {
@ -568,34 +568,34 @@ bool
CServerApp::startServer() CServerApp::startServer()
{ {
// skip if already started or starting // skip if already started or starting
if (s_serverState == kStarting || s_serverState == kStarted) { if (m_serverState == kStarting || m_serverState == kStarted) {
return true; return true;
} }
// initialize if necessary // initialize if necessary
if (s_serverState != kInitialized) { if (m_serverState != kInitialized) {
if (!initServer()) { if (!initServer()) {
// hard initialization failure // hard initialization failure
return false; return false;
} }
if (s_serverState == kInitializing) { if (m_serverState == kInitializing) {
// not ready to start // not ready to start
s_serverState = kInitializingToStart; m_serverState = kInitializingToStart;
return true; return true;
} }
assert(s_serverState == kInitialized); assert(m_serverState == kInitialized);
} }
double retryTime; double retryTime;
CClientListener* listener = NULL; CClientListener* listener = NULL;
try { try {
listener = openClientListener(args().m_config->getSynergyAddress()); listener = openClientListener(args().m_config->getSynergyAddress());
s_server = openServer(*args().m_config, s_primaryClient); m_server = openServer(*args().m_config, m_primaryClient);
listener->setServer(s_server); listener->setServer(m_server);
s_listener = listener; m_listener = listener;
updateStatus(); updateStatus();
LOG((CLOG_NOTE "started server, waiting for clients")); LOG((CLOG_NOTE "started server, waiting for clients"));
s_serverState = kStarted; m_serverState = kStarted;
return true; return true;
} }
catch (XSocketAddressInUse& e) { catch (XSocketAddressInUse& e) {
@ -612,12 +612,12 @@ CServerApp::startServer()
if (args().m_restartable) { if (args().m_restartable) {
// install a timer and handler to retry later // install a timer and handler to retry later
assert(s_timer == NULL); assert(m_timer == NULL);
LOG((CLOG_DEBUG "retry in %.0f seconds", retryTime)); LOG((CLOG_DEBUG "retry in %.0f seconds", retryTime));
s_timer = m_events->newOneShotTimer(retryTime, NULL); m_timer = m_events->newOneShotTimer(retryTime, NULL);
m_events->adoptHandler(CEvent::kTimer, s_timer, m_events->adoptHandler(CEvent::kTimer, m_timer,
new TMethodEventJob<CServerApp>(this, &CServerApp::retryHandler)); new TMethodEventJob<CServerApp>(this, &CServerApp::retryHandler));
s_serverState = kStarting; m_serverState = kStarting;
return true; return true;
} }
else { else {
@ -696,7 +696,7 @@ CServerApp::openClientListener(const CNetworkAddress& address)
CServer* CServer*
CServerApp::openServer(CConfig& config, CPrimaryClient* primaryClient) CServerApp::openServer(CConfig& config, CPrimaryClient* primaryClient)
{ {
CServer* server = new CServer(config, primaryClient, s_serverScreen, m_events, args().m_enableDragDrop); CServer* server = new CServer(config, primaryClient, m_serverScreen, m_events, args().m_enableDragDrop);
try { try {
m_events->adoptHandler( m_events->adoptHandler(
m_events->forCServer().disconnected(), server, m_events->forCServer().disconnected(), server,
@ -766,7 +766,7 @@ CServerApp::mainLoop()
} }
// load all available plugins. // load all available plugins.
ARCH->plugin().init(s_serverScreen->getEventTarget(), m_events); ARCH->plugin().init(m_serverScreen->getEventTarget(), m_events);
// handle hangup signal by reloading the server's configuration // handle hangup signal by reloading the server's configuration
ARCH->setSignalHandler(CArch::kHANGUP, &reloadSignalHandler, NULL); ARCH->setSignalHandler(CArch::kHANGUP, &reloadSignalHandler, NULL);
@ -800,7 +800,7 @@ CServerApp::mainLoop()
// wait until carbon loop is ready // wait until carbon loop is ready
COSXScreen* screen = dynamic_cast<COSXScreen*>( COSXScreen* screen = dynamic_cast<COSXScreen*>(
s_serverScreen->getPlatformScreen()); m_serverScreen->getPlatformScreen());
screen->waitForCarbonLoop(); screen->waitForCarbonLoop();
runCocoaApp(); runCocoaApp();

View File

@ -112,15 +112,14 @@ public:
static CServerApp& instance() { return (CServerApp&)CApp::instance(); } static CServerApp& instance() { return (CServerApp&)CApp::instance(); }
CServer* getServerPtr() { return s_server; } CServer* getServerPtr() { return m_server; }
// TODO: change s_ to m_ CServer* m_server;
CServer* s_server; EServerState m_serverState;
EServerState s_serverState; CScreen* m_serverScreen;
CScreen* s_serverScreen; CPrimaryClient* m_primaryClient;
CPrimaryClient* s_primaryClient; CClientListener* m_listener;
CClientListener* s_listener; CEventQueueTimer* m_timer;
CEventQueueTimer* s_timer;
private: private:
virtual bool parseArg(const int& argc, const char* const* argv, int& i); virtual bool parseArg(const int& argc, const char* const* argv, int& i);