|
1 // Copyright (c) 1997-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 // |
|
15 |
|
16 #if !defined(__SS_STD_H__) |
|
17 #define __SS_STD_H__ |
|
18 |
|
19 #include <es_prot.h> |
|
20 #include <es_enum.h> |
|
21 #include <es_panic.h> |
|
22 |
|
23 #include <es_panic_internal.h> |
|
24 #include <es_panic_partner.h> |
|
25 |
|
26 #include <connpref.h> // for TConnPref |
|
27 #include <cflog.h> |
|
28 #include <elements/sd_std.h> |
|
29 #include <comms-infras/api_ext_list.h> |
|
30 #include <comms-infras/api_ext_msg.h> |
|
31 #include <comms-infras/ss_log.h> |
|
32 |
|
33 |
|
34 /** |
|
35 @internalComponent |
|
36 */ |
|
37 //#define ESOCK_LIB_NAME _L("ESOCK") |
|
38 #define ESOCK_SERVER_LIB_NAME _L("ESOCKSVR") |
|
39 |
|
40 class CSockSession; |
|
41 class CSockSessionProxy; |
|
42 class CWorkerThread; |
|
43 class CPlayer; |
|
44 class CSockManData; |
|
45 class CPitBoss; |
|
46 |
|
47 /** |
|
48 @internalAll |
|
49 */ |
|
50 const TUint KDefaultHeapSize=0x1000; |
|
51 |
|
52 /** |
|
53 @internalAll |
|
54 */ |
|
55 const TUint KMaxHeapSize=0x80000; |
|
56 |
|
57 |
|
58 /** |
|
59 Internal socket options bitmap. |
|
60 @internalComponent |
|
61 */ |
|
62 const TUint KOptBlocking=0x00000001; |
|
63 |
|
64 /** |
|
65 Internal socket options bitmap. |
|
66 @internalComponent |
|
67 */ |
|
68 const TUint KOptDontRoute=0x00000002; |
|
69 |
|
70 /** |
|
71 Internal socket options bitmap. |
|
72 @internalComponent |
|
73 */ |
|
74 const TUint KOptKeepAlive=0x00000004; |
|
75 |
|
76 /** |
|
77 Internal socket options bitmap. |
|
78 @internalComponent |
|
79 */ |
|
80 const TUint KOptDebug=0x00000008; |
|
81 |
|
82 /** |
|
83 Internal socket options bitmap. |
|
84 @internalComponent |
|
85 */ |
|
86 const TUint KOptOOBInLine=0x00000010; |
|
87 |
|
88 /** |
|
89 Internal socket options bitmap. |
|
90 @internalComponent |
|
91 */ |
|
92 const TUint KOptReUseAddr=0x00000020; |
|
93 |
|
94 /** |
|
95 Internal socket options bitmap. |
|
96 @internalComponent |
|
97 */ |
|
98 const TUint KOptBroadCast=0x00000040; |
|
99 |
|
100 /** |
|
101 Internal socket options bitmap. |
|
102 @internalComponent |
|
103 */ |
|
104 const TUint KOptSendBufSet=0x00000080; |
|
105 |
|
106 /** |
|
107 Internal socket options bitmap. |
|
108 @internalComponent |
|
109 */ |
|
110 const TUint KOptRecBufSet=0x00000100; |
|
111 |
|
112 /** |
|
113 Internal socket options bitmap. |
|
114 @internalComponent |
|
115 */ |
|
116 const TUint KESocketDefaultOptions=KOptBlocking; |
|
117 |
|
118 /** |
|
119 Maximum length for any Dealer's server name |
|
120 @internalComponent |
|
121 */ |
|
122 const TInt KMaxSockSvrNameLength = 32; |
|
123 |
|
124 /** |
|
125 Delay from the SessionClose messages are sent to the players till the session is deleted. |
|
126 @internalComponent |
|
127 */ |
|
128 const TUint32 KSessionCloseDelay = 16*1000*1000; |
|
129 const TUint32 KSessionClosePlayerDeadline = 8*1000*1000; |
|
130 |
|
131 const TUint KMaxConnectionInfoSize = 16; |
|
132 const TInt KMaxFactoryNameSize = 32; |
|
133 |
|
134 |
|
135 namespace ESock |
|
136 { |
|
137 class CSubConnection; |
|
138 class CSocket; |
|
139 class CConnection; |
|
140 class CHostResolver; |
|
141 class CServiceResolver; |
|
142 class CNetDatabase; |
|
143 class CCommsProviderBase; |
|
144 } |
|
145 |
|
146 namespace Den |
|
147 { |
|
148 class RSafeMessage; |
|
149 } |
|
150 |
|
151 namespace SubSessActivities |
|
152 { |
|
153 class CESockClientActivityBase; |
|
154 } |
|
155 |
|
156 namespace NetInterfaces |
|
157 { |
|
158 class TInterfaceControl; |
|
159 } |
|
160 |
|
161 |
|
162 NONSHARABLE_CLASS(CSockSubSession) : public Den::CWorkerSubSession |
|
163 /** |
|
164 @class CSockSubSession |
|
165 @internalComponent |
|
166 */ |
|
167 { |
|
168 // friend class CSockSession; |
|
169 // friend class CPlayer; |
|
170 // friend class SubSessActivities::CESockClientActivityBase; |
|
171 |
|
172 public: |
|
173 // Reference counting methods formerly supplied by CObject. |
|
174 void DeleteMe(); //Utility fn |
|
175 virtual ~CSockSubSession(); |
|
176 |
|
177 CSockSession* Session(); |
|
178 const CSockSession* Session() const; |
|
179 |
|
180 virtual void CommsApiExtBindIfaceL(const RMessage2& aMessage); |
|
181 virtual void CommsApiExtIfaceSendReceiveL(const RMessage2& aMessage); |
|
182 virtual void CloseExtensionInterface(const RMessage2& aMessage); |
|
183 virtual void CancelAndCloseAllClientExtIfaces(); |
|
184 |
|
185 /** Special non-zero subsession pointer, used in a very few cases to select additional behaviour on a forwarded request. For example on |
|
186 creating a subsession this flags that tier resolution is first required |
|
187 */ |
|
188 static CSockSubSession* KFlagSpecialForwardCase(); |
|
189 |
|
190 // migrate to using SafeMessage |
|
191 virtual inline const RMessage2& Message() const |
|
192 { |
|
193 return static_cast<RMessage2&>(const_cast<Den::RSafeMessage&>(Den::CWorkerSubSession::SafeMessage())); |
|
194 }; |
|
195 |
|
196 protected: |
|
197 void CancelClientExtItfRequests() const; |
|
198 |
|
199 protected: |
|
200 CSockSubSession(CSockSession* aSession, CPlayer* aPlayer, TSubSessionUniqueId aSubSessionUniqueId); |
|
201 void ConstructL(CProtocolBase* aProtocol); |
|
202 |
|
203 #ifdef SYMBIAN_NETWORKING_PERFMETRICS |
|
204 inline void IncludePerformanceData(TInt aDeltaClientRxBytes, TInt aDeltaClientRxBuffBytes, TInt aDeltaClientTxBytes); |
|
205 #endif |
|
206 }; |
|
207 |
|
208 |
|
209 /** |
|
210 @class MSockSessionObserver |
|
211 Notifier class used by observers of CSockSession events. |
|
212 @internalComponent |
|
213 */ |
|
214 class MSockSessionObserver |
|
215 { |
|
216 public: |
|
217 /** Event indicating session is about to close */ |
|
218 virtual void SessionClosing(const CSockSession* aSession)=0; |
|
219 }; |
|
220 |
|
221 |
|
222 NONSHARABLE_CLASS(CSockSession) : public Den::CWorkerSession, public MProvdSecurityChecker |
|
223 |
|
224 /** |
|
225 @class CSockSession |
|
226 Server side representation of RSocketServ. |
|
227 @internalTechnology |
|
228 */ |
|
229 { |
|
230 #ifdef __CFLOG_ACTIVE |
|
231 friend class CSocketServer; // for iProcessName |
|
232 #endif |
|
233 |
|
234 friend class CSockSubSession; |
|
235 //friend class CPitBoss; |
|
236 public: |
|
237 CWorkerThread& WorkerThread() const; |
|
238 CPitBoss& PitBoss() const; |
|
239 |
|
240 static CSockSession* NewL(TProcessId aProcessId, TUidType aUid, Den::TSessionUniqueId aSessionUniqueId); |
|
241 void ConstructL(TProcessId aProcessId); |
|
242 ESock::CSocket * CSocketFromHandle(TUint aHandle); |
|
243 TBool FlowAndSCPRFromSocketHandle(TUint aHandle, Messages::TNodeId& aFlow, Messages::TNodeId& aSCPR); |
|
244 ESock::CHostResolver * CHostResolverFromHandle(TUint aHandle); |
|
245 ESock::CServiceResolver * CServiceResolverFromHandle(TUint aHandle); |
|
246 ESock::CNetDatabase * CNetDatabaseFromHandle(TUint aHandle); |
|
247 ESock::CConnection* CConnectionFromHandle(TUint aHandle); |
|
248 ESock::CSubConnection* CSubConnectionFromHandle(TUint aHandle); |
|
249 void TransferSocketL(); |
|
250 virtual ~CSockSession(); |
|
251 void AddProtocolL(CProtocolBase * const aProtocol); |
|
252 void RemoveProtocolL(CProtocolBase * const aProtocol); |
|
253 void NumProtocolsL(void); |
|
254 void ProtocolInfoL(void); |
|
255 void ProtocolInfoByNameL(void); |
|
256 void PanicClient(TESockPanic aPanic); |
|
257 |
|
258 void ForwardTierRequestL(const RMessage2& aMessage); |
|
259 virtual void ServiceL(const RMessage2& aMessage); |
|
260 void RequestOptimalDealerL(); |
|
261 // Methods implementing MProvdSecurityChecker methods |
|
262 TInt CheckPolicy(const TSecurityPolicy& aPolicy, const char *aDiagnostic); |
|
263 |
|
264 // from CWorkerSession |
|
265 void Disconnect(const RMessage2& aMessage); |
|
266 |
|
267 protected: |
|
268 CSockSession(TUidType aUid, Den::TSessionUniqueId aSessionUniqueId); |
|
269 void NotifyObservers(); |
|
270 inline CSockManData* SockManGlobals() const; |
|
271 |
|
272 #ifdef SYMBIAN_NETWORKING_PERFMETRICS |
|
273 void IncludePerformanceData(TInt aDeltaClientRxBytes, TInt aDeltaClientRxBuffBytes, TInt aDeltaClientTxBytes); |
|
274 #endif |
|
275 |
|
276 private: |
|
277 void CloseSubSessionL(const RMessage2& aMessage, Den::TSubSessInfo aType); |
|
278 |
|
279 #ifdef _DEBUG_SOCKET_FUNCTIONS |
|
280 void SSDbgFunctionL(const RMessage2& aMessage); |
|
281 #endif // _DEBUG_SOCKET_FUNCTIONS |
|
282 |
|
283 #if defined (_DEBUG_SOCKET_FUNCTIONS) |
|
284 void DispatchDebugMessageL(const RMessage2& aMessage); |
|
285 #endif // _DEBUG_SOCKET_FUNCTIONS |
|
286 |
|
287 private: |
|
288 /** Used exclusively for handling ESSRequestOptimalDealer IPC |
|
289 Assigned in CSockSession::RequestOptimalDealer and |
|
290 CSockSession destructor. */ |
|
291 Den::CCommonWorkerDealer* iOptimalDealer; |
|
292 |
|
293 TProcessId iEligiblePid; // ProcessId of authorised process, set by ESSRequestOptimalDealer. |
|
294 LOG_STMT( TBuf8<KMaxName> iProcessName; ) |
|
295 |
|
296 #if defined(_DEBUG_SOCKET_FUNCTIONS) |
|
297 class TDebugRequestParking |
|
298 { |
|
299 public: |
|
300 TInt iSubSessHandle; |
|
301 TInt iNumOutstanding; |
|
302 }; |
|
303 TDebugRequestParking iDebugParking; |
|
304 #endif |
|
305 }; |
|
306 |
|
307 NONSHARABLE_CLASS(CSocketServer) : public Den::CCommonServer |
|
308 /** |
|
309 @class CSocketServer |
|
310 @internalComponent |
|
311 */ |
|
312 { |
|
313 public: |
|
314 static CSocketServer* NewL(CWorkerThread* aOwnerThread); |
|
315 ~CSocketServer(); |
|
316 CPolicyServer::TCustomResult CustomSecurityCheckL(const RMessage2& aMsg, TInt& /*aAction*/, TSecurityInfo& /*aMissing*/); |
|
317 |
|
318 protected: |
|
319 CSocketServer(CWorkerThread* aOwnerThread, TInt aPriority); |
|
320 virtual CSession2* DoNewSessionL(const TProcessId& aProcessId, const TUidType& aProcessUid) const; |
|
321 virtual TVersion CurrentVersion() const; |
|
322 #ifdef _DEBUG |
|
323 private: |
|
324 mutable TBool iPostBootChecksRun; |
|
325 #endif |
|
326 }; |
|
327 |
|
328 |
|
329 // |
|
330 namespace ESock |
|
331 { |
|
332 class CSubConnectionFlowBase; |
|
333 } |
|
334 class TAcceptQEntry |
|
335 /** |
|
336 @class TAcceptQEntry |
|
337 @internalComponent |
|
338 */ |
|
339 { |
|
340 public: |
|
341 ESock::CSubConnectionFlowBase* iSSP; |
|
342 HBufC8* iConnectData; |
|
343 TInt iConnectDataError; |
|
344 }; |
|
345 |
|
346 |
|
347 |
|
348 template<class TInfo, TInt QueueSize> |
|
349 class TNotificationQueue |
|
350 /** |
|
351 @class TNotificationQueue |
|
352 Class used to maintain a notification queue for CConnection. |
|
353 @internalComponent |
|
354 */ |
|
355 { |
|
356 public: |
|
357 inline TNotificationQueue(); |
|
358 inline TBool IsEmpty() const { return iQueueLength == 0; } |
|
359 void Enque(const TInfo& aInfo); |
|
360 TBool Deque(TInfo& aInfo); |
|
361 |
|
362 /** |
|
363 Use only with non-pointers!!! If a pointer based queue should |
|
364 be reseted use the ResetWithPointers() method!!! |
|
365 */ |
|
366 void Reset(); |
|
367 |
|
368 |
|
369 /** |
|
370 When storing pointers in the queue these methods are essential in order |
|
371 to avoid memory leaking. |
|
372 Before inserting a pointer make sure with the IsFull() method that the queue |
|
373 is not full. If it is full remove the oldest element with the |
|
374 'GetTheOldestElem()' call and after that the enque can |
|
375 be called (work with pointer reference in order to be able to |
|
376 NULLed the queue element). |
|
377 |
|
378 When reseting the queue use the ResetAndDestroy() function which will |
|
379 delete the heap cells pointed by the pointers in the array and calls |
|
380 the Reset() method. |
|
381 |
|
382 Use these only with pointers!!! |
|
383 */ |
|
384 inline TBool IsFull() const { return iQueueLength == QueueSize;} |
|
385 inline TInfo& GetTheOldestElem(); |
|
386 void ResetAndDestroy(); |
|
387 private: |
|
388 TInfo iQueue[QueueSize]; |
|
389 TUint iQueueLength; |
|
390 TUint iQueueStart; |
|
391 }; |
|
392 |
|
393 #include <es_notq.inl> |
|
394 |
|
395 /** |
|
396 @internalComponent |
|
397 */ |
|
398 const TUint KMaxProgressQueueLength = 8; |
|
399 |
|
400 /** |
|
401 @internalComponent |
|
402 */ |
|
403 typedef TNotificationQueue<Elements::TStateChange, KMaxProgressQueueLength> TProgressQueue; |
|
404 |
|
405 /** |
|
406 @internalComponent |
|
407 */ |
|
408 const TUint KMaxInterfaceNotificationQueueLength = 8; |
|
409 |
|
410 /** |
|
411 @internalComponent |
|
412 */ |
|
413 typedef TNotificationQueue<TInterfaceNotification, KMaxInterfaceNotificationQueueLength> TInterfaceChangeQueue; |
|
414 |
|
415 /** |
|
416 @internalComponent |
|
417 */ |
|
418 const TUint KMaxSubConnectionEventQueueLength = 8; |
|
419 |
|
420 /** |
|
421 @internalComponent |
|
422 */ |
|
423 typedef TNotificationQueue<TSubConnectionEvent*, KMaxSubConnectionEventQueueLength> TSubConnectionEventQueue; |
|
424 |
|
425 /** |
|
426 @internalComponent |
|
427 */ |
|
428 GLREF_C void Fault(TESockFault aFault); |
|
429 |
|
430 /** |
|
431 @internalComponent |
|
432 */ |
|
433 IMPORT_C void Panic(TProtocolPanic aPanic); |
|
434 |
|
435 class CSockManData; |
|
436 class CSockSession; |
|
437 |
|
438 NONSHARABLE_CLASS(CSocketScheduler) : public CActiveScheduler |
|
439 /** |
|
440 @class CSocketScheduler |
|
441 @internalTechnology |
|
442 */ |
|
443 { |
|
444 |
|
445 public: |
|
446 static CSocketScheduler* New(); |
|
447 // ~CSocketScheduler(); |
|
448 // virtual void Error(TInt aError) const; |
|
449 // static TBool CheckLockedL(CSockSession* aSession); |
|
450 // static void SetLockedL(CSockSession* aSession); |
|
451 // static TInt Unlock(CSockSession* aSession); |
|
452 // void SetCurrentMessage(const RMessage2* aMessage); |
|
453 // void ClearCurrentMessage(const RMessage2* aMessage); |
|
454 // virtual void WaitForAnyRequest(); |
|
455 // inline static void SetGlobals(CSockManData* aGlobals); |
|
456 // inline static void SetWaitHook(TCallBack* aCall); |
|
457 inline static CSockManData* Globals(); |
|
458 private: |
|
459 // CSockManData* iGlobals; |
|
460 // Within any RunL() only one message (at most, since most RunL()s are for |
|
461 // neither a server message delivery nor a forward to an ESock peer) can |
|
462 // be the "current message" for a thread. It's referred to by pointer |
|
463 // because there's no way to check for completion of an aliased copy and |
|
464 // double completion is fatal; keeping this goal of sharing a single instance |
|
465 // clearly in sight is desirable. When a message is forwarded from a |
|
466 // Dealer to a Player then responsibility for handling passes to the Player. |
|
467 // mutable const RMessage2* iCurrentMessage; |
|
468 // TCallBack* iWaitHook; |
|
469 // CSockSession* iLockedSession; |
|
470 // CArrayFixFlat<RMessage2>* iLockedMessageFifo; |
|
471 }; |
|
472 |
|
473 #include <ss_std.inl> |
|
474 |
|
475 #endif |