radioapp/radiouiengine/src/radioscannerengine_p.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Fri, 11 Jun 2010 13:38:32 +0300
changeset 28 075425b8d9a4
parent 24 6df133bd92e1
child 32 189d20c34778
permissions -rw-r--r--
Revision: 201021 Kit: 2010123
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     1
/*
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     3
* All rights reserved.
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     4
* This component and the accompanying materials are made available
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     6
* which accompanies this distribution, and is available
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     8
*
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     9
* Initial Contributors:
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    11
*
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    12
* Contributors:
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    13
*
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    14
* Description:
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    15
*
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    16
*/
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    17
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    18
// User includes
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    19
#include "radioscannerengine_p.h"
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    20
#include "radioscannerengine.h"
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    21
#include "radiouiengine_p.h"
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    22
#include "radiouiengine.h"
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    23
#include "radiostationhandlerif.h"
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    24
#include "radioenginewrapper.h"
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    25
#include "radiostation.h"
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    26
#include "radiostationmodel.h"
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    27
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    28
/*!
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    29
 *
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    30
 * @param scanner
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    31
 * @param uiEngine
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    32
 */
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    33
RadioScannerEnginePrivate::RadioScannerEnginePrivate( RadioScannerEngine* scanner, RadioUiEnginePrivate& uiEngine ) :
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    34
    q_ptr( scanner ),
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    35
    mUiEngine( uiEngine ),
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    36
    mLastFoundFrequency( 0 ),
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    37
    mMutedByScanner( false ),
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    38
    mIsScanning( false )
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    39
{
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    40
    mUiEngine.wrapper().addObserver( this );
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    41
}
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    42
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    43
/*!
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    44
 *
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    45
 */
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    46
RadioScannerEnginePrivate::~RadioScannerEnginePrivate()
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    47
{
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    48
    mUiEngine.wrapper().removeObserver( this );
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    49
}
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    50
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    51
/*!
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    52
 * \reimp
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    53
 */
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    54
void RadioScannerEnginePrivate::tunedToFrequency( uint frequency, int reason )
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    55
{
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    56
    if ( !mIsScanning ) {
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    57
        return;
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    58
    }
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    59
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    60
    Q_Q( RadioScannerEngine );
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    61
    if ( reason == TuneReason::StationScanInitialization ) {
28
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 24
diff changeset
    62
        mUiEngine.wrapper().startSeeking( Seek::Up, TuneReason::StationScan );
24
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    63
    } else if ( reason == TuneReason::StationScan ) {
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    64
        if ( frequency > mLastFoundFrequency ) {
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    65
            // Station has been found normally
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    66
            mLastFoundFrequency = frequency;
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    67
            addFrequencyAndReport( frequency );
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    68
        } else if ( frequency == mUiEngine.api().minFrequency() ) {
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    69
            // Special case. A station has been found in the mininmum frequency
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    70
            addFrequencyAndReport( frequency );
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    71
        } else {
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    72
            // Seeking looped around the frequency band. Send invalid station as indicator that the scanning should stop
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    73
            q->emitStationFound( RadioStation() );
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    74
        }
28
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 24
diff changeset
    75
    } else {
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 24
diff changeset
    76
        q->emitStationFound( RadioStation() );
24
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    77
    }
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    78
}
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    79
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    80
/*!
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    81
 *
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    82
 */
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    83
void RadioScannerEnginePrivate::addFrequencyAndReport( const uint frequency )
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    84
{
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    85
    RadioStationModel& stationModel = mUiEngine.api().stationModel();
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    86
    stationModel.stationHandlerIf().addScannedFrequency( frequency );
28
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 24
diff changeset
    87
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 24
diff changeset
    88
    // Return value of findFrequency() is intentionally ignored. The station was just added
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 24
diff changeset
    89
    // to the model in the previous line so it should be found and if it isn't then an
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 24
diff changeset
    90
    // empty station is sent with the signal and scanner will stop the scanning process.
24
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    91
    RadioStation station;
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    92
    stationModel.findFrequency( frequency, station );
28
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 24
diff changeset
    93
24
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    94
    Q_Q( RadioScannerEngine );
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    95
    q->emitStationFound( station );
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    96
}
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    97