accessoryservices/accessoryserver/src/ASYProxy/ASYProxyAsyHandler.cpp
changeset 0 4e1aa6a622a0
child 21 ccb4f6b3db21
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:  Handler for ASY instance
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "ASYProxy.h"
       
    21 #include "ASYProxyAsyHandler.h"
       
    22 #include "acc_debug.h"
       
    23 #include <AsyServiceUids.h>
       
    24 #include <e32svr.h>
       
    25 #include <e32def.h>
       
    26 
       
    27 // EXTERNAL DATA STRUCTURES
       
    28 
       
    29 // EXTERNAL FUNCTION PROTOTYPES
       
    30 
       
    31 // CONSTANTS
       
    32 const TInt KMinASYHeapSize      = 0x2000;
       
    33 const TInt KDefaultASYHeapSize  = 0x4000;
       
    34 const TInt KMaxASYHeapSize      = 0x8000;
       
    35 
       
    36 const TInt KMinASYStackSize     = 0x1000;
       
    37 const TInt KDefaultASYStackSize = 0x2000;
       
    38 const TInt KMaxASYStackSize     = 0x4000;
       
    39 
       
    40 // MACROS
       
    41 
       
    42 // LOCAL CONSTANTS AND MACROS
       
    43 
       
    44 // MODULE DATA STRUCTURES
       
    45 
       
    46 // LOCAL FUNCTION PROTOTYPES
       
    47 
       
    48 // FORWARD DECLARATIONS
       
    49 
       
    50 // ============================= LOCAL FUNCTIONS ===============================
       
    51 
       
    52 // ============================ MEMBER FUNCTIONS ===============================
       
    53 
       
    54 // -----------------------------------------------------------------------------
       
    55 // CASYProxyASYHandler::CASYProxyASYHandler
       
    56 // C++ default constructor can NOT contain any code, that
       
    57 // might leave.
       
    58 // -----------------------------------------------------------------------------
       
    59 //
       
    60 CASYProxyASYHandler::CASYProxyASYHandler(
       
    61       CASYProxy* aASYProxy,
       
    62       const TInt aIndex,
       
    63       const TUid aHandlerUid,
       
    64       const CImplementationInformation& aImplementationInformation )
       
    65 
       
    66     : iHandlerUid( aHandlerUid ),
       
    67       iASYProxy( aASYProxy ),    
       
    68       iASYState( EASYProxyASYReset ),
       
    69       iIndex( aIndex ),
       
    70       iHeapValue( KDefaultASYHeapSize ),
       
    71       iStackValue( KDefaultASYStackSize )
       
    72     {
       
    73     COM_TRACE_4( "[AccFW:AsyProxy] CASYProxyASYHandler::CASYProxyASYHandler(0x%x, %d, 0x%x, 0x%x )", aASYProxy, aIndex, aHandlerUid.iUid, &aImplementationInformation );
       
    74     
       
    75     iImplementationInformation = const_cast<CImplementationInformation*>
       
    76                                            ( &aImplementationInformation );
       
    77 
       
    78     COM_TRACE_1( "[AccFW:AsyProxy] CASYProxyASYHandler::CASYProxyASYHandler( 0x%x )", &iImplementationInformation );
       
    79 
       
    80     SetMemoryValues();
       
    81 
       
    82     COM_TRACE_( "[AccFW:AsyProxy] CASYProxyASYHandler::CASYProxyASYHandler" );
       
    83     }
       
    84 
       
    85 // -----------------------------------------------------------------------------
       
    86 // CASYProxyASYHandler::ConstructL
       
    87 // Symbian 2nd phase constructor can leave.
       
    88 // -----------------------------------------------------------------------------
       
    89 //
       
    90 void CASYProxyASYHandler::ConstructL()
       
    91     {
       
    92     COM_TRACE_( "[AccFW:AsyProxy] CASYProxyASYHandler::ConstructL()" );
       
    93 
       
    94     LoadASYL();
       
    95 
       
    96     COM_TRACE_( "[AccFW:AsyProxy] CASYProxyASYHandler::ConstructL - return void" );
       
    97     }
       
    98 
       
    99 // -----------------------------------------------------------------------------
       
   100 // CASYProxyASYHandler::NewL
       
   101 // Two-phased constructor.
       
   102 // -----------------------------------------------------------------------------
       
   103 //
       
   104 CASYProxyASYHandler* CASYProxyASYHandler::NewL(
       
   105         CASYProxy* aASYProxy,
       
   106         const TInt aIndex,
       
   107         const TUid aHandlerUid,
       
   108         const CImplementationInformation& aImplementationInformation )
       
   109     {
       
   110     COM_TRACE_4( "[AccFW:AsyProxy] CASYProxyASYHandler::CASYProxyASYHandler(0x%x, %d, 0x%x, 0x%x )", aASYProxy, aIndex, aHandlerUid.iUid, &aImplementationInformation );
       
   111 
       
   112     CASYProxyASYHandler* self = new ( ELeave ) CASYProxyASYHandler(
       
   113                                                aASYProxy,
       
   114                                                aIndex,
       
   115                                                aHandlerUid,
       
   116                                                aImplementationInformation
       
   117                                                );
       
   118     CleanupStack::PushL( self );
       
   119     self->ConstructL();
       
   120     CleanupStack::Pop( self );
       
   121 
       
   122     COM_TRACE_1( "[AccFW:AsyProxy] CASYProxyASYHandler::NewL - return 0x%x", self );
       
   123 
       
   124     return self;
       
   125     }
       
   126 
       
   127 // Destructor
       
   128 CASYProxyASYHandler::~CASYProxyASYHandler()
       
   129     {
       
   130     COM_TRACE_( "[AccFW:AsyProxy] CASYProxyASYHandler::~CASYProxyASYHandler()" );
       
   131 
       
   132     if ( iASYServiceMain )
       
   133         {
       
   134         // Cancel main service
       
   135         iASYServiceMain->Cancel();
       
   136         delete iASYServiceMain;
       
   137         iASYServiceMain = NULL;
       
   138         }
       
   139 
       
   140     COM_TRACE_( "[AccFW:AsyProxy] CASYProxyASYHandler::~CASYProxyASYHandler" );
       
   141     }
       
   142 
       
   143 // -----------------------------------------------------------------------------
       
   144 // CASYProxyASYHandler::SetMemoryValues
       
   145 // Sets heap and stack memory values for a new thread
       
   146 // (other items were commented in a header).
       
   147 // -----------------------------------------------------------------------------
       
   148 //
       
   149 void CASYProxyASYHandler::SetMemoryValues()
       
   150     {
       
   151     COM_TRACE_( "[AccFW:AsyProxy] CASYProxyASYHandler::SetMemoryValues()" );
       
   152 
       
   153     TBuf8<KMaxImplementationInfoDataLength> bufOpaqData;
       
   154     bufOpaqData = iImplementationInformation->OpaqueData();
       
   155 
       
   156     TInt tmpHeapMemValue( 0 );
       
   157     TInt tmpStackMemValue( 0 );
       
   158 
       
   159     _LIT8( KMatchHeapAndStack, "Heap=0x????|Stack=0x????" );
       
   160     _LIT8( KMatchHeap,         "Heap=0x????" );
       
   161     _LIT8( KMatchStackAndHeap, "Stack=0x????|Heap=0x????" );
       
   162     _LIT8( KMatchStack,        "Stack=0x????" );
       
   163 
       
   164     _LIT8(KHeap,"Heap=0x");
       
   165     _LIT8(KStack,"Stack=0x");
       
   166 
       
   167     if ( ( KErrNotFound != bufOpaqData.Match( KMatchHeapAndStack ) ) ||
       
   168          ( KErrNotFound != bufOpaqData.Match( KMatchHeap ) ) ||
       
   169          ( KErrNotFound != bufOpaqData.Match( KMatchStackAndHeap ) ) ||
       
   170          ( KErrNotFound != bufOpaqData.Match( KMatchStack ) ) )
       
   171         {
       
   172         tmpHeapMemValue = ReadMemoryItem( bufOpaqData, KHeap );
       
   173         tmpStackMemValue = ReadMemoryItem( bufOpaqData, KStack );
       
   174 
       
   175         if ( ( tmpHeapMemValue != KErrGeneral ) &&
       
   176              ( tmpStackMemValue != KErrGeneral ) )
       
   177             {
       
   178 
       
   179             if ( ( tmpHeapMemValue > KMinASYHeapSize) &&
       
   180                  ( tmpHeapMemValue < KMaxASYHeapSize ) )
       
   181                 {
       
   182                 iHeapValue = tmpHeapMemValue;
       
   183                 }
       
   184 
       
   185             if ( ( tmpStackMemValue > KMinASYStackSize) &&
       
   186                  ( tmpStackMemValue < KMaxASYStackSize ) )
       
   187                 {
       
   188                 iStackValue = tmpStackMemValue;
       
   189                 }
       
   190             }
       
   191         }
       
   192     else
       
   193         {
       
   194         COM_TRACE_( "[AccFW:AsyProxy] CASYProxyASYHandler::SetMemoryValues - Opaque data was empty or in wrong format." );
       
   195         }
       
   196 
       
   197     COM_TRACE_2( "[AccFW:AsyProxy] CASYProxyASYHandler::SetMemoryValues(iHeapValue == 0x%x, iStackValue == 0x%x)", iHeapValue, iStackValue );
       
   198     COM_TRACE_( "[AccFW:AsyProxy] CASYProxyASYHandler::SetMemoryValues - return void" );
       
   199     }
       
   200 
       
   201 // -----------------------------------------------------------------------------
       
   202 // CASYProxyASYHandler::ReadMemoryItem
       
   203 // Sets heap and stack memory values for a new thread
       
   204 // (other items were commented in a header).
       
   205 // -----------------------------------------------------------------------------
       
   206 //
       
   207 TInt CASYProxyASYHandler::ReadMemoryItem( const TDesC8& aOpaqData,
       
   208                                           const TDesC8& aMemKey )
       
   209     {
       
   210     COM_TRACE_( "[AccFW:AsyProxy] CASYProxyASYHandler::ReadMemoryItem( TDesC8, TDesC8 )" );
       
   211 
       
   212     TPtrC8 ptrValue;
       
   213     TChar tmpChar;
       
   214     TLex8 lex;
       
   215     TBool hDigitsOK( ETrue );
       
   216     TUint memValue( 0 );
       
   217     const TInt KValueLength( 4 );
       
   218     TInt valueBeg(0);
       
   219     TInt valueFind( 0 );
       
   220     TInt retValue( KErrGeneral );
       
   221 
       
   222     valueFind = aOpaqData.Find( aMemKey );
       
   223     if ( KErrNotFound != valueFind )
       
   224         {
       
   225         valueBeg = valueFind + aMemKey.Length();
       
   226         ptrValue.Set( aOpaqData.Mid( valueBeg, KValueLength ) );
       
   227 
       
   228         for ( TInt i=0; i < KValueLength; i++ )
       
   229             {
       
   230             tmpChar = ptrValue[i];
       
   231             if ( !tmpChar.IsHexDigit() )
       
   232                 {
       
   233                 hDigitsOK = EFalse;
       
   234                 COM_TRACE_( "[AccFW:AsyProxy] CASYProxyASYHandler::ReadMemoryItem - Opaque data was in wrong format." );
       
   235                 break;
       
   236                 }
       
   237             }
       
   238 
       
   239         if ( hDigitsOK )
       
   240             {
       
   241             lex.Assign( ptrValue );
       
   242             if ( !lex.Val( memValue, EHex ) )
       
   243                 {
       
   244                 retValue = memValue;
       
   245                 }
       
   246             }
       
   247         }
       
   248     else
       
   249         {
       
   250         retValue = 0;
       
   251         }
       
   252 
       
   253     COM_TRACE_1( "[AccFW:AsyProxy] CASYProxyASYHandler::ReadMemoryItem - return 0x%x", retValue );
       
   254 
       
   255     return retValue;
       
   256     }
       
   257 
       
   258 // -----------------------------------------------------------------------------
       
   259 // CASYProxyASYHandler::LoadAsysL
       
   260 // Creates a new CASYProxyMainService object and orders it to start a new thread
       
   261 // (other items were commented in a header).
       
   262 // -----------------------------------------------------------------------------
       
   263 //
       
   264 void CASYProxyASYHandler::LoadASYL()
       
   265     {
       
   266     COM_TRACE_( "[AccFW:AsyProxy] CASYProxyASYHandler::LoadASYL()" );
       
   267 
       
   268     COM_TRACE_1( "[AccFW:AsyProxy] CASYProxyASYHandler::LoadASYL - iIndex == %d", iIndex );
       
   269     COM_TRACE_2( "[AccFW:AsyProxy] CASYProxyASYHandler::LoadASYL[%d] - ImplementationUid == 0x%x", iIndex, iImplementationInformation->ImplementationUid() );
       
   270     COM_TRACE_2( "[AccFW:AsyProxy] CASYProxyASYHandler::LoadASYL[%d] - iHandlerUid == 0x%x", iIndex, iHandlerUid );
       
   271     COM_TRACE_2( "[AccFW:AsyProxy] CASYProxyASYHandler::LoadASYL[%d] - dllUid == display_name == %S", iIndex, &iImplementationInformation->DisplayName() );
       
   272 
       
   273     COM_TRACE_2( "[AccFW:AsyProxy] CASYProxyASYHandler::LoadASYL[%d] - iHeapValue == 0x%x", iIndex, iHeapValue );
       
   274     COM_TRACE_2( "[AccFW:AsyProxy] CASYProxyASYHandler::LoadASYL[%d] - iStackValue == 0x%x", iIndex, iStackValue );
       
   275 
       
   276     iASYServiceMain = CASYProxyMainService::NewL( this );
       
   277 
       
   278     iASYServiceMain->StartThreadL(
       
   279                      iImplementationInformation->ImplementationUid(),
       
   280                      iHandlerUid,
       
   281                      iHeapValue,
       
   282                      iStackValue );
       
   283 
       
   284     COM_TRACE_( "[AccFW:AsyProxy] CASYProxyASYHandler::LoadASYL - return void" );
       
   285     }
       
   286 
       
   287 // -----------------------------------------------------------------------------
       
   288 // CASYProxyASYHandler::UpdateASYStateL
       
   289 // Updates the status information of ASY
       
   290 // Informs ASYProxy about changes of status
       
   291 // (other items were commented in a header).
       
   292 // -----------------------------------------------------------------------------
       
   293 //
       
   294 void CASYProxyASYHandler::UpdateASYStateL( TASYProxyASYState aASYState )
       
   295     {
       
   296     COM_TRACE_2( "[AccFW:AsyProxy] CASYProxyASYHandler::UpdateASYStateL(iIndex == %d, aAsyState == %d)", iIndex, aASYState );
       
   297 
       
   298     iASYState = aASYState;
       
   299 
       
   300     if ( aASYState == EASYProxyASYConnectionReady )
       
   301         {
       
   302         iASYProxy->LoadCompleteL( iIndex );
       
   303         }
       
   304 
       
   305     else if ( aASYState == EASYProxyASYThreadKills )
       
   306         {
       
   307         iASYProxy->ThreadKills( iIndex );
       
   308         }
       
   309 
       
   310     COM_TRACE_( "[AccFW:AsyProxy] CASYProxyASYHandler::UpdateASYStateL - return void" );
       
   311     }
       
   312 
       
   313 // -----------------------------------------------------------------------------
       
   314 // CASYProxyASYHandler::CurrentState
       
   315 // Returns the current status of ASY
       
   316 // (other items were commented in a header).
       
   317 // -----------------------------------------------------------------------------
       
   318 //
       
   319 TASYProxyASYState CASYProxyASYHandler::CurrentState() const
       
   320     {
       
   321     COM_TRACE_( "[AccFW:AsyProxy] CASYProxyASYHandler::CurrentState()" );
       
   322     COM_TRACE_1( "[AccFW:AsyProxy] CASYProxyASYHandler::CurrentState - iIndex == %d", iIndex );
       
   323     COM_TRACE_1( "[AccFW:AsyProxy] CASYProxyASYHandler::CurrentState - return %d", iASYState );
       
   324     return iASYState;
       
   325     }
       
   326 
       
   327 // -----------------------------------------------------------------------------
       
   328 // CASYProxyASYHandler::Index
       
   329 // Returns the index of this ASY
       
   330 // (other items were commented in a header).
       
   331 // -----------------------------------------------------------------------------
       
   332 //
       
   333 TInt CASYProxyASYHandler::Index() const
       
   334     {
       
   335     COM_TRACE_( "[AccFW:AsyProxy] CASYProxyASYHandler::Index()" );
       
   336     COM_TRACE_1( "[AccFW:AsyProxy] CASYProxyASYHandler::Index - return %d", iIndex );
       
   337     return iIndex;
       
   338     }
       
   339 
       
   340 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
   341 
       
   342 // End of File