williamr@2: // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). williamr@2: // All rights reserved. williamr@2: // This component and the accompanying materials are made available williamr@2: // 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 williamr@2: // which accompanies this distribution, and is available williamr@2: // at the URL "http://www.symbianfoundation.org/legal/licencesv10.html". williamr@2: // williamr@2: // Initial Contributors: williamr@2: // Nokia Corporation - initial contribution. williamr@2: // williamr@2: // Contributors: williamr@2: // williamr@2: // Description: williamr@2: // williamr@2: williamr@2: williamr@2: #ifndef __MMFCONTROLLERFRAMEWORK_H__ williamr@2: #define __MMFCONTROLLERFRAMEWORK_H__ williamr@2: williamr@2: #include williamr@2: #include williamr@2: #include williamr@2: #include williamr@2: #include williamr@2: #include williamr@2: williamr@2: // fwd ref williamr@2: class CMMFControllerImplementationInformation; williamr@2: class CLogonMonitor; williamr@2: williamr@2: _LIT(KMMFControllerProxyServerName, "MMFControllerProxyServer-"); williamr@2: williamr@2: /** williamr@2: @internalComponent williamr@2: */ williamr@2: #define KMMFControllerProxyVersion TVersion(7,1,1) williamr@2: williamr@2: /** williamr@2: @internalComponent williamr@2: */ williamr@2: const TInt KMMFControllerProxyMaxHeapSize = 0x1000000;//16MB williamr@2: williamr@2: /** williamr@2: @internalComponent williamr@2: */ williamr@2: const TInt KMMFControllerProxyMaxCachedMessages = 10; williamr@2: williamr@2: /** williamr@2: @internalComponent williamr@2: williamr@2: Signals that the message is destined for the controller proxy williamr@2: */ williamr@2: const TInt KMMFObjectHandleControllerProxy = -1; williamr@2: williamr@2: /** williamr@2: @publishedAll williamr@2: @released williamr@2: williamr@2: Signals that the message is destined for the controller williamr@2: */ williamr@2: const TInt KMMFObjectHandleController = -2; williamr@2: williamr@2: /** williamr@2: @publishedAll williamr@2: @released williamr@2: williamr@2: Null, or invalid, object handle williamr@2: */ williamr@2: const TInt KMMFObjectHandleNull = 0; williamr@2: /** williamr@2: @internalComponent williamr@2: williamr@2: The first valid object handle. The MMF Object container will williamr@2: begin iterating from here when generating object handles. williamr@2: */ williamr@2: const TInt KMMFObjectHandleFirstValid = 1; williamr@2: williamr@2: /** williamr@2: @internalComponent williamr@2: */ williamr@2: const TInt KMmfControllerThreadShutdownTimeout = 20000000; // 20 seconds williamr@2: williamr@2: /** williamr@2: @internalComponent williamr@2: williamr@2: The UID and messages associated with the controller proxy interface. williamr@2: */ williamr@2: const TUid KUidInterfaceMMFControllerProxy = {0x101F77E7}; williamr@2: williamr@2: /** williamr@2: @internalComponent williamr@2: williamr@2: Struct to allow RMMFController to pass several parameters to new CControllerProxyServer threads. williamr@2: */ williamr@2: struct TControllerProxyServerParams williamr@2: { williamr@2: RServer2* iServer; williamr@2: TBool iUsingSharedHeap; williamr@2: }; williamr@2: williamr@2: williamr@2: /** williamr@2: @internalComponent williamr@2: */ williamr@2: enum TMMFControllerProxyMessages williamr@2: { williamr@2: EMMFControllerProxyLoadControllerPluginByUid, williamr@2: EMMFControllerProxyReceiveEvents, williamr@2: EMMFControllerProxyCancelReceiveEvents williamr@2: }; williamr@2: williamr@2: williamr@2: /** williamr@2: @publishedAll williamr@2: @released williamr@2: williamr@2: Describes the destination of a message in the controller framework. williamr@2: williamr@2: The destination is defined by a UID describing the interface and an integer object handle. williamr@2: The controller framework uses this information when it receives a message to decide where williamr@2: to send the message. williamr@2: williamr@2: The controller plugin and controller proxy use the special constant handles williamr@2: KMMFObjectHandleControllerProxy and KMMFObjectHandleController for williamr@2: efficiency. williamr@2: williamr@2: @since 7.0s williamr@2: */ williamr@2: class TMMFMessageDestination williamr@2: { williamr@2: public: williamr@2: williamr@2: /** williamr@2: Default constructor. williamr@2: williamr@2: Assigns a null UID to the interface, and a null handle to the handle. williamr@2: williamr@2: @since 7.0s williamr@2: */ williamr@2: IMPORT_C TMMFMessageDestination(); williamr@2: williamr@2: /** williamr@2: Constructor for sending messages to the controller plugin. williamr@2: williamr@2: Assigns KMMFObjectHandleController to the destination handle. williamr@2: williamr@2: @param aInterfaceId williamr@2: The UID of the interface of this message destination. williamr@2: williamr@2: @since 7.0s williamr@2: */ williamr@2: IMPORT_C TMMFMessageDestination(TUid aInterfaceId); williamr@2: williamr@2: /** williamr@2: Full constructor. williamr@2: williamr@2: @param aInterfaceId williamr@2: The UID of the interface of this message destination. williamr@2: @param aDestinationHandle williamr@2: The handle of the destination object in the controller framework. williamr@2: williamr@2: @since 7.0s williamr@2: */ williamr@2: IMPORT_C TMMFMessageDestination(TUid aInterfaceId, TInt aDestinationHandle); williamr@2: williamr@2: /** williamr@2: Copy constructor. williamr@2: williamr@2: @param aOther williamr@2: The TMMFMessageDestination object to be copied. williamr@2: williamr@2: @since 7.0s williamr@2: */ williamr@2: IMPORT_C TMMFMessageDestination(const TMMFMessageDestination& aOther); williamr@2: williamr@2: /** williamr@2: Returns the UID of the interface of the message destination. williamr@2: williamr@2: @return The interface UID. williamr@2: williamr@2: @since 7.0s williamr@2: */ williamr@2: IMPORT_C TUid InterfaceId() const; williamr@2: williamr@2: /** williamr@2: Returns the handle of the destination object in the controller framework. williamr@2: williamr@2: @return The destination handle. williamr@2: williamr@2: @since 7.0s williamr@2: */ williamr@2: IMPORT_C TInt DestinationHandle() const; williamr@2: williamr@2: /** williamr@2: Compares two destinations. williamr@2: williamr@2: @param aOther williamr@2: The object to be compared with this object. williamr@2: williamr@2: @return A boolean indicating if the objects are the same. ETrue if the objects are the same, williamr@2: EFalse if the objects are different. williamr@2: williamr@2: @since 7.0s williamr@2: */ williamr@2: IMPORT_C TBool operator==(const TMMFMessageDestination& aOther) const; williamr@2: williamr@2: private: williamr@2: TUid iInterfaceId; williamr@2: TInt iDestinationHandle; williamr@2: /** williamr@2: This member is internal and not intended for use. williamr@2: */ williamr@2: TInt iReserved1; williamr@2: TInt iReserved2; williamr@2: TInt iReserved3; williamr@2: }; williamr@2: williamr@2: /** williamr@2: @publishedAll williamr@2: @released williamr@2: williamr@2: Package buffer for TMMFMessageDestination williamr@2: */ williamr@2: typedef TPckgBuf TMMFMessageDestinationPckg; williamr@2: williamr@2: williamr@2: /** williamr@2: @publishedAll williamr@2: @released williamr@2: williamr@2: Encapsulation of an RMessage or an RMessage2 to provide protection to controller plugins williamr@2: from the changes occurring with secure APIs. williamr@2: williamr@2: Adds required destination information to the message so the controller framework williamr@2: can determine which object the message is for. williamr@2: williamr@2: Adds capability to check whether the message has been completed. williamr@2: williamr@2: Allows two descriptors to be read from the client, and one descriptor to be copied to the client. williamr@2: williamr@2: @see RMMFControllerProxy::SendSync williamr@2: @see RMMFControllerProxy::SendAsync williamr@2: williamr@2: @since 7.0s williamr@2: */ williamr@2: class TMMFMessage williamr@2: { williamr@2: friend class CMMFControllerProxySession; williamr@2: friend class CMMFDevSoundSession; williamr@2: public: williamr@2: williamr@2: /** williamr@2: Copy constructor. williamr@2: williamr@2: A controller plugin should use this to take a copy of the message when it must wait for some williamr@2: other event before completing it. williamr@2: williamr@2: @param aMessage williamr@2: The message object to copy. williamr@2: williamr@2: @since 7.0s williamr@2: */ williamr@2: IMPORT_C TMMFMessage(const TMMFMessage& aMessage); williamr@2: williamr@2: /** williamr@2: Returns the destination of the message. williamr@2: williamr@2: @return The destination of the message, consisting of a UID defining the interface and the williamr@2: handle of the destination object. williamr@2: williamr@2: @since 7.0s williamr@2: */ williamr@2: IMPORT_C const TMMFMessageDestination& Destination(); williamr@2: williamr@2: /** williamr@2: Returns an integer describing the function being called. Equivalent to williamr@2: RMessage::Function(). williamr@2: williamr@2: @return The function being called over IPC. williamr@2: williamr@2: @see RMessage::Function() williamr@2: williamr@2: @since 7.0s williamr@2: */ williamr@2: IMPORT_C TInt Function(); williamr@2: williamr@2: /** williamr@2: Returns the size of the first descriptor that can be copied over from the client. williamr@2: williamr@2: Use this to create a descriptor of appropriate size before reading the data from the client. williamr@2: williamr@2: @return The size of data 1. williamr@2: @since 7.0s williamr@2: */ williamr@2: IMPORT_C TInt SizeOfData1FromClient(); williamr@2: williamr@2: /** williamr@2: Copy the first descriptor from the client. williamr@2: williamr@2: @param aDes williamr@2: A descriptor defining the area of memory into which the data from the client williamr@2: will be copied. Note, the descriptor must be of sufficient size. williamr@2: williamr@2: @return One of the system-wide error codes. In particular, KErrBadDescriptor will be returned williamr@2: if the client did not provide a valid descriptor. williamr@2: williamr@2: @since 7.0s williamr@2: */ williamr@2: IMPORT_C TInt ReadData1FromClient(TDes8& aDes); williamr@2: williamr@2: /** williamr@2: Copy the first descriptor from the client. williamr@2: williamr@2: This functino can leave with one of the system-wide error codes. In particular, the leave code williamr@2: KErrBadDescriptor will be used if the client did not provide a valid descriptor. williamr@2: williamr@2: @param aDes williamr@2: A descriptor defining the area of memory into which the data from the client williamr@2: will be copied. Note, the descriptor must be of sufficient size. williamr@2: williamr@2: @since 7.0s williamr@2: */ williamr@2: IMPORT_C void ReadData1FromClientL(TDes8& aDes); williamr@2: williamr@2: williamr@2: /** williamr@2: Returns the size of the second descriptor that can be copied over from the client. williamr@2: williamr@2: Use this to create a descriptor of appropriate size before reading the data from the client. williamr@2: williamr@2: @return The size of data 2. williamr@2: williamr@2: @since 7.0s williamr@2: */ williamr@2: IMPORT_C TInt SizeOfData2FromClient(); williamr@2: williamr@2: /** williamr@2: Copies the second descriptor from the client. williamr@2: williamr@2: @param aDes williamr@2: A descriptor defining the area of memory into which the data from the client williamr@2: will be copied. Note, the descriptor must be of sufficient size. williamr@2: williamr@2: @return One of the system-wide error codes. In particular, KErrBadDescriptor will be returned williamr@2: if the client did not provide a valid descriptor. williamr@2: williamr@2: @since 7.0s williamr@2: */ williamr@2: IMPORT_C TInt ReadData2FromClient(TDes8& aDes); williamr@2: williamr@2: /** williamr@2: Copies the second descriptor from the client. williamr@2: williamr@2: This function can leave with one of the system-wide error codes. In particular, the leave code williamr@2: KErrBadDescriptor will be used if the client did not provide a valid descriptor. williamr@2: williamr@2: @param aDes williamr@2: A descriptor defining the area of memory into which the data from the client williamr@2: will be copied. Note, the descriptor must be of sufficient size. williamr@2: williamr@2: @since 7.0s williamr@2: */ williamr@2: IMPORT_C void ReadData2FromClientL(TDes8& aDes); williamr@2: williamr@2: /** williamr@2: Copies data back to the client. williamr@2: williamr@2: @param aDes williamr@2: The data to be copied back to the client. Note that the client must williamr@2: have already created a descriptor of sufficient size for the data to be williamr@2: copied into. williamr@2: williamr@2: @return One of the system-wide error codes. In particular, the error code KErrBadDescriptor will williamr@2: be returned if the client did not provide a valid descriptor. williamr@2: williamr@2: @since 7.0s williamr@2: */ williamr@2: IMPORT_C TInt WriteDataToClient(const TDesC8& aDes); williamr@2: williamr@2: /** williamr@2: Copies the data back to the client. williamr@2: williamr@2: This function can leave with one of the system-wide error codes. In particular, the leave code williamr@2: KErrBadDescriptor will be used if the client did not provide a valid descriptor. williamr@2: williamr@2: @param aDes williamr@2: The data to be copied back to the client. Note that the client must have already williamr@2: created a descriptor of sufficient size for the data to be copied into. williamr@2: williamr@2: @since 7.0s williamr@2: */ williamr@2: IMPORT_C void WriteDataToClientL(const TDesC8& aDes); williamr@2: williamr@2: /** williamr@2: Signals to the client that its request has been completed. williamr@2: williamr@2: Equivalent to RMessage::Complete. williamr@2: williamr@2: @param aReason williamr@2: The result code to be given back to the client. williamr@2: williamr@2: @since 7.0s williamr@2: */ williamr@2: IMPORT_C void Complete(TInt aReason); williamr@2: williamr@2: IMPORT_C void AdoptFileHandleFromClientL(TInt aFsHandleIndex, TInt aFileHandleIndex, RFile& aFile); williamr@2: williamr@2: /** williamr@2: Checks whether this message has already been completed. williamr@2: williamr@2: @return A boolean indicating if the message has been completed. ETrue if the message has been williamr@2: completed, EFalse if not. williamr@2: williamr@2: @since 7.0s williamr@2: */ williamr@2: IMPORT_C TBool IsCompleted(); williamr@2: williamr@2: /** williamr@2: Constructs a TMMFMessage from an RMmfIpcMessage. williamr@2: williamr@2: @param aMessage williamr@2: The handle to the remote message. williamr@2: williamr@2: @since 7.0s williamr@2: */ williamr@2: IMPORT_C TMMFMessage(const RMmfIpcMessage& aMessage); williamr@2: williamr@2: /** williamr@2: Gets the destination info from the client. williamr@2: williamr@2: @since 7.0s williamr@2: */ williamr@2: IMPORT_C void FetchDestinationL(); williamr@2: private: williamr@2: #ifdef __MMF_USE_IPC_V2__ williamr@2: /** williamr@2: The encapsulated message williamr@2: */ williamr@2: RMessagePtr2 iMessage; williamr@2: /** williamr@2: The encapsulated function williamr@2: */ williamr@2: TInt iFunction; williamr@2: /** williamr@2: Private padding to preserve BC with earlier versions williamr@2: */ williamr@2: TInt iDummyPadding[6]; williamr@2: #else williamr@2: /** williamr@2: The RMessage encapsulated by this object. williamr@2: */ williamr@2: RMessage iMessage; williamr@2: #endif // __MMF_USE_IPC_V2__ williamr@2: williamr@2: /** williamr@2: The destination of this message. williamr@2: */ williamr@2: TMMFMessageDestination iDestination; williamr@2: williamr@2: /** williamr@2: Defines whether this object has yet to be completed. williamr@2: */ williamr@2: TBool iAmCompleted; williamr@2: }; williamr@2: williamr@2: /** williamr@2: @internalComponent williamr@2: williamr@2: Mixin class used by CLogonMonitor to inform about its state williamr@2: williamr@2: @since 9.3 williamr@2: */ williamr@2: class MLogonMonitorObserver williamr@2: { williamr@2: public: williamr@2: /** williamr@2: The monitored thread has been terminated. williamr@2: */ williamr@2: virtual void ThreadTerminated() = 0; williamr@2: }; williamr@2: williamr@2: /** williamr@2: @internalComponent williamr@2: williamr@2: RSessionBase-based client class to handle the creation of the controller thread and williamr@2: message sending over IPC. williamr@2: williamr@2: The controller proxy is responsible for sending and recieving messages over IPC; it does not williamr@2: care exactly what those messages are. williamr@2: williamr@2: Note the fact that, although this is an internal component, its size cannot be changed because williamr@2: it's embedded in a publishedAll class (RMMFController) and the size of the latter would also be williamr@2: changed raising a binary compatibility problem. williamr@2: williamr@2: @since 7.0s williamr@2: */ williamr@2: NONSHARABLE_CLASS(RMMFControllerProxy) : public RMmfSessionBase, public MLogonMonitorObserver williamr@2: { williamr@2: public: williamr@2: williamr@2: /** williamr@2: Constructor. williamr@2: @since 7.0s williamr@2: */ williamr@2: IMPORT_C RMMFControllerProxy(); williamr@2: williamr@2: /** williamr@2: Create a new thread and load a controller plugin into that thread. williamr@2: williamr@2: @param aControllerUid williamr@2: The UID of the controller plugin to be loaded. williamr@2: @param aUseSharedHeap williamr@2: If this value is EFalse each controller is created with its own heap. The alternative, williamr@2: if the value is ETrue, is that controllers share a special heap with other controllers williamr@2: created the same way. Each heap uses a chunk, so this avoids situations where the williamr@2: number of chunks per process is limited. The default behaviour is generally to be williamr@2: preferred, and should give lower overall memory usage. However, if many controllers are williamr@2: to be created for a particular thread, then ETrue should be provided to prevent running williamr@2: out of heaps or chunks. williamr@2: williamr@2: @return One of the system-wide error codes. williamr@2: @since 7.0s williamr@2: */ williamr@2: IMPORT_C TInt LoadController(TUid aControllerUid, TBool aUseSharedHeap); williamr@2: williamr@2: /** williamr@2: Create a new thread and load a controller plugin into that thread. williamr@2: williamr@2: @param aControllerInfo williamr@2: A reference to a CMMFControllerImplementationInformation object williamr@2: used for determining the controller UID and heap size williamr@2: @param aUseSharedHeap williamr@2: If this value is EFalse each controller is created with its own heap. The alternative, williamr@2: if the value is ETrue, is that controllers share a special heap with other controllers williamr@2: created the same way. Each heap uses a chunk, so this avoids situations where the williamr@2: number of chunks per process is limited. The default behaviour is generally to be williamr@2: preferred, and should give lower overall memory usage. However, if many controllers are williamr@2: to be created for a particular thread, then ETrue should be provided to prevent running williamr@2: out of heaps or chunks. williamr@2: williamr@2: @return One of the system-wide error codes. williamr@2: @since 7.0s williamr@2: */ williamr@2: IMPORT_C TInt LoadController(const CMMFControllerImplementationInformation& aControllerInfo, TBool aUseSharedHeap); williamr@2: williamr@2: /** williamr@2: Create a new thread in another process through Secure DRM Plugin server and load a controller plugin williamr@2: into that thread. The motivation of this model is to allow applications without DRM capability able williamr@2: to play protected content through MMF. williamr@2: williamr@2: @param aControllerUid williamr@2: The UID of the controller plugin to be loaded. williamr@2: @param aUseSharedHeap williamr@2: If this value is EFalse each controller is created with its own heap. The alternative, williamr@2: if the value is ETrue, is that controllers share a special heap with other controllers williamr@2: created the same way. Each heap uses a chunk, so this avoids situations where the williamr@2: number of chunks per process is limited. The default behaviour is generally to be williamr@2: preferred, and should give lower overall memory usage. However, if many controllers are williamr@2: to be created for a particular thread, then ETrue should be provided to prevent running williamr@2: out of heaps or chunks. williamr@2: williamr@2: @return One of the system-wide error codes. williamr@2: */ williamr@2: IMPORT_C TInt LoadControllerInSecureDRMProcess(TUid aControllerUid, TBool aUseSharedHeap); williamr@2: williamr@2: /** williamr@2: Create a new thread in another process through Secure DRM Plugin server and load a controller plugin williamr@2: into that thread. The motivation of this model is to allow applications without DRM capability able williamr@2: to play protected content through MMF. williamr@2: williamr@2: @param aControllerInfo williamr@2: A reference to a CMMFControllerImplementationInformation object williamr@2: used for determining the controller UID and heap size williamr@2: @param aUseSharedHeap williamr@2: If this value is EFalse each controller is created with its own heap. The alternative, williamr@2: if the value is ETrue, is that controllers share a special heap with other controllers williamr@2: created the same way. Each heap uses a chunk, so this avoids situations where the williamr@2: number of chunks per process is limited. The default behaviour is generally to be williamr@2: preferred, and should give lower overall memory usage. However, if many controllers are williamr@2: to be created for a particular thread, then ETrue should be provided to prevent running williamr@2: out of heaps or chunks. williamr@2: williamr@2: @return One of the system-wide error codes. williamr@2: */ williamr@2: IMPORT_C TInt LoadControllerInSecureDRMProcess(const CMMFControllerImplementationInformation& aControllerInfo, TBool aUseSharedHeap); williamr@2: williamr@2: /** williamr@2: Delete the controller plugin and close its thread. williamr@2: williamr@2: Clients must call Close() on the controller proxy, otherwise leaks will occur. williamr@2: williamr@2: @since 7.0s williamr@2: */ williamr@2: IMPORT_C void Close(); williamr@2: williamr@2: /** williamr@2: Send a message synchronously to the controller thread. williamr@2: williamr@2: The controller framework will analyze the message to determine its correct destination. williamr@2: williamr@2: Note: This method will not return until the controller framework has serviced the command. williamr@2: williamr@2: @param aDestination williamr@2: The destination of the message, consisting of the uid of williamr@2: the interface of this message. williamr@2: @param aFunction williamr@2: The function number to indicate which function is to be called williamr@2: on the interface defined in the aDestination parameter. williamr@2: @param aDataTo1 williamr@2: A reference to the first chunk of data to be copied to the controller williamr@2: framework. The exact contents of the data are dependent on the williamr@2: interface being called. Can be NULL. williamr@2: @param aDataTo2 williamr@2: A reference to the second chunk of data to be copied to the controller williamr@2: framework. The exact contents of the data are dependent on the williamr@2: interface being called. Can be NULL. williamr@2: @param aDataFrom williamr@2: A reference to an area of memory to which the controller framework will williamr@2: write any data to be passed back to the client. Can't be NULL. williamr@2: williamr@2: @return The result of the request. Exact range of values is dependent on the interface. williamr@2: @since 7.0s williamr@2: */ williamr@2: IMPORT_C TInt SendSync(const TMMFMessageDestinationPckg& aDestination, TInt aFunction, const TDesC8& aDataTo1, const TDesC8& aDataTo2, TDes8& aDataFrom) const; williamr@2: williamr@2: /** williamr@2: Send a message synchronously to the controller thread. williamr@2: williamr@2: The controller framework will analyze the message to determine its correct destination. williamr@2: williamr@2: Note: This method will not return until the controller framework has serviced the command. williamr@2: williamr@2: @param aDestination williamr@2: The destination of the message, consisting of the uid of williamr@2: the interface of this message. williamr@2: @param aFunction williamr@2: The function number to indicate which function is to be called williamr@2: on the interface defined in the aDestination parameter. williamr@2: @param aDataTo1 williamr@2: A reference to the first chunk of data to be copied to the controller williamr@2: framework. The exact contents of the data are dependent on the williamr@2: interface being called. Can be NULL. williamr@2: @param aDataTo2 williamr@2: A reference to the second chunk of data to be copied to the controller williamr@2: framework. The exact contents of the data are dependent on the williamr@2: interface being called. Can be NULL. williamr@2: williamr@2: @return The result of the request. Exact range of values is dependent on the interface. williamr@2: @since 7.0s williamr@2: */ williamr@2: IMPORT_C TInt SendSync(const TMMFMessageDestinationPckg& aDestination, TInt aFunction, const TDesC8& aDataTo1, const TDesC8& aDataTo2) const; williamr@2: williamr@2: /** williamr@2: Send a message asynchronously to the controller thread. williamr@2: williamr@2: The controller framework will analyze the message to determine its correct destination. williamr@2: williamr@2: Note: This method will return immediately. The RunL of the active object owning the williamr@2: aStatus parameter will be called when the command is completed by the williamr@2: controller framework. williamr@2: williamr@2: @param aDestination williamr@2: The destination of the message, consisting of the uid of williamr@2: the interface of this message. williamr@2: @param aFunction williamr@2: The function number to indicate which function is to be called williamr@2: on the interface defined in the aDestination parameter. williamr@2: @param aDataTo1 williamr@2: A reference to the first chunk of data to be copied to the controller williamr@2: framework. The exact contents of the data are dependent on the williamr@2: interface being called. Can be NULL. williamr@2: @param aDataTo2 williamr@2: A reference to the second chunk of data to be copied to the controller williamr@2: framework. The exact contents of the data are dependent on the williamr@2: interface being called. Can be NULL. williamr@2: @param aDataFrom williamr@2: A reference to an area of memory to which the controller framework will williamr@2: write any data to be passed back to the client. Can't be NULL. williamr@2: @param aStatus williamr@2: The TRequestStatus of an active object. This will contain the williamr@2: result of the request on completion. The exact range of williamr@2: result values is dependent on the interface. williamr@2: williamr@2: @since 7.0s williamr@2: */ williamr@2: IMPORT_C void SendAsync(const TMMFMessageDestinationPckg& aDestination, TInt aFunction, const TDesC8& aDataTo1, const TDesC8& aDataTo2, TDes8& aDataFrom, TRequestStatus& aStatus) const; williamr@2: williamr@2: /** williamr@2: Send a message asynchronously to the controller thread. williamr@2: williamr@2: The controller framework will analyze the message to determine its correct destination. williamr@2: williamr@2: Note: This method will return immediately. The RunL of the active object owning the williamr@2: aStatus parameter will be called when the command is completed by the williamr@2: controller framework. williamr@2: williamr@2: @param aDestination williamr@2: The destination of the message, consisting of the uid of williamr@2: the interface of this message. williamr@2: @param aFunction williamr@2: The function number to indicate which function is to be called williamr@2: on the interface defined in the aDestination parameter. williamr@2: @param aDataTo1 williamr@2: A reference to the first chunk of data to be copied to the controller williamr@2: framework. The exact contents of the data are dependent on the williamr@2: interface being called. Can be NULL. williamr@2: @param aDataTo2 williamr@2: A reference to the second chunk of data to be copied to the controller williamr@2: framework. The exact contents of the data are dependent on the williamr@2: interface being called. Can be NULL. williamr@2: @param aStatus williamr@2: The TRequestStatus of an active object. This will contain the williamr@2: result of the request on completion. The exact range of williamr@2: result values is dependent on the interface. williamr@2: williamr@2: @since 7.0s williamr@2: */ williamr@2: IMPORT_C void SendAsync(const TMMFMessageDestinationPckg& aDestination, TInt aFunction, const TDesC8& aDataTo1, const TDesC8& aDataTo2, TRequestStatus& aStatus) const; williamr@2: williamr@2: IMPORT_C TInt SendSync(TInt aFunction, const TIpcArgs& aIpcArgs) const; williamr@2: IMPORT_C void SendAsync(TInt aFunction, const TIpcArgs& aIpcArgs, TRequestStatus& aStatus) const; williamr@2: /** williamr@2: Register to receive events from the controller framework. williamr@2: williamr@2: Events can be generated at any time, and are generally associated with things that occur williamr@2: due to something happening internally within the controller. For example, an event will williamr@2: be generated if the controller stops playing due to reaching the end of a file. williamr@2: williamr@2: @param aEvent williamr@2: A reference to a TMMFEventPckg object that must be member data williamr@2: of the active object calling this method. The details of the event williamr@2: will be copied into this object when an event occurs. williamr@2: @param aStatus williamr@2: The TRequestStatus of the active object calling this method. williamr@2: williamr@2: @see TMMFEvent williamr@2: @see CMMFControllerEventMonitor williamr@2: @since 7.0s williamr@2: */ williamr@2: IMPORT_C void ReceiveEvents(TMMFEventPckg& aEvent, TRequestStatus& aStatus); williamr@2: williamr@2: /** williamr@2: Cancel a previous registration to receive events from the controller framework. williamr@2: williamr@2: This must be called from the DoCancel() method of the active object using the williamr@2: ReceiveEvents() API. williamr@2: williamr@2: @return One of the standard system-wide error codes. williamr@2: williamr@2: @see TMMFEvent williamr@2: @since 7.0s williamr@2: */ williamr@2: IMPORT_C TInt CancelReceiveEvents(); williamr@2: williamr@2: /** williamr@2: Set the priority of the controller's sub thread. williamr@2: williamr@2: This can be used to increase the responsiveness of the audio plugin to minimise williamr@2: any lag in processing. This function should be used with care as it may have knock-on williamr@2: effects elsewhere in the system. williamr@2: williamr@2: @param aPriority williamr@2: The TThreadPriority that the thread should run under. The default is EPriorityNormal. williamr@2: @return TInt williamr@2: A standard error code: KErrNone if successful, KErrNotReady if the thread does not have a williamr@2: valid handle. williamr@2: */ williamr@2: IMPORT_C TInt SetThreadPriority(const TThreadPriority& aPriority) const; williamr@2: williamr@2: /** williamr@2: The controller subthread has been terminated. williamr@2: williamr@2: This is called by CLogonMonitor when the the thread terminates williamr@2: */ williamr@2: void ThreadTerminated(); williamr@2: private: williamr@2: /** williamr@2: Creates the new thread williamr@2: */ williamr@2: TInt DoCreateSubThread(RServer2* aServer2, TUint aMaxHeapSize, TBool aUseSharedHeap); williamr@2: williamr@2: /** williamr@2: Determines the maximum heap size required by the selected controller williamr@2: */ williamr@2: TUint ControllersMaxHeapSizeL(TUid aControllerUid); williamr@2: williamr@2: /** williamr@2: Load a controller by UID williamr@2: williamr@2: @param aControllerUid williamr@2: The UID of the controller plugin to be loaded. williamr@2: @param aControllerInfo williamr@2: A reference to a CMMFControllerImplementationInformation object williamr@2: used for determining the heap size and DRM server supporting state. williamr@2: @param aUseSharedHeap williamr@2: If this value is EFalse each controller is created with its own heap. The alternative, williamr@2: if the value is ETrue, is that controllers share a special heap with other controllers williamr@2: created the same way. Each heap uses a chunk, so this avoids situations where the williamr@2: number of chunks per process is limited. The default behaviour is generally to be williamr@2: preferred, and should give lower overall memory usage. However, if many controllers are williamr@2: to be created for a particular thread, then ETrue should be provided to prevent running williamr@2: out of heaps or chunks. williamr@2: @param aNoDRMCap williamr@2: The indicator supplied from user used to determine whether the user's process has DRM williamr@2: capability williamr@2: @return TInt williamr@2: One of the system-wide error codes. williamr@2: */ williamr@2: TInt LoadController(TUid aControllerUid, const CMMFControllerImplementationInformation& aControllerInfo, TBool aUseSharedHeap, williamr@2: TBool aNoDRMCap = EFalse); williamr@2: williamr@2: /** williamr@2: Release heap - for use when a shared heap has been registered williamr@2: */ williamr@2: void ReleaseHeap(); williamr@2: williamr@2: /** williamr@2: Create a session to handle situation of playing DRM protected content in williamr@2: process with no DRM capability. williamr@2: DRM server process will be created, if not yet created. This server is responsible to williamr@2: manage and monitor all the MMF Controller servers created as seperate threads belong to williamr@2: DRM server process. Once the new MMF Controller server is running, a MMF Controller server williamr@2: session will be created and the handle is passing back. williamr@2: */ williamr@2: TInt DoCreateSessionForNoDRMCapClient(TUint aMaxHeapSize, TBool aUseSharedHeap); williamr@2: williamr@2: private: williamr@2: enum williamr@2: { williamr@2: /** williamr@2: Shared heap has been opened for this object, and must be closed williamr@2: */ williamr@2: EFlagOpenedSharedHeap=0x01 williamr@2: }; williamr@2: williamr@2: private: williamr@2: /** williamr@2: The thread in which the controller plugin will run. williamr@2: */ williamr@2: RThread iSubThread; williamr@2: /** williamr@2: Used to hold destination for messages from the controller proxy williamr@2: (not from clients calling SendSync/SendAsync!!) williamr@2: */ williamr@2: TMMFMessageDestinationPckg iDestinationPckg; williamr@2: /** williamr@2: Used to determine the success of a logon. If the status is not pending, the logon has failed williamr@2: and the thread should be closed. williamr@2: */ williamr@2: CLogonMonitor* iLogonAO; williamr@2: /** williamr@2: The priority at which the controller plugin thread runs. williamr@2: */ williamr@2: TThreadPriority iThreadPriority; williamr@2: /** williamr@2: Flags field williamr@2: */ williamr@2: TInt iFlags; williamr@2: /** williamr@2: This member is internal and not intended for use. williamr@2: */ williamr@2: TInt iReserved1; williamr@2: }; williamr@2: williamr@2: /** williamr@2: @internalComponent williamr@2: williamr@2: Used to Kill the controller thread either immediately or after a timeout. williamr@2: Used by the controller thread on startup to prevent orphaning if no sessions are created to it. williamr@2: */ williamr@2: class CMMFControllerProxyShutdown : public CTimer williamr@2: { williamr@2: enum {EMMFControllerProxyShutdownDelay=1000000}; // 1s williamr@2: public: williamr@2: williamr@2: /** williamr@2: Create a new shutdown timer. williamr@2: williamr@2: This method can leave with one of the system-wide error codes. williamr@2: williamr@2: @since 7.0s williamr@2: */ williamr@2: static CMMFControllerProxyShutdown* NewL(); williamr@2: williamr@2: /** williamr@2: Start the shutdown timer. The RunL of this active object will be called after williamr@2: EMMFControllerProxyShutdownDelay microseconds. williamr@2: williamr@2: @since 7.0s williamr@2: */ williamr@2: void Start(); williamr@2: williamr@2: /** williamr@2: Shut down the controller thread immediately. williamr@2: williamr@2: Calls CActiveScheduler::Stop(). williamr@2: williamr@2: @since 7.0s williamr@2: */ williamr@2: void ShutdownNow(); williamr@2: private: williamr@2: CMMFControllerProxyShutdown(); williamr@2: void ConstructL(); williamr@2: williamr@2: /** williamr@2: Calls ShutdownNow(). williamr@2: williamr@2: @since 7.0s williamr@2: */ williamr@2: void RunL(); williamr@2: }; williamr@2: williamr@2: williamr@2: /** williamr@2: @publishedAll williamr@2: @released williamr@2: williamr@2: Mixin class to define an object capable of handling an event within the controller framework. williamr@2: */ williamr@2: class MAsyncEventHandler williamr@2: { williamr@2: public: williamr@2: williamr@2: /** williamr@2: Sends an event to the client. williamr@2: williamr@2: @param aEvent williamr@2: The event. williamr@2: williamr@2: @since 7.0s williamr@2: */ williamr@2: virtual TInt SendEventToClient(const TMMFEvent& aEvent) = 0; williamr@2: }; williamr@2: williamr@2: /** williamr@2: @internalComponent williamr@2: williamr@2: Used to hold on to an TMMFMessage so we can complete it asynchronously to williamr@2: send an event to the client. williamr@2: williamr@2: @since 7.0s williamr@2: */ williamr@2: class CMMFEventReceiver : public CBase williamr@2: { williamr@2: public: williamr@2: williamr@2: /** williamr@2: Constructs a new event receiver. williamr@2: williamr@2: This method may leave with one of the system-wide error codes. williamr@2: williamr@2: @param aMessage williamr@2: The message to be completed when an event occurs. williamr@2: williamr@2: @return A pointer to the newly created event receiver. williamr@2: williamr@2: @since 7.0s williamr@2: */ williamr@2: static CMMFEventReceiver* NewL(const TMMFMessage& aMessage); williamr@2: williamr@2: /** williamr@2: Destructor. williamr@2: williamr@2: Completes the message with KErrCancel if the message hasn't already been completed. williamr@2: williamr@2: @since 7.0s williamr@2: */ williamr@2: ~CMMFEventReceiver(); williamr@2: williamr@2: /** williamr@2: Sends an event to the client. williamr@2: williamr@2: @param aEvent williamr@2: The event. williamr@2: williamr@2: @since 7.0s williamr@2: */ williamr@2: void SendEvent(const TMMFEvent& aEvent); williamr@2: private: williamr@2: williamr@2: /** williamr@2: Constructor. williamr@2: williamr@2: @param aMessage williamr@2: The message to be completed when an event occurs. williamr@2: williamr@2: @since 7.0s williamr@2: */ williamr@2: CMMFEventReceiver(const TMMFMessage& aMessage); williamr@2: private: williamr@2: /** williamr@2: The message to be completed when an event occurs. williamr@2: */ williamr@2: TMMFMessage iMessage; williamr@2: }; williamr@2: williamr@2: williamr@2: williamr@2: /** williamr@2: @internalComponent williamr@2: williamr@2: The controller proxy server. williamr@2: williamr@2: The main server inside the controller thread, responsible for creating and destroying the single williamr@2: session used to transmit messages from the client to the server. williamr@2: williamr@2: Every controller plugin runs in its own thread, and has its own controller proxy server. williamr@2: williamr@2: @since 7.0s williamr@2: */ williamr@2: class CMMFControllerProxyServer : public CMmfIpcServer williamr@2: { williamr@2: public: williamr@2: /** williamr@2: Construct the server. williamr@2: williamr@2: This method may leave with one of the system-wide error codes. williamr@2: williamr@2: @return The newly created server. williamr@2: williamr@2: @since 7.0s williamr@2: */ williamr@2: static CMMFControllerProxyServer* NewL(RServer2* aServer2 ); williamr@2: williamr@2: /** williamr@2: Destructor. williamr@2: williamr@2: @since 7.0s williamr@2: */ williamr@2: ~CMMFControllerProxyServer(); williamr@2: williamr@2: /** williamr@2: Static thread function. williamr@2: williamr@2: The address of this function is passed into RThread::Create. williamr@2: williamr@2: Unpackages the startup parameters and calls DoStartThreadL(). williamr@2: williamr@2: @param aAny williamr@2: A pointer to the packaged startup parameters. williamr@2: williamr@2: @return One of the system-wide error codes. williamr@2: williamr@2: @since 7.0s williamr@2: */ williamr@2: IMPORT_C static TInt StartThread(TAny* aParam); williamr@2: williamr@2: /** williamr@2: Called by the active scheduler when the ServiceL of the session leaves. williamr@2: Completes the message with the error and restarts the server. williamr@2: williamr@2: @param aError williamr@2: The error that the session ServiceL left with. williamr@2: williamr@2: @return KErrNone williamr@2: @since 7.0s williamr@2: */ williamr@2: TInt RunError(TInt aError); williamr@2: williamr@2: /** williamr@2: Signals that the session has been created. williamr@2: williamr@2: Stops the shutdown timer. williamr@2: williamr@2: @since 7.0s williamr@2: */ williamr@2: void SessionCreated(); williamr@2: williamr@2: /** williamr@2: Signals that the session has been destroyed. williamr@2: Causes the server to shut down immediately. williamr@2: williamr@2: @since 7.0s williamr@2: */ williamr@2: void SessionDestroyed(); williamr@2: private: williamr@2: williamr@2: /** williamr@2: Thread startup code. williamr@2: williamr@2: Creates the cleanup stack, installs the active scheduler and creates the server. williamr@2: Once all this is completed successfully, it signals the success back to the client. williamr@2: williamr@2: This function may leave with one of the system-wide error codes. williamr@2: williamr@2: @param aParams williamr@2: Used to signal startup success back to the client. williamr@2: williamr@2: @since 7.0s williamr@2: */ williamr@2: static void DoStartThreadL(TAny* aParam); williamr@2: williamr@2: /** williamr@2: Creates a new session. Only one session may be created with the ControllerProxyServer. williamr@2: williamr@2: This function may leave with one of the system-wide error codes. williamr@2: williamr@2: @param aVersion williamr@2: The version number of the session. williamr@2: williamr@2: @return A pointer to the new session. williamr@2: williamr@2: @since 7.0s williamr@2: */ williamr@2: CMmfIpcSession* NewSessionL(const TVersion& aVersion) const; williamr@2: williamr@2: /** williamr@2: Constructor. williamr@2: williamr@2: @since 7.0s williamr@2: */ williamr@2: CMMFControllerProxyServer(); williamr@2: williamr@2: /** williamr@2: Second phase constructor. williamr@2: williamr@2: @since 7.0s williamr@2: */ williamr@2: void ConstructL(RServer2* aServer2); williamr@2: williamr@2: /** williamr@2: Renaming Controller Proxy Server name williamr@2: williamr@2: @since 9.2 williamr@2: */ williamr@2: static void RenameControllerProxyThread(); williamr@2: williamr@2: private: williamr@2: /** williamr@2: The timer used to shut down the server in case the client fails to connect a session. williamr@2: */ williamr@2: CMMFControllerProxyShutdown* iShutdownTimer; williamr@2: /** williamr@2: Indicates whether we have a session connected. Only one session is allowed to connect to the server. williamr@2: */ williamr@2: TBool iHaveSession; williamr@2: }; williamr@2: williamr@2: class CMMFController; williamr@2: williamr@2: /** williamr@2: @internalComponent williamr@2: williamr@2: The controller proxy session. williamr@2: williamr@2: Only one session can be connected to a controller proxy server. williamr@2: williamr@2: @since 7.0s williamr@2: */ williamr@2: class CMMFControllerProxySession : public CMmfIpcSession, public MAsyncEventHandler williamr@2: { williamr@2: public: williamr@2: williamr@2: /** williamr@2: Construct the session. williamr@2: williamr@2: This method may leave with one of the system-wide error codes. williamr@2: williamr@2: @return The newly created server. williamr@2: williamr@2: @since 7.0s williamr@2: */ williamr@2: static CMMFControllerProxySession* NewL(); williamr@2: williamr@2: /** williamr@2: Second phase constructor called by the CServer base class. williamr@2: williamr@2: This function may leave with one of the system-wide error codes. williamr@2: williamr@2: @param aServer williamr@2: A reference to the server to which this session is attached. williamr@2: williamr@2: @since 7.0s williamr@2: */ williamr@2: void CreateL(const CMmfIpcServer& aServer); williamr@2: williamr@2: /** williamr@2: Destructor. williamr@2: */ williamr@2: ~CMMFControllerProxySession(); williamr@2: williamr@2: /** williamr@2: Called by the CServer baseclass when a request has been made by the client. williamr@2: williamr@2: This function may leave with on of the system-wide error codes. If williamr@2: a leave occurs, the message will be automatically completed by the williamr@2: RunError() of the Controller Proxy Server. williamr@2: williamr@2: @param aMessage williamr@2: The request to be handled. The controller proxy session will create williamr@2: a TMMFMessage from this, and pass on the request to the controller williamr@2: base class to handle. williamr@2: williamr@2: @since 7.0s williamr@2: */ williamr@2: void ServiceL(const RMmfIpcMessage& aMessage); williamr@2: williamr@2: /** williamr@2: Derived from MAsyncEventHandler. williamr@2: williamr@2: @see MAsyncEventHandler williamr@2: williamr@2: @since 7.0s williamr@2: */ williamr@2: TInt SendEventToClient(const TMMFEvent& aEvent); williamr@2: private: williamr@2: /** williamr@2: Constructor williamr@2: */ williamr@2: CMMFControllerProxySession(); williamr@2: williamr@2: /** williamr@2: Handle a request from the client to register to receive events from the controller framework. williamr@2: williamr@2: This function may leave with one of the system-wide error codes. williamr@2: williamr@2: @param aMessage williamr@2: The request to be handled. williamr@2: williamr@2: @return ETrue if the message is to be completed now, EFalse if the message will be completed williamr@2: later. williamr@2: */ williamr@2: TBool ReceiveEventsL(TMMFMessage& aMessage); williamr@2: williamr@2: /** williamr@2: Handle a request from the client to stop receiving events from the controller framework. williamr@2: williamr@2: This function may leave with one of the system-wide error codes. williamr@2: williamr@2: @param aMessage williamr@2: The request to be handled. williamr@2: williamr@2: @return ETrue if the message is to be completed now, EFalse if the message will be completed later. williamr@2: */ williamr@2: TBool CancelReceiveEvents(TMMFMessage& aMessage); williamr@2: williamr@2: /** williamr@2: Handle a request from the client to load a controller plugin. williamr@2: williamr@2: This function may leave with one of the system-wide error codes. williamr@2: williamr@2: @param aMessage williamr@2: The request to be handled. williamr@2: williamr@2: @return ETrue if the message is to be completed now, EFalse if the message will be completed later. williamr@2: */ williamr@2: TBool LoadControllerL(TMMFMessage& aMessage); williamr@2: private: williamr@2: /** williamr@2: The controller plugin. williamr@2: */ williamr@2: CMMFController* iController; williamr@2: /** williamr@2: A pointer to the server. williamr@2: */ williamr@2: CMMFControllerProxyServer* iServer; williamr@2: /** williamr@2: The event receiver. Used to send events to the client. williamr@2: */ williamr@2: CMMFEventReceiver* iEventReceiver; williamr@2: /** williamr@2: The events waiting to be sent to the client. williamr@2: */ williamr@2: RArray iEvents; williamr@2: }; williamr@2: williamr@2: williamr@2: #endif