kerneltest/f32test/shostmassstorage/msman/src/cusbhost.cpp
changeset 297 b2826f67641f
parent 90 947f0dc9f7a8
equal deleted inserted replaced
296:94f2adf59133 297:b2826f67641f
     1 // Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of the License "Eclipse Public License v1.0"
     4 // under the terms of the License "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
    27 #include "cusbmsmountmanager.h"
    27 #include "cusbmsmountmanager.h"
    28 
    28 
    29 #include "mdrivedisplay.h"
    29 #include "mdrivedisplay.h"
    30 #include "cusbhostao.h"
    30 #include "cusbhostao.h"
    31 #include "cusbhost.h"
    31 #include "cusbhost.h"
    32 #include "tmslog.h"
       
    33 #include "debug.h"
    32 #include "debug.h"
    34 
    33 
    35 
    34 
    36 
    35 
    37 _LIT(KHubDriverLddFileName, "usbhubdriver");
    36 _LIT(KHubDriverLddFileName, "usbhubdriver");
    38 _LIT(KUsbdiLddFileName, "usbdi");
    37 _LIT(KUsbdiLddFileName, "usbdi");
    39 
    38 
    40 
    39 
    41 CUsbHost* CUsbHost::NewL()
    40 CUsbHost* CUsbHost::NewL()
    42     {
    41     {
    43     __MSFNSLOG
    42     CUsbHost* r = new (ELeave) CUsbHost();
    44 	CUsbHost* r = new (ELeave) CUsbHost();
    43     CleanupStack::PushL(r);
    45 	CleanupStack::PushL(r);
    44 
    46 
    45     r->ConstructL();
    47 	r->ConstructL();
    46     CleanupStack::Pop();
    48 	CleanupStack::Pop();
    47     return r;
    49 	return r;
       
    50     }
    48     }
    51 
    49 
    52 
    50 
    53 void CUsbHost::ConstructL()
    51 void CUsbHost::ConstructL()
    54     {
    52     {
    55     __MSFNLOG
       
    56     OpenHubL();
    53     OpenHubL();
    57 	LoadFileSystemL();
    54     LoadFileSystemL();
    58 
    55 
    59     iUsbHostAo = CUsbHostAo::NewL(iHubDriver, iEvent, *this);
    56     iUsbHostAo = CUsbHostAo::NewL(iHubDriver, iEvent, *this);
    60 
    57 
    61     iMountManager = CUsbMsMountManager::NewL();
    58     iMountManager = CUsbMsMountManager::NewL();
    62     }
    59     }
    63 
    60 
    64 
    61 
    65 CUsbHost::CUsbHost()
    62 CUsbHost::CUsbHost()
    66     {
    63     {
    67     __MSFNLOG
       
    68     }
    64     }
    69 
    65 
    70 
    66 
    71 CUsbHost::~CUsbHost()
    67 CUsbHost::~CUsbHost()
    72     {
    68     {
    73     __MSFNLOG
       
    74     delete iUsbHostAo;
    69     delete iUsbHostAo;
    75 
    70 
    76     DismountAllFileSystemsL();
    71     DismountAllFileSystemsL();
    77     CloseAllDevicesL();
    72     CloseAllDevicesL();
    78     CloseHubL();
    73     CloseHubL();
    81     }
    76     }
    82 
    77 
    83 
    78 
    84 void CUsbHost::LoadFileSystemL()
    79 void CUsbHost::LoadFileSystemL()
    85     {
    80     {
    86     __MSFNLOG
       
    87     RFs fs;
    81     RFs fs;
    88     User::LeaveIfError(fs.Connect());
    82     User::LeaveIfError(fs.Connect());
    89     CleanupClosePushL(fs);
    83     CleanupClosePushL(fs);
    90 	_LIT(KFsNm, "elocal");
    84     _LIT(KFsNm, "elocal");
    91 
    85 
    92     TInt err;
    86     TInt err;
    93     err = fs.AddFileSystem(KFsNm);
    87     err = fs.AddFileSystem(KFsNm);
    94     if (err != KErrAlreadyExists)
    88     if (err != KErrAlreadyExists)
    95         User::LeaveIfError(err);
    89         User::LeaveIfError(err);
   106     }
   100     }
   107 
   101 
   108 
   102 
   109 void CUsbHost::OpenHubL()
   103 void CUsbHost::OpenHubL()
   110     {
   104     {
   111     __MSFNLOG
       
   112     TInt err;
   105     TInt err;
   113     err = User::LoadLogicalDevice(KHubDriverLddFileName);
   106     err = User::LoadLogicalDevice(KHubDriverLddFileName);
   114     if (err != KErrAlreadyExists)
   107     if (err != KErrAlreadyExists)
   115         User::LeaveIfError(err);
   108         User::LeaveIfError(err);
   116 
   109 
   123     }
   116     }
   124 
   117 
   125 
   118 
   126 void CUsbHost::CloseHubL()
   119 void CUsbHost::CloseHubL()
   127     {
   120     {
   128     __MSFNLOG
   121     iHubDriver.StopHost();
   129 	iHubDriver.StopHost();
   122     iHubDriver.Close();
   130 	iHubDriver.Close();
   123 
   131 
   124     TInt err1 = User::FreeLogicalDevice(KUsbdiLddFileName);
   132 	TInt err1 = User::FreeLogicalDevice(KUsbdiLddFileName);
   125     __ASSERT_DEBUG(err1==KErrNone, User::Panic(KUsbdiLddFileName, err1));
   133 	__ASSERT_DEBUG(err1==KErrNone, User::Panic(KUsbdiLddFileName, err1));
   126 
   134 
   127     TInt err2 = User::FreeLogicalDevice(KHubDriverLddFileName);
   135 	TInt err2 = User::FreeLogicalDevice(KHubDriverLddFileName);
   128     __ASSERT_DEBUG(err2==KErrNone, User::Panic(KHubDriverLddFileName, err2));
   136 	__ASSERT_DEBUG(err2==KErrNone, User::Panic(KHubDriverLddFileName, err2));
   129 
   137 
   130     User::LeaveIfError(err1);
   138 	User::LeaveIfError(err1);
   131     User::LeaveIfError(err2);
   139 	User::LeaveIfError(err2);
       
   140     }
   132     }
   141 
   133 
   142 
   134 
   143 TToken CUsbHost::OpenDeviceL()
   135 TToken CUsbHost::OpenDeviceL()
   144     {
   136     {
   145     __MSFNLOG
       
   146     CDevice* device = CDevice::NewL();
   137     CDevice* device = CDevice::NewL();
   147 
   138 
   148     TToken token = 0;
   139     TToken token = 0;
   149     TRAPD(err, token = device->OpenDeviceL(iDeviceHandle, iHubDriver));
   140     TRAPD(err, token = device->OpenDeviceL(iDeviceHandle, iHubDriver));
   150     if (err)
   141     if (err)
   157     }
   148     }
   158 
   149 
   159 
   150 
   160 void CUsbHost::CloseDeviceL()
   151 void CUsbHost::CloseDeviceL()
   161     {
   152     {
   162     __MSFNLOG
       
   163     CDevice* device = iMountManager->RemoveDeviceL(iDeviceHandle);
   153     CDevice* device = iMountManager->RemoveDeviceL(iDeviceHandle);
   164     device->CloseDeviceL();
   154     device->CloseDeviceL();
   165     delete device;
   155     delete device;
   166     }
   156     }
   167 
   157 
   168 
   158 
   169 void CUsbHost::CloseAllDevicesL()
   159 void CUsbHost::CloseAllDevicesL()
   170     {
   160     {
   171     __MSFNLOG
       
   172     iMountManager->CloseAllDevicesL();
   161     iMountManager->CloseAllDevicesL();
   173     }
   162     }
   174 
   163 
   175 
   164 
   176 void CUsbHost::MountDeviceL()
   165 void CUsbHost::MountDeviceL()
   177     {
   166     {
   178     __MSFNLOG
       
   179     iMountManager->MountDeviceL(iDeviceHandle);
   167     iMountManager->MountDeviceL(iDeviceHandle);
   180     }
   168     }
   181 
   169 
   182 
   170 
   183 void CUsbHost::DismountDeviceL()
   171 void CUsbHost::DismountDeviceL()
   184     {
   172     {
   185     __MSFNLOG
       
   186     iMountManager->DismountDeviceL(iDeviceHandle);
   173     iMountManager->DismountDeviceL(iDeviceHandle);
   187     }
   174     }
   188 
   175 
   189 
   176 
   190 void CUsbHost::DismountAllFileSystemsL()
   177 void CUsbHost::DismountAllFileSystemsL()
   191     {
   178     {
   192     __MSFNLOG
       
   193     iMountManager->DismountL();
   179     iMountManager->DismountL();
   194     }
   180     }
   195 
   181 
   196 
   182 
   197 void CUsbHost::Start()
   183 void CUsbHost::Start()
   198     {
   184     {
   199     __MSFNLOG
       
   200     iUsbHostAo->Wait();
   185     iUsbHostAo->Wait();
   201     }
   186     }
   202 
   187 
   203 
   188 
   204 void CUsbHost::ProcessBusEventL()
   189 void CUsbHost::ProcessBusEventL()
   205     {
   190     {
   206     __MSFNLOG
       
   207 
       
   208     __USBHOSTPRINT2(_L(">> CUsbHost RUsbHubDriver Event[%d] Device Handle = %d"),
   191     __USBHOSTPRINT2(_L(">> CUsbHost RUsbHubDriver Event[%d] Device Handle = %d"),
   209                     iEvent.iEventType, iEvent.iDeviceHandle);
   192                     iEvent.iEventType, iEvent.iDeviceHandle);
   210     __USBHOSTPRINT2(_L("Error = %d reason = %x"),
   193     __USBHOSTPRINT2(_L("Error = %d reason = %x"),
   211                     iEvent.iError, iEvent.iReason);
   194                     iEvent.iError, iEvent.iReason);
   212 
   195 
   216     if (event == RUsbHubDriver::TBusEvent::EDeviceAttached)
   199     if (event == RUsbHubDriver::TBusEvent::EDeviceAttached)
   217         {
   200         {
   218         /* Jungo stack has attached the device */
   201         /* Jungo stack has attached the device */
   219         TUint32 token = OpenDeviceL();
   202         TUint32 token = OpenDeviceL();
   220         MountDeviceL();
   203         MountDeviceL();
   221 	    __USBHOSTPRINT(_L("CUsbHost: device attached"));
   204         __USBHOSTPRINT(_L("CUsbHost: device attached"));
   222         }
   205         }
   223     else if (event == RUsbHubDriver::TBusEvent::EDeviceRemoved)
   206     else if (event == RUsbHubDriver::TBusEvent::EDeviceRemoved)
   224         {
   207         {
   225 		TRAPD(err, DismountDeviceL());
   208         TRAPD(err, DismountDeviceL());
   226 	    CloseDeviceL();
   209         CloseDeviceL();
   227         User::LeaveIfError(err);
   210         User::LeaveIfError(err);
   228         __USBHOSTPRINT(_L("CUsbHost: device removed"));
   211         __USBHOSTPRINT(_L("CUsbHost: device removed"));
   229         }
   212         }
   230 
   213 
   231     else
   214     else
   235     }
   218     }
   236 
   219 
   237 
   220 
   238 RUsbHubDriver::TBusEvent::TEvent CUsbHost::WaitForBusEvent()
   221 RUsbHubDriver::TBusEvent::TEvent CUsbHost::WaitForBusEvent()
   239     {
   222     {
   240     __MSFNLOG
       
   241     TRequestStatus status;
   223     TRequestStatus status;
   242     RUsbHubDriver::TBusEvent event;
   224     RUsbHubDriver::TBusEvent event;
   243     TBool eventReceived = EFalse;
   225     TBool eventReceived = EFalse;
   244     do
   226     do
   245         {
   227         {
   279     }
   261     }
   280 
   262 
   281 
   263 
   282 void CUsbHost::DriveMap(TDriveMap& aDriveMap) const
   264 void CUsbHost::DriveMap(TDriveMap& aDriveMap) const
   283     {
   265     {
   284     __MSFNSLOG
       
   285     iMountManager->DriveMap(aDriveMap);
   266     iMountManager->DriveMap(aDriveMap);
   286     }
   267     }
   287 
   268 
   288 
   269 
   289 void CUsbHost::DeviceMap(TInt aDeviceIndex, TDeviceMap& aDeviceMap) const
   270 void CUsbHost::DeviceMap(TInt aDeviceIndex, TDeviceMap& aDeviceMap) const
   290     {
   271     {
   291     __MSFNSLOG
       
   292     iMountManager->DeviceMap(aDeviceIndex, aDeviceMap);
   272     iMountManager->DeviceMap(aDeviceIndex, aDeviceMap);
   293     }
   273     }
   294 
   274 
   295 
   275 
   296 TInt CUsbHost::DevicesNumber() const
   276 TInt CUsbHost::DevicesNumber() const
   299     }
   279     }
   300 
   280 
   301 
   281 
   302 CUsbHostDisp* CUsbHostDisp::NewL(MDriveDisplay& aDriveDisplay)
   282 CUsbHostDisp* CUsbHostDisp::NewL(MDriveDisplay& aDriveDisplay)
   303     {
   283     {
   304     __MSFNSLOG
   284     CUsbHostDisp* r = new (ELeave) CUsbHostDisp(aDriveDisplay);
   305 	CUsbHostDisp* r = new (ELeave) CUsbHostDisp(aDriveDisplay);
   285     CleanupStack::PushL(r);
   306 	CleanupStack::PushL(r);
   286     r->ConstructL();
   307 	r->ConstructL();
   287     CleanupStack::Pop();
   308 	CleanupStack::Pop();
   288     return r;
   309 	return r;
       
   310     }
   289     }
   311 
   290 
   312 
   291 
   313 void CUsbHostDisp::ConstructL()
   292 void CUsbHostDisp::ConstructL()
   314     {
   293     {
   315     __MSFNLOG
       
   316     CUsbHost::ConstructL();
   294     CUsbHost::ConstructL();
   317     }
   295     }
   318 
   296 
   319 
   297 
   320 CUsbHostDisp::CUsbHostDisp(MDriveDisplay& aDriveDisplay)
   298 CUsbHostDisp::CUsbHostDisp(MDriveDisplay& aDriveDisplay)
   321 :   CUsbHost(),
   299 :   CUsbHost(),
   322     iDriveDisplay(aDriveDisplay)
   300     iDriveDisplay(aDriveDisplay)
   323     {
   301     {
   324     __MSFNLOG
       
   325     }
   302     }
   326 
   303 
   327 
   304 
   328 CUsbHostDisp::~CUsbHostDisp()
   305 CUsbHostDisp::~CUsbHostDisp()
   329     {
   306     {
   330     __MSFNLOG
       
   331     }
   307     }
   332 
   308 
   333 void CUsbHostDisp::ProcessBusEventL()
   309 void CUsbHostDisp::ProcessBusEventL()
   334     {
   310     {
   335     CUsbHost::ProcessBusEventL();
   311     CUsbHost::ProcessBusEventL();