upnpframework/upnpcommand/src/upnpbrowsetask.cpp
changeset 0 7f85d04be362
equal deleted inserted replaced
-1:000000000000 0:7f85d04be362
       
     1 /*
       
     2 * Copyright (c) 2007 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:  Source file for CUpnpBrowseTask class.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 // upnpframework / avcontroller api
       
    21 #include "upnpavcontrollerfactory.h"    // UPnPAVControllerFactory
       
    22 #include "upnpavcontroller.h"           // MUPnPAVController
       
    23 
       
    24 // upnpframework / commonui api's
       
    25 #include "upnpcommonui.h"
       
    26 
       
    27 // command internal
       
    28 #include "upnpfilepipe.h"               // CUpnpFilePipe
       
    29 #include "upnpcommandparameters.h"      // CUpnpCommandParameters
       
    30 #include "upnptaskhandler.h"            // MUpnpTaskHandler
       
    31 #include "upnpnotehandler.h"            // CUpnpNoteHandler
       
    32 #include "upnpbrowsetask.h"
       
    33 #include "upnpcommand.h"
       
    34 
       
    35 _LIT( KComponentLogfile, "upnpcommand.log");
       
    36 #include "upnplog.h"
       
    37 
       
    38 // --------------------------------------------------------------------------
       
    39 // CUpnpBrowseTask::NewL
       
    40 // Creates an instance of the implementation.
       
    41 // --------------------------------------------------------------------------
       
    42 //
       
    43 CUpnpTask* CUpnpBrowseTask::NewL()
       
    44     {
       
    45     __LOG( "[UpnpCommand]\t CUpnpBrowseTask::NewL" );
       
    46 
       
    47     // Create instance
       
    48     CUpnpBrowseTask* self = NULL;
       
    49     self = new (ELeave) CUpnpBrowseTask();
       
    50     CleanupStack::PushL( self );
       
    51     self->ConstructL();
       
    52     CleanupStack::Pop( self );
       
    53 
       
    54     // Cast the object and return
       
    55     return (CUpnpTask*)self;
       
    56     }
       
    57 
       
    58 // --------------------------------------------------------------------------
       
    59 // CUpnpBrowseTask::CUpnpBrowseTask
       
    60 // First phase construction.
       
    61 // --------------------------------------------------------------------------
       
    62 //
       
    63 CUpnpBrowseTask::CUpnpBrowseTask()
       
    64     {
       
    65     __LOG( "[UpnpCommand]\t CUpnpBrowseTask::Constructor" );
       
    66 
       
    67     // Initialise member variables
       
    68     iAVController = NULL;
       
    69     }
       
    70 
       
    71 // --------------------------------------------------------------------------
       
    72 // Destructor.
       
    73 // --------------------------------------------------------------------------
       
    74 //
       
    75 CUpnpBrowseTask::~CUpnpBrowseTask()
       
    76     {
       
    77     __LOG( "[UpnpCommand]\t CUpnpBrowseTask::Destructor" );
       
    78     }
       
    79 
       
    80 // --------------------------------------------------------------------------
       
    81 // CUpnpBrowseTask::ConstructL
       
    82 // Perform the second phase of two phase construction. Reserves the Upnp Fw
       
    83 // resources (they are released when the task is destroyed).
       
    84 // --------------------------------------------------------------------------
       
    85 //
       
    86 void CUpnpBrowseTask::ConstructL()
       
    87     {
       
    88     __LOG( "[UpnpCommand]\t CUpnpBrowseTask::ConstructL" );
       
    89     }
       
    90 
       
    91 // --------------------------------------------------------------------------
       
    92 // CUpnpBrowseTask::AllocateResourcesL
       
    93 // Allocates the Upnp Fw resources.
       
    94 // --------------------------------------------------------------------------
       
    95 //
       
    96 void CUpnpBrowseTask::AllocateResourcesL()
       
    97     {
       
    98      __LOG( "[UpnpCommand]\t CUpnpBrowseTask::AllocateResourcesL" );
       
    99  
       
   100     // Upnp Fw resources are allocated when the command is executed.
       
   101     }
       
   102 
       
   103 // --------------------------------------------------------------------------
       
   104 // CUpnpBrowseTask::ExecuteL
       
   105 // Executes the task.
       
   106 // --------------------------------------------------------------------------
       
   107 //
       
   108 void CUpnpBrowseTask::ExecuteL()
       
   109     {
       
   110     __LOG( "[UpnpCommand]\t CUpnpBrowseTask::ExecuteL" );
       
   111 
       
   112     // Leave if the command has been allocated already
       
   113     if( iAVController )
       
   114         {
       
   115         User::Leave( KErrInUse );
       
   116         }
       
   117 
       
   118     // Create UpnpAvControllerClient
       
   119     iAVController = UPnPAVControllerFactory::NewUPnPAVControllerL();
       
   120 
       
   121     TInt status = KErrNone;
       
   122     TInt leaveCode = KErrNone;
       
   123 
       
   124     // If the improved browse feature is available (introduced in Upnp Fw 2.1)
       
   125     // use it, otherwise use the old browse implementation (UpnpCommonUi).
       
   126     TRAP( leaveCode,
       
   127         CUPnPCommonUI *commonUi = CUPnPCommonUI::NewL();
       
   128         CleanupStack::PushL( commonUi );
       
   129 
       
   130         status = commonUi->ExecuteDeviceDialogL( *iAVController );
       
   131 
       
   132         // Clean up
       
   133         CleanupStack::PopAndDestroy( commonUi );
       
   134         commonUi = NULL;
       
   135         );
       
   136 
       
   137     // Show connection lost info note
       
   138     if( status == KErrDisconnected )
       
   139         {
       
   140         TRAP_IGNORE( NoteHandler()->ShowConnectionLostNoteL() );
       
   141         }
       
   142 
       
   143     // Fix UpnpCommonUi return value
       
   144     if( status > 0 )
       
   145         {
       
   146         status = KErrNone;
       
   147         }
       
   148 
       
   149     // If UpnpCommonUi leaved, handle the leave code (if necessary)
       
   150     if( status == KErrNone &&
       
   151         leaveCode != KErrNone )
       
   152         {
       
   153         status = leaveCode;
       
   154         }
       
   155 
       
   156     // Clean up
       
   157     delete iAVController;
       
   158     iAVController = NULL;
       
   159 
       
   160     // If there was an error, leave
       
   161     if( status != KErrNone )
       
   162         {
       
   163         User::Leave( status );
       
   164         }
       
   165     }
       
   166 
       
   167 // --------------------------------------------------------------------------
       
   168 // CUpnpBrowseTask::WLANConnectionLost
       
   169 // Notifies that the WLAN connection has been lost. All sessions are now
       
   170 // usable and must be closed.
       
   171 // --------------------------------------------------------------------------
       
   172 void CUpnpBrowseTask::WLANConnectionLost()
       
   173     {
       
   174     __LOG( "[UpnpCommand]\t CUpnpBrowseTask::WLANConnectionLost" );
       
   175 
       
   176     // Inform the client that connection was lost.
       
   177     CommandEvent( UpnpCommand::EEventComplete, KErrDisconnected );
       
   178 
       
   179     // Call task handler (UpnpCommandImplementation) to destroy this task
       
   180     if( TaskHandler() )
       
   181         {
       
   182         TaskHandler()->DestroyTask();
       
   183         }
       
   184     }
       
   185 
       
   186 // End of File