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