|
1 /** @file |
|
2 * Copyright (c) 2005-2008 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: CUpnpTimeoutElement |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <e32base.h> |
|
22 #include "upnptimeoutelement.h" |
|
23 #define KLogFile _L("UPnPStack.txt") |
|
24 #include "upnpcustomlog.h" |
|
25 |
|
26 // ============================ MEMBER FUNCTIONS =============================== |
|
27 |
|
28 // ----------------------------------------------------------------------------- |
|
29 // CUpnpTimeoutElement::CUpnpTimeoutElement |
|
30 // C++ default constructor can NOT contain any code, that |
|
31 // might leave. |
|
32 // ----------------------------------------------------------------------------- |
|
33 // |
|
34 EXPORT_C CUpnpTimeoutElement::CUpnpTimeoutElement(MUpnpTimeoutElementParent& aParent) |
|
35 : CActive(EPriorityNormal), iParent(aParent) |
|
36 { |
|
37 CActiveScheduler::Add( this ); |
|
38 iRenew = EOnce; |
|
39 } |
|
40 |
|
41 // ---------------------------------------------------------------------------- |
|
42 // CUpnpTimeoutElement::BaseConstructL |
|
43 // Base class constructor. |
|
44 // ----------------------------------------------------------------------------- |
|
45 // |
|
46 EXPORT_C void CUpnpTimeoutElement::BaseConstructL() |
|
47 { |
|
48 TInt err = iTimer.CreateLocal(); |
|
49 if ( KErrNone != err ) |
|
50 { |
|
51 LOGS1("CUpnpTimeoutElement::CUpnpTimeoutElement() CreateLocal FAILED: %d", err ); |
|
52 User::Leave( err ); |
|
53 } |
|
54 } |
|
55 // ----------------------------------------------------------------------------- |
|
56 // CUpnpTimeoutElement::~CUpnpTimeoutElement |
|
57 // Destructor. |
|
58 // ----------------------------------------------------------------------------- |
|
59 // |
|
60 EXPORT_C CUpnpTimeoutElement::~CUpnpTimeoutElement() |
|
61 { |
|
62 Cancel(); |
|
63 iTimer.Close(); |
|
64 } |
|
65 |
|
66 // ----------------------------------------------------------------------------- |
|
67 // CUpnpTimeoutElement::SetTimeout |
|
68 // Set timeout and start timer |
|
69 // ----------------------------------------------------------------------------- |
|
70 // |
|
71 EXPORT_C void CUpnpTimeoutElement::SetTimeout( TInt aSeconds ) |
|
72 { |
|
73 iSeconds=aSeconds; |
|
74 if (iSeconds>KTime) |
|
75 { |
|
76 TUint32 microsec = KTime * KMicroInSec; |
|
77 if ( IsActive() ) |
|
78 { |
|
79 Cancel(); |
|
80 } |
|
81 iTimer.After(iStatus, TTimeIntervalMicroSeconds32(microsec)); |
|
82 SetActive(); |
|
83 iState = ELongTime; |
|
84 } |
|
85 else |
|
86 { |
|
87 TUint32 microsec = aSeconds * KMicroInSec; |
|
88 if ( IsActive() ) |
|
89 { |
|
90 Cancel(); |
|
91 } |
|
92 iTimer.After(iStatus, TTimeIntervalMicroSeconds32(microsec)); |
|
93 SetActive(); |
|
94 iState = EAlive; |
|
95 } |
|
96 } |
|
97 |
|
98 // ----------------------------------------------------------------------------- |
|
99 // CUpnpTimeoutElement::RunL |
|
100 // When timer expires, RunL is called. |
|
101 // ----------------------------------------------------------------------------- |
|
102 // |
|
103 EXPORT_C void CUpnpTimeoutElement::RunL() |
|
104 { |
|
105 if (iStatus.Int() == KErrNone) |
|
106 { |
|
107 switch( iState ) |
|
108 { |
|
109 case ELongTime: |
|
110 if (iSeconds>KTime) iSeconds=iSeconds-KTime; |
|
111 SetTimeout(iSeconds); |
|
112 break; |
|
113 case EAlive: |
|
114 TRAP_IGNORE( iParent.TimeoutExpiredL( this ) ); |
|
115 break; |
|
116 case EDead: |
|
117 default: |
|
118 |
|
119 break; |
|
120 } |
|
121 } |
|
122 else |
|
123 { |
|
124 LOGS1("CUpnpTimeoutElement::CUpnpTimeoutElement() RunL iStatus %d", iStatus.Int() ); |
|
125 } |
|
126 } |
|
127 |
|
128 // ----------------------------------------------------------------------------- |
|
129 // CUpnpTimeoutElement::DoCancel |
|
130 // Cancel active request. |
|
131 // ----------------------------------------------------------------------------- |
|
132 // |
|
133 EXPORT_C void CUpnpTimeoutElement::DoCancel() |
|
134 { |
|
135 iTimer.Cancel(); |
|
136 } |
|
137 |
|
138 // ----------------------------------------------------------------------------- |
|
139 // CUpnpTimeoutElement::RunError |
|
140 // Cancel active request. |
|
141 // ----------------------------------------------------------------------------- |
|
142 // |
|
143 EXPORT_C TInt CUpnpTimeoutElement::RunError( TInt aError ) |
|
144 { |
|
145 LOGS1("CUpnpTimeoutElement::RunError, error %d",aError); |
|
146 return KErrNone; |
|
147 } |
|
148 |
|
149 |
|
150 // ----------------------------------------------------------------------------- |
|
151 // CUpnpTimeoutElement::SetRenew |
|
152 // Set renew. |
|
153 // ----------------------------------------------------------------------------- |
|
154 // |
|
155 EXPORT_C void CUpnpTimeoutElement::SetRenew( TRenew aRenew ) |
|
156 { |
|
157 iRenew = aRenew; |
|
158 } |
|
159 |
|
160 // ----------------------------------------------------------------------------- |
|
161 // CUpnpTimeoutElement::Renew |
|
162 // Return renew. |
|
163 // ----------------------------------------------------------------------------- |
|
164 // |
|
165 EXPORT_C CUpnpTimeoutElement::TRenew& CUpnpTimeoutElement::Renew() |
|
166 { |
|
167 return iRenew; |
|
168 } |
|
169 |
|
170 // End of File |