diff --git a/source/glest_game/main/main.cpp b/source/glest_game/main/main.cpp index f2555db9b..f202a39b0 100644 --- a/source/glest_game/main/main.cpp +++ b/source/glest_game/main/main.cpp @@ -29,7 +29,7 @@ #include "sound_renderer.h" #include "ImageReaders.h" #include "renderer.h" -#include "thread.h" +#include "simple_threads.h" #include "leak_dumper.h" @@ -101,157 +101,6 @@ public: } }; -class FileCRCPreCacheThread : public Thread -{ -private: - Mutex mutexRunning; - Mutex mutexQuit; - - bool quit; - bool running; - - void setRunningStatus(bool value); - void setQuitStatus(bool value); - -public: - FileCRCPreCacheThread(); - virtual void execute(); - void signalQuit(); - bool getQuitStatus(); - bool getRunningStatus(); - static void shutdownAndWait(FileCRCPreCacheThread *pThread); -}; - -FileCRCPreCacheThread::FileCRCPreCacheThread() { - - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - - setQuitStatus(false); - setRunningStatus(false); - - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); -} - -void FileCRCPreCacheThread::signalQuit() { - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - - setQuitStatus(true); - - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); -} - -void FileCRCPreCacheThread::setQuitStatus(bool value) { - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - - mutexQuit.p(); - quit = value; - mutexQuit.v(); - - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); -} - -bool FileCRCPreCacheThread::getQuitStatus() { - //SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - - bool retval = false; - mutexQuit.p(); - retval = quit; - mutexQuit.v(); - - //SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - - return retval; -} - -bool FileCRCPreCacheThread::getRunningStatus() { - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - - bool retval = false; - mutexRunning.p(); - retval = running; - mutexRunning.v(); - - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] running = %d\n",__FILE__,__FUNCTION__,__LINE__,retval); - - return retval; -} - -void FileCRCPreCacheThread::setRunningStatus(bool value) { - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] value = %d\n",__FILE__,__FUNCTION__,__LINE__,value); - - mutexRunning.p(); - running = value; - mutexRunning.v(); - - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] running = %d\n",__FILE__,__FUNCTION__,__LINE__,value); -} - -void FileCRCPreCacheThread::execute() { - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - - setRunningStatus(true); - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"FILE CRC PreCache thread is running\n"); - - try - { - Config &config = Config::getInstance(); - vector techDataPaths = config.getPathListForType(ptTechs); - //tech Tree listBox - vector techPaths; - findDirs(techDataPaths, techPaths); - if(techPaths.empty() == false) { - for(int idx = 0; idx < techPaths.size(); idx++) { - string &techPath = techPaths[idx]; - for(int idx2 = 0; idx2 < techPaths.size(); idx2++) { - string techName = techPaths[idx2]; - - printf("In [%s::%s Line: %d] caching CRC value for Tech [%s]\n",__FILE__,__FUNCTION__,__LINE__,techName.c_str()); - int32 techCRC = getFolderTreeContentsCheckSumRecursively(techDataPaths, string("/") + techName + string("/*"), ".xml", NULL); - printf("In [%s::%s Line: %d] cached CRC value for Tech [%s] is [%d]\n",__FILE__,__FUNCTION__,__LINE__,techName.c_str(),techCRC); - - if(getQuitStatus() == true) { - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - break; - } - sleep( 100 ); - } - if(getQuitStatus() == true) { - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - break; - } - } - } - } - catch(const exception &ex) { - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); - setRunningStatus(false); - } - catch(...) { - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] unknown error\n",__FILE__,__FUNCTION__,__LINE__); - setRunningStatus(false); - } - - setRunningStatus(false); - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"FILE CRC PreCache thread is exiting\n"); - - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); -} - -void FileCRCPreCacheThread::shutdownAndWait(FileCRCPreCacheThread *pThread) { - if(pThread != NULL) { - pThread->signalQuit(); - for( time_t elapsed = time(NULL); difftime(time(NULL),elapsed) <= 10; ) { - if(pThread->getRunningStatus() == false) { - break; - } - sleep(50); - //SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - } - //SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - } -} - - // ===================================================== // class MainWindow // ===================================================== @@ -494,6 +343,8 @@ int glestMain(int argc, char** argv){ gameInitialized = true; if(config.getBool("AllowGameDataSynchCheck","false") == true) { + vector techDataPaths = config.getPathListForType(ptTechs); + preCacheThread.setTechDataPaths(techDataPaths); preCacheThread.start(); } @@ -508,27 +359,27 @@ int glestMain(int argc, char** argv){ } } catch(const exception &e){ - FileCRCPreCacheThread::shutdownAndWait(&preCacheThread); + preCacheThread.shutdownAndWait(); //exceptionMessage(e); ExceptionHandler::handleRuntimeError(e.what()); } catch(const char *e){ //exceptionMessage(e); - FileCRCPreCacheThread::shutdownAndWait(&preCacheThread); + preCacheThread.shutdownAndWait(); ExceptionHandler::handleRuntimeError(e); } catch(const string &ex){ //exceptionMessage(e); - FileCRCPreCacheThread::shutdownAndWait(&preCacheThread); + preCacheThread.shutdownAndWait(); ExceptionHandler::handleRuntimeError(ex.c_str()); } catch(...){ //exceptionMessage(e); - FileCRCPreCacheThread::shutdownAndWait(&preCacheThread); + preCacheThread.shutdownAndWait(); ExceptionHandler::handleRuntimeError("Unknown error!"); } - FileCRCPreCacheThread::shutdownAndWait(&preCacheThread); + preCacheThread.shutdownAndWait(); //SoundRenderer &soundRenderer= SoundRenderer::getInstance(); //soundRenderer.stopAllSounds(); diff --git a/source/shared_lib/include/platform/common/base_thread.h b/source/shared_lib/include/platform/common/base_thread.h new file mode 100644 index 000000000..fb0daa2bd --- /dev/null +++ b/source/shared_lib/include/platform/common/base_thread.h @@ -0,0 +1,51 @@ +// ============================================================== +// This file is part of Glest Shared Library (www.glest.org) +// +// Copyright (C) 2009-2010 Titus Tscharntke (info@titusgames.de) and +// Mark Vejvoda (mark_vejvoda@hotmail.com) +// +// You can redistribute this code and/or modify it under +// the terms of the GNU General Public License as published +// by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version +// ============================================================== +#ifndef _SHARED_PLATFORMCOMMON_BASETHREAD_H_ +#define _SHARED_PLATFORMCOMMON_BASETHREAD_H_ + +#include "thread.h" + +using namespace Shared::Platform; + +namespace Shared { namespace PlatformCommon { + +// ===================================================== +// class BaseThread +// ===================================================== + +class BaseThread : public Thread +{ +protected: + Mutex mutexRunning; + Mutex mutexQuit; + + bool quit; + bool running; + + void setRunningStatus(bool value); + void setQuitStatus(bool value); + +public: + BaseThread(); + ~BaseThread(); + virtual void execute()=0; + + void signalQuit(); + bool getQuitStatus(); + bool getRunningStatus(); + static void shutdownAndWait(BaseThread *pThread); + void shutdownAndWait(); +}; + +}}//end namespace + +#endif diff --git a/source/shared_lib/include/platform/common/cache_manager.h b/source/shared_lib/include/platform/common/cache_manager.h new file mode 100644 index 000000000..be5eafb1c --- /dev/null +++ b/source/shared_lib/include/platform/common/cache_manager.h @@ -0,0 +1,71 @@ +// ============================================================== +// This file is part of Glest Shared Library (www.glest.org) +// +// Copyright (C) 2009-2010 Titus Tscharntke (info@titusgames.de) and +// Mark Vejvoda (mark_vejvoda@hotmail.com) +// +// You can redistribute this code and/or modify it under +// the terms of the GNU General Public License as published +// by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version +// ============================================================== + +#ifndef _SHARED_PLATFORMCOMMON_CACHEMANAGER_H_ +#define _SHARED_PLATFORMCOMMON_CACHEMANAGER_H_ + +#include "thread.h" + +using namespace Shared::Platform; + +namespace Shared { namespace PlatformCommon { + +// ===================================================== +// class BaseThread +// ===================================================== + +class CacheManager +{ +protected: + Mutex mutexCache; + + static std::map masterCacheList; + + typedef enum { + cacheItemGet, + cacheItemSet + } CacheAccessorType; + + template + static T manageCachedItem(string cacheKey, T *value,CacheAccessorType accessor) { + static std::map itemCache; + + if(accessor == cacheItemSet) { + masterCacheList[cacheKey] = true; + itemCache[cacheKey] = *value; + } + return itemCache[cacheKey]; + } + +public: + + CacheManager() { + + } + ~CacheManager() { + + } + + template + static T setCachedItem(string cacheKey, T value) { + manageCachedItem(cacheKey,value,cacheItemSet); + } + template + static T getCachedItem(string cacheKey) { + return manageCachedItem(cacheKey,NULL,cacheItemGet); + } + +}; + +}}//end namespace + +#endif diff --git a/source/shared_lib/include/platform/common/simple_threads.h b/source/shared_lib/include/platform/common/simple_threads.h new file mode 100644 index 000000000..723666483 --- /dev/null +++ b/source/shared_lib/include/platform/common/simple_threads.h @@ -0,0 +1,41 @@ +// ============================================================== +// This file is part of Glest Shared Library (www.glest.org) +// +// Copyright (C) 2005 Matthias Braun +// +// You can redistribute this code and/or modify it under +// the terms of the GNU General Public License as published +// by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version +// ============================================================== +#ifndef _SHARED_PLATFORMCOMMON_SIMPLETHREAD_H_ +#define _SHARED_PLATFORMCOMMON_SIMPLETHREAD_H_ + +#include "base_thread.h" +#include +#include + +using namespace std; + +namespace Shared { namespace PlatformCommon { + +// ===================================================== +// class FileCRCPreCacheThread +// ===================================================== + +class FileCRCPreCacheThread : public BaseThread +{ +protected: + + vector techDataPaths; + +public: + FileCRCPreCacheThread(); + FileCRCPreCacheThread(vector techDataPaths); + virtual void execute(); + void setTechDataPaths(vector techDataPaths) { this->techDataPaths = techDataPaths; } +}; + +}}//end namespace + +#endif diff --git a/source/shared_lib/include/platform/posix/socket.h b/source/shared_lib/include/platform/posix/socket.h index 70905825b..99f1f1f34 100644 --- a/source/shared_lib/include/platform/posix/socket.h +++ b/source/shared_lib/include/platform/posix/socket.h @@ -19,7 +19,7 @@ #include #include #include -#include "thread.h" +#include "base_thread.h" using std::string; @@ -37,6 +37,8 @@ using std::string; #endif +using namespace Shared::PlatformCommon; + namespace Shared{ namespace Platform{ // @@ -127,26 +129,14 @@ protected: static void throwException(string str); }; -class BroadCastClientSocketThread : public Thread +class BroadCastClientSocketThread : public BaseThread { private: - Mutex mutexRunning; - Mutex mutexQuit; - - bool quit; - bool running; - DiscoveredServersInterface *discoveredServersCB; - void setRunningStatus(bool value); - void setQuitStatus(bool value); - public: BroadCastClientSocketThread(DiscoveredServersInterface *cb); virtual void execute(); - void signalQuit(); - bool getQuitStatus(); - bool getRunningStatus(); }; // ===================================================== @@ -168,24 +158,13 @@ protected: static void startBroadCastClientThread(DiscoveredServersInterface *cb); }; -class BroadCastSocketThread : public Thread +class BroadCastSocketThread : public BaseThread { private: - Mutex mutexRunning; - Mutex mutexQuit; - - bool quit; - bool running; - - void setRunningStatus(bool value); - void setQuitStatus(bool value); public: BroadCastSocketThread(); virtual void execute(); - void signalQuit(); - bool getQuitStatus(); - bool getRunningStatus(); }; // ===================================================== diff --git a/source/shared_lib/sources/platform/common/base_thread.cpp b/source/shared_lib/sources/platform/common/base_thread.cpp new file mode 100644 index 000000000..1680367d0 --- /dev/null +++ b/source/shared_lib/sources/platform/common/base_thread.cpp @@ -0,0 +1,106 @@ +// ============================================================== +// This file is part of Glest Shared Library (www.glest.org) +// +// Copyright (C) 2009-2010 Titus Tscharntke (info@titusgames.de) and +// Mark Vejvoda (mark_vejvoda@hotmail.com) +// +// You can redistribute this code and/or modify it under +// the terms of the GNU General Public License as published +// by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version +// ============================================================== + +#include "base_thread.h" +#include "util.h" + +using namespace Shared::Util; + +namespace Shared { namespace PlatformCommon { + +BaseThread::BaseThread() { + + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + + setQuitStatus(false); + setRunningStatus(false); + + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); +} + +BaseThread::~BaseThread() { + shutdownAndWait(); +} + +void BaseThread::signalQuit() { + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + + setQuitStatus(true); + + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); +} + +void BaseThread::setQuitStatus(bool value) { + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + + mutexQuit.p(); + quit = value; + mutexQuit.v(); + + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); +} + +bool BaseThread::getQuitStatus() { + //SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + + bool retval = false; + mutexQuit.p(); + retval = quit; + mutexQuit.v(); + + //SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + + return retval; +} + +bool BaseThread::getRunningStatus() { + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + + bool retval = false; + mutexRunning.p(); + retval = running; + mutexRunning.v(); + + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] running = %d\n",__FILE__,__FUNCTION__,__LINE__,retval); + + return retval; +} + +void BaseThread::setRunningStatus(bool value) { + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] value = %d\n",__FILE__,__FUNCTION__,__LINE__,value); + + mutexRunning.p(); + running = value; + mutexRunning.v(); + + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] running = %d\n",__FILE__,__FUNCTION__,__LINE__,value); +} + +void BaseThread::shutdownAndWait(BaseThread *pThread) { + if(pThread != NULL) { + pThread->signalQuit(); + for( time_t elapsed = time(NULL); difftime(time(NULL),elapsed) <= 10; ) { + if(pThread->getRunningStatus() == false) { + break; + } + sleep(50); + //SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + } + //SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + } +} + +void BaseThread::shutdownAndWait() { + BaseThread::shutdownAndWait(this); +} + +}}//end namespace diff --git a/source/shared_lib/sources/platform/common/cache_manager.cpp b/source/shared_lib/sources/platform/common/cache_manager.cpp new file mode 100644 index 000000000..a7562aaf1 --- /dev/null +++ b/source/shared_lib/sources/platform/common/cache_manager.cpp @@ -0,0 +1,11 @@ +// ============================================================== +// This file is part of Glest Shared Library (www.glest.org) +// +// Copyright (C) 2009-2010 Titus Tscharntke (info@titusgames.de) and +// Mark Vejvoda (mark_vejvoda@hotmail.com) +// +// You can redistribute this code and/or modify it under +// the terms of the GNU General Public License as published +// by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version +// ============================================================== diff --git a/source/shared_lib/sources/platform/common/platform_common.cpp b/source/shared_lib/sources/platform/common/platform_common.cpp index 5009cfe3d..88a8788dc 100644 --- a/source/shared_lib/sources/platform/common/platform_common.cpp +++ b/source/shared_lib/sources/platform/common/platform_common.cpp @@ -7,6 +7,7 @@ //Foundation; either version 2 of the License, or (at your option) any later //version. #include "platform_common.h" +#include "cache_manager.h" #ifdef WIN32 @@ -290,6 +291,8 @@ int32 getFolderTreeContentsCheckSumRecursively(vector paths, string path SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); static std::map crcTreeCache; + //string cacheLookupId = string(__FILE__) + intToStr(__LINE__); + //std::map &crcTreeCache = CacheManager::getCachedItem(cacheLookupId); string cacheKey = ""; size_t count = paths.size(); diff --git a/source/shared_lib/sources/platform/common/simple_threads.cpp b/source/shared_lib/sources/platform/common/simple_threads.cpp new file mode 100644 index 000000000..9de1ce6ff --- /dev/null +++ b/source/shared_lib/sources/platform/common/simple_threads.cpp @@ -0,0 +1,73 @@ +// ============================================================== +// This file is part of Glest Shared Library (www.glest.org) +// +// Copyright (C) 2009-2010 Titus Tscharntke (info@titusgames.de) and +// Mark Vejvoda (mark_vejvoda@hotmail.com) +// +// You can redistribute this code and/or modify it under +// the terms of the GNU General Public License as published +// by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version +// ============================================================== + +#include "simple_threads.h" +#include "util.h" +#include "platform_common.h" + +using namespace Shared::Util; +using namespace Shared::PlatformCommon; + +namespace Shared { namespace PlatformCommon { + +FileCRCPreCacheThread::FileCRCPreCacheThread() : BaseThread() { +} + +void FileCRCPreCacheThread::execute() { + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + + setRunningStatus(true); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"FILE CRC PreCache thread is running\n"); + + try { + //tech Tree listBox + vector techPaths; + findDirs(techDataPaths, techPaths); + if(techPaths.empty() == false) { + for(int idx = 0; idx < techPaths.size(); idx++) { + string &techPath = techPaths[idx]; + for(int idx2 = 0; idx2 < techPaths.size(); idx2++) { + string techName = techPaths[idx2]; + + printf("In [%s::%s Line: %d] caching CRC value for Tech [%s]\n",__FILE__,__FUNCTION__,__LINE__,techName.c_str()); + int32 techCRC = getFolderTreeContentsCheckSumRecursively(techDataPaths, string("/") + techName + string("/*"), ".xml", NULL); + printf("In [%s::%s Line: %d] cached CRC value for Tech [%s] is [%d]\n",__FILE__,__FUNCTION__,__LINE__,techName.c_str(),techCRC); + + if(getQuitStatus() == true) { + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + break; + } + sleep( 100 ); + } + if(getQuitStatus() == true) { + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + break; + } + } + } + } + catch(const exception &ex) { + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); + setRunningStatus(false); + } + catch(...) { + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] unknown error\n",__FILE__,__FUNCTION__,__LINE__); + setRunningStatus(false); + } + + setRunningStatus(false); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"FILE CRC PreCache thread is exiting\n"); + + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); +} + +}}//end namespace diff --git a/source/shared_lib/sources/platform/posix/socket.cpp b/source/shared_lib/sources/platform/posix/socket.cpp index e6a0e6ced..228d41ae2 100644 --- a/source/shared_lib/sources/platform/posix/socket.cpp +++ b/source/shared_lib/sources/platform/posix/socket.cpp @@ -12,7 +12,6 @@ #include #include #include -//#include #if defined(HAVE_SYS_IOCTL_H) #define BSD_COMP /* needed for FIONREAD on Solaris2 */ @@ -1153,7 +1152,6 @@ void Socket::throwException(string str){ ClientSocket::ClientSocket() : Socket() { SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - //broadCastClientThread = NULL; stopBroadCastClientThread(); SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); @@ -1310,71 +1308,15 @@ void ClientSocket::connect(const Ip &ip, int port) // Description: Runs in its own thread to listen for broadcasts from // other servers // -BroadCastClientSocketThread::BroadCastClientSocketThread(DiscoveredServersInterface *cb) { +BroadCastClientSocketThread::BroadCastClientSocketThread(DiscoveredServersInterface *cb) : BaseThread() { SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - setQuitStatus(false); - setRunningStatus(false); discoveredServersCB = cb; SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } -void BroadCastClientSocketThread::signalQuit() { - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - - setQuitStatus(true); - - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); -} - -void BroadCastClientSocketThread::setQuitStatus(bool value) { - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - - mutexQuit.p(); - quit = value; - mutexQuit.v(); - - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); -} - -bool BroadCastClientSocketThread::getQuitStatus() { - //SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - - bool retval = false; - mutexQuit.p(); - retval = quit; - mutexQuit.v(); - - //SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - - return retval; -} - -bool BroadCastClientSocketThread::getRunningStatus() { - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - - bool retval = false; - mutexRunning.p(); - retval = running; - mutexRunning.v(); - - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] running = %d\n",__FILE__,__FUNCTION__,__LINE__,retval); - - return retval; -} - -void BroadCastClientSocketThread::setRunningStatus(bool value) { - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] value = %d\n",__FILE__,__FUNCTION__,__LINE__,value); - - mutexRunning.p(); - running = value; - mutexRunning.v(); - - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] running = %d\n",__FILE__,__FUNCTION__,__LINE__,value); -} - //======================================================================= // Function : broadcast thread // Description: Runs in its own thread to send out a broadcast to the local network @@ -1624,68 +1566,8 @@ Socket *ServerSocket::accept() return new Socket(newSock); } -BroadCastSocketThread::BroadCastSocketThread() { - +BroadCastSocketThread::BroadCastSocketThread() : BaseThread() { SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - - setQuitStatus(false); - setRunningStatus(false); - - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); -} - -void BroadCastSocketThread::signalQuit() { - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - - setQuitStatus(true); - - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); -} - -void BroadCastSocketThread::setQuitStatus(bool value) { - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - - mutexQuit.p(); - quit = value; - mutexQuit.v(); - - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); -} - -bool BroadCastSocketThread::getQuitStatus() { - //SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - - bool retval = false; - mutexQuit.p(); - retval = quit; - mutexQuit.v(); - - //SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - - return retval; -} - -bool BroadCastSocketThread::getRunningStatus() { - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - - bool retval = false; - mutexRunning.p(); - retval = running; - mutexRunning.v(); - - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] running = %d\n",__FILE__,__FUNCTION__,__LINE__,retval); - - return retval; -} - -void BroadCastSocketThread::setRunningStatus(bool value) { - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] value = %d\n",__FILE__,__FUNCTION__,__LINE__,value); - - mutexRunning.p(); - running = value; - mutexRunning.v(); - - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] running = %d\n",__FILE__,__FUNCTION__,__LINE__,value); } //======================================================================= @@ -1829,4 +1711,3 @@ void BroadCastSocketThread::execute() { }}//end namespace -