upnpavcontrolpoint/avcpengine/src/upnpdevicelistcommand.cpp
branchIOP_Improvements
changeset 40 08b5eae9f9ff
parent 39 6369bfd1b60d
child 41 b4d83ea1d6e2
equal deleted inserted replaced
39:6369bfd1b60d 40:08b5eae9f9ff
     1 /** @file
       
     2 * Copyright (c) 2005-2006 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:  CUpnpDeviceListCommand
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "upnpdevicelistcommand.h"
       
    20 
       
    21 #include "upnpavcpmanager.h"
       
    22 #include "upnpavcontrolpoint.h"
       
    23 
       
    24 
       
    25 // -----------------------------------------------------------------------------
       
    26 // CUpnpDeviceListCommand::NewL
       
    27 // Two-phased constructor.
       
    28 // -----------------------------------------------------------------------------
       
    29 //
       
    30 CUpnpDeviceListCommand* CUpnpDeviceListCommand::NewL(CUpnpAVCPManager& aAVCPManager, CUpnpAVCPEngineSession& aSession, const RMessage2& aMessage)
       
    31 	{
       
    32     CUpnpDeviceListCommand* self = new( ELeave ) CUpnpDeviceListCommand(aAVCPManager, aSession, aMessage);
       
    33     
       
    34     CleanupStack::PushL( self );
       
    35     self->ConstructL();
       
    36     CleanupStack::Pop( self );
       
    37 
       
    38     return self;   
       
    39 	}	
       
    40   
       
    41 // -----------------------------------------------------------------------------
       
    42 // CUpnpDeviceListCommand::ConstructL
       
    43 // Symbian 2nd phase constructor can leave.
       
    44 // -----------------------------------------------------------------------------
       
    45 //   
       
    46 void CUpnpDeviceListCommand::ConstructL() 
       
    47 	{
       
    48  	CUpnpCommand::BaseConstructL();
       
    49 	} 
       
    50   
       
    51 // -----------------------------------------------------------------------------
       
    52 // CUpnpDeviceListCommand::CUpnpDeviceListCommand
       
    53 // C++ default constructor can NOT contain any code, that
       
    54 // might leave.
       
    55 // -----------------------------------------------------------------------------   
       
    56 //    
       
    57 CUpnpDeviceListCommand::CUpnpDeviceListCommand(CUpnpAVCPManager& aAVCPManager, 
       
    58                    CUpnpAVCPEngineSession& aSession, 
       
    59                    const RMessage2& aMessage):
       
    60                    CUpnpCommand( aAVCPManager,
       
    61                    		     aSession, 
       
    62                    		     aMessage)
       
    63 	{
       
    64 	}
       
    65 
       
    66 // -----------------------------------------------------------------------------
       
    67 // CUpnpDeviceListCommand::~CUpnpDeviceListCommand
       
    68 // desctructor
       
    69 // -----------------------------------------------------------------------------
       
    70 // 
       
    71 CUpnpDeviceListCommand::~CUpnpDeviceListCommand()
       
    72 	{
       
    73     delete[] iDevices;
       
    74 	}
       
    75 
       
    76 
       
    77 // -----------------------------------------------------------------------------
       
    78 // CUpnpDeviceListCommand::ExecuteL
       
    79 // -----------------------------------------------------------------------------
       
    80 // 
       
    81 void CUpnpDeviceListCommand::ExecuteL()
       
    82 	{
       
    83 	//ASSERT(iType == EPrepareDeviceList);
       
    84 
       
    85 	RPointerArray<CUpnpDevice> devices = iAVCPManager.DeviceList();
       
    86 	iDeviceCount = devices.Count();
       
    87     DEBUGSTRING8(("Execute DeviceListCommand no. %d",iDeviceCount));
       
    88 
       
    89 	// set command id	
       
    90     TPckg<TInt> idPckg(iId);       		
       
    91 	iMessage.WriteL(0, idPckg);         
       
    92 	   
       
    93 	// set device count - list only MS devices
       
    94 	TPckg<TInt> devCountPckg(iDeviceCount);       		
       
    95 	iMessage.WriteL(1, devCountPckg);            
       
    96 	
       
    97 	iMessage.Complete(KErrNone);
       
    98 	
       
    99     if ( iDeviceCount > 0) 
       
   100     	{                
       
   101         iDevices = new(ELeave)TAVDevice[iDeviceCount];
       
   102         for (TInt i = 0; i < iDeviceCount; i++) 
       
   103         	{
       
   104             CUpnpDevice* device = devices[i];
       
   105             iDevices[i].iUDN.Copy( device->Uuid() );
       
   106             iDevices[i].iFriendlyName.Copy( device->DescriptionProperty(KAVCPEngineFriendlyName) );  
       
   107         	}
       
   108     	}
       
   109     else 
       
   110     	{
       
   111         delete this;   
       
   112     	}   
       
   113 	}
       
   114 
       
   115 // -----------------------------------------------------------------------------
       
   116 // CUpnpDeviceListCommand::SetResultL
       
   117 // -----------------------------------------------------------------------------
       
   118 // 
       
   119 void CUpnpDeviceListCommand::SetResultL(const RMessage2& aMessage) 
       
   120 	{
       
   121 	DEBUGSTRING8(("Set Result from DeviceListCommand"));
       
   122 	//ASSERT(aMessage.Function() == EDownloadDeviceList);
       
   123     if (iDevices) 
       
   124     	{
       
   125       	TPtr8 result(reinterpret_cast<TUint8*>(iDevices), sizeof(TAVDevice)*iDeviceCount, sizeof(TAVDevice)*iDeviceCount);
       
   126       	aMessage.WriteL(1, result);  
       
   127     	}	
       
   128 	}