You Are Here:

Community: Wiki

This page was last modified 13:31, 12 October 2008.

CS000991 - Editing a schedule using RScheduler

From Forum Nokia Wiki



ID CS000991 Creation date May 28, 2008
Platform S60 3rd Edition, FP1 Tested on devices Nokia N93
Category Symbian C++ Subcategory Files/Data


Keywords (APIs, classes, methods, functions): RScheduler, TSchedulerItemRef, TTaskSchedulerCondition, TTaskInfo, TTsTime, RProperty, RScheduler::Connect(), RScheduler::Register(), RScheduler::Close(), RScheduler::CreatePersistentSchedule(), RScheduler::ScheduleTask(), RScheduler::EditSchedule(), RScheduler::EnableSchedule(), RScheduler::DisableSchedule(), TTsTime::SetLocalTime(), RProperty::Define(), RProperty::Set(), RProperty::Delete()

Overview

This code snippet shows how to create, disable, enable, and edit a condition-based schedule using the class RScheduler. When schedules are created, they are enabled by default. By disabling a schedule the scheduled tasks are not executed even if they become due. The RScheduler methods EnableSchedule() and DisableSchedule() are used to enable/disable the example schedule. There are separate methods for time-based and condition-based schedules with different parameters for editing schedules. The condition-based EditSchedule() is used for editing the schedule in this example.

This snippet can be self-signed.

MMP file

The following libraries are required:

LIBRARY             schsvr.lib

Preconditions

ExampleTaskHandler.exe must be created before this code snippet can be executed. See CS000986 - Creating and registering a task handler with RScheduler.

Resource files

.rss

RESOURCE MENU_PANE r_schedulerexample_menu
    {
    items = 
        {
        //...
        MENU_ITEM {command = EEditExample;             txt = "EditExample";},
        //...
        MENU_ITEM {command = EAknSoftkeyExit;          txt = "Exit";}
        };
    }

.hrh

enum TSchedulerExampleIds
    {
   //...
    EEditExample,
    //...
    };

Header file

#ifndef __SCHEDULEREXAMPLEAPPUI_H__
#define __SCHEDULEREXAMPLEAPPUI_H__
 
#include <csch_cli.h> // RScheduler
#include <schinfo.h>  // TSchedulerItemRef, TTaskInfo... 
 
class CSchedulerExampleAppUi : public CAknAppUi
    {
    //...
public:   
    void HandleCommandL(TInt aCommand);
    //...
private:    
    void CreateConditionVariableL();
   
    void SetConditionVariableL(TInt aKeyValue); 
    
    void DeleteConditionVariableL();
    
    TInt EnableOrDisableSchedule(RScheduler& aScheduler, TInt aScheduleId, TBool aDoEnable);
    
    TInt CreateInitialConditionScheduleWithTaskL(
                                            TSchedulerItemRef& aSchedulerItem,
                                            RScheduler& aScheduler,
                                            TInt aKeyId, TInt aExpectedValue,
                                            const TTsTime& aDefaultRunTime
                                            );
 
 
 
    //...    
private:
 
    RScheduler iScheduler;
};
    
#endif // __SCHEDULEREXAMPLEAPPUI_H__


Source file

#include <e32property.h>
 
const TUid KExampleUid = TUid::Uid(0xE0060BBB); //UID3 from .mmp file
const TInt KExampleKey = 1;
 
void CSchedulerExampleAppUi::ConstructL()
    {
    //...
    User::LeaveIfError(iScheduler.Connect());
    
    _LIT(KExampleTaskHandlerExe, "ExampleTaskHandler.exe");
    TFileName exampleHandler(KExampleTaskHandlerExe);
        
    User::LeaveIfError(iScheduler.Register(exampleHandler, CActive::EPriorityStandard));    
    }
    
CSchedulerExampleAppUi::~CSchedulerExampleAppUi()
    {
 
    //...    
    iScheduler.Close(); 
    
    DeleteConditionVariableL(); 
    }    
 
void CSchedulerExampleAppUi::HandleCommandL(TInt aCommand)
  {
  TBuf<100> Text1; //first line of dialog text 
  TBuf<100> Text2; //second line of dialog text
      
  switch(aCommand)
    {
    case EEikCmdExit:
    case EAknSoftkeyExit:
      Exit();
      break;
//...
    case EEditExample:
      {
      TInt err(KErrNone);
                      
      CreateConditionVariableL();
      TSchedulerItemRef tempRef;
            
      TTsTime defaultTime;
      TTime time;
      time.HomeTime();
      time = time.operator+(TTimeIntervalMonths(1));
      defaultTime.SetLocalTime( time );
  
      err = CreateInitialConditionScheduleWithTaskL(tempRef, iScheduler, 
KExampleKey, 1, defaultTime );
      
      //disable the schedule
      err = EnableOrDisableSchedule(iScheduler, tempRef.iHandle, EFalse);
                
      //set condition variable to trigger the example task    
      SetConditionVariableL(1);
      
      //NOTE: nothing happens because the schedule is disabled!         
      //User::After(1000*1000*2);
 
      //set condition variable not to trigger the example task                      
      SetConditionVariableL(2);
        
      //enable the schedule again
      err = EnableOrDisableSchedule(iScheduler, tempRef.iHandle, ETrue);
            
      if(err == KErrNone)
        Text1.Append(_L("Schedule is enabled!"));      
            
      CArrayFixFlat<TTaskSchedulerCondition>* conditions = 
new (ELeave) CArrayFixFlat<TTaskSchedulerCondition>(1);        
                      
      CleanupStack::PushL(conditions);
      TTaskSchedulerCondition newCondition;
      newCondition.iCategory    = KExampleUid;
      newCondition.iKey         = KExampleKey;
      newCondition.iState       = 2;
      newCondition.iType        = TTaskSchedulerCondition::EEquals;
      conditions->AppendL(newCondition);
  
      //edit condition schedule to trigger the example task when 
      //condition variable equals to state 2
      err = iScheduler.EditSchedule(tempRef.iHandle, *conditions, defaultTime);
         
      if(err == KErrNone)
        Text2.Append(_L("Schedule is edited!"));
            
      CEikonEnv::Static()->InfoWinL(Text1, Text2);   
         
      //Task Scheduler launches the example task...      
            
      CleanupStack::PopAndDestroy(conditions);
      }
      break;
      
   default:
     //Panic(ESchedulerExampleUi);
     break;
     }
  }  
    
 
void CSchedulerExampleAppUi::CreateConditionVariableL()
  {
  TInt ret = RProperty::Define(KExampleUid, KExampleKey, RProperty::EInt);
  
  if (ret != KErrAlreadyExists)
    {      
    User::LeaveIfError(ret);
    }
  }
 
void CSchedulerExampleAppUi::SetConditionVariableL(TInt aKeyValue)              
  {  
  TInt ret = RProperty::Set(KExampleUid, KExampleKey, aKeyValue);
  
  User::LeaveIfError(ret);
  }
 
void CSchedulerExampleAppUi::DeleteConditionVariableL()
  {
  TInt ret = RProperty::Delete(KExampleUid, KExampleKey);
  
  if (ret != KErrNotFound)
    {
    User::LeaveIfError(ret);
    }
  }
 
TInt CSchedulerExampleAppUi::EnableOrDisableSchedule(
                                        RScheduler& aScheduler, 
                                        TInt aScheduleId, 
                                        TBool aDoEnable
                                        )
  {
  TInt ret(KErrNone);
  
  if(aDoEnable)
    {
    ret = aScheduler.EnableSchedule(aScheduleId);
    }
  else
    {
    ret = aScheduler.DisableSchedule(aScheduleId);
    }
  
  return ret;
  }
 
TInt CSchedulerExampleAppUi::CreateInitialConditionScheduleWithTaskL(
                       TSchedulerItemRef& aSchedulerItem,
                       RScheduler& aScheduler,
                       TInt aKeyId, TInt aTriggerValue,
                       const TTsTime& aDefaultRunTime
                    )
    {
    TInt ret(KErrNone);
    
    aSchedulerItem.iName = _L("Edit Schedule Example");
    
    CArrayFixFlat<TTaskSchedulerCondition>* conditions = 
new (ELeave) CArrayFixFlat<TTaskSchedulerCondition>(1);        
    CleanupStack::PushL(conditions);
    
    TTaskSchedulerCondition condition;
    condition.iCategory     = KExampleUid;
    condition.iKey          = aKeyId;
    condition.iState        = aTriggerValue;
    condition.iType         = TTaskSchedulerCondition::EEquals;
    conditions->AppendL(condition);
    
    ret = aScheduler.CreatePersistentSchedule(aSchedulerItem, *conditions, aDefaultRunTime);
    
    if (ret == KErrNone)
      {
      TTaskInfo taskInfo;
      taskInfo.iTaskId = 0;
      taskInfo.iName = _L("ExampleTask4");
      taskInfo.iPriority = 2;
      taskInfo.iRepeat = 0;
      HBufC* data = _L("ExampleData4").AllocLC();
        
      // schedule the example task
      ret = aScheduler.ScheduleTask(taskInfo, *data, aSchedulerItem.iHandle);
      CleanupStack::PopAndDestroy(); // data
      }
    else
      {
      //Creating persistent schedule failed, do something...    
      }
 
    CleanupStack::PopAndDestroy(conditions);
    
    return ret;
    }


Postconditions

The condition-based schedule with one example task has been created and the task execution is triggered using the Publish and Subscribe mechanism after the schedule is enabled and edited.

See also

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditFurlTechnocratiMagnoliaTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZdescriptionQSxEa0E20WikiE20javaE20symbianE5fosE20s60E20maemoE20cE2bE2bE20WikiE20HomeE20WikiE20HelpE20OverviewE20GlossaryE20CreateE20PageE20ProposeE20anE20ArticleE20SpotlightE20TopicE20E2dE20WE52TE20WidgetsE20ProgrammingE20E4canguageE20E2dE20SymbianE20CE2bE2bE20E2dE20OpenE20CE2fCE2bE2bE20E2dE20JavaE20E2dE20FlashE20E4citeE20E2dE20PythonE20WebE20TechnologiesE20E2dE20WE52TE20WidgetsE20E2dE20WidSetsE20ToolsE20andE20SE44KE20CodeE20E45E78amplesE20KnowledgeE20BaseE20TechnologyE20AreasE20SoftwareE20PlatformsE20E44evelopmentE20ProcessE20E3fE3fWikiE20ChineseE20E3fE3fE3fWikiE20JapaneseE20PortugueseE2fBrazilianE20E52ussianE20WhatE20linksE20hereE20UploadE20fileE20SpecialE20pagesE20PrintableE20versionE44ownloadE20asE20PE44FE20GoE20ToE20E2eE2eE2eX qdcZidentifierQSxhttpE3aE2fE2fwikiE2eforumE2enokiaE2ecomE2findeE78E2ephpE2fMMPE5ffileX qdcZpublisherQUxhttpE3aE2fE2fswE2enokiaE2ecomE2fidE2fc764fd1cE2d8b06E2d499aE2d9a6aE2d17c3903d5a65E2fforumE5fnokiaE5fcrawlerE5fagentX qdcZtitleQSxMMPE20fileE20E2dE20ForumE20NokiaE20WikiX qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfnTypeZCommunityContentQ qdcZtypeQUqfnTypeZE52esourceQ qdcZtypeQUqfnTypeZWebpageQ qdcZtypeQUqfnTypeZWikiContentQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qrssZdescriptionQSxEa0E20WikiE20javaE20symbianE5fosE20s60E20maemoE20cE2bE2bE20WikiE20HomeE20WikiE20HelpE20OverviewE20GlossaryE20CreateE20PageE20ProposeE20anE20ArticleE20SpotlightE20TopicE20E2dE20WE52TE20WidgetsE20ProgrammingE20E4canguageE20E2dE20SymbianE20CE2bE2bE20E2dE20OpenE20CE2fCE2bE2bE20E2dE20JavaE20E2dE20FlashE20E4citeE20E2dE20PythonE20WebE20TechnologiesE20E2dE20WE52TE20WidgetsE20E2dE20WidSetsE20ToolsE20andE20SE44KE20CodeE20E45E78amplesE20KnowledgeE20BaseE20TechnologyE20AreasE20SoftwareE20PlatformsE20E44evelopmentE20ProcessE20E3fE3fWikiE20ChineseE20E3fE3fE3fWikiE20JapaneseE20PortugueseE2fBrazilianE20E52ussianE20WhatE20linksE20hereE20UploadE20fileE20SpecialE20pagesE20PrintableE20versionE44ownloadE20asE20PE44FE20GoE20ToE20E2eE2eE2eX qfnZdistributionQUxhttpE3aE2fE2fwikiE2eforumE2enokiaE2ecomE2fX qfnZtypeQUqfnTypeZCommunityContentQ qfnZtypeQUqfnTypeZE52esourceQ qfnZtypeQUqfnTypeZWebpageQ qfnZtypeQUqfnTypeZWikiContentQ qfnZupdatedQDx2008E2d10E2d02X qfnZuserE5ftagQSxfileX qfnZuserE5ftagQSxlibpathX qfnZuserE5ftagQSxmmpX qfnZuserE5ftagQSxresourceX qmarsZdescriptionQSxEa0E20WikiE20javaE20symbianE5fosE20s60E20maemoE20cE2bE2bE20WikiE20HomeE20WikiE20HelpE20OverviewE20GlossaryE20CreateE20PageE20ProposeE20anE20ArticleE20SpotlightE20TopicE20E2dE20WE52TE20WidgetsE20ProgrammingE20E4canguageE20E2dE20SymbianE20CE2bE2bE20E2dE20OpenE20CE2fCE2bE2bE20E2dE20JavaE20E2dE20FlashE20E4citeE20E2dE20PythonE20WebE20TechnologiesE20E2dE20WE52TE20WidgetsE20E2dE20WidSetsE20ToolsE20andE20SE44KE20CodeE20E45E78amplesE20KnowledgeE20BaseE20TechnologyE20AreasE20SoftwareE20PlatformsE20E44evelopmentE20ProcessE20E3fE3fWikiE20ChineseE20E3fE3fE3fWikiE20JapaneseE20PortugueseE2fBrazilianE20E52ussianE20WhatE20linksE20hereE20UploadE20fileE20SpecialE20pagesE20PrintableE20versionE44ownloadE20asE20PE44FE20GoE20ToE20E2eE2eE2eX qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfnTypeZCommunityContentQ qrdfZtypeQUqfnTypeZE52esourceQ qrdfZtypeQUqfnTypeZWebpageQ qrdfZtypeQUqfnTypeZWikiContentQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ