messagingfw/scheduledsendmtm/schedulesendmtm/src/tmsvschedulesettingsutils.cpp
changeset 62 db3f5fa34ec7
parent 0 8e480a14352b
equal deleted inserted replaced
60:9f5ae1728557 62:db3f5fa34ec7
       
     1 // Copyright (c) 2004-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 #include <centralrepository.h>
       
    17 #include <s32mem.h>
       
    18 
       
    19 #include <tmsvschedulesettingsutils.h>
       
    20 #include <msvschedulesettings.h>
       
    21 #include <msvoffpeaktime.h>
       
    22 #include <msvsenderroraction.h>
       
    23 #include <msvsysagentaction.h>
       
    24 
       
    25 
       
    26 const TUint32 KIncrementSettingList = 0x00000010;
       
    27 const TInt KMaxVariableIntervals = 4096;
       
    28 const TInt KMaxSettingList = 256;
       
    29 const TInt KSysAgentActionsVersion = 1;
       
    30 const TInt KScheduleSettingsVersion = 1;
       
    31 const TInt KOffPeakTimesVersion = 1;
       
    32 const TInt KOffPeakTimeVersion = 1;
       
    33 const TInt KSendErrorActionVersion = 1;
       
    34 const TInt KSendErrorActionsVersion = 1;
       
    35 const TInt KSysAgentConditionActionVersion = 1;
       
    36 
       
    37 
       
    38 
       
    39 /**
       
    40 Saves Schedule Settings to the Central Repository.
       
    41 This function must be used within a CenRep Transaction.
       
    42 
       
    43 @param	aScheduleSettings
       
    44 Schedule settings
       
    45 
       
    46 @param	aRepository
       
    47 Repository to save settings to.
       
    48 */
       
    49 EXPORT_C void TMsvScheduleSettingsUtils::SaveScheduleSettingsL(const CMsvScheduleSettings& aScheduleSettings, CRepository& aRepository)
       
    50 	{
       
    51 	aRepository.Set(EScheduleVersionId, KScheduleSettingsVersion);	
       
    52 	aRepository.Set(ESchedulePriorityId, aScheduleSettings.Priority());
       
    53 	aRepository.Set(EScheduleValidityPeriodId, aScheduleSettings.ValidityPeriod().Int());
       
    54 	aRepository.Set(EScheduleIntervalTypeId, static_cast<TInt>(aScheduleSettings.IntervalType()));
       
    55 	aRepository.Set(EScheduleLatencyId, aScheduleSettings.Latency().Int());
       
    56 	aRepository.Set(EScheduleLongIntervalId, aScheduleSettings.LongInterval().Int());
       
    57 	aRepository.Set(EScheduleShortIntervalId, aScheduleSettings.ShortInterval().Int());
       
    58 	aRepository.Set(ESchedulePendingConditionsTimeoutId, aScheduleSettings.PendingConditionsTimeout().Int());
       
    59 
       
    60 	TInt count = aScheduleSettings.VariableIntervals().Count();
       
    61 	__ASSERT_ALWAYS(count<=KMaxVariableIntervals, User::Leave(KErrOverflow));	
       
    62 	aRepository.Set(EScheduleVariableIntervalsCountId, count);
       
    63 	
       
    64 	TUint32 variableIntervalId = EScheduleVariableIntervals;
       
    65 	for (TInt counter = 0; counter < count; ++counter)
       
    66 		{
       
    67 		aRepository.Set(variableIntervalId, aScheduleSettings.VariableIntervals().At(counter).Int());
       
    68 		++variableIntervalId;
       
    69 		}
       
    70 	}
       
    71 
       
    72 /**
       
    73 Saves Off Peak Times to CenRep.
       
    74 This function must be used within a CenRep Transaction.
       
    75 
       
    76 @param	aOffPeakTimes
       
    77 Off Peak Times
       
    78 
       
    79 @param	aRepository
       
    80 Repository to save settings to.
       
    81 */
       
    82 EXPORT_C void TMsvScheduleSettingsUtils::SaveOffPeakSettingsL(const CMsvOffPeakTimes& aOffPeakTimes, CRepository& aRepository)
       
    83 	{
       
    84 
       
    85 	aRepository.Set(EOffPeakTimesVersionId, KOffPeakTimesVersion);
       
    86 
       
    87 	TInt count = aOffPeakTimes.Count();
       
    88 	__ASSERT_ALWAYS(count<=KMaxSettingList, User::Leave(KErrOverflow));		
       
    89 	aRepository.Set(EOffPeakTimesCountId, count);
       
    90 
       
    91 	TUint32 offPeakTimeId = EOffPeakTimes;
       
    92 	for(TInt curTime = 0; curTime < count; ++curTime)
       
    93 		{	
       
    94 		aRepository.Set(offPeakTimeId + EOffPeakVersion, KOffPeakTimeVersion);		
       
    95 		aRepository.Set(offPeakTimeId + EOffPeakDay, static_cast<TInt>(aOffPeakTimes.At(curTime).Day()));
       
    96 		aRepository.Set(offPeakTimeId + EOffPeakHour, aOffPeakTimes.At(curTime).Hour());
       
    97 		aRepository.Set(offPeakTimeId + EOffPeakMinute, aOffPeakTimes.At(curTime).Minute());
       
    98 		aRepository.Set(offPeakTimeId + EOffPeakValidityPeriod, aOffPeakTimes.At(curTime).ValidityPeriod().Int());
       
    99 		
       
   100 		offPeakTimeId += KIncrementSettingList;
       
   101 		}	
       
   102 	}
       
   103 
       
   104 /**
       
   105 Saves Send Error Action to CenRep.
       
   106 This function must be used within a CenRep Transaction.
       
   107 
       
   108 @param	aErrorActionId
       
   109 CenRep Id
       
   110 
       
   111 @param	aErrorAction
       
   112 Send Error Action
       
   113 
       
   114 @param	aRepository
       
   115 Repository to save settings to.
       
   116 */
       
   117 void TMsvScheduleSettingsUtils::SaveSendErrorActionL(TUint32 aErrorActionId, const TMsvSendErrorAction& aErrorAction, CRepository& aRepository)
       
   118 	{
       
   119 	aRepository.Set(aErrorActionId + ESendErrorVersion, KSendErrorActionVersion);			
       
   120 	aRepository.Set(aErrorActionId + ESendErrorError, aErrorAction.iError);		
       
   121 	aRepository.Set(aErrorActionId + ESendErrorMaxRetries, static_cast<TInt>(aErrorAction.MaxRetries()));		
       
   122 	aRepository.Set(aErrorActionId + ESendErrorRetries, static_cast<TInt>(aErrorAction.iRetries));		
       
   123 	aRepository.Set(aErrorActionId + ESendErrorAction,  static_cast<TInt>(aErrorAction.iAction));		
       
   124 	aRepository.Set(aErrorActionId + ESendErrorRetrySpacing,  static_cast<TInt>(aErrorAction.iRetrySpacing));		
       
   125 	}
       
   126 
       
   127 /**
       
   128 Saves Send Error Actions to CenRep.
       
   129 This function must be used within a CenRep Transaction.
       
   130 
       
   131 @param	aErrorActions
       
   132 Send Error Actions
       
   133 
       
   134 @param	aRepository
       
   135 Repository to save settings to.
       
   136 */
       
   137 EXPORT_C void TMsvScheduleSettingsUtils::SaveSendErrorSettingsL(const CMsvSendErrorActions& aErrorActions, CRepository& aRepository)
       
   138 	{
       
   139 
       
   140 	aRepository.Set(ESendErrorActionsVersionId, KSendErrorActionsVersion);
       
   141 
       
   142 	// Default error actions	
       
   143 	SaveSendErrorActionL(ESendErrorDefaultAction, aErrorActions.Default(), aRepository);
       
   144 
       
   145 	// List of error actions
       
   146 	TInt count = aErrorActions.Errors().Count();
       
   147 	__ASSERT_ALWAYS(count<=KMaxSettingList, User::Leave(KErrOverflow));		
       
   148 	aRepository.Set(ESendErrorActionsCountId, count);
       
   149 
       
   150 	TUint32 errorActionId = ESendErrorActions;
       
   151 	for (TInt counter = 0; counter < count; ++counter)
       
   152 		{
       
   153 		SaveSendErrorActionL(errorActionId, aErrorActions.Errors().At(counter), aRepository);							
       
   154 		errorActionId += KIncrementSettingList;
       
   155 		}
       
   156 	}
       
   157 
       
   158 /**
       
   159 Saves System Agent Actions to CenRep.
       
   160 This function must be used within a CenRep Transaction.
       
   161 
       
   162 @param	aSysAgentActions
       
   163 System Agent Actions
       
   164 
       
   165 @param	aRepository
       
   166 Repository to save settings to.
       
   167 */
       
   168 EXPORT_C void TMsvScheduleSettingsUtils::SaveSysAgentSettingsL(const CMsvSysAgentActions& aSysAgentActions, CRepository& aRepository)
       
   169 	{
       
   170 
       
   171 	aRepository.Set(ESysAgentActionsVersionId, KSysAgentActionsVersion);
       
   172 		
       
   173 	// Default send error actions	
       
   174 	SaveSendErrorActionL(ESysAgentDefaultSendErrorAction, aSysAgentActions.iDefault, aRepository);
       
   175 		
       
   176 	// Sys Agent Settings		
       
   177 	TInt count = aSysAgentActions.Count();
       
   178 	__ASSERT_ALWAYS(count<=KMaxSettingList, User::Leave(KErrOverflow));		
       
   179 	aRepository.Set(ESysAgentActionsCountId, count);
       
   180 	
       
   181 	// Save a list of System Agent Actions and Send Error Actions
       
   182 	TUint32 sysAgentId = ESysAgentActions;
       
   183 	TUint32 errorActionId = ESysAgentSendErrorActions;
       
   184 	while (count--)
       
   185 		{
       
   186 		aRepository.Set(sysAgentId + ESysAgentVersion, KSysAgentConditionActionVersion);					
       
   187 		aRepository.Set(sysAgentId + ESysAgentVariable, static_cast<TInt>(aSysAgentActions.At(count).iCondition.iVariable.iUid));			
       
   188 		aRepository.Set(sysAgentId + ESysAgentState, aSysAgentActions.At(count).iCondition.iState);					
       
   189 		aRepository.Set(sysAgentId + ESysAgentType, static_cast<TInt>(aSysAgentActions.At(count).iCondition.iType));					
       
   190 		aRepository.Set(sysAgentId + ESysAgentDefault, aSysAgentActions.At(count).iUseDefaultSysAgentAction);					
       
   191  		sysAgentId += KIncrementSettingList;
       
   192 		
       
   193 		// Error actions
       
   194 		SaveSendErrorActionL(errorActionId, aSysAgentActions.At(count).iErrorAction, aRepository);							
       
   195 		errorActionId += KIncrementSettingList;
       
   196 		}	
       
   197 	}
       
   198 
       
   199 /**
       
   200 Loads Schedule Settings from CenRep.
       
   201 
       
   202 @param	aScheduleSettings
       
   203 Schedule settings
       
   204 
       
   205 @param	aRepository
       
   206 Repository to Load settings from.
       
   207 */
       
   208 EXPORT_C void TMsvScheduleSettingsUtils::LoadScheduleSettingsL(CMsvScheduleSettings& aScheduleSettings, CRepository& aRepository)
       
   209 	{
       
   210 	aScheduleSettings.Reset();
       
   211 
       
   212 	TInt temp = 0;
       
   213 
       
   214 	User::LeaveIfError(aRepository.Get(ESchedulePriorityId, temp));
       
   215 	aScheduleSettings.SetPriority(temp);
       
   216 		
       
   217 	User::LeaveIfError(aRepository.Get(EScheduleValidityPeriodId, temp));
       
   218 	aScheduleSettings.SetValidityPeriod(static_cast<TTimeIntervalMinutes>(temp));
       
   219 		
       
   220 	User::LeaveIfError(aRepository.Get(EScheduleIntervalTypeId, temp));
       
   221 	aScheduleSettings.SetIntervalType(static_cast<TIntervalType>(temp));
       
   222 		
       
   223 	User::LeaveIfError(aRepository.Get(EScheduleLatencyId, temp));
       
   224 	aScheduleSettings.SetLatency(static_cast<TTimeIntervalMicroSeconds32>(temp));
       
   225 
       
   226 	User::LeaveIfError(aRepository.Get(EScheduleLongIntervalId, temp));
       
   227 	aScheduleSettings.SetLongInterval(static_cast<TTimeIntervalSeconds>(temp));
       
   228 
       
   229 	User::LeaveIfError(aRepository.Get(EScheduleShortIntervalId, temp));
       
   230 	aScheduleSettings.SetShortInterval(static_cast<TTimeIntervalSeconds>(temp));
       
   231 
       
   232 	User::LeaveIfError(aRepository.Get(ESchedulePendingConditionsTimeoutId, temp));
       
   233 	aScheduleSettings.SetPendingConditionsTimeout(static_cast<TTimeIntervalMinutes>(temp));
       
   234 
       
   235 	User::LeaveIfError(aRepository.Get(EScheduleVariableIntervalsCountId, temp));
       
   236 	TInt count = temp;
       
   237 
       
   238 	if (count>0)
       
   239 		{		
       
   240 		TUint32 variableIntervalId = EScheduleVariableIntervals;
       
   241 	    CArrayFixFlat<TTimeIntervalSeconds>* intervals = new(ELeave)CArrayFixFlat<TTimeIntervalSeconds>(count);    
       
   242 	    CleanupStack::PushL(intervals);
       
   243 		for (TInt cur = 0; cur < count; ++cur)
       
   244 			{
       
   245 			User::LeaveIfError(aRepository.Get(variableIntervalId, temp));
       
   246 			intervals->AppendL(static_cast<TTimeIntervalSeconds>(temp));
       
   247 
       
   248 			++variableIntervalId;
       
   249 			}
       
   250 			
       
   251 		if (intervals->Count()>0)
       
   252 			{		
       
   253 	   		aScheduleSettings.SetVariableIntervalsL(*intervals);
       
   254 			}
       
   255 		CleanupStack::PopAndDestroy(intervals);	
       
   256 		}
       
   257 	}
       
   258 
       
   259 /**
       
   260 Loads Off Peak Times from CenRep.
       
   261 
       
   262 @param	aOffPeakTimes
       
   263 Off Peak Times
       
   264 
       
   265 @param	aRepository
       
   266 Repository to Load settings from.
       
   267 */
       
   268 EXPORT_C void TMsvScheduleSettingsUtils::LoadOffPeakSettingsL(CMsvOffPeakTimes& aOffPeakTimes, CRepository& aRepository)
       
   269 	{
       
   270 	aOffPeakTimes.Reset();
       
   271 
       
   272 	TInt temp = 0;
       
   273 	
       
   274 	User::LeaveIfError(aRepository.Get(EOffPeakTimesCountId, temp));
       
   275 	TInt count = temp;
       
   276 		
       
   277 	TUint32 settingId = 0;	
       
   278 	TUint32 offPeakTimeId = EOffPeakTimes;
       
   279 	TMsvOffPeakTime opTime;
       
   280 	for (TInt curTime = 0; curTime < count; ++curTime)
       
   281 		{			
       
   282 		opTime.Reset();
       
   283 		settingId = offPeakTimeId + EOffPeakDay;
       
   284 		User::LeaveIfError(aRepository.Get(settingId, temp));
       
   285 		opTime.SetDay(static_cast<TDay>(temp));
       
   286 
       
   287 		settingId = offPeakTimeId + EOffPeakHour;
       
   288 		User::LeaveIfError(aRepository.Get(settingId, temp));
       
   289 		opTime.SetHour(temp);
       
   290 
       
   291 		settingId = offPeakTimeId + EOffPeakMinute;
       
   292 		User::LeaveIfError(aRepository.Get(settingId, temp));
       
   293 		opTime.SetMinute(temp);
       
   294 
       
   295 		settingId = offPeakTimeId + EOffPeakValidityPeriod;
       
   296 		User::LeaveIfError(aRepository.Get(settingId, temp));
       
   297 		opTime.SetValidityPeriod(static_cast<TTimeIntervalMinutes>(temp));
       
   298 									
       
   299 		aOffPeakTimes.AppendL(opTime);			
       
   300 		offPeakTimeId += KIncrementSettingList;
       
   301 		}
       
   302 	}
       
   303 
       
   304 /**
       
   305 Loads a Send Error Action from CenRep.
       
   306 
       
   307 @param	aErrorActionId
       
   308 CenRep Id
       
   309 
       
   310 @param	aErrorAction
       
   311 Send Error Action
       
   312 
       
   313 @param	aRepository
       
   314 Repository to Load settings from.
       
   315 */
       
   316 void TMsvScheduleSettingsUtils::LoadSendErrorActionL(TUint32 aErrorActionId, TMsvSendErrorAction& aErrorAction, CRepository& aRepository)
       
   317 	{
       
   318 	aErrorAction.Reset();
       
   319 
       
   320 	TInt temp = 0;
       
   321 	TUint32 settingId = aErrorActionId + ESendErrorError;
       
   322 	User::LeaveIfError(aRepository.Get(settingId, temp));
       
   323 	aErrorAction.iError = temp;
       
   324 		
       
   325 	settingId = aErrorActionId + ESendErrorMaxRetries;
       
   326 	User::LeaveIfError(aRepository.Get(settingId, temp));
       
   327 	aErrorAction.SetMaxRetries(static_cast<TInt16>(temp));
       
   328 
       
   329 	settingId = aErrorActionId + ESendErrorRetries;
       
   330 	User::LeaveIfError(aRepository.Get(settingId, temp));
       
   331 	aErrorAction.iRetries = static_cast<TMsvSendRetries>(temp);
       
   332 
       
   333 	settingId = aErrorActionId + ESendErrorAction;
       
   334 	User::LeaveIfError(aRepository.Get(settingId, temp));
       
   335 	aErrorAction.iAction = static_cast<TMsvSendAction>(temp);
       
   336 
       
   337 	settingId = aErrorActionId + ESendErrorRetrySpacing;
       
   338 	User::LeaveIfError(aRepository.Get(settingId, temp));
       
   339 	aErrorAction.iRetrySpacing = static_cast<TMsvSendRetrySpacing>(temp);
       
   340 	}
       
   341 
       
   342 /**
       
   343 Loads Send Error Actions from CenRep.
       
   344 
       
   345 @param	aErrorActions
       
   346 Send Error Actions
       
   347 
       
   348 @param	aRepository
       
   349 Repository to Load settings from.
       
   350 */
       
   351 EXPORT_C void TMsvScheduleSettingsUtils::LoadSendErrorSettingsL(CMsvSendErrorActions& aErrorActions, CRepository& aRepository)
       
   352 	{
       
   353 	aErrorActions.Reset();
       
   354 	
       
   355 	TInt temp = 0;
       
   356 		
       
   357 	TMsvSendErrorAction action;
       
   358 	LoadSendErrorActionL(ESendErrorDefaultAction, action, aRepository);
       
   359 	aErrorActions.SetDefault(action);
       
   360 
       
   361 	User::LeaveIfError(aRepository.Get(ESendErrorActionsCountId, temp));	
       
   362 	TInt count = temp;
       
   363 		
       
   364 	TUint32 errorActionId = ESendErrorActions;
       
   365 	for (TInt counter = 0; counter < count; ++counter)
       
   366 		{
       
   367 		LoadSendErrorActionL(errorActionId, action, aRepository);
       
   368 		aErrorActions.AddSendErrorActionL(action);		
       
   369 		errorActionId += KIncrementSettingList;
       
   370 		}
       
   371 	}
       
   372 
       
   373 /**
       
   374 Loads System Agent Actions from CenRep.
       
   375 
       
   376 @param	aSysAgentActions
       
   377 System Agent Actions
       
   378 
       
   379 @param	aRepository
       
   380 Repository to Load settings from.
       
   381 */
       
   382 EXPORT_C void TMsvScheduleSettingsUtils::LoadSysAgentSettingsL(CMsvSysAgentActions& aSysAgentActions, CRepository& aRepository)
       
   383 	{
       
   384 	aSysAgentActions.Reset();
       
   385 	
       
   386 	TInt temp = 0;
       
   387 	
       
   388 	LoadSendErrorActionL(ESysAgentDefaultSendErrorAction, aSysAgentActions.iDefault, aRepository);
       
   389 
       
   390 	User::LeaveIfError(aRepository.Get(ESysAgentActionsCountId, temp));	
       
   391 	TInt count = temp;
       
   392 		
       
   393 	TUint32 settingId = 0;
       
   394 	TMsvSysAgentConditionAction condAction;
       
   395 	TUint32 sysAgentId = ESysAgentActions;
       
   396 	TUint32 errorActionId = ESysAgentSendErrorActions;
       
   397 	while (count--)
       
   398 		{
       
   399 		settingId = sysAgentId + ESysAgentVariable;	
       
   400 		User::LeaveIfError(aRepository.Get(settingId, temp));
       
   401 		condAction.iCondition.iVariable.iUid = temp;
       
   402 
       
   403 		settingId = sysAgentId + ESysAgentState;
       
   404 		User::LeaveIfError(aRepository.Get(settingId, condAction.iCondition.iState));	
       
   405 
       
   406 		settingId = sysAgentId + ESysAgentType;
       
   407 		User::LeaveIfError(aRepository.Get(settingId, temp));
       
   408 		condAction.iCondition.iType = static_cast<TMsvCondition::TMsvSchSendConditionType>(temp);
       
   409 
       
   410 		settingId = sysAgentId + ESysAgentDefault;
       
   411 		User::LeaveIfError(aRepository.Get(settingId, condAction.iUseDefaultSysAgentAction));
       
   412 
       
   413 		// Error actions
       
   414 		LoadSendErrorActionL(errorActionId, condAction.iErrorAction, aRepository);							
       
   415 						
       
   416 		aSysAgentActions.AppendL(condAction);			
       
   417 		sysAgentId += KIncrementSettingList;
       
   418 		errorActionId += KIncrementSettingList;
       
   419 		}
       
   420 	}