userlibandfileserver/fileserver/shostmassstorage/server/src/cusbhostmssession.cpp
branchanywhere
changeset 41 d32f34975bbf
parent 33 0173bcd7697c
child 176 af6ec97d9189
equal deleted inserted replaced
40:04a1b74efd48 41:d32f34975bbf
    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.
   116 			aMessage.Complete(r);
   113 			aMessage.Complete(r);
   117 			return;
   114 			return;
   118 			}
   115 			}
   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())
       
   123 			{
       
   124 			TRequestStatus* s=&iDeviceThread->iStatus;
       
   125 			iThread.RequestComplete(s, KErrSessionClosed);
       
   126 			}
       
   127 		iDeviceThread->Cancel();
       
   128 		delete iDeviceThread;
   119 		delete iDeviceThread;
   129 		iThread.Kill(KErrNone);
   120 		iThread.Kill(KErrNone);
   130 		aMessage.Complete(KErrNone);
   121 		aMessage.Complete(KErrNone);
   131 		return;
   122 		return;
   132 	default:
   123 	default:
   133 		break;
   124 		break;
   134 		}
   125 		}
   135 
   126 
   136 	__HOSTPRINT1(_L("Queuing %d message"), ++iMsgCount);
       
   137 	__ASSERT_DEBUG(iDeviceThread != NULL, User::Panic(KUsbMsHostPanicCat, EDeviceThreadDoesNotExist));
   127 	__ASSERT_DEBUG(iDeviceThread != NULL, User::Panic(KUsbMsHostPanicCat, EDeviceThreadDoesNotExist));
   138 
   128 
   139 	r = iDeviceThread->QueueMsg(aMessage);
   129 	r = iDeviceThread->QueueMsg(aMessage);
   140 	if(r != KErrNone)
   130 	if (r != KErrNone)
   141 		{
   131 		{
   142 		aMessage.Complete(r);
   132 		aMessage.Complete(r);
   143 		return;
   133 		return;
   144 		}
   134 		}
   145 
   135 
   146 	if(iDeviceThread->IsActive())
   136 	if (iClientStatus && *iClientStatus == KRequestPending)
   147 		{
   137 		{
   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"));
   138 		__HOSTPRINT(_L("Signaling device thread to handle message"));
   157 		TRequestStatus* s=&iDeviceThread->iStatus;
   139 		iThread.RequestComplete(iClientStatus, KErrNone);
   158 		iThread.RequestComplete(s, KErrNone);
       
   159 		}
   140 		}
   160 	}
   141 	}
   161 
   142 
   162 
   143 
   163 void CUsbHostMsSession::CreateDeviceThreadL(const RMessage2& aMessage)
   144 void CUsbHostMsSession::CreateDeviceThreadL(const RMessage2& aMessage)
   164 	{
   145 	{
       
   146     __MSFNLOG
   165 	THostMassStorageConfig msDeviceConfig;
   147 	THostMassStorageConfig msDeviceConfig;
   166 	TPtr8 ptr((TUint8*)&msDeviceConfig,sizeof(THostMassStorageConfig));
   148 	TPtr8 ptr((TUint8*)&msDeviceConfig,sizeof(THostMassStorageConfig));
   167 
   149 
   168 	aMessage.ReadL(0, ptr);
   150 	aMessage.ReadL(0, ptr);
   169 	__HOSTPRINT1(_L("EUsbHostMsRegisterInterface Token=%d "), msDeviceConfig.iInterfaceToken);
   151 	__HOSTPRINT1(_L("EUsbHostMsRegisterInterface Token=%d "), msDeviceConfig.iInterfaceToken);
   170 
   152 
   171 	TInt r = KErrNone;
   153     TBuf<32> nameBuf;
   172     TName nameBuf;
   154 	nameBuf.Format(_L("Host Ms Thread%8x"), msDeviceConfig.iInterfaceToken);
   173 	TRequestStatus aStatus;
   155 	iDeviceThread = CUsbHostMsDeviceThread::NewL(*this, msDeviceConfig.iInterfaceToken);
   174 
       
   175 	nameBuf.Format(_L("Host Ms Thread%d"), msDeviceConfig.iInterfaceToken);
       
   176 	iDeviceThread = CUsbHostMsDeviceThread::NewL(msDeviceConfig.iInterfaceToken);
       
   177 
   156 
   178 	RHeap* h = (RHeap*)&User::Allocator();
   157 	RHeap* h = (RHeap*)&User::Allocator();
   179 	TInt maxsize = h->MaxLength();	// loader heap max size = file server heap max size
   158 	TInt maxsize = h->MaxLength();	// loader heap max size = file server heap max size
   180 	const TUint KHeapMinSize = 2048;
   159 	const TUint KHeapMinSize = 2048;
   181 
   160 
   182 	r = iThread.Create(nameBuf, CUsbHostMsDeviceThread::Entry, KDefaultStackSize, KHeapMinSize, maxsize, iDeviceThread);
   161 	TInt r = iThread.Create(nameBuf, CUsbHostMsDeviceThread::Entry, KDefaultStackSize, KHeapMinSize, maxsize, iDeviceThread);
   183 	if(r != KErrNone)
   162 	if(r != KErrNone)
   184 		{
   163 		{
   185 		delete iDeviceThread;
   164 		delete iDeviceThread;
   186         iDeviceThread = NULL;
   165         iDeviceThread = NULL;
   187 		User::Leave(r);
   166 		User::Leave(r);
   188 		}
   167 		}
   189 	iThread.SetPriority(EPriorityAbsoluteBackgroundNormal);
   168 	iThread.SetPriority(EPriorityAbsoluteBackgroundNormal);
   190 	iThread.Rendezvous(aStatus);
   169 	TRequestStatus status;
       
   170 	iThread.Rendezvous(status);
   191 	iThread.Resume();
   171 	iThread.Resume();
   192 	User::WaitForRequest(aStatus);
   172 	User::WaitForRequest(status);
   193 	if(aStatus != KErrNone)
   173 	if(status != KErrNone)
   194 		{
   174 		{
   195 		if(iDeviceThread->IsActive())
       
   196 			{
       
   197 			TRequestStatus* s=&iDeviceThread->iStatus;
       
   198 			iThread.RequestComplete(s, KErrSessionClosed);
       
   199 			}
       
   200 		iDeviceThread->Cancel();
       
   201 		delete iDeviceThread;
   175 		delete iDeviceThread;
   202         iDeviceThread = NULL;
   176         iDeviceThread = NULL;
   203 		iThread.Kill(KErrNone);
   177 		iThread.Kill(KErrNone);
   204 		User::Leave(aStatus.Int());
   178 		User::Leave(status.Int());
   205 		}
   179 		}
   206 	}
   180 	}
       
   181 
       
   182 
       
   183 
       
   184 void CUsbHostMsSession::MessageRequest(TRequestStatus& aStatus)
       
   185     {
       
   186     __MSFNLOG
       
   187     iClientStatus = &aStatus;
       
   188     *iClientStatus = KRequestPending;
       
   189     }