|
1 /* |
|
2 * Copyright (c) 2003-2009 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 * Name : StateMgr.h |
|
16 * Part of : SigComp / state manager |
|
17 * Interface : |
|
18 * State manager |
|
19 * Version : 1.0 |
|
20 * |
|
21 */ |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 /** |
|
27 @internalComponent |
|
28 */ |
|
29 |
|
30 |
|
31 #ifndef STATEMGR_H |
|
32 #define STATEMGR_H |
|
33 |
|
34 // INCLUDES |
|
35 #include <e32base.h> |
|
36 #include <hash.h> |
|
37 |
|
38 #include "SigCompStateMgr.h" |
|
39 |
|
40 // consts |
|
41 |
|
42 // RFC3320: For the purpose of calculation, each state item is considered to |
|
43 // cost (state_length + 64) bytes. |
|
44 static const TInt KStateCostExtension = 64; |
|
45 |
|
46 static const TUint KStateIdentifierMinLength = 6; // minimum length of state id |
|
47 static const TUint KStateIdentifierMaxLength = 20; //maximum length of state id |
|
48 |
|
49 class TStateItem; |
|
50 |
|
51 // CLASS DECLARATION |
|
52 |
|
53 /** |
|
54 * State item container for internal use only. |
|
55 * |
|
56 * |
|
57 * @lib sigcomp |
|
58 */ |
|
59 |
|
60 class TStateItem |
|
61 { |
|
62 public: |
|
63 /** state usage counter */ |
|
64 TUint iUsageCounter; |
|
65 |
|
66 /** RFC defined fields */ |
|
67 TUint8 iStateIdentifier[KStateIdentifierMaxLength]; |
|
68 TUint16 iStateLength; |
|
69 TUint16 iStateAddress; |
|
70 TUint16 iStateInstruction; |
|
71 TUint16 iMinimumAccessLength; |
|
72 TUint8 iStateValue[1]; |
|
73 }; |
|
74 |
|
75 |
|
76 /** |
|
77 * State manager class. |
|
78 * |
|
79 * |
|
80 * @lib sigcomp |
|
81 */ |
|
82 |
|
83 class CSigCompCompartment; |
|
84 |
|
85 class CStateMgr : public CBase, public MSigCompStateMgr |
|
86 { |
|
87 |
|
88 public: // Constructors and destructor |
|
89 |
|
90 static CStateMgr* NewL(); |
|
91 static CStateMgr* NewLC(); |
|
92 |
|
93 /** |
|
94 * Destructor. |
|
95 */ |
|
96 virtual ~CStateMgr(); |
|
97 |
|
98 |
|
99 public: // new functions |
|
100 |
|
101 /** |
|
102 * allocate TStateItem object and add to state items list |
|
103 * |
|
104 * @param aStateLength length of the state value to be created. |
|
105 * |
|
106 * @returns just created TStateItem |
|
107 */ |
|
108 TStateItem* CreateStateItemL(TInt aStateLength); |
|
109 |
|
110 /** |
|
111 * reclaim state item from list and remove if not used |
|
112 * |
|
113 * @param aStateItem state item to be reclaimed. |
|
114 * |
|
115 */ |
|
116 void ReclaimStateItem(TStateItem* aStateItem); |
|
117 |
|
118 /** |
|
119 * Find state item of a given hash. |
|
120 * |
|
121 * @param aPartialIdentifier hash ID of the state item we are looking |
|
122 * for. |
|
123 * |
|
124 * @returns state item, or null if no state item was found |
|
125 */ |
|
126 TStateItem* FindStateItem(const TDesC8& aPartialIdentifier); |
|
127 |
|
128 /** |
|
129 * create state |
|
130 * |
|
131 * @param aCompartment compartment this state is associated with. |
|
132 * NULL means created state will be localy |
|
133 * available state. |
|
134 * @param aStateLength length of the state value |
|
135 * @param aStateAddress state address |
|
136 * @param aStateInstruction state instruction |
|
137 * @param aMinimumAccessLength minimum access length |
|
138 * @param aStateValue value of the state |
|
139 * @param aStateRetentionPriority retention priority of the state |
|
140 * |
|
141 * @returns state item |
|
142 */ |
|
143 TStateItem* CreateStateL(CSigCompCompartment* aCompartment, |
|
144 TUint16 aStateLength, TUint16 aStateAddress, |
|
145 TUint16 aStateInstruction, TUint16 aMinimumAccessLength, |
|
146 const TUint8* aStateValue, TUint16 aStateRetentionPriority); |
|
147 |
|
148 /** |
|
149 * Free state of a given hash, in the way described in RFC 3220, |
|
150 * chapter 6.2 |
|
151 * |
|
152 * @param aCompartment compartment |
|
153 * @param aPartialIdentifier hash ID of the state we want to free. |
|
154 * |
|
155 * @returns KErrNone if everything went ok, KErrNotFound if state |
|
156 * was not found. |
|
157 */ |
|
158 TInt FreeStateL(CSigCompCompartment* aCompartment, |
|
159 const TDesC8& aPartialIdentifier); |
|
160 |
|
161 /** |
|
162 * set returned feedback in compartment |
|
163 * |
|
164 * @param aCompartment compartment in which feedback will be saved |
|
165 * @param aReturnedFeedback the feedback itself. |
|
166 */ |
|
167 void SetReturnedFeedbackL(CSigCompCompartment& aCompartment, |
|
168 const TDesC8& aReturnedFeedback) const; |
|
169 /** |
|
170 * set requested feedback in compartment |
|
171 * |
|
172 * @param aCompartment compartment in which feedback will be saved |
|
173 * @param aRequestedFeedback the feedback itself. |
|
174 */ |
|
175 void SetRequestedFeedbackL(CSigCompCompartment& aCompartment, |
|
176 const TDesC8& aRequestedFeedback) const; |
|
177 /** |
|
178 * set returned parameters in compartment |
|
179 * |
|
180 * @param aCompartment compartment in which parameters will be saved |
|
181 * @param aReturnedParameters returned parameters to be saved. |
|
182 */ |
|
183 void SetReturnedParametersL(CSigCompCompartment& aCompartment, |
|
184 const TDesC8& aReturnedParameters) const; |
|
185 |
|
186 private: |
|
187 void ConstructL(); |
|
188 |
|
189 CStateMgr(); |
|
190 |
|
191 /** |
|
192 * Align given value to 4. |
|
193 * |
|
194 * @param aValue value to be aligned. |
|
195 * |
|
196 * @returns aligned value |
|
197 */ |
|
198 TInt Align4(TInt aValue) const; |
|
199 |
|
200 private: |
|
201 /** array containing all state items */ |
|
202 RPointerArray<TStateItem> iStateItems; |
|
203 |
|
204 /** SHA-1 instance */ |
|
205 CSHA1* iSHA1; |
|
206 |
|
207 }; |
|
208 |
|
209 #endif |
|
210 |
|
211 // End of File |