telephonyprotocols/pdplayer/umts/spudtel/src/ceteldriverfactory.cpp
changeset 0 3553901f7fa8
child 14 7ef16719d8cb
equal deleted inserted replaced
-1:000000000000 0:3553901f7fa8
       
     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 // etel driver factory
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file 
       
    20  @internalComponent
       
    21 */
       
    22 
       
    23 #include <e32base.h>
       
    24 #include <etelmm.h>
       
    25 
       
    26 #include "cspudcontextelem.h"
       
    27 #include "ceteldriverfactory.h"
       
    28 #include "spudteldebuglogger.h"
       
    29 #include "PDPFSM.h"
       
    30 using namespace EtelDriver;
       
    31 
       
    32 /**
       
    33 @param aPdpFsmInterface - pdp fsm interface
       
    34 */
       
    35 CEtelDriverFactory::CEtelDriverFactory (CPdpFsmInterface& aPdpFsmInterface)
       
    36 : iPdpFsmInterface(aPdpFsmInterface),
       
    37   iServiceChangeNotifier(iPacketService, iPdpFsmInterface)
       
    38 	{
       
    39 	SPUDTELVERBOSE_INFO_LOG(_L("CEtelDriverFactory::CEtelDriverFactory()"));
       
    40 	}
       
    41 
       
    42 /**
       
    43 @param aPdpFsmInterface - pdp fsm interface
       
    44 */
       
    45 CEtelDriverFactory* CEtelDriverFactory::NewL (CPdpFsmInterface& aPdpFsmInterface)
       
    46 	{
       
    47 	SPUDTEL_INFO_LOG(_L("CEtelDriverFactory::NewL()"));
       
    48 	
       
    49 	return new (ELeave) CEtelDriverFactory (aPdpFsmInterface);
       
    50 	}
       
    51 
       
    52 CEtelDriverFactory::~CEtelDriverFactory()
       
    53 	{
       
    54 	SPUDTEL_FNLOG("CEtelDriverFactory::~CEtelDriverFactory()");
       
    55 	SPUDTEL_INFO_LOG(_L("CEtelDriverFactory::~CEtelDriverFactory()"));
       
    56 
       
    57 	// cancel all notificators
       
    58 	iServiceChangeNotifier.Cancel();
       
    59 	
       
    60 	// cleanup array of CEtelDriverContext objs
       
    61 	for (TInt i = 0; i < iContexts.Count(); i++ )
       
    62 		{ 
       
    63 		delete iContexts[i]; 
       
    64 		}
       
    65 	iContexts.Reset();
       
    66 
       
    67 	// common data cleanup...
       
    68 	// sync operations only
       
    69 	iPacketService.Close();
       
    70 	iPhone.Close();
       
    71 
       
    72 	iTelServer.UnloadPhoneModule(iPdpFsmInterface.TsyName());
       
    73 
       
    74 	iTelServer.Close();	// Phone module unloaded automatically
       
    75 	
       
    76 	iStrategies.Reset();
       
    77 	}
       
    78 
       
    79 /**
       
    80 Function obtains the info on the phone object implemented in the TSY
       
    81 
       
    82 Assumes aloadedTsyName has no ".TSY" appendage
       
    83 Finds the phone information for the TSY just loaded. 
       
    84 Assumes just one phone in that TSY - or that every phone in it is equally useful.
       
    85 
       
    86 @param aTelServer - tel server
       
    87 @param aLoadedTsyName - name of the loaded Tsy.
       
    88 @param aInfo - information about the phone.
       
    89 */
       
    90 static void GetPhoneInfoL(RTelServer& aTelServer, const TDesC& aLoadedTsyName, RTelServer::TPhoneInfo& aInfo)
       
    91 	{
       
    92 	// dev. note: leavescan reports an error in this method.
       
    93 	// But there is no visible ground for it.
       
    94 	SPUDTEL_FNLOG("GetPhoneInfoL()");
       
    95 	TInt count;
       
    96 	User::LeaveIfError(aTelServer.EnumeratePhones(count));
       
    97 	if (count<=0)
       
    98 		{
       
    99 		User::Leave(KErrNotFound);
       
   100 		}
       
   101 		
       
   102 	TBool found = EFalse;
       
   103 	for (TInt i=0; i < count; i++)
       
   104 		{
       
   105 		TBuf<KCommsDbSvrMaxFieldLength> currentTsyName;
       
   106 		User::LeaveIfError(aTelServer.GetTsyName(i,currentTsyName));
       
   107 		
       
   108 		TInt r=currentTsyName.Locate('.');
       
   109 		if (r!=KErrNotFound)
       
   110 			{
       
   111 			currentTsyName.SetLength(r);
       
   112 			}
       
   113 		if (currentTsyName.CompareF(aLoadedTsyName)==KErrNone)
       
   114 			{
       
   115 			User::LeaveIfError(aTelServer.GetPhoneInfo(i,aInfo));
       
   116 			found = ETrue;
       
   117 			break;
       
   118 			}
       
   119 		}
       
   120 
       
   121 	if (!found)
       
   122 		{
       
   123 		User::Leave(KErrNotFound);
       
   124 		}
       
   125 
       
   126 	}
       
   127 
       
   128 /** initializes factory objects */
       
   129 void CEtelDriverFactory::InitL()
       
   130 	{
       
   131 	SPUDTEL_FNLOG("CEtelDriverFactory::InitL()");
       
   132 	SPUDTEL_INFO_LOG(_L("Initializing Etel driver"));
       
   133 	
       
   134 	iStrategies[EOpenPhoneStrategy] 			= &iOpenStrategy;
       
   135 	iStrategies[ESetQoSStrategy] 				= &iSetQoSStrategy;
       
   136 	iStrategies[ESetTftStrategy] 				= &iSetTftStrategy;
       
   137 	iStrategies[EChangeTftStrategy]				= &iChangeTftStrategy;
       
   138 	
       
   139 	iStrategies[ECreate1ryPdpContextStrategy] 	= &iCreate1ryPdpContextStrategy;
       
   140 	iStrategies[ECreate2ryPdpContextStrategy] 	= &iCreate2ryPdpContextStrategy;
       
   141 	iStrategies[EActivatePdpStrategy] 			= &iActivatePdpStrategy;
       
   142 	iStrategies[EGetNegQoSStrategy] 			= &iGetNegQoSStrategy;
       
   143 	iStrategies[EModifyActiveStrategy] 			= &iModifyActivePdpStrategy;
       
   144 	iStrategies[EContextDeleteStrategy] 		= &iContextDeleteStrategy;
       
   145 	iStrategies[ECreateMbmsPdpContextStrategy] = &iCreateMbmsPdpContextStrategy;
       
   146 	iStrategies[EActivateMbmsPdpStrategy]		= &iActivateMbmsPdpStrategy;
       
   147 	iStrategies[ESessionUpdateStrategy]         = &iMbmsSessionUpdateStragegy;
       
   148 
       
   149 	// initialization of operator to strategy id map
       
   150 	iInputToStrategyMap[EOpenPhone]				= EOpenPhoneStrategy;
       
   151 	iInputToStrategyMap[ESetQoS] 				= ESetQoSStrategy;
       
   152 	iInputToStrategyMap[ECreate1ryPdpContext] 	= ECreate1ryPdpContextStrategy;
       
   153 	iInputToStrategyMap[ECreate2ryPdpContext] 	= ECreate2ryPdpContextStrategy;
       
   154 	iInputToStrategyMap[ESetTft] 				= ESetTftStrategy;
       
   155 	iInputToStrategyMap[EChangeTft] 			= EChangeTftStrategy;
       
   156 	iInputToStrategyMap[EActivatePdp] 			= EActivatePdpStrategy;
       
   157 	iInputToStrategyMap[ENegQoSGet] 			= EGetNegQoSStrategy;
       
   158 	iInputToStrategyMap[EModifyActive] 			= EModifyActiveStrategy;
       
   159 	iInputToStrategyMap[EContextDelete]			= EContextDeleteStrategy;
       
   160 	iInputToStrategyMap[ECreateMbmsPdpContext]  = ECreateMbmsPdpContextStrategy;
       
   161 	iInputToStrategyMap[EActivateMbmsPdp]		= EActivateMbmsPdpStrategy;
       
   162 	iInputToStrategyMap[ESessionUpdate]			= ESessionUpdateStrategy;
       
   163 	User::LeaveIfError (iTelServer.Connect());
       
   164 	User::LeaveIfError(iTelServer.LoadPhoneModule(iPdpFsmInterface.TsyName()));
       
   165 
       
   166 	User::LeaveIfError(iTelServer.SetExtendedErrorGranularity(RTelServer::EErrorExtended));
       
   167 
       
   168 	RTelServer::TPhoneInfo phoneInfo;
       
   169 	GetPhoneInfoL(iTelServer, iPdpFsmInterface.TsyName(), phoneInfo);
       
   170 	User::LeaveIfError (iPhone.Open (iTelServer, phoneInfo.iName) );
       
   171 	User::LeaveIfError (iPacketService.Open (iPhone) );
       
   172 
       
   173 	// remaining async calls to phone are postponed to later async Input request
       
   174 	
       
   175 	iServiceChangeNotifier.Start();
       
   176 	}
       
   177 	
       
   178 /** creates pdp by id
       
   179 	dev. note: pdp context will NOT be opened during this call.
       
   180 
       
   181 @param aPdpId - id of a pdp context
       
   182 */
       
   183 void CEtelDriverFactory::CreatePdpL (TContextId aPdpId,SpudMan::TPdpContextType aContextType)
       
   184 	{
       
   185 	SPUDTEL_FNLOG("CEtelDriverFactory::CreatePdpL()");
       
   186 	SPUDTELVERBOSE_INFO_LOG1(_L("pdp id : %d"), aPdpId);
       
   187 	__ASSERT_ALWAYS((NULL == iContexts[aPdpId]), User::Panic(KTxtSpudTel, KErrArgument));
       
   188 
       
   189 	if (aContextType == SpudMan::EMbms)
       
   190 		{
       
   191 		iContexts[aPdpId]=CMbmsContextElem::NewL(aPdpId, *this, iPdpFsmInterface);
       
   192 		}
       
   193 	else
       
   194 		{
       
   195 		iContexts[aPdpId]=CSpudContextElem::NewL(aPdpId, *this, iPdpFsmInterface);
       
   196 		}
       
   197 	}
       
   198 
       
   199 
       
   200 /** frees pdp context by id 
       
   201 
       
   202 @param aPdpId - id of a pdp context
       
   203 */
       
   204 void CEtelDriverFactory::FreePdp(TContextId aPdpId)
       
   205 	{
       
   206 
       
   207 	SPUDTELVERBOSE_INFO_LOG1(_L("Free pdp id : %d"), aPdpId);
       
   208 	// the context has to be closed before a call to FreePdp
       
   209 	__ASSERT_ALWAYS(!Context(aPdpId).PacketContext().SubSessionHandle(), User::Panic(KTxtSpudTel, KErrInUse));
       
   210 	
       
   211 	delete iContexts[aPdpId];
       
   212 	iContexts[aPdpId] = NULL;
       
   213 
       
   214 	}
       
   215 
       
   216 
       
   217 /** starts etel notifications for pdp context
       
   218 
       
   219 @param aPdpId - id of a pdp context
       
   220 */
       
   221 void CEtelDriverFactory::StartPdpNotifications (TContextId aPdpId)
       
   222 	{
       
   223 	SPUDTELVERBOSE_INFO_LOG1(_L("StartPdpNotifications for pdp id : %d"), aPdpId);
       
   224 	// sanity check
       
   225 	ASSERT(iContexts[aPdpId]);
       
   226 	
       
   227 	iContexts[aPdpId]->Start();
       
   228 	}
       
   229 
       
   230 /** cancels etel notifications for aPdpId context 
       
   231 
       
   232 @param aPdpId - id of a pdp context
       
   233 */
       
   234 void CEtelDriverFactory::CancelPdpNotifications (TContextId aPdpId)
       
   235 	{
       
   236 	SPUDTELVERBOSE_INFO_LOG1(_L("CancelPdpNotifications for pdp id : %d"), aPdpId);
       
   237 	// sanity check
       
   238 	ASSERT(iContexts[aPdpId]);
       
   239 	
       
   240 	iContexts[aPdpId]->Cancel();
       
   241 	}
       
   242 
       
   243 /** cancels notifications for all pdp contexts */
       
   244 void CEtelDriverFactory::CancelAllPdpNotifications()
       
   245 	{
       
   246 	SPUDTEL_INFO_LOG(_L("CancelAllPdpNotifications"));
       
   247 	for(TContextId i = 0; i < static_cast<TContextId>(ContextCount()); i++)
       
   248 		{ 
       
   249 		CancelPdpNotifications (i); 
       
   250 		}
       
   251 	}
       
   252 
       
   253 
       
   254 TBool CEtelDriverFactory::HasContext(TContextId aId) const
       
   255     {
       
   256     return (iContexts[aId] != NULL);
       
   257     }
       
   258 
       
   259 
       
   260 /** context accessor
       
   261 
       
   262 @param aPdpId - id of a pdp context
       
   263 @return etel driver context
       
   264 */
       
   265 CEtelDriverContext& CEtelDriverFactory::Context(TContextId aId) 
       
   266 	{ 
       
   267 	// sanity check
       
   268 	__ASSERT_ALWAYS(iContexts[aId], User::Panic(KTxtSpudTel, KErrBadHandle));
       
   269 	return *iContexts[aId]->iContext; 
       
   270 	}