installationservices/swi/source/sislauncher/client/sislauncherclient.cpp
branchRCL_3
changeset 25 7333d7932ef7
parent 0 ba25891c3a9e
child 26 8b7f4e561641
equal deleted inserted replaced
24:5cc91383ab1e 25:7333d7932ef7
     1 /*
     1 /*
     2 * Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2004-2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of the License "Eclipse Public License v1.0"
     5 * under the terms of the License "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    27  
    27  
    28 #include "sislauncherclient.h"
    28 #include "sislauncherclient.h"
    29 #include "sislauncherclientserver.h"
    29 #include "sislauncherclientserver.h"
    30 #include "sisregistryfiledescription.h"
    30 #include "sisregistryfiledescription.h"
    31 #include "secutils.h"
    31 #include "secutils.h"
    32 
       
    33 #include "arrayutils.h"  // from source/sisregistry/common/ 
    32 #include "arrayutils.h"  // from source/sisregistry/common/ 
    34 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
    33 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
    35 #include "swtypereginfo.h"
    34 #include "swtypereginfo.h"
       
    35 #include "ipcutil.h"
    36 #endif
    36 #endif
    37 
    37 
    38 using namespace Swi;
    38 using namespace Swi;
    39 
    39 
    40 static TInt StartSisLauncherServer()
    40 static TInt StartSisLauncherServer()
    41 	{
    41     {
    42 	const TUidType serverUid(KNullUid, KNullUid, KServerUid3);
    42     const TUidType serverUid(KNullUid, KNullUid, KServerUid3);
    43 	RProcess server;
    43     RProcess server;
    44 	TInt err = server.Create(KSisLauncherServerImg, KNullDesC, serverUid);
    44     TInt err = server.Create(KSisLauncherServerImg, KNullDesC, serverUid);
    45 	if (err != KErrNone)
    45     if (err != KErrNone)
    46 		{
    46         {
    47 		return err;
    47         return err;
    48 		}
    48         }
    49 	TRequestStatus stat;
    49     TRequestStatus stat;
    50 	server.Rendezvous(stat);
    50     server.Rendezvous(stat);
    51 	if (stat != KRequestPending)
    51     if (stat != KRequestPending)
    52 		{
    52         {
    53 		server.Kill(0);		// abort startup
    53         server.Kill(0);     // abort startup
    54 		}
    54         }
    55 	else
    55     else
    56 		{
    56         {
    57 		server.Resume();	// logon OK - start the server
    57         server.Resume();    // logon OK - start the server
    58 		}
    58         }
    59 	User::WaitForRequest(stat);		// wait for start or death
    59     User::WaitForRequest(stat);     // wait for start or death
    60 	// we can't use the 'exit reason' if the server panicked as this
    60     // we can't use the 'exit reason' if the server panicked as this
    61 	// is the panic 'reason' and may be '0' which cannot be distinguished
    61     // is the panic 'reason' and may be '0' which cannot be distinguished
    62 	// from KErrNone
    62     // from KErrNone
    63 	err = (server.ExitType() == EExitPanic) ? KErrGeneral : stat.Int();
    63     err = (server.ExitType() == EExitPanic) ? KErrGeneral : stat.Int();
    64 	server.Close();
    64     server.Close();
    65 	return err;
    65     return err;
    66 	}
    66     }
    67 
    67 
    68 EXPORT_C TInt RSisLauncherSession::Connect()
    68 EXPORT_C TInt RSisLauncherSession::Connect()
    69 //
    69 //
    70 // Connect to the server, attempting to start it if necessary
    70 // Connect to the server, attempting to start it if necessary
    71 //
    71 //
    72 	{
    72     {
    73 	TInt retry=2;
    73 	#ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
    74 	for (;;)
    74     iBuffForLanguages = NULL;
       
    75 	#endif
       
    76     
       
    77     TInt retry=2;
       
    78     for (;;)
       
    79         {
       
    80         TInt err = CreateSession(KSisLauncherServerName, TVersion(0, 0, 0), 1);
       
    81         if (err != KErrNotFound && err != KErrServerTerminated)
       
    82             {
       
    83             return err;
       
    84             }
       
    85         if (--retry==0)
       
    86             {
       
    87             return err;
       
    88             }
       
    89         err = StartSisLauncherServer();
       
    90         if (err != KErrNone && err != KErrAlreadyExists)
       
    91             {
       
    92             return err;
       
    93             }
       
    94         }    
       
    95     }
       
    96 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
       
    97 EXPORT_C void RSisLauncherSession::Close()
       
    98     {	
       
    99     if (iBuffForLanguages)
       
   100         {
       
   101         delete iBuffForLanguages;
       
   102         iBuffForLanguages = NULL;
       
   103         }
       
   104 	    
       
   105     RSessionBase::Close();
       
   106     }
       
   107 #endif
       
   108 EXPORT_C void RSisLauncherSession::RunExecutableL(const TDesC& aFileName, TBool aWait)
       
   109     {
       
   110     TPckgC<TBool> wait(aWait);
       
   111     User::LeaveIfError(SendReceive(ERunExecutable, TIpcArgs(&aFileName, &wait)));
       
   112     }
       
   113 
       
   114 EXPORT_C void RSisLauncherSession::StartDocumentL(RFile& aFile, TBool aWait)
       
   115     {
       
   116     TPckgC<TBool> wait(aWait);
       
   117     TIpcArgs ipcArgs;
       
   118     aFile.TransferToServer(ipcArgs, 0, 1);
       
   119     ipcArgs.Set(2, &wait);
       
   120     User::LeaveIfError(SendReceive(EStartDocumentByHandle, ipcArgs));
       
   121     }
       
   122 
       
   123 EXPORT_C void RSisLauncherSession::StartByMimeL(RFile& aFile, const TDesC8& aMimeType, TBool aWait)
       
   124     {
       
   125     TPckgC<TBool> wait(aWait);
       
   126     TIpcArgs ipcArgs;
       
   127     aFile.TransferToServer(ipcArgs, 0, 1);
       
   128     ipcArgs.Set(2, &aMimeType);
       
   129     ipcArgs.Set(3, &wait);
       
   130     
       
   131     User::LeaveIfError(SendReceive(EStartByMimeByHandle, ipcArgs));
       
   132     }
       
   133 
       
   134 EXPORT_C void RSisLauncherSession::StartDocumentL(const TDesC& aFileName, TBool aWait)
       
   135     {
       
   136     TPckgC<TBool> wait(aWait);
       
   137     User::LeaveIfError(SendReceive(EStartDocument, TIpcArgs(&aFileName, &wait)));
       
   138     }
       
   139 
       
   140 EXPORT_C void RSisLauncherSession::StartByMimeL(const TDesC& aFileName, const TDesC8& aMimeType, TBool aWait)
       
   141     {
       
   142     TPckgC<TBool> wait(aWait);
       
   143     User::LeaveIfError(SendReceive(EStartByMime, TIpcArgs(&aFileName, &aMimeType, &wait)));
       
   144     }
       
   145 
       
   146 EXPORT_C void RSisLauncherSession::ShutdownAllL()
       
   147     {
       
   148     User::LeaveIfError(SendReceive(EShutdownAll));
       
   149     }
       
   150 
       
   151 EXPORT_C void RSisLauncherSession::CheckApplicationInUseL(RArray<TAppInUse>& aUidList)
       
   152     {
       
   153     TInt uidCount=aUidList.Count();
       
   154     if (uidCount)
       
   155         {
       
   156         HBufC8* appInUseBuf=HBufC8::NewLC(uidCount * sizeof(TAppInUse));
       
   157         TPtr8 appInUsePtr=appInUseBuf->Des();
       
   158         TUint8* dataPtr(NULL);
       
   159         TInt i;
       
   160         for (i = 0 ; i < uidCount ; ++i)
       
   161             {
       
   162             dataPtr=reinterpret_cast<TUint8*>(&aUidList[i]);
       
   163             appInUsePtr.Append(dataPtr, sizeof(TAppInUse));         
       
   164             }   
       
   165         User::LeaveIfError((SendReceive(ECheckApplicationInUse, TIpcArgs(&appInUsePtr))));
       
   166 
       
   167         //Copy the result back to the RArray
       
   168         dataPtr=const_cast<TUint8*>(appInUsePtr.Ptr());
       
   169         TAppInUse* appInUseDataPtr=reinterpret_cast<TAppInUse*>(dataPtr);
       
   170         for (i = 0; i < uidCount; ++i)
       
   171             {
       
   172             aUidList[i]=appInUseDataPtr[i]; 
       
   173             }               
       
   174             
       
   175         CleanupStack::PopAndDestroy(appInUseBuf);               
       
   176         }
       
   177     }
       
   178     
       
   179 EXPORT_C void RSisLauncherSession::ShutdownL(const RArray<TUid>& aUidList, TInt aTimeout)
       
   180     {
       
   181     TInt uidCount=aUidList.Count();
       
   182     if (uidCount)   
       
   183         {
       
   184         HBufC8* tUidBuf=HBufC8::NewLC(uidCount * sizeof(TUid));
       
   185         TPtr8 tUidBufPtr=tUidBuf->Des();
       
   186         const TUint8* dataPtr(NULL);
       
   187         
       
   188         for (TInt i=0;i<uidCount;i++)
       
   189             {
       
   190             dataPtr=reinterpret_cast<const TUint8*>(&aUidList[i]);
       
   191             tUidBufPtr.Append(dataPtr, sizeof(TUid));
       
   192             }   
       
   193         User::LeaveIfError((SendReceive(EShutdown, TIpcArgs(&tUidBufPtr, aTimeout))));      
       
   194         CleanupStack::PopAndDestroy(tUidBuf);                           
       
   195         }
       
   196     }
       
   197 
       
   198 EXPORT_C void RSisLauncherSession::NotifyNewAppsL(const RPointerArray<TDesC>& aFiles)
       
   199     {
       
   200     if (aFiles.Count() > 0)
       
   201         {
       
   202         CBufFlat* tmpBuf = CBufFlat::NewL(255);
       
   203         CleanupStack::PushL(tmpBuf);
       
   204             
       
   205         RBufWriteStream stream(*tmpBuf);
       
   206         CleanupClosePushL(stream);
       
   207 
       
   208         ExternalizePointerArrayL(aFiles, stream);
       
   209 
       
   210         // Create an HBufC8 from the stream buf's length, and copy 
       
   211         // the stream buffer into this descriptor
       
   212         HBufC8* buffer = HBufC8::NewLC(tmpBuf->Size());
       
   213         TPtr8 ptr(buffer->Des());
       
   214         tmpBuf->Read(0, ptr, tmpBuf->Size());
       
   215     
       
   216         User::LeaveIfError(SendReceive(ENotifyNewApps, TIpcArgs(&ptr)));
       
   217         CleanupStack::PopAndDestroy(3, tmpBuf);
       
   218         }
       
   219     }
       
   220 
       
   221 EXPORT_C void RSisLauncherSession::RunAfterEcomNotificationL(const RPointerArray<CSisRegistryFileDescription>& aFileList)
       
   222     {
       
   223     TInt count = aFileList.Count();
       
   224     if (count <= 0)
       
   225         {
       
   226         return; 
       
   227         }
       
   228 
       
   229     RFs fs;
       
   230     User::LeaveIfError(fs.Connect());
       
   231     CleanupClosePushL(fs);
       
   232     User::LeaveIfError(fs.ShareProtected());
       
   233 
       
   234     for (TInt i = 0; i < count; ++i)
       
   235         {
       
   236         CSisRegistryFileDescription* fileDes = aFileList[i];
       
   237 
       
   238         // open the file entry
       
   239         TEntry entry;
       
   240         if (fs.Entry(fileDes->Target(), entry) != KErrNone)
       
   241             {
       
   242             // just ignore, there's nothing we can do and we should try to process the
       
   243             // remaining files.
       
   244             continue;
       
   245             }
       
   246         
       
   247         TIpcArgs ipcArgs;
       
   248         TBool waitEnd = 0 != (fileDes->OperationOptions() & Sis::EInstFileRunOptionWaitEnd);
       
   249         TPckgC<TBool> wait(waitEnd);
       
   250         ipcArgs.Set(2, &wait);
       
   251 
       
   252         TInt err = KErrNone;
       
   253 
       
   254         if (entry.IsTypeValid() && SecUtils::IsExe(entry))
       
   255             {
       
   256             ipcArgs.Set(0,&fileDes->Target());
       
   257             err = SendReceive(EQueueRunExecutable, ipcArgs);
       
   258             }
       
   259         else 
       
   260             {
       
   261             RFile file;
       
   262             CleanupClosePushL(file);
       
   263             err = file.Open(fs, fileDes->Target(), EFileShareExclusive|EFileWrite);
       
   264 
       
   265             HBufC8* mimeType = 0;
       
   266 
       
   267             if (err == KErrNone)
       
   268                 {
       
   269                 if (fileDes->OperationOptions() & Sis::EInstFileRunOptionByMimeType)
       
   270                     {
       
   271                     mimeType = HBufC8::NewLC(fileDes->MimeType().Length());
       
   272                     TPtr8 ptr = mimeType->Des();
       
   273                     ptr.Copy(fileDes->MimeType());
       
   274                     }
       
   275 
       
   276                 if (file.TransferToServer(ipcArgs, 0, 1) != KErrNone)
       
   277                     {
       
   278                     // best effort is to continue with remaining exes
       
   279                     }   
       
   280                 else if (mimeType != 0)
       
   281                     {
       
   282                     TPtrC8 x = mimeType->Des();
       
   283                     ipcArgs.Set(3, &x);
       
   284                     err = SendReceive(EQueueStartByMimeByHandle, ipcArgs);
       
   285                     }
       
   286                 else
       
   287                     {
       
   288                     err = SendReceive(EQueueStartDocumentByHandle, ipcArgs);
       
   289                     }
       
   290                 if (mimeType != 0)
       
   291                     {
       
   292                     CleanupStack::PopAndDestroy(mimeType);
       
   293                     }
       
   294                 }
       
   295             CleanupStack::PopAndDestroy(&file); 
       
   296             }
       
   297         // best effort is to continue with other exes in the event of an error
       
   298         // so do nothing here.
       
   299         }
       
   300     CleanupStack::PopAndDestroy(&fs);
       
   301     User::LeaveIfError(SendReceive(EExecuteQueue));
       
   302     
       
   303     }
       
   304 
       
   305 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
       
   306 EXPORT_C void RSisLauncherSession::ParseSwTypeRegFileL(RFile& aFile, RPointerArray<Usif::CSoftwareTypeRegInfo>& aSwTypeRegInfoArray)
       
   307     {
       
   308     // Pack the file handle
       
   309     TIpcArgs ipcArgs;
       
   310     aFile.TransferToServer(ipcArgs, 0, 1);
       
   311 
       
   312     // Allocate a buffer for the parsed registration info
       
   313     TInt bufLen = 0;
       
   314     User::LeaveIfError(aFile.Size(bufLen));
       
   315     HBufC8* buf = HBufC8::NewLC(bufLen); // using the size of the file here is overhead but provides very simple code
       
   316     
       
   317     // Packe the buffer
       
   318     TPtr8 bufPtr(buf->Des());
       
   319     ipcArgs.Set(2, &bufPtr);
       
   320     
       
   321     // Send request to the server
       
   322     User::LeaveIfError(SendReceive(EParseSwTypeRegFile, ipcArgs));
       
   323 
       
   324     // Unpack the parsed registration info
       
   325     RDesReadStream rs(*buf);
       
   326     CleanupClosePushL(rs);
       
   327     SoftwareTypeRegInfoUtils::UnserializeArrayL(rs, aSwTypeRegInfoArray);
       
   328 
       
   329     CleanupStack::PopAndDestroy(2, buf); // rs
       
   330     }
       
   331 
       
   332 EXPORT_C void RSisLauncherSession::RegisterSifLauncherMimeTypesL(const RPointerArray<HBufC8>& aMimeTypes)
       
   333     {
       
   334     RegisterSifLauncherMimeTypesImplL(aMimeTypes, ETrue);
       
   335     }
       
   336 
       
   337 EXPORT_C void RSisLauncherSession::UnregisterSifLauncherMimeTypesL(const RPointerArray<HBufC8>& aMimeTypes)
       
   338     {
       
   339     RegisterSifLauncherMimeTypesImplL(aMimeTypes, EFalse);
       
   340     }
       
   341 
       
   342 void RSisLauncherSession::RegisterSifLauncherMimeTypesImplL(const RPointerArray<HBufC8>& aMimeTypes, TBool aRegister)
       
   343     {
       
   344     // Calculate the size of aMimeTypes in a buffer
       
   345     TInt bufLen = sizeof(TInt);
       
   346     for (TInt i=0; i<aMimeTypes.Count(); ++i)
       
   347         {
       
   348         bufLen += sizeof(TInt) + aMimeTypes[i]->Size();
       
   349         }
       
   350     
       
   351     // Externalize MIME types
       
   352     HBufC8* buf = HBufC8::NewLC(bufLen);
       
   353     TPtr8 bufPtr(buf->Des());
       
   354 
       
   355     RDesWriteStream ws(bufPtr);
       
   356     CleanupClosePushL(ws);
       
   357     
       
   358     ExternalizePointerArrayL(aMimeTypes, ws);
       
   359 
       
   360     ws.CommitL();
       
   361     CleanupStack::PopAndDestroy(&ws);
       
   362 
       
   363     // Send MIME types to the server
       
   364     TIpcArgs ipcArgs(&bufPtr);
       
   365     User::LeaveIfError(SendReceive(aRegister?ERegisterSifLauncherMimeTypes:EUnregisterSifLauncherMimeTypes, ipcArgs));
       
   366 
       
   367     CleanupStack::PopAndDestroy(buf);
       
   368     }
       
   369     
       
   370 EXPORT_C void  RSisLauncherSession::AsyncParseResourceFileSizeL(const RFile& aRegistrationFile, const RArray<TLanguage>& aAppLanguages, TRequestStatus& aStatus)
       
   371     {
       
   372     TInt langCount = aAppLanguages.Count();
       
   373     const TInt maxBufSize= sizeof(TInt) + langCount*sizeof(TLanguage);   // Size(Number of entries) + (Number of entries)*(Size of Language Id)
       
   374    
       
   375     // Allocate buffer for the array
       
   376     if (iBuffForLanguages)
       
   377         {
       
   378         delete iBuffForLanguages;
       
   379         iBuffForLanguages = NULL;
       
   380         }
       
   381     iBuffForLanguages = HBufC8::NewMaxL(maxBufSize);
       
   382     TPtr8 ptrBufForLanguages = iBuffForLanguages->Des();
       
   383 
       
   384     RDesWriteStream ins(ptrBufForLanguages);
       
   385     CleanupClosePushL(ins);
       
   386     ins.WriteInt32L(langCount);
       
   387     for (TInt i = 0; i < langCount; ++i)
       
   388         {
       
   389         ins.WriteInt32L((TInt)(aAppLanguages[i]));
       
   390         }
       
   391        
       
   392     ins.CommitL();
       
   393     CleanupStack::PopAndDestroy(&ins);
       
   394     
       
   395     TIpcArgs args;
       
   396     aRegistrationFile.TransferToServer(args, 0, 1);
       
   397     args.Set(2,&ptrBufForLanguages);
       
   398     SendReceive(EAsyncParseResourceFileSize, args, aStatus);    
       
   399     }
       
   400     
       
   401 EXPORT_C Usif::CApplicationRegistrationData*  RSisLauncherSession::AsyncParseResourceFileDataL(TInt aDataSize)
       
   402     {
       
   403     HBufC8* appRegData=HBufC8::NewMaxLC(aDataSize);
       
   404     TPtr8 appRegDataDes = appRegData->Des();
       
   405     TInt err=SendReceive(EAsyncParseResourceFileData, TIpcArgs(&appRegDataDes ));        
       
   406     User::LeaveIfError(err);
       
   407     
       
   408     Usif::CApplicationRegistrationData* applicationData= Usif::CApplicationRegistrationData::NewLC();
       
   409     // Got the buffer, internalise the arrays
       
   410     RDesReadStream readStream(*appRegData);
       
   411     CleanupClosePushL(readStream);    
       
   412     applicationData->InternalizeL(readStream);
       
   413     CleanupStack::PopAndDestroy(&readStream); 
       
   414     CleanupStack::Pop(applicationData);
       
   415     CleanupStack::PopAndDestroy(appRegData);
       
   416 	if (iBuffForLanguages)
    75 		{
   417 		{
    76 		TInt err = CreateSession(KSisLauncherServerName, TVersion(0, 0, 0), 1);
   418 		delete iBuffForLanguages;
    77 		if (err != KErrNotFound && err != KErrServerTerminated)
   419 		iBuffForLanguages = NULL;
    78 			{
       
    79 			return err;
       
    80 			}
       
    81 		if (--retry==0)
       
    82 			{
       
    83 			return err;
       
    84 			}
       
    85 		err = StartSisLauncherServer();
       
    86 		if (err != KErrNone && err != KErrAlreadyExists)
       
    87 			{
       
    88 			return err;
       
    89 			}
       
    90 		}
   420 		}
    91 	}
   421 	return applicationData;
    92 
   422     }
    93 EXPORT_C void RSisLauncherSession::RunExecutableL(const TDesC& aFileName, TBool aWait)
   423 
    94 	{
   424 EXPORT_C Usif::CApplicationRegistrationData* RSisLauncherSession::SyncParseResourceFileL(const RFile& aRegistrationFile, const RArray<TLanguage>& aAppLanguages)
    95 	TPckgC<TBool> wait(aWait);
   425     {
    96 	User::LeaveIfError(SendReceive(ERunExecutable, TIpcArgs(&aFileName, &wait)));
   426 	// Get the size of data
    97 	}
   427     TRequestStatus status;
    98 
   428     AsyncParseResourceFileSizeL (aRegistrationFile , aAppLanguages , status );
    99 EXPORT_C void RSisLauncherSession::StartDocumentL(RFile& aFile, TBool aWait)
   429     User::WaitForRequest(status);
   100 	{
   430     TInt size = status.Int(); 
   101 	TPckgC<TBool> wait(aWait);
   431     if (size < KErrNone)
   102 	TIpcArgs ipcArgs;
   432         {
   103 	aFile.TransferToServer(ipcArgs, 0, 1);
   433         User::LeaveIfError(status.Int());
   104 	ipcArgs.Set(2, &wait);
   434         return NULL;
   105 	User::LeaveIfError(SendReceive(EStartDocumentByHandle, ipcArgs));
   435         }
   106 	}
   436 
   107 
   437 	// Return the app reg data
   108 EXPORT_C void RSisLauncherSession::StartByMimeL(RFile& aFile, const TDesC8& aMimeType, TBool aWait)
   438     Usif::CApplicationRegistrationData* appRegData = AsyncParseResourceFileDataL(size);
   109 	{
   439     return appRegData;
   110 	TPckgC<TBool> wait(aWait);
   440     }
   111 	TIpcArgs ipcArgs;
   441 
   112 	aFile.TransferToServer(ipcArgs, 0, 1);
   442 
   113 	ipcArgs.Set(2, &aMimeType);
   443 EXPORT_C void RSisLauncherSession::NotifyNewAppsL(const RPointerArray<Usif::CApplicationRegistrationData>& aAppRegData)
   114 	ipcArgs.Set(3, &wait);
   444     {
   115 	
   445     if (aAppRegData.Count() > 0)
   116 	User::LeaveIfError(SendReceive(EStartByMimeByHandle, ipcArgs));
   446         {
   117 	}
   447         TInt bufLen = sizeof(TInt);
   118 
   448         const TInt appCount = aAppRegData.Count();
   119 EXPORT_C void RSisLauncherSession::StartDocumentL(const TDesC& aFileName, TBool aWait)
   449         for (TInt i=0; i<appCount; ++i)
   120 	{
   450             {
   121 	TPckgC<TBool> wait(aWait);
   451 			bufLen += GetObjectSizeL(aAppRegData[i]);
   122 	User::LeaveIfError(SendReceive(EStartDocument, TIpcArgs(&aFileName, &wait)));
   452             }
   123 	}
   453 
   124 
   454         HBufC8* buffer = HBufC8::NewLC(bufLen);
   125 EXPORT_C void RSisLauncherSession::StartByMimeL(const TDesC& aFileName, const TDesC8& aMimeType, TBool aWait)
   455         TPtr8 bufPtr(buffer->Des());
   126 	{
   456 
   127 	TPckgC<TBool> wait(aWait);
   457         RDesWriteStream ws(bufPtr);
   128 	User::LeaveIfError(SendReceive(EStartByMime, TIpcArgs(&aFileName, &aMimeType, &wait)));
   458         CleanupClosePushL(ws);
   129 	}
   459 
   130 
   460         ws.WriteInt32L(appCount);
   131 EXPORT_C void RSisLauncherSession::ShutdownAllL()
   461         for (TInt i=0; i<appCount; ++i)
   132 	{
   462             {
   133 	User::LeaveIfError(SendReceive(EShutdownAll));
   463             const Usif::CApplicationRegistrationData& info = *aAppRegData[i];
   134 	}
   464             ws << info;
   135 
   465             }
   136 EXPORT_C void RSisLauncherSession::CheckApplicationInUseL(RArray<TAppInUse>& aUidList)
   466         ws.CommitL();
   137 	{
   467         CleanupStack::PopAndDestroy(&ws);
   138 	TInt uidCount=aUidList.Count();
   468         
   139 	if (uidCount)
   469         TIpcArgs ipcArgs(&bufPtr);
   140 		{
   470         User::LeaveIfError(SendReceive(ENotifyNewAppsData, ipcArgs));
   141 		HBufC8* appInUseBuf=HBufC8::NewLC(uidCount * sizeof(TAppInUse));
   471 
   142 		TPtr8 appInUsePtr=appInUseBuf->Des();
   472         CleanupStack::PopAndDestroy(buffer);
   143 		TUint8* dataPtr(NULL);
   473         }
   144 		TInt i;
   474     }
   145 		for (i = 0 ; i < uidCount ; ++i)
   475 
   146 			{
   476 
   147 			dataPtr=reinterpret_cast<TUint8*>(&aUidList[i]);
   477 EXPORT_C void RSisLauncherSession::NotifyNewAppsL(const RArray<TAppUpdateInfo>& aAppUpdateInfo)
   148 			appInUsePtr.Append(dataPtr, sizeof(TAppInUse));			
   478     {
   149 			}	
   479     TInt bufLen = sizeof(TInt);
   150 		User::LeaveIfError((SendReceive(ECheckApplicationInUse, TIpcArgs(&appInUsePtr))));
   480     const TInt appCount = aAppUpdateInfo.Count();
   151 
   481     for (TInt i=0; i<appCount; ++i)
   152 		//Copy the result back to the RArray
   482         {
   153 		dataPtr=const_cast<TUint8*>(appInUsePtr.Ptr());
   483         bufLen += GetObjectSizeL(&aAppUpdateInfo[i]);
   154 		TAppInUse* appInUseDataPtr=reinterpret_cast<TAppInUse*>(dataPtr);
   484         }
   155 		for (i = 0; i < uidCount; ++i)
   485 
   156 			{
   486     HBufC8* buffer = HBufC8::NewLC(bufLen);
   157 			aUidList[i]=appInUseDataPtr[i];	
   487     TPtr8 bufPtr(buffer->Des());
   158 			}				
   488 
   159 			
   489     RDesWriteStream ws(bufPtr);
   160 		CleanupStack::PopAndDestroy(appInUseBuf);				
   490     CleanupClosePushL(ws);
   161 		}
   491 
   162 	}
   492     ws.WriteInt32L(appCount);
   163 	
   493     for (TInt i=0; i<appCount; ++i)
   164 EXPORT_C void RSisLauncherSession::ShutdownL(const RArray<TUid>& aUidList, TInt aTimeout)
   494         {
   165 	{
   495         const TAppUpdateInfo& info = aAppUpdateInfo[i];
   166 	TInt uidCount=aUidList.Count();
   496         ws << info;
   167 	if (uidCount)	
   497         }
   168 		{
   498     ws.CommitL();
   169 		HBufC8* tUidBuf=HBufC8::NewLC(uidCount * sizeof(TUid));
   499     CleanupStack::PopAndDestroy(&ws);
   170 		TPtr8 tUidBufPtr=tUidBuf->Des();
   500     
   171 		const TUint8* dataPtr(NULL);
   501     TIpcArgs ipcArgs(&bufPtr);
   172 		
   502     User::LeaveIfError(SendReceive(ENotifyApparcForApps, ipcArgs));
   173 		for (TInt i=0;i<uidCount;i++)
   503 
   174 			{
   504     CleanupStack::PopAndDestroy(buffer);
   175 			dataPtr=reinterpret_cast<const TUint8*>(&aUidList[i]);
   505     }
   176 			tUidBufPtr.Append(dataPtr, sizeof(TUid));
   506 
   177 			}	
   507 EXPORT_C TAppUpdateInfo::TAppUpdateInfo()
   178 		User::LeaveIfError((SendReceive(EShutdown, TIpcArgs(&tUidBufPtr, aTimeout))));		
   508     {    
   179 		CleanupStack::PopAndDestroy(tUidBuf);							
   509     }
   180 		}
   510 
   181 	}
   511 EXPORT_C TAppUpdateInfo::TAppUpdateInfo(TUid aAppUid, InstallActions aAction)
   182 
   512     {
   183 EXPORT_C void RSisLauncherSession::NotifyNewAppsL(const RPointerArray<TDesC>& aFiles)
   513     iAppUid = aAppUid;
   184 	{
   514     iAction = aAction;
   185 	if (aFiles.Count() > 0)
   515     }
   186 		{
   516 
   187 		CBufFlat* tmpBuf = CBufFlat::NewL(255);
   517 EXPORT_C void TAppUpdateInfo::InternalizeL(RReadStream& aReadStream)
   188 		CleanupStack::PushL(tmpBuf);
   518     {
   189 			
   519     iAppUid = TUid::Uid(aReadStream.ReadUint32L());
   190 		RBufWriteStream stream(*tmpBuf);
   520     iAction = (Swi::InstallActions)aReadStream.ReadUint32L();
   191 		CleanupClosePushL(stream);
   521     }
   192 
   522 
   193 		ExternalizePointerArrayL(aFiles, stream);
   523 EXPORT_C void TAppUpdateInfo::ExternalizeL(RWriteStream& aWriteStream) const
   194 
   524     {
   195 		// Create an HBufC8 from the stream buf's length, and copy 
   525     aWriteStream.WriteUint32L(iAppUid.iUid);
   196 		// the stream buffer into this descriptor
   526     aWriteStream.WriteInt32L(iAction);
   197 		HBufC8* buffer = HBufC8::NewLC(tmpBuf->Size());
   527     }
   198 		TPtr8 ptr(buffer->Des());
   528 
   199 		tmpBuf->Read(0, ptr, tmpBuf->Size());
       
   200 	
       
   201 		User::LeaveIfError(SendReceive(ENotifyNewApps, TIpcArgs(&ptr)));
       
   202 		CleanupStack::PopAndDestroy(3, tmpBuf);
       
   203 		}
       
   204 	}
       
   205 
       
   206 EXPORT_C void RSisLauncherSession::RunAfterEcomNotificationL(const RPointerArray<CSisRegistryFileDescription>& aFileList)
       
   207 	{
       
   208 	TInt count = aFileList.Count();
       
   209 	if (count <= 0)
       
   210 		{
       
   211 		return; 
       
   212 		}
       
   213 
       
   214 	RFs fs;
       
   215 	User::LeaveIfError(fs.Connect());
       
   216 	CleanupClosePushL(fs);
       
   217 	User::LeaveIfError(fs.ShareProtected());
       
   218 
       
   219 	for (TInt i = 0; i < count; ++i)
       
   220 		{
       
   221 		CSisRegistryFileDescription* fileDes = aFileList[i];
       
   222 
       
   223 		// open the file entry
       
   224 		TEntry entry;
       
   225 		if (fs.Entry(fileDes->Target(), entry) != KErrNone)
       
   226 			{
       
   227 			// just ignore, there's nothing we can do and we should try to process the
       
   228 			// remaining files.
       
   229 			continue;
       
   230 			}
       
   231 		
       
   232 		TIpcArgs ipcArgs;
       
   233 		TBool waitEnd = 0 != (fileDes->OperationOptions() & Sis::EInstFileRunOptionWaitEnd);
       
   234 		TPckgC<TBool> wait(waitEnd);
       
   235 		ipcArgs.Set(2, &wait);
       
   236 
       
   237 		TInt err = KErrNone;
       
   238 
       
   239 		if (entry.IsTypeValid() && SecUtils::IsExe(entry))
       
   240 			{
       
   241 			ipcArgs.Set(0,&fileDes->Target());
       
   242 			err = SendReceive(EQueueRunExecutable, ipcArgs);
       
   243 			}
       
   244 		else 
       
   245 			{
       
   246 			RFile file;
       
   247 			CleanupClosePushL(file);
       
   248 			err = file.Open(fs, fileDes->Target(), EFileShareExclusive|EFileWrite);
       
   249 
       
   250 			HBufC8* mimeType = 0;
       
   251 
       
   252 			if (err == KErrNone)
       
   253 				{
       
   254 				if (fileDes->OperationOptions() & Sis::EInstFileRunOptionByMimeType)
       
   255 					{
       
   256 					mimeType = HBufC8::NewLC(fileDes->MimeType().Length());
       
   257 					TPtr8 ptr = mimeType->Des();
       
   258 					ptr.Copy(fileDes->MimeType());
       
   259 					}
       
   260 
       
   261 				if (file.TransferToServer(ipcArgs, 0, 1) != KErrNone)
       
   262 					{
       
   263 					// best effort is to continue with remaining exes
       
   264 					}	
       
   265 				else if (mimeType != 0)
       
   266 					{
       
   267 					TPtrC8 x = mimeType->Des();
       
   268 					ipcArgs.Set(3, &x);
       
   269 					err = SendReceive(EQueueStartByMimeByHandle, ipcArgs);
       
   270 					}
       
   271 				else
       
   272 					{
       
   273 					err = SendReceive(EQueueStartDocumentByHandle, ipcArgs);
       
   274 					}
       
   275 				if (mimeType != 0)
       
   276 					{
       
   277 					CleanupStack::PopAndDestroy(mimeType);
       
   278 					}
       
   279 				}
       
   280 			CleanupStack::PopAndDestroy(&file); 
       
   281 			}
       
   282 		// best effort is to continue with other exes in the event of an error
       
   283 		// so do nothing here.
       
   284 		}
       
   285 	CleanupStack::PopAndDestroy(&fs);
       
   286 	User::LeaveIfError(SendReceive(EExecuteQueue));
       
   287 	
       
   288 	}
       
   289 
       
   290 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
       
   291 EXPORT_C void RSisLauncherSession::ParseSwTypeRegFileL(RFile& aFile, RPointerArray<CSoftwareTypeRegInfo>& aSwTypeRegInfoArray)
       
   292 	{
       
   293 	// Pack the file handle
       
   294 	TIpcArgs ipcArgs;
       
   295 	aFile.TransferToServer(ipcArgs, 0, 1);
       
   296 
       
   297 	// Allocate a buffer for the parsed registration info
       
   298 	TInt bufLen = 0;
       
   299 	User::LeaveIfError(aFile.Size(bufLen));
       
   300 	HBufC8* buf = HBufC8::NewLC(bufLen); // using the size of the file here is overhead but provides very simple code
       
   301 	
       
   302 	// Packe the buffer
       
   303 	TPtr8 bufPtr(buf->Des());
       
   304 	ipcArgs.Set(2, &bufPtr);
       
   305 	
       
   306 	// Send request to the server
       
   307 	User::LeaveIfError(SendReceive(EParseSwTypeRegFile, ipcArgs));
       
   308 
       
   309 	// Unpack the parsed registration info
       
   310 	RDesReadStream rs(*buf);
       
   311 	CleanupClosePushL(rs);
       
   312 	SoftwareTypeRegInfoUtils::UnserializeArrayL(rs, aSwTypeRegInfoArray);
       
   313 
       
   314 	CleanupStack::PopAndDestroy(2, buf); // rs
       
   315 	}
       
   316 
       
   317 EXPORT_C void RSisLauncherSession::RegisterSifLauncherMimeTypesL(const RPointerArray<HBufC8>& aMimeTypes)
       
   318 	{
       
   319 	RegisterSifLauncherMimeTypesImplL(aMimeTypes, ETrue);
       
   320 	}
       
   321 
       
   322 EXPORT_C void RSisLauncherSession::UnregisterSifLauncherMimeTypesL(const RPointerArray<HBufC8>& aMimeTypes)
       
   323 	{
       
   324 	RegisterSifLauncherMimeTypesImplL(aMimeTypes, EFalse);
       
   325 	}
       
   326 
       
   327 void RSisLauncherSession::RegisterSifLauncherMimeTypesImplL(const RPointerArray<HBufC8>& aMimeTypes, TBool aRegister)
       
   328 	{
       
   329 	// Calculate the size of aMimeTypes in a buffer
       
   330 	TInt bufLen = sizeof(TInt);
       
   331 	for (TInt i=0; i<aMimeTypes.Count(); ++i)
       
   332 		{
       
   333 		bufLen += sizeof(TInt) + aMimeTypes[i]->Size();
       
   334 		}
       
   335 	
       
   336 	// Externalize MIME types
       
   337 	HBufC8* buf = HBufC8::NewLC(bufLen);
       
   338 	TPtr8 bufPtr(buf->Des());
       
   339 
       
   340 	RDesWriteStream ws(bufPtr);
       
   341 	CleanupClosePushL(ws);
       
   342 	
       
   343 	ExternalizePointerArrayL(aMimeTypes, ws);
       
   344 
       
   345 	ws.CommitL();
       
   346 	CleanupStack::PopAndDestroy(&ws);
       
   347 
       
   348 	// Send MIME types to the server
       
   349 	TIpcArgs ipcArgs(&bufPtr);
       
   350 	User::LeaveIfError(SendReceive(aRegister?ERegisterSifLauncherMimeTypes:EUnregisterSifLauncherMimeTypes, ipcArgs));
       
   351 
       
   352 	CleanupStack::PopAndDestroy(buf);
       
   353 	}
       
   354 #endif
   529 #endif