748
|
1 |
// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
2 |
// All rights reserved.
|
|
3 |
// This component and the accompanying materials are made available
|
|
4 |
// under the terms of the License "Symbian Foundation License v1.0"
|
|
5 |
// which accompanies this distribution, and is available
|
|
6 |
// at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
// csesuresessionbase.cpp
|
|
15 |
//
|
|
16 |
//
|
|
17 |
|
|
18 |
#include "csecureserverbase.h"
|
|
19 |
#include "cshutdowntimer.h"
|
|
20 |
#include <e32debug.h>
|
|
21 |
/// Lbs
|
|
22 |
#include "lbsdevloggermacros.h"
|
|
23 |
|
|
24 |
/**
|
|
25 |
Create a new session, called from CPolicyServer
|
|
26 |
|
|
27 |
@param aVersion TVersion reference
|
|
28 |
@param aMessage RMessage2 object reference
|
|
29 |
@return CSession2 based object pointer
|
|
30 |
@internalTechnology
|
|
31 |
@released
|
|
32 |
*/
|
|
33 |
CSession2* CSecureServerBase::NewSessionL(const TVersion &aVersion, const RMessage2& aMessage) const
|
|
34 |
{
|
|
35 |
TVersion v = GetServerVersion();
|
|
36 |
if(!User::QueryVersionSupported(v, aVersion))
|
|
37 |
{
|
|
38 |
User::Leave(KErrNotSupported);
|
|
39 |
}
|
|
40 |
CSession2* session = DoNewSessionL(aVersion, aMessage);
|
|
41 |
return session;
|
|
42 |
}
|
|
43 |
|
|
44 |
/**
|
|
45 |
destrcutor, cancel if any outstanding request of shutdown timer and release it.
|
|
46 |
|
|
47 |
@internalTechnology
|
|
48 |
@released
|
|
49 |
*/
|
|
50 |
CSecureServerBase::~CSecureServerBase()
|
|
51 |
{
|
|
52 |
LBSLOG(ELogP1,"->CSecureServerBase::~CSecureServerBase");
|
|
53 |
if(iShutdownTimer)
|
|
54 |
{
|
|
55 |
if(iShutdownTimer->IsActive())
|
|
56 |
iShutdownTimer->Cancel();
|
|
57 |
}
|
|
58 |
delete iShutdownTimer;
|
|
59 |
iShutdownTimer = NULL;
|
|
60 |
LBSLOG(ELogP1,"->CSecureServerBase::~CSecureServerBase");
|
|
61 |
}
|
|
62 |
|
|
63 |
/**
|
|
64 |
Create shut down timer
|
|
65 |
|
|
66 |
@internalTechnology
|
|
67 |
@released
|
|
68 |
*/
|
|
69 |
void CSecureServerBase::BaseConstructL(TBool aShutdownTimerRequired)
|
|
70 |
{
|
|
71 |
LBSLOG(ELogP1,"->CSecureServerBase::BaseConstructL");
|
|
72 |
iBaseConstructCalled = ETrue;
|
|
73 |
if(aShutdownTimerRequired)
|
|
74 |
{
|
|
75 |
iShutdownTimer = new (ELeave) CShutdownTimer();
|
|
76 |
iShutdownTimer->ConstructL();
|
|
77 |
}
|
|
78 |
LBSLOG(ELogP1,"<-CSecureServerBase::BaseConstructL");
|
|
79 |
}
|
|
80 |
|
|
81 |
/**
|
|
82 |
constructor, create server base with specified priority and policy, default shut down time delay
|
|
83 |
|
|
84 |
@param aPriority Defined server priority
|
|
85 |
@param aSecurityPolicy A TPolicy object reference, to define server security policy
|
|
86 |
@internalTechnology
|
|
87 |
@released
|
|
88 |
*/
|
|
89 |
CSecureServerBase::CSecureServerBase(TInt aPriority, const TPolicy& aSecurityPolicy) : CPolicyServer(aPriority, aSecurityPolicy),
|
|
90 |
iShutdownDelay(KDefaultShutdownDelay)
|
|
91 |
{
|
|
92 |
// nothing to do?
|
|
93 |
}
|
|
94 |
|
|
95 |
/**
|
|
96 |
Increase the session count by 1
|
|
97 |
The function is called whenever a new session is created, cancel the current outstanding request of shutdown timer
|
|
98 |
|
|
99 |
@internalTechnology
|
|
100 |
@released
|
|
101 |
*/
|
|
102 |
void CSecureServerBase::IncSession()
|
|
103 |
{
|
|
104 |
LBSLOG(ELogP1,"->CSecureServerBase::IncSession");
|
|
105 |
__ASSERT_ALWAYS(iBaseConstructCalled, PanicServer(EBaseConstructNotCalled));
|
|
106 |
++iSessionCount;
|
|
107 |
if(iShutdownTimer)
|
|
108 |
{
|
|
109 |
iShutdownTimer->Cancel();
|
|
110 |
}
|
|
111 |
LBSLOG(ELogP1,"<-CSecureServerBase::IncSession");
|
|
112 |
}
|
|
113 |
|
|
114 |
/**
|
|
115 |
Decrease the session count by 1
|
|
116 |
The function is called whenever a new session is released, start shutdown timer with current shut down timer delay
|
|
117 |
|
|
118 |
@internalTechnology
|
|
119 |
@released
|
|
120 |
*/
|
|
121 |
void CSecureServerBase::DecSession()
|
|
122 |
{
|
|
123 |
LBSLOG(ELogP1,"->CSecureServerBase::DecSession");
|
|
124 |
|
|
125 |
__ASSERT_ALWAYS(iBaseConstructCalled, PanicServer(EBaseConstructNotCalled));
|
|
126 |
--iSessionCount;
|
|
127 |
if(iSessionCount > 0)
|
|
128 |
return; // bail out early
|
|
129 |
// ~CSecureSessionBase calls this, but it can be called after
|
|
130 |
// ~CSecureServerBase(!) e.g. a forced shutdown of the server with clients still connected
|
|
131 |
// so we need to guard this.
|
|
132 |
if(iShutdownTimer)
|
|
133 |
{
|
|
134 |
iShutdownTimer->Start(iShutdownDelay); // otherwise start the shutdown timer.
|
|
135 |
}
|
|
136 |
LBSLOG(ELogP1,"<-CSecureServerBase::DecSession");
|
|
137 |
}
|
|
138 |
|
|
139 |
/**
|
|
140 |
Return the session count
|
|
141 |
|
|
142 |
@return Session count
|
|
143 |
@internalTechnology
|
|
144 |
@released
|
|
145 |
*/
|
|
146 |
TInt CSecureServerBase::GetSessionCount() const
|
|
147 |
{
|
|
148 |
__ASSERT_ALWAYS(iBaseConstructCalled, PanicServer(EBaseConstructNotCalled));
|
|
149 |
return iSessionCount;
|
|
150 |
}
|
|
151 |
|
|
152 |
/**
|
|
153 |
Get the current shut down delay
|
|
154 |
|
|
155 |
@return Shut down time delay
|
|
156 |
@internalTechnology
|
|
157 |
@released
|
|
158 |
*/
|
|
159 |
TTimeIntervalMicroSeconds32 CSecureServerBase::GetShutdownDelay() const
|
|
160 |
{
|
|
161 |
__ASSERT_ALWAYS(iBaseConstructCalled, PanicServer(EBaseConstructNotCalled));
|
|
162 |
return iShutdownDelay;
|
|
163 |
}
|
|
164 |
|
|
165 |
/**
|
|
166 |
Set shut down delay
|
|
167 |
|
|
168 |
@param aDelay Shut down time delay
|
|
169 |
@internalTechnology
|
|
170 |
@released
|
|
171 |
*/
|
|
172 |
void CSecureServerBase::SetShutdownDelay(const TTimeIntervalMicroSeconds32 aDelay)
|
|
173 |
{
|
|
174 |
__ASSERT_ALWAYS(iBaseConstructCalled, PanicServer(EBaseConstructNotCalled));
|
|
175 |
iShutdownDelay = aDelay;
|
|
176 |
}
|
|
177 |
|
|
178 |
/**
|
|
179 |
Panic the server with specified panic reason code
|
|
180 |
|
|
181 |
@param aPanicCode Panic reason code
|
|
182 |
@internalTechnology
|
|
183 |
@released
|
|
184 |
*/
|
|
185 |
void CSecureServerBase::PanicServer(TInt aPanicCode) const
|
|
186 |
{
|
|
187 |
_LIT(KSecureServerBase, "SecureServerBase");
|
|
188 |
User::Panic(KSecureServerBase, aPanicCode);
|
|
189 |
}
|