39
|
1 |
/*
|
|
2 |
* ==============================================================================
|
|
3 |
* Name : epos_csuplsessionretryq.cpp
|
|
4 |
* Part of : SUPL Framework / SUPL Server
|
|
5 |
* Description : Class to handle retries of failed requests. It waits for all the current sessions to end and then
|
|
6 |
* notifies the failed sessions that they can retry.
|
|
7 |
* Version :
|
|
8 |
*
|
|
9 |
* Copyright (c) 2010 Nokia Corporation.
|
|
10 |
* This material, including documentation and any related
|
|
11 |
* computer programs, is protected by copyright controlled by
|
|
12 |
* Nokia Corporation. All rights are reserved. Copying,
|
|
13 |
* including reproducing, storing, adapting or translating, any
|
|
14 |
* or all of this material requires the prior written consent of
|
|
15 |
* Nokia Corporation. This material also contains confidential
|
|
16 |
* information which may not be disclosed to others without the
|
|
17 |
* prior written consent of Nokia Corporation.
|
|
18 |
* ==============================================================================
|
|
19 |
*/
|
|
20 |
|
|
21 |
// INCLUDE FILES
|
|
22 |
#include <e32base.h>
|
|
23 |
#include <e32debug.h>
|
|
24 |
|
|
25 |
#include "epos_csuplsessionretryq.h"
|
|
26 |
#include "epos_csuplsessionrequest.h"
|
|
27 |
#include "epos_csuplglobal.h"
|
|
28 |
|
|
29 |
//#ifdef _DEBUG
|
|
30 |
_LIT(KTraceFileName, "SUPL_GW::epos_csuplsessionretryq.cpp");
|
|
31 |
//#endif
|
|
32 |
|
|
33 |
// CONSTANTS
|
|
34 |
const TTimeIntervalSeconds KRecentConnectionInterval(5);
|
|
35 |
const TTimeIntervalMicroSeconds32 KSmallDelay(2000000);
|
|
36 |
const TTimeIntervalMicroSeconds32 KReissueRequestDelay(5000000);
|
|
37 |
|
|
38 |
// ================= MEMBER FUNCTIONS =======================
|
|
39 |
|
|
40 |
// C++ default constructor can NOT contain any code, that
|
|
41 |
// might leave.
|
|
42 |
//
|
|
43 |
CSuplSessionRetryQ::CSuplSessionRetryQ()
|
|
44 |
: CTimer(EPriorityNormal)
|
|
45 |
{
|
|
46 |
DEBUG_TRACE("CSuplSessionRetryQ", __LINE__)
|
|
47 |
CActiveScheduler::Add(this);
|
|
48 |
}
|
|
49 |
|
|
50 |
// Destructor
|
|
51 |
CSuplSessionRetryQ::~CSuplSessionRetryQ()
|
|
52 |
{
|
|
53 |
DEBUG_TRACE("~CSuplSessionRetryQ", __LINE__)
|
|
54 |
Cancel();
|
|
55 |
iSessionRequests.Close();
|
|
56 |
}
|
|
57 |
|
|
58 |
// Two-phased constructor
|
|
59 |
CSuplSessionRetryQ* CSuplSessionRetryQ::NewL()
|
|
60 |
{
|
|
61 |
DEBUG_TRACE("NewL", __LINE__)
|
|
62 |
CSuplSessionRetryQ* self = new (ELeave) CSuplSessionRetryQ();
|
|
63 |
CleanupStack::PushL(self);
|
|
64 |
self->ConstructL();
|
|
65 |
CleanupStack::Pop();
|
|
66 |
return self;
|
|
67 |
}
|
|
68 |
|
|
69 |
// EPOC default constructor
|
|
70 |
void CSuplSessionRetryQ::ConstructL()
|
|
71 |
{
|
|
72 |
DEBUG_TRACE("ConstructL", __LINE__)
|
|
73 |
CTimer::ConstructL();
|
|
74 |
}
|
|
75 |
|
|
76 |
|
|
77 |
void CSuplSessionRetryQ::AddToQueueL(CSuplSessionRequest& aSessionRequest)
|
|
78 |
{
|
|
79 |
TBuf<256> msg(_L("AddToQueueL, count = "));
|
|
80 |
msg.AppendNum(iSessionRequests.Count()+1);
|
|
81 |
SuplGlobal::Trace(msg, KTraceFileName, __LINE__);
|
|
82 |
// if there is no open connection and there is nothing else in the queue then check when it's possible to
|
|
83 |
// re-issue, otherwise just leave in the queue
|
|
84 |
if(iSessionRequests.Count() == 0 && iSessionCount == 0)
|
|
85 |
{
|
|
86 |
TTime now;
|
|
87 |
now.UniversalTime();
|
|
88 |
// if there was some recent connection made that was closed then ask for re-issue straight away
|
|
89 |
if(iSomeSessionEnded && now - KRecentConnectionInterval < iTimeOfLastEndedSession)
|
|
90 |
{
|
|
91 |
DEBUG_TRACE("Re-issuing request straight away", __LINE__)
|
|
92 |
RDebug::Printf("[LBS][SUPL]Re-issuing request straight away");
|
|
93 |
After(KSmallDelay);
|
|
94 |
}
|
|
95 |
// if there is no previous request then wait a little before re-issuing request
|
|
96 |
else
|
|
97 |
{
|
|
98 |
DEBUG_TRACE("Re-issuing request after a delay", __LINE__)
|
|
99 |
RDebug::Printf("[LBS][SUPL]Re-issuing request after a delay");
|
|
100 |
After(KReissueRequestDelay);
|
|
101 |
}
|
|
102 |
}
|
|
103 |
iSessionRequests.AppendL(&aSessionRequest);
|
|
104 |
}
|
|
105 |
|
|
106 |
void CSuplSessionRetryQ::RemoveFromQueueL(CSuplSessionRequest& aSessionRequest)
|
|
107 |
{
|
|
108 |
TInt index = 0;
|
|
109 |
index = iSessionRequests.Find(&aSessionRequest);
|
|
110 |
if(index != KErrNotFound)
|
|
111 |
{
|
|
112 |
iSessionRequests.Remove(index);
|
|
113 |
|
|
114 |
TBuf<256> msg(_L("Removed from queue, count = "));
|
|
115 |
msg.AppendNum(iSessionRequests.Count());
|
|
116 |
SuplGlobal::Trace(msg, KTraceFileName, __LINE__);
|
|
117 |
|
|
118 |
}
|
|
119 |
}
|
|
120 |
|
|
121 |
void CSuplSessionRetryQ::SessionStarted()
|
|
122 |
{
|
|
123 |
++iSessionCount;
|
|
124 |
|
|
125 |
|
|
126 |
TBuf<256> msg(_L("SessionStarted, session count = "));
|
|
127 |
msg.AppendNum(iSessionCount);
|
|
128 |
SuplGlobal::Trace(msg, KTraceFileName, __LINE__);
|
|
129 |
}
|
|
130 |
|
|
131 |
void CSuplSessionRetryQ::SessionEnded()
|
|
132 |
{
|
|
133 |
--iSessionCount;
|
|
134 |
|
|
135 |
TBuf<256> msg(_L("SessionEnded, session count = "));
|
|
136 |
msg.AppendNum(iSessionCount);
|
|
137 |
SuplGlobal::Trace(msg, KTraceFileName, __LINE__);
|
|
138 |
|
|
139 |
|
|
140 |
if(iSessionCount == 0 && iSessionRequests.Count() > 0)
|
|
141 |
{
|
|
142 |
DEBUG_TRACE("Re-issuing request straight away", __LINE__)
|
|
143 |
After(KSmallDelay);
|
|
144 |
}
|
|
145 |
// If a connection just closed remember the time-stamp so later it can be decided when to re-issue
|
|
146 |
iSomeSessionEnded = ETrue;
|
|
147 |
iTimeOfLastEndedSession.UniversalTime();
|
|
148 |
}
|
|
149 |
|
|
150 |
// ---------------------------------------------------------
|
|
151 |
// CSuplSessionRetryQ::RunL
|
|
152 |
//
|
|
153 |
// (other items were commented in a header).
|
|
154 |
// ---------------------------------------------------------
|
|
155 |
//
|
|
156 |
void CSuplSessionRetryQ::RunL()
|
|
157 |
{
|
|
158 |
TBuf<256> msg(_L("RunL, session count = "));
|
|
159 |
msg.AppendNum(iSessionCount);
|
|
160 |
msg.Append(_L(", queue count = "));
|
|
161 |
msg.AppendNum(iSessionRequests.Count());
|
|
162 |
SuplGlobal::Trace(msg, KTraceFileName, __LINE__);
|
|
163 |
|
|
164 |
// If a connection is already open, wait until it finishes
|
|
165 |
if(iSessionCount == 0 && iSessionRequests.Count() > 0)
|
|
166 |
{
|
|
167 |
DEBUG_TRACE("Re-issuing request now", __LINE__)
|
|
168 |
// re-issue request for the first item in the queue
|
|
169 |
TRAPD(err, iSessionRequests[0]->ReIssueRequestL());
|
|
170 |
while(err!=KErrNone && iSessionRequests.Count() > 1)
|
|
171 |
{
|
|
172 |
// if for some reason re-issuing doesn't work then just try the next requestor and forget about the first one
|
|
173 |
DEBUG_TRACE("Re-issue failed, trying next one in the queue", __LINE__)
|
|
174 |
iSessionRequests.Remove(0);
|
|
175 |
TRAP(err, iSessionRequests[0]->ReIssueRequestL());
|
|
176 |
}
|
|
177 |
if(err!=KErrNone)
|
|
178 |
{
|
|
179 |
DEBUG_TRACE("Re-issue failed", __LINE__)
|
|
180 |
}
|
|
181 |
iSessionRequests.Remove(0);
|
|
182 |
}
|
|
183 |
}
|
|
184 |
|
|
185 |
|