appfw/apparchitecture/apgrfx/apgrecog.cpp
changeset 0 2e3d3ce01487
child 46 eea20ed08f4b
child 47 312d2b433792
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 // 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 
       
   407 @param aDataType On return, contains the result of the attempt to recognize 
       
   408 data. 
       
   409 @return KErrNone, if successful; otherwise one of the other system-wide error 
       
   410 codes. 
       
   411 */
       
   412 EXPORT_C TInt RApaLsSession::RecognizeData(const TDesC8& aBuffer, TDataRecognitionResult& aDataType) const
       
   413     {
       
   414     return RecognizeData(KNullDesC,aBuffer,aDataType);
       
   415     }
       
   416 
       
   417 /** Gets the data (MIME) type for data taken from a file with a specified name.
       
   418 
       
   419 @param aName The full filename, including drive and path, of the file containing the data.
       
   420 @param aBuffer A buffer containing data taken from the specified file; typically 
       
   421 the data is read from the beginning of the file.
       
   422 @param aDataType On return, contains the result of the attempt to recognize 
       
   423 data. 
       
   424 @return KErrNone, if successful; otherwise one of the other system-wide error 
       
   425 codes. 
       
   426 */
       
   427 EXPORT_C TInt RApaLsSession::RecognizeData(const TDesC& aName, const TDesC8& aBuffer, TDataRecognitionResult& aDataType) const
       
   428 	{
       
   429 	TPckg<TDataRecognitionResult> result(aDataType);
       
   430 	return SendReceiveWithReconnect(EAppListServRecognizeData,TIpcArgs(&result, &aName, &aBuffer));
       
   431 	} //lint !e1764: Suppress reference parameter could be declared const ref
       
   432 
       
   433 /** Gets the data (MIME) type for data in a file passed by handle.
       
   434 
       
   435 @param aFile The file containing the data. Before this function can be called,
       
   436 the file server session which owns this file handle must first be marked as shareable by 
       
   437 calling RFs::ShareProtected().
       
   438 @param aDataType On return, contains the result of the attempt to recognize 
       
   439 data. 
       
   440 @return KErrNone, if successful; otherwise one of the other system-wide error 
       
   441 codes. */
       
   442 EXPORT_C TInt RApaLsSession::RecognizeData(const RFile& aFile, TDataRecognitionResult& aDataType) const
       
   443 	{
       
   444 	TPckg<TDataRecognitionResult> result(aDataType);
       
   445 	TIpcArgs ipcArgs(&result);
       
   446 	const TInt error = aFile.TransferToServer(ipcArgs, 1, 2);
       
   447 	if (error)
       
   448 		return error;
       
   449 
       
   450 	return SendReceiveWithReconnect(EAppListServRecognizeDataPassedByFileHandle,ipcArgs);
       
   451 	} //lint !e1764 Suppress reference parameter 'aDataType' could be declared const ref
       
   452 
       
   453 
       
   454 
       
   455 /** Tests whether data taken from a named file has the specified 
       
   456 data (MIME) type.
       
   457 
       
   458 @param aName The name of the file containing the data.
       
   459 @param aBuffer A buffer containing data taken from the specified file; typically 
       
   460 the data is read from the beginning of the file.
       
   461 @param aDataType The data (MIME) type.
       
   462 @param aResult On return, contains the result of the test.
       
   463 @return KErrNone, if successful; otherwise one of the other system-wide error 
       
   464 codes. 
       
   465 */
       
   466 EXPORT_C TInt RApaLsSession::RecognizeSpecificData(const TDesC& aName, const TDesC8& aBuffer, const TDataType& aDataType, TBool& aResult) const
       
   467 	{
       
   468 	const TPckgC<TDataType> dataType(aDataType);
       
   469 	const TInt returnValue=SendReceiveWithReconnect(EAppListServRecognizeSpecificData,TIpcArgs(&dataType, &aName, &aBuffer));
       
   470 	if (returnValue<0)
       
   471 		return returnValue;
       
   472 
       
   473 	aResult = returnValue;
       
   474 	return KErrNone;
       
   475 	}
       
   476 	
       
   477 /** 
       
   478 Gets the data (MIME) type for files in a specified directory. Because this call may take a long
       
   479 time to complete, the asynchronous version is strongly recommended. Furthermore, it is not possible
       
   480 to use this synchronous function while an asynchronous request is still active.
       
   481 @publishedAll
       
   482 @released
       
   483 @param aPath A valid path. Note that the path must end with a backslash.
       
   484 @param aResult If the call was successful, this parameter contains the recognition result.
       
   485 @return KErrNone, if successful; otherwise one of the other system-wide error codes.
       
   486 */
       
   487 EXPORT_C TInt RApaLsSession::RecognizeFilesL(const TDesC& aPath, CDataRecognitionResultArray& aResult) const
       
   488 	{
       
   489 	return RecognizeFilesL(aPath, KAllDataTypes, aResult);
       
   490 	}
       
   491 
       
   492 /** 
       
   493 Gets the data (MIME) type for files in a specified directory. Because this call may take a long
       
   494 time to complete, the asynchronous version is strongly recommended. Furthermore, it is not possible
       
   495 to use this synchronous function while an asynchronous request is still active.
       
   496 @publishedAll
       
   497 @released
       
   498 @param aPath A valid path. Note that the path must end with a backslash.
       
   499 @param aDataType A data type filter. Wildcards are allowed. For example, "text*" would also
       
   500 add "text/plain" data types to the result.
       
   501 @param aResult If the call was successful, this parameter contains the recognition result.
       
   502 @return KErrNone, if successful; otherwise one of the other system-wide error codes.
       
   503 */
       
   504 EXPORT_C TInt RApaLsSession::RecognizeFilesL(const TDesC& aPath, const TDesC8& aDataType, CDataRecognitionResultArray& aResult) const
       
   505 	{
       
   506 	if(iExtension && iExtension->RecognitionActive())
       
   507 		return KErrInUse;
       
   508 
       
   509 	_LIT(KBackslash,"\\");
       
   510 	if(aPath.Right(1) != KBackslash)
       
   511 		return KErrPathNotFound;
       
   512 
       
   513 	TPckgBuf<TUint> requiredBufferSizePckg;
       
   514 	aResult.SetPath(aPath);
       
   515 	TInt error = SendReceiveWithReconnect(EAppListServRecognizeFiles,TIpcArgs(&aPath,&requiredBufferSizePckg,&aDataType));
       
   516 	if(!error)
       
   517 		error=TransferAndInternalizeDataL(aPath, requiredBufferSizePckg(), aResult);
       
   518 
       
   519 	return error;
       
   520 
       
   521 	}
       
   522 
       
   523 /** 
       
   524 Gets the data (MIME) type for files in a specified directory.
       
   525 @publishedAll
       
   526 @released
       
   527 @param aPath A valid path. Note that the path must end with a backslash.
       
   528 @param aResult If the call was successful, this parameter contains the recognition result.
       
   529 @param aStatus A request status object.
       
   530 */
       
   531 EXPORT_C void RApaLsSession::RecognizeFilesL(const TDesC& aPath, CDataRecognitionResultArray& aResult, TRequestStatus& aStatus)
       
   532 	{
       
   533 	RecognizeFilesL(aPath,KAllDataTypes,aResult,aStatus);
       
   534 	}
       
   535 
       
   536 /** 
       
   537 Gets the data (MIME) type for files in a specified directory.
       
   538 @publishedAll
       
   539 @released
       
   540 @param aPath A valid path. Note that the path must end with a backslash.
       
   541 @param aDataType A data type filter. Wildcards are allowed. For example, "text*" would also
       
   542 add "text/plain" data types to the result.
       
   543 @param aResult If the call was successful, this parameter contains the recognition result.
       
   544 @param aStatus A request status object
       
   545 */
       
   546 EXPORT_C void RApaLsSession::RecognizeFilesL(const TDesC& aPath, const TDesC8& aDataType, CDataRecognitionResultArray& aResult, TRequestStatus& aStatus)
       
   547 	{
       
   548 	if(!iExtension)
       
   549 		iExtension = new (ELeave) CApaLsSessionExtension(*this);
       
   550 
       
   551 	iExtension->RecognizeFilesL(aPath, aDataType, aResult, aStatus);
       
   552 	}
       
   553 
       
   554 /**
       
   555 This function transfers the data to the client-side and "fills" the CDataRecognitionResultArray object. 
       
   556 @internalComponent
       
   557 */
       
   558 TInt RApaLsSession::TransferAndInternalizeDataL(const TDesC& aPath, const TInt aRequiredBufferSize, CDataRecognitionResultArray& aResult) const
       
   559 	{
       
   560 	CBufFlat* const buffer = CBufFlat::NewL(aRequiredBufferSize);
       
   561 	CleanupStack::PushL(buffer);
       
   562 	buffer->ExpandL(0,aRequiredBufferSize);
       
   563 	TPtr8 bufPtr=buffer->Ptr(0);
       
   564 
       
   565 	// transfer recognition buffer
       
   566 	TInt error = SendReceiveWithReconnect(EAppListServTransferRecognitionResult,TIpcArgs(&aPath,&bufPtr,aRequiredBufferSize));
       
   567 	if(!error)
       
   568 		error = aResult.InternalizeL(*buffer);
       
   569 
       
   570 	CleanupStack::PopAndDestroy(buffer);
       
   571 	return error;
       
   572 	}
       
   573 
       
   574 /** 
       
   575 Cancels any outstanding asynchronous recognition requests.
       
   576 @publishedAll
       
   577 @released
       
   578 */
       
   579 EXPORT_C void RApaLsSession::CancelRecognizeFiles()
       
   580 	{
       
   581 	if(iExtension)
       
   582 		iExtension->CancelRecognizeFiles();
       
   583 	
       
   584 	delete iExtension;
       
   585 	iExtension = NULL;
       
   586 	}
       
   587 
       
   588 /** Tests whether data taken from a file passed by handle has the specified 
       
   589 data (MIME) type.
       
   590 
       
   591 @param aFile The file containing the data. Before this function can be called,
       
   592 the file server session which owns this file handle must first be marked as shareable by 
       
   593 calling RFs::ShareProtected().
       
   594 @param aDataType The data (MIME) type.
       
   595 @param aResult On return, contains the result of the test.
       
   596 @return KErrNone, if successful; otherwise one of the other system-wide error 
       
   597 codes. */
       
   598 EXPORT_C TInt RApaLsSession::RecognizeSpecificData(const RFile& aFile, const TDataType& aDataType, TBool& aResult) const
       
   599 	{
       
   600 	const TPckgC<TDataType> dataType(aDataType);
       
   601 	TIpcArgs ipcArgs(&dataType);
       
   602 	TInt returnValue = aFile.TransferToServer(ipcArgs, 1, 2);
       
   603 	if (returnValue == KErrNone)
       
   604 		returnValue = SendReceiveWithReconnect(EAppListServRecognizeSpecificDataPassedByFileHandle,ipcArgs);
       
   605 
       
   606 	if (returnValue < KErrNone)
       
   607 		return returnValue;
       
   608 		
       
   609 	aResult = returnValue;
       
   610 	return KErrNone;
       
   611 	}
       
   612 
       
   613 
       
   614 
       
   615 /** Gets the confidence threshold for successful data recognition.
       
   616 
       
   617 This is the minimum acceptable confidence level that must be reported by a 
       
   618 data recognizer for data to be accepted as of a given type.
       
   619 
       
   620 @param aConfidence On return, the confidence threshold. 
       
   621 @return KErrNone, if successful; otherwise one of the other system-wide error 
       
   622 codes. 
       
   623 */
       
   624 EXPORT_C TInt RApaLsSession::GetAcceptedConfidence(TInt& aConfidence) const
       
   625 	{
       
   626 	TPckg<TInt> confidence(aConfidence);
       
   627 	return SendReceiveWithReconnect(EAppListServGetConfidence,TIpcArgs(&confidence));
       
   628 	} //lint !e1764 Suppress reference parameter could be declared const ref
       
   629 
       
   630 
       
   631 
       
   632 /** Sets the confidence threshold for successful data recognition.
       
   633 
       
   634 This is the minimum acceptable confidence level that must be reported by a 
       
   635 data recognizer for data to be accepted as of a given type.
       
   636 
       
   637 @param aConfidence The confidence threshold. Although this is an integer value, 
       
   638 data recognizers use the discrete values defined by the CApaDataRecognizerType::TRecognitionConfidence 
       
   639 enumeration.
       
   640 @return KErrNone, if successful; otherwise one of the other system-wide error 
       
   641 codes. 
       
   642 @capability WriteDeviceData 
       
   643 */
       
   644 EXPORT_C TInt RApaLsSession::SetAcceptedConfidence(TInt aConfidence)
       
   645 	{
       
   646 	return SendReceiveWithReconnect(EAppListServSetConfidence,TIpcArgs(aConfidence));
       
   647 	} //lint !e1762 Suppress member function could be made const
       
   648 
       
   649 
       
   650 /** Gets a list of recognized data(MIME) types by all recognizers.
       
   651 
       
   652 @param aDataTypes The array of data (MIME) types.
       
   653 @return KErrNone, if successful; otherwise one of the other system-wide error 
       
   654 codes. 
       
   655 */
       
   656 EXPORT_C TInt RApaLsSession::GetSupportedDataTypesL(CDataTypeArray& aDataTypes) const
       
   657 	{
       
   658 	// gets the datatype count in terms of buffer length; negative value means one of the system-wide error
       
   659 	TInt ret = SendReceiveWithReconnect(EAppListServGetDataTypesPhase1,TIpcArgs());
       
   660 	if (ret>0)
       
   661 		{
       
   662 		CBufFlat* const buf=CBufFlat::NewL(ret);
       
   663 		CleanupStack::PushL(buf);
       
   664 		buf->ExpandL(0,ret);
       
   665 		TPtr8 ptr=buf->Ptr(0);
       
   666 		ret=SendReceiveWithReconnect(EAppListServGetDataTypesPhase2,TIpcArgs(&ptr));
       
   667 		if (ret==KErrNone)
       
   668 			{
       
   669 			RBufReadStream readStream(*buf);
       
   670 			readStream >> aDataTypes;
       
   671 			}
       
   672 			
       
   673 		CleanupStack::PopAndDestroy(buf);
       
   674 		}
       
   675 		
       
   676 	return ret;
       
   677 	}
       
   678 
       
   679