|
1 /* |
|
2 * Copyright (c) 2002-2004 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 * Base class for client side event handlers. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #ifndef IMPSHANDLER_H |
|
21 #define IMPSHANDLER_H |
|
22 |
|
23 // INCLUDES |
|
24 #include <e32base.h> |
|
25 #include "impspacked.h" |
|
26 #include "impsclientsrv.h" |
|
27 #include "impshandlertimer.h" |
|
28 |
|
29 // FORWARD DECLARATIONS |
|
30 class RImpsClient2; |
|
31 class MImpsStatusHandler2; |
|
32 class MImpsErrorHandler2; |
|
33 class CImpsFields; |
|
34 |
|
35 // CLASS DECLARATION |
|
36 |
|
37 |
|
38 // ----------------------------------------------------------------------------- |
|
39 // TWvBuf::CWvBuf |
|
40 // ----------------------------------------------------------------------------- |
|
41 class TWvBuf |
|
42 { |
|
43 public: |
|
44 /** |
|
45 * Constructor |
|
46 * @param aBuf data buffer |
|
47 */ |
|
48 TWvBuf( HBufC8* aBuf ); |
|
49 |
|
50 public: |
|
51 TPtr8 iPtr; // pointer to the buffer |
|
52 }; |
|
53 |
|
54 |
|
55 /** |
|
56 * Abstract base class for WV event handlers. |
|
57 */ |
|
58 class CImpsHandler2 :public CActive |
|
59 { |
|
60 public: // Constructors and destructor |
|
61 |
|
62 /** |
|
63 * Destructor. |
|
64 */ |
|
65 virtual ~CImpsHandler2(); |
|
66 |
|
67 |
|
68 public: // New functions |
|
69 |
|
70 /** |
|
71 * Start the execution. Ready to get messages after that. |
|
72 */ |
|
73 void StartRun(); |
|
74 |
|
75 /** |
|
76 * Session status handler accessor |
|
77 * @return status event handler |
|
78 */ |
|
79 inline MImpsStatusHandler2* StatusHandler(); |
|
80 |
|
81 /** |
|
82 * Session status handler mutator. |
|
83 * Registers status to server too. |
|
84 * @param aObserver status event observer |
|
85 */ |
|
86 void SetStatusHandlerL( MImpsStatusHandler2* aObserver ); |
|
87 |
|
88 /** |
|
89 * Error handler accessor |
|
90 * @return error handler |
|
91 */ |
|
92 inline MImpsErrorHandler2* ErrorHandler(); |
|
93 |
|
94 /** |
|
95 * Error handler mutator. |
|
96 * Registers status to server too. |
|
97 */ |
|
98 void SetErrorHandlerL( MImpsErrorHandler2* aObserver ); |
|
99 |
|
100 /** |
|
101 * Request event message body from the server |
|
102 */ |
|
103 void EventHandled(); |
|
104 |
|
105 private: // New functions |
|
106 |
|
107 /** |
|
108 * Read message from server thread |
|
109 * @param aLength data length to be read |
|
110 * @return ETrue if message read complete, no need to read body separately |
|
111 */ |
|
112 TBool ReadDataL( TInt aLength ); |
|
113 |
|
114 /** |
|
115 * Request event message body from the server |
|
116 */ |
|
117 void EventBody(); |
|
118 |
|
119 /** |
|
120 * Reset IPC buffer |
|
121 */ |
|
122 void ResetBuffers(); |
|
123 |
|
124 /** |
|
125 * Current event message buffer size |
|
126 * @return buffer size |
|
127 */ |
|
128 inline TInt CurrentSize() const; |
|
129 |
|
130 protected: // New functions |
|
131 |
|
132 /** |
|
133 * Actual construction. |
|
134 */ |
|
135 void ConstructL(); |
|
136 |
|
137 /** |
|
138 * Call appropriate observer |
|
139 * @param aErrorFields used if error case. NULL or ImpsFields structure |
|
140 * |
|
141 */ |
|
142 virtual void HandleEventL( CImpsFields* aErrorFields )=0; |
|
143 |
|
144 /** |
|
145 * Detailed error handling |
|
146 * @param aOpCode operation-id |
|
147 * @param aStatus error code |
|
148 * @param aFields error data |
|
149 */ |
|
150 void HandleErrorEventL( |
|
151 TInt aOpCode, TInt aStatus, CImpsFields* aFields); |
|
152 |
|
153 /** |
|
154 * Registers base class observer for session status change observer |
|
155 */ |
|
156 void DoRegisterStatusHandlerL( ); |
|
157 |
|
158 /** |
|
159 * Unregisters base class observer for session status change observer |
|
160 */ |
|
161 void DoUnregisterStatusHandlerL( ); |
|
162 |
|
163 /** |
|
164 * Registers base class observer for detailed error observer |
|
165 */ |
|
166 void DoRegisterErrorHandlerL( ); |
|
167 |
|
168 /** |
|
169 * Unregisters base class observer for detailed error observer |
|
170 */ |
|
171 void DoUnregisterErrorHandlerL( ); |
|
172 |
|
173 protected: |
|
174 |
|
175 /** |
|
176 * C++ constructor |
|
177 */ |
|
178 CImpsHandler2( TInt aPriority, RImpsClient2& aClient ); |
|
179 |
|
180 |
|
181 protected: // Functions from base classes |
|
182 |
|
183 /** |
|
184 * From CActive |
|
185 */ |
|
186 void RunL(); |
|
187 |
|
188 /** |
|
189 * From CActive |
|
190 */ |
|
191 void DoCancel(); |
|
192 |
|
193 protected: // Data |
|
194 |
|
195 // Message header area |
|
196 TBuf<sizeof(SImpsEventData)> iEventData; |
|
197 |
|
198 // Client interface reference who is using this object |
|
199 RImpsClient2& iClient; |
|
200 // Pointer to registered online status observer |
|
201 MImpsStatusHandler2* iStatusHandler; |
|
202 // Pointer to registered detailed error observer |
|
203 MImpsErrorHandler2* iErrorHandler; |
|
204 // Internal message data structure |
|
205 CImpsFields* iFields; |
|
206 |
|
207 private: // Data |
|
208 |
|
209 // Pointer to stack variable to detect the deletion of the heap |
|
210 // instance. This case takes place if a client |
|
211 // calls Unregister in observer method. |
|
212 TBool* iDestroyedPtr; |
|
213 |
|
214 // IPC buffers and auxiliary classes |
|
215 TIpcArgs iArgs; |
|
216 HBufC8* iBody; |
|
217 TWvBuf* iPtrStore; |
|
218 |
|
219 // Timer for server busy situations |
|
220 CImpsHandlerTimer* iBusyTimer; |
|
221 }; |
|
222 |
|
223 |
|
224 inline MImpsStatusHandler2* CImpsHandler2::StatusHandler() |
|
225 { |
|
226 return iStatusHandler; |
|
227 } |
|
228 |
|
229 inline MImpsErrorHandler2* CImpsHandler2::ErrorHandler() |
|
230 { |
|
231 return iErrorHandler; |
|
232 } |
|
233 |
|
234 inline TInt CImpsHandler2::CurrentSize() const |
|
235 { |
|
236 return iBody ? iBody->Des().MaxSize() : 0; |
|
237 } |
|
238 |
|
239 #endif |
|
240 |
|
241 // End of File |