usbuis/usbsettingsapp/src/usbuimodelactive.cpp
branchRCL_3
changeset 24 e02eb84a14d2
parent 23 25fce757be94
child 25 60826dff342d
equal deleted inserted replaced
23:25fce757be94 24:e02eb84a14d2
     1 /*
       
     2 * Copyright (c) 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: 
       
    15 *
       
    16 */
       
    17 
       
    18 #include "usbuimodelactive.h"
       
    19 #include "usbdebug.h"
       
    20 
       
    21 
       
    22 
       
    23 /*!
       
    24     Constructor.
       
    25  */
       
    26 UsbUiModelActive::UsbUiModelActive( int priority, QObject *parent )
       
    27 :   QObject( parent )
       
    28 {
       
    29     myDebug() << ">>> UsbUiModelActive::UsbUiModelActive";
       
    30     d = new UsbUiModelActivePrivate( this, priority );
       
    31     int err= iUsbWatcher.Connect();    
       
    32     myDebug() << "iUsbWatcher.Connect() returned ";
       
    33     myDebug() << err;  
       
    34     myDebug() << "<<< UsbUiModelActive::UsbUiModelActive";
       
    35 }
       
    36 
       
    37 /*!
       
    38     Destructor.
       
    39  */
       
    40 UsbUiModelActive::~UsbUiModelActive()
       
    41 {        
       
    42     myDebug() << ">>> UsbUiModelActive::~UsbUiModelActive";
       
    43     delete d;
       
    44     iUsbWatcher.Close(); 
       
    45     myDebug() << "<<< UsbUiModelActive::~UsbUiModelActive";
       
    46 }
       
    47 /*!
       
    48  * emits a signal when the request is completed
       
    49  */
       
    50 void UsbUiModelActive::emitRequestCompleted( int status )
       
    51 {
       
    52     myDebug() << ">>> UsbUiModelActive::emitRequestCompleted status: ";
       
    53     myDebug() << status; 
       
    54     emit requestCompleted( status );
       
    55     myDebug() << "<<< UsbUiModelActive::emitRequestCompleted";
       
    56 }
       
    57 
       
    58 /*!
       
    59  * Sets the the selected personality through usbwatcher
       
    60  */
       
    61 void UsbUiModelActive::SetUsbPersonality(int personality)
       
    62     {
       
    63     myDebug() << ">>> UsbUiModelActive::SetUsbPersonality";
       
    64     myDebug() << "requested personality is ";
       
    65     myDebug() << personality;   
       
    66     // Change the personality asynchrously, result checked in RunL()
       
    67     if( IsActive() ) 
       
    68         {
       
    69         Cancel();
       
    70         }
       
    71     myDebug() << "setting new personality";    
       
    72     iUsbWatcher.SetPersonality(RequestStatus(), personality);
       
    73     SetActive();
       
    74     myDebug() << "<<< UsbUiModelActive::SetUsbPersonality";
       
    75 
       
    76     }
       
    77 /*!
       
    78  * cancles the personality set in usbwatcher
       
    79  */
       
    80 void UsbUiModelActive::CancelSetPersonality()
       
    81     {
       
    82     iUsbWatcher.CancelSetPersonality();    
       
    83     }
       
    84 
       
    85 /*!
       
    86     Constructor.
       
    87  */
       
    88 UsbUiModelActivePrivate::UsbUiModelActivePrivate( 
       
    89         UsbUiModelActive *parent, int priority )
       
    90 :   CActive( (TInt) priority ), q( parent )
       
    91 {
       
    92     myDebug() << ">>> UsbUiModelActivePrivate::UsbUiModelActivePrivate";
       
    93     CActiveScheduler::Add( this );
       
    94     myDebug() << "<<< UsbUiModelActivePrivate::UsbUiModelActivePrivate";
       
    95 }
       
    96 
       
    97 
       
    98 /*!
       
    99     Destructor.
       
   100  */
       
   101 UsbUiModelActivePrivate::~UsbUiModelActivePrivate()
       
   102 {
       
   103     Cancel();
       
   104 }
       
   105 
       
   106 
       
   107 /*!
       
   108  *  Called by the active scheduler when the request has been completed.
       
   109  */
       
   110 void UsbUiModelActivePrivate::RunL()
       
   111 {
       
   112     myDebug() << ">>> UsbUiModelActivePrivate::RunL";
       
   113     q->emitRequestCompleted( iStatus.Int() );
       
   114     myDebug() << "<<< UsbUiModelActivePrivate::RunL";
       
   115 }
       
   116 
       
   117 
       
   118 /*!
       
   119     Called by the active scheduler when the request has been cancelled.
       
   120  */
       
   121 void UsbUiModelActivePrivate::DoCancel()
       
   122 {
       
   123     q->CancelSetPersonality();
       
   124 }
       
   125 
       
   126 
       
   127 /*!
       
   128     Called by the active scheduler when an error in RunL has occurred.
       
   129  */
       
   130 TInt UsbUiModelActivePrivate::RunError( TInt aError )
       
   131 {
       
   132     q->emitRequestCompleted( aError );
       
   133     return KErrNone;
       
   134 }