You Are Here:

Community: Wiki

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

CS000990 - Getting schedule and task count using RScheduler

From Forum Nokia Wiki



ID CS000990 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, TScheduleEntryInfo2, TTaskSchedulerCondition, TTaskInfo, TTsTime, TScheduleState2, RScheduler::Connect(), RScheduler::Register(), RScheduler::Close(), RScheduler::GetScheduleRefsL(), RScheduler::GetScheduleL()

Overview

This code snippet implements three simple helper methods to get a count of schedules, scheduled condition-based tasks, and scheduled time-based tasks. The RScheduler method GetScheduleRefsL() is used to get the count of schedules. The filter parameter of this method can be used to include all schedules (EAllSchedules) or only pending (EPendingSchedules) schedules to count.

The RScheduler method GetScheduleL() is used to get task count of the schedule by a given ID. This example implements separate methods for time-based and condition-based schedules. All these helper methods return -1 in error situations.

This snippet can be self-signed.

MMP file

The following libraries are required:

LIBRARY             schsvr.lib

Preconditions

ExampleTaskHandler.exe must be created and time-based and condition-based schedules with example tasks must be scheduled before this code snippet can be executed. See code snippets CS000986 - Creating and registering a task handler with RScheduler, CS000987 - Creating persistent and transient schedules with RScheduler, and CS000988 - Creating a condition-based schedule with RScheduler for more information.

Resource files

.rss

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

.hrh

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

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:        
    TInt GetConditionBasedScheduleTaskCountL(RScheduler& aScheduler, 
                                             TInt aScheduleId, 
                                             TInt& aTaskCount);   
    
    TInt GetTimeBasedScheduleTaskCountL(RScheduler& aScheduler, 
                                        TInt aScheduleId, 
                                        TInt& aTaskCount);    
    
    TInt GetScheduleCountL(TScheduleFilter aFilter, 
                            RScheduler& aScheduler, 
                            TInt& aScheduleCount);
    //...    
private:
 
    RScheduler iScheduler;
    
    TSchedulerItemRef iPersistentScheduleHandle;
    TSchedulerItemRef iConditionScheduleHandle;    
    };
    
#endif // __SCHEDULEREXAMPLEAPPUI_H__


Source file

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(); 
    }    
 
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 EGetCountExample:
      {
      TInt err(KErrNone);          
      TInt scheduleCount=-1;
      TInt timeBasedScheduleTaskCount=-1;
      TInt conditionBasedScheduleTaskCount=-1;
                      
      err = GetScheduleCountL(EAllSchedules, iScheduler, scheduleCount);
                                 
      err = GetTimeBasedScheduleTaskCountL(iScheduler, 
    iPersistentScheduleHandle.iHandle, timeBasedScheduleTaskCount );
            
      err = GetConditionBasedScheduleTaskCountL(iScheduler,
 iConditionScheduleHandle.iHandle, conditionBasedScheduleTaskCount );
    
      Text1.Append(_L("ScheduleCount:"));
      Text1.AppendNum(scheduleCount);
                    
      Text2.Append(_L("TimeBasedScheduleTaskCount:"));
      Text2.AppendNum(timeBasedScheduleTaskCount);
      Text2.Append(_L("\nConditionBasedScheduleTaskCount:"));
      Text2.AppendNum(conditionBasedScheduleTaskCount);
              
      CEikonEnv::Static()->InfoWinL(Text1, Text2);
      }
      break;
      
   default:
     //Panic(ESchedulerExampleUi);
     break;
     }
  }  
    
 
TInt CSchedulerExampleAppUi::GetConditionBasedScheduleTaskCountL(RScheduler& aScheduler,
                               TInt aScheduleId, 
                               TInt& aTaskCount)  
  {
  TInt ret(KErrNone);
  
  CArrayFixFlat<TTaskInfo>* tasks = 
new (ELeave) CArrayFixFlat<TTaskInfo>(1);
  CleanupStack::PushL(tasks);
 
  TTsTime time;
  TScheduleState2 state;
   CArrayFixFlat<TTaskSchedulerCondition>* conditions = 
new (ELeave) CArrayFixFlat<TTaskSchedulerCondition>(1);        
  CleanupStack::PushL(conditions);
    
  tasks->Reset();
  ret = aScheduler.GetScheduleL(aScheduleId, 
                  state, 
                 *conditions, 
                 time,
                *tasks);
  CleanupStack::PopAndDestroy(conditions);
  
  if(ret == KErrNone)
    aTaskCount = tasks->Count();
  else
    aTaskCount = -1;
 
  CleanupStack::PopAndDestroy(tasks);
  
  return ret;
  }
 
 
TInt CSchedulerExampleAppUi::GetTimeBasedScheduleTaskCountL(RScheduler& aScheduler, 
                               TInt aScheduleId, 
                               TInt& aTaskCount)  
  {
  TInt ret(KErrNone);
 
  CArrayFixFlat<TTaskInfo>* tasks = new (ELeave) CArrayFixFlat<TTaskInfo>(1);
  CleanupStack::PushL(tasks);
  
  TTsTime time;
  TScheduleState2 state;
  CArrayFixFlat<TScheduleEntryInfo2>* entries = 
new (ELeave) CArrayFixFlat<TScheduleEntryInfo2>(1);
  CleanupStack::PushL(entries);
    
  tasks->Reset();
  ret = aScheduler.GetScheduleL(aScheduleId, 
                  state, 
                  *entries, 
                  *tasks, 
                  time);
  
  CleanupStack::PopAndDestroy(entries);
  
  if(ret == KErrNone)
    aTaskCount = tasks->Count();
  else
    aTaskCount = -1;
  
  CleanupStack::PopAndDestroy(tasks);
  
  return ret;
  }
 
 
TInt CSchedulerExampleAppUi::GetScheduleCountL(TScheduleFilter aFilter, 
                              RScheduler& aScheduler, 
                              TInt& aScheduleCount)
  {
  TInt ret(KErrNone); 
  
  CArrayFixFlat<TSchedulerItemRef>* items = 
new (ELeave) CArrayFixFlat<TSchedulerItemRef> (1);
  CleanupStack::PushL(items);
 
  ret = aScheduler.GetScheduleRefsL(*items, aFilter);
 
  if(ret == KErrNone)
    aScheduleCount = items->Count();
  else
    aScheduleCount = -1;
  
  CleanupStack::PopAndDestroy(items);
  
  return ret;
  }


Postconditions

The count of schedules, time-based schedule tasks, and condition-based schedule tasks are displayed to the user with info dialogs.

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