kerneltest/f32test/shostmassstorage/testclient/usbtestmsclient/cusbmassstoragesession.cpp
changeset 297 b2826f67641f
parent 0 a41df078684a
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".
    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 
    19 
    20 /**
    20 /**
    31 #include "cusbmassstoragesession.h"
    31 #include "cusbmassstoragesession.h"
    32 #include "cusbmassstoragecontroller.h"
    32 #include "cusbmassstoragecontroller.h"
    33 #include "cusbmassstorageserver.h"
    33 #include "cusbmassstorageserver.h"
    34 
    34 
    35 #include "debug.h"
    35 #include "debug.h"
    36 #include "msdebug.h"
       
    37 
    36 
    38 /**
    37 /**
    39  Construct a Symbian OS session object.
    38  Construct a Symbian OS session object.
    40 
    39 
    41  @param	aServer		Service the session will be a member of
    40  @param aServer     Service the session will be a member of
    42  @param	aMessage	The message from the client.
    41  @param aMessage    The message from the client.
    43  @return	A new CUsbMassStorageSession object
    42  @return    A new CUsbMassStorageSession object
    44  */
    43  */
    45 CUsbMassStorageSession* CUsbMassStorageSession::NewL(CUsbMassStorageServer& aServer)
    44 CUsbMassStorageSession* CUsbMassStorageSession::NewL(CUsbMassStorageServer& aServer)
    46 	{
    45     {
    47     __MSFNSLOG
    46     CUsbMassStorageSession* r = new (ELeave) CUsbMassStorageSession(aServer);
    48 	CUsbMassStorageSession* r = new (ELeave) CUsbMassStorageSession(aServer);
    47     CleanupStack::PushL(r);
    49 	CleanupStack::PushL(r);
    48     r->ConstructL();
    50 	r->ConstructL();
    49     CleanupStack::Pop();
    51 	CleanupStack::Pop();
    50     return r;
    52 	return r;
    51     }
    53 	}
       
    54 
    52 
    55 /**
    53 /**
    56  Constructor.
    54  Constructor.
    57 
    55 
    58  @param	aServer	Service the session will be a member of
    56  @param aServer Service the session will be a member of
    59  */
    57  */
    60 CUsbMassStorageSession::CUsbMassStorageSession(CUsbMassStorageServer& aServer)
    58 CUsbMassStorageSession::CUsbMassStorageSession(CUsbMassStorageServer& aServer)
    61 	: iUsbMsServer(aServer)
    59     : iUsbMsServer(aServer)
    62 	{
    60     {
    63     __MSFNLOG
    61     }
    64 	}
       
    65 
    62 
    66 
    63 
    67 /**
    64 /**
    68  2nd Phase Construction.
    65  2nd Phase Construction.
    69  */
    66  */
    70 void CUsbMassStorageSession::ConstructL()
    67 void CUsbMassStorageSession::ConstructL()
    71 	{
    68     {
    72     __MSFNLOG
    69     iUsbMsServer.IncrementSessionCount();
    73 	iUsbMsServer.IncrementSessionCount();
       
    74     if (iUsbMsServer.SessionCount() > 1)
    70     if (iUsbMsServer.SessionCount() > 1)
    75         {
    71         {
    76         __PRINT1(_L("\tiSessionCount: %d\n"), iUsbMsServer.SessionCount());
    72         __PRINT1(_L("\tiSessionCount: %d\n"), iUsbMsServer.SessionCount());
    77         // Only one session is allowed
    73         // Only one session is allowed
    78         User::Leave(KErrInUse);
    74         User::Leave(KErrInUse);
    79         }
    75         }
    80  	}
    76     }
    81 
    77 
    82 
    78 
    83 /**
    79 /**
    84  Destructor.
    80  Destructor.
    85  */
    81  */
    86 CUsbMassStorageSession::~CUsbMassStorageSession()
    82 CUsbMassStorageSession::~CUsbMassStorageSession()
    87 	{
    83     {
    88     __MSFNLOG
    84     iUsbMsServer.DecrementSessionCount();
    89 	iUsbMsServer.DecrementSessionCount();
    85     }
    90 	}
       
    91 
    86 
    92 /**
    87 /**
    93  Called when a message is received from the client.
    88  Called when a message is received from the client.
    94 
    89 
    95  @param	aMessage	Message received from the client
    90  @param aMessage    Message received from the client
    96  */
    91  */
    97 void CUsbMassStorageSession::ServiceL(const RMessage2& aMessage)
    92 void CUsbMassStorageSession::ServiceL(const RMessage2& aMessage)
    98 	{
    93     {
    99     __MSFNLOG
    94     DispatchMessageL(aMessage);
   100 	DispatchMessageL(aMessage);
    95     }
   101 	}
       
   102 
    96 
   103 /**
    97 /**
   104  Handles the request (in the form of a the message) received from the client
    98  Handles the request (in the form of a the message) received from the client
   105 
    99 
   106  @internalTechnology
   100  @internalTechnology
   107  @param	aMessage	The received message
   101  @param aMessage    The received message
   108  */
   102  */
   109 void CUsbMassStorageSession::DispatchMessageL(const RMessage2& aMessage)
   103 void CUsbMassStorageSession::DispatchMessageL(const RMessage2& aMessage)
   110 	{
   104     {
   111     __MSFNLOG
   105     TInt ret = KErrNone;
   112 	TInt ret = KErrNone;
       
   113 
   106 
   114 	switch (aMessage.Function())
   107     switch (aMessage.Function())
   115 		{
   108         {
   116 	case EUsbMsStart:
   109     case EUsbMsStart:
   117 		ret = Start(aMessage);
   110         ret = Start(aMessage);
   118 		break;
   111         break;
   119 	case EUsbMsStop:
   112     case EUsbMsStop:
   120 		ret = Stop();
   113         ret = Stop();
   121 		break;
   114         break;
   122 	case EUsbMsShutdown:
   115     case EUsbMsShutdown:
   123 		ret = Shutdown();
   116         ret = Shutdown();
   124 		break;
   117         break;
   125 
   118 
   126 	default:
   119     default:
   127 		aMessage.Panic(KUsbMsCliPncCat, EUsbMsPanicIllegalIPC);
   120         aMessage.Panic(KUsbMsCliPncCat, EUsbMsPanicIllegalIPC);
   128 		break;
   121         break;
   129 		}
   122         }
   130 
   123 
   131 	aMessage.Complete(ret);
   124     aMessage.Complete(ret);
   132 	}
   125     }
   133 
   126 
   134 /**
   127 /**
   135  Client request to start the device.
   128  Client request to start the device.
   136 
   129 
   137  @return	Any error that occurred or KErrNone
   130  @return    Any error that occurred or KErrNone
   138  */
   131  */
   139 TInt CUsbMassStorageSession::Start(const RMessage2& aMessage)
   132 TInt CUsbMassStorageSession::Start(const RMessage2& aMessage)
   140 	{
   133     {
   141     __MSFNLOG
   134     __PRINT(_L("CUsbMassStorageSession::Start\n"));
   142 	__PRINT(_L("CUsbMassStorageSession::Start\n"));
       
   143 
   135 
   144 	TMassStorageConfig msConfig;
   136     TMassStorageConfig msConfig;
   145 	TRAPD(err, GetMsConfigL(aMessage, msConfig));
   137     TRAPD(err, GetMsConfigL(aMessage, msConfig));
   146 	if (err != KErrNone)
   138     if (err != KErrNone)
   147 		{
   139         {
   148 		__PRINT(_L("Failed to get mass storage configuration data\n"));
   140         __PRINT(_L("Failed to get mass storage configuration data\n"));
   149 		return err;
   141         return err;
   150 		}
   142         }
   151 
   143 
   152 	return iUsbMsServer.Controller().Start(msConfig);
   144     return iUsbMsServer.Controller().Start(msConfig);
   153 	}
   145     }
   154 
   146 
   155 /**
   147 /**
   156  Client request to stop the device.
   148  Client request to stop the device.
   157 
   149 
   158  @return	Any error that occurred or KErrNone
   150  @return    Any error that occurred or KErrNone
   159  */
   151  */
   160 TInt CUsbMassStorageSession::Stop()
   152 TInt CUsbMassStorageSession::Stop()
   161     {
   153     {
   162     __MSFNLOG
       
   163     TInt err = iUsbMsServer.Controller().Stop();
   154     TInt err = iUsbMsServer.Controller().Stop();
   164 	return err;
   155     return err;
   165 	}
   156     }
   166 
   157 
   167 /**
   158 /**
   168  Client request to shut down the server
   159  Client request to shut down the server
   169 
   160 
   170  @return KErrNone
   161  @return KErrNone
   171  */
   162  */
   172 TInt CUsbMassStorageSession::Shutdown()
   163 TInt CUsbMassStorageSession::Shutdown()
   173     {
   164     {
   174     __MSFNLOG
       
   175     CActiveScheduler::Stop();
   165     CActiveScheduler::Stop();
   176 	return KErrNone;
   166     return KErrNone;
   177 	}
   167     }
   178 
   168 
   179  /**
   169  /**
   180   Get mass storage configuration data from the received message
   170   Get mass storage configuration data from the received message
   181   */
   171   */
   182  void CUsbMassStorageSession::GetMsConfigL(const RMessage2& aMessage, TMassStorageConfig& aMsStorage)
   172  void CUsbMassStorageSession::GetMsConfigL(const RMessage2& aMessage, TMassStorageConfig& aMsStorage)
   183  	{
   173     {
   184     __MSFNLOG
   174     aMessage.ReadL(0,aMsStorage.iVendorId);
   185  	aMessage.ReadL(0,aMsStorage.iVendorId);
   175     aMessage.ReadL(1,aMsStorage.iProductId);
   186  	aMessage.ReadL(1,aMsStorage.iProductId);
   176     aMessage.ReadL(2,aMsStorage.iProductRev);
   187  	aMessage.ReadL(2,aMsStorage.iProductRev);
   177     }
   188  	}