userlibandfileserver/fileserver/shostmassstorage/server/src/cusbhostmssession.cpp
changeset 4 56f325a607ea
parent 0 a41df078684a
child 6 0173bcd7697c
equal deleted inserted replaced
2:4122176ea935 4:56f325a607ea
    17  @file
    17  @file
    18  @internalTechnology
    18  @internalTechnology
    19 */
    19 */
    20 
    20 
    21 #include <e32base.h>
    21 #include <e32base.h>
    22 #include <e32base_private.h>
    22 
    23 #include <e32property.h>
       
    24 #include "msctypes.h"
    23 #include "msctypes.h"
    25 #include "mscutils.h"
       
    26 #include "shared.h"
    24 #include "shared.h"
    27 #include "msgservice.h"
    25 #include "msgservice.h"
    28 #include "cusbhostmslogicalunit.h"
    26 #include "cusbhostmslogicalunit.h"
    29 #include "cusbhostmsdevice.h"
    27 #include "cusbhostmsdevice.h"
    30 #include "cusbhostmsserver.h"
    28 #include "cusbhostmsserver.h"
    57  */
    55  */
    58 CUsbHostMsSession::CUsbHostMsSession(CUsbHostMsServer& aServer)
    56 CUsbHostMsSession::CUsbHostMsSession(CUsbHostMsServer& aServer)
    59 	: iUsbHostMsServer(aServer)
    57 	: iUsbHostMsServer(aServer)
    60 	{
    58 	{
    61     __MSFNLOG
    59     __MSFNLOG
    62 	iMsgCount = 0;
       
    63 	}
    60 	}
    64 
    61 
    65 
    62 
    66 /**
    63 /**
    67  2nd Phase Construction.
    64  2nd Phase Construction.
   119 		break;
   116 		break;
   120 	/* If it is a cleanup then we need to delete the iDeviceThread */
   117 	/* If it is a cleanup then we need to delete the iDeviceThread */
   121 	case EUsbHostMsFinalCleanup:
   118 	case EUsbHostMsFinalCleanup:
   122 		if(iDeviceThread->IsActive())
   119 		if(iDeviceThread->IsActive())
   123 			{
   120 			{
   124 			TRequestStatus* s=&iDeviceThread->iStatus;
   121 			iThread.RequestComplete(iClientStatus, KErrSessionClosed);
   125 			iThread.RequestComplete(s, KErrSessionClosed);
       
   126 			}
   122 			}
   127 		iDeviceThread->Cancel();
   123 	
   128 		delete iDeviceThread;
   124 		delete iDeviceThread;
   129 		iThread.Kill(KErrNone);
   125 		iThread.Kill(KErrNone);
   130 		aMessage.Complete(KErrNone);
   126 		aMessage.Complete(KErrNone);
   131 		return;
   127 		return;
   132 	default:
   128 	default:
   133 		break;
   129 		break;
   134 		}
   130 		}
   135 
   131 
   136 	__HOSTPRINT1(_L("Queuing %d message"), ++iMsgCount);
       
   137 	__ASSERT_DEBUG(iDeviceThread != NULL, User::Panic(KUsbMsHostPanicCat, EDeviceThreadDoesNotExist));
   132 	__ASSERT_DEBUG(iDeviceThread != NULL, User::Panic(KUsbMsHostPanicCat, EDeviceThreadDoesNotExist));
   138 
   133 
   139 	r = iDeviceThread->QueueMsg(aMessage);
   134 	r = iDeviceThread->QueueMsg(aMessage);
   140 	if(r != KErrNone)
   135 	if (r != KErrNone)
   141 		{
   136 		{
   142 		aMessage.Complete(r);
   137 		aMessage.Complete(r);
   143 		return;
   138 		return;
   144 		}
   139 		}
   145 
   140 
   146 	if(iDeviceThread->IsActive())
   141 	if (iClientStatus && *iClientStatus == KRequestPending)
   147 		{
   142 		{
   148 		iDeviceThread->Lock();
       
   149 		if(iDeviceThread->iIsSignalled)
       
   150 			{
       
   151 			iDeviceThread->Unlock();
       
   152 			return;
       
   153 			}
       
   154 		iDeviceThread->iIsSignalled = ETrue;
       
   155 		iDeviceThread->Unlock();
       
   156 		__HOSTPRINT(_L("Signaling device thread to handle message"));
   143 		__HOSTPRINT(_L("Signaling device thread to handle message"));
   157 		TRequestStatus* s=&iDeviceThread->iStatus;
   144 		iThread.RequestComplete(iClientStatus, KErrNone);
   158 		iThread.RequestComplete(s, KErrNone);
       
   159 		}
   145 		}
   160 	}
   146 	}
   161 
   147 
   162 
   148 
   163 void CUsbHostMsSession::CreateDeviceThreadL(const RMessage2& aMessage)
   149 void CUsbHostMsSession::CreateDeviceThreadL(const RMessage2& aMessage)
   164 	{
   150 	{
       
   151     __MSFNLOG
   165 	THostMassStorageConfig msDeviceConfig;
   152 	THostMassStorageConfig msDeviceConfig;
   166 	TPtr8 ptr((TUint8*)&msDeviceConfig,sizeof(THostMassStorageConfig));
   153 	TPtr8 ptr((TUint8*)&msDeviceConfig,sizeof(THostMassStorageConfig));
   167 
   154 
   168 	aMessage.ReadL(0, ptr);
   155 	aMessage.ReadL(0, ptr);
   169 	__HOSTPRINT1(_L("EUsbHostMsRegisterInterface Token=%d "), msDeviceConfig.iInterfaceToken);
   156 	__HOSTPRINT1(_L("EUsbHostMsRegisterInterface Token=%d "), msDeviceConfig.iInterfaceToken);
   170 
   157 
   171 	TInt r = KErrNone;
   158     TBuf<20> nameBuf;
   172     TName nameBuf;
       
   173 	TRequestStatus aStatus;
       
   174 
       
   175 	nameBuf.Format(_L("Host Ms Thread%d"), msDeviceConfig.iInterfaceToken);
   159 	nameBuf.Format(_L("Host Ms Thread%d"), msDeviceConfig.iInterfaceToken);
   176 	iDeviceThread = CUsbHostMsDeviceThread::NewL(msDeviceConfig.iInterfaceToken);
   160 	iDeviceThread = CUsbHostMsDeviceThread::NewL(*this, msDeviceConfig.iInterfaceToken);
   177 
   161 
   178 	RHeap* h = (RHeap*)&User::Allocator();
   162 	RHeap* h = (RHeap*)&User::Allocator();
   179 	TInt maxsize = h->MaxLength();	// loader heap max size = file server heap max size
   163 	TInt maxsize = h->MaxLength();	// loader heap max size = file server heap max size
   180 	const TUint KHeapMinSize = 2048;
   164 	const TUint KHeapMinSize = 2048;
   181 
   165 
   182 	r = iThread.Create(nameBuf, CUsbHostMsDeviceThread::Entry, KDefaultStackSize, KHeapMinSize, maxsize, iDeviceThread);
   166 	TInt r = iThread.Create(nameBuf, CUsbHostMsDeviceThread::Entry, KDefaultStackSize, KHeapMinSize, maxsize, iDeviceThread);
   183 	if(r != KErrNone)
   167 	if(r != KErrNone)
   184 		{
   168 		{
   185 		delete iDeviceThread;
   169 		delete iDeviceThread;
   186         iDeviceThread = NULL;
   170         iDeviceThread = NULL;
   187 		User::Leave(r);
   171 		User::Leave(r);
   188 		}
   172 		}
   189 	iThread.SetPriority(EPriorityAbsoluteBackgroundNormal);
   173 	iThread.SetPriority(EPriorityAbsoluteBackgroundNormal);
   190 	iThread.Rendezvous(aStatus);
   174 	TRequestStatus status;
       
   175 	iThread.Rendezvous(status);
   191 	iThread.Resume();
   176 	iThread.Resume();
   192 	User::WaitForRequest(aStatus);
   177 	User::WaitForRequest(status);
   193 	if(aStatus != KErrNone)
   178 	if(status != KErrNone)
   194 		{
   179 		{
   195 		if(iDeviceThread->IsActive())
   180 		if(iDeviceThread->IsActive())
   196 			{
   181 			{			
   197 			TRequestStatus* s=&iDeviceThread->iStatus;
   182 			iThread.RequestComplete(iClientStatus, KErrSessionClosed);
   198 			iThread.RequestComplete(s, KErrSessionClosed);
       
   199 			}
   183 			}
   200 		iDeviceThread->Cancel();
   184 		iDeviceThread->Cancel();
   201 		delete iDeviceThread;
   185 		delete iDeviceThread;
   202         iDeviceThread = NULL;
   186         iDeviceThread = NULL;
   203 		iThread.Kill(KErrNone);
   187 		iThread.Kill(KErrNone);
   204 		User::Leave(aStatus.Int());
   188 		User::Leave(status.Int());
   205 		}
   189 		}
   206 	}
   190 	}
       
   191 
       
   192 
       
   193 
       
   194 void CUsbHostMsSession::MessageRequest(TRequestStatus& aStatus)
       
   195     {
       
   196     __MSFNLOG
       
   197     iClientStatus = &aStatus;
       
   198     *iClientStatus = KRequestPending;
       
   199     }