[Gdal-dev] GDAL, ECW, and COM

Chapman, Martin MChapman at sanz.com
Fri Apr 1 19:16:37 EST 2005


And one more thing:

To create it:

for (int i = 0; i < m_nIndex; i++)
			{
				CParseServer* pParseServer = ::new
CParseServer();
				
				pParseServer->m_nIdleTime =
ParseServers.GetIdleTime(i);
				pParseServer->m_nMailServerPort =
ParseServers.GetMailServerPort(i);
				pParseServer->m_nProcessMax =
ParseServers.GetProcessMax(i);
				pParseServer->m_sEmailFrom =
ParseServers.GetEmailFrom(i);
				pParseServer->m_sEmailSubject =
ParseServers.GetEmailSubject(i);
				pParseServer->m_sEmailTo =
ParseServers.GetEmailTo(i);
				pParseServer->m_sMailServerHost =
ParseServers.GetMailServerHost(i);
				pParseServer->m_sMailServerPassword =
ParseServers.GetMailServerPassword(i);
				pParseServer->m_sMailServerProfile =
ParseServers.GetMailServerProfile(i);

				m_vThreads.push_back(CreateThread(NULL,
0, (LPTHREAD_START_ROUTINE)&ThreadProc, (LPVOID)pParseServer, 0,
&dwThreadId));
			}

And to destroy it:

HRESULT CParseMonitorModule::PostMessageLoop()
{
	try
	{
		DWORD dwResult;
		CParseProcessor::m_bRunning = false;
		vector<HANDLE>::iterator Iter;

		for (Iter = m_vThreads.begin(); true; Iter++)
		{
			if ((dwResult = WaitForMultipleObjects((DWORD)
m_vThreads.size(), 
				&m_vThreads[0], TRUE, 20000)) ==
WAIT_OBJECT_0)
				break;
			else if((dwResult == WAIT_FAILED) || (dwResult
== WAIT_ABANDONED))
				this->LogEvent("WaitForMultipleObjects
Failed");
			else
			this->SetServiceStatus(SERVICE_STOP_PENDING);
		}

		for (Iter = m_vThreads.begin(); Iter !=
m_vThreads.end(); Iter++)
			CloseHandle(*Iter);
	}
	catch(...)
	{
		this->LogEvent(_T("An unexpected error occurred in
PostMessageLoop"));
	}

	return __super::PostMessageLoop();
}

Martin

-----Original Message-----
From: gdal-dev-bounces at xserve.flids.com
[mailto:gdal-dev-bounces at xserve.flids.com] On Behalf Of Frank Warmerdam
Sent: Friday, April 01, 2005 3:46 PM
To: Peng Gao
Cc: GDAL Dev
Subject: Re: [Gdal-dev] GDAL, ECW, and COM


On Apr 1, 2005 5:10 PM, Peng Gao <pgao at esri.com> wrote:
> I wrote a new GDAL dataset whose implementation uses some COM objects.

> When I do a CreateCopy() using my dataset as input, it works for most 
> formats except ECW. The error is that COM objects can not be cocreated

> because CoInitialize() is not called on the thread. The following is 
> the call stack (Windows) when the error occurred. It looks like a 
> different thread from the main thread where GDALDriver::CreateCopy() 
> is invoked.
> 
> If this is true, can the compressor thread be enclosed in 
> CoInitialize() and CoUninitialize()?

Peng,

I'm am not too savvy on COM or multi-threading issues, so you may need
to spell a few things out for me. 

First, my understanding is that the ECW driver is multi-threaded, and 
uses seperate working threads when compressing.  Furthermore, these
worker threads end up "calling back" to get the data source the source
dataset.  So the IO calls on the source file will happen in a thread
other than the main one used for GDAL. 

I gather it is this being called from a different thread that is causing
you problems? 

>From the GDAL level I don't really have any access inside the ECW
compressor thread except for in the callback.  I suppose I could add
something to do a coinitialize in there on the first callback, but it 
really seems like this is an issue with the COM based driver.  Couldn't
it do a CoInitialize() internally in any function that gets called by a
new thread? 

Doing the uninitialize would be quite a bit tricker since there is no
easy way to know when the last call from the thread has been made.

Darn, I hate multi-threading.

Best regards,
-- 
---------------------------------------+--------------------------------
---------------------------------------+------
I set the clouds in motion - turn up   | Frank Warmerdam,
warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | Geospatial Programmer for Rent
_______________________________________________
Gdal-dev mailing list
Gdal-dev at xserve.flids.com
http://xserve.flids.com/mailman/listinfo/gdal-dev



More information about the Gdal-dev mailing list