realtimenetprots/sipfw/SIP/TransactionUser/src/TimerValueRetriever.cpp
changeset 0 307788aac0a8
equal deleted inserted replaced
-1:000000000000 0:307788aac0a8
       
     1 // Copyright (c) 2006-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 // Name          : TimerValueRetriever.cpp
       
    15 // Part of       : TransactionUser
       
    16 // Version       : SIP/5.0
       
    17 //
       
    18 
       
    19 
       
    20 
       
    21 #include <centralrepository.h>
       
    22 #include "SIPSDKCRKeys.h"
       
    23 #include "SipAssert.h"
       
    24 #include "TimerValueRetriever.h"
       
    25 
       
    26 
       
    27 // -----------------------------------------------------------------------------
       
    28 // CTimerValueRetriever::NewL
       
    29 // -----------------------------------------------------------------------------
       
    30 //
       
    31 CTimerValueRetriever* CTimerValueRetriever::NewL()
       
    32 	{
       
    33     CTimerValueRetriever* self = new (ELeave) CTimerValueRetriever();
       
    34     CleanupStack::PushL(self);
       
    35     self->ConstructL();
       
    36     CleanupStack::Pop(self);
       
    37     return self;
       
    38     }
       
    39 
       
    40 // -----------------------------------------------------------------------------
       
    41 // CTimerValueRetriever::CTimerValueRetriever
       
    42 // -----------------------------------------------------------------------------
       
    43 //
       
    44 CTimerValueRetriever::CTimerValueRetriever() :
       
    45 	CActive(EPriorityStandard)
       
    46 	{
       
    47 	CActiveScheduler::Add(this);
       
    48 	}
       
    49 
       
    50 // -----------------------------------------------------------------------------
       
    51 // CTimerValueRetriever::ConstructL
       
    52 // -----------------------------------------------------------------------------
       
    53 //
       
    54 void CTimerValueRetriever::ConstructL()
       
    55 	{
       
    56 	iRepository = CRepository::NewL(KCRUidSIP);
       
    57 	ReadValuesL();
       
    58 	for(TUint i = 0; i < EMaxSupportedBearer;i++)
       
    59 		__ASSERT_ALWAYS(iTimerValues[i].CheckValues(), User::Leave(KErrCorrupt));
       
    60 	ListenForChangesL();
       
    61 	}
       
    62 
       
    63 // -----------------------------------------------------------------------------
       
    64 // CTimerValueRetriever::~CTimerValueRetriever
       
    65 // -----------------------------------------------------------------------------
       
    66 //
       
    67 CTimerValueRetriever::~CTimerValueRetriever()
       
    68 	{
       
    69 	Cancel();
       
    70 	delete iRepository;
       
    71 	}
       
    72 
       
    73 // -----------------------------------------------------------------------------
       
    74 // CTimerValueRetriever::DoCancel
       
    75 // -----------------------------------------------------------------------------
       
    76 //
       
    77 void CTimerValueRetriever::DoCancel()
       
    78 	{
       
    79 	if (iRepository)
       
    80 		{
       
    81 		iRepository->NotifyCancelAll();
       
    82 		}
       
    83 	}
       
    84 
       
    85 // -----------------------------------------------------------------------------
       
    86 // CTimerValueRetriever::RunL
       
    87 // -----------------------------------------------------------------------------
       
    88 //
       
    89 void CTimerValueRetriever::RunL()
       
    90 	{
       
    91 	__SIP_ASSERT_LEAVE(iRepository, KErrNotFound);
       
    92 
       
    93 	// In S60, repository completes the notification request with value 1, even
       
    94 	// though there is no error.
       
    95 	if (iStatus.Int() >= KErrNone)
       
    96 		{
       
    97 		ReadValuesL();
       
    98 		}
       
    99 
       
   100 	ListenForChangesL();
       
   101 	}
       
   102 
       
   103 // -----------------------------------------------------------------------------
       
   104 // CTimerValueRetriever::RunError
       
   105 // -----------------------------------------------------------------------------
       
   106 //
       
   107 TInt CTimerValueRetriever::RunError(TInt aError)
       
   108 	{
       
   109 	return (aError == KErrNoMemory) ? aError : KErrNone;
       
   110 	}
       
   111 
       
   112 // -----------------------------------------------------------------------------
       
   113 // CTimerValueRetriever::TimerValues
       
   114 // -----------------------------------------------------------------------------
       
   115 //
       
   116 TTimerValues& CTimerValueRetriever::TimerValues(BearerType aType)
       
   117 	{
       
   118 	if(EMaxSupportedBearer > aType)
       
   119 		return iTimerValues[aType];
       
   120 	else
       
   121 		return iTimerValues[EModemBearer];
       
   122 	}
       
   123 	
       
   124 // -----------------------------------------------------------------------------
       
   125 // CTimerValueRetriever::ReadValuesL
       
   126 // If the values read from repository are invalid, use the previous values.
       
   127 // -----------------------------------------------------------------------------
       
   128 //
       
   129 void CTimerValueRetriever::ReadValuesL()
       
   130 	{
       
   131 	__SIP_ASSERT_LEAVE(iRepository, KErrNotFound);
       
   132 
       
   133     TInt t1 = 0;
       
   134     TInt t2 = 0;
       
   135     TInt t4 = 0;
       
   136 
       
   137     User::LeaveIfError(iRepository->Get(KSIPTransactionTimerT1, t1));
       
   138     User::LeaveIfError(iRepository->Get(KSIPTransactionTimerT2, t2));
       
   139     User::LeaveIfError(iRepository->Get(KSIPTransactionTimerT4, t4));
       
   140 
       
   141 	TTimerValues newMBValues(t1, t2, t4);
       
   142 	if (newMBValues.CheckValues())
       
   143 		{
       
   144 		iTimerValues[EModemBearer] = newMBValues;
       
   145 		}
       
   146 	
       
   147 	User::LeaveIfError(iRepository->Get(KSIPTransactionTimerLANT1, t1));
       
   148 	User::LeaveIfError(iRepository->Get(KSIPTransactionTimerLANT2, t2));
       
   149 	User::LeaveIfError(iRepository->Get(KSIPTransactionTimerLANT4, t4));
       
   150 
       
   151 	TTimerValues newLBValues(t1, t2, t4);
       
   152 	if (newLBValues.CheckValues())
       
   153 		{
       
   154 		iTimerValues[ELanBearer] = newLBValues;
       
   155 		}
       
   156     }
       
   157 
       
   158 // -----------------------------------------------------------------------------
       
   159 // CTimerValueRetriever::ListenForChangesL
       
   160 // -----------------------------------------------------------------------------
       
   161 //
       
   162 void CTimerValueRetriever::ListenForChangesL()
       
   163 	{
       
   164 	__SIP_ASSERT_LEAVE(iRepository, KErrNotFound);
       
   165 
       
   166 	const TUint32 KDummyPartialKey = 0x0;
       
   167 	//This mask means listening for all keys 
       
   168 	const TUint32 KMaskIncludingAllKeys = 0x0;
       
   169 
       
   170 	User::LeaveIfError(iRepository->NotifyRequest(KDummyPartialKey,
       
   171 												  KMaskIncludingAllKeys,
       
   172 												  iStatus));
       
   173 	SetActive();
       
   174 	}
       
   175 
       
   176 // -----------------------------------------------------------------------------
       
   177 // CTimerValueRetriever::HighestT1Value
       
   178 // -----------------------------------------------------------------------------
       
   179 //
       
   180 TUint CTimerValueRetriever::HighestT1()
       
   181 	{
       
   182 	TUint t1 = 0;
       
   183 	for(TUint i = 0; i < EMaxSupportedBearer;i++)
       
   184 		if(iTimerValues[i].T1() > t1)
       
   185 			t1 = iTimerValues[i].T1();
       
   186 	return t1;
       
   187 	}