localconnectivityservice/obexreceiveservices/bip/src/BIPController.cpp
branchRCL_3
changeset 39 4096754ee773
parent 38 3dcb815346df
child 40 52a167391590
equal deleted inserted replaced
38:3dcb815346df 39:4096754ee773
     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         if(iBTTransferState == ETransferPutDiskError)
       
   297             {
       
   298             return KErrDiskFull;
       
   299             }
       
   300         
       
   301         if(iBTObject->Name().Length() > KMaxFileName)
       
   302             {
       
   303             TRACE_INFO( _L( "[oppreceiveservice] COPPController: PutPacketIndication truncating name of file being received\t" ) );
       
   304             TRAPD(err, iBTObject->SetNameL(iBTObject->Name().Left(KMaxFileName)));
       
   305             if(err != KErrNone)
       
   306                 {
       
   307                 return KErrAccessDenied;
       
   308                 }
       
   309             }     
       
   310         iReceivingFileName = iBTObject->Name();   // get name of receiving file
       
   311         iTotalSizeByte = iBTObject->Length();     // get size of receiving file                       
       
   312         
       
   313         // Check that capacity is suitable as soon as possible
       
   314         if(!iLengthHeaderReceived && iTotalSizeByte > 0)
       
   315             {
       
   316             iLengthHeaderReceived = ETrue; // total size value is from length header
       
   317             TBool capacity = ETrue;
       
   318             TRAPD(retTrap, capacity = CheckCapacityL());
       
   319             if(retTrap != KErrNone)
       
   320                 {
       
   321                 return KErrGeneral;
       
   322                 }
       
   323             if(!capacity)
       
   324                 {
       
   325                 TRAP_IGNORE(TObexUtilsUiLayer::ShowGlobalConfirmationQueryL(R_OUT_OF_MEMORY));
       
   326                 return KErrDiskFull;
       
   327                 }
       
   328             }
       
   329         
       
   330         
       
   331         // successfully received put packet if we reached here
       
   332         iBTTransferState = ETransferPut;
       
   333         
       
   334         // Now we need to either create (in the first instance) or update the dialog on the UI.
       
   335         if(ReceivingIndicatorActive())
       
   336             {
       
   337             UpdateReceivingIndicator();
       
   338             }
       
   339         else if(!iNoteDisplayed)
       
   340             {
       
   341             // No note launched yet, so try to launch
       
   342             TRAPD(err, LaunchReceivingIndicatorL());
       
   343             iNoteDisplayed = (err == KErrNone);
       
   344             }
       
   345         }
       
   346     
       
   347     TRACE_FUNC_EXIT
       
   348     return KErrNone;
       
   349     }
       
   350 
       
   351 // ---------------------------------------------------------
       
   352 // PutCompleteIndication() 
       
   353 // ---------------------------------------------------------
       
   354 //
       
   355 TInt CBIPController::PutCompleteIndication()  // Once receive has completed.
       
   356     {
       
   357     TRACE_FUNC_ENTRY
       
   358     TInt retVal = KErrNone;
       
   359     if(iBTTransferState == ETransferPutCancel)
       
   360         {
       
   361         retVal = KErrIrObexRespUnauthorized;
       
   362         HandleError(ETrue);
       
   363         }
       
   364     else
       
   365         {
       
   366         retVal = HandlePutCompleteIndication();
       
   367         iBTTransferState = ETransferIdle;
       
   368         CloseReceivingIndicator();
       
   369         }
       
   370     TRACE_FUNC_EXIT
       
   371     return retVal;
       
   372     }
       
   373 
       
   374 // ---------------------------------------------------------
       
   375 // GetRequestIndication()
       
   376 // ---------------------------------------------------------
       
   377 //
       
   378 CObexBufObject* CBIPController::GetRequestIndication( CObexBaseObject* aRequiredObject )
       
   379     {
       
   380     TRACE_FUNC_ENTRY
       
   381     iBTTransferState = ETransferGet;
       
   382     TInt err = RemoveCapabilityObject();
       
   383     if (err == KErrNone)
       
   384         {
       
   385         if( aRequiredObject->Type() == KBipCapabilityType )
       
   386             {
       
   387             TRAP( err, HandleGetCapabilityRequestL( ) );
       
   388             if( err == KErrNone )
       
   389                 {
       
   390                 return iGetObject;
       
   391                 }
       
   392             }
       
   393         }
       
   394     TRACE_FUNC_EXIT
       
   395     return NULL;
       
   396     }
       
   397 
       
   398 // ---------------------------------------------------------
       
   399 // GetPacketIndication()
       
   400 // ---------------------------------------------------------
       
   401 //
       
   402 TInt CBIPController::GetPacketIndication()
       
   403     {
       
   404     TRACE_FUNC_ENTRY
       
   405     return KErrNone;
       
   406     }
       
   407 
       
   408 // ---------------------------------------------------------
       
   409 // GetCompleteIndication()
       
   410 // ---------------------------------------------------------
       
   411 //
       
   412 TInt CBIPController::GetCompleteIndication()
       
   413     {
       
   414     TRACE_FUNC_ENTRY
       
   415     delete iGetObject;
       
   416     iGetObject=NULL;
       
   417     TInt err = RemoveCapabilityObject();
       
   418     if (err != KErrNone)
       
   419         {
       
   420         err = KErrGeneral;
       
   421         }
       
   422     iBTTransferState = ETransferIdle;
       
   423     TRACE_FUNC_EXIT
       
   424     return err;
       
   425     }
       
   426 
       
   427 // ---------------------------------------------------------
       
   428 // SetPathIndication()
       
   429 // ---------------------------------------------------------
       
   430 //
       
   431 TInt CBIPController::SetPathIndication( const CObex::TSetPathInfo& /*aPathInfo*/, 
       
   432                                         const TDesC8& /*aInfo*/)
       
   433     {
       
   434     TRACE_FUNC
       
   435     // SetPath is not implemented in BIP - so following IrOBEX guidance, return
       
   436     // the Forbidden response code.
       
   437     return KErrIrObexRespForbidden;
       
   438     }
       
   439 
       
   440 /**
       
   441 * This function is implementation for mixin-class for Obexutils.
       
   442 * It is called every time another instance modifies disk status,
       
   443 * for example when it cross warning/critical level.
       
   444 * Parameters:
       
   445 * @param aCheckType             Disktype changes.
       
   446 */
       
   447 void CBIPController::HandleNotifyL(TMemoryPropertyCheckType aCheckType)
       
   448     {    
       
   449     TRACE_FUNC_ENTRY    
       
   450     // Only interested on this notification if we are receiving something
       
   451     if ( iBTTransferState == ETransferPut )
       
   452         {
       
   453        // Check the keys, what has been changed.
       
   454        if ( aCheckType == ECheckPhoneMemory )
       
   455            {
       
   456            if ( SysUtil::FFSSpaceBelowCriticalLevelL( NULL, 0 ) )
       
   457                {                
       
   458                TRACE_INFO( _L( "[obexreceiveservicebip] CBIPController: Obex Server error diskfull:\t" ) );
       
   459                iBTTransferState = ETransferPutDiskError;
       
   460                }
       
   461            }
       
   462        else if ( aCheckType == ECheckMMCMemory )
       
   463            {                
       
   464            if ( SysUtil::MMCSpaceBelowCriticalLevelL( NULL, 0 ) )
       
   465                {                    
       
   466                TRACE_INFO( _L( "[obexreceiveservicebip] CBIPController: Obex Server error diskfull:\t" ) );
       
   467                iBTTransferState = ETransferPutDiskError;
       
   468                }
       
   469            }            
       
   470         }        
       
   471     TRACE_FUNC_EXIT    
       
   472     }
       
   473     
       
   474 // ---------------------------------------------------------
       
   475 // HandleGetCapabilityRequestL()
       
   476 // ---------------------------------------------------------
       
   477 //
       
   478 void CBIPController::HandleGetCapabilityRequestL()
       
   479     {
       
   480     TRACE_FUNC_ENTRY    
       
   481     CBIPCapabilityHandler* capHandler = CBIPCapabilityHandler::NewL();
       
   482     CleanupStack::PushL(capHandler);
       
   483     capHandler->CreateCapabilityObjectL(iCapabilityFileName);
       
   484     delete iGetObject;
       
   485     iGetObject = NULL; 
       
   486     iGetObject = CObexBufObject::NewL(NULL);
       
   487     iGetObject->SetDataBufL(iCapabilityFileName);
       
   488     CleanupStack::PopAndDestroy(capHandler);
       
   489     TRACE_FUNC_EXIT
       
   490     }
       
   491 
       
   492 // ---------------------------------------------------------
       
   493 // HandlePutImageRequest()
       
   494 // ---------------------------------------------------------
       
   495 //
       
   496 void CBIPController::HandlePutImageRequestL()
       
   497     {
       
   498     TRACE_FUNC_ENTRY
       
   499     
       
   500     delete iBTObject;
       
   501     iBTObject = NULL;
       
   502 
       
   503     if (!iFs.Handle())
       
   504         {
       
   505         User::Leave(KErrGeneral);
       
   506         }
       
   507     
       
   508     // Assign an initial value to iDrive
       
   509     iDrive = GetDriveWithMaximumFreeSpaceL();    
       
   510     
       
   511     // If iDrive is at critical space level, we immediately show out_of_memory.
       
   512     //
       
   513     if (SysUtil::DiskSpaceBelowCriticalLevelL(&iFs, 0, iDrive))
       
   514         {
       
   515         TRAP_IGNORE(TObexUtilsUiLayer::ShowGlobalConfirmationQueryL(R_OUT_OF_MEMORY));
       
   516         User::Leave(KErrGeneral);
       
   517         }
       
   518     
       
   519     iBTObject = CObexBufObject::NewL(NULL);    
       
   520     
       
   521     delete iBuf;
       
   522     iBuf = NULL;
       
   523     
       
   524     TChar driveLetter;
       
   525     iDefaultFolder.Zero();
       
   526     iFs.DriveToChar(iDrive, driveLetter);
       
   527     iDefaultFolder.Append(driveLetter);
       
   528     if ( iDrive == EDriveC )
       
   529         {
       
   530         iDefaultFolder.Append(_L(":\\data\\"));
       
   531         }
       
   532     else
       
   533         {
       
   534         iDefaultFolder.Append(_L(":\\"));
       
   535         }
       
   536     
       
   537     iDefaultFolder.Append(iCenRepFolder);
       
   538     
       
   539     iFile = RFile();
       
   540     iFullPathFilename.Zero();
       
   541     TObexUtilsMessageHandler::CreateReceiveBufferAndRFileL(iFile, iDefaultFolder, iFullPathFilename, iBuf, KBufferSize);
       
   542     User::LeaveIfError(iFile.Open(iFs, iFullPathFilename, EFileWrite));
       
   543     TObexRFileBackedBuffer bufferdetails(*iBuf, iFile, CObexBufObject::EDoubleBuffering);
       
   544     TRAPD(err, iBTObject->SetDataBufL(bufferdetails));
       
   545     if (err != KErrNone)
       
   546         {
       
   547         iBTTransferState = ETransferPutInitError;
       
   548         User::Leave(KErrGeneral); 
       
   549         }
       
   550         
       
   551     TRACE_FUNC_EXIT
       
   552     }
       
   553 
       
   554 
       
   555 // ---------------------------------------------------------
       
   556 // HandlePutCompleteIndication()
       
   557 // ---------------------------------------------------------
       
   558 //
       
   559 TInt CBIPController::HandlePutCompleteIndication()
       
   560 	{
       
   561     TRACE_FUNC_ENTRY
       
   562     TInt retVal = KErrNone;
       
   563 
       
   564     iDefaultFolder.Zero();
       
   565     TChar driveLetter;
       
   566     if ( iDrive == EDriveC )
       
   567         {
       
   568         iFs.DriveToChar(iDrive, driveLetter);
       
   569         iDefaultFolder.Append(driveLetter);
       
   570         iDefaultFolder.Append(_L(":\\data\\"));
       
   571         iDefaultFolder.Append(iCenRepFolder);
       
   572         }
       
   573     else
       
   574         {
       
   575         iFs.DriveToChar(iDrive, driveLetter);
       
   576         iDefaultFolder.Append(driveLetter);
       
   577         iDefaultFolder.Append(_L(":\\"));
       
   578         iDefaultFolder.Append(iCenRepFolder);
       
   579         }
       
   580     
       
   581     iFullPathFilename.Zero();
       
   582     iFullPathFilename.Append(iDefaultFolder);
       
   583     TRAP ( retVal, TObexUtilsMessageHandler::SaveFileToFileSystemL(iBTObject,
       
   584                                                                    KUidMsgTypeBt,
       
   585                                                                    iMsvIdParent,
       
   586                                                                    iFullPathFilename,
       
   587                                                                    iFile,
       
   588                                                                    iRemoteDeviceName));
       
   589     if ( retVal == KErrNone)
       
   590         {
       
   591         TRAP (retVal, TObexUtilsMessageHandler::AddEntryToInboxL(iMsvIdParent, iFullPathFilename));
       
   592         }
       
   593     
       
   594     
       
   595     if( retVal != KErrNone )
       
   596         {
       
   597         TRACE_ERROR((_L( "[obexreceiveservicebip] CBIPController: HandlePutCompleteIndication error:\t %d" ), retVal ) );              
       
   598         TRAP( retVal, TObexUtilsMessageHandler::RemoveInboxEntriesL(iBTObject, iMsvIdParent));
       
   599         retVal = KErrDiskFull;
       
   600         }
       
   601     // Even if the object saving fails we must return image handle with error code
       
   602     TRAP_IGNORE( iBIPImageHandler->AddImageHandleHeaderL( iBTObexServer ) );            
       
   603     TRACE_INFO( _L( "[obexreceiveservicebip] HandlePutCompleteIndication Done\t" ) );
       
   604     delete iBTObject;
       
   605     iBTObject = NULL;
       
   606     delete iBuf;
       
   607     iBuf = NULL;
       
   608     iPreviousDefaultFolder = iDefaultFolder;  // save the last file path where file is successfully saved to file system.
       
   609     iMsvIdParent = KMsvNullIndexEntryId;
       
   610     TRACE_FUNC_EXIT     
       
   611     return retVal;
       
   612 	}
       
   613 // ---------------------------------------------------------
       
   614 // RemoveCapabilityObject()
       
   615 // ---------------------------------------------------------
       
   616 //		
       
   617 TInt CBIPController::RemoveCapabilityObject()
       
   618     {
       
   619     TRACE_FUNC_ENTRY
       
   620     if ( (iCapabilityFileName.Compare(KNullDesC)) == 0 )
       
   621         {
       
   622         return KErrNone; 
       
   623         }     
       
   624     if ( !iFs.Handle() )
       
   625         {
       
   626         TRACE_INFO( (_L( "[bipreceiveservice] RemoveCapabilityObject return" )) ); 
       
   627         return KErrGeneral;
       
   628         }               
       
   629     iFs.Delete(iCapabilityFileName);        
       
   630     iCapabilityFileName=KNullDesC; 
       
   631     TRACE_FUNC_EXIT 
       
   632     return KErrNone;    
       
   633     }
       
   634 	 
       
   635 // ---------------------------------------------------------
       
   636 // CheckCapacity()
       
   637 // ---------------------------------------------------------
       
   638 //	    
       
   639 TBool CBIPController::CheckCapacityL()
       
   640     {
       
   641     TRACE_FUNC_ENTRY   
       
   642     
       
   643     iDrive = EDriveZ; // Intialize iDrive to Z
       
   644     TInt filesize = iBTObject->Length();
       
   645     
       
   646     TInt mmcDrive = KDefaultDrive;   // External memory card  
       
   647     TInt imsDrive = KDefaultDrive;   // Internal mass storage
       
   648     
       
   649     User::LeaveIfError(DriveInfo::GetDefaultDrive(DriveInfo::EDefaultMassStorage, imsDrive));
       
   650     User::LeaveIfError(DriveInfo::GetDefaultDrive(DriveInfo::EDefaultRemovableMassStorage, mmcDrive));      
       
   651      
       
   652     TRACE_INFO( (_L( "[oppreceiveservice] CheckCapacityL imsDrive=%d; mmcDrive=%d\t" ),imsDrive, mmcDrive ) );
       
   653 
       
   654     TVolumeInfo volumeInfo;
       
   655     TInt err = iFs.Volume(volumeInfo, imsDrive);
       
   656     
       
   657     // If err != KErrNone, Drive is not available.
       
   658     //
       
   659     if ( !err )
       
   660         {
       
   661         // Check capacity on Internal mass storage            
       
   662         TRACE_INFO( (_L( "[obexreceiveservicebip] CheckCapacityL Internal mass storage \t" )) );
       
   663         if ( !SysUtil::DiskSpaceBelowCriticalLevelL( &iFs, filesize, imsDrive ) )
       
   664             {
       
   665             iDrive = imsDrive;            
       
   666             }
       
   667         }
       
   668     if ( iDrive == EDriveZ )
       
   669         {
       
   670         err = iFs.Volume(volumeInfo, mmcDrive);
       
   671         if ( !err )
       
   672             {
       
   673             // Check capacity on memory card    
       
   674             TRACE_INFO( (_L( "[obexreceiveservicebip] CheckCapacityL Checking memory card\t" )) );
       
   675             if ( !SysUtil::DiskSpaceBelowCriticalLevelL( &iFs, filesize, mmcDrive ) )
       
   676                 {                    
       
   677                 iDrive = mmcDrive;
       
   678                 }   
       
   679             }
       
   680         }           
       
   681     if ( iDrive == EDriveZ )
       
   682         {
       
   683         TRACE_INFO( (_L( "[obexreceiveservicebip] CheckCapacityL Checking phone memory\t" )) );
       
   684         // Phone memory
       
   685         if( !SysUtil::DiskSpaceBelowCriticalLevelL( &iFs, filesize, EDriveC ))
       
   686             {
       
   687             iDrive = EDriveC;
       
   688             }
       
   689         }
       
   690   
       
   691     TRACE_INFO( (_L( "[obexreceiveservicebip] CheckCapacityL iDrive = %d\t" ),iDrive ) );                   
       
   692     TRACE_FUNC_EXIT
       
   693     
       
   694     if (iDrive == EDriveZ)
       
   695         {
       
   696         // If there is no free space for receiving file, we need to set iPreviousDefaultFolder back to iDefaultFolder.
       
   697         // In order to show the file receveing dialog correctly.
       
   698         iDefaultFolder = iPreviousDefaultFolder;
       
   699         return EFalse;
       
   700         }
       
   701     return ETrue;
       
   702     }    
       
   703 
       
   704 
       
   705 // ---------------------------------------------------------
       
   706 // IsOBEXActive()
       
   707 // ---------------------------------------------------------
       
   708 //
       
   709 TBool CBIPController::IsOBEXActive()
       
   710     {    
       
   711     TRACE_FUNC    
       
   712     return ETrue;
       
   713     }
       
   714 
       
   715 // ---------------------------------------------------------
       
   716 // SetMediaType()
       
   717 // ---------------------------------------------------------
       
   718 //
       
   719 void CBIPController::SetMediaType( TSrcsMediaType __DEBUG_ONLY(aMediaType) ) 
       
   720     {
       
   721     TRACE_FUNC
       
   722     // BIP is only for Bluetooth, so that is all we expect
       
   723     __ASSERT_DEBUG(aMediaType == ESrcsMediaBT, User::Panic(KBipPanicCategory, EBipPanicNotBluetoothMediaType));
       
   724     }
       
   725 
       
   726 // ---------------------------------------------------------
       
   727 // SetObexServer()
       
   728 // ---------------------------------------------------------
       
   729 //
       
   730 TInt CBIPController::SetObexServer( CObexServer* aServer)
       
   731     {
       
   732     TInt retVal=KErrNone;
       
   733     if (aServer)
       
   734         {
       
   735         iBTObexServer=aServer;
       
   736         retVal=aServer->Start(this);
       
   737         }
       
   738     return retVal;
       
   739     }    
       
   740 
       
   741 void CBIPController::LaunchReceivingIndicatorL()
       
   742     {
       
   743     if(ReceivingIndicatorActive())
       
   744         {
       
   745         return;
       
   746         }
       
   747     
       
   748     if(iTotalSizeByte > 0)
       
   749         {
       
   750         iProgressDialog = CGlobalProgressDialog::NewL(this);  
       
   751         if(iReceivingFileName.Length() > 0)
       
   752             {
       
   753             iProgressDialog->ShowProgressDialogNameSizeL(iReceivingFileName, iTotalSizeByte);
       
   754             }
       
   755         else
       
   756             {
       
   757             iProgressDialog->ShowProgressDialogL(R_BT_RECEIVING_DATA);
       
   758             }
       
   759         }
       
   760     else
       
   761         {
       
   762         iWaitDialog = CGlobalDialog::NewL(this);
       
   763         iWaitDialog->ShowNoteDialogL(R_BT_RECEIVING_DATA, ETrue);
       
   764         }
       
   765     }
       
   766 
       
   767 void CBIPController::UpdateReceivingIndicator()
       
   768     {
       
   769     if(iProgressDialog)
       
   770         {
       
   771         iProgressDialog->UpdateProgressDialog(iBTObject->BytesReceived(), iTotalSizeByte);
       
   772         }
       
   773     // else we are using a wait note, so no "need" to update
       
   774     }
       
   775 
       
   776 void CBIPController::HandleGlobalProgressDialogL( TInt aSoftkey )
       
   777     {
       
   778     TRACE_FUNC
       
   779     
       
   780     if(aSoftkey == EAknSoftkeyCancel)
       
   781         {
       
   782         CancelTransfer();
       
   783         }
       
   784     else if(aSoftkey == EAknSoftkeyHide)
       
   785         {
       
   786         CloseReceivingIndicator(EFalse); // Don't reset state as only hiding
       
   787         }
       
   788     }
       
   789 
       
   790 void CBIPController::HandleGlobalNoteDialogL( TInt aSoftkey )
       
   791     {
       
   792     TRACE_FUNC
       
   793     
       
   794     if( aSoftkey == EAknSoftkeyCancel )
       
   795         {
       
   796         CancelTransfer();
       
   797         }
       
   798     else if( aSoftkey == EAknSoftkeyHide)
       
   799         {
       
   800         CloseReceivingIndicator(EFalse); // Don't reset state as only hiding
       
   801         }
       
   802     }
       
   803 
       
   804 void CBIPController::CloseReceivingIndicator(TBool aResetDisplayedState)
       
   805     {
       
   806     TRACE_FUNC
       
   807     if(aResetDisplayedState)
       
   808         {
       
   809         iNoteDisplayed = EFalse;
       
   810         }
       
   811     if(iProgressDialog)
       
   812         {
       
   813         iProgressDialog->ProcessFinished();
       
   814         delete iProgressDialog;
       
   815         iProgressDialog = NULL;
       
   816         }
       
   817     if(iWaitDialog)
       
   818         {
       
   819         iWaitDialog->ProcessFinished();
       
   820         delete iWaitDialog;
       
   821         iWaitDialog = NULL;
       
   822         }
       
   823     }
       
   824  
       
   825  // ---------------------------------------------------------
       
   826  // GetDriveWithMaximumFreeSpace()
       
   827  // ---------------------------------------------------------
       
   828  // 
       
   829  TInt CBIPController::GetDriveWithMaximumFreeSpaceL()
       
   830      {
       
   831      // Get drive with maximum freespace among phone memory, MMC, internal mass storage.
       
   832      //
       
   833       TRACE_FUNC   
       
   834      
       
   835      TVolumeInfo volumeInfoC;
       
   836      TVolumeInfo volumeInfoE;
       
   837      TVolumeInfo volumeInfoF;
       
   838      TInt64 max = 0;
       
   839      TInt drive = 0;
       
   840      
       
   841      TInt err = iFs.Volume(volumeInfoC, EDriveC);
       
   842     
       
   843      if ( !err )
       
   844          {
       
   845          // set initial values to max and drive.
       
   846          max = volumeInfoC.iFree;
       
   847          drive = EDriveC;
       
   848          }
       
   849           
       
   850      err = iFs.Volume(volumeInfoE, EDriveE);     
       
   851      if ( !err )
       
   852          {
       
   853          if (volumeInfoE.iFree >= max)
       
   854              {
       
   855              max = volumeInfoE.iFree;
       
   856              drive = EDriveE;             
       
   857              }
       
   858          
       
   859          }
       
   860           
       
   861      err = iFs.Volume(volumeInfoF, EDriveF);
       
   862      if ( !err )
       
   863          {
       
   864          if (volumeInfoF.iFree >= max)
       
   865              {
       
   866              max = volumeInfoF.iFree;
       
   867              drive = EDriveF;             
       
   868              }
       
   869          }
       
   870      max = 0;
       
   871      return drive;
       
   872      }
       
   873  
       
   874  // ----------------------------------------------------------
       
   875  // COPPController::HandleDevManComplete
       
   876  // Callback from devman
       
   877  // ----------------------------------------------------------
       
   878  //    
       
   879  // 
       
   880  void CBIPController::HandleGetDevicesComplete(TInt aErr, CBTDeviceArray* /*aDeviceArray*/)
       
   881     {
       
   882     if ( aErr == KErrNone )
       
   883         {
       
   884         if ( iResultArray->Count())
       
   885             {
       
   886             iRemoteDeviceName.Zero();
       
   887             if ( iResultArray->At(0)->FriendlyName().Length() > 0 )
       
   888                 {
       
   889                 TRACE_INFO( _L( "[CBIPController] HandleGetDevicesComplete: got friendly name \t" ) );
       
   890                 iRemoteDeviceName.Copy(iResultArray->At(0)->FriendlyName());
       
   891                 }
       
   892             else
       
   893                 {
       
   894                 TRACE_INFO( _L( "[CBIPController] HandleGetDevicesComplete: got devciename name \t" ) );                
       
   895                 TRAP_IGNORE(iRemoteDeviceName.Copy(BTDeviceNameConverter::ToUnicodeL(iResultArray->At(0)->DeviceName())));
       
   896                 }
       
   897             }
       
   898         }
       
   899     }
       
   900  
       
   901 //////////////////////////// Global part ////////////////////////////
       
   902 
       
   903 //  End of File