epoc32/include/mmf/server/mmfsubthreadbase.h
branchSymbian2
changeset 2 2fe1408b6811
child 4 837f303aceeb
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/epoc32/include/mmf/server/mmfsubthreadbase.h	Tue Mar 16 16:12:26 2010 +0000
     1.3 @@ -0,0 +1,266 @@
     1.4 +// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// 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
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +#ifndef __MMFSUBTHREADBASE_H__
    1.20 +#define __MMFSUBTHREADBASE_H__
    1.21 +
    1.22 +#include <e32base.h>
    1.23 +#include <e32std.h>
    1.24 +#include <mmf/common/mmfpaniccodes.h>
    1.25 +#include <mmf/common/mmfcontroller.h>
    1.26 +
    1.27 +/**
    1.28 +@publishedAll
    1.29 +@released
    1.30 +
    1.31 +Defines the maximum number of event messages that will be held server-side
    1.32 +while waiting for the client to request the next message in the queue.
    1.33 +*/
    1.34 +static const TInt KMMFSubThreadMaxCachedMessages = 4;
    1.35 +
    1.36 +/**
    1.37 +@publishedAll
    1.38 +@released
    1.39 +
    1.40 +Defines the maximum heap size paramater used when creating the datapath subthread.
    1.41 +*/
    1.42 +static const TInt KMMFSubThreadMaxHeapSize = 0x100000;//1MB
    1.43 +
    1.44 +
    1.45 +/**
    1.46 +@publishedAll
    1.47 +@released
    1.48 +
    1.49 +ITC message ID's used by the client to send commands to the datapath subthread server.
    1.50 +*/
    1.51 +enum TMMFSubThreadMessageIds
    1.52 +	{
    1.53 +  	/**
    1.54 +	Message ID for message to request next event from the sub thread server.
    1.55 +	*/
    1.56 +	EMMFSubThreadReceiveEvents,
    1.57 +	/**
    1.58 +	Message ID for message to cancel a previous request to receive an event from the sub thread server.
    1.59 +	*/
    1.60 +	EMMFSubThreadCancelReceiveEvents,
    1.61 +	/**
    1.62 +	Message ID for message to request that the sub thread shuts itself down.
    1.63 +	*/
    1.64 +	EMMFSubThreadShutdown,
    1.65 +	/**
    1.66 +	Message ID for message to request the datapath subthread load a datapath.
    1.67 +	*/
    1.68 +	EMMFDataPathProxyLoadDataPathBy,
    1.69 +	/**
    1.70 +	Message ID for message to request the datapath subthread load a datapath with a specified 
    1.71 +	media ID.
    1.72 +	*/
    1.73 +	EMMFDataPathProxyLoadDataPathByMediaId,
    1.74 +	/**
    1.75 +	Message ID for message to request the datapath subthread load a datapath with a specified codec.
    1.76 +	*/
    1.77 +	EMMFDataPathProxyLoadDataPathByCodecUid,
    1.78 +	/**
    1.79 +	Message ID for message to request the datapath subthread load a datapath with a specified media 
    1.80 +	ID and codec.
    1.81 +	*/
    1.82 +	EMMFDataPathProxyLoadDataPathByMediaIdCodecUid,
    1.83 +	/**
    1.84 +    Message ID for message to add a data source to the datapath.
    1.85 +	*/
    1.86 +	EMMFDataPathProxyAddDataSource,
    1.87 +	/**
    1.88 +	Message ID for message to add a data sink to the datapath.
    1.89 +	*/
    1.90 +	EMMFDataPathProxyAddDataSink,
    1.91 +	/**
    1.92 +	Message ID for message to prime the datapath.
    1.93 +	*/
    1.94 +	EMMFDataPathProxyPrime,
    1.95 +	/**
    1.96 +	Message ID for message to start the datapath playing.
    1.97 +	*/
    1.98 +	EMMFDataPathProxyPlay,
    1.99 +	/**
   1.100 +	Message ID for message to pause the datapath.
   1.101 +	*/
   1.102 +	EMMFDataPathProxyPause,
   1.103 +	/**
   1.104 +	Message ID for message to stop the datapath.
   1.105 +	*/
   1.106 +	EMMFDataPathProxyStop,
   1.107 +	/**
   1.108 +	Message ID for message to get the datapath's position.
   1.109 +	*/
   1.110 +	EMMFDataPathProxyGetPosition,
   1.111 +	/**
   1.112 +	Message ID for message to set the datapath's position.
   1.113 +	*/
   1.114 +	EMMFDataPathProxySetPosition,
   1.115 +	/**
   1.116 +	Message ID for message to set the datapath's play window.
   1.117 +	*/
   1.118 +	EMMFDataPathProxySetPlayWindow,
   1.119 +	/**
   1.120 +	Message ID for message to clear the datapath's play window.
   1.121 +	*/
   1.122 +	EMMFDataPathProxyClearPlayWindow,
   1.123 +	/**
   1.124 +	Message ID for message to get the datapath's current state.
   1.125 +	*/
   1.126 +	EMMFDataPathProxyState,
   1.127 +	/**
   1.128 +	Unused.
   1.129 +	*/
   1.130 +	EMMFAudioPolicyProxyGetAudioPolicy
   1.131 +	};
   1.132 +
   1.133 +
   1.134 +class RMMFSubThreadBase; // declared here.
   1.135 +/**
   1.136 +@internalTechnology
   1.137 +
   1.138 +Base class for clients to MMF sub threads.
   1.139 +Provides functionality to start the sub thread and transmit events from subthread to main thread.
   1.140 +*/
   1.141 +NONSHARABLE_CLASS( RMMFSubThreadBase ): public RMmfSessionBase
   1.142 +	{
   1.143 +public:
   1.144 +	RMMFSubThreadBase(TTimeIntervalMicroSeconds32 aShutdownTimeout) : iShutdownTimeout(aShutdownTimeout) {};
   1.145 +	/**
   1.146 +	Returns the id of the subthread, allowing a client to logon to the thread to receive notification of its death.
   1.147 +	*/
   1.148 +	TThreadId SubThreadId() {return iSubThread.Id();};
   1.149 +	/**
   1.150 +	Allows a client to receive events from the subthread.
   1.151 +	*/
   1.152 +	IMPORT_C void ReceiveEvents(TMMFEventPckg& aEventPckg, TRequestStatus& aStatus);
   1.153 +	IMPORT_C TInt CancelReceiveEvents();
   1.154 +	/**
   1.155 +	Signal to the subthread to exit.
   1.156 +	Note: This function will not return until the subthread has exited, or a timeout has occurred.
   1.157 +	*/
   1.158 +	IMPORT_C void Shutdown();
   1.159 +protected:
   1.160 +	/**
   1.161 +	Should be called by derived classes to start the subthread.
   1.162 +	*/
   1.163 +	TInt DoCreateSubThread(const TDesC& aName, TThreadFunction aFunction, TBool aUseNewHeap = EFalse);
   1.164 +	void Panic(TMMFSubThreadPanicCode aPanicCode);
   1.165 +protected:
   1.166 +	RThread iSubThread;
   1.167 +	TTimeIntervalMicroSeconds32 iShutdownTimeout;
   1.168 +private:
   1.169 +	/**
   1.170 +	Used to determine the success of a logon.  If the status is not pending, the logon has failed
   1.171 +	and the thread should be closed.
   1.172 +	*/
   1.173 +	TRequestStatus iLogonStatus;
   1.174 +	/**
   1.175 +	This member is internal and not intended for use.
   1.176 +	*/
   1.177 +	TInt iReserved1;
   1.178 +	TInt iReserved2;
   1.179 +	TInt iReserved3;
   1.180 +	};
   1.181 +
   1.182 +/**
   1.183 +@internalTechnology
   1.184 +
   1.185 +Used to Kill the subthread either immediately or after a timeout.
   1.186 +Used by the subthread on startup to prevent orphaning if no sessions are created to it.
   1.187 +*/
   1.188 +class CMMFSubThreadShutdown : public CTimer
   1.189 +	{
   1.190 +	enum {EMMFSubThreadShutdownDelay=1000000};	// 1s
   1.191 +public:
   1.192 +	static CMMFSubThreadShutdown* NewL();
   1.193 +	CMMFSubThreadShutdown();
   1.194 +	void ConstructL();
   1.195 +	void Start();
   1.196 +	void ShutdownNow();
   1.197 +private:
   1.198 +	void RunL();
   1.199 +	};
   1.200 +
   1.201 +/**
   1.202 +@internalTechnology
   1.203 +
   1.204 +Subthread server base class.
   1.205 +Provides session counting and will kill the subthread immediately when the session count reaches zero.
   1.206 +Starts the shutdown timer on construction to prevent orphaning if no sessions are created.
   1.207 +*/
   1.208 +class CMMFSubThreadServer : public CMmfIpcServer
   1.209 +	{
   1.210 +public:
   1.211 +	virtual ~CMMFSubThreadServer();
   1.212 +	virtual void SessionCreated();
   1.213 +	virtual TInt RunError(TInt aError);
   1.214 +	virtual void ShutdownNow();
   1.215 +protected:
   1.216 +	virtual CMmfIpcSession* NewSessionL(const TVersion& aVersion) const = 0;
   1.217 +	CMMFSubThreadServer(TInt aPriority);
   1.218 +	void ConstructL();
   1.219 +private:
   1.220 +	CMMFSubThreadShutdown* iShutdownTimer;
   1.221 +	};
   1.222 +
   1.223 +/**
   1.224 +@internalTechnology
   1.225 +
   1.226 +Used to hold on to an RMessage so we can complete it asynchronously to send an event to the main thread.
   1.227 +*/
   1.228 +class CMMFSubThreadEventReceiver : public CBase
   1.229 +	{
   1.230 +public:
   1.231 +	static CMMFSubThreadEventReceiver* NewL(const RMmfIpcMessage& aMessage);
   1.232 +	~CMMFSubThreadEventReceiver();
   1.233 +	void SendEvent(const TMMFEvent& aEvent);
   1.234 +private:
   1.235 +	CMMFSubThreadEventReceiver(const RMmfIpcMessage& aMessage);
   1.236 +private:
   1.237 +	RMmfIpcMessage iMessage;
   1.238 +	TBool iNeedToCompleteMessage;
   1.239 +	};
   1.240 +
   1.241 +/**
   1.242 +@internalTechnology
   1.243 +
   1.244 +Subthread session base class.
   1.245 +Derived classes must implement the ServiceL() method.
   1.246 +*/
   1.247 +class CMMFSubThreadSession : public CMmfIpcSession, public MAsyncEventHandler
   1.248 +	{
   1.249 +public:
   1.250 +	virtual ~CMMFSubThreadSession();
   1.251 +	void CreateL(const CMmfIpcServer& aServer);
   1.252 +	virtual void ServiceL(const RMmfIpcMessage& aMessage) = 0;
   1.253 +	//from MAsyncEventHandler
   1.254 +	TInt SendEventToClient(const TMMFEvent& aEvent);
   1.255 +protected:
   1.256 +	CMMFSubThreadSession() {};
   1.257 +	TBool ReceiveEventsL(const RMmfIpcMessage& aMessage);
   1.258 +	TBool CancelReceiveEvents();
   1.259 +	TBool ShutDown();
   1.260 +protected:
   1.261 +	CMMFSubThreadServer* iServer;
   1.262 +private:
   1.263 +	CMMFSubThreadEventReceiver* iEventReceiver;
   1.264 +	RArray<TMMFEvent> iEvents;
   1.265 +	};
   1.266 +
   1.267 +
   1.268 +
   1.269 +#endif