|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #ifndef __ISIUSERCHANNEL_H__ |
|
21 #define __ISIUSERCHANNEL_H__ |
|
22 |
|
23 // Includes |
|
24 #include <kernel.h> // For DLogicalChannel |
|
25 #include "misirouterchannelif.h" // For MISIRouterChannelIf |
|
26 #include "isiinternaldefs.h" // For TISIAsyncRequest |
|
27 |
|
28 // Forward declaration |
|
29 class DISIMsgQueue; |
|
30 class MISIChannelRouterIf; |
|
31 |
|
32 /** |
|
33 * Provides channel for user side ISI API |
|
34 */ |
|
35 NONSHARABLE_CLASS( DISIUserChannel ) : public DLogicalChannel, public MISIRouterChannelIf |
|
36 { |
|
37 |
|
38 public: |
|
39 |
|
40 /** |
|
41 * C++ default constructor. |
|
42 */ |
|
43 DISIUserChannel(); |
|
44 |
|
45 /** |
|
46 * Destructor. |
|
47 */ |
|
48 ~DISIUserChannel(); |
|
49 |
|
50 ///// Functions from base class DLogicalChannel start |
|
51 |
|
52 /** |
|
53 * Second phase constructor. Run in user thread context. |
|
54 * Thread in CS and can not be pre-empted. |
|
55 * See other comments from DLogicalChannel. |
|
56 * @param aUnit, Not used at the moment. |
|
57 * @param anInfo, Not used at the moment. |
|
58 * @param aVer, Not used at the moment. |
|
59 */ |
|
60 virtual TInt DoCreate( TInt aUnit, const TDesC8* anInfo, const TVersion& aVer ); |
|
61 |
|
62 /** |
|
63 * Kernel message que function. Run in kernel thread context. |
|
64 * See other comments from DLogicalChannel. |
|
65 * @param aMsg, message from Request function. |
|
66 */ |
|
67 virtual void HandleMsg( TMessageBase* aMsg ); |
|
68 |
|
69 /** |
|
70 * Overwritten so that accepts only calls with DoControl. |
|
71 * See other comments from DLogicalChannel. |
|
72 */ |
|
73 TInt Request( TInt aReqNo, TAny* a1, TAny* a2 ); |
|
74 |
|
75 ///// Functions from base class DLogicalChannel end |
|
76 |
|
77 ///// Functions from MISIRouterChannelIf start |
|
78 |
|
79 /** |
|
80 * See comments from MISIRouterChannelIf. |
|
81 */ |
|
82 void EnqueChannelRequestCompleteDfc( TInt aRequest, TInt aStatusToComplete ); |
|
83 |
|
84 /* |
|
85 * See comments from MISIRouterChannelIf. |
|
86 */ |
|
87 void ReceiveMsg( const TDesC8& aMessage ); |
|
88 |
|
89 ///// Functions from MISIRouterChannelIf end |
|
90 |
|
91 private: |
|
92 |
|
93 /* |
|
94 * Handling of all requests. |
|
95 * @param aFunction, request id |
|
96 * @param a1, pointer to parameters. |
|
97 * @param a2, not used |
|
98 * @return error code |
|
99 */ |
|
100 TInt HandleRequest( TInt aFunction, TAny* a1, TAny* a2 ); |
|
101 |
|
102 /* |
|
103 * Handling of synchronous requests. |
|
104 * @param aFunction, request id |
|
105 * @param a1, pointer to parameters. |
|
106 * @return error code |
|
107 */ |
|
108 TInt HandleSyncRequest( TInt aFunction, TAny* a1 ); |
|
109 |
|
110 /* |
|
111 * Handling of asynchronous requests. |
|
112 * @param aFunction, request id |
|
113 * @param a1, pointer to parameters. |
|
114 * @return None |
|
115 */ |
|
116 void HandleAsyncRequest( TInt aFunction, TAny* a1 ); |
|
117 |
|
118 /* |
|
119 * Do the cancellation of request. |
|
120 * @param aRequest, |
|
121 * @param aMask |
|
122 * @return None |
|
123 */ |
|
124 void DoCancel( TInt aRequest, TInt aMask ); |
|
125 |
|
126 /* |
|
127 * Disconnect channel |
|
128 * @return None |
|
129 */ |
|
130 void Disconnect(); |
|
131 |
|
132 /** |
|
133 * DFC function that empties message receive queue to user thread. |
|
134 * @param aPtr, pointer to self |
|
135 * @return None |
|
136 */ |
|
137 static void EmptyRxQueueDfc( TAny* aPtr ); |
|
138 |
|
139 /** |
|
140 * DFC function that completes channel requests to user thread. |
|
141 * Run always in ISI user channel kernel thread context. |
|
142 * @param aPtr, pointer to self |
|
143 * @return None |
|
144 */ |
|
145 static void CompleteChannelRequestDfc( TAny* aPtr ); |
|
146 |
|
147 /** |
|
148 * Resets channel message queues. |
|
149 * @return None |
|
150 */ |
|
151 void ResetQueues(); |
|
152 |
|
153 /* |
|
154 * Internal class for handling async requests. |
|
155 */ |
|
156 NONSHARABLE_CLASS( DISIUserAsyncRequests ) : public DBase |
|
157 { |
|
158 |
|
159 public: |
|
160 |
|
161 /* |
|
162 * Constructor |
|
163 * @param aSize, size of the request list. |
|
164 */ |
|
165 DISIUserAsyncRequests( const TInt aSize ); |
|
166 |
|
167 /* |
|
168 * Destructor |
|
169 */ |
|
170 ~DISIUserAsyncRequests(); |
|
171 |
|
172 /* |
|
173 * Check is the request pending. |
|
174 * Do not call with FM held. |
|
175 * @param aRequest, request to check |
|
176 * @return pending status |
|
177 */ |
|
178 TBool IsPending( const TUint aRequest ); |
|
179 |
|
180 /* |
|
181 * Set the request pending. |
|
182 * Do not call with FM held. |
|
183 * @param aRequest, request to set pending |
|
184 * @param aDfc, pointer to DFC function which is enqued when request is completed |
|
185 * @param aStatus, pointer to status which is modified when request is completed |
|
186 */ |
|
187 void SetPending( const TUint aRequest, TRequestStatus* aStatus = NULL ); |
|
188 |
|
189 private: |
|
190 |
|
191 // For list access |
|
192 friend class DISIUserChannel; |
|
193 // Guarding lock. |
|
194 NFastMutex* iRequestLock; |
|
195 // For clients request status pointers |
|
196 TRequestStatus* iRequestStatusList[ EISILastAsyncRequest ]; |
|
197 // Request completion values |
|
198 TInt iRequestCompletionValueList[ EISILastAsyncRequest ]; |
|
199 // Request completion queue |
|
200 RArray<TInt> iRequestCompletedList; |
|
201 |
|
202 }; |
|
203 |
|
204 private: |
|
205 |
|
206 // Not owned, no need to guard open/close in one thread in construction and desctruction. |
|
207 DThread* iThread; |
|
208 // Not owned, no need to guard only written in one thread in construction and desctruction. |
|
209 MISIChannelRouterIf* iRouterIf; |
|
210 // Pointers to client message buffer, not owned |
|
211 TAny* iReceiveBufPtr; |
|
212 // not owned |
|
213 TUint16* iNeededBufLen; |
|
214 // Owned, synchronized internally with fastmutexes. |
|
215 DISIUserAsyncRequests* iRequests; |
|
216 // Owned, no need to sync don internally |
|
217 TDfc* iEmptyRxQueueDfc; |
|
218 // Owned, no need to sync don internally |
|
219 TDfc* iCompleteChannelRequestDfc; |
|
220 TDfcQue* iMainThread; |
|
221 TDfcQue* iCompletionThread; |
|
222 // Owned, synchronized internally with fastmutexes no need to guard |
|
223 DISIMsgQueue* iRx; |
|
224 // Channel indentifiers |
|
225 TUint8 iObjId; |
|
226 TInt32 iUID; |
|
227 |
|
228 }; |
|
229 |
|
230 #endif // __ISIUSERCHANNEL_H__ |
|
231 |
|
232 // End of File |