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