userlibandfileserver/fileserver/shostmassstorage/server/protocol/cscsiprotocol.cpp
branchRCL_3
changeset 87 2f92ad2dc5db
parent 62 4a8fed1c0ef6
child 97 41f0cfe18c80
--- a/userlibandfileserver/fileserver/shostmassstorage/server/protocol/cscsiprotocol.cpp	Mon Mar 15 12:45:50 2010 +0200
+++ b/userlibandfileserver/fileserver/shostmassstorage/server/protocol/cscsiprotocol.cpp	Wed Mar 31 23:38:45 2010 +0300
@@ -1,4 +1,4 @@
-// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
+// Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
 // All rights reserved.
 // This component and the accompanying materials are made available
 // under the terms of the License "Eclipse Public License v1.0"
@@ -26,8 +26,6 @@
 #include "shared.h"
 #include "msgservice.h"
 
-#include "mscutils.h"
-
 #include "mtransport.h"
 #include "mprotocol.h"
 #include "tscsiclientreq.h"
@@ -45,7 +43,6 @@
 #include "usbmshostpanic.h"
 
 
-
 /**
 Create the CScsiProtocol object.
 
@@ -68,8 +65,8 @@
 void CScsiProtocol::ConstructL(TLun aLun)
     {
 	__MSFNLOG
+	// iState = EEntry;
     iFsm = CMassStorageFsm::NewL(*this);
-	iState = EDisconnected;
 
     const TInt blockLength = 0x200;
 
@@ -99,6 +96,7 @@
 void CScsiProtocol::InitialiseUnitL()
     {
 	__MSFNLOG
+    iState = EDisconnected;
 
 	// A device may take time to mount the media. If the device fails attempt to
 	// retry the connection for a number of seconds
@@ -107,10 +105,9 @@
         {
         retryCounter--;
         iFsm->ConnectLogicalUnitL();
-        iState = iFsm->IsConnected() ? EConnected: EDisconnected;
-
-        if (iState == EConnected)
+        if (iFsm->IsConnected())
             {
+            iState = EConnected;
             break;
             }
         User::After(1000 * 200);    // 200 mS
@@ -162,8 +159,7 @@
     if (err)
         {
         __SCSIPRINT1(_L("READ(10) Err=%d"), err);
-        DoCheckConditionL();
-        User::LeaveIfError(KErrAbort);
+        User::LeaveIfError(DoCheckConditionL());
         }
 
     // handle residue
@@ -189,8 +185,7 @@
         TInt err = iSbcInterface->Read10L(aPos/blockLen, aCopybuf, len);
         if (err)
             {
-            DoCheckConditionL();
-            User::LeaveIfError(KErrAbort);
+            User::LeaveIfError(DoCheckConditionL());
             }
         }
     }
@@ -217,8 +212,7 @@
 	TInt err = iSbcInterface->Write10L(aPos/blockLen, aCopybuf, aOffset, len);
     if (err)
         {
-        DoCheckConditionL();
-        User::LeaveIfError(KErrAbort);
+        User::LeaveIfError(DoCheckConditionL());
         }
 
     while (len != aLen)
@@ -242,8 +236,7 @@
         TInt err = iSbcInterface->Write10L(aPos/blockLen, buf, aOffset, len);
         if (err)
             {
-            DoCheckConditionL();
-            User::LeaveIfError(KErrAbort);
+            User::LeaveIfError(DoCheckConditionL());
             }
         }
     }
@@ -268,15 +261,11 @@
         err = iSbcInterface->ReadCapacity10L(lastLba, blockLength);
         } while (err == KErrCommandStalled && stallCounter-- > 0);
 
-
     if (err)
         {
-        if (err == KErrCommandFailed)
-            {
-            // Clear sense error
-            DoCheckConditionL();
-            }
-        User::LeaveIfError(KErrAbort);
+        // DoCheckConditionL clears sense error
+        // Media not present will return KErrNotReady so leave here
+        User::LeaveIfError(DoCheckConditionL());
         }
 
     // update iWriteProtect
@@ -286,14 +275,24 @@
         if (err == KErrCommandFailed)
             {
             // Clear sense error
-            DoCheckConditionL();
+            err = DoCheckConditionL();
+            // ignore error if unsupported
+            if (err != KErrUnknown)
+                {
+                User::LeaveIfError(err);
+                }
             }
 
         err = MsModeSense6L();
         if (err == KErrCommandFailed)
             {
             // Clear sense error
-            DoCheckConditionL();
+            err = DoCheckConditionL();
+            // ignore error if unsupported
+            if (err != KErrUnknown)
+                {
+                User::LeaveIfError(err);
+                }
             }           
         }
 
@@ -481,33 +480,49 @@
     }
 
 
-void CScsiProtocol::DoCheckConditionL()
+TInt CScsiProtocol::DoCheckConditionL()
     {
 	__MSFNLOG
     User::LeaveIfError(MsRequestSenseL());
 
+    TInt err;
+
     // Check if init is needed
     if (iSenseInfo.iSenseCode == TSenseInfo::ENotReady &&
         iSenseInfo.iAdditional == TSenseInfo::EAscLogicalUnitNotReady &&
         iSenseInfo.iQualifier == TSenseInfo::EAscqInitializingCommandRequired)
         {
         // start unit
-        TInt err = iSbcInterface->StartStopUnitL(ETrue);
-
+        err = iSbcInterface->StartStopUnitL(ETrue);
         if (err)
             {
             User::LeaveIfError(MsRequestSenseL());
             }
-
         }
 
-    TInt r = GetSystemWideSenseError(iSenseInfo);
+    err = GetSystemWideSenseError(iSenseInfo);
 
-    if (((r == KErrNotReady) && (iState == EConnected)) ||
-        r == KErrDisconnected)
-	    {
-        CompleteNotifyChangeL();
+    TScsiState nextState = iState;
+    if (err == KErrDisconnected)
+        {
+        nextState = EDisconnected;
+        }
+    else if (err == KErrNotReady)
+        {
+        nextState = EMediaNotPresent;
         }
+    else
+        {
+        // no state change;
+        }
+
+    if (nextState != iState)
+        {
+        iMediaChangeNotifier.DoNotifyL();
+        iState = nextState;
+        }
+           
+    return err;
     }
 
 
@@ -730,7 +745,7 @@
     __MSFNLOG
 	TInt err = KErrNone;
 
-	if(iFsm->IsRemovableMedia() || iState == EDisconnected)
+	if(iFsm->IsRemovableMedia() || iState != EConnected)
         {
 		iFsm->SetStatusCheck();
 		TRAP(err, iFsm->ConnectLogicalUnitL());
@@ -760,18 +775,6 @@
         }
 	}
 
-void CScsiProtocol::CompleteNotifyChangeL()
-	{
-    __MSFNLOG
-    if (!iFsm->IsStatusCheck())
-		{
-		if (iState == EConnected)
-			{
-			iState = EDisconnected;
-            iMediaChangeNotifier.DoNotifyL();
-			}
-		}
-	}
 
 RMediaChangeNotifier::RMediaChangeNotifier()
 :   iRegistered(EFalse)