|
1 /* |
|
2 * Copyright (c) 2002-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: Declares CUPTimer class |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32svr.h> |
|
20 #include <upnpitem.h> |
|
21 |
|
22 #include "cuptimer.h" |
|
23 |
|
24 // --------------------------------------------------------------------------- |
|
25 // NewL |
|
26 // --------------------------------------------------------------------------- |
|
27 // |
|
28 CUPTimer* CUPTimer::NewL() |
|
29 { |
|
30 CUPTimer* self = NewLC(); |
|
31 CleanupStack::Pop(self); |
|
32 return self; |
|
33 } |
|
34 |
|
35 // --------------------------------------------------------------------------- |
|
36 // NewLC |
|
37 // --------------------------------------------------------------------------- |
|
38 // |
|
39 CUPTimer* CUPTimer::NewLC() |
|
40 { |
|
41 CUPTimer* self = new (ELeave) CUPTimer(); |
|
42 CleanupStack::PushL(self); |
|
43 self->ConstructL(); |
|
44 return self; |
|
45 } |
|
46 |
|
47 // --------------------------------------------------------------------------- |
|
48 // ~CUPTimer |
|
49 // --------------------------------------------------------------------------- |
|
50 // |
|
51 CUPTimer::~CUPTimer() |
|
52 { |
|
53 |
|
54 Cancel(); |
|
55 |
|
56 if (iTimeOutTimer) |
|
57 { |
|
58 delete iTimeOutTimer; |
|
59 iTimeOutTimer = NULL; |
|
60 } |
|
61 } |
|
62 |
|
63 // --------------------------------------------------------------------------- |
|
64 // SetActiveNow |
|
65 // --------------------------------------------------------------------------- |
|
66 // |
|
67 void CUPTimer::SetActiveNow() |
|
68 { |
|
69 TRequestStatus* statusPtr = &iStatus; |
|
70 User::RequestComplete (statusPtr, KErrNone); |
|
71 } |
|
72 |
|
73 // --------------------------------------------------------------------------- |
|
74 // RunL |
|
75 // --------------------------------------------------------------------------- |
|
76 // |
|
77 void CUPTimer::RunL() |
|
78 { |
|
79 iTimeOutTimer->Cancel(); |
|
80 iObserver->TimerExpiredL(iItemToShare); |
|
81 } |
|
82 |
|
83 // --------------------------------------------------------------------------- |
|
84 // RunL |
|
85 // --------------------------------------------------------------------------- |
|
86 // |
|
87 TInt CUPTimer::RunError(TInt aError) |
|
88 { |
|
89 Cancel(); |
|
90 |
|
91 return aError; |
|
92 } |
|
93 |
|
94 // --------------------------------------------------------------------------- |
|
95 // DoCancel |
|
96 // --------------------------------------------------------------------------- |
|
97 // |
|
98 void CUPTimer::DoCancel() |
|
99 { |
|
100 if (iTimeOutTimer->IsActive()) |
|
101 { |
|
102 iTimeOutTimer->Cancel(); |
|
103 } |
|
104 return; |
|
105 } |
|
106 |
|
107 // --------------------------------------------------------------------------- |
|
108 // WaitUntilTimeExpired |
|
109 // --------------------------------------------------------------------------- |
|
110 // |
|
111 void CUPTimer::WaitUntilTimeExpired(MUPTimerObserver* aObserver, |
|
112 TTimeIntervalMicroSeconds32 aTimeOut, |
|
113 CUpnpItem* aItemToShare)//, |
|
114 // TRequestStatus &aStatus) |
|
115 { |
|
116 |
|
117 /* This might be a little bit dangerous but server knows when to start timer */ |
|
118 Cancel(); |
|
119 |
|
120 iItemToShare = aItemToShare; |
|
121 |
|
122 if(!IsActive()) |
|
123 { |
|
124 SetActive(); |
|
125 } |
|
126 |
|
127 |
|
128 iObserver = aObserver; |
|
129 |
|
130 // Start the time out timer |
|
131 TRAPD(trapError, iTimeOutTimer = CPeriodic::NewL(EPriorityBackground)); |
|
132 if (trapError != KErrNone) |
|
133 { |
|
134 |
|
135 } |
|
136 |
|
137 TCallBack callback(CUPTimer::TimedOut,(TAny*)(this)); |
|
138 iTimeOutTimer->Start(aTimeOut, aTimeOut, callback); |
|
139 |
|
140 iStatus = KRequestPending; |
|
141 } |
|
142 |
|
143 |
|
144 // --------------------------------------------------------------------------- |
|
145 // ConstructL |
|
146 // --------------------------------------------------------------------------- |
|
147 // |
|
148 void CUPTimer::ConstructL() |
|
149 { |
|
150 CActiveScheduler::Add(this); |
|
151 } |
|
152 |
|
153 // --------------------------------------------------------------------------- |
|
154 // CUPTimer |
|
155 // --------------------------------------------------------------------------- |
|
156 // |
|
157 CUPTimer::CUPTimer() : CActive(EPriorityNormal) |
|
158 { |
|
159 |
|
160 } |
|
161 |
|
162 // --------------------------------------------------------------------------- |
|
163 // CancelTimer |
|
164 // --------------------------------------------------------------------------- |
|
165 // |
|
166 |
|
167 void CUPTimer::CancelTimer() |
|
168 { |
|
169 Cancel(); |
|
170 } |
|
171 |
|
172 // --------------------------------------------------------------------------- |
|
173 // TimedOut |
|
174 // --------------------------------------------------------------------------- |
|
175 // |
|
176 TInt CUPTimer::TimedOut(TAny* aPtr) |
|
177 { |
|
178 CUPTimer* obj = reinterpret_cast<CUPTimer*>(aPtr); |
|
179 if (obj) |
|
180 { |
|
181 obj->SetActiveNow(); |
|
182 } |
|
183 |
|
184 return KErrNone; |
|
185 } |
|
186 |
|
187 // End of File |