videocollection/hgmyvideos/src/vcxhgtelephonyclient.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Tue, 26 Jan 2010 12:00:59 +0200
changeset 1 6711b85517b7
parent 0 96612d01cf9f
permissions -rw-r--r--
Revision: 201001 Kit: 201004

/*
* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of the License "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description:      Implementation of a telephony client.*
*/




// INCLUDE FILES
#include <mmtsy_names.h>
#include <secui.h>
#include <secuisecurityhandler.h>

#include "vcxhgtelephonyclient.h"

// CONSTANTS
const TInt KTimeBeforeRetryingServerConnection = 50000;

// ============================ MEMBER FUNCTIONS =============================

// ---------------------------------------------------------------------------
// CVcxHgTelephonyClient::CVcxHgTelephonyClient()
// ---------------------------------------------------------------------------
//
CVcxHgTelephonyClient::CVcxHgTelephonyClient()
     : iPhoneConnected( EFalse )
    {
    }

// ---------------------------------------------------------------------------
// CVcxHgTelephonyClient::~CVcxHgTelephonyClient()
// ---------------------------------------------------------------------------
//
CVcxHgTelephonyClient::~CVcxHgTelephonyClient()
    {
    if ( iPhoneConnected )
        {
        // Close phone
        if ( iPhone.SubSessionHandle() )
            {
            iPhone.Close();
            }

        // Close ETel connection
        if ( iServer.Handle() )
            {
            iServer.UnloadPhoneModule( KMmTsyModuleName );
            iServer.Close();
            }
        }
    }
    
// ---------------------------------------------------------------------------
// CVcxHgTelephonyClient::CheckLockCodeL()
// ---------------------------------------------------------------------------
//   
TBool CVcxHgTelephonyClient::CheckLockCodeL()
    {
    TBool lockCodeAccepted = EFalse ;
    
    if ( !iPhoneConnected )
        {
        // Connect to ETel server
        // All server connections are retried because occasional
        // fails on connections are possible, at least on some servers.
        TInt err = iServer.Connect();
        if ( err != KErrNone )
            {
            User::After( KTimeBeforeRetryingServerConnection );
            TInt err = iServer.Connect();
            }
        User::LeaveIfError( err );
        User::LeaveIfError( iServer.SetExtendedErrorGranularity(
            RTelServer::EErrorExtended ) );

        // Load TSY.
        err = iServer.LoadPhoneModule( KMmTsyModuleName );
        if ( KErrAlreadyExists != err )
            {
            // May also return KErrAlreadyExists if something else
            // has already loaded the TSY module. And that is
            // not an error.
            User::LeaveIfError( err );
            }

        // Open phones
        User::LeaveIfError( iPhone.Open( iServer, KMmTsyPhoneName ) );
        iPhoneConnected = ETrue;
        }

#ifndef __WINS__
    // Initialize sec ui.
    CSecurityHandler* handler = new( ELeave ) CSecurityHandler( iPhone );
    CleanupStack::PushL( handler );
    TSecUi::InitializeLibL();

    lockCodeAccepted = handler->AskSecCodeL();

    // Uninitialize security ui.
    CleanupStack::PopAndDestroy( handler );
    TSecUi::UnInitializeLib();
#else
    lockCodeAccepted = ETrue;
#endif

    return lockCodeAccepted;
    }