userlibandfileserver/fileserver/shostmassstorage/client/rusbhostmslogicalunit.cpp
changeset 9 96e5fb8b040d
child 6 0173bcd7697c
equal deleted inserted replaced
-1:000000000000 9:96e5fb8b040d
       
     1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of the License "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 /**
       
    17  @file
       
    18  @internalTechnology
       
    19 */
       
    20 
       
    21 #include <e32std.h>
       
    22 #include <e32std_private.h>
       
    23 
       
    24 #include "msgservice.h"
       
    25 #include "rusbhostmsdevice.h"
       
    26 #include "rusbhostmslogicalunit.h"
       
    27 #include "debug.h"
       
    28 
       
    29 TVersion RUsbHostMsLogicalUnit::Version() const
       
    30 	{
       
    31 	return(TVersion(KUsbHostMsSrvMajorVersionNumber,
       
    32                     KUsbHostMsSrvMinorVersionNumber,
       
    33                     KUsbHostMsSrvBuildVersionNumber));
       
    34 	}
       
    35 
       
    36 EXPORT_C RUsbHostMsLogicalUnit::RUsbHostMsLogicalUnit()
       
    37 	{
       
    38 	// Intentionally left blank
       
    39 	}
       
    40 
       
    41 /**
       
    42 Send a command to initialise the Mass Storage device.
       
    43 
       
    44 @param aMsg
       
    45 @param aDevHandleIndex
       
    46 @param aLun
       
    47 
       
    48 @return TInt
       
    49 */
       
    50 EXPORT_C TInt RUsbHostMsLogicalUnit::Initialise(const RMessage2& aMsg,
       
    51                                                 TInt aDevHandleIndex,
       
    52 												TUint32 aLun)
       
    53 	{
       
    54 	__FNLOG("RUsbHostMsLogicalUnit::Initialise");
       
    55 	TInt r = dev.Open(aMsg, aDevHandleIndex);
       
    56 	if (r != KErrNone)
       
    57 		{
       
    58 		__PRINT1(_L("Session handle can not be opened %d"),r);
       
    59 		return r;
       
    60 		}
       
    61 
       
    62 	r = CreateSubSession(dev, EUsbHostMsRegisterLun, TIpcArgs(aLun));
       
    63 	if (r != KErrNone)
       
    64 		{
       
    65 		__PRINT1(_L("SubSession creation failed %d"),r);
       
    66 		return r;
       
    67 		}
       
    68 	return r;
       
    69 	}
       
    70 
       
    71 
       
    72 /**
       
    73 Send a command to read the Mass Storage device.
       
    74 
       
    75 @param aPos Position to start reading from
       
    76 @param aLength Number of Bytes
       
    77 @param aTrg Buffer to copy data to
       
    78 
       
    79 @return TInt KErrNone, if the send operation is successful;
       
    80 	KErrServerTerminated, if the server no longer present; KErrServerBusy, if there are no message slots available;
       
    81 	KErrNoMemory, if there is insufficient memory available.
       
    82 */
       
    83 EXPORT_C TInt RUsbHostMsLogicalUnit::Read(TInt64 aPos, TInt aLength, TDes8& aTrg)
       
    84 	{
       
    85 	__FNLOG("RUsbHostMsLogicalUnit::Read");
       
    86 
       
    87 	TReadWrite data;
       
    88 	data.iPos = aPos;
       
    89 	data.iLen = aLength;
       
    90 
       
    91 	__PRINT2(_L("pos = 0x%lx, len = x%x"), data.iPos, data.iLen);
       
    92 
       
    93 	TPckg<TReadWrite> pckg(data);
       
    94 	/* We handle the message asynchronously in the thread modelled MSC */
       
    95 	TRequestStatus	status;
       
    96 	SendReceive(EUsbHostMsRead, TIpcArgs(&pckg, &aTrg), status);
       
    97 	User::WaitForRequest(status);
       
    98     __PRINT2(_L("pos = 0x%lx, len = x%x"), data.iPos, data.iLen);
       
    99 	return status.Int();
       
   100 	}
       
   101 
       
   102 
       
   103 /**
       
   104 Send a command to write to the Mass Storage device.
       
   105 
       
   106 @param aPos Position to start reading from
       
   107 @param aLength Number of Bytes
       
   108 @param aTrg Buffer to copy data from
       
   109 
       
   110 @return TInt KErrNone, if the send operation is successful;
       
   111 	KErrServerTerminated, if the server no longer present; KErrServerBusy, if there are no message slots available;
       
   112 	KErrNoMemory, if there is insufficient memory available.
       
   113 available.
       
   114 */
       
   115 EXPORT_C TInt RUsbHostMsLogicalUnit::Write(TInt64 aPos, TInt aLength, const TDesC8& aTrg)
       
   116 	{
       
   117 	__FNLOG("RUsbHostMsLogicalUnit::Write");
       
   118 
       
   119 	TReadWrite data;
       
   120 	data.iPos = aPos;
       
   121 	data.iLen = aLength;
       
   122 
       
   123 	__PRINT2(_L("pos = 0x%lx, len = x%x"), data.iPos, data.iLen);
       
   124 
       
   125 	TPckg<TReadWrite> pckg(data);
       
   126 	/* We handle the message asynchronously in the thread modelled MSC */
       
   127 	TRequestStatus	status;
       
   128 	SendReceive(EUsbHostMsWrite, TIpcArgs(&aTrg, &pckg), status);
       
   129 	User::WaitForRequest(status);
       
   130 	return status.Int();
       
   131 	}
       
   132 
       
   133 
       
   134 /**
       
   135 Send a command to erase an area of the Mass Storage device.
       
   136 
       
   137 @param aPos Position to start reading from
       
   138 @param aLength Number of Bytes
       
   139 
       
   140 @return TInt KErrNone, if the send operation is successful;
       
   141 	KErrServerTerminated, if the server no longer present; KErrServerBusy, if there are no message slots available;
       
   142 	KErrNoMemory, if there is insufficient memory available.
       
   143 available.
       
   144 */
       
   145 EXPORT_C TInt RUsbHostMsLogicalUnit::Erase(TInt64 aPos, TInt aLength)
       
   146 	{
       
   147 	__FNLOG("RUsbHostMsLogicalUnit::Erase");
       
   148 
       
   149 	TReadWrite data;
       
   150 	data.iPos = aPos;
       
   151 	data.iLen = aLength;
       
   152 
       
   153 	__PRINT2(_L("pos = 0x%lx, len = x%x"), data.iPos, data.iLen);
       
   154 
       
   155 	TPckg<TReadWrite> pckg(data);
       
   156 	/* We handle the message asynchronously in the thread modelled MSC */
       
   157 	TRequestStatus	status;
       
   158 	SendReceive(EUsbHostMsErase, TIpcArgs(&pckg), status);
       
   159 	User::WaitForRequest(status);
       
   160 	return status.Int();
       
   161 	}
       
   162 
       
   163 
       
   164 /**
       
   165 Send a command to get the nedia's capacity info.
       
   166 
       
   167 @param aCapsInfo [OUT] A buffer to copy the capacity info to.
       
   168 
       
   169 @return TInt KErrNone, if the send operation is successful;
       
   170 KErrServerTerminated, if the server no longer present; KErrServerBusy, if there
       
   171 are no message slots available; KErrNoMemory, if there is insufficient memory
       
   172 available.
       
   173 */
       
   174 EXPORT_C TInt RUsbHostMsLogicalUnit::Caps(TCapsInfo& aCapsInfo)
       
   175 	{
       
   176 	__FNLOG("RUsbHostMsLogicalUnit::Caps");
       
   177 
       
   178     TPckg<TCapsInfo> data(aCapsInfo);
       
   179 
       
   180 	/* We handle the message asynchronously in the thread modelled MSC */
       
   181 	TRequestStatus	status;
       
   182 	SendReceive(EUsbHostMsCapacity, TIpcArgs(&data),status);
       
   183 	User::WaitForRequest(status);
       
   184 	return status.Int();
       
   185 	}
       
   186 
       
   187 /**
       
   188 Request notification of media change to the file server
       
   189 
       
   190 @param aChanged The descriptor pointing to iChanged flag in TDrive to be updated
       
   191 when error occurs during read or write.
       
   192 @param aStatus The request status This is set to KErrNone on completion, or KErrCancel when the logical unit is closed;
       
   193 	KErrServerTerminated, if the server no longer present; KErrServerBusy, if there are no message slots available;
       
   194 	KErrNoMemory, if there is insufficient memory available.
       
   195 @return None
       
   196 */
       
   197 EXPORT_C void RUsbHostMsLogicalUnit::NotifyChange(TDes8& aChanged, TRequestStatus &aStatus)
       
   198 	{
       
   199 	__FNLOG("RUsbHostMsLogicalUnit::NotifyChange");
       
   200 
       
   201 	SendReceive(EUsbHostMsNotifyChange, TIpcArgs(&aChanged), aStatus);
       
   202 	}
       
   203 
       
   204 /**
       
   205 Request to suspend the logical unit associated with this drive
       
   206 */
       
   207 EXPORT_C void RUsbHostMsLogicalUnit::SuspendLun()
       
   208 	{
       
   209 	__FNLOG("RUsbHostMsLogicalUnit::SuspendLun");
       
   210 
       
   211 	SendReceive(EUsbHostMsSuspendLun, TIpcArgs(NULL));
       
   212 	}
       
   213 
       
   214 /**
       
   215 Close the sub-session.
       
   216 
       
   217 @return TInt KErrNone
       
   218 */
       
   219 EXPORT_C TInt RUsbHostMsLogicalUnit::UnInitialise()
       
   220 	{
       
   221 	__FNLOG("RUsbHostMsLogicalUnit::UnInitialise");
       
   222 
       
   223 	CloseSubSession(EUsbHostMsUnRegisterLun);
       
   224 	dev.Close();
       
   225 	return KErrNone;
       
   226 	}
       
   227 
       
   228 
       
   229 /**
       
   230 Request that the drive is remounted.
       
   231 
       
   232 @param aFlags Flags to be passed to the drive
       
   233 
       
   234 @return EXPORT_C TInt KErrNone, if the send operation is successful;
       
   235 KErrServerTerminated, if the server no longer present; KErrServerBusy, if there
       
   236 are no message slots available; KErrNoMemory, if there is insufficient memory
       
   237 available.
       
   238 */
       
   239 EXPORT_C TInt RUsbHostMsLogicalUnit::ForceRemount(TUint aFlags)
       
   240 	{
       
   241 	__FNLOG("RUsbHostMsLogicalUnit::ForceRemount");
       
   242 
       
   243 	__PRINT1(_L("flags = %d"), aFlags);
       
   244 
       
   245 	TRequestStatus	status;
       
   246 	SendReceive(EUsbHostMsForceRemount, TIpcArgs(aFlags), status);
       
   247 	User::WaitForRequest(status);
       
   248 	return status.Int();
       
   249 	}
       
   250 
       
   251 EXPORT_C void RUsbHostMsLogicalUnit::NotifyChangeCancel()
       
   252 	{
       
   253 	__FNLOG("RUsbHostMsLogicalUnit::NotifyChangeCancel");
       
   254 	SendReceive(EUsbHostMsCancelChangeNotifier, TIpcArgs(NULL));
       
   255 	}