appfw/apparchitecture/apserv/APSRECUTIL.H
changeset 0 2e3d3ce01487
equal deleted inserted replaced
-1:000000000000 0:2e3d3ce01487
       
     1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // apsrecutil.h
       
    15 //
       
    16 
       
    17 
       
    18 #ifndef __APSRECUTIL_H__
       
    19 #define __APSRECUTIL_H__
       
    20 
       
    21 #include <e32base.h>
       
    22 #include <apmrec.h>
       
    23 #include "apsserv.h"
       
    24 
       
    25 /**
       
    26 Reference-counted object which stores a recognition result in a more compact format
       
    27 than TDataRecognitionResult does. Also includes the file name.
       
    28 
       
    29 The reason why instances of this class are reference-counted is that they might 
       
    30 be "owned" by the cache and CDirectoryRecognitionResult at the same time. If both
       
    31 of them had their own copies unnecessarily much memory would be wasted.
       
    32 @internalComponent
       
    33 */
       
    34 NONSHARABLE_CLASS(CRecognitionResult) : public CObject
       
    35 	{
       
    36 public:
       
    37 	static CRecognitionResult* NewL(const TDesC& aFileName, const TDataRecognitionResult& aRecognitionResult);
       
    38 	TUint GetRequiredBufferSize() const;
       
    39 	void WriteToStreamL(RWriteStream& aWriteStream);
       
    40 	
       
    41 	void Get(TDataRecognitionResult& aRecognitionResult);
       
    42 	inline const TDesC8& DataType() const { return *iDataType; }
       
    43 	inline const TDesC& FileName() const { return *iFileName; }
       
    44 private:
       
    45 	CRecognitionResult(HBufC* aFileName, HBufC8* aDataType, TUid aUid, TInt aConfidence);
       
    46 	~CRecognitionResult();
       
    47 private:
       
    48 	const HBufC* const iFileName;
       
    49 	const HBufC8* const iDataType;
       
    50 	TUid iUid;
       
    51 	TInt iConfidence;
       
    52 	};
       
    53 
       
    54 /**
       
    55 Holds the recognition results of all files of a directory.
       
    56 @internalComponent
       
    57 */
       
    58 NONSHARABLE_CLASS(CDirectoryRecognitionResult) : public CBase
       
    59 	{
       
    60 public:
       
    61 	CDirectoryRecognitionResult(HBufC* aPath, HBufC8* aDataTypeFilter);
       
    62 	~CDirectoryRecognitionResult();
       
    63 	void AppendL(CRecognitionResult* aEntry);
       
    64 	void WriteToStreamL(RWriteStream& aWriteStream);
       
    65 	inline TInt RequiredBufferSize() const {return iRequiredBufferSize;}
       
    66 	inline HBufC& Path() { return *iPath; }
       
    67 private:
       
    68 	TInt iRequiredBufferSize;
       
    69 	HBufC* iPath;
       
    70 	HBufC8* iDataTypeFilter;
       
    71 	RPointerArray<CRecognitionResult> iEntries;
       
    72 	};
       
    73 
       
    74 /**
       
    75 Utility class which does synchronous and asynchronous file recognitions of a directory
       
    76 @internalComponent
       
    77 */
       
    78 NONSHARABLE_CLASS(CFileRecognitionUtility) : public CActive
       
    79 	{
       
    80 public:
       
    81 	CFileRecognitionUtility(CApaAppArcServer& aServer, TInt aMaxBufSize, RFs& aFs);
       
    82 	~CFileRecognitionUtility();
       
    83 	void RecognizeSynchronouslyL(CDirectoryRecognitionResult& aResult);
       
    84 	void RecognizeAsynchronously(CDirectoryRecognitionResult& aResult, const RMessage2& aMessage);
       
    85 	void CancelRecognitionRequest();
       
    86 protected:
       
    87 	void ReadDirectoryL();
       
    88 	void RecognizeFileL();
       
    89 private:
       
    90 	void NextStep();
       
    91 	void RunL();
       
    92 	void DoCancel();
       
    93 	TInt BufferSizeL() const;
       
    94 private:
       
    95 	HBufC* iPath;
       
    96 	CDirectoryRecognitionResult* iResult;
       
    97 	CApaAppArcServer& iServer;
       
    98 	TInt iMaxBufSize;
       
    99 	RFs& iFs;
       
   100 	CDir* iEntryList;
       
   101 	TInt iIndex;
       
   102 	TInt iStep;
       
   103 	RMessage2 iMessage;
       
   104 	};
       
   105 
       
   106 #endif	// __APSRECUTIL_H__
       
   107