|
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/ssmcommandlistresourcereader.h> |
|
17 #include <ssm/ssmcommandlist.h> |
|
18 #include <ssm/ssmconditionalcallback.h> |
|
19 #include "ssmpanic.h" |
|
20 #include "ssmcommandlistresourcereaderimpl.h" |
|
21 #include "ssmcommandlistimpl.h" |
|
22 |
|
23 /** |
|
24 Constructs a new command list resource reader object. |
|
25 |
|
26 This object must be successfully initialised before it can |
|
27 be used to create command lists. |
|
28 |
|
29 @param aFs A connected file server session. |
|
30 @param aCommandListPath Path identifying a directory containing command list resource files. |
|
31 @param aConditionalCallback A callback used to determine whether an individual command should be |
|
32 included in the command list or not. |
|
33 @return A fully constructed, uninitialised command list resource reader. |
|
34 @leave KErrArgument If @c aCommandListPath is zero length. |
|
35 */ |
|
36 EXPORT_C CSsmCommandListResourceReader* CSsmCommandListResourceReader::NewL(RFs& aFs, const TDesC& aCommandListPath, MSsmConditionalCallback& aConditionalCallback) |
|
37 { |
|
38 CSsmCommandListResourceReader* self = new (ELeave) CSsmCommandListResourceReader(); |
|
39 CleanupStack::PushL(self); |
|
40 self->ConstructL(aFs, aCommandListPath, aConditionalCallback); |
|
41 CleanupStack::Pop(self); |
|
42 return self; |
|
43 } |
|
44 |
|
45 CSsmCommandListResourceReader::CSsmCommandListResourceReader() |
|
46 { |
|
47 } |
|
48 |
|
49 /** |
|
50 Destructor. |
|
51 |
|
52 This frees all resources owned by the object, prior to its destruction. |
|
53 */ |
|
54 EXPORT_C CSsmCommandListResourceReader::~CSsmCommandListResourceReader() |
|
55 { |
|
56 delete iImpl; |
|
57 delete iCommandList; |
|
58 } |
|
59 |
|
60 void CSsmCommandListResourceReader::ConstructL(RFs& aFs, const TDesC& aCommandListPath, MSsmConditionalCallback& aConditionalCallback) |
|
61 { |
|
62 iImpl = CSsmCommandListResourceReaderImpl::NewL(aFs, aCommandListPath, aConditionalCallback); |
|
63 } |
|
64 |
|
65 /** |
|
66 Initialises a command list resource reader. |
|
67 |
|
68 During initialisation, the reader builds a list of mappings between command list ids |
|
69 and associated @c SSM_COMMAND_LIST resources. This is done by reading the |
|
70 @c SSM_COMMAND_LIST_MAPPING resource for each of the command list resource files |
|
71 located in the command list path provided on construction of this object. |
|
72 |
|
73 This object must be initialised before calling @c PrepareCommandList or @c GetCommandList. |
|
74 |
|
75 Initialising an already initialised object just completes @c aStatus with KErrNone. |
|
76 |
|
77 Initialisation is performed asynchronously in the calling thread, so the Active Scheduler |
|
78 must be allowed to run while waiting for @c aStatus to complete. |
|
79 This means code such as @c User::WaitForRequest(aStatus) should not be used to wait for |
|
80 initialisation to complete, as this would cause the current thread to block indefinately. |
|
81 |
|
82 @param aStatus Completes with KErrNone if successful, KErrNotFound if no command list |
|
83 resource files can be found, or a resource file contains no |
|
84 command list id mappings, KErrNotSupported if the @c SSM_COMMAND_LIST_ROOT resource |
|
85 contains an invalid version number, otherwise a system wide error code. |
|
86 @panic CmdResourceRead EInUse1 if currently initialising or preparing a command list. |
|
87 */ |
|
88 EXPORT_C void CSsmCommandListResourceReader::Initialise(TRequestStatus& aStatus) |
|
89 { |
|
90 iImpl->Initialise(aStatus); |
|
91 } |
|
92 |
|
93 /** |
|
94 Cancels an outstanding @c Initialise request by completing the reqeust with KErrCancel. |
|
95 */ |
|
96 EXPORT_C void CSsmCommandListResourceReader::InitialiseCancel() |
|
97 { |
|
98 iImpl->InitialiseCancel(); |
|
99 } |
|
100 |
|
101 /** |
|
102 Initiates preparation of a command list used to transition to a new state. |
|
103 |
|
104 If command list preparation is successfull, the command list may be obtained by calling |
|
105 GetCommandList. |
|
106 |
|
107 Preparation is performed asynchronously in the calling thread, so the Active Scheduler |
|
108 must be allowed to run while waiting for @c aStatus to complete. |
|
109 This means code such as @c User::WaitForRequest(aStatus) should not be used to wait for |
|
110 preparation to complete, as this would cause the current thread to block indefinately. |
|
111 |
|
112 @pre Object must have been successfully initialised via a call to @c Initialise(). |
|
113 @param aCommandListId An integer that uniquely identifies a @c SSM_COMMAND_LIST resource |
|
114 containing a list of commands. |
|
115 @param aState State used to construct the Publish System State command. |
|
116 The command list @c aCommandListId should contain exactly one |
|
117 Publish System State command. |
|
118 @param aStatus Completes with KErrNone if successful, KErrNotFound if the |
|
119 @c SSM_COMMAND_LIST resource corresponding to @c aCommandListId |
|
120 cannot be found, otherwise a system wide error code. |
|
121 @panic CmdResourceRead EInUse2 if currently initialising or preparing a command list. |
|
122 @panic CmdResourceRead ENotInitialized if not successfully initialised. |
|
123 */ |
|
124 EXPORT_C void CSsmCommandListResourceReader::PrepareCommandList(TInt aCommandListId, const TSsmState& aState, TRequestStatus& aStatus) |
|
125 { |
|
126 __ASSERT_ALWAYS(!iImpl->Busy(), PanicNow(KPanicCmdResourceReader, EInUse2)); |
|
127 delete iCommandList; |
|
128 iCommandList = NULL; |
|
129 TRAPD(err, iCommandList = CSsmCommandList::NewL()); |
|
130 if (err != KErrNone) |
|
131 { |
|
132 TRequestStatus* status = &aStatus; |
|
133 User::RequestComplete(status, err); |
|
134 } |
|
135 else |
|
136 { |
|
137 iImpl->PrepareCommandList(*iCommandList, aCommandListId, aState, aStatus); |
|
138 } |
|
139 } |
|
140 |
|
141 /** |
|
142 Initiates preparation of a command list used to change the value of a system wide property. |
|
143 |
|
144 This object must be initialised before calling @c PrepareCommandList or @c GetCommandList. |
|
145 |
|
146 If command list preparation is successfull, the command list may be obtained by calling |
|
147 GetCommandList. |
|
148 |
|
149 Preparation is performed asynchronously in the calling thread, so the Active Scheduler |
|
150 must be allowed to run while waiting for @c aStatus to complete. |
|
151 This means code such as @c User::WaitForRequest(aStatus) should not be used to wait for |
|
152 preparation to complete, as this would cause the current thread to block indefinately. |
|
153 |
|
154 @pre Object must have been successfully initialised via a call to @c Initialise(). |
|
155 @param aCommandListId An integer that uniquely identifies a @c SSM_COMMAND_LIST resource |
|
156 containing a list of commands. |
|
157 @param aSwp System wide property used to construct the Publish System Wide Property command. |
|
158 The command list @c aCommandListId should contain exactly one |
|
159 Publish System Wide Property command. |
|
160 @param aStatus Completes with KErrNone if successful, KErrNotFound if the |
|
161 @c SSM_COMMAND_LIST resource corresponding to @c aCommandListId |
|
162 cannot be found, otherwise a system wide error code. |
|
163 @panic CmdResourceRead EInUse3 if currently initialising or preparing a command list. |
|
164 @panic CmdResourceRead ENotInitialized2 if not successfully initialised. |
|
165 */ |
|
166 EXPORT_C void CSsmCommandListResourceReader::PrepareCommandList(TInt aCommandListId, const TSsmSwp& aSwp, TRequestStatus& aStatus) |
|
167 { |
|
168 __ASSERT_ALWAYS(!iImpl->Busy(), PanicNow(KPanicCmdResourceReader, EInUse3)); |
|
169 delete iCommandList; |
|
170 iCommandList = NULL; |
|
171 TRAPD(err, iCommandList = CSsmCommandList::NewL()); |
|
172 if (err != KErrNone) |
|
173 { |
|
174 TRequestStatus* status = &aStatus; |
|
175 User::RequestComplete(status, err); |
|
176 } |
|
177 else |
|
178 { |
|
179 iImpl->PrepareCommandList(*iCommandList, aCommandListId, aSwp, aStatus); |
|
180 } |
|
181 } |
|
182 |
|
183 /** |
|
184 Cancels an outstanding @c PrepareCommandList request by completing the request with KErrCancel. |
|
185 */ |
|
186 EXPORT_C void CSsmCommandListResourceReader::PrepareCommandListCancel() |
|
187 { |
|
188 iImpl->PrepareCommandListCancel(); |
|
189 delete iCommandList; |
|
190 iCommandList = NULL; |
|
191 } |
|
192 |
|
193 /** |
|
194 Following successful completion of a @c PrepareCommandList request, |
|
195 returns the prepared command list. |
|
196 |
|
197 Only the most recently prepared command list may be returned by this method and |
|
198 may only be returned once, because ownership of the returned command list is |
|
199 transferred to the caller. |
|
200 Subsequent calls to this method with no prepare inbetween will return NULL. |
|
201 |
|
202 @pre A command list must have been successfully prepared via a call to @c PrepareCommandList(). |
|
203 @return A new command list object populated with commands read from resource. |
|
204 Ownership of the returned command list is transferred to the caller. |
|
205 @panic CmdResourceRead ENoPreparedCommandList if a prepared command list is not available. |
|
206 */ |
|
207 EXPORT_C CSsmCommandList* CSsmCommandListResourceReader::GetCommandList() |
|
208 { |
|
209 __ASSERT_DEBUG(iImpl->IsCommandListReady(), PanicNow(KPanicCmdResourceReader, ENoPreparedCommandList)); |
|
210 CSsmCommandList* const commandList = iCommandList; |
|
211 iCommandList = NULL; // return ownership of command list to the caller |
|
212 return commandList; |
|
213 } |
|
214 |
|
215 /** |
|
216 Fills the provided array with command list ids. |
|
217 On return, aArray contains valid command list ids that may be passed to @c PrepareCommandList. |
|
218 |
|
219 @pre Object must have been successfully initialised via a call to @c Initialise(). |
|
220 @param aArray An empty array to be populated with command list ids. |
|
221 @leave KErrArgument If @c aArray is non-empty. |
|
222 @panic CmdResourceRead ENotInitialized3 if not successfully initialised. |
|
223 */ |
|
224 EXPORT_C void CSsmCommandListResourceReader::GetCommandListIdsL(RArray<TInt>& aArray) const |
|
225 { |
|
226 iImpl->GetCommandListIdsL(aArray); |
|
227 } |
|
228 |