userlibandfileserver/fileserver/smassstorage/cusbmassstoragesession.cpp
changeset 286 48e57fb1237e
parent 0 a41df078684a
equal deleted inserted replaced
285:ff5437e4337c 286:48e57fb1237e
     1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2004-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".
    10 //
    10 //
    11 // Contributors:
    11 // Contributors:
    12 //
    12 //
    13 // Description:
    13 // Description:
    14 // Implements a Session of a Symbian OS server for the RUsbMassStorage API
    14 // Implements a Session of a Symbian OS server for the RUsbMassStorage API
    15 // 
    15 //
    16 //
    16 //
    17 
    17 
    18 /**
    18 /**
    19  @file
    19  @file
    20  @internalTechnology
    20  @internalTechnology
    21 */
    21 */
    22 
    22 
    23 #include "cusbmassstoragesession.h"
    23 #include <e32std.h>
       
    24 #include <e32base.h>
       
    25 #include "usbmsshared.h"
       
    26 
       
    27 #include "drivemanager.h"
    24 #include "cusbmassstoragecontroller.h"
    28 #include "cusbmassstoragecontroller.h"
    25 #include "cusbmassstorageserver.h"
    29 #include "cusbmassstorageserver.h"
    26 #include "usbmsshared.h"
    30 #include "cusbmassstoragesession.h"
       
    31 
       
    32 #include "OstTraceDefinitions.h"
       
    33 #ifdef OST_TRACE_COMPILER_IN_USE
       
    34 #include "cusbmassstoragesessionTraces.h"
       
    35 #endif
       
    36 
    27 
    37 
    28 /**
    38 /**
    29  Construct a Symbian OS session object.
    39  Construct a Symbian OS session object.
    30  
    40 
    31  @param	aServer		Service the session will be a member of
    41  @param aServer     Service the session will be a member of
    32  @param	aMessage	The message from the client.
    42  @param aMessage    The message from the client.
    33  @return	A new CUsbMassStorageSession object
    43  @return    A new CUsbMassStorageSession object
    34  */
    44  */
    35 CUsbMassStorageSession* CUsbMassStorageSession::NewL(CUsbMassStorageServer& aServer)
    45 CUsbMassStorageSession* CUsbMassStorageSession::NewL(CUsbMassStorageServer& aServer)
    36 	{
    46     {
    37 	CUsbMassStorageSession* r = new (ELeave) CUsbMassStorageSession(aServer);
    47     CUsbMassStorageSession* r = new (ELeave) CUsbMassStorageSession(aServer);
    38 	CleanupStack::PushL(r);
    48     CleanupStack::PushL(r);
    39 	r->ConstructL();
    49     r->ConstructL();
    40 	CleanupStack::Pop();
    50     CleanupStack::Pop();
    41 	return r;
    51     return r;
    42 	}
    52     }
    43 
    53 
    44 /**
    54 /**
    45  Constructor.
    55  Constructor.
    46  
    56 
    47  @param	aServer	Service the session will be a member of
    57  @param aServer Service the session will be a member of
    48  */
    58  */
    49 CUsbMassStorageSession::CUsbMassStorageSession(CUsbMassStorageServer& aServer)
    59 CUsbMassStorageSession::CUsbMassStorageSession(CUsbMassStorageServer& aServer)
    50 	: iUsbMsServer(aServer)
    60     : iUsbMsServer(aServer)
    51 	{
    61     {
    52     __PRINT(_L("CUsbMassStorageSession::CUsbMassStorageSession\n"));
    62     OstTraceFunctionEntry0(CUSBMASSSTORAGESESSION_100);
    53 	}
    63     }
    54 
    64 
    55 
    65 
    56 /**
    66 /**
    57  2nd Phase Construction.
    67  2nd Phase Construction.
    58  */
    68  */
    59 void CUsbMassStorageSession::ConstructL()
    69 void CUsbMassStorageSession::ConstructL()
    60 	{
    70     {
    61 	iUsbMsServer.IncrementSessionCount();
    71     iUsbMsServer.IncrementSessionCount();
    62     if (iUsbMsServer.SessionCount() > 1)
    72     if (iUsbMsServer.SessionCount() > 1)
    63         {
    73         {
    64         __PRINT1(_L("\tiSessionCount: %d\n"), iUsbMsServer.SessionCount());
    74         OstTrace1(TRACE_SMASSSTORAGE_FS, CUSBMASSSTORAGESESSION_101,
       
    75                   "iSessionCount: %d", iUsbMsServer.SessionCount());
    65         // Only one session is allowed
    76         // Only one session is allowed
    66         User::Leave(KErrInUse);
    77         User::Leave(KErrInUse);
    67         }        
    78         }
    68  	}
    79     }
    69 
    80 
    70 
    81 
    71 /**
    82 /**
    72  Destructor.
    83  Destructor.
    73  */
    84  */
    74 CUsbMassStorageSession::~CUsbMassStorageSession()
    85 CUsbMassStorageSession::~CUsbMassStorageSession()
    75 	{
    86     {
    76 	iUsbMsServer.DecrementSessionCount();
    87     iUsbMsServer.DecrementSessionCount();
    77 	}
    88     }
    78 
    89 
    79 /**
    90 /**
    80  Called when a message is received from the client.
    91  Called when a message is received from the client.
    81  
    92 
    82  @param	aMessage	Message received from the client
    93  @param aMessage    Message received from the client
    83  */
    94  */
    84 void CUsbMassStorageSession::ServiceL(const RMessage2& aMessage)
    95 void CUsbMassStorageSession::ServiceL(const RMessage2& aMessage)
    85 	{
    96     {
    86 	DispatchMessageL(aMessage);
    97     DispatchMessageL(aMessage);
    87 	}
    98     }
    88 
    99 
    89 /**
   100 /**
    90  Handles the request (in the form of a the message) received from the client
   101  Handles the request (in the form of a the message) received from the client
    91  
   102 
    92  @internalTechnology
   103  @internalTechnology
    93  @param	aMessage	The received message
   104  @param aMessage    The received message
    94  */
   105  */
    95 void CUsbMassStorageSession::DispatchMessageL(const RMessage2& aMessage)
   106 void CUsbMassStorageSession::DispatchMessageL(const RMessage2& aMessage)
    96 	{
   107     {
    97 	TInt ret = KErrNone;
   108     TInt ret = KErrNone;
    98 	
       
    99 	switch (aMessage.Function())
       
   100 		{
       
   101 	case EUsbMsStart:
       
   102 		ret = Start(aMessage);
       
   103 		break;
       
   104 	case EUsbMsStop:
       
   105 		ret = Stop();
       
   106 		break;
       
   107 	case EUsbMsShutdown:
       
   108 		ret = Shutdown();
       
   109 		break;
       
   110 
   109 
   111 	default:
   110     switch (aMessage.Function())
   112 		aMessage.Panic(KUsbMsCliPncCat, EUsbMsPanicIllegalIPC);
   111         {
   113 		break;
   112     case EUsbMsStart:
   114 		}
   113         ret = Start(aMessage);
       
   114         break;
       
   115     case EUsbMsStop:
       
   116         ret = Stop();
       
   117         break;
       
   118     case EUsbMsShutdown:
       
   119         ret = Shutdown();
       
   120         break;
   115 
   121 
   116 	aMessage.Complete(ret);
   122     default:
   117 	}
   123         aMessage.Panic(KUsbMsCliPncCat, EUsbMsPanicIllegalIPC);
       
   124         break;
       
   125         }
       
   126 
       
   127     aMessage.Complete(ret);
       
   128     }
   118 
   129 
   119 /**
   130 /**
   120  Client request to start the device.
   131  Client request to start the device.
   121  
   132 
   122  @return	Any error that occurred or KErrNone
   133  @return    Any error that occurred or KErrNone
   123  */
   134  */
   124 TInt CUsbMassStorageSession::Start(const RMessage2& aMessage)
   135 TInt CUsbMassStorageSession::Start(const RMessage2& aMessage)
   125 	{
   136     {
   126 	__PRINT(_L("CUsbMassStorageSession::Start\n"));
   137     OstTraceFunctionEntry0(CUSBMASSSTORAGESESSION_103);
       
   138     TMassStorageConfig msConfig;
       
   139     TRAPD(err, GetMsConfigL(aMessage, msConfig));
       
   140     if (err != KErrNone)
       
   141         {
       
   142         OstTrace1(TRACE_SMASSSTORAGE_FS, CUSBMASSSTORAGESESSION_111,
       
   143                   "Failed to get mass storage configuration data err=%d", err);
       
   144         return err;
       
   145         }
   127 
   146 
   128 	TMassStorageConfig msConfig;
   147     return iUsbMsServer.Controller().Start(msConfig);
   129 	TRAPD(err, GetMsConfigL(aMessage, msConfig));
   148     }
   130 	if (err != KErrNone)
       
   131 		{
       
   132 		__PRINT(_L("Failed to get mass storage configuration data\n"));
       
   133 		return err;
       
   134 		}
       
   135 		
       
   136 	return iUsbMsServer.Controller().Start(msConfig);
       
   137 	}
       
   138 
   149 
   139 /**
   150 /**
   140  Client request to stop the device.
   151  Client request to stop the device.
   141  
   152 
   142  @return	Any error that occurred or KErrNone
   153  @return    Any error that occurred or KErrNone
   143  */
   154  */
   144 TInt CUsbMassStorageSession::Stop()
   155 TInt CUsbMassStorageSession::Stop()
   145     {
   156     {
   146     __PRINT(_L("CUsbMassStorageSession::Stop\n"));
   157     OstTraceFunctionEntry0(CUSBMASSSTORAGESESSION_104);
   147     TInt err = iUsbMsServer.Controller().Stop();
   158     TInt err = iUsbMsServer.Controller().Stop();
   148 	return err;
   159     return err;
   149 	}
   160     }
   150 
   161 
   151 /**
   162 /**
   152  Client request to shut down the server
   163  Client request to shut down the server
   153  
   164 
   154  @return KErrNone
   165  @return KErrNone
   155  */
   166  */
   156 TInt CUsbMassStorageSession::Shutdown()
   167 TInt CUsbMassStorageSession::Shutdown()
   157     {
   168     {
   158     __PRINT(_L("CUsbMassStorageSession::Shutdown\n"));
   169     OstTraceFunctionEntry0(CUSBMASSSTORAGESESSION_105);
   159     CActiveScheduler::Stop();
   170     CActiveScheduler::Stop();
   160 	return KErrNone;
   171     return KErrNone;
   161 	}
   172     }
   162 
   173 
   163  /**
   174  /**
   164   Get mass storage configuration data from the received message
   175   Get mass storage configuration data from the received message
   165   */
   176   */
   166  void CUsbMassStorageSession::GetMsConfigL(const RMessage2& aMessage, TMassStorageConfig& aMsStorage)
   177  void CUsbMassStorageSession::GetMsConfigL(const RMessage2& aMessage, TMassStorageConfig& aMsStorage)
   167  	{
   178     {
   168  	aMessage.ReadL(0,aMsStorage.iVendorId);
   179     aMessage.ReadL(0,aMsStorage.iVendorId);
   169  	aMessage.ReadL(1,aMsStorage.iProductId);
   180     aMessage.ReadL(1,aMsStorage.iProductId);
   170  	aMessage.ReadL(2,aMsStorage.iProductRev);
   181     aMessage.ReadL(2,aMsStorage.iProductRev);
   171  	}
   182     }