realtimenetprots/sipfw/SIP/Codec/src/SIPStrings.cpp
changeset 0 307788aac0a8
equal deleted inserted replaced
-1:000000000000 0:307788aac0a8
       
     1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Name          : SIPStrings.cpp
       
    15 // Part of       : SIP Codec
       
    16 // Version       : SIP/4.0 
       
    17 //
       
    18 
       
    19 
       
    20 
       
    21 #include "sipstrings.h"
       
    22 #include "CSIPCodecTlsPtrs.h"
       
    23 #include "CSIPStrings.h"
       
    24 #include "sipstrconsts.h"
       
    25 #include "_sipcodecdefs.h"
       
    26 
       
    27 
       
    28 // -----------------------------------------------------------------------------
       
    29 // SIPStrings::OpenL
       
    30 // Opens stringpool owner, leaves if one already exists in TLS
       
    31 // -----------------------------------------------------------------------------
       
    32 //
       
    33 EXPORT_C void SIPStrings::OpenL()
       
    34 	{
       
    35 	CSIPCodecTlsPtrs* tlsPtrs = static_cast<CSIPCodecTlsPtrs*>( Dll::Tls() );
       
    36 	if( !tlsPtrs )
       
    37 		{
       
    38 		CSIPStrings* strings = CSIPStrings::NewL();
       
    39         CleanupStack::PushL( strings );
       
    40 		tlsPtrs = new(ELeave)CSIPCodecTlsPtrs( strings );
       
    41 		CleanupStack::Pop( strings );
       
    42 		CleanupStack::PushL( tlsPtrs );
       
    43 		User::LeaveIfError( Dll::SetTls( tlsPtrs ) );
       
    44 		CleanupStack::Pop( tlsPtrs );
       
    45 		}
       
    46 	else
       
    47 		{
       
    48 		CSIPStrings* strings = tlsPtrs->iStrings;
       
    49 		// SIPHeaderLookup cannot have created the tls, 
       
    50 		// since SIPHeaderLookup is depended on SIPStrings		
       
    51 		__ASSERT_ALWAYS( strings, 
       
    52 		                User::Panic( KNullDesC, KErrAlreadyExists ));
       
    53 		strings->IncrementUsageCount();
       
    54 		}
       
    55 	}
       
    56 
       
    57 // -----------------------------------------------------------------------------
       
    58 // SIPStrings::Close
       
    59 // Closes & deletes string pool
       
    60 // -----------------------------------------------------------------------------
       
    61 //
       
    62 EXPORT_C void SIPStrings::Close()
       
    63 	{
       
    64 	CSIPCodecTlsPtrs* tlsPtrs = static_cast<CSIPCodecTlsPtrs*>( Dll::Tls() );
       
    65 	if ( !tlsPtrs )
       
    66         {
       
    67         return;
       
    68         }
       
    69     CSIPStrings* strings = tlsPtrs->iStrings;
       
    70     // SIPStrings must be always Closed after SIPHeaderLookup,
       
    71     // since SIPHeaderLookup depends on SIPStrings
       
    72  	__ASSERT_ALWAYS( strings, User::Panic( KNullDesC, KErrNotFound ));
       
    73     strings->DecrementUsageCount();
       
    74     if ( strings->UsageCount() == 0 )
       
    75     	{ 
       
    76 		if ( !tlsPtrs->iHeaderLookup )
       
    77 			{
       
    78 			delete tlsPtrs;
       
    79 			Dll::FreeTls();
       
    80 			}
       
    81 		else
       
    82 			{
       
    83 			tlsPtrs->DestroyStrings();
       
    84 			}
       
    85     	}
       
    86 	}
       
    87 	
       
    88 // -----------------------------------------------------------------------------
       
    89 // SIPStrings::StringF
       
    90 // -----------------------------------------------------------------------------
       
    91 //
       
    92 EXPORT_C RStringF SIPStrings::StringF( TInt aIndex )
       
    93 	{
       
    94 	CSIPStrings* strings = Strings();	              	
       
    95 	return strings->Pool().StringF( aIndex, strings->Table() );
       
    96 	}
       
    97 
       
    98 // -----------------------------------------------------------------------------
       
    99 // SIPStrings::StringPool
       
   100 // Returns string pool
       
   101 // -----------------------------------------------------------------------------
       
   102 //
       
   103 EXPORT_C RStringPool SIPStrings::Pool()
       
   104     {
       
   105 	return Strings()->Pool();
       
   106     }
       
   107 
       
   108 // -----------------------------------------------------------------------------
       
   109 // SIPStrings::StringTableL
       
   110 // Returns string table
       
   111 // -----------------------------------------------------------------------------
       
   112 //
       
   113 EXPORT_C const TStringTable& SIPStrings::Table()
       
   114     {
       
   115 	return Strings()->Table();
       
   116     }
       
   117     
       
   118 // -----------------------------------------------------------------------------
       
   119 // SIPStrings::Strings
       
   120 // -----------------------------------------------------------------------------
       
   121 //    
       
   122 CSIPStrings* SIPStrings::Strings()
       
   123 	{
       
   124 	CSIPCodecTlsPtrs* tlsPtrs = static_cast<CSIPCodecTlsPtrs*>( Dll::Tls() );	
       
   125     __ASSERT_ALWAYS( tlsPtrs, User::Panic( KNullDesC, KErrNotReady ) );	
       
   126 	
       
   127     CSIPStrings* strings = tlsPtrs->iStrings;
       
   128     __ASSERT_ALWAYS( strings, User::Panic( KNullDesC, KErrNotReady ) );
       
   129     
       
   130     return strings;
       
   131 	}