void GameNetworkInterface::requestCommand(const NetworkCommand *networkCommand, bool insertAtStart) {
	assert(networkCommand != NULL);
	Mutex *mutex = getServerSynchAccessor();

    if(insertAtStart == false) {
    	MutexSafeWrapper safeMutex(mutex,string(__FILE__) + "_" + intToStr(__LINE__));
        requestedCommands.push_back(*networkCommand);
    }
    else {
    	MutexSafeWrapper safeMutex(mutex,string(__FILE__) + "_" + intToStr(__LINE__));
        requestedCommands.insert(requestedCommands.begin(),*networkCommand);
    }
}
void BaseThread::setExecutingTask(bool value) {
	static string mutexOwnerId = CODE_AT_LINE;
	MutexSafeWrapper safeMutex(mutexExecutingTask,mutexOwnerId);
	mutexExecutingTask->setOwnerId(mutexOwnerId);
	executingTask = value;
	safeMutex.ReleaseLock();
}
void BaseThread::setThreadOwnerValid(bool value) {
	static string mutexOwnerId = CODE_AT_LINE;
	MutexSafeWrapper safeMutex(mutexThreadOwnerValid,mutexOwnerId);
	mutexThreadOwnerValid->setOwnerId(mutexOwnerId);
	threadOwnerValid = value;
	safeMutex.ReleaseLock();
}
bool BaseThread::getDeleteSelfOnExecutionDone() {
    //bool retval = false;
    static string mutexOwnerId = CODE_AT_LINE;
    MutexSafeWrapper safeMutex(mutexDeleteSelfOnExecutionDone,mutexOwnerId);
    bool retval = deleteSelfOnExecutionDone;
    safeMutex.ReleaseLock();

    return retval;
}
bool BaseThread::getStarted() {
	static string mutexOwnerId = CODE_AT_LINE;
	MutexSafeWrapper safeMutex(mutexStarted,mutexOwnerId);
	mutexStarted->setOwnerId(mutexOwnerId);
	bool retval = started;
	safeMutex.ReleaseLock();

	return retval;
}
void NetworkInterface::clearHighlightedCellList() {
	static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
	MutexSafeWrapper safeMutex(networkAccessMutex,mutexOwnerId);

	if(highlightedCellList.empty() == false) {
		if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] markedCellList.size() = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,markedCellList.size());
		highlightedCellList.clear();
	}
}
bool BaseThread::getExecutingTask() {
	//bool retval = false;
	static string mutexOwnerId = CODE_AT_LINE;
	MutexSafeWrapper safeMutex(mutexExecutingTask,mutexOwnerId);
	bool retval = executingTask;
	safeMutex.ReleaseLock();

	return retval;
}
void BaseThread::setRunningStatus(bool value) {
	static string mutexOwnerId = CODE_AT_LINE;
	MutexSafeWrapper safeMutex(mutexRunning,mutexOwnerId);
	mutexRunning->setOwnerId(mutexOwnerId);
	running = value;
	if(value == true) {
		setHasBeginExecution(true);
	}
	safeMutex.ReleaseLock();
}
bool BaseThread::getHasBeginExecution() {
	//bool retval = false;
	static string mutexOwnerId = CODE_AT_LINE;
	MutexSafeWrapper safeMutex(mutexBeginExecution,mutexOwnerId);
	//mutexBeginExecution.setOwnerId(mutexOwnerId);
	bool retval = hasBeginExecution;
	safeMutex.ReleaseLock();

	return retval;
}
bool BaseThread::getThreadOwnerValid() {
	//bool ret = false;
	static string mutexOwnerId = CODE_AT_LINE;
	MutexSafeWrapper safeMutex(mutexThreadOwnerValid,mutexOwnerId);
	//mutexThreadOwnerValid.setOwnerId(mutexOwnerId);
	bool ret = threadOwnerValid;
	safeMutex.ReleaseLock();

	return ret;
}
bool BaseThread::getQuitStatus() {
	//bool retval = false;
	static string mutexOwnerId = CODE_AT_LINE;
	MutexSafeWrapper safeMutex(mutexQuit,mutexOwnerId);
	//mutexQuit.setOwnerId(mutexOwnerId);
	bool retval = quit;
	safeMutex.ReleaseLock();

	return retval;
}
void BaseThread::setHasBeginExecution(bool value) {
	if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] uniqueID [%s]\n",__FILE__,__FUNCTION__,__LINE__,uniqueID.c_str());

	static string mutexOwnerId = CODE_AT_LINE;
	MutexSafeWrapper safeMutex(mutexBeginExecution,mutexOwnerId);
	mutexBeginExecution->setOwnerId(mutexOwnerId);
	hasBeginExecution = value;
	safeMutex.ReleaseLock();

	if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] uniqueID [%s]\n",__FILE__,__FUNCTION__,__LINE__,uniqueID.c_str());
}
void NetworkInterface::setHighlightedCell(const MarkedCell &msg){
	static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
	MutexSafeWrapper safeMutex(networkAccessMutex,mutexOwnerId);

	for(int idx = 0; idx < (int)highlightedCellList.size(); idx++) {
		MarkedCell mc = highlightedCellList[idx];
		if(mc.getFactionIndex()==msg.getFactionIndex()){
			highlightedCellList.erase(highlightedCellList.begin()+ idx);
			break;
		}
	}
	highlightedCellList.push_back(msg);
}
bool BaseThread::getRunningStatus() {
	//bool retval = false;

	static string mutexOwnerId = CODE_AT_LINE;
	MutexSafeWrapper safeMutex(mutexRunning,mutexOwnerId);
	bool retval = running;
	safeMutex.ReleaseLock();

	if(retval == false) {
		retval = !getHasBeginExecution();
	}

	return retval;
}
std::vector<ChatMsgInfo> NetworkInterface::getChatTextList(bool clearList) {
	std::vector<ChatMsgInfo> result;

	static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
	MutexSafeWrapper safeMutex(networkAccessMutex,mutexOwnerId);

	if(chatTextList.empty() == false) {
		result = chatTextList;

		if(clearList == true) {
			chatTextList.clear();
		}
	}
	return result;
}
std::vector<MarkedCell> NetworkInterface::getHighlightedCellList(bool clearList) {
	std::vector<MarkedCell> result;

	static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
	MutexSafeWrapper safeMutex(networkAccessMutex,mutexOwnerId);

	if(highlightedCellList.empty() == false) {
		result = highlightedCellList;

		if(clearList == true) {
			highlightedCellList.clear();
		}
	}
	return result;
}
uint32 NetworkInterface::getNetworkPlayerFactionCRC(int index) {
	static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
	MutexSafeWrapper safeMutex(networkPlayerFactionCRCMutex,mutexOwnerId);

	return networkPlayerFactionCRC[index];
}
void NetworkInterface::setLastPingInfoToNow() {
	static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
	MutexSafeWrapper safeMutex(networkAccessMutex,mutexOwnerId);

	this->lastPingInfo.setPingReceivedLocalTime(time(NULL));
}
NetworkMessagePing NetworkInterface::getLastPingInfo() {
	static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
	MutexSafeWrapper safeMutex(networkAccessMutex,mutexOwnerId);

	return lastPingInfo;
}
void NetworkInterface::setLastPingInfo(const NetworkMessagePing &ping) {
	static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
	MutexSafeWrapper safeMutex(networkAccessMutex,mutexOwnerId);

	this->lastPingInfo = ping;
}
double NetworkInterface::getLastPingLag() {
	static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
	MutexSafeWrapper safeMutex(networkAccessMutex,mutexOwnerId);

	return difftime((long int)time(NULL),lastPingInfo.getPingReceivedLocalTime());
}
void NetworkInterface::setNetworkPlayerFactionCRC(int index, uint32 crc) {
	static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
	MutexSafeWrapper safeMutex(networkPlayerFactionCRCMutex,mutexOwnerId);

	networkPlayerFactionCRC[index]=crc;
}
void NetworkInterface::addChatInfo(const ChatMsgInfo &msg) {
	static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
	MutexSafeWrapper safeMutex(networkAccessMutex,mutexOwnerId);

	chatTextList.push_back(msg);
}
void BaseThread::setDeleteSelfOnExecutionDone(bool value) {
	static string mutexOwnerId = CODE_AT_LINE;
    MutexSafeWrapper safeMutex(mutexDeleteSelfOnExecutionDone,mutexOwnerId);
    mutexDeleteSelfOnExecutionDone->setOwnerId(mutexOwnerId);
    deleteSelfOnExecutionDone = value;
}
void NetworkInterface::addUnMarkedCell(const UnMarkedCell &msg) {
	static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
	MutexSafeWrapper safeMutex(networkAccessMutex,mutexOwnerId);

	unmarkedCellList.push_back(msg);
}