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: |
|
15 */ |
|
16 #ifndef __HTI_COMMON__ |
|
17 #define __HTI_COMMON__ |
|
18 |
|
19 #ifdef _EXPORT_HTI_COMMON_ |
|
20 #define EXPORT_FROM_DLL __declspec(dllexport) |
|
21 #else |
|
22 #define EXPORT_FROM_DLL __declspec(dllimport) |
|
23 #endif |
|
24 |
|
25 #include <windows.h> |
|
26 |
|
27 // CONSTANTS |
|
28 const int HTIMSG_TIMEOUT_5_SECONDS = 5000; // milliseconds |
|
29 const int HTIMSG_TIMEOUT_10_SECONDS = 10000; |
|
30 const int HTIMSG_TIMEOUT_30_SECONDS = 30000; |
|
31 const int HTIMSG_TIMEOUT_60_SECONDS = 30000; |
|
32 |
|
33 // GENERAL UTIL FUNCTIONS |
|
34 /** |
|
35 * Checks if a string parameter is valid. Not null or empty. |
|
36 */ |
|
37 EXPORT_FROM_DLL int check_mandatory_string_parameter(struct soap* soap, |
|
38 char* parameter, |
|
39 char* parameterName); |
|
40 /** |
|
41 * Checks if a wide character string parameter is valid. Not null or empty. |
|
42 */ |
|
43 EXPORT_FROM_DLL int check_mandatory_wcstring_parameter(struct soap* soap, |
|
44 wchar_t* parameter, |
|
45 char* parameterName); |
|
46 /** |
|
47 * A little addition to basic soap functions. Same as soap_receiver_fault |
|
48 * but can add formatted data to faultstring. |
|
49 */ |
|
50 EXPORT_FROM_DLL int soap_receiver_fault_format(struct soap *soap, |
|
51 const char *faultstring, |
|
52 const char *faultdetail, ...); |
|
53 /** |
|
54 * Prints bytes to the screen |
|
55 */ |
|
56 EXPORT_FROM_DLL void dump( BYTE *data, int dataLen ); |
|
57 |
|
58 |
|
59 // CLASSES |
|
60 // Class for HTI message manipulation |
|
61 class HtiMsgHelper |
|
62 { |
|
63 public: |
|
64 /** |
|
65 * Constructors. |
|
66 */ |
|
67 EXPORT_FROM_DLL HtiMsgHelper( struct soap *soap ); |
|
68 EXPORT_FROM_DLL HtiMsgHelper( struct soap *soap, DWORD serviceId ); |
|
69 EXPORT_FROM_DLL HtiMsgHelper( struct soap *soap, DWORD serviceId, BYTE command ); |
|
70 |
|
71 /** |
|
72 * Destructor. |
|
73 */ |
|
74 EXPORT_FROM_DLL ~HtiMsgHelper(); |
|
75 |
|
76 /** |
|
77 * General util methods. |
|
78 */ |
|
79 EXPORT_FROM_DLL BYTE* GetMsgBody() { return m_msgBody; }; |
|
80 EXPORT_FROM_DLL int GetMsgLen() { return m_msgBodyLen; }; |
|
81 |
|
82 /** |
|
83 * Methods for getting data from HTI message. |
|
84 */ |
|
85 EXPORT_FROM_DLL BYTE GetByte( int offset ) { return *(BYTE*)(m_msgBody+offset); }; |
|
86 EXPORT_FROM_DLL WORD GetWord( int offset ) { return *(WORD*)(m_msgBody+offset); }; |
|
87 EXPORT_FROM_DLL DWORD GetDWord( int offset ) { return *(DWORD*)(m_msgBody+offset); }; |
|
88 EXPORT_FROM_DLL int GetInt( int offset ) { return *(int*)(m_msgBody+offset); }; |
|
89 EXPORT_FROM_DLL char* GetSoapString( int offset, int len ); |
|
90 EXPORT_FROM_DLL wchar_t* GetSoapWCString( int offset, int len ); |
|
91 |
|
92 /** |
|
93 * Received HTI message checking methods |
|
94 */ |
|
95 EXPORT_FROM_DLL int CheckMsgExactLen( int len ); |
|
96 EXPORT_FROM_DLL int CheckMsgMinLen( int len ); |
|
97 EXPORT_FROM_DLL int CheckCommandCode( BYTE code ); |
|
98 |
|
99 /** |
|
100 * Methods for adding data to HTI message. |
|
101 */ |
|
102 EXPORT_FROM_DLL void AddByte( BYTE data ); |
|
103 EXPORT_FROM_DLL void AddWord( WORD data ); |
|
104 EXPORT_FROM_DLL void AddDWord( DWORD data ); |
|
105 EXPORT_FROM_DLL void AddInt( int data ); |
|
106 EXPORT_FROM_DLL void AddUInt64( unsigned __int64 data ); |
|
107 EXPORT_FROM_DLL void AddString( char* string ); |
|
108 EXPORT_FROM_DLL void AddWCString( wchar_t* string ); |
|
109 EXPORT_FROM_DLL void AddData( void* data, int dataLen ); |
|
110 |
|
111 // does not add if null or length is zero |
|
112 EXPORT_FROM_DLL void AddStringWithLengthByte( char* string ); |
|
113 EXPORT_FROM_DLL void AddWCStringWithLengthByte( wchar_t* string ); |
|
114 |
|
115 // adds at least the lenght byte |
|
116 EXPORT_FROM_DLL void AddStringWithLengthByteZero( char* string ); |
|
117 EXPORT_FROM_DLL void AddStringWithLengthWordZero( char* string ); |
|
118 EXPORT_FROM_DLL void AddWCStringWithLengthByteZero( wchar_t* string ); |
|
119 |
|
120 /** |
|
121 * Methods for sending and receiving. |
|
122 * Can be replaced if needed. |
|
123 */ |
|
124 virtual EXPORT_FROM_DLL void SendMsg(); |
|
125 virtual EXPORT_FROM_DLL int ReceiveMsg( int timeout ); |
|
126 virtual EXPORT_FROM_DLL int SendReceiveMsg( int timeout ); |
|
127 |
|
128 protected: |
|
129 /** |
|
130 * Increases m_msgBody for adding new data |
|
131 */ |
|
132 void IncBodySize( int size ); |
|
133 |
|
134 protected: |
|
135 /** |
|
136 * soap env. |
|
137 */ |
|
138 struct soap *m_soap; |
|
139 |
|
140 /** |
|
141 * Service id used in sending the message. |
|
142 */ |
|
143 DWORD m_serviceId; |
|
144 |
|
145 /** |
|
146 * The actual message and its length in bytes. |
|
147 * Destroyed when message is sent. Received message is not destroyed |
|
148 * because we dont have ownership. |
|
149 */ |
|
150 BYTE* m_msgBody; |
|
151 int m_msgBodyLen; |
|
152 }; |
|
153 |
|
154 #endif //__HTI_COMMON__ |
|