networkcontrol/qosfwconfig/qos/src/policies.cpp
changeset 0 af10295192d8
equal deleted inserted replaced
-1:000000000000 0:af10295192d8
       
     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 //
       
    15 
       
    16 #include "policies.h"
       
    17 #include "qoslog.h"
       
    18 
       
    19 #ifdef _LOG
       
    20 #include "qos_prot.h"	// for the TLogAddress class!
       
    21 
       
    22 // Dump selector
       
    23 void DumpSelector(const CSelectorBase& aSel)
       
    24 	{
       
    25 	TLogAddress dst(aSel.iDst);
       
    26 	TLogAddress dmsk(aSel.iDstMask);
       
    27 	TLogAddress src(aSel.iSrc);
       
    28 	TLogAddress smsk(aSel.iSrcMask);
       
    29 	Log::Printf(_L("\t\tsel(%d): src=%S - %d %S dst=%S - %d %S prot=%d name='%S' iap=%d uid(%d %d %d) pri=%d, owner=%d"),
       
    30 			aSel.iType,
       
    31 			&src, (TInt)aSel.iSrcPortMax, &smsk,
       
    32 			&dst, (TInt)aSel.iDstPortMax, &dmsk,
       
    33 			(TInt)aSel.iProtocol, &aSel.iName,
       
    34 			aSel.iIapId,
       
    35 			aSel.iUid.UidType()[0].iUid, aSel.iUid.UidType()[1].iUid, aSel.iUid.UidType()[2].iUid,
       
    36 			aSel.iPriority, aSel.iOwner);
       
    37 	}
       
    38 #endif
       
    39 
       
    40 //
       
    41 // CPolicySelector
       
    42 //
       
    43 CPolicySelector::CPolicySelector(TPfqosMessage& aMsg) :
       
    44   CSelectorBase(aMsg.iBase, aMsg.iSelector, aMsg.iSrcAddr, aMsg.iDstAddr, 
       
    45 				EPfqosFlowspecPolicy)
       
    46 	{
       
    47 	iType = EPfqosFlowspecPolicy;
       
    48 	LOG(Log::Printf(_L("new\tqos selector[%u] EPfqosFlowspecPolicy(%d) size=%d"), (TInt)this, iType, sizeof(CPolicySelector)));
       
    49 	}
       
    50 
       
    51 CPolicySelector::CPolicySelector(CSelectorBase& aSel) 
       
    52 	: CSelectorBase(aSel)
       
    53 	{
       
    54 	iType = EPfqosFlowspecPolicy;
       
    55 	LOG(Log::Printf(_L("new\tqos selector[%u] EPfqosFlowspecPolicy(%d) size=%d"), (TInt)this, iType, sizeof(CPolicySelector)));
       
    56 	}
       
    57 
       
    58 CPolicySelector::~CPolicySelector()
       
    59 	{
       
    60 	LOG(Log::Printf(_L("~\tqos selector[%u] EPfqosFlowspecPolicy(%d) -- done"), (TInt)this, iType));
       
    61 	}
       
    62 
       
    63 void CPolicySelector::SetQoSParameters(const TPfqosFlowSpec& aSpec)
       
    64 	{
       
    65 	if (!aSpec.iExt)
       
    66 		{
       
    67 		return;
       
    68 		}
       
    69 
       
    70 	// Uplink
       
    71 	iQoS.SetUpLinkDelay(aSpec.iExt->uplink_delay);
       
    72 	iQoS.SetUpLinkMaximumPacketSize(aSpec.iExt->uplink_maximum_packet_size);
       
    73 	iQoS.SetUpLinkAveragePacketSize(aSpec.iExt->uplink_average_packet_size);
       
    74 	iQoS.SetUpLinkPriority(aSpec.iExt->uplink_priority);
       
    75 	iQoS.SetUpLinkMaximumBurstSize(aSpec.iExt->uplink_maximum_burst_size);
       
    76 	iQoS.SetUplinkBandwidth(aSpec.iExt->uplink_bandwidth);
       
    77 	iQoS.SetName(aSpec.iExt->name);
       
    78 
       
    79 	// Downlink
       
    80 	iQoS.SetDownLinkDelay(aSpec.iExt->downlink_delay);
       
    81 	iQoS.SetDownLinkMaximumPacketSize(
       
    82 		aSpec.iExt->downlink_maximum_packet_size);
       
    83 	iQoS.SetDownLinkAveragePacketSize(
       
    84 		aSpec.iExt->downlink_average_packet_size);
       
    85 	iQoS.SetDownLinkPriority(aSpec.iExt->downlink_priority);
       
    86 	iQoS.SetDownLinkMaximumBurstSize(aSpec.iExt->downlink_maximum_burst_size);
       
    87 	iQoS.SetDownlinkBandwidth(aSpec.iExt->downlink_bandwidth);
       
    88 
       
    89 	// Flags
       
    90 	iQoS.SetFlags(aSpec.iExt->flags);
       
    91 	}
       
    92 
       
    93 
       
    94 //
       
    95 // CModuleSelector
       
    96 //
       
    97 CModuleSelector::CModuleSelector(TPfqosMessage& aMsg) 
       
    98 	: CSelectorBase(aMsg.iBase, aMsg.iSelector, aMsg.iSrcAddr, aMsg.iDstAddr, 
       
    99 					EPfqosModulespecPolicy), 
       
   100 	  iModules(_FOFF(CModuleSpec, iDLink))
       
   101 	{
       
   102 	iType = EPfqosModulespecPolicy;
       
   103 	LOG(Log::Printf(_L("new\tqos selector[%u] EPfqosModulespecPolicy(%d) size=%d"), (TInt)this, iType, sizeof(CPolicySelector)));
       
   104 	}
       
   105 
       
   106 
       
   107 CModuleSelector::CModuleSelector(CSelectorBase& aSel) 
       
   108 	: CSelectorBase(aSel), iModules(_FOFF(CModuleSpec, iDLink))
       
   109 	{
       
   110 	iType = EPfqosModulespecPolicy;
       
   111 	LOG(Log::Printf(_L("new\tqos selector[%u] EPfqosModulespecPolicy(%d) size=%d"), (TInt)this, iType, sizeof(CPolicySelector)));
       
   112 	}
       
   113 
       
   114 
       
   115 CModuleSelector::~CModuleSelector()
       
   116 	{
       
   117 	LOG(Log::Printf(_L("~\tqos selector[%u] EPfqosModulespecPolicy(%d) - destruct start"), (TInt)this, iType));
       
   118 	TDblQueIter<CModuleSpec> iter(iModules);
       
   119 	CModuleSpec* sel;
       
   120 
       
   121 	while ((sel = iter++) != NULL)
       
   122 		{
       
   123 		sel->iDLink.Deque();
       
   124 		delete sel;
       
   125 		}
       
   126 	LOG(Log::Printf(_L("~\tqos selector[%u] EPfqosModulespecPolicy(%d) - destruct complete"), (TInt)this, iType));
       
   127 	}
       
   128 
       
   129 void CModuleSelector::AddModuleSpec(CModuleSpec& aModule)
       
   130 	{
       
   131 	iModules.AddLast(aModule);
       
   132 	}
       
   133 
       
   134 void CModuleSelector::RemoveModuleSpec(CModuleSpec* aModule)
       
   135 	{
       
   136 	aModule->iDLink.Deque();
       
   137 	delete aModule;
       
   138 	}
       
   139 
       
   140 CModuleSpec* CModuleSelector::FindModuleSpec(TUint aProtocolId)
       
   141 	{
       
   142 	TDblQueIter<CModuleSpec> iter(iModules);
       
   143 	CModuleSpec* sel;
       
   144 
       
   145 	while ((sel = iter++) != NULL)
       
   146 		{
       
   147 		if (sel->ProtocolId() == aProtocolId)
       
   148 			{
       
   149 			return sel;
       
   150 			}
       
   151 		}
       
   152 	return NULL;
       
   153 	}
       
   154 
       
   155 //
       
   156 // CModuleSpec
       
   157 //
       
   158 CModuleSpec* CModuleSpec::NewL(const TDesC& aFileName, 
       
   159 							   const TDesC& aModuleName)
       
   160 	{
       
   161 	CModuleSpec* moduleSpec = new (ELeave) CModuleSpec();
       
   162 	CleanupStack::PushL(moduleSpec);
       
   163 	moduleSpec->ContructL(aFileName, aModuleName);
       
   164 	CleanupStack::Pop();
       
   165 	return moduleSpec;
       
   166 	}
       
   167 
       
   168 CModuleSpec* CModuleSpec::NewL(const TPfqosModule& aModule)
       
   169 	{
       
   170 	CModuleSpec* moduleSpec = new (ELeave) CModuleSpec();
       
   171 	CleanupStack::PushL(moduleSpec);
       
   172 	moduleSpec->ContructL(aModule);
       
   173 	CleanupStack::Pop();
       
   174 	return moduleSpec;
       
   175 	}
       
   176 
       
   177 void CModuleSpec::ContructL(const TPfqosModule& aModule)
       
   178 	{
       
   179 	iExtension = CExtension::NewL();
       
   180 	iExtension->CopyL(aModule.iData);
       
   181 	TPtrC8 fileName((TUint8*)aModule.iExt->path);
       
   182 	iFileName.Copy(fileName);
       
   183 	TPtrC8 moduleName((TUint8*)aModule.iExt->name);
       
   184 	iName.Copy(moduleName);
       
   185 	iProtocolId = aModule.iExt->protocol_id;
       
   186 	iFlags = aModule.iExt->flags;
       
   187 	}
       
   188 
       
   189 void CModuleSpec::ContructL(const TDesC& aFileName, const TDesC& aModuleName)
       
   190 	{
       
   191 	iExtension = CExtension::NewL();
       
   192 	iFileName.Copy(aFileName);
       
   193 	iName.Copy(aModuleName);
       
   194 	iProtocolId = 0;
       
   195 	iFlags = 0;
       
   196 	}
       
   197 
       
   198 CModuleSpec::CModuleSpec()
       
   199 	{
       
   200 	LOG(Log::Printf(_L("new\tqos ModuleSpec[%u] size=%d"), (TInt)this, sizeof(CModuleSpec)));
       
   201 	iProtocolId = 0;
       
   202 	iFlags = 0;
       
   203 	iFileName.FillZ();
       
   204 	iName.FillZ();
       
   205 	}
       
   206 
       
   207 
       
   208 CModuleSpec::~CModuleSpec()
       
   209 	{
       
   210 	delete iExtension;
       
   211 	LOG(Log::Printf(_L("~\tqos ModuleSpec[%u] deleted"), (TInt)this));
       
   212 	}