sl@0: // Copyright (c) 1995-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 the License "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: // e32\include\twintnotifier.h sl@0: // Text Window Server text notifiers. sl@0: // sl@0: // WARNING: This file contains some APIs which are internal and are subject sl@0: // to change without notice. Such APIs should therefore not be used sl@0: // outside the Kernel and Hardware Services package. sl@0: // sl@0: sl@0: #ifndef __TWINTNOTIFIER_H__ sl@0: #define __TWINTNOTIFIER_H__ sl@0: sl@0: #include sl@0: sl@0: sl@0: // Notifier Plugin architecture copied from UIKON sl@0: sl@0: sl@0: sl@0: /** sl@0: @internalComponent sl@0: */ sl@0: _LIT(KNotifierPlugInExt,"*.*"); sl@0: sl@0: sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: sl@0: Defines the path which is searched for notifier plugin DLLs. sl@0: */ sl@0: _LIT(KNotifierPlugInSearchPath,"\\sys\\bin\\tnotifiers\\"); sl@0: sl@0: sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @deprecated sl@0: */ sl@0: const TUid KUidNotifierPlugIn={0x10005522}; sl@0: sl@0: sl@0: sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: */ sl@0: const TUid KUidTextNotifierPlugInV2={0x101fe38b}; sl@0: sl@0: sl@0: sl@0: /** sl@0: @internalComponent sl@0: */ sl@0: _LIT8(KNotifierPaused,"Eik_Notifier_Paused"); sl@0: sl@0: sl@0: sl@0: /** sl@0: @internalComponent sl@0: */ sl@0: _LIT8(KNotifierResumed,"Eik_Notifier_Resumed"); sl@0: sl@0: sl@0: sl@0: enum TNotExtStatus sl@0: /** sl@0: @internalComponent sl@0: */ sl@0: { sl@0: ENotExtRequestCompleted =0, sl@0: ENotExtRequestQueued =1, sl@0: }; sl@0: sl@0: sl@0: sl@0: sl@0: class MNotifierManager sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: sl@0: An interface that allows notifiers to manage their own startup and shutdown. sl@0: sl@0: This class is likely to be of interest to notifiers that observe engines sl@0: using publically available APIs rather than those that are run via RNotifier sl@0: sl@0: @see RNotifier sl@0: */ sl@0: { sl@0: public: sl@0: /** sl@0: Starts the specified notifier. sl@0: sl@0: @param aNotifierUid The Uid that identifies the notifier. sl@0: @param aBuffer Data that can be passed from the client-side. sl@0: The format and meaning of any data sl@0: is implementation dependent. sl@0: @param aResponse Data that can be returned to the client-side. sl@0: The format and meaning of any data is implementation dependent. sl@0: */ sl@0: virtual void StartNotifierL(TUid aNotifierUid,const TDesC8& aBuffer,TDes8& aResponse)=0; sl@0: sl@0: sl@0: sl@0: /** sl@0: Cancels the specified notifier. sl@0: sl@0: @param aNotifierUid The Uid that identifies the notifier. sl@0: */ sl@0: virtual void CancelNotifier(TUid aNotifierUid)=0; sl@0: sl@0: sl@0: /** sl@0: Updates a currently active notifier with new data. sl@0: sl@0: @param aNotifierUid The Uid that identifies the notifier. sl@0: @param aBuffer New data that can be passed from the client-side. sl@0: The format and meaning of any data is implementation dependent. sl@0: @param aResponse Data that can be returned to the client-side. sl@0: The format and meaning of any data is implementation dependent. sl@0: */ sl@0: virtual void UpdateNotifierL(TUid aNotifierUid,const TDesC8& aBuffer,TDes8& aResponse)=0; sl@0: }; sl@0: sl@0: sl@0: sl@0: sl@0: class MNotifierBase2 sl@0: /** sl@0: @publishedPartner sl@0: @released sl@0: sl@0: Interface to a plug-in server side notifier for the text window server. sl@0: sl@0: Any number of MNotifierBase2 objects can be included in a single DLL. sl@0: All notifiers are loaded during device startup and are not destroyed until sl@0: the notifier server closes down. sl@0: sl@0: Note that the text window server is not used in production ROMs. sl@0: It is used when testing low level code. sl@0: */ sl@0: { sl@0: public: sl@0: /** sl@0: Defines a set of notifier priorities. The use and application of these sl@0: values is implementation dependent. ENotifierPriorityAbsolute defines sl@0: the highest priority value; subsequent enum values define decreasing sl@0: priority values. sl@0: */ sl@0: enum TNotifierPriority sl@0: { sl@0: ENotifierPriorityAbsolute=500, sl@0: ENotifierPriorityVHigh=400, sl@0: ENotifierPriorityHigh=300, sl@0: ENotifierPriorityLow=200, sl@0: ENotifierPriorityVLow=100, sl@0: ENotifierPriorityLowest=0 sl@0: }; sl@0: public: sl@0: /** sl@0: Encapsulates the notifier parameters. sl@0: */ sl@0: class TNotifierInfo sl@0: { sl@0: public: sl@0: /** sl@0: The Uid that identifies the notifier. sl@0: */ sl@0: TUid iUid; sl@0: sl@0: /** sl@0: The Uid that identifies the channel to be used by sl@0: the notifier (e.g. the screen, an LED etc). sl@0: */ sl@0: TUid iChannel; sl@0: sl@0: /** sl@0: The notifier priority, typically chosen from the standard set. sl@0: sl@0: @see MNotifierBase2::TNotifierPriority sl@0: */ sl@0: TInt iPriority; sl@0: }; sl@0: public: sl@0: sl@0: sl@0: sl@0: /** sl@0: Frees all resources owned by this notifier. sl@0: sl@0: This function is called by the notifier framework when all resources sl@0: allocated by notifiers should be freed. As a minimum, the implementation sl@0: should delete this object (i.e. delete this;). sl@0: sl@0: Note that it is important to implement this function correctly sl@0: to avoid memory leaks. sl@0: */ sl@0: virtual void Release()=0; sl@0: sl@0: sl@0: sl@0: /** sl@0: Performs any initialisation that this notifier may require. sl@0: sl@0: The function is called when the notifier is first loaded, sl@0: i.e. when the plug-in DLL is loaded. It is called only once. sl@0: sl@0: As a minimum, the implementation should return a TNotifierInfo instance sl@0: describing the notifier parameters. A good implementation would be to set sl@0: up a TNotifierInfo as a data member, and then to return it. This is because sl@0: the same information is returned by Info(). sl@0: sl@0: The function is safe to leave from, so it is possible, sl@0: although rarely necessary, to allocate objects as you would normally do sl@0: in a ConstructL() function as part of two-phase construction. sl@0: sl@0: @return The parameters of the notifier. sl@0: sl@0: @see MNotifierBase2::Info sl@0: */ sl@0: virtual TNotifierInfo RegisterL()=0; sl@0: sl@0: sl@0: sl@0: /** sl@0: Gets the notifier parameters. sl@0: sl@0: This is the same information as returned by RegisterL(), although sl@0: the returned values may be varied at run-time. sl@0: */ sl@0: virtual TNotifierInfo Info() const=0; sl@0: sl@0: sl@0: sl@0: /** sl@0: Starts the notifier. sl@0: sl@0: This is called as a result of a client-side call sl@0: to RNotifier::StartNotifier(), which the client uses to start a notifier sl@0: from which it does not expect a response. sl@0: sl@0: The function is synchronous, but it should be implemented so that sl@0: it completes as soon as possible, allowing the notifier framework sl@0: to enforce its priority mechanism. sl@0: sl@0: It is not possible to wait for a notifier to complete before returning sl@0: from this function unless the notifier is likely to finish implementing sl@0: its functionality immediately. sl@0: sl@0: @param aBuffer Data that can be passed from the client-side. sl@0: The format and meaning of any data is implementation dependent. sl@0: sl@0: @return A pointer descriptor representing data for the initial response sl@0: sl@0: @see RNotifier::StartNotifier sl@0: */ sl@0: virtual TPtrC8 StartL(const TDesC8& aBuffer)=0; sl@0: sl@0: sl@0: sl@0: /** sl@0: Starts the notifier. sl@0: sl@0: This is called as a result of a client-side call to sl@0: the asynchronous function RNotifier::StartNotifierAndGetResponse(). sl@0: This means that the client is waiting, asynchronously, for the notifier sl@0: to tell the client that it has finished its work. sl@0: sl@0: It is important to return from this function as soon as possible, sl@0: sl@0: The implementation of a derived class must make sure that Complete() is sl@0: called on the RMessage2 object when the notifier is deactivated. sl@0: sl@0: This function may be called multiple times if more than one client starts sl@0: the notifier. sl@0: sl@0: @param aBuffer Data that can be passed from the client-side. The format sl@0: and meaning of any data is implementation dependent. sl@0: @param aReplySlot The offset within the message arguments for the reply. sl@0: This message argument will refer to a modifiable sl@0: descriptor, a TDes8 type, into which data sl@0: can be returned. The format and meaning sl@0: of any returned data is implementation dependent. sl@0: @param aMessage Encapsulates a client request. sl@0: sl@0: @see RNotifier::StartNotifierAndGetResponse sl@0: */ sl@0: virtual void StartL(const TDesC8& aBuffer, TInt aReplySlot, const RMessagePtr2& aMessage)=0; sl@0: sl@0: sl@0: sl@0: /** sl@0: Cancels an active notifier. sl@0: sl@0: This is called as a result of a client-side call sl@0: to RNotifier::CancelNotifier(). sl@0: sl@0: An implementation should free any relevant resources, and complete sl@0: any outstanding messages, if relevant. sl@0: sl@0: @see RNotifier::CancelNotifier sl@0: */ sl@0: virtual void Cancel()=0; sl@0: sl@0: sl@0: sl@0: /** sl@0: Updates a currently active notifier with new data. sl@0: sl@0: This is called as a result of a client-side call sl@0: to RNotifier::UpdateNotifier(). sl@0: sl@0: @param aBuffer Data that can be passed from the client-side. sl@0: The format and meaning of any data is sl@0: implementation dependent. sl@0: sl@0: @return A pointer descriptor representing data that may be returned. sl@0: The format and meaning of any data is implementation dependent. sl@0: sl@0: @see RNotifier::UpdateNotifier sl@0: */ sl@0: virtual TPtrC8 UpdateL(const TDesC8& aBuffer)=0; sl@0: public: sl@0: sl@0: sl@0: sl@0: /** sl@0: Sets the notifier manager. sl@0: sl@0: @param aManager A pointer to the notifier manager. sl@0: */ sl@0: void SetManager(MNotifierManager* aManager); sl@0: protected: sl@0: MNotifierManager* iManager; sl@0: private: sl@0: TInt iNotBSpare; sl@0: }; sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: // Remaining classes are internal to the text window server sl@0: sl@0: sl@0: sl@0: class CNotifierManager; sl@0: sl@0: /** sl@0: @internalComponent sl@0: */ sl@0: class CNotifierServer : public CServer2 sl@0: { sl@0: public: sl@0: static CNotifierServer* NewL(); sl@0: ~CNotifierServer(); sl@0: public: // from CServer2 sl@0: CSession2* NewSessionL(const TVersion &aVersion,const RMessage2&) const; sl@0: public: sl@0: CNotifierServer(TInt aPriority); sl@0: inline CNotifierManager* Manager() const; sl@0: public: sl@0: void SetIsExiting(); sl@0: TBool IsExiting() const; sl@0: private: sl@0: void ConstructL(); sl@0: private: sl@0: CNotifierManager* iManager; sl@0: TBool iExiting; sl@0: }; sl@0: sl@0: sl@0: sl@0: sl@0: /** sl@0: @internalComponent sl@0: */ sl@0: class CNotifierSession : public CSession2 sl@0: { sl@0: public: sl@0: CNotifierSession(const CNotifierServer& aServer); sl@0: ~CNotifierSession(); sl@0: public: // from CSession2 sl@0: void ServiceL(const RMessage2& aMessage); sl@0: private: sl@0: enum TNotifierPanic sl@0: { sl@0: ENotifierPanicInconsistentDescriptorLengths=0, sl@0: ENotifierPanicPasswordWindow, sl@0: }; sl@0: private: sl@0: void DisplayAlertL(const RMessage2& aMessage); sl@0: void DisplayInfoMsgL(const RMessage2& aMessage); sl@0: void DoStartNotifierL(const RMessage2& aMessage); sl@0: void DoUpdateNotifierL(const RMessage2& aMessage); sl@0: void StartNotifierAndGetResponseL(const RMessage2& aMessage,TBool& aCleanupComplete); sl@0: void PanicClient(const RMessage2& aMessage,TNotifierPanic aCode); sl@0: static TInt InfoPrintThread(TAny* aMessage); sl@0: void RunPasswordWindowL(const RMessage2& aMessage); sl@0: public: sl@0: static RSemaphore NotifierSemaphore; sl@0: private: sl@0: const CNotifierServer* iServer; sl@0: TInt iClientId; sl@0: }; sl@0: sl@0: sl@0: sl@0: sl@0: class CQueueItem; sl@0: class CChannelMonitor; sl@0: class CActivityMonitor; sl@0: class CNotifierQueue; sl@0: sl@0: /** sl@0: @internalComponent sl@0: */ sl@0: class CNotifierManager : public CBase, public MNotifierManager sl@0: { sl@0: public: sl@0: static CNotifierManager* NewL(); sl@0: ~CNotifierManager(); sl@0: void RegisterL(RFs& aFs); sl@0: void NotifierStartL(TUid aNotifierUid,const TDesC8& aBuffer,TPtrC8* aResponse,TInt aClientId); sl@0: TInt NotifierUpdateL(TUid aNotifierUid,const TDesC8& aBuffer,TDes8* aResponse,TInt aClientId); sl@0: TInt NotifierCancel(TUid aNotifierUid); sl@0: void NotifierStartAndGetResponseL(TUid aNotifierUid,const TDesC8& aBuffer,TInt aReplySlot, sl@0: const RMessage2& aMessage,TInt aClientId,TBool& aCleanupComplete); sl@0: void HandleClientExit(TInt aClientId); sl@0: void NotifierStartAndGetResponseL(TUid aNotifierUid,TUid aChannelUid,const TDesC8& aBuffer,TInt aReplySlot, sl@0: const RMessage2& aMessage,TInt aClientId,TBool& aCleanupComplete); sl@0: public: // from MNotifierManager sl@0: void StartNotifierL(TUid aNotifierUid,const TDesC8& aBuffer,TDes8& aResponse); sl@0: void CancelNotifier(TUid aNotifierUid); sl@0: void UpdateNotifierL(TUid aNotifierUid,const TDesC8& aBuffer,TDes8& aResponse); sl@0: private: sl@0: void DoAddPlugInL(const TDesC& aPath,const TDesC& aFileName,const TUidType& aUidType); sl@0: CNotifierManager(); sl@0: void ConstructL(); sl@0: void StartFromQueueL(CQueueItem* aItem); sl@0: private: sl@0: CArrayPtr* iObservedList; sl@0: CArrayFix* iLibraries; sl@0: CChannelMonitor* iChannelMonitor; sl@0: CActivityMonitor* iActivityMonitor; sl@0: CNotifierQueue* iQueue; sl@0: }; sl@0: sl@0: sl@0: sl@0: sl@0: /** sl@0: @internalComponent sl@0: */ sl@0: class TChannelActivity sl@0: { sl@0: public: sl@0: inline TChannelActivity(TUid aChannel,TInt aHighestPriorityRunning); sl@0: public: sl@0: TUid iChannel; sl@0: TInt iHighestPriorityRunning; sl@0: }; sl@0: sl@0: sl@0: sl@0: sl@0: /** sl@0: @internalComponent sl@0: */ sl@0: class CChannelMonitor : public CBase sl@0: { sl@0: public: sl@0: static CChannelMonitor* NewL(); sl@0: inline void AddNewChannelL(TUid aChannel); sl@0: TBool AlreadyHasChannel(TUid aChannel) const; sl@0: TInt ActivityLevel(TUid aChannel) const; sl@0: void UpdateChannel(TUid aChannel,TInt aLevel); sl@0: private: sl@0: CChannelMonitor(); sl@0: private: sl@0: CArrayFixFlat iMonitor; sl@0: }; sl@0: sl@0: sl@0: sl@0: sl@0: /** sl@0: @internalComponent sl@0: */ sl@0: class CNotifierActivity : public CBase sl@0: { sl@0: public: sl@0: static CNotifierActivity* NewLC(const MNotifierBase2::TNotifierInfo& aInfo,TInt aClientId); sl@0: ~CNotifierActivity(); sl@0: TInt Find(TInt aClientId) const; sl@0: private: sl@0: CNotifierActivity(const MNotifierBase2::TNotifierInfo& aInfo); sl@0: void ConstructL(TInt aClientId); sl@0: public: sl@0: const MNotifierBase2::TNotifierInfo iInfo; sl@0: CArrayFixFlat iClientArray; sl@0: }; sl@0: sl@0: sl@0: sl@0: sl@0: /** sl@0: @internalComponent sl@0: */ sl@0: class CActivityMonitor : public CBase sl@0: { sl@0: public: sl@0: static CActivityMonitor* NewL(); sl@0: ~CActivityMonitor(); sl@0: void AddL(const MNotifierBase2::TNotifierInfo& aInfo,TInt aClientId); sl@0: void Remove(TUid aNotifierUid,TInt aClientId); sl@0: void RemoveNotifier(TUid aNotifierUid,TUid aChannel); sl@0: void RemoveClient(TInt aClientId); sl@0: TBool IsNotifierActive(TUid aNotifierUid,TUid aChannel) const; sl@0: TBool IsChannelActive(TUid aChannel,TUid& aNotifier,MNotifierBase2::TNotifierPriority& aHighestPriority) const; sl@0: TBool IsClientPresent(TUid aNotifierUid,TUid aChannel,TInt aClientId) const; sl@0: TBool NotifierForClient(TUid& aNotifier,TInt aClientId) const; sl@0: private: sl@0: CActivityMonitor(); sl@0: TInt Find(TUid aNotifierUid) const; sl@0: TInt Find(TUid aNotifierUid,TUid aChannel) const; sl@0: private: sl@0: CArrayPtrFlat iMonitor; sl@0: }; sl@0: sl@0: sl@0: sl@0: sl@0: /** sl@0: @internalComponent sl@0: */ sl@0: class CQueueItem : public CBase sl@0: { sl@0: public: sl@0: static CQueueItem* NewL(const MNotifierBase2::TNotifierInfo& aInfo,const TDesC8& aBuffer,TInt aReplySlot, sl@0: const RMessage2& aMessage,TInt aClientId); //Asynchronous sl@0: static CQueueItem* NewL(const MNotifierBase2::TNotifierInfo& aInfo,const TDesC8& aBuffer, sl@0: TInt aClientId); //synchronous sl@0: ~CQueueItem(); sl@0: private: sl@0: CQueueItem(const MNotifierBase2::TNotifierInfo& aInfo); sl@0: void ConstructL(const TDesC8& aBuffer,TInt aClientId); sl@0: void ConstructL(const TDesC8& aBuffer,const RMessage2& aMessage,TInt aClientId,TInt aReplySlot); sl@0: public: sl@0: const MNotifierBase2::TNotifierInfo iInfo; sl@0: HBufC8* iBuffer; sl@0: TBool iAsynchronous; sl@0: RMessage2 iMessage; // IMPORTANT, we need to keep a full RMessage object until suport for V1 notifiers is removed sl@0: TInt iClientId; sl@0: TInt iReplySlot; sl@0: }; sl@0: sl@0: sl@0: sl@0: sl@0: /** sl@0: @internalComponent sl@0: */ sl@0: class CNotifierQueue : public CBase sl@0: { sl@0: public: sl@0: static CNotifierQueue* NewL(); sl@0: inline void QueueItemL(CQueueItem* aItem); sl@0: CQueueItem* FetchItem(TUid aChannel); sl@0: TBool IsAlreadyQueued(TUid aNotifier,TUid aChannel) const; sl@0: void RemoveClient(TInt aClientId); sl@0: TInt GetHighestQueuePriority(TUid aChannel); sl@0: private: sl@0: inline CNotifierQueue(); sl@0: private: sl@0: CArrayPtrFlat iQueue; sl@0: }; sl@0: sl@0: inline TChannelActivity::TChannelActivity(TUid aChannel, TInt aHighestPriorityRunning) sl@0: :iChannel(aChannel),iHighestPriorityRunning(aHighestPriorityRunning) sl@0: {} sl@0: sl@0: inline void CChannelMonitor::AddNewChannelL(TUid aChannel) sl@0: {iMonitor.AppendL(TChannelActivity(aChannel,0));} sl@0: sl@0: inline CNotifierManager* CNotifierServer::Manager() const sl@0: {return iManager;} sl@0: sl@0: inline void CNotifierQueue::QueueItemL(CQueueItem* aItem) sl@0: {iQueue.AppendL(aItem);} sl@0: inline CNotifierQueue::CNotifierQueue() sl@0: :iQueue(3) sl@0: {} sl@0: sl@0: #endif // __TWINTNOTIFIER_H__