telephonyserverplugins/common_tsy/phonetsy/src/cmmphonefactorytsy.cpp
branchopencode
changeset 32 58332560b319
parent 24 6638e7f4bd8f
equal deleted inserted replaced
24:6638e7f4bd8f 32:58332560b319
    12 //
    12 //
    13 // Description:
    13 // Description:
    14 // INCLUDE FILES
    14 // INCLUDE FILES
    15 //
    15 //
    16 
    16 
       
    17 
       
    18 
    17 #include <featmgr/featurecontrol.h>
    19 #include <featmgr/featurecontrol.h>
    18 #include <featureuids.h>
    20 #include <featureuids.h>
    19 
    21 
    20 #include <ctsy/mmtsy_names.h>
       
    21 #include <ctsy/serviceapi/ctsysatmessagingbase.h>
       
    22 
       
    23 #include "cmmmessagemanagerbase.h"
       
    24 #include "cmmphonefactorytsy.h"
    22 #include "cmmphonefactorytsy.h"
    25 #include "cmmphonetsy.h"
    23 #include "cmmphonetsy.h"
       
    24 #include <ctsy/mmtsy_names.h>
    26 #include "MmTsy_conf.h"
    25 #include "MmTsy_conf.h"
    27 
    26 #include "cmmmessagemanagerbase.h"
    28 _LIT(KLtsyIniFile, "ltsydata.ini");
    27 #include <ctsy/serviceapi/ctsysatmessagingbase.h>
    29 
    28 
    30 #ifdef USING_CTSY_DISPATCHER
    29 #ifdef USING_CTSY_DISPATCHER
    31 _LIT(KDefaultLicenseeTsyDllName, "ctsydispatcher.dll");
    30 _LIT(KLicenseeTsyDllName, "licenseetsy.dll");
    32 const TInt KDefaultLicenseeTsyUID3 =  0x10285C38;
    31 _LIT(KCtsyDispatcherDllName, "ctsydispatcher.dll");
    33 #else
    32 
    34 _LIT(KDefaultLicenseeTsyDllName, "licenseetsy.dll");
    33 const TInt KLicenseeTsyUID3 = 0x2000BEE4;
    35 const TInt KDefaultLicenseeTsyUID3 = 0x2000BEE4;
    34 const TInt KCtsyDispatcherUID3 =  0x10285C38;
       
    35 
       
    36 typedef MLtsyFactoryBase*(*TFactoryBaseNewL)();
       
    37 
    36 #endif //USING_CTSY_DISPATCHER
    38 #endif //USING_CTSY_DISPATCHER
    37 
       
    38 typedef MLtsyFactoryBase*(*TFactoryBaseNewL)();
       
    39 
       
    40 // ======== MEMBER FUNCTIONS ========
    39 // ======== MEMBER FUNCTIONS ========
    41 
    40 
    42 CMmPhoneFactoryTsy::CMmPhoneFactoryTsy()
    41 CMmPhoneFactoryTsy::CMmPhoneFactoryTsy()
    43     {
    42     {
    44     // Version numbers defined in ETEL.h
    43     // Version numbers defined in ETEL.h
    61     {
    60     {
    62     }
    61     }
    63 
    62 
    64 CMmPhoneFactoryTsy::~CMmPhoneFactoryTsy()
    63 CMmPhoneFactoryTsy::~CMmPhoneFactoryTsy()
    65     {
    64     {
       
    65 #ifdef USING_CTSY_DISPATCHER
    66     iLoadedLib.Close();
    66     iLoadedLib.Close();
    67     }
    67 #endif //USING_CTSY_DISPATCHER
       
    68 	}
    68 
    69 
    69 // ---------------------------------------------------------------------------
    70 // ---------------------------------------------------------------------------
    70 // CMmPhoneFactoryTsy::NewPhoneL
    71 // CMmPhoneFactoryTsy::NewPhoneL
    71 // Creates a new phone object instance
    72 // Creates a new phone object instance
    72 // (other items were commented in a header).
    73 // (other items were commented in a header).
    79     iPhoneTsy = NULL;
    80     iPhoneTsy = NULL;
    80 
    81 
    81     // In case of debug build, print flag info.
    82     // In case of debug build, print flag info.
    82 #ifdef TF_LOGGING_ENABLED
    83 #ifdef TF_LOGGING_ENABLED
    83     
    84     
    84     RFeatureControl featureControl;
    85 	RFeatureControl featureControl;
    85     TInt err = featureControl.Open();
    86 	TInt err = featureControl.Open();
    86     if (err != KErrNone)
    87 	if (err != KErrNone)
    87         {
    88 		{
    88 TFLOGSTRING("CMmPhoneFactoryTsy::NewPhoneL - failed to connect to FeatMgr");
    89 TFLOGSTRING("CMmPhoneFactoryTsy::NewPhoneL - failed to connect to FeatMgr");
    89         }
    90 		}
    90     else if (featureControl.FeatureSupported(NFeature::KCsVideoTelephony) == KFeatureSupported) 
    91 	else if (featureControl.FeatureSupported(NFeature::KCsVideoTelephony) == KFeatureSupported) 
    91         {
    92         {
    92 TFLOGSTRING("TSY: __CS_VIDEO_TELEPHONY -flag is on");
    93 TFLOGSTRING("TSY: __CS_VIDEO_TELEPHONY -flag is on");
    93         }
    94         }
    94     else if (featureControl.FeatureSupported(NFeature::KEmergencyCallsEnabledInOfflineMode) == KFeatureSupported)
    95 	else if (featureControl.FeatureSupported(NFeature::KEmergencyCallsEnabledInOfflineMode) == KFeatureSupported)
    95         {
    96         {
    96 TFLOGSTRING("TSY: __COMMON_TSY__EMERGENCY_CALLS_ENABLED_IN_OFFLINE_MODE -flag is on");
    97 TFLOGSTRING("TSY: __COMMON_TSY__EMERGENCY_CALLS_ENABLED_IN_OFFLINE_MODE -flag is on");
    97         }
    98         }
    98 
    99 
    99     featureControl.Close();
   100 	featureControl.Close();
   100 #endif
   101 #endif
   101     
   102 	
   102     // Check if the Phone Name is OK
   103     // Check if the Phone Name is OK
   103     if ( KErrNone == aName.CompareF( KMmTsyPhoneName ) )
   104     if ( KErrNone == aName.CompareF( KMmTsyPhoneName ) )
   104         {
   105         {
   105         iMessageRouter = NULL;
   106         iMessageRouter = NULL;
   106 
   107 
   107         // Create Message Manager (the 'core' of the LTSY Plug-in API)
   108         // Create Message Manager (the 'core' of the LTSY Plug-in API)
   108         CMmMessageManagerBase* messageManager = CMmMessageManagerBase::NewL();
   109         CMmMessageManagerBase* messageManager = CMmMessageManagerBase::NewL();
   109         User::LeaveIfNull(messageManager);
   110         if ( messageManager )
   110         CleanupStack::PushL( messageManager );
   111             {
       
   112 	        CleanupStack::PushL( messageManager );
   111         
   113         
   112         // LTSY Plug-in API successfully created
   114             // LTSY Plug-in API successfully created
   113 TFLOGSTRING("TSY: CMmPhoneFactoryTsy::NewL - Starting to open LicenceeTSY");
   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 );
   114         
   138         
   115         // get TSY message manager callback object
   139 		        // Licencee Tsy successfully created
   116         MmMessageManagerCallback* callBack = 
       
   117             messageManager->GetMessageManagerCallback();
       
   118         
       
   119         // Dynamic loading of LTSY
       
   120         MLtsyFactoryBase* ltsyFactory = LoadLibraryL();
       
   121         
       
   122         // Get message router from LTSY. All current interface versions
       
   123         // have the same GetMessageRouter defined in version 1.
       
   124         MLtsyFactoryV1* ptr_v1 = 
       
   125             static_cast<MLtsyFactoryV1*>( ltsyFactory );
       
   126                 
       
   127         iMessageRouter = ptr_v1->GetMessageRouter( *callBack );
       
   128         User::LeaveIfNull( iMessageRouter );
       
   129 
       
   130         // Licencee Tsy successfully created
       
   131 TFLOGSTRING("TSY: CMmPhoneFactoryTsy::NewL -  LicenceeTSY successfully opened");
   140 TFLOGSTRING("TSY: CMmPhoneFactoryTsy::NewL -  LicenceeTSY successfully opened");
   132 
   141 
   133         // set the pointer to the message router object
   142 	            // set the pointer to the message router object
   134         messageManager->SetMessageRouter( iMessageRouter );
   143 	            messageManager->SetMessageRouter( iMessageRouter );
   135 
   144 
   136         // Ownership of messageManager to be passed to iPhoneTsy.
   145 	            // Ownership of messageManager passed to iPhoneTsy.
   137         CleanupStack::Pop( messageManager );
   146                 CleanupStack::Pop( messageManager );
   138         
   147 	            // Create Phone Tsy (which creates the whole Common TSY)
   139         // Create Phone Tsy (which creates the whole Common TSY)
       
   140 TFLOGSTRING("TSY: CMmPhoneFactoryTsy::NewL - Starting to open CommonTSY");
   148 TFLOGSTRING("TSY: CMmPhoneFactoryTsy::NewL - Starting to open CommonTSY");
   141         iPhoneTsy = CMmPhoneTsy::NewL(messageManager, this, ltsyFactory);
   149 	            iPhoneTsy = CMmPhoneTsy::NewL( 
   142 
   150 	                messageManager, this, iLtsyFactory );
   143         if ( iPhoneTsy )
   151 
   144             {
   152 	            if ( iPhoneTsy )
       
   153 	                {
   145 TFLOGSTRING("TSY: CMmPhoneFactoryTsy::NewL - CommonTSY successfully opened");
   154 TFLOGSTRING("TSY: CMmPhoneFactoryTsy::NewL - CommonTSY successfully opened");
   146             messageManager->SetPhoneTsy( iPhoneTsy );
   155 	                messageManager->SetPhoneTsy( iPhoneTsy );
   147             }
   156 	                }
   148         else
   157                 }
   149             {
   158             else
   150 TFLOGSTRING("TSY: CMmPhoneFactoryTsy::NewL - CommonTSY not opened");
   159             	{
       
   160     	        CleanupStack::PopAndDestroy( messageManager );
       
   161             	}
   151             }
   162             }
   152         }
   163         }
   153 
   164 
   154     return iPhoneTsy;
   165     return iPhoneTsy;
   155     }
   166     }
   276     
   287     
   277     if ( KErrNone == aName.CompareF( KSatToolkit ) )
   288     if ( KErrNone == aName.CompareF( KSatToolkit ) )
   278         {
   289         {
   279 TFLOGSTRING("TSY: CMmPhoneFactoryTsy::NewSimAtk - Starting to open SimAtkTSY");
   290 TFLOGSTRING("TSY: CMmPhoneFactoryTsy::NewSimAtk - Starting to open SimAtkTSY");
   280 
   291 
   281         // Dynamic loading of LTSY
   292         if( iLtsyFactory )
   282         MLtsyFactoryBase* ltsyFactory = NULL;
       
   283         TRAPD(ret, ltsyFactory = LoadLibraryL());
       
   284         if (ret == KErrNone)
       
   285             {
   293             {
   286             // Get SIM ATK TSY messaging service from LicenseeTsy
   294             // Get SIM ATK TSY messaging service from LicenseeTsy
   287             MLtsyFactoryV1* ptr_v1 = static_cast<MLtsyFactoryV1*>( ltsyFactory );
   295             MLtsyFactoryV1* ptr_v1 = 
       
   296             	static_cast<MLtsyFactoryV1*>( iLtsyFactory );
   288      
   297      
   289 #ifdef USING_CTSY_DISPATCHER        
   298 #ifdef USING_CTSY_DISPATCHER     	
   290             satMessaging = ptr_v1->GetSatMessagingService(iPhoneTsy->SmsService());
   299            	satMessaging = ptr_v1->GetSatMessagingService( 
       
   300             	iPhoneTsy->SmsService() );
   291 #else
   301 #else
   292             satMessaging = ptr_v1->GetSatMessagingService( );
   302            	satMessaging = ptr_v1->GetSatMessagingService( );
   293 #endif
   303 #endif
   294             }        
   304             }
   295         }
   305         }
   296 
   306 
   297     return satMessaging;
   307     return satMessaging;
   298     }
   308     }
   299 
   309 
   326     return factory; 
   336     return factory; 
   327     }
   337     }
   328 
   338 
   329 #ifdef USING_CTSY_DISPATCHER
   339 #ifdef USING_CTSY_DISPATCHER
   330 TBool CMmPhoneFactoryTsy::UsingCtsyDispatcher()
   340 TBool CMmPhoneFactoryTsy::UsingCtsyDispatcher()
   331     {
   341 	{
   332     //function to determine whether the setup is using the CTSY Dispatcher layer.
   342 	//function to determine whether the setup is using the CTSY Dispatcher layer.
   333 #ifdef USING_CTSY_DISPATCHER 
   343 #ifdef USING_CTSY_DISPATCHER 
   334     return ETrue; 
   344 	return ETrue; 
   335 #else
   345 #else
   336     return EFalse;
   346 	return EFalse;
   337 #endif
   347 #endif
   338     }
   348 	}
       
   349 
       
   350 MLtsyFactoryBase* CMmPhoneFactoryTsy::LoadLibraryL()
       
   351 	{
       
   352 	//load library.  This can either be LicenseeTsy or CtsyDispatcher dlls
       
   353 	TPtrC dllname;
       
   354 	TInt uid3_int;
       
   355 	if(UsingCtsyDispatcher())
       
   356 		{
       
   357 		dllname.Set(KCtsyDispatcherDllName);
       
   358 		uid3_int = KCtsyDispatcherUID3;
       
   359 		}
       
   360 	else
       
   361 		{
       
   362 		dllname.Set(KLicenseeTsyDllName);
       
   363 		uid3_int = KLicenseeTsyUID3;
       
   364 		}
       
   365 	
       
   366 	TFLOGSTRING3("TSY: CMmPhoneFactoryTsy::LoadLibraryL - Loading Dll=%S, UID3=0x%x", &dllname, uid3_int);
       
   367 	
       
   368 	TUidType uid(KNullUid, KNullUid, TUid::Uid(uid3_int));
       
   369 	
       
   370 	User::LeaveIfError(iLoadedLib.Load(dllname));
       
   371 	
       
   372 	// Check the Uid3 is as expected
       
   373 	if(iLoadedLib.Type()[2]!=TUid::Uid(uid3_int))
       
   374 		User::Leave(KErrBadLibraryEntryPoint);
       
   375 	
       
   376 	TFactoryBaseNewL libEntry=(TFactoryBaseNewL)iLoadedLib.Lookup(1);	
       
   377 	MLtsyFactoryBase* factory=(*libEntry)();	// libEntry may leave.
       
   378 	
       
   379 	return factory;
       
   380 	}
   339 #endif //USING_CTSY_DISPATCHER
   381 #endif //USING_CTSY_DISPATCHER
   340 
   382 
   341 // ---------------------------------------------------------------------------
   383 //  End of File
   342 // CMmPhoneFactoryTsy::LoadLibraryL
   384 
   343 // Dynamically loads a LTSY.
   385 
   344 // ---------------------------------------------------------------------------
       
   345 //
       
   346 MLtsyFactoryBase* CMmPhoneFactoryTsy::LoadLibraryL()
       
   347     {
       
   348     TPtrC ltsyDllName(0, NULL);
       
   349     TUint ltsyDllUid = 0;
       
   350     
       
   351 #ifdef USING_CTSY_DISPATCHER 
       
   352     ltsyDllName.Set(KDefaultLicenseeTsyDllName);
       
   353     ltsyDllUid = KDefaultLicenseeTsyUID3; 
       
   354 #else
       
   355     RBuf configData;
       
   356     CleanupClosePushL(configData);
       
   357     ReadConfigFileL(&configData);
       
   358     
       
   359     TRAPD(ret,
       
   360           {
       
   361           ltsyDllName.Set(ReadDllNameFromConfigL(configData));
       
   362           ltsyDllUid = ReadDllUidFromConfigL(configData);
       
   363           });
       
   364     
       
   365     if (ret != KErrNone)
       
   366         {
       
   367         ltsyDllName.Set(KDefaultLicenseeTsyDllName);
       
   368         ltsyDllUid = KDefaultLicenseeTsyUID3;
       
   369         TFLOGSTRING2("TSY: Failed to load LTSY dll details from ini (error: %d), using defaults", ret);
       
   370         }
       
   371 #endif
       
   372     
       
   373     TFLOGSTRING3("TSY: CMmPhoneFactoryTsy::LoadLibraryL - Loading Dll=%S, UID3=0x%x", &ltsyDllName, ltsyDllUid);
       
   374     User::LeaveIfError(iLoadedLib.Load(ltsyDllName));
       
   375     
       
   376 #ifndef USING_CTSY_DISPATCHER
       
   377     CleanupStack::PopAndDestroy();  // configData
       
   378 #endif
       
   379     
       
   380     // Check the Uid3 is as expected
       
   381     if (iLoadedLib.Type()[2] != TUid::Uid(ltsyDllUid))
       
   382         {
       
   383         User::Leave(KErrBadLibraryEntryPoint);
       
   384         }
       
   385     
       
   386     TFactoryBaseNewL libEntry = REINTERPRET_CAST(TFactoryBaseNewL, iLoadedLib.Lookup(1));   
       
   387     MLtsyFactoryBase* factory = (*libEntry)();    // libEntry may leave.
       
   388     
       
   389     User::LeaveIfNull(factory);
       
   390     TFLOGSTRING("TSY: Loaded LTSY");
       
   391     return factory;
       
   392     }
       
   393 
       
   394 TPtrC CMmPhoneFactoryTsy::ReadDllNameFromConfigL(const TDesC& aConfigData)
       
   395     {
       
   396     _LIT(KLicenseeTsyDllKeyName, "LicenseeTsyDllName");
       
   397     TPtrC dllName = GetValueForKeyL(aConfigData, KLicenseeTsyDllKeyName);
       
   398     TFLOGSTRING2("TSY: Config file: LTSY DLL name = %S", &dllName);
       
   399     return dllName;
       
   400     }
       
   401 
       
   402 TUint CMmPhoneFactoryTsy::ReadDllUidFromConfigL(const TDesC& aConfigData)
       
   403     {
       
   404     _LIT(KLicenseeTsyUid3, "LicenseeTsyUid3");
       
   405 
       
   406     const TDesC& rawUid = GetValueForKeyL(aConfigData, KLicenseeTsyUid3);
       
   407     // only take the right 8 characters (ie discard the "0x")
       
   408     ASSERT(rawUid.Length() >= 8);
       
   409     TLex lex(rawUid.Right(8));   
       
   410     TUint uid;
       
   411     User::LeaveIfError(lex.Val(uid, EHex));
       
   412     TFLOGSTRING2("TSY: Config file: LTSY UID3 = 0x%x", uid);
       
   413     return uid;
       
   414     }
       
   415 
       
   416 /*static*/
       
   417 void CMmPhoneFactoryTsy::ReadConfigFileL(RBuf* aConfigData)
       
   418 /**
       
   419  * Reads config file from system drive or, if not present, from ROM
       
   420  *
       
   421  * @param aConfigData This buffer gets created and has the ini file contents loaded into it
       
   422  */
       
   423     {
       
   424     RFs fs;
       
   425     User::LeaveIfError(fs.Connect());
       
   426     CleanupClosePushL(fs);
       
   427 
       
   428     fs.SetSessionToPrivate(fs.GetSystemDrive());
       
   429 
       
   430     RFile configFile;
       
   431     TFLOGSTRING2("TSY: Reading ini file %S", &KLtsyIniFile);
       
   432     TInt ret = configFile.Open(fs, KLtsyIniFile, EFileShareExclusive);
       
   433     if (ret == KErrNotFound)
       
   434         {
       
   435         User::LeaveIfError(fs.SetSessionToPrivate(EDriveZ));
       
   436         User::LeaveIfError(configFile.Open(fs, KLtsyIniFile, EFileShareExclusive));
       
   437         }
       
   438     CleanupClosePushL(configFile);
       
   439 
       
   440     TInt configFileSize;
       
   441     User::LeaveIfError(configFile.Size(configFileSize));
       
   442 
       
   443     RBuf8 fileBuf;
       
   444     fileBuf.Create(configFileSize);
       
   445     CleanupClosePushL(fileBuf);
       
   446     User::LeaveIfError(configFile.Read(fileBuf));
       
   447 
       
   448     aConfigData->CreateL(configFileSize);
       
   449     aConfigData->Copy(fileBuf);
       
   450 
       
   451     CleanupStack::PopAndDestroy(3, &fs); // fs, configFile, fileBuf
       
   452     }
       
   453 
       
   454 /*static*/
       
   455 TPtrC CMmPhoneFactoryTsy::GetValueForKeyL(const TDesC& aKeysValues, const TDesC& aKey)
       
   456 /**
       
   457  * Gets the value for a specified key. The expected format is
       
   458  * <pre>
       
   459  * key1 value1
       
   460  * key2 value2
       
   461  * </pre>
       
   462  * 
       
   463  * However the parsing is flexible enough to allow "key1 =value1" as it allows an equals separator and extra whitespace
       
   464  * The value cannot include whitespace, even if quoted.
       
   465  */
       
   466     {
       
   467     // this matches the bracket expression in this regexp: \w+\s*=?\s*(\w+)[\s$]
       
   468     TInt startOfKey = aKeysValues.Find(aKey);
       
   469     TLex valueExtractor(aKeysValues);
       
   470     valueExtractor.Inc(startOfKey + aKey.Length());
       
   471     valueExtractor.SkipSpaceAndMark();
       
   472     // allow equals separating key and value
       
   473     if (valueExtractor.Peek() == '=')
       
   474         {
       
   475         valueExtractor.Inc();
       
   476         valueExtractor.SkipSpaceAndMark();
       
   477         }
       
   478     
       
   479     TPtrC value = valueExtractor.NextToken();
       
   480     __ASSERT_ALWAYS(value.Length() > 0, User::Leave(KErrCorrupt));
       
   481     return value;
       
   482     }