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