telephonyserverplugins/common_tsy/phonetsy/src/cmmphonefactorytsy.cpp
branchRCL_3
changeset 65 630d2f34d719
parent 15 fc69e1e37771
child 66 07a122eea281
equal deleted inserted replaced
61:17af172ffa5f 65:630d2f34d719
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2006-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
    14 // INCLUDE FILES
    14 // INCLUDE FILES
    15 //
    15 //
    16 
    16 
    17 
    17 
    18 
    18 
       
    19 #include "OstTraceDefinitions.h"
       
    20 #ifdef OST_TRACE_COMPILER_IN_USE
       
    21 #include "cmmphonefactorytsyTraces.h"
       
    22 #endif
    19 #include <featmgr/featurecontrol.h>
    23 #include <featmgr/featurecontrol.h>
    20 #include <featureuids.h>
    24 #include <featureuids.h>
    21 
    25 
       
    26 #include <ctsy/mmtsy_names.h>
       
    27 #include <ctsy/serviceapi/ctsysatmessagingbase.h>
       
    28 
       
    29 #include "cmmmessagemanagerbase.h"
    22 #include "cmmphonefactorytsy.h"
    30 #include "cmmphonefactorytsy.h"
    23 #include "cmmphonetsy.h"
    31 #include "cmmphonetsy.h"
    24 #include <ctsy/mmtsy_names.h>
       
    25 #include "MmTsy_conf.h"
    32 #include "MmTsy_conf.h"
    26 #include "cmmmessagemanagerbase.h"
    33 
    27 #include <ctsy/serviceapi/ctsysatmessagingbase.h>
    34 _LIT(KLtsyIniFile, "ltsydata.ini");
    28 
    35 
    29 #ifdef USING_CTSY_DISPATCHER
    36 #ifdef USING_CTSY_DISPATCHER
    30 _LIT(KLicenseeTsyDllName, "licenseetsy.dll");
    37 _LIT(KDefaultLicenseeTsyDllName, "ctsydispatcher.dll");
    31 _LIT(KCtsyDispatcherDllName, "ctsydispatcher.dll");
    38 const TInt KDefaultLicenseeTsyUID3 =  0x10285C38;
    32 
    39 #else
    33 const TInt KLicenseeTsyUID3 = 0x2000BEE4;
    40 _LIT(KDefaultLicenseeTsyDllName, "licenseetsy.dll");
    34 const TInt KCtsyDispatcherUID3 =  0x10285C38;
    41 const TInt KDefaultLicenseeTsyUID3 = 0x2000BEE4;
       
    42 #endif //USING_CTSY_DISPATCHER
    35 
    43 
    36 typedef MLtsyFactoryBase*(*TFactoryBaseNewL)();
    44 typedef MLtsyFactoryBase*(*TFactoryBaseNewL)();
    37 
    45 
    38 #endif //USING_CTSY_DISPATCHER
       
    39 // ======== MEMBER FUNCTIONS ========
    46 // ======== MEMBER FUNCTIONS ========
    40 
    47 
    41 CMmPhoneFactoryTsy::CMmPhoneFactoryTsy()
    48 CMmPhoneFactoryTsy::CMmPhoneFactoryTsy()
    42     {
    49     {
    43     // Version numbers defined in ETEL.h
    50     // Version numbers defined in ETEL.h
    60     {
    67     {
    61     }
    68     }
    62 
    69 
    63 CMmPhoneFactoryTsy::~CMmPhoneFactoryTsy()
    70 CMmPhoneFactoryTsy::~CMmPhoneFactoryTsy()
    64     {
    71     {
    65 #ifdef USING_CTSY_DISPATCHER
       
    66     iLoadedLib.Close();
    72     iLoadedLib.Close();
    67 #endif //USING_CTSY_DISPATCHER
    73     }
    68 	}
       
    69 
    74 
    70 // ---------------------------------------------------------------------------
    75 // ---------------------------------------------------------------------------
    71 // CMmPhoneFactoryTsy::NewPhoneL
    76 // CMmPhoneFactoryTsy::NewPhoneL
    72 // Creates a new phone object instance
    77 // Creates a new phone object instance
    73 // (other items were commented in a header).
    78 // (other items were commented in a header).
    74 // ---------------------------------------------------------------------------
    79 // ---------------------------------------------------------------------------
    75 //
    80 //
    76 CPhoneBase* CMmPhoneFactoryTsy::NewPhoneL( const TDesC& aName )
    81 CPhoneBase* CMmPhoneFactoryTsy::NewPhoneL( const TDesC& aName )
    77     {
    82     {
    78 TFLOGSTRING("TSY: CMmPhoneFactoryTsy::NewL - NEW LOG");
    83 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CMMPHONEFACTORYTSY_NEWPHONEL_1, "TSY: CMmPhoneFactoryTsy::NewL - NEW LOG");
    79 
    84 
    80     iPhoneTsy = NULL;
    85     iPhoneTsy = NULL;
    81 
    86 
    82     // In case of debug build, print flag info.
    87     // In case of debug build, print flag info.
    83 #ifdef TF_LOGGING_ENABLED
    88 #ifdef TF_LOGGING_ENABLED
    84     
    89     
    85 	RFeatureControl featureControl;
    90     RFeatureControl featureControl;
    86 	TInt err = featureControl.Open();
    91     TInt err = featureControl.Open();
    87 	if (err != KErrNone)
    92     if (err != KErrNone)
    88 		{
    93         {
    89 TFLOGSTRING("CMmPhoneFactoryTsy::NewPhoneL - failed to connect to FeatMgr");
    94 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CMMPHONEFACTORYTSY_NEWPHONEL_2, "CMmPhoneFactoryTsy::NewPhoneL - failed to connect to FeatMgr");
    90 		}
    95         }
    91 	else if (featureControl.FeatureSupported(NFeature::KCsVideoTelephony) == KFeatureSupported) 
    96     else if (featureControl.FeatureSupported(NFeature::KCsVideoTelephony) == KFeatureSupported) 
    92         {
    97         {
    93 TFLOGSTRING("TSY: __CS_VIDEO_TELEPHONY -flag is on");
    98 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CMMPHONEFACTORYTSY_NEWPHONEL_3, "TSY: __CS_VIDEO_TELEPHONY -flag is on");
    94         }
    99         }
    95 	else if (featureControl.FeatureSupported(NFeature::KEmergencyCallsEnabledInOfflineMode) == KFeatureSupported)
   100     else if (featureControl.FeatureSupported(NFeature::KEmergencyCallsEnabledInOfflineMode) == KFeatureSupported)
    96         {
   101         {
    97 TFLOGSTRING("TSY: __COMMON_TSY__EMERGENCY_CALLS_ENABLED_IN_OFFLINE_MODE -flag is on");
   102 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CMMPHONEFACTORYTSY_NEWPHONEL_4, "TSY: __COMMON_TSY__EMERGENCY_CALLS_ENABLED_IN_OFFLINE_MODE -flag is on");
    98         }
   103         }
    99 
   104 
   100 	featureControl.Close();
   105     featureControl.Close();
   101 #endif
   106 #endif
   102 	
   107     
   103     // Check if the Phone Name is OK
   108     // Check if the Phone Name is OK
   104     if ( KErrNone == aName.CompareF( KMmTsyPhoneName ) )
   109     if ( KErrNone == aName.CompareF( KMmTsyPhoneName ) )
   105         {
   110         {
   106         iMessageRouter = NULL;
   111         iMessageRouter = NULL;
   107 
   112                 
   108         // Create Message Manager (the 'core' of the LTSY Plug-in API)
   113         // Dynamic loading of LTSY
   109         CMmMessageManagerBase* messageManager = CMmMessageManagerBase::NewL();
   114         iLtsyFactory = LoadLibraryL();
   110         if ( messageManager )
       
   111             {
       
   112 	        CleanupStack::PushL( messageManager );
       
   113         
       
   114             // LTSY Plug-in API successfully created
       
   115 TFLOGSTRING("TSY: CMmPhoneFactoryTsy::NewL - Starting to open LicenceeTSY");
       
   116             
       
   117             // get TSY message manager callback object
       
   118             MmMessageManagerCallback* callBack = 
       
   119                 messageManager->GetMessageManagerCallback();
       
   120             
       
   121 #ifdef USING_CTSY_DISPATCHER
       
   122             iLtsyFactory = LoadLibraryL();
       
   123 #else
       
   124             // library entry for LTSY, get base factory object
       
   125             iLtsyFactory = LTsyFactoryL();
       
   126             
       
   127 #endif //USING_CTSY_DISPATCHER
       
   128 
       
   129             if( iLtsyFactory )
       
   130                 {
       
   131                 // Get message router from LTSY. All current interface versions
       
   132                 // have the same GetMessageRouter defined in version 1.
       
   133                 MLtsyFactoryV1* ptr_v1 = 
       
   134                 	static_cast<MLtsyFactoryV1*>( iLtsyFactory );
       
   135                         
       
   136                 iMessageRouter = ptr_v1->GetMessageRouter( *callBack );
       
   137 		        User::LeaveIfNull( iMessageRouter );
       
   138         
       
   139 		        // Licencee Tsy successfully created
       
   140 TFLOGSTRING("TSY: CMmPhoneFactoryTsy::NewL -  LicenceeTSY successfully opened");
       
   141 
       
   142 	            // set the pointer to the message router object
       
   143 	            messageManager->SetMessageRouter( iMessageRouter );
       
   144 
       
   145 	            // Ownership of messageManager passed to iPhoneTsy.
       
   146                 CleanupStack::Pop( messageManager );
       
   147 	            // Create Phone Tsy (which creates the whole Common TSY)
       
   148 TFLOGSTRING("TSY: CMmPhoneFactoryTsy::NewL - Starting to open CommonTSY");
       
   149 	            iPhoneTsy = CMmPhoneTsy::NewL( 
       
   150 	                messageManager, this, iLtsyFactory );
       
   151 
       
   152 	            if ( iPhoneTsy )
       
   153 	                {
       
   154 TFLOGSTRING("TSY: CMmPhoneFactoryTsy::NewL - CommonTSY successfully opened");
       
   155 	                messageManager->SetPhoneTsy( iPhoneTsy );
       
   156 	                }
       
   157                 }
       
   158             else
       
   159             	{
       
   160     	        CleanupStack::PopAndDestroy( messageManager );
       
   161             	}
       
   162             }
       
   163         }
   115         }
   164 
   116 
   165     return iPhoneTsy;
   117     return iPhoneTsy;
   166     }
   118     }
   167 
   119 
   285     {
   237     {
   286     CTsySatMessagingBase* satMessaging = NULL;
   238     CTsySatMessagingBase* satMessaging = NULL;
   287     
   239     
   288     if ( KErrNone == aName.CompareF( KSatToolkit ) )
   240     if ( KErrNone == aName.CompareF( KSatToolkit ) )
   289         {
   241         {
   290 TFLOGSTRING("TSY: CMmPhoneFactoryTsy::NewSimAtk - Starting to open SimAtkTSY");
   242 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CMMPHONEFACTORYTSY_NEWSIMATK_1, "TSY: CMmPhoneFactoryTsy::NewSimAtk - Starting to open SimAtkTSY");
   291 
   243        
   292         if( iLtsyFactory )
   244         if (iLtsyFactory == NULL)
       
   245             {
       
   246             TRAP_IGNORE(iLtsyFactory = LoadLibraryL());
       
   247             }
       
   248         
       
   249         if (iLtsyFactory != NULL)
   293             {
   250             {
   294             // Get SIM ATK TSY messaging service from LicenseeTsy
   251             // Get SIM ATK TSY messaging service from LicenseeTsy
   295             MLtsyFactoryV1* ptr_v1 = 
   252             MLtsyFactoryV1* ptr_v1 = static_cast<MLtsyFactoryV1*>( iLtsyFactory );
   296             	static_cast<MLtsyFactoryV1*>( iLtsyFactory );
       
   297      
   253      
   298 #ifdef USING_CTSY_DISPATCHER     	
   254 #ifdef USING_CTSY_DISPATCHER        
   299            	satMessaging = ptr_v1->GetSatMessagingService( 
   255             satMessaging = ptr_v1->GetSatMessagingService(iPhoneTsy->SmsService());
   300             	iPhoneTsy->SmsService() );
       
   301 #else
   256 #else
   302            	satMessaging = ptr_v1->GetSatMessagingService( );
   257             satMessaging = ptr_v1->GetSatMessagingService( );
   303 #endif
   258 #endif
   304             }
   259             }        
   305         }
   260         }
   306 
   261 
   307     return satMessaging;
   262     return satMessaging;
   308     }
   263     }
   309 
   264 
   327 // Returns: CPhoneFactoryBase*: Pointer to CMmPhoneFactoryTsy class
   282 // Returns: CPhoneFactoryBase*: Pointer to CMmPhoneFactoryTsy class
   328 // ---------------------------------------------------------------------------
   283 // ---------------------------------------------------------------------------
   329 //
   284 //
   330 EXPORT_C CPhoneFactoryBase* LibEntry()
   285 EXPORT_C CPhoneFactoryBase* LibEntry()
   331     {
   286     {
   332 TFLOGSTRING("TSY: CPhoneFactoryBase::LibEntry()...");
   287 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, LIBENTRY_1, "TSY: CPhoneFactoryBase::LibEntry()...");
   333     // return NULL if instantiation fails
   288     // return NULL if instantiation fails
   334     CMmPhoneFactoryTsy* factory(NULL);
   289     CMmPhoneFactoryTsy* factory(NULL);
   335     TRAP_IGNORE(factory = CMmPhoneFactoryTsy::NewL()); 
   290     TRAP_IGNORE(factory = CMmPhoneFactoryTsy::NewL()); 
   336     return factory; 
   291     return factory; 
   337     }
   292     }
   338 
   293 
   339 #ifdef USING_CTSY_DISPATCHER
   294 #ifdef USING_CTSY_DISPATCHER
   340 TBool CMmPhoneFactoryTsy::UsingCtsyDispatcher()
   295 TBool CMmPhoneFactoryTsy::UsingCtsyDispatcher()
   341 	{
   296 /**
   342 	//function to determine whether the setup is using the CTSY Dispatcher layer.
   297  * Function to determine whether the setup is using the CTSY Dispatcher layer.
       
   298  */
       
   299     {
       
   300     return ETrue; 
       
   301     }
       
   302 #endif //USING_CTSY_DISPATCHER
       
   303 
       
   304 // ---------------------------------------------------------------------------
       
   305 // CMmPhoneFactoryTsy::LoadLibraryL
       
   306 // Dynamically loads a LTSY.
       
   307 // ---------------------------------------------------------------------------
       
   308 //
       
   309 MLtsyFactoryBase* CMmPhoneFactoryTsy::LoadLibraryL()
       
   310     {
       
   311     TPtrC ltsyDllName(0, NULL);
       
   312     TUint ltsyDllUid = 0;
       
   313     
   343 #ifdef USING_CTSY_DISPATCHER 
   314 #ifdef USING_CTSY_DISPATCHER 
   344 	return ETrue; 
   315     ltsyDllName.Set(KDefaultLicenseeTsyDllName);
       
   316     ltsyDllUid = KDefaultLicenseeTsyUID3; 
   345 #else
   317 #else
   346 	return EFalse;
   318     RBuf configData;
       
   319     CleanupClosePushL(configData);
       
   320     
       
   321     TRAPD(ret,
       
   322           {
       
   323           ReadConfigFileL(&configData);
       
   324           ltsyDllName.Set(ReadDllNameFromConfigL(configData));
       
   325           ltsyDllUid = ReadDllUidFromConfigL(configData);
       
   326           });
       
   327     
       
   328     if (ret != KErrNone)
       
   329         {
       
   330         ltsyDllName.Set(KDefaultLicenseeTsyDllName);
       
   331         ltsyDllUid = KDefaultLicenseeTsyUID3;
       
   332 OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_ERROR, CMMPHONEFACTORYTSY_LOADLIBRARYL_1A, "TSY: Failed to load LTSY dll details from ini (error: %d), using defaults", ret);
       
   333         }
   347 #endif
   334 #endif
   348 	}
   335     
   349 
   336 OstTraceDefExt2(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CMMPHONEFACTORYTSY_LOADLIBRARYL_1, "TSY: CMmPhoneFactoryTsy::LoadLibraryL - Loading Dll=%S, UID3=0x%8X", ltsyDllName, ltsyDllUid);
   350 MLtsyFactoryBase* CMmPhoneFactoryTsy::LoadLibraryL()
   337     User::LeaveIfError(iLoadedLib.Load(ltsyDllName));
   351 	{
   338     
   352 	//load library.  This can either be LicenseeTsy or CtsyDispatcher dlls
   339 #ifndef USING_CTSY_DISPATCHER
   353 	TPtrC dllname;
   340     CleanupStack::PopAndDestroy();  // configData
   354 	TInt uid3_int;
   341 #endif
   355 	if(UsingCtsyDispatcher())
   342     
   356 		{
   343     // Check the Uid3 is as expected
   357 		dllname.Set(KCtsyDispatcherDllName);
   344     if (iLoadedLib.Type()[2] != TUid::Uid(ltsyDllUid))
   358 		uid3_int = KCtsyDispatcherUID3;
   345         {
   359 		}
   346         User::Leave(KErrBadLibraryEntryPoint);
   360 	else
   347         }
   361 		{
   348     
   362 		dllname.Set(KLicenseeTsyDllName);
   349     TFactoryBaseNewL libEntry = reinterpret_cast<TFactoryBaseNewL>(iLoadedLib.Lookup(1));   
   363 		uid3_int = KLicenseeTsyUID3;
   350     MLtsyFactoryBase* factory = (*libEntry)();    // libEntry may leave.
   364 		}
   351     User::LeaveIfNull(factory);
   365 	
   352     
   366 	TFLOGSTRING3("TSY: CMmPhoneFactoryTsy::LoadLibraryL - Loading Dll=%S, UID3=0x%x", &dllname, uid3_int);
   353     InitCtsyL(factory);
   367 	
   354     
   368 	TUidType uid(KNullUid, KNullUid, TUid::Uid(uid3_int));
   355 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CMMPHONEFACTORYTSY_LOADLIBRARYL_2, "TSY: Loaded LTSY");
   369 	
   356     return factory;
   370 	User::LeaveIfError(iLoadedLib.Load(dllname));
   357     }
   371 	
   358 
   372 	// Check the Uid3 is as expected
   359 void CMmPhoneFactoryTsy::InitCtsyL(MLtsyFactoryBase* aLtsyFactory)
   373 	if(iLoadedLib.Type()[2]!=TUid::Uid(uid3_int))
   360 /**
   374 		User::Leave(KErrBadLibraryEntryPoint);
   361  * Initialises iPhoneTsy
   375 	
   362  */
   376 	TFactoryBaseNewL libEntry=(TFactoryBaseNewL)iLoadedLib.Lookup(1);	
   363     {    
   377 	MLtsyFactoryBase* factory=(*libEntry)();	// libEntry may leave.
   364     if (iPhoneTsy != NULL)
   378 	
   365         {
   379 	return factory;
   366         return;
   380 	}
   367         }
   381 #endif //USING_CTSY_DISPATCHER
   368     
   382 
   369     // Create Message Manager (the 'core' of the LTSY Plug-in API)
   383 //  End of File
   370     CMmMessageManagerBase* messageManager = CMmMessageManagerBase::NewL();
   384 
   371     User::LeaveIfNull(messageManager);
   385 
   372     CleanupStack::PushL( messageManager );
       
   373 
       
   374     // get TSY message manager callback object
       
   375     MmMessageManagerCallback* callBack = 
       
   376         messageManager->GetMessageManagerCallback();
       
   377 
       
   378     // Get message router from LTSY. All current interface versions
       
   379     // have the same GetMessageRouter defined in version 1.
       
   380     MLtsyFactoryV1* ptr_v1 = 
       
   381          static_cast<MLtsyFactoryV1*>( aLtsyFactory );
       
   382              
       
   383     iMessageRouter = ptr_v1->GetMessageRouter( *callBack );
       
   384     User::LeaveIfNull( iMessageRouter );
       
   385     
       
   386     // set the pointer to the message router object
       
   387     messageManager->SetMessageRouter( iMessageRouter );
       
   388 
       
   389     // Ownership of messageManager to be passed to iPhoneTsy.
       
   390     CleanupStack::Pop( messageManager );
       
   391     
       
   392     // LTSY Plug-in API successfully created
       
   393 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CMMPHONEFACTORYTSY_INITLTSYL_1, "TSY: CMmPhoneFactoryTsy::NewL - Starting to open CommonTSY");
       
   394     // Create Phone Tsy (which creates the whole Common TSY)
       
   395     iPhoneTsy = CMmPhoneTsy::NewL(messageManager, this, aLtsyFactory);
       
   396 
       
   397     if (iPhoneTsy != NULL)
       
   398         {
       
   399         // Licencee Tsy successfully created
       
   400 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_NORMAL, CMMPHONEFACTORYTSY_INITLTSYL_2, "TSY: CMmPhoneFactoryTsy::NewL -  CommonTSY successfully opened");
       
   401         messageManager->SetPhoneTsy( iPhoneTsy );
       
   402         }
       
   403     else
       
   404         {
       
   405 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_WARNING, CMMPHONEFACTORYTSY_INITLTSYL_3, "TSY: CMmPhoneFactoryTsy::NewL - CommonTSY not opened");
       
   406         }
       
   407     }
       
   408 
       
   409 TPtrC CMmPhoneFactoryTsy::ReadDllNameFromConfigL(const TDesC& aConfigData)
       
   410     {
       
   411     _LIT(KLicenseeTsyDllKeyName, "LicenseeTsyDllName");
       
   412     TPtrC dllName = GetValueForKeyL(aConfigData, KLicenseeTsyDllKeyName);
       
   413 OstTraceDefExt1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CMMPHONEFACTORYTSY_READDLLNAMEFROMCONFIGL_1, "TSY: Config file: LTSY DLL name = %S", dllName);
       
   414     return dllName;
       
   415     }
       
   416 
       
   417 TUint CMmPhoneFactoryTsy::ReadDllUidFromConfigL(const TDesC& aConfigData)
       
   418     {
       
   419     _LIT(KLicenseeTsyUid3, "LicenseeTsyUid3");
       
   420 
       
   421     const TDesC& rawUid = GetValueForKeyL(aConfigData, KLicenseeTsyUid3);
       
   422     // only take the right 8 characters (ie discard the "0x")
       
   423     ASSERT(rawUid.Length() >= 8);
       
   424     TLex lex(rawUid.Right(8));   
       
   425     TUint uid;
       
   426     User::LeaveIfError(lex.Val(uid, EHex));
       
   427 OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CMMPHONEFACTORYTSY_READUIDFROMCONFIGL_1, "TSY: Config file: LTSY UID3 = 0x%x", uid);
       
   428     return uid;
       
   429     }
       
   430 
       
   431 /*static*/
       
   432 void CMmPhoneFactoryTsy::ReadConfigFileL(RBuf* aConfigData)
       
   433 /**
       
   434  * Reads config file from system drive or, if not present, from ROM
       
   435  *
       
   436  * @param aConfigData This buffer gets created and has the ini file contents loaded into it
       
   437  */
       
   438     {
       
   439     RFs fs;
       
   440     User::LeaveIfError(fs.Connect());
       
   441     CleanupClosePushL(fs);
       
   442 
       
   443 OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CMMPHONEFACTORYTSY_READCONFIGFILE_1, "TSY: Trying to load from %d (C) drive", fs.GetSystemDrive());
       
   444     fs.SetSessionToPrivate(fs.GetSystemDrive());
       
   445 
       
   446     RFile configFile;
       
   447     TInt ret = configFile.Open(fs, KLtsyIniFile, EFileShareExclusive);
       
   448     if (ret == KErrNotFound)
       
   449         {
       
   450 OstTraceDefExt2(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CMMPHONEFACTORYTSY_READCONFIGFILE_2, "TSY: Trying to load ini from %d (Z) drive, as read for system drive returned error %d", EDriveZ, ret);
       
   451         User::LeaveIfError(fs.SetSessionToPrivate(EDriveZ));
       
   452         User::LeaveIfError(configFile.Open(fs, KLtsyIniFile, EFileShareExclusive));
       
   453         }
       
   454 
       
   455 OstTraceDefExt1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CMMPHONEFACTORYTSY_READCONFIGFILE_3, "TSY: Reading ini file %S", KLtsyIniFile);
       
   456     
       
   457     CleanupClosePushL(configFile);
       
   458 
       
   459     TInt configFileSize;
       
   460     User::LeaveIfError(configFile.Size(configFileSize));
       
   461 
       
   462     RBuf8 fileBuf;
       
   463     User::LeaveIfError(fileBuf.Create(configFileSize));
       
   464     CleanupClosePushL(fileBuf);
       
   465     User::LeaveIfError(configFile.Read(fileBuf));
       
   466 
       
   467     aConfigData->CreateL(configFileSize);
       
   468     aConfigData->Copy(fileBuf);
       
   469 
       
   470     CleanupStack::PopAndDestroy(3, &fs); // fs, configFile, fileBuf
       
   471     }
       
   472 
       
   473 /*static*/
       
   474 TPtrC CMmPhoneFactoryTsy::GetValueForKeyL(const TDesC& aKeysValues, const TDesC& aKey)
       
   475 /**
       
   476  * Gets the value for a specified key. The expected format is
       
   477  * <pre>
       
   478  * key1 value1
       
   479  * key2 value2
       
   480  * </pre>
       
   481  * 
       
   482  * However the parsing is flexible enough to allow "key1 =value1" as it allows an equals separator and extra whitespace
       
   483  * The value cannot include whitespace, even if quoted.
       
   484  */
       
   485     {
       
   486     // this matches the bracket expression in this regexp: \w+\s*=?\s*(\w+)[\s$]
       
   487     TInt startOfKey = aKeysValues.Find(aKey);
       
   488     TLex valueExtractor(aKeysValues);
       
   489     valueExtractor.Inc(startOfKey + aKey.Length());
       
   490     valueExtractor.SkipSpaceAndMark();
       
   491     // allow equals separating key and value
       
   492     if (valueExtractor.Peek() == '=')
       
   493         {
       
   494         valueExtractor.Inc();
       
   495         valueExtractor.SkipSpaceAndMark();
       
   496         }
       
   497     
       
   498     TPtrC value = valueExtractor.NextToken();
       
   499     __ASSERT_ALWAYS(value.Length() > 0, User::Leave(KErrCorrupt));
       
   500     return value;
       
   501     }