|
1 // Copyright (c) 2002-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" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.symbianfoundation.org/legal/licencesv10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #ifndef __MMFSUBTHREADBASE_H__ |
|
17 #define __MMFSUBTHREADBASE_H__ |
|
18 |
|
19 #include <e32base.h> |
|
20 #include <e32std.h> |
|
21 #include <mmf/common/mmfpaniccodes.h> |
|
22 #include <mmf/common/mmfcontroller.h> |
|
23 |
|
24 /** |
|
25 @publishedAll |
|
26 @released |
|
27 |
|
28 Defines the maximum number of event messages that will be held server-side |
|
29 while waiting for the client to request the next message in the queue. |
|
30 */ |
|
31 static const TInt KMMFSubThreadMaxCachedMessages = 4; |
|
32 |
|
33 /** |
|
34 @publishedAll |
|
35 @released |
|
36 |
|
37 Defines the maximum heap size paramater used when creating the datapath subthread. |
|
38 */ |
|
39 static const TInt KMMFSubThreadMaxHeapSize = 0x100000;//1MB |
|
40 |
|
41 |
|
42 /** |
|
43 @publishedAll |
|
44 @released |
|
45 |
|
46 ITC message ID's used by the client to send commands to the datapath subthread server. |
|
47 */ |
|
48 enum TMMFSubThreadMessageIds |
|
49 { |
|
50 /** |
|
51 Message ID for message to request next event from the sub thread server. |
|
52 */ |
|
53 EMMFSubThreadReceiveEvents, |
|
54 /** |
|
55 Message ID for message to cancel a previous request to receive an event from the sub thread server. |
|
56 */ |
|
57 EMMFSubThreadCancelReceiveEvents, |
|
58 /** |
|
59 Message ID for message to request that the sub thread shuts itself down. |
|
60 */ |
|
61 EMMFSubThreadShutdown, |
|
62 /** |
|
63 Message ID for message to request the datapath subthread load a datapath. |
|
64 */ |
|
65 EMMFDataPathProxyLoadDataPathBy, |
|
66 /** |
|
67 Message ID for message to request the datapath subthread load a datapath with a specified |
|
68 media ID. |
|
69 */ |
|
70 EMMFDataPathProxyLoadDataPathByMediaId, |
|
71 /** |
|
72 Message ID for message to request the datapath subthread load a datapath with a specified codec. |
|
73 */ |
|
74 EMMFDataPathProxyLoadDataPathByCodecUid, |
|
75 /** |
|
76 Message ID for message to request the datapath subthread load a datapath with a specified media |
|
77 ID and codec. |
|
78 */ |
|
79 EMMFDataPathProxyLoadDataPathByMediaIdCodecUid, |
|
80 /** |
|
81 Message ID for message to add a data source to the datapath. |
|
82 */ |
|
83 EMMFDataPathProxyAddDataSource, |
|
84 /** |
|
85 Message ID for message to add a data sink to the datapath. |
|
86 */ |
|
87 EMMFDataPathProxyAddDataSink, |
|
88 /** |
|
89 Message ID for message to prime the datapath. |
|
90 */ |
|
91 EMMFDataPathProxyPrime, |
|
92 /** |
|
93 Message ID for message to start the datapath playing. |
|
94 */ |
|
95 EMMFDataPathProxyPlay, |
|
96 /** |
|
97 Message ID for message to pause the datapath. |
|
98 */ |
|
99 EMMFDataPathProxyPause, |
|
100 /** |
|
101 Message ID for message to stop the datapath. |
|
102 */ |
|
103 EMMFDataPathProxyStop, |
|
104 /** |
|
105 Message ID for message to get the datapath's position. |
|
106 */ |
|
107 EMMFDataPathProxyGetPosition, |
|
108 /** |
|
109 Message ID for message to set the datapath's position. |
|
110 */ |
|
111 EMMFDataPathProxySetPosition, |
|
112 /** |
|
113 Message ID for message to set the datapath's play window. |
|
114 */ |
|
115 EMMFDataPathProxySetPlayWindow, |
|
116 /** |
|
117 Message ID for message to clear the datapath's play window. |
|
118 */ |
|
119 EMMFDataPathProxyClearPlayWindow, |
|
120 /** |
|
121 Message ID for message to get the datapath's current state. |
|
122 */ |
|
123 EMMFDataPathProxyState, |
|
124 /** |
|
125 Unused. |
|
126 */ |
|
127 EMMFAudioPolicyProxyGetAudioPolicy |
|
128 }; |
|
129 |
|
130 |
|
131 class RMMFSubThreadBase; // declared here. |
|
132 /** |
|
133 @internalTechnology |
|
134 |
|
135 Base class for clients to MMF sub threads. |
|
136 Provides functionality to start the sub thread and transmit events from subthread to main thread. |
|
137 */ |
|
138 NONSHARABLE_CLASS( RMMFSubThreadBase ): public RMmfSessionBase |
|
139 { |
|
140 public: |
|
141 RMMFSubThreadBase(TTimeIntervalMicroSeconds32 aShutdownTimeout) : iShutdownTimeout(aShutdownTimeout) {}; |
|
142 /** |
|
143 Returns the id of the subthread, allowing a client to logon to the thread to receive notification of its death. |
|
144 */ |
|
145 TThreadId SubThreadId() {return iSubThread.Id();}; |
|
146 /** |
|
147 Allows a client to receive events from the subthread. |
|
148 */ |
|
149 IMPORT_C void ReceiveEvents(TMMFEventPckg& aEventPckg, TRequestStatus& aStatus); |
|
150 IMPORT_C TInt CancelReceiveEvents(); |
|
151 /** |
|
152 Signal to the subthread to exit. |
|
153 Note: This function will not return until the subthread has exited, or a timeout has occurred. |
|
154 */ |
|
155 IMPORT_C void Shutdown(); |
|
156 protected: |
|
157 /** |
|
158 Should be called by derived classes to start the subthread. |
|
159 */ |
|
160 TInt DoCreateSubThread(const TDesC& aName, TThreadFunction aFunction, TBool aUseNewHeap = EFalse); |
|
161 void Panic(TMMFSubThreadPanicCode aPanicCode); |
|
162 protected: |
|
163 RThread iSubThread; |
|
164 TTimeIntervalMicroSeconds32 iShutdownTimeout; |
|
165 private: |
|
166 /** |
|
167 Used to determine the success of a logon. If the status is not pending, the logon has failed |
|
168 and the thread should be closed. |
|
169 */ |
|
170 TRequestStatus iLogonStatus; |
|
171 /** |
|
172 This member is internal and not intended for use. |
|
173 */ |
|
174 TInt iReserved1; |
|
175 TInt iReserved2; |
|
176 TInt iReserved3; |
|
177 }; |
|
178 |
|
179 /** |
|
180 @internalTechnology |
|
181 |
|
182 Used to Kill the subthread either immediately or after a timeout. |
|
183 Used by the subthread on startup to prevent orphaning if no sessions are created to it. |
|
184 */ |
|
185 class CMMFSubThreadShutdown : public CTimer |
|
186 { |
|
187 enum {EMMFSubThreadShutdownDelay=1000000}; // 1s |
|
188 public: |
|
189 static CMMFSubThreadShutdown* NewL(); |
|
190 CMMFSubThreadShutdown(); |
|
191 void ConstructL(); |
|
192 void Start(); |
|
193 void ShutdownNow(); |
|
194 private: |
|
195 void RunL(); |
|
196 }; |
|
197 |
|
198 /** |
|
199 @internalTechnology |
|
200 |
|
201 Subthread server base class. |
|
202 Provides session counting and will kill the subthread immediately when the session count reaches zero. |
|
203 Starts the shutdown timer on construction to prevent orphaning if no sessions are created. |
|
204 */ |
|
205 class CMMFSubThreadServer : public CMmfIpcServer |
|
206 { |
|
207 public: |
|
208 virtual ~CMMFSubThreadServer(); |
|
209 virtual void SessionCreated(); |
|
210 virtual TInt RunError(TInt aError); |
|
211 virtual void ShutdownNow(); |
|
212 protected: |
|
213 virtual CMmfIpcSession* NewSessionL(const TVersion& aVersion) const = 0; |
|
214 CMMFSubThreadServer(TInt aPriority); |
|
215 void ConstructL(); |
|
216 private: |
|
217 CMMFSubThreadShutdown* iShutdownTimer; |
|
218 }; |
|
219 |
|
220 /** |
|
221 @internalTechnology |
|
222 |
|
223 Used to hold on to an RMessage so we can complete it asynchronously to send an event to the main thread. |
|
224 */ |
|
225 class CMMFSubThreadEventReceiver : public CBase |
|
226 { |
|
227 public: |
|
228 static CMMFSubThreadEventReceiver* NewL(const RMmfIpcMessage& aMessage); |
|
229 ~CMMFSubThreadEventReceiver(); |
|
230 void SendEvent(const TMMFEvent& aEvent); |
|
231 private: |
|
232 CMMFSubThreadEventReceiver(const RMmfIpcMessage& aMessage); |
|
233 private: |
|
234 RMmfIpcMessage iMessage; |
|
235 TBool iNeedToCompleteMessage; |
|
236 }; |
|
237 |
|
238 /** |
|
239 @internalTechnology |
|
240 |
|
241 Subthread session base class. |
|
242 Derived classes must implement the ServiceL() method. |
|
243 */ |
|
244 class CMMFSubThreadSession : public CMmfIpcSession, public MAsyncEventHandler |
|
245 { |
|
246 public: |
|
247 virtual ~CMMFSubThreadSession(); |
|
248 void CreateL(const CMmfIpcServer& aServer); |
|
249 virtual void ServiceL(const RMmfIpcMessage& aMessage) = 0; |
|
250 //from MAsyncEventHandler |
|
251 TInt SendEventToClient(const TMMFEvent& aEvent); |
|
252 protected: |
|
253 CMMFSubThreadSession() {}; |
|
254 TBool ReceiveEventsL(const RMmfIpcMessage& aMessage); |
|
255 TBool CancelReceiveEvents(); |
|
256 TBool ShutDown(); |
|
257 protected: |
|
258 CMMFSubThreadServer* iServer; |
|
259 private: |
|
260 CMMFSubThreadEventReceiver* iEventReceiver; |
|
261 RArray<TMMFEvent> iEvents; |
|
262 }; |
|
263 |
|
264 |
|
265 |
|
266 #endif |