os/security/authorisation/userpromptservice/examples/integration/tmsgserver/tmsgserver.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/authorisation/userpromptservice/examples/integration/tmsgserver/tmsgserver.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,144 @@
     1.4 +/*
     1.5 +* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of the License "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description: 
    1.18 +* Example code
    1.19 +*
    1.20 +*/
    1.21 +
    1.22 +
    1.23 +/**
    1.24 + @file
    1.25 + @internalComponent
    1.26 + @test
    1.27 +*/
    1.28 +
    1.29 +#ifndef TMSGSERVER_H_
    1.30 +#define TMSGSERVER_H_
    1.31 +
    1.32 +#include <e32base.h>
    1.33 +#include <e32cmn.h>
    1.34 +#include <e32std.h>
    1.35 +#include <ups/upsclient.h>
    1.36 +
    1.37 +
    1.38 +// Standard shutdown timer for transient servers
    1.39 +class CShutdown : public CTimer
    1.40 +	{
    1.41 +	enum {KMyShutdownDelay=0x200000};	// approx 2s
    1.42 +public:
    1.43 +	inline CShutdown();
    1.44 +	inline void ConstructL();
    1.45 +	inline void Start();
    1.46 +private:
    1.47 +	void RunL();
    1.48 +	}; 
    1.49 +
    1.50 +enum TMsgServerPanic
    1.51 +	{
    1.52 +	EPanicIllegalFunction,
    1.53 +	};	
    1.54 +		
    1.55 +/**
    1.56 + Example system server that uses the User Prompt Service.
    1.57 + */
    1.58 +class CMsgServer : public CPolicyServer
    1.59 +	{
    1.60 +public:
    1.61 +	static CMsgServer* NewLC();
    1.62 +	CSession2* NewSessionL(const TVersion& aVersion,const RMessage2& aMessage) const;
    1.63 +	inline UserPromptService::RUpsSession& Ups();	
    1.64 +	void AddSession();
    1.65 +	void DropSession();	   
    1.66 +	TCustomResult CustomFailureActionL(const RMessage2& aMessage, TInt aAction, const TSecurityInfo& aMissing);
    1.67 +	~CMsgServer();
    1.68 +private:
    1.69 +	CMsgServer();
    1.70 +	void ConstructL();
    1.71 +private:
    1.72 +	// Server Policies
    1.73 +	static const TInt KPolicyRanges = 3;
    1.74 +	static const TInt KPolicyElements = 1;
    1.75 +	static const TInt iRanges[KPolicyRanges];
    1.76 +	static const TUint8 iElementsIndex[KPolicyRanges];
    1.77 +	static const CPolicyServer::TPolicyElement iPolicyElements[KPolicyElements];
    1.78 +	static const CPolicyServer::TPolicy iPolicy;
    1.79 +	CShutdown iShutdown;
    1.80 +	TInt iSessionCount;
    1.81 +	
    1.82 +	UserPromptService::RUpsSession iUps;	/// UPS session class held by Server
    1.83 +	};	
    1.84 +	
    1.85 +/**
    1.86 + Active object that asynchronously processes the sending of a message. 
    1.87 + An extra state is added to support UPS authorisation.
    1.88 + In a more complicated server there may be several different message processor
    1.89 + classes.
    1.90 + */	   
    1.91 +class CMsgProcessor : public CActive
    1.92 +	{
    1.93 +	enum TState {EIdle, EAuthorising, ESending};
    1.94 +public:
    1.95 +	static CMsgProcessor* NewL(UserPromptService::RUpsSubsession& aAuth);		
    1.96 +	void ProcessL(const RMessage2& aMessage, TBool aPlatsecResult);
    1.97 +	~CMsgProcessor();
    1.98 +private:
    1.99 +	CMsgProcessor(UserPromptService::RUpsSubsession& aAuth);
   1.100 +	void ConstructL();
   1.101 +	void RunL();
   1.102 +	void DoCancel();
   1.103 +	TInt RunError(TInt aError);
   1.104 +	void Reset();
   1.105 +	void GetParamsL(const RMessage2& aMessage);	
   1.106 +	void AuthoriseL(const RMessage2& aMessage, TBool aPlatsecResult);
   1.107 +	void SendL();
   1.108 +	
   1.109 +private:
   1.110 +	RMessage2 iMessage;
   1.111 +	TState iState;
   1.112 +	RBuf iMsgTo;
   1.113 +	RBuf iMsgBody;
   1.114 +	RTimer iTimer;		
   1.115 +	
   1.116 +	UserPromptService::RUpsSubsession& iAuth;	/// Handle to UPS sub-session for client
   1.117 +	TUpsDecision iDecision;						/// Whether the request was authorised
   1.118 +	TBool iPlatsecResult;						/// Whether the platsec check passed	
   1.119 +	// In techview this corresponds to 
   1.120 +	// ups\policies\test\tupspolicies\resource\ups_01041000_01041001.rss
   1.121 +	// and is recognised by the example UPS dialog creator and notifier.
   1.122 +	static const TUint KServiceId = 0x01041001;
   1.123 +	};
   1.124 +	
   1.125 +/**
   1.126 + Session class for example message server that uses the User Prompt Service
   1.127 + */
   1.128 +class CMsgServerSession : public CSession2
   1.129 +	{
   1.130 +public:
   1.131 +	CMsgServerSession();
   1.132 +	void CreateL();	
   1.133 +	void SetPlatsecResult(TBool aResult);
   1.134 +	~CMsgServerSession();
   1.135 +private:
   1.136 +	inline CMsgServer& Server(); 
   1.137 +	void ServiceL(const RMessage2& aMessage);		 
   1.138 +	CMsgProcessor* iProcessor;
   1.139 +		  
   1.140 +	/// Normally, a sub-session is created for each client or client connection
   1.141 +	UserPromptService::RUpsSubsession iAuth;	
   1.142 +	/// Only initialise iAuth once
   1.143 +	TBool iAuthInitialised;
   1.144 +	/// RUpsSubsession::Authorise needs to know whether the platsec check passed
   1.145 +	TBool iPlatsecResult;
   1.146 +	};
   1.147 +#endif /* TMSGSERVER_H_*/