btobexprofiles/obexreceiveservices/bip/src/BIPController.cpp
changeset 32 19bd632b5100
child 40 997690c3397a
child 42 b72428996822
equal deleted inserted replaced
31:a0ea99b6fa53 32:19bd632b5100
       
     1 /*
       
     2 * Copyright (c) 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:  Obex Server image receiver module implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include    <avkon.hrh>                    // AVKON components
       
    21 #include    "BIPController.h"
       
    22 #include    "BIPCapabilityHandler.h"
       
    23 #include    "BIPImageHandler.h"
       
    24 
       
    25 
       
    26 #include    <e32base.h>
       
    27 #include    <StringLoader.h>               // Series 60 localisation stringloader
       
    28 #include    <obexutilsmessagehandler.h>
       
    29 #include    <obexutilsuilayer.h>
       
    30 #include    <obexutilsdialog.h>
       
    31 #include    <UiklafInternalCRKeys.h>
       
    32 #include    <Obexutils.rsg>
       
    33 #include    <sysutil.h>
       
    34 #include    <bautils.h>
       
    35 #include    <driveinfo.h>                   
       
    36 #include    <AknWaitDialog.h>
       
    37 #include    <btengdomaincrkeys.h> 
       
    38 #include    <e32math.h> 
       
    39 #include    <es_sock.h>
       
    40 #include    <bt_sock.h>
       
    41 #include    <msvids.h>
       
    42 #include    "debug.h"
       
    43         
       
    44 // CONSTANTS
       
    45 _LIT8(KBipCapabilityType, "x-bt/img-capabilities\0");
       
    46 
       
    47 
       
    48 const TInt    KBufferSize = 0x10000;  // 64 kB
       
    49 
       
    50 // ================= MEMBER FUNCTIONS =======================
       
    51 
       
    52 CBIPController* CBIPController::NewL()
       
    53     {
       
    54     CBIPController* self = new ( ELeave ) CBIPController();
       
    55 	CleanupStack::PushL( self );
       
    56 	self->ConstructL();
       
    57 	CleanupStack::Pop(self); 
       
    58 	return self;
       
    59     }
       
    60     
       
    61 // ---------------------------------------------------------
       
    62 // CBIPController()
       
    63 // ---------------------------------------------------------
       
    64 //
       
    65 CBIPController::CBIPController()
       
    66     {
       
    67     }
       
    68 
       
    69 // ---------------------------------------------------------
       
    70 // ConstructL()
       
    71 // ---------------------------------------------------------
       
    72 //
       
    73 void CBIPController::ConstructL()
       
    74     {
       
    75     TRACE_FUNC_ENTRY
       
    76     iBIPImageHandler = CBIPImageHandler::NewL();
       
    77     iLowMemoryActiveCDrive = CObexUtilsPropertyNotifier::NewL(this, ECheckPhoneMemory);
       
    78     iLowMemoryActiveMMC = CObexUtilsPropertyNotifier::NewL(this, ECheckMMCMemory);
       
    79     iDevMan = CBTEngDevMan::NewL(this);
       
    80     iResultArray = new(ELeave) CBTDeviceArray(1);
       
    81     // Get default folder from CenRep 
       
    82     TObexUtilsMessageHandler::GetCenRepKeyStringValueL(KCRUidBluetoothEngine, KLCReceiveFolder, iCenRepFolder);
       
    83     TRACE_FUNC_EXIT
       
    84     }
       
    85 
       
    86 // ---------------------------------------------------------
       
    87 // ~CBIPController()
       
    88 // ---------------------------------------------------------
       
    89 //
       
    90 CBIPController::~CBIPController()
       
    91     {   
       
    92     TRACE_FUNC_ENTRY    
       
    93     delete iGetObject;    
       
    94     delete iBIPCapabilityHandler;    
       
    95     delete iBIPImageHandler;    
       
    96     delete iLowMemoryActiveCDrive;    
       
    97     delete iLowMemoryActiveMMC;    
       
    98     delete iBuf;
       
    99     delete iProgressDialog;
       
   100     delete iWaitDialog;
       
   101     delete iBTObject;
       
   102     delete iDevMan;
       
   103     if (iResultArray)
       
   104         {
       
   105         iResultArray->ResetAndDestroy();
       
   106         delete iResultArray;
       
   107         }
       
   108     iFs.Close();
       
   109     TRACE_FUNC_EXIT    
       
   110     }
       
   111 
       
   112 // ---------------------------------------------------------
       
   113 // ErrorIndication()
       
   114 // ---------------------------------------------------------
       
   115 //
       
   116 void CBIPController::ErrorIndication(TInt TRACE_ONLY(aError))
       
   117     {
       
   118     TRACE_FUNC_ENTRY
       
   119     TRACE_ERROR((_L("[obexreceiveservicebip] CBIPController: ErrorIndication error:\t %d"), aError));
       
   120     HandleError(EFalse); // false because this is not an explicit abort
       
   121     TRACE_FUNC_EXIT
       
   122     }
       
   123 
       
   124 // ---------------------------------------------------------
       
   125 // AbortIndication()
       
   126 // ---------------------------------------------------------
       
   127 //
       
   128 void CBIPController::AbortIndication()
       
   129     {
       
   130     TRACE_FUNC_ENTRY
       
   131     HandleError(ETrue); // true because this is an explicit abort
       
   132     TRACE_FUNC_EXIT
       
   133     }
       
   134 
       
   135 void CBIPController::HandleError(TBool aAbort)
       
   136     {
       
   137     TRACE_FUNC_ENTRY
       
   138     
       
   139     if( iBTTransferState == ETransferPut || (!aAbort && iBTTransferState == ETransferPutDiskError) )
       
   140         {
       
   141         if(iBTObject)
       
   142             {
       
   143             iBTObject->Reset();
       
   144             }
       
   145         CancelTransfer();
       
   146         TRAP_IGNORE(TObexUtilsUiLayer::ShowGlobalConfirmationQueryL( R_BT_FAILED_TO_RECEIVE));
       
   147         }
       
   148     delete iBuf;
       
   149     iBuf = NULL;
       
   150     
       
   151     iBTTransferState = ETransferIdle;
       
   152     TRAP_IGNORE(TObexUtilsMessageHandler::RemoveInboxEntriesL(iBTObject,iMsvIdParent));
       
   153     TRAP_IGNORE(TObexUtilsMessageHandler::RemoveTemporaryRFileL(iFullPathFilename));
       
   154     
       
   155     TRACE_FUNC_EXIT
       
   156     }
       
   157 
       
   158 // ---------------------------------------------------------
       
   159 // CancelTransfer()
       
   160 // ---------------------------------------------------------
       
   161 //
       
   162 void CBIPController::CancelTransfer()
       
   163     {
       
   164     TRACE_FUNC_ENTRY
       
   165     CloseReceivingIndicator();
       
   166     if(iBTTransferState == ETransferPut)
       
   167         {
       
   168         iBTTransferState = ETransferPutCancel;
       
   169         }
       
   170     else // go to idle for all other states
       
   171         {
       
   172         iBTTransferState = ETransferIdle;
       
   173         }
       
   174     }
       
   175 // ---------------------------------------------------------
       
   176 // TransportUpIndication()
       
   177 // ---------------------------------------------------------
       
   178 //
       
   179 void CBIPController::TransportUpIndication()
       
   180     {
       
   181     TRACE_FUNC
       
   182     if (!iFs.Handle())
       
   183         {
       
   184         TRACE_INFO( (_L( "[bipreceiveservice] TransportUpIndication iFs.Connect()" )) ); 
       
   185         if (iFs.Connect())   // error value not checked, iFs.Handle() checked one more time before first useage
       
   186             {
       
   187             TRACE_INFO( (_L( "[bipreceiveservice] TransportUpIndication iFs.Connect() failed" )) ); 
       
   188             }
       
   189         }
       
   190     
       
   191     iFile = RFile();
       
   192     iFullPathFilename.Zero();
       
   193     iCapabilityFileName.Zero();
       
   194     }
       
   195 
       
   196 // ---------------------------------------------------------
       
   197 // ObexConnectIndication()
       
   198 // ---------------------------------------------------------
       
   199 //
       
   200 TInt CBIPController::ObexConnectIndication( const TObexConnectInfo& /*aRemoteInfo*/, const TDesC8& /*aInfo*/ )
       
   201     {
       
   202     TRACE_FUNC
       
   203     
       
   204     // Get remote device socket address and bluetooth name
       
   205     // Remote bluetooth name will be displayed in the new message in inbox.
       
   206     //
       
   207     TSockAddr addr;
       
   208     iBTObexServer->RemoteAddr(addr);
       
   209     TBTDevAddr tBTDevAddr = static_cast<TBTSockAddr>(addr).BTAddr();
       
   210     
       
   211     TBTRegistrySearch nameSearch;
       
   212     nameSearch.FindAddress(tBTDevAddr);
       
   213     
       
   214     iResultArray->Reset();
       
   215     // Ignore any errors here, if we don't get the name, we don't get the name.
       
   216     // It is also possible that the name is received too late....
       
   217     static_cast<void>(iDevMan->GetDevices(nameSearch, iResultArray));
       
   218     
       
   219     return KErrNone;
       
   220     }
       
   221 
       
   222 // ---------------------------------------------------------
       
   223 // ObexDisconnectIndication()
       
   224 // ---------------------------------------------------------
       
   225 //
       
   226 void CBIPController::ObexDisconnectIndication(const TDesC8& /*aInfo*/)
       
   227     {
       
   228     TRACE_FUNC
       
   229     }
       
   230 
       
   231 // ---------------------------------------------------------
       
   232 // TransportDownIndication()
       
   233 // ---------------------------------------------------------
       
   234 //
       
   235 void CBIPController::TransportDownIndication()
       
   236     {
       
   237     TRACE_FUNC   
       
   238     // Remove receiving buffer and files used during file receiving.
       
   239     //
       
   240     delete iBTObject;
       
   241     iBTObject = NULL;
       
   242     TRAP_IGNORE(TObexUtilsMessageHandler::RemoveTemporaryRFileL (iFullPathFilename));  
       
   243     iFs.Close();
       
   244     }
       
   245 
       
   246 // ---------------------------------------------------------
       
   247 // PutRequestIndication()
       
   248 // ---------------------------------------------------------
       
   249 //
       
   250 CObexBufObject* CBIPController::PutRequestIndication()
       
   251     {   
       
   252     TRACE_FUNC_ENTRY
       
   253     iLengthHeaderReceived = EFalse; // New put request so clear header based state
       
   254     iBTTransferState = ETransferPut;
       
   255     
       
   256     // Checking if backup is running now - if backup process is active, then we
       
   257     // need to cancel transfer - otherwise phone will freeze during receiving
       
   258     // data
       
   259     if ( TObexUtilsUiLayer::IsBackupRunning() )
       
   260         {
       
   261         TRACE_INFO ( _L ("Backup in progress! Canceling incoming transfer."));
       
   262         iBTTransferState = ETransferPutInitError;
       
   263         return NULL;
       
   264         }
       
   265         
       
   266     TRAPD(err, HandlePutImageRequestL());
       
   267     if (err == KErrNone)
       
   268         {
       
   269         return iBTObject;
       
   270         }
       
   271     if (iBTTransferState != ETransferPutInitError)
       
   272         {
       
   273         iBTTransferState = ETransferPutDiskError;
       
   274         }
       
   275     TRACE_FUNC_EXIT
       
   276     return NULL;
       
   277     }
       
   278 
       
   279 // ---------------------------------------------------------
       
   280 // PutPacketIndication() 
       
   281 // ---------------------------------------------------------
       
   282 //
       
   283 TInt CBIPController::PutPacketIndication()
       
   284     {
       
   285     TRACE_FUNC_ENTRY
       
   286     if(iBTTransferState == ETransferPutCancel)
       
   287         {
       
   288         // User cancelled the put request, so error the next packet to terminate the put request.
       
   289         // BIP considers the Unauthorized error response suitable for this...
       
   290         HandleError(ETrue); // reset state and clear up
       
   291         return KErrIrObexRespUnauthorized;
       
   292         }
       
   293     
       
   294     if (iBTObject)
       
   295         {
       
   296         iTotalSizeByte = iBTObject->Length();     // get size of receiving file
       
   297         iReceivingFileName = iBTObject->Name();   // get name of receiving file
       
   298         
       
   299         // Check that capacity is suitable as soon as possible
       
   300         if(!iLengthHeaderReceived && iTotalSizeByte > 0)
       
   301             {
       
   302             iLengthHeaderReceived = ETrue; // total size value is from length header
       
   303             TBool capacity = ETrue;
       
   304             TRAPD(retTrap, capacity = CheckCapacityL());
       
   305             if(retTrap != KErrNone)
       
   306                 {
       
   307                 return KErrGeneral;
       
   308                 }
       
   309             if(!capacity)
       
   310                 {
       
   311                 TRAP_IGNORE(TObexUtilsUiLayer::ShowGlobalConfirmationQueryL(R_OUT_OF_MEMORY));
       
   312                 return KErrDiskFull;
       
   313                 }
       
   314             }
       
   315         if(iBTObject->Name().Length() > KMaxFileName)
       
   316             {
       
   317             return KErrAccessDenied;
       
   318             }
       
   319         if(iBTTransferState == ETransferPutDiskError)
       
   320             {
       
   321             return KErrDiskFull;
       
   322             }
       
   323         // successfully received put packet if we reached here
       
   324         iBTTransferState = ETransferPut;
       
   325         
       
   326         // Now we need to either create (in the first instance) or update the dialog on the UI.
       
   327         if(ReceivingIndicatorActive())
       
   328             {
       
   329             UpdateReceivingIndicator();
       
   330             }
       
   331         else if(!iNoteDisplayed)
       
   332             {
       
   333             // No note launched yet, so try to launch
       
   334             TRAPD(err, LaunchReceivingIndicatorL());
       
   335             iNoteDisplayed = (err == KErrNone);
       
   336             }
       
   337         }
       
   338     
       
   339     TRACE_FUNC_EXIT
       
   340     return KErrNone;
       
   341     }
       
   342 
       
   343 // ---------------------------------------------------------
       
   344 // PutCompleteIndication() 
       
   345 // ---------------------------------------------------------
       
   346 //
       
   347 TInt CBIPController::PutCompleteIndication()  // Once receive has completed.
       
   348     {
       
   349     TRACE_FUNC_ENTRY
       
   350     TInt retVal = KErrNone;
       
   351     if(iBTTransferState == ETransferPutCancel)
       
   352         {
       
   353         retVal = KErrIrObexRespUnauthorized;
       
   354         HandleError(ETrue);
       
   355         }
       
   356     else
       
   357         {
       
   358         retVal = HandlePutCompleteIndication();
       
   359         iBTTransferState = ETransferIdle;
       
   360         CloseReceivingIndicator();
       
   361         }
       
   362     TRACE_FUNC_EXIT
       
   363     return retVal;
       
   364     }
       
   365 
       
   366 // ---------------------------------------------------------
       
   367 // GetRequestIndication()
       
   368 // ---------------------------------------------------------
       
   369 //
       
   370 CObexBufObject* CBIPController::GetRequestIndication( CObexBaseObject* aRequiredObject )
       
   371     {
       
   372     TRACE_FUNC_ENTRY
       
   373     iBTTransferState = ETransferGet;
       
   374     TInt err = RemoveCapabilityObject();
       
   375     if (err == KErrNone)
       
   376         {
       
   377         if( aRequiredObject->Type() == KBipCapabilityType )
       
   378             {
       
   379             TRAP( err, HandleGetCapabilityRequestL( ) );
       
   380             if( err == KErrNone )
       
   381                 {
       
   382                 return iGetObject;
       
   383                 }
       
   384             }
       
   385         }
       
   386     TRACE_FUNC_EXIT
       
   387     return NULL;
       
   388     }
       
   389 
       
   390 // ---------------------------------------------------------
       
   391 // GetPacketIndication()
       
   392 // ---------------------------------------------------------
       
   393 //
       
   394 TInt CBIPController::GetPacketIndication()
       
   395     {
       
   396     TRACE_FUNC_ENTRY
       
   397     return KErrNone;
       
   398     }
       
   399 
       
   400 // ---------------------------------------------------------
       
   401 // GetCompleteIndication()
       
   402 // ---------------------------------------------------------
       
   403 //
       
   404 TInt CBIPController::GetCompleteIndication()
       
   405     {
       
   406     TRACE_FUNC_ENTRY
       
   407     delete iGetObject;
       
   408     iGetObject=NULL;
       
   409     TInt err = RemoveCapabilityObject();
       
   410     if (err != KErrNone)
       
   411         {
       
   412         err = KErrGeneral;
       
   413         }
       
   414     iBTTransferState = ETransferIdle;
       
   415     TRACE_FUNC_EXIT
       
   416     return err;
       
   417     }
       
   418 
       
   419 // ---------------------------------------------------------
       
   420 // SetPathIndication()
       
   421 // ---------------------------------------------------------
       
   422 //
       
   423 TInt CBIPController::SetPathIndication( const CObex::TSetPathInfo& /*aPathInfo*/, 
       
   424                                         const TDesC8& /*aInfo*/)
       
   425     {
       
   426     TRACE_FUNC
       
   427     // SetPath is not implemented in BIP - so following IrOBEX guidance, return
       
   428     // the Forbidden response code.
       
   429     return KErrIrObexRespForbidden;
       
   430     }
       
   431 
       
   432 /**
       
   433 * This function is implementation for mixin-class for Obexutils.
       
   434 * It is called every time another instance modifies disk status,
       
   435 * for example when it cross warning/critical level.
       
   436 * Parameters:
       
   437 * @param aCheckType             Disktype changes.
       
   438 */
       
   439 void CBIPController::HandleNotifyL(TMemoryPropertyCheckType aCheckType)
       
   440     {    
       
   441     TRACE_FUNC_ENTRY    
       
   442     // Only interested on this notification if we are receiving something
       
   443     if ( iBTTransferState == ETransferPut )
       
   444         {
       
   445        // Check the keys, what has been changed.
       
   446        if ( aCheckType == ECheckPhoneMemory )
       
   447            {
       
   448            if ( SysUtil::FFSSpaceBelowCriticalLevelL( NULL, 0 ) )
       
   449                {                
       
   450                TRACE_INFO( _L( "[obexreceiveservicebip] CBIPController: Obex Server error diskfull:\t" ) );
       
   451                iBTTransferState = ETransferPutDiskError;
       
   452                }
       
   453            }
       
   454        else if ( aCheckType == ECheckMMCMemory )
       
   455            {                
       
   456            if ( SysUtil::MMCSpaceBelowCriticalLevelL( NULL, 0 ) )
       
   457                {                    
       
   458                TRACE_INFO( _L( "[obexreceiveservicebip] CBIPController: Obex Server error diskfull:\t" ) );
       
   459                iBTTransferState = ETransferPutDiskError;
       
   460                }
       
   461            }            
       
   462         }        
       
   463     TRACE_FUNC_EXIT    
       
   464     }
       
   465     
       
   466 // ---------------------------------------------------------
       
   467 // HandleGetCapabilityRequestL()
       
   468 // ---------------------------------------------------------
       
   469 //
       
   470 void CBIPController::HandleGetCapabilityRequestL()
       
   471     {
       
   472     TRACE_FUNC_ENTRY    
       
   473     CBIPCapabilityHandler* capHandler = CBIPCapabilityHandler::NewL();
       
   474     CleanupStack::PushL(capHandler);
       
   475     capHandler->CreateCapabilityObjectL(iCapabilityFileName);
       
   476     delete iGetObject;
       
   477     iGetObject = NULL; 
       
   478     iGetObject = CObexBufObject::NewL(NULL);
       
   479     iGetObject->SetDataBufL(iCapabilityFileName);
       
   480     CleanupStack::PopAndDestroy(capHandler);
       
   481     TRACE_FUNC_EXIT
       
   482     }
       
   483 
       
   484 // ---------------------------------------------------------
       
   485 // HandlePutImageRequest()
       
   486 // ---------------------------------------------------------
       
   487 //
       
   488 void CBIPController::HandlePutImageRequestL()
       
   489     {
       
   490     TRACE_FUNC_ENTRY
       
   491     
       
   492     delete iBTObject;
       
   493     iBTObject = NULL;
       
   494 
       
   495     if (!iFs.Handle())
       
   496         {
       
   497         User::Leave(KErrGeneral);
       
   498         }
       
   499     
       
   500     // Assign an initial value to iDrive
       
   501     iDrive = GetDriveWithMaximumFreeSpaceL();    
       
   502     
       
   503     // If iDrive is at critical space level, we immediately show out_of_memory.
       
   504     //
       
   505     if (SysUtil::DiskSpaceBelowCriticalLevelL(&iFs, 0, iDrive))
       
   506         {
       
   507         TRAP_IGNORE(TObexUtilsUiLayer::ShowGlobalConfirmationQueryL(R_OUT_OF_MEMORY));
       
   508         User::Leave(KErrGeneral);
       
   509         }
       
   510     
       
   511     iBTObject = CObexBufObject::NewL(NULL);    
       
   512     
       
   513     delete iBuf;
       
   514     iBuf = NULL;
       
   515     
       
   516     TChar driveLetter;
       
   517     iDefaultFolder.Zero();
       
   518     iFs.DriveToChar(iDrive, driveLetter);
       
   519     iDefaultFolder.Append(driveLetter);
       
   520     if ( iDrive == EDriveC )
       
   521         {
       
   522         iDefaultFolder.Append(_L(":\\data\\"));
       
   523         }
       
   524     else
       
   525         {
       
   526         iDefaultFolder.Append(_L(":\\"));
       
   527         }
       
   528     
       
   529     iDefaultFolder.Append(iCenRepFolder);
       
   530     
       
   531     iFile = RFile();
       
   532     iFullPathFilename.Zero();
       
   533     TObexUtilsMessageHandler::CreateReceiveBufferAndRFileL(iFile, iDefaultFolder, iFullPathFilename, iBuf, KBufferSize);
       
   534     User::LeaveIfError(iFile.Open(iFs, iFullPathFilename, EFileWrite));
       
   535     TObexRFileBackedBuffer bufferdetails(*iBuf, iFile, CObexBufObject::EDoubleBuffering);
       
   536     TRAPD(err, iBTObject->SetDataBufL(bufferdetails));
       
   537     if (err != KErrNone)
       
   538         {
       
   539         iBTTransferState = ETransferPutInitError;
       
   540         User::Leave(KErrGeneral); 
       
   541         }
       
   542         
       
   543     TRACE_FUNC_EXIT
       
   544     }
       
   545 
       
   546 
       
   547 // ---------------------------------------------------------
       
   548 // HandlePutCompleteIndication()
       
   549 // ---------------------------------------------------------
       
   550 //
       
   551 TInt CBIPController::HandlePutCompleteIndication()
       
   552 	{
       
   553     TRACE_FUNC_ENTRY
       
   554     TInt retVal = KErrNone;
       
   555 
       
   556     iDefaultFolder.Zero();
       
   557     TChar driveLetter;
       
   558     if ( iDrive == EDriveC )
       
   559         {
       
   560         iFs.DriveToChar(iDrive, driveLetter);
       
   561         iDefaultFolder.Append(driveLetter);
       
   562         iDefaultFolder.Append(_L(":\\data\\"));
       
   563         iDefaultFolder.Append(iCenRepFolder);
       
   564         }
       
   565     else
       
   566         {
       
   567         iFs.DriveToChar(iDrive, driveLetter);
       
   568         iDefaultFolder.Append(driveLetter);
       
   569         iDefaultFolder.Append(_L(":\\"));
       
   570         iDefaultFolder.Append(iCenRepFolder);
       
   571         }
       
   572     
       
   573     iFullPathFilename.Zero();
       
   574     iFullPathFilename.Append(iDefaultFolder);
       
   575     TRAP ( retVal, TObexUtilsMessageHandler::SaveFileToFileSystemL(iBTObject,
       
   576                                                                    KUidMsgTypeBt,
       
   577                                                                    iMsvIdParent,
       
   578                                                                    iFullPathFilename,
       
   579                                                                    iFile,
       
   580                                                                    iRemoteDeviceName));
       
   581     if ( retVal == KErrNone)
       
   582         {
       
   583         TRAP (retVal, TObexUtilsMessageHandler::AddEntryToInboxL(iMsvIdParent, iFullPathFilename));
       
   584         }
       
   585     
       
   586     
       
   587     if( retVal != KErrNone )
       
   588         {
       
   589         TRACE_ERROR((_L( "[obexreceiveservicebip] CBIPController: HandlePutCompleteIndication error:\t %d" ), retVal ) );              
       
   590         TRAP( retVal, TObexUtilsMessageHandler::RemoveInboxEntriesL(iBTObject, iMsvIdParent));
       
   591         retVal = KErrDiskFull;
       
   592         }
       
   593     // Even if the object saving fails we must return image handle with error code
       
   594     TRAP_IGNORE( iBIPImageHandler->AddImageHandleHeaderL( iBTObexServer ) );            
       
   595     TRACE_INFO( _L( "[obexreceiveservicebip] HandlePutCompleteIndication Done\t" ) );
       
   596     delete iBTObject;
       
   597     iBTObject = NULL;
       
   598     delete iBuf;
       
   599     iBuf = NULL;
       
   600     iPreviousDefaultFolder = iDefaultFolder;  // save the last file path where file is successfully saved to file system.
       
   601     iMsvIdParent = KMsvNullIndexEntryId;
       
   602     TRACE_FUNC_EXIT     
       
   603     return retVal;
       
   604 	}
       
   605 // ---------------------------------------------------------
       
   606 // RemoveCapabilityObject()
       
   607 // ---------------------------------------------------------
       
   608 //		
       
   609 TInt CBIPController::RemoveCapabilityObject()
       
   610     {
       
   611     TRACE_FUNC_ENTRY
       
   612     if ( (iCapabilityFileName.Compare(KNullDesC)) == 0 )
       
   613         {
       
   614         return KErrNone; 
       
   615         }     
       
   616     if ( !iFs.Handle() )
       
   617         {
       
   618         TRACE_INFO( (_L( "[bipreceiveservice] RemoveCapabilityObject return" )) ); 
       
   619         return KErrGeneral;
       
   620         }               
       
   621     iFs.Delete(iCapabilityFileName);        
       
   622     iCapabilityFileName=KNullDesC; 
       
   623     TRACE_FUNC_EXIT 
       
   624     return KErrNone;    
       
   625     }
       
   626 	 
       
   627 // ---------------------------------------------------------
       
   628 // CheckCapacity()
       
   629 // ---------------------------------------------------------
       
   630 //	    
       
   631 TBool CBIPController::CheckCapacityL()
       
   632     {
       
   633     TRACE_FUNC_ENTRY   
       
   634     
       
   635     iDrive = EDriveZ; // Intialize iDrive to Z
       
   636     TInt filesize = iBTObject->Length();
       
   637     
       
   638     TInt mmcDrive = KDefaultDrive;   // External memory card  
       
   639     TInt imsDrive = KDefaultDrive;   // Internal mass storage
       
   640     
       
   641     User::LeaveIfError(DriveInfo::GetDefaultDrive(DriveInfo::EDefaultMassStorage, imsDrive));
       
   642     User::LeaveIfError(DriveInfo::GetDefaultDrive(DriveInfo::EDefaultRemovableMassStorage, mmcDrive));      
       
   643      
       
   644     TRACE_INFO( (_L( "[oppreceiveservice] CheckCapacityL imsDrive=%d; mmcDrive=%d\t" ),imsDrive, mmcDrive ) );
       
   645 
       
   646     TVolumeInfo volumeInfo;
       
   647     TInt err = iFs.Volume(volumeInfo, imsDrive);
       
   648     
       
   649     // If err != KErrNone, Drive is not available.
       
   650     //
       
   651     if ( !err )
       
   652         {
       
   653         // Check capacity on Internal mass storage            
       
   654         TRACE_INFO( (_L( "[obexreceiveservicebip] CheckCapacityL Internal mass storage \t" )) );
       
   655         if ( !SysUtil::DiskSpaceBelowCriticalLevelL( &iFs, filesize, imsDrive ) )
       
   656             {
       
   657             iDrive = imsDrive;            
       
   658             }
       
   659         }
       
   660     if ( iDrive == EDriveZ )
       
   661         {
       
   662         err = iFs.Volume(volumeInfo, mmcDrive);
       
   663         if ( !err )
       
   664             {
       
   665             // Check capacity on memory card    
       
   666             TRACE_INFO( (_L( "[obexreceiveservicebip] CheckCapacityL Checking memory card\t" )) );
       
   667             if ( !SysUtil::DiskSpaceBelowCriticalLevelL( &iFs, filesize, mmcDrive ) )
       
   668                 {                    
       
   669                 iDrive = mmcDrive;
       
   670                 }   
       
   671             }
       
   672         }           
       
   673     if ( iDrive == EDriveZ )
       
   674         {
       
   675         TRACE_INFO( (_L( "[obexreceiveservicebip] CheckCapacityL Checking phone memory\t" )) );
       
   676         // Phone memory
       
   677         if( !SysUtil::DiskSpaceBelowCriticalLevelL( &iFs, filesize, EDriveC ))
       
   678             {
       
   679             iDrive = EDriveC;
       
   680             }
       
   681         }
       
   682   
       
   683     TRACE_INFO( (_L( "[obexreceiveservicebip] CheckCapacityL iDrive = %d\t" ),iDrive ) );                   
       
   684     TRACE_FUNC_EXIT
       
   685     
       
   686     if (iDrive == EDriveZ)
       
   687         {
       
   688         // If there is no free space for receiving file, we need to set iPreviousDefaultFolder back to iDefaultFolder.
       
   689         // In order to show the file receveing dialog correctly.
       
   690         iDefaultFolder = iPreviousDefaultFolder;
       
   691         return EFalse;
       
   692         }
       
   693     return ETrue;
       
   694     }    
       
   695 
       
   696 
       
   697 // ---------------------------------------------------------
       
   698 // IsOBEXActive()
       
   699 // ---------------------------------------------------------
       
   700 //
       
   701 TBool CBIPController::IsOBEXActive()
       
   702     {    
       
   703     TRACE_FUNC    
       
   704     return ETrue;
       
   705     }
       
   706 
       
   707 // ---------------------------------------------------------
       
   708 // SetMediaType()
       
   709 // ---------------------------------------------------------
       
   710 //
       
   711 void CBIPController::SetMediaType( TSrcsMediaType __DEBUG_ONLY(aMediaType) ) 
       
   712     {
       
   713     TRACE_FUNC
       
   714     // BIP is only for Bluetooth, so that is all we expect
       
   715     __ASSERT_DEBUG(aMediaType == ESrcsMediaBT, User::Panic(KBipPanicCategory, EBipPanicNotBluetoothMediaType));
       
   716     }
       
   717 
       
   718 // ---------------------------------------------------------
       
   719 // SetObexServer()
       
   720 // ---------------------------------------------------------
       
   721 //
       
   722 TInt CBIPController::SetObexServer( CObexServer* aServer)
       
   723     {
       
   724     TInt retVal=KErrNone;
       
   725     if (aServer)
       
   726         {
       
   727         iBTObexServer=aServer;
       
   728         retVal=aServer->Start(this);
       
   729         }
       
   730     return retVal;
       
   731     }    
       
   732 
       
   733 void CBIPController::LaunchReceivingIndicatorL()
       
   734     {
       
   735     if(ReceivingIndicatorActive())
       
   736         {
       
   737         return;
       
   738         }
       
   739     
       
   740     if(iTotalSizeByte > 0)
       
   741         {
       
   742         iProgressDialog = CGlobalProgressDialog::NewL(this);  
       
   743         if(iReceivingFileName.Length() > 0)
       
   744             {
       
   745             iProgressDialog->ShowProgressDialogNameSizeL(iReceivingFileName, iTotalSizeByte);
       
   746             }
       
   747         else
       
   748             {
       
   749             iProgressDialog->ShowProgressDialogL(R_BT_RECEIVING_DATA);
       
   750             }
       
   751         }
       
   752     else
       
   753         {
       
   754         iWaitDialog = CGlobalDialog::NewL(this);
       
   755         iWaitDialog->ShowNoteDialogL(R_BT_RECEIVING_DATA, ETrue);
       
   756         }
       
   757     }
       
   758 
       
   759 void CBIPController::UpdateReceivingIndicator()
       
   760     {
       
   761     if(iProgressDialog)
       
   762         {
       
   763         iProgressDialog->UpdateProgressDialog(iBTObject->BytesReceived(), iTotalSizeByte);
       
   764         }
       
   765     // else we are using a wait note, so no "need" to update
       
   766     }
       
   767 
       
   768 void CBIPController::HandleGlobalProgressDialogL( TInt aSoftkey )
       
   769     {
       
   770     TRACE_FUNC
       
   771     
       
   772     if(aSoftkey == EAknSoftkeyCancel)
       
   773         {
       
   774         CancelTransfer();
       
   775         }
       
   776     else if(aSoftkey == EAknSoftkeyHide)
       
   777         {
       
   778         CloseReceivingIndicator(EFalse); // Don't reset state as only hiding
       
   779         }
       
   780     }
       
   781 
       
   782 void CBIPController::HandleGlobalNoteDialogL( TInt aSoftkey )
       
   783     {
       
   784     TRACE_FUNC
       
   785     
       
   786     if( aSoftkey == EAknSoftkeyCancel )
       
   787         {
       
   788         CancelTransfer();
       
   789         }
       
   790     else if( aSoftkey == EAknSoftkeyHide)
       
   791         {
       
   792         CloseReceivingIndicator(EFalse); // Don't reset state as only hiding
       
   793         }
       
   794     }
       
   795 
       
   796 void CBIPController::CloseReceivingIndicator(TBool aResetDisplayedState)
       
   797     {
       
   798     TRACE_FUNC
       
   799     if(aResetDisplayedState)
       
   800         {
       
   801         iNoteDisplayed = EFalse;
       
   802         }
       
   803     if(iProgressDialog)
       
   804         {
       
   805         iProgressDialog->ProcessFinished();
       
   806         delete iProgressDialog;
       
   807         iProgressDialog = NULL;
       
   808         }
       
   809     if(iWaitDialog)
       
   810         {
       
   811         iWaitDialog->ProcessFinished();
       
   812         delete iWaitDialog;
       
   813         iWaitDialog = NULL;
       
   814         }
       
   815     }
       
   816  
       
   817  // ---------------------------------------------------------
       
   818  // GetDriveWithMaximumFreeSpace()
       
   819  // ---------------------------------------------------------
       
   820  // 
       
   821  TInt CBIPController::GetDriveWithMaximumFreeSpaceL()
       
   822      {
       
   823      // Get drive with maximum freespace among phone memory, MMC, internal mass storage.
       
   824      //
       
   825       TRACE_FUNC   
       
   826      
       
   827      TVolumeInfo volumeInfoC;
       
   828      TVolumeInfo volumeInfoE;
       
   829      TVolumeInfo volumeInfoF;
       
   830      TInt64 max = 0;
       
   831      TInt drive = 0;
       
   832      
       
   833      TInt err = iFs.Volume(volumeInfoC, EDriveC);
       
   834     
       
   835      if ( !err )
       
   836          {
       
   837          // set initial values to max and drive.
       
   838          max = volumeInfoC.iFree;
       
   839          drive = EDriveC;
       
   840          }
       
   841           
       
   842      err = iFs.Volume(volumeInfoE, EDriveE);     
       
   843      if ( !err )
       
   844          {
       
   845          if (volumeInfoE.iFree >= max)
       
   846              {
       
   847              max = volumeInfoE.iFree;
       
   848              drive = EDriveE;             
       
   849              }
       
   850          
       
   851          }
       
   852           
       
   853      err = iFs.Volume(volumeInfoF, EDriveF);
       
   854      if ( !err )
       
   855          {
       
   856          if (volumeInfoF.iFree >= max)
       
   857              {
       
   858              max = volumeInfoF.iFree;
       
   859              drive = EDriveF;             
       
   860              }
       
   861          }
       
   862      max = 0;
       
   863      return drive;
       
   864      }
       
   865  
       
   866  // ----------------------------------------------------------
       
   867  // COPPController::HandleDevManComplete
       
   868  // Callback from devman
       
   869  // ----------------------------------------------------------
       
   870  //    
       
   871  // 
       
   872  void CBIPController::HandleGetDevicesComplete(TInt aErr, CBTDeviceArray* /*aDeviceArray*/)
       
   873     {
       
   874     if ( aErr == KErrNone )
       
   875         {
       
   876         if ( iResultArray->Count())
       
   877             {
       
   878             iRemoteDeviceName.Zero();
       
   879             if ( iResultArray->At(0)->FriendlyName().Length() > 0 )
       
   880                 {
       
   881                 TRACE_INFO( _L( "[CBIPController] HandleGetDevicesComplete: got friendly name \t" ) );
       
   882                 iRemoteDeviceName.Copy(iResultArray->At(0)->FriendlyName());
       
   883                 }
       
   884             else
       
   885                 {
       
   886                 TRACE_INFO( _L( "[CBIPController] HandleGetDevicesComplete: got devciename name \t" ) );                
       
   887                 TRAP_IGNORE(iRemoteDeviceName.Copy(BTDeviceNameConverter::ToUnicodeL(iResultArray->At(0)->DeviceName())));
       
   888                 }
       
   889             }
       
   890         }
       
   891     }
       
   892  
       
   893 //////////////////////////// Global part ////////////////////////////
       
   894 
       
   895 //  End of File