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