|
1 // Copyright (c) 2004-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 "SCHTASK.H" |
|
17 #include "taskfile.h" |
|
18 #include "SCHEXEC.H" |
|
19 #include <schinfointernal.h> |
|
20 |
|
21 /** |
|
22 Returns the index of the slot in the process environment data that contains the |
|
23 shared file server session (RFs) handle passed from the Task Scheduler. |
|
24 |
|
25 @return The index of the shared file server session handle |
|
26 @see RFile::AdoptFromCreator |
|
27 */ |
|
28 EXPORT_C TInt TScheduledTaskFile::FsHandleIndex() |
|
29 { |
|
30 return KTaskFsHandleIndex; |
|
31 } |
|
32 |
|
33 /** |
|
34 Returns the index of the slot in the process environment data that contains the |
|
35 shared file (RFile) handle passed from the Task Scheduler. |
|
36 |
|
37 @return The index of the shared file handle |
|
38 @see RFile::AdoptFromCreator |
|
39 */ |
|
40 EXPORT_C TInt TScheduledTaskFile::FileHandleIndex() |
|
41 { |
|
42 return KTaskFileHandleIndex; |
|
43 } |
|
44 |
|
45 /** Creates the object from the specified stream. |
|
46 |
|
47 @param aStream The stream containing the external representation of this object. |
|
48 @return A new instance of a CScheduledTask object. */ |
|
49 EXPORT_C CScheduledTask* CScheduledTask::NewLC(RReadStream& aStream) |
|
50 { |
|
51 CScheduledTask* self = new(ELeave) CScheduledTask; |
|
52 CleanupStack::PushL(self); |
|
53 self->InternalizeL(aStream); |
|
54 return self; |
|
55 } |
|
56 |
|
57 CScheduledTask::CScheduledTask() |
|
58 { |
|
59 } |
|
60 /** |
|
61 @internalComponent |
|
62 */ |
|
63 CScheduledTask::CScheduledTask(TTaskInfo& aInfo, |
|
64 HBufC* aData, |
|
65 TScheduleType aScheduleType, |
|
66 const TSecurityInfo& aSecurityInfo) |
|
67 : iInfo(aInfo), |
|
68 iData(aData), |
|
69 iScheduleType(aScheduleType), |
|
70 iSecurityInfo(aSecurityInfo) |
|
71 { |
|
72 iPLink.iPriority = aInfo.iPriority; |
|
73 } |
|
74 |
|
75 CScheduledTask::~CScheduledTask() |
|
76 { |
|
77 delete iData; |
|
78 } |
|
79 /** |
|
80 Remove from queue |
|
81 @internalComponent only used by server |
|
82 */ |
|
83 void CScheduledTask::Remove() |
|
84 { |
|
85 iPLink.Deque(); |
|
86 } |
|
87 |
|
88 /** |
|
89 queue offset |
|
90 @internalComponent only used by server |
|
91 */ |
|
92 TInt CScheduledTask::Offset() |
|
93 { |
|
94 return (_FOFF(CScheduledTask,iPLink)); |
|
95 } |
|
96 |
|
97 |
|
98 /** Gets the detailed information for the task. |
|
99 |
|
100 @return Detailed information about a task. */ |
|
101 EXPORT_C const TTaskInfo& CScheduledTask::Info() const |
|
102 { |
|
103 return iInfo; |
|
104 } |
|
105 |
|
106 /** Gets a reference to the data to be passed to the program on execution. |
|
107 |
|
108 @return A reference to the descriptor containing the data. */ |
|
109 EXPORT_C const HBufC& CScheduledTask::Data() const |
|
110 { |
|
111 return *iData; |
|
112 } |
|
113 |
|
114 /** Gets the time when the task stops being valid. |
|
115 |
|
116 If the executing program determines that this time is in the past, then it |
|
117 should not run the task. |
|
118 |
|
119 @return The time when the task stops being valid */ |
|
120 EXPORT_C const TTsTime& CScheduledTask::ValidUntil() const |
|
121 { |
|
122 return iValidUntil; |
|
123 } |
|
124 |
|
125 /** |
|
126 Gets the schedules type. |
|
127 */ |
|
128 EXPORT_C TScheduleType CScheduledTask::ScheduleType() const |
|
129 { |
|
130 return iScheduleType; |
|
131 } |
|
132 |
|
133 /** |
|
134 Gets the security information for this scheduled task. This information |
|
135 is the securityID, VenforID and capabilities of the client who created |
|
136 the schedule responsible for invoking this task. |
|
137 */ |
|
138 EXPORT_C const TSecurityInfo& CScheduledTask::SecurityInfo() const |
|
139 { |
|
140 return iSecurityInfo; |
|
141 } |
|
142 |
|
143 /** |
|
144 Is this task due? |
|
145 @internalComponent only used by server |
|
146 */ |
|
147 TBool CScheduledTask::Due() const |
|
148 { |
|
149 return iDue; |
|
150 } |
|
151 |
|
152 /** |
|
153 Decrement repeat counter |
|
154 @internalComponent only used by server |
|
155 */ |
|
156 void CScheduledTask::DecRepeat() |
|
157 { |
|
158 iInfo.iRepeat--; |
|
159 } |
|
160 |
|
161 /** |
|
162 Set due flag. |
|
163 @internalComponent only used by server |
|
164 */ |
|
165 void CScheduledTask::SetDue(TBool aDue) |
|
166 { |
|
167 iDue = aDue; |
|
168 } |
|
169 |
|
170 /** |
|
171 Mark task as being due. |
|
172 @param aValidUntil time this task will be valid until. |
|
173 This information will be passed to the registered executable, |
|
174 so they may check whether the task should still be executed. |
|
175 @internalComponent only used by server |
|
176 */ |
|
177 void CScheduledTask::OnDue(const TTsTime& aValidUntil) |
|
178 { |
|
179 iValidUntil = aValidUntil; |
|
180 iDue = ETrue; |
|
181 } |
|
182 |
|
183 /** |
|
184 Return flag that determines if task is transisent or persistent. |
|
185 @internalComponent only used by server |
|
186 */ |
|
187 TBool CScheduledTask::Persists() const |
|
188 {return iPersists;} |
|
189 |
|
190 /** |
|
191 Mark task as belonging to a persistent schedule. |
|
192 @internalComponent only used by server |
|
193 */ |
|
194 void CScheduledTask::SetPersists() |
|
195 {iPersists = ETrue;} |
|
196 |
|
197 /** |
|
198 externalize data to stream. |
|
199 @internalComponent only used by server |
|
200 */ |
|
201 void CScheduledTask::ExternalizeL(RWriteStream& aStream) const |
|
202 { |
|
203 aStream << *iData; |
|
204 aStream << iValidUntil; |
|
205 aStream << iInfo; |
|
206 aStream.WriteInt32L(iScheduleId); |
|
207 aStream.WriteInt32L(iScheduleType); |
|
208 aStream << iSecurityInfo; |
|
209 aStream.WriteInt32L(iPersists); |
|
210 } |
|
211 |
|
212 void CScheduledTask::InternalizeL(RReadStream& aStream) |
|
213 { |
|
214 iData = HBufC::NewL(aStream, KMaxTInt); |
|
215 aStream >> iValidUntil; |
|
216 aStream >> iInfo; |
|
217 iScheduleId = aStream.ReadInt32L(); |
|
218 iScheduleType = static_cast<TScheduleType>(aStream.ReadInt32L()); |
|
219 aStream >> iSecurityInfo; |
|
220 iPersists = aStream.ReadInt32L();; |
|
221 } |
|
222 |
|
223 /** |
|
224 Gets the schedulesID |
|
225 @internalComponent only used by server |
|
226 */ |
|
227 TInt CScheduledTask::ScheduleId() const |
|
228 { |
|
229 return iScheduleId; |
|
230 } |
|
231 |
|
232 /** |
|
233 Sets the schedules ID |
|
234 @internalComponent only used by server |
|
235 */ |
|
236 void CScheduledTask::SetScheduleId(TInt aScheduleId) |
|
237 { |
|
238 iScheduleId = aScheduleId; |
|
239 } |
|
240 |
|
241 |
|
242 // Streaming operators for TSecurityInfo |
|
243 RWriteStream& operator<<(RWriteStream& aWriteStream, |
|
244 const TSecurityInfo& aSecurityInfo) |
|
245 { |
|
246 //write security policy |
|
247 aWriteStream.WriteUint32L(aSecurityInfo.iSecureId); |
|
248 aWriteStream.WriteUint32L(aSecurityInfo.iVendorId); |
|
249 // write capabilities by looping through all available |
|
250 for (TUint jj = 0; jj < ECapability_Limit; ++jj) |
|
251 if(aSecurityInfo.iCaps.HasCapability((TCapability)jj)) |
|
252 aWriteStream.WriteUint8L(jj); |
|
253 aWriteStream.WriteUint8L(ECapability_HardLimit); // terminate capabilities with hard limit |
|
254 return aWriteStream; |
|
255 } |
|
256 |
|
257 RReadStream& operator>>(RReadStream& aReadStream, |
|
258 TSecurityInfo& aSecurityInfo) |
|
259 { |
|
260 |
|
261 aSecurityInfo.iSecureId = aReadStream.ReadUint32L(); |
|
262 aSecurityInfo.iVendorId = aReadStream.ReadUint32L(); |
|
263 aSecurityInfo.iCaps.SetEmpty(); |
|
264 TCapability cap = ECapability_None; |
|
265 aSecurityInfo.iCaps.AddCapability(cap); |
|
266 while (cap != ECapability_HardLimit ) |
|
267 { |
|
268 aSecurityInfo.iCaps.AddCapability(cap); |
|
269 cap = (TCapability)aReadStream.ReadUint8L(); |
|
270 } |
|
271 return aReadStream; |
|
272 } |
|
273 |
|
274 |
|
275 |