cbsref/telephonyrefplugins/atltsy/atcommand/generic/src/tsyconfg.cpp
changeset 44 8b72faa1200f
equal deleted inserted replaced
39:2473f5e227f9 44:8b72faa1200f
       
     1 // Copyright (c) 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 // @file tsyconfig.cpp
       
    15 // This contains CTsyConfig which manage access to CommDB configuration.
       
    16 // 
       
    17 
       
    18 // system include
       
    19 #include <commsdattypesv1_1.h>
       
    20 #include <commsdat_partner.h>
       
    21 using namespace CommsDat;
       
    22 
       
    23 // user include
       
    24 #include "tsyconfg.h"
       
    25 #include "mslogger.h"
       
    26 
       
    27 #ifdef __LOGDEB__
       
    28 _LIT8(KLogEntry,"CTsyConfig::%S\t%S");
       
    29 #define LOCAL_LOGTEXT(function,text) {_LIT8(F,function);_LIT8(T,text);LOGTEXT3(KLogEntry,&F,&T);}
       
    30 #else
       
    31 #define LOCAL_LOGTEXT(function,text)
       
    32 #endif
       
    33 
       
    34 // const defination
       
    35 const TInt KDefaultLocationInternalPref = 0;
       
    36 const RCall::TMonitorSpeakerControl KDefaultModemSpeakerSetting = RCall::EMonitorSpeakerControlOnUntilCarrier;
       
    37 const RCall::TMonitorSpeakerVolume KDefaultMonitorSpeakerVolume = RCall::EMonitorSpeakerVolumeOff;
       
    38 const RCall::TWaitForDialTone KDefaultWaitForDialTone = RCall::EDialToneNoWait;
       
    39 
       
    40 // ---------------------------------------------------------------------------
       
    41 // CTsyConfig::NewL
       
    42 // other items were commented in a header
       
    43 // ---------------------------------------------------------------------------
       
    44 CTsyConfig* CTsyConfig::NewL() 
       
    45 	{
       
    46 	CTsyConfig* self = new(ELeave) CTsyConfig();
       
    47 	CleanupStack::PushL(self);
       
    48 	self->ConstructL(); 
       
    49 	CleanupStack::Pop();
       
    50 	return (self);
       
    51 	}
       
    52 
       
    53 // ---------------------------------------------------------------------------
       
    54 // CTsyConfig::CTsyConfig
       
    55 // other items were commented in a header
       
    56 // ---------------------------------------------------------------------------
       
    57 CTsyConfig::CTsyConfig()
       
    58 	{	
       
    59 	}
       
    60 
       
    61 // ---------------------------------------------------------------------------
       
    62 // CTsyConfig::ConstructL
       
    63 // other items were commented in a header
       
    64 // ---------------------------------------------------------------------------
       
    65 void CTsyConfig::ConstructL()
       
    66 	{
       
    67 	iLocationId = 0;
       
    68 	iModemBearer = 0;
       
    69 	SetCurrentTableViewL();
       
    70 	GetLocationModemSettingsL();
       
    71 	}
       
    72 
       
    73 // ---------------------------------------------------------------------------
       
    74 // CTsyConfig::SetCurrentTableViewL
       
    75 // other items were commented in a header
       
    76 // ---------------------------------------------------------------------------
       
    77 void CTsyConfig::SetCurrentTableViewL()
       
    78 	{
       
    79 	TInt r = KErrNone;
       
    80 
       
    81 	for (TInt i = 0; i < 10; i++)
       
    82 		{
       
    83 		TRAP(r, GetCurrentTableViewsL()); // Place a cursor on the default modem record in comms database server
       
    84 		if (r == KErrAccessDenied)        // if we get access denied from DBMS, which is a timing thing, just re-post
       
    85 			{
       
    86 			User::After(1000000);
       
    87 			continue;
       
    88 			}
       
    89 		else
       
    90 			{
       
    91 			break;
       
    92 			}
       
    93 		}
       
    94 	
       
    95 	if(r)
       
    96 		{
       
    97 		LOGTEXT(_L8("CommDB values seem to be corrupt"));
       
    98 		User::Leave(KErrEtelModemSettingsCorrupt);
       
    99 		}
       
   100 	}
       
   101 
       
   102 // ---------------------------------------------------------------------------
       
   103 // CTsyConfig::GetLocationModemSettingsL
       
   104 // other items were commented in a header
       
   105 // ---------------------------------------------------------------------------
       
   106 void CTsyConfig::GetLocationModemSettingsL()
       
   107 	{
       
   108 	ASSERT(iModemBearer != 0);
       
   109 	
       
   110 	iSpeakerSetting = KDefaultModemSpeakerSetting;
       
   111 	iSpeakerVolume = KDefaultMonitorSpeakerVolume;
       
   112 	
       
   113 	if(iLocationId == 0)
       
   114 		{
       
   115 		iInterval = KDefaultLocationInternalPref;
       
   116 		iWaitForDialTonePref = KDefaultWaitForDialTone;
       
   117 		}
       
   118 	else
       
   119 		{
       
   120 		TBool value(EFalse);
       
   121 		CMDBField<TUint32>* intervalField = new(ELeave) CMDBField<TUint32>(KCDTIdPauseAfterDialOut);
       
   122 		CleanupStack::PushL(intervalField);
       
   123 		intervalField->SetRecordId(iLocationId);
       
   124 		intervalField->LoadL(*iDbSession);
       
   125 		iInterval = *intervalField;
       
   126 		CleanupStack::PopAndDestroy(intervalField);
       
   127 		
       
   128 		CMDBField<TUint32>* valueField = new(ELeave) CMDBField<TUint32>(KCDTIdWaitForDialTone);		
       
   129 		CleanupStack::PushL(valueField);
       
   130 		valueField->SetRecordId(iLocationId);
       
   131 		valueField->LoadL(*iDbSession);
       
   132 		value = *valueField;
       
   133 		CleanupStack::PopAndDestroy(valueField);
       
   134 		
       
   135 		if (value)
       
   136 			{
       
   137 			iWaitForDialTonePref = RCall::EDialToneWait;
       
   138 			}
       
   139 		else
       
   140 			{
       
   141 			iWaitForDialTonePref = RCall::EDialToneNoWait;
       
   142 			}
       
   143 		}
       
   144 
       
   145     // read speaker preferences
       
   146 	CMDBField<TUint32>* speakerPrefField = new(ELeave) CMDBField<TUint32>(KCDTIdSpeakerPref);
       
   147 	CleanupStack::PushL(speakerPrefField);
       
   148 	speakerPrefField->SetRecordId(iModemBearer);
       
   149 	speakerPrefField->LoadL(*iDbSession);
       
   150 	iSpeakerSetting = static_cast<RCall::TMonitorSpeakerControl>(static_cast<TUint32>(*speakerPrefField));
       
   151 	CleanupStack::PopAndDestroy(speakerPrefField);
       
   152 	
       
   153 	// read speaker volume preferences
       
   154 	CMDBField<TUint32>* speakerVolPrefField = new(ELeave) CMDBField<TUint32>(KCDTIdSpeakerVolPref);
       
   155 	CleanupStack::PushL(speakerVolPrefField);
       
   156 	speakerVolPrefField->SetRecordId(iModemBearer);
       
   157 	speakerVolPrefField->LoadL(*iDbSession);
       
   158 	iSpeakerVolume = static_cast<RCall::TMonitorSpeakerVolume>(static_cast<TUint32>(*speakerVolPrefField));			
       
   159 	CleanupStack::PopAndDestroy(speakerVolPrefField);
       
   160 
       
   161     // read modem rate
       
   162 	CMDBField<TUint32>* rateField = new(ELeave) CMDBField<TUint32>(KCDTIdRate);
       
   163 	CleanupStack::PushL(rateField);
       
   164 	rateField->SetRecordId(iModemBearer);
       
   165 	rateField->LoadL(*iDbSession);
       
   166 	TUint32 rate;
       
   167 	rate = *rateField;
       
   168 	CleanupStack::PopAndDestroy(rateField);
       
   169 	
       
   170 	// read data bits for modem
       
   171 	CMDBField<TUint32>* dataBitsField = new(ELeave) CMDBField<TUint32>(KCDTIdDataBits);
       
   172 	CleanupStack::PushL(dataBitsField);
       
   173 	dataBitsField->SetRecordId(iModemBearer);
       
   174 	dataBitsField->LoadL(*iDbSession);
       
   175 	TUint32 dataBits;
       
   176 	dataBits = *dataBitsField;
       
   177 	CleanupStack::PopAndDestroy(dataBitsField);
       
   178     
       
   179 	// read stop bits for modem
       
   180 	CMDBField<TUint32>* stopBitsField = new(ELeave) CMDBField<TUint32>(KCDTIdStopBits);
       
   181 	CleanupStack::PushL(stopBitsField);
       
   182 	stopBitsField->SetRecordId(iModemBearer);
       
   183 	stopBitsField->LoadL(*iDbSession);
       
   184 	TUint32 stopBits;
       
   185 	stopBits = *stopBitsField;
       
   186 	CleanupStack::PopAndDestroy(stopBitsField);
       
   187 	
       
   188 	// read parity for modem
       
   189 	CMDBField<TUint32>* parityField = new(ELeave) CMDBField<TUint32>(KCDTIdParity);
       
   190 	CleanupStack::PushL(parityField);
       
   191 	parityField->SetRecordId(iModemBearer);
       
   192 	parityField->LoadL(*iDbSession);
       
   193 	TUint32 parity;
       
   194 	parity = *parityField;
       
   195 	CleanupStack::PopAndDestroy(parityField);
       
   196 	
       
   197 	// read handshake for modem
       
   198 	CMDBField<TUint32>* handshakeField = new(ELeave) CMDBField<TUint32>(KCDTIdHandshaking);
       
   199 	CleanupStack::PushL(handshakeField);
       
   200 	handshakeField->SetRecordId(iModemBearer);
       
   201 	handshakeField->LoadL(*iDbSession);
       
   202 	TUint32 handshake;
       
   203 	handshake = *handshakeField;
       
   204 	CleanupStack::PopAndDestroy(handshakeField);
       
   205     
       
   206 	// set the modem configuration
       
   207 	iConfig.iRate = (TBps)rate;
       
   208 	iConfig.iDataBits = (TDataBits)dataBits;
       
   209 	iConfig.iStopBits = (TStopBits)stopBits;
       
   210 	iConfig.iParity = (TParity)parity;
       
   211 	iConfig.iHandshake = handshake;
       
   212 	}
       
   213 
       
   214 // ---------------------------------------------------------------------------
       
   215 // CTsyConfig::~CTsyConfig
       
   216 // other items were commented in a header
       
   217 // ---------------------------------------------------------------------------
       
   218 CTsyConfig::~CTsyConfig()
       
   219 	{
       
   220 	delete iDbSession;
       
   221 	}
       
   222 
       
   223 // ---------------------------------------------------------------------------
       
   224 // CTsyConfig::ConfigModemStringL
       
   225 // other items were commented in a header
       
   226 // ---------------------------------------------------------------------------
       
   227 TInt CTsyConfig::ConfigModemStringL(const TDesC& aStringTag, TDes8& aString)
       
   228 	{
       
   229 	ASSERT(iDbSession != 0);
       
   230 	CCDModemBearerRecord* modemRecord = static_cast<CCDModemBearerRecord*>(CCDRecordBase::RecordFactoryL(KCDTIdModemBearerRecord));
       
   231 	CleanupStack::PushL(modemRecord);
       
   232 	modemRecord->SetRecordId(iModemBearer);
       
   233 	modemRecord->LoadL(*iDbSession);
       
   234 	
       
   235 	TInt ret;
       
   236 	TInt type(0);
       
   237 	CMDBElement* baseField = NULL;
       
   238 	TRAP(ret, baseField = modemRecord->GetFieldByNameL(aStringTag, type));
       
   239 	if (ret == KErrNone)
       
   240 		{
       
   241 		// check for type
       
   242 		switch(type)
       
   243 			{
       
   244 			case EMedText:
       
   245 			case EText:
       
   246 				{
       
   247 				CMDBField<TDesC>* field16 = static_cast<CMDBField<TDesC>*>(baseField);
       
   248 				const TDesC& refField = *field16;
       
   249 				aString.Copy(refField);
       
   250 				ret = KErrNone;
       
   251 				}
       
   252 				break;
       
   253 			case EDesC8:
       
   254 				{
       
   255 				CMDBField<TDesC8>* field = static_cast<CMDBField<TDesC8>*>(baseField);
       
   256 				aString = *field;
       
   257 				ret = KErrNone;
       
   258 				}
       
   259 				break;
       
   260 			default:
       
   261 				ret = KErrNotFound;
       
   262 			}
       
   263     	}
       
   264 	CleanupStack::PopAndDestroy(modemRecord);
       
   265 
       
   266 	return ret;
       
   267 	}
       
   268 
       
   269 // ---------------------------------------------------------------------------
       
   270 // CTsyConfig::ConfigModemStringL
       
   271 // other items were commented in a header
       
   272 // ---------------------------------------------------------------------------
       
   273 TInt CTsyConfig::ConfigModemStringL(const TDesC& aStringTag, TDes16& aString)
       
   274 	{
       
   275 	ASSERT(iDbSession != 0);
       
   276 	// get the table record
       
   277 	CCDModemBearerRecord* modemRecord = static_cast<CCDModemBearerRecord*>(CCDRecordBase::RecordFactoryL(KCDTIdModemBearerRecord));
       
   278 	CleanupStack::PushL(modemRecord);
       
   279 	modemRecord->SetRecordId(iModemBearer);
       
   280 	modemRecord->LoadL(*iDbSession);
       
   281 	
       
   282 	TInt ret;
       
   283 	TInt type(0);
       
   284 	CMDBElement* baseField = NULL;
       
   285 	TRAP(ret, baseField = modemRecord->GetFieldByNameL(aStringTag, type));
       
   286 	if (ret == KErrNone)
       
   287 		{
       
   288 		// check for type
       
   289 		switch(type)
       
   290 			{
       
   291 			case EMedText:
       
   292 			case EText:
       
   293 				{
       
   294 				CMDBField<TDesC>* field = static_cast<CMDBField<TDesC>*>(baseField);
       
   295 				aString = *field;
       
   296 				ret = KErrNone;
       
   297 				}
       
   298 				break;
       
   299 			case EDesC8:
       
   300 				{
       
   301 				// des16 needs to be cast to des8
       
   302 				CMDBField<TDesC8>* field8 = static_cast<CMDBField<TDesC8>*>(baseField);
       
   303 				const TDesC8& refField = *field8;
       
   304 				aString.Copy(refField);
       
   305 				ret = KErrNone;
       
   306 				}
       
   307 				break;
       
   308 			default:
       
   309 				ret = KErrNotFound;
       
   310 			}
       
   311 		}
       
   312 	
       
   313 	CleanupStack::PopAndDestroy(modemRecord);
       
   314 
       
   315 	return ret;
       
   316 	}
       
   317 
       
   318 // ---------------------------------------------------------------------------
       
   319 // CTsyConfig::GetSpeakerSettingPref
       
   320 // other items were commented in a header
       
   321 // ---------------------------------------------------------------------------
       
   322 void CTsyConfig::GetSpeakerSettingPref(RCall::TMonitorSpeakerControl& aSpeakerSetting)
       
   323 	{
       
   324 	aSpeakerSetting = iSpeakerSetting;
       
   325 	}
       
   326 
       
   327 // ---------------------------------------------------------------------------
       
   328 // CTsyConfig::GetSpeakerVolumePref
       
   329 // other items were commented in a header
       
   330 // ---------------------------------------------------------------------------
       
   331 void CTsyConfig::GetSpeakerVolumePref(RCall::TMonitorSpeakerVolume& aSpeakerVolume)
       
   332 	{
       
   333 	aSpeakerVolume = iSpeakerVolume;
       
   334 	}
       
   335 
       
   336 // ---------------------------------------------------------------------------
       
   337 // CTsyConfig::GetWaitForDialTonePref
       
   338 // other items were commented in a header
       
   339 // ---------------------------------------------------------------------------
       
   340 void CTsyConfig::GetWaitForDialTonePref(RCall::TWaitForDialTone& aWaitForDialTonePref)
       
   341 	{
       
   342 	aWaitForDialTonePref = iWaitForDialTonePref;
       
   343 	}
       
   344 
       
   345 // ---------------------------------------------------------------------------
       
   346 // CTsyConfig::PortConfig
       
   347 // other items were commented in a header
       
   348 // ---------------------------------------------------------------------------
       
   349 TInt CTsyConfig::PortConfig(TCommConfig& aConfigPckg, TConfigType aConfigType)
       
   350 	{
       
   351 	TCommConfig configDummyPckg;
       
   352 	TCommConfigV01& config = configDummyPckg();
       
   353 	config = iConfig;
       
   354 	
       
   355 	if (aConfigType==EConfigTypeHangUp ||
       
   356 		aConfigType==EConfigTypeQuickInit)
       
   357 		{
       
   358 		config.iHandshake = 0;//&= (~(KConfigFailDCD | KConfigObeyDCD | KConfigFailDSR));
       
   359 		}
       
   360 	else
       
   361 		{
       
   362 		switch (aConfigType)
       
   363 			{
       
   364 		case EConfigTypePreInit:
       
   365 			config.iHandshake &= (~(KConfigObeyCTS | KConfigFailCTS | KConfigObeyDCD | KConfigFailDCD | KConfigFailDSR));
       
   366 			break;
       
   367 		case EConfigTypeInit:
       
   368 			config.iHandshake &= (~(KConfigObeyCTS | KConfigFailCTS | KConfigObeyDCD | KConfigFailDCD));
       
   369 			break;
       
   370 		case EConfigTypeConnect:
       
   371 			config.iHandshake &= (~(KConfigFailCTS | KConfigFailDCD));	// fail DCD masked out, as should get NO CARRIER anyway
       
   372 			break;
       
   373 		case EConfigTypeFull:
       
   374 			break;
       
   375 		case EConfigTypeDDBugWorkAroundStart:
       
   376 			if (config.iRate!=EBps300)	// ensure that something other than handshaking has changed
       
   377 				config.iRate=EBps300;	// to work around the bug in the ARM device driver
       
   378 			else
       
   379 				config.iRate=EBps2400;
       
   380 			config.iHandshake=0;
       
   381 			break;
       
   382 		case EConfigTypeDDBugWorkAroundEnd:
       
   383 			config.iHandshake=0;
       
   384 			break;
       
   385 		default:
       
   386 			break;
       
   387 			}
       
   388 		}
       
   389 	
       
   390 	aConfigPckg=configDummyPckg;
       
   391 	return KErrNone;
       
   392 	}
       
   393 
       
   394 // ---------------------------------------------------------------------------
       
   395 // CTsyConfig::GetCurrentTableViewsL
       
   396 // other items were commented in a header
       
   397 // ---------------------------------------------------------------------------
       
   398 void CTsyConfig::GetCurrentTableViewsL() 
       
   399 	{
       
   400 	ResetCurrentTableViews();
       
   401 	
       
   402 #ifdef SYMBIAN_NON_SEAMLESS_NETWORK_BEARER_MOBILITY
       
   403 	iDbSession = CMDBSession::NewL(KCDVersion1_2);
       
   404 #else
       
   405 	iDbSession = CMDBSession::NewL(KCDVersion1_1);
       
   406 #endif
       
   407 
       
   408 	iModemBearer = 0;
       
   409 	iLocationId = 0;
       
   410 	// Search the bearer tables for records using the Phonetsy.TSY
       
   411 	GetModemBearerIdL(iModemBearer);
       
   412 
       
   413 	// Get the associated locationId
       
   414 	GetLocationIdL(iModemBearer,iLocationId);
       
   415 	
       
   416 	//Check if the selected bearer is an MMTSY bearer with a valid location
       
   417 	if(!iModemBearer || !iLocationId) 
       
   418 		{
       
   419 		//
       
   420 		// Selected bearer does not mention the MMTSY
       
   421 		LOCAL_LOGTEXT("GetCurrentSettingsL","PhoneTSY not mentioned in the selected bearer");
       
   422 		User::Leave(KErrNotFound);
       
   423 		}
       
   424 	}
       
   425 
       
   426 // ---------------------------------------------------------------------------
       
   427 // CTsyConfig::ResetCurrentTableViews
       
   428 // other items were commented in a header
       
   429 // ---------------------------------------------------------------------------
       
   430 void CTsyConfig::ResetCurrentTableViews()
       
   431 	{
       
   432 	delete iDbSession;
       
   433 	iDbSession = NULL;		
       
   434 	}
       
   435 
       
   436 // ---------------------------------------------------------------------------
       
   437 // CTsyConfig::GetLocationIdL
       
   438 // other items were commented in a header
       
   439 // ---------------------------------------------------------------------------
       
   440 void CTsyConfig::GetLocationIdL(const TUint32& aBearerId, TUint32& aLocationId) 
       
   441  	{
       
   442     CCDIAPRecord *iapRecord = static_cast<CCDIAPRecord*>(CCDRecordBase::RecordFactoryL(KCDTIdIAPRecord));
       
   443   	CleanupStack::PushL(iapRecord);
       
   444   	
       
   445   	iapRecord->iBearer = aBearerId;
       
   446   	TBool err = iapRecord->FindL(*iDbSession);
       
   447   	if (err)
       
   448   		{
       
   449   		aLocationId = iapRecord->iLocation;
       
   450   		}
       
   451   	else
       
   452   		{
       
   453   		aLocationId = static_cast<TUint32>(KErrNotFound);
       
   454   		}
       
   455   	
       
   456     CleanupStack::PopAndDestroy(iapRecord);
       
   457     
       
   458 	}
       
   459 
       
   460 // ---------------------------------------------------------------------------
       
   461 // CTsyConfig::GetModemBearerIdL
       
   462 // other items were commented in a header
       
   463 // ---------------------------------------------------------------------------
       
   464 void CTsyConfig::GetModemBearerIdL(TUint32& aBearerId)
       
   465 	{
       
   466     CCDModemBearerRecord *modemRecord = static_cast<CCDModemBearerRecord*>(CCDRecordBase::RecordFactoryL(KCDTIdModemBearerRecord));
       
   467     CleanupStack::PushL(modemRecord);
       
   468     
       
   469     _LIT(KTsyName,"phonetsy"); // Note this is case sensitive and must match the name in commdb
       
   470     modemRecord->iTsyName.SetMaxLengthL(KMaxTextLength);
       
   471     modemRecord->iTsyName = KTsyName;
       
   472     
       
   473     TBool searchResult = modemRecord->FindL(*iDbSession);
       
   474     
       
   475     if (searchResult)
       
   476 	    {
       
   477 		aBearerId = modemRecord->RecordId();	
       
   478 	    }
       
   479 	else
       
   480 		{
       
   481 		aBearerId = static_cast<TUint32>(KErrNotFound);
       
   482 		}
       
   483     
       
   484     CleanupStack::PopAndDestroy(modemRecord);
       
   485 	}
       
   486 
       
   487 // End of file