diff -r c40eb8fe8501 -r 6524e815f76f wlan_bearer/wlanengine/wlan_symbian/wlanengine_symbian_3.1/src/wlanbgscanawscomms.cpp --- a/wlan_bearer/wlanengine/wlan_symbian/wlanengine_symbian_3.1/src/wlanbgscanawscomms.cpp Tue Feb 02 02:03:13 2010 +0200 +++ b/wlan_bearer/wlanengine/wlan_symbian/wlanengine_symbian_3.1/src/wlanbgscanawscomms.cpp Sat Feb 20 00:38:18 2010 +0200 @@ -16,13 +16,15 @@ */ /* -* %version: 2 % +* %version: 3 % */ #include -#include +#include +#include #include "awsinterface.h" +#include "wlanbgscanawscommsinterface.h" #include "awsenginebase.h" #include "wlanbgscancommandlistener.h" #include "wlanbgscancommand.h" @@ -45,6 +47,12 @@ */ const TInt KFirstItemIndex = 0; +MWlanBgScanAwsComms* CWlanBgScanAwsCommsFactory::InstanceL( CWlanBgScan& aBgScan ) + { + DEBUG( "CWlanBgScanAwsCommsFactory::Instance()" ); + return CWlanBgScanAwsComms::NewL( aBgScan ); + } + // ======== MEMBER FUNCTIONS ======== // --------------------------------------------------------------------------- @@ -55,7 +63,7 @@ CActive( CActive::EPriorityStandard ), iBgScan( aBgScan ), iAws( NULL ), - iAwsImplInfo( NULL ), + iAwsImplUid( 0 ), iCommandHandler( NULL ), iAwsVersion( 0 ), iPendingCommand( EAwsCommandMax ), @@ -65,22 +73,23 @@ } // --------------------------------------------------------------------------- -// CWlanBgScanAwsComms::ConstructL +// CWlanBgScanAwsComms::~CWlanBgScanAwsComms() // --------------------------------------------------------------------------- // -void CWlanBgScanAwsComms::ConstructL() +CWlanBgScanAwsComms::~CWlanBgScanAwsComms() { - DEBUG( "CWlanBgScanAwsComms::ConstructL()" ); + DEBUG( "CWlanBgScanAwsComms::~CWlanBgScanAwsComms()" ); + + delete iAws; + iAws = NULL; - // create handler for incoming messages from AWS - iCommandHandler = CWlanBgScanCommand::NewL( *this ); - - CActiveScheduler::Add( this ); + delete iCommandHandler; + iCommandHandler = NULL; - // leaves if no AWS present in system - StartAwsThreadL(); - - DEBUG( "CWlanBgScanAwsComms::ConstructL() - done" ); + iAwsMsgQueue.Close(); + Cancel(); + iWlanEngineThread.Close(); + //iStartupLock.Close(); } // --------------------------------------------------------------------------- @@ -98,24 +107,35 @@ } // --------------------------------------------------------------------------- -// CWlanBgScanAwsComms::~CWlanBgScanAwsComms() +// CWlanBgScanAwsComms::ConstructL // --------------------------------------------------------------------------- // -CWlanBgScanAwsComms::~CWlanBgScanAwsComms() +void CWlanBgScanAwsComms::ConstructL() { - DEBUG( "CWlanBgScanAwsComms::~CWlanBgScanAwsComms()" ); - - delete iAws; - iAws = NULL; - - delete iAwsImplInfo; - iAwsImplInfo = NULL; - - delete iCommandHandler; - iCommandHandler = NULL; - - iAwsMsgQueue.Close(); - Cancel(); + DEBUG( "CWlanBgScanAwsComms::ConstructL()" ); + + // Get handle to current (WLAN Engine) thread so that + // the handle can be later used for completing the + // request status from AWS thread. + TThreadId id = RThread().Id(); + TInt err = iWlanEngineThread.Open( id ); + if( err != KErrNone ) + { + DEBUG( "CWlanBgScanAwsComms::ConstructL() - Opening own thread handle failed" ); + User::Leave( KErrBadHandle ); + } + + // create handler for incoming messages from AWS + iCommandHandler = CWlanBgScanCommand::NewL( *this ); + + CActiveScheduler::Add( this ); + + DEBUG( "CWlanBgScanAwsComms::ConstructL() - Starting AWS thread" ); + + // leaves if no AWS present in system + StartAwsThreadL(); + + DEBUG( "CWlanBgScanAwsComms::ConstructL() - done" ); } // --------------------------------------------------------------------------- @@ -135,6 +155,8 @@ // --------------------------------------------------------------------------- // CWlanBgScanAwsComms::StartAwsThreadL +// +// This method is executing in the context of the WLAN Engine thread. // --------------------------------------------------------------------------- // void CWlanBgScanAwsComms::StartAwsThreadL() @@ -154,28 +176,48 @@ } // first found AWS implementation will be taken into use - iAwsImplInfo = static_cast( awsImplArray[KFirstItemIndex] ); - awsImplArray.Remove( KFirstItemIndex ); + CImplementationInformation* awsImplInfo = static_cast( awsImplArray[KFirstItemIndex] ); + iAwsImplUid = awsImplInfo->ImplementationUid().iUid; + + DEBUG( "CWlanBgScanAwsComms::InstantiateAwsPluginL() - trying to instantiate AWS implementation:" ); + DEBUG1( "CWlanBgScanAwsComms::InstantiateAwsPluginL() - ImplementationUid: 0x%08X", awsImplInfo->ImplementationUid().iUid ); +#ifdef _DEBUG + TBuf8 buf8; + buf8.Copy( awsImplInfo->DisplayName() ); +#endif + DEBUG1S( "CWlanBgScanAwsComms::InstantiateAwsPluginL() - DisplayName: ", buf8.Length(), buf8.Ptr() ); + DEBUG1( "CWlanBgScanAwsComms::InstantiateAwsPluginL() - Version: %i", awsImplInfo->Version() ); + DEBUG1S( "CWlanBgScanAwsComms::InstantiateAwsPluginL() - DataType: ", awsImplInfo->DataType().Length(), awsImplInfo->DataType().Ptr() ); + DEBUG1S( "CWlanBgScanAwsComms::InstantiateAwsPluginL() - OpaqueData: ", awsImplInfo->OpaqueData().Length(), awsImplInfo->OpaqueData().Ptr() ); + DEBUG1( "CWlanBgScanAwsComms::InstantiateAwsPluginL() - RomOnly: %i", awsImplInfo->RomOnly() ); + DEBUG1( "CWlanBgScanAwsComms::InstantiateAwsPluginL() - RomBased: %i", awsImplInfo->RomBased() ); + DEBUG1( "CWlanBgScanAwsComms::InstantiateAwsPluginL() - VendorId: 0x%08X", awsImplInfo->VendorId().iId ); + + DEBUG( "CWlanBgScanAwsComms::StartAwsThreadL() - setting request status to pending" ); + iStatus = KRequestPending; + DEBUG( "CWlanBgScanAwsComms::StartAwsThreadL() - setting pending command to EAwsStartupCompleted" ); + iPendingCommand = EAwsStartupCompleted; + DEBUG( "CWlanBgScanAwsComms::StartAwsThreadL() - setting ao active" ); + SetActive(); - CleanupStack::PopAndDestroy( &awsImplArray ); //this causes a call to CleanupEComArray - DEBUG( "CWlanBgScanAwsComms::StartAwsThreadL() - creating AWS thread" ); RThread thread; - TInt err = thread.Create( iAwsImplInfo->DisplayName(), + TInt err = thread.Create( awsImplInfo->DisplayName(), AwsThreadEntryPoint, KDefaultStackSize, KMinHeapSize, KMaxHeapSize, reinterpret_cast( this ) ); + + CleanupStack::PopAndDestroy( &awsImplArray ); //this causes a call to CleanupEComArray + if( err != KErrNone) { DEBUG1( "CWlanBgScanAwsComms::StartAwsThreadL() - error: thread creation failed with error %i", err ); - delete iAwsImplInfo; - iAwsImplInfo = NULL; User::Leave( err ); } - DEBUG( "CWlanBgScanAwsComms::StartAwsThreadL() - Resuming AWS thread" ); + DEBUG( "CWlanBgScanAwsComms::StartAwsThreadL() - resuming AWS thread" ); thread.Resume(); thread.Close(); @@ -190,7 +232,7 @@ // TInt CWlanBgScanAwsComms::AwsThreadEntryPoint( TAny* aThisPtr ) { - DEBUG("CWlanBgScanAwsComms::AwsThreadEntryPoint()"); + DEBUG( "CWlanBgScanAwsComms::AwsThreadEntryPoint()" ); CWlanBgScanAwsComms* self = static_cast( aThisPtr ); @@ -204,71 +246,59 @@ __UHEAP_MARK; - TRAPD( err, self->InstantiateAwsPluginL() ); + TRAPD( err, self->InstantiateAndRunAwsPluginL() ); if ( err != KErrNone ) { - DEBUG1("CWlanBgScanAwsComms::AwsThreadEntryPoint() - AWS instantiation leaved with code %i", err); + DEBUG1( "CWlanBgScanAwsComms::AwsThreadEntryPoint() - error: AWS instantiation leaved, completing request to WLAN Engine thread with code %i", err ); + TRequestStatus *status = &self->iStatus; + self->iWlanEngineThread.RequestComplete( status, err ); } - + __UHEAP_MARKEND; delete cleanup; cleanup = NULL; + DEBUG( "CWlanBgScanAwsComms::AwsThreadEntryPoint() - AWS thread exiting" ); return KErrNone; } // ----------------------------------------------------------------------------- -// CWlanBgScanAwsComms::InstantiateAwsPluginL +// CWlanBgScanAwsComms::InstantiateAndRunAwsPluginL // // This method is executing in the context of the AWS thread. // ----------------------------------------------------------------------------- // -void CWlanBgScanAwsComms::InstantiateAwsPluginL() +void CWlanBgScanAwsComms::InstantiateAndRunAwsPluginL() { - DEBUG("CWlanBgScanAwsComms::InstantiateAwsPluginL()"); - - ASSERT( iAwsImplInfo ); + DEBUG( "CWlanBgScanAwsComms::InstantiateAndRunAwsPluginL()" ); CActiveScheduler* scheduler = new (ELeave) CActiveScheduler(); CleanupStack::PushL( scheduler ); CActiveScheduler::Install( scheduler ); - DEBUG( "CWlanBgScanAwsComms::InstantiateAwsPluginL() - trying to instantiate AWS implementation:" ); - DEBUG1( "CWlanBgScanAwsComms::InstantiateAwsPluginL() - ImplementationUid: 0x%08X", iAwsImplInfo->ImplementationUid().iUid ); -#ifdef _DEBUG - TBuf8 buf8; - buf8.Copy( iAwsImplInfo->DisplayName() ); -#endif - DEBUG1S("CWlanBgScanAwsComms::InstantiateAwsPluginL() - DisplayName: ", buf8.Length(), buf8.Ptr() ); - DEBUG1( "CWlanBgScanAwsComms::InstantiateAwsPluginL() - Version: %i", iAwsImplInfo->Version() ); - DEBUG1S("CWlanBgScanAwsComms::InstantiateAwsPluginL() - DataType: ", iAwsImplInfo->DataType().Length(), iAwsImplInfo->DataType().Ptr() ); - DEBUG1S("CWlanBgScanAwsComms::InstantiateAwsPluginL() - OpaqueData: ", iAwsImplInfo->OpaqueData().Length(), iAwsImplInfo->OpaqueData().Ptr() ); - DEBUG1( "CWlanBgScanAwsComms::InstantiateAwsPluginL() - RomOnly: %i", iAwsImplInfo->RomOnly() ); - DEBUG1( "CWlanBgScanAwsComms::InstantiateAwsPluginL() - RomBased: %i", iAwsImplInfo->RomBased() ); - DEBUG1( "CWlanBgScanAwsComms::InstantiateAwsPluginL() - VendorId: 0x%08X", iAwsImplInfo->VendorId().iId ); + DEBUG( "CWlanBgScanAwsComms::InstantiateAndRunAwsPluginL() - active scheduler installed" ); + CAwsEngineBase::TAwsEngineConstructionParameters params = { this, KBgScanVersion, iAwsVersion }; + + TRequestStatus *status = &iStatus; - CAwsEngineBase::TAwsEngineConstructionParameters params = { this, KBgScanVersion, iAwsVersion }; - iAws = CAwsEngineBase::NewL( iAwsImplInfo->ImplementationUid().iUid, ¶ms ); + DEBUG( "CWlanBgScanAwsComms::InstantiateAndRunAwsPluginL() - calling CAwsEngineBase::NewL()" ); + iAws = CAwsEngineBase::NewL( iAwsImplUid, ¶ms ); // iAws deallocated in destructor + + DEBUG1( "CWlanBgScanAwsComms::InstantiateAndRunAwsPluginL() - AWS version %u instantiated", iAwsVersion ); - DEBUG1( "CWlanBgScanAwsComms::InstantiateAwsPluginL() - AWS instantiated OK, iAwsVersion %u", iAwsVersion ); - iAwsOk = ETrue; - - __e32_memory_barrier(); - DEBUG( "CWlanBgScanAwsComms::InstantiateAwsPluginL() - data members synchronized" ); + DEBUG( "CWlanBgScanAwsComms::InstantiateAndRunAwsPluginL() - completing request to WLAN Engine thread" ); + iWlanEngineThread.RequestComplete( status, KErrNone ); - DEBUG( "CWlanBgScanAwsComms::InstantiateAwsPluginL() - starting active scheduler - AWS is now in control of this thread" ); + DEBUG( "CWlanBgScanAwsComms::InstantiateAndRunAwsPluginL() - starting active scheduler - AWS is now in control of this thread" ); CActiveScheduler::Start(); // Thread execution will stay in CActiveScheduler::Start() until active scheduler is stopped - DEBUG("CWlanBgScanAwsComms::InstantiateAwsPluginL() - active scheduler stopped" ); - + DEBUG("CWlanBgScanAwsComms::InstantiateAndRunAwsPluginL() - active scheduler stopped" ); + // clean up - delete iAws; - iAws = NULL; CleanupStack::PopAndDestroy( scheduler ); - DEBUG( "CWlanBgScanAwsComms::InstantiateAwsPluginL() - exiting..." ); - User::Exit( KErrNone ); + DEBUG( "CWlanBgScanAwsComms::InstantiateAndRunAwsPluginL() - done" ); } // --------------------------------------------------------------------------- @@ -289,6 +319,8 @@ // --------------------------------------------------------------------------- // CWlanBgScanAwsComms::SendOrQueueAwsCommand +// +// This method is executing in the context of the WLAN Engine thread. // --------------------------------------------------------------------------- // void CWlanBgScanAwsComms::SendOrQueueAwsCommand( TAwsMessage& aMessage ) @@ -320,6 +352,8 @@ // --------------------------------------------------------------------------- // CWlanBgScanAwsComms::SendAwsCommand +// +// This method is executing in the context of the WLAN Engine thread. // --------------------------------------------------------------------------- // void CWlanBgScanAwsComms::SendAwsCommand( TAwsMessage& aMessage ) @@ -373,12 +407,30 @@ // --------------------------------------------------------------------------- // CWlanBgScanAwsComms::RunL +// +// This method is executing in the context of the WLAN Engine thread. // --------------------------------------------------------------------------- // void CWlanBgScanAwsComms::RunL() { DEBUG2( "CWlanBgScanAwsComms::RunL() - command: %u, completion status: %d", iPendingCommand, iStatus.Int() ); + switch ( iPendingCommand ) + { + case EAwsStartupCompleted: + { + DEBUG( "CWlanBgScanAwsComms::RunL() - AWS startup has been completed" ); + iBgScan.AwsStartupComplete( iStatus.Int() ); + break; + } + default: + { + DEBUG( "CWlanBgScanAwsComms::RunL() - AWS command has been completed" ); + iBgScan.AwsCommandComplete( iPendingCommand, iStatus.Int() ); + break; + } + } + TAwsMessage cmd = { EAwsCommandMax, NULL }; // if there are more commands, send the next one @@ -421,13 +473,3 @@ iBgScan.DoSetInterval( aNewInterval ); } -// --------------------------------------------------------------------------- -// CWlanBgScanAwsComms::IsAwsPresent -// --------------------------------------------------------------------------- -// -TBool CWlanBgScanAwsComms::IsAwsPresent() - { - DEBUG1( "CWlanBgScanAwsComms::IsAwsPresent() - returning %d", iAwsOk ); - - return iAwsOk; - }