serviceproviders/sapi_applicationmanager/appmanagerservice/src/appmanagerservice.cpp
changeset 5 989d2f495d90
child 46 5146369cfdc9
equal deleted inserted replaced
1:a36b1e19a461 5:989d2f495d90
       
     1 /*
       
     2 * Copyright (c) 2007-2007 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  This Class provides the core functionality to Application Manager
       
    15 *				 SAPI
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 #include <e32std.h>
       
    22 #include <apgcli.h>
       
    23 
       
    24 #include "appmanagerservice.h"
       
    25 #include "launcher.h"
       
    26 #include "launcherobserver.h"
       
    27 #include "installpkgiterator.h"
       
    28 #include "appiterator.h"
       
    29 #include "asynchrequestmanager.h"
       
    30 
       
    31 //Content Type
       
    32 _LIT(KApplication,"Application");
       
    33 _LIT(KUserInstalledPackage,"UserInstalledPackage");
       
    34 
       
    35 #define KMAXPATHLENGTH 255
       
    36 
       
    37 // -----------------------------------------------------------------------------
       
    38 // CAppManagerService::NewLC
       
    39 // Returns the instance of CAppManagerService class.
       
    40 // -----------------------------------------------------------------------------
       
    41 EXPORT_C CAppManagerService* CAppManagerService::NewL()
       
    42 	{
       
    43 	CAppManagerService* self = new ( ELeave )CAppManagerService();
       
    44 	CleanupStack::PushL( self );
       
    45 	self->ConstructL();
       
    46 	CleanupStack::Pop( self );
       
    47 	return self;
       
    48 	}
       
    49 
       
    50 
       
    51 // -----------------------------------------------------------------------------
       
    52 // CAppManagerService::~CAppManagerService
       
    53 // Destructor
       
    54 // -----------------------------------------------------------------------------
       
    55 
       
    56 CAppManagerService::~CAppManagerService()
       
    57 	{
       
    58 	
       
    59 	//releasing the AsynchRequestManager class   
       
    60     delete iAsynchReqMngr;    
       
    61 	
       
    62 	//Closing the session of application  arch server
       
    63     iApaLsSession.Close();
       
    64     
       
    65     //releasing the launcher class
       
    66     delete iLauncher;
       
    67   
       
    68   	}
       
    69 
       
    70 
       
    71 // -----------------------------------------------------------------------------
       
    72 // CAppManagerService::LaunchApplication
       
    73 // This function Launch the given Application
       
    74 // -----------------------------------------------------------------------------
       
    75 
       
    76 EXPORT_C void CAppManagerService::LaunchApplicationL( const TDesC& aAppId,
       
    77                                                       const TDesC8& aCmdLine,
       
    78                                                       const TOptions& aOptions,
       
    79                                                       MAppObserver* aObserver,
       
    80                                                       TInt32 aTransactionID )
       
    81 	{
       
    82 
       
    83     if ( !aObserver )
       
    84         {
       
    85         //Synchronous call
       
    86        
       
    87         iLauncher->LaunchApplicationL( aAppId, aCmdLine, aOptions);
       
    88       
       
    89         }
       
    90     else
       
    91         {
       
    92         //Asynchorous opertaion
       
    93         //Add observer for supporting cancel to multiple asynch request
       
    94        
       
    95         TThreadId threadId =iLauncher->LaunchApplicationL( aAppId, aCmdLine, aOptions);
       
    96         CLauncherObserver* observer = iAsynchReqMngr->AddObsereverLC( aObserver,aTransactionID, threadId );
       
    97         CleanupStack::Pop( observer );
       
    98   	    
       
    99 	    
       
   100 	    }
       
   101 
       
   102 
       
   103 
       
   104    }
       
   105 
       
   106 
       
   107 // -----------------------------------------------------------------------------
       
   108 // CAppManagerService::LaunchApplication
       
   109 // This function Launch the given content
       
   110 // -----------------------------------------------------------------------------
       
   111 
       
   112 EXPORT_C void CAppManagerService::LaunchDocumentL( TDocument& aCriteria,
       
   113        	                                           const TDesC8& aMimeType,
       
   114        	                                           const TOptions& aOptions ,
       
   115        	                                           TDesC& aFileName,
       
   116        	                                           MAppObserver* aObserver,
       
   117        	                                           TInt32 aTransactionID )
       
   118 	{
       
   119 
       
   120     if ( !aObserver )
       
   121         {
       
   122         //Synchronous call
       
   123         __UHEAP_MARK;
       
   124         iLauncher->LaunchDocumentL( aCriteria, aMimeType, aOptions, aFileName);
       
   125         __UHEAP_MARKEND;
       
   126         }
       
   127     else
       
   128         {
       
   129         //Asynchorous call
       
   130         //Add observer for supporting cancel to multiple asynch request
       
   131         TThreadId threadId = iLauncher->LaunchDocumentL(aCriteria, aMimeType, aOptions, aFileName );
       
   132         CLauncherObserver* observer = iAsynchReqMngr->AddObsereverLC( aObserver,aTransactionID, threadId );
       
   133         CleanupStack::Pop( observer );
       
   134         }
       
   135 
       
   136    }
       
   137 
       
   138 // -----------------------------------------------------------------------------
       
   139 // CAppManagerService::GetListL
       
   140 // This function gives the list of all appication or installed packages 
       
   141 // according to the content
       
   142 // -----------------------------------------------------------------------------
       
   143 
       
   144 EXPORT_C void  CAppManagerService::GetListL( MIterator*&   aIterator,
       
   145                                              const TDesC& aContent, 
       
   146                                              const CFilterParam* aFilterParam )
       
   147     {
       
   148 	
       
   149 
       
   150 	if( KErrNone == aContent.CompareF(KApplication) )
       
   151 		{
       
   152         //CAppIterator class traverse the list of all application
       
   153 		aIterator = CAppIterator::NewL( iApaLsSession, aFilterParam );
       
   154 		}
       
   155 	else if(KErrNone == aContent.CompareF(KUserInstalledPackage) )
       
   156 		{
       
   157 		//CInstallPkgIterator class traverse the list of user intsalled package
       
   158 		aIterator = CInstallPkgIterator::NewL();
       
   159 		}
       
   160 	else
       
   161 		{
       
   162 		// wrong content
       
   163 		User::Leave( KErrArgument );
       
   164 		}
       
   165  
       
   166 
       
   167 	}
       
   168 
       
   169 // -----------------------------------------------------------------------------
       
   170 // CAppManagerService::Cancel
       
   171 // Cancel the pending asynchronous request
       
   172 // -----------------------------------------------------------------------------
       
   173 EXPORT_C TInt CAppManagerService::Cancel( TInt32 aTransactionID )
       
   174 	{
       
   175 
       
   176        return iAsynchReqMngr->Cancel( aTransactionID );
       
   177 
       
   178 	}
       
   179 
       
   180 // -----------------------------------------------------------------------------
       
   181 // CAppManagerService::CAppManagerService
       
   182 // ConstructorL
       
   183 // -----------------------------------------------------------------------------
       
   184 void CAppManagerService::ConstructL()
       
   185 
       
   186 	{
       
   187 	//opening the session with application arch server
       
   188     User::LeaveIfError(iApaLsSession.Connect());
       
   189     
       
   190     //creating the instance of launcher class for delegating all launching request
       
   191     iLauncher = CLauncher::NewL( iApaLsSession );
       
   192 	
       
   193 	 //creating the instance of Asynch request manager which care the multiple asynch request
       
   194     iAsynchReqMngr = CAsynchRequestManager::NewL();
       
   195 	
       
   196 	}
       
   197 
       
   198 
       
   199 
       
   200 // -----------------------------------------------------------------------------
       
   201 // CAppManagerService::ValidateFilePathL
       
   202 // Validate the given filepath
       
   203 // -----------------------------------------------------------------------------
       
   204 void CAppManagerService::ValidateFilePathL(const TDesC& aFilePath)
       
   205 	{
       
   206 	RFile file;	
       
   207 	RFs fs;
       
   208 	
       
   209 	if (aFilePath.Length() > KMAXPATHLENGTH)
       
   210 		User::Leave(KErrArgument);
       
   211 	
       
   212 	User::LeaveIfError(fs.Connect());
       
   213  
       
   214  	CleanupClosePushL(fs);
       
   215  	
       
   216  	if (file.Open(fs, aFilePath, EFileRead) != KErrNone)
       
   217  		{
       
   218  		User::Leave(KErrPathNotFound);
       
   219  		}
       
   220  		
       
   221  	CleanupStack::PopAndDestroy();
       
   222 	}