videofeeds/clientapi/src/CIptvMyVideosCopyOrMoveObserver.cpp
branchRCL_3
changeset 23 befca0ec475f
parent 0 96612d01cf9f
equal deleted inserted replaced
22:839377eedc2b 23:befca0ec475f
       
     1 /*
       
     2 * Copyright (c) 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 the License "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:    Observer for completion of copy or move requests.*
       
    15 */
       
    16 
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "IptvClientServerCommon.h"
       
    22 #include "RIptvClientSession.h"
       
    23 #include "CIptvMyVideosCopyOrMoveObserver.h"
       
    24 #include "MIptvMyVideosClientObserver.h"
       
    25 #include "CIptvMyVideosGlobalFileId.h"
       
    26 #include "CIptvMyVideosGlobalFolderId.h"
       
    27 
       
    28 // CONSTANTS
       
    29 const TInt KTUint32SizeInBytes = 4;
       
    30 
       
    31 // ============================ MEMBER FUNCTIONS ===============================
       
    32 
       
    33 // ---------------------------------------------------------
       
    34 // CIptvMyVideosCopyOrMoveObserver::CIptvMyVideosCopyOrMoveObserver()
       
    35 // ---------------------------------------------------------
       
    36 //
       
    37 CIptvMyVideosCopyOrMoveObserver::CIptvMyVideosCopyOrMoveObserver(MIptvMyVideosClientObserver& aClientObserver, RIptvClientSession& aSession) 
       
    38  :  CActive(EPriorityStandard),
       
    39     iClientObserver(aClientObserver),
       
    40     iSession(aSession),
       
    41     iMsgPtr((unsigned char*)0, 0)
       
    42     {
       
    43     CActiveScheduler::Add(this);
       
    44     }
       
    45 
       
    46 // ---------------------------------------------------------
       
    47 // CIptvMyVideosCopyOrMoveObserver::NewL()
       
    48 // ---------------------------------------------------------
       
    49 //
       
    50 CIptvMyVideosCopyOrMoveObserver* CIptvMyVideosCopyOrMoveObserver::NewL(MIptvMyVideosClientObserver& aClientObserver, RIptvClientSession& aSession)
       
    51     {
       
    52     CIptvMyVideosCopyOrMoveObserver* self = new (ELeave) CIptvMyVideosCopyOrMoveObserver(aClientObserver, aSession);
       
    53     CleanupStack::PushL(self);
       
    54     self->ConstructL();
       
    55     CleanupStack::Pop(self);
       
    56     return self;
       
    57     }
       
    58 
       
    59 // ---------------------------------------------------------
       
    60 // CIptvMyVideosCopyOrMoveObserver::ConstructL()
       
    61 // ---------------------------------------------------------
       
    62 //
       
    63 void CIptvMyVideosCopyOrMoveObserver::ConstructL()
       
    64     {
       
    65     }
       
    66 
       
    67 // ---------------------------------------------------------
       
    68 // CIptvMyVideosCopyOrMoveObserver::~CIptvMyVideosCopyOrMoveObserver()
       
    69 // ---------------------------------------------------------
       
    70 //
       
    71 CIptvMyVideosCopyOrMoveObserver::~CIptvMyVideosCopyOrMoveObserver()
       
    72     {
       
    73     Cancel();
       
    74 
       
    75     delete iMsg;
       
    76     }
       
    77 
       
    78 // ---------------------------------------------------------
       
    79 // CIptvMyVideosCopyOrMoveObserver::SetActiveL()
       
    80 // ---------------------------------------------------------
       
    81 //
       
    82 void CIptvMyVideosCopyOrMoveObserver::SetActiveL(TUint16 aCommand, CIptvMyVideosGlobalFileId& aSourceFileId, CIptvMyVideosGlobalFolderId& aTargetFolderId)
       
    83     {
       
    84     if (! IsActive())
       
    85         {
       
    86         TInt dataSize = 0;
       
    87 
       
    88         delete iMsg;
       
    89         iMsg = NULL;
       
    90 
       
    91         dataSize  = KTUint32SizeInBytes; // aCommand
       
    92         dataSize += aSourceFileId.CountExternalizeSize();
       
    93         dataSize += aTargetFolderId.CountExternalizeSize();
       
    94 
       
    95         iMsg = HBufC8::NewL(dataSize > (KTUint32SizeInBytes * 2) ? dataSize : (KTUint32SizeInBytes * 2)); // Return values need 8 bytes.
       
    96         iMsgPtr.Set(iMsg->Des());      
       
    97 
       
    98         RDesWriteStream stream;
       
    99         stream.Open(iMsgPtr);
       
   100         CleanupClosePushL( stream );
       
   101         aSourceFileId.ExternalizeL(stream);
       
   102         aTargetFolderId.ExternalizeL(stream);
       
   103         CleanupStack::PopAndDestroy( &stream );
       
   104 
       
   105         iSession.SendRequest(aCommand, iMsgPtr, iStatus);
       
   106         CActive::SetActive();        
       
   107         }
       
   108     }
       
   109     
       
   110 // ---------------------------------------------------------
       
   111 // CIptvMyVideosCopyOrMoveObserver::SetActiveL()
       
   112 // ---------------------------------------------------------
       
   113 //
       
   114 void CIptvMyVideosCopyOrMoveObserver::SetActiveL(TUint16 aCommand, CIptvMyVideosGlobalFolderId& aSourceFolderId, CIptvMyVideosGlobalFolderId& aTargetFolderId)
       
   115     {
       
   116     if (! IsActive())
       
   117         {
       
   118         TInt dataSize = 0;
       
   119 
       
   120         delete iMsg;
       
   121         iMsg = NULL;
       
   122 
       
   123         dataSize  = KTUint32SizeInBytes; // aCommand
       
   124         dataSize += aSourceFolderId.CountExternalizeSize();
       
   125         dataSize += aTargetFolderId.CountExternalizeSize();
       
   126 
       
   127         iMsg = HBufC8::NewL(dataSize > (KTUint32SizeInBytes * 2) ? dataSize : (KTUint32SizeInBytes * 2)); // Return values need 8 bytes.
       
   128         iMsgPtr.Set(iMsg->Des());      
       
   129 
       
   130         RDesWriteStream stream;
       
   131         stream.Open(iMsgPtr);
       
   132         CleanupClosePushL( stream );
       
   133         aSourceFolderId.ExternalizeL(stream);
       
   134         aTargetFolderId.ExternalizeL(stream);
       
   135         CleanupStack::PopAndDestroy( &stream );
       
   136 
       
   137         iSession.SendRequest(aCommand, iMsgPtr, iStatus);
       
   138         CActive::SetActive();        
       
   139         }
       
   140     }
       
   141 
       
   142 // -----------------------------------------------------------------------------
       
   143 // CIptvMyVideosCopyOrMoveObserver::RunL()
       
   144 // Server has finished the copy or move request.
       
   145 // -----------------------------------------------------------------------------
       
   146 //
       
   147 void CIptvMyVideosCopyOrMoveObserver::RunL()
       
   148     {
       
   149     TInt operationStatus = KErrGeneral;
       
   150     TInt failed          = 0;
       
   151 
       
   152     if (iStatus.Int() == KErrNone)
       
   153         {
       
   154         if (iMsg)
       
   155             {
       
   156             RDesReadStream stream;
       
   157             CleanupClosePushL( stream );
       
   158             stream.Open(iMsgPtr);
       
   159             operationStatus = stream.ReadUint32L();
       
   160             failed          = stream.ReadUint32L();
       
   161             CleanupStack::PopAndDestroy( &stream );
       
   162             }
       
   163         }
       
   164 
       
   165     delete iMsg;
       
   166     iMsg = NULL;
       
   167 
       
   168     // Call obsever, except in the case when server was cancelled.
       
   169     // This situation happens during shutdown so client is no more.    
       
   170     if (iStatus.Int() != KErrCancel)
       
   171         {
       
   172         iClientObserver.CopyOrMoveResponse(iStatus.Int(), operationStatus, failed);
       
   173         }
       
   174     }
       
   175 
       
   176 // ---------------------------------------------------------
       
   177 // CIptvMyVideosCopyOrMoveObserver::DoCancel()
       
   178 // ---------------------------------------------------------
       
   179 //
       
   180 void CIptvMyVideosCopyOrMoveObserver::DoCancel()
       
   181     {
       
   182     }
       
   183 
       
   184 // End of file.