diff -r f345bda72bc4 -r 43e37759235e Symbian3/Examples/guid-6013a680-57f9-415b-8851-c4fa63356636/threadaoengine_8cpp_source.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Symbian3/Examples/guid-6013a680-57f9-415b-8851-c4fa63356636/threadaoengine_8cpp_source.html Tue Mar 30 16:16:55 2010 +0100 @@ -0,0 +1,179 @@ + + +
+ +00001 /* +00002 * Copyright © 2008 Nokia Corporation. +00003 */ +00004 +00005 +00006 // INCLUDES +00007 #include <e32base.h> +00008 #include <aknnotewrappers.h> +00009 +00010 #include "..\inc\threadaoengine.h" +00011 #include "SharedIntermediator.h" +00012 #include "BluetoothRefreshTimer.h" +00013 #include "Devicelistcontainer.h" +00014 +00015 // CONSTANTS +00016 _LIT( KThreadOneName, "thread1" ); +00017 const TInt KStackSize = 4096; +00018 +00019 // ---------------------------------------------------------------------------- +00020 // CThreadAOEngine::CThreadAOEngine(CSharedIntermediator* aSMediator) +00021 // +00022 // Constructor. +00023 // ---------------------------------------------------------------------------- +00024 CThreadAOEngine::CThreadAOEngine( CSharedIntermediator* aSMediator ) : +00025 iCreatedThreads(EFalse), +00026 iSMediator(aSMediator), iListener(0) +00027 { +00028 } +00029 +00030 // ---------------------------------------------------------------------------- +00031 // CThreadAOEngine::~CThreadAOEngine() +00032 // +00033 // Destructor. +00034 // ---------------------------------------------------------------------------- +00035 CThreadAOEngine::~CThreadAOEngine() +00036 { +00037 // Thread should be killed allready, if thread is already killed this does +00038 // nothing +00039 iThreadOne.Kill(KErrNone); +00040 // Handles should be closed +00041 iThreadOne.Close(); +00042 +00043 delete iListener; +00044 } +00045 +00046 CThreadAOEngine* CThreadAOEngine::NewL(CSharedIntermediator* aSMediator) +00047 { +00048 CThreadAOEngine* self = CThreadAOEngine::NewLC(aSMediator); +00049 CleanupStack::Pop(self); +00050 return self; +00051 } +00052 +00053 CThreadAOEngine* CThreadAOEngine::NewLC(CSharedIntermediator* aSMediator) +00054 { +00055 CThreadAOEngine* self = new (ELeave) CThreadAOEngine(aSMediator); +00056 CleanupStack::PushL(self); +00057 self->ConstructL(); +00058 return self; +00059 } +00060 +00061 // Standard Symbian OS 2nd phase constructor +00062 void CThreadAOEngine::ConstructL() +00063 { +00064 } +00065 +00066 // ---------------------------------------------------------------------------- +00067 // CThreadAOEngine::StartL() +00068 // +00069 // Create a new thread (= thread1). +00070 // ---------------------------------------------------------------------------- +00071 void CThreadAOEngine::StartL() +00072 { +00073 +00074 // Create threads only once +00075 if ( iCreatedThreads == false ) +00076 { +00077 CreateThreadsL(); +00078 } +00079 } +00080 +00081 // ---------------------------------------------------------------------------- +00082 // CThreadAOEngine::Stop() +00083 // +00084 // Stop thread1. Stop thread1 ActiveScheduler. +00085 // ---------------------------------------------------------------------------- +00086 void CThreadAOEngine::Stop() +00087 { +00088 // Notify that the BT search should be cancelled. +00089 iSMediator->SetStopSearching(ETrue); +00090 } +00091 +00092 // ---------------------------------------------------------------------------- +00093 // CThreadAOEngine::ExecuteThread(TAny *aPtr) +00094 // +00095 // Threadfunction of threadOne. Executed only by threadOne. +00096 // ---------------------------------------------------------------------------- +00097 TInt CThreadAOEngine::ExecuteThreadOne(TAny *aPtr) +00098 { +00099 CSharedIntermediator* sharedMediator = +00100 static_cast<CSharedIntermediator*>( aPtr ); +00101 +00102 // Create cleanupstack +00103 CTrapCleanup* cleanupStack = CTrapCleanup::New(); +00104 +00105 // Test cleanup stack, additional cleanup stack must be prosessed under TRAP +00106 // We can't use low level cleanup stack handling +00107 TRAPD( error, CThreadAOEngine::CreateActiveSchedulerL( sharedMediator ) ) +00108 +00109 delete cleanupStack; +00110 +00111 return 0; +00112 } +00113 +00114 +00115 // ---------------------------------------------------------------------------- +00116 // CThreadAOEngine::CreateActiveScheduler(CSharedIntermediator* aSMediator) +00117 // +00118 // Create ActiveScheduler for thread1. +00119 // ---------------------------------------------------------------------------- +00120 void CThreadAOEngine::CreateActiveSchedulerL(CSharedIntermediator* aSMediator) +00121 { +00122 // create a new active scheduler +00123 CActiveScheduler* activeScheduler = new (ELeave) CActiveScheduler; +00124 CleanupStack::PushL(activeScheduler); +00125 +00126 // use static function Install to install previously created scheduler +00127 CActiveScheduler::Install(activeScheduler); +00128 +00129 CActiveSchedulerWait* wait = new (ELeave) CActiveSchedulerWait; +00130 CleanupStack::PushL(wait); +00131 +00132 CBluetoothRefreshTimer* timer = CBluetoothRefreshTimer::NewL( +00133 aSMediator, wait ); +00134 CleanupStack::PushL(timer); +00135 +00136 CActiveScheduler::Add(timer); +00137 +00138 // Scheduler must have one outstanding request before it can be started. +00139 timer->StartL(); +00140 wait->Start(); +00141 +00142 // Remove and delete scheduler and the rest. +00143 CleanupStack::PopAndDestroy(3); +00144 } +00145 +00146 +00147 // ---------------------------------------------------------------------------- +00148 // CThreadAOEngine::CreateThreadsL() +00149 // +00150 // Create thread1 and resume it. Activate thread1 listener. +00151 // ---------------------------------------------------------------------------- +00152 void CThreadAOEngine::CreateThreadsL() +00153 { +00154 // Create thread which uses the same heap as main program. +00155 iThreadOne.Create( KThreadOneName, ExecuteThreadOne, KStackSize, NULL, iSMediator); +00156 iThreadOne.Resume(); +00157 +00158 // Listen to thread1 state. +00159 iListener = CThreadListener::NewL(iThreadOne); +00160 +00161 iCreatedThreads = ETrue; +00162 } +00163 +