|
1 /* |
|
2 * Copyright (c) 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: Hti Message incapsulates HTI protocol messages structure. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef MESSAGEPARSER_H__ |
|
20 #define MESSAGEPARSER_H__ |
|
21 |
|
22 #include <e32std.h> |
|
23 #include <e32base.h> |
|
24 |
|
25 |
|
26 const TInt KDefaultPriority = 0; |
|
27 const TInt KPriorityMask = 0x2; |
|
28 const TInt KHtiMsgServiceUidLen = 4; |
|
29 |
|
30 class CHtiMessage : public CBase |
|
31 { |
|
32 public: |
|
33 /** |
|
34 * Constructs and parses a new message from descriptor in question. |
|
35 * This method is used to construct hti message from incoming data. |
|
36 * The descriptor must start from HTI header. |
|
37 * Available amount of data is copied from the descriptor depending |
|
38 * on the message size value in the header. The remaining data of |
|
39 * message body must be added using method AddToBody(). |
|
40 * |
|
41 * @return new Hti message |
|
42 * |
|
43 * @see CheckValidHeader() for function to define either descriptor |
|
44 * starts from a valid Hti message header |
|
45 * @see AddToBody() |
|
46 */ |
|
47 static CHtiMessage* NewL(const TDesC8& aMessage); |
|
48 |
|
49 /** |
|
50 * Creates a new HTI message without extension. |
|
51 * Can leave with KErrArgument if passed data are invalid |
|
52 * or other system-wide leave code (e.g. KErrNoMemory). |
|
53 * Ownership of aMessagBody is transfered. |
|
54 * This method is used to create a new outgoing HTI message. |
|
55 * |
|
56 * @param aMessageBody message body content |
|
57 * @param aServiceUid target service name |
|
58 * @param aWraped flag to indicate either |
|
59 * Security manager must wrap message body |
|
60 * @param aPriority message priority |
|
61 * |
|
62 */ |
|
63 static CHtiMessage* NewL(TDesC8* aMessageBody, |
|
64 const TUid aServiceUid, |
|
65 TBool aWraped = EFalse, |
|
66 TInt aPriority = KDefaultPriority); |
|
67 |
|
68 /** |
|
69 * Creates a new HTI message with extension. |
|
70 * Can leave with KErrArgument if passed data are invalid |
|
71 * or other system-wide leave code (e.g. KErrNoMemory). |
|
72 * Ownership of aMessagBody is transfered. |
|
73 * This method is used to create a new outgoing HTI message. |
|
74 * |
|
75 * @param aMessageBody message body content |
|
76 * @param aServiceUid target service name |
|
77 * @param aExtBody extension content |
|
78 * @param aWraped flag to indicate either |
|
79 * Security manager must wrap message body |
|
80 * @param aPriority message priority |
|
81 * |
|
82 */ |
|
83 static CHtiMessage* NewL(TDesC8* aMessageBody, |
|
84 const TUid aServiceUid, |
|
85 const TDesC8& aExtBody, |
|
86 TBool aWraped = EFalse, |
|
87 TInt aPriority = KDefaultPriority); |
|
88 |
|
89 /** |
|
90 * Deletes all message data allocated in heap. |
|
91 */ |
|
92 virtual ~CHtiMessage(); |
|
93 |
|
94 /** |
|
95 * Returns ETrue when the descriptor in question starts from |
|
96 * valid HTI header. |
|
97 * |
|
98 * @param aMessage descriptor with probable HTI message |
|
99 * |
|
100 * @return ETrue HTI header is valid |
|
101 */ |
|
102 static TBool CheckValidHtiHeader(const TDesC8& aMessage); |
|
103 |
|
104 /** |
|
105 * Returns message size based on the header in question |
|
106 * |
|
107 * @param aMessage descriptor with an HTI message |
|
108 */ |
|
109 static TInt Size(const TDesC8& aMessage); |
|
110 |
|
111 /** |
|
112 * Returns the minimal size of HTI message header. |
|
113 * |
|
114 */ |
|
115 static TInt MinHeaderSize(); |
|
116 |
|
117 /** |
|
118 * Check either HTI message body has body of required size as specified |
|
119 * in Hti header. |
|
120 */ |
|
121 TBool IsBodyComplete() const; |
|
122 |
|
123 /** |
|
124 * Appends to the body a new part. If the descriptor length bigger |
|
125 * than remaining space for message body, only part |
|
126 * of the descritpor is copied to fill in all available space. |
|
127 * |
|
128 * @param aBodyPart descriptor with remaining message body |
|
129 * |
|
130 * @return number of bytes copied from the descriptor |
|
131 */ |
|
132 TInt AddToBody(const TDesC8& aBodyPart); |
|
133 |
|
134 /** |
|
135 * Returns the size of a whole message (BodySize()+HeaderSize()) |
|
136 */ |
|
137 TInt Size() const; |
|
138 |
|
139 /** |
|
140 * Returns message service uid |
|
141 */ |
|
142 TUid DestinationServiceUid() const; |
|
143 |
|
144 /** |
|
145 * Returns message body size |
|
146 */ |
|
147 TInt BodySize() const; |
|
148 |
|
149 /** |
|
150 * Returns message priority |
|
151 */ |
|
152 TInt Priority() const; |
|
153 |
|
154 /** |
|
155 * Returns wrap flag |
|
156 */ |
|
157 TBool IsWrapped() const; |
|
158 |
|
159 /** |
|
160 * Returns header extension |
|
161 */ |
|
162 TPtrC8 Extension() const; |
|
163 |
|
164 /** |
|
165 * Returns extention section size |
|
166 */ |
|
167 TInt ExtSize() const; |
|
168 |
|
169 /** |
|
170 * Returns header size including extension section. |
|
171 */ |
|
172 TInt HeaderSize() const; |
|
173 |
|
174 /** |
|
175 * Returns message body |
|
176 */ |
|
177 TPtrC8 Body() const; |
|
178 |
|
179 /** |
|
180 * Return message header |
|
181 */ |
|
182 TPtrC8 Header() const; |
|
183 |
|
184 public: |
|
185 /** |
|
186 * Returns the offset of a link data member |
|
187 */ |
|
188 static const TInt iLinkOffset; |
|
189 |
|
190 protected: |
|
191 /** |
|
192 * Constructor |
|
193 */ |
|
194 CHtiMessage(); |
|
195 |
|
196 /** |
|
197 * Second-level constructors |
|
198 */ |
|
199 void ConstructL(const TDesC8& aMessage); |
|
200 void ConstructL(const TUid aServiceUid, |
|
201 TDesC8* aMessageBody, |
|
202 const TDesC8& aExtBody, |
|
203 TBool aWraped, |
|
204 TInt aPriority); |
|
205 /** |
|
206 * helper function that make TInt from 3 bytes in big-endian format |
|
207 * @param aSrc bytes with integer |
|
208 * |
|
209 * @return integer |
|
210 */ |
|
211 //static TInt ParseLittleEndian3(const TUint8* aSrc); |
|
212 |
|
213 private: |
|
214 /** |
|
215 * Link used when creating message queues |
|
216 */ |
|
217 TSglQueLink iLink; |
|
218 |
|
219 /** |
|
220 * Message body used when constructing from parts |
|
221 * when body is ready pointer is copied to iBodyDes |
|
222 */ |
|
223 HBufC8* iBody; |
|
224 |
|
225 /** |
|
226 * Complete body, used for access methods |
|
227 */ |
|
228 TDesC8* iBodyDes; |
|
229 |
|
230 /** |
|
231 * Message header in binary format |
|
232 */ |
|
233 TUint8* iHeader; |
|
234 |
|
235 /** |
|
236 * Body size copied from iHeader for quick access |
|
237 */ |
|
238 TInt iBodySize; |
|
239 |
|
240 /** |
|
241 * Service UID extracted from iHeader. |
|
242 */ |
|
243 TUid iServiceUid; |
|
244 |
|
245 /** |
|
246 * Size of extension section to be added to the header |
|
247 * Used during message construction from parts |
|
248 */ |
|
249 TInt iExtRemainderSize; |
|
250 }; |
|
251 |
|
252 #endif |