upnp/upnpstack/controlpointbase/src/upnpcpbdevicedescription.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 simple device discovery process.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 
       
    21 #include <e32base.h>
       
    22 
       
    23 #include <upnpdevice.h>
       
    24 #include "upnpcontenthandlerscontroller.h"
       
    25 
       
    26 #include "upnpcpbdevicedescription.h"
       
    27 #include "upnpcpbhttpmessagecontroller.h"
       
    28 
       
    29 // LOGGER SETTINGS
       
    30 #define KLogFile _L("UPnPControlPoint.txt")
       
    31 #include <upnpcustomlog.h>
       
    32 
       
    33 static const TInt KDefaultLenght = 200;
       
    34 // ============================ MEMBER FUNCTIONS ===============================
       
    35 
       
    36 // -----------------------------------------------------------------------------
       
    37 // CUpnpCpbDeviceDescription::~CUpnpCpbDeviceDescription
       
    38 // Destructor
       
    39 // -----------------------------------------------------------------------------
       
    40 //
       
    41 CUpnpCpbDeviceDescription::~CUpnpCpbDeviceDescription()
       
    42     {
       
    43     LOG_FUNC_NAME;
       
    44     delete iSaxController;
       
    45     delete iRootDevice;
       
    46     iUuids.Close();
       
    47     }
       
    48 
       
    49 // -----------------------------------------------------------------------------
       
    50 // CUpnpCpbDeviceDescription::NullTargetDevice
       
    51 // Constructor
       
    52 // -----------------------------------------------------------------------------
       
    53 //
       
    54 void CUpnpCpbDeviceDescription::NullTargetDevice()
       
    55     {
       
    56     iRootDevice = NULL;
       
    57     }
       
    58 
       
    59 // -----------------------------------------------------------------------------
       
    60 // CUpnpCpbDeviceDescription::NullTargetDevice
       
    61 // Constructor
       
    62 // -----------------------------------------------------------------------------
       
    63 //
       
    64 void CUpnpCpbDeviceDescription::DeleteTargetDevice()
       
    65     {
       
    66     delete iRootDevice;
       
    67     iRootDevice = NULL;
       
    68     }
       
    69 
       
    70 // -----------------------------------------------------------------------------
       
    71 // CUpnpCpbDeviceDescription::CUpnpCpbDeviceDescription
       
    72 // Constructor
       
    73 // -----------------------------------------------------------------------------
       
    74 //
       
    75 CUpnpCpbDeviceDescription::CUpnpCpbDeviceDescription(
       
    76     MUpnpCpbHttpMessageController& aMessanger,
       
    77     CUpnpCpbDeviceRepository& aRepository)
       
    78     : iMessanger(aMessanger), iRepository(aRepository)
       
    79     {
       
    80     LOG_FUNC_NAME;
       
    81     iResult = KDisscoveryFinished;
       
    82     }
       
    83 
       
    84 // -----------------------------------------------------------------------------
       
    85 // CUpnpCpbDeviceDescription::FailedUuidsL
       
    86 // Returns incorrect uuids
       
    87 // -----------------------------------------------------------------------------
       
    88 //
       
    89 const TPtrC8 CUpnpCpbDeviceDescription::FailedUuidsL()
       
    90     {
       
    91     if ( !iUuids.Length() )
       
    92         {
       
    93         RPointerArray<CUpnpDevice> devices;
       
    94         iRootDevice->GetAllDevices(devices);
       
    95         CleanupClosePushL(devices);
       
    96         for (TInt i(0); i<devices.Count(); i++)
       
    97             {
       
    98             AddToUuidsL(devices[i]->Uuid());
       
    99             }
       
   100         AddToUuidsL(iRootDevice->Uuid());
       
   101         CleanupStack::PopAndDestroy(&devices);
       
   102         }
       
   103     return iUuids;
       
   104     }
       
   105 
       
   106 // -----------------------------------------------------------------------------
       
   107 // CUpnpCpbDeviceDescription::ConstructL
       
   108 // Second phase constructor
       
   109 // -----------------------------------------------------------------------------
       
   110 //
       
   111 void CUpnpCpbDeviceDescription::ConstructL()
       
   112     {
       
   113     LOG_FUNC_NAME;
       
   114     // Sax paresr for service description
       
   115     iSaxController = CUpnpContentHandlersController::NewL();
       
   116     iUuids.CreateL( KDefaultLenght );
       
   117     }
       
   118 
       
   119 // -----------------------------------------------------------------------------
       
   120 // CUpnpCpbDeviceDescription::GetTargetDevice
       
   121 // Get currently processed device.
       
   122 // -----------------------------------------------------------------------------
       
   123 //
       
   124 CUpnpDevice* CUpnpCpbDeviceDescription::GetTargetDevice()
       
   125     {
       
   126     LOG_FUNC_NAME;
       
   127     return iRootDevice;
       
   128     }
       
   129 
       
   130 // -----------------------------------------------------------------------------
       
   131 // CUpnpCpbDeviceDescription::AddToUiidsL
       
   132 //  Add next uuid to uuid list
       
   133 // -----------------------------------------------------------------------------
       
   134 //
       
   135 void CUpnpCpbDeviceDescription::AddToUuidsL(const TDesC8& aUuid)
       
   136     {
       
   137     if ( (iUuids.Length() + aUuid.Length()
       
   138             + UpnpString::KSemiColon().Length()) < iUuids.MaxLength() )
       
   139         {
       
   140         if (iUuids.Length())
       
   141             {
       
   142             iUuids.Append(UpnpString::KSemiColon());
       
   143             }
       
   144         iUuids.Append(aUuid);
       
   145         }
       
   146     else
       
   147         {
       
   148         iUuids.ReAllocL(iUuids.MaxLength() + aUuid.Length()
       
   149                 + UpnpString::KSemiColon().Length());
       
   150         if (iUuids.Length())
       
   151             {
       
   152             iUuids.Append(UpnpString::KSemiColon());
       
   153             }
       
   154         iUuids.Append(aUuid);
       
   155         }
       
   156     }
       
   157 
       
   158 // -----------------------------------------------------------------------------
       
   159 // Finds next service description url to be processed.
       
   160 // -----------------------------------------------------------------------------
       
   161 //
       
   162 const TPtrC8 CUpnpCpbDeviceDescription::GetNextServiceType(CUpnpDevice* aDevice)
       
   163     {
       
   164     // Because all service descriptions are not retrieved, retrieve next one.
       
   165     TInt serviceDescriptionsReceived = aDevice->ServiceList().Count();
       
   166     TInt j;
       
   167     for ( j=0; j < serviceDescriptionsReceived; j++)
       
   168         {
       
   169         if (aDevice->ServiceList()[j]->IsAdded() == EFalse)
       
   170             {
       
   171             return aDevice->ServiceList()[j]->ServiceDescriptionUrl();
       
   172             }
       
   173         }
       
   174     return KNullDesC8();
       
   175     }
       
   176 
       
   177 //  End of File