upnpsharing/upnpsharingalgorithm/src/upnpsharingao.cpp
branchIOP_Improvements
changeset 40 08b5eae9f9ff
equal deleted inserted replaced
39:6369bfd1b60d 40:08b5eae9f9ff
       
     1 /**
       
     2  * Copyright (c) 2009 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:  CUpnpSharingAO class implementation
       
    15  *
       
    16  */
       
    17 
       
    18 // INCLUDES
       
    19 #include <upnpcontainer.h>
       
    20 #include <upnpfilesharing.h>
       
    21 #include "upnpsharingao.h"
       
    22 #include "upnpsharingalgorithmconstants.h"
       
    23 #include "upnplog.h"
       
    24 
       
    25 // --------------------------------------------------------------------------
       
    26 // CUpnpSecAccessController::NewL
       
    27 // --------------------------------------------------------------------------
       
    28 //
       
    29 CUpnpSharingAO* CUpnpSharingAO::NewL()
       
    30     {
       
    31     __LOG( "[CUpnpSharingAlgorithm]\t CUpnpSharingAO::NewL" );
       
    32 
       
    33     CUpnpSharingAO* self = new (ELeave) CUpnpSharingAO;
       
    34     CleanupStack::PushL( self );
       
    35     self->ConstructL();
       
    36     CleanupStack::Pop( self );
       
    37     return self;
       
    38     }
       
    39 
       
    40 // --------------------------------------------------------------------------
       
    41 // CUpnpSharingAO::ConstructL
       
    42 // --------------------------------------------------------------------------
       
    43 //
       
    44 void CUpnpSharingAO::ConstructL()
       
    45     {
       
    46     __LOG( "[CUpnpSharingAlgorithm]\t CUpnpSharingAO::\
       
    47 ConstructL" );
       
    48 
       
    49     if ( !CActiveScheduler::Current() )
       
    50         {
       
    51         iScheduler = new( ELeave ) CActiveScheduler;
       
    52         CActiveScheduler::Install( iScheduler );
       
    53         }
       
    54 
       
    55     // Add this active object to the active scheduler.
       
    56     CActiveScheduler::Add( this );
       
    57 
       
    58     iFileSharing = CUpnpFileSharing::NewL();
       
    59     iWaitRequest = new ( ELeave ) CActiveSchedulerWait();
       
    60 
       
    61     }
       
    62 
       
    63 // --------------------------------------------------------------------------
       
    64 // CUpnpSharingAO::~CUpnpSharingAO
       
    65 // --------------------------------------------------------------------------
       
    66 //
       
    67 CUpnpSharingAO::~CUpnpSharingAO()
       
    68     {
       
    69     __LOG( "[CUpnpSharingAlgorithm]\t CUpnpSharingAO::\
       
    70 ~CUpnpSharingAO" );
       
    71 
       
    72     delete iFileSharing;
       
    73     delete iWaitRequest;
       
    74 
       
    75     if ( CActiveScheduler::Current() == iScheduler )
       
    76         {
       
    77         CActiveScheduler::Install( NULL );
       
    78         }
       
    79     delete iScheduler;
       
    80     }
       
    81 
       
    82 // --------------------------------------------------------------------------
       
    83 // CUpnpSharingAO::ShareFileL
       
    84 // --------------------------------------------------------------------------
       
    85 //
       
    86 void CUpnpSharingAO::ShareFileL( const TDesC8& aParentContainerId,
       
    87                                  CUpnpItem* aItem )
       
    88     {
       
    89     __LOG( "[CUpnpSharingAlgorithm]\t CUpnpSharingAO::ShareFileL" );
       
    90 
       
    91     iFileSharing->ShareItemL( aParentContainerId, *aItem, iStatus );
       
    92 
       
    93     CompleteRequestL();
       
    94     }
       
    95 
       
    96 // --------------------------------------------------------------------------
       
    97 // CUpnpSharingAO::ShareReferenceL
       
    98 // --------------------------------------------------------------------------
       
    99 //
       
   100 void CUpnpSharingAO::ShareReferenceL( const TInt aParentContainerId,
       
   101                                       const TInt aOriginalItemId,
       
   102                                       CUpnpItem* aItem )
       
   103     {
       
   104     __LOG( "[CUpnpSharingAlgorithm]\t CUpnpSharingAO::ShareReferenceL" );
       
   105 
       
   106     iFileSharing->ShareReferenceL( aParentContainerId,
       
   107                                    aOriginalItemId,
       
   108                                    *aItem,
       
   109                                    iStatus );
       
   110 
       
   111     CompleteRequestL();
       
   112     }
       
   113 
       
   114 // --------------------------------------------------------------------------
       
   115 // CUpnpSharingAO::ShareContainerL
       
   116 // --------------------------------------------------------------------------
       
   117 //
       
   118 void CUpnpSharingAO::ShareContainerL( CUpnpContainer* aContainer )
       
   119     {
       
   120     __LOG( "[CUpnpSharingAlgorithm]\t CUpnpSharingAO::ShareContainerL" );
       
   121 
       
   122     iFileSharing->ShareContainerL( aContainer->ParentId(),
       
   123                                    *aContainer,
       
   124                                    iStatus );
       
   125 
       
   126     CompleteRequestL();
       
   127     }
       
   128 
       
   129 // --------------------------------------------------------------------------
       
   130 // CUpnpSharingAO::UnShareFileL
       
   131 // --------------------------------------------------------------------------
       
   132 //
       
   133 void CUpnpSharingAO::UnshareFileL( const TInt aItemId )
       
   134     {
       
   135     __LOG( "[CUpnpSharingAlgorithm]\t CUpnpSharingAO::\
       
   136 UnShareFileL" );
       
   137 
       
   138     iFileSharing->UnshareItemL( aItemId, iStatus );
       
   139 
       
   140     CompleteRequestL();
       
   141     }
       
   142 
       
   143 // --------------------------------------------------------------------------
       
   144 // CUpnpSharingAO::UnShareContainerL
       
   145 // --------------------------------------------------------------------------
       
   146 //
       
   147 void CUpnpSharingAO::UnshareContainerL( const TInt aContainerId )
       
   148     {
       
   149     __LOG( "[CUpnpSharingAlgorithm]\t CUpnpSharingAO::\
       
   150 UnShareContainerL" );
       
   151 
       
   152     iFileSharing->UnshareContainerL( aContainerId, iStatus );
       
   153 
       
   154     CompleteRequestL();
       
   155     }
       
   156 
       
   157 // --------------------------------------------------------------------------
       
   158 // CUpnpCdsReaderAO::CompleteRequestL
       
   159 // --------------------------------------------------------------------------
       
   160 //
       
   161 void CUpnpSharingAO::CompleteRequestL()
       
   162     {
       
   163     __LOG( "[CUpnpSharingAlgorithm]\t CUpnpSharingAO::\
       
   164 CompleteRequestL" );
       
   165 
       
   166     if ( !IsActive() )
       
   167         {
       
   168         SetActive();
       
   169         }
       
   170     else
       
   171         {
       
   172         User::Leave( KErrInUse );
       
   173         }
       
   174 
       
   175     // ...and then wait request to complete
       
   176     // RunL releases wait
       
   177     WaitRequestToComplete();
       
   178     // Leave if error happens on file unsharing
       
   179     User::LeaveIfError( iStatus.Int() );
       
   180     }
       
   181 
       
   182 // --------------------------------------------------------------------------
       
   183 // CUpnpSharingAO::RunL
       
   184 // --------------------------------------------------------------------------
       
   185 //
       
   186 void CUpnpSharingAO::CUpnpSharingAO::RunL()
       
   187     {
       
   188     __LOG( "[CUpnpSharingAlgorithm]\t CUpnpSharingAO::RunL" );
       
   189 
       
   190     // Request completed - no need to wait anymore
       
   191     // Let ao caller to continue
       
   192     StopWaitingRequestComplete();
       
   193     }
       
   194 
       
   195 // ---------------------------------------------------------------------------
       
   196 // CUpnpSharingAO::DoCancel
       
   197 // ---------------------------------------------------------------------------
       
   198 //
       
   199 void CUpnpSharingAO::CUpnpSharingAO::DoCancel()
       
   200     {
       
   201     __LOG( "[CUpnpSharingAlgorithm]\t CUpnpSharingAO::DoCancel" );
       
   202 
       
   203     Cancel();
       
   204     }
       
   205 
       
   206 // ---------------------------------------------------------------------------
       
   207 // CUpnpSharingAO::WaitRequestToComplete
       
   208 // ---------------------------------------------------------------------------
       
   209 //
       
   210 void CUpnpSharingAO::WaitRequestToComplete()
       
   211     {
       
   212     __LOG( "[CUpnpSharingAlgorithm]\t CUpnpSharingAO::\
       
   213 WaitRequestToComplete" );
       
   214 
       
   215     if ( iWaitRequest &&
       
   216          !iWaitRequest->IsStarted() )
       
   217         {
       
   218         iWaitRequest->Start();
       
   219         }
       
   220     }
       
   221 
       
   222 // ---------------------------------------------------------------------------
       
   223 // CUpnpSharingAO::StopWaitingRequestComplete
       
   224 // ---------------------------------------------------------------------------
       
   225 //
       
   226 void CUpnpSharingAO::StopWaitingRequestComplete()
       
   227     {
       
   228     __LOG( "[CUpnpSharingAlgorithm]\t CUpnpSharingAO::\
       
   229 StopWaitingRequestComplete" );
       
   230 
       
   231     if ( iWaitRequest &&
       
   232          iWaitRequest->IsStarted() )
       
   233         {
       
   234         iWaitRequest->AsyncStop();
       
   235         }
       
   236     }
       
   237 
       
   238 //  End of File