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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 #ifndef __MMFSUBTHREADBASE_H__
17 #define __MMFSUBTHREADBASE_H__
21 #include <mmf/common/mmfpaniccodes.h>
22 #include <mmf/common/mmfcontroller.h>
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.
31 static const TInt KMMFSubThreadMaxCachedMessages = 4;
37 Defines the maximum heap size paramater used when creating the datapath subthread.
39 static const TInt KMMFSubThreadMaxHeapSize = 0x100000;//1MB
46 ITC message ID's used by the client to send commands to the datapath subthread server.
48 enum TMMFSubThreadMessageIds
51 Message ID for message to request next event from the sub thread server.
53 EMMFSubThreadReceiveEvents,
55 Message ID for message to cancel a previous request to receive an event from the sub thread server.
57 EMMFSubThreadCancelReceiveEvents,
59 Message ID for message to request that the sub thread shuts itself down.
61 EMMFSubThreadShutdown,
63 Message ID for message to request the datapath subthread load a datapath.
65 EMMFDataPathProxyLoadDataPathBy,
67 Message ID for message to request the datapath subthread load a datapath with a specified
70 EMMFDataPathProxyLoadDataPathByMediaId,
72 Message ID for message to request the datapath subthread load a datapath with a specified codec.
74 EMMFDataPathProxyLoadDataPathByCodecUid,
76 Message ID for message to request the datapath subthread load a datapath with a specified media
79 EMMFDataPathProxyLoadDataPathByMediaIdCodecUid,
81 Message ID for message to add a data source to the datapath.
83 EMMFDataPathProxyAddDataSource,
85 Message ID for message to add a data sink to the datapath.
87 EMMFDataPathProxyAddDataSink,
89 Message ID for message to prime the datapath.
91 EMMFDataPathProxyPrime,
93 Message ID for message to start the datapath playing.
95 EMMFDataPathProxyPlay,
97 Message ID for message to pause the datapath.
99 EMMFDataPathProxyPause,
101 Message ID for message to stop the datapath.
103 EMMFDataPathProxyStop,
105 Message ID for message to get the datapath's position.
107 EMMFDataPathProxyGetPosition,
109 Message ID for message to set the datapath's position.
111 EMMFDataPathProxySetPosition,
113 Message ID for message to set the datapath's play window.
115 EMMFDataPathProxySetPlayWindow,
117 Message ID for message to clear the datapath's play window.
119 EMMFDataPathProxyClearPlayWindow,
121 Message ID for message to get the datapath's current state.
123 EMMFDataPathProxyState,
127 EMMFAudioPolicyProxyGetAudioPolicy
131 class RMMFSubThreadBase; // declared here.
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.
138 NONSHARABLE_CLASS( RMMFSubThreadBase ): public RMmfSessionBase
141 RMMFSubThreadBase(TTimeIntervalMicroSeconds32 aShutdownTimeout) : iShutdownTimeout(aShutdownTimeout) {};
143 Returns the id of the subthread, allowing a client to logon to the thread to receive notification of its death.
145 TThreadId SubThreadId() {return iSubThread.Id();};
147 Allows a client to receive events from the subthread.
149 IMPORT_C void ReceiveEvents(TMMFEventPckg& aEventPckg, TRequestStatus& aStatus);
150 IMPORT_C TInt CancelReceiveEvents();
152 Signal to the subthread to exit.
153 Note: This function will not return until the subthread has exited, or a timeout has occurred.
155 IMPORT_C void Shutdown();
158 Should be called by derived classes to start the subthread.
160 TInt DoCreateSubThread(const TDesC& aName, TThreadFunction aFunction, TBool aUseNewHeap = EFalse);
161 void Panic(TMMFSubThreadPanicCode aPanicCode);
164 TTimeIntervalMicroSeconds32 iShutdownTimeout;
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.
170 TRequestStatus iLogonStatus;
172 This member is internal and not intended for use.
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.
185 class CMMFSubThreadShutdown : public CTimer
187 enum {EMMFSubThreadShutdownDelay=1000000}; // 1s
189 static CMMFSubThreadShutdown* NewL();
190 CMMFSubThreadShutdown();
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.
205 class CMMFSubThreadServer : public CMmfIpcServer
208 virtual ~CMMFSubThreadServer();
209 virtual void SessionCreated();
210 virtual TInt RunError(TInt aError);
211 virtual void ShutdownNow();
213 virtual CMmfIpcSession* NewSessionL(const TVersion& aVersion) const = 0;
214 CMMFSubThreadServer(TInt aPriority);
217 CMMFSubThreadShutdown* iShutdownTimer;
223 Used to hold on to an RMessage so we can complete it asynchronously to send an event to the main thread.
225 class CMMFSubThreadEventReceiver : public CBase
228 static CMMFSubThreadEventReceiver* NewL(const RMmfIpcMessage& aMessage);
229 ~CMMFSubThreadEventReceiver();
230 void SendEvent(const TMMFEvent& aEvent);
232 CMMFSubThreadEventReceiver(const RMmfIpcMessage& aMessage);
234 RMmfIpcMessage iMessage;
235 TBool iNeedToCompleteMessage;
241 Subthread session base class.
242 Derived classes must implement the ServiceL() method.
244 class CMMFSubThreadSession : public CMmfIpcSession, public MAsyncEventHandler
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);
253 CMMFSubThreadSession() {};
254 TBool ReceiveEventsL(const RMmfIpcMessage& aMessage);
255 TBool CancelReceiveEvents();
258 CMMFSubThreadServer* iServer;
260 CMMFSubThreadEventReceiver* iEventReceiver;
261 RArray<TMMFEvent> iEvents;