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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 #ifndef __MSVSCHEDULESEND_H__
17 #define __MSVSCHEDULESEND_H__
20 #undef _MSG_NO_LOGGING
29 #include <msvschedulepackage.h>
30 #include <msvscheduledentry.h>
32 class CMsvEntrySelection;
33 class TMsvSchedulePackage;
34 class TMsvSendErrorAction;
37 class CMsvOffPeakTimes;
38 class CMsvScheduleSettings;
39 class CMsvSendErrorActions;
40 class CMsvSysAgentActions;
41 class TMsvSchedulePackage;
42 class TMsvEntryScheduleData;
43 class CMsvServerEntry;
46 const TUid KUidMsvScheduledSendingDLL = {0x100056A0};
47 const TInt KMsvSchsendArrayGrowth = 10;
49 #ifdef _MSG_NO_LOGGING
52 _LIT(KSchSendLogDir, "schsend");
53 _LIT(KSchSendLogFile,"SchSend.txt");
54 #define SCHSENDLOG(a) a
58 Provides a Server MTM's interface to the Task Scheduler for messaging
61 Server MTM's must provide a derived class that implements GetMessageL() to
62 provide a factory for MTM-specific scheduling CMsvScheduledEntry-based objects.
67 class CMsvScheduleSend : public CBase
70 IMPORT_C ~CMsvScheduleSend();
72 IMPORT_C void ScheduleL(const CMsvEntrySelection& aSelection, const TMsvSchedulePackage& aPackage);
74 IMPORT_C void ReScheduleL(const CMsvEntrySelection& aSelection, const TMsvSchedulePackage& aPackage, const TMsvSendErrorAction* aErrorAction = NULL);
76 IMPORT_C void CheckScheduleL(const CMsvEntrySelection& aSelection);
77 IMPORT_C void DeleteScheduleL(const CMsvEntrySelection& aSelection);
79 IMPORT_C void SendingCompleteL(TMsvEntry& aEntry, const TBool aChangeEntry = EFalse);
80 IMPORT_C void SendingCompleteL(const CMsvEntrySelection& aSelection);
83 inline CMsvOffPeakTimes& OffPeakTimes() const;
84 inline CMsvScheduleSettings& ScheduleSettings() const;
85 inline CMsvSendErrorActions& SendErrorActions() const;
86 inline CMsvSysAgentActions& AgentActions() const;
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);
97 IMPORT_C void LoadScheduleSettingsL(CRepository& aRepository);
101 IMPORT_C CMsvScheduleSend(CMsvServerEntry& aServerEntry);
102 IMPORT_C virtual void ConstructL();
105 Gets the schedule data and recipients of a message.
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.
115 The message's schedule data.
117 virtual CMsvScheduledEntry* GetMessageL(const TMsvId aId) const = 0;
123 EDefaultTaskPriority = 1, //used when scheduling a task in the task scheduler
124 EDefaultTaskRepeat = 0 //used when scheduling a task in the task scheduler
127 void SendingCompleteL(CMsvScheduledEntry& aScheduledEntry, const TBool aChangeEntry);
129 TBool GetNextRetry(CMsvScheduledEntry& aMessage, const TMsvSendErrorAction& aErrorAction, TTimeIntervalSeconds& aInterval) const;
131 void DoScheduleL(CMsvScheduledEntries& aSchEntries, const TInt aFinalState, const TTime& aTime, TBool aPendingConditions);
132 void DoReScheduleL(CMsvScheduledEntries& aSchEntries);
134 void GetMessagesL(const CMsvEntrySelection& aSelection);
136 void ConnectAndRegisterL();
138 void ScheduleEntryL(CMsvScheduledEntry& aMessage, const TInt aFinalState, const TTime& aStartTime, const TSchedulerItemRef& aRef, TBool aPendingConditions);
140 void GetOffPeakL(TTime aFromTime, TTime& aStartTime, TTimeIntervalMinutes& aValidityPeriod) const;
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);
148 void PopulateScheduleConditionsL(CArrayFixFlat<TTaskSchedulerCondition>& aSchConditions);
149 TBool SetMessageStartTime(CMsvScheduledEntry& aMessage, const TTime& aFromTime, const TMsvSendErrorAction* aErrorAction = NULL);
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, ...);
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
166 CMsvSendErrorActions* iErrorActions;
167 /** The System Agent conditions that must be satisfied before a sending attempt. */
168 CMsvSysAgentActions* iAgentActions;
170 /** Indicates if this has been registered with the Task Scheduler.
172 Initially set to EFalse. */
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;
181 /** Array of message schedule data. */
182 CMsvScheduledEntries* iSchEntries;
184 /** Array of schedule entry data. */
185 CArrayFixFlat<TScheduleEntryInfo2>* iSchEntryInfo;
186 /** Array of schedule task data. */
187 CArrayFixFlat<TTaskInfo>* iSchTaskInfo;
190 #include <msvschedulesend.inl>