|
1 /* |
|
2 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * Implements CUpsSession. See class and function definitions for |
|
16 * more information. |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 /** |
|
22 @file |
|
23 */ |
|
24 |
|
25 #include "upsserver.h" |
|
26 #include "authoriser.h" |
|
27 #include <ups/upserr.h> |
|
28 |
|
29 namespace UserPromptService |
|
30 { |
|
31 |
|
32 CUpsSubsession* CUpsSubsession::NewL(CUpsSession &aSession, const RMessage2& aMessage) |
|
33 /** |
|
34 Factory function allocates a new, initialized instance of CUpsSubsession. |
|
35 |
|
36 @param aMessage Standard server-side handle to message. |
|
37 @return New, initialized instance of CUpsSubsession which |
|
38 is owned by the caller. |
|
39 */ |
|
40 { |
|
41 CUpsSubsession* self = new(ELeave) CUpsSubsession(aSession); |
|
42 // Note that CUpsSubsession ulitmately derives from CObject and therefore it MUST NOT be deleted directly, |
|
43 // instead it should be closed if we leave. |
|
44 // nb. CUpsSession does NOT derive from CObject... |
|
45 CleanupClosePushL(*self); |
|
46 self->ConstructL(aMessage); |
|
47 CleanupStack::Pop(self); |
|
48 return self; |
|
49 } |
|
50 |
|
51 CUpsSubsession::CUpsSubsession(CUpsSession &aSession) |
|
52 /** |
|
53 This private constructor prevents direct instantiation and provides |
|
54 a single point of definition from which to call the superclass c'tor. |
|
55 */ |
|
56 : CScsSubsession(aSession) |
|
57 { |
|
58 // empty. |
|
59 //RDebug::Printf("0x%x CUpsSubsession(session %x)\n", this, &aSession); |
|
60 } |
|
61 |
|
62 void CUpsSubsession::ConstructL(const RMessage2& aMessage) |
|
63 /** |
|
64 Initialize this subsession object by opening a handle to the |
|
65 thread whose identifier has been sent. |
|
66 |
|
67 @param aSession Ref to session creating us |
|
68 @param aMessage Standard server-side handle to message. |
|
69 */ |
|
70 { |
|
71 // ARGS: TThreadId, TProcessId |
|
72 |
|
73 TPckg<TThreadId> tidBuf(iClientTid); |
|
74 aMessage.ReadL(0, tidBuf); |
|
75 |
|
76 TPckg<TProcessId> pidBuf(iClientPid); |
|
77 aMessage.ReadL(1, pidBuf); |
|
78 } |
|
79 |
|
80 CUpsSubsession::~CUpsSubsession() |
|
81 /** |
|
82 Close this object's handle to the SS client thread. |
|
83 */ |
|
84 { |
|
85 //RDebug::Printf("0x%x ~CUpsSubsession()\n", this); |
|
86 iDestination.Close(); |
|
87 iOpaqueData.Close(); |
|
88 } |
|
89 |
|
90 TBool CUpsSubsession::DoServiceL(TInt aFunction, const RMessage2& aMessage) |
|
91 /** |
|
92 Implement CScsSubsession by handling the supplied message. |
|
93 |
|
94 @param aFunction Function identifier without SCS code. |
|
95 @param aMessage Standard server-side handle to message. |
|
96 @return ETrue means complete client request now. |
|
97 */ |
|
98 { |
|
99 UserPromptService::TSubsessionFunction f = |
|
100 static_cast<UserPromptService::TSubsessionFunction>(aFunction); |
|
101 //RDebug::Printf("0x%x CUpsSubsession::DoServiceL function %d\n", this, f); |
|
102 switch (f) |
|
103 { |
|
104 case UserPromptService::ESubsessPreparePrompt: |
|
105 PreparePromptL(aMessage); |
|
106 break; |
|
107 |
|
108 case UserPromptService::ESubsessExecutePrompt: |
|
109 ExecutePromptL(aMessage); |
|
110 return EFalse; // If ExecutePrompt returns, instead of leaving, it must have setup an async req |
|
111 BULLSEYE_OFF |
|
112 default: |
|
113 User::Leave(KErrNotSupported); |
|
114 break; |
|
115 BULLSEYE_RESTORE |
|
116 } |
|
117 return ETrue; |
|
118 } |
|
119 |
|
120 void CUpsSubsession::PreparePromptL(const RMessage2& aMessage) |
|
121 /** |
|
122 Save service, description, and opaque data for use in the |
|
123 following execute prompt command. |
|
124 */ |
|
125 { |
|
126 // TIpcArgs is TServiceId aServiceId, const TDesC* aDestination, const TDesC8* aOpaqueData |
|
127 |
|
128 iServiceId.iUid = aMessage.Int0(); |
|
129 |
|
130 // Get Description |
|
131 TInt destinationLength = aMessage.GetDesLengthL(1); |
|
132 iDestination.Close(); |
|
133 iDestination.CreateL(destinationLength); |
|
134 aMessage.ReadL(1, iDestination); |
|
135 |
|
136 // Get Opaque Data |
|
137 TInt opaqueDataLength = aMessage.GetDesLengthL(2); |
|
138 iOpaqueData.Close(); |
|
139 if(opaqueDataLength) |
|
140 { |
|
141 iOpaqueData.CreateL(opaqueDataLength); |
|
142 aMessage.ReadL(2, iOpaqueData); |
|
143 } |
|
144 } |
|
145 |
|
146 void CUpsSubsession::ExecutePromptL(const RMessage2& aMessage) |
|
147 /** |
|
148 Create and start the CAuthoriser to process the request. |
|
149 */ |
|
150 { |
|
151 // TIpcArgs is OUT:TUpsDecision& aDecision, IN:TBool aServerCheckOk |
|
152 |
|
153 // The authorizer object is derived from CAsyncRequest and its |
|
154 // lifecycle is automatically managed by the SCS framework |
|
155 // |
|
156 // iDestination and iOpaqueData are transfered to the CAuthoriser, |
|
157 // our handles will be closed. |
|
158 TBool serverCheckOk = aMessage.Int1(); |
|
159 CUpsSession *session = static_cast<CUpsSession*>(&iSession); |
|
160 RPolicyCacheCountedHandle &cacheManager = session->UpsServer()->iPolicyCache; |
|
161 CleanupReleasePushL(cacheManager); |
|
162 if(!cacheManager.IsOpen()) |
|
163 { |
|
164 cacheManager.OpenL(); |
|
165 } |
|
166 CAuthoriser *authoriser = CAuthoriser::NewL(cacheManager, |
|
167 session, this, serverCheckOk, |
|
168 iClientTid, iClientPid, |
|
169 aMessage, iServiceId, iDestination, iOpaqueData); |
|
170 CleanupStack::Pop(&cacheManager); // transfered ownership to the new CAuthoriser |
|
171 CleanupStack::PushL(authoriser); |
|
172 authoriser->TransferToScsFrameworkL(); |
|
173 CleanupStack::Pop(authoriser); // authoriser now owned by SCS framework |
|
174 |
|
175 /** |
|
176 The authoriser is now responsible for completing the request, |
|
177 so we must NOT leave. |
|
178 |
|
179 We could start the request processing off by calling an |
|
180 authoriser function from within a TRAP handler, but for future |
|
181 proofing we tell the authoriser to self complete so the |
|
182 processing all happens within the active scheduler framework |
|
183 and the authoriser state machine. This will make it much easier |
|
184 to completly restart request processing (if we decide to when |
|
185 policies are changed). |
|
186 */ |
|
187 authoriser->Wakeup(); |
|
188 } |
|
189 |
|
190 |
|
191 } // End of namespace UserPromptService |
|
192 // End of file |