upnp/upnpstack/controlpointbase/src/upnpcpbdevicelistutils.cpp
changeset 0 f5a58ecadc66
equal deleted inserted replaced
-1:000000000000 0:f5a58ecadc66
       
     1 /** @file
       
     2 * Copyright (c) 2007-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:  Declares utils function for devices list class.
       
    15 *
       
    16 */
       
    17  
       
    18 
       
    19 // INCLUDE FILES
       
    20 
       
    21 #include <e32base.h>
       
    22 
       
    23 #include <upnpdevice.h>
       
    24 
       
    25 #include "upnpcpbdevicelistutils.h"
       
    26 
       
    27 // ============================ MEMBER FUNCTIONS ===============================
       
    28 
       
    29 // -----------------------------------------------------------------------------
       
    30 // UPnPCpbDeviceDistUtils::GetFromList
       
    31 // Get device from list
       
    32 // -----------------------------------------------------------------------------
       
    33 //
       
    34 CUpnpDevice* UpnpCpbDeviceListUtils::GetFromList(const TDesC8& aUuid, RPointerArray<CUpnpDevice>& aList)
       
    35     {
       
    36     CUpnpDevice* res = NULL;
       
    37     for ( TInt l = 0; l < aList.Count(); l++ )
       
    38         {
       
    39         if ( aList[l]->Uuid().Compare( aUuid )  ==  0 )
       
    40             {
       
    41             res = aList[l];
       
    42             break;
       
    43             }	
       
    44         }
       
    45     return res;	
       
    46     }
       
    47     
       
    48 // -----------------------------------------------------------------------------
       
    49 // UPnPCpbDeviceDistUtils::GetRootFromList
       
    50 // Get device from list
       
    51 // -----------------------------------------------------------------------------
       
    52 //
       
    53 CUpnpDevice* UpnpCpbDeviceListUtils::GetRootFromList( const TDesC8& aDeviceUuid, 
       
    54                                        RPointerArray<CUpnpDevice>& aDeviceList )
       
    55     {
       
    56     CUpnpDevice* res = NULL;
       
    57     for ( TInt l = 0; l < aDeviceList.Count(); l++ )
       
    58         {
       
    59         if ( !aDeviceList[l]->IsEmbeddDevice() )
       
    60             {            
       
    61             if ( aDeviceList[l]->Uuid().Compare( aDeviceUuid )  ==  0 )
       
    62                 {
       
    63                 res = aDeviceList[l];
       
    64                 break;
       
    65                 }
       
    66                 
       
    67             RPointerArray<CUpnpDevice> devicesAll;
       
    68             aDeviceList[l]->GetAllDevices( devicesAll );                      
       
    69             for ( TInt k = 0; k < devicesAll.Count(); k++ )
       
    70                 {            
       
    71                 if ( aDeviceUuid.Compare( devicesAll[k]->Uuid() ) == 0 )
       
    72                     {
       
    73                     devicesAll.Close();         
       
    74                     res = aDeviceList[l];
       
    75                     break;
       
    76                     }
       
    77                 }
       
    78             devicesAll.Close();
       
    79             }
       
    80         }
       
    81     return res;	
       
    82     }
       
    83  
       
    84 // -----------------------------------------------------------------------------
       
    85 // UPnPCPBDeviceDistUtils::ExistOnList
       
    86 // Chech if device is on list
       
    87 // -----------------------------------------------------------------------------
       
    88 //    
       
    89 TBool UpnpCpbDeviceListUtils::ExistOnList(const TDesC8& aUuid, RPointerArray<CUpnpDevice>& aList)
       
    90     {
       
    91     TBool res(EFalse);
       
    92     if(UpnpCpbDeviceListUtils::GetFromList(aUuid,aList))
       
    93         {
       
    94         res = ETrue;
       
    95         }
       
    96     return res;
       
    97     }
       
    98 
       
    99 // -----------------------------------------------------------------------------
       
   100 // CUpnpCpbDeviceRepository::AddDeviceL
       
   101 // Add device to device list
       
   102 // -----------------------------------------------------------------------------
       
   103 // 
       
   104 TBool UpnpCpbDeviceListUtils::AddDeviceL(CUpnpDevice* aDevice, RPointerArray<CUpnpDevice>& aList)
       
   105     {
       
   106     TInt error(KErrNone);
       
   107     TInt result = AddDevice(aDevice, aList, error);
       
   108     User::LeaveIfError(error);
       
   109     return result;
       
   110     };
       
   111 
       
   112 // -----------------------------------------------------------------------------
       
   113 // CUpnpCpbDeviceRepository::AddDevicesL
       
   114 // Add devices to device list
       
   115 // -----------------------------------------------------------------------------
       
   116 // 
       
   117 void UpnpCpbDeviceListUtils::AddDevicesL(RPointerArray<CUpnpDevice>& aSource, RPointerArray<CUpnpDevice>& aTarget)
       
   118     {
       
   119     TInt error(KErrNone);
       
   120     for(TInt i(0); i<aSource.Count(); i++)
       
   121         {
       
   122         AddDevice(aSource[i], aTarget, error);
       
   123         if(error < KErrNone)
       
   124             {
       
   125             for(; i>0; i--)
       
   126                 {
       
   127                 aTarget.Remove(aTarget.Count() - 1);
       
   128                 }
       
   129             break;
       
   130             }
       
   131         }
       
   132     
       
   133     User::LeaveIfError(error);
       
   134     };
       
   135 
       
   136 // -----------------------------------------------------------------------------
       
   137 // CUpnpCpbDeviceRepository::AddDevice
       
   138 // Add device to device list
       
   139 // -----------------------------------------------------------------------------
       
   140 // 
       
   141 TBool UpnpCpbDeviceListUtils::AddDevice(CUpnpDevice* aDevice, RPointerArray<CUpnpDevice>& aList, TInt& aError)
       
   142     {
       
   143     TBool result = EFalse;
       
   144     if(!UpnpCpbDeviceListUtils::ExistOnList(aDevice->Uuid(), aList))
       
   145         {
       
   146         aError = aList.Append(aDevice);
       
   147         result = ETrue;
       
   148         }
       
   149     return result;
       
   150     };
       
   151 
       
   152 //  End of File