javaextensions/satsa/apdu/src.s60/cstschannelmanager.cpp
branchRCL_3
changeset 19 04becd199f91
equal deleted inserted replaced
16:f5050f1da672 19:04becd199f91
       
     1 /*
       
     2 * Copyright (c) 2008 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:
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 //  INCLUDE FILES
       
    20 #include "cstsapduexchanger.h"
       
    21 #include "cstschannelmanager.h"
       
    22 #include "cstsmanagechannel.h"
       
    23 #include "cstsmanagechannelresp.h"
       
    24 #include "stsapduconstants.h"
       
    25 #include "logger.h"
       
    26 
       
    27 namespace java
       
    28 {
       
    29 namespace satsa
       
    30 {
       
    31 
       
    32 // ============================ MEMBER FUNCTIONS ===============================
       
    33 
       
    34 // -----------------------------------------------------------------------------
       
    35 // CSTSChannelManager::CSTSChannelManager
       
    36 // C++ default constructor can NOT contain any code, that
       
    37 // might leave.
       
    38 // -----------------------------------------------------------------------------
       
    39 //
       
    40 CSTSChannelManager::CSTSChannelManager(CSTSApduExchanger* aApduExchanger)
       
    41 {
       
    42     iApduExchanger = aApduExchanger;
       
    43 }
       
    44 
       
    45 // -----------------------------------------------------------------------------
       
    46 // CSTSChannelManager::ConstructL
       
    47 // Symbian 2nd phase constructor can leave.
       
    48 // -----------------------------------------------------------------------------
       
    49 //
       
    50 void CSTSChannelManager::ConstructL()
       
    51 {
       
    52     iCmdApdu = CSTSManageChannel::NewL(0, //can be zero at first
       
    53                                        CSTSManageChannel::ESTSOpenChannel, CSTSApdu::ESTSUICC);
       
    54     iRespApdu = CSTSManageChannelResp::NewL(KSTSLogicalChannelsMax, //three in Open channel case
       
    55                                             CSTSApdu::ESTSUICC);
       
    56 
       
    57 }
       
    58 
       
    59 // -----------------------------------------------------------------------------
       
    60 // CSTSChannelManager::NewL
       
    61 // Two-phased constructor.
       
    62 // -----------------------------------------------------------------------------
       
    63 //
       
    64 CSTSChannelManager* CSTSChannelManager::NewL(CSTSApduExchanger* aApduExchanger)
       
    65 {
       
    66     CSTSChannelManager* self = new(ELeave) CSTSChannelManager(aApduExchanger);
       
    67 
       
    68     CleanupStack::PushL(self);
       
    69     self->ConstructL();
       
    70 
       
    71     CleanupStack::Pop(self);
       
    72     return self;
       
    73 }
       
    74 
       
    75 // Destructor
       
    76 CSTSChannelManager::~CSTSChannelManager()
       
    77 {
       
    78     delete iCmdApdu;
       
    79     delete iRespApdu;
       
    80 }
       
    81 
       
    82 // -----------------------------------------------------------------------------
       
    83 // CSTSChannelManager::RequestChannelL
       
    84 // Uses MANAGE CHANNEL APDU for opening any channel. Returns opened channel if
       
    85 // open was succesfull or otherwise leave code.
       
    86 // or KErrNotFound if there was no free channels
       
    87 // (other items were commented in a header).
       
    88 // -----------------------------------------------------------------------------
       
    89 //
       
    90 TInt CSTSChannelManager::RequestChannel()
       
    91 {
       
    92     LOG(ESATSA, EInfo, "+ CSTSChannelManager::RequestChannel");
       
    93     TInt returnValue;
       
    94 
       
    95     //channel number chan be left empty in open channel case
       
    96     iCmdApdu->SetApduType(CSTSManageChannel::ESTSOpenChannel, 0);
       
    97 
       
    98     returnValue = iApduExchanger->ExchangeApdu(*iCmdApdu, *iRespApdu);
       
    99 
       
   100     if (returnValue == KErrNone)
       
   101     {
       
   102         if (!iRespApdu->IsNormalEnding())
       
   103         {
       
   104             returnValue = KErrNotFound;
       
   105         }
       
   106         else
       
   107         {
       
   108             returnValue = iRespApdu->GetChannel();
       
   109         }
       
   110     }
       
   111     LOG(ESATSA, EInfo, "+ CSTSChannelManager::RequestChannel");
       
   112     return returnValue;
       
   113 
       
   114 }
       
   115 
       
   116 // -----------------------------------------------------------------------------
       
   117 // CSTSChannelManager::CloseChannelL
       
   118 // Uses manage channel apdu for closing the channel. Returns error code if
       
   119 // something was wrong.
       
   120 // (other items were commented in a header).
       
   121 // -----------------------------------------------------------------------------
       
   122 //
       
   123 TInt CSTSChannelManager::CloseChannel(TInt aChannel)
       
   124 {
       
   125     TInt err = KErrNone;
       
   126     //channel 0 can not be closed
       
   127     if (aChannel > 0)
       
   128     {
       
   129         iCmdApdu->SetApduType(CSTSManageChannel::ESTSCloseChannel, aChannel);
       
   130 
       
   131         err = iApduExchanger->ExchangeApdu(*iCmdApdu, *iRespApdu);
       
   132 
       
   133         if (err == KErrNone)
       
   134         {
       
   135             if (!iRespApdu->IsNormalEnding())
       
   136             {
       
   137                 err = KErrGeneral;
       
   138             }
       
   139         }
       
   140     }
       
   141     return err;
       
   142 }
       
   143 
       
   144 } // namespace satsa
       
   145 } // namespace java
       
   146 //  End of File
       
   147 
       
   148