sl@0: /* sl@0: * Copyright (c) 2007-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: * Example code sl@0: * sl@0: */ sl@0: sl@0: sl@0: /** sl@0: @file sl@0: @internalComponent sl@0: @test sl@0: */ sl@0: sl@0: #ifndef TMSGSERVER_H_ sl@0: #define TMSGSERVER_H_ sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: sl@0: // Standard shutdown timer for transient servers sl@0: class CShutdown : public CTimer sl@0: { sl@0: enum {KMyShutdownDelay=0x200000}; // approx 2s sl@0: public: sl@0: inline CShutdown(); sl@0: inline void ConstructL(); sl@0: inline void Start(); sl@0: private: sl@0: void RunL(); sl@0: }; sl@0: sl@0: enum TMsgServerPanic sl@0: { sl@0: EPanicIllegalFunction, sl@0: }; sl@0: sl@0: /** sl@0: Example system server that uses the User Prompt Service. sl@0: */ sl@0: class CMsgServer : public CPolicyServer sl@0: { sl@0: public: sl@0: static CMsgServer* NewLC(); sl@0: CSession2* NewSessionL(const TVersion& aVersion,const RMessage2& aMessage) const; sl@0: inline UserPromptService::RUpsSession& Ups(); sl@0: void AddSession(); sl@0: void DropSession(); sl@0: TCustomResult CustomFailureActionL(const RMessage2& aMessage, TInt aAction, const TSecurityInfo& aMissing); sl@0: ~CMsgServer(); sl@0: private: sl@0: CMsgServer(); sl@0: void ConstructL(); sl@0: private: sl@0: // Server Policies sl@0: static const TInt KPolicyRanges = 3; sl@0: static const TInt KPolicyElements = 1; sl@0: static const TInt iRanges[KPolicyRanges]; sl@0: static const TUint8 iElementsIndex[KPolicyRanges]; sl@0: static const CPolicyServer::TPolicyElement iPolicyElements[KPolicyElements]; sl@0: static const CPolicyServer::TPolicy iPolicy; sl@0: CShutdown iShutdown; sl@0: TInt iSessionCount; sl@0: sl@0: UserPromptService::RUpsSession iUps; /// UPS session class held by Server sl@0: }; sl@0: sl@0: /** sl@0: Active object that asynchronously processes the sending of a message. sl@0: An extra state is added to support UPS authorisation. sl@0: In a more complicated server there may be several different message processor sl@0: classes. sl@0: */ sl@0: class CMsgProcessor : public CActive sl@0: { sl@0: enum TState {EIdle, EAuthorising, ESending}; sl@0: public: sl@0: static CMsgProcessor* NewL(UserPromptService::RUpsSubsession& aAuth); sl@0: void ProcessL(const RMessage2& aMessage, TBool aPlatsecResult); sl@0: ~CMsgProcessor(); sl@0: private: sl@0: CMsgProcessor(UserPromptService::RUpsSubsession& aAuth); sl@0: void ConstructL(); sl@0: void RunL(); sl@0: void DoCancel(); sl@0: TInt RunError(TInt aError); sl@0: void Reset(); sl@0: void GetParamsL(const RMessage2& aMessage); sl@0: void AuthoriseL(const RMessage2& aMessage, TBool aPlatsecResult); sl@0: void SendL(); sl@0: sl@0: private: sl@0: RMessage2 iMessage; sl@0: TState iState; sl@0: RBuf iMsgTo; sl@0: RBuf iMsgBody; sl@0: RTimer iTimer; sl@0: sl@0: UserPromptService::RUpsSubsession& iAuth; /// Handle to UPS sub-session for client sl@0: TUpsDecision iDecision; /// Whether the request was authorised sl@0: TBool iPlatsecResult; /// Whether the platsec check passed sl@0: // In techview this corresponds to sl@0: // ups\policies\test\tupspolicies\resource\ups_01041000_01041001.rss sl@0: // and is recognised by the example UPS dialog creator and notifier. sl@0: static const TUint KServiceId = 0x01041001; sl@0: }; sl@0: sl@0: /** sl@0: Session class for example message server that uses the User Prompt Service sl@0: */ sl@0: class CMsgServerSession : public CSession2 sl@0: { sl@0: public: sl@0: CMsgServerSession(); sl@0: void CreateL(); sl@0: void SetPlatsecResult(TBool aResult); sl@0: ~CMsgServerSession(); sl@0: private: sl@0: inline CMsgServer& Server(); sl@0: void ServiceL(const RMessage2& aMessage); sl@0: CMsgProcessor* iProcessor; sl@0: sl@0: /// Normally, a sub-session is created for each client or client connection sl@0: UserPromptService::RUpsSubsession iAuth; sl@0: /// Only initialise iAuth once sl@0: TBool iAuthInitialised; sl@0: /// RUpsSubsession::Authorise needs to know whether the platsec check passed sl@0: TBool iPlatsecResult; sl@0: }; sl@0: #endif /* TMSGSERVER_H_*/