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