mpxmusicplayer/commonui/src/mpxtlshelper.cpp
changeset 0 ff3acec5bc43
equal deleted inserted replaced
-1:000000000000 0:ff3acec5bc43
       
     1 /*
       
     2 * Copyright (c) 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:  Implementation of TLS Helper
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "mpxtlshelper.h"
       
    22 
       
    23 
       
    24 // ======== MEMBER FUNCTIONS ========
       
    25 
       
    26 // ---------------------------------------------------------------------------
       
    27 // Initialize TLS for storing application information.
       
    28 // ---------------------------------------------------------------------------
       
    29 //
       
    30 EXPORT_C void MPXTlsHelper::InitializeL()
       
    31     {
       
    32     TMPXTlsStruct* tls = reinterpret_cast<TMPXTlsStruct*>( Dll::Tls() );
       
    33     if ( !tls )
       
    34         {
       
    35         TMPXTlsStruct* tls = new ( ELeave ) TMPXTlsStruct;
       
    36         tls->iHostUid = KNullUid;
       
    37         tls->iNeedSave = EFalse;
       
    38         tls->iAllowMove = EFalse;
       
    39         tls->iLaunchMode = EMPXLaunchModeStopped;
       
    40         tls->useCount = 1;
       
    41         Dll::SetTls( reinterpret_cast<TAny*>( tls ) );
       
    42         }
       
    43     else
       
    44         {
       
    45         tls->useCount++;
       
    46         }
       
    47     }
       
    48 
       
    49 // ---------------------------------------------------------------------------
       
    50 // Uninitialize TLS data storage. Must be called
       
    51 // before exiting application to unload resources.
       
    52 // ---------------------------------------------------------------------------
       
    53 //
       
    54 EXPORT_C void MPXTlsHelper::Uninitialize()
       
    55     {
       
    56     TMPXTlsStruct* tls =  reinterpret_cast<TMPXTlsStruct*>( Dll::Tls() );
       
    57     if ( tls && !( --tls->useCount ) )
       
    58         {
       
    59         delete tls;
       
    60         tls = NULL;
       
    61         Dll::SetTls( NULL );
       
    62         }
       
    63     }
       
    64 
       
    65 // ---------------------------------------------------------------------------
       
    66 // Store host application UID to TLS.
       
    67 // ---------------------------------------------------------------------------
       
    68 //
       
    69 EXPORT_C void MPXTlsHelper::SetHostUidL(
       
    70     const TUid& aUid )
       
    71     {
       
    72     TMPXTlsStruct* tls =  reinterpret_cast<TMPXTlsStruct*>( Dll::Tls() );
       
    73     if ( tls )
       
    74         {
       
    75         tls->iHostUid = aUid;
       
    76         }
       
    77     else
       
    78         {
       
    79         User::Leave( KErrNotReady );
       
    80         }
       
    81     }
       
    82 
       
    83 // ---------------------------------------------------------------------------
       
    84 // Store file path of saved clip.
       
    85 // ---------------------------------------------------------------------------
       
    86 //
       
    87 EXPORT_C void MPXTlsHelper::SetFilePath(
       
    88     const TDesC& aFilePath )
       
    89     {
       
    90     TMPXTlsStruct* tls =  reinterpret_cast<TMPXTlsStruct*>( Dll::Tls() );
       
    91     if ( tls )
       
    92         {
       
    93         tls->iFilePath = (TFileName) aFilePath;
       
    94         }
       
    95     }
       
    96 
       
    97 
       
    98 // ---------------------------------------------------------------------------
       
    99 // Store file path of saved clip.
       
   100 // ---------------------------------------------------------------------------
       
   101 //
       
   102 EXPORT_C TFileName MPXTlsHelper::FilePath()
       
   103     {
       
   104     TMPXTlsStruct* tls =  reinterpret_cast<TMPXTlsStruct*>( Dll::Tls() );
       
   105     if ( tls )
       
   106         {
       
   107         return (TFileName)tls->iFilePath;
       
   108         }
       
   109 
       
   110     return TFileName(NULL);
       
   111     }
       
   112 
       
   113 // ---------------------------------------------------------------------------
       
   114 // Fetch host application UID from TLS.
       
   115 // ---------------------------------------------------------------------------
       
   116 //
       
   117 EXPORT_C TUid MPXTlsHelper::HostUid()
       
   118     {
       
   119     TUid hostUid( KNullUid );
       
   120 
       
   121     TMPXTlsStruct* tls =  reinterpret_cast<TMPXTlsStruct*>( Dll::Tls() );
       
   122     if ( tls )
       
   123         {
       
   124         hostUid = tls->iHostUid;
       
   125         }
       
   126 
       
   127     return hostUid;
       
   128     }
       
   129 
       
   130 // ---------------------------------------------------------------------------
       
   131 // Set 'need save' flag.
       
   132 // ---------------------------------------------------------------------------
       
   133 //
       
   134 EXPORT_C void MPXTlsHelper::SetNeedSave( TBool aNeedSave )
       
   135     {
       
   136     TMPXTlsStruct* tls =  reinterpret_cast<TMPXTlsStruct*>( Dll::Tls() );
       
   137     if ( tls )
       
   138         {
       
   139         tls->iNeedSave = aNeedSave;
       
   140         }
       
   141     }
       
   142 
       
   143 // ---------------------------------------------------------------------------
       
   144 // Get 'need save' flag.
       
   145 // ---------------------------------------------------------------------------
       
   146 //
       
   147 EXPORT_C TBool MPXTlsHelper::NeedSave()
       
   148     {
       
   149     TBool needSave( EFalse );
       
   150 
       
   151     TMPXTlsStruct* tls =  reinterpret_cast<TMPXTlsStruct*>( Dll::Tls() );
       
   152     if ( tls )
       
   153         {
       
   154         needSave = tls->iNeedSave;
       
   155         }
       
   156 
       
   157     return needSave;
       
   158     }
       
   159 
       
   160 // ---------------------------------------------------------------------------
       
   161 // Sets Allow Move flag.
       
   162 // ---------------------------------------------------------------------------
       
   163 //
       
   164 EXPORT_C void MPXTlsHelper::SetAllowMove( TBool aAllowMove )
       
   165     {
       
   166     TMPXTlsStruct* tls =  reinterpret_cast<TMPXTlsStruct*>( Dll::Tls() );
       
   167     if ( tls )
       
   168         {
       
   169         tls->iAllowMove = aAllowMove;
       
   170         }
       
   171     }
       
   172 
       
   173 // ---------------------------------------------------------------------------
       
   174 // Gets Allow Move flag.
       
   175 // ---------------------------------------------------------------------------
       
   176 //
       
   177 EXPORT_C TBool MPXTlsHelper::AllowMove()
       
   178     {
       
   179     TBool allowMove( EFalse );
       
   180 
       
   181     TMPXTlsStruct* tls =  reinterpret_cast<TMPXTlsStruct*>( Dll::Tls() );
       
   182     if ( tls )
       
   183         {
       
   184         allowMove = tls->iAllowMove;
       
   185         }
       
   186 
       
   187     return allowMove;
       
   188     }
       
   189 
       
   190 // ---------------------------------------------------------------------------
       
   191 // Set launch mode.
       
   192 // ---------------------------------------------------------------------------
       
   193 //
       
   194 EXPORT_C void MPXTlsHelper::SetLaunchModeL( TMPXLaunchMode aMode )
       
   195     {
       
   196     TMPXTlsStruct* tls =  reinterpret_cast<TMPXTlsStruct*>( Dll::Tls() );
       
   197     if ( tls )
       
   198         {
       
   199         tls->iLaunchMode = aMode;
       
   200         }
       
   201     else
       
   202         {
       
   203         User::Leave( KErrNotReady );
       
   204         }
       
   205     }
       
   206 
       
   207 // ---------------------------------------------------------------------------
       
   208 // Get launch mode.
       
   209 // ---------------------------------------------------------------------------
       
   210 //
       
   211 EXPORT_C TMPXLaunchMode MPXTlsHelper::LaunchMode()
       
   212     {
       
   213     TMPXLaunchMode mode( EMPXLaunchModeUnknown );
       
   214 
       
   215     TMPXTlsStruct* tls =  reinterpret_cast<TMPXTlsStruct*>( Dll::Tls() );
       
   216     if ( tls )
       
   217         {
       
   218         mode = tls->iLaunchMode;
       
   219         }
       
   220 
       
   221     return mode;
       
   222     }
       
   223 
       
   224 //  End of File