mtpfws/mtpfw/dataproviders/devdp/src/cmtpdevicedp.cpp
branchRCL_3
changeset 3 8b094906a049
parent 2 4843bb5893b6
child 4 60a94a45d437
equal deleted inserted replaced
2:4843bb5893b6 3:8b094906a049
    31 #include "cmtprequestprocessor.h"
    31 #include "cmtprequestprocessor.h"
    32 #include "cmtpstoragewatcher.h"
    32 #include "cmtpstoragewatcher.h"
    33 #include "mtpdevicedpconst.h"
    33 #include "mtpdevicedpconst.h"
    34 #include "mtpdevicedpprocessor.h"
    34 #include "mtpdevicedpprocessor.h"
    35 #include "mtpdevdppanic.h"
    35 #include "mtpdevdppanic.h"
       
    36 #include "cmtpconnectionmgr.h"
    36 
    37 
    37 #include "cmtpextndevdp.h"
    38 #include "cmtpextndevdp.h"
    38 
    39 
    39 // Class constants.
    40 // Class constants.
    40 __FLOG_STMT(_LIT8(KComponent,"DeviceDataProvider");)
    41 __FLOG_STMT(_LIT8(KComponent,"DeviceDataProvider");)
    77 
    78 
    78     iExtnPluginMapArray.ResetAndDestroy();
    79     iExtnPluginMapArray.ResetAndDestroy();
    79     iExtnPluginMapArray.Close();
    80     iExtnPluginMapArray.Close();
    80 	iEvent.Reset();
    81 	iEvent.Reset();
    81 
    82 
       
    83     delete iDeviceInfoTimer;
       
    84     iFrameWork.Close();
    82     __FLOG(_L8("~CMTPDeviceDataProvider - Exit"));
    85     __FLOG(_L8("~CMTPDeviceDataProvider - Exit"));
    83     __FLOG_CLOSE;
    86     __FLOG_CLOSE;
    84     }
    87     }
    85 
    88 
    86 void CMTPDeviceDataProvider::Cancel()
    89 void CMTPDeviceDataProvider::Cancel()
   122     }
   125     }
   123 
   126 
   124 void CMTPDeviceDataProvider::ProcessRequestPhaseL(TMTPTransactionPhase aPhase, const TMTPTypeRequest& aRequest, MMTPConnection& aConnection)
   127 void CMTPDeviceDataProvider::ProcessRequestPhaseL(TMTPTransactionPhase aPhase, const TMTPTypeRequest& aRequest, MMTPConnection& aConnection)
   125     {
   128     {
   126     __FLOG(_L8("ProcessRequestPhaseL - Entry"));
   129     __FLOG(_L8("ProcessRequestPhaseL - Entry"));
       
   130     TUint16 opCode( aRequest.Uint16( TMTPTypeRequest::ERequestOperationCode ) );    
   127     TInt index = LocateRequestProcessorL(aRequest, aConnection);
   131     TInt index = LocateRequestProcessorL(aRequest, aConnection);
   128     __ASSERT_DEBUG(index != KErrNotFound, Panic(EMTPDevDpNoMatchingProcessor));
   132     __ASSERT_DEBUG(index != KErrNotFound, Panic(EMTPDevDpNoMatchingProcessor));
   129     MMTPRequestProcessor* processor = iActiveProcessors[index];
   133     MMTPRequestProcessor* processor = iActiveProcessors[index];
   130     iActiveProcessor = index;
   134     iActiveProcessor = index;
   131     iActiveProcessorRemoved = EFalse;
   135     iActiveProcessorRemoved = EFalse;
   138 	    {
   142 	    {
   139 	    processor->Release();    	
   143 	    processor->Release();    	
   140 	    iActiveProcessors.Remove(index);
   144 	    iActiveProcessors.Remove(index);
   141 	    }
   145 	    }
   142     iActiveProcessor = -1;
   146     iActiveProcessor = -1;
       
   147     
       
   148     __FLOG_VA((_L8("opCode = 0x%x"), opCode));
       
   149     __FLOG_VA((_L8("TranPort UID = 0x%x"), iFrameWork.ConnectionMgr().TransportUid().iUid));
       
   150     __FLOG_VA((_L8("CommandState = 0x%x"), iCommandState));    
       
   151     const static TInt32 KMTPUsbTransportUid = 0x102827B2;
       
   152 
       
   153     if((EMTPOpCodeGetDeviceInfo == opCode)&&(KMTPUsbTransportUid == iFrameWork.ConnectionMgr().TransportUid().iUid))
       
   154         {
       
   155         __FLOG(_L8("EMTPOpCodeGetDeviceInfo == opCode"));
       
   156         //If GetDeviceInfo comes and there is no OpenSession before, the timer will start. And tread the host as Mac. 
       
   157         //Only the first GetDeviceInfo in one session will start the timer.
       
   158         if((EIdle == iCommandState)&&(NULL == iDeviceInfoTimer))
       
   159             {
       
   160             __FLOG(_L8("EMTPOpCodeGetDeviceInfo == opCode, start timer"));
       
   161             iCommandState = EStartDeviceInfoTimer;
       
   162             iDeviceInfoTimer = CMTPDeviceInfoTimer::NewL(*this);
       
   163             iDeviceInfoTimer->Start();
       
   164             }
       
   165         else
       
   166             {
       
   167             __FLOG(_L8("EMTPOpCodeGetDeviceInfo == opCode, Not start timer"));            
       
   168             }
       
   169         }
       
   170     else
       
   171        {       
       
   172        __FLOG(_L8("EMTPOpCodeGetDeviceInfo != opCode"));
       
   173        if((EMTPOpCodeOpenSession == opCode)&&(EIdle == iCommandState))
       
   174             {
       
   175             __FLOG(_L8("EMTPOpCodeGetDeviceInfo == opCode, set CommandState to be EOpenSession"));
       
   176             iCommandState = EOpenSession;
       
   177             }
       
   178        
       
   179        if(iDeviceInfoTimer)
       
   180            {
       
   181            __FLOG(_L8("iDeviceInfoTimer != NULL, stop timer"));
       
   182            delete iDeviceInfoTimer;
       
   183            iDeviceInfoTimer = NULL;
       
   184            }
       
   185        else
       
   186            {
       
   187            __FLOG(_L8("iDeviceInfoTimer == NULL, NOT stop timer"));            
       
   188            }
       
   189        }    
   143     __FLOG(_L8("ProcessRequestPhaseL - Exit"));
   190     __FLOG(_L8("ProcessRequestPhaseL - Exit"));
   144     }
   191     }
   145 
   192 
   146 void CMTPDeviceDataProvider::StartObjectEnumerationL(TUint32 aStorageId, TBool /*aPersistentFullEnumeration*/)
   193 void CMTPDeviceDataProvider::StartObjectEnumerationL(TUint32 aStorageId, TBool /*aPersistentFullEnumeration*/)
   147     {
   194     {
   326 Constructor.
   373 Constructor.
   327 */
   374 */
   328 CMTPDeviceDataProvider::CMTPDeviceDataProvider(TAny* aParams) :
   375 CMTPDeviceDataProvider::CMTPDeviceDataProvider(TAny* aParams) :
   329     CMTPDataProviderPlugin(aParams),
   376     CMTPDataProviderPlugin(aParams),
   330     iActiveProcessors(KMTPDeviceDpSessionGranularity),
   377     iActiveProcessors(KMTPDeviceDpSessionGranularity),
   331     iActiveProcessor(-1)
   378     iActiveProcessor(-1),
       
   379     iDeviceInfoTimer(NULL),
       
   380     iCommandState(EIdle)
   332     {
   381     {
   333 
   382 
   334     }
   383     }
   335 
   384 
   336 /**
   385 /**
   536 		{
   585 		{
   537 	    __FLOG(_L8("\nTere is an issue in loading the plugin !!!!!\n"));
   586 	    __FLOG(_L8("\nTere is an issue in loading the plugin !!!!!\n"));
   538 		}
   587 		}
   539 
   588 
   540     iEnumerator = CMTPFSEnumerator::NewL(Framework(), iDpSingletons.ExclusionMgrL(), *this, KProcessLimit);
   589     iEnumerator = CMTPFSEnumerator::NewL(Framework(), iDpSingletons.ExclusionMgrL(), *this, KProcessLimit);
   541     
   590     iFrameWork.OpenL();
   542     
   591     
   543     __FLOG(_L8("ConstructL - Exit"));
   592     __FLOG(_L8("ConstructL - Exit"));
   544 
   593 
   545     }
   594     }
   546 
   595 
   663     		{        		
   712     		{        		
   664     			processor->Release();
   713     			processor->Release();
   665     		} 
   714     		} 
   666 		}
   715 		}
   667         }
   716         }
       
   717     __FLOG_VA((_L8("current state is =%d"), iCommandState));    
       
   718     if(iCommandState != EIdle)
       
   719         {
       
   720         if(iDeviceInfoTimer)
       
   721             {
       
   722             delete iDeviceInfoTimer;
       
   723             iDeviceInfoTimer = NULL;
       
   724             }
       
   725         iCommandState = EIdle;
       
   726         iDevDpSingletons.DeviceDataStore().SetConnectMac(EFalse);
       
   727         }
   668     __FLOG(_L8("SessionClosedL - Exit"));
   728     __FLOG(_L8("SessionClosedL - Exit"));
   669     }
   729     }
   670 
   730 
   671 /**
   731 /**
   672 Prepares for a newly-opened session.
   732 Prepares for a newly-opened session.
   681     __FLOG(_L8("SessionOpenedL - Entry"));
   741     __FLOG(_L8("SessionOpenedL - Entry"));
   682     __FLOG_VA((_L8("SessionID = %d"), aSession.iMTPId));
   742     __FLOG_VA((_L8("SessionID = %d"), aSession.iMTPId));
   683     __FLOG(_L8("SessionOpenedL - Exit"));
   743     __FLOG(_L8("SessionOpenedL - Exit"));
   684     }
   744     }
   685 
   745 
       
   746 void CMTPDeviceDataProvider::SetConnectMac()
       
   747     {
       
   748     __FLOG(_L8("SetConnectMac - Entry"));   
       
   749     iDevDpSingletons.DeviceDataStore().SetConnectMac(ETrue);
       
   750     __FLOG_VA((_L8("previous state = %d, current is ESetIsMac"), iCommandState));    
       
   751     iCommandState = ESetIsMac;
       
   752     __FLOG(_L8("SetConnectMac - Exit"));     
       
   753     }
       
   754 
       
   755 /**
       
   756 CMTPDeviceInfoTimer factory method. 
       
   757 @return A pointer to a new CMTPDeviceInfoTimer instance. Ownership IS transfered.
       
   758 @leave One of the system wide error codes if a processing failure occurs.
       
   759 */
       
   760 CMTPDeviceInfoTimer* CMTPDeviceInfoTimer::NewL(CMTPDeviceDataProvider& aDeviceProvider)
       
   761     {
       
   762     CMTPDeviceInfoTimer* self = new (ELeave) CMTPDeviceInfoTimer(aDeviceProvider);
       
   763     CleanupStack::PushL(self);
       
   764     self->ConstructL();
       
   765     CleanupStack::Pop(self);
       
   766     return self;
       
   767     }
       
   768     
       
   769 /**
       
   770 Destructor.
       
   771 */
       
   772 CMTPDeviceInfoTimer::~CMTPDeviceInfoTimer()
       
   773     {
       
   774     Cancel();
       
   775     iLdd.Close();
       
   776     __FLOG_CLOSE;    
       
   777     }
       
   778     
       
   779 /**
       
   780 Starts the deviceinfo timer.
       
   781 */
       
   782 // DeviceInfo delay, in microseconds. 5s
       
   783 const TUint KMTPDeviceInfoDelay = (1000000 * 5);
       
   784 void CMTPDeviceInfoTimer::Start()
       
   785     {
       
   786     __FLOG(_L8("CMTPDeviceInfoTimer::Start - Entry"));    
       
   787 
       
   788     After(KMTPDeviceInfoDelay);
       
   789     iState = EStartTimer;
       
   790     __FLOG(_L8("CMTPDeviceInfoTimer::Start - Exit"));     
       
   791     }
       
   792     
       
   793 void CMTPDeviceInfoTimer::RunL()
       
   794     {
       
   795     __FLOG(_L8("CMTPDeviceInfoTimer::RunL - Entry"));
       
   796     __FLOG_VA((_L8("iStatus == %d"), iStatus.Int()));    
       
   797 
       
   798     switch(iState)
       
   799         {
       
   800         case EStartTimer:
       
   801             __FLOG(_L8("CMTPDeviceInfoTimer::RunL - EStartTimer"));
       
   802             // Open the USB device interface.
       
   803             User::LeaveIfError(iLdd.Open(0));
       
   804             iLdd.ReEnumerate(iStatus);
       
   805             iDeviceProvider.SetConnectMac();
       
   806             iState = EUSBReEnumerate;
       
   807             SetActive();
       
   808             break;
       
   809         case EUSBReEnumerate:          
       
   810             __FLOG(_L8("CMTPDeviceInfoTimer::RunL - EUSBReEnumerate"));            
       
   811             break;
       
   812         default:
       
   813             __FLOG(_L8("CMTPDeviceInfoTimer::RunL - default")); 
       
   814             break;
       
   815         }
       
   816     __FLOG(_L8("CMTPDeviceInfoTimer::RunL - Exit"));    
       
   817     }
       
   818     
       
   819 /** 
       
   820 Constructor
       
   821 */
       
   822 CMTPDeviceInfoTimer::CMTPDeviceInfoTimer(CMTPDeviceDataProvider& aDeviceProvider) : 
       
   823     CTimer(EPriorityNormal),iDeviceProvider(aDeviceProvider),iState(EIdle)
       
   824     {
       
   825     
       
   826     }    
       
   827 
       
   828 /**
       
   829 Second phase constructor.
       
   830 */    
       
   831 void CMTPDeviceInfoTimer::ConstructL()
       
   832     {
       
   833     __FLOG_OPEN(KMTPSubsystem, KComponent);
       
   834     CTimer::ConstructL();
       
   835     CActiveScheduler::Add(this);
       
   836     }