activityfw/storage/server/tsrc/t_server/t_installer.cpp
changeset 117 c63ee96dbe5f
equal deleted inserted replaced
115:3ab5c078b490 117:c63ee96dbe5f
       
     1 /*
       
     2  * Copyright (c) 2010 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 "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:  ?Description
       
    15  *
       
    16  */
       
    17 
       
    18 #include <usif/usifcommon.h>
       
    19 #include <usif/scr/screntries.h>
       
    20 
       
    21 #include "t_installer.h"
       
    22 
       
    23 using namespace Usif;
       
    24 
       
    25 // ================= MEMBER FUNCTIONS =======================
       
    26 
       
    27 // ---------------------------------------------------------------------------
       
    28 // T_CaInstaller::~T_CaInstaller
       
    29 // ---------------------------------------------------------------------------
       
    30 //
       
    31 T_Installer::~T_Installer()
       
    32     {
       
    33     Cancel();
       
    34     //iFs.Close();
       
    35     delete iArguments;
       
    36     delete iResults;
       
    37     iInstaller.Close();
       
    38     iSoftwareRegistry.Close();
       
    39     }
       
    40 
       
    41 // ---------------------------------------------------------------------------
       
    42 // T_CaInstaller::NewL
       
    43 // ---------------------------------------------------------------------------
       
    44 //
       
    45 T_Installer *T_Installer::NewL(TInt aPriority)
       
    46     {
       
    47     T_Installer *self = new (ELeave) T_Installer(
       
    48             aPriority );
       
    49     CleanupStack::PushL( self );
       
    50     self->ConstructL();
       
    51     CleanupStack::Pop( self );
       
    52     return self;
       
    53     }
       
    54 
       
    55 // ---------------------------------------------------------------------------
       
    56 // T_CaInstaller::T_CaInstaller
       
    57 // ---------------------------------------------------------------------------
       
    58 //
       
    59 T_Installer::T_Installer( TInt aPriority ) :
       
    60     CActive( aPriority ), iInstaller()
       
    61     {
       
    62     CActiveScheduler::Add( this );
       
    63     }
       
    64 
       
    65 // ---------------------------------------------------------------------------
       
    66 // T_CaInstaller::ConstructL
       
    67 // ---------------------------------------------------------------------------
       
    68 //
       
    69 void T_Installer::ConstructL()
       
    70     {
       
    71     iArguments = COpaqueNamedParams::NewL();
       
    72     iResults = COpaqueNamedParams::NewL();
       
    73     
       
    74     iArguments->AddIntL( KSifInParam_InstallInactive, ETrue );
       
    75     iArguments->AddIntL( KSifInParam_InstallSilently, ETrue );
       
    76     
       
    77     User::LeaveIfError( iInstaller.Connect() );
       
    78     User::LeaveIfError( iSoftwareRegistry.Connect() );
       
    79     //User::LeaveIfError( iFs.Connect() ); 
       
    80     }
       
    81 
       
    82 // ---------------------------------------------------------------------------
       
    83 // T_CaInstallOperation::ConstructL
       
    84 // ---------------------------------------------------------------------------
       
    85 //
       
    86 void T_Installer::InstallL( const TDesC& aFileName )
       
    87     {
       
    88     if (IsActive())
       
    89         {
       
    90         User::Leave(KErrInUse);
       
    91         }
       
    92 
       
    93     iInstaller.Install( aFileName, *iArguments, *iResults, iStatus );
       
    94     SetActive();
       
    95     iSchedulerWait.Start();
       
    96     User::LeaveIfError(iStatus.Int());
       
    97 
       
    98     }
       
    99     
       
   100 // ---------------------------------------------------------------------------
       
   101 // T_CaInstaller::UnistallL
       
   102 // ---------------------------------------------------------------------------
       
   103 //
       
   104 void T_Installer::UninstallL(TComponentId aComponentId)
       
   105     {
       
   106     if (IsActive())
       
   107         {
       
   108         User::Leave( KErrInUse );
       
   109         }
       
   110     
       
   111     if (aComponentId >= 1) 
       
   112         {
       
   113         iInstaller.Uninstall( aComponentId, *iArguments, *iResults, iStatus );
       
   114         SetActive();
       
   115         iSchedulerWait.Start();
       
   116         User::LeaveIfError(iStatus.Int());
       
   117         }
       
   118     
       
   119     }
       
   120 
       
   121 // ---------------------------------------------------------------------------
       
   122 // T_CaInstaller::UnistallL
       
   123 // ---------------------------------------------------------------------------
       
   124 //
       
   125 void T_Installer::UninstallL(const TDesC& aFileName)
       
   126     {    
       
   127         UninstallL( GetComponentIdL(aFileName) );    
       
   128     }
       
   129 
       
   130 // ---------------------------------------------------------------------------
       
   131 // T_CaInstaller::UnistallL
       
   132 // ---------------------------------------------------------------------------
       
   133 //
       
   134 void T_Installer::UninstallL( TUint32 aUid )
       
   135     {
       
   136     UninstallL( GetComponentIdL( aUid ) );    
       
   137     }
       
   138 
       
   139 TComponentId T_Installer::GetComponentIdL( const TDesC& aFileName )
       
   140     {
       
   141     CComponentFilter* const fileNameFilter = CComponentFilter::NewLC();
       
   142     fileNameFilter->SetFileL( aFileName );
       
   143 
       
   144     RArray<TComponentId> componentIds;
       
   145     CleanupClosePushL( componentIds );
       
   146     iSoftwareRegistry.GetComponentIdsL( componentIds, fileNameFilter );
       
   147 
       
   148     TComponentId componentId( 0 );
       
   149     
       
   150     if ( componentIds.Count() == 1 )
       
   151         {
       
   152         componentId = componentIds[0];    
       
   153         }
       
   154     else if ( componentIds.Count() >= 2 )
       
   155         {
       
   156         User::Leave( KErrGeneral );
       
   157         }
       
   158     
       
   159     CleanupStack::PopAndDestroy( &componentIds );
       
   160     CleanupStack::PopAndDestroy( fileNameFilter );
       
   161     
       
   162     return componentId;
       
   163     }
       
   164 
       
   165 
       
   166 TComponentId T_Installer::GetComponentIdL( TInt32 aUid )
       
   167     {
       
   168     TUid uid;
       
   169     TComponentId componentId = iSoftwareRegistry.GetComponentIdForAppL(
       
   170             uid.Uid( aUid ) );;
       
   171     
       
   172     if ( componentId <= 0 )
       
   173         {
       
   174         User::Leave( KErrGeneral );  
       
   175         }
       
   176     return componentId;
       
   177     }
       
   178 // ---------------------------------------------------------------------------
       
   179 // T_CaInstaller::RunL
       
   180 // ---------------------------------------------------------------------------
       
   181 //
       
   182 void T_Installer::RunL()
       
   183     {
       
   184     iSchedulerWait.AsyncStop();
       
   185     }
       
   186 
       
   187 // ---------------------------------------------------------------------------
       
   188 // T_CaInstaller::DoCancel
       
   189 // ---------------------------------------------------------------------------
       
   190 //
       
   191 void T_Installer::DoCancel()
       
   192     {
       
   193     iInstaller.CancelOperation();
       
   194     iSchedulerWait.AsyncStop();
       
   195     }
       
   196 
       
   197 // ---------------------------------------------------------------------------
       
   198 // T_CaInstaller::RunError
       
   199 // ---------------------------------------------------------------------------
       
   200 //
       
   201 TInt T_Installer::RunError(TInt /*aError*/)
       
   202     {
       
   203     return KErrNone;
       
   204     }