Esempio n. 1
0
// ================================================
// Entity
// vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
EnvRegion::EnvRegion() : ExtendedDataSet()
{


	EnvRegionID = 0;
   CigiPos.LatX = 0.0;
   CigiPos.LonY = 0.0;
   CigiPos.AltZ = 0.0;
   CigiPos.Yaw = 0.0;
   CigiPos.Pitch = 0.0;
   CigiPos.Roll = 0.0;
   XSize = 0.0f;
   YSize = 0.0f;
   CornerRadius = 0.0f;
   Transition = 0.0f;
   RgnState = CigiBaseEnvRgnCtrl::Inactive;
   WeatherProp = CigiBaseEnvRgnCtrl::UseLast;
   Aerosol = CigiBaseEnvRgnCtrl::UseLast;
   MaritimeSurface = CigiBaseEnvRgnCtrl::UseLast;
   TerrestrialSurface = CigiBaseEnvRgnCtrl::UseLast;


   CreateExtendedData(ExtendedDataCount);


}
BOOL CSocketThreadManager::SpawnThreads(LPCSTR lpClassName)
{
	try
	{
		//Add to this class our thread ID, and a random number
		if (!lpClassName)
		{
			//Calculate our string
			int iStringLength;
			iStringLength=strlen(CSocketThreadManager_Class);

			//Add some size to it
			iStringLength+=50;

			//Allocate the string
			std::auto_ptr<char> pString(new char[iStringLength]);

			//Get our thread ID
			DWORD dwThreadID;
			dwThreadID=GetCurrentThreadId();

			//Get the tick of the system
			DWORD dwProcessID;
			dwProcessID=GetTickCount();
			
			//Create the string
			sprintf(pString.get(),"%s_%lu_%lu",CSocketThreadManager_Class,
											   GetCurrentThreadId(),
											   GetTickCount());

			//And register the window
			//Check if we need to register the class
			if (!m_bRegisteredWindow)
				if (!RegisterClass(pString.get()))
				{
					//Report it
					ReportError("SpawnThreads","Failed to register window!");

					//And quit
					return FALSE;
				}
		
			//Save the class name
			m_sClassName=pString.get();
		}
		else
			m_sClassName=lpClassName;

		//Start creating threads
		//Allocate the thread structure
		m_pThreadData=new ThreadData[m_ulThreadCount];

		//Initialize the data
		for (int iCount=0;iCount<m_ulThreadCount;++iCount)
		{
			m_pThreadData[iCount].bFreeze=FALSE;
			m_pThreadData[iCount].pEvent=NULL;
			m_pThreadData[iCount].hInstance=NULL;
			m_pThreadData[iCount].hWindowHandle=NULL;
			m_pThreadData[iCount].iSocketCount=0;
			m_pThreadData[iCount].iTimeoutCount=0;
			m_pThreadData[iCount].pThread=NULL;
			m_pThreadData[iCount].pCSection=COSManager::CreateCriticalSection();
			m_pThreadData[iCount].pClass=this;
		}

		//Did we have an error?
		BOOL bError;
		bError=FALSE;

		//Our waiting list
		CWaitList aList;

		//Start spawning
		for (int iCounter=0;
			 iCounter<m_ulThreadCount;
			 ++iCounter)
		{
			//Copy the class name
			m_pThreadData[iCounter].sClassName=m_sClassName;

			//Create an event
			m_pThreadData[iCounter].pEvent=COSManager::CreateEvent();

			//Add it to the list
			aList.AddObject(m_pThreadData[iCounter].pEvent,
							TRUE);

			//Set our instance
			m_pThreadData[iCounter].hInstance=m_hInstance;

			//Create extended data
			CreateExtendedData(m_pThreadData[iCounter].aExtension);

			//And create it
			m_pThreadData[iCounter].pThread=COSManager::CreateThread(SocketThread);
			
			//Check the thread has been created
			if (!m_pThreadData[iCounter].pThread->GetThreadID())
			{
				//Report the error
				ReportError("SpawnThreads","Failed to create thread!");

				//We have an error
				bError=TRUE;

				//Exit the loop
				break;
			}
			else
				//Start the thread
				m_pThreadData[iCounter].pThread->Start((LPVOID)&m_pThreadData[iCounter]);
		}

		//Tmp position
		DWORD dwTmp;

		if (aList.Wait(TRUE,
					   dwTmp,
					   THREADS_TIMEOUT))
		{
			//Report the error
			ReportError("SpawnThreads","Timeout waiting for threads!");

			//Close the threads
			CleanThreads(TRUE);

			//Exit
			return FALSE;
		}
		else if (bError)
		{
			//Close the threads
			CleanThreads(FALSE);

			//Exit
			return FALSE;
		}
		else
		{
			//We are OK
			m_bInitialized=TRUE;

			//Done
			return TRUE;
		}
	}
	ERROR_HANDLER_RETURN("SpawnThreads",FALSE)
}