localconnectivityservice/obexsendservices/obexservicebtsend/src/btsssendlisthandler.cpp
branchRCL_3
changeset 40 52a167391590
equal deleted inserted replaced
39:4096754ee773 40:52a167391590
       
     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:  Converter class implementation for converting AIW paramerer 
       
    15 *                list to bt send parameter list
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #include <AiwGenericParam.h>
       
    21 
       
    22 #include "BTSSSendListHandler.h"
       
    23 #include "BTServiceParameterList.h"
       
    24 #include "BTSendingServiceDebug.h"
       
    25 
       
    26 
       
    27 
       
    28 // ======== MEMBER FUNCTIONS ========
       
    29 
       
    30 // ---------------------------------------------------------------------------
       
    31 // CBTSSSendListHandler()
       
    32 // ---------------------------------------------------------------------------
       
    33 //
       
    34 CBTSSSendListHandler::CBTSSSendListHandler(): CActive( EPriorityNormal )
       
    35     {
       
    36     CActiveScheduler::Add(this);
       
    37     }
       
    38 
       
    39 // ---------------------------------------------------------------------------
       
    40 // ConstructL()
       
    41 // ---------------------------------------------------------------------------
       
    42 //
       
    43 void CBTSSSendListHandler::ConstructL()
       
    44     {
       
    45     }
       
    46 
       
    47 
       
    48 // ---------------------------------------------------------------------------
       
    49 // NewL()
       
    50 // ---------------------------------------------------------------------------
       
    51 //
       
    52 CBTSSSendListHandler* CBTSSSendListHandler::NewL()
       
    53     {
       
    54     CBTSSSendListHandler* self = CBTSSSendListHandler::NewLC();
       
    55     CleanupStack::Pop( self );
       
    56     return self;
       
    57     }
       
    58 
       
    59 
       
    60 // ---------------------------------------------------------------------------
       
    61 // NewLC()
       
    62 // ---------------------------------------------------------------------------
       
    63 //
       
    64 CBTSSSendListHandler* CBTSSSendListHandler::NewLC()
       
    65     {
       
    66     CBTSSSendListHandler* self = new( ELeave ) CBTSSSendListHandler();
       
    67     CleanupStack::PushL( self );
       
    68     self->ConstructL();
       
    69     return self;
       
    70     }
       
    71 
       
    72 
       
    73 // ---------------------------------------------------------------------------
       
    74 // CBTSSSendListHandler
       
    75 // ---------------------------------------------------------------------------
       
    76 //
       
    77 CBTSSSendListHandler::~CBTSSSendListHandler()    
       
    78     {
       
    79     FLOG(_L("[BTSS]\t CBTSSSendListHandler::Destructor"));     
       
    80     Cancel();
       
    81     }
       
    82 
       
    83 // ---------------------------------------------------------------------------
       
    84 // ConvertList()
       
    85 // ---------------------------------------------------------------------------
       
    86 //
       
    87 TInt CBTSSSendListHandler::ConvertList( const CAiwGenericParamList* aOutParamList, 
       
    88                                         CBTServiceParameterList* aList)
       
    89     {
       
    90     FLOG(_L("[BTSS]\t CBTSSSendListHandler::ConvertList"));           
       
    91     iListIndex = 0;    
       
    92     iOutParamList = aOutParamList;
       
    93     iList = aList;
       
    94     iStatus = KRequestPending;
       
    95     AddObject();
       
    96     SetActive();
       
    97     
       
    98     iSyncWaiter.Start();
       
    99     FLOG(_L("[BTSS]\t CBTSSSendListHandler::ConvertList done"));           
       
   100     return iStatus.Int();
       
   101     }
       
   102 
       
   103 // ---------------------------------------------------------------------------
       
   104 // AddObject()
       
   105 // ---------------------------------------------------------------------------
       
   106 //
       
   107 void CBTSSSendListHandler::AddObject()
       
   108     {
       
   109     FLOG(_L("[BTSS]\t CBTSSSendListHandler::AddObjectL()"));       
       
   110     TRAPD(error, DoAddObjectL());
       
   111     if (error != KErrNone )
       
   112         {        
       
   113         //Complete request
       
   114         TRequestStatus* status = &iStatus;
       
   115         User::RequestComplete(status, error);
       
   116         }
       
   117     FLOG(_L("[BTSS]\t CBTSSSendListHandler::AddObjectL() Done"));           
       
   118     }
       
   119 
       
   120 // ---------------------------------------------------------------------------
       
   121 // From class CActive.
       
   122 // RunL()
       
   123 // ---------------------------------------------------------------------------
       
   124 //
       
   125 void CBTSSSendListHandler::DoAddObjectL()
       
   126     {
       
   127     FLOG(_L("[BTSS]\t CBTSSSendListHandler::DoAddObjectL()"));   
       
   128     
       
   129     const TAiwGenericParam* param=&(*iOutParamList)[iListIndex];
       
   130 
       
   131     if ( param->SemanticId() != EGenericParamFile )
       
   132         {
       
   133         FLOG(_L("[BTSS]\t CBTSSSendListHandler::DoAddObjectL() wrong semantic Id: Leave"));            
       
   134         }
       
   135       // Try to add file as an image
       
   136       //       
       
   137     if( param->Value().TypeId()== EVariantTypeFileHandle)
       
   138         {           
       
   139         TRAPD( retVal, iList->AddImageL( param->Value().AsFileHandle()  ));
       
   140         FLOG(_L("[BTSS]\t CBTSSSendListHandler::DoAddObjectL AddImage"));            
       
   141         if( retVal != KErrNone )
       
   142             {
       
   143             // File was not an image. We can not use BIP 
       
   144             // so add rest of the files as objects
       
   145             //             
       
   146             FLOG(_L("[BTSS]\t CBTSSSendListHandler::DoAddObjectL AddImage filed try object"));            
       
   147             iList->AddObjectL( param->Value().AsFileHandle() );
       
   148             }            
       
   149         }
       
   150     else 
       
   151         {           
       
   152         TRAPD( retVal, iList->AddImageL( param->Value().AsDes() ) );
       
   153         if( retVal != KErrNone )
       
   154             {
       
   155             // File was not an image. We can not use BIP 
       
   156             // so add rest of the files as objects
       
   157             //                
       
   158             iList->AddObjectL( param->Value().AsDes() );
       
   159             }
       
   160         }
       
   161       //Complete request
       
   162     TRequestStatus* status = &iStatus;
       
   163     User::RequestComplete(status, KErrNone);
       
   164       
       
   165     FLOG(_L("[BTSS]\t CBTSSSendListHandler::DoAddObjectL() completed"));  
       
   166     }
       
   167 // ---------------------------------------------------------------------------
       
   168 // From class CActive.
       
   169 // RunL()
       
   170 // ---------------------------------------------------------------------------
       
   171 //
       
   172 void CBTSSSendListHandler::RunL()
       
   173     {
       
   174     FLOG(_L("[BTSS]\t CBTSSSendListHandler::DoAddObjectL()"));       
       
   175     iListIndex++;
       
   176     if ( iOutParamList->Count() > iListIndex && iStatus.Int() == KErrNone )
       
   177         {        
       
   178         iStatus = KRequestPending;
       
   179         AddObject();
       
   180         SetActive();
       
   181         }
       
   182     else
       
   183         {
       
   184         if ( iSyncWaiter.IsStarted() )
       
   185             {
       
   186             iSyncWaiter.AsyncStop();
       
   187             }
       
   188         }
       
   189     FLOG(_L("[BTSS]\t CBTSSSendListHandler::DoAddObjectL() Done"));           
       
   190     }
       
   191 // ---------------------------------------------------------------------------
       
   192 // From class CActive.
       
   193 // DoCancel()
       
   194 // ---------------------------------------------------------------------------
       
   195 //
       
   196 void CBTSSSendListHandler::DoCancel()
       
   197     {
       
   198     FLOG(_L("[BTSS]\t CBTSSSendListHandler::DoCancel()"));           
       
   199     if ( iSyncWaiter.IsStarted() )
       
   200         {
       
   201         iSyncWaiter.AsyncStop();
       
   202         }
       
   203     FLOG(_L("[BTSS]\t CBTSSSendListHandler::DoCancel() done"));               
       
   204     }