userlibandfileserver/fileserver/shostmassstorage/server/controller/tlogicalunitlist.cpp
changeset 297 b2826f67641f
parent 127 e408fc570bb5
equal deleted inserted replaced
296:94f2adf59133 297:b2826f67641f
    23 
    23 
    24 #include "msctypes.h"
    24 #include "msctypes.h"
    25 #include "cusbhostmslogicalunit.h"
    25 #include "cusbhostmslogicalunit.h"
    26 #include "tlogicalunitlist.h"
    26 #include "tlogicalunitlist.h"
    27 
    27 
    28 #include "msdebug.h"
    28 #include "OstTraceDefinitions.h"
    29 #include "debug.h"
    29 #ifdef OST_TRACE_COMPILER_IN_USE
       
    30 #include "tlogicalunitlistTraces.h"
       
    31 #endif
    30 
    32 
    31 TLogicalUnitList::~TLogicalUnitList()
    33 TLogicalUnitList::~TLogicalUnitList()
    32     {
    34     {
    33     __MSFNLOG
       
    34     iLu.ResetAndDestroy();
    35     iLu.ResetAndDestroy();
    35     }
    36     }
    36 
    37 
    37 void TLogicalUnitList::AddLuL(CUsbHostMsLogicalUnit* aLu)
    38 void TLogicalUnitList::AddLuL(CUsbHostMsLogicalUnit* aLu)
    38     {
    39     {
    39     __MSFNLOG
    40     OstTrace1(TRACE_SHOSTMASSSTORAGE_HOST, TLOGICALUNITLIST_10,
    40     __HOSTPRINT1(_L("Adding LU 0x%x"), aLu);
    41               "Adding LU 0x%x", aLu);
    41     TInt r= FindLu(aLu->Lun());
    42     TInt r= FindLu(aLu->Lun());
    42 
    43 
    43     if (r < 0)
    44     if (r < 0)
    44         {
    45         {
    45         if (r != KErrNotFound)
    46         if (r != KErrNotFound)
    46             {
    47             {
    47             User::Leave(r);
    48             User::Leave(r);
    48             }
    49             }
    49         }
    50         }
    50     else	// If it is able to find the lun already
    51     else    // If it is able to find the lun already
    51         {
    52         {
    52         User::Leave(KErrAlreadyExists);
    53         User::Leave(KErrAlreadyExists);
    53         }
    54         }
    54 
    55 
    55 	User::LeaveIfError(iLu.Append(aLu));
    56     User::LeaveIfError(iLu.Append(aLu));
    56     }
    57     }
    57 
    58 
    58 
    59 
    59 void TLogicalUnitList::RemoveLuL(TLun aLun)
    60 void TLogicalUnitList::RemoveLuL(TLun aLun)
    60     {
    61     {
    61     __MSFNLOG
       
    62     TInt index = FindLu(aLun);
    62     TInt index = FindLu(aLun);
    63     User::LeaveIfError(index);
    63     User::LeaveIfError(index);
    64 
    64 
    65     CUsbHostMsLogicalUnit* lu = iLu[index];
    65     CUsbHostMsLogicalUnit* lu = iLu[index];
    66     TRAPD(err, lu->UnInitL());
    66     TRAPD(err, lu->UnInitL());
    67     delete lu;
    67     delete lu;
    68     iLu.Remove(index);
    68     iLu.Remove(index);
    69 	if(err != KErrNone)
    69     if(err != KErrNone)
    70 		User::Leave(err);
    70         User::Leave(err);
    71     }
    71     }
    72 
    72 
    73 
    73 
    74 void TLogicalUnitList::RemoveAllLuL()
    74 void TLogicalUnitList::RemoveAllLuL()
    75     {
    75     {
    76     __MSFNLOG
    76     TInt ret = KErrNone;
    77 	TInt ret = KErrNone;
       
    78     for (TInt index = 0; index < iLu.Count(); index++)
    77     for (TInt index = 0; index < iLu.Count(); index++)
    79         {
    78         {
    80         CUsbHostMsLogicalUnit* lu = iLu[index];
    79         CUsbHostMsLogicalUnit* lu = iLu[index];
    81         TRAPD(err, lu->UnInitL());
    80         TRAPD(err, lu->UnInitL());
    82         delete lu;
    81         delete lu;
    83         // set return flag for first error condition
    82         // set return flag for first error condition
    84 		if (ret == KErrNone && err != KErrNone)
    83         if (ret == KErrNone && err != KErrNone)
    85 			ret = err;
    84             ret = err;
    86         }
    85         }
    87 
    86 
    88     iLu.Reset();
    87     iLu.Reset();
    89     User::LeaveIfError(ret);
    88     User::LeaveIfError(ret);
    90     }
    89     }
    91 
    90 
    92 TInt TLogicalUnitList::Count() const
    91 TInt TLogicalUnitList::Count() const
    93     {
    92     {
    94     __MSFNSLOG
    93     return iLu.Count();
    95 	return iLu.Count();
    94     }
    96 	}
       
    97 
    95 
    98 TInt TLogicalUnitList::FindLu(TLun aLun) const
    96 TInt TLogicalUnitList::FindLu(TLun aLun) const
    99     {
    97     {
   100     __MSFNSLOG
       
   101 
       
   102     TInt index;
    98     TInt index;
   103     for (index = 0; index < iLu.Count(); index++)
    99     for (index = 0; index < iLu.Count(); index++)
   104         {
   100         {
   105         __HOSTPRINT2(_L("search LUN=%d : interface id = %d"), aLun, iLu[index]->Lun());
   101         OstTraceExt2(TRACE_SHOSTMASSSTORAGE_HOST, TLOGICALUNITLIST_11,
       
   102                      "search LUN=%d : interface id = %d",
       
   103                      (TInt)aLun, (TInt)iLu[index]->Lun());
   106         if (iLu[index]->Lun() == aLun)
   104         if (iLu[index]->Lun() == aLun)
   107             {
   105             {
   108             break;
   106             break;
   109             }
   107             }
   110         }
   108         }
   117     return index; // Instead of KErrNone, we pass the index >= 0 of the aLun in the list
   115     return index; // Instead of KErrNone, we pass the index >= 0 of the aLun in the list
   118     }
   116     }
   119 
   117 
   120 CUsbHostMsLogicalUnit& TLogicalUnitList::GetLuL(TLun aLun) const
   118 CUsbHostMsLogicalUnit& TLogicalUnitList::GetLuL(TLun aLun) const
   121     {
   119     {
   122     __MSFNSLOG
       
   123     TInt index = FindLu(aLun);
   120     TInt index = FindLu(aLun);
   124     User::LeaveIfError(index);
   121     User::LeaveIfError(index);
   125     return *iLu[index];
   122     return *iLu[index];
   126     }
   123     }
   127 
   124 
   128 
   125 
   129 CUsbHostMsLogicalUnit& TLogicalUnitList::GetLu(TInt aIndex) const
   126 CUsbHostMsLogicalUnit& TLogicalUnitList::GetLu(TInt aIndex) const
   130     {
   127     {
   131     __MSFNSLOG
       
   132     return *iLu[aIndex];
   128     return *iLu[aIndex];
   133     }
   129     }