1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * implementation for simple NTB build policy |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 /** |
|
21 @file |
|
22 @internalComponent |
|
23 */ |
|
24 |
|
25 |
|
26 #include "ncmntbbuildsimplepolicy.h" |
|
27 #include "ncmntbbuilder.h" |
|
28 #include "ncmpktdrvcommon.h" |
|
29 #include "OstTraceDefinitions.h" |
|
30 #ifdef OST_TRACE_COMPILER_IN_USE |
|
31 #include "ncmntbbuildsimplepolicyTraces.h" |
|
32 #endif |
|
33 |
|
34 |
|
35 |
|
36 const TInt KMaxPacketsOfNtb = 10; |
|
37 const TInt KMaxPacketDelay = 1000; |
|
38 const TInt KMinFreeBuffers = 5; |
|
39 |
|
40 |
|
41 _LIT(KSimPolicyPanic, "CNcmNtbBuildSimplePolicy"); |
|
42 const TInt KTimerError = 1; |
|
43 |
|
44 |
|
45 // ======== MEMBER FUNCTIONS ======== |
|
46 // |
|
47 |
|
48 |
|
49 CNcmNtbBuildPolicy* CNcmNtbBuildSimplePolicy::NewL(CNcmNtbBuilder& aNtbBuilder) |
|
50 { |
|
51 OstTraceFunctionEntry1( CNCMNTBBUILDSIMPLEPOLICY_NEWL_ENTRY, ( TUint )&( aNtbBuilder ) ); |
|
52 CNcmNtbBuildSimplePolicy *self=new (ELeave) CNcmNtbBuildSimplePolicy(aNtbBuilder); |
|
53 CleanupStack::PushL(self); |
|
54 self->ConstructL(); |
|
55 CleanupStack::Pop(); |
|
56 OstTraceFunctionExit0( CNCMNTBBUILDSIMPLEPOLICY_NEWL_EXIT ); |
|
57 return self; |
|
58 } |
|
59 |
|
60 CNcmNtbBuildSimplePolicy::CNcmNtbBuildSimplePolicy(CNcmNtbBuilder& aNtbBuilder) |
|
61 : CNcmNtbBuildPolicy(aNtbBuilder) |
|
62 { |
|
63 CActiveScheduler::Add(this); |
|
64 } |
|
65 |
|
66 CNcmNtbBuildSimplePolicy::~CNcmNtbBuildSimplePolicy() |
|
67 { |
|
68 OstTraceFunctionEntry1( CNCMNTBBUILDSIMPLEPOLICY_CNCMNTBBUILDSIMPLEPOLICY_ENTRY, this ); |
|
69 Cancel(); |
|
70 iTimer.Close(); |
|
71 OstTraceFunctionExit1( CNCMNTBBUILDSIMPLEPOLICY_CNCMNTBBUILDSIMPLEPOLICY_EXIT, this ); |
|
72 } |
|
73 |
|
74 void CNcmNtbBuildSimplePolicy::DoCancel() |
|
75 { |
|
76 OstTraceFunctionEntry1( CNCMNTBBUILDSIMPLEPOLICY_DOCANCEL_ENTRY, this ); |
|
77 iTimer.Cancel(); |
|
78 iPacketsCount = 0; |
|
79 OstTraceFunctionExit1( CNCMNTBBUILDSIMPLEPOLICY_DOCANCEL_EXIT, this ); |
|
80 } |
|
81 |
|
82 |
|
83 void CNcmNtbBuildSimplePolicy::ConstructL() |
|
84 { |
|
85 User::LeaveIfError(iTimer.CreateLocal()); |
|
86 } |
|
87 |
|
88 void CNcmNtbBuildSimplePolicy::RunL() |
|
89 { |
|
90 OstTraceFunctionEntry1( CNCMNTBBUILDSIMPLEPOLICY_RUNL_ENTRY, this ); |
|
91 OstTrace1( TRACE_NORMAL, CNCMNTBBUILDSIMPLEPOLICY_RUNL, "CNcmNtbBuildSimplePolicy::RunL Status=%d", iStatus.Int() ); |
|
92 |
|
93 if(iStatus.Int() != KErrNone) |
|
94 { |
|
95 User::Panic(KSimPolicyPanic, KTimerError); |
|
96 OstTraceFunctionExit1( CNCMNTBBUILDSIMPLEPOLICY_RUNL_EXIT, this ); |
|
97 return; |
|
98 } |
|
99 |
|
100 if (iPacketsCount > 0) |
|
101 { |
|
102 iNtbBuilder.CompleteNtbBuild(); |
|
103 } |
|
104 OstTraceFunctionExit1( CNCMNTBBUILDSIMPLEPOLICY_RUNL_EXIT_DUP1, this ); |
|
105 } |
|
106 |
|
107 void CNcmNtbBuildSimplePolicy::CompleteNtbBuild() |
|
108 { |
|
109 OstTraceFunctionEntry1( CNCMNTBBUILDSIMPLEPOLICY_COMPLETENTBBUILD_ENTRY, this ); |
|
110 |
|
111 Cancel(); |
|
112 iPacketsCount = 0; |
|
113 OstTraceFunctionExit1( CNCMNTBBUILDSIMPLEPOLICY_COMPLETENTBBUILD_EXIT, this ); |
|
114 } |
|
115 |
|
116 |
|
117 void CNcmNtbBuildSimplePolicy::StartNewNtb() |
|
118 { |
|
119 OstTraceFunctionEntry1( CNCMNTBBUILDSIMPLEPOLICY_STARTNEWNTB_ENTRY, this ); |
|
120 OstTraceFunctionExit1( CNCMNTBBUILDSIMPLEPOLICY_STARTNEWNTB_EXIT, this ); |
|
121 } |
|
122 |
|
123 void CNcmNtbBuildSimplePolicy::UpdateNtb(TInt aSize) |
|
124 { |
|
125 OstTraceFunctionEntryExt( CNCMNTBBUILDSIMPLEPOLICY_UPDATENTB_ENTRY, this ); |
|
126 OstTrace1( TRACE_NORMAL, CNCMNTBBUILDSIMPLEPOLICY_UPDATENTB, "CNcmNtbBuildSimplePolicy::UpdateNtb aSize=%d", aSize ); |
|
127 |
|
128 if (iPacketsCount == 0) |
|
129 { |
|
130 iStatus = KRequestPending; |
|
131 iTimer.After(iStatus, KMaxPacketDelay); |
|
132 SetActive(); |
|
133 } |
|
134 |
|
135 if (KMaxPacketsOfNtb <= ++iPacketsCount && aSize >= iBufferSize/2) |
|
136 { |
|
137 iNtbBuilder.CompleteNtbBuild(); |
|
138 } |
|
139 else if (iFreeBufferCount >= KMinFreeBuffers && aSize >= iBufferSize/8) |
|
140 { |
|
141 iNtbBuilder.CompleteNtbBuild(); |
|
142 } |
|
143 OstTraceFunctionExit1( CNCMNTBBUILDSIMPLEPOLICY_UPDATENTB_EXIT, this ); |
|
144 } |
|
145 |
|
146 void CNcmNtbBuildSimplePolicy::UpdateBufferSize(TInt aSize) |
|
147 { |
|
148 iBufferSize = aSize; |
|
149 } |
|
150 |
|
151 void CNcmNtbBuildSimplePolicy::UpdateFreeBufferCount(TInt aCount) |
|
152 { |
|
153 iFreeBufferCount = aCount; |
|
154 } |
|
155 |
|
156 void CNcmNtbBuildSimplePolicy::UpdateTotalBufferCount(TInt aCount) |
|
157 { |
|
158 iTotalBufferCount = aCount; |
|
159 } |
|
160 |
|