|
1 // Copyright (c) 2008-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 |
|
17 |
|
18 /** |
|
19 @file |
|
20 @internalComponent |
|
21 */ |
|
22 |
|
23 #ifndef BULKSERVER_H |
|
24 #define BULKSERVER_H |
|
25 |
|
26 #include <e32base.h> |
|
27 #include <e32msgqueue.h> |
|
28 #include "bulkservermsgqueue.h" |
|
29 |
|
30 class CBulkBearerInterface; |
|
31 class CMessageQueue; |
|
32 class CRemConBulkSession; |
|
33 class CRemConMessage; |
|
34 class TRemConAddress; |
|
35 |
|
36 class CRemConServer; |
|
37 |
|
38 |
|
39 /** |
|
40 The bulk server class for Rem Con. |
|
41 */ |
|
42 NONSHARABLE_CLASS(CRemConBulkServer) : public CPolicyServer |
|
43 { |
|
44 public: |
|
45 /** |
|
46 RemCon bulk server construction. |
|
47 @return Ownership of a new RemCon bulk server object |
|
48 */ |
|
49 static CRemConBulkServer* NewLC(RMsgQueue<TBulkServerMsg>& aMsgQueue); |
|
50 |
|
51 /** Destructor. */ |
|
52 ~CRemConBulkServer(); |
|
53 |
|
54 public: // called by session objects |
|
55 /** Called by a session when a client session is created. Cancels the |
|
56 shutdown timer in accordance with transient server design. */ |
|
57 TInt ClientOpened(CRemConBulkSession& aSession, TProcessId aProcessId); |
|
58 |
|
59 /** Called by a session when a client session is destroyed. Starts the |
|
60 shutdown timer if necessary in accordance with transient server design. |
|
61 Does not assume that the session successfully registered itself with the |
|
62 server to begin with. |
|
63 */ |
|
64 void ClientClosed(CRemConBulkSession& aSession); |
|
65 |
|
66 /** Called by a session when a client session has issued a receive. |
|
67 */ |
|
68 void ReceiveRequest(CRemConBulkSession& aSession); |
|
69 |
|
70 /** |
|
71 Starts the process of sending a response. |
|
72 Always takes ownership of aMsg. |
|
73 @return error |
|
74 */ |
|
75 TInt SendResponse(CRemConMessage& aMsg, CRemConBulkSession& aSess); |
|
76 |
|
77 /** |
|
78 Sends a reject back to the bearer. |
|
79 */ |
|
80 void SendReject(TRemConAddress aAddr, TUid aInterfaceUid, TUint aOperationId, TUint aTransactionId); |
|
81 |
|
82 inline CBulkBearerInterface& BulkBearerInterface(); |
|
83 |
|
84 public: // called by the bearer manager |
|
85 inline RPointerArray<CRemConBulkSession>& Sessions(); |
|
86 |
|
87 /** |
|
88 Handles a new incoming command. |
|
89 Always takes ownership of aMsg. |
|
90 */ |
|
91 void NewCommand(CRemConMessage& aMsg); |
|
92 |
|
93 void CommandExpired(TUint aTransactionId); |
|
94 |
|
95 private: |
|
96 /** Constructor. */ |
|
97 CRemConBulkServer(RMsgQueue<TBulkServerMsg>& aMsgQueue); |
|
98 |
|
99 /** 2nd-phase construction. */ |
|
100 void ConstructL(); |
|
101 |
|
102 private: // from CPolicyServer |
|
103 /** |
|
104 Called by the base class to create a new session. |
|
105 @param aVersion Version of client |
|
106 @param aMessage Client's IPC message |
|
107 @return A new session to be used for the client. If this could not be made, |
|
108 this function should leave. |
|
109 */ |
|
110 CSession2* NewSessionL(const TVersion &aVersion, const RMessage2& aMessage) const; |
|
111 |
|
112 private: // utility |
|
113 CRemConBulkSession* Session(TUint aSessionId) const; |
|
114 |
|
115 void StartShutdownTimerIfNoSessions(); |
|
116 |
|
117 #ifdef __FLOG_ACTIVE |
|
118 void LogSessions() const; |
|
119 void LogIncomingPendingDelivery() const; |
|
120 void LogIncomingDelivered() const; |
|
121 #endif // __FLOG_ACTIVE |
|
122 |
|
123 CMessageQueue& IncomingPendingDelivery(); |
|
124 CMessageQueue& IncomingDelivered(); |
|
125 |
|
126 void DeliverCmdToClient(const CRemConMessage& aMsg, CRemConBulkSession& aSess); |
|
127 void DeliverMessageToClient(CRemConMessage& aMsg, CRemConBulkSession& aSess); |
|
128 |
|
129 private: // called by the shutdown timer |
|
130 /** |
|
131 Called by the shutdown timer when it fires. Terminates the server thread. |
|
132 @param aThis This. |
|
133 @return KErrNone. |
|
134 */ |
|
135 static TInt TimerFired(TAny* aThis); |
|
136 |
|
137 |
|
138 private: // owned |
|
139 |
|
140 // NB This isn't really being used as a CPeriodic, but (a) it will do the |
|
141 // job, and (b) it saves us writing our own concrete timer (there aren't |
|
142 // any other more suitable concrete timer classes). |
|
143 CPeriodic* iShutdownTimer; |
|
144 |
|
145 // Shutdown delay (when there are no sessions) = 1 second- there's no |
|
146 // point hanging around. |
|
147 static const TUint KShutdownDelay = 1 * 1000 * 1000; |
|
148 |
|
149 RPointerArray<CRemConBulkSession> iSessions; |
|
150 |
|
151 CMessageQueue* iIncomingPendingDelivery; |
|
152 CMessageQueue* iIncomingDelivered; |
|
153 |
|
154 CBulkBearerInterface* iBulkBearerInterface; |
|
155 |
|
156 RMsgQueue<TBulkServerMsg> iRemConMsgQueue; |
|
157 |
|
158 CRemConServer* iControlServer; //unowned. |
|
159 }; |
|
160 |
|
161 // Inlines |
|
162 |
|
163 RPointerArray<CRemConBulkSession>& CRemConBulkServer::Sessions() |
|
164 { |
|
165 return iSessions; |
|
166 } |
|
167 |
|
168 CBulkBearerInterface& CRemConBulkServer::BulkBearerInterface() |
|
169 { |
|
170 return *iBulkBearerInterface; |
|
171 } |
|
172 |
|
173 #endif // BULKSERVER_H |