|
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 // Name : SigCompCompartmentStatesHolder.cpp |
|
15 // Part of : SigComp |
|
16 // SigComp API frontend |
|
17 // Version : 1.0 |
|
18 // |
|
19 |
|
20 |
|
21 |
|
22 // INCLUDE FILES |
|
23 #include "Sigcomp.h" |
|
24 #include "StateMgr.h" |
|
25 #include "SigCompCompartmentStatesHolder.h" |
|
26 |
|
27 |
|
28 // ============================ MEMBER FUNCTIONS ============================== |
|
29 |
|
30 CSigCompCompartmentStatesHolder::CSigCompCompartmentStatesHolder( |
|
31 CStateMgr& aStateMgr, |
|
32 CSigComp::TMemorySize aStateMemorySize) |
|
33 { |
|
34 |
|
35 iStateMgr = &aStateMgr; |
|
36 iStateMemorySize = aStateMemorySize; |
|
37 iStateMemoryUsed = 0; |
|
38 } |
|
39 |
|
40 // Destructor |
|
41 EXPORT_C CSigCompCompartmentStatesHolder::~CSigCompCompartmentStatesHolder() |
|
42 { |
|
43 |
|
44 TInt csiNum = iCompartmentStateItems.Count(); |
|
45 for (TInt i = 0; i < csiNum; i++) |
|
46 { |
|
47 TStateItem* si = iCompartmentStateItems[i].iStateItem; |
|
48 iStateMgr->ReclaimStateItem(si); |
|
49 } |
|
50 |
|
51 iCompartmentStateItems.Close(); |
|
52 |
|
53 iStateMgr = NULL; |
|
54 } |
|
55 |
|
56 |
|
57 // ---------------------------------------------------------------------------- |
|
58 // CSigCompCompartmentStatesHolder::AddStateItemL |
|
59 // add new state to compartment |
|
60 // ---------------------------------------------------------------------------- |
|
61 // |
|
62 |
|
63 TBool CSigCompCompartmentStatesHolder::AddStateItemL(TStateItem* aStateItem, |
|
64 TUint16 aStateRetentionPriority) |
|
65 { |
|
66 |
|
67 TInt csiNum = iCompartmentStateItems.Count(); |
|
68 |
|
69 for (TInt i = 0; i < csiNum; i++) |
|
70 { |
|
71 if (iCompartmentStateItems[i].iStateItem == aStateItem) |
|
72 { |
|
73 return EFalse; |
|
74 } |
|
75 } |
|
76 |
|
77 while ((iStateMemoryUsed+aStateItem->iStateLength+64) > |
|
78 static_cast<TUint>(iStateMemorySize)) |
|
79 { |
|
80 TInt j = -1; |
|
81 csiNum = iCompartmentStateItems.Count(); |
|
82 for (TInt i = 0; i < csiNum; i++) |
|
83 { |
|
84 if (j < 0) |
|
85 { |
|
86 j = i; |
|
87 } |
|
88 else |
|
89 { |
|
90 TUint srp1 = iCompartmentStateItems[i].iStateRetentionPriority; |
|
91 TUint srp2 = iCompartmentStateItems[j].iStateRetentionPriority; |
|
92 if (srp1 < srp2) |
|
93 { |
|
94 j = i; |
|
95 } |
|
96 } |
|
97 } |
|
98 |
|
99 RemoveStateItemL(j); |
|
100 } |
|
101 |
|
102 TCompartmentStateItem csi; |
|
103 csi.iStateItem = aStateItem; |
|
104 csi.iStateRetentionPriority = aStateRetentionPriority; |
|
105 |
|
106 User::LeaveIfError(iCompartmentStateItems.Append(csi)); |
|
107 iStateMemoryUsed += (aStateItem->iStateLength + 64); |
|
108 |
|
109 return ETrue; |
|
110 } |
|
111 |
|
112 |
|
113 // ---------------------------------------------------------------------------- |
|
114 // CSigCompCompartmentStatesHolder::RemoveStateItemL |
|
115 // remove state from compartment |
|
116 // ---------------------------------------------------------------------------- |
|
117 // |
|
118 |
|
119 void CSigCompCompartmentStatesHolder::RemoveStateItemL( |
|
120 TStateItem* aStateItem) |
|
121 { |
|
122 |
|
123 TInt csiNum = iCompartmentStateItems.Count(); |
|
124 for (TInt i = 0; i < csiNum; i++) |
|
125 { |
|
126 if (iCompartmentStateItems[i].iStateItem == aStateItem) |
|
127 { |
|
128 RemoveStateItemL(i); |
|
129 } |
|
130 } |
|
131 } |
|
132 |
|
133 |
|
134 void CSigCompCompartmentStatesHolder::RemoveStateItemL(TInt aStateItemIndex) |
|
135 { |
|
136 |
|
137 TStateItem* si = iCompartmentStateItems[aStateItemIndex].iStateItem; |
|
138 iStateMemoryUsed -= (si->iStateLength + 64); |
|
139 iStateMgr->ReclaimStateItem(si); |
|
140 iCompartmentStateItems.Remove(aStateItemIndex); |
|
141 } |