localisation/apparchitecture/apgrfx/APGCLI.CPP
branchSymbian3
changeset 57 b8d18c84f71c
parent 6 c108117318cb
equal deleted inserted replaced
56:aa99f2208aad 57:b8d18c84f71c
     1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of the License "Eclipse Public License v1.0"
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     7 //
     8 // Initial Contributors:
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
     9 // Nokia Corporation - initial contribution.
    10 //
    10 //
    11 // Contributors:
    11 // Contributors:
    12 //
    12 //
    13 // Description:
    13 // Description:
       
    14 // apgcli.cpp
    14 //
    15 //
    15 
    16 
    16 #include "../apserv/APSCLSV.H"
    17 #include "../apserv/APSCLSV.H"
       
    18 #include "../apserv/apsserv.h"
       
    19 
       
    20 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    21 #if !defined(__APA_INTERNAL_H__)
       
    22 #include "apainternal.h"
       
    23 #endif
       
    24 #if !defined(__APGICNFL_PARTNER_H__)
       
    25 #include "apgicnflpartner.h"
       
    26 #endif
       
    27 #endif //SYMBIAN_ENABLE_SPLIT_HEADERS
    17 #include "APGCLI.H"
    28 #include "APGCLI.H"
    18 #include "APACMDLN.H"
       
    19 #include "APGSTD.H"
    29 #include "APGSTD.H"
    20 #include "APGICNFL.H"
    30 #include "APGICNFL.H"
    21 #include <apsserv.h>
       
    22 #include <apmrec.h>
       
    23 #include <s32mem.h>
       
    24 #include "APGPRIV.H"
    31 #include "APGPRIV.H"
    25 #include <apadef.h>
       
    26 #include "apprivate.h"
    32 #include "apprivate.h"
    27 
    33 
    28 #if defined(USE_IH_RAISE_EVENT)
    34 const TUint KInitialIconBufSize = sizeof(TSize)*6 + sizeof(TInt);
    29 #include <SystemMonitor/RaiseEvent.h>
    35 const TUint KInitialViewDataBufSize = sizeof(TApaAppViewInfo)*6 + sizeof(TInt);
    30 #include <test/testinstrumentation.h>
    36 const TUint KInitialOwnedFilesBufSize = sizeof(TFileName)*6 + sizeof(TInt);
    31 #endif
       
    32 
       
    33 class CApaLsSessionExtension;
       
    34 
       
    35 const TUint KInitialIconBufSize=sizeof(TSize)*6+sizeof(TInt);
       
    36 const TUint KInitialViewDataBufSize=sizeof(TApaAppViewInfo)*6+sizeof(TInt);
       
    37 const TUint KInitialOwnedFilesBufSize=sizeof(TFileName)*6+sizeof(TInt);
       
    38 const TUint KDefaultBufSize = 0x400;
    37 const TUint KDefaultBufSize = 0x400;
    39 const TUint KAsyncMessageSlots=4; //one slot each for, RApaLsSession::SetNotify, RApaLsSession::
    38 const TUint KAsyncMessageSlots = 4; // One slot each for, RApaLsSession::SetNotify, RApaLsSession::
    40                                   //RegisterListPopulationCompleteObserver and RApaLsSession::NotifyOnDataMappingChange
    39                                     // RegisterListPopulationCompleteObserver and RApaLsSession::NotifyOnDataMappingChange
    41                                   //CAsyncFileRecognition::Start makes an asynch request of apparc server.
    40                                     // CAsyncFileRecognition::Start makes an asynch request of apparc server.
    42 
    41 
    43 _LIT8(KAllDataTypes,"*");
    42 extern void CleanupAppServiceArray(TAny* aServiceArray);
    44 
       
    45 extern void CleanupServiceArray(TAny* aServiceArray);
       
    46 
    43 
    47 IMPORT_C extern const TInt KMinApplicationStackSize;
    44 IMPORT_C extern const TInt KMinApplicationStackSize;
    48 
    45 
       
    46 /** 
       
    47 @internalComponent
       
    48 */
    49 class MArrayFiller
    49 class MArrayFiller
    50 	{
    50 	{
    51 public:
    51 public:
    52 	virtual void AppendItemL(RReadStream& aReadStream)=0;
    52 	virtual void AppendItemFromStreamL(RReadStream& aReadStream) = 0;
    53 	};
    53 	};
    54 
    54 
    55 class TSizeArrayFiller : public MArrayFiller
    55 /** 
       
    56 @internalComponent
       
    57 */
       
    58 NONSHARABLE_CLASS(TSizeArrayFiller) : public MArrayFiller
    56 	{
    59 	{
    57 public:
    60 public:
    58 	inline TSizeArrayFiller(CArrayFixFlat<TSize>& aArray) :iArray(aArray) {}
    61 	inline TSizeArrayFiller(CArrayFixFlat<TSize>& aArray) : iArray(aArray) {}
    59 	virtual void AppendItemL(RReadStream& aReadStream);
    62 public: // from MArrayFiller
       
    63 	void AppendItemFromStreamL(RReadStream& aReadStream);
    60 private:
    64 private:
    61 	CArrayFixFlat<TSize>& iArray;
    65 	CArrayFixFlat<TSize>& iArray;
    62 	};
    66 	};
    63 
    67 
    64 class TViewDataArrayFiller : public MArrayFiller
    68 /** 
       
    69 @internalComponent
       
    70 */
       
    71 NONSHARABLE_CLASS(TViewDataArrayFiller) : public MArrayFiller
    65 	{
    72 	{
    66 public:
    73 public:
    67 	inline TViewDataArrayFiller(CApaAppViewArray& aArray) :iArray(aArray) {}
    74 	inline TViewDataArrayFiller(CApaAppViewArray& aArray) : iArray(aArray) {}
    68 	virtual void AppendItemL(RReadStream& aReadStream);
    75 public: // from MArrayFiller
       
    76 	void AppendItemFromStreamL(RReadStream& aReadStream);
    69 private:
    77 private:
    70 	CApaAppViewArray& iArray;
    78 	CApaAppViewArray& iArray;
    71 	};
    79 	};
    72 
    80 
    73 class TDesCArrayFiller : public MArrayFiller
    81 /** 
       
    82 @internalComponent
       
    83 */
       
    84 NONSHARABLE_CLASS(TDesCArrayFiller) : public MArrayFiller
    74 	{
    85 	{
    75 public:
    86 public:
    76 	inline TDesCArrayFiller(CDesCArray& aArray) :iArray(aArray) {}
    87 	inline TDesCArrayFiller(CDesCArray& aArray) : iArray(aArray) {}
    77 	virtual void AppendItemL(RReadStream& aReadStream);
    88 public: // from MArrayFiller
       
    89 	void AppendItemFromStreamL(RReadStream& aReadStream);
    78 private:
    90 private:
    79 	CDesCArray& iArray;
    91 	CDesCArray& iArray;
    80 	};
    92 	};
    81 
    93 
    82 /**
    94 // TSizeArrayFiller
    83 This class is used to simplify the usage of the asynchronous RApaLsSession::RecognizeFilesL() function.
    95 
       
    96 void TSizeArrayFiller::AppendItemFromStreamL(RReadStream& aReadStream)
       
    97 	{
       
    98 	TSize size;
       
    99 	size.iWidth = aReadStream.ReadUint32L();
       
   100 	size.iHeight= aReadStream.ReadUint32L();
       
   101 	iArray.AppendL(size);
       
   102 	}
       
   103 
       
   104 // TViewDataArrayFiller
       
   105 
       
   106 void TViewDataArrayFiller::AppendItemFromStreamL(RReadStream& aReadStream)
       
   107 	{
       
   108 	TApaAppViewInfo info;
       
   109 	aReadStream >> info;
       
   110 	iArray.AppendL(info);
       
   111 	}
       
   112 
       
   113 // TDesCArrayFiller
       
   114 
       
   115 void TDesCArrayFiller::AppendItemFromStreamL(RReadStream& aReadStream)
       
   116 	{
       
   117 	TFileName info;
       
   118 	aReadStream >> info;
       
   119 	iArray.AppendL(info);
       
   120 	}
       
   121 
       
   122 /** 
    84 @internalComponent
   123 @internalComponent
    85 */
   124 */
    86 class CAsyncFileRecognition : public CActive
   125 EXPORT_C TUint MinApplicationStackSize()
    87 	{
   126 	{
    88 public:
   127 	return KMinApplicationStackSize;
    89 	CAsyncFileRecognition(CDataRecognitionResultArray& aResult, TRequestStatus& aUsersRequestStatus, CApaLsSessionExtension& aSession);
   128 	}
    90 	~CAsyncFileRecognition();
   129 
    91 	void Start(const TDesC& aPath, const TDesC8& aDataType);
   130 
    92 private:
   131 //
    93 	void RunL();
   132 // class RApaLsSession
    94 	void DoCancel();
   133 //
    95 private: // data
   134 
    96 	TPckgBuf<TUint> iRequiredBufferSizePckg;
   135 EXPORT_C RApaLsSession::RApaLsSession()
    97 	CDataRecognitionResultArray& iResult;
   136 	: iExtension(NULL)
    98 	TRequestStatus& iUsersRequestStatus;
   137 	{}
    99 	CApaLsSessionExtension& iSession;
   138 
   100 	const TDesC* iPath;
   139 
   101 	const TDesC8* iDataType;
   140 
   102 	};
   141 /** Connects a client to the application architecture server, creating a session 
   103 
   142 with it.
   104 /**
   143 
   105 This class is an extension class for RApaLsSession. It was added to reduce the need
   144 @return KErrNone if successful; otherwise, one of the system-wide error codes. 
   106 of BC breaks in later releases.
   145 */
   107 @internalComponent
   146 EXPORT_C TInt RApaLsSession::Connect()
   108 */
   147 	{
   109 class CApaLsSessionExtension : public CBase
   148 	TInt r=CreateSession(KAppListServerName,Version(),KAsyncMessageSlots);
   110 	{
   149 	return(r); 
   111 public:
   150 	}
   112 	CApaLsSessionExtension(RApaLsSession& aSession);
   151 
   113 	~CApaLsSessionExtension();
   152 EXPORT_C void RApaLsSession::Close()
   114 
   153 /** 
   115 	void SendReceive(TInt aFunction,const TIpcArgs& aArgs,TRequestStatus& aStatus) const;
   154 Closes the session. Needs to be called to avoid memory leaks.
   116 	TInt SendReceive(TInt aFunction,const TIpcArgs& aArgs) const;
       
   117 
       
   118 	// file recognition functions
       
   119 	void RecognizeFilesL(const TDesC& aPath, const TDesC8& aDataType, CDataRecognitionResultArray& aResult, TRequestStatus& aStatus);
       
   120 	void CancelRecognizeFiles();
       
   121 	void FilesRecognized(const TDesC& aPath, TInt aRequiredBufferSize, CDataRecognitionResultArray& aResult, TRequestStatus& aUsersRequestStatus, const TRequestStatus& aErrorCode);
       
   122 	TBool RecognitionActive() const;
       
   123 private:
       
   124 	RApaLsSession& iSession;	// we are a friend of this class!
       
   125 	CAsyncFileRecognition* iAsyncFileRecognition;
       
   126 	};
       
   127 
       
   128 /**
       
   129 An entry of a CDataRecognitionResultArray object. Stores TDataRecognitionResult and the file name
       
   130 in a compact format.
       
   131 @internalComponent
       
   132 */
       
   133 class CDataRecognitionResultArrayEntry : public CBase
       
   134 	{
       
   135 public:
       
   136 	CDataRecognitionResultArrayEntry(HBufC* aFileName, HBufC8* aDataType, TUid aUid, TInt aConfidence);
       
   137 	~CDataRecognitionResultArrayEntry();
       
   138 	void GetDataRecognitionResult(TDataRecognitionResult& aResult) const;
       
   139 	const TDesC& FileName() const;
       
   140 private:
       
   141 	HBufC* iFileName;
       
   142 	HBufC8* iDataType;
       
   143 	TUid iUid;
       
   144 	TInt iConfidence;
       
   145 	};
       
   146 
       
   147 //////////////////////////////
       
   148 // CAsyncFileRecognition
       
   149 //////////////////////////////
       
   150 
       
   151 CAsyncFileRecognition::CAsyncFileRecognition(CDataRecognitionResultArray& aResult, TRequestStatus& aUsersRequestStatus, CApaLsSessionExtension& aSession)
       
   152 	: CActive(EPriorityStandard),
       
   153 	  iResult(aResult),
       
   154 	  iUsersRequestStatus(aUsersRequestStatus),
       
   155 	  iSession(aSession)
       
   156 	{
       
   157 	CActiveScheduler::Add(this);
       
   158 	}
       
   159 
       
   160 void CAsyncFileRecognition::Start(const TDesC& aPath, const TDesC8& aDataType)
       
   161 	{
       
   162 	iPath = &aPath;
       
   163 	iDataType = &aDataType;
       
   164 	iStatus = KRequestPending;
       
   165 	iSession.SendReceive(EAppListServRecognizeFilesAsync,TIpcArgs(&aPath,&iRequiredBufferSizePckg,&aDataType),iStatus);
       
   166 	SetActive();
       
   167 	}
       
   168 
       
   169 CAsyncFileRecognition::~CAsyncFileRecognition()
       
   170 	{
       
   171 	Cancel();
       
   172 	iPath = NULL;
       
   173 	iDataType = NULL;
       
   174 	}
       
   175 
       
   176 void CAsyncFileRecognition::RunL()
       
   177 	{
       
   178 	iSession.FilesRecognized(*iPath, iRequiredBufferSizePckg(), iResult, iUsersRequestStatus, iStatus);
       
   179 	}
       
   180 
       
   181 void CAsyncFileRecognition::DoCancel()
       
   182 	{
       
   183 	iSession.SendReceive(ECancelRecognizeFiles,TIpcArgs(TIpcArgs::ENothing));
       
   184 	TRequestStatus* status = &iUsersRequestStatus;
       
   185 	User::RequestComplete( status, KErrCancel );
       
   186 	}
       
   187 
       
   188 //////////////////////////////
       
   189 // CApaLsSessionExtension
       
   190 //////////////////////////////
       
   191 
       
   192 CApaLsSessionExtension::CApaLsSessionExtension(RApaLsSession& aSession)
       
   193 	: iSession(aSession),
       
   194 	  iAsyncFileRecognition(NULL)
       
   195 	{
       
   196 	}
       
   197 
       
   198 CApaLsSessionExtension::~CApaLsSessionExtension()
       
   199 	{
       
   200 	delete iAsyncFileRecognition;
       
   201 	}
       
   202 
       
   203 void CApaLsSessionExtension::SendReceive(TInt aFunction,const TIpcArgs& aArgs,TRequestStatus& aStatus) const
       
   204 	{
       
   205 	iSession.SendReceive(aFunction,aArgs,aStatus); //lint !e1060 Suppress protected member is not accessible to non-member non-friend
       
   206 	}
       
   207 
       
   208 TInt CApaLsSessionExtension::SendReceive(TInt aFunction,const TIpcArgs& aArgs) const
       
   209 	{
       
   210 	return iSession.SendReceive(aFunction,aArgs); //lint !e1060 Suppress protected member is not accessible to non-member non-friend
       
   211 	}
       
   212 
       
   213 /**
       
   214 Asynchronous recognition of a directory.
       
   215 Function uses an internal CAsyncFileRecognition object to hide the 
       
   216 second server message (transferring the data to the client) from the user.
       
   217 When the path is not correct or the server is already busy with another 
       
   218 recognition request, the function completes the request with an error.
       
   219 @internalComponent
       
   220 */
       
   221 void CApaLsSessionExtension::RecognizeFilesL(const TDesC& aPath, const TDesC8& aDataType, CDataRecognitionResultArray& aResult, TRequestStatus& aStatus)
       
   222 	{
       
   223 	_LIT(KBackslash,"\\");
       
   224 
       
   225 	if(aPath.Right(1) != KBackslash)
       
   226 		{
       
   227 		TRequestStatus* status = &aStatus;
       
   228 		User::RequestComplete(status,KErrPathNotFound);
       
   229 		}
       
   230 	
       
   231 	aResult.SetPath(aPath);
       
   232 	aStatus = KRequestPending;
       
   233 
       
   234 	if(!iAsyncFileRecognition)
       
   235 		{
       
   236 		iAsyncFileRecognition = new (ELeave) CAsyncFileRecognition(aResult, aStatus, *this);
       
   237 		iAsyncFileRecognition->Start(aPath, aDataType);
       
   238 		}
       
   239 	else
       
   240 		{
       
   241 		TRequestStatus* status = &aStatus;
       
   242 		User::RequestComplete(status,KErrInUse);
       
   243 		}
       
   244 	}
       
   245 
       
   246 TBool CApaLsSessionExtension::RecognitionActive() const
       
   247 	{
       
   248 	return iAsyncFileRecognition ? ETrue : EFalse;
       
   249 	}
       
   250 
       
   251 void CApaLsSessionExtension::CancelRecognizeFiles()
       
   252 	{
       
   253 	if(iAsyncFileRecognition)
       
   254 		{
       
   255 		iAsyncFileRecognition->Cancel();
       
   256 		delete iAsyncFileRecognition;
       
   257 		iAsyncFileRecognition = NULL;
       
   258 		}
       
   259 	}
       
   260 
       
   261 void CApaLsSessionExtension::FilesRecognized(const TDesC& aPath, TInt aRequiredBufferSize, CDataRecognitionResultArray& aResult, TRequestStatus& aUsersRequestStatus, const TRequestStatus& aErrorCode)
       
   262 /**
       
   263 Callback function called by an CAsyncFileRecognition object, when an asynchronous
       
   264 recognition has finished. If the recognition was successful, the data is transferred
       
   265 to the client-side.
       
   266 @internalComponent
       
   267 */
       
   268 	{
       
   269 	TRequestStatus* status = &aUsersRequestStatus;
       
   270 	if(aErrorCode == KErrNone)
       
   271 		{
       
   272 		// transfer the result
       
   273 		TRAPD(error,iSession.TransferAndInternalizeDataL(aPath, aRequiredBufferSize, aResult));
       
   274 		User::RequestComplete(status, error);
       
   275 		}
       
   276 	else
       
   277 		{
       
   278 		User::RequestComplete(status, aErrorCode.Int());
       
   279 		}
       
   280 	delete iAsyncFileRecognition;
       
   281 	iAsyncFileRecognition = 0;
       
   282 	}
       
   283 
       
   284 
       
   285 ///////////////////////////////////////
       
   286 // CDataRecognitionResultArrayEntry
       
   287 ///////////////////////////////////////
       
   288 
       
   289 CDataRecognitionResultArrayEntry::CDataRecognitionResultArrayEntry(HBufC* aFileName, HBufC8* aDataType, TUid aUid, TInt aConfidence)
       
   290 	: iFileName(aFileName), 
       
   291 	  iDataType(aDataType), 
       
   292 	  iUid(aUid), 
       
   293 	  iConfidence(aConfidence)
       
   294 	{
       
   295 	}
       
   296 
       
   297 CDataRecognitionResultArrayEntry::~CDataRecognitionResultArrayEntry()
       
   298 	{
       
   299 	delete iFileName;
       
   300 	delete iDataType;
       
   301 	}
       
   302 
       
   303 void CDataRecognitionResultArrayEntry::GetDataRecognitionResult(TDataRecognitionResult& aResult) const
       
   304 	{
       
   305 	TDataRecognitionResult result;
       
   306 	if(iDataType->Length() != 0)
       
   307 		{
       
   308 		TDataType dataType(*iDataType);
       
   309 		result.iDataType = dataType;
       
   310 		}
       
   311 	else
       
   312 		{
       
   313 		TDataType dataType(iUid);
       
   314 		result.iDataType = dataType;
       
   315 		}
       
   316 	result.iConfidence = iConfidence;
       
   317 	aResult = result;
       
   318 	}
       
   319 
       
   320 const TDesC& CDataRecognitionResultArrayEntry::FileName() const
       
   321 	{
       
   322 	if (iFileName == NULL)
       
   323 		return KNullDesC;
       
   324 	else
       
   325 		return *iFileName;
       
   326 	}
       
   327 
       
   328 
       
   329 ///////////////////////////////////
       
   330 // CDataRecognitionResultArray
       
   331 ///////////////////////////////////
       
   332 
       
   333 /**
       
   334 Constructor
       
   335 @publishedAll
   155 @publishedAll
   336 @released
   156 @released
   337 */
   157 */
   338 EXPORT_C CDataRecognitionResultArray::CDataRecognitionResultArray()
   158 	{
   339 	{
   159 	CancelRecognizeFiles();
   340 	}
   160 	RHandleBase::Close();
   341 
   161 	}
   342 /**
       
   343 Destructor
       
   344 @publishedAll
       
   345 @released
       
   346 */
       
   347 EXPORT_C CDataRecognitionResultArray::~CDataRecognitionResultArray()
       
   348 	{
       
   349 	iEntries.ResetAndDestroy();
       
   350 	}
       
   351 
       
   352 /**
       
   353 Returns the path of the recognition results.
       
   354 @publishedAll
       
   355 @released
       
   356 @return The path of the recognition results
       
   357 */
       
   358 EXPORT_C const TFileName& CDataRecognitionResultArray::Path() const
       
   359 	{
       
   360 	return iPath;
       
   361 	}
       
   362 
       
   363 /**
       
   364 Returns the number of entries in the CDataRecognitionResultArray.
       
   365 @publishedAll
       
   366 @released
       
   367 @return The number of entries in the CDataRecognitionResultArray.
       
   368 */
       
   369 EXPORT_C TUint CDataRecognitionResultArray::Count() const
       
   370 	{
       
   371 	return iEntries.Count();
       
   372 	}
       
   373 
       
   374 /**
       
   375 Returns the recognition result of the given index.
       
   376 @publishedAll
       
   377 @released
       
   378 @param aResult On successful completion, this parameter contains the recognition result at the given index.
       
   379 @param aIndex The index of the recognition result to be returned. An invalid index causes
       
   380 the function to leave with KErrNotFound.
       
   381 @return The requested TDataRecognitionResult object
       
   382 @leave KErrNotFound An invalid index is passed
       
   383 */
       
   384 EXPORT_C void CDataRecognitionResultArray::GetDataRecognitionResultL(TDataRecognitionResult& aResult, const TUint aIndex) const
       
   385 	{
       
   386 	if( aIndex >= iEntries.Count() )
       
   387 		{
       
   388 		User::Leave(KErrNotFound);
       
   389 		}
       
   390 	iEntries[aIndex]->GetDataRecognitionResult(aResult);
       
   391 	}
       
   392 
       
   393 /**
       
   394 Returns the file name of the object at the given index.
       
   395 @publishedAll
       
   396 @released
       
   397 @param aFileName On successful completion, this parameter contains the file name of the object at the given index. 
       
   398 @param aIndex Specifies which file name to be returned. An invalid index causes
       
   399 the function to leave with KErrNotFound.
       
   400 @return The requested file name
       
   401 @leave KErrNotFound An invalid index is passed
       
   402 */
       
   403 EXPORT_C void CDataRecognitionResultArray::GetFileNameL(TFileName& aFileName, const TUint aIndex) const
       
   404 	{
       
   405 	if( aIndex >= iEntries.Count() )
       
   406 		{
       
   407 		User::Leave(KErrNotFound);
       
   408 		}
       
   409 	aFileName.Zero();
       
   410 	aFileName.Copy( (iEntries[aIndex]->FileName()) );
       
   411 	}
       
   412 
       
   413 TUint CDataRecognitionResultArray::InternalizeL(const CBufFlat& aBuffer)
       
   414 	{
       
   415 	RBufReadStream readStream;
       
   416 	
       
   417 	readStream.Open(aBuffer);
       
   418 	const TInt count=readStream.ReadUint32L();
       
   419 	for (TInt i=0; i<count; ++i)
       
   420 		{
       
   421 		const TInt fileNameLength = readStream.ReadUint8L();
       
   422 		HBufC* const fileName = HBufC::NewLC(fileNameLength);
       
   423 		TPtr fileNamePtr = fileName->Des();
       
   424 		readStream.ReadL(fileNamePtr,fileNameLength);
       
   425 
       
   426 		const TInt dataTypeLength = readStream.ReadUint8L();
       
   427 		HBufC8* const dataType = HBufC8::NewLC(dataTypeLength);
       
   428 		TPtr8 dataTypePtr = dataType->Des();
       
   429 		readStream.ReadL(dataTypePtr,dataTypeLength);
       
   430 
       
   431 		TUid uid;
       
   432 		uid.iUid = readStream.ReadInt32L();
       
   433 		
       
   434 		TInt const confidence = readStream.ReadInt32L();
       
   435 		
       
   436 		CDataRecognitionResultArrayEntry* entry = new (ELeave) CDataRecognitionResultArrayEntry(fileName,dataType,uid,confidence);
       
   437 		iEntries.Append(entry);
       
   438 		
       
   439 		CleanupStack::Pop(dataType);	// ownership was transferred to "entry"
       
   440 		CleanupStack::Pop(fileName);	// ownership was transferred to "entry"
       
   441 		}
       
   442 
       
   443 	readStream.Close();
       
   444 		
       
   445 	return KErrNone;
       
   446 	}
       
   447 
       
   448 void CDataRecognitionResultArray::SetPath(const TFileName& aPath)
       
   449 	{
       
   450 	iPath.Copy(aPath);
       
   451 	}
       
   452 
       
   453 ////////////////////////////////////
       
   454 //RApaLsSession
       
   455 ////////////////////////////////////
       
   456 
       
   457 EXPORT_C RApaLsSession::RApaLsSession()
       
   458 	: iExtension(0)
       
   459 	{}
       
   460 
       
   461 
       
   462 
       
   463 /** Connects a client to the application architecture server, creating a session 
       
   464 with it.
       
   465 
       
   466 @return KErrNone if successful; otherwise, one of the system-wide error codes. 
       
   467 */
       
   468 EXPORT_C TInt RApaLsSession::Connect()
       
   469 	{
       
   470 	TInt r=CreateSession(KAppListServerName,Version(),KAsyncMessageSlots);
       
   471 	return(r); 
       
   472 	}
       
   473 
       
   474 
   162 
   475 
   163 
   476 /** Gets the version of the application architecture server.
   164 /** Gets the version of the application architecture server.
   477 
   165 
   478 @return The version number. 
   166 @return The version number. 
   479 */
   167 */
   480 EXPORT_C TVersion RApaLsSession::Version(void) const
   168 EXPORT_C TVersion RApaLsSession::Version(void) const
   481 	{
   169 	{
   482 	return(TVersion(KAppListServMajorVersionNumber,KAppListServMinorVersionNumber,KAppListServBuildVersionNumber));
   170 	return(TVersion(KAppListServMajorVersionNumber,KAppListServMinorVersionNumber,KAppListServBuildVersionNumber));
   483 	}
   171 	}
   484 
       
   485 
   172 
   486 
   173 
   487 /** Gets the total number of applications.
   174 /** Gets the total number of applications.
   488 
   175 
   489 Control panel applications are excluded.
   176 Control panel applications are excluded.
   491 @param aCount On return, the total number of applications.
   178 @param aCount On return, the total number of applications.
   492 @return KErrNone if successful, otherwise one of the system-wide error codes. 
   179 @return KErrNone if successful, otherwise one of the system-wide error codes. 
   493 */
   180 */
   494 EXPORT_C TInt RApaLsSession::AppCount(TInt& aCount) const
   181 EXPORT_C TInt RApaLsSession::AppCount(TInt& aCount) const
   495 	{
   182 	{
   496 	return DoAppCount(aCount,EAppListServAppCount);
   183 	return DoAppCount(aCount, EAppListServAppCount);
   497 	}
   184 	}
   498 
       
   499 
   185 
   500 
   186 
   501 /** Gets the total number of embeddable applications.
   187 /** Gets the total number of embeddable applications.
   502 
   188 
   503 Control panel applications are excluded.
   189 Control panel applications are excluded.
   505 @param aCount On return, the total number of embeddable applications.
   191 @param aCount On return, the total number of embeddable applications.
   506 @return KErrNone, if successful, otherwise one of the system-wide error codes. 
   192 @return KErrNone, if successful, otherwise one of the system-wide error codes. 
   507 */
   193 */
   508 EXPORT_C TInt RApaLsSession::EmbeddableAppCount(TInt& aCount) const
   194 EXPORT_C TInt RApaLsSession::EmbeddableAppCount(TInt& aCount) const
   509 	{
   195 	{
   510 	return DoAppCount(aCount,EAppListServEmbedCount);
   196 	return DoAppCount(aCount, EAppListServEmbedCount);
   511 	}
   197 	}
       
   198 
   512 
   199 
   513 TInt RApaLsSession::DoAppCount(TInt& aCount,TInt aCommand) const
   200 TInt RApaLsSession::DoAppCount(TInt& aCount,TInt aCommand) const
   514 // returns the number of embeddable apps in the server side list
   201 // returns the number of embeddable apps in the server side list
   515 	{
   202 	{
   516 	__ASSERT_DEBUG(aCommand==EAppListServEmbedCount || aCommand==EAppListServAppCount,Panic(EDPanicWrongCommand));
   203 	__ASSERT_DEBUG(aCommand==EAppListServEmbedCount || aCommand==EAppListServAppCount,Panic(EDPanicWrongCommand));
   517 	const TInt returnValue=SendReceiveWithReconnect(aCommand,TIpcArgs());
   204 	const TInt returnValue = SendReceiveWithReconnect(aCommand,TIpcArgs());
   518 	if (returnValue<0)
   205 	if (returnValue < 0)
   519 		{
       
   520 		return returnValue;
   206 		return returnValue;
   521 		}
   207 	
   522 	aCount=returnValue;
   208 	aCount = returnValue;
   523 	return KErrNone;
   209 	return KErrNone;
   524 	}
   210 	}
   525 
   211 
   526 
   212 
   527 
   213 
   536 */
   222 */
   537 EXPORT_C TInt RApaLsSession::GetAllApps() const
   223 EXPORT_C TInt RApaLsSession::GetAllApps() const
   538 	{
   224 	{
   539 	return GetAllApps(0);
   225 	return GetAllApps(0);
   540 	}
   226 	}
   541 
       
   542 
   227 
   543 
   228 
   544 /** Initialises the process of getting all applications in the cached list.
   229 /** Initialises the process of getting all applications in the cached list.
   545 
   230 
   546 Control panel applications are excluded.
   231 Control panel applications are excluded.
   711 EXPORT_C TInt RApaLsSession::GetServerApps(TUid aServiceUid) const
   396 EXPORT_C TInt RApaLsSession::GetServerApps(TUid aServiceUid) const
   712 	{
   397 	{
   713 	return GetServerApps(aServiceUid, 0);
   398 	return GetServerApps(aServiceUid, 0);
   714 	}
   399 	}
   715 
   400 
   716 
       
   717 
       
   718 /** Initialises the process of getting server applications in the cached list.
   401 /** Initialises the process of getting server applications in the cached list.
   719 
   402 
   720 Control panel applications are excluded.
   403 Control panel applications are excluded.
   721 
   404 
   722 A call to this function is followed by subsequent and repeated calls to GetNextApp() 
   405 A call to this function is followed by subsequent and repeated calls to GetNextApp() 
   735 EXPORT_C TInt RApaLsSession::GetServerApps(TUid aServiceUid, TInt aScreenMode) const
   418 EXPORT_C TInt RApaLsSession::GetServerApps(TUid aServiceUid, TInt aScreenMode) const
   736 	{
   419 	{
   737 	return SendReceiveWithReconnect(EAppListServInitServerAppList,TIpcArgs(aScreenMode, aServiceUid.iUid));
   420 	return SendReceiveWithReconnect(EAppListServInitServerAppList,TIpcArgs(aScreenMode, aServiceUid.iUid));
   738 	}
   421 	}
   739 
   422 
   740 
       
   741 
       
   742 /** Gets information about the next application or embeddable application from 
   423 /** Gets information about the next application or embeddable application from 
   743 the cached list.
   424 the cached list.
   744 
   425 
   745 A sequence of calls to this function must always be preceded by a call to 
   426 A sequence of calls to this function must always be preceded by a call to 
   746 one of GetAllApps(), GetEmbeddableApps() or GetFilteredApps().
   427 one of GetAllApps(), GetEmbeddableApps() or GetFilteredApps().
   752 */
   433 */
   753 EXPORT_C TInt RApaLsSession::GetNextApp(TApaAppInfo& aInfo) const
   434 EXPORT_C TInt RApaLsSession::GetNextApp(TApaAppInfo& aInfo) const
   754 	{
   435 	{
   755 	return GetNextApp(aInfo,0);
   436 	return GetNextApp(aInfo,0);
   756 	}
   437 	}
   757 
       
   758 
       
   759 
   438 
   760 /** Gets information about the next application or embeddable application from 
   439 /** Gets information about the next application or embeddable application from 
   761 the cached list.
   440 the cached list.
   762 
   441 
   763 A sequence of calls to this function must always be preceded by a call to 
   442 A sequence of calls to this function must always be preceded by a call to 
   770 not completed; otherwise one of the other system wide error codes. 
   449 not completed; otherwise one of the other system wide error codes. 
   771 */
   450 */
   772 EXPORT_C TInt RApaLsSession::GetNextApp(TApaAppInfo& aInfo,TInt aScreenMode) const
   451 EXPORT_C TInt RApaLsSession::GetNextApp(TApaAppInfo& aInfo,TInt aScreenMode) const
   773 	{
   452 	{
   774 	TPckg<TApaAppInfo> info(aInfo);
   453 	TPckg<TApaAppInfo> info(aInfo);
   775 	TInt ret=SendReceiveWithReconnect(EAppListServGetNextApp,TIpcArgs(aScreenMode,&info));
   454 	TInt err = SendReceiveWithReconnect(EAppListServGetNextApp, TIpcArgs(aScreenMode,&info));
   776 	if (ret==KErrNone)
   455 	if (!err)
   777 		aInfo = info();
   456 		aInfo = info();
   778 	else if (ret==KErrNotFound)
   457 	else if (err==KErrNotFound)
   779 		ret = ENoMoreAppsInList;
   458 		err = ENoMoreAppsInList;
   780 	else if (ret==KErrCorrupt)
   459 	else if (err==KErrCorrupt)
   781 		ret = EAppListInvalid;
   460 		err = EAppListInvalid;
   782 	return ret;
   461 	
       
   462 	return err;
   783 	}
   463 	}
   784 
   464 
   785 
   465 
   786 
   466 
   787 /** Gets information about the application with the specified UID.
   467 /** Gets information about the application with the specified UID.
   791 this object is not changed.
   471 this object is not changed.
   792 @param aAppUid The application specific UID.
   472 @param aAppUid The application specific UID.
   793 @return KErrNone if successful; KErrNotFound if a matching entry could not be found; 
   473 @return KErrNone if successful; KErrNotFound if a matching entry could not be found; 
   794 otherwise one of the other system wide error codes. 
   474 otherwise one of the other system wide error codes. 
   795 */
   475 */
   796 EXPORT_C TInt RApaLsSession::GetAppInfo(TApaAppInfo& aInfo,TUid aAppUid) const
   476 EXPORT_C TInt RApaLsSession::GetAppInfo(TApaAppInfo& aInfo, TUid aAppUid) const
   797 	{
   477 	{
   798 	TPckg<TApaAppInfo> info(aInfo);
   478 	TPckg<TApaAppInfo> info(aInfo);
   799 	return SendReceiveWithReconnect(EAppListServGetAppInfo,TIpcArgs(aAppUid.iUid,&info));
   479 	return SendReceiveWithReconnect(EAppListServGetAppInfo, TIpcArgs(aAppUid.iUid,&info));
   800 	} //lint !e1764 Suppress reference parameter 'aInfo' could be declared const ref
   480 	} //lint !e1764 Suppress reference parameter 'aInfo' could be declared const ref
   801 	
   481 	
   802 /** Sets the short caption of the application.
   482 /** Sets the short caption of the application.
   803 
   483 
   804 Overrides the short caption specified in the localizable resource file for this application.
   484 Overrides the short caption specified in the localizable resource file for this application.
   811 @return KErrNone if successful, otherwise one of the system wide error codes.
   491 @return KErrNone if successful, otherwise one of the system wide error codes.
   812 */ 
   492 */ 
   813 EXPORT_C TInt RApaLsSession::SetAppShortCaption(const TDesC& aShortCaption, TLanguage aLanguage, TUid aAppUid)
   493 EXPORT_C TInt RApaLsSession::SetAppShortCaption(const TDesC& aShortCaption, TLanguage aLanguage, TUid aAppUid)
   814 	{
   494 	{
   815 	if (aShortCaption.Length() > KApaMaxAppCaption || aShortCaption.Length() == 0)
   495 	if (aShortCaption.Length() > KApaMaxAppCaption || aShortCaption.Length() == 0)
   816 		{
       
   817 		return KErrArgument;
   496 		return KErrArgument;
   818 		}
   497 
   819 	return SendReceiveWithReconnect(EAppListServSetAppShortCaption, TIpcArgs(aAppUid.iUid, &aShortCaption, aLanguage));
   498 	return SendReceiveWithReconnect(EAppListServSetAppShortCaption, TIpcArgs(aAppUid.iUid, &aShortCaption, aLanguage));
   820 	} //lint !e1762 Suppress member function could be made const
   499 	} //lint !e1762 Suppress member function could be made const
       
   500 
   821 
   501 
   822 /** Gets the default screen-number of the application with the specified UID.
   502 /** Gets the default screen-number of the application with the specified UID.
   823 
   503 
   824 @param aDefaultScreenNumber On return, contains the default screen-number, if an application 
   504 @param aDefaultScreenNumber On return, contains the default screen-number, if an application 
   825 with the specified UID is found. If no matching application is found, then 
   505 with the specified UID is found. If no matching application is found, then 
   828 @return KErrNone if successful; KErrNotFound if a matching entry could not be found; 
   508 @return KErrNone if successful; KErrNotFound if a matching entry could not be found; 
   829 otherwise one of the other system wide error codes. 
   509 otherwise one of the other system wide error codes. 
   830 */
   510 */
   831 EXPORT_C TInt RApaLsSession::GetDefaultScreenNumber(TInt& aDefaultScreenNumber, TUid aAppUid) const
   511 EXPORT_C TInt RApaLsSession::GetDefaultScreenNumber(TInt& aDefaultScreenNumber, TUid aAppUid) const
   832 	{
   512 	{
   833 	const TInt result=SendReceiveWithReconnect(EAppListServGetDefaultScreenNumber, TIpcArgs(aAppUid.iUid));
   513 	const TInt result = SendReceiveWithReconnect(EAppListServGetDefaultScreenNumber, TIpcArgs(aAppUid.iUid));
   834 	if (result<0)
   514 	if (result < 0)
   835 		{
       
   836 		return result;
   515 		return result;
   837 		}
   516 
   838 	aDefaultScreenNumber=result;
   517 	aDefaultScreenNumber = result;
   839 	return KErrNone;
   518 	return KErrNone;
   840 	}
   519 	}
   841 
   520 
   842 
   521 
   843 /** Gets the capabilities of the application with the specified UID.
   522 /** Gets the capabilities of the application with the specified UID.
   854 	{
   533 	{
   855 	return SendReceiveWithReconnect(EAppListServGetAppCapability,TIpcArgs(&aCapabilityBuf,aAppUid.iUid));
   534 	return SendReceiveWithReconnect(EAppListServGetAppCapability,TIpcArgs(&aCapabilityBuf,aAppUid.iUid));
   856 	}
   535 	}
   857 
   536 
   858 
   537 
   859 
       
   860 /** Starts an application defined by the specified command line information.
       
   861     This is an asynchronous method which doesn't wait for the process creation to complete.
       
   862     To be informed of the process creation success, 
       
   863     then appropriate overloaded method taking a TRequestStatus parameter should be used.
       
   864     
       
   865 This is only recommended for non document based applications.
       
   866 
       
   867 View based applications are usually started by activating a specific view 
       
   868 using CCoeAppUi::ActivateViewL. Alternatively, using StartApp() to start a 
       
   869 view based application will activate the application's default view.
       
   870 
       
   871 @param aCommandLine The command line.
       
   872 @return KErrNone, if successful; KErrNotFound, if the application cannot be 
       
   873 found; otherwise one of the other system-wide error codes. 
       
   874 @see CCoeAppUi::ActivateViewL() 
       
   875 */
       
   876 EXPORT_C TInt RApaLsSession::StartApp(const CApaCommandLine& aCommandLine)
       
   877 	{
       
   878 	return DoStartApp(aCommandLine, NULL,NULL);
       
   879 	}
       
   880 	
       
   881 /** Starts an application defined by the specified command line information.
       
   882     This is an asynchronous method which doesn't wait for the process creation to complete.
       
   883     To be informed of the process creation success, 
       
   884     then appropriate overloaded method taking a TRequestStatus parameter should be used.
       
   885 
       
   886 This is only recommended for non document based applications.
       
   887 
       
   888 View based applications are usually started by activating a specific view 
       
   889 using CCoeAppUi::ActivateViewL. Alternatively, using StartApp() to start a 
       
   890 view based application will activate the application's default view.
       
   891 
       
   892 @param aCommandLine The command line.
       
   893 @param aThreadId On return, the id of the main thread started.
       
   894 @return KErrNone, if successful; KErrNotFound, if the application cannot be 
       
   895 found; otherwise one of the other system-wide error codes. 
       
   896 @see CCoeAppUi::ActivateViewL() 
       
   897 */	
       
   898 EXPORT_C TInt RApaLsSession::StartApp(const CApaCommandLine& aCommandLine,TThreadId& aThreadId)
       
   899 	{
       
   900 	return DoStartApp(aCommandLine, &aThreadId,NULL);
       
   901 	}
       
   902 
       
   903 	
       
   904 /** Starts an application defined by the specified command line information.
       
   905 
       
   906 This is only recommended for non document based applications.
       
   907 
       
   908 View based applications are usually started by activating a specific view 
       
   909 using CCoeAppUi::ActivateViewL. Alternatively, using StartApp() to start a 
       
   910 view based application will activate the application's default view.
       
   911 
       
   912 @param aCommandLine The command line.
       
   913 @param aThreadId On return, the id of the main thread started.
       
   914 @param aRequestStatusForRendezvous If not NULL, the asynchronous RProcess::Rendezvous() 
       
   915 function is called (being passed this TRequestStatus object) before RProcess::Resume() is called on 
       
   916 the new application process. If this function does not return KErrNone, RProcess::Rendezvous() will
       
   917 not be called passing aRequestStatusForRendezvous, so in this case the caller must not wait
       
   918 on aRequestStatusForRendezvous.
       
   919 @return KErrNone, if successful; KErrNotFound, if the application cannot be 
       
   920 found; otherwise one of the other system-wide error codes. 
       
   921 @see CCoeAppUi::ActivateViewL() 
       
   922 */
       
   923 EXPORT_C TInt RApaLsSession::StartApp(const CApaCommandLine& aCommandLine,TThreadId& aThreadId,TRequestStatus* aRequestStatusForRendezvous )
       
   924 	{
       
   925 	return DoStartApp(aCommandLine, &aThreadId,aRequestStatusForRendezvous);
       
   926 	}
       
   927 
       
   928 
       
   929 TInt RApaLsSession::DoStartApp(const CApaCommandLine& aCommandLine, TThreadId* aThreadId,TRequestStatus* aRequestStatusForRendezvous)
       
   930 	{
       
   931 	TRAPD(error, DoStartAppL(aCommandLine, aThreadId, aRequestStatusForRendezvous));
       
   932 	return error;
       
   933 	}
       
   934 
       
   935 void RApaLsSession::DoStartAppL(const CApaCommandLine& aCommandLine, TThreadId* aThreadId,TRequestStatus* aRequestStatusForRendezvous)
       
   936 	{
       
   937 	// This function does not require "this" object to be connected to the Apparc server,
       
   938 	// but if not, it works with some limitations (see the following document for a list
       
   939 	// of these limitations: 
       
   940 	// generic/app-framework/Documentation/PREQ967_solution_constraints.doc).
       
   941 
       
   942 #if defined(USE_IH_RAISE_EVENT)
       
   943 	const TInt appStartupInstrumentationEventIdBase=aCommandLine.AppStartupInstrumentationEventIdBase();
       
   944 	if (appStartupInstrumentationEventIdBase!=0)
       
   945 		{
       
   946 		IH_DECLARE( lInstrumentationHandler );
       
   947 		IH_CREATE( lInstrumentationHandler );
       
   948 		IH_RAISE_EVENT( lInstrumentationHandler, appStartupInstrumentationEventIdBase+MTestInstrumentation::TIDOffsetBeginApplicationFirstRedraw );
       
   949 		IH_RAISE_EVENT( lInstrumentationHandler, appStartupInstrumentationEventIdBase+MTestInstrumentation::TIDOffsetBeginApplicationReadyForInput );
       
   950 		IH_DELETE( lInstrumentationHandler );
       
   951 		}
       
   952 #endif
       
   953 
       
   954  	// Retrieve the executable name from the CApaCommandLine object passed in.
       
   955 	const TPtrC logicalExecutableName(aCommandLine.ExecutableName());
       
   956 	// Rule-based app launching is not allowed unless there is a connected RApaLsSession object.
       
   957 	if(Handle() != KNullHandle)
       
   958 		{
       
   959 		// requesting from rule-based plug-ins if we can run an application 
       
   960 		// if server fails while requested rule-based plug-ins it returns a negative value - proceed with launching the application in this case
       
   961 		TBool okayToRun = SendReceiveWithReconnect(EAppListServRuleBasedLaunching, TIpcArgs(&logicalExecutableName));
       
   962 		if(!okayToRun)
       
   963 			{
       
   964 			User::Leave(KErrCancel);
       
   965 			}
       
   966 		}
       
   967 
       
   968 	TFileName nativeExecutableNameOfNonNativeApplication;
       
   969 	RProcess process;
       
   970 	HBufC8* opaqueData=NULL;
       
   971 	CleanupStack::PushL(TCleanupItem(DeletePointerToPointerToTAny, &opaqueData));
       
   972 
       
   973 	// if we're connected to the Apparc server, try to get the opaque-data and native-executable name
       
   974 	// (the latter is only if it's a non-native application that we're launching)
       
   975 	if (Handle()!=KNullHandle)
       
   976 		{
       
   977 		const TInt lengthOfOpaqueData=User::LeaveIfError(SendReceiveWithReconnect(EAppListServGetNativeExecutableNameIfNonNative, TIpcArgs(&nativeExecutableNameOfNonNativeApplication, &logicalExecutableName)));
       
   978 		if (lengthOfOpaqueData>0)
       
   979 			{
       
   980 			User::LeaveIfError(GetOpaqueData(opaqueData, lengthOfOpaqueData));
       
   981 			}
       
   982 		}
       
   983 
       
   984 	// try first to create the application process without interacting with the Apparc server at all - 
       
   985 	// assumes "logicalExecutableName" is itself a native executable
       
   986 	TUidType uidType(KNullUid, KNullUid, KNullUid);
       
   987 	TInt err = process.CreateWithStackOverride(logicalExecutableName, KNullDesC, uidType, MinApplicationStackSize(), EOwnerProcess);
       
   988 	 
       
   989 	// If we haven't been able to create the process using the native executable name from the command line
       
   990 	// object, instead try to create it using the native executable name of the non-native application.
       
   991 	// Can only do this if apparc is connected and thus this name has been retrieved above and 
       
   992 	// nativeExecutableNameOfNonNativeApplication populated.
       
   993 	if ((err != KErrNone) && nativeExecutableNameOfNonNativeApplication.Length()>0)
       
   994 			{
       
   995 			err = process.CreateWithStackOverride(nativeExecutableNameOfNonNativeApplication, KNullDesC, uidType, MinApplicationStackSize(), EOwnerProcess);
       
   996 			}
       
   997 
       
   998 	// if we managed to create the process via either of the two methods attempted above (with the native 
       
   999 	// name or the native name of the non-native app), finish setting it up and "resume" it
       
  1000 	if (err == KErrNone)
       
  1001 		{
       
  1002 		CleanupStack::PushL(TCleanupItem(CleanupOperation, &process));
       
  1003 		if (opaqueData!=NULL)
       
  1004 			{
       
  1005 			const_cast<CApaCommandLine&>(aCommandLine).SetOpaqueDataL(*opaqueData);
       
  1006 			}
       
  1007 		aCommandLine.SetProcessEnvironmentL(process);
       
  1008 		if (aThreadId!=NULL)
       
  1009 			{
       
  1010 			GetThreadIdL(*aThreadId, process);
       
  1011 			}
       
  1012 		if (aRequestStatusForRendezvous!=NULL)
       
  1013 			{
       
  1014 			process.Rendezvous(*aRequestStatusForRendezvous);
       
  1015 			}
       
  1016 		// Note - must not leave between here and the end of this method because we only expect
       
  1017 		// the caller to wait on aRequestStatusForRendezvous if this method does not leave.
       
  1018 		if(aRequestStatusForRendezvous != NULL && *aRequestStatusForRendezvous != KRequestPending)
       
  1019 			{
       
  1020 			User::WaitForRequest(*aRequestStatusForRendezvous);
       
  1021 			User::Leave(aRequestStatusForRendezvous->Int()); // item on cleanupstack terminates and closes the process
       
  1022 			}
       
  1023 		else
       
  1024 			{
       
  1025 			process.Resume();	
       
  1026 			}
       
  1027 		CleanupStack::Pop(&process);	
       
  1028 		process.Close();
       
  1029 		}
       
  1030 	else // Couldn't create a process
       
  1031 		{
       
  1032 		if (Handle()==KNullHandle) // not connected to apparc
       
  1033 			{
       
  1034 			const TPtrC executableName(aCommandLine.ExecutableName());
       
  1035 			
       
  1036 			// Java applications have an empty ExecutableName, as they use the CApaCommandLine's
       
  1037 			// opaque-data attribute. Not connected to apparc so can't start a non-native app.
       
  1038 			// Therefore we should handle this case with KErrNotSupported rather than whatever
       
  1039 			// RProcess::Create returns when passed an empty descriptor.  
       
  1040 			if (executableName.Length() == 0)
       
  1041 				{
       
  1042 				User::Leave(KErrNotSupported);
       
  1043 				}
       
  1044 				
       
  1045 			// Otherwise return the error code from RProcess::Create.
       
  1046 			User::Leave(err);
       
  1047 			
       
  1048 			}
       
  1049 		else // Handle()!=KNullHandle
       
  1050 			{
       
  1051 			// we can only proceed with the remaining option if we're connected to the Apparc server	
       
  1052 			// as a last resort, try use the legacy file-recognizer framework to launch the application
       
  1053 			TThreadId dummyThreadId;
       
  1054 			TPckg<TThreadId> threadId((aThreadId!=NULL)? *aThreadId: dummyThreadId);
       
  1055 			const TInt opcode=(aThreadId==NULL)?
       
  1056 									EAppListServStartAppWithoutReturningThreadId:
       
  1057 									EAppListServStartAppReturningThreadId;
       
  1058 			TIpcArgs ipcArgs;
       
  1059 			aCommandLine.GetIpcArgsLC(ipcArgs);
       
  1060 			if (aThreadId!=NULL)
       
  1061 				{
       
  1062 				ipcArgs.Set(CApaCommandLine::EIpcFirstFreeSlot, &threadId);
       
  1063 				}
       
  1064 			User::LeaveIfError(SendReceiveWithReconnect(opcode, ipcArgs));
       
  1065 			if (aRequestStatusForRendezvous!=NULL)
       
  1066 				{
       
  1067 				User::RequestComplete(aRequestStatusForRendezvous,KErrNone);
       
  1068 				}
       
  1069 			CleanupStack::PopAndDestroy(); // the TIpcArgs
       
  1070 			}
       
  1071 		}
       
  1072 	CleanupStack::PopAndDestroy(&opaqueData);
       
  1073 	} //lint !e1762 Suppress member function could be made const
       
  1074 	
       
  1075 void RApaLsSession::CleanupOperation(TAny* aAny)
       
  1076 	{
       
  1077 	RProcess* activeProcess = reinterpret_cast<RProcess*>(aAny);	
       
  1078 	activeProcess->Terminate(KErrGeneral);
       
  1079 	activeProcess->Close();
       
  1080 	}
       
  1081 	
       
  1082 void RApaLsSession::GetThreadIdL(TThreadId& aThreadId, const RProcess& aProcess)
       
  1083 	{ // static
       
  1084 	TFullName fullName(aProcess.Name());
       
  1085 	_LIT(KCCMain,"::Main");
       
  1086 	fullName.Append(KCCMain);
       
  1087 	RThread thread;
       
  1088 	User::LeaveIfError(thread.Open(fullName,EOwnerThread));
       
  1089 	aThreadId=thread.Id();
       
  1090 	thread.Close();
       
  1091 	}
       
  1092 
       
  1093 void RApaLsSession::DeletePointerToPointerToTAny(TAny* aPointerToPointerToTAny)
       
  1094 	{ // static
       
  1095 	__ASSERT_ALWAYS(aPointerToPointerToTAny, Panic(EPanicNullPointer));
       
  1096 	delete *static_cast<TAny**>(aPointerToPointerToTAny); //lint !e613 Suppress possible use of null pointer
       
  1097 	} //lint !e818 Suppress pointer parameter could be declared as pointing to const
       
  1098 
       
  1099 /**
       
  1100 Sets up slots 0 and 1 in aIpcArgs - assumes that slots 2 and 3 have already been set up; 
       
  1101 it then invokes aOpcode
       
  1102 */
       
  1103 TInt RApaLsSession::GetExecutableName(TDes& aNativeExecutableName, TDes& aLogicalExecutableName, HBufC8*& aOpaqueData, TIpcArgs& aIpcArgs, TInt aOpcode) const
       
  1104 	{
       
  1105 	aNativeExecutableName.SetLength(0); // if this comes out zero-length from EAppListServExecutableNameForXxx below then use the logicalExecutableName in RProcess::Create (in this case it's a native C++ application)
       
  1106 	aIpcArgs.Set(0, &aNativeExecutableName);
       
  1107 	aIpcArgs.Set(1, &aLogicalExecutableName);
       
  1108 	const TInt lengthOfOpaqueData=SendReceiveWithReconnect(aOpcode, aIpcArgs);
       
  1109 	if (lengthOfOpaqueData<0)
       
  1110 		{
       
  1111 		return lengthOfOpaqueData; // it's an error code
       
  1112 		}
       
  1113 	if (lengthOfOpaqueData>0)
       
  1114 		{
       
  1115 		return GetOpaqueData(aOpaqueData, lengthOfOpaqueData);
       
  1116 		}
       
  1117 	aOpaqueData=NULL;
       
  1118 	return KErrNone;
       
  1119 	}
       
  1120 
       
  1121 TInt RApaLsSession::GetOpaqueData(HBufC8*& aOpaqueData, TInt aLengthOfOpaqueData) const
       
  1122 	{
       
  1123 	HBufC8* const opaqueData=HBufC8::New(aLengthOfOpaqueData);
       
  1124 	if (opaqueData==NULL)
       
  1125 		{
       
  1126 		return KErrNoMemory;
       
  1127 		}
       
  1128 	TPtr8 opaqueData_asWritable(opaqueData->Des());
       
  1129 	const TInt error=SendReceiveWithReconnect(EAppListServGetOpaqueData, TIpcArgs(&opaqueData_asWritable));
       
  1130 	if (error!=KErrNone)
       
  1131 		{
       
  1132 		delete opaqueData;
       
  1133 		return error;
       
  1134 		}
       
  1135 	aOpaqueData=opaqueData;
       
  1136 	return error;
       
  1137 	}
       
  1138 
       
  1139 TInt RApaLsSession::StartApplicationPassingFileHandle(const TDesC& aNativeExecutableName, const TDesC& aLogicalExecutableName, const TDesC8* aOpaqueData, const RFile& aFile, TThreadId& aThreadId, TRequestStatus* aRequestStatusForRendezvous)
       
  1140 	{
       
  1141 	TFileName documentName;
       
  1142 	aFile.FullName(documentName);
       
  1143 	CApaCommandLine* commandLine=NULL;	
       
  1144 	TRAPD(error, commandLine=CApaCommandLine::NewLC();
       
  1145 			commandLine->SetCommandL(EApaCommandOpen);
       
  1146 			commandLine->SetExecutableNameL(aLogicalExecutableName);
       
  1147 			commandLine->SetFileByHandleL(aFile);
       
  1148 			commandLine->SetDocumentNameL(documentName);
       
  1149 			if (aOpaqueData!=NULL)
       
  1150 				{
       
  1151 				commandLine->SetOpaqueDataL(*aOpaqueData);
       
  1152 				}
       
  1153 			StartApplicationL(aNativeExecutableName, *commandLine, aThreadId, aRequestStatusForRendezvous);
       
  1154 			CleanupStack::PopAndDestroy(commandLine));
       
  1155 	return error;
       
  1156 	}
       
  1157 	
       
  1158 TInt RApaLsSession::StartApplicationPassingDocumentName(const TDesC& aNativeExecutableName, const TDesC& aLogicalExecutableName, const TDesC8* aOpaqueData, const TDesC& aDocumentName, TThreadId& aThreadId,TApaCommand aCommand, TRequestStatus* aRequestStatusForRendezvous)
       
  1159 	{
       
  1160 	CApaCommandLine* commandLine=NULL;
       
  1161 	TRAPD(error, commandLine=CApaCommandLine::NewLC();
       
  1162 			commandLine->SetCommandL(aCommand);
       
  1163 			commandLine->SetExecutableNameL(aLogicalExecutableName);
       
  1164 			commandLine->SetDocumentNameL(aDocumentName);
       
  1165 			if (aOpaqueData!=NULL)
       
  1166 				{
       
  1167 				commandLine->SetOpaqueDataL(*aOpaqueData);
       
  1168 				}
       
  1169 			StartApplicationL(aNativeExecutableName, *commandLine, aThreadId, aRequestStatusForRendezvous);
       
  1170 			CleanupStack::PopAndDestroy(commandLine));
       
  1171 	return error;
       
  1172 	}
       
  1173 
       
  1174 void RApaLsSession::StartApplicationL(const TDesC& aNativeExecutableName, const CApaCommandLine& aCommandLine, TThreadId& aThreadId, TRequestStatus* aRequestStatusForRendezvous)
       
  1175 	{ 
       
  1176 	RProcess process;
       
  1177 	TPtrC actualNativeExecutableName(aNativeExecutableName);
       
  1178 	if (actualNativeExecutableName.Length()==0)
       
  1179 		{
       
  1180 		actualNativeExecutableName.Set(aCommandLine.ExecutableName()); // it's a native C++ application, rather than a MIDlet, Python script, etc
       
  1181 		}
       
  1182 
       
  1183 	if(Handle() != KNullHandle)
       
  1184 		{
       
  1185 		//requesting from rule-based plug-ins if we can run an application 
       
  1186 		TBool okayToRun = SendReceiveWithReconnect(EAppListServRuleBasedLaunching, TIpcArgs(&actualNativeExecutableName));
       
  1187 		//If server fails while requested rule-based plug-ins it returns a negative value. 
       
  1188 		//We shall proceed with launching an application in this case.
       
  1189 		if(!okayToRun)
       
  1190 			{
       
  1191 			User::Leave(KErrCancel); 
       
  1192 			}
       
  1193 		}
       
  1194 
       
  1195 	TUidType uidType(KNullUid, KNullUid, KNullUid);
       
  1196 	User::LeaveIfError(process.CreateWithStackOverride(actualNativeExecutableName, KNullDesC, uidType, MinApplicationStackSize(), EOwnerProcess)); // RProcess::CreateWithStackOveride - TESTED
       
  1197 		
       
  1198 	CleanupClosePushL(process);
       
  1199 	aCommandLine.SetProcessEnvironmentL(process);
       
  1200 	GetThreadIdL(aThreadId, process);
       
  1201 	if (aRequestStatusForRendezvous!=NULL)
       
  1202 		{
       
  1203 		process.Rendezvous(*aRequestStatusForRendezvous);
       
  1204 		}
       
  1205 	process.Resume();
       
  1206 	CleanupStack::PopAndDestroy(&process);
       
  1207 	} //lint !e1762 Suppress member function could be made const
       
  1208 
       
  1209 
       
  1210 
       
  1211 /** Gets the data (MIME) type for data taken from a file with a specified name.
       
  1212 
       
  1213 @param aName The full filename, including drive and path, of the file containing the data.
       
  1214 @param aBuffer A buffer containing data taken from the specified file; typically 
       
  1215 the data is read from the beginning of the file.
       
  1216 @param aDataType On return, contains the result of the attempt to recognize 
       
  1217 data. 
       
  1218 @return KErrNone, if successful; otherwise one of the other system-wide error 
       
  1219 codes. 
       
  1220 */
       
  1221 EXPORT_C TInt RApaLsSession::RecognizeData(const TDesC& aName, const TDesC8& aBuffer, TDataRecognitionResult& aDataType) const
       
  1222 	{
       
  1223 	TPckg<TDataRecognitionResult> result(aDataType);
       
  1224 	return SendReceiveWithReconnect(EAppListServRecognizeData,TIpcArgs(&result, &aName, &aBuffer));
       
  1225 	} //lint !e1764: Suppress reference parameter could be declared const ref
       
  1226 
       
  1227 /** Gets the data (MIME) type for data in a file passed by handle.
       
  1228 
       
  1229 @param aFile The file containing the data. Before this function can be called,
       
  1230 the file server session which owns this file handle must first be marked as shareable by 
       
  1231 calling RFs::ShareProtected().
       
  1232 @param aDataType On return, contains the result of the attempt to recognize 
       
  1233 data. 
       
  1234 @return KErrNone, if successful; otherwise one of the other system-wide error 
       
  1235 codes. */
       
  1236 EXPORT_C TInt RApaLsSession::RecognizeData(const RFile& aFile, TDataRecognitionResult& aDataType) const
       
  1237 	{
       
  1238 	TPckg<TDataRecognitionResult> result(aDataType);
       
  1239 	TIpcArgs ipcArgs(&result);
       
  1240 	const TInt error = aFile.TransferToServer(ipcArgs, 1, 2);
       
  1241 	if (error != KErrNone)
       
  1242 		{
       
  1243 		return error;
       
  1244 		}
       
  1245 	return SendReceiveWithReconnect(EAppListServRecognizeDataPassedByFileHandle,ipcArgs);
       
  1246 	} //lint !e1764 Suppress reference parameter 'aDataType' could be declared const ref
       
  1247 
       
  1248 
       
  1249 
       
  1250 /** Tests whether data taken from a named file has the specified 
       
  1251 data (MIME) type.
       
  1252 
       
  1253 @param aName The name of the file containing the data.
       
  1254 @param aBuffer A buffer containing data taken from the specified file; typically 
       
  1255 the data is read from the beginning of the file.
       
  1256 @param aDataType The data (MIME) type.
       
  1257 @param aResult On return, contains the result of the test.
       
  1258 @return KErrNone, if successful; otherwise one of the other system-wide error 
       
  1259 codes. 
       
  1260 */
       
  1261 EXPORT_C TInt RApaLsSession::RecognizeSpecificData(const TDesC& aName, const TDesC8& aBuffer, const TDataType& aDataType, TBool& aResult) const
       
  1262 	{
       
  1263 	const TPckgC<TDataType> dataType(aDataType);
       
  1264 	const TInt returnValue=SendReceiveWithReconnect(EAppListServRecognizeSpecificData,TIpcArgs(&dataType, &aName, &aBuffer));
       
  1265 	if (returnValue<0)
       
  1266 		{
       
  1267 		return returnValue;
       
  1268 		}
       
  1269 	aResult=returnValue;
       
  1270 	return KErrNone;
       
  1271 	}
       
  1272 	
       
  1273 EXPORT_C TInt RApaLsSession::RecognizeFilesL(const TDesC& aPath, CDataRecognitionResultArray& aResult) const
       
  1274 /** 
       
  1275 Gets the data (MIME) type for files in a specified directory. Because this call may take a long
       
  1276 time to complete, the asynchronous version is strongly recommended. Furthermore, it is not possible
       
  1277 to use this synchronous function while an asynchronous request is still active.
       
  1278 @publishedAll
       
  1279 @released
       
  1280 @param aPath A valid path. Note that the path must end with a backslash.
       
  1281 @param aResult If the call was successful, this parameter contains the recognition result.
       
  1282 @return KErrNone, if successful; otherwise one of the other system-wide error codes.
       
  1283 */
       
  1284 	{
       
  1285 	return RecognizeFilesL(aPath, KAllDataTypes, aResult);
       
  1286 	}
       
  1287 
       
  1288 EXPORT_C TInt RApaLsSession::RecognizeFilesL(const TDesC& aPath, const TDesC8& aDataType, CDataRecognitionResultArray& aResult) const
       
  1289 /** 
       
  1290 Gets the data (MIME) type for files in a specified directory. Because this call may take a long
       
  1291 time to complete, the asynchronous version is strongly recommended. Furthermore, it is not possible
       
  1292 to use this synchronous function while an asynchronous request is still active.
       
  1293 @publishedAll
       
  1294 @released
       
  1295 @param aPath A valid path. Note that the path must end with a backslash.
       
  1296 @param aDataType A data type filter. Wildcards are allowed. For example, "text*" would also
       
  1297 add "text/plain" data types to the result.
       
  1298 @param aResult If the call was successful, this parameter contains the recognition result.
       
  1299 @return KErrNone, if successful; otherwise one of the other system-wide error codes.
       
  1300 */
       
  1301 	{
       
  1302 	if(iExtension && iExtension->RecognitionActive())
       
  1303 		{
       
  1304 		return KErrInUse;
       
  1305 		}
       
  1306 	_LIT(KBackslash,"\\");
       
  1307 	if(aPath.Right(1) != KBackslash)
       
  1308 		{
       
  1309 		return KErrPathNotFound;
       
  1310 		}
       
  1311 
       
  1312 	TPckgBuf<TUint> requiredBufferSizePckg;
       
  1313 	aResult.SetPath(aPath);
       
  1314 	TInt error = SendReceiveWithReconnect(EAppListServRecognizeFiles,TIpcArgs(&aPath,&requiredBufferSizePckg,&aDataType));
       
  1315 	if(KErrNone == error)
       
  1316 		{
       
  1317 		error=TransferAndInternalizeDataL(aPath, requiredBufferSizePckg(), aResult);
       
  1318 		}
       
  1319 	return error;
       
  1320 
       
  1321 	}
       
  1322 
       
  1323 EXPORT_C void RApaLsSession::RecognizeFilesL(const TDesC& aPath, CDataRecognitionResultArray& aResult, TRequestStatus& aStatus)
       
  1324 /** 
       
  1325 Gets the data (MIME) type for files in a specified directory.
       
  1326 @publishedAll
       
  1327 @released
       
  1328 @param aPath A valid path. Note that the path must end with a backslash.
       
  1329 @param aResult If the call was successful, this parameter contains the recognition result.
       
  1330 @param aStatus A request status object.
       
  1331 */
       
  1332 	{
       
  1333 	RecognizeFilesL(aPath,KAllDataTypes,aResult,aStatus);
       
  1334 	}
       
  1335 
       
  1336 EXPORT_C void RApaLsSession::RecognizeFilesL(const TDesC& aPath, const TDesC8& aDataType, CDataRecognitionResultArray& aResult, TRequestStatus& aStatus)
       
  1337 /** 
       
  1338 Gets the data (MIME) type for files in a specified directory.
       
  1339 @publishedAll
       
  1340 @released
       
  1341 @param aPath A valid path. Note that the path must end with a backslash.
       
  1342 @param aDataType A data type filter. Wildcards are allowed. For example, "text*" would also
       
  1343 add "text/plain" data types to the result.
       
  1344 @param aResult If the call was successful, this parameter contains the recognition result.
       
  1345 @param aStatus A request status object
       
  1346 */
       
  1347 	{
       
  1348 	if(iExtension == NULL)
       
  1349 		{
       
  1350 		iExtension = new (ELeave) CApaLsSessionExtension(*this);
       
  1351 		}
       
  1352 	iExtension->RecognizeFilesL(aPath, aDataType, aResult, aStatus);
       
  1353 	}
       
  1354 
       
  1355 TInt RApaLsSession::TransferAndInternalizeDataL(const TDesC& aPath, const TInt aRequiredBufferSize, CDataRecognitionResultArray& aResult) const
       
  1356 /**
       
  1357 This function transfers the data to the client-side and "fills" the CDataRecognitionResultArray object. 
       
  1358 @internalComponent
       
  1359 */
       
  1360 {
       
  1361 	CBufFlat* const buffer=CBufFlat::NewL(aRequiredBufferSize);
       
  1362 	CleanupStack::PushL(buffer);
       
  1363 	buffer->ExpandL(0,aRequiredBufferSize);
       
  1364 	TPtr8 bufPtr=buffer->Ptr(0);
       
  1365 
       
  1366 	// transfer recognition buffer
       
  1367 	TInt error = SendReceiveWithReconnect(EAppListServTransferRecognitionResult,TIpcArgs(&aPath,&bufPtr,aRequiredBufferSize));
       
  1368 	if(KErrNone == error)
       
  1369 		{
       
  1370 		error = aResult.InternalizeL(*buffer);
       
  1371 		}
       
  1372 	CleanupStack::PopAndDestroy(buffer);
       
  1373 	return error;
       
  1374 	}
       
  1375 
       
  1376 EXPORT_C void RApaLsSession::CancelRecognizeFiles()
       
  1377 /** 
       
  1378 Cancels any outstanding asynchronous recognition requests.
       
  1379 @publishedAll
       
  1380 @released
       
  1381 */
       
  1382 	{
       
  1383 	if(iExtension)
       
  1384 		{
       
  1385 		iExtension->CancelRecognizeFiles();
       
  1386 		}
       
  1387 	}
       
  1388 
       
  1389 EXPORT_C void RApaLsSession::Close()
       
  1390 /** 
       
  1391 Closes the session. Needs to be called to avoid memory leaks.
       
  1392 @publishedAll
       
  1393 @released
       
  1394 */
       
  1395 	{
       
  1396 	CancelRecognizeFiles();
       
  1397 	RHandleBase::Close();
       
  1398 	delete iExtension;
       
  1399 	iExtension = NULL;
       
  1400 	}
       
  1401 
       
  1402 EXPORT_C TInt RApaLsSession::RecognizeSpecificData(const RFile& aFile, const TDataType& aDataType, TBool& aResult) const
       
  1403 /** Tests whether data taken from a file passed by handle has the specified 
       
  1404 data (MIME) type.
       
  1405 
       
  1406 @param aFile The file containing the data. Before this function can be called,
       
  1407 the file server session which owns this file handle must first be marked as shareable by 
       
  1408 calling RFs::ShareProtected().
       
  1409 @param aDataType The data (MIME) type.
       
  1410 @param aResult On return, contains the result of the test.
       
  1411 @return KErrNone, if successful; otherwise one of the other system-wide error 
       
  1412 codes. */
       
  1413 	{
       
  1414 	const TPckgC<TDataType> dataType(aDataType);
       
  1415 	TIpcArgs ipcArgs(&dataType);
       
  1416 	TInt returnValue = aFile.TransferToServer(ipcArgs, 1, 2);
       
  1417 	if (returnValue == KErrNone)
       
  1418 		{
       
  1419 		returnValue=SendReceiveWithReconnect(EAppListServRecognizeSpecificDataPassedByFileHandle,ipcArgs);
       
  1420 		}
       
  1421 	if (returnValue < KErrNone)
       
  1422 		{
       
  1423 		return returnValue;
       
  1424 		}
       
  1425 	aResult=returnValue;
       
  1426 	return KErrNone;
       
  1427 	}
       
  1428 
       
  1429 
       
  1430 /** Gets the UID of an application that can handle the specified data (MIME) type.
   538 /** Gets the UID of an application that can handle the specified data (MIME) type.
  1431 
   539 
  1432 If no application can be found, the function returns the UID of the preferred 
   540 If no application can be found, the function returns the UID of the preferred 
  1433 default handler. If none of the default handlers can handle the data type, 
   541 default handler. If none of the default handlers can handle the data type, 
  1434 then a NULL UID is returned.
   542 then a NULL UID is returned.
  1443 	{
   551 	{
  1444 	const TPckgC<TDataType> dataType(aDataType);
   552 	const TPckgC<TDataType> dataType(aDataType);
  1445 	TPckg<TUid> uid(aAppUid);
   553 	TPckg<TUid> uid(aAppUid);
  1446 	return SendReceiveWithReconnect(EAppListServAppForDataType,TIpcArgs(&dataType,&uid));
   554 	return SendReceiveWithReconnect(EAppListServAppForDataType,TIpcArgs(&dataType,&uid));
  1447 	} //lint !e1764 Suppress reference parameter 'aAppUid' could be declared const ref
   555 	} //lint !e1764 Suppress reference parameter 'aAppUid' could be declared const ref
  1448 
       
  1449 
       
  1450 /** Finds and launches an application to handle the document contained in the specified 
       
  1451 file.
       
  1452 
       
  1453 @param aFileName The document name.
       
  1454 @param aThreadId On return, the id of the main thread started.
       
  1455 @param aLaunchType Not used. Reserved for future use.
       
  1456 @return KErrNone, if successful; EAppListInvalid, if the server's initial population of 
       
  1457 the list has not completed; KErrNotFound, if a matching entry could not be found; otherwise 
       
  1458 one of the other system-wide error codes. 
       
  1459 */
       
  1460 EXPORT_C TInt RApaLsSession::StartDocument(const TDesC& aFileName, TThreadId& aThreadId, TLaunchType /*aLaunchType*/)
       
  1461 	{
       
  1462 	HBufC8* buffer=NULL;
       
  1463 	TInt error=GetBufferFromFile(buffer, aFileName);
       
  1464 	if (error!=KErrNone)
       
  1465 		{
       
  1466 		return error;
       
  1467 		}
       
  1468 	TFileName nativeExecutableName; // the name of the EXE that we pass to RProcess::Create
       
  1469 	TFileName logicalExecutableName; // the name of the MIDlet, Python script, etc
       
  1470 	HBufC8* opaqueData=NULL;
       
  1471 	TIpcArgs ipcArgs;
       
  1472 	ipcArgs.Set(2, &aFileName);
       
  1473 	ipcArgs.Set(3, buffer);
       
  1474 	error=GetExecutableName(nativeExecutableName, logicalExecutableName, opaqueData, ipcArgs, EAppListServGetExecutableNameGivenDocument);
       
  1475 	if (error!=KErrNone)
       
  1476 		{
       
  1477 		delete buffer;
       
  1478 		return error;
       
  1479 		}
       
  1480 	error = StartApplicationPassingDocumentName(nativeExecutableName, logicalExecutableName, opaqueData, aFileName, aThreadId, EApaCommandOpen, NULL);
       
  1481 	delete opaqueData;
       
  1482 	if(error!=KErrNone && error!=KErrCancel)
       
  1483 		{
       
  1484 		TPckg<TThreadId> threadId(aThreadId);
       
  1485 		error = SendReceiveWithReconnect(EAppListServStartDocument,TIpcArgs(&threadId, &aFileName, buffer));
       
  1486 		}
       
  1487 	delete buffer;
       
  1488 	return error;
       
  1489 	}
       
  1490 
       
  1491 EXPORT_C TInt RApaLsSession::StartDocument(RFile& aFile, TThreadId& aThreadId, TRequestStatus* aRequestStatusForRendezvous/*=NULL*/)
       
  1492 /** Finds and launches an application to handle the document contained in the specified file
       
  1493 
       
  1494 @param aFile  The file handle. Before this function can be called,
       
  1495 the file server session which owns this file handle must first be marked as shareable by 
       
  1496 calling RFs::ShareProtected().
       
  1497 @param aThreadId On return, the id of the main thread started.
       
  1498 @param aRequestStatusForRendezvous If not NULL, the asynchronous RProcess::Rendezvous() 
       
  1499 function is called (being passed this TRequestStatus object) before RProcess::Resume() is called on 
       
  1500 the new application process.
       
  1501 @return KErrNone, if successful; KErrNotFound, if no suitable application can 
       
  1502 be found; otherwise one of the other system-wide error codes. */
       
  1503 	{
       
  1504 	TFileName nativeExecutableName; // the name of the EXE that we pass to RProcess::Create
       
  1505 	TFileName logicalExecutableName; // the name of the MIDlet, Python script, etc
       
  1506 	HBufC8* opaqueData=NULL;
       
  1507 	TIpcArgs ipcArgs;
       
  1508 	TInt error=aFile.TransferToServer(ipcArgs, 2, 3);
       
  1509 	if (error == KErrNone)
       
  1510 		{
       
  1511 		error=GetExecutableName(nativeExecutableName, logicalExecutableName, opaqueData, ipcArgs, EAppListServGetExecutableNameGivenDocumentPassedByFileHandle);
       
  1512 		}
       
  1513 	if (error!=KErrNone)
       
  1514 		{
       
  1515 		return error;
       
  1516 		}
       
  1517 	error=StartApplicationPassingFileHandle(nativeExecutableName, logicalExecutableName, opaqueData, aFile, aThreadId, aRequestStatusForRendezvous);
       
  1518 	delete opaqueData;
       
  1519 	return error;
       
  1520 	} //lint !e1764 Suppress reference parameter could be declared const ref
       
  1521 
       
  1522 
       
  1523 /** Launches an application that can handle the specified data (MIME) type.
       
  1524 
       
  1525 The application handles the document contained in the specified file.
       
  1526 
       
  1527 @param aFileName The document name.
       
  1528 @param aDataType The data (MIME) type.
       
  1529 @param aThreadId On return, the id of the main thread started.
       
  1530 @param aLaunchType Not used. Reserved for future use.
       
  1531 @return KErrNone, if successful; EAppListInvalid if the server's initial population of 
       
  1532 the list has not completed; KErrNotFound, if no suitable application can 
       
  1533 be found; otherwise one of the other system-wide error codes. 
       
  1534 */
       
  1535 EXPORT_C TInt RApaLsSession::StartDocument(const TDesC& aFileName, const TDataType& aDataType, TThreadId& aThreadId, TLaunchType /*aLaunchType*/)
       
  1536 	{
       
  1537 	TFileName nativeExecutableName; // the name of the EXE that we pass to RProcess::Create
       
  1538 	TFileName logicalExecutableName; // the name of the MIDlet, Python script, etc
       
  1539 	HBufC8* opaqueData=NULL;
       
  1540 	const TPckgC<TDataType> dataType(aDataType);
       
  1541 	TIpcArgs ipcArgs;
       
  1542 	ipcArgs.Set(2, &dataType);
       
  1543 	TInt error=GetExecutableName(nativeExecutableName, logicalExecutableName, opaqueData, ipcArgs, EAppListServGetExecutableNameGivenDataType);
       
  1544 	if (error!=KErrNone)
       
  1545 		{
       
  1546 		return error;
       
  1547 		}
       
  1548 	error = StartApplicationPassingDocumentName(nativeExecutableName, logicalExecutableName, opaqueData, aFileName, aThreadId,EApaCommandOpen,NULL);
       
  1549 	delete opaqueData;
       
  1550 	if(error!=KErrNone && error!=KErrCancel)
       
  1551 		{
       
  1552 		TPckg<TThreadId> threadId(aThreadId);
       
  1553 		error = SendReceiveWithReconnect(EAppListServStartDocumentByDataType,TIpcArgs(&threadId, &aFileName, &dataType));
       
  1554 		}
       
  1555 	return error;
       
  1556 	}
       
  1557 
       
  1558 EXPORT_C TInt RApaLsSession::StartDocument(RFile& aFile, const TDataType& aDataType, TThreadId& aThreadId, TRequestStatus* aRequestStatusForRendezvous/*=NULL*/)
       
  1559 /** Finds and launches an application to handle the document contained in the specified file
       
  1560 
       
  1561 @param aFile The file handle.
       
  1562 @param aDataType The data (MIME) type.
       
  1563 @param aThreadId On return, the id of the main thread started.
       
  1564 @param aRequestStatusForRendezvous If not NULL, the asynchronous RProcess::Rendezvous() 
       
  1565 function is called (being passed this TRequestStatus object) before RProcess::Resume() is called on 
       
  1566 the new application process.
       
  1567 @return KErrNone, if successful; KErrNotFound, if no suitable application can 
       
  1568 be found; otherwise one of the other system-wide error codes. */
       
  1569 	{
       
  1570 	TFileName nativeExecutableName; // the name of the EXE that we pass to RProcess::Create
       
  1571 	TFileName logicalExecutableName; // the name of the MIDlet, Python script, etc
       
  1572 	HBufC8* opaqueData=NULL;
       
  1573 	const TPckgC<TDataType> dataType(aDataType);
       
  1574 	TIpcArgs ipcArgs;
       
  1575 	ipcArgs.Set(2, &dataType);
       
  1576 	TInt error=GetExecutableName(nativeExecutableName, logicalExecutableName, opaqueData, ipcArgs, EAppListServGetExecutableNameGivenDataType);
       
  1577 	if (error!=KErrNone)
       
  1578 		{
       
  1579 		return error;
       
  1580 		}
       
  1581 	error=StartApplicationPassingFileHandle(nativeExecutableName, logicalExecutableName, opaqueData, aFile, aThreadId, aRequestStatusForRendezvous);
       
  1582 	delete opaqueData;
       
  1583 	return error;
       
  1584 	} //lint !e1764 Suppress reference parameter could be declared const ref
       
  1585 
       
  1586 EXPORT_C TInt RApaLsSession::StartDocument(const TDesC& aFileName, TUid aAppUid, TThreadId& aThreadId, TLaunchType aLaunchType)
       
  1587 /** Launches the application identified by the specified UID.
       
  1588 
       
  1589 The application handles the document contained in the specified file.
       
  1590 
       
  1591 @param aFileName The document name.
       
  1592 @param aAppUid The application specific UID.
       
  1593 @param aThreadId On return, the id of the main thread started.
       
  1594 @param aLaunchType Not used. Reserved for future use.
       
  1595 @return KErrNone, if successful; EAppListInvalid if the server's initial population of 
       
  1596 the list has not completed; KErrNotFound, if no suitable application can 
       
  1597 be found; otherwise one of the other system-wide error codes. */
       
  1598 	{
       
  1599 	TFileName nativeExecutableName; // the name of the EXE that we pass to RProcess::Create
       
  1600 	TFileName logicalExecutableName; // the name of the MIDlet, Python script, etc
       
  1601 	HBufC8* opaqueData=NULL;
       
  1602 	TIpcArgs ipcArgs;
       
  1603 	ipcArgs.Set(2, aAppUid.iUid);
       
  1604 	TInt error=GetExecutableName(nativeExecutableName, logicalExecutableName, opaqueData, ipcArgs, EAppListServGetExecutableNameGivenAppUid);
       
  1605 	if (error!=KErrNone)
       
  1606 		{
       
  1607 		return error;
       
  1608 		}
       
  1609 	error = StartApplicationPassingDocumentName(nativeExecutableName, logicalExecutableName, opaqueData, aFileName, aThreadId,EApaCommandOpen,NULL);
       
  1610 	delete opaqueData;
       
  1611 	if(error!=KErrNone && error!=KErrCancel)
       
  1612 		{
       
  1613 		error = StartAndCreate(EAppListServStartDocumentByUid,aFileName,aAppUid,aThreadId,aLaunchType);
       
  1614 		}
       
  1615 	return error;
       
  1616 	}
       
  1617 
       
  1618 EXPORT_C TInt RApaLsSession::StartDocument(RFile& aFile, TUid aAppUid, TThreadId& aThreadId, TRequestStatus* aRequestStatusForRendezvous/*=NULL*/)
       
  1619 /** Finds and launches an application to handle the document contained in the specified file
       
  1620 
       
  1621 @param aFile The file handle.
       
  1622 @param aAppUid The application specific UID.
       
  1623 @param aThreadId On return, the id of the main thread started.
       
  1624 @param aRequestStatusForRendezvous If not NULL, the asynchronous RProcess::Rendezvous() 
       
  1625 function is called (being passed this TRequestStatus object) before RProcess::Resume() is called on 
       
  1626 the new application process.
       
  1627 @return KErrNone, if successful; KErrNotFound, if no suitable application can 
       
  1628 be found; otherwise one of the other system-wide error codes. */
       
  1629 	{
       
  1630 	TFileName nativeExecutableName; // the name of the EXE that we pass to RProcess::Create
       
  1631 	TFileName logicalExecutableName; // the name of the MIDlet, Python script, etc
       
  1632 	HBufC8* opaqueData=NULL;
       
  1633 	TIpcArgs ipcArgs;
       
  1634 	ipcArgs.Set(2, aAppUid.iUid);
       
  1635 	TInt error=GetExecutableName(nativeExecutableName, logicalExecutableName, opaqueData, ipcArgs, EAppListServGetExecutableNameGivenAppUid);
       
  1636 	if (error!=KErrNone)
       
  1637 		{
       
  1638 		return error;
       
  1639 		}
       
  1640 	error=StartApplicationPassingFileHandle(nativeExecutableName, logicalExecutableName, opaqueData, aFile, aThreadId, aRequestStatusForRendezvous);
       
  1641 	delete opaqueData;
       
  1642 	return error;
       
  1643 	} //lint !e1764 Suppress reference parameter could be declared const ref
       
  1644 
       
  1645 
       
  1646 /** Launches the application identified by the specified UID and creates a new document.
       
  1647 
       
  1648 To create a document file with the passed document name, the application needs to override the 3-parameter
       
  1649 overload of ProcessCommandParametersL() to call the 2-parameter overload.
       
  1650 
       
  1651 Otherwise, a document will be created with the default document name present in the application resource file.
       
  1652 If default document name is empty or not provided, no document is created.
       
  1653 
       
  1654 If the application resource file is not present, a document with application caption name is created.
       
  1655 
       
  1656 @param aFileName The document name.
       
  1657 @param aAppUid The application specific UID. 
       
  1658 @param aThreadId On return, the id of the main thread started.
       
  1659 @param aLaunchType Not used. Reserved for future use.
       
  1660 @return KErrNone, if successful; EAppListInvalid if the server's initial population of 
       
  1661 the list has not completed; KErrNotFound, if no suitable application can 
       
  1662 be found; otherwise one of the other system-wide error codes. 
       
  1663 @see CEikAppUi::ProcessCommandParametersL().
       
  1664 */
       
  1665 EXPORT_C TInt RApaLsSession::CreateDocument(const TDesC& aFileName, TUid aAppUid, TThreadId& aThreadId, TLaunchType aLaunchType)
       
  1666 	{
       
  1667 	TFileName nativeExecutableName; // the name of the EXE that we pass to RProcess::Create
       
  1668 	TFileName logicalExecutableName; // the name of the MIDlet, Python script, etc
       
  1669 	HBufC8* opaqueData=NULL;
       
  1670 	TIpcArgs ipcArgs;
       
  1671 	ipcArgs.Set(2, aAppUid.iUid);
       
  1672 	TInt error=GetExecutableName(nativeExecutableName, logicalExecutableName, opaqueData, ipcArgs, EAppListServGetExecutableNameGivenAppUid);
       
  1673 	if (error!=KErrNone)
       
  1674 		{
       
  1675 		return error;
       
  1676 		}
       
  1677 	error = StartApplicationPassingDocumentName(nativeExecutableName, logicalExecutableName, opaqueData, aFileName, aThreadId,EApaCommandCreate,NULL);
       
  1678 	delete opaqueData;
       
  1679 	if(error!=KErrNone && error!=KErrCancel)
       
  1680 		{
       
  1681 		error = StartAndCreate(EAppListServCreateDocumentByUid,aFileName,aAppUid,aThreadId,aLaunchType);
       
  1682 		}
       
  1683 	return error;
       
  1684 	}
       
  1685 	
       
  1686 TInt RApaLsSession::StartAndCreate(TInt aRqst,const TDesC& aFileName, TUid aAppUid, TThreadId& aThreadId, TLaunchType /*aLaunchType*/)
       
  1687 	{
       
  1688 	TPckg<TThreadId> threadId(aThreadId);
       
  1689 	return SendReceiveWithReconnect(aRqst,TIpcArgs(&threadId, &aFileName, aAppUid.iUid));
       
  1690 	} 	//lint !e1762 !e1764
       
  1691 		//Suppress reference parameter 'aThreadId' could be declared const ref
       
  1692 		//Suppress member function could be made const
       
  1693 
       
  1694 
       
  1695 
   556 
  1696 
   557 
  1697 /** Gets the available icon sizes for the application with the specified UID.
   558 /** Gets the available icon sizes for the application with the specified UID.
  1698 
   559 
  1699 @param aAppUid The application specific UID.
   560 @param aAppUid The application specific UID.
  1703 be found; KErrNotSupported, if the application provides icons in non-MBM format;
   564 be found; KErrNotSupported, if the application provides icons in non-MBM format;
  1704 otherwise one of the other system wide error codes. 
   565 otherwise one of the other system wide error codes. 
  1705 */
   566 */
  1706 EXPORT_C TInt RApaLsSession::GetAppIconSizes(TUid aAppUid, CArrayFixFlat<TSize>& aArrayToFill) const
   567 EXPORT_C TInt RApaLsSession::GetAppIconSizes(TUid aAppUid, CArrayFixFlat<TSize>& aArrayToFill) const
  1707 	{
   568 	{
  1708 	TRAPD(error,DoGetAppIconSizesL(aAppUid,aArrayToFill));
   569 	TRAPD(error, DoGetAppIconSizesL(aAppUid,aArrayToFill));
  1709 	return error;
   570 	return error;
  1710 	}
       
  1711 
       
  1712 void RApaLsSession::FetchArrayL(MArrayFiller& aArrayFiller,TUid aAppUid, TInt aOpcode, TInt aInitialBufSize) const
       
  1713 	{
       
  1714 	CBufFlat* buffer=CBufFlat::NewL(aInitialBufSize);
       
  1715 	CleanupStack::PushL(buffer);
       
  1716 	buffer->ExpandL(0,aInitialBufSize);
       
  1717 	TPtr8 bufPtr=buffer->Ptr(0);
       
  1718 	const TInt sizeRequired=User::LeaveIfError(SendReceiveWithReconnect(aOpcode,TIpcArgs(aAppUid.iUid,buffer->Size(),&bufPtr)));
       
  1719 	if (sizeRequired>0)
       
  1720 		{
       
  1721 		__ASSERT_DEBUG(sizeRequired>buffer->Size(),User::Invariant());
       
  1722 		CleanupStack::PopAndDestroy(buffer);
       
  1723 		buffer=CBufFlat::NewL(sizeRequired);
       
  1724 		CleanupStack::PushL(buffer);
       
  1725 		buffer->ExpandL(0,sizeRequired);
       
  1726 		bufPtr.Set(buffer->Ptr(0));
       
  1727 #if defined(_DEBUG)
       
  1728 		const TInt check=
       
  1729 #endif
       
  1730 		User::LeaveIfError(SendReceiveWithReconnect(aOpcode,TIpcArgs(aAppUid.iUid,buffer->Size(),&bufPtr)));
       
  1731 		__ASSERT_DEBUG(check==0,User::Invariant());
       
  1732 		}
       
  1733 	RBufReadStream readStream;
       
  1734 	readStream.Open(*buffer);
       
  1735 	const TInt count=readStream.ReadUint32L();
       
  1736 	for (TInt i=0; i<count; ++i)
       
  1737 		{
       
  1738 		aArrayFiller.AppendItemL(readStream);
       
  1739 		}
       
  1740 	CleanupStack::PopAndDestroy(buffer);
       
  1741 	}
   571 	}
  1742 
   572 
  1743 void RApaLsSession::DoGetAppIconSizesL(TUid aAppUid, CArrayFixFlat<TSize>& aArrayToFill) const
   573 void RApaLsSession::DoGetAppIconSizesL(TUid aAppUid, CArrayFixFlat<TSize>& aArrayToFill) const
  1744 	{
   574 	{
  1745 	TSizeArrayFiller arrayFiller(aArrayToFill);
   575 	TSizeArrayFiller arrayFiller(aArrayToFill);
  1746 	FetchArrayL(arrayFiller, aAppUid, EAppListServGetAppIconSizes, KInitialIconBufSize);
   576 	FetchArrayL(arrayFiller, aAppUid, EAppListServGetAppIconSizes, KInitialIconBufSize);
  1747 	}
   577 	}
  1748 
   578 
       
   579 /**
       
   580 This method implementes a generic mechanism for retrieving data items from the AppArc server.
       
   581 The data items can be either TSize, TApaAppViewInfo, or TDesC (see MArrayFiller).
       
   582 @internalTechnology
       
   583 */
       
   584 void RApaLsSession::FetchArrayL(MArrayFiller& aArray, TUid aAppUid, TInt aOpcode, TInt aInitialBufSize) const
       
   585 	{
       
   586 	// Create a buffer to recieve the data in
       
   587 	CBufFlat* buffer = CBufFlat::NewL(aInitialBufSize);
       
   588 	CleanupStack::PushL(buffer);
       
   589 	
       
   590 	// Set its size and create a pointer for writing to it
       
   591 	buffer->ExpandL(0,aInitialBufSize);
       
   592 	TPtr8 bufPtr = buffer->Ptr(0);
       
   593 	
       
   594 	// Get the data from the AppArc server
       
   595 	
       
   596 	const TInt sizeRequired = SendReceiveWithReconnect(aOpcode,TIpcArgs(aAppUid.iUid,buffer->Size(),&bufPtr));
       
   597 	User::LeaveIfError(sizeRequired); 	// Negative values are error codes
       
   598 	if (sizeRequired > 0)	// If the initial buffer was too small...
       
   599 		{
       
   600 		// (This should really never happen - the code below is a backup for release builds only
       
   601 		ASSERT(0); // so panic any debug builds)
       
   602 		
       
   603 		// ...create a bigger one and try again
       
   604 		CleanupStack::PopAndDestroy(buffer);
       
   605 		buffer = CBufFlat::NewL(sizeRequired);
       
   606 		CleanupStack::PushL(buffer);
       
   607 		buffer->ExpandL(0, sizeRequired);
       
   608 		bufPtr.Set(buffer->Ptr(0));
       
   609 		User::LeaveIfError(SendReceiveWithReconnect(aOpcode, TIpcArgs(aAppUid.iUid, buffer->Size(), &bufPtr)));
       
   610 		}
       
   611 	
       
   612 	// Create a read stream for reading from the buffer	
       
   613 	RBufReadStream readStream;
       
   614 	CleanupClosePushL(readStream);
       
   615 	readStream.Open(*buffer);
       
   616 	
       
   617 	// Get the item count from the stream and popoulate the array
       
   618 	const TInt count = readStream.ReadUint32L();
       
   619 	for (TInt i = 0; i < count; ++i)
       
   620 		aArray.AppendItemFromStreamL(readStream);
       
   621 
       
   622 	CleanupStack::PopAndDestroy(&readStream);
       
   623 	CleanupStack::PopAndDestroy(buffer);
       
   624 	}
  1749 
   625 
  1750 
   626 
  1751 /** Gets the nearest matching application icon for the application with the specified 
   627 /** Gets the nearest matching application icon for the application with the specified 
  1752 UID.
   628 UID.
  1753 
   629 
  1767 */
   643 */
  1768 EXPORT_C TInt RApaLsSession::GetAppIcon(TUid aAppUid, TSize aSize, CApaMaskedBitmap& aAppBitmap) const
   644 EXPORT_C TInt RApaLsSession::GetAppIcon(TUid aAppUid, TSize aSize, CApaMaskedBitmap& aAppBitmap) const
  1769 	{
   645 	{
  1770 	SReturnData_AppIconByUidAndSize returnData = {0,0};
   646 	SReturnData_AppIconByUidAndSize returnData = {0,0};
  1771 	TPckg<SReturnData_AppIconByUidAndSize> returnData_asDescriptor(returnData);
   647 	TPckg<SReturnData_AppIconByUidAndSize> returnData_asDescriptor(returnData);
  1772 	TInt error=SendReceiveWithReconnect(EAppListServAppIconByUidAndSize,TIpcArgs(aAppUid.iUid,aSize.iWidth,aSize.iHeight,&returnData_asDescriptor));
   648 	TInt error = SendReceiveWithReconnect(EAppListServAppIconByUidAndSize, TIpcArgs(aAppUid.iUid,aSize.iWidth,aSize.iHeight,&returnData_asDescriptor));
  1773 	if (error==KErrNone)
   649 	if (!error)
  1774 		{
   650 		{
  1775 		error=aAppBitmap.Duplicate(returnData.iIcon);
   651 		error = aAppBitmap.Duplicate(returnData.iIcon);
  1776 		if (error==KErrNone)
   652 		if (!error)
  1777 			{
   653 			error = aAppBitmap.Mask()->Duplicate(returnData.iIconMask);
  1778 			error=aAppBitmap.Mask()->Duplicate(returnData.iIconMask);
       
  1779 			}
       
  1780 		}
   654 		}
       
   655 
  1781 	return error;
   656 	return error;
  1782 	}
   657 	}
  1783 
       
  1784 
   658 
  1785 
   659 
  1786 /** 
   660 /** 
  1787  gets the bitmap handles from the Server, forms these up into a CApaMaskedBitmap
   661  gets the bitmap handles from the Server, forms these up into a CApaMaskedBitmap
  1788 
   662 
  1803 EXPORT_C TInt RApaLsSession::GetAppIcon(TUid aAppUid, TInt aSize, CApaMaskedBitmap& aAppBitmap) const
   677 EXPORT_C TInt RApaLsSession::GetAppIcon(TUid aAppUid, TInt aSize, CApaMaskedBitmap& aAppBitmap) const
  1804 	{
   678 	{
  1805 	__ASSERT_ALWAYS((aSize>=0) && (aSize<3), Panic(EDPanicBadIconSize));
   679 	__ASSERT_ALWAYS((aSize>=0) && (aSize<3), Panic(EDPanicBadIconSize));
  1806 	SReturnData_AppIconByUid returnData = {0,0};
   680 	SReturnData_AppIconByUid returnData = {0,0};
  1807 	TPckg<SReturnData_AppIconByUid> returnData_asDescriptor(returnData);
   681 	TPckg<SReturnData_AppIconByUid> returnData_asDescriptor(returnData);
  1808 	TInt error=SendReceiveWithReconnect(EAppListServAppIconByUid,TIpcArgs(aAppUid.iUid,aSize,&returnData_asDescriptor));
   682 	TInt error = SendReceiveWithReconnect(EAppListServAppIconByUid,TIpcArgs(aAppUid.iUid,aSize,&returnData_asDescriptor));
  1809 	if (error==KErrNone)
   683 	if (!error)
  1810 		{
   684 		{
  1811 		error=aAppBitmap.Duplicate(returnData.iIcon);
   685 		error = aAppBitmap.Duplicate(returnData.iIcon);
  1812 		if (error==KErrNone)
   686 		if (!error)
  1813 			{
   687 			error = aAppBitmap.Mask()->Duplicate(returnData.iIconMask);
  1814 			error=aAppBitmap.Mask()->Duplicate(returnData.iIconMask);
       
  1815 			}
       
  1816 		}
   688 		}
       
   689 		
  1817 	return error;
   690 	return error;
  1818 	}
   691 	}
  1819 
   692 
  1820 
   693 
  1821 	
       
  1822 EXPORT_C TInt RApaLsSession::GetAppIcon(TUid aAppUid, RFile& aFile) const 
       
  1823 /** Gets an open shareable read only file handle to the application icon file for the 
   694 /** Gets an open shareable read only file handle to the application icon file for the 
  1824 application with the specified UID. 
   695 application with the specified UID. 
  1825 
   696 
  1826 An icon file can only be defined by applications providing an application registration file.
   697 An icon file can only be defined by applications providing an application registration file.
  1827 
   698 
  1834 @param aFile On return, a read only open file handle to the icon file.
   705 @param aFile On return, a read only open file handle to the icon file.
  1835 @return KErrNone, if successful; KErrNotFound, if a matching application could not be found, 
   706 @return KErrNone, if successful; KErrNotFound, if a matching application could not be found, 
  1836 or an icon filename was not defined; otherwise one of the other system wide error codes. 
   707 or an icon filename was not defined; otherwise one of the other system wide error codes. 
  1837 @see GetAppIcon 
   708 @see GetAppIcon 
  1838 */ 
   709 */ 
       
   710 EXPORT_C TInt RApaLsSession::GetAppIcon(TUid aAppUid, RFile& aFile) const 
  1839 	{
   711 	{
  1840 	__ASSERT_ALWAYS(aFile.SubSessionHandle() == KNullHandle, Panic(EDPanicHandleAlreadySet));
   712 	__ASSERT_ALWAYS(aFile.SubSessionHandle() == KNullHandle, Panic(EDPanicHandleAlreadySet));
  1841 	TPckgBuf<TInt> fileHandle;
   713 	TPckgBuf<TInt> fileHandle;
  1842 	TInt sessionHandleOrErrorCode = SendReceiveWithReconnect(EAppListServAppIconFileHandle, TIpcArgs(aAppUid.iUid, &fileHandle));
   714 	TInt sessionHandleOrErrorCode = SendReceiveWithReconnect(EAppListServAppIconFileHandle, TIpcArgs(aAppUid.iUid, &fileHandle));
  1843 	if (sessionHandleOrErrorCode >= KErrNone)
   715 	if (sessionHandleOrErrorCode >= KErrNone)
  1846 	    }
   718 	    }
  1847 	return sessionHandleOrErrorCode;
   719 	return sessionHandleOrErrorCode;
  1848 	}   
   720 	}   
  1849 
   721 
  1850 
   722 
  1851 
       
  1852 EXPORT_C TInt RApaLsSession::AppForDocument(const TDesC& aFileName, TUid& aAppUid, TDataType& aDataType) const
       
  1853 /** Gets the data (MIME) type of the data in the specified file and gets the UID 
   723 /** Gets the data (MIME) type of the data in the specified file and gets the UID 
  1854 of an application that can handle this type.
   724 of an application that can handle this type.
  1855 
   725 
  1856 @param aFileName The name of the file containing the data.
   726 @param aFileName The name of the file containing the data.
  1857 @param aAppUid On return, the UID of the application that can handle the data 
   727 @param aAppUid On return, the UID of the application that can handle the data 
  1858 (MIME) type; this may be NULL.
   728 (MIME) type; this may be NULL.
  1859 @param aDataType On return, the data (MIME) type.
   729 @param aDataType On return, the data (MIME) type.
  1860 @return KErrNone, if successful; otherwise one of the other system-wide error 
   730 @return KErrNone, if successful; otherwise one of the other system-wide error 
  1861 codes. */
   731 codes. */
       
   732 EXPORT_C TInt RApaLsSession::AppForDocument(const TDesC& aFileName, TUid& aAppUid, TDataType& aDataType) const
  1862 	{
   733 	{
  1863 	return DoAppForDocumentOptionallySpecifyingService(aFileName, TUid::Null(), aAppUid, aDataType, EAppListServAppForDocument);
   734 	return DoAppForDocumentOptionallySpecifyingService(aFileName, TUid::Null(), aAppUid, aDataType, EAppListServAppForDocument);
  1864 	}
   735 	}
  1865 
   736 
  1866 
   737 
  1879 EXPORT_C TInt RApaLsSession::AppForDocument(const RFile& aFile, TUid& aAppUid, TDataType& aDataType) const
   750 EXPORT_C TInt RApaLsSession::AppForDocument(const RFile& aFile, TUid& aAppUid, TDataType& aDataType) const
  1880 	{
   751 	{
  1881 	return DoAppForDocumentOptionallySpecifyingService(aFile, TUid::Null(), aAppUid, aDataType, EAppListServAppForDocumentPassedByFileHandle);
   752 	return DoAppForDocumentOptionallySpecifyingService(aFile, TUid::Null(), aAppUid, aDataType, EAppListServAppForDocumentPassedByFileHandle);
  1882 	}
   753 	}
  1883 
   754 
       
   755 
  1884 /** Tests whether the file is a native executable (DLL or EXE).
   756 /** Tests whether the file is a native executable (DLL or EXE).
  1885 
   757 
  1886 @param aFileName The name of the file containing the data.
   758 @param aFileName The name of the file containing the data.
  1887 @param aProgram On return, true, if the file contains application code; false, 
   759 @param aProgram On return, true, if the file contains application code; false, 
  1888 otherwise.
   760 otherwise.
  1894 	_LIT(KLitSysBin, "\\sys\\bin\\");
   766 	_LIT(KLitSysBin, "\\sys\\bin\\");
  1895 	aProgram=(TParsePtrC(aFileName).Path().CompareF(KLitSysBin)==0);
   767 	aProgram=(TParsePtrC(aFileName).Path().CompareF(KLitSysBin)==0);
  1896 	return KErrNone;
   768 	return KErrNone;
  1897 	}
   769 	}
  1898 
   770 
  1899 /** Gets the confidence threshold for successful data recognition.
   771 
  1900 
       
  1901 This is the minimum acceptable confidence level that must be reported by a 
       
  1902 data recognizer for data to be accepted as of a given type.
       
  1903 
       
  1904 @param aConfidence On return, the confidence threshold. 
       
  1905 @return KErrNone, if successful; otherwise one of the other system-wide error 
       
  1906 codes. 
       
  1907 */
       
  1908 EXPORT_C TInt RApaLsSession::GetAcceptedConfidence(TInt& aConfidence) const
       
  1909 	{
       
  1910 	TPckg<TInt> confidence(aConfidence);
       
  1911 	return SendReceiveWithReconnect(EAppListServGetConfidence,TIpcArgs(&confidence));
       
  1912 	} //lint !e1764 Suppress reference parameter could be declared const ref
       
  1913 
       
  1914 
       
  1915 
       
  1916 /** Sets the confidence threshold for successful data recognition.
       
  1917 
       
  1918 This is the minimum acceptable confidence level that must be reported by a 
       
  1919 data recognizer for data to be accepted as of a given type.
       
  1920 
       
  1921 @param aConfidence The confidence threshold. Although this is an integer value, 
       
  1922 data recognizers use the discrete values defined by the CApaDataRecognizerType::TRecognitionConfidence 
       
  1923 enumeration.
       
  1924 @return KErrNone, if successful; otherwise one of the other system-wide error 
       
  1925 codes. 
       
  1926 @capability WriteDeviceData 
       
  1927 */
       
  1928 EXPORT_C TInt RApaLsSession::SetAcceptedConfidence(TInt aConfidence)
       
  1929 	{
       
  1930 	return SendReceiveWithReconnect(EAppListServSetConfidence,TIpcArgs(aConfidence));
       
  1931 	} //lint !e1762 Suppress member function could be made const
       
  1932 
       
  1933 
       
  1934 EXPORT_C TInt RApaLsSession::GetPreferredBufSize(TInt& aPreferredBufSize) const
       
  1935 /** Gets the preferred number of bytes of data to read from a file for the purpose 
   772 /** Gets the preferred number of bytes of data to read from a file for the purpose 
  1936 of recognizing the data type.
   773 of recognizing the data type.
  1937 
   774 
  1938 This should be used to determine the size of buffer to pass to the 3-parameter 
   775 This should be used to determine the size of buffer to pass to the 3-parameter 
  1939 overload of RecognizeData() or to the 4-parameter overload of RecognizeSpecificData().
   776 overload of RecognizeData() or to the 4-parameter overload of RecognizeSpecificData().
  1942 by any of the currently installed data-recognizers, or the value that would be 
   779 by any of the currently installed data-recognizers, or the value that would be 
  1943 returned by GetMaxDataBufSize(), whichever is less.
   780 returned by GetMaxDataBufSize(), whichever is less.
  1944 @return KErrNone, if successful; otherwise one of the other system-wide error 
   781 @return KErrNone, if successful; otherwise one of the other system-wide error 
  1945 codes.
   782 codes.
  1946 @see GetMaxDataBufSize() */
   783 @see GetMaxDataBufSize() */
  1947 	{
   784 EXPORT_C TInt RApaLsSession::GetPreferredBufSize(TInt& aPreferredBufSize) const
  1948 	const TInt preferredBufSize=SendReceiveWithReconnect(EAppListServPreferredBufSize, TIpcArgs());
   785 	{
  1949 	if (preferredBufSize<KErrNone)
   786 	const TInt preferredBufSize = SendReceiveWithReconnect(EAppListServPreferredBufSize, TIpcArgs());
  1950 		{
   787 	if (preferredBufSize < KErrNone)
  1951 		return preferredBufSize; // it's an error
   788 		return preferredBufSize; // it's an error
  1952 		}
   789 
  1953 	aPreferredBufSize=preferredBufSize;
   790 	aPreferredBufSize = preferredBufSize;
  1954 	return KErrNone;
   791 	return KErrNone;
  1955 	}
   792 	}
  1956 
   793 
  1957 EXPORT_C TInt RApaLsSession::GetMaxDataBufSize(TInt& aBufSize) const
   794 
  1958 /** Gets the maximum size of the data that can be read from a file for the purpose 
   795 /** Gets the maximum size of the data that can be read from a file for the purpose 
  1959 of recognizing the data type.
   796 of recognizing the data type.
  1960 
   797 
  1961 To determine the size of buffer to pass to the 3-parameter overload of RecognizeData() 
   798 To determine the size of buffer to pass to the 3-parameter overload of RecognizeData() 
  1962 or to the 4-parameter overload of RecognizeSpecificData(), use GetPreferredBufSize() 
   799 or to the 4-parameter overload of RecognizeSpecificData(), use GetPreferredBufSize() 
  1965 @param aBufSize On return, contains the maximum size.
   802 @param aBufSize On return, contains the maximum size.
  1966 @return KErrNone, if successful; otherwise one of the other system-wide error 
   803 @return KErrNone, if successful; otherwise one of the other system-wide error 
  1967 codes.
   804 codes.
  1968 @see SetMaxDataBufSize()
   805 @see SetMaxDataBufSize()
  1969 @see GetPreferredBufSize() */
   806 @see GetPreferredBufSize() */
  1970 	{
   807 EXPORT_C TInt RApaLsSession::GetMaxDataBufSize(TInt& aBufSize) const
  1971 	const TInt returnValue=SendReceiveWithReconnect(EAppListServGetBufSize,TIpcArgs());
   808 	{
  1972 	if (returnValue<0)
   809 	const TInt returnValue = SendReceiveWithReconnect(EAppListServGetBufSize, TIpcArgs());
  1973 		{
   810 	if (returnValue < 0)
  1974 		return returnValue;
   811 		return returnValue;
  1975 		}
   812 
  1976 	aBufSize=returnValue;
   813 	aBufSize = returnValue;
  1977 	return KErrNone;
   814 	return KErrNone;
  1978 	}
   815 	}
  1979 
       
  1980 
   816 
  1981 
   817 
  1982 /** Sets the maximum size of the data that can be read from a file for the purpose 
   818 /** Sets the maximum size of the data that can be read from a file for the purpose 
  1983 of recognizing the data type.
   819 of recognizing the data type.
  1984 
   820 
  1998 */
   834 */
  1999 EXPORT_C TInt RApaLsSession::SetMaxDataBufSize(TInt aBufSize)
   835 EXPORT_C TInt RApaLsSession::SetMaxDataBufSize(TInt aBufSize)
  2000 	{
   836 	{
  2001 	return SendReceiveWithReconnect(EAppListServSetBufSize,TIpcArgs(aBufSize));
   837 	return SendReceiveWithReconnect(EAppListServSetBufSize,TIpcArgs(aBufSize));
  2002 	} //lint !e1762 Suppress member function could be made const
   838 	} //lint !e1762 Suppress member function could be made const
  2003 
       
  2004 
       
  2005 
       
  2006 /** Gets a list of recognized data(MIME) types by all recognizers.
       
  2007 
       
  2008 @param aDataTypes The array of data (MIME) types.
       
  2009 @return KErrNone, if successful; otherwise one of the other system-wide error 
       
  2010 codes. 
       
  2011 */
       
  2012 EXPORT_C TInt RApaLsSession::GetSupportedDataTypesL(CDataTypeArray& aDataTypes) const
       
  2013 	{
       
  2014 	// gets the datatype count in terms of buffer length; negative value means one of the system-wide error
       
  2015 	TInt ret=SendReceiveWithReconnect(EAppListServGetDataTypesPhase1,TIpcArgs());
       
  2016 	if (ret>0)
       
  2017 		{
       
  2018 		CBufFlat* const buf=CBufFlat::NewL(ret);
       
  2019 		CleanupStack::PushL(buf);
       
  2020 		buf->ExpandL(0,ret);
       
  2021 		TPtr8 ptr=buf->Ptr(0);
       
  2022 		ret=SendReceiveWithReconnect(EAppListServGetDataTypesPhase2,TIpcArgs(&ptr));
       
  2023 		if (ret==KErrNone)
       
  2024 			{
       
  2025 			RBufReadStream readStream(*buf);
       
  2026 			readStream >> aDataTypes;
       
  2027 			}
       
  2028 		CleanupStack::PopAndDestroy(buf);
       
  2029 		}
       
  2030 	return ret;
       
  2031 	}
       
  2032 
       
  2033 
   839 
  2034 
   840 
  2035 /** Gets the icon for the specified view published by the application that has 
   841 /** Gets the icon for the specified view published by the application that has 
  2036 the specified UID.
   842 the specified UID.
  2037 
   843 
  2050 	{
   856 	{
  2051 	const TApaAppViewIconSizeData appViewIconSizeData(aAppUid, aViewUid, aSize);
   857 	const TApaAppViewIconSizeData appViewIconSizeData(aAppUid, aViewUid, aSize);
  2052 	const TPckgC<TApaAppViewIconSizeData> inputData(appViewIconSizeData);
   858 	const TPckgC<TApaAppViewIconSizeData> inputData(appViewIconSizeData);
  2053 	SReturnData_ViewIconByUidAndSize returnData = {0,0};
   859 	SReturnData_ViewIconByUidAndSize returnData = {0,0};
  2054 	TPckg<SReturnData_ViewIconByUidAndSize> returnData_asDescriptor(returnData);
   860 	TPckg<SReturnData_ViewIconByUidAndSize> returnData_asDescriptor(returnData);
  2055 	TInt error=SendReceiveWithReconnect(EAppListServViewIconByUidAndSize,TIpcArgs(&inputData,&returnData_asDescriptor));
   861 	TInt error = SendReceiveWithReconnect(EAppListServViewIconByUidAndSize,TIpcArgs(&inputData,&returnData_asDescriptor));
  2056 	if (error==KErrNone)
   862 	if (!error)
  2057 		{
   863 		{
  2058 		error=aViewBitmap.Duplicate(returnData.iIcon);
   864 		error = aViewBitmap.Duplicate(returnData.iIcon);
  2059 		if (error==KErrNone)
   865 		if (!error)
  2060 			{
   866 			error = aViewBitmap.Mask()->Duplicate(returnData.iIconMask);
  2061 			error=aViewBitmap.Mask()->Duplicate(returnData.iIconMask);
       
  2062 			}
       
  2063 		}
   867 		}
       
   868 		
  2064 	return error;
   869 	return error;
  2065 	}
   870 	}
  2066 
       
  2067 
   871 
  2068 
   872 
  2069 /** Gets the views published by the application that has the specified UID.
   873 /** Gets the views published by the application that has the specified UID.
  2070 
   874 
  2071 Information on each view is contained in a TApaAppViewInfo object, and this 
   875 Information on each view is contained in a TApaAppViewInfo object, and this 
  2089 	TViewDataArrayFiller arrayFiller(aArrayToFill);
   893 	TViewDataArrayFiller arrayFiller(aArrayToFill);
  2090 	FetchArrayL(arrayFiller, aAppUid, EAppListServGetAppViews, KInitialViewDataBufSize);
   894 	FetchArrayL(arrayFiller, aAppUid, EAppListServGetAppViews, KInitialViewDataBufSize);
  2091 	}
   895 	}
  2092 
   896 
  2093 
   897 
  2094 
       
  2095 /** Gets the list of file names for which the application with the specified 
   898 /** Gets the list of file names for which the application with the specified 
  2096 UID claims ownership.
   899 UID claims ownership.
  2097 
   900 
  2098 The list is written to a descriptor array supplied by the caller.
   901 The list is written to a descriptor array supplied by the caller.
  2099 
   902 
  2108 EXPORT_C TInt RApaLsSession::GetAppOwnedFiles(CDesCArray& aAppOwnedFiles, TUid aAppUid) const
   911 EXPORT_C TInt RApaLsSession::GetAppOwnedFiles(CDesCArray& aAppOwnedFiles, TUid aAppUid) const
  2109 	{
   912 	{
  2110 	TRAPD(error,DoGetAppOwnedFilesL(aAppOwnedFiles,aAppUid));
   913 	TRAPD(error,DoGetAppOwnedFilesL(aAppOwnedFiles,aAppUid));
  2111 	return error;
   914 	return error;
  2112 	}
   915 	}
  2113 
       
  2114 
   916 
  2115 
   917 
  2116 /** Gets the number of icons defined by the app that has the specified UID
   918 /** Gets the number of icons defined by the app that has the specified UID
  2117 
   919 
  2118 Applications that don't define icons in their application information file will
   920 Applications that don't define icons in their application information file will
  2125 the other system-wide error codes. 
   927 the other system-wide error codes. 
  2126 */
   928 */
  2127 EXPORT_C TInt RApaLsSession::NumberOfOwnDefinedIcons(TUid aAppUid, TInt& aCount) const
   929 EXPORT_C TInt RApaLsSession::NumberOfOwnDefinedIcons(TUid aAppUid, TInt& aCount) const
  2128 	{
   930 	{
  2129 	TPckgBuf<TInt> pckg;
   931 	TPckgBuf<TInt> pckg;
  2130 	TInt ret=SendReceiveWithReconnect(EAppListServNumberOfOwnDefinedIcons,TIpcArgs(aAppUid.iUid,&pckg));
   932 	const TInt err = SendReceiveWithReconnect(EAppListServNumberOfOwnDefinedIcons,TIpcArgs(aAppUid.iUid,&pckg));
  2131 	if (ret==KErrNone)
   933 	if (!err)
  2132 		{
   934 		aCount = pckg();
  2133 		aCount=pckg();
   935 
  2134 		}
   936 	return err;
  2135 	return ret;
   937 	}
  2136 	}
       
  2137 
       
  2138 
   938 
  2139 
   939 
  2140 /** Gets the full filename of a file containing application icons for the
   940 /** Gets the full filename of a file containing application icons for the
  2141 application with the specified UID.
   941 application with the specified UID.
  2142 
   942 
  2153 */
   953 */
  2154 EXPORT_C TInt RApaLsSession::GetAppIcon(TUid aAppUid, HBufC*& aFullFileName) const
   954 EXPORT_C TInt RApaLsSession::GetAppIcon(TUid aAppUid, HBufC*& aFullFileName) const
  2155 	{
   955 	{
  2156 	TFileName fileName;
   956 	TFileName fileName;
  2157 	TPckg<TFileName> filenamePckg(fileName);
   957 	TPckg<TFileName> filenamePckg(fileName);
  2158 	TInt ret=SendReceiveWithReconnect(EAppListServAppIconFileName, TIpcArgs(aAppUid.iUid, &filenamePckg));
   958 	const TInt err = SendReceiveWithReconnect(EAppListServAppIconFileName, TIpcArgs(aAppUid.iUid, &filenamePckg));
  2159 	if (ret==KErrNone)
   959 	if (!err)
  2160 		{
   960 		{
  2161 		HBufC* fullFileName = HBufC::New(fileName.Length());
   961 		HBufC* fullFileName = HBufC::New(fileName.Length());
  2162 		if (fullFileName == NULL)
   962 		if (fullFileName == NULL)
  2163 			{
       
  2164 			return KErrNoMemory;
   963 			return KErrNoMemory;
  2165 			}
       
  2166 		else
   964 		else
  2167 			{
   965 			{
  2168 			*fullFileName = fileName;
   966 			*fullFileName = fileName;
  2169 			aFullFileName = fullFileName; // ownership transferred to caller
   967 			aFullFileName = fullFileName; // ownership transferred to caller
  2170 			}
   968 			}
  2171 		}
   969 		}
  2172 	return ret;
   970 		
  2173 	}
   971 	return err;
  2174 
   972 	}
  2175 
   973 
  2176 
   974 
  2177 /** Gets the full filename of a file containing view-specific icons for the application
   975 /** Gets the full filename of a file containing view-specific icons for the application
  2178 with the specified UID and view.
   976 with the specified UID and view.
  2179 
   977 
  2192 */
   990 */
  2193 EXPORT_C TInt RApaLsSession::GetAppViewIcon(TUid aAppUid, TUid aViewUid, HBufC*& aFullFileName) const
   991 EXPORT_C TInt RApaLsSession::GetAppViewIcon(TUid aAppUid, TUid aViewUid, HBufC*& aFullFileName) const
  2194 	{
   992 	{
  2195 	TFileName fileName;
   993 	TFileName fileName;
  2196 	TPckg<TFileName> filenamePckg(fileName);
   994 	TPckg<TFileName> filenamePckg(fileName);
  2197 	TInt ret=SendReceiveWithReconnect(EAppListServAppViewIconFileName, TIpcArgs(aAppUid.iUid, aViewUid.iUid, &filenamePckg));
   995 	const TInt err = SendReceiveWithReconnect(EAppListServAppViewIconFileName, TIpcArgs(aAppUid.iUid, aViewUid.iUid, &filenamePckg));
  2198 	if (ret==KErrNone)
   996 	if (!err)
  2199 		{
   997 		{
  2200 		HBufC* fullFileName = HBufC::New(fileName.Length());
   998 		HBufC* fullFileName = HBufC::New(fileName.Length());
  2201 		if (fullFileName == NULL)
   999 		if (fullFileName == NULL)
  2202 			{
       
  2203 			return KErrNoMemory;
  1000 			return KErrNoMemory;
  2204 			}
       
  2205 		else
  1001 		else
  2206 			{
  1002 			{
  2207 			*fullFileName = fileName;
  1003 			*fullFileName = fileName;
  2208 			aFullFileName = fullFileName; // ownership transferred to caller
  1004 			aFullFileName = fullFileName; // ownership transferred to caller
  2209 			}
  1005 			}
  2210 		}
  1006 		}
  2211 	return ret;
  1007 
  2212 	}
  1008 	return err;
  2213 
  1009 	}
  2214 
  1010 
  2215 
  1011 
  2216 /** Changes an existing data type mapping, or adds a new one.
  1012 /** Changes an existing data type mapping, or adds a new one.
  2217 
  1013 
  2218 If the data type is not currently mapped, a new mapping is added. 
  1014 If the data type is not currently mapped, a new mapping is added. 
  2226 */
  1022 */
  2227 EXPORT_C TInt RApaLsSession::InsertDataMapping(const TDataType& aDataType, TDataTypePriority aPriority, TUid aUid)
  1023 EXPORT_C TInt RApaLsSession::InsertDataMapping(const TDataType& aDataType, TDataTypePriority aPriority, TUid aUid)
  2228 	{
  1024 	{
  2229 	return InsertDataMapping(aDataType, aPriority, aUid, KOpenServiceUid);
  1025 	return InsertDataMapping(aDataType, aPriority, aUid, KOpenServiceUid);
  2230 	}
  1026 	}
       
  1027 
  2231 
  1028 
  2232 /** Changes an existing data type mapping, or adds a new one.
  1029 /** Changes an existing data type mapping, or adds a new one.
  2233 
  1030 
  2234 If the data type is not currently mapped, a new mapping is added. 
  1031 If the data type is not currently mapped, a new mapping is added. 
  2235 If the data type is mapped, its mapping is replaced.
  1032 If the data type is mapped, its mapping is replaced.
  2238 @param aDataType A new or existing data type.
  1035 @param aDataType A new or existing data type.
  2239 @param aPriority The priority with which the application handles the data type.
  1036 @param aPriority The priority with which the application handles the data type.
  2240 @param aUid The UID of the application to associate with the data type.
  1037 @param aUid The UID of the application to associate with the data type.
  2241 @param aServiceUid The UID of the service.
  1038 @param aServiceUid The UID of the service.
  2242 @return KErrNone on success, or a system-wide error code. 
  1039 @return KErrNone on success, or a system-wide error code. 
       
  1040 @internalComponent
       
  1041 @released
  2243 */
  1042 */
  2244 EXPORT_C TInt RApaLsSession::InsertDataMapping(const TDataType& aDataType, TDataTypePriority aPriority, 
  1043 EXPORT_C TInt RApaLsSession::InsertDataMapping(const TDataType& aDataType, TDataTypePriority aPriority, 
  2245 	TUid aUid, TUid aServiceUid)
  1044 	TUid aUid, TUid aServiceUid)
  2246 	{
  1045 	{
  2247 	const TPckgC<TDataType> dataType(aDataType);
  1046 	const TPckgC<TDataType> dataType(aDataType);
  2248 	return SendReceiveWithReconnect(EAppListInsertDataMapping, 
  1047 	return SendReceiveWithReconnect(EAppListInsertDataMapping, 
  2249 		TIpcArgs(&dataType, TInt(aPriority), aUid.iUid, aServiceUid.iUid));
  1048 		TIpcArgs(&dataType, TInt(aPriority), aUid.iUid, aServiceUid.iUid));
  2250 	} //lint !e1762 Suppress member function could be made const
  1049 	} //lint !e1762 Suppress member function could be made const
       
  1050 
  2251 
  1051 
  2252 /** Changes an existing data type mapping, or adds a new one.
  1052 /** Changes an existing data type mapping, or adds a new one.
  2253 If the data type is not currently mapped, it is added.
  1053 If the data type is not currently mapped, it is added.
  2254 If the data type is mapped with a priority lower than aPriority, the new mapping replaces the existing one. 
  1054 If the data type is mapped with a priority lower than aPriority, the new mapping replaces the existing one. 
  2255 Otherwise, no change is made.
  1055 Otherwise, no change is made.
  2263 */
  1063 */
  2264 EXPORT_C TInt RApaLsSession::InsertDataMappingIfHigher(const TDataType& aDataType, TDataTypePriority aPriority, TUid aUid, TBool& aInserted)
  1064 EXPORT_C TInt RApaLsSession::InsertDataMappingIfHigher(const TDataType& aDataType, TDataTypePriority aPriority, TUid aUid, TBool& aInserted)
  2265 	{
  1065 	{
  2266 	TPckgBuf<TBool> inserted(EFalse);
  1066 	TPckgBuf<TBool> inserted(EFalse);
  2267 	const TPckgC<TDataType> dataType(aDataType);
  1067 	const TPckgC<TDataType> dataType(aDataType);
  2268 	const TInt ret = SendReceiveWithReconnect(EAppListInsertDataMappingIfHigher, TIpcArgs(&dataType, TInt(aPriority), aUid.iUid, &inserted));
  1068 	const TInt err = SendReceiveWithReconnect(EAppListInsertDataMappingIfHigher, TIpcArgs(&dataType, TInt(aPriority), aUid.iUid, &inserted));
  2269 	if(ret == KErrNone)
  1069 	if(!err)
  2270 		{
       
  2271 		aInserted = inserted();
  1070 		aInserted = inserted();
  2272 		}
  1071 		
  2273 	return ret;
  1072 	return err;
  2274 	} //lint !e1762 Suppress member function could be made const
  1073 	} //lint !e1762 Suppress member function could be made const
  2275 
  1074 
  2276 
  1075 
  2277 
  1076 
  2278 /** Removes an existing user mapping between an application and data-type made through InsertDataMapping() or InsertDataMappingIfHigher().
  1077 /** Removes an existing user mapping between an application and data-type made through InsertDataMapping() or InsertDataMappingIfHigher().
  2287 EXPORT_C TInt RApaLsSession::DeleteDataMapping(const TDataType& aDataType)
  1086 EXPORT_C TInt RApaLsSession::DeleteDataMapping(const TDataType& aDataType)
  2288 	{
  1087 	{
  2289 	return DeleteDataMapping(aDataType, KOpenServiceUid);
  1088 	return DeleteDataMapping(aDataType, KOpenServiceUid);
  2290 	}
  1089 	}
  2291 
  1090 
       
  1091 
  2292 /** Removes an existing data type mapping.
  1092 /** Removes an existing data type mapping.
  2293 
  1093 
  2294 @capability WriteDeviceData Prevent removal of data type mappings by malicious programs.
  1094 @capability WriteDeviceData Prevent removal of data type mappings by malicious programs.
  2295 @param aDataType Data type whose mapping should be removed.
  1095 @param aDataType Data type whose mapping should be removed.
  2296 @param aServiceUid The UID of the service.
  1096 @param aServiceUid The UID of the service.
  2297 @panic USER 0 The specified data type cannot be found. Debug builds only.
  1097 @panic USER 0 The specified data type cannot be found. Debug builds only.
  2298 @return KErrNone on success, or a system-wide error code. 
  1098 @return KErrNone on success, or a system-wide error code. 
       
  1099 @internalComponent
       
  1100 @released
  2299 */
  1101 */
  2300 EXPORT_C TInt RApaLsSession::DeleteDataMapping(const TDataType& aDataType, TUid aServiceUid)
  1102 EXPORT_C TInt RApaLsSession::DeleteDataMapping(const TDataType& aDataType, TUid aServiceUid)
  2301 	{
  1103 	{
  2302 	const TPckgC<TDataType> dataType(aDataType);
  1104 	const TPckgC<TDataType> dataType(aDataType);
  2303 	return SendReceiveWithReconnect(EAppListDeleteDataMapping, TIpcArgs(&dataType, aServiceUid.iUid));
  1105 	return SendReceiveWithReconnect(EAppListDeleteDataMapping, TIpcArgs(&dataType, aServiceUid.iUid));
  2304 	} //lint !e1762 Suppress member function could be made const
  1106 	} //lint !e1762 Suppress member function could be made const
       
  1107 
  2305 	
  1108 	
  2306 /** Gets the application associated with the data type and the service uid from
  1109 /** Gets the application associated with the data type and the service uid from
  2307 the datatype store. 
  1110 the datatype store. 
  2308 
  1111 
  2309 The function will only look into the datatype store and will not use the 
  1112 The function will only look into the datatype store and will not use the 
  2313 @param aAppUid On return, the UID of the application that can handle the data 
  1116 @param aAppUid On return, the UID of the application that can handle the data 
  2314 (MIME) type; this may be NULL.
  1117 (MIME) type; this may be NULL.
  2315 @param aServiceUid The UID of the service.
  1118 @param aServiceUid The UID of the service.
  2316 @return KErrNone, if successful; otherwise one of the other system-wide error 
  1119 @return KErrNone, if successful; otherwise one of the other system-wide error 
  2317 codes. 
  1120 codes. 
       
  1121 @internalComponent
       
  1122 @released
  2318 */
  1123 */
  2319 EXPORT_C TInt RApaLsSession::GetAppByDataType(const TDataType& aDataType, TUid aServiceUid, TUid& aAppUid) const
  1124 EXPORT_C TInt RApaLsSession::GetAppByDataType(const TDataType& aDataType, TUid aServiceUid, TUid& aAppUid) const
  2320 	{
  1125 	{
  2321 	const TPckgC<TDataType> dataType(aDataType);
  1126 	const TPckgC<TDataType> dataType(aDataType);
  2322 	TPckg<TUid> uid(aAppUid);
  1127 	TPckg<TUid> uid(aAppUid);
  2323 	const TInt returnValue=SendReceiveWithReconnect(EAppListServGetAppByDataType,TIpcArgs(&dataType, aServiceUid.iUid, &uid));
  1128 	const TInt returnValue = SendReceiveWithReconnect(EAppListServGetAppByDataType,TIpcArgs(&dataType, aServiceUid.iUid, &uid));
  2324 	if (returnValue<0)
  1129 	if (returnValue < 0)
  2325 		{
       
  2326 		return returnValue;
  1130 		return returnValue;
  2327 		}
  1131 	
  2328 	if (aAppUid == KNullUid)
  1132 	return (aAppUid == KNullUid ? KErrNotFound : KErrNone);
  2329 		{
       
  2330 		return KErrNotFound;
       
  2331 		}
       
  2332 	else
       
  2333 		{
       
  2334 		return KErrNone;
       
  2335 		}
       
  2336 	} //lint !e1764 Suppress reference parameter 'aAppUid' could be declared const ref
  1133 	} //lint !e1764 Suppress reference parameter 'aAppUid' could be declared const ref
       
  1134 
  2337 
  1135 
  2338 /** Determines the current language an application is using to display its
  1136 /** Determines the current language an application is using to display its
  2339 user interface.
  1137 user interface.
  2340 @param aAppUid The application specific UID.
  1138 @param aAppUid The application specific UID.
  2341 @param aLanguage On return, the application language.  
  1139 @param aLanguage On return, the application language.  
  2343 otherwise one of the other system wide error codes.
  1141 otherwise one of the other system wide error codes.
  2344 */
  1142 */
  2345 EXPORT_C TInt RApaLsSession::ApplicationLanguage(TUid aAppUid, TLanguage& aLanguage) const
  1143 EXPORT_C TInt RApaLsSession::ApplicationLanguage(TUid aAppUid, TLanguage& aLanguage) const
  2346 	{
  1144 	{
  2347 	TPckgBuf<TLanguage> pckg;
  1145 	TPckgBuf<TLanguage> pckg;
  2348 	TInt errVal = SendReceiveWithReconnect(EAppListServApplicationLanguage, TIpcArgs(aAppUid.iUid, &pckg));
  1146 	const TInt err = SendReceiveWithReconnect(EAppListServApplicationLanguage, TIpcArgs(aAppUid.iUid, &pckg));
  2349 	if (errVal == KErrNone)
  1147 	if (!err)
  2350 		{
       
  2351 		aLanguage = pckg();
  1148 		aLanguage = pckg();
  2352 		}
  1149 
  2353 	return errVal;
  1150 	return err;
  2354 	}
  1151 	}
       
  1152 
  2355 
  1153 
  2356 /** Gets the services implemented by the application that has the specified
  1154 /** Gets the services implemented by the application that has the specified
  2357 application UID.
  1155 application UID.
  2358 
  1156 
  2359 The returned CApaAppServiceInfoArray object contains an array of TApaAppServiceInfo objects.
  1157 The returned CApaAppServiceInfoArray object contains an array of TApaAppServiceInfo objects.
  2376 @released
  1174 @released
  2377 */
  1175 */
  2378 EXPORT_C CApaAppServiceInfoArray* RApaLsSession::GetAppServicesLC(TUid aAppUid) const
  1176 EXPORT_C CApaAppServiceInfoArray* RApaLsSession::GetAppServicesLC(TUid aAppUid) const
  2379 	{
  1177 	{
  2380 	CArrayFixFlat<TApaAppServiceInfo>* serviceArray = new(ELeave) CArrayFixFlat<TApaAppServiceInfo>(4);
  1178 	CArrayFixFlat<TApaAppServiceInfo>* serviceArray = new(ELeave) CArrayFixFlat<TApaAppServiceInfo>(4);
  2381 	CleanupStack::PushL(TCleanupItem(CleanupServiceArray, serviceArray));
  1179 	CleanupStack::PushL(TCleanupItem(CleanupAppServiceArray, serviceArray));
  2382 	CBufBase* buffer = GetServiceBufferLC(EAppListServGetAppServices, aAppUid);
  1180 	CBufBase* buffer = GetServiceBufferLC(EAppListServGetAppServices, aAppUid);
  2383 	RBufReadStream readStream(*buffer);
  1181 	RBufReadStream readStream(*buffer);
  2384 	readStream >> *serviceArray;
  1182 	readStream >> *serviceArray;
  2385 	CleanupStack::PopAndDestroy(buffer);
  1183 	CleanupStack::PopAndDestroy(buffer);
  2386 	CleanupStack::Pop(serviceArray);
  1184 	CleanupStack::Pop(serviceArray);
  2387 	CApaAppServiceInfoArrayWrapper* wrapper = CApaAppServiceInfoArrayWrapper::NewL(serviceArray); // takes ownership of serviceArray
  1185 	CApaAppServiceInfoArrayImpl* wrapper = CApaAppServiceInfoArrayImpl::NewL(serviceArray); // takes ownership of serviceArray
  2388 	CleanupStack::PushL(wrapper);
  1186 	CleanupStack::PushL(wrapper);
  2389 	return wrapper;
  1187 	return wrapper;
  2390 	}
  1188 	}
  2391 
  1189 
  2392 CBufBase* RApaLsSession::GetServiceBufferLC(TInt aOpcode, TUid aUid1, TUid aUid2/*=KNullUid*/) const
  1190 CBufBase* RApaLsSession::GetServiceBufferLC(TInt aOpcode, TUid aUid1, TUid aUid2/*=KNullUid*/) const
  2458 @released
  1256 @released
  2459 */
  1257 */
  2460 EXPORT_C CApaAppServiceInfoArray* RApaLsSession::GetServiceImplementationsLC(TUid aServiceUid) const
  1258 EXPORT_C CApaAppServiceInfoArray* RApaLsSession::GetServiceImplementationsLC(TUid aServiceUid) const
  2461 	{
  1259 	{
  2462 	CArrayFixFlat<TApaAppServiceInfo>* serviceArray = new(ELeave) CArrayFixFlat<TApaAppServiceInfo>(4);
  1260 	CArrayFixFlat<TApaAppServiceInfo>* serviceArray = new(ELeave) CArrayFixFlat<TApaAppServiceInfo>(4);
  2463 	CleanupStack::PushL(TCleanupItem(CleanupServiceArray, serviceArray));
  1261 	CleanupStack::PushL(TCleanupItem(CleanupAppServiceArray, serviceArray));
  2464 	CBufBase* buffer = GetServiceBufferLC(EAppListServGetServiceImplementations, aServiceUid);
  1262 	CBufBase* buffer = GetServiceBufferLC(EAppListServGetServiceImplementations, aServiceUid);
  2465 	RBufReadStream readStream(*buffer);
  1263 	RBufReadStream readStream(*buffer);
  2466 	readStream >> *serviceArray;
  1264 	readStream >> *serviceArray;
  2467 	CleanupStack::PopAndDestroy(buffer);
  1265 	CleanupStack::PopAndDestroy(buffer);
  2468 	CleanupStack::Pop(serviceArray);
  1266 	CleanupStack::Pop(serviceArray);
  2469 	CApaAppServiceInfoArrayWrapper* wrapper = CApaAppServiceInfoArrayWrapper::NewL(serviceArray); // takes ownership of serviceArray
  1267 	CApaAppServiceInfoArrayImpl* wrapper = CApaAppServiceInfoArrayImpl::NewL(serviceArray); // takes ownership of serviceArray
  2470 	CleanupStack::PushL(wrapper);
  1268 	CleanupStack::PushL(wrapper);
  2471 	return wrapper;
  1269 	return wrapper;
  2472 	}
  1270 	}
  2473 	
  1271 	
  2474 EXPORT_C CApaAppServiceInfoArray* RApaLsSession::GetServiceImplementationsLC(TUid aServiceUid, const TDataType& aDataType) const
  1272 EXPORT_C CApaAppServiceInfoArray* RApaLsSession::GetServiceImplementationsLC(TUid aServiceUid, const TDataType& aDataType) const
  2493 @publishedPartner
  1291 @publishedPartner
  2494 @released
  1292 @released
  2495 */
  1293 */
  2496 	{
  1294 	{
  2497 	CArrayFixFlat<TApaAppServiceInfo>* serviceArray = new(ELeave) CArrayFixFlat<TApaAppServiceInfo>(4);
  1295 	CArrayFixFlat<TApaAppServiceInfo>* serviceArray = new(ELeave) CArrayFixFlat<TApaAppServiceInfo>(4);
  2498 	CleanupStack::PushL(TCleanupItem(CleanupServiceArray, serviceArray));
  1296 	CleanupStack::PushL(TCleanupItem(CleanupAppServiceArray, serviceArray));
  2499 	CBufBase* buffer = GetServiceBufferLC(EAppListServGetServiceImplementationsDataType, aServiceUid, aDataType);
  1297 	CBufBase* buffer = GetServiceBufferLC(EAppListServGetServiceImplementationsDataType, aServiceUid, aDataType);
  2500 	RBufReadStream readStream(*buffer);
  1298 	RBufReadStream readStream(*buffer);
  2501 	readStream >> *serviceArray;
  1299 	readStream >> *serviceArray;
  2502 	CleanupStack::PopAndDestroy(buffer);
  1300 	CleanupStack::PopAndDestroy(buffer);
  2503 	CleanupStack::Pop(serviceArray);
  1301 	CleanupStack::Pop(serviceArray);
  2504 	CApaAppServiceInfoArrayWrapper* wrapper = CApaAppServiceInfoArrayWrapper::NewL(serviceArray); // takes ownership of serviceArray
  1302 	CApaAppServiceInfoArrayImpl* wrapper = CApaAppServiceInfoArrayImpl::NewL(serviceArray); // takes ownership of serviceArray
  2505 	CleanupStack::PushL(wrapper);
  1303 	CleanupStack::PushL(wrapper);
  2506 	return wrapper;
  1304 	return wrapper;
  2507 	}
  1305 	}
  2508 
  1306 
  2509 /** Gets the service UIDs implemented by the application with the specified UID.
  1307 /** Gets the service UIDs implemented by the application with the specified UID.
  2552 @released
  1350 @released
  2553 */
  1351 */
  2554 EXPORT_C CApaAppServiceInfoArray* RApaLsSession::GetAppServiceOpaqueDataLC(TUid aAppUid, TUid aServiceUid) const
  1352 EXPORT_C CApaAppServiceInfoArray* RApaLsSession::GetAppServiceOpaqueDataLC(TUid aAppUid, TUid aServiceUid) const
  2555 	{
  1353 	{
  2556 	CArrayFixFlat<TApaAppServiceInfo>* serviceArray = new(ELeave) CArrayFixFlat<TApaAppServiceInfo>(4);
  1354 	CArrayFixFlat<TApaAppServiceInfo>* serviceArray = new(ELeave) CArrayFixFlat<TApaAppServiceInfo>(4);
  2557 	CleanupStack::PushL(TCleanupItem(CleanupServiceArray, serviceArray));
  1355 	CleanupStack::PushL(TCleanupItem(CleanupAppServiceArray, serviceArray));
  2558 	CBufBase* buffer = GetServiceBufferLC(EAppListServGetAppServiceOpaqueData, aAppUid, aServiceUid);
  1356 	CBufBase* buffer = GetServiceBufferLC(EAppListServGetAppServiceOpaqueData, aAppUid, aServiceUid);
  2559 	RBufReadStream readStream(*buffer);
  1357 	RBufReadStream readStream(*buffer);
  2560 	readStream >> *serviceArray;
  1358 	readStream >> *serviceArray;
  2561 	CleanupStack::PopAndDestroy(buffer);
  1359 	CleanupStack::PopAndDestroy(buffer);
  2562 	CleanupStack::Pop(serviceArray);
  1360 	CleanupStack::Pop(serviceArray);
  2563 	CApaAppServiceInfoArrayWrapper* wrapper = CApaAppServiceInfoArrayWrapper::NewL(serviceArray); // takes ownership of serviceArray
  1361 	CApaAppServiceInfoArrayImpl* wrapper = CApaAppServiceInfoArrayImpl::NewL(serviceArray); // takes ownership of serviceArray
  2564 	CleanupStack::PushL(wrapper);
  1362 	CleanupStack::PushL(wrapper);
  2565 	return wrapper;
  1363 	return wrapper;
  2566 	}
  1364 	}
  2567 
       
  2568 
  1365 
  2569 
  1366 
  2570 /** Gets the UID of an application that can handle the specified data (MIME) type and service.
  1367 /** Gets the UID of an application that can handle the specified data (MIME) type and service.
  2571 
  1368 
  2572 If no application can be found, the function returns the UID of the preferred 
  1369 If no application can be found, the function returns the UID of the preferred 
  2627 	return DoAppForDocumentOptionallySpecifyingService(aFile, aServiceUid, aAppUid, aDataType, EAppListServAppForDocumentAndServicePassedByFileHandle);
  1424 	return DoAppForDocumentOptionallySpecifyingService(aFile, aServiceUid, aAppUid, aDataType, EAppListServAppForDocumentAndServicePassedByFileHandle);
  2628 	}
  1425 	}
  2629 
  1426 
  2630 TInt RApaLsSession::DoAppForDocumentOptionallySpecifyingService(const TDesC& aFileName, TUid aServiceUid, TUid& aAppUid, TDataType& aDataType, TInt aOpcode) const
  1427 TInt RApaLsSession::DoAppForDocumentOptionallySpecifyingService(const TDesC& aFileName, TUid aServiceUid, TUid& aAppUid, TDataType& aDataType, TInt aOpcode) const
  2631 	{
  1428 	{
  2632 	if (aFileName.Length()==0)
  1429 	if (!aFileName.Length())
  2633 		{
  1430 		{
  2634 		aAppUid = KNullUid;
  1431 		aAppUid = KNullUid;
  2635 		return KErrNone;
  1432 		return KErrNone;
  2636 		}
  1433 		}
  2637 	HBufC8* buffer=NULL;
  1434 		
  2638 	TInt error=GetBufferFromFile(buffer, aFileName);
  1435 	HBufC8* buffer = NULL;
  2639 	if (error!=KErrNone)
  1436 	TInt error = GetNewBufferFromFile(buffer, aFileName);
  2640 		{
  1437 	if (error)
  2641 		return error;
  1438 		return error;
  2642 		}
  1439 
  2643 	SReturnData_AppForDocument returnData;
  1440 	SReturnData_AppForDocument returnData;
  2644 	TPckg<SReturnData_AppForDocument> returnData_asDescriptor(returnData);
  1441 	TPckg<SReturnData_AppForDocument> returnData_asDescriptor(returnData);
  2645 	error=SendReceiveWithReconnect(aOpcode,TIpcArgs(&returnData_asDescriptor, aServiceUid.iUid, &aFileName, buffer));
  1442 	error = SendReceiveWithReconnect(aOpcode, TIpcArgs(&returnData_asDescriptor, aServiceUid.iUid, &aFileName, buffer));
  2646 	delete buffer;
  1443 	delete buffer;
  2647 	buffer=NULL;
  1444 	buffer = NULL;
  2648 	if (error==KErrNone)
  1445 	
       
  1446 	if (!error)
  2649 		{
  1447 		{
  2650 		aAppUid=returnData.iUid;
  1448 		aAppUid = returnData.iUid;
  2651 		aDataType=returnData.iDataType;
  1449 		aDataType = returnData.iDataType;
  2652 		}
  1450 		}
       
  1451 
  2653 	return error;
  1452 	return error;
  2654 	}
  1453 	}
  2655 
  1454 
       
  1455 /**
       
  1456 */
  2656 TInt RApaLsSession::DoAppForDocumentOptionallySpecifyingService(const RFile& aFile, TUid aServiceUid, TUid& aAppUid, TDataType& aDataType, TInt aOpcode) const
  1457 TInt RApaLsSession::DoAppForDocumentOptionallySpecifyingService(const RFile& aFile, TUid aServiceUid, TUid& aAppUid, TDataType& aDataType, TInt aOpcode) const
  2657 	{
  1458 	{
  2658 	SReturnData_AppForDocument returnData;
  1459 	SReturnData_AppForDocument returnData;
  2659 	TPckg<SReturnData_AppForDocument> returnData_asDescriptor(returnData);
  1460 	TPckg<SReturnData_AppForDocument> returnData_asDescriptor(returnData);
  2660 	TIpcArgs ipcArgs(&returnData_asDescriptor, aServiceUid.iUid);
  1461 	TIpcArgs ipcArgs(&returnData_asDescriptor, aServiceUid.iUid);
  2661 	TInt error=aFile.TransferToServer(ipcArgs, 2, 3);
  1462 	TInt error = aFile.TransferToServer(ipcArgs, 2, 3);
  2662 	if (error == KErrNone)
  1463 	if (!error)
       
  1464 		error = SendReceiveWithReconnect(aOpcode, ipcArgs);
       
  1465 
       
  1466 	if (!error)
  2663 		{
  1467 		{
  2664 		error=SendReceiveWithReconnect(aOpcode, ipcArgs);
  1468 		aAppUid = returnData.iUid;
       
  1469 		aDataType = returnData.iDataType;
  2665 		}
  1470 		}
  2666 	if (error==KErrNone)
  1471 		
       
  1472 	return error;
       
  1473 	}
       
  1474 
       
  1475 /**
       
  1476 */
       
  1477 TInt RApaLsSession::GetNewBufferFromFile(HBufC8*& aBuffer, const TDesC& aFileName) const
       
  1478 	{
       
  1479 	aBuffer = NULL;
       
  1480 	TInt preferredBufSize = 0;
       
  1481 	const TInt error = GetPreferredBufSize(preferredBufSize);
       
  1482 	if (error < KErrNone)
       
  1483 		return error;
       
  1484 
       
  1485 	HBufC8* const buffer = HBufC8::New(Max(8, preferredBufSize)); // 8 is a sensible minimum
       
  1486 	if (!buffer)
       
  1487 		return KErrNoMemory;
       
  1488 
       
  1489 	const RFs* fsSession = FsSession();
       
  1490 	RFs tempFsSession;
       
  1491 	if (!fsSession)
  2667 		{
  1492 		{
  2668 		aAppUid=returnData.iUid;
  1493 		const TInt error = tempFsSession.Connect();
  2669 		aDataType=returnData.iDataType;
  1494 		if (error)
  2670 		}
       
  2671 	return error;
       
  2672 	}
       
  2673 
       
  2674 TInt RApaLsSession::GetBufferFromFile(HBufC8*& aBuffer, const TDesC& aFileName) const
       
  2675 	{
       
  2676 	TInt preferredBufSize=0;
       
  2677 	const TInt error=GetPreferredBufSize(preferredBufSize);
       
  2678 	if (error<KErrNone)
       
  2679 		{
       
  2680 		return error;
       
  2681 		}
       
  2682 	HBufC8* const buffer=HBufC8::New(Max(8, preferredBufSize)); // 8 is a sensible minimum
       
  2683 	if (buffer==NULL)
       
  2684 		{
       
  2685 		return KErrNoMemory;
       
  2686 		}
       
  2687 	const RFs* fsSession=FsSession();
       
  2688 	RFs tempFsSession;
       
  2689 	if (fsSession==NULL)
       
  2690 		{
       
  2691 		const TInt error=tempFsSession.Connect();
       
  2692 		if (error!=KErrNone)
       
  2693 			{
  1495 			{
  2694 			delete buffer;
  1496 			delete buffer;
  2695 			return error;
  1497 			return error;
  2696 			}
  1498 			}
  2697 		fsSession=&tempFsSession;
  1499 
       
  1500 		fsSession = &tempFsSession;
  2698 		}
  1501 		}
       
  1502 		
  2699 	if (fsSession->IsValidName(aFileName))
  1503 	if (fsSession->IsValidName(aFileName))
  2700 		{
  1504 		{
  2701 		TPtr8 buffer_asWritable(buffer->Des());
  1505 		TPtr8 buffer_asWritable(buffer->Des());
  2702 		const TInt error=fsSession->ReadFileSection(aFileName, 0, buffer_asWritable, preferredBufSize);
  1506 		const TInt error = fsSession->ReadFileSection(aFileName, 0, buffer_asWritable, preferredBufSize);
  2703 		if (error!=KErrNone)
  1507 		if (error)
  2704 			{
  1508 			{
  2705 			delete buffer;
  1509 			delete buffer;
  2706 			tempFsSession.Close();
  1510 			tempFsSession.Close();
  2707 			return error;
  1511 			return error;
  2708 			}
  1512 			}
  2709 		}
  1513 		}
  2710 	if (fsSession==&tempFsSession)
  1514 		
  2711 		{
  1515 	if (fsSession == &tempFsSession)
  2712 		tempFsSession.Close();
  1516 		tempFsSession.Close();
  2713 		}
  1517 		
  2714 	aBuffer=buffer;
  1518 	aBuffer = buffer;
  2715 	return KErrNone;
  1519 	return KErrNone;
  2716 	}
  1520 	}
  2717 
  1521 
  2718 EXPORT_C void RApaLsSession::SetFsSessionL(RFs& aFsSession)
  1522 
  2719 /**
  1523 /**
  2720 @internalTechnology
  1524 @internalTechnology
  2721 */
  1525 */
       
  1526 EXPORT_C void RApaLsSession::SetFsSessionL(RFs& aFsSession)
  2722 	{ // static
  1527 	{ // static
  2723 	User::LeaveIfError(Dll::SetTls(&aFsSession));
  1528 	User::LeaveIfError(Dll::SetTls(&aFsSession));
  2724 	}
  1529 	}
  2725 
  1530 
  2726 EXPORT_C void RApaLsSession::ClearFsSession()
       
  2727 /**
  1531 /**
  2728 @internalTechnology
  1532 @internalTechnology
  2729 */
  1533 */
       
  1534 EXPORT_C void RApaLsSession::ClearFsSession()
  2730 	{ // static
  1535 	{ // static
  2731 	Dll::FreeTls();
  1536 	Dll::FreeTls();
  2732 	}
  1537 	}
  2733 
  1538 
       
  1539 /**
       
  1540 @internalTechnology
       
  1541 */
  2734 EXPORT_C RFs* RApaLsSession::FsSession()
  1542 EXPORT_C RFs* RApaLsSession::FsSession()
  2735 /**
       
  2736 @internalComponent
       
  2737 */
       
  2738 	{ // static
  1543 	{ // static
  2739 	return static_cast<RFs*>(Dll::Tls());
  1544 	return static_cast<RFs*>(Dll::Tls());
  2740 	}
  1545 	}
  2741 
  1546 
  2742 /** @publishedPartner */
  1547 /** @publishedPartner */
  2797 		parser->SetNoWild(fileName, &KLitPathForNonNativeResourceAndIconFiles, &driveName);
  1602 		parser->SetNoWild(fileName, &KLitPathForNonNativeResourceAndIconFiles, &driveName);
  2798 		aRegistrationResourceFile.SetLocalisableResourceFileL(parser->FullName());
  1603 		aRegistrationResourceFile.SetLocalisableResourceFileL(parser->FullName());
  2799 
  1604 
  2800 		CleanupStack::PopAndDestroy(parser);
  1605 		CleanupStack::PopAndDestroy(parser);
  2801 		}
  1606 		}
       
  1607 		
  2802 	aRegistrationResourceFile.GenerateFileContentsL(ipcParameter0); // must be done after the aRegistrationResourceFile.SetLocalisableResourceFileL call (if there is one)
  1608 	aRegistrationResourceFile.GenerateFileContentsL(ipcParameter0); // must be done after the aRegistrationResourceFile.SetLocalisableResourceFileL call (if there is one)
  2803 	SNonNativeApplicationInfo nonNativeApplicationInfo;
  1609 	SNonNativeApplicationInfo nonNativeApplicationInfo;
  2804 	nonNativeApplicationInfo.iApplicationType=aApplicationType;
  1610 	nonNativeApplicationInfo.iApplicationType=aApplicationType;
  2805 	nonNativeApplicationInfo.iDrive=aDrive;
  1611 	nonNativeApplicationInfo.iDrive=aDrive;
  2806 	ipcParameter0.ReAllocL(sizeof(SNonNativeApplicationInfo)+ipcParameter0.Length());
  1612 	ipcParameter0.ReAllocL(sizeof(SNonNativeApplicationInfo)+ipcParameter0.Length());
  2830 EXPORT_C void RApaLsSession::CommitNonNativeApplicationsUpdatesL()
  1636 EXPORT_C void RApaLsSession::CommitNonNativeApplicationsUpdatesL()
  2831 	{
  1637 	{
  2832 	TIpcArgs ipcArgs(EFalse, 0, 0, 0);
  1638 	TIpcArgs ipcArgs(EFalse, 0, 0, 0);
  2833 	User::LeaveIfError(SendReceiveWithReconnect(EAppListServCommitNonNativeApplications, ipcArgs));
  1639 	User::LeaveIfError(SendReceiveWithReconnect(EAppListServCommitNonNativeApplications, ipcArgs));
  2834 	} //lint !e1762 Suppress member function could be made const
  1640 	} //lint !e1762 Suppress member function could be made const
  2835 
  1641 	
  2836 
  1642 
  2837 /**
  1643 /**
  2838 Commits the non-native application updates. This is an asynchronous method which will not wait until 
  1644 Commits the non-native application updates. This is an asynchronous method which will not wait until 
  2839 the application list is updated. CApaAppListNotifier class should be used to synchronize the completion 
  1645 the application list is updated. CApaAppListNotifier class should be used to synchronize the completion 
  2840 of updating the application list. 
  1646 of updating the application list. 
  2864 	{
  1670 	{
  2865 	TIpcArgs ipcArgs(0, 0, 0, 0);
  1671 	TIpcArgs ipcArgs(0, 0, 0, 0);
  2866 	return SendReceiveWithReconnect(EAppListServRollbackNonNativeApplications, ipcArgs);
  1672 	return SendReceiveWithReconnect(EAppListServRollbackNonNativeApplications, ipcArgs);
  2867 	} //lint !e1762 Suppress member function could be made const
  1673 	} //lint !e1762 Suppress member function could be made const
  2868 
  1674 
       
  1675 /**
       
  1676 @internalTechnology 
       
  1677 */
  2869 EXPORT_C void RApaLsSession::SetNotify(TBool aCompleteImmediatelyIfNoScanImpendingOrInProgress, TRequestStatus& aStatus)
  1678 EXPORT_C void RApaLsSession::SetNotify(TBool aCompleteImmediatelyIfNoScanImpendingOrInProgress, TRequestStatus& aStatus)
  2870 /**
       
  2871 @internalTechnology */
       
  2872 	{
  1679 	{
  2873 	SendReceive(ESetNotify,TIpcArgs(aCompleteImmediatelyIfNoScanImpendingOrInProgress),aStatus);
  1680 	SendReceive(ESetNotify,TIpcArgs(aCompleteImmediatelyIfNoScanImpendingOrInProgress),aStatus);
  2874 	} //lint !e1762 Suppress member function could be made const
  1681 	} //lint !e1762 Suppress member function could be made const
  2875 
  1682 
       
  1683 /**
       
  1684 @internalTechnology 
       
  1685 */
  2876 EXPORT_C void RApaLsSession::CancelNotify()
  1686 EXPORT_C void RApaLsSession::CancelNotify()
  2877 /**
       
  2878 @internalTechnology */
       
  2879 	{
  1687 	{
  2880 	SendReceive(ECancelNotify,TIpcArgs());
  1688 	SendReceive(ECancelNotify,TIpcArgs());
  2881 	} //lint !e1762 Suppress member function could be made const
  1689 	} //lint !e1762 Suppress member function could be made const
  2882 	
  1690 	
  2883 /**
  1691 /**
  2916 */
  1724 */
  2917 EXPORT_C TInt RApaLsSession::ForceRegistration(const RPointerArray<TDesC>& aRegFiles)
  1725 EXPORT_C TInt RApaLsSession::ForceRegistration(const RPointerArray<TDesC>& aRegFiles)
  2918 	{
  1726 	{
  2919 	CBufFlat* buffer = 0;
  1727 	CBufFlat* buffer = 0;
  2920 	TRAPD(err, buffer = CreateRegFilesBufferL(aRegFiles));
  1728 	TRAPD(err, buffer = CreateRegFilesBufferL(aRegFiles));
  2921 	if (err != KErrNone)
  1729 	if (err)
  2922 		{
       
  2923 		return err;
  1730 		return err;
  2924 		}
  1731 	
  2925 	TPtr8 ptr = buffer->Ptr(0);
  1732 	TPtr8 ptr = buffer->Ptr(0);
  2926 	const TInt returnValue=SendReceiveWithReconnect(EAppListServForceRegistration,TIpcArgs(&ptr));
  1733 	const TInt returnValue=SendReceiveWithReconnect(EAppListServForceRegistration,TIpcArgs(&ptr));
  2927 	delete buffer;
  1734 	delete buffer;
  2928 	return returnValue;
  1735 	return returnValue;
  2929 	} //lint !e1762 Suppress member function could be made const
  1736 	} //lint !e1762 Suppress member function could be made const
  2930 	
  1737 	
  2931 TInt RApaLsSession::SendReceiveWithReconnect(TInt aFunction,const TIpcArgs& aIpcArgs) const
  1738 	
       
  1739 /**
       
  1740 Make a call to AppArc server's aFunction, passing it aIpcArgs.
       
  1741 */
       
  1742 TInt RApaLsSession::SendReceiveWithReconnect(TInt aFunction, const TIpcArgs& aIpcArgs) const
  2932 	{
  1743 	{
  2933 	TInt ret = SendReceive(aFunction, aIpcArgs);
  1744 	TInt ret = SendReceive(aFunction, aIpcArgs);
  2934 	if(ret != KErrServerTerminated)
  1745 	if(ret != KErrServerTerminated)
  2935 		{
  1746 		{
  2936 		return ret;
  1747 		return ret;
  2952 	{
  1763 	{
  2953 	TDesCArrayFiller arrayFiller(aArrayToFill);
  1764 	TDesCArrayFiller arrayFiller(aArrayToFill);
  2954 	FetchArrayL(arrayFiller, aAppUid, EAppListServGetFileOwnershipInfo, KInitialOwnedFilesBufSize);
  1765 	FetchArrayL(arrayFiller, aAppUid, EAppListServGetFileOwnershipInfo, KInitialOwnedFilesBufSize);
  2955 	}
  1766 	}
  2956 
  1767 
  2957 EXPORT_C void RApaLsSession::RegisterListPopulationCompleteObserver(TRequestStatus& aStatus) const
  1768 
  2958 /** Registers an observer with apparc server to notify when the initial population of applist is completed
  1769 /** Registers an observer with apparc server to notify when the initial population of applist is completed
  2959 
  1770 
  2960 @param aStatus Request status object. On successful completion contains KErrNone, otherwise one of the 
  1771 @param aStatus Request status object. On successful completion contains KErrNone, otherwise one of the 
  2961 system-wide error codes. 
  1772 system-wide error codes. 
  2962 @see CancelListPopulationCompleteObserver()
  1773 @see CancelListPopulationCompleteObserver()
  2963 */
  1774 */
       
  1775 EXPORT_C void RApaLsSession::RegisterListPopulationCompleteObserver(TRequestStatus& aStatus) const
  2964 	{
  1776 	{
  2965 	SendReceive(ERegisterListPopulationCompleteObserver,TIpcArgs(TIpcArgs::ENothing),aStatus);
  1777 	SendReceive(ERegisterListPopulationCompleteObserver,TIpcArgs(TIpcArgs::ENothing),aStatus);
  2966 	}
  1778 	}
  2967 
  1779 
  2968 EXPORT_C TInt RApaLsSession::CancelListPopulationCompleteObserver() const
  1780 
  2969 /** Cancels the observer registered with apparc server to notify when the initial population of applist is completed
  1781 /** Cancels the observer registered with apparc server to notify when the initial population of applist is completed
  2970  
  1782  
  2971 @return KErrNone, if successful; otherwise one of the system-wide error codes. 
  1783 @return KErrNone, if successful; otherwise one of the system-wide error codes. 
  2972 */
  1784 */
       
  1785 EXPORT_C TInt RApaLsSession::CancelListPopulationCompleteObserver() const
  2973 	{
  1786 	{
  2974 	return SendReceiveWithReconnect(ECancelListPopulationCompleteObserver,TIpcArgs(TIpcArgs::ENothing));
  1787 	return SendReceiveWithReconnect(ECancelListPopulationCompleteObserver,TIpcArgs(TIpcArgs::ENothing));
  2975 	}
  1788 	}
  2976 
  1789 
  2977 EXPORT_C TInt RApaLsSession::MatchesSecurityPolicy(TBool& aMatches, TUid aAppUid, const TSecurityPolicy& aSecurityPolicy) const
  1790 
  2978 /** Tests whether the given TSecurityPolicy matches with the application TSecurityPolicy.
  1791 /** Tests whether the given TSecurityPolicy matches with the application TSecurityPolicy.
  2979 
  1792 
  2980 @param aMatches On return, contains the result. ETrue if the application TSecurityPolicy matches the given TSecurityPolicy or else EFalse
  1793 @param aMatches On return, contains the result. ETrue if the application TSecurityPolicy matches the given TSecurityPolicy or else EFalse
  2981 @param aAppUid Uid of the application for which the security policy has to be matched
  1794 @param aAppUid Uid of the application for which the security policy has to be matched
  2982 @param aSecurityPolicy TSecurityPolicy to test whether the application with given uid matches with its TSecurityPolicy or not.
  1795 @param aSecurityPolicy TSecurityPolicy to test whether the application with given uid matches with its TSecurityPolicy or not.
  2983 @return KErrNone, if successful; otherwise one of the other system-wide error codes.
  1796 @return KErrNone, if successful; otherwise one of the other system-wide error codes.
  2984 @see TSecurityPolicy
  1797 @see TSecurityPolicy
  2985 */
  1798 */
       
  1799 EXPORT_C TInt RApaLsSession::MatchesSecurityPolicy(TBool& aMatches, TUid aAppUid, const TSecurityPolicy& aSecurityPolicy) const
  2986 	{
  1800 	{
  2987 	const TPckgC<TSecurityPolicy> securityPolicy(aSecurityPolicy);
  1801 	const TPckgC<TSecurityPolicy> securityPolicy(aSecurityPolicy);
  2988 	const TInt result = SendReceiveWithReconnect(EMatchesSecurityPolicy,TIpcArgs(aAppUid.iUid, &securityPolicy));
  1802 	const TInt result = SendReceiveWithReconnect(EMatchesSecurityPolicy,TIpcArgs(aAppUid.iUid, &securityPolicy));
  2989 
  1803 
  2990 	if (result>=0)
  1804 	if (result>=0)
  2991 		{
       
  2992 		aMatches = result;
  1805 		aMatches = result;
  2993 		}
  1806 
  2994 	return result;
  1807 	return result;
  2995 	}
  1808 	}
  2996 
  1809 
       
  1810 
  2997 EXPORT_C void RApaLsSession::RApaLsSession_Reserved1()
  1811 EXPORT_C void RApaLsSession::RApaLsSession_Reserved1()
  2998 	{
  1812 	{
  2999 	}
  1813 	}
  3000 	
  1814 	
  3001 EXPORT_C void RApaLsSession::RApaLsSession_Reserved2()
  1815 EXPORT_C void RApaLsSession::RApaLsSession_Reserved2()
  3002 	{
  1816 	{
  3003 	}
  1817 	}
  3004 	
  1818 	
  3005 EXPORT_C void RApaLsSession::NotifyOnDataMappingChange(TRequestStatus& aRequestStatus)
  1819 
  3006 /** Notification of changes in data-type mapping
  1820 /** Notification of changes in data-type mapping
  3007 
  1821 
  3008 This asynchronous function (whose corresponding "cancel" operation is CancelNotifyOnDataTypeMappingChange) completes when any data-type / application-UID association changes, i.e. when the default application handling a particular MIME-type changes.
  1822 This asynchronous function (whose corresponding "cancel" operation is CancelNotifyOnDataTypeMappingChange) completes when any data-type / application-UID association changes, i.e. when the default application handling a particular MIME-type changes.
  3009 
  1823 
  3010 @param aRequestStatus As is normal for an asynchronous operation, this object is set to something other than KRequestPending when the asynchronous operation that has been triggered by this function completes.
  1824 @param aRequestStatus As is normal for an asynchronous operation, this object is set to something other than KRequestPending when the asynchronous operation that has been triggered by this function completes.
  3011 @see CancelNotifyOnDataTypeMappingChange
  1825 @see CancelNotifyOnDataTypeMappingChange
  3012 */
  1826 */
       
  1827 EXPORT_C void RApaLsSession::NotifyOnDataMappingChange(TRequestStatus& aRequestStatus)
  3013 	{
  1828 	{
  3014 	SendReceive(ENotifyOnDataMappingChange,TIpcArgs(), aRequestStatus);
  1829 	SendReceive(ENotifyOnDataMappingChange,TIpcArgs(), aRequestStatus);
  3015  	} //lint !e1762 Suppress member function could be made const
  1830  	} //lint !e1762 Suppress member function could be made const
       
  1831 
  3016  	
  1832  	
  3017 EXPORT_C void RApaLsSession::CancelNotifyOnDataMappingChange()
       
  3018 /** Cancellation of notification of changes in data-type mapping
  1833 /** Cancellation of notification of changes in data-type mapping
  3019 
  1834 
  3020 This cancels the outstanding the NotifyOnDataTypeMappingChange issued by this client, if there is one outstanding. Otherwise it does nothing.
  1835 This cancels the outstanding the NotifyOnDataTypeMappingChange issued by this client, if there is one outstanding. Otherwise it does nothing.
  3021 @see NotifyOnDataTypeMappingChange
  1836 @see NotifyOnDataTypeMappingChange
  3022 */
  1837 */
       
  1838 EXPORT_C void RApaLsSession::CancelNotifyOnDataMappingChange()
  3023 	{
  1839 	{
  3024 	SendReceive(ECancelNotifyOnDataMappingChange,TIpcArgs());
  1840 	SendReceive(ECancelNotifyOnDataMappingChange,TIpcArgs());
  3025 	} //lint !e1762 Suppress member function could be made const
  1841 	} //lint !e1762 Suppress member function could be made const
       
  1842 
  3026 
  1843 
  3027 CBufFlat* RApaLsSession::CreateRegFilesBufferL(const RPointerArray<TDesC>& aRegFiles)
  1844 CBufFlat* RApaLsSession::CreateRegFilesBufferL(const RPointerArray<TDesC>& aRegFiles)
  3028 	{
  1845 	{
  3029 	// Serialize the array
  1846 	// Serialize the array
  3030 	// Format of the buffer is :
  1847 	// Format of the buffer is :
  3048 	for (TInt index = 0; index < count; ++index)
  1865 	for (TInt index = 0; index < count; ++index)
  3049 		{
  1866 		{
  3050 		writeStream.WriteUint32L(aRegFiles[index]->Length());
  1867 		writeStream.WriteUint32L(aRegFiles[index]->Length());
  3051 		writeStream.WriteL(*aRegFiles[index]);
  1868 		writeStream.WriteL(*aRegFiles[index]);
  3052 		}
  1869 		}
       
  1870 
  3053 	writeStream.CommitL();
  1871 	writeStream.CommitL();
  3054 	CleanupStack::PopAndDestroy(&writeStream);
  1872 	CleanupStack::PopAndDestroy(&writeStream);
  3055 	CleanupStack::Pop(buffer);
  1873 	CleanupStack::Pop(buffer);
  3056 	return buffer;
  1874 	return buffer;
  3057 	}
  1875 	}
  3058 
       
  3059 // TSizeArrayFiller
       
  3060 
       
  3061 void TSizeArrayFiller::AppendItemL(RReadStream& aReadStream)
       
  3062 	{
       
  3063 	TSize size;
       
  3064 	size.iWidth =aReadStream.ReadUint32L();
       
  3065 	size.iHeight=aReadStream.ReadUint32L();
       
  3066 	iArray.AppendL(size);
       
  3067 	}
       
  3068 
       
  3069 
       
  3070 
       
  3071 // TViewDataArrayFiller
       
  3072 
       
  3073 void TViewDataArrayFiller::AppendItemL(RReadStream& aReadStream)
       
  3074 	{
       
  3075 	TApaAppViewInfo info;
       
  3076 	aReadStream >> info;
       
  3077 	iArray.AppendL(info);
       
  3078 	}
       
  3079 
       
  3080 
       
  3081 
       
  3082 // TDesCArrayFiller
       
  3083 
       
  3084 void TDesCArrayFiller::AppendItemL(RReadStream& aReadStream)
       
  3085 	{
       
  3086 	TFileName info;
       
  3087 	aReadStream >> info;
       
  3088 	iArray.AppendL(info);
       
  3089 	}
       
  3090 
       
  3091 /* @internalComponent
       
  3092 */
       
  3093 EXPORT_C TUint MinApplicationStackSize()
       
  3094 	{
       
  3095 	return KMinApplicationStackSize;
       
  3096 	}