|
1 /* |
|
2 * Copyright (c) 2003 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 * AO class for alive timer. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #ifndef CImpsAliveManager_H |
|
21 #define CImpsAliveManager_H |
|
22 |
|
23 |
|
24 // INCLUDES |
|
25 #include <e32base.h> |
|
26 #include "impsservercommon.h" |
|
27 |
|
28 // CONSTANTS |
|
29 const TInt KImpsMaxAliveRetryOnce = 2; // max retries in one round |
|
30 const TInt KImpsMaxAliveScheduleErr = 1; // nbr of scheduled rounds may fail |
|
31 const TInt KUseAfterLimit = 120; // internal aux contant |
|
32 |
|
33 |
|
34 // DATA TYPES |
|
35 enum TImpsAliveState |
|
36 { |
|
37 EImpsAliveIdle, // Timer not started |
|
38 EImpsAliveActive, // Timer started |
|
39 EImpsAlivePending, // Waiting response |
|
40 }; |
|
41 |
|
42 // FORWARD DECLARATIONS |
|
43 class MImpsCSPSession; |
|
44 class CImpsAliveManager; |
|
45 class CImpsAliveTimer; |
|
46 |
|
47 // CLASS DECLARATION |
|
48 |
|
49 class CImpsAliveManager : public CActive |
|
50 { |
|
51 public: // Constructors and destructor |
|
52 |
|
53 |
|
54 /** |
|
55 * Two-phased constructor. |
|
56 * @param aServer WV engine server |
|
57 */ |
|
58 static CImpsAliveManager* NewL( MImpsCSPSession& aServer ); |
|
59 |
|
60 /** |
|
61 * Destructor. |
|
62 */ |
|
63 virtual ~CImpsAliveManager(); |
|
64 |
|
65 public: |
|
66 |
|
67 |
|
68 /** |
|
69 * Start KeepAlive timer for idle times |
|
70 * @param aInterval idle time in seconds |
|
71 * @return error code |
|
72 */ |
|
73 void StartTimer( TInt aInterval ); |
|
74 |
|
75 /** |
|
76 * Stop KeepAlive timer for idle times |
|
77 */ |
|
78 void StopTimer( ); |
|
79 |
|
80 /** |
|
81 * Check transport response and decide what to do. |
|
82 * @param aCode error code |
|
83 */ |
|
84 void CheckResp( TInt aCode ); |
|
85 |
|
86 /** |
|
87 * Check transport error and decide what to do. |
|
88 * @param aTid failed transaction-id |
|
89 */ |
|
90 void CheckError( const TDesC& aTid ); |
|
91 |
|
92 /** |
|
93 * Send KeepAlive primitive |
|
94 * @param aSchedule true if triggered by scheduled timer |
|
95 */ |
|
96 void SendKeepAlive( TBool aSchedule ); |
|
97 |
|
98 protected: |
|
99 // From base class |
|
100 void RunL(); |
|
101 |
|
102 void DoCancel(); |
|
103 |
|
104 private: |
|
105 |
|
106 /** |
|
107 * C++ default constructor. |
|
108 * @param aServer WV engine server |
|
109 */ |
|
110 CImpsAliveManager( MImpsCSPSession& aServer ); |
|
111 |
|
112 /** |
|
113 * By default Symbian OS constructor is private. |
|
114 */ |
|
115 void ConstructL(); |
|
116 |
|
117 // By default, prohibit copy constructor |
|
118 CImpsAliveManager( const CImpsAliveManager& ); |
|
119 // Prohibit assigment operator |
|
120 CImpsAliveManager& operator= ( const CImpsAliveManager& ); |
|
121 |
|
122 /** |
|
123 * Do the error routines. |
|
124 */ |
|
125 void DoHandleError( ); |
|
126 |
|
127 /** |
|
128 * Close CSP Session |
|
129 */ |
|
130 void DoSessionClose(); |
|
131 |
|
132 |
|
133 private: // Data |
|
134 TInt iFailCount; |
|
135 TInt iTimerFail; |
|
136 TImpsAliveState iState; |
|
137 MImpsCSPSession& iServer; |
|
138 CImpsAliveTimer* iTimer; |
|
139 TBool iScheduled; |
|
140 TBuf<KImpsMaxTID> iTid; |
|
141 TInt iSeconds; |
|
142 }; |
|
143 |
|
144 |
|
145 |
|
146 // CLASS DECLARATION |
|
147 |
|
148 /** |
|
149 * CImpsAliveTimer |
|
150 * Idle timer to lauch Keep-Alive requests in CSP protocol. |
|
151 */ |
|
152 class CImpsAliveTimer: public CActive |
|
153 { |
|
154 public: |
|
155 |
|
156 /** |
|
157 * Constructor |
|
158 * @param aServer WV engine server |
|
159 * @param aPriority active object priority |
|
160 */ |
|
161 CImpsAliveTimer( CImpsAliveManager& aServer, TInt aPriority ); |
|
162 |
|
163 /** |
|
164 * Destructor |
|
165 */ |
|
166 virtual ~CImpsAliveTimer(); |
|
167 |
|
168 /** |
|
169 * Start waiting. If not reset again while wait time |
|
170 * then Alive msg will be sent. |
|
171 * Use CActive::Cancel() to cancel the request. |
|
172 * @param aWaitSeconds wait time in seconds |
|
173 */ |
|
174 void Start( TInt aWaitSeconds ); |
|
175 |
|
176 /** |
|
177 * Stop the timer |
|
178 */ |
|
179 void Stop( ); |
|
180 |
|
181 |
|
182 protected: |
|
183 // From base class |
|
184 void RunL(); |
|
185 |
|
186 void DoCancel(); |
|
187 private: |
|
188 TInt iSeconds; |
|
189 CImpsAliveManager& iMgr; |
|
190 RTimer iTimer; |
|
191 TBool iReset; |
|
192 TBool iCanceled; |
|
193 TInt iMicroSeconds; |
|
194 |
|
195 }; |
|
196 |
|
197 |
|
198 #endif // ?INCLUDE_H |
|
199 |
|
200 // End of File |