localisation/apparchitecture/apgrfx/apgrecog.cpp
branchSymbian3
changeset 57 b8d18c84f71c
equal deleted inserted replaced
56:aa99f2208aad 57:b8d18c84f71c
       
     1 // Copyright (c) 1997-2010 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 // apgrecog.cpp
       
    15 //
       
    16 
       
    17 
       
    18 #include "../apserv/APSCLSV.H"
       
    19 #include "APGCLI.H"
       
    20 #include "APGPRIV.H"
       
    21 
       
    22 class CAsyncFileRecognition;
       
    23 
       
    24 _LIT8(KAllDataTypes,"*");
       
    25 
       
    26 
       
    27 /**
       
    28 This class is an extension class for RApaLsSession. It was added to reduce the need
       
    29 of BC breaks in later releases.
       
    30 @internalComponent
       
    31 */
       
    32 NONSHARABLE_CLASS(CApaLsSessionExtension) : public CBase
       
    33 	{
       
    34 public:
       
    35 	CApaLsSessionExtension(RApaLsSession& aSession);
       
    36 	~CApaLsSessionExtension();
       
    37 
       
    38 	void SendReceive(TInt aFunction,const TIpcArgs& aArgs,TRequestStatus& aStatus) const;
       
    39 	TInt SendReceive(TInt aFunction,const TIpcArgs& aArgs) const;
       
    40 
       
    41 	// file recognition functions
       
    42 	void RecognizeFilesL(const TDesC& aPath, const TDesC8& aDataType, CDataRecognitionResultArray& aResult, TRequestStatus& aStatus);
       
    43 	void CancelRecognizeFiles();
       
    44 	void FilesRecognized(const TDesC& aPath, TInt aRequiredBufferSize, CDataRecognitionResultArray& aResult, TRequestStatus& aUsersRequestStatus, const TRequestStatus& aErrorCode);
       
    45 	TBool RecognitionActive() const;
       
    46 private:
       
    47 	RApaLsSession& iSession;	// we are a friend of this class!
       
    48 	CAsyncFileRecognition* iAsyncFileRecognition;
       
    49 	};
       
    50 
       
    51 /**
       
    52 This class is used to simplify the usage of the asynchronous RApaLsSession::RecognizeFilesL() function.
       
    53 @internalComponent
       
    54 */
       
    55 NONSHARABLE_CLASS(CAsyncFileRecognition) : public CActive
       
    56 	{
       
    57 public:
       
    58 	CAsyncFileRecognition(CDataRecognitionResultArray& aResult, TRequestStatus& aUsersRequestStatus, CApaLsSessionExtension& aSession);
       
    59 	~CAsyncFileRecognition();
       
    60 	void Start(const TDesC& aPath, const TDesC8& aDataType);
       
    61 private:
       
    62 	void RunL();
       
    63 	void DoCancel();
       
    64 private: // data
       
    65 	TPckgBuf<TUint> iRequiredBufferSizePckg;
       
    66 	CDataRecognitionResultArray& iResult;
       
    67 	TRequestStatus& iUsersRequestStatus;
       
    68 	CApaLsSessionExtension& iSession;
       
    69 	const TDesC* iPath;
       
    70 	const TDesC8* iDataType;
       
    71 	};
       
    72 
       
    73 /**
       
    74 An entry of a CDataRecognitionResultArray object. Stores TDataRecognitionResult and the file name
       
    75 in a compact format.
       
    76 @internalComponent
       
    77 */
       
    78 NONSHARABLE_CLASS(CDataRecognitionResultArray::CItem) : public CBase
       
    79 	{
       
    80 public:
       
    81 	CItem(HBufC* aFileName, HBufC8* aDataType, TUid aUid, TInt aConfidence);
       
    82 	~CItem();
       
    83 	void GetDataRecognitionResult(TDataRecognitionResult& aResult) const;
       
    84 	const TDesC& FileName() const;
       
    85 private:
       
    86 	HBufC* iFileName;
       
    87 	HBufC8* iDataType;
       
    88 	TUid iUid;
       
    89 	TInt iConfidence;
       
    90 	};
       
    91 
       
    92 
       
    93 //
       
    94 // CApaLsSessionExtension
       
    95 //
       
    96 
       
    97 CApaLsSessionExtension::CApaLsSessionExtension(RApaLsSession& aSession)
       
    98 	: iSession(aSession),
       
    99 	  iAsyncFileRecognition(NULL)
       
   100 	{
       
   101 	}
       
   102 
       
   103 CApaLsSessionExtension::~CApaLsSessionExtension()
       
   104 	{
       
   105 	delete iAsyncFileRecognition;
       
   106 	}
       
   107 
       
   108 void CApaLsSessionExtension::SendReceive(TInt aFunction,const TIpcArgs& aArgs,TRequestStatus& aStatus) const
       
   109 	{
       
   110 	iSession.SendReceive(aFunction,aArgs,aStatus); //lint !e1060 Suppress protected member is not accessible to non-member non-friend
       
   111 	}
       
   112 
       
   113 TInt CApaLsSessionExtension::SendReceive(TInt aFunction,const TIpcArgs& aArgs) const
       
   114 	{
       
   115 	return iSession.SendReceive(aFunction,aArgs); //lint !e1060 Suppress protected member is not accessible to non-member non-friend
       
   116 	}
       
   117 
       
   118 
       
   119 
       
   120 //
       
   121 // CAsyncFileRecognition
       
   122 //
       
   123 
       
   124 CAsyncFileRecognition::CAsyncFileRecognition(CDataRecognitionResultArray& aResult, TRequestStatus& aUsersRequestStatus, CApaLsSessionExtension& aSession)
       
   125 	: CActive(EPriorityStandard),
       
   126 	  iResult(aResult),
       
   127 	  iUsersRequestStatus(aUsersRequestStatus),
       
   128 	  iSession(aSession)
       
   129 	{
       
   130 	CActiveScheduler::Add(this);
       
   131 	}
       
   132 
       
   133 void CAsyncFileRecognition::Start(const TDesC& aPath, const TDesC8& aDataType)
       
   134 	{
       
   135 	iPath = &aPath;
       
   136 	iDataType = &aDataType;
       
   137 	iStatus = KRequestPending;
       
   138 	iSession.SendReceive(EAppListServRecognizeFilesAsync,TIpcArgs(&aPath,&iRequiredBufferSizePckg,&aDataType),iStatus);
       
   139 	SetActive();
       
   140 	}
       
   141 
       
   142 CAsyncFileRecognition::~CAsyncFileRecognition()
       
   143 	{
       
   144 	Cancel();
       
   145 	iPath = NULL;
       
   146 	iDataType = NULL;
       
   147 	}
       
   148 
       
   149 void CAsyncFileRecognition::RunL()
       
   150 	{
       
   151 	iSession.FilesRecognized(*iPath, iRequiredBufferSizePckg(), iResult, iUsersRequestStatus, iStatus);
       
   152 	}
       
   153 
       
   154 void CAsyncFileRecognition::DoCancel()
       
   155 	{
       
   156 	iSession.SendReceive(ECancelRecognizeFiles,TIpcArgs(TIpcArgs::ENothing));
       
   157 	TRequestStatus* status = &iUsersRequestStatus;
       
   158 	User::RequestComplete( status, KErrCancel );
       
   159 	}
       
   160 
       
   161 
       
   162 /**
       
   163 Asynchronous recognition of a directory.
       
   164 Function uses an internal CAsyncFileRecognition object to hide the 
       
   165 second server message (transferring the data to the client) from the user.
       
   166 When the path is not correct or the server is already busy with another 
       
   167 recognition request, the function completes the request with an error.
       
   168 @internalComponent
       
   169 */
       
   170 void CApaLsSessionExtension::RecognizeFilesL(const TDesC& aPath, const TDesC8& aDataType, CDataRecognitionResultArray& aResult, TRequestStatus& aStatus)
       
   171 	{
       
   172 	_LIT(KBackslash,"\\");
       
   173 
       
   174 	if(aPath.Right(1) != KBackslash)
       
   175 		{
       
   176 		TRequestStatus* status = &aStatus;
       
   177 		User::RequestComplete(status,KErrPathNotFound);
       
   178 		}
       
   179 	
       
   180 	aResult.SetPath(aPath);
       
   181 	aStatus = KRequestPending;
       
   182 
       
   183 	if(!iAsyncFileRecognition)
       
   184 		{
       
   185 		iAsyncFileRecognition = new (ELeave) CAsyncFileRecognition(aResult, aStatus, *this);
       
   186 		iAsyncFileRecognition->Start(aPath, aDataType);
       
   187 		}
       
   188 	else
       
   189 		{
       
   190 		TRequestStatus* status = &aStatus;
       
   191 		User::RequestComplete(status,KErrInUse);
       
   192 		}
       
   193 	}
       
   194 
       
   195 TBool CApaLsSessionExtension::RecognitionActive() const
       
   196 	{
       
   197 	return iAsyncFileRecognition ? ETrue : EFalse;
       
   198 	}
       
   199 
       
   200 void CApaLsSessionExtension::CancelRecognizeFiles()
       
   201 	{
       
   202 	if(iAsyncFileRecognition)
       
   203 		{
       
   204 		iAsyncFileRecognition->Cancel();
       
   205 		delete iAsyncFileRecognition;
       
   206 		iAsyncFileRecognition = NULL;
       
   207 		}
       
   208 	}
       
   209 
       
   210 /**
       
   211 Callback function called by an CAsyncFileRecognition object, when an asynchronous
       
   212 recognition has finished. If the recognition was successful, the data is transferred
       
   213 to the client-side.
       
   214 @internalComponent
       
   215 */
       
   216 void CApaLsSessionExtension::FilesRecognized(const TDesC& aPath, TInt aRequiredBufferSize, CDataRecognitionResultArray& aResult, TRequestStatus& aUsersRequestStatus, const TRequestStatus& aErrorCode)
       
   217 	{
       
   218 	TRequestStatus* status = &aUsersRequestStatus;
       
   219 	if(aErrorCode == KErrNone)
       
   220 		{
       
   221 		// transfer the result
       
   222 		TRAPD(error,iSession.TransferAndInternalizeDataL(aPath, aRequiredBufferSize, aResult));
       
   223 		User::RequestComplete(status, error);
       
   224 		}
       
   225 	else
       
   226 		User::RequestComplete(status, aErrorCode.Int());
       
   227 
       
   228 	delete iAsyncFileRecognition;
       
   229 	iAsyncFileRecognition = 0;
       
   230 	}
       
   231 
       
   232 
       
   233 //
       
   234 // CItem
       
   235 //
       
   236 
       
   237 CDataRecognitionResultArray::CItem::CItem(HBufC* aFileName, HBufC8* aDataType, TUid aUid, TInt aConfidence)
       
   238 	: iFileName(aFileName), 
       
   239 	  iDataType(aDataType), 
       
   240 	  iUid(aUid), 
       
   241 	  iConfidence(aConfidence)
       
   242 	{
       
   243 	}
       
   244 
       
   245 CDataRecognitionResultArray::CItem::~CItem()
       
   246 	{
       
   247 	delete iFileName;
       
   248 	delete iDataType;
       
   249 	}
       
   250 
       
   251 void CDataRecognitionResultArray::CItem::GetDataRecognitionResult(TDataRecognitionResult& aResult) const
       
   252 	{
       
   253 	TDataRecognitionResult result;
       
   254 	if(iDataType->Length() != 0)
       
   255 		{
       
   256 		TDataType dataType(*iDataType);
       
   257 		result.iDataType = dataType;
       
   258 		}
       
   259 	else
       
   260 		{
       
   261 		TDataType dataType(iUid);
       
   262 		result.iDataType = dataType;
       
   263 		}
       
   264 
       
   265 	result.iConfidence = iConfidence;
       
   266 	aResult = result;
       
   267 	}
       
   268 
       
   269 const TDesC& CDataRecognitionResultArray::CItem::FileName() const
       
   270 	{
       
   271 	if (iFileName == NULL)
       
   272 		return KNullDesC;
       
   273 	else
       
   274 		return *iFileName;
       
   275 	}
       
   276 
       
   277 
       
   278 //
       
   279 // CDataRecognitionResultArray
       
   280 //
       
   281 
       
   282 /**
       
   283 Constructor
       
   284 @publishedAll
       
   285 @released
       
   286 */
       
   287 EXPORT_C CDataRecognitionResultArray::CDataRecognitionResultArray()
       
   288 	{
       
   289 	}
       
   290 
       
   291 /**
       
   292 Destructor
       
   293 @publishedAll
       
   294 @released
       
   295 */
       
   296 EXPORT_C CDataRecognitionResultArray::~CDataRecognitionResultArray()
       
   297 	{
       
   298 	iItems.ResetAndDestroy();
       
   299 	}
       
   300 
       
   301 /**
       
   302 Returns the path of the recognition results.
       
   303 @publishedAll
       
   304 @released
       
   305 @return The path of the recognition results
       
   306 */
       
   307 EXPORT_C const TFileName& CDataRecognitionResultArray::Path() const
       
   308 	{
       
   309 	return iPath;
       
   310 	}
       
   311 
       
   312 /**
       
   313 Returns the number of entries in the CDataRecognitionResultArray.
       
   314 @publishedAll
       
   315 @released
       
   316 @return The number of entries in the CDataRecognitionResultArray.
       
   317 */
       
   318 EXPORT_C TUint CDataRecognitionResultArray::Count() const
       
   319 	{
       
   320 	return iItems.Count();
       
   321 	}
       
   322 
       
   323 /**
       
   324 Returns the recognition result of the given index.
       
   325 @publishedAll
       
   326 @released
       
   327 @param aResult On successful completion, this parameter contains the recognition result at the given index.
       
   328 @param aIndex The index of the recognition result to be returned. An invalid index causes
       
   329 the function to leave with KErrNotFound.
       
   330 @return The requested TDataRecognitionResult object
       
   331 @leave KErrNotFound An invalid index is passed
       
   332 */
       
   333 EXPORT_C void CDataRecognitionResultArray::GetDataRecognitionResultL(TDataRecognitionResult& aResult, const TUint aIndex) const
       
   334 	{
       
   335 	if( aIndex >= iItems.Count() )
       
   336 		User::Leave(KErrNotFound);
       
   337 
       
   338 	iItems[aIndex]->GetDataRecognitionResult(aResult);
       
   339 	}
       
   340 
       
   341 /**
       
   342 Returns the file name of the object at the given index.
       
   343 @publishedAll
       
   344 @released
       
   345 @param aFileName On successful completion, this parameter contains the file name of the object at the given index. 
       
   346 @param aIndex Specifies which file name to be returned. An invalid index causes
       
   347 the function to leave with KErrNotFound.
       
   348 @return The requested file name
       
   349 @leave KErrNotFound An invalid index is passed
       
   350 */
       
   351 EXPORT_C void CDataRecognitionResultArray::GetFileNameL(TFileName& aFileName, const TUint aIndex) const
       
   352 	{
       
   353 	if( aIndex >= iItems.Count() )
       
   354 		User::Leave(KErrNotFound);
       
   355 
       
   356 	aFileName.Zero();
       
   357 	aFileName.Copy( (iItems[aIndex]->FileName()) );
       
   358 	}
       
   359 
       
   360 TUint CDataRecognitionResultArray::InternalizeL(const CBufFlat& aBuffer)
       
   361 	{
       
   362 	RBufReadStream readStream;
       
   363 	
       
   364 	readStream.Open(aBuffer);
       
   365 	const TInt count=readStream.ReadUint32L();
       
   366 	for (TInt i=0; i<count; ++i)
       
   367 		{
       
   368 		const TInt fileNameLength = readStream.ReadUint8L();
       
   369 		HBufC* const fileName = HBufC::NewLC(fileNameLength);
       
   370 		TPtr fileNamePtr = fileName->Des();
       
   371 		readStream.ReadL(fileNamePtr,fileNameLength);
       
   372 
       
   373 		const TInt dataTypeLength = readStream.ReadUint8L();
       
   374 		HBufC8* const dataType = HBufC8::NewLC(dataTypeLength);
       
   375 		TPtr8 dataTypePtr = dataType->Des();
       
   376 		readStream.ReadL(dataTypePtr,dataTypeLength);
       
   377 
       
   378 		TUid uid;
       
   379 		uid.iUid = readStream.ReadInt32L();
       
   380 		
       
   381 		TInt const confidence = readStream.ReadInt32L();
       
   382 		
       
   383 		CItem* entry = new (ELeave) CItem(fileName,dataType,uid,confidence);
       
   384 		iItems.Append(entry);
       
   385 		
       
   386 		CleanupStack::Pop(dataType);	// ownership was transferred to "entry"
       
   387 		CleanupStack::Pop(fileName);	// ownership was transferred to "entry"
       
   388 		}
       
   389 
       
   390 	readStream.Close();
       
   391 		
       
   392 	return KErrNone;
       
   393 	}
       
   394 
       
   395 void CDataRecognitionResultArray::SetPath(const TFileName& aPath)
       
   396 	{
       
   397 	iPath.Copy(aPath);
       
   398 	}
       
   399 
       
   400 //
       
   401 //RApaLsSession
       
   402 //
       
   403 
       
   404 /** Gets the data (MIME) type of data passed by buffer.
       
   405 
       
   406 @param aBuffer A buffer containing data; Provide preferred size of buffer. 
       
   407 If MIME type could not be recognized using this buffer, provide a buffer of 
       
   408 larger size.
       
   409 @param aDataType On return, contains the result of the attempt to recognize 
       
   410 data. 
       
   411 @return KErrNone, if successful; otherwise one of the other system-wide error 
       
   412 codes. 
       
   413 
       
   414 @see RApaLsSession::GetPreferredBufSize()
       
   415 */
       
   416 EXPORT_C TInt RApaLsSession::RecognizeData(const TDesC8& aBuffer, TDataRecognitionResult& aDataType) const
       
   417     {
       
   418     return RecognizeData(KNullDesC,aBuffer,aDataType);
       
   419     }
       
   420 
       
   421 /** Gets the data (MIME) type for data taken from a file with a specified name.
       
   422 
       
   423 @param aName The full filename, including drive and path, of the file containing the data.
       
   424 @param aBuffer A buffer containing data taken from the specified file; Provide preferred size of buffer 
       
   425 from beginning of the file. If MIME type could not be recognized using this buffer, provide a buffer of 
       
   426 larger size.
       
   427 @param aDataType On return, contains the result of the attempt to recognize 
       
   428 data. 
       
   429 @return KErrNone, if successful; otherwise one of the other system-wide error 
       
   430 codes. 
       
   431 
       
   432 @see RApaLsSession::GetPreferredBufSize()
       
   433 */
       
   434 EXPORT_C TInt RApaLsSession::RecognizeData(const TDesC& aName, const TDesC8& aBuffer, TDataRecognitionResult& aDataType) const
       
   435 	{
       
   436 	TPckg<TDataRecognitionResult> result(aDataType);
       
   437 	return SendReceiveWithReconnect(EAppListServRecognizeData,TIpcArgs(&result, &aName, &aBuffer));
       
   438 	} //lint !e1764: Suppress reference parameter could be declared const ref
       
   439 
       
   440 /** Gets the data (MIME) type for data in a file passed by handle.
       
   441 
       
   442 @param aFile The file containing the data. Before this function can be called,
       
   443 the file server session which owns this file handle must first be marked as shareable by 
       
   444 calling RFs::ShareProtected().
       
   445 @param aDataType On return, contains the result of the attempt to recognize 
       
   446 data. 
       
   447 @return KErrNone, if successful; otherwise one of the other system-wide error 
       
   448 codes. */
       
   449 EXPORT_C TInt RApaLsSession::RecognizeData(const RFile& aFile, TDataRecognitionResult& aDataType) const
       
   450 	{
       
   451 	TPckg<TDataRecognitionResult> result(aDataType);
       
   452 	TIpcArgs ipcArgs(&result);
       
   453 	const TInt error = aFile.TransferToServer(ipcArgs, 1, 2);
       
   454 	if (error)
       
   455 		return error;
       
   456 
       
   457 	return SendReceiveWithReconnect(EAppListServRecognizeDataPassedByFileHandle,ipcArgs);
       
   458 	} //lint !e1764 Suppress reference parameter 'aDataType' could be declared const ref
       
   459 
       
   460 
       
   461 
       
   462 /** Tests whether data taken from a named file has the specified 
       
   463  * data (MIME) type.
       
   464 
       
   465 @param aName The name of the file containing the data.
       
   466 @param aBuffer A buffer containing data taken from the specified file; Provide preferred size of buffer 
       
   467 from beginning of the file. If MIME type could not be recognized using this buffer, provide a buffer of 
       
   468 larger size.
       
   469 @param aDataType The data (MIME) type.
       
   470 @param aResult On return, contains the result of the test.
       
   471 @return KErrNone, if successful; otherwise one of the other system-wide error 
       
   472 codes. 
       
   473 
       
   474 @see RApaLsSession::GetPreferredBufSize()
       
   475 */
       
   476 EXPORT_C TInt RApaLsSession::RecognizeSpecificData(const TDesC& aName, const TDesC8& aBuffer, const TDataType& aDataType, TBool& aResult) const
       
   477 	{
       
   478 	const TPckgC<TDataType> dataType(aDataType);
       
   479 	const TInt returnValue=SendReceiveWithReconnect(EAppListServRecognizeSpecificData,TIpcArgs(&dataType, &aName, &aBuffer));
       
   480 	if (returnValue<0)
       
   481 		return returnValue;
       
   482 
       
   483 	aResult = returnValue;
       
   484 	return KErrNone;
       
   485 	}
       
   486 	
       
   487 /** 
       
   488 Gets the data (MIME) type for files in a specified directory. Because this call may take a long
       
   489 time to complete, the asynchronous version is strongly recommended. Furthermore, it is not possible
       
   490 to use this synchronous function while an asynchronous request is still active.
       
   491 @publishedAll
       
   492 @released
       
   493 @param aPath A valid path. Note that the path must end with a backslash.
       
   494 @param aResult If the call was successful, this parameter contains the recognition result.
       
   495 @return KErrNone, if successful; otherwise one of the other system-wide error codes.
       
   496 */
       
   497 EXPORT_C TInt RApaLsSession::RecognizeFilesL(const TDesC& aPath, CDataRecognitionResultArray& aResult) const
       
   498 	{
       
   499 	return RecognizeFilesL(aPath, KAllDataTypes, aResult);
       
   500 	}
       
   501 
       
   502 /** 
       
   503 Gets the data (MIME) type for files in a specified directory. Because this call may take a long
       
   504 time to complete, the asynchronous version is strongly recommended. Furthermore, it is not possible
       
   505 to use this synchronous function while an asynchronous request is still active.
       
   506 @publishedAll
       
   507 @released
       
   508 @param aPath A valid path. Note that the path must end with a backslash.
       
   509 @param aDataType A data type filter. Wildcards are allowed. For example, "text*" would also
       
   510 add "text/plain" data types to the result.
       
   511 @param aResult If the call was successful, this parameter contains the recognition result.
       
   512 @return KErrNone, if successful; otherwise one of the other system-wide error codes.
       
   513 */
       
   514 EXPORT_C TInt RApaLsSession::RecognizeFilesL(const TDesC& aPath, const TDesC8& aDataType, CDataRecognitionResultArray& aResult) const
       
   515 	{
       
   516 	if(iExtension && iExtension->RecognitionActive())
       
   517 		return KErrInUse;
       
   518 
       
   519 	_LIT(KBackslash,"\\");
       
   520 	if(aPath.Right(1) != KBackslash)
       
   521 		return KErrPathNotFound;
       
   522 
       
   523 	TPckgBuf<TUint> requiredBufferSizePckg;
       
   524 	aResult.SetPath(aPath);
       
   525 	TInt error = SendReceiveWithReconnect(EAppListServRecognizeFiles,TIpcArgs(&aPath,&requiredBufferSizePckg,&aDataType));
       
   526 	if(!error)
       
   527 		error=TransferAndInternalizeDataL(aPath, requiredBufferSizePckg(), aResult);
       
   528 
       
   529 	return error;
       
   530 
       
   531 	}
       
   532 
       
   533 /** 
       
   534 Gets the data (MIME) type for files in a specified directory.
       
   535 @publishedAll
       
   536 @released
       
   537 @param aPath A valid path. Note that the path must end with a backslash.
       
   538 @param aResult If the call was successful, this parameter contains the recognition result.
       
   539 @param aStatus A request status object.
       
   540 */
       
   541 EXPORT_C void RApaLsSession::RecognizeFilesL(const TDesC& aPath, CDataRecognitionResultArray& aResult, TRequestStatus& aStatus)
       
   542 	{
       
   543 	RecognizeFilesL(aPath,KAllDataTypes,aResult,aStatus);
       
   544 	}
       
   545 
       
   546 /** 
       
   547 Gets the data (MIME) type for files in a specified directory.
       
   548 @publishedAll
       
   549 @released
       
   550 @param aPath A valid path. Note that the path must end with a backslash.
       
   551 @param aDataType A data type filter. Wildcards are allowed. For example, "text*" would also
       
   552 add "text/plain" data types to the result.
       
   553 @param aResult If the call was successful, this parameter contains the recognition result.
       
   554 @param aStatus A request status object
       
   555 */
       
   556 EXPORT_C void RApaLsSession::RecognizeFilesL(const TDesC& aPath, const TDesC8& aDataType, CDataRecognitionResultArray& aResult, TRequestStatus& aStatus)
       
   557 	{
       
   558 	if(!iExtension)
       
   559 		iExtension = new (ELeave) CApaLsSessionExtension(*this);
       
   560 
       
   561 	iExtension->RecognizeFilesL(aPath, aDataType, aResult, aStatus);
       
   562 	}
       
   563 
       
   564 /**
       
   565 This function transfers the data to the client-side and "fills" the CDataRecognitionResultArray object. 
       
   566 @internalComponent
       
   567 */
       
   568 TInt RApaLsSession::TransferAndInternalizeDataL(const TDesC& aPath, const TInt aRequiredBufferSize, CDataRecognitionResultArray& aResult) const
       
   569 	{
       
   570 	CBufFlat* const buffer = CBufFlat::NewL(aRequiredBufferSize);
       
   571 	CleanupStack::PushL(buffer);
       
   572 	buffer->ExpandL(0,aRequiredBufferSize);
       
   573 	TPtr8 bufPtr=buffer->Ptr(0);
       
   574 
       
   575 	// transfer recognition buffer
       
   576 	TInt error = SendReceiveWithReconnect(EAppListServTransferRecognitionResult,TIpcArgs(&aPath,&bufPtr,aRequiredBufferSize));
       
   577 	if(!error)
       
   578 		error = aResult.InternalizeL(*buffer);
       
   579 
       
   580 	CleanupStack::PopAndDestroy(buffer);
       
   581 	return error;
       
   582 	}
       
   583 
       
   584 /** 
       
   585 Cancels any outstanding asynchronous recognition requests.
       
   586 @publishedAll
       
   587 @released
       
   588 */
       
   589 EXPORT_C void RApaLsSession::CancelRecognizeFiles()
       
   590 	{
       
   591 	if(iExtension)
       
   592 		iExtension->CancelRecognizeFiles();
       
   593 	
       
   594 	delete iExtension;
       
   595 	iExtension = NULL;
       
   596 	}
       
   597 
       
   598 /** Tests whether data taken from a file passed by handle has the specified 
       
   599 data (MIME) type.
       
   600 
       
   601 @param aFile The file containing the data. Before this function can be called,
       
   602 the file server session which owns this file handle must first be marked as shareable by 
       
   603 calling RFs::ShareProtected().
       
   604 @param aDataType The data (MIME) type.
       
   605 @param aResult On return, contains the result of the test.
       
   606 @return KErrNone, if successful; otherwise one of the other system-wide error 
       
   607 codes. */
       
   608 EXPORT_C TInt RApaLsSession::RecognizeSpecificData(const RFile& aFile, const TDataType& aDataType, TBool& aResult) const
       
   609 	{
       
   610 	const TPckgC<TDataType> dataType(aDataType);
       
   611 	TIpcArgs ipcArgs(&dataType);
       
   612 	TInt returnValue = aFile.TransferToServer(ipcArgs, 1, 2);
       
   613 	if (returnValue == KErrNone)
       
   614 		returnValue = SendReceiveWithReconnect(EAppListServRecognizeSpecificDataPassedByFileHandle,ipcArgs);
       
   615 
       
   616 	if (returnValue < KErrNone)
       
   617 		return returnValue;
       
   618 		
       
   619 	aResult = returnValue;
       
   620 	return KErrNone;
       
   621 	}
       
   622 
       
   623 
       
   624 
       
   625 /** Gets the confidence threshold for successful data recognition.
       
   626 
       
   627 This is the minimum acceptable confidence level that must be reported by a 
       
   628 data recognizer for data to be accepted as of a given type.
       
   629 
       
   630 @param aConfidence On return, the confidence threshold. 
       
   631 @return KErrNone, if successful; otherwise one of the other system-wide error 
       
   632 codes. 
       
   633 */
       
   634 EXPORT_C TInt RApaLsSession::GetAcceptedConfidence(TInt& aConfidence) const
       
   635 	{
       
   636 	TPckg<TInt> confidence(aConfidence);
       
   637 	return SendReceiveWithReconnect(EAppListServGetConfidence,TIpcArgs(&confidence));
       
   638 	} //lint !e1764 Suppress reference parameter could be declared const ref
       
   639 
       
   640 
       
   641 
       
   642 /** Sets the confidence threshold for successful data recognition.
       
   643 
       
   644 This is the minimum acceptable confidence level that must be reported by a 
       
   645 data recognizer for data to be accepted as of a given type.
       
   646 
       
   647 @param aConfidence The confidence threshold. Although this is an integer value, 
       
   648 data recognizers use the discrete values defined by the CApaDataRecognizerType::TRecognitionConfidence 
       
   649 enumeration.
       
   650 @return KErrNone, if successful; otherwise one of the other system-wide error 
       
   651 codes. 
       
   652 @capability WriteDeviceData 
       
   653 */
       
   654 EXPORT_C TInt RApaLsSession::SetAcceptedConfidence(TInt aConfidence)
       
   655 	{
       
   656 	return SendReceiveWithReconnect(EAppListServSetConfidence,TIpcArgs(aConfidence));
       
   657 	} //lint !e1762 Suppress member function could be made const
       
   658 
       
   659 
       
   660 /** Gets a list of recognized data(MIME) types by all recognizers.
       
   661 
       
   662 @param aDataTypes The array of data (MIME) types.
       
   663 @return KErrNone, if successful; otherwise one of the other system-wide error 
       
   664 codes. 
       
   665 */
       
   666 EXPORT_C TInt RApaLsSession::GetSupportedDataTypesL(CDataTypeArray& aDataTypes) const
       
   667 	{
       
   668 	// gets the datatype count in terms of buffer length; negative value means one of the system-wide error
       
   669 	TInt ret = SendReceiveWithReconnect(EAppListServGetDataTypesPhase1,TIpcArgs());
       
   670 	if (ret>0)
       
   671 		{
       
   672 		CBufFlat* const buf=CBufFlat::NewL(ret);
       
   673 		CleanupStack::PushL(buf);
       
   674 		buf->ExpandL(0,ret);
       
   675 		TPtr8 ptr=buf->Ptr(0);
       
   676 		ret=SendReceiveWithReconnect(EAppListServGetDataTypesPhase2,TIpcArgs(&ptr));
       
   677 		if (ret==KErrNone)
       
   678 			{
       
   679 			RBufReadStream readStream(*buf);
       
   680 			readStream >> aDataTypes;
       
   681 			}
       
   682 			
       
   683 		CleanupStack::PopAndDestroy(buf);
       
   684 		}
       
   685 		
       
   686 	return ret;
       
   687 	}
       
   688 
       
   689