epoc32/include/mmf/server/mmfsubthreadbase.h
branchSymbian3
changeset 4 837f303aceeb
parent 2 2fe1408b6811
equal deleted inserted replaced
3:e1b950c65cb4 4:837f303aceeb
     1 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     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
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     7 //
     8 // Initial Contributors:
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
     9 // Nokia Corporation - initial contribution.
    10 //
    10 //
    11 // Contributors:
    11 // Contributors:
    18 
    18 
    19 #include <e32base.h>
    19 #include <e32base.h>
    20 #include <e32std.h>
    20 #include <e32std.h>
    21 #include <mmf/common/mmfpaniccodes.h>
    21 #include <mmf/common/mmfpaniccodes.h>
    22 #include <mmf/common/mmfcontroller.h>
    22 #include <mmf/common/mmfcontroller.h>
       
    23 
       
    24 #ifndef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    25 #include <mmf/server/mmfsubthreadbaseimpl.h>
       
    26 #endif
    23 
    27 
    24 /**
    28 /**
    25 @publishedAll
    29 @publishedAll
    26 @released
    30 @released
    27 
    31 
   128 	};
   132 	};
   129 
   133 
   130 
   134 
   131 class RMMFSubThreadBase; // declared here.
   135 class RMMFSubThreadBase; // declared here.
   132 /**
   136 /**
   133 @internalTechnology
   137 @publishedAll
   134 
   138 
   135 Base class for clients to MMF sub threads.
   139 Base class for clients to MMF sub threads.
   136 Provides functionality to start the sub thread and transmit events from subthread to main thread.
   140 Provides functionality to start the sub thread and transmit events from subthread to main thread.
   137 */
   141 */
   138 NONSHARABLE_CLASS( RMMFSubThreadBase ): public RMmfSessionBase
   142 NONSHARABLE_CLASS( RMMFSubThreadBase ): public RMmfSessionBase
   174 	TInt iReserved1;
   178 	TInt iReserved1;
   175 	TInt iReserved2;
   179 	TInt iReserved2;
   176 	TInt iReserved3;
   180 	TInt iReserved3;
   177 	};
   181 	};
   178 
   182 
   179 /**
   183 #endif
   180 @internalTechnology
       
   181 
   184 
   182 Used to Kill the subthread either immediately or after a timeout.
       
   183 Used by the subthread on startup to prevent orphaning if no sessions are created to it.
       
   184 */
       
   185 class CMMFSubThreadShutdown : public CTimer
       
   186 	{
       
   187 	enum {EMMFSubThreadShutdownDelay=1000000};	// 1s
       
   188 public:
       
   189 	static CMMFSubThreadShutdown* NewL();
       
   190 	CMMFSubThreadShutdown();
       
   191 	void ConstructL();
       
   192 	void Start();
       
   193 	void ShutdownNow();
       
   194 private:
       
   195 	void RunL();
       
   196 	};
       
   197 
       
   198 /**
       
   199 @internalTechnology
       
   200 
       
   201 Subthread server base class.
       
   202 Provides session counting and will kill the subthread immediately when the session count reaches zero.
       
   203 Starts the shutdown timer on construction to prevent orphaning if no sessions are created.
       
   204 */
       
   205 class CMMFSubThreadServer : public CMmfIpcServer
       
   206 	{
       
   207 public:
       
   208 	virtual ~CMMFSubThreadServer();
       
   209 	virtual void SessionCreated();
       
   210 	virtual TInt RunError(TInt aError);
       
   211 	virtual void ShutdownNow();
       
   212 protected:
       
   213 	virtual CMmfIpcSession* NewSessionL(const TVersion& aVersion) const = 0;
       
   214 	CMMFSubThreadServer(TInt aPriority);
       
   215 	void ConstructL();
       
   216 private:
       
   217 	CMMFSubThreadShutdown* iShutdownTimer;
       
   218 	};
       
   219 
       
   220 /**
       
   221 @internalTechnology
       
   222 
       
   223 Used to hold on to an RMessage so we can complete it asynchronously to send an event to the main thread.
       
   224 */
       
   225 class CMMFSubThreadEventReceiver : public CBase
       
   226 	{
       
   227 public:
       
   228 	static CMMFSubThreadEventReceiver* NewL(const RMmfIpcMessage& aMessage);
       
   229 	~CMMFSubThreadEventReceiver();
       
   230 	void SendEvent(const TMMFEvent& aEvent);
       
   231 private:
       
   232 	CMMFSubThreadEventReceiver(const RMmfIpcMessage& aMessage);
       
   233 private:
       
   234 	RMmfIpcMessage iMessage;
       
   235 	TBool iNeedToCompleteMessage;
       
   236 	};
       
   237 
       
   238 /**
       
   239 @internalTechnology
       
   240 
       
   241 Subthread session base class.
       
   242 Derived classes must implement the ServiceL() method.
       
   243 */
       
   244 class CMMFSubThreadSession : public CMmfIpcSession, public MAsyncEventHandler
       
   245 	{
       
   246 public:
       
   247 	virtual ~CMMFSubThreadSession();
       
   248 	void CreateL(const CMmfIpcServer& aServer);
       
   249 	virtual void ServiceL(const RMmfIpcMessage& aMessage) = 0;
       
   250 	//from MAsyncEventHandler
       
   251 	TInt SendEventToClient(const TMMFEvent& aEvent);
       
   252 protected:
       
   253 	CMMFSubThreadSession() {};
       
   254 	TBool ReceiveEventsL(const RMmfIpcMessage& aMessage);
       
   255 	TBool CancelReceiveEvents();
       
   256 	TBool ShutDown();
       
   257 protected:
       
   258 	CMMFSubThreadServer* iServer;
       
   259 private:
       
   260 	CMMFSubThreadEventReceiver* iEventReceiver;
       
   261 	RArray<TMMFEvent> iEvents;
       
   262 	};
       
   263 
       
   264 
       
   265 
       
   266 #endif