1 /* |
|
2 * Copyright (c) 2005 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: Connection manager timer |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDES |
|
22 #include "msgconntimer.h" |
|
23 #include "msgconnmanager.h" |
|
24 |
|
25 // ================= MEMBER FUNCTIONS ======================= |
|
26 |
|
27 // --------------------------------------------------------- |
|
28 // C++ constructor can NOT contain any code, that |
|
29 // might leave. |
|
30 // --------------------------------------------------------- |
|
31 // |
|
32 CMsgConnTimer::CMsgConnTimer() : CActive( EPriorityStandard ), |
|
33 iCompleteIfCancel( EFalse ) |
|
34 |
|
35 { |
|
36 } |
|
37 |
|
38 // --------------------------------------------------------- |
|
39 // C++ constructor can NOT contain any code, that |
|
40 // might leave. |
|
41 // --------------------------------------------------------- |
|
42 // |
|
43 CMsgConnTimer::CMsgConnTimer( MMsgConnTimerCallback* aClient ) : |
|
44 CActive( EPriorityStandard ), |
|
45 iClient( aClient ) |
|
46 |
|
47 |
|
48 { |
|
49 } |
|
50 |
|
51 // --------------------------------------------------------- |
|
52 // Symbian OS default constructor may leave. |
|
53 // |
|
54 // --------------------------------------------------------- |
|
55 // |
|
56 void CMsgConnTimer::ConstructL() |
|
57 { |
|
58 User::LeaveIfError( iTimer.CreateLocal() ); |
|
59 CActiveScheduler::Add( this ); |
|
60 } |
|
61 |
|
62 // --------------------------------------------------------- |
|
63 // Two-phased constructor. |
|
64 // |
|
65 // --------------------------------------------------------- |
|
66 // |
|
67 CMsgConnTimer* CMsgConnTimer::NewL() |
|
68 { |
|
69 CMsgConnTimer* self = new ( ELeave ) CMsgConnTimer(); |
|
70 CleanupStack::PushL( self ); |
|
71 self->ConstructL(); |
|
72 CleanupStack::Pop(); |
|
73 return self; |
|
74 } |
|
75 |
|
76 // --------------------------------------------------------- |
|
77 // Two-phased constructor. |
|
78 // |
|
79 // --------------------------------------------------------- |
|
80 // |
|
81 CMsgConnTimer* CMsgConnTimer::NewL( MMsgConnTimerCallback* aClient ) |
|
82 { |
|
83 CMsgConnTimer* self = new ( ELeave ) CMsgConnTimer( aClient ); |
|
84 CleanupStack::PushL( self ); |
|
85 self->ConstructL(); |
|
86 CleanupStack::Pop(); |
|
87 return self; |
|
88 } |
|
89 |
|
90 // --------------------------------------------------------- |
|
91 // Destructor |
|
92 // |
|
93 // --------------------------------------------------------- |
|
94 // |
|
95 CMsgConnTimer::~CMsgConnTimer() |
|
96 { |
|
97 #ifdef _DEBUG |
|
98 CMsgConnManager::WriteToLog( _L8( "CMsgConnTimer::~CMsgConnTimer(), destructor called." ) ); |
|
99 #endif |
|
100 Cancel(); |
|
101 iTimer.Close(); |
|
102 } |
|
103 |
|
104 // --------------------------------------------------------- |
|
105 // CMsgConnTimer::ActivateTimer |
|
106 // |
|
107 // --------------------------------------------------------- |
|
108 // |
|
109 void CMsgConnTimer::ActivateTimer( TRequestStatus& aStatus, |
|
110 TTimeIntervalMicroSeconds32 aDelay ) |
|
111 { |
|
112 #ifdef _DEBUG |
|
113 CMsgConnManager::WriteToLog( _L8( "CMsgConnTimer::ActivateTimer()." ) ); |
|
114 #endif |
|
115 __ASSERT_ALWAYS( !IsActive(), User::Panic( _L("ConnectionTimer"), 1 ) ); |
|
116 iClient = NULL; |
|
117 aStatus = KRequestPending; |
|
118 iClientStatus = &aStatus; |
|
119 iTimer.After( iStatus, aDelay ); |
|
120 #ifdef _DEBUG |
|
121 CMsgConnManager::WriteToLog( _L8( " Timer activated." ) ); |
|
122 #endif |
|
123 SetActive(); |
|
124 } |
|
125 |
|
126 // --------------------------------------------------------- |
|
127 // CMsgConnTimer::ActivateTimer |
|
128 // |
|
129 // --------------------------------------------------------- |
|
130 // |
|
131 void CMsgConnTimer::ActivateTimer( MMsgConnTimerCallback* aClient, |
|
132 TTimeIntervalMicroSeconds32 aDelay ) |
|
133 { |
|
134 #ifdef _DEBUG |
|
135 CMsgConnManager::WriteToLog( _L8( "CMsgConnTimer::ActivateTimer()" ) ); |
|
136 #endif |
|
137 __ASSERT_ALWAYS( !IsActive(), User::Panic( _L("ConnectionTimer"), 1 ) ); |
|
138 iClient = aClient; |
|
139 iClientStatus = NULL; |
|
140 iTimer.After( iStatus, aDelay ); |
|
141 #ifdef _DEBUG |
|
142 CMsgConnManager::WriteToLog( _L8( " Timer activated (with client)" ) ); |
|
143 #endif |
|
144 SetActive(); |
|
145 } |
|
146 |
|
147 // --------------------------------------------------------- |
|
148 // CMsgConnTimer::RunL |
|
149 // |
|
150 // --------------------------------------------------------- |
|
151 // |
|
152 void CMsgConnTimer::RunL() |
|
153 { |
|
154 #ifdef _DEBUG |
|
155 CMsgConnManager::WriteToLog( _L8( "CMsgConnTimer::RunL()." ) ); |
|
156 #endif |
|
157 if( iClient != NULL ) |
|
158 { |
|
159 #ifdef _DEBUG |
|
160 CMsgConnManager::WriteToLog( _L8( " iClient != NULL, Callback interface in use." ) ); |
|
161 #endif |
|
162 iClient->HandleTimerEvent( iStatus.Int() ); |
|
163 iClient = NULL; |
|
164 } |
|
165 else |
|
166 { |
|
167 #ifdef _DEBUG |
|
168 CMsgConnManager::WriteToLog( _L8( " iClient == NULL, completing request." ) ); |
|
169 #endif |
|
170 User::RequestComplete( iClientStatus, iStatus.Int() ); |
|
171 } |
|
172 } |
|
173 |
|
174 // --------------------------------------------------------- |
|
175 // CMsgConnTimer::DoCancel |
|
176 // |
|
177 // --------------------------------------------------------- |
|
178 // |
|
179 void CMsgConnTimer::DoCancel() |
|
180 { |
|
181 #ifdef _DEBUG |
|
182 CMsgConnManager::WriteToLog( _L8( "CMsgConnTimer::DoCancel()" ) ); |
|
183 #endif |
|
184 iTimer.Cancel(); |
|
185 if( iClientStatus != NULL ) |
|
186 User::RequestComplete( iClientStatus, KErrCancel ); |
|
187 #ifdef _DEBUG |
|
188 CMsgConnManager::WriteToLog( _L8( " DoCancel() ends" ) ); |
|
189 #endif |
|
190 } |
|
191 |
|
192 // End of File |
|
193 |
|