|
1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include <ssm/ssmstatemanager.h> |
|
17 #include "ssmclisrv.h" |
|
18 |
|
19 /** |
|
20 Connect this session without pre-allocating any async message slots. |
|
21 This version of @c Connect signifies that the session has no dedicated pool of asynchronous message |
|
22 objects but uses the global pool, reducing the kernel memory required to create the session. |
|
23 This is the best version to use unless either: |
|
24 1. The session never sends asynchronous messages, in which case you should specify '0', OR |
|
25 2. The session makes guarantees on at least one asynchronous API that it cannot fail with KErrNoMemory - |
|
26 in which case the maximum number of concurrent asynchronous messages that may |
|
27 be outstanding on a single session must be used. |
|
28 |
|
29 @return KErrNone or a system wide errorcode |
|
30 */ |
|
31 EXPORT_C TInt RSsmStateManager::Connect() |
|
32 { |
|
33 const TInt KTryAllocSlotsFromSystemPoolInRuntime = -1; |
|
34 return Connect(KTryAllocSlotsFromSystemPoolInRuntime); |
|
35 } |
|
36 |
|
37 /** |
|
38 Connect this session with pre-allocated async message slots. |
|
39 |
|
40 In theory a maximum of 3 slots is required for state transition requests because |
|
41 the server can only have two requests queued but must still be able to handle an incoming |
|
42 request to ESsmFail. There is no upper limit for the number of slots that might be |
|
43 required for Swp change requests. |
|
44 |
|
45 @return KErrNone or a system wide errorcode |
|
46 */ |
|
47 EXPORT_C TInt RSsmStateManager::Connect(TInt aAsyncMessageSlots) |
|
48 { |
|
49 return DoConnect(KSsmServerName, Version(), aAsyncMessageSlots); |
|
50 } |
|
51 |
|
52 /** |
|
53 This exists for testing purposes only. |
|
54 @internalComponent |
|
55 */ |
|
56 TInt RSsmStateManager::DoConnect(const TDesC& aServerName, TVersion aVersion, TInt aAsyncMessageSlots) |
|
57 { |
|
58 if(!Handle()) |
|
59 { |
|
60 return CreateSession(aServerName, aVersion, aAsyncMessageSlots); |
|
61 } |
|
62 |
|
63 return KErrAlreadyExists; |
|
64 } //lint !e1746 Suppress parameter 'aVersion' could be made const reference |
|
65 |
|
66 /** |
|
67 Close this session. |
|
68 */ |
|
69 EXPORT_C void RSsmStateManager::Close() |
|
70 { |
|
71 RSessionBase::Close(); |
|
72 } |
|
73 |
|
74 /** |
|
75 Used as part of connect requests to ensure compatibility between client and server binaries. |
|
76 @internalComponent |
|
77 */ |
|
78 TVersion RSsmStateManager::Version() const |
|
79 { |
|
80 return(TVersion(KSsmServMajorVersionNumber, KSsmServMinorVersionNumber, KSsmServBuildVersionNumber)); |
|
81 } |
|
82 |
|
83 /** |
|
84 Issues a synchronous request for a transition from current system state to @c aRequest. |
|
85 The request does not return until the transition has been started (or been rejected). |
|
86 |
|
87 @param aRequest The requested target system state together with a reason. |
|
88 @return Returns either @c KErrNone if the request was accepted or @c KErrNotSupported |
|
89 if the request could not be allowed. If the SendReceive operation |
|
90 failed, a system wide errorcode is returned. |
|
91 */ |
|
92 EXPORT_C TInt RSsmStateManager::RequestStateTransition(TSsmStateTransition aRequest) |
|
93 { |
|
94 if(Handle()) |
|
95 { |
|
96 const TUint32 stateAsInt = aRequest.State().Int(); |
|
97 const TInt reason = aRequest.Reason(); |
|
98 return SendReceive(ERequestStateTransition, TIpcArgs(stateAsInt, reason)); |
|
99 } |
|
100 |
|
101 return KErrDisconnected; |
|
102 } //lint !e1746 Suppress parameter 'aRequest' could be made const reference |
|
103 |
|
104 /** |
|
105 Issues an asynchronous request for a transition from current system state to @c aRequest. |
|
106 The @c TRequestStatus will be completed when the transition has been started (or |
|
107 earlier if it is rejected by the policy). |
|
108 |
|
109 @param aRequest The requested target system state together with a reason. |
|
110 @param aStatus The request status object used to contain the completion status of the request. |
|
111 The completion status will be either @c KErrNone when the tansition is started or |
|
112 @c KErrNotSupported if the request could not be allowed. |
|
113 One of the system wide error-codes if the @c SendReceive operation failed. |
|
114 */ |
|
115 EXPORT_C void RSsmStateManager::RequestStateTransition(TSsmStateTransition aRequest, TRequestStatus& aStatus) |
|
116 { |
|
117 if(Handle()) |
|
118 { |
|
119 const TUint32 stateAsInt = aRequest.State().Int(); |
|
120 const TInt reason = aRequest.Reason(); |
|
121 SendReceive(ERequestStateTransition, TIpcArgs(stateAsInt, reason), aStatus); |
|
122 return; |
|
123 } |
|
124 |
|
125 TRequestStatus* clientStatus = &aStatus; |
|
126 User::RequestComplete(clientStatus, KErrDisconnected); |
|
127 } //lint !e1746 Suppress parameter 'aRequest' could be made const reference |
|
128 |
|
129 /** |
|
130 Issues a synchronous request to cancel all pending transitions which have been requested |
|
131 from this session. Refer to the @c TRequestStatus that was passed into the async |
|
132 @c RequestStateTransition to see if a request was Cancelled. |
|
133 |
|
134 It is not possible to Cancel an ongoing system state transition with this function |
|
135 If you want to abort a transition that is already in progress you need to request |
|
136 another transition, it is then up to the system state policy DLL implementation to finish |
|
137 the ongoing transition as early as possible and start on the new transition. |
|
138 */ |
|
139 EXPORT_C void RSsmStateManager::RequestStateTransitionCancel() |
|
140 { |
|
141 if(Handle()) |
|
142 { |
|
143 const TInt kErrNone = SendReceive(ERequestStateTransitionCancel); |
|
144 } //lint !e529 Suppress symbol not subsequently referenced. Because synchronous IPC never fails |
|
145 } |
|
146 |
|
147 /** |
|
148 Issues a synchronous request to change the value of a System Wide Property. |
|
149 The request does not return until the request has been started (or been rejected). |
|
150 |
|
151 @param aSwp The identifier for the Swp and its new value. |
|
152 @return Returns either @c KErrNone if the request was accepted or @c KErrNotSupported |
|
153 if the request could not be allowed. If the SendReceive operation |
|
154 failed, a system wide errorcode is returned. |
|
155 */ |
|
156 EXPORT_C TInt RSsmStateManager::RequestSwpChange(TSsmSwp aSwp) |
|
157 { |
|
158 if(Handle()) |
|
159 { |
|
160 TUint32 key = aSwp.Key(); |
|
161 TInt value = aSwp.Value(); |
|
162 return SendReceive(ERequestSwpChange, TIpcArgs(key, value)); |
|
163 } |
|
164 |
|
165 return KErrDisconnected; |
|
166 } //lint !e1746 Suppress parameter 'aSwp' could be made const reference |
|
167 |
|
168 /** |
|
169 Issues an asynchronous request to change the value of a System Wide Property. |
|
170 The @c TRequestStatus will be completed when the request has been started (or been rejected). |
|
171 |
|
172 @param aSwp The identifier for the Swp and its new value. |
|
173 @param aStatus The request status object used to contain the completion status of the request. |
|
174 The completion status will be either @c KErrNone if the request was accepted or |
|
175 @c KErrNotSupported if the request could not be allowed. |
|
176 One of the system wide error-codes if the @c SendReceive operation failed. |
|
177 */ |
|
178 EXPORT_C void RSsmStateManager::RequestSwpChange(TSsmSwp aSwp, TRequestStatus& aStatus) |
|
179 { |
|
180 if(Handle()) |
|
181 { |
|
182 TUint32 key = aSwp.Key(); |
|
183 TInt value = aSwp.Value(); |
|
184 SendReceive(ERequestSwpChange, TIpcArgs(key, value), aStatus); |
|
185 return; |
|
186 } |
|
187 |
|
188 TRequestStatus* clientStatus = &aStatus; |
|
189 User::RequestComplete(clientStatus, KErrDisconnected); |
|
190 } //lint !e1746 Suppress parameter 'aSwp' could be made const reference |
|
191 |
|
192 /** |
|
193 Request to Cancel any request originating from this session for which the @c TRequestStatus |
|
194 has not yet been completed. |
|
195 */ |
|
196 EXPORT_C void RSsmStateManager::RequestSwpChangeCancel() |
|
197 { |
|
198 if(Handle()) |
|
199 { |
|
200 const TInt kErrNone = SendReceive(ERequestSwpChangeCancel); |
|
201 } //lint !e529 Suppress symbol not subsequently referenced. Because synchronous IPC never fails |
|
202 } |
|
203 |
|
204 /** |
|
205 Establish a mapping between the identifier key of a System Wide Property and the DLL that implements |
|
206 the MSsmSwpPolicy interface for the System Wide Property in question. |
|
207 |
|
208 These DLLs can only be loaded from ROM (Z:). There will be no attempt to load or verify the existence of |
|
209 the given file until the first time it is used (i.e. the first time there is a call to @c RequestSwpChange()) |
|
210 |
|
211 @param aSwp The identifier key of a System Wide Property |
|
212 @param aFilename The filename of the MSsmSwpPolicy DLL for this property. Should be given with no path, |
|
213 with or without extension. |
|
214 @return KErrNone or a system wide errorcode |
|
215 @internalTechnology |
|
216 */ |
|
217 EXPORT_C TInt RSsmStateManager::RegisterSwpMapping(TUint aSwpKey, const TDesC& aFilename) |
|
218 { |
|
219 if(Handle()) |
|
220 { |
|
221 TIpcArgs args(aSwpKey, &aFilename); |
|
222 return SendReceive(ERequestRegisterSwpMapping, args); |
|
223 } |
|
224 |
|
225 return KErrDisconnected; |
|
226 } //lint !e1746 Suppress parameter 'aSwpKey' could be made const reference |