os/mm/mmlibs/mmfw/inc/mmf/server/mmfsubthreadbaseimpl.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
#ifndef __MMFSUBTHREADBASE_IMPL_H__
sl@0
    17
#define __MMFSUBTHREADBASE_IMPL_H__
sl@0
    18
sl@0
    19
#include <e32base.h>
sl@0
    20
#include <e32std.h>
sl@0
    21
#include <mmf/common/mmfpaniccodes.h>
sl@0
    22
#include <mmf/common/mmfcontroller.h>
sl@0
    23
#ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
sl@0
    24
#include <mmf/common/mmfipcserver.h>
sl@0
    25
#endif
sl@0
    26
sl@0
    27
sl@0
    28
/**
sl@0
    29
@internalTechnology
sl@0
    30
sl@0
    31
Used to Kill the subthread either immediately or after a timeout.
sl@0
    32
Used by the subthread on startup to prevent orphaning if no sessions are created to it.
sl@0
    33
*/
sl@0
    34
class CMMFSubThreadShutdown : public CTimer
sl@0
    35
	{
sl@0
    36
	enum {EMMFSubThreadShutdownDelay=1000000};	// 1s
sl@0
    37
public:
sl@0
    38
	static CMMFSubThreadShutdown* NewL();
sl@0
    39
	CMMFSubThreadShutdown();
sl@0
    40
	void ConstructL();
sl@0
    41
	void Start();
sl@0
    42
	void ShutdownNow();
sl@0
    43
private:
sl@0
    44
	void RunL();
sl@0
    45
	};
sl@0
    46
sl@0
    47
/**
sl@0
    48
@internalTechnology
sl@0
    49
sl@0
    50
Subthread server base class.
sl@0
    51
Provides session counting and will kill the subthread immediately when the session count reaches zero.
sl@0
    52
Starts the shutdown timer on construction to prevent orphaning if no sessions are created.
sl@0
    53
*/
sl@0
    54
class CMMFSubThreadServer : public CMmfIpcServer
sl@0
    55
	{
sl@0
    56
public:
sl@0
    57
	virtual ~CMMFSubThreadServer();
sl@0
    58
	virtual void SessionCreated();
sl@0
    59
	virtual TInt RunError(TInt aError);
sl@0
    60
	virtual void ShutdownNow();
sl@0
    61
protected:
sl@0
    62
	virtual CMmfIpcSession* NewSessionL(const TVersion& aVersion) const = 0;
sl@0
    63
	CMMFSubThreadServer(TInt aPriority);
sl@0
    64
	void ConstructL();
sl@0
    65
private:
sl@0
    66
	CMMFSubThreadShutdown* iShutdownTimer;
sl@0
    67
	};
sl@0
    68
sl@0
    69
/**
sl@0
    70
@internalTechnology
sl@0
    71
sl@0
    72
Used to hold on to an RMessage so we can complete it asynchronously to send an event to the main thread.
sl@0
    73
*/
sl@0
    74
class CMMFSubThreadEventReceiver : public CBase
sl@0
    75
	{
sl@0
    76
public:
sl@0
    77
	static CMMFSubThreadEventReceiver* NewL(const RMmfIpcMessage& aMessage);
sl@0
    78
	~CMMFSubThreadEventReceiver();
sl@0
    79
	void SendEvent(const TMMFEvent& aEvent);
sl@0
    80
private:
sl@0
    81
	CMMFSubThreadEventReceiver(const RMmfIpcMessage& aMessage);
sl@0
    82
private:
sl@0
    83
	RMmfIpcMessage iMessage;
sl@0
    84
	TBool iNeedToCompleteMessage;
sl@0
    85
	};
sl@0
    86
sl@0
    87
/**
sl@0
    88
@internalTechnology
sl@0
    89
sl@0
    90
Subthread session base class.
sl@0
    91
Derived classes must implement the ServiceL() method.
sl@0
    92
*/
sl@0
    93
class CMMFSubThreadSession : public CMmfIpcSession, public MAsyncEventHandler
sl@0
    94
	{
sl@0
    95
public:
sl@0
    96
	virtual ~CMMFSubThreadSession();
sl@0
    97
	void CreateL(const CMmfIpcServer& aServer);
sl@0
    98
	virtual void ServiceL(const RMmfIpcMessage& aMessage) = 0;
sl@0
    99
	//from MAsyncEventHandler
sl@0
   100
	TInt SendEventToClient(const TMMFEvent& aEvent);
sl@0
   101
protected:
sl@0
   102
	CMMFSubThreadSession() {};
sl@0
   103
	TBool ReceiveEventsL(const RMmfIpcMessage& aMessage);
sl@0
   104
	TBool CancelReceiveEvents();
sl@0
   105
	TBool ShutDown();
sl@0
   106
protected:
sl@0
   107
	CMMFSubThreadServer* iServer;
sl@0
   108
private:
sl@0
   109
	CMMFSubThreadEventReceiver* iEventReceiver;
sl@0
   110
	RArray<TMMFEvent> iEvents;
sl@0
   111
	};
sl@0
   112
sl@0
   113
sl@0
   114
sl@0
   115
#endif
sl@0
   116