pkiutilities/DeviceToken/Src/KeyStore/Server/DevCertKeyStoreSession.cpp
changeset 0 164170e6151a
equal deleted inserted replaced
-1:000000000000 0:164170e6151a
       
     1 /*
       
     2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:   Implementation of DevCertKeyStoreSession
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include "DevCertKeyStoreSession.h"
       
    21 #include "DevCertKeyStoreServer.h"
       
    22 #include "DevCertOpenedKeysSrv.h"
       
    23 
       
    24 
       
    25 // ======== MEMBER FUNCTIONS ========
       
    26 
       
    27 // ---------------------------------------------------------------------------
       
    28 // CDevCertKeyStoreSession::NewL()
       
    29 // ---------------------------------------------------------------------------
       
    30 // 
       
    31 CDevCertKeyStoreSession* CDevCertKeyStoreSession::NewL( CDevCertKeyStoreServer& aServer )
       
    32     {
       
    33     return new (ELeave) CDevCertKeyStoreSession( aServer );
       
    34     }
       
    35 
       
    36 
       
    37 // ---------------------------------------------------------------------------
       
    38 // CDevCertKeyStoreSession::CDevCertKeyStoreSession()
       
    39 // ---------------------------------------------------------------------------
       
    40 // 
       
    41 CDevCertKeyStoreSession::CDevCertKeyStoreSession(CDevCertKeyStoreServer& aServer )
       
    42   : iServer(aServer)
       
    43     {
       
    44     }
       
    45 
       
    46 
       
    47 // ---------------------------------------------------------------------------
       
    48 // CDevCertKeyStoreSession::~CDevCertKeyStoreSession()
       
    49 // ---------------------------------------------------------------------------
       
    50 //
       
    51 CDevCertKeyStoreSession::~CDevCertKeyStoreSession()
       
    52     {
       
    53     iServer.RemoveSession(*this);
       
    54 
       
    55     for (TInt i = 0 ; i < iOpenedKeys.Count() ; ++i)
       
    56         {
       
    57         CDevCertOpenedKeySrv* object = iOpenedKeys[i].iObject;
       
    58         delete object;
       
    59         }
       
    60     iOpenedKeys.Close();
       
    61     }
       
    62 
       
    63 
       
    64 // ---------------------------------------------------------------------------
       
    65 // CDevCertKeyStoreSession::DoServiceL()
       
    66 // ---------------------------------------------------------------------------
       
    67 //
       
    68 void CDevCertKeyStoreSession::DoServiceL(const RMessage2& aMessage)
       
    69     {
       
    70     iServer.ServiceRequestL(aMessage, *this);
       
    71     }
       
    72 
       
    73 
       
    74 // ---------------------------------------------------------------------------
       
    75 // CDevCertKeyStoreSession::AddOpenedKeyL()
       
    76 // ---------------------------------------------------------------------------
       
    77 //
       
    78 TInt CDevCertKeyStoreSession::AddOpenedKeyL(CDevCertOpenedKeySrv& aObject)
       
    79     {
       
    80     TObjectIndex oi;
       
    81     oi.iObject = &aObject;
       
    82     oi.iHandle = ++iLastHandle;
       
    83     User::LeaveIfError(iOpenedKeys.InsertInSignedKeyOrder(oi));
       
    84     return oi.iHandle;
       
    85     }
       
    86 
       
    87 
       
    88 // ---------------------------------------------------------------------------
       
    89 // CDevCertKeyStoreSession::RemoveOpenedKeyL()
       
    90 // ---------------------------------------------------------------------------
       
    91 //
       
    92 void CDevCertKeyStoreSession::RemoveOpenedKeyL(TInt aHandle)
       
    93     {
       
    94     TObjectIndex oi;
       
    95     oi.iHandle = aHandle;
       
    96     TInt pos = iOpenedKeys.Find(oi);
       
    97     User::LeaveIfError(pos);
       
    98     delete iOpenedKeys[pos].iObject;
       
    99     iOpenedKeys.Remove(pos);  
       
   100     }
       
   101 
       
   102 
       
   103 // ---------------------------------------------------------------------------
       
   104 // CDevCertKeyStoreSession::OpenedKey()
       
   105 // ---------------------------------------------------------------------------
       
   106 //
       
   107 CDevCertOpenedKeySrv* CDevCertKeyStoreSession::OpenedKey(TInt aHandle)
       
   108     {
       
   109     TObjectIndex oi;
       
   110     oi.iHandle = aHandle;
       
   111     TInt pos = iOpenedKeys.Find(oi);
       
   112     return (pos != KErrNotFound) ? iOpenedKeys[pos].iObject : NULL;
       
   113     }
       
   114 
       
   115 
       
   116 // ---------------------------------------------------------------------------
       
   117 // CDevCertKeyStoreSession::HasOpenKey()
       
   118 // ---------------------------------------------------------------------------
       
   119 //
       
   120 TBool CDevCertKeyStoreSession::HasOpenKey(TInt aHandle)
       
   121     {
       
   122     TBool result = EFalse;
       
   123     for (TInt i = 0 ; i < iOpenedKeys.Count() ; ++i)
       
   124         {
       
   125         CDevCertOpenedKeySrv* object = iOpenedKeys[i].iObject;
       
   126         if (object->Handle() == aHandle)
       
   127             {
       
   128             result = ETrue;
       
   129             break;
       
   130             }
       
   131         }
       
   132     return result;
       
   133     }
       
   134 
       
   135 //EOF
       
   136