|
1 /* |
|
2 * Copyright (c) 2004-2007 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: Defines the CBtSoapCodec class to create and read SOAP-encoded messages. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef CBTSOAPCODEC_H |
|
20 #define CBTSOAPCODEC_H |
|
21 |
|
22 #include <e32base.h> |
|
23 #include <f32file.h> |
|
24 #include <e32math.h> |
|
25 |
|
26 #include "cxmlhandler.h" |
|
27 #include "tprintcapability.h" |
|
28 #include "btprotocolconsts.h" |
|
29 |
|
30 /** @name Constants */ |
|
31 /** Template file to use to create the XML soap-encoded messages */ |
|
32 _LIT( KBtXmlTemplate, "z:\\resource\\imageprintdata\\protocols\\btxmltemplate.txt" ); |
|
33 |
|
34 |
|
35 /** general tags */ |
|
36 _LIT8(KBtEnvelopeStartTag, "<s:Envelope"); |
|
37 _LIT8(KBtEnvelopeEndTag, "</s:Envelope>"); |
|
38 _LIT8(KBtBodyStartTag, "<s:Body>"); |
|
39 _LIT8(KBtBodyEndTag, "</s:Body>"); |
|
40 |
|
41 _LIT8(KBtAction, "[Action]"); |
|
42 _LIT8(KBtActionData, "[ActionData]"); |
|
43 _LIT8(KBtBytesInBody, "[BytesInBody]"); |
|
44 |
|
45 /** Create job tags */ |
|
46 _LIT8(KBtCreateJobStart, "[CreateJobStart]"); |
|
47 _LIT8(KBtCreateJobEnd, "[CreateJobEnd]"); |
|
48 |
|
49 /** Get printer attributes tags */ |
|
50 _LIT8(KBtGetPrinterAttributesAllStart, "[GetPrinterAttributesAllStart]"); |
|
51 _LIT8(KBtGetPrinterAttributesAllEnd, "[GetPrinterAttributesAllEnd]"); |
|
52 _LIT8(KBtGetPrinterAttributesStart, "[GetPrinterAttributesStart]"); |
|
53 _LIT8(KBtGetPrinterAttributesEnd, "[GetPrinterAttributesEnd]"); |
|
54 _LIT8(KBtGetPrinterCapabilitiesStart, "[GetPrinterCapabilitiesStart]"); |
|
55 _LIT8(KBtGetPrinterCapabilitiesEnd, "[GetPrinterCapabilitiesEnd]"); |
|
56 _LIT8(KBtGetPrinterStateStart, "[GetPrinterStateStart]"); |
|
57 _LIT8(KBtGetPrinterStateEnd, "[GetPrinterStateEnd]"); |
|
58 |
|
59 |
|
60 /** Get printer attributes tags */ |
|
61 _LIT8(KBtGetJobAttributesStart, "[GetJobAttributesStart]"); |
|
62 _LIT8(KBtGetJobAttributesEnd, "[GetJobAttributesEnd]"); |
|
63 |
|
64 /** Get margins tags */ |
|
65 _LIT8(KBtGetMarginsStart, "[GetMarginsStart]"); |
|
66 _LIT8(KBtGetMarginsEnd, "[GetMarginsEnd]"); |
|
67 _LIT8(KBtMediaSizeData, "[MediaSizeData]"); |
|
68 _LIT8(KBtMediaTypeData, "[MediaTypeData]"); |
|
69 |
|
70 /** Job related */ |
|
71 _LIT8(KBtJobIdStart, "[JobIdStart]"); |
|
72 _LIT8(KBtJobIdEnd, "[JobIdEnd]"); |
|
73 |
|
74 /** Actions */ |
|
75 enum TBtSoapActions |
|
76 { |
|
77 EBtUnknownAction = -1, |
|
78 EBtCreateJob, |
|
79 EBtCreateJobResponse, |
|
80 EBtGetPrinterAttributes, |
|
81 EBtGetPrinterAttributesResponse, |
|
82 EBtGetJobAttributes, |
|
83 EBtGetJobAttributesResponse, |
|
84 EBtCancelJob, |
|
85 EBtCancelJobResponse, |
|
86 EBtGetEvent, |
|
87 EBtGetEventResponse, |
|
88 EBtGetMargins, |
|
89 EBtGetMarginsResponse, |
|
90 // Not actual actions but identifiers as sub for EBtGetPrinterAttributes |
|
91 EBtGetPrinterCapabilities, |
|
92 EBtGetPrinterState |
|
93 }; |
|
94 |
|
95 _LIT8(KBtCreateJob, "CreateJob"); |
|
96 _LIT8(KBtCreateJobResponse, "CreateJobResponse"); |
|
97 _LIT8(KBtGetPrinterAttributes, "GetPrinterAttributes"); |
|
98 _LIT8(KBtGetPrinterAttributesResponse, "GetPrinterAttributesResponse"); |
|
99 _LIT8(KBtGetJobAttributes, "GetJobAttributes"); |
|
100 _LIT8(KBtGetJobAttributesResponse, "GetJobAttributesResponse"); |
|
101 _LIT8(KBtCancelJob, "CancelJob"); |
|
102 _LIT8(KBtCancelJobResponse, "CancelJobResponse"); |
|
103 _LIT8(KBtGetEvent, "GetEvent"); |
|
104 _LIT8(KBtGetEventResponse, "GetEventResponse"); |
|
105 _LIT8(KBtGetMargins, "GetMargins"); |
|
106 _LIT8(KBtGetMarginsResponse, "GetMarginsResponse"); |
|
107 |
|
108 _LIT8(KBtNumberUpSupported, "NumberUpSupported"); |
|
109 _LIT8(KBtMediaTypesSupported, "MediaTypesSupported"); |
|
110 _LIT8(KBtMediaSizesSupported, "MediaSizesSupported"); |
|
111 _LIT8(KBtPrintQualitySupported, "PrintQualitySupported"); |
|
112 _LIT8(KBtMediaLoaded, "MediaLoaded"); |
|
113 _LIT8(KBtLoadedMediumDetails, "LoadedMediumDetails"); |
|
114 |
|
115 /** Attributes */ |
|
116 _LIT8(KBtOperationStatus, "OperationStatus"); |
|
117 _LIT8(KBtJobId, "JobId"); |
|
118 _LIT8(KBtJobName, "JobName"); |
|
119 _LIT8(KBtJobState, "JobState"); |
|
120 _LIT8(KBtJobOriginatingUserName, "JobOriginatingUserName"); |
|
121 _LIT8(KBtJobMediaSheetsCompleted, "JobMediaSheetsCompleted"); |
|
122 _LIT8(KBtJobPending, "NumberOfInterveningJobs"); |
|
123 |
|
124 _LIT8(KBtPrinterName, "PrinterName"); |
|
125 _LIT8(KBtPrinterState, "PrinterState"); |
|
126 _LIT8(KBtPrinterStateReasons, "PrinterStateReasons"); |
|
127 |
|
128 _LIT8(KBtDocumentFormat, "DocumentFormat"); |
|
129 _LIT8(KBtCopies, "Copies"); |
|
130 _LIT8(KBtSides, "Sides"); |
|
131 _LIT8(KBtNumberUp, "NumberUp"); |
|
132 _LIT8(KBtOrientationRequest, "OrientationRequest"); |
|
133 _LIT8(KBtMediaSize, "MediaSize"); |
|
134 _LIT8(KBtMediaType, "MediaType"); |
|
135 _LIT8(KBtPrintQuality, "PrintQuality"); |
|
136 _LIT8(KBtLoadedMediumSize, "LoadedMediumSize"); |
|
137 _LIT8(KBtLoadedMediumType, "LoadedMediumType"); |
|
138 |
|
139 _LIT8(KBtStartTag, "<%S>"); |
|
140 _LIT8(KBtEndTag, "</%S>"); |
|
141 _LIT8(KBtValueTemplate, "[%S]"); |
|
142 |
|
143 static const TInt KAttrStrLen = 0x100; |
|
144 typedef TBuf8<KAttrStrLen> TBtAttrString8; |
|
145 typedef TBuf8<KDefaultRealWidth> TBtIntString8; |
|
146 |
|
147 /** |
|
148 * @class CBtSoapCodec |
|
149 * @brief Class to create and read SOAP-encoded messages. |
|
150 * |
|
151 * Class defines methods to encode and decode BPP actions to SOAP-encoded messages. |
|
152 * @n |
|
153 * @b Usage: |
|
154 * @n |
|
155 * @b Creating a message: |
|
156 * <OL> |
|
157 * 1. Create an instance of the class |
|
158 * 2. Create an encoded message by CreateSoapL |
|
159 * </OL> |
|
160 * @n |
|
161 * After a message is created, it must be added in OBEX message body. |
|
162 * @n |
|
163 * @b Reading a message: |
|
164 * After a OBEX message is received, a body from it can be given to |
|
165 * CBtSoapCodec to decode the SOAP-encoded message. |
|
166 * <OL> |
|
167 * 1. Decode and the message by ReadSoapL |
|
168 * 2. Get the attributes(s) of the message by GetAttributeL |
|
169 * </OL> |
|
170 * |
|
171 */ |
|
172 NONSHARABLE_CLASS( CBtSoapCodec ) : public CBase |
|
173 { |
|
174 public: |
|
175 |
|
176 /** NewL |
|
177 * @brief Creates a new instance of SOAP codec class. |
|
178 * @return Pointer to the instance. |
|
179 */ |
|
180 static CBtSoapCodec* NewL(); |
|
181 |
|
182 /** NewLC |
|
183 * @brief Creates a new instance of SOAP codec class and leaves it in the cleanup stack. |
|
184 * @return Pointer to the instance. |
|
185 */ |
|
186 static CBtSoapCodec* NewLC(); |
|
187 |
|
188 /** ~CBtSoapCodec |
|
189 * @brief Destructor. |
|
190 */ |
|
191 ~CBtSoapCodec(); |
|
192 |
|
193 |
|
194 /** Reset |
|
195 * @brief Resets the member variables. |
|
196 */ |
|
197 void Reset(); |
|
198 |
|
199 /** CreateSoapL |
|
200 * @brief Creates the SOAP-encoded message. |
|
201 * According to the action parameter given, the method reads |
|
202 * the xml template for a named action from file @ref KBtXmlTemplate |
|
203 * and decodes it with the data concerning. |
|
204 * @param aAction Name of the action for the message to create. |
|
205 * @param aJobId Jod identifier for the actions required. |
|
206 * NOTE: for CreateJob operation the job id is the cumulative number |
|
207 * of the created jobs during the session. |
|
208 * @return Pointer to the SOAP-encoded message for the action |
|
209 */ |
|
210 TPtrC8 CreateSoapL(const TInt aAction, const TInt aJobId = KErrNotFound); |
|
211 |
|
212 /** SoapAction |
|
213 * @brief Returns for the action of the SOAP-encoded message |
|
214 * @return TBtSoapActions type action identifier |
|
215 */ |
|
216 TInt SoapAction(); |
|
217 |
|
218 /** ReadSoapL |
|
219 * @brief Reads the SOAP-encoded message. |
|
220 * The message is read and the class is initialized with the data of the message. |
|
221 * @param aAction Returns the name of the action of the SOAP-encoded data |
|
222 * @param aSoapBuffer The buffer to read |
|
223 */ |
|
224 void ReadSoapL(TInt& aAction, const TDesC8& aSoapBuffer); |
|
225 |
|
226 /** @overload void ReadSoapL(TInt& aAction, const TDesC8& aSoapBuffer) */ |
|
227 void ReadSoapL(TInt& aAction, const CBufBase& aSoapBuffer); |
|
228 |
|
229 /** @overload void ReadSoapL(TInt& aAction, const TDesC8& aSoapBuffer) */ |
|
230 void ReadSoapL(const TDesC8& aSoapBuffer); |
|
231 |
|
232 /** @overload void ReadSoapL(TInt& aAction, const TDesC8& aSoapBuffer) */ |
|
233 void ReadSoapL(const CBufBase& aSoapBuffer); |
|
234 |
|
235 public: |
|
236 void CreateJobResponseL(TInt& aJobId, TInt& aErrorCode); |
|
237 |
|
238 void GetPrinterAttributesResponseL(TInt& aState, TInt& aStateReasons, |
|
239 RArray<TPrintCapability>& aCapabilities, |
|
240 TInt& aOperationStatus); |
|
241 |
|
242 void GetPrinterStateResponseL(TInt& aState, TInt& aStateReasons, TInt& aOperationStatus); |
|
243 |
|
244 void GetPrinterCapabilitiesResponseL(RArray<TPrintCapability>& aCapabilities, |
|
245 TInt& aOperationStatus); |
|
246 |
|
247 void GetJobAttributesResponseL(const TInt aJobId, |
|
248 TInt& aJobState, |
|
249 TBtAttrString8& aJobName, |
|
250 TBtAttrString8& aOriginator, |
|
251 TInt& aSheetsCompleted, |
|
252 TInt& aPendingJobs, |
|
253 TInt& aOperationStatus ); |
|
254 |
|
255 void CancelJobResponseL(const TInt aJobId, TInt& aOperationStatus); |
|
256 |
|
257 void GetEventResponseL(const TInt aJobId, |
|
258 TInt& aJobState, |
|
259 TInt& aPrinterState, |
|
260 TInt& aStateReasons, |
|
261 TInt& aOperationStatus); |
|
262 TInt OperationStatusL(); |
|
263 |
|
264 public: |
|
265 /** GetAttributeL |
|
266 * @brief Reads the requested attributes's value. |
|
267 * @param aName Name of the attribute |
|
268 * @param aValue Returns the value of the attribute |
|
269 * @param aError Returns the code for the occurred error or KErrNone |
|
270 */ |
|
271 void GetAttributeL(const TDesC8& aName, TDes8& aValue, TInt& aError); |
|
272 |
|
273 void GetAttributeListL(const TDesC8& aName, CDesC8ArrayFlat& aList, TInt& aError); |
|
274 |
|
275 public: |
|
276 /** TestMeL - Static test method |
|
277 * @brief Static method to test this class' public interface. |
|
278 */ |
|
279 static void TestMeL(); |
|
280 static TPtrC8 CreateJobResponseTestSoap(); |
|
281 static TPtrC8 CancelJobResponseTestSoap(); |
|
282 static TPtrC8 GetPrinterAttributesResponseTestSoap(); |
|
283 static TPtrC8 GetJobAttributesResponseTestSoap(); |
|
284 static TPtrC8 GetEventsResponseTestSoap(); |
|
285 static TPtrC8 GetMarginsResponseTestSoap(); |
|
286 |
|
287 protected: |
|
288 |
|
289 /** ConstructL |
|
290 * @brief Symbian second phase constructor. |
|
291 */ |
|
292 void ConstructL(); |
|
293 |
|
294 private: |
|
295 |
|
296 /** CBtSoapCodec |
|
297 * @brief C++ constructor |
|
298 */ |
|
299 CBtSoapCodec(); |
|
300 |
|
301 /** CreateSoapTemplateL |
|
302 * @brief Constructs a correct type message template. |
|
303 * According to the given parameters method composes a template |
|
304 * for the message with general headers and action specific data block. |
|
305 * @param aStartTag Start tag for the action |
|
306 * @param aEndTag End tag for the action |
|
307 */ |
|
308 void CreateSoapTemplateL(const TDesC8& aStartTag, const TDesC8& aEndTag); |
|
309 |
|
310 /** CreateJobSoapL |
|
311 * @brief Composes the CreateJob action specific data in template. |
|
312 */ |
|
313 void CreateJobSoapL(const TInt aJobId); |
|
314 |
|
315 /** GetPrinterAttributesSoapL |
|
316 * @brief Composes the GetPrinterAttributes action specific data in template. |
|
317 */ |
|
318 void GetPrinterAttributesSoapL(); |
|
319 void GetCapabilitiesSoapL(); |
|
320 void GetPrinterStateSoapL(); |
|
321 |
|
322 void GetJobAttributesSoapL(const TDesC8& aJobId); |
|
323 void CancelJobSoapL(const TDesC8& aJobId); |
|
324 void GetEventSoapL(const TDesC8& aJobId); |
|
325 void GetMarginsSoapL(); |
|
326 |
|
327 TPrintCapability ParseLayoutL(); |
|
328 TPrintCapability ParseQualityL(); |
|
329 TPrintCapability ParsePaperSizeL(); |
|
330 void ParseDefaultSizeL(TPrintCapability& aSize, TInt& aPos); |
|
331 TInt ValuePosition(TPrintCapability aCapab, TInt aValue); |
|
332 |
|
333 private: |
|
334 |
|
335 /** @var HBufC8* iActionBuffer |
|
336 * Buffer to store the action data */ |
|
337 HBufC8* iActionBuffer; |
|
338 |
|
339 /** @var CXmlHandler* iXmlHandler |
|
340 * XML handler */ |
|
341 CXmlHandler* iXmlHandler; |
|
342 |
|
343 }; |
|
344 |
|
345 #endif // CBTSOAPCODEC_H |
|
346 |
|
347 // End of File |