|         |      1 /* | 
|         |      2 * Copyright (c) 2006-2007 Nokia Corporation and/or its subsidiary(-ies). | 
|         |      3 * All rights reserved. | 
|         |      4 * This component and the accompanying materials are made available | 
|         |      5 * under the terms of "Eclipse Public License v1.0"" | 
|         |      6 * which accompanies this distribution, and is available | 
|         |      7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". | 
|         |      8 * | 
|         |      9 * Initial Contributors: | 
|         |     10 * Nokia Corporation - initial contribution. | 
|         |     11 * | 
|         |     12 * Contributors: | 
|         |     13 * | 
|         |     14 * Description:  Background thread functionality wrapper | 
|         |     15 * | 
|         |     16 */ | 
|         |     17  | 
|         |     18  | 
|         |     19  | 
|         |     20 #ifndef CFILEMANAGERTHREADWRAPPER_H | 
|         |     21 #define CFILEMANAGERTHREADWRAPPER_H | 
|         |     22  | 
|         |     23  | 
|         |     24 // INCLUDES | 
|         |     25 #include <e32base.h> | 
|         |     26 #include "MFileManagerThreadFunction.h" | 
|         |     27  | 
|         |     28  | 
|         |     29 // CLASS DECLARATION | 
|         |     30 /** | 
|         |     31 *  The class implements a background thread functionality wrapper | 
|         |     32 * | 
|         |     33 *  @lib FileManagerEngine.lib | 
|         |     34 *  @since 3.1 | 
|         |     35 */ | 
|         |     36 NONSHARABLE_CLASS(CFileManagerThreadWrapper) : public CActive | 
|         |     37     { | 
|         |     38     public: | 
|         |     39         static CFileManagerThreadWrapper* NewL(); | 
|         |     40  | 
|         |     41         ~CFileManagerThreadWrapper();         | 
|         |     42  | 
|         |     43     public: // New functions | 
|         |     44         /** | 
|         |     45         * Starts background thread. Can be used only by client thread. | 
|         |     46         * @since 3.1 | 
|         |     47         * @param aFunction Reference to background thread abstraction. | 
|         |     48         * @param aPriority background thread priority | 
|         |     49         * @param aNotify client notify flags | 
|         |     50         *        see MFileManagerThreadFunction::TNotifyType | 
|         |     51         * @return System wide error code | 
|         |     52         */ | 
|         |     53         TInt StartThread( | 
|         |     54             MFileManagerThreadFunction& aFunction, | 
|         |     55             TUint aNotify, | 
|         |     56             TThreadPriority aPriority ); | 
|         |     57  | 
|         |     58         /** | 
|         |     59         * Cancels background thread. | 
|         |     60         * Background thread is exited when ongoing ThreadStepL is finished. | 
|         |     61         * Can be used only by client thread. | 
|         |     62         * @since 3.1 | 
|         |     63         */ | 
|         |     64         void CancelThread(); | 
|         |     65  | 
|         |     66         /** | 
|         |     67         * Checks if background thread has been canceled. | 
|         |     68         * Can be used by both client and background threads. | 
|         |     69         * E.g. checks can be done inside long running ThreadStepL. | 
|         |     70         * @since 3.1 | 
|         |     71         * @return ETrue if canceled, otherwise EFalse | 
|         |     72         */ | 
|         |     73         TBool IsThreadCanceled() const; | 
|         |     74  | 
|         |     75         /** | 
|         |     76         * Resumes thread when called after error or step finished  | 
|         |     77         * notification. Can only be used by client thread. | 
|         |     78         * @since 3.2 | 
|         |     79         */ | 
|         |     80         void ResumeThread(); | 
|         |     81  | 
|         |     82         /** | 
|         |     83         * Checks if thread has been started | 
|         |     84         * notification. Can only be used by client thread. | 
|         |     85         * @since 3.2 | 
|         |     86         * @return ETrue if started, otherwise EFalse | 
|         |     87         */ | 
|         |     88         TBool IsThreadStarted() const; | 
|         |     89  | 
|         |     90     private: // From CActive | 
|         |     91         void RunL(); | 
|         |     92  | 
|         |     93         TInt RunError( TInt aErr ); | 
|         |     94  | 
|         |     95         void DoCancel(); | 
|         |     96  | 
|         |     97     private: | 
|         |     98         CFileManagerThreadWrapper(); | 
|         |     99  | 
|         |    100         void ConstructL(); | 
|         |    101  | 
|         |    102         static TInt ThreadFunction( TAny* ptr ); | 
|         |    103  | 
|         |    104         void ThreadFunctionL(); | 
|         |    105  | 
|         |    106         TInt NotifyClientAndWaitConfirm( TInt aErr ); | 
|         |    107  | 
|         |    108         void DoNotifyL( TInt aErr ); | 
|         |    109  | 
|         |    110         NONSHARABLE_CLASS(CNotifyObserver) : public CActive | 
|         |    111             { | 
|         |    112             public: | 
|         |    113                 static CNotifyObserver* NewL( | 
|         |    114                     CFileManagerThreadWrapper& aWrapper ); | 
|         |    115  | 
|         |    116                 ~CNotifyObserver(); | 
|         |    117  | 
|         |    118                 void Activate(); | 
|         |    119  | 
|         |    120                 void Complete( RThread& aThread, TInt aResult ); | 
|         |    121  | 
|         |    122             private: // From CActive | 
|         |    123                 void RunL(); | 
|         |    124  | 
|         |    125                 TInt RunError( TInt aErr ); | 
|         |    126  | 
|         |    127                 void DoCancel(); | 
|         |    128  | 
|         |    129             private: | 
|         |    130                 CNotifyObserver( CFileManagerThreadWrapper& aWrapper ); | 
|         |    131  | 
|         |    132             private: | 
|         |    133                 CFileManagerThreadWrapper& iWrapper; | 
|         |    134             }; | 
|         |    135  | 
|         |    136     private: // Data | 
|         |    137         // Own: For synchronising client and background thread | 
|         |    138         RSemaphore iSemaphore; | 
|         |    139         // Own: Client thread id | 
|         |    140         TThreadId iClientId; | 
|         |    141         // Ref: Pointer to thread function | 
|         |    142         MFileManagerThreadFunction* iFunction; | 
|         |    143         // Own: Client notify type flags, Client writes and thread only reads | 
|         |    144         TUint iNotify; | 
|         |    145         // Own: Thread cancel indicator, Client writes and thread only reads | 
|         |    146         TBool iCancel; | 
|         |    147         // Own: Observer wrapper to notify client about thread events | 
|         |    148         CNotifyObserver* iNotifyObserver; | 
|         |    149         // Own: Thread resume pending indicator, Client reads and writes | 
|         |    150         TBool iResumePending; | 
|         |    151     }; | 
|         |    152  | 
|         |    153 #endif // CFILEMANAGERTHREADWRAPPER_H | 
|         |    154  | 
|         |    155 // End of File |