1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericservices/taskscheduler/SCHSVR/SSCH_SES.CPP Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,837 @@
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 +// User includes
1.20 +#include "SSCH_STD.H"
1.21 +#include "CSCHCODE.H"
1.22 +#include "SCHCLI.H"
1.23 +#include "SchLogger.h"
1.24 +#include "SCHMAN.H"
1.25 +#include "SCHEDULE.H"
1.26 +#include <schtask.h>
1.27 +
1.28 +// Constants
1.29 +const TInt KSchedulerArrayGranularity = 1;
1.30 +_LIT(KSchedulerPanic, "Task Scheduler");
1.31 +
1.32 +void PanicClient(TInt aPanic, const RMessage2& aMessage)
1.33 +//
1.34 +// Toast the client
1.35 +//
1.36 + {
1.37 + //Note that panic also completes the message so don't complete anywhere else
1.38 + aMessage.Panic(KSchedulerPanic,aPanic);
1.39 + }
1.40 +
1.41 +CSchSession::CSchSession(CTaskScheduler& aScheduler)
1.42 +//
1.43 +// C'Tor - must pass client to CSession
1.44 +//
1.45 + : CSession2(),
1.46 + iTaskScheduler(&aScheduler),
1.47 + iClient(NULL)
1.48 + {
1.49 + }
1.50 +
1.51 +CSchSession::~CSchSession()
1.52 + {
1.53 + if (iClient)
1.54 + {
1.55 + iClient->DecUsers();
1.56 + if (!iClient->Users())
1.57 + {
1.58 + iClient->Remove();
1.59 + delete iClient;
1.60 + iClient = NULL;
1.61 + }
1.62 + }
1.63 + if(!iPendingNotification.IsNull())
1.64 + iPendingNotification.Complete(KErrCancel);
1.65 + }
1.66 +
1.67 +void CSchSession::ServiceError(const RMessage2& aMessage,TInt aError)
1.68 +//
1.69 +// Handle an error or leave from CMySession::ServiceL()
1.70 +// A bad descriptor error implies a badly programmed client, so panic it;
1.71 +// otherwise use the default handling (report the error to the client)
1.72 +//
1.73 + {
1.74 + if (aError==KErrBadDescriptor)
1.75 + PanicClient(EPanicBadDescriptor,aMessage);
1.76 + CSession2::ServiceError(aMessage,aError);
1.77 + }
1.78 +
1.79 +void CSchSession::ServiceL(const RMessage2& aMessage)
1.80 +//
1.81 +// Handle messages for this session.
1.82 +// all API functions are synchronous so complete here too
1.83 +//
1.84 + {
1.85 +
1.86 + iClientMessage = BSUL::CClientMessage::NewL(aMessage);
1.87 +
1.88 + //Validate the message
1.89 + TRAPD(error, iClientMessage->ValidateL());
1.90 +
1.91 + if(error == KErrNone)
1.92 + {
1.93 + TRAP(error, DoServiceL());
1.94 + }
1.95 +
1.96 + // don't complete message if we have paniced client (ie message is NULL)
1.97 + iClientMessage->CompleteRequestL(error);
1.98 +
1.99 + delete iClientMessage;
1.100 + iClientMessage = NULL;
1.101 + }
1.102 +
1.103 +void CSchSession::DoServiceL()
1.104 +//
1.105 +// Handle messages for this session.
1.106 +// all API functions are synchronous so complete here too
1.107 +//
1.108 + {
1.109 + switch (iClientMessage->Function())
1.110 + {
1.111 +#if defined (_DEBUG)
1.112 + case ESchDbgMarkHeap:
1.113 + __UHEAP_MARK;
1.114 + break;
1.115 + case ESchDbgCheckHeap:
1.116 + __UHEAP_CHECK(iClientMessage->GetIntL(0));
1.117 + break;
1.118 + case ESchDbgMarkEnd:
1.119 + {
1.120 + TInt count = iClientMessage->GetIntL(0);
1.121 +
1.122 + //Three allocations are made for this message so add 3 to count
1.123 + //CClientMessage::NewL
1.124 + //CIntParameter::NewL
1.125 + //RPointerArray::AppendL
1.126 + __UHEAP_MARKENDC(count + 3);
1.127 + }
1.128 + break;
1.129 + case ESchDbgFailNext:
1.130 + __UHEAP_FAILNEXT(iClientMessage->GetIntL(0));
1.131 + break;
1.132 + case ESchDbgResetHeap:
1.133 + __UHEAP_RESET;
1.134 + break;
1.135 + case ESchFaultServer:
1.136 + {
1.137 + // make sure we complete the message first before Killing this server
1.138 + iClientMessage->CompleteRequestL(KErrNone);
1.139 + RProcess().Kill(0);
1.140 + return;
1.141 + }
1.142 +#endif
1.143 + case ERegisterClient:
1.144 + RegisterClientL();
1.145 + break;
1.146 + case ECreateTimeSchedule:
1.147 + CreateTimeScheduleL();
1.148 + break;
1.149 + case ECreateConditionSchedule:
1.150 + CreateConditionScheduleL();
1.151 + break;
1.152 + case EScheduleTask:
1.153 + ScheduleTaskL();
1.154 + break;
1.155 + case EDeleteTask:
1.156 + DeleteTaskL();
1.157 + break;
1.158 + case EDeleteSchedule:
1.159 + {
1.160 + CSchedule* schedule = iTaskScheduler->FindL(iClientMessage->GetIntL(0));
1.161 + CheckPersistsInBackupL(*schedule);
1.162 + //check that user has permission to delete this schedule.
1.163 + schedule->CheckAccessAllowedL(iClientMessage->Message());
1.164 + iTaskScheduler->RemoveScheduleL(iClientMessage->GetIntL(0));
1.165 + break;
1.166 + }
1.167 + case EDisableSchedule:
1.168 + {
1.169 + CSchedule* schedule = iTaskScheduler->FindL(iClientMessage->GetIntL(0));
1.170 + CheckPersistsInBackupL(*schedule);
1.171 + //check that user has permission to disable this schedule.
1.172 + schedule->CheckAccessAllowedL(iClientMessage->Message());
1.173 + iTaskScheduler->DisableScheduleL(iClientMessage->GetIntL(0));
1.174 + break;
1.175 + }
1.176 + case EEnableSchedule:
1.177 + {
1.178 + CSchedule* schedule = iTaskScheduler->FindL(iClientMessage->GetIntL(0));
1.179 + CheckPersistsInBackupL(*schedule);
1.180 + //check that user has permission to enable this schedule.
1.181 + schedule->CheckAccessAllowedL(iClientMessage->Message());
1.182 + iTaskScheduler->EnableScheduleL(iClientMessage->GetIntL(0));
1.183 + break;
1.184 + }
1.185 + case EEditTimeSchedule:
1.186 + EditTimeScheduleL();
1.187 + break;
1.188 + case EEditConditionSchedule:
1.189 + EditConditionScheduleL();
1.190 + break;
1.191 + case EGetScheduleRefs:
1.192 + GetScheduleRefsL();
1.193 + break;
1.194 + case ECountSchedules:
1.195 + CountSchedulesL();
1.196 + break;
1.197 + case EGetScheduleInfo:
1.198 + GetScheduleInfoL();
1.199 + break;
1.200 + case EGetTimeScheduleData:
1.201 + GetTimeScheduleDataL();
1.202 + break;
1.203 + case EGetConditionScheduleData:
1.204 + GetConditionScheduleDataL();
1.205 + break;
1.206 + case EGetTaskData:
1.207 + GetTaskDataL();
1.208 + break;
1.209 + case EGetTaskRefs:
1.210 + GetTaskRefsL();
1.211 + break;
1.212 + case ECountTasks:
1.213 + CountTasksL();
1.214 + break;
1.215 + case EGetTask:
1.216 + GetTaskInfoL();
1.217 + break;
1.218 + case EGetSchedulerItemRefAndNextDueTime:
1.219 + GetScheduleItemRefAndDueTimeL();
1.220 + break;
1.221 + case EGetTaskDataSize:
1.222 + GetTaskDataSizeL();
1.223 + break;
1.224 + case EGetScheduleType:
1.225 + GetScheduleTypeL();
1.226 + break;
1.227 + default:
1.228 + User::Leave(EPanicIllegalFunction);
1.229 + break;
1.230 +
1.231 + }//switch
1.232 +
1.233 + }
1.234 +
1.235 +//private functions
1.236 +void CSchSession::RegisterClientL()
1.237 + {
1.238 + TFileName writeBuf;
1.239 +
1.240 + iClientMessage->ReadL(0,writeBuf);
1.241 +
1.242 + // should return existing client if there is one
1.243 + CClientProxy* client = iTaskScheduler->AddClientL(writeBuf, iClientMessage->GetIntL(1));
1.244 + client->IncUsers();
1.245 + if (iClient)
1.246 + {
1.247 + iClient->DecUsers();
1.248 + if (!iClient->Users())
1.249 + {
1.250 + LOGSTRING2("CSchSession::RegisterClientL - removing existing client %S", &iClient->ExecutorFileName());
1.251 + iClient->Remove();
1.252 + delete iClient;
1.253 + }
1.254 + }
1.255 + iClient = client;
1.256 + }
1.257 +
1.258 +void CSchSession::CreateTimeScheduleL()
1.259 + {
1.260 + // get settings
1.261 + TScheduleSettings2 settings;
1.262 + TPScheduleSettings pS(settings);
1.263 + iClientMessage->ReadL(0, pS);
1.264 +
1.265 + //WriteDeviceData needed to create persistent schedules
1.266 + if(settings.iPersists)
1.267 + {
1.268 + // backup or restore in progress, so don't allow functions that might write to store
1.269 + if (iTaskScheduler->BUROperationInProgress() != EBUROperationNoActivity)
1.270 + {
1.271 + User::Leave(KErrServerBusy);
1.272 + }
1.273 +
1.274 + CheckCapabilityL();
1.275 + }
1.276 +
1.277 + //Verify that the length of the condition list passed in is as expected
1.278 + if(iClientMessage->GetDesLengthL(1) !=
1.279 + (settings.iEntryCount * sizeof(TScheduleEntryInfo2)))
1.280 + {
1.281 + User::Leave(KErrBadDescriptor);
1.282 + }
1.283 +
1.284 + // get entries
1.285 + CArrayFixFlat<TScheduleEntryInfo2>* entries
1.286 + = new(ELeave) CArrayFixFlat<TScheduleEntryInfo2>(settings.iEntryCount);
1.287 + CleanupStack::PushL(entries);
1.288 + entries->ResizeL(settings.iEntryCount);
1.289 + TPtr8 entriesPtr(REINTERPRET_CAST(TUint8*,&(entries->At(0))), settings.iEntryCount * sizeof(TScheduleEntryInfo2));
1.290 + iClientMessage->ReadL(1, entriesPtr);
1.291 +
1.292 + // create schedule
1.293 + const TInt handle = iTaskScheduler->GenerateId();
1.294 + if (handle == KErrOverflow)
1.295 + User::Leave(KErrOverflow);
1.296 +
1.297 + // write back ID
1.298 + TPInt id(handle);
1.299 + iClientMessage->WriteL(2,id);
1.300 +
1.301 + // get security info
1.302 + TSecurityInfo securityInfo(iClientMessage->Message());
1.303 +
1.304 + // Create schedule and add to scheduler
1.305 + CSchedule* newschedule = CSchedule::NewLC(handle,
1.306 + settings.iName,
1.307 + settings.iPersists,
1.308 + *entries,
1.309 + securityInfo);
1.310 + iTaskScheduler->AddScheduleL(*newschedule);
1.311 + CleanupStack::Pop(newschedule);
1.312 + CleanupStack::PopAndDestroy(entries);
1.313 + }
1.314 +
1.315 +void CSchSession::CreateConditionScheduleL()
1.316 + {
1.317 + // get settings
1.318 + TScheduleSettings2 settings;
1.319 + TPScheduleSettings pS(settings);
1.320 + iClientMessage->ReadL(0, pS);
1.321 +
1.322 + //WriteDeviceData needed to create persistent schedules
1.323 + if(settings.iPersists)
1.324 + {
1.325 + // backup or restore in progress, so don't allow functions that might write to store
1.326 + if (iTaskScheduler->BUROperationInProgress() != EBUROperationNoActivity)
1.327 + {
1.328 + User::Leave(KErrServerBusy);
1.329 + }
1.330 +
1.331 + CheckCapabilityL();
1.332 + }
1.333 +
1.334 + //Verify that the length of the condition list passed in is as expected
1.335 + if(iClientMessage->GetDesLengthL(1) !=
1.336 + (settings.iEntryCount * sizeof(TTaskSchedulerCondition)))
1.337 + {
1.338 + User::Leave(KErrBadDescriptor);
1.339 + }
1.340 +
1.341 + // get entries
1.342 + CArrayFixFlat<TTaskSchedulerCondition>* entries
1.343 + = new(ELeave) CArrayFixFlat<TTaskSchedulerCondition>(settings.iEntryCount);
1.344 + CleanupStack::PushL(entries);
1.345 + entries->ResizeL(settings.iEntryCount);
1.346 + TPtr8 entriesPtr(REINTERPRET_CAST(TUint8*,&(entries->At(0))), settings.iEntryCount * sizeof(TTaskSchedulerCondition));
1.347 + iClientMessage->ReadL(1, entriesPtr);
1.348 +
1.349 + // get time
1.350 + TTsTime defaultRunTime;
1.351 + TPckg<TTsTime> pTime(defaultRunTime);
1.352 + iClientMessage->ReadL(2, pTime);
1.353 +
1.354 + // create schedule
1.355 + const TInt handle = iTaskScheduler->GenerateId();
1.356 + if (handle == KErrOverflow)
1.357 + User::Leave(KErrOverflow);
1.358 +
1.359 + // write back ID
1.360 + TPInt id(handle);
1.361 + iClientMessage->WriteL(3,id);
1.362 +
1.363 + // get security info
1.364 + TSecurityInfo securityInfo(iClientMessage->Message());
1.365 +
1.366 + // Create schedule and add to scheduler
1.367 + CSchedule* newschedule
1.368 + = CSchedule::NewLC(handle,
1.369 + settings.iName,
1.370 + settings.iPersists,
1.371 + *entries,
1.372 + defaultRunTime,
1.373 + securityInfo);
1.374 + iTaskScheduler->AddScheduleL(*newschedule);
1.375 + CleanupStack::Pop(newschedule);
1.376 + CleanupStack::PopAndDestroy(entries);
1.377 + }
1.378 +
1.379 +void CSchSession::EditTimeScheduleL()
1.380 + {
1.381 + CSchedule* schedule = iTaskScheduler->FindL(iClientMessage->GetIntL(1));
1.382 +
1.383 + CheckPersistsInBackupL(*schedule);
1.384 + //check that user has permission to edit this schedule.
1.385 + schedule->CheckAccessAllowedL(iClientMessage->Message());
1.386 +
1.387 + //check that this is a time schedule!
1.388 + if(schedule->Type() != ETimeSchedule)
1.389 + User::Leave(KErrArgument);
1.390 +
1.391 + // Get entry count
1.392 + const TInt count = iClientMessage->GetIntL(0);
1.393 +
1.394 + //Verify that the length of the condition list passed in is as expected
1.395 + if(iClientMessage->GetDesLengthL(2) != (count * sizeof(TScheduleEntryInfo2)))
1.396 + {
1.397 + User::Leave(KErrBadDescriptor);
1.398 + }
1.399 +
1.400 + // Get new entry list
1.401 + CArrayFixFlat<TScheduleEntryInfo2>* entries
1.402 + = new(ELeave) CArrayFixFlat<TScheduleEntryInfo2> (KSchedulerArrayGranularity);
1.403 + CleanupStack::PushL(entries);
1.404 + entries->ResizeL(count);
1.405 + TPtr8 entriesPtr(REINTERPRET_CAST(TUint8*, &(entries->At(0))), count*sizeof(TScheduleEntryInfo2));
1.406 +
1.407 + iClientMessage->ReadL(2, entriesPtr);
1.408 +
1.409 + // Give it to scheduler along with schedule id
1.410 + iTaskScheduler->EditScheduleL(iClientMessage->GetIntL(1), *entries);
1.411 + CleanupStack::PopAndDestroy(entries);
1.412 + }
1.413 +
1.414 +void CSchSession::EditConditionScheduleL()
1.415 + {
1.416 + CSchedule* schedule = iTaskScheduler->FindL(iClientMessage->GetIntL(1));
1.417 +
1.418 + CheckPersistsInBackupL(*schedule);
1.419 + //check that user has permission to edit this schedule.
1.420 + schedule->CheckAccessAllowedL(iClientMessage->Message());
1.421 +
1.422 + //check that this is a condition schedule!
1.423 + if(schedule->Type() != EConditionSchedule)
1.424 + User::Leave(KErrArgument);
1.425 +
1.426 + // Get entry count
1.427 + const TInt count = iClientMessage->GetIntL(0);
1.428 +
1.429 + //Verify that the length of the condition list passed in is as expected
1.430 + if(iClientMessage->GetDesLengthL(2) != (count * sizeof(TTaskSchedulerCondition)))
1.431 + {
1.432 + User::Leave(KErrBadDescriptor);
1.433 + }
1.434 +
1.435 + // Get new entry list
1.436 + CArrayFixFlat<TTaskSchedulerCondition>* entries
1.437 + = new(ELeave) CArrayFixFlat<TTaskSchedulerCondition> (KSchedulerArrayGranularity);
1.438 + CleanupStack::PushL(entries);
1.439 + entries->ResizeL(count);
1.440 + TPtr8 entriesPtr(REINTERPRET_CAST(TUint8*, &(entries->At(0))), count*sizeof(TTaskSchedulerCondition));
1.441 + iClientMessage->ReadL(2, entriesPtr);
1.442 +
1.443 + // get time
1.444 + TTsTime defaultRunTime;
1.445 + TPckg<TTsTime> pTime(defaultRunTime);
1.446 + iClientMessage->ReadL(3, pTime);
1.447 +
1.448 + // Give it to scheduler along with schedule id
1.449 + iTaskScheduler->EditScheduleL(iClientMessage->GetIntL(1), *entries, defaultRunTime);
1.450 + CleanupStack::PopAndDestroy(entries);
1.451 + }
1.452 +
1.453 +void CSchSession::ScheduleTaskL()
1.454 + {
1.455 + // If client is registered, it is allowed to schedule tasks
1.456 + if(iClient != NULL)
1.457 + {
1.458 + TTaskInfo taskInfo;
1.459 + TPTaskInfo pI(taskInfo);
1.460 + iClientMessage->ReadL(0, pI);
1.461 +
1.462 + CSchedule* schedule = iTaskScheduler->FindL(iClientMessage->GetIntL(1));
1.463 +
1.464 + CheckPersistsInBackupL(*schedule);
1.465 +
1.466 + //check that user has permission to schedule a task using this schedule.
1.467 + schedule->CheckAccessAllowedL(iClientMessage->Message());
1.468 +
1.469 + taskInfo.iTaskId = schedule->GenerateTaskId();
1.470 +
1.471 + if (taskInfo.iTaskId == KErrOverflow)
1.472 + {
1.473 + User::Leave(KErrOverflow);
1.474 + }
1.475 + // panic client if this is a condition schedule and client is asking for
1.476 + // repeats. This doesnt make sense.
1.477 + if (schedule->Type() == EConditionSchedule && taskInfo.iRepeat != 0)
1.478 + User::Leave(KErrArgument);
1.479 +
1.480 + // Create a new scheduled task with associated task data
1.481 + TInt len = iClientMessage->GetDesLengthL(3);
1.482 + HBufC* taskdata = HBufC::NewLC(len);
1.483 +
1.484 + TPtr pData(taskdata->Des());
1.485 + iClientMessage->ReadL(3, pData);
1.486 +
1.487 + CScheduledTask* newTask = new(ELeave) CScheduledTask(taskInfo,
1.488 + taskdata,
1.489 + schedule->Type(),
1.490 + schedule->SecurityInfo());
1.491 + CleanupStack::Pop(taskdata); //taskdata now owned by newTask
1.492 + CleanupStack::PushL(newTask);
1.493 + // Have to store the associated task, so that in the case where the
1.494 + // tasks need to be restored from a backup, we can ensure that the
1.495 + // task is associated with the correct schedule.
1.496 + newTask->SetScheduleId(schedule->Id());
1.497 +
1.498 + //If the schedule that the task is associated with is persistent then set the flag
1.499 + if(schedule->Persists())
1.500 + {
1.501 + newTask->SetPersists();
1.502 + }
1.503 + LOGSTRING("CSchSession::ScheduleTaskL - writing back task id to client");
1.504 + TPInt id(taskInfo.iTaskId);
1.505 + iClientMessage->WriteL(2,id);
1.506 +
1.507 + TScheduledTask* task = new(ELeave) TScheduledTask(*newTask,*iClient);
1.508 +
1.509 + // Now that task has been created sucessfully, we can add newTask to Client
1.510 + iClient->AddTask(*newTask); // task info is owned by client: schedule just keeps a reference
1.511 + CleanupStack::Pop(newTask);
1.512 +
1.513 + schedule->AddTask(*task); //add new task - its now owned by schedule
1.514 +
1.515 + LOGSTRING("CSchSession::ScheduleTaskL - scheduling task with task scheduler");
1.516 + // If this leaves we need to still remove task from client and schedule.
1.517 + // No easy way to do this via CleanupStack
1.518 + TRAPD(err, iTaskScheduler->ScheduleTaskL(*schedule, *iClient));
1.519 + if(err)
1.520 + {
1.521 + schedule->RemoveTask(task);
1.522 + iClient->RemoveTask(newTask);
1.523 + User::Leave(err);
1.524 + }
1.525 + }
1.526 + else
1.527 + //Client hasnt been registered so it isn't allowed to schedule task, panic client
1.528 + {
1.529 + iClientMessage->PanicClient(KSchedulerPanic,EPanicNotRegistered);
1.530 + }
1.531 + }
1.532 +
1.533 +void CSchSession::DeleteTaskL()
1.534 + {
1.535 + const TInt taskId = iClientMessage->GetIntL(0);
1.536 +
1.537 + const TInt scheduleId = (taskId/KScheduleIdDifferential)*KScheduleIdDifferential;
1.538 +
1.539 + //check that user has permission to delete a task using this schedule.
1.540 + CSchedule* schedule = iTaskScheduler->FindL(scheduleId);
1.541 + CheckPersistsInBackupL(*schedule);
1.542 + schedule->CheckAccessAllowedL(iClientMessage->Message());
1.543 +
1.544 + iTaskScheduler->DeleteTaskL(scheduleId, taskId);
1.545 + }
1.546 +
1.547 +//retrieval functions
1.548 +void CSchSession::CountSchedulesL()
1.549 + {
1.550 + TScheduleFilter filter = STATIC_CAST(TScheduleFilter, iClientMessage->GetIntL(1));
1.551 + //GetScheduleRefs filters on clients schedule permssion as well.
1.552 + TInt count = iTaskScheduler->GetScheduleRefsL(NULL,filter, iClientMessage->Message());
1.553 + TPInt pCount(count);
1.554 + iClientMessage->WriteL(0,pCount);
1.555 + }
1.556 +
1.557 +void CSchSession::GetScheduleRefsL()
1.558 + {
1.559 + //client calls CountSchedules() first to get expected count. still
1.560 + //need to check it's valid though...
1.561 +
1.562 + const TInt expectedCount = iClientMessage->GetIntL(0);
1.563 + TScheduleFilter filter = STATIC_CAST(TScheduleFilter, iClientMessage->GetIntL(1));
1.564 +
1.565 + CArrayFixFlat<TSchedulerItemRef>* refArray
1.566 + = new(ELeave) CArrayFixFlat<TSchedulerItemRef>(KSchedulerArrayGranularity);
1.567 + CleanupStack::PushL(refArray);
1.568 +
1.569 + //GetScheduleRefs filters on clients schedule permssion as well.
1.570 + TInt count = iTaskScheduler->GetScheduleRefsL(refArray, filter, iClientMessage->Message());
1.571 + if ((expectedCount<count) || (count == 0))
1.572 + User::Leave(KErrArgument);
1.573 +
1.574 + TPtrC8 pS(REINTERPRET_CAST(TUint8*, &refArray->At(0)),sizeof(TSchedulerItemRef)*expectedCount);
1.575 + iClientMessage->WriteL(2, pS);
1.576 + CleanupStack::PopAndDestroy();//info array
1.577 + }
1.578 +
1.579 +void CSchSession::GetTimeScheduleDataL()
1.580 + {
1.581 + //client input:handle at info at aMessage.Int0()
1.582 + //info at aMessage.Ptr1()
1.583 + //info contains: exepcted entry count
1.584 + //scheduler output: entries at aM.Ptr2()
1.585 + TInt handle = iClientMessage->GetIntL(0);
1.586 +
1.587 + TScheduleInfo info;
1.588 + TPScheduleInfo pS(info);
1.589 + iClientMessage->ReadL(1, pS);
1.590 +
1.591 + CSchedule* schedule = iTaskScheduler->FindL(handle);
1.592 +
1.593 + //check that user has permission to get this schedules info.
1.594 + schedule->CheckAccessAllowedL(iClientMessage->Message());
1.595 +
1.596 + if (schedule->Type() != ETimeSchedule)
1.597 + User::Leave(KErrArgument); //calling wrong API
1.598 +
1.599 + CArrayFixFlat<TScheduleEntryInfo2>* entries
1.600 + = new(ELeave) CArrayFixFlat<TScheduleEntryInfo2> (KSchedulerArrayGranularity);
1.601 + CleanupStack::PushL(entries);
1.602 + schedule->EntriesL(*entries);
1.603 + if ((entries->Count())!=info.iEntryCount)
1.604 + User::Leave(KErrArgument);
1.605 + //write entries
1.606 + TPtrC8 pE(REINTERPRET_CAST(TUint8*, &entries->At(0)),sizeof(TScheduleEntryInfo2)*info.iEntryCount);
1.607 + iClientMessage->WriteL(2, pE);
1.608 +
1.609 + CleanupStack::PopAndDestroy(entries);//entry array
1.610 + }
1.611 +
1.612 +void CSchSession::GetConditionScheduleDataL()
1.613 + {
1.614 + //client input:handle at info at aMessage.Int0()
1.615 + //info at aMessage.Ptr1()
1.616 + //info contains: exepcted entry count
1.617 + //scheduler output: entries at aM.Ptr2()
1.618 + TInt handle = iClientMessage->GetIntL(0);
1.619 +
1.620 + TScheduleInfo info;
1.621 + TPScheduleInfo pS(info);
1.622 + iClientMessage->ReadL(1, pS);
1.623 +
1.624 + CSchedule* schedule = iTaskScheduler->FindL(handle);
1.625 +
1.626 + //check that user has permission to get this schedules info.
1.627 + schedule->CheckAccessAllowedL(iClientMessage->Message());
1.628 +
1.629 + if (schedule->Type() != EConditionSchedule)
1.630 + User::Leave(KErrArgument); //calling wrong API
1.631 +
1.632 + CArrayFixFlat<TTaskSchedulerCondition>* conditions
1.633 + = new(ELeave) CArrayFixFlat<TTaskSchedulerCondition> (KSchedulerArrayGranularity);
1.634 + CleanupStack::PushL(conditions);
1.635 + schedule->ConditionsL(*conditions);
1.636 + if ((conditions->Count())!=info.iEntryCount)
1.637 + User::Leave(KErrArgument);
1.638 + //write entries
1.639 + TPtrC8 pE(REINTERPRET_CAST(TUint8*, &conditions->At(0)),sizeof(TTaskSchedulerCondition)*info.iEntryCount);
1.640 + iClientMessage->WriteL(2, pE);
1.641 +
1.642 + //write time
1.643 + TTsTime defaultTime(schedule->DefaultRunTimeL());
1.644 + TPBTime pDefaultTime(defaultTime);
1.645 + iClientMessage->WriteL(3, pDefaultTime);
1.646 +
1.647 + CleanupStack::PopAndDestroy(conditions);//condition array
1.648 + }
1.649 +
1.650 +void CSchSession::GetScheduleTypeL()
1.651 + {
1.652 + TScheduleType type;
1.653 + TInt handle = iClientMessage->GetIntL(0);
1.654 + CSchedule* schedule = iTaskScheduler->FindL(handle);
1.655 +
1.656 + //check that user has permission to get this schedules info.
1.657 + schedule->CheckAccessAllowedL(iClientMessage->Message());
1.658 +
1.659 + type = schedule->Type();
1.660 + TPInt pType(type);
1.661 + iClientMessage->WriteL(1,pType);
1.662 + }
1.663 +
1.664 +void CSchSession::GetTaskDataL()
1.665 + {//client input:handle at info at aMessage.Int0()
1.666 + //info at aMessage.Ptr1()
1.667 + //info contains: exepcted entry count, expected task count
1.668 + //scheduler output: tasks at aM.Ptr2()
1.669 + TInt handle = iClientMessage->GetIntL(0);
1.670 +
1.671 + TScheduleInfo info;
1.672 + TPScheduleInfo pS(info);
1.673 + iClientMessage->ReadL(1, pS);
1.674 +
1.675 + CSchedule* schedule = iTaskScheduler->FindL(handle);
1.676 +
1.677 + //check that user has permission to get this task info (based on owning
1.678 + // schedules info).
1.679 + schedule->CheckAccessAllowedL(iClientMessage->Message());
1.680 +
1.681 + CArrayFixFlat<TTaskInfo>* tasks
1.682 + = new(ELeave) CArrayFixFlat<TTaskInfo> (KSchedulerArrayGranularity);
1.683 + CleanupStack::PushL(tasks);
1.684 + schedule->TasksL(*tasks);
1.685 + if ((tasks->Count())!=info.iTaskCount)
1.686 + User::Leave(KErrArgument);
1.687 + //write tasks if there are any
1.688 + if (info.iTaskCount>0)
1.689 + {
1.690 + TPtrC8 pT(REINTERPRET_CAST(TUint8*, &tasks->At(0)),sizeof(TTaskInfo)*info.iTaskCount);
1.691 + iClientMessage->WriteL(2, pT);
1.692 + }
1.693 + CleanupStack::PopAndDestroy(tasks);//task array
1.694 + }
1.695 +
1.696 +void CSchSession::GetScheduleInfoL()
1.697 + {
1.698 + CSchedule* schedule = iTaskScheduler->FindL(iClientMessage->GetIntL(0));
1.699 +
1.700 + //check that user has permission to get this schedules info.
1.701 + schedule->CheckAccessAllowedL(iClientMessage->Message());
1.702 +
1.703 + TScheduleInfo info;
1.704 + if (schedule->Type() == ETimeSchedule)
1.705 + schedule->GetInfo(info, EFalse);
1.706 + else
1.707 + schedule->GetInfo(info, ETrue);
1.708 +
1.709 + TPBScheduleInfo pInfo(info);
1.710 + iClientMessage->WriteL(1, pInfo);
1.711 + TTsTime dueTime(schedule->DueTime());
1.712 + TPBTime pDueTime(dueTime);
1.713 + iClientMessage->WriteL(2, pDueTime);
1.714 + }
1.715 +
1.716 +void CSchSession::GetTaskRefsL()
1.717 + {
1.718 + //taskrefs for all,
1.719 + //or just the ones I scheduled,
1.720 + //or just the pending ones,
1.721 + //or just the pending ones I scheduled
1.722 +
1.723 + TInt expectedCount = iClientMessage->GetIntL(0);
1.724 + TScheduleFilter sFilter = STATIC_CAST(TScheduleFilter, iClientMessage->GetIntL(1));
1.725 + TTaskFilter tFilter = STATIC_CAST(TTaskFilter, iClientMessage->GetIntL(2));
1.726 + CArrayFixFlat<TSchedulerItemRef>* refs
1.727 + = new (ELeave) CArrayFixFlat<TSchedulerItemRef> (KSchedulerArrayGranularity);
1.728 + CleanupStack::PushL(refs);
1.729 +
1.730 + //GetTaskRefs filters on clients schedule permssion as well.
1.731 + TInt actualCount = iTaskScheduler->GetTaskRefsL(refs, sFilter, tFilter,iClient, iClientMessage->Message());
1.732 +
1.733 + // Must find enough tasks.
1.734 + if((actualCount != expectedCount) || (refs->Count() == 0))
1.735 + User::Leave(KErrArgument);
1.736 +
1.737 + // Write array back to client
1.738 + TPtrC8 pR(REINTERPRET_CAST(TUint8*,&refs->At(0)),sizeof(TSchedulerItemRef)*expectedCount);
1.739 + iClientMessage->WriteL(3, pR);
1.740 + CleanupStack::PopAndDestroy();//refs
1.741 + }
1.742 +
1.743 +void CSchSession::CountTasksL()
1.744 + {
1.745 + //count either all of 'em or just mine
1.746 +
1.747 + TScheduleFilter sFilter = STATIC_CAST(TScheduleFilter, iClientMessage->GetIntL(1));
1.748 + TTaskFilter tFilter = STATIC_CAST(TTaskFilter, iClientMessage->GetIntL(2));
1.749 +
1.750 + //GetTaskRefs filters on clients schedule permssion as well.
1.751 + TInt count = iTaskScheduler->GetTaskRefsL(NULL, sFilter, tFilter,iClient, iClientMessage->Message());
1.752 +
1.753 + TPInt pCount(count);
1.754 + iClientMessage->WriteL(0,pCount);
1.755 + }
1.756 +
1.757 +void CSchSession::GetTaskInfoL()
1.758 + {
1.759 + // Get task
1.760 + TInt taskId = iClientMessage->GetIntL(0);
1.761 + TInt scheduleId = (taskId/KScheduleIdDifferential)*KScheduleIdDifferential;
1.762 + CSchedule* schedule = iTaskScheduler->FindL(scheduleId);
1.763 +
1.764 + //check that user has permission to get this task info (based on owning
1.765 + //schedules info).
1.766 + schedule->CheckAccessAllowedL(iClientMessage->Message());
1.767 +
1.768 + TScheduledTask* task = schedule->Task(taskId);
1.769 + if (!task)
1.770 + User::Leave(KErrNotFound);
1.771 +
1.772 + TPBTaskInfo pI(task->Info());
1.773 +
1.774 + iClientMessage->WriteL(1, pI);//write info
1.775 +
1.776 + // If there isn't enough room to hold the task data in the client buffer then
1.777 + // indicate by returning KErrArgument
1.778 + TInt clientBufferSize = iClientMessage->GetIntL(2);
1.779 + if (clientBufferSize < task->Data().Length())
1.780 + User::Leave(KErrArgument);
1.781 + iClientMessage->WriteL(3, task->Data());
1.782 + }
1.783 +
1.784 +void CSchSession::GetScheduleItemRefAndDueTimeL()
1.785 + {
1.786 + // Get CSchedule object
1.787 + TInt taskId = iClientMessage->GetIntL(0);
1.788 + TInt scheduleId = (taskId/KScheduleIdDifferential)*KScheduleIdDifferential;
1.789 + CSchedule* schedule = iTaskScheduler->FindL(scheduleId);
1.790 +
1.791 + //check that user has permission to get this schedules info.
1.792 + schedule->CheckAccessAllowedL(iClientMessage->Message());
1.793 +
1.794 + TSchedulerItemRef ref;
1.795 + ref.iHandle = schedule->Id();
1.796 + ref.iName = schedule->Name();
1.797 +
1.798 + TPBSchedulerItemRef pRef(ref);
1.799 + iClientMessage->WriteL(1, pRef);
1.800 +
1.801 + TTsTime dueTime(schedule->DueTime());
1.802 + TPBTime pDueTime(dueTime);
1.803 + iClientMessage->WriteL(2, pDueTime);
1.804 + }
1.805 +
1.806 +void CSchSession::GetTaskDataSizeL()
1.807 + {
1.808 + TInt taskId = iClientMessage->GetIntL(0);
1.809 + TInt scheduleId = (taskId/KScheduleIdDifferential)*KScheduleIdDifferential;
1.810 + CSchedule* schedule = iTaskScheduler->FindL(scheduleId);
1.811 +
1.812 + //check that user has permission to get this task info (based on owning
1.813 + //schedules info).
1.814 + schedule->CheckAccessAllowedL(iClientMessage->Message());
1.815 +
1.816 + TScheduledTask* task = schedule->Task(taskId);
1.817 + if (!task)
1.818 + User::Leave(KErrNotFound);
1.819 +
1.820 + TInt size = task->Data().Length();
1.821 + TPInt pSize(size);
1.822 + iClientMessage->WriteL(1,pSize);
1.823 + }
1.824 +
1.825 +void CSchSession::CheckCapabilityL()
1.826 + {
1.827 + if( !( iClientMessage->Message().HasCapability(ECapabilityWriteDeviceData)
1.828 + || (PlatSec::ConfigSetting(PlatSec::EPlatSecEnforcement)==0 ))) // Enforcement off
1.829 + User::Leave(KErrPermissionDenied);
1.830 + }
1.831 +
1.832 +void CSchSession::CheckPersistsInBackupL(const CSchedule& aSchedule)
1.833 + {
1.834 + // backup or restore in progress, so don't allow functions that might write to store
1.835 + if ((iTaskScheduler->BUROperationInProgress() != EBUROperationNoActivity) && (aSchedule.Persists()))
1.836 + {
1.837 + User::Leave(KErrServerBusy);
1.838 + }
1.839 + }
1.840 +