sl@0: // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #ifndef __MMFSUBTHREADBASE_IMPL_H__ sl@0: #define __MMFSUBTHREADBASE_IMPL_H__ sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS sl@0: #include sl@0: #endif sl@0: sl@0: sl@0: /** sl@0: @internalTechnology sl@0: sl@0: Used to Kill the subthread either immediately or after a timeout. sl@0: Used by the subthread on startup to prevent orphaning if no sessions are created to it. sl@0: */ sl@0: class CMMFSubThreadShutdown : public CTimer sl@0: { sl@0: enum {EMMFSubThreadShutdownDelay=1000000}; // 1s sl@0: public: sl@0: static CMMFSubThreadShutdown* NewL(); sl@0: CMMFSubThreadShutdown(); sl@0: void ConstructL(); sl@0: void Start(); sl@0: void ShutdownNow(); sl@0: private: sl@0: void RunL(); sl@0: }; sl@0: sl@0: /** sl@0: @internalTechnology sl@0: sl@0: Subthread server base class. sl@0: Provides session counting and will kill the subthread immediately when the session count reaches zero. sl@0: Starts the shutdown timer on construction to prevent orphaning if no sessions are created. sl@0: */ sl@0: class CMMFSubThreadServer : public CMmfIpcServer sl@0: { sl@0: public: sl@0: virtual ~CMMFSubThreadServer(); sl@0: virtual void SessionCreated(); sl@0: virtual TInt RunError(TInt aError); sl@0: virtual void ShutdownNow(); sl@0: protected: sl@0: virtual CMmfIpcSession* NewSessionL(const TVersion& aVersion) const = 0; sl@0: CMMFSubThreadServer(TInt aPriority); sl@0: void ConstructL(); sl@0: private: sl@0: CMMFSubThreadShutdown* iShutdownTimer; sl@0: }; sl@0: sl@0: /** sl@0: @internalTechnology sl@0: sl@0: Used to hold on to an RMessage so we can complete it asynchronously to send an event to the main thread. sl@0: */ sl@0: class CMMFSubThreadEventReceiver : public CBase sl@0: { sl@0: public: sl@0: static CMMFSubThreadEventReceiver* NewL(const RMmfIpcMessage& aMessage); sl@0: ~CMMFSubThreadEventReceiver(); sl@0: void SendEvent(const TMMFEvent& aEvent); sl@0: private: sl@0: CMMFSubThreadEventReceiver(const RMmfIpcMessage& aMessage); sl@0: private: sl@0: RMmfIpcMessage iMessage; sl@0: TBool iNeedToCompleteMessage; sl@0: }; sl@0: sl@0: /** sl@0: @internalTechnology sl@0: sl@0: Subthread session base class. sl@0: Derived classes must implement the ServiceL() method. sl@0: */ sl@0: class CMMFSubThreadSession : public CMmfIpcSession, public MAsyncEventHandler sl@0: { sl@0: public: sl@0: virtual ~CMMFSubThreadSession(); sl@0: void CreateL(const CMmfIpcServer& aServer); sl@0: virtual void ServiceL(const RMmfIpcMessage& aMessage) = 0; sl@0: //from MAsyncEventHandler sl@0: TInt SendEventToClient(const TMMFEvent& aEvent); sl@0: protected: sl@0: CMMFSubThreadSession() {}; sl@0: TBool ReceiveEventsL(const RMmfIpcMessage& aMessage); sl@0: TBool CancelReceiveEvents(); sl@0: TBool ShutDown(); sl@0: protected: sl@0: CMMFSubThreadServer* iServer; sl@0: private: sl@0: CMMFSubThreadEventReceiver* iEventReceiver; sl@0: RArray iEvents; sl@0: }; sl@0: sl@0: sl@0: sl@0: #endif sl@0: