sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
3 |
* All rights reserved.
|
sl@0
|
4 |
* This component and the accompanying materials are made available
|
sl@0
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
6 |
* which accompanies this distribution, and is available
|
sl@0
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* Initial Contributors:
|
sl@0
|
10 |
* Nokia Corporation - initial contribution.
|
sl@0
|
11 |
*
|
sl@0
|
12 |
* Contributors:
|
sl@0
|
13 |
*
|
sl@0
|
14 |
* Description:
|
sl@0
|
15 |
* Example code
|
sl@0
|
16 |
*
|
sl@0
|
17 |
*/
|
sl@0
|
18 |
|
sl@0
|
19 |
|
sl@0
|
20 |
/**
|
sl@0
|
21 |
@file
|
sl@0
|
22 |
@internalComponent
|
sl@0
|
23 |
@test
|
sl@0
|
24 |
*/
|
sl@0
|
25 |
|
sl@0
|
26 |
#ifndef TMSGSERVER_H_
|
sl@0
|
27 |
#define TMSGSERVER_H_
|
sl@0
|
28 |
|
sl@0
|
29 |
#include <e32base.h>
|
sl@0
|
30 |
#include <e32cmn.h>
|
sl@0
|
31 |
#include <e32std.h>
|
sl@0
|
32 |
#include <ups/upsclient.h>
|
sl@0
|
33 |
|
sl@0
|
34 |
|
sl@0
|
35 |
// Standard shutdown timer for transient servers
|
sl@0
|
36 |
class CShutdown : public CTimer
|
sl@0
|
37 |
{
|
sl@0
|
38 |
enum {KMyShutdownDelay=0x200000}; // approx 2s
|
sl@0
|
39 |
public:
|
sl@0
|
40 |
inline CShutdown();
|
sl@0
|
41 |
inline void ConstructL();
|
sl@0
|
42 |
inline void Start();
|
sl@0
|
43 |
private:
|
sl@0
|
44 |
void RunL();
|
sl@0
|
45 |
};
|
sl@0
|
46 |
|
sl@0
|
47 |
enum TMsgServerPanic
|
sl@0
|
48 |
{
|
sl@0
|
49 |
EPanicIllegalFunction,
|
sl@0
|
50 |
};
|
sl@0
|
51 |
|
sl@0
|
52 |
/**
|
sl@0
|
53 |
Example system server that uses the User Prompt Service.
|
sl@0
|
54 |
*/
|
sl@0
|
55 |
class CMsgServer : public CPolicyServer
|
sl@0
|
56 |
{
|
sl@0
|
57 |
public:
|
sl@0
|
58 |
static CMsgServer* NewLC();
|
sl@0
|
59 |
CSession2* NewSessionL(const TVersion& aVersion,const RMessage2& aMessage) const;
|
sl@0
|
60 |
inline UserPromptService::RUpsSession& Ups();
|
sl@0
|
61 |
void AddSession();
|
sl@0
|
62 |
void DropSession();
|
sl@0
|
63 |
TCustomResult CustomFailureActionL(const RMessage2& aMessage, TInt aAction, const TSecurityInfo& aMissing);
|
sl@0
|
64 |
~CMsgServer();
|
sl@0
|
65 |
private:
|
sl@0
|
66 |
CMsgServer();
|
sl@0
|
67 |
void ConstructL();
|
sl@0
|
68 |
private:
|
sl@0
|
69 |
// Server Policies
|
sl@0
|
70 |
static const TInt KPolicyRanges = 3;
|
sl@0
|
71 |
static const TInt KPolicyElements = 1;
|
sl@0
|
72 |
static const TInt iRanges[KPolicyRanges];
|
sl@0
|
73 |
static const TUint8 iElementsIndex[KPolicyRanges];
|
sl@0
|
74 |
static const CPolicyServer::TPolicyElement iPolicyElements[KPolicyElements];
|
sl@0
|
75 |
static const CPolicyServer::TPolicy iPolicy;
|
sl@0
|
76 |
CShutdown iShutdown;
|
sl@0
|
77 |
TInt iSessionCount;
|
sl@0
|
78 |
|
sl@0
|
79 |
UserPromptService::RUpsSession iUps; /// UPS session class held by Server
|
sl@0
|
80 |
};
|
sl@0
|
81 |
|
sl@0
|
82 |
/**
|
sl@0
|
83 |
Active object that asynchronously processes the sending of a message.
|
sl@0
|
84 |
An extra state is added to support UPS authorisation.
|
sl@0
|
85 |
In a more complicated server there may be several different message processor
|
sl@0
|
86 |
classes.
|
sl@0
|
87 |
*/
|
sl@0
|
88 |
class CMsgProcessor : public CActive
|
sl@0
|
89 |
{
|
sl@0
|
90 |
enum TState {EIdle, EAuthorising, ESending};
|
sl@0
|
91 |
public:
|
sl@0
|
92 |
static CMsgProcessor* NewL(UserPromptService::RUpsSubsession& aAuth);
|
sl@0
|
93 |
void ProcessL(const RMessage2& aMessage, TBool aPlatsecResult);
|
sl@0
|
94 |
~CMsgProcessor();
|
sl@0
|
95 |
private:
|
sl@0
|
96 |
CMsgProcessor(UserPromptService::RUpsSubsession& aAuth);
|
sl@0
|
97 |
void ConstructL();
|
sl@0
|
98 |
void RunL();
|
sl@0
|
99 |
void DoCancel();
|
sl@0
|
100 |
TInt RunError(TInt aError);
|
sl@0
|
101 |
void Reset();
|
sl@0
|
102 |
void GetParamsL(const RMessage2& aMessage);
|
sl@0
|
103 |
void AuthoriseL(const RMessage2& aMessage, TBool aPlatsecResult);
|
sl@0
|
104 |
void SendL();
|
sl@0
|
105 |
|
sl@0
|
106 |
private:
|
sl@0
|
107 |
RMessage2 iMessage;
|
sl@0
|
108 |
TState iState;
|
sl@0
|
109 |
RBuf iMsgTo;
|
sl@0
|
110 |
RBuf iMsgBody;
|
sl@0
|
111 |
RTimer iTimer;
|
sl@0
|
112 |
|
sl@0
|
113 |
UserPromptService::RUpsSubsession& iAuth; /// Handle to UPS sub-session for client
|
sl@0
|
114 |
TUpsDecision iDecision; /// Whether the request was authorised
|
sl@0
|
115 |
TBool iPlatsecResult; /// Whether the platsec check passed
|
sl@0
|
116 |
// In techview this corresponds to
|
sl@0
|
117 |
// ups\policies\test\tupspolicies\resource\ups_01041000_01041001.rss
|
sl@0
|
118 |
// and is recognised by the example UPS dialog creator and notifier.
|
sl@0
|
119 |
static const TUint KServiceId = 0x01041001;
|
sl@0
|
120 |
};
|
sl@0
|
121 |
|
sl@0
|
122 |
/**
|
sl@0
|
123 |
Session class for example message server that uses the User Prompt Service
|
sl@0
|
124 |
*/
|
sl@0
|
125 |
class CMsgServerSession : public CSession2
|
sl@0
|
126 |
{
|
sl@0
|
127 |
public:
|
sl@0
|
128 |
CMsgServerSession();
|
sl@0
|
129 |
void CreateL();
|
sl@0
|
130 |
void SetPlatsecResult(TBool aResult);
|
sl@0
|
131 |
~CMsgServerSession();
|
sl@0
|
132 |
private:
|
sl@0
|
133 |
inline CMsgServer& Server();
|
sl@0
|
134 |
void ServiceL(const RMessage2& aMessage);
|
sl@0
|
135 |
CMsgProcessor* iProcessor;
|
sl@0
|
136 |
|
sl@0
|
137 |
/// Normally, a sub-session is created for each client or client connection
|
sl@0
|
138 |
UserPromptService::RUpsSubsession iAuth;
|
sl@0
|
139 |
/// Only initialise iAuth once
|
sl@0
|
140 |
TBool iAuthInitialised;
|
sl@0
|
141 |
/// RUpsSubsession::Authorise needs to know whether the platsec check passed
|
sl@0
|
142 |
TBool iPlatsecResult;
|
sl@0
|
143 |
};
|
sl@0
|
144 |
#endif /* TMSGSERVER_H_*/
|