accessoryservices/accessoryserver/src/ASYProxy/ASYProxyAsyLoader.cpp
changeset 0 4e1aa6a622a0
child 20 1ddbe54d0645
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 /*
       
     2 * Copyright (c) 2002-2006 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:  Loader of ASYs
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "ASYProxy.h"
       
    21 #include "ASYProxyAsyHandler.h"
       
    22 #include "acc_debug.h"
       
    23 #include <e32svr.h>
       
    24 
       
    25 // EXTERNAL DATA STRUCTURES
       
    26 
       
    27 // EXTERNAL FUNCTION PROTOTYPES
       
    28 
       
    29 // CONSTANTS
       
    30 
       
    31 // MACROS
       
    32 
       
    33 // LOCAL CONSTANTS AND MACROS
       
    34 
       
    35 // MODULE DATA STRUCTURES
       
    36 
       
    37 // LOCAL FUNCTION PROTOTYPES
       
    38 
       
    39 // FORWARD DECLARATIONS
       
    40 
       
    41 // ============================= LOCAL FUNCTIONS ===============================
       
    42 
       
    43 // ============================ MEMBER FUNCTIONS ===============================
       
    44 
       
    45 // -----------------------------------------------------------------------------
       
    46 // CASYProxyAsyLoader::CASYProxyAsyLoader
       
    47 // C++ default constructor can NOT contain any code, that
       
    48 // might leave.
       
    49 // -----------------------------------------------------------------------------
       
    50 //
       
    51 CASYProxyAsyLoader::CASYProxyAsyLoader(
       
    52                     CASYProxy* aAsyProxy ) :
       
    53                         CActive( CActive::EPriorityStandard ),
       
    54                         iListRet( EFalse ),
       
    55                         iArrayItemCounter( 0 ),
       
    56                         iStepToDo( EASYLoadingStepListInit ),
       
    57                         iAsyProxy( aAsyProxy )
       
    58 
       
    59     {
       
    60     COM_TRACE_1( "[AccFW:AsyProxy] CASYProxyAsyLoader::CASYProxyAsyLoader(0x%x)", &aAsyProxy );
       
    61 
       
    62     CActiveScheduler::Add( this );
       
    63 
       
    64     COM_TRACE_( "[AccFW:AsyProxy] CASYProxyAsyLoader::CASYProxyAsyLoader" );
       
    65     }
       
    66 
       
    67 // -----------------------------------------------------------------------------
       
    68 // CASYProxyAsyLoader::ConstructL
       
    69 // Symbian 2nd phase constructor can leave.
       
    70 // -----------------------------------------------------------------------------
       
    71 //
       
    72 void CASYProxyAsyLoader::ConstructL()
       
    73     {
       
    74     COM_TRACE_( "[AccFW:AsyProxy] CASYProxyAsyLoader::ConstructL()" );
       
    75 
       
    76     iTimer = CASYProxyLoaderTimer::NewL( this );
       
    77     iTimer->StartTimer();
       
    78 
       
    79     COM_TRACE_( "[AccFW:AsyProxy] CASYProxyAsyLoader::ConstructL - return void" );
       
    80     }
       
    81 
       
    82 // -----------------------------------------------------------------------------
       
    83 // CASYProxyAsyLoader::NewL
       
    84 // Two-phased constructor.
       
    85 // -----------------------------------------------------------------------------
       
    86 //
       
    87 CASYProxyAsyLoader* CASYProxyAsyLoader::NewL(
       
    88                     CASYProxy* aAsyProxy )
       
    89     {
       
    90     COM_TRACE_1( "[AccFW:AsyProxy] CASYProxyAsyLoader::NewL(0x%x)", aAsyProxy );
       
    91 
       
    92     CASYProxyAsyLoader* self = new (ELeave) CASYProxyAsyLoader( aAsyProxy );
       
    93 
       
    94     CleanupStack::PushL( self );
       
    95     self->ConstructL();
       
    96     CleanupStack::Pop( self );
       
    97 
       
    98     COM_TRACE_1( "[AccFW:AsyProxy] CASYProxyAsyLoader::NewL - return 0x%x", self );
       
    99 
       
   100     return self;
       
   101     }
       
   102 
       
   103 // Destructor
       
   104 CASYProxyAsyLoader::~CASYProxyAsyLoader()
       
   105     {
       
   106     COM_TRACE_( "[AccFW:AsyProxy] CASYProxyAsyLoader::~CASYProxyAsyLoader()" );
       
   107 
       
   108     Cancel();
       
   109     Cleanup();
       
   110 
       
   111     COM_TRACE_( "[AccFW:AsyProxy] CASYProxyAsyLoader::~CASYProxyAsyLoader" );
       
   112     }
       
   113 
       
   114 // -----------------------------------------------------------------------------
       
   115 // CASYProxyAsyLoader::DoCancel
       
   116 // Cancel of Active object
       
   117 // (other items were commented in a header).
       
   118 // -----------------------------------------------------------------------------
       
   119 //
       
   120 void CASYProxyAsyLoader::DoCancel()
       
   121     {
       
   122     COM_TRACE_( "[AccFW:AsyProxy] CASYProxyAsyLoader::DoCancel()" );
       
   123 
       
   124     // Cancel is called only from destructor
       
   125     // Cleanup is called from destructor
       
   126 
       
   127     COM_TRACE_( "[AccFW:AsyProxy] CASYProxyAsyLoader::DoCancel - return void" );
       
   128     }
       
   129 
       
   130 // -----------------------------------------------------------------------------
       
   131 // CASYProxyAsyLoader::DoCancel
       
   132 // Deletes own class members
       
   133 // (other items were commented in a header).
       
   134 // -----------------------------------------------------------------------------
       
   135 //
       
   136 void CASYProxyAsyLoader::Cleanup()
       
   137     {
       
   138     COM_TRACE_( "[AccFW:AsyProxy] CASYProxyAsyLoader::Cleanup()" );
       
   139 
       
   140     delete iTimer;
       
   141     iTimer = NULL;
       
   142 
       
   143     iImplUidsHandlerArray.Reset();
       
   144     iServiceImplInfoArray.ResetAndDestroy();
       
   145     iHandlerImplInfoArray.ResetAndDestroy();
       
   146 
       
   147     COM_TRACE_( "[AccFW:AsyProxy] CASYProxyAsyLoader::Cleanup - return void" );
       
   148     }
       
   149 
       
   150 // -----------------------------------------------------------------------------
       
   151 // CASYProxyAsyLoader::RunL
       
   152 // Loading has been splitted to five section
       
   153 // Each of them are under time out control.
       
   154 // - case ListImplementations
       
   155 // - case CheckListValues
       
   156 // - case OrderImplementations
       
   157 // - case LoadASY
       
   158 // - case LoadingOver
       
   159 // (other items were commented in a header).
       
   160 // -----------------------------------------------------------------------------
       
   161 //
       
   162 void CASYProxyAsyLoader::RunL()
       
   163     {
       
   164     COM_TRACE_( "[AccFW:AsyProxy] CASYProxyAsyLoader::RunL()" );
       
   165 
       
   166     User::LeaveIfError( iStatus.Int() );
       
   167     
       
   168     if ( iTimer && iTimer->IsActive() )
       
   169         {
       
   170         NextStep();
       
   171         switch ( iStepToDo )
       
   172             {
       
   173             case EASYLoadingStepListImplementations :
       
   174                     ListImplementationsL();
       
   175                     SetActive();
       
   176                     break;
       
   177 
       
   178             case EASYLoadingStepOrderImplementations :
       
   179                     ArrangeImplementationsL();
       
   180                     SetActive();
       
   181                     break;
       
   182 
       
   183             case EASYLoadingStepLoadASY :
       
   184                     DoIssueRequestL();
       
   185                     SetActive();
       
   186                     break;
       
   187 
       
   188             case EASYLoadingOver :
       
   189                     break;
       
   190 
       
   191             default :
       
   192                     // Nothing to do. Assert if it comes here.
       
   193                     TRACE_ASSERT_ALWAYS;
       
   194                     break;
       
   195             }
       
   196         }
       
   197 
       
   198     COM_TRACE_( "[AccFW:AsyProxy] CASYProxyAsyLoader::RunL - return void" );
       
   199     }
       
   200 
       
   201 // -----------------------------------------------------------------------------
       
   202 // CASYProxyAsyLoader::RunError
       
   203 // Returns KErrNone
       
   204 // (other items were commented in a header).
       
   205 // -----------------------------------------------------------------------------
       
   206 //
       
   207 TInt CASYProxyAsyLoader::RunError( TInt aError )
       
   208     {
       
   209     COM_TRACE_1( "[AccFW:AsyProxy] CASYProxyAsyLoader::RunError(%d)", aError );
       
   210 
       
   211      // Avoid Panic in CActiveScheduler
       
   212     aError = KErrNone;
       
   213 
       
   214     COM_TRACE_( "[AccFW:AsyProxy] CASYProxyAsyLoader::RunError - return KErrNone" );
       
   215 
       
   216     return aError;
       
   217     }
       
   218 
       
   219 // -----------------------------------------------------------------------------
       
   220 // CASYProxyAsyLoader::IssueRequest
       
   221 // Starts the loading process of ASY
       
   222 // (other items were commented in a header).
       
   223 // -----------------------------------------------------------------------------
       
   224 //
       
   225 void CASYProxyAsyLoader::IssueRequest()
       
   226     {
       
   227     COM_TRACE_( "[AccFW:AsyProxy] CASYProxyAsyLoader::IssueRequest()" );
       
   228 
       
   229     SetActive();
       
   230     TRequestStatus* ptrStat = &iStatus;
       
   231     *ptrStat = KRequestPending;
       
   232 
       
   233     User::RequestComplete( ptrStat, KErrNone );
       
   234 
       
   235     COM_TRACE_( "[AccFW:AsyProxy] CASYProxyAsyLoader::IssueRequest - return void" );
       
   236     }
       
   237 
       
   238 // -----------------------------------------------------------------------------
       
   239 // CASYProxyAsyLoader::DoIssueRequestL
       
   240 // Last step of loading process of ASY
       
   241 // Creates own CASYProxyASYHandler -object for each ASY to continue it's loading
       
   242 // (other items were commented in a header).
       
   243 // -----------------------------------------------------------------------------
       
   244 //
       
   245 void CASYProxyAsyLoader::DoIssueRequestL()
       
   246     {
       
   247     COM_TRACE_( "[AccFW:AsyProxy] CASYProxyAsyLoader::DoIssueRequest()" );
       
   248     
       
   249     COM_TRACE_1( "[AccFW:AsyProxy] CASYProxyAsyLoader::DoIssueRequestL() - iArrayItemCounter == %d", iArrayItemCounter ); 
       
   250 
       
   251     if ( iArrayItemCounter < iServiceImplInfoArray.Count() )
       
   252         {
       
   253         TRequestStatus* ptrStat = &iStatus;
       
   254         *ptrStat = KRequestPending;
       
   255 
       
   256         CASYProxyASYHandler* createdAccHandler = NULL;
       
   257 
       
   258         // Starts new ASY creating
       
   259         TRAPD( err, createdAccHandler = CASYProxyASYHandler::NewL(
       
   260                 iAsyProxy,
       
   261                 iArrayItemCounter,
       
   262                 iImplUidsHandlerArray.operator[]( iArrayItemCounter ),
       
   263                 *iServiceImplInfoArray[ iArrayItemCounter ]
       
   264                 ) );
       
   265 
       
   266         COM_TRACE_1( "[AccFW:AsyProxy] CASYProxyAsyLoader::DoIssueRequest() - err == %d", err );
       
   267 		if ( createdAccHandler )
       
   268 			{
       
   269 			CleanupStack::PushL ( createdAccHandler );
       
   270 	        iAsyProxy->iAccHandlerArray.AppendL( createdAccHandler );
       
   271 	        iArrayItemCounter++;
       
   272 	        CleanupStack::Pop ( createdAccHandler );
       
   273 			}
       
   274 					
       
   275         User::RequestComplete( ptrStat, err );
       
   276         }
       
   277      else 
       
   278         {
       
   279         User::Leave( KErrArgument );
       
   280         }
       
   281 
       
   282     COM_TRACE_( "[AccFW:AsyProxy] CASYProxyAsyLoader::DoIssueRequest - return void" );
       
   283     }
       
   284 
       
   285 // -----------------------------------------------------------------------------
       
   286 // CASYProxy::ListImplementationsL
       
   287 // List implementations for ASY by using RECom library
       
   288 //    - List service parts to iServiceImplInfoArray
       
   289 //    - List handler parts to iHandlerImplInfoArray
       
   290 // (other items were commented in a header).
       
   291 // -----------------------------------------------------------------------------
       
   292 //
       
   293 void CASYProxyAsyLoader::ListImplementationsL()
       
   294     {
       
   295     COM_TRACE_( "[AccFW:AsyProxy] CASYProxyAsyLoader::ListImplementationsL()" );
       
   296 
       
   297     TRequestStatus* ptrStat = &iStatus;
       
   298     *ptrStat = KRequestPending;
       
   299 
       
   300     TBufC8<KMaxImplementationInfoDataLength>
       
   301             ASYPluginMainServiceName( ( TText8* ) KACCESSORYPLUGINAPIMAINSERVICE );
       
   302 
       
   303     TBufC8<KMaxImplementationInfoDataLength>
       
   304             ASYPluginHandlerName    ( ( TText8* ) KACCESSORYPLUGINAPIHANDLER );
       
   305 
       
   306      // ASY interface_uid
       
   307     TUid pluginInterfaceUid;
       
   308     pluginInterfaceUid.iUid = KACCESSORYPLUGINAPIUID;
       
   309 
       
   310     TEComResolverParams resolverParam;
       
   311 
       
   312     // MainService
       
   313     // -----------------------------------------------------
       
   314     resolverParam.SetDataType( ASYPluginMainServiceName );
       
   315     REComSession::ListImplementationsL( pluginInterfaceUid, 
       
   316                                         resolverParam, 
       
   317                                         iServiceImplInfoArray );
       
   318 
       
   319     // Handler
       
   320     // -----------------------------------------------------
       
   321     resolverParam.SetDataType( ASYPluginHandlerName );
       
   322     REComSession::ListImplementationsL( pluginInterfaceUid, 
       
   323                                         resolverParam, 
       
   324                                         iHandlerImplInfoArray );
       
   325 
       
   326     iListRet = ( iServiceImplInfoArray.Count() > 0 ) ? ETrue : EFalse;
       
   327     COM_TRACE_1( "[AccFW:AsyProxy] CASYProxyAsyLoader::ListImplementationsL - count == %d", iServiceImplInfoArray.Count() );
       
   328     COM_TRACE_1( "[AccFW:AsyProxy] CASYProxyAsyLoader::ListImplementationsL - iListRet == %d", iListRet );
       
   329 
       
   330     User::RequestComplete( ptrStat, KErrNone );
       
   331 
       
   332     COM_TRACE_( "[AccFW:AsyProxy] CASYProxyAsyLoader::ListImplementationsL - return void");
       
   333     }
       
   334 
       
   335 // -----------------------------------------------------------------------------
       
   336 // CASYProxy::ArrangeImplementationsL
       
   337 // Arranges the listed implementations
       
   338 // 1. Find "Idle ASYs" ( i.e. ASY has only service part and not handler part )
       
   339 //    - Service parts are in iServiceImplInfoArray
       
   340 //    - Handler parts are in iHandlerImplInfoArray
       
   341 // 2. Move idle ASYs to last ones within iServiceImplInfoArray
       
   342 // 3. Find Service / Handler pairs
       
   343 //    - Service parts are still in iServiceImplInfoArray
       
   344 //    - Handler parts implementation Uids added to iImplUidsHandlerArray
       
   345 // 4. Add zero values to iImplUidsHandlerArray until it's length is same as
       
   346 //    length of iServiceImplInfoArray
       
   347 // 5. Create CASYProxyASYHandler -array
       
   348 // (other items were commented in a header).
       
   349 // -----------------------------------------------------------------------------
       
   350 //
       
   351 void CASYProxyAsyLoader::ArrangeImplementationsL()
       
   352     {
       
   353     COM_TRACE_( "[AccFW:AsyProxy] CASYProxyAsyLoader::ArrangeImplementationsL()" );
       
   354 
       
   355     TRequestStatus* ptrStat = &iStatus;
       
   356     *ptrStat = KRequestPending;
       
   357 
       
   358     RArray<TInt> onlyServicesIndexArray;
       
   359     CleanupClosePushL( onlyServicesIndexArray );
       
   360 
       
   361     TBuf<KMaxImplementationInfoDataLength>  bufDisplayNameService;
       
   362     TBuf<KMaxImplementationInfoDataLength>  bufDisplayNameHandler;
       
   363 
       
   364     // Find implementation indexes of idle ASYs
       
   365     // ----------------------------------------------------------------
       
   366     TInt lastServiceIndex = iServiceImplInfoArray.Count() - 1;
       
   367     TInt lastHandlerIndex = iHandlerImplInfoArray.Count() - 1;
       
   368 
       
   369     for ( TInt i=0; i<=lastServiceIndex; i++ )
       
   370         { 
       
   371         TBool found( EFalse );
       
   372         bufDisplayNameService = iServiceImplInfoArray.operator[]( i )->DisplayName();
       
   373         for ( TInt j=0; j<=lastHandlerIndex; j++ )
       
   374             {
       
   375             bufDisplayNameHandler = iHandlerImplInfoArray.operator[]( j )->DisplayName();
       
   376             if ( KErrNotFound != bufDisplayNameService.Match( bufDisplayNameHandler ) )
       
   377                 {
       
   378                 found = ETrue;
       
   379                 break; // Break j loop
       
   380                 }
       
   381             }
       
   382 
       
   383         if ( found == EFalse )
       
   384             {
       
   385             onlyServicesIndexArray.Append( i );
       
   386             }
       
   387         }
       
   388 
       
   389     // ASYProxy must know the "real" ASYs count
       
   390     iAsyProxy->SetASYsCount( iServiceImplInfoArray.Count() - onlyServicesIndexArray.Count() );
       
   391 
       
   392     // Move idle ASYs to last ones within iServiceImplInfoArray
       
   393     // ----------------------------------------------------------------
       
   394     for ( TInt k = onlyServicesIndexArray.Count() - 1; k>=0; k-- )
       
   395         {
       
   396         CImplementationInformation *implementationInformation =
       
   397             iServiceImplInfoArray.operator[]( onlyServicesIndexArray.operator[]( k ) );
       
   398 
       
   399         iServiceImplInfoArray.Remove( onlyServicesIndexArray.operator[]( k ) );
       
   400         iServiceImplInfoArray.Append( implementationInformation );
       
   401         }
       
   402 
       
   403     // Find Service / Handler pairs
       
   404     // ----------------------------------------------------------------
       
   405     for ( TInt i=0; i<=lastServiceIndex; i++ )
       
   406         {
       
   407         bufDisplayNameService = iServiceImplInfoArray.operator[]( i )->DisplayName();
       
   408         for ( TInt j=0; j<=lastHandlerIndex; j++ )
       
   409             {
       
   410             bufDisplayNameHandler = iHandlerImplInfoArray.operator[]( j )->DisplayName();
       
   411             if ( KErrNotFound != bufDisplayNameService.Match( bufDisplayNameHandler ) )
       
   412                 {
       
   413                 TUid implementUid = iHandlerImplInfoArray.operator[]( j )->ImplementationUid();
       
   414 
       
   415                 User::LeaveIfError( iImplUidsHandlerArray.Append( implementUid ) );
       
   416                 }
       
   417             }
       
   418         }
       
   419 
       
   420     // Add zero -values to iImplUidsHandlerArray for the last idle ASYs
       
   421     // ----------------------------------------------------------------
       
   422     TUid zeroUid;
       
   423     zeroUid.iUid = ZEROHANDLERUID;
       
   424     while ( iImplUidsHandlerArray.Count() < iServiceImplInfoArray.Count() )
       
   425         {
       
   426         iImplUidsHandlerArray.Append( zeroUid );
       
   427         }
       
   428 
       
   429     User::RequestComplete( ptrStat, KErrNone );
       
   430     CleanupStack::PopAndDestroy( &onlyServicesIndexArray );
       
   431     // only ServicesIndexArray.Close() was called;
       
   432 
       
   433     COM_TRACE_( "[AccFW:AsyProxy] CASYProxyAsyLoader::ArrangeImplementationsL - return void" );
       
   434     }
       
   435 
       
   436 // -----------------------------------------------------------------------------
       
   437 // CASYProxy::NextStep
       
   438 // Increases the loading process control splitter variable
       
   439 // (other items were commented in a header).
       
   440 // -----------------------------------------------------------------------------
       
   441 //
       
   442 void CASYProxyAsyLoader::NextStep()
       
   443     {
       
   444     COM_TRACE_( "[AccFW:AsyProxy] CASYProxyAsyLoader::NextStep()" );
       
   445 
       
   446     switch ( iStepToDo )
       
   447         {
       
   448         case EASYLoadingStepListInit :
       
   449             iStepToDo = EASYLoadingStepListImplementations;
       
   450             break;
       
   451         case EASYLoadingStepListImplementations :
       
   452             iStepToDo = iListRet ? EASYLoadingStepOrderImplementations : EASYLoadingOver;
       
   453             break;
       
   454         case EASYLoadingStepOrderImplementations :
       
   455             iStepToDo = EASYLoadingStepLoadASY;
       
   456             break;
       
   457         case EASYLoadingStepLoadASY :
       
   458             if ( iArrayItemCounter == iServiceImplInfoArray.Count() )
       
   459                 {
       
   460                 iStepToDo = EASYLoadingOver;
       
   461                 }
       
   462             break;
       
   463         default :
       
   464             iStepToDo = EASYLoadingOver;
       
   465             break;
       
   466         }
       
   467 
       
   468     COM_TRACE_1( "[AccFW:AsyProxy] CASYProxyAsyLoader::NextStep - iStepToDo == %d", iStepToDo );
       
   469     COM_TRACE_( "[AccFW:AsyProxy] CASYProxyAsyLoader::NextStep - return void" );
       
   470     }
       
   471 
       
   472 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
   473 
       
   474 // End of File