messagingfw/scheduledsendmtm/schedulesendmtm/inc/MsvScheduleSend.h
changeset 62 db3f5fa34ec7
parent 0 8e480a14352b
child 58 6c34d0baa0b1
equal deleted inserted replaced
60:9f5ae1728557 62:db3f5fa34ec7
       
     1 // Copyright (c) 1999-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 #ifndef __MSVSCHEDULESEND_H__
       
    17 #define __MSVSCHEDULESEND_H__
       
    18 
       
    19 #ifdef _DEBUG
       
    20 #undef _MSG_NO_LOGGING
       
    21 #endif
       
    22 
       
    23  
       
    24 
       
    25 
       
    26 #include <e32base.h>
       
    27 #include <msvstd.h>
       
    28 #include <csch_cli.h>
       
    29 #include <msvschedulepackage.h>
       
    30 #include <msvscheduledentry.h>
       
    31 
       
    32 class CMsvEntrySelection;
       
    33 class TMsvSchedulePackage;
       
    34 class TMsvSendErrorAction;
       
    35 class CMsvStore;
       
    36 class TMsvEntry;
       
    37 class CMsvOffPeakTimes;
       
    38 class CMsvScheduleSettings;
       
    39 class CMsvSendErrorActions;
       
    40 class CMsvSysAgentActions;
       
    41 class TMsvSchedulePackage;
       
    42 class TMsvEntryScheduleData;
       
    43 class CMsvServerEntry;
       
    44 class CRepository;
       
    45 
       
    46 const TUid KUidMsvScheduledSendingDLL	= {0x100056A0};
       
    47 const TInt KMsvSchsendArrayGrowth		= 10;
       
    48 
       
    49 #ifdef _MSG_NO_LOGGING
       
    50 #define SCHSENDLOG(a)
       
    51 #else
       
    52 _LIT(KSchSendLogDir, "schsend");
       
    53 _LIT(KSchSendLogFile,"SchSend.txt");
       
    54 #define SCHSENDLOG(a) a
       
    55 #endif
       
    56 
       
    57 /** 
       
    58 Provides a Server MTM's interface to the Task Scheduler for messaging 
       
    59 scheduling.
       
    60 
       
    61 Server MTM's must provide a derived class that implements GetMessageL() to 
       
    62 provide a factory for MTM-specific scheduling CMsvScheduledEntry-based objects. 
       
    63 
       
    64 @publishedAll
       
    65 @released
       
    66 */
       
    67 class CMsvScheduleSend : public CBase
       
    68 	{
       
    69 public:
       
    70 	IMPORT_C ~CMsvScheduleSend();
       
    71 
       
    72 	IMPORT_C void ScheduleL(const CMsvEntrySelection& aSelection, const TMsvSchedulePackage& aPackage);
       
    73 
       
    74 	IMPORT_C void ReScheduleL(const CMsvEntrySelection& aSelection, const TMsvSchedulePackage& aPackage, const TMsvSendErrorAction* aErrorAction = NULL);
       
    75 
       
    76 	IMPORT_C void CheckScheduleL(const CMsvEntrySelection& aSelection);
       
    77 	IMPORT_C void DeleteScheduleL(const CMsvEntrySelection& aSelection);
       
    78 
       
    79 	IMPORT_C void SendingCompleteL(TMsvEntry& aEntry, const TBool aChangeEntry = EFalse);
       
    80 	IMPORT_C void SendingCompleteL(const CMsvEntrySelection& aSelection);
       
    81 
       
    82 
       
    83 	inline CMsvOffPeakTimes& OffPeakTimes() const;
       
    84 	inline CMsvScheduleSettings& ScheduleSettings() const;
       
    85 	inline CMsvSendErrorActions& SendErrorActions() const;
       
    86 	inline CMsvSysAgentActions& AgentActions() const;
       
    87 
       
    88 	IMPORT_C static void CreateScheduleL(RScheduler& aScheduler, const CMsvScheduleSettings& aSettings, const TTime& aStartTime, const TTimeIntervalMinutes& aValidityPeriod, TSchedulerItemRef& aRef);
       
    89 	IMPORT_C static void CreateScheduleL(RScheduler& aScheduler, const CArrayFixFlat<TTaskSchedulerCondition>& aConditions, const TTime& aTimeout, TSchedulerItemRef& aRef);
       
    90 	IMPORT_C static void FindScheduleL(RScheduler& aScheduler, const TTime& aStartTime, TSchedulerItemRef& aRef);
       
    91 	IMPORT_C static void FindScheduleL(RScheduler& aScheduler, const CArrayFixFlat<TTaskSchedulerCondition>& aConditions, const TTime& aTimeout, TSchedulerItemRef& aRef);
       
    92 	IMPORT_C static void RoundUpToMinute(TTime& aTime);
       
    93 	IMPORT_C static void ScheduleEntryL(RScheduler& aScheduler, const TSchedulerItemRef& aRef, const TMsvSchedulePackage& aPackage, TTaskInfo& aInfo);
       
    94 	IMPORT_C static void UpdateEntryAfterSchedule(const TSchedulerItemRef& aRef, const TTaskInfo& aInfo, const TTime& aTime, TInt aFinalState, TMsvEntry& aEntry, TMsvEntryScheduleData& aData);
       
    95 	IMPORT_C static void ConnectAndRegisterL(RScheduler& aScheduler, const CMsvScheduleSettings& aSettings);
       
    96 
       
    97 	IMPORT_C void LoadScheduleSettingsL(CRepository& aRepository);
       
    98 
       
    99 protected:
       
   100 
       
   101 	IMPORT_C CMsvScheduleSend(CMsvServerEntry& aServerEntry);
       
   102 	IMPORT_C virtual void ConstructL();
       
   103 
       
   104 /**
       
   105 Gets the schedule data and recipients of a message.
       
   106 
       
   107 Recipient information is MTM-specific, so the server MTM must provide a 
       
   108 derived class that implements CMsvScheduledEntry, and return objects of 
       
   109 that type from this function.
       
   110 
       
   111 @param	aId 
       
   112 The message ID.
       
   113 
       
   114 @return 
       
   115 The message's schedule data.
       
   116 */
       
   117 	virtual CMsvScheduledEntry* GetMessageL(const TMsvId aId) const = 0;
       
   118 
       
   119 private:
       
   120 
       
   121 	enum
       
   122 		{
       
   123 		EDefaultTaskPriority	= 1, //used when scheduling a task in the task scheduler
       
   124 		EDefaultTaskRepeat		= 0	 //used when scheduling a task in the task scheduler
       
   125 		};
       
   126 	
       
   127 	void SendingCompleteL(CMsvScheduledEntry& aScheduledEntry, const TBool aChangeEntry);
       
   128 
       
   129 	TBool GetNextRetry(CMsvScheduledEntry& aMessage, const TMsvSendErrorAction& aErrorAction, TTimeIntervalSeconds& aInterval) const;
       
   130 
       
   131 	void DoScheduleL(CMsvScheduledEntries& aSchEntries, const TInt aFinalState, const TTime& aTime, TBool aPendingConditions);
       
   132 	void DoReScheduleL(CMsvScheduledEntries& aSchEntries);
       
   133 	
       
   134 	void GetMessagesL(const CMsvEntrySelection& aSelection);
       
   135 
       
   136 	void ConnectAndRegisterL();
       
   137 
       
   138 	void ScheduleEntryL(CMsvScheduledEntry& aMessage, const TInt aFinalState, const TTime& aStartTime, const TSchedulerItemRef& aRef, TBool aPendingConditions);
       
   139 
       
   140 	void GetOffPeakL(TTime aFromTime, TTime& aStartTime, TTimeIntervalMinutes& aValidityPeriod) const;
       
   141 	
       
   142 	void DeleteScheduleForEntryL(CMsvScheduledEntry& aMessage);
       
   143 	void ResetScheduleInfoForEntryL(CMsvScheduledEntry& aMessage, const TBool aChangeEntry);
       
   144 	void SortByDateAndPendingConditionsL(CMsvScheduledEntries& aScheduledEntries);
       
   145 	void CreateScheduleL(const TTime& aStartTime, const TTimeIntervalMinutes& aValidityPeriod, const CArrayFixFlat<TTaskSchedulerCondition>& aSchConditions, TBool aPendingConditions, TSchedulerItemRef& aRef);
       
   146 	void FindScheduleL(const TTime& aTime, const CArrayFixFlat<TTaskSchedulerCondition>& aSchConditions, TBool aPendingConditions, TSchedulerItemRef& aRef);
       
   147 
       
   148 	void PopulateScheduleConditionsL(CArrayFixFlat<TTaskSchedulerCondition>& aSchConditions);
       
   149 	TBool SetMessageStartTime(CMsvScheduledEntry& aMessage, const TTime& aFromTime, const TMsvSendErrorAction* aErrorAction = NULL);
       
   150 
       
   151 	TBool TaskAndMessageMatchL(const CMsvScheduledEntry& aMessage);
       
   152 	TMsvId GetMessageIdForTaskL(TInt aTaskId);
       
   153 #ifndef _MSG_NO_LOGGING
       
   154 	void FLog(TRefByValue<const TDesC> aFormat, ...);
       
   155 	void FLog(TRefByValue<const TDesC8> aFormat, ...);
       
   156 #endif
       
   157 
       
   158 protected:
       
   159 
       
   160 	/** The Server MTM specific scheduled message sending settings. */
       
   161 	CMsvScheduleSettings*	iSettings;
       
   162 	/** The Server MTM specific off peak time periods. */
       
   163 	CMsvOffPeakTimes*		iOffPeakTimes;
       
   164 	/** The Server MTM specific actions to take when particular errors occur during 
       
   165 	message sending. */
       
   166 	CMsvSendErrorActions*	iErrorActions;
       
   167 	/** The System Agent conditions that must be satisfied before a sending attempt. */
       
   168 	CMsvSysAgentActions*	iAgentActions;
       
   169 
       
   170 	/** Indicates if this has been registered with the Task Scheduler. 
       
   171 	
       
   172 	Initially set to EFalse. */
       
   173 	TBool					iRegistered;	
       
   174 	/** Provides an interface to the Task Scheduler. */
       
   175 	RScheduler				iScheduler;	
       
   176 	/** The CMsvServerEntry of the server MTM. */
       
   177 	CMsvServerEntry&		iServerEntry;
       
   178 	/** Scheduling options. */
       
   179 	TMsvSchedulePackage		iPackage;
       
   180 
       
   181 	/** Array of message schedule data. */
       
   182 	CMsvScheduledEntries*	iSchEntries;
       
   183 
       
   184 	/** Array of schedule entry data. */
       
   185 	CArrayFixFlat<TScheduleEntryInfo2>* iSchEntryInfo;
       
   186 	/** Array of schedule task data. */
       
   187 	CArrayFixFlat<TTaskInfo>* iSchTaskInfo;
       
   188 	};
       
   189 
       
   190 #include <msvschedulesend.inl>
       
   191 
       
   192 #endif