accessoryservices/accessoryserver/src/ASYProxy/ASYProxy.cpp
changeset 0 4e1aa6a622a0
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     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:  Polymorphic interface to Accessory Server
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "ASYProxyAsyHandler.h"
       
    21 #include "ASYProxy.h"
       
    22 #include <ecom/ecom.h>
       
    23 #include "AsyProxyObserver.h"
       
    24 #include "acc_debug.h"
       
    25 
       
    26 #include <e32svr.h>
       
    27 
       
    28 // EXTERNAL DATA STRUCTURES
       
    29 
       
    30 // EXTERNAL FUNCTION PROTOTYPES
       
    31 
       
    32 // CONSTANTS
       
    33 
       
    34 // MACROS
       
    35 
       
    36 // LOCAL CONSTANTS AND MACROS
       
    37 
       
    38 // MODULE DATA STRUCTURES
       
    39 
       
    40 // LOCAL FUNCTION PROTOTYPES
       
    41 
       
    42 // ASYProxy -dll construction function
       
    43 EXPORT_C CASYProxyAPI* NewAccessoryHandlerProxyL();
       
    44 
       
    45 // FORWARD DECLARATIONS
       
    46 
       
    47 // ============================= LOCAL FUNCTIONS ===============================
       
    48 
       
    49 // -----------------------------------------------------------------------------
       
    50 // NewAccessoryHandlerProxyL Creates instance of CASYProxy
       
    51 // Returns: self: Pointer to created instance
       
    52 // -----------------------------------------------------------------------------
       
    53 //
       
    54 EXPORT_C CASYProxyAPI* NewAccessoryHandlerProxyL()
       
    55     {
       
    56     API_TRACE_( "[AccFW:AsyProxy] NewAccessoryHandlerProxy()" );
       
    57 
       
    58     CASYProxy* self = new ( ELeave ) CASYProxy();
       
    59     CleanupStack::PushL( self );
       
    60     self->ConstructL();
       
    61     CleanupStack::Pop( self );
       
    62 
       
    63     API_TRACE_1( "[AccFW:AsyProxy] NewAccessoryHandlerProxy - return 0x%x", self );
       
    64 
       
    65     return (CASYProxyAPI*) self;
       
    66     }
       
    67 
       
    68 // ============================ MEMBER FUNCTIONS ===============================
       
    69 
       
    70 // -----------------------------------------------------------------------------
       
    71 // CASYProxy::CASYProxy
       
    72 // C++ default constructor can NOT contain any code, that
       
    73 // might leave.
       
    74 // -----------------------------------------------------------------------------
       
    75 //
       
    76 CASYProxy::CASYProxy()
       
    77     : iRealASYsCount( -1 ), iLoadedRealASYsCount( 0 ), iLoadedASYsCount( 0 )
       
    78     {
       
    79     COM_TRACE_( "[AccFW:AsyProxy] CASYProxy::CASYProxy()" );
       
    80     COM_TRACE_( "[AccFW:AsyProxy] CASYProxy::CASYProxy" );
       
    81     }
       
    82 
       
    83 // -----------------------------------------------------------------------------
       
    84 // CASYProxy::ConstructL
       
    85 // Symbian 2nd phase constructor can leave.
       
    86 // -----------------------------------------------------------------------------
       
    87 //
       
    88 void CASYProxy::ConstructL()
       
    89     {
       
    90     COM_TRACE_( "[AccFW:AsyProxy] CASYProxy::ConstructL()" );
       
    91 
       
    92 #ifdef _DEBUG
       
    93 
       
    94     TRAPD( openErr, REComSession::OpenL() )
       
    95     COM_TRACE_1( "[AccFW:AsyProxy] CASYProxy::ConstructL - REComSession::OpenL() == %d", openErr );
       
    96     User::LeaveIfError( openErr );
       
    97 
       
    98 #else
       
    99 
       
   100     REComSession::OpenL();
       
   101 
       
   102 #endif // _DEBUG
       
   103 
       
   104     COM_TRACE_( "[AccFW:AsyProxy] CASYProxy::ConstructL - return void" );
       
   105     }
       
   106 
       
   107 // Destructor
       
   108 CASYProxy::~CASYProxy()
       
   109     {
       
   110     COM_TRACE_( "[AccFW:AsyProxy] CASYProxy::~CASYProxy()" );
       
   111 
       
   112     DestroyLoader();
       
   113     iAccHandlerArray.ResetAndDestroy();
       
   114 
       
   115     // RECom isn't needed any more
       
   116     REComSession::FinalClose();
       
   117 
       
   118     COM_TRACE_( "[AccFW:AsyProxy] CASYProxy::~CASYProxy" );
       
   119     }
       
   120 
       
   121 // -----------------------------------------------------------------------------
       
   122 // CASYProxy::LoadASYs
       
   123 // Launches ASYLoader to start loading ASYs
       
   124 // (other items were commented in a header).
       
   125 // -----------------------------------------------------------------------------
       
   126 //
       
   127 void CASYProxy::LoadASYs()
       
   128     {
       
   129     COM_TRACE_( "[AccFW:AsyProxy] CASYProxy::LoadASYs()" );
       
   130 
       
   131     iAsyLoader->IssueRequest();
       
   132 
       
   133     COM_TRACE_( "[AccFW:AsyProxy] CASYProxy::LoadASYs - return void" );
       
   134     }
       
   135 
       
   136 // -----------------------------------------------------------------------------
       
   137 // CASYProxy::InitializeL
       
   138 // Sets pointer for observer to make possible callbacks
       
   139 // Creates a new CASYProxyAsyLoader -object
       
   140 // (other items were commented in a header).
       
   141 // -----------------------------------------------------------------------------
       
   142 //
       
   143 void CASYProxy::InitializeL( MASYProxyObserver* aAccServerObserver )
       
   144     {
       
   145     COM_TRACE_( "[AccFW:AsyProxy] CASYProxy::InitializeL()" );
       
   146 
       
   147     iAccServerObserver = aAccServerObserver;
       
   148     iAsyLoader = CASYProxyAsyLoader::NewL( this );
       
   149 
       
   150     COM_TRACE_( "[AccFW:AsyProxy] CASYProxy::InitializeL - return void" );
       
   151     }
       
   152 
       
   153 // -----------------------------------------------------------------------------
       
   154 // CASYProxy::ASYInfo
       
   155 // Returns implementation information
       
   156 // (other items were commented in a header).
       
   157 // -----------------------------------------------------------------------------
       
   158 //
       
   159 const CImplementationInformation* CASYProxy::ASYInfo( TInt aIndex ) const
       
   160     {
       
   161     COM_TRACE_1( "[AccFW:AsyProxy] CASYProxy::ASYInfo(%d)", aIndex );
       
   162 
       
   163     if ( iAccHandlerArray.Count() )
       
   164         {
       
   165 
       
   166         COM_TRACE_1( "[AccFW:AsyProxy] CASYProxy::ASYInfo - return 0x%x", &iAccHandlerArray.operator[]( aIndex )->iImplementationInformation );
       
   167 
       
   168         return iAccHandlerArray.operator[]( aIndex )->iImplementationInformation;
       
   169         }
       
   170 
       
   171      else
       
   172         {
       
   173 
       
   174         COM_TRACE_( "[AccFW:AsyProxy] CASYProxy::ASYInfo - return NULL" );
       
   175 
       
   176         return NULL;
       
   177         }
       
   178     }
       
   179 
       
   180 // -----------------------------------------------------------------------------
       
   181 // CASYProxy::ASYState
       
   182 // Returns state of ASY
       
   183 // (other items were commented in a header).
       
   184 // -----------------------------------------------------------------------------
       
   185 //
       
   186 TASYProxyASYState CASYProxy::ASYState( TInt aIndex ) const
       
   187     {
       
   188     COM_TRACE_1( "[AccFW:AsyProxy] CASYProxy::ASYState(%d)", aIndex );
       
   189     
       
   190     if ( iAccHandlerArray.Count() )
       
   191         {
       
   192 
       
   193         COM_TRACE_1( "[AccFW:AsyProxy] CASYProxy::ASYState - return %d", iAccHandlerArray.operator[]( aIndex )->CurrentState() );
       
   194 
       
   195         return iAccHandlerArray.operator[]( aIndex )->CurrentState();
       
   196         }
       
   197 
       
   198     else 
       
   199         {
       
   200 
       
   201         COM_TRACE_( "[AccFW:AsyProxy] CASYProxy::ASYState - return TASYProxyASYStateReset");
       
   202 
       
   203         return EASYProxyASYReset;
       
   204         }
       
   205     }
       
   206 
       
   207 // -----------------------------------------------------------------------------
       
   208 // CASYProxy::SetASYsCount
       
   209 // Sets ASYs count
       
   210 // (other items were commented in a header).
       
   211 // -----------------------------------------------------------------------------
       
   212 //
       
   213 void CASYProxy::SetASYsCount( TInt aCount )
       
   214     {
       
   215     COM_TRACE_1( "[AccFW:AsyProxy] CASYProxy::SetASYsCount(%d)", aCount );
       
   216     
       
   217     iRealASYsCount = aCount;
       
   218 
       
   219     COM_TRACE_( "[AccFW:AsyProxy] CASYProxy::SetASYsCount - return void" );
       
   220     }
       
   221 
       
   222 // -----------------------------------------------------------------------------
       
   223 // CASYProxy::ASYCount
       
   224 // Returns count of ASYs
       
   225 // (other items were commented in a header).
       
   226 // -----------------------------------------------------------------------------
       
   227 //
       
   228 TInt CASYProxy::ASYsCount() const
       
   229     {
       
   230     COM_TRACE_( "[AccFW:AsyProxy] CASYProxy::ASYsCount()" );
       
   231 
       
   232     COM_TRACE_1( "[AccFW:AsyProxy] CASYProxy::ASYsCount - return %d", iRealASYsCount );
       
   233 
       
   234     return iRealASYsCount;
       
   235     }
       
   236 
       
   237 // -----------------------------------------------------------------------------
       
   238 // CASYProxy::LoadCompleteL
       
   239 // Inform observer that loading is completed
       
   240 // (other items were commented in a header).
       
   241 // -----------------------------------------------------------------------------
       
   242 //
       
   243 void CASYProxy::LoadCompleteL( const TInt aASYIndex )
       
   244     {
       
   245     COM_TRACE_1( "[AccFW:AsyProxy] CASYProxy::LoadCompleteL(%d)", aASYIndex );
       
   246 
       
   247     iLoadedASYsCount++;
       
   248 
       
   249     if ( aASYIndex <= ASYsCount() - 1 )
       
   250         {
       
   251         iLoadedRealASYsCount++;
       
   252 
       
   253         TBool lastASYComplete =
       
   254               ( iLoadedRealASYsCount == ASYsCount() ) ? ETrue : EFalse;
       
   255 
       
   256         iAccServerObserver->LoadCompleteL( aASYIndex, lastASYComplete );
       
   257         }
       
   258 
       
   259     DestroyLoader();
       
   260 
       
   261     COM_TRACE_( "[AccFW:AsyProxy] CASYProxy::LoadCompleteL" );
       
   262     }
       
   263 
       
   264 // -----------------------------------------------------------------------------
       
   265 // CASYProxy::ThreadKills
       
   266 // Inform observer that loading is completed
       
   267 // (other items were commented in a header).
       
   268 // -----------------------------------------------------------------------------
       
   269 //
       
   270 void CASYProxy::ThreadKills( const TInt aASYIndex )
       
   271     {
       
   272     COM_TRACE_1( "[AccFW:AsyProxy] CASYProxy::ThreadKills(%d)", aASYIndex );
       
   273 
       
   274     iAccServerObserver->ThreadKills( aASYIndex );
       
   275 
       
   276     COM_TRACE_( "[AccFW:AsyProxy] CASYProxy::ThreadKills" );
       
   277     }
       
   278 
       
   279 // -----------------------------------------------------------------------------
       
   280 // CASYProxy::LoadTimeOutL
       
   281 // Inform observer that loading is timed out
       
   282 // (other items were commented in a header).
       
   283 // -----------------------------------------------------------------------------
       
   284 //
       
   285 void CASYProxy::LoadTimeOutL()
       
   286     {
       
   287     COM_TRACE_( "[AccFW:AsyProxy] CASYProxy::LoadTimeOutL()" );
       
   288 
       
   289     if ( ( iLoadedRealASYsCount < ASYsCount() ) || ( ASYsCount() < 0 ) )
       
   290         {
       
   291         iAccServerObserver->LoadingTimedOutL();
       
   292         }
       
   293 
       
   294     DestroyLoader();
       
   295 
       
   296     COM_TRACE_( "[AccFW:AsyProxy] CASYProxy::LoadTimeOutL - return void" );
       
   297     }
       
   298 
       
   299 // -----------------------------------------------------------------------------
       
   300 // CASYProxy::DestroyLoader
       
   301 // Deletes the ASY loader instance
       
   302 // (other items were commented in a header).
       
   303 // -----------------------------------------------------------------------------
       
   304 //
       
   305 void CASYProxy::DestroyLoader()
       
   306     {
       
   307     COM_TRACE_( "[AccFW:AsyProxy] CASYProxy::DestroyLoader()" );
       
   308     
       
   309     TInt handlerCount( 0 );
       
   310     handlerCount = iAccHandlerArray.Count();
       
   311 
       
   312     if ( iAsyLoader && iLoadedASYsCount == handlerCount )
       
   313         {
       
   314         delete iAsyLoader;
       
   315         iAsyLoader = 0;
       
   316         }
       
   317 
       
   318     COM_TRACE_( "[AccFW:AsyProxy] CASYProxy::DestroyLoader" );
       
   319     }
       
   320 
       
   321 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
   322 
       
   323 // End of File