upnp/upnpstack/controlpointbase/src/upnpcpbsimpledevicedescription.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 "upnpcpbsimpledevicedescription.h"
       
    27 #include "upnpcpbhttpmessagecontroller.h"
       
    28 #include "upnpcpbdevicerepository.h"
       
    29 
       
    30 // LOGGER SETTINGS
       
    31 #define KLogFile _L("UPnPControlPoint.txt")
       
    32 #include <upnpcustomlog.h>
       
    33 
       
    34 // ============================ MEMBER FUNCTIONS ===============================
       
    35 
       
    36 // -----------------------------------------------------------------------------
       
    37 // CUpnpCpbSimpleDeviceDescription::NewL
       
    38 // Two-phased constructor
       
    39 // -----------------------------------------------------------------------------
       
    40 //
       
    41 CUpnpCpbSimpleDeviceDescription* CUpnpCpbSimpleDeviceDescription::NewL(
       
    42         MUpnpCpbHttpMessageController& aMessanger,
       
    43         CUpnpCpbDeviceRepository& aRepository)
       
    44     {
       
    45     LOG_FUNC_NAME;
       
    46     CUpnpCpbSimpleDeviceDescription* self =
       
    47         new (ELeave) CUpnpCpbSimpleDeviceDescription(aMessanger, aRepository);
       
    48 
       
    49     CleanupStack::PushL(self);
       
    50     self->ConstructL();
       
    51     CleanupStack::Pop(self);
       
    52 
       
    53     return self;
       
    54     }
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 // CUpnpCpbSimpleDeviceDescription::~CUpnpCpbSimpleDeviceDescription
       
    58 // Destructor
       
    59 // -----------------------------------------------------------------------------
       
    60 //
       
    61 CUpnpCpbSimpleDeviceDescription::~CUpnpCpbSimpleDeviceDescription()
       
    62     {
       
    63     LOG_FUNC_NAME;
       
    64     if(!iIsNull)
       
    65         {
       
    66         delete iRootDevice;
       
    67         }
       
    68     iRootDevice = NULL;
       
    69     }
       
    70 
       
    71 // -----------------------------------------------------------------------------
       
    72 // CUpnpCpbSimpleDeviceDescription::CUpnpCpbSimpleDeviceDescription
       
    73 // Constructor
       
    74 // -----------------------------------------------------------------------------
       
    75 //
       
    76 CUpnpCpbSimpleDeviceDescription::CUpnpCpbSimpleDeviceDescription(
       
    77         MUpnpCpbHttpMessageController& aMessanger,
       
    78         CUpnpCpbDeviceRepository& aRepository)
       
    79     : CUpnpCpbDeviceDescription(aMessanger, aRepository)
       
    80     {
       
    81     LOG_FUNC_NAME;
       
    82     }
       
    83 
       
    84 // -----------------------------------------------------------------------------
       
    85 // CUpnpCpbSimpleDeviceDescription::DiscoverDeviceL
       
    86 // Start processing device.
       
    87 // -----------------------------------------------------------------------------
       
    88 //
       
    89 TInt CUpnpCpbSimpleDeviceDescription::DiscoverDeviceL(CUpnpDevice* aDevice)
       
    90     {
       
    91     LOG_FUNC_NAME;
       
    92     iIsNull = EFalse;
       
    93     iRootDevice = aDevice;
       
    94     // check if device match the type
       
    95     if(!iRepository.MatchTargetDevice(aDevice->DeviceType()))
       
    96         {
       
    97         iResult = KDisscoveryFinished;
       
    98         return iResult;
       
    99         }
       
   100 
       
   101     iResult = KDisscoveryInProgress;
       
   102     TPtrC8 buffer(GetNextServiceType(iRootDevice));
       
   103 
       
   104     if (buffer.Length())
       
   105         {
       
   106         LOGS("CUpnpCpbSimpleDeviceDescription::DiscoverDeviceL - Discovering services");
       
   107 
       
   108         //ask for 1st service description
       
   109         iResult = KDisscoveryInProgress;
       
   110         TInt sessionId = iMessanger.GetServiceDescriptionL (aDevice, buffer);
       
   111         // put SessionID to memory per pending Service Description request
       
   112         aDevice->WaitServiceDescriptionL( sessionId );
       
   113         }
       
   114     else
       
   115         {
       
   116         LOGS("CUpnpCpbSimpleDeviceDescription::DiscoverDeviceL - "
       
   117              "No service info for the device");
       
   118         LOGS("CUpnpCpbSimpleDeviceDescription::DiscoverDeviceL - "
       
   119              "All device info brought - device officially discovered");
       
   120         iResult = KDisscoveryFinished;
       
   121         }
       
   122     return iResult;
       
   123     }
       
   124 
       
   125 // -----------------------------------------------------------------------------
       
   126 // CUpnpCpbSimpleDeviceDescription::ServiceDescription
       
   127 // Function processing service description
       
   128 // -----------------------------------------------------------------------------
       
   129 //
       
   130 TInt CUpnpCpbSimpleDeviceDescription::ServiceDescriptionL(CUpnpHttpMessage* aMsg)
       
   131     {
       
   132     LOG_FUNC_NAME;
       
   133 
       
   134     // Check if device is waiting for this service
       
   135     TBool waiting(EFalse);
       
   136     if(!iRootDevice)
       
   137         {
       
   138         iResult = KErrNotFound;
       
   139         }
       
   140     else
       
   141         {
       
   142         for( TInt servCount(0);
       
   143                 servCount < iRootDevice->WaitServiceDescriptionCount(); servCount++)
       
   144             {
       
   145             if ( iRootDevice->WaitServiceDescriptionSessionId(servCount )
       
   146                      == aMsg->SessionId())
       
   147                 {
       
   148                 waiting = ETrue;
       
   149                 break;
       
   150                 }
       
   151             }
       
   152         // Waiting for service description
       
   153         if(waiting)
       
   154             {
       
   155             // Processing message
       
   156             if ( !aMsg->Is2xx())
       
   157                 {
       
   158                 LOGS("CUpnpCpbSimpleDeviceDescription::ServiceDescriptionL - "
       
   159                      "Wrong response recived.");
       
   160                 iResult = KDisscoveryIncorrect;
       
   161                 }
       
   162             else
       
   163                 {
       
   164                 iResult = ProcessServiceDescriptionL(aMsg);
       
   165                 }
       
   166             }
       
   167         else
       
   168             {
       
   169             iResult = KErrNotFound;
       
   170             }
       
   171         }
       
   172     return iResult;
       
   173     }
       
   174 
       
   175 // -----------------------------------------------------------------------------
       
   176 // CUpnpCpbSimpleDeviceDescription::ServiceDescription
       
   177 // Parse service description
       
   178 // -----------------------------------------------------------------------------
       
   179 //
       
   180 TInt CUpnpCpbSimpleDeviceDescription::ProcessServiceDescriptionL(CUpnpHttpMessage* aMsg)
       
   181     {
       
   182     LOG_FUNC_NAME;
       
   183     CUpnpDevice::TServiceAdd result;
       
   184 
       
   185     // Parsing service desription
       
   186     CUpnpService* service = NULL;
       
   187     service = iSaxController->ParseServiceL(aMsg->Body(), iRootDevice);
       
   188 
       
   189     CleanupStack::PushL(service);
       
   190     result = iRootDevice->AddServiceL(aMsg->SessionId(), service);
       
   191     CleanupStack::Pop(service);
       
   192 
       
   193     if ( result == CUpnpDevice::EAllServicesAdded )
       
   194         { // device has received all service descriptions
       
   195         LOGS("CUpnpCpbSimpleDeviceDescription::ProcessServiceDescriptionL  - "
       
   196              "All service info added to the parent device");
       
   197         iResult = 	KDisscoveryFinished;
       
   198         }
       
   199     else if ( result == CUpnpDevice::EServiceAdded )
       
   200         {
       
   201         LOGS("CUpnpCpbSimpleDeviceDescription::ProcessServiceDescriptionL - "
       
   202              "Service added");
       
   203         // Waiting for next desciptions.
       
   204         iResult = 	KDisscoveryInProgress;
       
   205 
       
   206         TPtrC8 buffer(GetNextServiceType(iRootDevice));
       
   207         TInt sessionId = iMessanger.GetServiceDescriptionL (iRootDevice,
       
   208                                   buffer);
       
   209         // put SessionID to memory per pending Service Description request
       
   210         iRootDevice->WaitServiceDescriptionL( sessionId );
       
   211         }
       
   212     else
       
   213         {
       
   214         delete service;
       
   215         iResult = KDisscoveryInProgress;
       
   216         }
       
   217 
       
   218     LOGS1("CUpnpCpbSimpleDeviceDescription::ProcessServiceDescriptionL -res=%d", iResult);
       
   219     return iResult;
       
   220     }
       
   221 
       
   222 // -----------------------------------------------------------------------------
       
   223 // CUpnpCpbSimpleDeviceDescription::GetIncompliteRootDevice
       
   224 //  Append discovered devices to array
       
   225 // -----------------------------------------------------------------------------
       
   226 //
       
   227 CUpnpDevice* CUpnpCpbSimpleDeviceDescription::GetIncompliteRootDevice()
       
   228     {
       
   229     return NULL;
       
   230     }
       
   231 
       
   232 // -----------------------------------------------------------------------------
       
   233 // CUpnpCpbSimpleDeviceDescription::NullTargetDevice
       
   234 // Constructor
       
   235 // -----------------------------------------------------------------------------
       
   236 //
       
   237 void CUpnpCpbSimpleDeviceDescription::NullTargetDevice()
       
   238     {
       
   239     if (iResult == KDisscoveryFinished)
       
   240         {
       
   241         iIsNull = ETrue;
       
   242         }
       
   243     }
       
   244 
       
   245 // -----------------------------------------------------------------------------
       
   246 // CUpnpCpbSimpleDeviceDescription::NullTargetDevice
       
   247 // Constructor
       
   248 // -----------------------------------------------------------------------------
       
   249 //
       
   250 void CUpnpCpbSimpleDeviceDescription::DeleteTargetDevice()
       
   251     {
       
   252     if (!iIsNull || iResult == KDisscoveryIncorrect)
       
   253         {
       
   254         delete iRootDevice;
       
   255         }
       
   256     iRootDevice = NULL;
       
   257     }
       
   258 
       
   259 // -----------------------------------------------------------------------------
       
   260 // CUpnpCpbSimpleDeviceDescription::GetDiscoveredDeviceL
       
   261 //  Append discovered devices to array
       
   262 // -----------------------------------------------------------------------------
       
   263 //
       
   264 void CUpnpCpbSimpleDeviceDescription::GetDiscoveredDeviceL(
       
   265     RPointerArray<CUpnpDevice>& aArray, TBool /*aRemove*/ )
       
   266     {
       
   267     if (iRootDevice && iRepository.MatchTargetDevice(iRootDevice->DeviceType()))
       
   268         {
       
   269         if(iResult == KDisscoveryFinished)
       
   270             {
       
   271             aArray.AppendL(iRootDevice);
       
   272             }
       
   273         }
       
   274     }
       
   275 
       
   276 // -----------------------------------------------------------------------------
       
   277 // CUpnpCpbSimpleDeviceDescription::GetUninterestingDeviceL
       
   278 //  Append not discovered (does not match the type) devices to array
       
   279 // -----------------------------------------------------------------------------
       
   280 //
       
   281 void CUpnpCpbSimpleDeviceDescription::GetUninterestingDeviceL(
       
   282     RPointerArray<CUpnpDevice>& aArray, TBool /*aRemove*/ )
       
   283     {
       
   284     if (iRootDevice && !iRepository.MatchTargetDevice(iRootDevice->DeviceType()))
       
   285         {
       
   286         if (iResult == KDisscoveryFinished)
       
   287             {
       
   288             aArray.AppendL(iRootDevice);
       
   289             }
       
   290         }
       
   291     }
       
   292 
       
   293 // -----------------------------------------------------------------------------
       
   294 // CUpnpCpbSimpleDeviceDescription::GetUnnededDeviceL
       
   295 //  Append discovered but not matching target types devices to array
       
   296 // -----------------------------------------------------------------------------
       
   297 //
       
   298 void CUpnpCpbSimpleDeviceDescription::GetUnnededDeviceL(
       
   299     RPointerArray<CUpnpDevice>& /*aArray*/, TBool /*aRemove*/ )
       
   300     {
       
   301     // nothing to do, in case of simple device discovered are only matching type devices
       
   302     }
       
   303 
       
   304 // -----------------------------------------------------------------------------
       
   305 // CUpnpCpbSimpleDeviceDescription::FailedUuids
       
   306 //  Returns incorrect uuids
       
   307 // -----------------------------------------------------------------------------
       
   308 //
       
   309 const TPtrC8 CUpnpCpbSimpleDeviceDescription::FailedUuidsL()
       
   310     {
       
   311     if (iRootDevice)
       
   312         {
       
   313         return iRootDevice->Uuid();
       
   314         }
       
   315     else
       
   316         {
       
   317         return KNullDesC8();
       
   318         }
       
   319     }
       
   320 
       
   321 //  End of File