networkcontrol/qoslib/src/qos_policy.cpp
changeset 0 af10295192d8
equal deleted inserted replaced
-1:000000000000 0:af10295192d8
       
     1 // Copyright (c) 2003-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 //
       
    15 
       
    16 #include "qoslib.h"
       
    17 #include "qoslib_glob.h"
       
    18 #include "pfqos_stream.h"
       
    19 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    20 #include <networking/qoslib_internal.h>
       
    21 #endif
       
    22 
       
    23 /**
       
    24 Default constructor. 
       
    25 
       
    26 RQoSPolicy::Open() must always be called before any other 
       
    27 methods in the RQoSPolicy can be called. 
       
    28 
       
    29 @publishedPartner
       
    30 @released
       
    31 @capability NetworkControl Restrict QoS policy operations because they may 
       
    32 affect several data flows.
       
    33 */
       
    34 EXPORT_C RQoSPolicy::RQoSPolicy() : iPolicy(NULL)
       
    35 	{
       
    36 	}
       
    37 
       
    38 /**
       
    39 Destructor. 
       
    40  
       
    41 Closes any open policy. 
       
    42 
       
    43 @publishedPartner
       
    44 @released
       
    45 @capability NetworkControl Restrict QoS policy operations because they may 
       
    46 affect several data flows.
       
    47 */
       
    48 EXPORT_C RQoSPolicy::~RQoSPolicy()
       
    49 	{
       
    50 	if (iPolicy)
       
    51 		iPolicy->Close();
       
    52 	}
       
    53 
       
    54 /**
       
    55 This must always be called before any other function can be used. 
       
    56  
       
    57 It specifies the selector for a QoS policy. 
       
    58  
       
    59 @publishedPartner
       
    60 @released
       
    61 @capability NetworkControl Restrict QoS policy operations because they may 
       
    62 affect several data flows.
       
    63 @param aSelector Selector for the QoS policy.
       
    64 @return KErrNone, if successful; otherwise, an error code if the QoS channel 
       
    65 cannot be opened. 
       
    66 */
       
    67 EXPORT_C TInt RQoSPolicy::Open(const TQoSSelector& aSelector)
       
    68 	{
       
    69 	if (iPolicy)
       
    70 		return KErrAlreadyExists;
       
    71 	CQoSMan* manager = NULL;
       
    72 	TRAPD(err,
       
    73 		manager = CQoSMan::NewL();
       
    74 		// There is manager->Open() in above NewL.
       
    75 		// How and when is that cancelled, if leave happens below? --msa
       
    76 		iPolicy = manager->OpenQoSPolicyL(aSelector)
       
    77 		);
       
    78 	return err;
       
    79 	}
       
    80 
       
    81 /**
       
    82 Sets the QoS parameters for the QoS policy. 
       
    83  
       
    84 A CQoSAddEvent event is received asynchronously to indicate the success or 
       
    85 failure of the request. 
       
    86  
       
    87 @publishedPartner
       
    88 @released
       
    89 @capability NetworkControl Restrict QoS policy operations because they may 
       
    90 affect several data flows.
       
    91 @param aPolicy QoS parameters.
       
    92 @return KErrNone, if successful; otherwise, an error code. 
       
    93 */
       
    94 EXPORT_C TInt RQoSPolicy::SetQoS(CQoSParameters& aPolicy)
       
    95 	{
       
    96 	if (!iPolicy)
       
    97 		return KErrNotReady;
       
    98 	TRAPD(err, iPolicy->SetQoSL(aPolicy));
       
    99 	return err;
       
   100 	}
       
   101 
       
   102 /**
       
   103 Gets the QoS policy from QoS policy database. 
       
   104 
       
   105 A CQoSGetEvent event is received asynchronously to indicate the success or 
       
   106 failure of the request.
       
   107  
       
   108 @publishedPartner
       
   109 @released
       
   110 @capability NetworkControl Restrict QoS policy operations because they may 
       
   111 affect several data flows.
       
   112 @return KErrNone, if successful; otherwise, an error code. 
       
   113 */
       
   114 EXPORT_C TInt RQoSPolicy::GetQoS()
       
   115 	{
       
   116 	if (!iPolicy)
       
   117 		return KErrNotReady;
       
   118 	TRAPD(err, iPolicy->GetQoSL());
       
   119 	return err;
       
   120 	}
       
   121 
       
   122 /**
       
   123 Deletes the QoS policy.
       
   124  
       
   125 @publishedPartner
       
   126 @released
       
   127 @capability NetworkControl Restrict QoS policy operations because they may 
       
   128 affect several data flows.
       
   129 @return KErrNone, if successful; otherwise, an error code (e.g. if 
       
   130 RQoSPolicy::Open() was not called).
       
   131 */
       
   132 EXPORT_C TInt RQoSPolicy::Close()
       
   133 	{
       
   134 	if (!iPolicy)
       
   135 		return KErrNotReady;
       
   136 	TRAPD(err, iPolicy->DeleteL());
       
   137 	if (err == KErrNone)
       
   138 		{
       
   139 		iPolicy->Close();
       
   140 		iPolicy = NULL;
       
   141 		}
       
   142 	return err;
       
   143 	}
       
   144 
       
   145 /**
       
   146 Registers an event observer to catch QoS events.
       
   147 
       
   148 @publishedPartner
       
   149 @released
       
   150 @capability NetworkControl Restrict QoS policy operations because they may 
       
   151 affect several data flows.
       
   152 @param aObserver Event observer.
       
   153 @param aMask An event mask. An application can specify a set of QoS events 
       
   154 that it wants to receive. By default all events are notified to the 
       
   155 application. See TQoSEvent enumerations.
       
   156 @return KErrNone, if successful; otherwise, an error code. 
       
   157 */
       
   158 EXPORT_C TInt RQoSPolicy::NotifyEvent(MQoSObserver& aObserver, TUint aMask)
       
   159 	{
       
   160 	if (!iPolicy)
       
   161 		return KErrNotReady;
       
   162 	return iPolicy->NotifyEvent(aObserver, aMask);
       
   163 	}
       
   164 
       
   165 /**
       
   166 Deregisters an event observer to catch QoS events. 
       
   167  
       
   168 @publishedPartner
       
   169 @released
       
   170 @capability NetworkControl Restrict QoS policy operations because they may 
       
   171 affect several data flows.
       
   172 @param aObserver Event observer.
       
   173 @return KErrNone if successful, otherwise an error code. 
       
   174 */
       
   175 EXPORT_C TInt RQoSPolicy::CancelNotifyEvent(MQoSObserver& aObserver)
       
   176 	{
       
   177 	if (!iPolicy)
       
   178 		return KErrNotReady;
       
   179 	return iPolicy->CancelNotifyEvent(aObserver);
       
   180 	}
       
   181 
       
   182 /**
       
   183 Loads a QoS policy file into the QoS policy database. 
       
   184  
       
   185 A TQoSEvent event (EQoSEventLoadPolicyFile) is received asynchronously to 
       
   186 indicate the success or failure of the request. 
       
   187  
       
   188 @publishedPartner
       
   189 @released
       
   190 @capability NetworkControl Restrict QoS policy operations because they may 
       
   191 affect several data flows.
       
   192 @param aName Name of the QoS policy file to be loaded.
       
   193 @return KErrNone, if successful; otherwise, an error code. 
       
   194 */
       
   195 EXPORT_C TInt RQoSPolicy::LoadPolicyFile(const TDesC& aName)
       
   196 	{
       
   197 	if (!iPolicy)
       
   198 		return KErrNotReady;
       
   199 	TRAPD(err, iPolicy->LoadFileL(aName));
       
   200 	return err;
       
   201 	}
       
   202 
       
   203 /**
       
   204 Unloads a QoS policy file from the QoS policy database. 
       
   205  
       
   206 A TQoSEvent event (EQoSEventUnloadPolicyFile) is received asynchronously to 
       
   207 indicate the success or failure of the request. 
       
   208  
       
   209 @publishedPartner
       
   210 @released
       
   211 @capability NetworkControl Restrict QoS policy operations because they may 
       
   212 affect several data flows.
       
   213 @param aName Name of the QoS policy file to be unloaded.
       
   214 @return KErrNone, if successful; otherwise, an error code. 
       
   215 */
       
   216 EXPORT_C TInt RQoSPolicy::UnloadPolicyFile(const TDesC& aName)
       
   217 	{
       
   218 	if (!iPolicy)
       
   219 		return KErrNotReady;
       
   220 	TRAPD(err, iPolicy->UnloadFileL(aName));
       
   221 	return err;
       
   222 	}
       
   223 
       
   224 
       
   225 //
       
   226 CQoSRequestBase::~CQoSRequestBase()
       
   227 	{
       
   228 	iManager->ClearPendingRequest(this);
       
   229 	iManager->Close();
       
   230 	}
       
   231 
       
   232 void CQoSRequestBase::ParseExtensions(TPfqosMessage& aMsg, CQoSParameters& aPolicy)
       
   233 	{
       
   234 	aMsg.SetQoSParameters(aPolicy.iQoS);
       
   235 	TSglQueIter<CPfqosPolicyData> iter(aMsg.iExtensions);
       
   236 	CPfqosPolicyData *data;
       
   237 
       
   238 	while ((data = iter++) != NULL)
       
   239 		{
       
   240 		TInt extensionType;
       
   241 		TInt ret = GetExtensionType(data->Data(), extensionType);
       
   242 		if (ret == KErrNone)
       
   243 			{
       
   244 			CExtensionBase *ext = aPolicy.FindExtension(extensionType);
       
   245 			if (ext)
       
   246 				ext->ParseMessage(data->Data());
       
   247 			}
       
   248 		}
       
   249 	}
       
   250 
       
   251 TInt CQoSRequestBase::GetExtensionType(const TDesC8& aData, TInt& aType)
       
   252 	{
       
   253 	const TUint8 *p = aData.Ptr();
       
   254 	TInt length = aData.Length();
       
   255 	//lint -e{826} thinks this cast is suspicious -- is not!
       
   256 	struct pfqos_configure *ext = (struct pfqos_configure *) p;
       
   257 
       
   258 	if (length < (TInt)sizeof(pfqos_configure))
       
   259 		return KErrGeneral;	 // EMSGSIZE (impossible message size)
       
   260 
       
   261 	if (ext->pfqos_configure_len * 8 != length)
       
   262 		return KErrGeneral;	 // EMSGSIZE (incorrect message length)
       
   263 
       
   264 	if (ext->pfqos_ext_type != EPfqosExtExtension)
       
   265 		return KErrGeneral;
       
   266 
       
   267 	p += sizeof(struct pfqos_configure);
       
   268 	//lint -e{826} thinks this cast is suspicious -- is not!
       
   269 	pfqos_extension *extensionType = (pfqos_extension *) p;
       
   270 	aType = extensionType->pfqos_extension_type;
       
   271 	return KErrNone;
       
   272 	}
       
   273 
       
   274 TInt CQoSRequestBase::NotifyEvent(MQoSObserver& aObserver, TUint aMask)
       
   275 	{
       
   276 	if (aMask & ~KQoSEventAll)
       
   277 		return KErrNotSupported;
       
   278 	iEventMask = aMask;
       
   279 	iObserver = &aObserver;
       
   280 	return KErrNone;
       
   281 	}
       
   282 
       
   283 TInt CQoSRequestBase::CancelNotifyEvent(MQoSObserver& aObserver)
       
   284 	{
       
   285 	if (iObserver != &aObserver)
       
   286 		return KErrNotFound;
       
   287 	iObserver = NULL;
       
   288 	return KErrNone;
       
   289 	}
       
   290 
       
   291 
       
   292 //
       
   293 CPolicy* CPolicy::NewL(CQoSMan* aManager, const TQoSSelector& aSelector)
       
   294 	{
       
   295 	CPolicy* policy = new (ELeave) CPolicy(aManager, aSelector);
       
   296 	return policy;
       
   297 	}
       
   298 
       
   299 CPolicy::CPolicy(CQoSMan* aManager, const TQoSSelector& aSelector)
       
   300 	{
       
   301 	iManager = aManager;
       
   302 	iSelector = aSelector;
       
   303 	iPending = ENone;
       
   304 	iPolicyCreated = EFalse;
       
   305 	}
       
   306 
       
   307 CPolicy::~CPolicy()
       
   308 	{
       
   309 	iManager->RemoveQoSPolicy(this);
       
   310 	}
       
   311 
       
   312 void CPolicy::Close()
       
   313 	{
       
   314 	delete this;
       
   315 	}
       
   316 
       
   317 TBool CPolicy::Match(const TQoSSelector& aSelector)
       
   318 	{
       
   319 	return (iSelector == aSelector);
       
   320 	}
       
   321 
       
   322 void CPolicy::SetQoSL(CQoSParameters& aPolicy)
       
   323 	{
       
   324 	if (iPending != ENone)
       
   325 		User::Leave(KErrInUse);
       
   326 	iPolicy.CopyL(aPolicy);
       
   327 	CRequest* request = CRequest::NewL(this, KQoSDefaultBufSize);
       
   328 	if (iPolicyCreated)
       
   329 		{
       
   330 		request->iMsg->Init(EPfqosUpdate);
       
   331 		iPending = EPendingUpdate;
       
   332 		}
       
   333 	else
       
   334 		{
       
   335 		request->iMsg->Init(EPfqosAdd);
       
   336 		iPending = EPendingAdd;
       
   337 		}
       
   338 	request->iMsg->AddSelector((TUint8)iSelector.Protocol(), 
       
   339 							   iManager->Uid().UidType(), 
       
   340 							   EPfqosFlowspecPolicy, 
       
   341 							   iSelector.IapId(), 
       
   342 							   EPfqosApplicationPriority, 
       
   343 							   TPtr(0,0));
       
   344 	request->iMsg->AddSrcAddress(iSelector.GetSrc(), 
       
   345 								 iSelector.GetSrcMask(), 
       
   346 								 (TUint16)iSelector.MaxPortSrc()); 
       
   347 	request->iMsg->AddDstAddress(iSelector.GetDst(), 
       
   348 								 iSelector.GetDstMask(), 
       
   349 								 (TUint16)iSelector.MaxPortDst()); 
       
   350 	request->iMsg->AddQoSParameters(iPolicy.iQoS);
       
   351 	
       
   352 	TQoSExtensionQueueIter iter(iPolicy.Extensions());
       
   353 	CExtensionBase *extension;
       
   354 	while ((extension=iter++) != NULL)
       
   355 		request->iMsg->AddExtensionPolicy(extension->Data());
       
   356 	iManager->Send(request);
       
   357 
       
   358 	}
       
   359 
       
   360 void CPolicy::GetQoSL()
       
   361 	{
       
   362 
       
   363 	if (iPending != ENone)
       
   364 		User::Leave(KErrInUse);
       
   365 	CRequest* request = CRequest::NewL(this, KQoSDefaultBufSize);
       
   366 	request->iMsg->Init(EPfqosGet);
       
   367 	iPending = EPendingGet;
       
   368 	request->iMsg->AddSelector((TUint8)iSelector.Protocol(), 
       
   369 							   iManager->Uid().UidType(), 
       
   370 							   EPfqosFlowspecPolicy, 
       
   371 							   iSelector.IapId(), 
       
   372 							   EPfqosApplicationPriority, 
       
   373 							   TPtr(0,0));
       
   374 	request->iMsg->AddSrcAddress(iSelector.GetSrc(), 
       
   375 								 iSelector.GetSrcMask(), 
       
   376 								 (TUint16)iSelector.MaxPortSrc()); 
       
   377 	request->iMsg->AddDstAddress(iSelector.GetDst(), 
       
   378 								 iSelector.GetDstMask(), 
       
   379 								 (TUint16)iSelector.MaxPortDst()); 
       
   380 	
       
   381 	TQoSExtensionQueueIter iter(iPolicy.Extensions());
       
   382 	CExtensionBase *extension;
       
   383 	while ((extension=iter++) != NULL)
       
   384 		request->iMsg->AddExtensionPolicy(extension->Data());
       
   385 	iManager->Send(request);
       
   386 
       
   387 	}
       
   388 
       
   389 void CPolicy::DeleteL()
       
   390 	{
       
   391 	CRequest* request = CRequest::NewL(this,KQoSDefaultBufSize);
       
   392 	request->iMsg->Init(EPfqosDelete);
       
   393 	iPending = EPendingDelete;
       
   394 	request->iMsg->AddSelector((TUint8)iSelector.Protocol(), 
       
   395 							   iManager->Uid().UidType(), 
       
   396 							   EPfqosFlowspecPolicy, 
       
   397 							   iSelector.IapId(), 
       
   398 							   EPfqosApplicationPriority, 
       
   399 							   TPtr(0,0));
       
   400 	request->iMsg->AddSrcAddress(iSelector.GetSrc(), 
       
   401 								 iSelector.GetSrcMask(), 
       
   402 								 (TUint16)iSelector.MaxPortSrc()); 
       
   403 	request->iMsg->AddDstAddress(iSelector.GetDst(), 
       
   404 								 iSelector.GetDstMask(), 
       
   405 								 (TUint16)iSelector.MaxPortDst()); 
       
   406 	
       
   407 	TQoSExtensionQueueIter iter(iPolicy.Extensions());
       
   408 	CExtensionBase *item;
       
   409 	while ((item = iter++) != NULL)
       
   410 		request->iMsg->AddExtensionHeader((TUint16)item->Type());
       
   411 
       
   412 	iManager->Send(request);
       
   413 	}
       
   414 
       
   415 void CPolicy::ProcessReply(TPfqosMessage& aMsg)
       
   416 	{
       
   417 	TInt aErrorCode = aMsg.iBase.iMsg->pfqos_msg_errno;
       
   418 
       
   419 
       
   420 
       
   421 	TPendingStatus status = iPending;
       
   422 
       
   423 	if (aErrorCode)
       
   424 		{
       
   425 		if (status == EPendingLoadFile || status == EPendingUnloadFile)
       
   426 			{
       
   427 			iPending = ENone;
       
   428 #if _UNICODE
       
   429 			TPtrC8 tmp((TUint8*)aMsg.iConfigFile.iExt->filename);
       
   430 			TFileName filename;
       
   431 			filename.Copy(tmp);
       
   432 #else
       
   433 			TPtrC8 filename((TUint8*)aMsg.iConfigFile.iExt->filename);
       
   434 #endif
       
   435 			TQoSEvent event_type;
       
   436 			if (status == EPendingLoadFile)
       
   437 				event_type = EQoSEventLoadPolicyFile;
       
   438 			else
       
   439 				event_type = EQoSEventUnloadPolicyFile;
       
   440 			CQoSLoadEvent event(event_type, aErrorCode, filename);
       
   441 			if (iObserver && iEventMask & EQoSEventLoadPolicyFile)
       
   442 				iObserver->Event(event);
       
   443 			}
       
   444 		else
       
   445 			{
       
   446 			NotifyError(aErrorCode);
       
   447 			}
       
   448 		}
       
   449 	else
       
   450 		{
       
   451 		iPending = ENone;
       
   452 
       
   453 		switch (status)
       
   454 			{
       
   455 		case EPendingAdd:
       
   456 			{
       
   457 			CQoSParameters policy;
       
   458 			ParseExtensions(aMsg, policy);
       
   459 			CQoSAddEvent event(&policy, aErrorCode);
       
   460 			if (iObserver && iEventMask & EQoSEventAddPolicy)
       
   461 				iObserver->Event(event);
       
   462 			iPolicyCreated = ETrue;
       
   463 			}
       
   464 			break;
       
   465 
       
   466 		case EPendingUpdate:
       
   467 			{
       
   468 			CQoSParameters policy;
       
   469 			ParseExtensions(aMsg, policy);
       
   470 			CQoSAddEvent event(&policy, aErrorCode);
       
   471 			if (iObserver && iEventMask & EQoSEventAddPolicy)
       
   472 				iObserver->Event(event);
       
   473 			}
       
   474 			break;
       
   475 
       
   476 		case EPendingDelete:
       
   477 			{
       
   478 			iPending = ENone;
       
   479 			CQoSDeleteEvent event(aErrorCode);
       
   480 			if (iObserver && iEventMask & EQoSEventDeletePolicy)
       
   481 				iObserver->Event(event);
       
   482 			}
       
   483 			break;
       
   484 
       
   485 		case EPendingGet:
       
   486 			{
       
   487 			CQoSParameters policy;
       
   488 
       
   489 
       
   490 			ParseExtensions(aMsg, policy);
       
   491 
       
   492 
       
   493 			CQoSGetEvent event(&policy, aErrorCode);
       
   494 
       
   495 
       
   496 			if (iObserver && iEventMask & EQoSEventGetPolicy)
       
   497 				iObserver->Event(event);
       
   498 			}
       
   499 			break;
       
   500 
       
   501 		case EPendingLoadFile:
       
   502 		case EPendingUnloadFile:
       
   503 			{
       
   504 #if _UNICODE
       
   505 			TPtrC8 tmp((TUint8*)aMsg.iConfigFile.iExt->filename);
       
   506 			TFileName filename;
       
   507 			filename.Copy(tmp);
       
   508 #else
       
   509 			TPtrC8 filename((TUint8*)aMsg.iConfigFile.iExt->filename);
       
   510 #endif
       
   511 			TQoSEvent event_type;
       
   512 			if (status == EPendingLoadFile)
       
   513 				event_type = EQoSEventLoadPolicyFile;
       
   514 			else
       
   515 				event_type = EQoSEventUnloadPolicyFile;
       
   516 			CQoSLoadEvent event(event_type, KErrNone, filename);
       
   517 			if (iObserver && iEventMask & EQoSEventLoadPolicyFile)
       
   518 				iObserver->Event(event);
       
   519 			}
       
   520 			break;
       
   521 
       
   522 		default:
       
   523 			break;
       
   524 			}
       
   525 		}
       
   526 	}
       
   527 
       
   528 TBool CPolicy::MatchReply(const TPfqosMessage& aMsg, TUint8 aMsgType)
       
   529 	{
       
   530 	if (((iPending == EPendingAdd && aMsgType == EPfqosAdd) ||
       
   531 	 (iPending == EPendingUpdate && aMsgType == EPfqosUpdate) ||
       
   532 	 (iPending == EPendingGet && aMsgType == EPfqosGet) ||
       
   533 	 (iPending == EPendingDelete && aMsgType == EPfqosDelete) ||
       
   534 	 (iPending == EPendingLoadFile && aMsgType == EPfqosLoadFile) ||
       
   535 	 (iPending == EPendingUnloadFile && aMsgType == EPfqosUnloadFile)) &&
       
   536 	(iSelector.GetDst().Match(*aMsg.iDstAddr.iAddr)) &&
       
   537 	(iSelector.GetSrc().Match(*aMsg.iSrcAddr.iAddr)) &&
       
   538 	(iSelector.Protocol() == aMsg.iSelector.iExt->protocol) &&
       
   539 	(iSelector.GetDst().Port() == aMsg.iDstAddr.iAddr->Port()) &&
       
   540 	(iSelector.GetSrc().Port() == aMsg.iSrcAddr.iAddr->Port()) &&
       
   541 	(iSelector.MaxPortDst() == aMsg.iDstAddr.iExt->pfqos_port_max) &&
       
   542 	(iSelector.MaxPortSrc() == aMsg.iSrcAddr.iExt->pfqos_port_max))
       
   543 		return ETrue;
       
   544 
       
   545 	return EFalse;
       
   546 	}
       
   547 
       
   548 void CPolicy::ProcessEvent(TPfqosMessage& aMsg)
       
   549 	{
       
   550 	if ((iSelector.GetDst().Match(*aMsg.iDstAddr.iAddr)) &&
       
   551 	(iSelector.GetSrc().Match(*aMsg.iSrcAddr.iAddr)) &&
       
   552 	(iSelector.Protocol() == aMsg.iSelector.iExt->protocol) &&
       
   553 	(iSelector.GetDst().Port() == aMsg.iDstAddr.iAddr->Port()) &&
       
   554 	(iSelector.GetSrc().Port() == aMsg.iSrcAddr.iAddr->Port()) &&
       
   555 	(iSelector.MaxPortDst() == aMsg.iDstAddr.iExt->pfqos_port_max) &&
       
   556 	(iSelector.MaxPortSrc() == aMsg.iSrcAddr.iExt->pfqos_port_max))
       
   557 		{
       
   558 		iCapabilities = aMsg.iEvent.iExt->event_value;
       
   559 
       
   560 		switch (aMsg.iEvent.iExt->event_type)
       
   561 			{
       
   562 		case KPfqosEventFailure:
       
   563 			if (iObserver && iEventMask & EQoSEventFailure)
       
   564 				{
       
   565 				ParseExtensions(aMsg, iPolicy);
       
   566 				CQoSFailureEvent event(iPolicy, aMsg.iBase.iMsg->pfqos_msg_errno);
       
   567 				iObserver->Event(event);
       
   568 				}
       
   569 			break;
       
   570 
       
   571 		case KPfqosEventConfirm:
       
   572 			if (iObserver && iEventMask & EQoSEventConfirm)
       
   573 				{
       
   574 				ParseExtensions(aMsg, iPolicy);
       
   575 				CQoSConfirmEvent event(iPolicy);
       
   576 				iObserver->Event(event);
       
   577 		  		}
       
   578 			break;
       
   579 
       
   580 		case KPfqosEventAdapt:
       
   581 			if (iObserver && iEventMask & EQoSEventAdapt)
       
   582 				{
       
   583 				ParseExtensions(aMsg, iPolicy);
       
   584 				CQoSAdaptEvent event(iPolicy, aMsg.iBase.iMsg->pfqos_msg_errno);
       
   585 				iObserver->Event(event);
       
   586 				}
       
   587 			break;
       
   588 
       
   589 		default:
       
   590 			return;
       
   591 			}
       
   592 		}
       
   593 	}
       
   594 
       
   595 void CPolicy::NotifyError(TInt aReason)
       
   596 	{
       
   597 	TPendingStatus status = iPending;
       
   598 	iPending = ENone;
       
   599 
       
   600 	if (aReason)
       
   601 		{
       
   602 		switch (status)
       
   603 			{
       
   604 		case EPendingAdd:
       
   605 		case EPendingUpdate:
       
   606 			{
       
   607 			CQoSAddEvent event(&iPolicy, aReason);
       
   608 			if (iObserver && iEventMask & EQoSEventAddPolicy)
       
   609 				iObserver->Event(event);
       
   610 			}
       
   611 			break;
       
   612 
       
   613 		case EPendingGet:
       
   614 			{
       
   615 			CQoSGetEvent event(NULL, aReason);
       
   616 			if (iObserver && iEventMask & EQoSEventGetPolicy)
       
   617 				iObserver->Event(event);
       
   618 			}
       
   619 			break;
       
   620 
       
   621 		case EPendingDelete:
       
   622 			{
       
   623 			CQoSDeleteEvent event(aReason);
       
   624 			if (iObserver && iEventMask & EQoSEventDeletePolicy)
       
   625 				iObserver->Event(event);
       
   626 			}
       
   627 			break;
       
   628 
       
   629 		default:
       
   630 			break;
       
   631 			}
       
   632 		}
       
   633 	}
       
   634 
       
   635 
       
   636 void CPolicy::LoadFileL(const TDesC& aName)
       
   637 	{
       
   638 	if (iPending != ENone)
       
   639 		User::Leave(KErrInUse);
       
   640 	if (aName.Length() > KMaxFileName)
       
   641 		User::Leave(KErrArgument);
       
   642 	CRequest* request = CRequest::NewL(this, KQoSDefaultBufSize);
       
   643 	request->iMsg->Init(EPfqosLoadFile);
       
   644 	iPending = EPendingLoadFile;
       
   645 	request->iMsg->AddSelector((TUint8)iSelector.Protocol(), 
       
   646 							   iManager->Uid().UidType(), 
       
   647 							   EPfqosFlowspecPolicy, 
       
   648 							   iSelector.IapId(), 
       
   649 							   EPfqosApplicationPriority, 
       
   650 							   TPtr(0,0));
       
   651 	request->iMsg->AddSrcAddress(iSelector.GetSrc(), 
       
   652 								 iSelector.GetSrcMask(), 
       
   653 								 (TUint16)iSelector.MaxPortSrc()); 
       
   654 	request->iMsg->AddDstAddress(iSelector.GetDst(), 
       
   655 								 iSelector.GetDstMask(), 
       
   656 								 (TUint16)iSelector.MaxPortDst());
       
   657 	request->iMsg->AddConfigFile(aName);
       
   658 	iManager->Send(request);
       
   659 	}
       
   660 
       
   661 void CPolicy::UnloadFileL(const TDesC& aName)
       
   662 	{
       
   663 	if (iPending != ENone)
       
   664 		User::Leave(KErrInUse);
       
   665 	if (aName.Length() > KMaxFileName)
       
   666 		User::Leave(KErrArgument);
       
   667 	CRequest* request = CRequest::NewL(this, KQoSDefaultBufSize);
       
   668 	request->iMsg->Init(EPfqosUnloadFile);
       
   669 	iPending = EPendingUnloadFile;
       
   670 	request->iMsg->AddSelector((TUint8)iSelector.Protocol(), 
       
   671 							   iManager->Uid().UidType(), 
       
   672 							   EPfqosFlowspecPolicy, 
       
   673 							   iSelector.IapId(), 
       
   674 							   EPfqosApplicationPriority, 
       
   675 							   TPtr(0,0));
       
   676 	request->iMsg->AddSrcAddress(iSelector.GetSrc(), 
       
   677 								 iSelector.GetSrcMask(), 
       
   678 								 (TUint16)iSelector.MaxPortSrc()); 
       
   679 	request->iMsg->AddDstAddress(iSelector.GetDst(), 
       
   680 								 iSelector.GetDstMask(), 
       
   681 								 (TUint16)iSelector.MaxPortDst());
       
   682 	request->iMsg->AddConfigFile(aName);
       
   683 	iManager->Send(request);
       
   684 	}