upnpavcontrolpoint/avcpengine/src/upnpresolvehandler.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:  CUpnpResolveHandler
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "upnpresolvehandler.h"
       
    20 #include "upnppathresolver.h"
       
    21 #include "upnppathelement.h"
       
    22 
       
    23 #include "upnpavcpmanager.h"
       
    24 #include "upnpavcontrolpoint.h"
       
    25 
       
    26 
       
    27 #include "upnpstring.h"
       
    28 
       
    29 #include "upnpavcpenginehelper.h"
       
    30 #include "upnpmdebug.h"
       
    31 using namespace UpnpAVCPEngine;
       
    32 
       
    33 // ============================ MEMBER FUNCTIONS ===============================
       
    34 
       
    35 // -----------------------------------------------------------------------------
       
    36 // CUpnpResolveHandler::NewL
       
    37 // Two-phased constructor.
       
    38 // -----------------------------------------------------------------------------
       
    39 //
       
    40 CUpnpResolveHandler* CUpnpResolveHandler::NewL(CUpnpAVCPManager& aAVCPManager, CUpnpPathResolver& aResolver, MUpnpResolverObserver& aObserver) 
       
    41 	{
       
    42     CUpnpResolveHandler* self = new( ELeave ) CUpnpResolveHandler(aAVCPManager,aResolver, aObserver);
       
    43     
       
    44     CleanupStack::PushL( self );
       
    45     self->ConstructL();
       
    46     CleanupStack::Pop( self );
       
    47 
       
    48     return self;    
       
    49 	}
       
    50 
       
    51 // -----------------------------------------------------------------------------
       
    52 // CUpnpResolveHandler::CUpnpResolveHandler
       
    53 // C++ default constructor can NOT contain any code, that
       
    54 // might leave.
       
    55 // -----------------------------------------------------------------------------
       
    56 //
       
    57 CUpnpResolveHandler::CUpnpResolveHandler(CUpnpAVCPManager& aAVCPManager,
       
    58                             CUpnpPathResolver& aResolver, 
       
    59                             MUpnpResolverObserver& aObserver):
       
    60                             iAVCPManager(aAVCPManager),
       
    61                             iResolver(aResolver),
       
    62                             iObserver(aObserver),
       
    63                             iPathIndex(-1)    
       
    64 	{
       
    65 	}
       
    66 
       
    67 // -----------------------------------------------------------------------------
       
    68 // CUpnpResolveHandler::~CUpnpResolveHandler
       
    69 // -----------------------------------------------------------------------------
       
    70 //
       
    71 CUpnpResolveHandler::~CUpnpResolveHandler()
       
    72 	{    
       
    73 	iResolver.RemoveHandler(this);
       
    74 	
       
    75 	delete iPath;
       
    76 	delete iLastId;
       
    77 	iPathElements.ResetAndDestroy();
       
    78 	}
       
    79 
       
    80 // -----------------------------------------------------------------------------
       
    81 // CUpnpResolveHandler::ConstructL
       
    82 // -----------------------------------------------------------------------------
       
    83 //
       
    84 void CUpnpResolveHandler::ConstructL() 
       
    85 	{
       
    86 	}
       
    87 
       
    88 // -----------------------------------------------------------------------------
       
    89 // CUpnpResolveHandler::SessionId
       
    90 // -----------------------------------------------------------------------------
       
    91 //
       
    92 TInt CUpnpResolveHandler::SessionId() 
       
    93 	{
       
    94     return iSessionId;    
       
    95 	}
       
    96 
       
    97 // -----------------------------------------------------------------------------
       
    98 // CUpnpResolveHandler::ResolveL
       
    99 // -----------------------------------------------------------------------------
       
   100 //
       
   101 void CUpnpResolveHandler::ResolveL(const TDesC8& aPath) 
       
   102 	{
       
   103 
       
   104     delete iPath;
       
   105     iPath = NULL;   
       
   106 
       
   107     iPath = aPath.AllocL();
       
   108     DEBUGSTRING8(("\tCResolveHandler::ResolveL %S", iPath));
       
   109 
       
   110     UpnpAVCPEngine::ParsePathToElementsL(iPath->Des(),iPathElements);
       
   111     
       
   112     DEBUGSTRING8(("\tCount of path elements %d", iPathElements.Count()));
       
   113     if (iPathElements.Count() == 0 || (iPathElements.Count() == 1 && iPathElements[0]->Length() == 0))	 
       
   114     	{
       
   115         CUpnpPathElement* elem = CUpnpPathElement::NewL();
       
   116         CleanupStack::PushL(elem);
       
   117         elem->SetIdL(KRootId());  
       
   118         elem->SetNameL(KRootName());  
       
   119        
       
   120         iObserver.ResolvedIdL(KErrNone, elem);
       
   121         CleanupStack::PopAndDestroy(elem);
       
   122         delete this;
       
   123     	}
       
   124     else 
       
   125     	{
       
   126         iPathIndex = 0;
       
   127         iLastId = KRootId().AllocL();
       
   128         iResolver.LockReset();
       
   129         CheckNextElementL();
       
   130     	}
       
   131 	}
       
   132 
       
   133 
       
   134 // -----------------------------------------------------------------------------
       
   135 // CUpnpResolveHandler::CheckNextElementL
       
   136 // -----------------------------------------------------------------------------
       
   137 //
       
   138 void CUpnpResolveHandler::CheckNextElementL(TBool aSendAction) 
       
   139 	{	
       
   140 	DEBUGSTRING8(("\tCheckNextElementL %d", aSendAction));
       
   141     CUpnpPathElement* element = iResolver.GetElementL(*iLastId,*iPathElements[iPathIndex]);
       
   142     
       
   143     if (element) 
       
   144     	{
       
   145     	
       
   146         iPathIndex++;
       
   147                      
       
   148         delete iLastId;
       
   149         iLastId = NULL;
       
   150         
       
   151         iLastId = element->Id().AllocL();
       
   152         DEBUGSTRING8(("\tFind element for index  %d with id %S", iPathIndex,iLastId));
       
   153         if (iPathIndex == iPathElements.Count() ) 
       
   154         	{
       
   155             iObserver.ResolvedIdL(KErrNone, element);  
       
   156             iResolver.UnlockReset();
       
   157             delete this; 
       
   158         	}
       
   159         else 
       
   160         	{
       
   161             CheckNextElementL();
       
   162         	}
       
   163     	}	 
       
   164     else if (aSendAction) 
       
   165     	{
       
   166         DEBUGSTRING8(("\tSend browse action for %S", iLastId));
       
   167         iSessionId = iAVCPManager.CdsBrowseActionL(iResolver.UUID(),*iLastId, KBrowseDirectChildren, KDefaultBrowseFilter, iStartIndex, KRequestedCountLimit, KNullDesC8);                
       
   168         DEBUGSTRING8(("\tSend browse action for %S with session id %d", iLastId, iSessionId));
       
   169         iAVCPManager.RegisterForAction(*this);
       
   170     	}
       
   171     else 
       
   172     	{
       
   173         iObserver.ResolvedIdL(KErrNotFound, NULL); 
       
   174         iResolver.UnlockReset();
       
   175         delete this;
       
   176     	}
       
   177     
       
   178 	}
       
   179 
       
   180 // -----------------------------------------------------------------------------
       
   181 // CUpnpResolveHandler::Interpret
       
   182 // -----------------------------------------------------------------------------
       
   183 //
       
   184 void CUpnpResolveHandler::InterpretL(TInt aErrorCode, CUpnpAction* aAction) 
       
   185 	{
       
   186 	DEBUGSTRING(("\tInterpret %d", aErrorCode));
       
   187     if (aErrorCode == EHttp200Ok) 
       
   188     	{
       
   189 
       
   190         TInt startIndex = StrToIntL( aAction->ArgumentValue( KStartingIndex ) );         
       
   191         TInt requestCount = StrToIntL( aAction->ArgumentValue( KRequestedCount ) );         
       
   192         
       
   193         TInt numberReturned = StrToIntL( aAction->ArgumentValue( KNumberReturned ) ); 
       
   194         TInt totalMatches = StrToIntL( aAction->ArgumentValue( KTotalMatches ) );         
       
   195                                                   
       
   196         iResolver.ParseBrowseResponseL(aAction->ArgumentValue( KResult ));  
       
   197         
       
   198         if ( startIndex+numberReturned < totalMatches)  
       
   199         	{
       
   200             iStartIndex +=  KRequestedCountLimit;
       
   201             iSessionId = iAVCPManager.CdsBrowseActionL(iResolver.UUID(),*iLastId, KBrowseDirectChildren, KDefaultBrowseFilter, iStartIndex, KRequestedCountLimit, KNullDesC8);                
       
   202             iAVCPManager.RegisterForAction(*this);
       
   203         	}
       
   204         else 
       
   205         	{
       
   206             CheckNextElementL(EFalse);
       
   207         	}
       
   208         
       
   209     	}
       
   210     else 
       
   211     	{
       
   212         iObserver.ResolvedIdL(KErrNotFound, NULL); 
       
   213         iResolver.UnlockReset();
       
   214         delete this;  
       
   215     	}            
       
   216 	}
       
   217 	
       
   218 // -----------------------------------------------------------------------------
       
   219 // CUpnpResolveHandler::RunError
       
   220 // -----------------------------------------------------------------------------
       
   221 //
       
   222 void CUpnpResolveHandler::RunError(TInt aErrorCode) 
       
   223 	{
       
   224 	DEBUGSTRING(("\tRunError %d", aErrorCode));	
       
   225 	TRAP_IGNORE( iObserver.ResolvedIdL(KErrNotFound, NULL) ); 
       
   226 	delete this;
       
   227 	}  	
       
   228 
       
   229 //  End of File