languageinterworkingfw/servicehandler/src/liwtlsdata.cpp
changeset 57 61b27eec6533
parent 45 7aa6007702af
equal deleted inserted replaced
45:7aa6007702af 57:61b27eec6533
     1 /*
       
     2 * Copyright (c) 2005 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 the License "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:       TLS data object.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 // INCLUDE FILES
       
    24 #include "liwtlsdata.h"
       
    25 
       
    26 // CONSTANTS
       
    27 
       
    28 const TInt KMenuLaunchObserversGranularity = 2;
       
    29 
       
    30 // ================= MEMBER FUNCTIONS ==========================================
       
    31 
       
    32 CLiwTlsData::CLiwTlsData() :
       
    33     iMenuLaunchObservers( KMenuLaunchObserversGranularity )
       
    34     {
       
    35     }
       
    36 
       
    37 CLiwTlsData::~CLiwTlsData()
       
    38     {
       
    39     iMenuLaunchObservers.Reset();
       
    40     Dll::FreeTls();
       
    41     }
       
    42     
       
    43 CLiwTlsData* CLiwTlsData::NewL()
       
    44     {
       
    45     CLiwTlsData* data = new( ELeave ) CLiwTlsData;
       
    46     CleanupStack::PushL( data );
       
    47     data->ConstructL();
       
    48     CleanupStack::Pop(data); // data
       
    49     return data;
       
    50     }
       
    51     
       
    52 void CLiwTlsData::ConstructL()
       
    53     {
       
    54     User::LeaveIfError( Dll::SetTls( this ) );
       
    55     }
       
    56 
       
    57 // -----------------------------------------------------------------------------
       
    58 // CLiwTlsData::OpenL
       
    59 // -----------------------------------------------------------------------------
       
    60 //
       
    61 CLiwTlsData* CLiwTlsData::OpenL()
       
    62     {
       
    63     CLiwTlsData* data = Instance();
       
    64     if ( !data )
       
    65         {
       
    66         data = NewL();
       
    67         }
       
    68     
       
    69     data->iRefCount++;
       
    70     return data;
       
    71     }
       
    72 
       
    73 // -----------------------------------------------------------------------------
       
    74 // CLiwTlsData::Close
       
    75 // -----------------------------------------------------------------------------
       
    76 //
       
    77 void CLiwTlsData::Close()
       
    78     {
       
    79     CLiwTlsData* data = Instance();
       
    80     __ASSERT_DEBUG( data, User::Invariant() );
       
    81     if ( data )
       
    82         {
       
    83         if ( --data->iRefCount == 0 )
       
    84             {
       
    85             delete data; // also frees TLS
       
    86             }
       
    87         }
       
    88     }
       
    89 
       
    90 // -----------------------------------------------------------------------------
       
    91 // CLiwTlsData::AddMenuLaunchObserverL
       
    92 // -----------------------------------------------------------------------------
       
    93 //
       
    94 void CLiwTlsData::AddMenuLaunchObserverL( MLiwMenuLaunchObserver* aObserver )
       
    95     {
       
    96     User::LeaveIfError( iMenuLaunchObservers.Append( aObserver ) );
       
    97     }
       
    98 
       
    99 // -----------------------------------------------------------------------------
       
   100 // CLiwTlsData::RemoveMenuLaunchObserver
       
   101 // -----------------------------------------------------------------------------
       
   102 //   
       
   103 void CLiwTlsData::RemoveMenuLaunchObserver( MLiwMenuLaunchObserver* aObserver )
       
   104     {
       
   105     TInt index = iMenuLaunchObservers.Find( aObserver );
       
   106     if ( index >= 0 )
       
   107         {
       
   108         iMenuLaunchObservers.Remove( index );
       
   109         }
       
   110     }
       
   111     
       
   112 // -----------------------------------------------------------------------------
       
   113 // CLiwTlsData::ReportMenuLaunch
       
   114 // -----------------------------------------------------------------------------
       
   115 //
       
   116 void CLiwTlsData::ReportMenuLaunch()
       
   117     {
       
   118     TInt count = iMenuLaunchObservers.Count();
       
   119     for ( TInt index = 0 ; index < count ; index++ )
       
   120         {
       
   121         iMenuLaunchObservers[index]->MenuLaunched();
       
   122         }
       
   123     }
       
   124 
       
   125 // End of file