1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericservices/taskscheduler/SCHSVR/SCHTASK.CPP Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,275 @@
1.4 +// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include "SCHTASK.H"
1.20 +#include "taskfile.h"
1.21 +#include "SCHEXEC.H"
1.22 +#include <schinfointernal.h>
1.23 +
1.24 +/**
1.25 +Returns the index of the slot in the process environment data that contains the
1.26 +shared file server session (RFs) handle passed from the Task Scheduler.
1.27 +
1.28 +@return The index of the shared file server session handle
1.29 +@see RFile::AdoptFromCreator
1.30 +*/
1.31 +EXPORT_C TInt TScheduledTaskFile::FsHandleIndex()
1.32 + {
1.33 + return KTaskFsHandleIndex;
1.34 + }
1.35 +
1.36 +/**
1.37 +Returns the index of the slot in the process environment data that contains the
1.38 +shared file (RFile) handle passed from the Task Scheduler.
1.39 +
1.40 +@return The index of the shared file handle
1.41 +@see RFile::AdoptFromCreator
1.42 +*/
1.43 +EXPORT_C TInt TScheduledTaskFile::FileHandleIndex()
1.44 + {
1.45 + return KTaskFileHandleIndex;
1.46 + }
1.47 +
1.48 +/** Creates the object from the specified stream.
1.49 +
1.50 +@param aStream The stream containing the external representation of this object.
1.51 +@return A new instance of a CScheduledTask object. */
1.52 +EXPORT_C CScheduledTask* CScheduledTask::NewLC(RReadStream& aStream)
1.53 + {
1.54 + CScheduledTask* self = new(ELeave) CScheduledTask;
1.55 + CleanupStack::PushL(self);
1.56 + self->InternalizeL(aStream);
1.57 + return self;
1.58 + }
1.59 +
1.60 +CScheduledTask::CScheduledTask()
1.61 + {
1.62 + }
1.63 +/**
1.64 +@internalComponent
1.65 +*/
1.66 +CScheduledTask::CScheduledTask(TTaskInfo& aInfo,
1.67 + HBufC* aData,
1.68 + TScheduleType aScheduleType,
1.69 + const TSecurityInfo& aSecurityInfo)
1.70 +: iInfo(aInfo),
1.71 + iData(aData),
1.72 + iScheduleType(aScheduleType),
1.73 + iSecurityInfo(aSecurityInfo)
1.74 + {
1.75 + iPLink.iPriority = aInfo.iPriority;
1.76 + }
1.77 +
1.78 +CScheduledTask::~CScheduledTask()
1.79 + {
1.80 + delete iData;
1.81 + }
1.82 +/**
1.83 +Remove from queue
1.84 +@internalComponent only used by server
1.85 +*/
1.86 +void CScheduledTask::Remove()
1.87 + {
1.88 + iPLink.Deque();
1.89 + }
1.90 +
1.91 +/**
1.92 +queue offset
1.93 +@internalComponent only used by server
1.94 +*/
1.95 +TInt CScheduledTask::Offset()
1.96 + {
1.97 + return (_FOFF(CScheduledTask,iPLink));
1.98 + }
1.99 +
1.100 +
1.101 +/** Gets the detailed information for the task.
1.102 +
1.103 +@return Detailed information about a task. */
1.104 +EXPORT_C const TTaskInfo& CScheduledTask::Info() const
1.105 + {
1.106 + return iInfo;
1.107 + }
1.108 +
1.109 +/** Gets a reference to the data to be passed to the program on execution.
1.110 +
1.111 +@return A reference to the descriptor containing the data. */
1.112 +EXPORT_C const HBufC& CScheduledTask::Data() const
1.113 + {
1.114 + return *iData;
1.115 + }
1.116 +
1.117 +/** Gets the time when the task stops being valid.
1.118 +
1.119 +If the executing program determines that this time is in the past, then it
1.120 +should not run the task.
1.121 +
1.122 +@return The time when the task stops being valid */
1.123 +EXPORT_C const TTsTime& CScheduledTask::ValidUntil() const
1.124 + {
1.125 + return iValidUntil;
1.126 + }
1.127 +
1.128 +/**
1.129 +Gets the schedules type.
1.130 +*/
1.131 +EXPORT_C TScheduleType CScheduledTask::ScheduleType() const
1.132 + {
1.133 + return iScheduleType;
1.134 + }
1.135 +
1.136 +/**
1.137 +Gets the security information for this scheduled task. This information
1.138 +is the securityID, VenforID and capabilities of the client who created
1.139 +the schedule responsible for invoking this task.
1.140 +*/
1.141 +EXPORT_C const TSecurityInfo& CScheduledTask::SecurityInfo() const
1.142 + {
1.143 + return iSecurityInfo;
1.144 + }
1.145 +
1.146 +/**
1.147 +Is this task due?
1.148 +@internalComponent only used by server
1.149 +*/
1.150 +TBool CScheduledTask::Due() const
1.151 + {
1.152 + return iDue;
1.153 + }
1.154 +
1.155 +/**
1.156 +Decrement repeat counter
1.157 +@internalComponent only used by server
1.158 +*/
1.159 +void CScheduledTask::DecRepeat()
1.160 + {
1.161 + iInfo.iRepeat--;
1.162 + }
1.163 +
1.164 +/**
1.165 +Set due flag.
1.166 +@internalComponent only used by server
1.167 +*/
1.168 +void CScheduledTask::SetDue(TBool aDue)
1.169 + {
1.170 + iDue = aDue;
1.171 + }
1.172 +
1.173 +/**
1.174 +Mark task as being due.
1.175 +@param aValidUntil time this task will be valid until.
1.176 +This information will be passed to the registered executable,
1.177 +so they may check whether the task should still be executed.
1.178 +@internalComponent only used by server
1.179 +*/
1.180 +void CScheduledTask::OnDue(const TTsTime& aValidUntil)
1.181 + {
1.182 + iValidUntil = aValidUntil;
1.183 + iDue = ETrue;
1.184 + }
1.185 +
1.186 +/**
1.187 +Return flag that determines if task is transisent or persistent.
1.188 +@internalComponent only used by server
1.189 +*/
1.190 +TBool CScheduledTask::Persists() const
1.191 + {return iPersists;}
1.192 +
1.193 +/**
1.194 +Mark task as belonging to a persistent schedule.
1.195 +@internalComponent only used by server
1.196 +*/
1.197 +void CScheduledTask::SetPersists()
1.198 + {iPersists = ETrue;}
1.199 +
1.200 +/**
1.201 +externalize data to stream.
1.202 +@internalComponent only used by server
1.203 +*/
1.204 +void CScheduledTask::ExternalizeL(RWriteStream& aStream) const
1.205 + {
1.206 + aStream << *iData;
1.207 + aStream << iValidUntil;
1.208 + aStream << iInfo;
1.209 + aStream.WriteInt32L(iScheduleId);
1.210 + aStream.WriteInt32L(iScheduleType);
1.211 + aStream << iSecurityInfo;
1.212 + aStream.WriteInt32L(iPersists);
1.213 + }
1.214 +
1.215 +void CScheduledTask::InternalizeL(RReadStream& aStream)
1.216 + {
1.217 + iData = HBufC::NewL(aStream, KMaxTInt);
1.218 + aStream >> iValidUntil;
1.219 + aStream >> iInfo;
1.220 + iScheduleId = aStream.ReadInt32L();
1.221 + iScheduleType = static_cast<TScheduleType>(aStream.ReadInt32L());
1.222 + aStream >> iSecurityInfo;
1.223 + iPersists = aStream.ReadInt32L();;
1.224 + }
1.225 +
1.226 +/**
1.227 +Gets the schedulesID
1.228 +@internalComponent only used by server
1.229 +*/
1.230 +TInt CScheduledTask::ScheduleId() const
1.231 + {
1.232 + return iScheduleId;
1.233 + }
1.234 +
1.235 +/**
1.236 +Sets the schedules ID
1.237 +@internalComponent only used by server
1.238 +*/
1.239 +void CScheduledTask::SetScheduleId(TInt aScheduleId)
1.240 + {
1.241 + iScheduleId = aScheduleId;
1.242 + }
1.243 +
1.244 +
1.245 +// Streaming operators for TSecurityInfo
1.246 +RWriteStream& operator<<(RWriteStream& aWriteStream,
1.247 + const TSecurityInfo& aSecurityInfo)
1.248 + {
1.249 + //write security policy
1.250 + aWriteStream.WriteUint32L(aSecurityInfo.iSecureId);
1.251 + aWriteStream.WriteUint32L(aSecurityInfo.iVendorId);
1.252 + // write capabilities by looping through all available
1.253 + for (TUint jj = 0; jj < ECapability_Limit; ++jj)
1.254 + if(aSecurityInfo.iCaps.HasCapability((TCapability)jj))
1.255 + aWriteStream.WriteUint8L(jj);
1.256 + aWriteStream.WriteUint8L(ECapability_HardLimit); // terminate capabilities with hard limit
1.257 + return aWriteStream;
1.258 + }
1.259 +
1.260 +RReadStream& operator>>(RReadStream& aReadStream,
1.261 + TSecurityInfo& aSecurityInfo)
1.262 + {
1.263 +
1.264 + aSecurityInfo.iSecureId = aReadStream.ReadUint32L();
1.265 + aSecurityInfo.iVendorId = aReadStream.ReadUint32L();
1.266 + aSecurityInfo.iCaps.SetEmpty();
1.267 + TCapability cap = ECapability_None;
1.268 + aSecurityInfo.iCaps.AddCapability(cap);
1.269 + while (cap != ECapability_HardLimit )
1.270 + {
1.271 + aSecurityInfo.iCaps.AddCapability(cap);
1.272 + cap = (TCapability)aReadStream.ReadUint8L();
1.273 + }
1.274 + return aReadStream;
1.275 + }
1.276 +
1.277 +
1.278 +