btobexprofiles/obexsendservices/obexservicesendutils/src/BTSOPPController.cpp
branchRCL_3
changeset 56 9386f31cc85b
parent 55 613943a21004
child 61 269724087bed
equal deleted inserted replaced
55:613943a21004 56:9386f31cc85b
     1 /*
       
     2 * Copyright (c) 2002 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:  Object push controller implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "BTSOPPController.h"
       
    22 #include "BTSUDebug.h"
       
    23 
       
    24 // ============================ MEMBER FUNCTIONS ===============================
       
    25 
       
    26 // -----------------------------------------------------------------------------
       
    27 // CBTSOPPController::CBTSOPPController
       
    28 // C++ default constructor can NOT contain any code, that
       
    29 // might leave.
       
    30 // -----------------------------------------------------------------------------
       
    31 //
       
    32 CBTSOPPController::CBTSOPPController( MBTServiceObserver* aObserver,
       
    33                                      CBTServiceParameterList* aList ) : 
       
    34                                      iListPtr( aList ), 
       
    35                                      iObserverPtr( aObserver )
       
    36     {
       
    37     }
       
    38 
       
    39 // -----------------------------------------------------------------------------
       
    40 // CBTSOPPController::ConstructL
       
    41 // Symbian 2nd phase constructor can leave.
       
    42 // -----------------------------------------------------------------------------
       
    43 //
       
    44 void CBTSOPPController::ConstructL( const TUint aRemotePort, const TBTDevAddr& aRemoteDeviceAddr )
       
    45     {
       
    46     FLOG(_L("[BTSS]\t CBTSOPPController::ConstructL()"));
       
    47     
       
    48     RArray<CObexHeader*> headerList;
       
    49     CleanupClosePushL( headerList );
       
    50     CreateClientL ( this, aRemoteDeviceAddr, aRemotePort, headerList );
       
    51     CleanupStack::Pop();   
       
    52     headerList.Close();
       
    53    
       
    54     FLOG(_L("[BTSS]\t CBTSOPPController::ConstructL() completed"));
       
    55     }
       
    56 
       
    57 // -----------------------------------------------------------------------------
       
    58 // CBTSOPPController::NewL
       
    59 // Two-phased constructor.
       
    60 // -----------------------------------------------------------------------------
       
    61 //
       
    62 CBTSOPPController* CBTSOPPController::NewL( MBTServiceObserver* aObserver,
       
    63                                            const TUint aRemotePort,
       
    64                                            const TBTDevAddr& aRemoteDeviceAddr,
       
    65                                            CBTServiceParameterList* aList )
       
    66     {
       
    67     CBTSOPPController* self = new( ELeave ) CBTSOPPController( aObserver, aList );
       
    68     CleanupStack::PushL( self );
       
    69     self->ConstructL( aRemotePort, aRemoteDeviceAddr );
       
    70     CleanupStack::Pop();
       
    71     return self;
       
    72     }
       
    73 
       
    74 // Destructor
       
    75 CBTSOPPController::~CBTSOPPController()
       
    76     {
       
    77     FLOG(_L("[BTSU]\t CBTSOPPController::Destructor()"));    
       
    78     }
       
    79 
       
    80 // -----------------------------------------------------------------------------
       
    81 // CBTSOPPController::ConnectCompleted
       
    82 // -----------------------------------------------------------------------------
       
    83 //
       
    84 void CBTSOPPController::ConnectCompleted( TInt aStatus )
       
    85     {
       
    86     FLOG(_L("[BTSS]\t CBTSOPPController::ConnectCompleted()"));
       
    87     
       
    88     if ( aStatus == KErrNone )
       
    89         {
       
    90         TRAPD( error, HandleConnectCompleteIndicationL() );
       
    91         if ( error != KErrNone )
       
    92             {
       
    93             // Sending initialisation has failed
       
    94             //
       
    95             iObserverPtr->ControllerComplete( EBTSConnectingFailed );
       
    96             }
       
    97         }
       
    98     else
       
    99         {
       
   100         //Error on Obex level
       
   101         //
       
   102         iObserverPtr->ControllerComplete( EBTSConnectingFailed );
       
   103         }
       
   104 
       
   105     FLOG(_L("[BTSS]\t CBTSOPPController::ConnectCompleted() completed"));
       
   106     }
       
   107 
       
   108 // -----------------------------------------------------------------------------
       
   109 // CBTSOPPController::ClientConnectionClosed
       
   110 // -----------------------------------------------------------------------------
       
   111 //
       
   112 void CBTSOPPController::ClientConnectionClosed()
       
   113     {
       
   114     FLOG(_L("[BTSS]\t CBTSOPPController::ClientConnectionClosed()"));
       
   115 
       
   116     // Everything ready, stop service
       
   117     //
       
   118     iObserverPtr->ControllerComplete( EBTSNoError );
       
   119 
       
   120     FLOG(_L("[BTSS]\t CBTSOPPController::ClientConnectionClosed() completed"));
       
   121     }
       
   122 
       
   123 // -----------------------------------------------------------------------------
       
   124 // CBTSOPPController::PutCompleted
       
   125 // -----------------------------------------------------------------------------
       
   126 //
       
   127 void CBTSOPPController::PutCompleted( TInt aStatus, const CObexHeaderSet* aPutResponse )
       
   128     {
       
   129     FLOG(_L("[BTSS]\t CBTSOPPController::PutCompleted()"));
       
   130 	aPutResponse=aPutResponse;
       
   131 
       
   132   
       
   133     if ( aStatus == KErrNone )
       
   134         {       
       
   135         iFileIndex++;
       
   136         Send();        
       
   137         }
       
   138     else
       
   139         {
       
   140         iObserverPtr->ControllerComplete( EBTSPuttingFailed );
       
   141         }
       
   142     
       
   143     FLOG(_L("[BTSS]\t CBTSOPPController::PutCompleted() done"));
       
   144     }
       
   145 
       
   146 // -----------------------------------------------------------------------------
       
   147 // CBTSOPPController::GetCompleted
       
   148 // -----------------------------------------------------------------------------
       
   149 //
       
   150 void CBTSOPPController::GetCompleted( TInt /*aStatus*/, CObexBufObject* /*aGetResponse*/ )
       
   151     {
       
   152     FLOG(_L("[BTSS]\t CBTSOPPController::GetCompleted() Not used with OPP"));
       
   153     }
       
   154 
       
   155 // -----------------------------------------------------------------------------
       
   156 // CBTSOPPController::Send
       
   157 // -----------------------------------------------------------------------------
       
   158 //
       
   159 void CBTSOPPController::Send()
       
   160     {
       
   161     FLOG(_L("[BTSS]\t CBTSOPPController::Send()"));
       
   162     
       
   163     TInt error(KErrNone);
       
   164 
       
   165     if ( iListPtr->ObjectCount() > 0 && iFileIndex < iListPtr->ObjectCount() )
       
   166         {    
       
   167         RArray<CObexHeader*> headerList; // the array does not need to be closed    
       
   168 
       
   169         TRAP( error, {
       
   170                 UpdateProgressNoteL();
       
   171                 iClient->PutObjectL( headerList, iListPtr->ObjectAtL( iFileIndex ));  });
       
   172 
       
   173         if ( error )
       
   174             {
       
   175             FTRACE(FPrint(_L("[BTSU]\t CBTSOPPController::Send() putting leaved with %d"), error ));
       
   176             iObserverPtr->ControllerComplete( EBTSPuttingFailed );
       
   177             }
       
   178         }
       
   179     else
       
   180         {        
       
   181         FLOG(_L("[BTSU]\t CBTSOPPController::Send() all objects sent, closing connection"));
       
   182 
       
   183         // All objects sent, close client connection.
       
   184         //
       
   185         iClient->CloseClientConnection();
       
   186         }
       
   187 
       
   188     FLOG(_L("[BTSS]\t CBTSOPPController::Send() Done"));
       
   189     }
       
   190 
       
   191 //-----------------------------------------------------------------------------
       
   192 // void CBTSOPPController::ConnectTimedOut()
       
   193 // -----------------------------------------------------------------------------
       
   194 //        
       
   195 void CBTSOPPController::ConnectTimedOut()    
       
   196     {
       
   197     iObserverPtr->ConnectTimedOut();
       
   198     }
       
   199 
       
   200 // -----------------------------------------------------------------------------
       
   201 // CBTSOPPController::HandleConnectCompleteIndicationL
       
   202 // -----------------------------------------------------------------------------
       
   203 //
       
   204 void CBTSOPPController::HandleConnectCompleteIndicationL()
       
   205     {
       
   206     FLOG(_L("[BTSS]\t CBTSOPPController::HandleConnectCompleteIndicationL()"));
       
   207     TBTSUImageParam imgparam;
       
   208     if ( iListPtr->ImageCount() > 0 )
       
   209         {
       
   210         for( TInt index = 0; index < iListPtr->ImageCount(); index++ )
       
   211             {
       
   212             // Copy files from Image list to Object list
       
   213             // from now on we use only object list.
       
   214             imgparam = iListPtr->ImageAtL( index );
       
   215             if(!imgparam.iSend)
       
   216                 {
       
   217                 iListPtr->AddObjectL( imgparam.iFile);
       
   218                 }            
       
   219             }
       
   220         }
       
   221     iObserverPtr->LaunchProgressNoteL( iClient, iListPtr->ObjectCount() );
       
   222     iFileIndex = 0;
       
   223     UpdateProgressNoteL();    
       
   224     Send();
       
   225     }
       
   226 
       
   227 
       
   228 void CBTSOPPController::UpdateProgressNoteL()
       
   229     {
       
   230     TInt size;
       
   231     RBuf filename;
       
   232     iListPtr->ObjectAtL( iFileIndex ).Size(size);
       
   233     filename.CreateL(KMaxFileName);
       
   234     iListPtr->ObjectAtL( iFileIndex ).Name(filename);
       
   235     iObserverPtr->UpdateProgressNoteL(size,iFileIndex,filename);
       
   236     filename.Close();
       
   237     }
       
   238 
       
   239 //  End of File