networkprotocolmodules/networkprotocolmodule/LbsProtocolModule/src/cconfigmanager.cpp
changeset 36 b47902b73a93
parent 0 9cfd9a3ee49c
child 52 29dbbeac905d
equal deleted inserted replaced
35:a2efdd544abf 36:b47902b73a93
       
     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 // This file provides the implementation of the class that manages
       
    15 // configuration of Test Protocol Module operation.
       
    16 // 
       
    17 //
       
    18 
       
    19 #include <centralrepository.h>
       
    20 #include "cconfigmanager.h"
       
    21 
       
    22 /** Static constructor.
       
    23 @return A new instance of the CConfigManager class
       
    24 */  
       
    25 CConfigManager* CConfigManager::NewL()
       
    26 	{
       
    27 	CConfigManager* self = new (ELeave) CConfigManager();
       
    28 	CleanupStack::PushL(self);
       
    29 	self->ConstructL();
       
    30 	CleanupStack::Pop(self);
       
    31 	return self;
       
    32 	}
       
    33 
       
    34 
       
    35 /** Standard constructor.
       
    36 */  
       
    37 CConfigManager::CConfigManager()
       
    38 	{
       
    39 	}
       
    40 
       
    41 
       
    42 /** Standard destructor.
       
    43 */  
       
    44 CConfigManager::~CConfigManager()
       
    45 	{
       
    46 	iDecisionTable.Close();
       
    47 	}
       
    48 	
       
    49 	
       
    50 /** Private second-stage constructor.
       
    51 */  
       
    52 void CConfigManager::ConstructL()
       
    53 	{
       
    54 	LoadDecisionDataL();
       
    55 	}
       
    56 	
       
    57 	
       
    58 /** Load external decision table data.
       
    59 This retrieves decision table entries from the external data source which
       
    60 has been installed as part of the system configuration.
       
    61 
       
    62 This data is stored in the internal decision table in rows and columns
       
    63 that represent the current and new operations, respectively.
       
    64 */  
       
    65 void CConfigManager::LoadDecisionDataL()
       
    66 	{
       
    67 	// Pre-allocate table space
       
    68 	iDecisionTable.ReserveL(KMaxOperationTypes * KMaxOperationTypes);
       
    69 
       
    70 	// Open central repository
       
    71 	CRepository* repository = CRepository::NewLC(TUid::Uid(KMyRepositoryUid));
       
    72 
       
    73 	// For each row - current operation
       
    74 	for (TInt row = 0; row < KMaxOperationTypes; row++)
       
    75 		{
       
    76 		// For each column - new operation
       
    77 		for (TInt col = 0; col < KMaxOperationTypes; col++)
       
    78 			{
       
    79 			// Retrieve an item from central repository using a UID
       
    80 			// which is derived from the row and column numbers
       
    81 			TInt dataValue = -1;
       
    82 			TUint32 uid = (row * KMaxOperationTypes) + col + 1;
       
    83 			TConflictResult value = KDefaultDecision; // initialise to default
       
    84 			if (KErrNone == repository->Get(uid, dataValue))
       
    85 				{
       
    86 				// Convert entry value to decision value
       
    87 				switch (dataValue)
       
    88 					{
       
    89 				case 0:
       
    90 					value = EConflictRejectNew;
       
    91 					break;
       
    92 				case 1:
       
    93 #ifdef PM_HACK_FOR_INC103104				
       
    94 					value = EConflictRejectNew;
       
    95 #else
       
    96 					value = EConflictQueueNew;
       
    97 #endif //PM_HACK_FOR_INC103104
       
    98 					break;
       
    99 				case 2:
       
   100 					value = EConflictCancelCurrent;
       
   101 					break;
       
   102 				case 3:
       
   103 					value = EConflictQueueCurrent;
       
   104 					break;
       
   105 				default:
       
   106 					value = EConflictNone;
       
   107 					break;
       
   108 					};
       
   109 				}
       
   110 
       
   111 			iDecisionTable.Append(value);
       
   112 			}
       
   113 		}
       
   114 
       
   115 	// Close central repository
       
   116 	CleanupStack::PopAndDestroy(repository);
       
   117 	}
       
   118 	
       
   119 	
       
   120 /** Get conflict decision.
       
   121 Generates a conflict decision based on the nature of a current operation,
       
   122 and the nature of a new operation.
       
   123 
       
   124 @param aCurrentOp The current operation
       
   125 @param aNewOp The new operation for which a decision is required
       
   126 @return TConflictDecision The conflict decision:
       
   127 	EConflictNone			- This implies there is no current operation
       
   128 							  and the new operation is simply started
       
   129 	EConflictRejectNew		- The new operation is rejected and any
       
   130 							  current operation proceeds unaffected
       
   131 	EConflictQueueNew		- The new operation is queued awaiting
       
   132 							  completion of any current operation
       
   133 	EConflictCancelCurrent	- The current operation is cancelled and
       
   134 							  the new operation is started
       
   135 	EConflictQueueCurrent	- The current operation is queued an awaits
       
   136 							  the completion of the new operation
       
   137 */  
       
   138 CConfigManager::TConflictResult CConfigManager::ConflictDecision(const TConflictOperation& aCurrentOp, const TConflictOperation& aNewOp) const
       
   139 	{
       
   140 	TConflictResult result = KDefaultDecision; // initialise to default decision
       
   141 	TInt currentOpIndex;
       
   142 	TInt newOpIndex;
       
   143 
       
   144 	// Get table row index - current operation
       
   145 	currentOpIndex = DecisionTableIndex(aCurrentOp);
       
   146 	if (0 <= currentOpIndex)
       
   147 		{
       
   148 		// Get table column index - new operation
       
   149 		newOpIndex = DecisionTableIndex(aNewOp);
       
   150 		if (0 <= newOpIndex)
       
   151 			{
       
   152 			// Retrieve entry using row and column index values
       
   153 			result = iDecisionTable[(currentOpIndex*KMaxOperationTypes) + newOpIndex];
       
   154 			}
       
   155 		}
       
   156 
       
   157 	return result;
       
   158 	}
       
   159 
       
   160 
       
   161 /** Get an index for the specified operation.
       
   162 */
       
   163 TInt CConfigManager::DecisionTableIndex(const TConflictOperation& aOperation) const
       
   164 	{
       
   165 	TInt index = -1; // initialised to an invalid index
       
   166 
       
   167 	// What type of operation is specified?
       
   168 	switch (aOperation.iOperation)
       
   169 		{
       
   170 
       
   171 	case EOpMoLr:
       
   172 	case EOpNbLr:
       
   173 		index = KMoLr;
       
   174 		break;
       
   175 
       
   176 	case EOpMtLr:
       
   177 	case EOpNiLr:
       
   178 		if (EPriorityEmergency == aOperation.iPriority)
       
   179 			{
       
   180 			index = KEmergency;
       
   181 			}
       
   182 		else
       
   183 			{
       
   184 			index = KMtLr;
       
   185 			}
       
   186 		break;
       
   187 
       
   188 	case EOpX3p:
       
   189 		// What priority of X3P is specified?
       
   190 		switch (aOperation.iPriority)
       
   191 			{
       
   192 		case EPriorityLow:
       
   193 			index = KX3pLow;
       
   194 			break;
       
   195 
       
   196 		case EPriorityMedium:
       
   197 			index = KX3pMid;
       
   198 			break;
       
   199 
       
   200 		case EPriorityHigh:
       
   201 			index = KX3pHi;
       
   202 			break;
       
   203 
       
   204 		default:
       
   205 			break;
       
   206 			};
       
   207 		break;
       
   208 
       
   209 	default:
       
   210 		break;
       
   211 		};
       
   212 
       
   213 	return index;
       
   214 	}
       
   215