backupandrestore/backupengine/src/absessionmap.cpp
changeset 0 d0791faffa3f
child 15 f85613f12947
equal deleted inserted replaced
-1:000000000000 0:d0791faffa3f
       
     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 // Implementations of CABSessionMap and CABSessionElement classes.
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20 */
       
    21 
       
    22 #include "absession.h"
       
    23 #include "absessionmap.h"
       
    24 #include "sbedataowner.h"
       
    25 #include <connect/panic.h>
       
    26 
       
    27 namespace conn
       
    28 	{
       
    29 	
       
    30 	CABSessionElement::CABSessionElement(TSecureId aSecureId) : iKey(aSecureId), iValue(NULL)
       
    31     /**
       
    32     Class Constructor
       
    33 
       
    34 	@param aSecureId The secure Id of the data owner that the session has been created for    
       
    35 	*/
       
    36 		{
       
    37 		}
       
    38 
       
    39 	CABSessionElement::~CABSessionElement()
       
    40     /**
       
    41     Class destructor
       
    42     */
       
    43 		{
       
    44 		}
       
    45 
       
    46 	CABSessionElement* CABSessionElement::NewL(TSecureId aSecureId)
       
    47 	/**
       
    48 	Symbian first phase constructor
       
    49 	@param aSecureId The secure Id of the data owner that the session has been created for
       
    50 	*/
       
    51 		{
       
    52 		CABSessionElement* self = new (ELeave) CABSessionElement(aSecureId);
       
    53 		CleanupStack::PushL(self);
       
    54 		self->ConstructL();
       
    55 		CleanupStack::Pop(self);
       
    56 		return self;
       
    57 		}
       
    58 		
       
    59 	void CABSessionElement::ConstructL()
       
    60 	/**
       
    61 	Create the session for the data owner specified by iKey
       
    62 	*/
       
    63 		{
       
    64 		// Note that the server takes ownership of the session, not this object
       
    65 		iValue = CABSession::NewL(iKey);
       
    66 		}
       
    67 					
       
    68 	CABSessionMap* CABSessionMap::NewL()
       
    69 	/**
       
    70 	Symbian first phase constructor
       
    71 	
       
    72 	@return Pointer to a created CABSessionMap object
       
    73 	*/
       
    74 		{
       
    75 		CABSessionMap* self = new (ELeave) CABSessionMap;
       
    76 		return self;
       
    77 		}
       
    78 		
       
    79 	CABSession& CABSessionMap::CreateL(TSecureId aSecureId)
       
    80 	/**
       
    81 	Create a new element and session, returning that session if required
       
    82 	
       
    83 	@param aSecureId The SID to initialise the session with
       
    84 	@return Reference to the created session
       
    85 	*/
       
    86 		{
       
    87 		CABSessionElement* element = CABSessionElement::NewL(aSecureId);
       
    88 		CleanupStack::PushL(element);
       
    89 		iMapElements.AppendL(element);
       
    90 		CleanupStack::Pop(element);
       
    91 		return element->Value();
       
    92 		}
       
    93 		
       
    94 	void CABSessionMap::Delete(TSecureId aSecureId)
       
    95 	/**
       
    96 	Delete the session and remove it from the map
       
    97 	
       
    98 	@param aSecureId The key to the session to be deleted
       
    99 	*/
       
   100 		{
       
   101 		TInt count = iMapElements.Count();
       
   102 		
       
   103 		for (TInt index = 0; index < count; index++)
       
   104 			{
       
   105 			if (iMapElements[index]->Key() == aSecureId)
       
   106 				{
       
   107 				delete iMapElements[index];
       
   108 				iMapElements.Remove(index);
       
   109 				
       
   110 				break;
       
   111 				}
       
   112 			}
       
   113 		}
       
   114 		
       
   115 	CABSession& CABSessionMap::SessionL(TSecureId aSecureId)
       
   116 	/**
       
   117 	Accessor for the session using the SID as the key
       
   118 	
       
   119 	@param aSecureId The SID of the DO that's connected to the returned session
       
   120 	@leave KErrNotFound If no session exists for that SID
       
   121 	@return The session that the DO with SID aSecureId is connected to
       
   122 	*/
       
   123 		{
       
   124 		TInt count = iMapElements.Count();
       
   125 		CABSession* pSession = NULL;
       
   126 		
       
   127 		for (TInt index = 0; index < count; index++)
       
   128 			{
       
   129 			if (iMapElements[index]->Key() == aSecureId)
       
   130 				{
       
   131 				pSession = &iMapElements[index]->Value();
       
   132 				
       
   133 				break;
       
   134 				}
       
   135 			}
       
   136 			
       
   137 		if (!pSession)
       
   138 			{
       
   139 			User::Leave(KErrNotFound);
       
   140 			}
       
   141 		
       
   142 		return *pSession;
       
   143 		}
       
   144 
       
   145 	CABSessionMap::CABSessionMap()
       
   146     /**
       
   147     Class Constructor
       
   148     */
       
   149 		{
       
   150 		}
       
   151 
       
   152 	CABSessionMap::~CABSessionMap()
       
   153     /**
       
   154     Class destructor
       
   155     */
       
   156 		{
       
   157 		iMapElements.ResetAndDestroy();
       
   158 		iMapElements.Close();
       
   159 		}
       
   160 	
       
   161 	void CABSessionMap::InvalidateABSessions()
       
   162 	/** 
       
   163 	Set each CABSession currently hold in the map as invalid
       
   164 	*/ 
       
   165 		{
       
   166 		TInt count = iMapElements.Count();
       
   167 		CABSession* pSession = NULL;
       
   168 					
       
   169 		for (TInt index = 0; index < count; index++)
       
   170 			{
       
   171 			pSession = &iMapElements[index]->Value();
       
   172 			if (pSession)
       
   173 				{
       
   174 				pSession->SetInvalid();
       
   175 				}
       
   176 			}
       
   177 		}
       
   178 	}