- overhaul of thread processing, especially in the menus, things now freeze much less and should be more reliable

This commit is contained in:
Mark Vejvoda 2011-01-02 06:46:48 +00:00
parent 9150701e70
commit 2b1732e27e
17 changed files with 435 additions and 507 deletions

View File

@ -238,7 +238,7 @@ Renderer::~Renderer() {
this->game = NULL;
}
void Renderer::simpleTask() {
void Renderer::simpleTask(BaseThread *callingThread) {
// This code reads pixmaps from a queue and saves them to disk
Pixmap2D *savePixMapBuffer=NULL;
string path="";
@ -840,7 +840,7 @@ void Renderer::renderConsoleLine(int lineIndex, int xPosition, int yPosition, in
Vec4f fontColor;
const Metrics &metrics= Metrics::getInstance();
const FontMetrics *fontMetrics= font->getMetrics();
if(game != NULL) {
fontColor = game->getGui()->getDisplay()->getColor();
}
@ -930,21 +930,21 @@ void Renderer::renderConsole(const Console *console,const bool showFullConsole,c
if(showFullConsole) {
for(int i = 0; i < console->getStoredLineCount(); ++i) {
const ConsoleLineInfo &lineInfo = console->getStoredLineItem(i);
renderConsoleLine(i, console->getXPos(), console->getYPos(),
renderConsoleLine(i, console->getXPos(), console->getYPos(),
console->getLineHeight(), console->getFont(), console->getStringToHighlight(), &lineInfo);
}
}
else if(showMenuConsole) {
for(int i = 0; i < console->getStoredLineCount() && i < maxConsoleLines; ++i) {
const ConsoleLineInfo &lineInfo = console->getStoredLineItem(i);
renderConsoleLine(i, console->getXPos(), console->getYPos(),
renderConsoleLine(i, console->getXPos(), console->getYPos(),
console->getLineHeight(), console->getFont(), console->getStringToHighlight(), &lineInfo);
}
}
else {
for(int i = 0; i < console->getLineCount(); ++i) {
const ConsoleLineInfo &lineInfo = console->getLineItem(i);
renderConsoleLine(i, console->getXPos(), console->getYPos(),
renderConsoleLine(i, console->getXPos(), console->getYPos(),
console->getLineHeight(), console->getFont(), console->getStringToHighlight(), &lineInfo);
}
}

View File

@ -174,7 +174,7 @@ public:
//light
static const float maxLightDist;
public:
enum Shadows {
sDisabled,
@ -433,7 +433,7 @@ private:
void renderTile(const Vec2i &pos);
void renderQuad(int x, int y, int w, int h, const Texture2D *texture);
void simpleTask();
void simpleTask(BaseThread *callingThread);
//static
static Texture2D::Filter strToTextureFilter(const string &s);

View File

@ -222,7 +222,7 @@ void Program::eventMouseMove(int x, int y, const MouseState *ms) {
}
}
void Program::simpleTask() {
void Program::simpleTask(BaseThread *callingThread) {
loopWorker();
}

View File

@ -154,7 +154,7 @@ public:
void init(WindowGl *window, bool initSound=true, bool toggleFullScreen=false);
void exit();
virtual void simpleTask();
virtual void simpleTask(BaseThread *callingThread);
void mouseDownLeft(int x, int y);
void eventMouseMove(int x, int y, const MouseState *ms);

View File

@ -507,14 +507,10 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, b
console.addLine(lang.get("To switch off music press")+" - \""+configKeys.getCharKey("ToggleMusic")+"\"");
//chatManager.init(&console, world.getThisTeamIndex());
chatManager.init(&console, -1,true);
GraphicComponent::applyAllCustomProperties(containerName);
MutexSafeWrapper safeMutexPtr(&publishToMasterserverThreadPtrChangeAccessor);
publishToMasterserverThreadInDeletion = false;
publishToMasterserverThread = new SimpleTaskThread(this,0,25);
publishToMasterserverThread->setUniqueID(__FILE__);
publishToMasterserverThread->start();
@ -523,35 +519,20 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, b
}
MenuStateCustomGame::~MenuStateCustomGame() {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
if(publishToMasterserverThreadInDeletion == false) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
MutexSafeWrapper safeMutexPtr(&publishToMasterserverThreadPtrChangeAccessor);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
if(publishToMasterserverThread != NULL) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
if(publishToMasterserverThread != NULL) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
needToBroadcastServerSettings = false;
needToRepublishToMasterserver = false;
//BaseThread::shutdownAndWait(publishToMasterserverThread);
if(publishToMasterserverThread != NULL &&
publishToMasterserverThread->shutdownAndWait() == true) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
delete publishToMasterserverThread;
publishToMasterserverThread = NULL;
}
publishToMasterserverThreadInDeletion = false;
safeMutexPtr.ReleaseLock();
}
else {
safeMutexPtr.ReleaseLock();
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
if(publishToMasterserverThread != NULL &&
publishToMasterserverThread->canShutdown(true) == true &&
publishToMasterserverThread->shutdownAndWait() == true) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
delete publishToMasterserverThread;
}
publishToMasterserverThread = NULL;
needToBroadcastServerSettings = false;
needToRepublishToMasterserver = false;
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
@ -561,26 +542,20 @@ MenuStateCustomGame::~MenuStateCustomGame() {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
void MenuStateCustomGame::returnToParentMenu(){
void MenuStateCustomGame::returnToParentMenu() {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
MutexSafeWrapper safeMutexPtr(&publishToMasterserverThreadPtrChangeAccessor);
publishToMasterserverThreadInDeletion = true;
needToBroadcastServerSettings = false;
needToRepublishToMasterserver = false;
bool returnToMasterServerMenu = parentMenuIsMs;
//BaseThread::shutdownAndWait(publishToMasterserverThread);
if(publishToMasterserverThread != NULL &&
publishToMasterserverThread->canShutdown() == true &&
publishToMasterserverThread->shutdownAndWait() == true) {
delete publishToMasterserverThread;
publishToMasterserverThread = NULL;
}
publishToMasterserverThreadInDeletion = false;
safeMutexPtr.ReleaseLock();
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
if(returnToMasterServerMenu) {
@ -618,22 +593,20 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton){
soundRenderer.playFx(coreData.getClickSoundA());
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
MutexSafeWrapper safeMutex((publishToMasterserverThread != NULL ? publishToMasterserverThread->getMutexThreadObjectAccessor() : NULL));
needToBroadcastServerSettings = false;
needToRepublishToMasterserver = false;
safeMutex.ReleaseLock();
MutexSafeWrapper safeMutexPtr(&publishToMasterserverThreadPtrChangeAccessor);
publishToMasterserverThreadInDeletion = true;
//BaseThread::shutdownAndWait(publishToMasterserverThread);
if(publishToMasterserverThread != NULL &&
publishToMasterserverThread->canShutdown() == true &&
publishToMasterserverThread->shutdownAndWait() == true) {
delete publishToMasterserverThread;
publishToMasterserverThread = NULL;
}
publishToMasterserverThreadInDeletion = false;
safeMutexPtr.ReleaseLock();
//publishToMasterserverThreadInDeletion = false;
//safeMutexPtr.ReleaseLock();
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
@ -652,7 +625,7 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton){
else if(listBoxMap.mouseClick(x, y)){
SystemFlags::OutputDebug(SystemFlags::debugSystem,"%s\n", getCurrentMapFile().c_str());
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
MutexSafeWrapper safeMutex((publishToMasterserverThread != NULL ? publishToMasterserverThread->getMutexThreadObjectAccessor() : NULL));
loadMapInfo(Map::getMapPath(getCurrentMapFile(),"",false), &mapInfo, true);
labelMapInfo.setText(mapInfo.desc);
@ -670,7 +643,7 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton){
}
}
else if (listBoxAdvanced.getSelectedItemIndex() == 1 && listBoxFogOfWar.mouseClick(x, y)) {
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
MutexSafeWrapper safeMutex((publishToMasterserverThread != NULL ? publishToMasterserverThread->getMutexThreadObjectAccessor() : NULL));
if(listBoxPublishServer.getSelectedItemIndex() == 0) {
needToRepublishToMasterserver = true;
@ -683,7 +656,7 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton){
}
}
else if (listBoxAdvanced.getSelectedItemIndex() == 1 && listBoxAllowObservers.mouseClick(x, y)) {
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
MutexSafeWrapper safeMutex((publishToMasterserverThread != NULL ? publishToMasterserverThread->getMutexThreadObjectAccessor() : NULL));
if(listBoxPublishServer.getSelectedItemIndex() == 0) {
needToRepublishToMasterserver = true;
@ -697,7 +670,7 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton){
}
}
else if (listBoxAdvanced.getSelectedItemIndex() == 1 && listBoxEnableObserverMode.mouseClick(x, y)) {
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
MutexSafeWrapper safeMutex((publishToMasterserverThread != NULL ? publishToMasterserverThread->getMutexThreadObjectAccessor() : NULL));
if(listBoxPublishServer.getSelectedItemIndex() == 0) {
needToRepublishToMasterserver = true;
@ -710,7 +683,7 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton){
}
}
else if (listBoxAdvanced.getSelectedItemIndex() == 1 && listBoxPathFinderType.mouseClick(x, y)) {
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
MutexSafeWrapper safeMutex((publishToMasterserverThread != NULL ? publishToMasterserverThread->getMutexThreadObjectAccessor() : NULL));
if(listBoxPublishServer.getSelectedItemIndex() == 0) {
needToRepublishToMasterserver = true;
@ -725,20 +698,8 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton){
else if (listBoxAdvanced.mouseClick(x, y)) {
//TODO
}
/*
else if (listBoxAdvanced.getSelectedItemIndex() == 1 && listBoxEnableServerControlledAI.mouseClick(x, y) && listBoxEnableServerControlledAI.getEditable()) {
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
needToRepublishToMasterserver = true;
if(hasNetworkGameSettings() == true)
{
needToSetChangedGameSettings = true;
lastSetChangedGameSettings = time(NULL);
}
}
*/
else if(listBoxTileset.mouseClick(x, y)){
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
MutexSafeWrapper safeMutex((publishToMasterserverThread != NULL ? publishToMasterserverThread->getMutexThreadObjectAccessor() : NULL));
if(listBoxPublishServer.getSelectedItemIndex() == 0) {
needToRepublishToMasterserver = true;
@ -750,7 +711,7 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton){
}
}
else if(listBoxMapFilter.mouseClick(x, y)){
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
MutexSafeWrapper safeMutex((publishToMasterserverThread != NULL ? publishToMasterserverThread->getMutexThreadObjectAccessor() : NULL));
switchToNextMapGroup(listBoxMapFilter.getSelectedItemIndex()-oldListBoxMapfilterIndex);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"%s\n", getCurrentMapFile().c_str());
@ -772,7 +733,7 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton){
else if(listBoxTechTree.mouseClick(x, y)){
reloadFactions(false);
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
MutexSafeWrapper safeMutex((publishToMasterserverThread != NULL ? publishToMasterserverThread->getMutexThreadObjectAccessor() : NULL));
if(listBoxPublishServer.getSelectedItemIndex() == 0) {
needToRepublishToMasterserver = true;
@ -785,25 +746,12 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton){
}
}
else if(listBoxPublishServer.mouseClick(x, y) && listBoxPublishServer.getEditable()) {
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
MutexSafeWrapper safeMutex((publishToMasterserverThread != NULL ? publishToMasterserverThread->getMutexThreadObjectAccessor() : NULL));
needToRepublishToMasterserver = true;
soundRenderer.playFx(coreData.getClickSoundC());
}
/*
else if(listBoxAdvanced.getSelectedItemIndex() == 1 && listBoxNetworkFramePeriod.mouseClick(x, y)){
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
needToRepublishToMasterserver = true;
if(hasNetworkGameSettings() == true)
{
needToSetChangedGameSettings = true;
lastSetChangedGameSettings = time(NULL);
}
soundRenderer.playFx(coreData.getClickSoundC());
}
*/
else if(listBoxAdvanced.getSelectedItemIndex() == 1 && listBoxNetworkPauseGameForLaggedClients.mouseClick(x, y)){
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
MutexSafeWrapper safeMutex((publishToMasterserverThread != NULL ? publishToMasterserverThread->getMutexThreadObjectAccessor() : NULL));
if(listBoxPublishServer.getSelectedItemIndex() == 0) {
needToRepublishToMasterserver = true;
@ -818,7 +766,7 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton){
}
else {
for(int i=0; i<mapInfo.players; ++i) {
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
MutexSafeWrapper safeMutex((publishToMasterserverThread != NULL ? publishToMasterserverThread->getMutexThreadObjectAccessor() : NULL));
if (listBoxAdvanced.getSelectedItemIndex() == 1) {
// set multiplier
@ -993,7 +941,7 @@ void MenuStateCustomGame::RestoreLastGameSettings() {
ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface();
serverInterface->setGameSettings(&gameSettings,false);
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
MutexSafeWrapper safeMutex((publishToMasterserverThread != NULL ? publishToMasterserverThread->getMutexThreadObjectAccessor() : NULL));
if(listBoxPublishServer.getSelectedItemIndex() == 0) {
needToRepublishToMasterserver = true;
@ -1007,7 +955,7 @@ void MenuStateCustomGame::RestoreLastGameSettings() {
}
void MenuStateCustomGame::PlayNow() {
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
MutexSafeWrapper safeMutex((publishToMasterserverThread != NULL ? publishToMasterserverThread->getMutexThreadObjectAccessor() : NULL));
saveGameSettingsToFile("lastCustomGamSettings.mgg");
closeUnusedSlots();
@ -1145,18 +1093,13 @@ void MenuStateCustomGame::PlayNow() {
needToRepublishToMasterserver = false;
safeMutex.ReleaseLock();
MutexSafeWrapper safeMutexPtr(&publishToMasterserverThreadPtrChangeAccessor);
publishToMasterserverThreadInDeletion = true;
//BaseThread::shutdownAndWait(publishToMasterserverThread);
if(publishToMasterserverThread != NULL &&
publishToMasterserverThread->canShutdown() == true &&
publishToMasterserverThread->shutdownAndWait() == true) {
delete publishToMasterserverThread;
publishToMasterserverThread = NULL;
}
publishToMasterserverThreadInDeletion = false;
safeMutexPtr.ReleaseLock();
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
assert(program != NULL);
@ -1379,11 +1322,9 @@ void MenuStateCustomGame::update() {
Chrono chrono;
chrono.start();
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
MutexSafeWrapper safeMutex((publishToMasterserverThread != NULL ? publishToMasterserverThread->getMutexThreadObjectAccessor() : NULL));
try {
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
if(serverInitError == true) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
@ -1633,7 +1574,6 @@ void MenuStateCustomGame::update() {
labelNetStatus[i].setText(szBuf);
}
else {
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] C - ctNetwork\n",__FILE__,__FUNCTION__);
string port = intToStr(config.getInt("ServerPort"));
if(port != intToStr(GameConstants::serverPort)){
port = port + " " + lang.get("NonStandardPort") + "!)";
@ -1852,46 +1792,36 @@ void MenuStateCustomGame::publishToMasterserver()
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
void MenuStateCustomGame::simpleTask() {
void MenuStateCustomGame::simpleTask(BaseThread *callingThread) {
try {
if(publishToMasterserverThreadInDeletion == true) {
if(callingThread->getQuitStatus() == true) {
return;
}
if( publishToMasterserverThread == NULL ||
publishToMasterserverThread->getQuitStatus() == true) {
return;
}
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
bool republish = (needToRepublishToMasterserver == true && publishToServerInfo.size() != 0);
needToRepublishToMasterserver = false;
std::map<string,string> newPublishToServerInfo = publishToServerInfo;
MutexSafeWrapper safeMutex(callingThread->getMutexThreadObjectAccessor());
bool republish = (needToRepublishToMasterserver == true && publishToServerInfo.size() != 0);
needToRepublishToMasterserver = false;
std::map<string,string> newPublishToServerInfo = publishToServerInfo;
publishToServerInfo.clear();
bool broadCastSettings = needToBroadcastServerSettings;
needToBroadcastServerSettings=false;
bool hasClientConnection = false;
if(broadCastSettings) {
bool broadCastSettings = needToBroadcastServerSettings;
needToBroadcastServerSettings = false;
bool hasClientConnection = false;
if(broadCastSettings == true) {
ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface();
hasClientConnection = serverInterface->hasClientConnection();
}
bool needPing = (difftime(time(NULL),lastNetworkPing) >= GameConstants::networkPingInterval);
safeMutex.ReleaseLock(true);
bool needPing = (difftime(time(NULL),lastNetworkPing) >= GameConstants::networkPingInterval);
safeMutex.ReleaseLock();
if( publishToMasterserverThread == NULL ||
publishToMasterserverThread->getQuitStatus() == true) {
if(callingThread->getQuitStatus() == true) {
return;
}
if(republish == true) {
safeMutex.Lock();
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
//string request = Config::getInstance().getString("Masterserver") + "addServerInfo.php?" + newPublishToServerInfo;
string request = Config::getInstance().getString("Masterserver") + "addServerInfo.php?";
CURL *handle = SystemFlags::initHTTP();
@ -1906,10 +1836,16 @@ void MenuStateCustomGame::simpleTask() {
//printf("the request is:\n%s\n",request.c_str());
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] the request is:\n%s\n",__FILE__,__FUNCTION__,__LINE__,request.c_str());
safeMutex.ReleaseLock(true);
std::string serverInfo = SystemFlags::getHTTP(request,handle);
SystemFlags::cleanupHTTP(&handle);
if(callingThread->getQuitStatus() == true) {
return;
}
safeMutex.Lock();
//printf("the result is:\n'%s'\n",serverInfo.c_str());
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] the result is:\n'%s'\n",__FILE__,__FUNCTION__,__LINE__,serverInfo.c_str());
@ -1918,47 +1854,39 @@ void MenuStateCustomGame::simpleTask() {
showMasterserverError=true;
masterServererErrorToShow = (serverInfo != "" ? serverInfo : "No Reply");
}
safeMutex.ReleaseLock(true);
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
if( publishToMasterserverThread == NULL ||
publishToMasterserverThread->getQuitStatus() == true) {
if(callingThread->getQuitStatus() == true) {
return;
}
if(broadCastSettings) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
if(broadCastSettings == true) {
safeMutex.Lock();
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface();
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
MutexSafeWrapper safeMutex2(&masterServerThreadAccessor);
GameSettings gameSettings;
loadGameSettings(&gameSettings);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
serverInterface->setGameSettings(&gameSettings,false);
safeMutex2.ReleaseLock();
if(hasClientConnection == true) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
MutexSafeWrapper safeMutex3(&masterServerThreadAccessor);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
serverInterface->broadcastGameSetup(&gameSettings);
safeMutex3.ReleaseLock();
}
safeMutex.ReleaseLock(true);
}
if( publishToMasterserverThread == NULL ||
publishToMasterserverThread->getQuitStatus() == true) {
if(callingThread->getQuitStatus() == true) {
return;
}
safeMutex.Lock();
if(needPing == true) {
lastNetworkPing = time(NULL);
@ -1966,19 +1894,21 @@ void MenuStateCustomGame::simpleTask() {
ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface();
NetworkMessagePing msg(GameConstants::networkPingInterval,time(NULL));
MutexSafeWrapper safeMutex2(&masterServerThreadAccessor);
serverInterface->broadcastPing(&msg);
safeMutex2.ReleaseLock();
}
safeMutex.ReleaseLock();
}
catch(const std::exception &ex) {
char szBuf[4096]="";
sprintf(szBuf,"In [%s::%s %d] Error detected:\n%s\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
SystemFlags::OutputDebug(SystemFlags::debugError,szBuf);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"%s",szBuf);
//throw runtime_error(szBuf);!!!
showGeneralError=true;
generalErrorToShow = ex.what();
if(callingThread->getQuitStatus() == false) {
//throw runtime_error(szBuf);!!!
showGeneralError=true;
generalErrorToShow = ex.what();
}
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
@ -2638,7 +2568,7 @@ void MenuStateCustomGame::keyDown(char key) {
activeInputLabel->setText(text);
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
MutexSafeWrapper safeMutex((publishToMasterserverThread != NULL ? publishToMasterserverThread->getMutexThreadObjectAccessor() : NULL));
if(hasNetworkGameSettings() == true) {
needToSetChangedGameSettings = true;
lastSetChangedGameSettings = time(NULL);
@ -2693,7 +2623,7 @@ void MenuStateCustomGame::keyPress(char c) {
text.insert(text.end()-1, c);
activeInputLabel->setText(text);
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
MutexSafeWrapper safeMutex((publishToMasterserverThread != NULL ? publishToMasterserverThread->getMutexThreadObjectAccessor() : NULL));
if(hasNetworkGameSettings() == true) {
needToSetChangedGameSettings = true;
lastSetChangedGameSettings = time(NULL);

View File

@ -102,9 +102,9 @@ private:
bool needToBroadcastServerSettings;
std::map<string,string> publishToServerInfo;
SimpleTaskThread *publishToMasterserverThread;
Mutex masterServerThreadAccessor;
Mutex publishToMasterserverThreadPtrChangeAccessor;
bool publishToMasterserverThreadInDeletion;
//Mutex masterServerThreadAccessor;
//Mutex publishToMasterserverThreadPtrChangeAccessor;
//bool publishToMasterserverThreadInDeletion;
bool parentMenuIsMs;
int soundConnectionCount;
@ -157,7 +157,7 @@ public:
virtual void keyUp(char key);
virtual void simpleTask();
virtual void simpleTask(BaseThread *callingThread);
virtual bool isInSpecialKeyCaptureEvent() { return chatManager.getEditEnabled(); }
private:

View File

@ -241,8 +241,6 @@ MenuStateMasterserver::MenuStateMasterserver(Program *program, MainMenu *mainMen
chatManager.setYPos(consoleIRC.getYPos()-20);
chatManager.setFont(CoreData::getInstance().getMenuFontNormal());
MutexSafeWrapper safeMutexPtr(&masterServerThreadPtrChangeAccessor);
masterServerThreadInDeletion = false;
needUpdateFromServer = true;
updateFromMasterserverThread = new SimpleTaskThread(this,0,100);
updateFromMasterserverThread->setUniqueID(__FILE__);
@ -300,48 +298,29 @@ void MenuStateMasterserver::IRC_CallbackEvent(IRCEventType evt, const char* orig
void MenuStateMasterserver::cleanup() {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//printf("In [%s::%s Line: %d] [%p]\n",__FILE__,__FUNCTION__,__LINE__,ircClient);
MutexSafeWrapper safeMutex((updateFromMasterserverThread != NULL ? updateFromMasterserverThread->getMutexThreadObjectAccessor() : NULL));
needUpdateFromServer = false;
if(masterServerThreadInDeletion == false) {
MutexSafeWrapper safeMutexPtr(&masterServerThreadPtrChangeAccessor);
if(updateFromMasterserverThread != NULL) {
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
needUpdateFromServer = false;
safeMutex.ReleaseLock();
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//BaseThread::shutdownAndWait(updateFromMasterserverThread);
masterServerThreadInDeletion = true;
if(updateFromMasterserverThread != NULL &&
updateFromMasterserverThread->shutdownAndWait() == true) {
delete updateFromMasterserverThread;
}
updateFromMasterserverThread = NULL;
masterServerThreadInDeletion = false;
safeMutexPtr.ReleaseLock();
}
else {
safeMutexPtr.ReleaseLock();
}
}
if(updateFromMasterserverThread != NULL &&
updateFromMasterserverThread->canShutdown(true) == true &&
updateFromMasterserverThread->shutdownAndWait() == true) {
delete updateFromMasterserverThread;
}
updateFromMasterserverThread = NULL;
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
clearServerLines();
clearUserButtons();
//printf("Exiting master server menu [%p]\n",ircClient);
MutexSafeWrapper safeMutexIRCPtr(&mutexIRCClient);
if(ircClient != NULL) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
ircClient->setCallbackObj(NULL);
ircClient->signalQuit();
//if(ircClient->shutdownAndWait() == true) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//delete ircClient;
//}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
ircClient = NULL;
}
@ -351,14 +330,12 @@ void MenuStateMasterserver::cleanup() {
MenuStateMasterserver::~MenuStateMasterserver() {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//printf("In [%s::%s Line: %d] [%p]\n",__FILE__,__FUNCTION__,__LINE__,ircClient);
cleanup();
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] END\n",__FILE__,__FUNCTION__,__LINE__);
}
void MenuStateMasterserver::clearServerLines() {
while(!serverLines.empty()){
while(!serverLines.empty()) {
delete serverLines.back();
serverLines.pop_back();
}
@ -401,7 +378,7 @@ void MenuStateMasterserver::mouseClick(int x, int y, MouseButton mouseButton){
else if(buttonRefresh.mouseClick(x, y)){
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
MutexSafeWrapper safeMutex((updateFromMasterserverThread != NULL ? updateFromMasterserverThread->getMutexThreadObjectAccessor() : NULL));
soundRenderer.playFx(coreData.getClickSoundB());
needUpdateFromServer = true;
@ -410,22 +387,8 @@ void MenuStateMasterserver::mouseClick(int x, int y, MouseButton mouseButton){
else if(buttonReturn.mouseClick(x, y)){
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
soundRenderer.playFx(coreData.getClickSoundB());
//BaseThread::shutdownAndWait(updateFromMasterserverThread);
MutexSafeWrapper safeMutexPtr(&masterServerThreadPtrChangeAccessor);
masterServerThreadInDeletion = true;
if(updateFromMasterserverThread != NULL &&
updateFromMasterserverThread->shutdownAndWait() == true) {
delete updateFromMasterserverThread;
}
updateFromMasterserverThread = NULL;
masterServerThreadInDeletion = false;
safeMutexPtr.ReleaseLock();
safeMutex.ReleaseLock();
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
cleanup();
@ -439,26 +402,13 @@ void MenuStateMasterserver::mouseClick(int x, int y, MouseButton mouseButton){
else if(buttonCreateGame.mouseClick(x, y)){
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
MutexSafeWrapper safeMutex((updateFromMasterserverThread != NULL ? updateFromMasterserverThread->getMutexThreadObjectAccessor() : NULL));
soundRenderer.playFx(coreData.getClickSoundB());
needUpdateFromServer = false;
safeMutex.ReleaseLock();
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//BaseThread::shutdownAndWait(updateFromMasterserverThread);
MutexSafeWrapper safeMutexPtr(&masterServerThreadPtrChangeAccessor);
masterServerThreadInDeletion = true;
if(updateFromMasterserverThread != NULL &&
updateFromMasterserverThread->shutdownAndWait() == true) {
delete updateFromMasterserverThread;
}
updateFromMasterserverThread = NULL;
masterServerThreadInDeletion = false;
safeMutexPtr.ReleaseLock();
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
cleanup();
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
@ -467,12 +417,12 @@ void MenuStateMasterserver::mouseClick(int x, int y, MouseButton mouseButton){
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
else if(listBoxAutoRefresh.mouseClick(x, y)){
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
MutexSafeWrapper safeMutex((updateFromMasterserverThread != NULL ? updateFromMasterserverThread->getMutexThreadObjectAccessor() : NULL));
soundRenderer.playFx(coreData.getClickSoundA());
autoRefreshTime=10*listBoxAutoRefresh.getSelectedItemIndex();
}
else {
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
MutexSafeWrapper safeMutex((updateFromMasterserverThread != NULL ? updateFromMasterserverThread->getMutexThreadObjectAccessor() : NULL));
bool clicked=false;
if(!clicked && serverScrollBar.getElementCount()!=0){
for(int i = serverScrollBar.getVisibleStart(); i <= serverScrollBar.getVisibleEnd(); ++i) {
@ -486,15 +436,7 @@ void MenuStateMasterserver::mouseClick(int x, int y, MouseButton mouseButton){
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
safeMutex.ReleaseLock();
MutexSafeWrapper safeMutexPtr(&masterServerThreadPtrChangeAccessor);
masterServerThreadInDeletion = true;
if(updateFromMasterserverThread != NULL &&
updateFromMasterserverThread->shutdownAndWait() == true) {
delete updateFromMasterserverThread;
}
updateFromMasterserverThread = NULL;
masterServerThreadInDeletion = false;
safeMutexPtr.ReleaseLock();
cleanup();
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
mainMenu->setState(new MenuStateConnectedGame(program, mainMenu,jmMasterserver));
@ -523,7 +465,7 @@ void MenuStateMasterserver::mouseClick(int x, int y, MouseButton mouseButton){
}
void MenuStateMasterserver::mouseMove(int x, int y, const MouseState *ms){
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
MutexSafeWrapper safeMutex((updateFromMasterserverThread != NULL ? updateFromMasterserverThread->getMutexThreadObjectAccessor() : NULL));
if (mainMessageBox.getEnabled()) {
mainMessageBox.mouseMove(x, y);
@ -556,7 +498,7 @@ void MenuStateMasterserver::mouseMove(int x, int y, const MouseState *ms){
void MenuStateMasterserver::render(){
Renderer &renderer= Renderer::getInstance();
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
MutexSafeWrapper safeMutex((updateFromMasterserverThread != NULL ? updateFromMasterserverThread->getMutexThreadObjectAccessor() : NULL));
if(mainMessageBox.getEnabled()) {
renderer.renderMessageBox(&mainMessageBox);
}
@ -632,7 +574,7 @@ void MenuStateMasterserver::render(){
}
void MenuStateMasterserver::update() {
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
MutexSafeWrapper safeMutex((updateFromMasterserverThread != NULL ? updateFromMasterserverThread->getMutexThreadObjectAccessor() : NULL));
if(autoRefreshTime!=0 && difftime(time(NULL),lastRefreshTimer) >= autoRefreshTime ) {
needUpdateFromServer = true;
lastRefreshTimer= time(NULL);
@ -727,139 +669,124 @@ void MenuStateMasterserver::update() {
}
}
void MenuStateMasterserver::simpleTask() {
if(masterServerThreadInDeletion == true) {
void MenuStateMasterserver::simpleTask(BaseThread *callingThread) {
if(callingThread->getQuitStatus() == true) {
return;
}
if( updateFromMasterserverThread == NULL ||
updateFromMasterserverThread->getQuitStatus() == true) {
return;
}
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
MutexSafeWrapper safeMutex(callingThread->getMutexThreadObjectAccessor());
bool needUpdate = needUpdateFromServer;
safeMutex.ReleaseLock();
if(needUpdate == true) {
updateServerInfo();
}
}
void MenuStateMasterserver::updateServerInfo() {
try {
if(masterServerThreadInDeletion == true) {
return;
}
MutexSafeWrapper safeMutexPtr(&masterServerThreadPtrChangeAccessor);
if( updateFromMasterserverThread == NULL ||
updateFromMasterserverThread->getQuitStatus() == true) {
safeMutexPtr.ReleaseLock();
return;
}
safeMutexPtr.ReleaseLock(true);
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
needUpdateFromServer = false;
safeMutex.ReleaseLock(true);
if(announcementLoaded == false) {
string announcementURL = Config::getInstance().getString("AnnouncementURL","http://master.megaglest.org/files/announcement.txt");
if(announcementURL != "") {
std::string announcementTxt = SystemFlags::getHTTP(announcementURL);
if(StartsWith(announcementTxt,"Announcement from Masterserver:") == true) {
int newlineCount=0;
size_t lastIndex=0;
//announcementLabel.setText(announcementTxt);
consoleIRC.addLine(announcementTxt);
while(true){
lastIndex=announcementTxt.find("\n",lastIndex+1);
if(lastIndex==string::npos)
{
break;
}
else
{
newlineCount++;
}
}
newlineCount--;// remove my own line
for( int i=0; i< newlineCount;++i ){
consoleIRC.addLine("");
}
}
}
consoleIRC.addLine("---------------------------------------------");
string versionURL = Config::getInstance().getString("VersionURL","http://master.megaglest.org/files/versions/")+glestVersionString+".txt";
//printf("\nversionURL=%s\n",versionURL.c_str());
if(versionURL != "") {
std::string versionTxt = SystemFlags::getHTTP(versionURL);
if(StartsWith(versionTxt,"Version info:") == true) {
int newlineCount=0;
size_t lastIndex=0;
//versionInfoLabel.setText(versionTxt);
consoleIRC.addLine(versionTxt);
while(true){
lastIndex=versionTxt.find("\n",lastIndex+1);
if(lastIndex==string::npos)
{
break;
}
else
{
newlineCount++;
}
}
newlineCount--;// remove my own line
for( int i=0; i< newlineCount;++i ){
consoleIRC.addLine("");
}
}
}
consoleIRC.addLine("---------------------------------------------");
// write hint to console:
Config &configKeys = Config::getInstance(std::pair<ConfigType,ConfigType>(cfgMainKeys,cfgUserKeys));
consoleIRC.addLine(Lang::getInstance().get("To switch off music press")+" - \""+configKeys.getCharKey("ToggleMusic")+"\"");
announcementLoaded=true;
}
Lang &lang= Lang::getInstance();
try {
if(Config::getInstance().getString("Masterserver","") != "") {
std::string localServerInfoString = SystemFlags::getHTTP(Config::getInstance().getString("Masterserver") + "showServersForGlest.php");
serverInfoString=localServerInfoString;
if(callingThread->getQuitStatus() == true) {
return;
}
needUpdateFromServer = false;
if(announcementLoaded == false) {
string announcementURL = Config::getInstance().getString("AnnouncementURL","http://master.megaglest.org/files/announcement.txt");
if(announcementURL != "") {
safeMutex.ReleaseLock(true);
std::string announcementTxt = SystemFlags::getHTTP(announcementURL);
if(callingThread->getQuitStatus() == true) {
return;
}
safeMutex.Lock();
if(StartsWith(announcementTxt,"Announcement from Masterserver:") == true) {
int newlineCount=0;
size_t lastIndex=0;
//announcementLabel.setText(announcementTxt);
consoleIRC.addLine(announcementTxt);
while(true) {
lastIndex=announcementTxt.find("\n",lastIndex+1);
if(lastIndex==string::npos) {
break;
}
else {
newlineCount++;
}
}
newlineCount--;// remove my own line
for( int i=0; i< newlineCount;++i ) {
consoleIRC.addLine("");
}
}
}
consoleIRC.addLine("---------------------------------------------");
string versionURL = Config::getInstance().getString("VersionURL","http://master.megaglest.org/files/versions/")+glestVersionString+".txt";
//printf("\nversionURL=%s\n",versionURL.c_str());
if(versionURL != "") {
safeMutex.ReleaseLock(true);
std::string versionTxt = SystemFlags::getHTTP(versionURL);
if(callingThread->getQuitStatus() == true) {
return;
}
safeMutex.Lock();
if(StartsWith(versionTxt,"Version info:") == true) {
int newlineCount=0;
size_t lastIndex=0;
//versionInfoLabel.setText(versionTxt);
consoleIRC.addLine(versionTxt);
while(true) {
lastIndex=versionTxt.find("\n",lastIndex+1);
if(lastIndex==string::npos) {
break;
}
else {
newlineCount++;
}
}
newlineCount--;// remove my own line
for( int i=0; i< newlineCount;++i ) {
consoleIRC.addLine("");
}
}
}
consoleIRC.addLine("---------------------------------------------");
// write hint to console:
Config &configKeys = Config::getInstance(std::pair<ConfigType,ConfigType>(cfgMainKeys,cfgUserKeys));
consoleIRC.addLine(Lang::getInstance().get("To switch off music press")+" - \""+configKeys.getCharKey("ToggleMusic")+"\"");
announcementLoaded=true;
}
Lang &lang= Lang::getInstance();
try {
if(Config::getInstance().getString("Masterserver","") != "") {
safeMutex.ReleaseLock(true);
std::string localServerInfoString = SystemFlags::getHTTP(Config::getInstance().getString("Masterserver") + "showServersForGlest.php");
if(callingThread->getQuitStatus() == true) {
return;
}
safeMutex.Lock();
serverInfoString=localServerInfoString;
}
}
catch(const exception &ex) {
serverInfoString=ex.what();
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line %d] error during Internet game status update: [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
}
}
catch(const exception &ex) {
serverInfoString=ex.what();
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line %d] error during Internet game status update: [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
}
safeMutexPtr.Lock();
if( updateFromMasterserverThread == NULL ||
updateFromMasterserverThread->getQuitStatus() == true) {
safeMutexPtr.ReleaseLock();
return;
}
safeMutexPtr.ReleaseLock();
}
catch(const exception &e){
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what());
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Line: %d, error [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what());
threadedErrorMsg = e.what();
catch(const exception &e){
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what());
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Line: %d, error [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what());
threadedErrorMsg = e.what();
}
}
}
void MenuStateMasterserver::rebuildServerLines(const string &serverInfo)
{
void MenuStateMasterserver::rebuildServerLines(const string &serverInfo) {
int numberOfOldServerLines=serverLines.size();
clearServerLines();
Lang &lang= Lang::getInstance();

View File

@ -97,9 +97,6 @@ private:
static DisplayMessageFunction pCB_DisplayMessage;
std::string threadedErrorMsg;
Mutex masterServerThreadAccessor;
Mutex masterServerThreadPtrChangeAccessor;
bool masterServerThreadInDeletion;
std::vector<string> ircArgs;
Mutex mutexIRCClient;
@ -122,7 +119,7 @@ public:
virtual void keyPress(char c);
virtual void keyUp(char key);
virtual void simpleTask();
virtual void simpleTask(BaseThread *callingThread);
static void setDisplayMessageFunction(DisplayMessageFunction pDisplayMessage) { pCB_DisplayMessage = pDisplayMessage; }
@ -133,7 +130,6 @@ private:
void setButtonLinePosition(int pos);
void clearServerLines();
void clearUserButtons();
void updateServerInfo();
void rebuildServerLines(const string &serverInfo);
void cleanup();
virtual void IRC_CallbackEvent(IRCEventType evt, const char* origin, const char **params, unsigned int count);

View File

@ -146,7 +146,7 @@ ServerInterface::~ServerInterface() {
// This triggers a gameOver message to be sent to the masterserver
lastMasterserverHeartbeatTime = 0;
if(needToRepublishToMasterserver == true) {
simpleTask();
simpleTask(NULL);
}
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
@ -1523,7 +1523,7 @@ std::map<string,string> ServerInterface::publishToMasterserver() {
return publishToServerInfo;
}
void ServerInterface::simpleTask() {
void ServerInterface::simpleTask(BaseThread *callingThread) {
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
MutexSafeWrapper safeMutex(&masterServerThreadAccessor,intToStr(__LINE__));

View File

@ -121,7 +121,7 @@ public:
Mutex * getServerSynchAccessor() { return &serverSynchAccessor; }
virtual void simpleTask();
virtual void simpleTask(BaseThread *callingThread);
void addClientToServerIPAddress(uint32 clientIp,uint32 ServerIp);
private:

View File

@ -58,7 +58,7 @@ public:
static SoundRenderer &getInstance();
bool init(Window *window);
void update();
virtual void simpleTask() { update(); }
virtual void simpleTask(BaseThread *callingThread) { update(); }
SoundPlayer *getSoundPlayer() const {return soundPlayer;}
//music

View File

@ -31,13 +31,21 @@ protected:
Mutex mutexRunning;
Mutex mutexQuit;
Mutex mutexBeginExecution;
Mutex mutexDeleteSelfOnExecutionDone;
Mutex mutexThreadObjectAccessor;
Mutex mutexExecutingTask;
bool executingTask;
bool quit;
bool running;
string uniqueID;
bool hasBeginExecution;
bool deleteSelfOnExecutionDone;
virtual void setQuitStatus(bool value);
void deleteSelfIfRequired();
public:
BaseThread();
@ -47,17 +55,26 @@ public:
virtual void signalQuit();
virtual bool getQuitStatus();
virtual bool getRunningStatus();
virtual bool getHasBeginExecution();
virtual void setHasBeginExecution(bool value);
static bool shutdownAndWait(BaseThread *ppThread);
virtual bool shutdownAndWait();
virtual bool canShutdown() { return true; }
virtual bool canShutdown(bool deleteSelfIfShutdownDelayed=false);
virtual bool getDeleteSelfOnExecutionDone();
virtual void setDeleteSelfOnExecutionDone(bool value);
void setUniqueID(string value) { uniqueID = value; }
string getUniqueID() { return uniqueID; }
virtual void setRunningStatus(bool value);
void setExecutingTask(bool value);
bool getExecutingTask();
Mutex * getMutexThreadObjectAccessor() { return &mutexThreadObjectAccessor; }
};
class RunningStatusSafeWrapper {
@ -85,6 +102,32 @@ public:
}
};
class ExecutingTaskSafeWrapper {
protected:
BaseThread *thread;
public:
ExecutingTaskSafeWrapper(BaseThread *thread) {
this->thread = thread;
Enable();
}
~ExecutingTaskSafeWrapper() {
Disable();
}
void Enable() {
if(this->thread != NULL) {
this->thread->setExecutingTask(true);
}
}
void Disable() {
if(this->thread != NULL) {
this->thread->setExecutingTask(false);
}
}
};
}}//end namespace
#endif

View File

@ -48,7 +48,7 @@ public:
//
class SimpleTaskCallbackInterface {
public:
virtual void simpleTask() = 0;
virtual void simpleTask(BaseThread *callingThread) = 0;
};
class SimpleTaskThread : public BaseThread
@ -63,9 +63,6 @@ protected:
bool taskSignalled;
bool needTaskSignal;
Mutex mutexExecutingTask;
bool executingTask;
public:
SimpleTaskThread();
SimpleTaskThread(SimpleTaskCallbackInterface *simpleTaskInterface,
@ -73,12 +70,10 @@ public:
unsigned int millisecsBetweenExecutions=0,
bool needTaskSignal = false);
virtual void execute();
virtual bool canShutdown();
virtual bool canShutdown(bool deleteSelfIfShutdownDelayed=false);
void setTaskSignalled(bool value);
bool getTaskSignalled();
void setExecutingTask(bool value);
bool getExecutingTask();
};
// =====================================================

View File

@ -121,7 +121,7 @@ public:
Socket();
virtual ~Socket();
virtual void simpleTask();
virtual void simpleTask(BaseThread *callingThread);
static int getBroadCastPort() { return broadcast_portno; }
static void setBroadCastPort(int value) { broadcast_portno = value; }

View File

@ -27,6 +27,8 @@ BaseThread::BaseThread() : Thread() {
setQuitStatus(false);
setRunningStatus(false);
setHasBeginExecution(false);
setExecutingTask(false);
setDeleteSelfOnExecutionDone(false);
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
@ -117,6 +119,46 @@ void BaseThread::setRunningStatus(bool value) {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] uniqueID [%s]\n",__FILE__,__FUNCTION__,__LINE__,uniqueID.c_str());
}
void BaseThread::setExecutingTask(bool value) {
MutexSafeWrapper safeMutex(&mutexExecutingTask);
executingTask = value;
safeMutex.ReleaseLock();
}
bool BaseThread::getExecutingTask() {
bool retval = false;
MutexSafeWrapper safeMutex(&mutexExecutingTask);
retval = executingTask;
safeMutex.ReleaseLock();
return retval;
}
bool BaseThread::getDeleteSelfOnExecutionDone() {
bool retval = false;
MutexSafeWrapper safeMutex(&mutexDeleteSelfOnExecutionDone);
retval = deleteSelfOnExecutionDone;
safeMutex.ReleaseLock();
return retval;
}
void BaseThread::setDeleteSelfOnExecutionDone(bool value) {
MutexSafeWrapper safeMutex(&mutexDeleteSelfOnExecutionDone);
deleteSelfOnExecutionDone = value;
}
void BaseThread::deleteSelfIfRequired() {
if(getDeleteSelfOnExecutionDone() == true) {
delete this;
return;
}
}
bool BaseThread::canShutdown(bool deleteSelfIfShutdownDelayed) {
return true;
}
bool BaseThread::shutdownAndWait(BaseThread *pThread) {
bool ret = false;
if(pThread != NULL) {

View File

@ -26,50 +26,54 @@ FileCRCPreCacheThread::FileCRCPreCacheThread() : BaseThread() {
}
void FileCRCPreCacheThread::execute() {
RunningStatusSafeWrapper runningStatus(this);
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
{
RunningStatusSafeWrapper runningStatus(this);
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
if(getQuitStatus() == true) {
return;
}
if(getQuitStatus() == true) {
deleteSelfIfRequired();
return;
}
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"FILE CRC PreCache thread is running\n");
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"FILE CRC PreCache thread is running\n");
try {
//tech Tree listBox
vector<string> techPaths;
findDirs(techDataPaths, techPaths);
if(techPaths.empty() == false) {
for(unsigned int idx = 0; idx < techPaths.size(); idx++) {
string techName = techPaths[idx];
try {
//tech Tree listBox
vector<string> techPaths;
findDirs(techDataPaths, techPaths);
if(techPaths.empty() == false) {
for(unsigned int idx = 0; idx < techPaths.size(); idx++) {
string techName = techPaths[idx];
time_t elapsedTime = time(NULL);
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] caching CRC value for Tech [%s] [%d of %d]\n",__FILE__,__FUNCTION__,__LINE__,techName.c_str(),idx+1,(int)techPaths.size());
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] caching CRC value for Tech [%s] [%d of %d]\n",__FILE__,__FUNCTION__,__LINE__,techName.c_str(),idx+1,techPaths.size());
time_t elapsedTime = time(NULL);
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] caching CRC value for Tech [%s] [%d of %d]\n",__FILE__,__FUNCTION__,__LINE__,techName.c_str(),idx+1,(int)techPaths.size());
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] caching CRC value for Tech [%s] [%d of %d]\n",__FILE__,__FUNCTION__,__LINE__,techName.c_str(),idx+1,techPaths.size());
int32 techCRC = getFolderTreeContentsCheckSumRecursively(techDataPaths, string("/") + techName + string("/*"), ".xml", NULL);
int32 techCRC = getFolderTreeContentsCheckSumRecursively(techDataPaths, string("/") + techName + string("/*"), ".xml", NULL);
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] cached CRC value for Tech [%s] is [%d] [%d of %d] took %.3f seconds.\n",__FILE__,__FUNCTION__,__LINE__,techName.c_str(),techCRC,idx+1,(int)techPaths.size(),difftime(time(NULL),elapsedTime));
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] cached CRC value for Tech [%s] is [%d] [%d of %d] took %.3f seconds.\n",__FILE__,__FUNCTION__,__LINE__,techName.c_str(),techCRC,idx+1,techPaths.size(),difftime(time(NULL),elapsedTime));
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] cached CRC value for Tech [%s] is [%d] [%d of %d] took %.3f seconds.\n",__FILE__,__FUNCTION__,__LINE__,techName.c_str(),techCRC,idx+1,(int)techPaths.size(),difftime(time(NULL),elapsedTime));
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] cached CRC value for Tech [%s] is [%d] [%d of %d] took %.3f seconds.\n",__FILE__,__FUNCTION__,__LINE__,techName.c_str(),techCRC,idx+1,techPaths.size(),difftime(time(NULL),elapsedTime));
if(getQuitStatus() == true) {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
break;
}
sleep( 100 );
}
}
}
catch(const exception &ex) {
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
}
catch(...) {
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] UNKNOWN Error\n",__FILE__,__FUNCTION__,__LINE__);
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] unknown error\n",__FILE__,__FUNCTION__,__LINE__);
}
if(getQuitStatus() == true) {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
break;
}
sleep( 50 );
}
}
}
catch(const exception &ex) {
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
}
catch(...) {
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] UNKNOWN Error\n",__FILE__,__FUNCTION__,__LINE__);
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] unknown error\n",__FILE__,__FUNCTION__,__LINE__);
}
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] FILE CRC PreCache thread is exiting\n",__FILE__,__FUNCTION__,__LINE__);
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] FILE CRC PreCache thread is exiting\n",__FILE__,__FUNCTION__,__LINE__);
}
deleteSelfIfRequired();
}
SimpleTaskThread::SimpleTaskThread( SimpleTaskCallbackInterface *simpleTaskInterface,
@ -81,77 +85,79 @@ SimpleTaskThread::SimpleTaskThread( SimpleTaskCallbackInterface *simpleTaskInter
this->millisecsBetweenExecutions = millisecsBetweenExecutions;
this->needTaskSignal = needTaskSignal;
setTaskSignalled(false);
setExecutingTask(false);
}
bool SimpleTaskThread::canShutdown() {
return (getExecutingTask() == false);
bool SimpleTaskThread::canShutdown(bool deleteSelfIfShutdownDelayed) {
bool ret = (getExecutingTask() == false);
if(deleteSelfIfShutdownDelayed == true) {
setDeleteSelfOnExecutionDone(deleteSelfIfShutdownDelayed);
signalQuit();
}
return ret;
}
void SimpleTaskThread::execute() {
RunningStatusSafeWrapper runningStatus(this);
try {
if(getQuitStatus() == true) {
return;
}
{
RunningStatusSafeWrapper runningStatus(this);
try {
if(getQuitStatus() == true) {
return;
}
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] uniqueID [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->getUniqueID().c_str());
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] uniqueID [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->getUniqueID().c_str());
unsigned int idx = 0;
for(;this->simpleTaskInterface != NULL;) {
bool runTask = true;
if(needTaskSignal == true) {
runTask = getTaskSignalled();
if(runTask == true) {
setTaskSignalled(false);
}
}
unsigned int idx = 0;
for(;this->simpleTaskInterface != NULL;) {
bool runTask = true;
if(needTaskSignal == true) {
runTask = getTaskSignalled();
if(runTask == true) {
setTaskSignalled(false);
}
}
if(getQuitStatus() == true) {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] uniqueID [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->getUniqueID().c_str());
break;
}
else if(runTask == true) {
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] uniqueID [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->getUniqueID().c_str());
if(getQuitStatus() == false) {
try {
setExecutingTask(true);
this->simpleTaskInterface->simpleTask();
setExecutingTask(false);
}
catch(const exception &ex) {
setExecutingTask(false);
throw runtime_error(ex.what());
}
}
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] uniqueID [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->getUniqueID().c_str());
}
if(getQuitStatus() == true) {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] uniqueID [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->getUniqueID().c_str());
break;
}
else if(runTask == true) {
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] uniqueID [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->getUniqueID().c_str());
if(getQuitStatus() == false) {
ExecutingTaskSafeWrapper safeExecutingTaskMutex(this);
this->simpleTaskInterface->simpleTask(this);
}
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] uniqueID [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->getUniqueID().c_str());
}
if(this->executionCount > 0) {
idx++;
if(idx >= this->executionCount) {
break;
}
}
if(getQuitStatus() == true) {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] uniqueID [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->getUniqueID().c_str());
break;
}
if(this->executionCount > 0) {
idx++;
if(idx >= this->executionCount) {
break;
}
}
if(getQuitStatus() == true) {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] uniqueID [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->getUniqueID().c_str());
break;
}
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] uniqueID [%s] millisecsBetweenExecutions = %d\n",__FILE__,__FUNCTION__,__LINE__,this->getUniqueID().c_str(),millisecsBetweenExecutions);
sleep(this->millisecsBetweenExecutions);
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] uniqueID [%s] millisecsBetweenExecutions = %d\n",__FILE__,__FUNCTION__,__LINE__,this->getUniqueID().c_str(),millisecsBetweenExecutions);
}
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] uniqueID [%s] millisecsBetweenExecutions = %d\n",__FILE__,__FUNCTION__,__LINE__,this->getUniqueID().c_str(),millisecsBetweenExecutions);
sleep(this->millisecsBetweenExecutions);
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] uniqueID [%s] millisecsBetweenExecutions = %d\n",__FILE__,__FUNCTION__,__LINE__,this->getUniqueID().c_str(),millisecsBetweenExecutions);
}
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] uniqueID [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->getUniqueID().c_str());
}
catch(const exception &ex) {
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] uniqueID [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->getUniqueID().c_str());
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] uniqueID [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->getUniqueID().c_str());
}
catch(const exception &ex) {
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] uniqueID [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->getUniqueID().c_str());
throw runtime_error(ex.what());
}
throw runtime_error(ex.what());
}
}
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] uniqueID [%s] END\n",__FILE__,__FUNCTION__,__LINE__,this->getUniqueID().c_str());
deleteSelfIfRequired();
}
void SimpleTaskThread::setTaskSignalled(bool value) {
@ -177,21 +183,6 @@ bool SimpleTaskThread::getTaskSignalled() {
return retval;
}
void SimpleTaskThread::setExecutingTask(bool value) {
MutexSafeWrapper safeMutex(&mutexExecutingTask);
executingTask = value;
safeMutex.ReleaseLock();
}
bool SimpleTaskThread::getExecutingTask() {
bool retval = false;
MutexSafeWrapper safeMutex(&mutexExecutingTask);
retval = executingTask;
safeMutex.ReleaseLock();
return retval;
}
// -------------------------------------------------
LogFileThread::LogFileThread() : BaseThread() {
@ -223,41 +214,45 @@ bool LogFileThread::checkSaveCurrentLogBufferToDisk() {
}
void LogFileThread::execute() {
RunningStatusSafeWrapper runningStatus(this);
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
{
RunningStatusSafeWrapper runningStatus(this);
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
if(getQuitStatus() == true) {
return;
}
if(getQuitStatus() == true) {
deleteSelfIfRequired();
return;
}
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"LogFile thread is running\n");
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"LogFile thread is running\n");
try {
for(;this->getQuitStatus() == false;) {
if(checkSaveCurrentLogBufferToDisk() == true) {
saveToDisk(false,false);
try {
for(;this->getQuitStatus() == false;) {
if(checkSaveCurrentLogBufferToDisk() == true) {
saveToDisk(false,false);
}
if(this->getQuitStatus() == false) {
sleep(50);
}
}
if(this->getQuitStatus() == false) {
sleep(50);
}
}
// Ensure remaining entryies are logged to disk on shutdown
saveToDisk(true,false);
}
catch(const exception &ex) {
//SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
}
catch(...) {
//SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] UNKNOWN Error\n",__FILE__,__FUNCTION__,__LINE__);
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] unknown error\n",__FILE__,__FUNCTION__,__LINE__);
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] UNKNOWN Error\n",__FILE__,__FUNCTION__,__LINE__);
}
// Ensure remaining entryies are logged to disk on shutdown
saveToDisk(true,false);
}
catch(const exception &ex) {
//SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
}
catch(...) {
//SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] UNKNOWN Error\n",__FILE__,__FUNCTION__,__LINE__);
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] unknown error\n",__FILE__,__FUNCTION__,__LINE__);
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] UNKNOWN Error\n",__FILE__,__FUNCTION__,__LINE__);
}
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] LogFile thread is exiting\n",__FILE__,__FUNCTION__,__LINE__);
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] LogFile thread is exiting\n",__FILE__,__FUNCTION__,__LINE__);
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] LogFile thread is exiting\n",__FILE__,__FUNCTION__,__LINE__);
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] LogFile thread is exiting\n",__FILE__,__FUNCTION__,__LINE__);
}
deleteSelfIfRequired();
}
std::size_t LogFileThread::getLogEntryBufferCount() {

View File

@ -787,7 +787,7 @@ float Socket::getThreadedPingMS(std::string host) {
return result;
}
void Socket::simpleTask() {
void Socket::simpleTask(BaseThread *callingThread) {
// update ping times every x seconds
const int pingFrequencySeconds = 2;
if(difftime(time(NULL),lastThreadedPing) < pingFrequencySeconds) {