epoc32/include/mmf/common/mmfcontrollerframeworkclasses.h
branchSymbian3
changeset 4 837f303aceeb
equal deleted inserted replaced
3:e1b950c65cb4 4:837f303aceeb
       
     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 
       
    17 #ifndef __MMFCONTROLLERFRAMEWORKCLASSES_H__
       
    18 #define __MMFCONTROLLERFRAMEWORKCLASSES_H__
       
    19 
       
    20 #include <e32base.h>
       
    21 #include <e32std.h>
       
    22 #include <f32file.h>
       
    23 #include <mmf/common/mmfutilities.h>
       
    24 #include <mmf/common/mmfcontrollerframeworkbase.h>
       
    25 #include <mmf/common/mmfipc.h>
       
    26 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    27 #include <mmf/common/mmfipcserver.h>
       
    28 #endif
       
    29 
       
    30 
       
    31 // fwd ref
       
    32 class CMMFControllerImplementationInformation;
       
    33 class CLogonMonitor;
       
    34 
       
    35 
       
    36 /**
       
    37 @internalComponent
       
    38 */
       
    39 #define KMMFControllerProxyVersion TVersion(7,1,1)
       
    40 
       
    41 /**
       
    42 @internalComponent
       
    43 */
       
    44 const TInt KMMFControllerProxyMaxHeapSize = 0x1000000;//16MB
       
    45 
       
    46 /**
       
    47 @internalComponent
       
    48 */
       
    49 const TInt KMMFControllerProxyMaxCachedMessages = 10;
       
    50 
       
    51 /**
       
    52 @internalComponent
       
    53 
       
    54 Signals that the message is destined for the controller proxy
       
    55 */
       
    56 const TInt KMMFObjectHandleControllerProxy = -1;
       
    57 
       
    58 /**
       
    59 @internalComponent
       
    60 
       
    61 The first valid object handle.  The MMF Object container will
       
    62 begin iterating from here when generating object handles.
       
    63 */
       
    64 const TInt KMMFObjectHandleFirstValid = 1;
       
    65 
       
    66 /**
       
    67 @internalComponent
       
    68 */
       
    69 const TInt KMmfControllerThreadShutdownTimeout = 20000000;	// 20 seconds
       
    70 
       
    71 /**
       
    72 @internalComponent
       
    73 
       
    74 The UID and messages associated with the controller proxy interface.
       
    75 */
       
    76 const TUid KUidInterfaceMMFControllerProxy = {0x101F77E7};
       
    77 
       
    78 /**
       
    79 @internalComponent
       
    80 
       
    81 Struct to allow RMMFController to pass several parameters to new CControllerProxyServer threads.
       
    82 */
       
    83 struct TControllerProxyServerParams 
       
    84 	{
       
    85 	RServer2*	iServer;
       
    86 	TBool		iUsingSharedHeap;
       
    87 	};
       
    88 	
       
    89 
       
    90 /**
       
    91 @internalComponent
       
    92 */
       
    93 enum TMMFControllerProxyMessages
       
    94 	{
       
    95 	EMMFControllerProxyLoadControllerPluginByUid,
       
    96 	EMMFControllerProxyReceiveEvents,
       
    97 	EMMFControllerProxyCancelReceiveEvents
       
    98 	};
       
    99 
       
   100 /**
       
   101 @internalComponent
       
   102 
       
   103 Used to Kill the controller thread either immediately or after a timeout.
       
   104 Used by the controller thread on startup to prevent orphaning if no sessions are created to it.
       
   105 */
       
   106 class CMMFControllerProxyShutdown : public CTimer
       
   107 	{
       
   108 	enum {EMMFControllerProxyShutdownDelay=1000000};	// 1s
       
   109 public:
       
   110 
       
   111 	/**
       
   112 	Create a new shutdown timer.
       
   113 
       
   114 	This method can leave with one of the system-wide error codes.
       
   115 
       
   116 	@since 7.0s
       
   117 	*/
       
   118 	static CMMFControllerProxyShutdown* NewL();
       
   119 
       
   120 	/**
       
   121 	Start the shutdown timer.  The RunL of this active object will be called after
       
   122 	EMMFControllerProxyShutdownDelay microseconds.
       
   123 
       
   124 	@since 7.0s
       
   125 	*/
       
   126 	void Start();
       
   127 
       
   128 	/**
       
   129 	Shut down the controller thread immediately.
       
   130 	
       
   131 	Calls CActiveScheduler::Stop().
       
   132 
       
   133 	@since 7.0s
       
   134 	*/
       
   135 	void ShutdownNow();
       
   136 private:
       
   137 	CMMFControllerProxyShutdown();
       
   138 	void ConstructL();
       
   139 
       
   140 	/**
       
   141 	Calls ShutdownNow().
       
   142 
       
   143 	@since 7.0s
       
   144 	*/
       
   145 	void RunL();
       
   146 	};
       
   147 
       
   148 
       
   149 /**
       
   150 @internalComponent
       
   151 
       
   152 Used to hold on to an TMMFMessage so we can complete it asynchronously to 
       
   153 send an event to the client.
       
   154 
       
   155 @since 7.0s
       
   156 */
       
   157 class CMMFEventReceiver : public CBase
       
   158 	{
       
   159 public:
       
   160 
       
   161 	/**
       
   162 	Constructs a new event receiver.
       
   163 	
       
   164 	This method may leave with one of the system-wide error codes.
       
   165 
       
   166 	@param  aMessage
       
   167 	        The message to be completed when an event occurs.
       
   168 
       
   169 	@return A pointer to the newly created event receiver.
       
   170 
       
   171 	@since  7.0s
       
   172 	*/
       
   173 	static CMMFEventReceiver* NewL(const TMMFMessage& aMessage);
       
   174 
       
   175 	/**
       
   176 	Destructor.
       
   177 
       
   178 	Completes the message with KErrCancel if the message hasn't already been completed.
       
   179 
       
   180 	@since 7.0s
       
   181 	*/
       
   182 	~CMMFEventReceiver();
       
   183 
       
   184 	/**
       
   185 	Sends an event to the client.
       
   186 
       
   187 	@param  aEvent
       
   188 	        The event.
       
   189 
       
   190 	@since  7.0s
       
   191 	*/
       
   192 	void SendEvent(const TMMFEvent& aEvent);
       
   193 private:
       
   194 
       
   195 	/**
       
   196 	Constructor.
       
   197 
       
   198 	@param  aMessage
       
   199 	        The message to be completed when an event occurs.
       
   200 
       
   201 	@since  7.0s
       
   202 	*/
       
   203 	CMMFEventReceiver(const TMMFMessage& aMessage);
       
   204 private:
       
   205 	/** 
       
   206 	The message to be completed when an event occurs.
       
   207 	*/
       
   208 	TMMFMessage iMessage;
       
   209 	};
       
   210 
       
   211 /**
       
   212 @internalComponent
       
   213 
       
   214 The controller proxy server.
       
   215 
       
   216 The main server inside the controller thread, responsible for creating and destroying the single
       
   217 session used to transmit messages from the client to the server.
       
   218 
       
   219 Every controller plugin runs in its own thread, and has its own controller proxy server.
       
   220 
       
   221 @since 7.0s
       
   222 */
       
   223 class CMMFControllerProxyServer : public CMmfIpcServer
       
   224 	{
       
   225 public:
       
   226 	/**
       
   227 	Construct the server.
       
   228 
       
   229 	This method may leave with one of the system-wide error codes.
       
   230 
       
   231 	@return The newly created server.
       
   232 
       
   233 	@since  7.0s
       
   234 	*/
       
   235 	static CMMFControllerProxyServer* NewL(RServer2* aServer2 );
       
   236 
       
   237 	/**
       
   238 	Destructor.
       
   239 
       
   240 	@since 7.0s
       
   241 	*/
       
   242 	~CMMFControllerProxyServer();
       
   243 
       
   244 	/**
       
   245 	Static thread function.
       
   246 
       
   247 	The address of this function is passed into RThread::Create.
       
   248 
       
   249 	Unpackages the startup parameters and calls DoStartThreadL().
       
   250 
       
   251 	@param  aAny
       
   252 	        A pointer to the packaged startup parameters.
       
   253 
       
   254 	@return One of the system-wide error codes.
       
   255 
       
   256 	@since 7.0s
       
   257 	*/
       
   258 	IMPORT_C static TInt StartThread(TAny* aParam);
       
   259 
       
   260 	/**
       
   261 	Called by the active scheduler when the ServiceL of the session leaves.
       
   262 	Completes the message with the error and restarts the server.
       
   263 
       
   264 	@param  aError
       
   265 	        The error that the session ServiceL left with.
       
   266 
       
   267 	@return  KErrNone
       
   268 	@since 7.0s
       
   269 	*/
       
   270 	TInt RunError(TInt aError);
       
   271 
       
   272 	/**
       
   273 	Signals that the session has been created.
       
   274 
       
   275 	Stops the shutdown timer.
       
   276 
       
   277 	@since 7.0s
       
   278 	*/
       
   279 	void SessionCreated();
       
   280 
       
   281 	/**
       
   282 	Signals that the session has been destroyed.
       
   283 	Causes the server to shut down immediately.
       
   284 
       
   285 	@since 7.0s
       
   286 	*/
       
   287 	void SessionDestroyed();
       
   288 private:
       
   289 
       
   290 	/**
       
   291 	Thread startup code.
       
   292 
       
   293 	Creates the cleanup stack, installs the active scheduler and creates the server.
       
   294 	Once all this is completed successfully, it signals the success back to the client.
       
   295 
       
   296 	This function may leave with one of the system-wide error codes.
       
   297 
       
   298 	@param  aParams
       
   299 	        Used to signal startup success back to the client.
       
   300 
       
   301 	@since 7.0s
       
   302 	*/
       
   303 	static void DoStartThreadL(TAny* aParam);
       
   304 
       
   305 	/**
       
   306 	Creates a new session.  Only one session may be created with the ControllerProxyServer.
       
   307 
       
   308 	This function may leave with one of the system-wide error codes.
       
   309 
       
   310 	@param  aVersion
       
   311 	        The version number of the session.
       
   312 
       
   313 	@return A pointer to the new session.
       
   314 
       
   315 	@since 7.0s
       
   316 	*/
       
   317 	CMmfIpcSession* NewSessionL(const TVersion& aVersion) const;
       
   318 
       
   319 	/** 
       
   320 	Constructor.
       
   321 
       
   322 	@since 7.0s
       
   323 	*/
       
   324 	CMMFControllerProxyServer();
       
   325 
       
   326 	/**
       
   327 	Second phase constructor.
       
   328 
       
   329 	@since 7.0s
       
   330 	*/
       
   331 	void ConstructL(RServer2* aServer2);
       
   332 	
       
   333 	/**
       
   334 	Renaming Controller Proxy Server name
       
   335 	
       
   336 	@since 9.2
       
   337 	*/
       
   338 	static void RenameControllerProxyThread();
       
   339 
       
   340 private:
       
   341 	/** 
       
   342 	The timer used to shut down the server in case the client fails to connect a session.
       
   343 	*/
       
   344 	CMMFControllerProxyShutdown* iShutdownTimer;
       
   345 	/** 
       
   346 	Indicates whether we have a session connected.  Only one session is allowed to connect to the server.
       
   347 	*/
       
   348 	TBool iHaveSession;
       
   349 	};
       
   350 
       
   351 class CMMFController;
       
   352 
       
   353 /**
       
   354 @internalComponent
       
   355 
       
   356 The controller proxy session.
       
   357 
       
   358 Only one session can be connected to a controller proxy server.
       
   359 
       
   360 @since 7.0s
       
   361 */
       
   362 class CMMFControllerProxySession : public CMmfIpcSession, public MAsyncEventHandler
       
   363 	{
       
   364 public:
       
   365 
       
   366 	/**
       
   367 	Construct the session.
       
   368 
       
   369 	This method may leave with one of the system-wide error codes.
       
   370 
       
   371 	@return The newly created server.
       
   372 
       
   373 	@since 7.0s
       
   374 	*/
       
   375 	static CMMFControllerProxySession* NewL();
       
   376 
       
   377 	/**
       
   378 	Second phase constructor called by the CServer base class.
       
   379 
       
   380 	This function may leave with one of the system-wide error codes.
       
   381 
       
   382 	@param  aServer
       
   383 	        A reference to the server to which this session is attached.
       
   384 
       
   385 	@since  7.0s
       
   386 	*/
       
   387 	void CreateL(const CMmfIpcServer& aServer);
       
   388 
       
   389 	/**
       
   390 	Destructor.
       
   391 	*/
       
   392 	~CMMFControllerProxySession();
       
   393 
       
   394 	/**
       
   395 	Called by the CServer baseclass when a request has been made by the client.
       
   396 
       
   397 	This function may leave with on of the system-wide error codes. If
       
   398 	a leave occurs, the message will be automatically completed by the
       
   399 	RunError() of the Controller Proxy Server.
       
   400 
       
   401 	@param  aMessage
       
   402 	        The request to be handled.  The controller proxy session will create
       
   403 	        a TMMFMessage from this, and pass on the request to the controller
       
   404 	        base class to handle.
       
   405 
       
   406 	@since	7.0s
       
   407 	*/
       
   408 	void ServiceL(const RMmfIpcMessage& aMessage);
       
   409 
       
   410 	/**
       
   411 	Derived from MAsyncEventHandler.
       
   412 
       
   413 	@see MAsyncEventHandler
       
   414 
       
   415 	@since	7.0s
       
   416 	*/
       
   417 	TInt SendEventToClient(const TMMFEvent& aEvent);
       
   418 private:
       
   419 	/**
       
   420 	Constructor
       
   421 	*/
       
   422 	CMMFControllerProxySession();
       
   423 
       
   424 	/**
       
   425 	Handle a request from the client to register to receive events from the controller framework.
       
   426 
       
   427 	This function may leave with one of the system-wide error codes.
       
   428 
       
   429 	@param  aMessage
       
   430 	        The request to be handled.
       
   431 
       
   432 	@return ETrue if the message is to be completed now, EFalse if the message will be completed 
       
   433 	        later.
       
   434 	*/
       
   435 	TBool ReceiveEventsL(TMMFMessage& aMessage);
       
   436 
       
   437 	/**
       
   438 	Handle a request from the client to stop receiving events from the controller framework.
       
   439 
       
   440 	This function may leave with one of the system-wide error codes.
       
   441 
       
   442 	@param  aMessage
       
   443 	        The request to be handled.
       
   444 
       
   445 	@return ETrue if the message is to be completed now, EFalse if the message will be completed later.
       
   446 	*/
       
   447 	TBool CancelReceiveEvents(TMMFMessage& aMessage);
       
   448 
       
   449 	/**
       
   450 	Handle a request from the client to load a controller plugin.
       
   451 
       
   452 	This function may leave with one of the system-wide error codes.
       
   453 
       
   454 	@param  aMessage
       
   455 	        The request to be handled.
       
   456 
       
   457 	@return ETrue if the message is to be completed now, EFalse if the message will be completed later.
       
   458 	*/
       
   459 	TBool LoadControllerL(TMMFMessage& aMessage);
       
   460 private:
       
   461 	/** 
       
   462 	The controller plugin. 
       
   463 	*/
       
   464 	CMMFController* iController;
       
   465 	/** 
       
   466 	A pointer to the server. 
       
   467 	*/
       
   468 	CMMFControllerProxyServer* iServer;
       
   469 	/** 
       
   470 	The event receiver.  Used to send events to the client.
       
   471 	*/
       
   472 	CMMFEventReceiver* iEventReceiver;
       
   473 	/** 
       
   474 	The events waiting to be sent to the client.
       
   475 	*/
       
   476 	RArray<TMMFEvent> iEvents;
       
   477 	};
       
   478 
       
   479 #endif //__MMFCONTROLLERFRAMEWORKCLASSES_H__