realtimenetprots/sipfw/ProfileAgent/PluginMgr/Src/SipProfileAgentConfigRetriever.cpp
changeset 0 307788aac0a8
equal deleted inserted replaced
-1:000000000000 0:307788aac0a8
       
     1 // Copyright (c) 2008-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          : SipProfileAgentConfigRetriever.cpp
       
    15 // Part of       : SIP / SIP Profile Server
       
    16 //
       
    17 
       
    18 
       
    19 
       
    20 #include <centralrepository.h>
       
    21 #include "SipProfileAgentConfigRetriever.h"
       
    22 #include <sipprofileservercrkeys.h>
       
    23 
       
    24 #define KIETFDefaultExpiryValue 3600
       
    25 #define KIMSDefaultExpiryValue 600000
       
    26 // -----------------------------------------------------------------------------
       
    27 // CSipProfileAgentConfigRetriever::NewL
       
    28 // -----------------------------------------------------------------------------
       
    29 //
       
    30 CSipProfileAgentConfigRetriever* CSipProfileAgentConfigRetriever::NewL()
       
    31 	{
       
    32 	CSipProfileAgentConfigRetriever* self = new (ELeave) CSipProfileAgentConfigRetriever();
       
    33     CleanupStack::PushL(self);
       
    34     self->ConstructL();
       
    35     CleanupStack::Pop(self);
       
    36     return self;
       
    37     }
       
    38 
       
    39 // -----------------------------------------------------------------------------
       
    40 // CSipProfileAgentConfigRetriever::CSipProfileAgentConfigRetriever
       
    41 // -----------------------------------------------------------------------------
       
    42 //
       
    43 CSipProfileAgentConfigRetriever::CSipProfileAgentConfigRetriever() :
       
    44 	CActive(EPriorityStandard)
       
    45 	{
       
    46 	CActiveScheduler::Add(this);
       
    47 	}
       
    48 
       
    49 // -----------------------------------------------------------------------------
       
    50 // CSipProfileAgentConfigRetriever::ConstructL
       
    51 // -----------------------------------------------------------------------------
       
    52 //
       
    53 void CSipProfileAgentConfigRetriever::ConstructL()
       
    54 	{
       
    55 	iRepository = CRepository::NewL(KCRUidProfileSrv);		
       
    56 	for(TUint32 i = 0; i < TSIPProfileTypeInfo::EMaxSIPProfileClass; i++)
       
    57 		{
       
    58 		for(TUint32 j = 0; j < CSipProfileAgentConfigExtension::EMaxProfileProperty; j++)
       
    59 			{
       
    60 			iProfilePropertyKeys[i][j] = 0;
       
    61 			}
       
    62 		iDefaultRegistrationValue[i] = 0;
       
    63 		iDefaultSubscriptionValue[i] = 0;
       
    64 		}
       
    65 	ReadValuesL();
       
    66 	ListenForChangesL();
       
    67 	}
       
    68 
       
    69 // -----------------------------------------------------------------------------
       
    70 // CSipProfileAgentConfigRetriever::~CSipProfileAgentConfigRetriever
       
    71 // -----------------------------------------------------------------------------
       
    72 //
       
    73 CSipProfileAgentConfigRetriever::~CSipProfileAgentConfigRetriever()
       
    74 	{
       
    75 	Cancel();
       
    76 	delete iRepository;
       
    77 	}
       
    78 
       
    79 // -----------------------------------------------------------------------------
       
    80 // CSipProfileAgentConfigRetriever::DoCancel
       
    81 // -----------------------------------------------------------------------------
       
    82 //
       
    83 void CSipProfileAgentConfigRetriever::DoCancel()
       
    84 	{
       
    85 	if (iRepository)
       
    86 		{
       
    87 		iRepository->NotifyCancelAll();
       
    88 		}
       
    89 	}
       
    90 
       
    91 // -----------------------------------------------------------------------------
       
    92 // CSipProfileAgentConfigRetriever::RunL
       
    93 // -----------------------------------------------------------------------------
       
    94 //
       
    95 void CSipProfileAgentConfigRetriever::RunL()
       
    96 	{
       
    97 
       
    98 	// In S60, repository completes the notification request with value 1, even
       
    99 	// though there is no error.
       
   100 	if (iStatus.Int() >= KErrNone)
       
   101 		{
       
   102 		ReadValuesL();
       
   103 		}
       
   104 
       
   105 	ListenForChangesL();
       
   106 	}
       
   107 
       
   108 // -----------------------------------------------------------------------------
       
   109 // CSipProfileAgentConfigRetriever::RunError
       
   110 // -----------------------------------------------------------------------------
       
   111 //
       
   112 TInt CSipProfileAgentConfigRetriever::RunError(TInt aError)
       
   113 	{
       
   114 	return (aError == KErrNoMemory) ? aError : KErrNone;
       
   115 	}
       
   116 
       
   117 // -----------------------------------------------------------------------------
       
   118 // CSipProfileAgentConfigRetriever::ExpiryValueL
       
   119 // -----------------------------------------------------------------------------
       
   120 //
       
   121 TUint CSipProfileAgentConfigRetriever::ExpiryValueL(
       
   122 		TSIPProfileTypeInfo::TSIPProfileClass aClass,
       
   123 		CSipProfileAgentConfigExtension::TProfileProperty aProperty)
       
   124 	{
       
   125 
       
   126 	if(!(aClass < TSIPProfileTypeInfo::EMaxSIPProfileClass) || 
       
   127 	    !(aProperty < CSipProfileAgentConfigExtension::EMaxProfileProperty))
       
   128 		{ 
       
   129 		return KIETFDefaultExpiryValue;
       
   130 		}
       
   131 	
       
   132 	TUint32 Val = 0;
       
   133 	
       
   134 	switch(aProperty)
       
   135 	    {
       
   136 	    case CSipProfileAgentConfigExtension::EProfileRegistrationValue:
       
   137 	        Val = iDefaultRegistrationValue[aClass];break;
       
   138 		case CSipProfileAgentConfigExtension::EProfileSubscriptionValue:
       
   139 		    Val = iDefaultSubscriptionValue[aClass];break;
       
   140 	    }
       
   141 	
       
   142 	if(0 == Val)
       
   143 	    {
       
   144 	    if(TSIPProfileTypeInfo::EIms == aClass)
       
   145 	        Val = KIMSDefaultExpiryValue;
       
   146 	    else
       
   147 	        Val = KIETFDefaultExpiryValue;
       
   148 	    }
       
   149 	return Val;
       
   150 	}
       
   151 
       
   152 // -----------------------------------------------------------------------------
       
   153 // CSipProfileAgentConfigRetriever::ReadValuesL
       
   154 // If the values read from repository are invalid, use the previous values.
       
   155 // -----------------------------------------------------------------------------
       
   156 //
       
   157 void CSipProfileAgentConfigRetriever::ReadValuesL()
       
   158 	{
       
   159 	RArray<TUint32> ProfilePropertiesTableKeys;
       
   160 	TUint ProfileType(0);
       
   161 	TUint Property(0);
       
   162 	TInt PptVal(0);
       
   163 	
       
   164 	iRepository->FindL(KSIPProfilePropertiesTable,KSIPProfileTableMask,
       
   165 			ProfilePropertiesTableKeys);
       
   166 	TInt count = ProfilePropertiesTableKeys.Count();
       
   167 	for(TUint16 i=0;i<count;i++)
       
   168 		{
       
   169 		ProfileType = (ProfilePropertiesTableKeys[i] & KSIPProfileTypeMask) >> 
       
   170 				KSIPProfileTypeShift;
       
   171 		Property = (ProfilePropertiesTableKeys[i] & KSIPProfilePropertyMask) >> 
       
   172 				KSIPProfilePropertyShift;
       
   173 		if((ProfileType-1) < TSIPProfileTypeInfo::EMaxSIPProfileClass &&
       
   174 				(Property-1) < CSipProfileAgentConfigExtension::EMaxProfileProperty)
       
   175 			{
       
   176 			User::LeaveIfError(iRepository->Get(
       
   177 					ProfilePropertiesTableKeys[i], PptVal));
       
   178 			iProfilePropertyKeys[ProfileType-1][Property-1] = 
       
   179 					ProfilePropertiesTableKeys[i];
       
   180 			switch(Property-1)
       
   181 			    {
       
   182 			    case CSipProfileAgentConfigExtension::EProfileRegistrationValue:
       
   183 			        iDefaultRegistrationValue[ProfileType-1] =  PptVal; break;
       
   184 			    case CSipProfileAgentConfigExtension::EProfileSubscriptionValue:
       
   185 			        iDefaultSubscriptionValue[ProfileType-1] =  PptVal; break;
       
   186 			    }
       
   187 			}
       
   188 		}
       
   189 	ProfilePropertiesTableKeys.Reset();
       
   190     }
       
   191 
       
   192 // -----------------------------------------------------------------------------
       
   193 // CSipProfileAgentConfigRetriever::ListenForChangesL
       
   194 // -----------------------------------------------------------------------------
       
   195 //
       
   196 void CSipProfileAgentConfigRetriever::ListenForChangesL()
       
   197 	{
       
   198 
       
   199 	const TUint32 KDummyPartialKey = 0x0;
       
   200 	//This mask means listening for all keys 
       
   201 	const TUint32 KMaskIncludingAllKeys = 0x0;
       
   202 
       
   203 	User::LeaveIfError(iRepository->NotifyRequest(KDummyPartialKey,
       
   204 												  KMaskIncludingAllKeys,
       
   205 												  iStatus));
       
   206 	SetActive();
       
   207 	}