|
1 // Copyright (c) 2007-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 "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // This file provides the implementation for CNetUps's methods |
|
15 // @internalAll |
|
16 // @released |
|
17 // |
|
18 // |
|
19 |
|
20 #include <e32std.h> // defines DLL TLS |
|
21 #include <e32err.h> // defines standard error codes |
|
22 #include <e32const.h> // defines KMaxTInt32 |
|
23 |
|
24 #include "netupsassert.h" // defines NetUps Asserts |
|
25 #include "netupsserviceid.h" // defines the supported service ids. |
|
26 |
|
27 |
|
28 #include "netups.h" // defines public NetUps interface |
|
29 #include "netupsimpl.h" // defines the NetUps implementation |
|
30 #include "netupstls.h" // defines structure used to store Netups components in TLS |
|
31 |
|
32 using namespace Messages; |
|
33 |
|
34 namespace NetUps |
|
35 { |
|
36 __FLOG_STMT(_LIT8(KNetUpsSubsys, "esock");) |
|
37 __FLOG_STMT(_LIT8(KNetUpsComponent, "NetUps");) /*esockloader*/ |
|
38 |
|
39 EXPORT_C CNetUps* CNetUps::NewL(TInt32 aServiceId) |
|
40 /** Creates an instance of the Net UPS. |
|
41 @return A pointer to an instance of the Net UPS if successful, otherwise leaves with a system error code. |
|
42 */ |
|
43 { |
|
44 CNetUps* self = new (ELeave) CNetUps(aServiceId); |
|
45 |
|
46 #ifdef NETUPS_TEST_HARNESS |
|
47 __UHEAP_MARK; |
|
48 #endif |
|
49 |
|
50 CleanupStack::PushL(self); |
|
51 self->ConstructL(aServiceId); |
|
52 CleanupStack::Pop(self); |
|
53 |
|
54 return self; |
|
55 } |
|
56 |
|
57 void CNetUps::ConstructL(TInt32 aServiceId) |
|
58 { |
|
59 if (aServiceId != EIpServiceId) |
|
60 { |
|
61 __FLOG_STATIC1(KNetUpsSubsys, KNetUpsComponent, _L("CNetUps::ConstructL aServiceId = %d"), aServiceId); |
|
62 User::Leave(KErrNotSupported); |
|
63 } |
|
64 |
|
65 CNetUpsTls* netUpsTls = static_cast<CNetUpsTls*>(Dll::Tls()); |
|
66 |
|
67 __FLOG_OPEN(KNetUpsSubsys, KNetUpsComponent); |
|
68 __FLOG_2(_L("CNetUps %08x:\tConstructL(), aServiceId = %d"), this, aServiceId); |
|
69 |
|
70 if (netUpsTls == NULL) |
|
71 { |
|
72 netUpsTls = CNetUpsTls::NewL(aServiceId); |
|
73 |
|
74 CleanupStack::PushL(netUpsTls); |
|
75 Dll::SetTls( static_cast<TAny*>(const_cast<CNetUpsTls*>(netUpsTls)) ); |
|
76 CleanupStack::Pop(netUpsTls); |
|
77 } |
|
78 |
|
79 iNetUps = netUpsTls->GetNetUpsImpl(); |
|
80 |
|
81 if (iNetUps->RefCount() == KMaxTInt32) |
|
82 { |
|
83 User::Leave(KErrOverflow); |
|
84 } |
|
85 else |
|
86 { |
|
87 iNetUps->IncrementRefCount(); |
|
88 } |
|
89 |
|
90 } |
|
91 |
|
92 CNetUps::CNetUps(TInt32 aServiceId) : iServiceId(aServiceId) |
|
93 { |
|
94 } |
|
95 |
|
96 CNetUps::~CNetUps() |
|
97 /** Deletes this instance of the Net UPS. |
|
98 */ |
|
99 { |
|
100 __FLOG_1(_L("CNetUps %08x:\t~CNetUps()"), this); |
|
101 |
|
102 if (iNetUps) // OOM tests require this, investigate. |
|
103 { |
|
104 iNetUps->DecrementRefCount(); |
|
105 |
|
106 if (iNetUps->RefCount() <= 0) |
|
107 { |
|
108 CNetUpsTls* netUpsTls = static_cast<CNetUpsTls*>(Dll::Tls()); |
|
109 delete netUpsTls; |
|
110 Dll::SetTls( static_cast<TAny*>(NULL) ); |
|
111 } |
|
112 } |
|
113 |
|
114 __FLOG_CLOSE; |
|
115 #ifdef NETUPS_TEST_HARNESS |
|
116 __UHEAP_MARKEND; |
|
117 #endif |
|
118 } |
|
119 |
|
120 EXPORT_C TBool CNetUps::UpsDisabled(TInt32 aServiceId) |
|
121 /** Determines whether the NetUps Component is disabled or enabled for a given Service ID. |
|
122 |
|
123 @param aServiceId The service ID which specialises this query. |
|
124 */ |
|
125 { |
|
126 __FLOG_STATIC1(KNetUpsSubsys, KNetUpsComponent, _L("CNetUps::UpsDisabled(), aServiceId = %d"), aServiceId); |
|
127 |
|
128 TBool rc = ETrue; |
|
129 |
|
130 if (aServiceId != EIpServiceId) |
|
131 { |
|
132 __FLOG_STATIC0(KNetUpsSubsys, KNetUpsComponent, _L("CNetUps::UpsDisabled() Service id not supported")); |
|
133 rc = EFalse; |
|
134 } |
|
135 else |
|
136 { |
|
137 CNetUps* netUps = NULL; |
|
138 TRAPD(err, netUps = CNetUps::NewL(aServiceId);) |
|
139 if (err == KErrNone) |
|
140 { |
|
141 // coverity[leave_without_push] |
|
142 delete netUps; |
|
143 rc = EFalse; |
|
144 } |
|
145 } |
|
146 |
|
147 return rc; |
|
148 } |
|
149 |
|
150 EXPORT_C void CNetUps::ProcessPolicyCheckRequestL(TPolicyCheckRequestData& aPolicyCheckRequestData, TRequestId& aRequestId) |
|
151 |
|
152 /** Processes an asynchronous UPS policy check request; when the request completes the CNetUps calls |
|
153 MPolicyCheckRequestOriginator::ProcessPolicyCheckResponse to notify the originator of the response. |
|
154 |
|
155 @param aPolicyCheckRequestData A structure which encapsulates the attributes associated with a policy check request. |
|
156 @param aRequestId The NetUps updates this variable with an identifier which uniquely identifies this policy check request. |
|
157 |
|
158 */ |
|
159 { |
|
160 __FLOG_7(_L("CNetUps %08x:\tProcessPolicyCheckRequestL(): process id = %d, thread id = %d, service id = %d, platsec result = %d, commsId = %08x, originator = %08x"), |
|
161 this, aPolicyCheckRequestData.iProcessId.Id(), aPolicyCheckRequestData.iThreadId.Id(), (TInt32) aPolicyCheckRequestData.iServiceId, aPolicyCheckRequestData.iPlatSecCheckResult, &aPolicyCheckRequestData.iCommsId, &aPolicyCheckRequestData.iPolicyCheckRequestOriginator); |
|
162 |
|
163 aPolicyCheckRequestData.SetServiceId(iServiceId); |
|
164 iNetUps->ProcessPolicyCheckRequestL(aPolicyCheckRequestData, aRequestId); |
|
165 } |
|
166 |
|
167 EXPORT_C TInt CNetUps::CancelRequest(const TNodeId& aCallersNodeId, const TRequestId& aRequestId) |
|
168 /** Cancels an outstanding asynchronous UPS Policy Check Request. |
|
169 * |
|
170 @param aCallersNodeId A structure which uniquely identifies the node which posted the original request. |
|
171 @param aRequestId This variable uniquelyidentifies the policy check request which is to be cancelled. |
|
172 */ |
|
173 { |
|
174 __FLOG_3(_L("CNetUps %08x:\tCancelRequest(), aCallersNodeId = %08x, iServiceId = %d"), this, &aCallersNodeId, iServiceId); |
|
175 |
|
176 return iNetUps->CancelRequest(iServiceId, aCallersNodeId, aRequestId); |
|
177 } |
|
178 |
|
179 |
|
180 EXPORT_C void CNetUps::IncrementConnectionCountL(const TNodeId& aCallersNodeId) |
|
181 /** Increments the connection count associated with a particular thread. |
|
182 Typically the connection count is incremented by the NetUps as soon as the request is authorised to |
|
183 avoid race conditions which may result in an inaccurate connection count. |
|
184 |
|
185 @param aCallersNodeId The CommsId associated with the caller of this method. |
|
186 */ |
|
187 { |
|
188 __FLOG_3(_L("CNetUps %08x:\tIncrementConnectionCountL(), aCallersNodeId = %08x, iServiceId = %d"), this, &aCallersNodeId, iServiceId); |
|
189 |
|
190 iNetUps->IncrementConnectionCountL(iServiceId, aCallersNodeId); |
|
191 } |
|
192 |
|
193 EXPORT_C void CNetUps::DecrementConnectionCountL(const TNodeId& aCallersNodeId) |
|
194 /** Decrements the connection count associated with a particular thread. |
|
195 This method should always be called when a connection is deleted. |
|
196 |
|
197 @param aCallersNodeId The CommsId associated with the caller of this method. |
|
198 */ |
|
199 { |
|
200 __FLOG_3(_L("CNetUps %08x:\tDecrementConnectionCountL(), aCallersNodeId = %08x, iServiceId = %d"), this, &aCallersNodeId, iServiceId); |
|
201 |
|
202 iNetUps->DecrementConnectionCountL(iServiceId, aCallersNodeId); |
|
203 } |
|
204 |
|
205 EXPORT_C void CNetUps::DecrementConnectionCountL(const Messages::TNodeId& aCallersNodeId, TProcessId& aProcessId, TThreadId& aThreadId) |
|
206 { |
|
207 __FLOG_5(_L("CNetUps %08x:\tDecrementConnectionCount1L(), aCallersNodeId = %08x, iServiceId = %d, process id = %d, thread id = %d,"), this, &aCallersNodeId, iServiceId, aProcessId.Id(), aThreadId.Id()); |
|
208 |
|
209 iNetUps->DecrementConnectionCountL(iServiceId, aCallersNodeId, aProcessId, aThreadId); |
|
210 } |
|
211 |
|
212 } // end of namespace |
|
213 |