cpsecplugins/cpadvancedsecplugin/src/cpsecmodsyncwrapper.cpp
branchRCL_3
changeset 22 03674e5abf46
parent 21 09b1ac925e3f
child 23 94da73d93b58
equal deleted inserted replaced
21:09b1ac925e3f 22:03674e5abf46
     1 /*
       
     2 * Copyright (c) 2005-2010 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 the CSecModUISyncWrapper class
       
    15 *                Implements a synchronous wrapper for easier use of Symbian's
       
    16 *                Security Frameworks's API's.
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 #include "cpsecmodsyncwrapper.h"
       
    22 #include <ct/ccttokentypeinfo.h>
       
    23 #include <ct/mcttokentype.h>
       
    24 #include <ct/ccttokentype.h>
       
    25 #include <ct/tcttokenobjecthandle.h>
       
    26 #include <mctauthobject.h>
       
    27 #include <unifiedkeystore.h>
       
    28 #include <mctkeystore.h>
       
    29 #include <../../inc/cpsecplugins.h>
       
    30 
       
    31 
       
    32 // ============================ MEMBER FUNCTIONS ===============================
       
    33 
       
    34 // -----------------------------------------------------------------------------
       
    35 // CSecModUISyncWrapper::CSecModUISyncWrapper()
       
    36 // C++ default constructor can NOT contain any code, that
       
    37 // might leave.
       
    38 // -----------------------------------------------------------------------------
       
    39 //
       
    40 CSecModUISyncWrapper::CSecModUISyncWrapper() : CActive( EPriorityStandard )
       
    41     {
       
    42     CActiveScheduler::Add(this);
       
    43     }
       
    44 
       
    45 
       
    46 // -----------------------------------------------------------------------------
       
    47 // CSecModUISyncWrapper::NewLC
       
    48 // Two-phased constructor.
       
    49 // -----------------------------------------------------------------------------
       
    50 //
       
    51 CSecModUISyncWrapper* CSecModUISyncWrapper::NewLC()
       
    52     {
       
    53     CSecModUISyncWrapper* wrap = new (ELeave) CSecModUISyncWrapper();
       
    54     CleanupStack::PushL(wrap);
       
    55     return wrap;
       
    56     }
       
    57 
       
    58 // -----------------------------------------------------------------------------
       
    59 // CSecModUISyncWrapper::NewL
       
    60 // Two-phased constructor.
       
    61 // -----------------------------------------------------------------------------
       
    62 //
       
    63 CSecModUISyncWrapper* CSecModUISyncWrapper::NewL()
       
    64     {
       
    65     RDEBUG("0", 0);
       
    66     CSecModUISyncWrapper* wrap = CSecModUISyncWrapper::NewLC();
       
    67     CleanupStack::Pop(wrap);
       
    68     return wrap;
       
    69     }
       
    70 
       
    71 // Destructor
       
    72 CSecModUISyncWrapper::~CSecModUISyncWrapper()
       
    73     {
       
    74     Cancel();
       
    75     iOperation = EOperationNone;
       
    76     }
       
    77 
       
    78 // -----------------------------------------------------------------------------
       
    79 // CSecModUISyncWrapper::Initialize(CUnifiedKeyStore& aKeyStore)
       
    80 // Two-phased constructor.
       
    81 // -----------------------------------------------------------------------------
       
    82 //
       
    83 
       
    84 TInt CSecModUISyncWrapper::Initialize(CUnifiedKeyStore& aKeyStore)
       
    85     {
       
    86     if( !IsActive() && !iWait.IsStarted() )
       
    87         {
       
    88         iOperation = EOperationInit;
       
    89         iObject = STATIC_CAST(TAny*, &aKeyStore);
       
    90         aKeyStore.Initialize(iStatus);
       
    91         SetActive();
       
    92         iWait.Start();
       
    93         iOperation = EOperationNone;
       
    94         return iStatus.Int();
       
    95         }
       
    96     return KErrInUse;
       
    97     }
       
    98 
       
    99 // -----------------------------------------------------------------------------
       
   100 // CSecModUIModel::GetAuthObjectInterface(...)
       
   101 // -----------------------------------------------------------------------------
       
   102 //
       
   103 TInt CSecModUISyncWrapper::GetAuthObjectInterface(
       
   104     MCTToken& aToken, MCTTokenInterface*& aTokenInterface)
       
   105     {
       
   106     RDEBUG("0", 0);
       
   107     if( !IsActive() && !iWait.IsStarted() )
       
   108         {
       
   109         iOperation = EOperationGetAOInterface;
       
   110         iObject = STATIC_CAST(TAny*, &aToken);
       
   111         const TUid KUidInterfaceAO = { KCTInterfaceAuthenticationObject };
       
   112         aToken.GetInterface(KUidInterfaceAO, aTokenInterface, iStatus);
       
   113         iOperation = EOperationGetAOInterface;
       
   114         SetActive();
       
   115         iWait.Start();
       
   116         iOperation = EOperationNone;
       
   117         return iStatus.Int();
       
   118         }
       
   119     return KErrInUse;
       
   120     }
       
   121 
       
   122 // -----------------------------------------------------------------------------
       
   123 // CSecModUISyncWrapper::ListAuthObjects(...)
       
   124 // -----------------------------------------------------------------------------
       
   125 //
       
   126 TInt CSecModUISyncWrapper::ListAuthObjects(
       
   127     MCTAuthenticationObjectList& aAuthObjList,
       
   128     RMPointerArray<MCTAuthenticationObject>& aAuthObjects)
       
   129     {
       
   130     if( !IsActive() && !iWait.IsStarted() )
       
   131         {
       
   132         iOperation = EOperationListAOs;
       
   133         iObject = STATIC_CAST(TAny*, &aAuthObjList);
       
   134         aAuthObjList.List( aAuthObjects, iStatus );
       
   135         iOperation = EOperationListAOs;
       
   136         SetActive();
       
   137         iWait.Start();
       
   138         iOperation = EOperationNone;
       
   139         return iStatus.Int();
       
   140         }
       
   141     return KErrInUse;
       
   142     }
       
   143 
       
   144 // -----------------------------------------------------------------------------
       
   145 // CSecModUISyncWrapper::ListKeys(...)
       
   146 // -----------------------------------------------------------------------------
       
   147 //
       
   148 TInt CSecModUISyncWrapper::ListKeys(
       
   149     MCTKeyStore& aKeyStore,
       
   150     RMPointerArray<CCTKeyInfo>& aKeysInfos,
       
   151     const TCTKeyAttributeFilter& aFilter)
       
   152     {
       
   153     RDEBUG("0", 0);
       
   154     if( !IsActive() && !iWait.IsStarted() )
       
   155         {
       
   156         iOperation = EOperationListKeys;
       
   157         iObject = STATIC_CAST(TAny*, &aKeyStore);
       
   158         aKeyStore.List(aKeysInfos, aFilter, iStatus);
       
   159         SetActive();
       
   160         iWait.Start();
       
   161         iOperation = EOperationNone;
       
   162         return iStatus.Int();
       
   163         }
       
   164     return KErrInUse;
       
   165     }
       
   166 
       
   167 // -----------------------------------------------------------------------------
       
   168 // CSecModUISyncWrapper::DeleteKey(...)
       
   169 // -----------------------------------------------------------------------------
       
   170 //
       
   171 TInt CSecModUISyncWrapper::DeleteKey(
       
   172     CUnifiedKeyStore& aKeyStore,
       
   173     TCTTokenObjectHandle aHandle)
       
   174     {
       
   175     RDEBUG("0", 0);
       
   176     if( !IsActive() && !iWait.IsStarted() )
       
   177         {
       
   178         iOperation = EOperationDelKey;
       
   179         iObject = STATIC_CAST(TAny*, &aKeyStore);
       
   180         aKeyStore.DeleteKey(aHandle, iStatus);
       
   181         SetActive();
       
   182         iWait.Start();
       
   183         iOperation = EOperationNone;
       
   184         return iStatus.Int();
       
   185         }
       
   186     return KErrInUse;
       
   187     }
       
   188 
       
   189 // -----------------------------------------------------------------------------
       
   190 // CSecModUISyncWrapper::ChangeReferenceData(MCTAuthenticationObject& aAuthObject)
       
   191 // -----------------------------------------------------------------------------
       
   192 //
       
   193 TInt CSecModUISyncWrapper::ChangeReferenceData(
       
   194     MCTAuthenticationObject& aAuthObject)
       
   195     {
       
   196     RDEBUG("0", 0);
       
   197     if( !IsActive() && !iWait.IsStarted() )
       
   198         {
       
   199         iOperation = EOperationChangeReferenceData;
       
   200         iObject = STATIC_CAST(TAny*, &aAuthObject);
       
   201         aAuthObject.ChangeReferenceData(iStatus);
       
   202         SetActive();
       
   203         iWait.Start();
       
   204         iOperation = EOperationNone;
       
   205         return iStatus.Int();
       
   206         }
       
   207     return KErrInUse;
       
   208     }
       
   209 
       
   210 // -----------------------------------------------------------------------------
       
   211 // CSecModUIModel::UnblockAuthObject(MCTAuthenticationObject& aAuthObject)
       
   212 // -----------------------------------------------------------------------------
       
   213 //
       
   214 TInt CSecModUISyncWrapper::UnblockAuthObject(
       
   215     MCTAuthenticationObject& aAuthObject)
       
   216     {
       
   217     RDEBUG("0", 0);
       
   218     if( !IsActive() && !iWait.IsStarted() )
       
   219         {
       
   220         iOperation = EOperationUnblockAO;
       
   221         iObject = STATIC_CAST(TAny*, &aAuthObject);
       
   222         aAuthObject.Unblock(iStatus);
       
   223         SetActive();
       
   224         iWait.Start();
       
   225         iOperation = EOperationNone;
       
   226         return iStatus.Int();
       
   227         }
       
   228     return KErrInUse;
       
   229     }
       
   230 
       
   231 // -----------------------------------------------------------------------------
       
   232 // CSecModUIModel::EnableAuthObject(MCTAuthenticationObject& aAuthObject)
       
   233 // -----------------------------------------------------------------------------
       
   234 //
       
   235 TInt CSecModUISyncWrapper::EnableAuthObject(
       
   236     MCTAuthenticationObject& aAuthObject)
       
   237     {
       
   238     RDEBUG("0", 0);
       
   239     if( !IsActive() && !iWait.IsStarted() )
       
   240         {
       
   241         iOperation = EOperationEnableAO;
       
   242         iObject = STATIC_CAST(TAny*, &aAuthObject);
       
   243         aAuthObject.Enable(iStatus);
       
   244         iOperation = EOperationUnblockAO;
       
   245         SetActive();
       
   246         iWait.Start();
       
   247         iOperation = EOperationNone;
       
   248         return iStatus.Int();
       
   249         }
       
   250     return KErrInUse;
       
   251     }
       
   252 
       
   253 // -----------------------------------------------------------------------------
       
   254 // CSecModUIModel::DisableAuthObject(MCTAuthenticationObject& aAuthObject)
       
   255 // -----------------------------------------------------------------------------
       
   256 //
       
   257 TInt CSecModUISyncWrapper::DisableAuthObject(
       
   258     MCTAuthenticationObject& aAuthObject)
       
   259     {
       
   260     if( !IsActive() && !iWait.IsStarted() )
       
   261         {
       
   262         iOperation = EOperationDisableAO;
       
   263         iObject = STATIC_CAST(TAny*, &aAuthObject);
       
   264         aAuthObject.Disable(iStatus);
       
   265         SetActive();
       
   266         iWait.Start();
       
   267         iOperation = EOperationNone;
       
   268         return iStatus.Int();
       
   269         }
       
   270     return KErrInUse;
       
   271     }
       
   272 
       
   273 // -----------------------------------------------------------------------------
       
   274 // CSecModUISyncWrapper::CloseAuthObject(MCTAuthenticationObject& aAuthObject)
       
   275 // -----------------------------------------------------------------------------
       
   276 //
       
   277 TInt CSecModUISyncWrapper::CloseAuthObject(
       
   278     MCTAuthenticationObject& aAuthObject)
       
   279     {
       
   280     if( !IsActive() && !iWait.IsStarted() )
       
   281         {
       
   282         iOperation = EOperationCloseAO;
       
   283         iObject = STATIC_CAST(TAny*, &aAuthObject);
       
   284         aAuthObject.Close(iStatus);
       
   285         SetActive();
       
   286         iWait.Start();
       
   287         iOperation = EOperationNone;
       
   288         return iStatus.Int();
       
   289         }
       
   290     return KErrInUse;
       
   291     }
       
   292 
       
   293 // -----------------------------------------------------------------------------
       
   294 // CSecModUIModel::TimeRemaining(...)
       
   295 // -----------------------------------------------------------------------------
       
   296 //
       
   297 TInt CSecModUISyncWrapper::TimeRemaining(
       
   298     MCTAuthenticationObject& aAuthObject,
       
   299     TInt& aStime )
       
   300     {
       
   301     RDEBUG("0", 0);
       
   302     if( !IsActive() && !iWait.IsStarted() )
       
   303         {
       
   304         iOperation = EOperationTimeRemAO;
       
   305         iObject = STATIC_CAST(TAny*, &aAuthObject);
       
   306         aAuthObject.TimeRemaining(aStime, iStatus);
       
   307         SetActive();
       
   308         iWait.Start();
       
   309         iOperation = EOperationNone;
       
   310         return iStatus.Int();
       
   311         }
       
   312     return KErrInUse;
       
   313     }
       
   314 
       
   315 // -----------------------------------------------------------------------------
       
   316 // CSecModUISyncWrapper::DoCancel
       
   317 // Cancels the ongoing operation if possible.
       
   318 // -----------------------------------------------------------------------------
       
   319 //
       
   320 void CSecModUISyncWrapper::DoCancel()
       
   321     {
       
   322     RDEBUG("iOperation", iOperation);
       
   323     switch ( iOperation )
       
   324         {
       
   325         case EOperationInit:
       
   326             {
       
   327             STATIC_CAST(CUnifiedKeyStore*, iObject)->CancelInitialize();
       
   328             break;
       
   329             }
       
   330         case EOperationGetAOInterface:
       
   331             {
       
   332             STATIC_CAST(MCTToken*, iObject)->CancelGetInterface();
       
   333             break;
       
   334             }
       
   335         case EOperationListAOs:
       
   336             {
       
   337             STATIC_CAST(MCTAuthenticationObjectList*, iObject)->CancelList();
       
   338             break;
       
   339             }
       
   340         case EOperationListKeys:
       
   341             {
       
   342             STATIC_CAST(MCTKeyStore*, iObject)->CancelList();
       
   343             break;
       
   344             }
       
   345         case EOperationDelKey:
       
   346             {
       
   347             STATIC_CAST(CUnifiedKeyStore*, iObject)->CancelDeleteKey();
       
   348             break;
       
   349             }
       
   350         case EOperationChangeReferenceData:
       
   351             {
       
   352             STATIC_CAST(MCTAuthenticationObject*, iObject)->
       
   353                 CancelChangeReferenceData();
       
   354             break;
       
   355             }
       
   356         case EOperationUnblockAO:
       
   357             {
       
   358             STATIC_CAST(MCTAuthenticationObject*, iObject)->CancelUnblock();
       
   359             break;
       
   360             }
       
   361         case EOperationEnableAO:
       
   362             {
       
   363             STATIC_CAST(MCTAuthenticationObject*, iObject)->CancelEnable();
       
   364             break;
       
   365             }
       
   366         case EOperationDisableAO:
       
   367             {
       
   368             STATIC_CAST(MCTAuthenticationObject*, iObject)->CancelDisable();
       
   369             break;
       
   370             }
       
   371         case EOperationCloseAO:
       
   372             {
       
   373             STATIC_CAST(MCTAuthenticationObject*, iObject)->CancelClose();
       
   374             break;
       
   375             }
       
   376         case EOperationTimeRemAO:
       
   377             {
       
   378             STATIC_CAST(MCTAuthenticationObject*, iObject)->CancelTimeRemaining();
       
   379             break;
       
   380             }
       
   381         default:
       
   382             {
       
   383             break;
       
   384             }
       
   385         }
       
   386     if (iWait.IsStarted())
       
   387         {
       
   388         iWait.AsyncStop();
       
   389         }
       
   390     }
       
   391 
       
   392 // -----------------------------------------------------------------------------
       
   393 // CSecModUISyncWrapper::RunL
       
   394 // If no errors happened, stop. Show an error note if needed.
       
   395 // -----------------------------------------------------------------------------
       
   396 //
       
   397 void CSecModUISyncWrapper::RunL()
       
   398     {
       
   399     iWait.AsyncStop();
       
   400     }
       
   401