appinstaller/AppinstUi/Server/Src/SWInstRequestObject.cpp
changeset 80 9dcba1ee99f7
parent 77 d1838696558c
equal deleted inserted replaced
77:d1838696558c 80:9dcba1ee99f7
     1 /*
       
     2 * Copyright (c) 2002-2004 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:   This module contains the implementation of CSWInstRequestObject 
       
    15 *                class member functions.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 
       
    22 #include <StringLoader.h>
       
    23 #include <SWInstDefs.h>
       
    24 #include <SWInstSvrUI.rsg>
       
    25 #include <SWInstTaskManager.h>
       
    26 
       
    27 #include "SWInstRequestObject.h"
       
    28 #include "SWInstUIPluginAPI.h"
       
    29 #include "CUIDialogs.h"
       
    30 #include "SWInstServerPanic.h"
       
    31 
       
    32 using namespace SwiUI;
       
    33 
       
    34 _LIT( KSWInstSingleInstanceMutex, "SWINST_INSTANCE" );
       
    35 
       
    36 // ============================ MEMBER FUNCTIONS ===============================
       
    37 
       
    38 // -----------------------------------------------------------------------------
       
    39 // CSWInstRequestObject::CSWInstRequestObject
       
    40 // C++ default constructor can NOT contain any code, that
       
    41 // might leave.
       
    42 // -----------------------------------------------------------------------------
       
    43 //
       
    44 CSWInstRequestObject::CSWInstRequestObject( const RMessage2& aMessage )
       
    45     : CActive( CActive::EPriorityStandard ),
       
    46       iMessage( aMessage ),
       
    47       iMessageSet( ETrue ),
       
    48       iObjectId( aMessage.Function() )
       
    49     {
       
    50     CActiveScheduler::Add( this );
       
    51     }
       
    52 
       
    53 // -----------------------------------------------------------------------------
       
    54 // CSWInstRequestObject::CSWInstRequestObject
       
    55 // C++ default constructor can NOT contain any code, that
       
    56 // might leave.
       
    57 // -----------------------------------------------------------------------------
       
    58 //
       
    59 CSWInstRequestObject::CSWInstRequestObject( TInt aObjectId )
       
    60     : CActive( CActive::EPriorityStandard ),
       
    61       iObjectId( aObjectId )
       
    62     {
       
    63     CActiveScheduler::Add( this );
       
    64     }
       
    65 
       
    66 // -----------------------------------------------------------------------------
       
    67 // CSWInstRequestObject::BaseConstructL
       
    68 // Symbian 2nd phase constructor can leave.
       
    69 // -----------------------------------------------------------------------------
       
    70 //
       
    71 void CSWInstRequestObject::BaseConstructL()
       
    72     {
       
    73     iTaskManager = CTaskManager::NewL();
       
    74     }
       
    75     
       
    76 // Destructor
       
    77 CSWInstRequestObject::~CSWInstRequestObject()
       
    78     {    
       
    79     delete iUIPlugin;
       
    80     CActive::Cancel();
       
    81     delete iTaskManager;
       
    82     iSingleInstanceMutex.Close();
       
    83     }
       
    84 
       
    85 
       
    86 // -----------------------------------------------------------------------------
       
    87 // CSWInstRequestObject::Message
       
    88 // Returns the message object having this request.
       
    89 // (other items were commented in a header).
       
    90 // -----------------------------------------------------------------------------
       
    91 //
       
    92 RMessage2* CSWInstRequestObject::Message()
       
    93     {
       
    94     return &iMessage;    
       
    95     }
       
    96 
       
    97 // -----------------------------------------------------------------------------
       
    98 // CSWInstRequestObject::ObjectHandle
       
    99 // Returns the request id of this object.
       
   100 // (other items were commented in a header).
       
   101 // -----------------------------------------------------------------------------
       
   102 //
       
   103 TInt CSWInstRequestObject::ObjectId() const
       
   104     {
       
   105     return iObjectId;
       
   106     }
       
   107 
       
   108 // -----------------------------------------------------------------------------
       
   109 // CSWInstRequestObject::Complete
       
   110 // Completes the request.
       
   111 // (other items were commented in a header).
       
   112 // -----------------------------------------------------------------------------
       
   113 //
       
   114 void CSWInstRequestObject::Complete( TInt aResult )
       
   115     {
       
   116     iSingleInstanceMutex.Close();
       
   117 
       
   118     if ( iMessageSet )
       
   119         {
       
   120         iMessage.Complete( aResult );    
       
   121         }
       
   122 
       
   123     if ( iCancelMessageSet )
       
   124         {
       
   125         iCancelMessage.Complete( KErrNone );        
       
   126         }    
       
   127     
       
   128     if ( iCallback )
       
   129         {
       
   130         iCallback->RequestCompleted( aResult );
       
   131         } 
       
   132     }
       
   133 
       
   134 // -----------------------------------------------------------------------------
       
   135 // CSWInstRequestObject::SetCallback
       
   136 // Sets the request callback handler.
       
   137 // (other items were commented in a header).
       
   138 // -----------------------------------------------------------------------------
       
   139 //
       
   140 void CSWInstRequestObject::SetCallback( MRequestCallback* aCallback )
       
   141     {
       
   142     iCallback = aCallback;    
       
   143     }
       
   144 
       
   145 // -----------------------------------------------------------------------------
       
   146 // CSWInstRequestObject::Cancel
       
   147 // Cancel current operation.
       
   148 // (other items were commented in a header).
       
   149 // -----------------------------------------------------------------------------
       
   150 //
       
   151 void CSWInstRequestObject::Cancel()
       
   152     {
       
   153     if ( IsActive() )
       
   154         {    
       
   155         iCancelling = ETrue;    
       
   156         CancelRequest();    
       
   157         }    
       
   158     }
       
   159 
       
   160 // -----------------------------------------------------------------------------
       
   161 // CSWInstRequestObject::Cancel
       
   162 // Cancel current operation.
       
   163 // (other items were commented in a header).
       
   164 // -----------------------------------------------------------------------------
       
   165 //
       
   166 void CSWInstRequestObject::Cancel( const RMessage2& aMessage )
       
   167     {
       
   168     if ( IsActive() )
       
   169         {        
       
   170         iCancelMessage = aMessage;
       
   171         iCancelMessageSet = ETrue;    
       
   172         iCancelling = ETrue;    
       
   173         CancelRequest();    
       
   174         }        
       
   175     }
       
   176 
       
   177 // -----------------------------------------------------------------------------
       
   178 // CSWInstRequestObject::CreatePluginL
       
   179 // Creates a UI plugin based on the given mime time.
       
   180 // (other items were commented in a header).
       
   181 // -----------------------------------------------------------------------------
       
   182 //
       
   183 void CSWInstRequestObject::CreatePluginL( const TDesC8& aMime )
       
   184     {
       
   185     iUIPlugin = CSWInstUIPluginAPI::NewL( aMime );
       
   186     }
       
   187 
       
   188 // -----------------------------------------------------------------------------
       
   189 // CSWInstRequestObject::LeaveIfInUseL
       
   190 // Checks if there is another request object in use globally. Leaves with
       
   191 // KSWInstErrBusy if there is.
       
   192 // (other items were commented in a header).
       
   193 // -----------------------------------------------------------------------------
       
   194 //
       
   195 void CSWInstRequestObject::LeaveIfInUseL()
       
   196     {
       
   197     TInt err = iSingleInstanceMutex.CreateGlobal( KSWInstSingleInstanceMutex() );
       
   198     if ( err == KErrAlreadyExists )
       
   199         {
       
   200         if ( !iIsSilent )
       
   201             {            
       
   202             HBufC* noteText = StringLoader::LoadLC( R_SWINSTSVRUI_BUSY_INSTALL );
       
   203             CommonUI::CCUIDialogs* commonDlg = CommonUI::CCUIDialogs::NewL();
       
   204             CleanupStack::PushL( commonDlg );
       
   205             commonDlg->ShowErrorNoteL( *noteText );
       
   206             CleanupStack::PopAndDestroy( 2, noteText );        
       
   207             }        
       
   208         User::Leave( KSWInstErrBusy );
       
   209         }    
       
   210     }
       
   211   
       
   212 // -----------------------------------------------------------------------------
       
   213 // CSWInstRequestObject::CompleteSelf
       
   214 // Completes this active object.
       
   215 // (other items were commented in a header).
       
   216 // -----------------------------------------------------------------------------
       
   217 //
       
   218 void CSWInstRequestObject::CompleteSelf( TInt aResult )
       
   219     {
       
   220     __ASSERT_ALWAYS( !IsActive(), PanicServer( ESWInstPanicBadHandle ) );
       
   221     
       
   222     TRequestStatus* stat = &iStatus;    
       
   223     User::RequestComplete( stat, aResult );
       
   224     SetActive();  
       
   225     }
       
   226 
       
   227 // -----------------------------------------------------------------------------
       
   228 // CSWInstRequestObject::RunL
       
   229 // Called by framework when request is finished.
       
   230 // (other items were commented in a header).
       
   231 // -----------------------------------------------------------------------------
       
   232 //    
       
   233 void CSWInstRequestObject::RunL()
       
   234     {
       
   235     RequestCompleteL( iStatus.Int() );
       
   236     }
       
   237 
       
   238 // -----------------------------------------------------------------------------
       
   239 // CSWInstRequestObject::DoCancelL
       
   240 // Called by framework when request is cancelled.
       
   241 // (other items were commented in a header).
       
   242 // -----------------------------------------------------------------------------
       
   243 // 
       
   244 void CSWInstRequestObject::DoCancel()
       
   245     {
       
   246     // Empty 
       
   247     }
       
   248 
       
   249 // -----------------------------------------------------------------------------
       
   250 // CSWInstRequestObject::RunError
       
   251 // Handles a leave occurring in the request completion event handler RunL().
       
   252 // (other items were commented in a header).
       
   253 // -----------------------------------------------------------------------------
       
   254 // 
       
   255 TInt CSWInstRequestObject::RunError( TInt aError )
       
   256     {
       
   257     // Complete the client ipc message with the error
       
   258     Complete( aError );
       
   259 
       
   260     return KErrNone;
       
   261     }
       
   262 
       
   263 //  End of File