upnpsharing/upnpcontentserver/src/upnpcontainercheckerao.cpp
branchIOP_Improvements
changeset 40 08b5eae9f9ff
parent 39 6369bfd1b60d
child 41 b4d83ea1d6e2
equal deleted inserted replaced
39:6369bfd1b60d 40:08b5eae9f9ff
     1 /*
       
     2 * Copyright (c) 2006-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:      This module handlers the cleaning and creating of the
       
    15  *                filesystem to mediaserver
       
    16  *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 #include <e32debug.h>
       
    24 #include "upnpcommonutils.h"
       
    25 #include "upnpcontentserverdefs.h"
       
    26 #include "upnpcontainercheckerao.h"
       
    27 #include "upnpunsharerao.h"
       
    28 
       
    29 _LIT( KComponentLogfile, "contentserver.txt");
       
    30 #include "upnplog.h"
       
    31 
       
    32 // CONSTANTS
       
    33 const TInt KDefaultBrowseReqCount( 100 );
       
    34 const TInt KDefaultBrowseStartingInd( 0 );
       
    35 
       
    36 using namespace UpnpContentServer;
       
    37 
       
    38 // --------------------------------------------------------------------------
       
    39 // CUpnpContainerCheckerAo::CUpnpContainerCheckerAo()
       
    40 // C++ constructor.
       
    41 // --------------------------------------------------------------------------
       
    42 //
       
    43 CUpnpContainerCheckerAo::CUpnpContainerCheckerAo(
       
    44     MUpnpSharingCallback* aCallback ) :
       
    45     CActive( CActive::EPriorityIdle ),
       
    46     iCallback( aCallback )
       
    47     {
       
    48     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
       
    49     iCurrentOperation = ENotActive;
       
    50     iState = EIdle;
       
    51     iTotalMatches = KErrNotFound;
       
    52     __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );
       
    53     }
       
    54 
       
    55 
       
    56 // --------------------------------------------------------------------------
       
    57 // CUpnpContainerCheckerAo::~CUpnpContainerCheckerAo()
       
    58 // C++ destructor.
       
    59 // --------------------------------------------------------------------------
       
    60 //
       
    61 CUpnpContainerCheckerAo::~CUpnpContainerCheckerAo()
       
    62     {
       
    63     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
       
    64     delete iFileSharing;
       
    65     iFileSharing = NULL;
       
    66     iMediaServer.Close();
       
    67 
       
    68     if ( IsActive() )
       
    69         {
       
    70         __LOG1("CUpnpContainerCheckerAo destructor IsActive iCurrentOp=%d",
       
    71               iCurrentOperation );
       
    72         iCurrentOperation = ENotActive;
       
    73         TRequestStatus* stat = &iStatus;
       
    74         User::RequestComplete( stat, KErrNone );
       
    75         }
       
    76 
       
    77     Cancel();
       
    78 
       
    79     Cleanup();
       
    80 
       
    81     __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );
       
    82     }
       
    83 
       
    84 // --------------------------------------------------------------------------
       
    85 // CUpnpContainerCheckerAo::ValidateContainerStructureL
       
    86 // ( other items are commented in header )
       
    87 // --------------------------------------------------------------------------
       
    88 //
       
    89 TInt CUpnpContainerCheckerAo::ValidateContainerStructureL( 
       
    90     RArray<TInt>* aIds )
       
    91     {
       
    92     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
       
    93 
       
    94     CActiveScheduler::Add( this );
       
    95     TInt err( KErrNotFound );
       
    96 
       
    97     iClientIds = aIds;
       
    98 
       
    99     // First initialize resources
       
   100     iOperationMode = EValidateContainers;
       
   101     iCurrentOperation = EInitialize;
       
   102     SelfComplete( KErrNone );
       
   103 
       
   104     __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );
       
   105     return err;
       
   106     }
       
   107 
       
   108 // --------------------------------------------------------------------------
       
   109 // CUpnpContainerCheckerAo::GetDefaultContainerIdsL
       
   110 // ( other items are commented in header )
       
   111 // --------------------------------------------------------------------------
       
   112 //
       
   113 TInt CUpnpContainerCheckerAo::CheckDefaultContainersL(
       
   114     RArray<TInt>* aIds )
       
   115     {
       
   116     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
       
   117     iOperationMode = ECheckDefaultContainers;
       
   118     TInt err( KErrNone );
       
   119 
       
   120     iClientIds = aIds;
       
   121 
       
   122     CActiveScheduler::Add( this );
       
   123     iCurrentOperation = EInitialize;
       
   124     SelfComplete( KErrNone );
       
   125 
       
   126     __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );
       
   127     return err;
       
   128     }
       
   129 
       
   130 // --------------------------------------------------------------------------
       
   131 // CUpnpContainerCheckerAo::RequestStop
       
   132 // ( other items are commented in header )
       
   133 // --------------------------------------------------------------------------
       
   134 //
       
   135 void CUpnpContainerCheckerAo::RequestStop(
       
   136     MUpnpSharingCallback::TSharingStopType aStopType )
       
   137     {
       
   138     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
       
   139     iStopRequested = aStopType;
       
   140     __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );
       
   141     }
       
   142 
       
   143 // --------------------------------------------------------------------------
       
   144 // CUpnpContainerCheckerAo::InitializeL
       
   145 // ( other items are commented in header )
       
   146 // --------------------------------------------------------------------------
       
   147 //
       
   148 TInt CUpnpContainerCheckerAo::InitializeL()
       
   149     {
       
   150     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
       
   151     // First initialize resources
       
   152     iFileSharing = CUpnpFileSharing::NewL();
       
   153     TInt error( iMediaServer.Connect() );
       
   154     if ( error )
       
   155         {
       
   156         __LOG8_1( "iMediaServer.Connect err: %d",error );
       
   157         }
       
   158     User::LeaveIfError( error );
       
   159 
       
   160     if ( !error )
       
   161         {
       
   162         // start offline if not started
       
   163         TInt status( RUpnpMediaServerClient::EStopped );
       
   164         error = iMediaServer.Status( status );
       
   165         if ( !error && status == RUpnpMediaServerClient::EStopped )
       
   166             {
       
   167             error = iMediaServer.StartOffline();
       
   168             }
       
   169         }
       
   170 
       
   171     SelfComplete( error );
       
   172     iCurrentOperation = EQueryDefaultContainers;
       
   173     __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );
       
   174     return error;
       
   175     }
       
   176 
       
   177 // --------------------------------------------------------------------------
       
   178 // CUpnpContainerCheckerAo::QueryDefaultContainerIdsL
       
   179 // ( other items are commented in header )
       
   180 // --------------------------------------------------------------------------
       
   181 //
       
   182 void CUpnpContainerCheckerAo::QueryDefaultContainerIdsL()
       
   183     {
       
   184     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
       
   185     iState = EResolveDefaultContainerIds;
       
   186 
       
   187     CUpnpBrowseCriteria* browseCriteria = CreateBrowseCriteriaLC();
       
   188 
       
   189     delete iContainerList;
       
   190     iContainerList = NULL;
       
   191 
       
   192     iContainerList = CUpnpContainerList::NewL();
       
   193 
       
   194     // Get shared containers to iContainerList
       
   195     iFileSharing->GetSharedContainerListL( KRootContainerId,
       
   196                                            *browseCriteria,
       
   197                                            *iContainerList,
       
   198                                            iMatchCount,
       
   199                                            iStatus );
       
   200     iCurrentOperation = EQueryDefaultContainersResult;
       
   201     CleanupStack::PopAndDestroy( browseCriteria );
       
   202     SetActive();
       
   203     __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );
       
   204     }
       
   205 
       
   206 // --------------------------------------------------------------------------
       
   207 // CUpnpContainerCheckerAo::QueryDefaultContainerIdsResultL
       
   208 // ( other items are commented in header )
       
   209 // --------------------------------------------------------------------------
       
   210 //
       
   211 void CUpnpContainerCheckerAo::QueryDefaultContainerIdsResultL()
       
   212     {
       
   213     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
       
   214     CUpnpContainer* tmpContainer( NULL );
       
   215     if ( !iContainerList )
       
   216         {
       
   217         User::Leave( KErrGeneral );
       
   218         }
       
   219     switch ( iContainerPosition )
       
   220         {
       
   221     case CUpnpContainerCheckerAo::EImageAndVideo :
       
   222         {
       
   223         tmpContainer =
       
   224             UPnPCommonUtils::FindContainerByTitle( *iContainerList,
       
   225                                                    KImageContainerName );
       
   226         if ( tmpContainer )
       
   227             {
       
   228             iImageVideoContainerId = UPnPCommonUtils::DesC8ToInt(
       
   229                 tmpContainer->Id() );
       
   230             iContainerList->RemoveAndDestroy( tmpContainer->Id() );
       
   231             tmpContainer = NULL;
       
   232             iContainerPosition++;
       
   233             iCurrentOperation = EQueryDefaultContainersResult;
       
   234             SelfComplete( KErrNone );
       
   235             }
       
   236         else
       
   237             {
       
   238             iCurrentOperation = EShareContainer;
       
   239             ShareContainerL( iContainerPosition );
       
   240             }
       
   241         }
       
   242     break;
       
   243     case CUpnpContainerCheckerAo::EMusic :
       
   244         {
       
   245         tmpContainer =
       
   246             UPnPCommonUtils::FindContainerByTitle( *iContainerList,
       
   247                                                    KMusicContainerName );
       
   248         if ( tmpContainer )
       
   249             {
       
   250             iMusicContainerId = UPnPCommonUtils::DesC8ToInt(
       
   251                 tmpContainer->Id() );
       
   252             iContainerList->RemoveAndDestroy( tmpContainer->Id() );
       
   253             tmpContainer = NULL;
       
   254             iContainerPosition++;
       
   255             iCurrentOperation = EQueryDefaultContainersResult;
       
   256             SelfComplete( KErrNone );
       
   257             }
       
   258         else
       
   259             {
       
   260             iCurrentOperation = EShareContainer;
       
   261             ShareContainerL( iContainerPosition );
       
   262             }
       
   263         }
       
   264     break;
       
   265     case CUpnpContainerCheckerAo::EUploaded :
       
   266         {
       
   267         tmpContainer =
       
   268             UPnPCommonUtils::FindContainerByTitle( *iContainerList,
       
   269                                                    KUploadedContainerName );
       
   270         if ( tmpContainer )
       
   271             {
       
   272             iUploadContainerId = UPnPCommonUtils::DesC8ToInt(
       
   273                 tmpContainer->Id() );
       
   274             iContainerList->RemoveAndDestroy( tmpContainer->Id() );
       
   275             tmpContainer = NULL;
       
   276             iContainerPosition++;
       
   277             iCurrentOperation = EQueryDefaultContainersResult;
       
   278             SelfComplete( KErrNone );
       
   279             }
       
   280         else
       
   281             {
       
   282             iCurrentOperation = EShareContainer;
       
   283             ShareContainerL( iContainerPosition );
       
   284             }
       
   285         }
       
   286     break;
       
   287     default :
       
   288         {
       
   289         // Store IDs of possible unwanted containers
       
   290         if ( iOperationMode != ECheckDefaultContainers )
       
   291             {
       
   292             for ( TInt i(0); i< iContainerList->ObjectCount(); i++ )
       
   293                 {
       
   294                 tmpContainer = static_cast< CUpnpContainer* >(
       
   295                     iContainerList->operator[]( i ));
       
   296                 iSharedContainerIds.AppendL(
       
   297                     UPnPCommonUtils::DesC8ToInt( tmpContainer->Id() ) );
       
   298                 }
       
   299 
       
   300 
       
   301             iState = EUnshareExtraContainers;
       
   302             iCurrentOperation = EUnshareContainer;
       
   303             }
       
   304         else
       
   305             {
       
   306             iCurrentOperation = ENotActive;
       
   307             }
       
   308 
       
   309         // Just add the Ids to client
       
   310         if ( iClientIds )
       
   311             {
       
   312             iClientIds->Reset();
       
   313             iClientIds->Append( iImageVideoContainerId );
       
   314             iClientIds->Append( iMusicContainerId );
       
   315             iClientIds->Append( iUploadContainerId );
       
   316             iClientIds->Compress();
       
   317             }
       
   318         delete iContainerList;
       
   319         iContainerList = NULL;
       
   320         SelfComplete( KErrNone );
       
   321         }
       
   322         break;
       
   323         }
       
   324 
       
   325     __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );
       
   326     }
       
   327 
       
   328 // --------------------------------------------------------------------------
       
   329 // CUpnpContainerCheckerAo::RunL
       
   330 // ( other items are commented in header )
       
   331 // --------------------------------------------------------------------------
       
   332 //
       
   333 void CUpnpContainerCheckerAo::RunL()
       
   334     {
       
   335     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
       
   336     if ( iStatus.Int() )
       
   337         {
       
   338         __LOG1( "Error: %d", iStatus.Int() );
       
   339         }
       
   340     
       
   341     if ( iStatus.Int() == KErrCorrupt )
       
   342         {
       
   343         if ( iRecoverError == ENoError )
       
   344             {
       
   345             iRecoverError = EDropAllContent;
       
   346             }
       
   347         else
       
   348             {
       
   349             iCurrentOperation = ENotActive;
       
   350             iRecoverError = ENoError;
       
   351             }
       
   352         }
       
   353     else if ( iStatus.Int() == KErrNoMemory ||
       
   354               iStatus.Int() == KErrDiskFull ||
       
   355               iStatus.Int() == KErrServerTerminated )
       
   356              {
       
   357              iCurrentOperation = ENotActive;
       
   358              SelfComplete( iStatus.Int() );
       
   359              }
       
   360 
       
   361 
       
   362     if ( iRecoverError )
       
   363         {
       
   364         switch ( iRecoverError )
       
   365             {
       
   366         case EDropAllContent :
       
   367             {
       
   368             iFileSharing->DropAllContentL( iStatus );
       
   369             iRecoverError = EDropAllContentResult;
       
   370             SetActive();
       
   371             }
       
   372             break; 
       
   373         case EDropAllContentResult :
       
   374             {
       
   375             if ( iStatus.Int() == KErrCorrupt )
       
   376                 {
       
   377                 iCurrentOperation = ENotActive;
       
   378                 SelfComplete( iStatus.Int() );
       
   379                 }
       
   380             else
       
   381                 {
       
   382                 iRecoverError = ENoError;
       
   383                 SelfComplete( KErrNone );
       
   384                 }
       
   385             }
       
   386             break;    
       
   387         default:
       
   388             __LOG1( "Error: %d", __LINE__ );
       
   389             break;
       
   390             }
       
   391 
       
   392         }
       
   393     else
       
   394         {
       
   395 
       
   396         if ( iStopRequested == MUpnpSharingCallback::ESharingPause )
       
   397             {
       
   398             delete iFileSharing;
       
   399             iFileSharing = NULL;
       
   400             iFileSharing = CUpnpFileSharing::NewL();
       
   401             TInt e = iMediaServer.Stop( 
       
   402                          RUpnpMediaServerClient::EStopSilent );
       
   403             if ( e )
       
   404                 {
       
   405                 __LOG1( "Error: %d", e );
       
   406                 }
       
   407             e = iMediaServer.StartOffline();
       
   408             if ( e )
       
   409                 {
       
   410                 __LOG1( "Error: %d", e );
       
   411                 }
       
   412             iStopRequested = MUpnpSharingCallback::ESharingNoStop;
       
   413             }
       
   414 
       
   415         switch ( iCurrentOperation )
       
   416             {
       
   417         case EInitialize :
       
   418             {
       
   419             InitializeL();
       
   420             }
       
   421             break;
       
   422         case EQueryDefaultContainers :
       
   423             {
       
   424             QueryDefaultContainerIdsL();
       
   425             }
       
   426             break;
       
   427         case EQueryDefaultContainersResult :
       
   428             {
       
   429             QueryDefaultContainerIdsResultL();
       
   430             }
       
   431             break;
       
   432         case EUnshareItemList :
       
   433             {
       
   434             UnshareItemListL();
       
   435             }
       
   436             break;
       
   437         case EQueryItemFromMediaServer :
       
   438             {
       
   439             QueryContainerItemsL();
       
   440             }
       
   441             break;
       
   442         case EQueryItemFromMediaServerResult :
       
   443             {
       
   444             QueryItemFromCdsResultL();
       
   445             }
       
   446             break;
       
   447         case EShareContainer :
       
   448             {
       
   449             __LOG1( "Error: %d", __LINE__ );
       
   450             }
       
   451             break;
       
   452         case EShareContainerResult :
       
   453             {
       
   454             ShareContainerResult();
       
   455             }
       
   456             break;
       
   457         case ENotActive :
       
   458             {
       
   459             Cleanup();
       
   460             if ( iCallback )
       
   461                 {
       
   462                 iCallback->CompleteSharingOperationL( iStatus.Int(), 0 );
       
   463                 }
       
   464             }
       
   465             // all operations requested done
       
   466             break;
       
   467         case EUnshareContainer :
       
   468             {
       
   469             UnshareContainerL();
       
   470             }
       
   471             break;
       
   472         case EUnshareContainerResult :
       
   473             {
       
   474             UnshareContainerResultL();
       
   475             }
       
   476             break;
       
   477         default :
       
   478             {
       
   479             __LOG1( "Error: %d", __LINE__ );
       
   480             break;
       
   481             }
       
   482             }
       
   483         }
       
   484     __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );
       
   485     }
       
   486 
       
   487 // --------------------------------------------------------------------------
       
   488 // CUpnpContainerCheckerAo::DoCancel
       
   489 // Cancels active object
       
   490 // --------------------------------------------------------------------------
       
   491 //
       
   492 void CUpnpContainerCheckerAo::DoCancel()
       
   493     {
       
   494     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
       
   495     // NOTE: The cancelling of mediaserver request must be made in destructor
       
   496     // because there is no cancel in CUpnpFileSharing
       
   497     __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );
       
   498     }
       
   499 
       
   500 // --------------------------------------------------------------------------
       
   501 // CUpnpContainerCheckerAo::RunError
       
   502 // ( other items are commented in header )
       
   503 // --------------------------------------------------------------------------
       
   504 //
       
   505 TInt CUpnpContainerCheckerAo::RunError( TInt aError )
       
   506     {
       
   507     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
       
   508     if ( aError )
       
   509         {
       
   510         __LOG8_1( "CUpnpContainerCheckerAo::RunError", aError );
       
   511         }
       
   512     TInt ret( KErrNone );
       
   513     if ( aError == KErrNoMemory ||
       
   514          aError == KErrDiskFull ||
       
   515          aError == KErrCorrupt )
       
   516         {
       
   517         iCurrentOperation = ENotActive;
       
   518         SelfComplete( aError );
       
   519         }
       
   520     else 
       
   521         {
       
   522         
       
   523         }
       
   524     __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );
       
   525     return ret;
       
   526     }
       
   527 
       
   528 
       
   529 // --------------------------------------------------------------------------
       
   530 // CUpnpContainerCheckerAo::QueryItemFromCdsResultL
       
   531 // ( other items are commented in header )
       
   532 // --------------------------------------------------------------------------
       
   533 //
       
   534 void CUpnpContainerCheckerAo::QueryItemFromCdsResultL()
       
   535     {
       
   536     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
       
   537     TInt objCount( iItemList->ObjectCount() );
       
   538     if ( objCount && ( iExecStatus < iTotalMatches ) )
       
   539         {
       
   540         iCurrentOperation = EUnshareItemList;
       
   541         }
       
   542     else
       
   543         {
       
   544         if ( iState == EEmptyRootContainerItems )
       
   545             {
       
   546             iState = EEmptyUploadedContainerItems;
       
   547             iCurrentOperation = EQueryItemFromMediaServer;
       
   548             }
       
   549         else
       
   550             {
       
   551             iState = EIdle;
       
   552             iCurrentOperation = ENotActive;
       
   553             }
       
   554         iExecStatus = 0;
       
   555         iTotalMatches = KErrNotFound;
       
   556 
       
   557         }
       
   558 
       
   559     SelfComplete( KErrNone );
       
   560     __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );
       
   561     }
       
   562 
       
   563 // --------------------------------------------------------------------------
       
   564 // CUpnpContainerCheckerAo::UnshareItemListL
       
   565 // ( other items are commented in header )
       
   566 // --------------------------------------------------------------------------
       
   567 //
       
   568 void CUpnpContainerCheckerAo::UnshareItemListL()
       
   569     {
       
   570     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
       
   571 
       
   572     iExecStatus += iItemList->ObjectCount();
       
   573     iFileSharing->UnshareItemListL( *iItemList, iMatchCount, iStatus );
       
   574 
       
   575     delete iItemList;
       
   576     iItemList = NULL;
       
   577     iCurrentOperation = EQueryItemFromMediaServer;
       
   578     SetActive();
       
   579     __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );
       
   580     }
       
   581 
       
   582 // --------------------------------------------------------------------------
       
   583 // CUpnpContainerCheckerAo::ShareContainerL
       
   584 // ( other items are commented in header )
       
   585 // --------------------------------------------------------------------------
       
   586 //
       
   587 void CUpnpContainerCheckerAo::ShareContainerL( TInt aPos )
       
   588     {
       
   589     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
       
   590  /*   iTmpContainer = CUpnpContainer::NewL();
       
   591     iTmpContainer->SetParentIdL( *UPnPCommonUtils::IntToDesC8LC(
       
   592         KRootContainerId ) );
       
   593     CleanupStack::PopAndDestroy(); //UPnPCommonUtils::IntToDesC8LC
       
   594     iTmpContainer->SetObjectClassL( KStorageFolderContainerClass );
       
   595 
       
   596     switch ( aPos )
       
   597         {
       
   598     case CUpnpContainerCheckerAo::EImageAndVideo :
       
   599         {
       
   600         iTmpContainer->SetTitleL( KImageContainerName );
       
   601         }
       
   602         break;
       
   603     case CUpnpContainerCheckerAo::EMusic :
       
   604         {
       
   605         iTmpContainer->SetTitleL( KMusicContainerName );
       
   606         }
       
   607         break;
       
   608     case CUpnpContainerCheckerAo::EUploaded :
       
   609         {
       
   610         iTmpContainer->SetTitleL( KUploadedContainerName );
       
   611         }
       
   612         break;
       
   613     default :
       
   614         break;
       
   615         }
       
   616     if ( iTmpContainer )
       
   617         {
       
   618         iFileSharing->ShareContainerL(
       
   619             *UPnPCommonUtils::IntToDesC8LC( KRootContainerId ),
       
   620             *iTmpContainer,
       
   621             iStatus );
       
   622         iCurrentOperation = EShareContainerResult;
       
   623         CleanupStack::PopAndDestroy(); // UPnPCommonUtils::IntToDesC8LC
       
   624         iCurrentOperation = EShareContainerResult;
       
   625         SetActive();
       
   626         }*/
       
   627     __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );
       
   628     }
       
   629 
       
   630 // --------------------------------------------------------------------------
       
   631 // CUpnpContainerCheckerAo::ShareContainerResult
       
   632 // ( other items are commented in header )
       
   633 // --------------------------------------------------------------------------
       
   634 //
       
   635 void CUpnpContainerCheckerAo::ShareContainerResult( )
       
   636     {
       
   637     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
       
   638     if ( !iStatus.Int() )
       
   639         {
       
   640         // Store the IDs
       
   641         if ( iContainerPosition == CUpnpContainerCheckerAo::EUploaded )
       
   642             {
       
   643             iUploadContainerId = UPnPCommonUtils::DesC8ToInt(
       
   644                 iTmpContainer->Id() );
       
   645             }
       
   646 
       
   647         else if ( iContainerPosition ==
       
   648                   CUpnpContainerCheckerAo::EImageAndVideo )
       
   649             {
       
   650             iImageVideoContainerId = UPnPCommonUtils::DesC8ToInt(
       
   651                 iTmpContainer->Id() );
       
   652             }
       
   653         else if ( iContainerPosition == CUpnpContainerCheckerAo::EMusic )
       
   654             {
       
   655             iMusicContainerId = UPnPCommonUtils::DesC8ToInt(
       
   656                 iTmpContainer->Id() );
       
   657             }
       
   658 
       
   659 
       
   660         }
       
   661     delete iTmpContainer;
       
   662     iTmpContainer = NULL;
       
   663 
       
   664     iCurrentOperation = EQueryDefaultContainersResult;
       
   665     iContainerPosition++;
       
   666     SelfComplete( KErrNone );
       
   667     __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );
       
   668     }
       
   669 
       
   670 // --------------------------------------------------------------------------
       
   671 // CUpnpContainerCheckerAo::UnshareContainerL
       
   672 // ( other items are commented in header )
       
   673 // --------------------------------------------------------------------------
       
   674 //
       
   675 void CUpnpContainerCheckerAo::UnshareContainerL()
       
   676     {
       
   677     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
       
   678     iCurrentOperation = EUnshareContainerResult;
       
   679     switch ( iState )
       
   680         {
       
   681     case EEmptyUploadedContainer :
       
   682         {
       
   683         __LOG1( "Error: %d", __LINE__ );
       
   684         }
       
   685         break;
       
   686     case EUnshareExtraContainers :
       
   687         {
       
   688         if ( iSharedContainerIds.Count() )
       
   689             {
       
   690             iSharedContainerIds.Compress();
       
   691             iFileSharing->UnshareContainerL( iSharedContainerIds[ 0 ],
       
   692                                              iStatus );
       
   693             iSharedContainerIds.Remove( 0 );
       
   694             SetActive();
       
   695             }
       
   696         else
       
   697             {
       
   698             iState = EEmptyRootContainerItems;
       
   699             QueryContainerItemsL();
       
   700             }
       
   701         }
       
   702         break;
       
   703     default :
       
   704         {
       
   705         __LOG1( "Error: %d", __LINE__ );
       
   706         }
       
   707         break;
       
   708         }
       
   709 
       
   710     __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );
       
   711     }
       
   712 
       
   713 // --------------------------------------------------------------------------
       
   714 // CUpnpContainerCheckerAo::UnshareContainerResultL
       
   715 // ( other items are commented in header )
       
   716 // --------------------------------------------------------------------------
       
   717 //
       
   718 void CUpnpContainerCheckerAo::UnshareContainerResultL()
       
   719     {
       
   720     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
       
   721     if ( iState == EEmptyUploadedContainer )
       
   722         {
       
   723         __LOG1( "Error: %d", __LINE__ );
       
   724         }
       
   725     else if ( iState == EUnshareExtraContainers )
       
   726         {
       
   727         if ( iSharedContainerIds.Count() )
       
   728             {
       
   729             iCurrentOperation = EUnshareContainer;
       
   730             }
       
   731         else
       
   732             {
       
   733             iState = EEmptyRootContainerItems;
       
   734             iCurrentOperation = EQueryItemFromMediaServer;
       
   735             }
       
   736         SelfComplete( KErrNone );
       
   737         }
       
   738 
       
   739     __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );
       
   740     }
       
   741 
       
   742 // --------------------------------------------------------------------------
       
   743 // CUpnpContainerCheckerAo::QueryContainerItemsL
       
   744 // ( other items are commented in header )
       
   745 // --------------------------------------------------------------------------
       
   746 //
       
   747 void CUpnpContainerCheckerAo::QueryContainerItemsL()
       
   748     {
       
   749     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
       
   750     delete iItemList;
       
   751     iItemList = NULL;
       
   752     iItemList = CUpnpItemList::NewL();
       
   753     TInt containerId( KRootContainerId );
       
   754     if ( iState == EEmptyUploadedContainerItems )
       
   755         {
       
   756         containerId = iUploadContainerId;
       
   757         }
       
   758     CUpnpBrowseCriteria* browseCriteria = CreateBrowseCriteriaLC();
       
   759     if ( iTotalMatches == KErrNotFound )
       
   760         {
       
   761         iFileSharing->GetSharedItemListL (
       
   762             containerId, *browseCriteria,
       
   763             *iItemList, iTotalMatches, iStatus );
       
   764         }
       
   765     else
       
   766         {
       
   767         TInt tmp( 0 );
       
   768         iFileSharing->GetSharedItemListL (
       
   769             containerId, *browseCriteria,
       
   770             *iItemList, tmp, iStatus );
       
   771         }
       
   772     iCurrentOperation = EQueryItemFromMediaServerResult;
       
   773     CleanupStack::PopAndDestroy( browseCriteria );
       
   774     SetActive();
       
   775     __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );
       
   776     }
       
   777 
       
   778 // --------------------------------------------------------------------------
       
   779 // CUpnpContainerCheckerAo::CreateBrowseCriteriaLC
       
   780 // ( other items are commented in header )
       
   781 // --------------------------------------------------------------------------
       
   782 //
       
   783 CUpnpBrowseCriteria* CUpnpContainerCheckerAo::CreateBrowseCriteriaLC() const
       
   784     {
       
   785     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
       
   786     CUpnpBrowseCriteria* browseCriteria = CUpnpBrowseCriteria::NewLC();
       
   787     browseCriteria->SetRequestedCount( KDefaultBrowseReqCount );
       
   788     browseCriteria->SetStartingIndex( KDefaultBrowseStartingInd );
       
   789     __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );
       
   790     return browseCriteria;
       
   791     }
       
   792 
       
   793 // --------------------------------------------------------------------------
       
   794 // CUpnpContainerCheckerAo::Cleanup
       
   795 // ( other items are commented in header )
       
   796 // --------------------------------------------------------------------------
       
   797 //
       
   798 void CUpnpContainerCheckerAo::Cleanup()
       
   799     {
       
   800     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
       
   801     iExecStatus = 0;
       
   802     iTotalMatches = KErrNotFound;
       
   803     iImageVideoContainerId = 0;
       
   804     iMusicContainerId = 0;
       
   805     iUploadContainerId = 0;
       
   806     iContainerPosition = 0;
       
   807     iClientIds = NULL;
       
   808     delete iItemList;
       
   809     iItemList = NULL;
       
   810     delete iContainerList;
       
   811     iContainerList = NULL;
       
   812     delete iTmpContainer;
       
   813     iTmpContainer = NULL;
       
   814     iSharedContainerIds.Close();
       
   815     iState = EIdle;
       
   816     iCurrentOperation = ENotActive;
       
   817     if ( IsAdded() )
       
   818         {
       
   819         Deque();
       
   820         }
       
   821     __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );
       
   822     }
       
   823 
       
   824 // --------------------------------------------------------------------------
       
   825 // CUpnpContainerCheckerAo::SelfComplete
       
   826 // Start observing events
       
   827 // --------------------------------------------------------------------------
       
   828 //
       
   829 void CUpnpContainerCheckerAo::SelfComplete( TInt aError )
       
   830     {
       
   831     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
       
   832     SetActive();
       
   833     TRequestStatus* stat = &iStatus;
       
   834     User::RequestComplete( stat, aError );
       
   835     __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );
       
   836     }
       
   837 
       
   838 // End of File