baseport/syborg/webcamera/webcamera_ldd.cpp
changeset 124 606eafc6d6a8
parent 52 0dfaca43d90e
equal deleted inserted replaced
52:0dfaca43d90e 124:606eafc6d6a8
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 #include <kern_priv.h>
    18 #include <kern_priv.h>
    19 #include "webcamera_ldd.h"
    19 #include "webcamera_ldd.h"
    20 #include <webcamera_driver.h>
       
    21 
    20 
    22 #define DP(format...) Kern::Printf(format)
    21 #define DP(format...) Kern::Printf(format)
    23 
    22 
    24 _LIT(KDriver1PanicCategory,"WebcameraDevice");
    23 _LIT(KDriver1PanicCategory,"WebcameraDevice");
    25 
    24 
    26 /**
    25 /**
    27  *Create Logic device.
    26 Create Logic device.
    28  *
       
    29  */
    27  */
    30 DECLARE_STANDARD_LDD()
    28 DECLARE_STANDARD_LDD()
    31 	{
    29 	{
    32     DP("DECLARE_STANDARD_LDD()");
    30 	DP("DECLARE_STANDARD_LDD()");
    33     return new DWebcameraLogicalDevice;
    31 	return new DWebcameraLogicalDevice;
    34 	}
    32 	}
    35 
    33 
    36 /**
    34 /**
    37   Constructor
    35 Constructor
    38 */
    36 */
    39 DWebcameraLogicalDevice::DWebcameraLogicalDevice()
    37 DWebcameraLogicalDevice::DWebcameraLogicalDevice()
    40 	{
    38 	{
    41 	DP("DWebcameraLogicalDevice()");
    39 	DP("DWebcameraLogicalDevice()");
    42     // Set version number for this device
    40 	// Set version number for this device
    43     iVersion=RWebcameraDevice::VersionRequired();
    41 	iVersion = RWebcameraDevice::VersionRequired();
    44     // Indicate that we work with a PDD
    42 	// Indicate that we work with a PDD
    45     iParseMask=KDeviceAllowPhysicalDevice;
    43 	iParseMask = KDeviceAllowPhysicalDevice;
    46 	}
    44 	}
    47 
    45 
    48 /**
    46 /**
    49   Destructor
    47 Destructor
    50 */
    48 */
    51 DWebcameraLogicalDevice::~DWebcameraLogicalDevice()
    49 DWebcameraLogicalDevice::~DWebcameraLogicalDevice()
    52 	{
    50 	{
    53 	}
    51 	}
    54 
    52 
    55 /**
    53 /**
    56   Second stage constructor for DDriver1Factory.
    54 Second stage constructor for DDriver1Factory.
    57   This must at least set a name for the driver object.
    55 This must at least set a name for the driver object.
    58 
    56 
    59   @return KErrNone if successful, otherwise one of the other system wide error codes.
    57 @return KErrNone if successful, otherwise one of the other system wide error codes.
    60 */
    58 */
    61 TInt DWebcameraLogicalDevice::Install()
    59 TInt DWebcameraLogicalDevice::Install()
    62 	{
    60 	{
    63 	DP("DWebcameraLogicalDevice::Install()");
    61 	DP("DWebcameraLogicalDevice::Install()");
    64 
    62 
    65 	return SetName(&RWebcameraDevice::Name());
    63 	return SetName(&RWebcameraDevice::Name());
    66 	}
    64 	}
    67 
    65 
    68 /**
    66 /**
    69   Return the drivers capabilities.
    67 Return the drivers capabilities.
    70   Called in the response to an RDevice::GetCaps() request.
    68 Called in the response to an RDevice::GetCaps() request.
    71 
    69 
    72   @param aDes User-side descriptor to write capabilities information into
    70 @param aDes User-side descriptor to write capabilities information into
    73 */
    71 */
    74 void DWebcameraLogicalDevice::GetCaps(TDes8& aDes) const
    72 void DWebcameraLogicalDevice::GetCaps(TDes8& aDes) const
    75 	{
    73 	{
    76     // Create a capabilities object
    74 	// Create a capabilities object
    77 	RWebcameraDevice::TCaps caps;
    75 	RWebcameraDevice::TCaps caps;
    78     caps.iVersion = iVersion;
    76 	caps.iVersion = iVersion;
    79     // Write it back to user memory
    77 	// Write it back to user memory
    80     Kern::InfoCopy(aDes,(TUint8*)&caps,sizeof(caps));
    78 	Kern::InfoCopy(aDes, (TUint8*)&caps, sizeof(caps));
    81 	}
    79 	}
    82 
    80 
    83 /**
    81 /**
    84   Called by the kernel's device driver framework to create a Logical Channel.
    82 Called by the kernel's device driver framework to create a Logical Channel.
    85   This is called in the context of the user thread (client) which requested the creation of a Logical Channel
    83 This is called in the context of the user thread (client) which requested the creation of a Logical Channel
    86   (E.g. through a call to RBusLogicalChannel::DoCreate)
    84 (E.g. through a call to RBusLogicalChannel::DoCreate)
    87   The thread is in a critical section.
    85 The thread is in a critical section.
    88 
    86 
    89   @param aChannel Set to point to the created Logical Channel
    87 @param aChannel Set to point to the created Logical Channel
    90 
    88 @return KErrNone if successful, otherwise one of the other system wide error codes.
    91   @return KErrNone if successful, otherwise one of the other system wide error codes.
       
    92 */
    89 */
    93 TInt DWebcameraLogicalDevice::Create(DLogicalChannelBase*& aChannel)
    90 TInt DWebcameraLogicalDevice::Create(DLogicalChannelBase*& aChannel)
    94 	{
    91 	{
    95 	DP("DWebcameraLogicalDevice::Create() start");
    92 	DP("DWebcameraLogicalDevice::Create() start");
    96 	aChannel = new DWebcameraLogicalChannel;
    93 	aChannel = new DWebcameraLogicalChannel;
    97 	if(!aChannel)
    94 	if (!aChannel)
       
    95 		{
    98 		return KErrNoMemory;
    96 		return KErrNoMemory;
       
    97 		}
       
    98 	DP("DWebcameraLogicalDevice::Create() end");
    99 	return KErrNone;
    99 	return KErrNone;
   100 	DP("DWebcameraLogicalDevice::Create() end");
   100 	}
   101 	}
   101 
   102 
   102 /**
   103 /**
   103 Constructor
   104   Constructor
       
   105 */
   104 */
   106 DWebcameraLogicalChannel::DWebcameraLogicalChannel()
   105 DWebcameraLogicalChannel::DWebcameraLogicalChannel()
   107 	: iReceiveDataDfc(GetOneFlameDfc, this, 1)
   106 	: iReceiveDataDfc(GetFlameDfc, this, 1)
   108 	  ,iCaptureDfc(CaptureDfc,this,1)
   107 	, iCaptureDfc(CaptureDfc, this, 1)
   109 	{
   108 	{
   110 	DP("DWebcameraLogicalChannel::DWebcameraLogicalChannel() start");
   109 	DP("DWebcameraLogicalChannel::DWebcameraLogicalChannel() start");
   111 
   110 
   112     // Get pointer to client threads DThread object
   111 	// Get pointer to client threads DThread object
   113 	iClient=&Kern::CurrentThread();
   112 	iClient = &Kern::CurrentThread();
   114     // Open a reference on client thread so it's control block can't dissapear until
   113 	// Open a reference on client thread so it's control block can't dissapear until
   115     // this driver has finished with it.
   114 	// this driver has finished with it.
   116 	((DObject*)iClient)->Open();
   115 	((DObject*)iClient)->Open();
   117 	
   116 	iWebCameraState = RWebcameraDevice::EPowerOff;
       
   117 
   118 	DP("DWebcameraLogicalChannel::DWebcameraLogicalChannel() end");
   118 	DP("DWebcameraLogicalChannel::DWebcameraLogicalChannel() end");
   119 	}
   119 	}
   120 
   120 
   121 /**
   121 /**
   122   Destructor
   122 Destructor
   123 */
   123 */
   124 DWebcameraLogicalChannel::~DWebcameraLogicalChannel()
   124 DWebcameraLogicalChannel::~DWebcameraLogicalChannel()
   125 	{
   125 	{
   126 	DP("DWebcameraLogicalChannel::~DWebcameraLogicalChannel() start");
   126 	DP("DWebcameraLogicalChannel::~DWebcameraLogicalChannel() start");
   127     // Cancel all processing that we may be doing
   127 	// Cancel all processing that we may be doing
   128 	DoCancel(RWebcameraDevice::EAllRequests);	
   128 	DoCancel(RWebcameraDevice::EAllRequests);
   129 	if (iComm)
   129 	// Close sharedchunks
   130 		{
   130 	CloseSharedChunks();
   131 		delete iComm;
   131 	// Close our reference on the client thread
   132 		}
   132 	Kern::SafeClose((DObject*&)iClient, NULL);
   133     if (iChunk)
   133 
   134         {
   134 	delete iConvert;
   135         Epoc::FreePhysicalRam(iPhysAddr, iSize);
   135 
   136         }
   136 	// Buffer Free.
   137     // Close our reference on the client thread
   137 	Kern::Free(iHeaderPtr);
   138 	Kern::SafeClose((DObject*&)iClient,NULL);
   138 	Kern::Free(iDataPtr);
       
   139 	Kern::Free(iBmpBuf);
   139 	DP("DWebcameraLogicalChannel::~DWebcameraLogicalChannel() end");
   140 	DP("DWebcameraLogicalChannel::~DWebcameraLogicalChannel() end");
   140 	}
   141 	}
   141 
   142 
   142 /**
   143 /**
   143   Called when a user thread requests a handle to this channel.
   144 Called when a user thread requests a handle to this channel.
   144 */
   145 */
   145 TInt DWebcameraLogicalChannel::RequestUserHandle(DThread* aThread, TOwnerType aType)
   146 TInt DWebcameraLogicalChannel::RequestUserHandle(DThread* aThread, TOwnerType aType)
   146     {
   147 	{
   147     // Make sure that only our client can get a handle
   148 	// Make sure that only our client can get a handle
   148     if (aType!=EOwnerThread || aThread!=iClient)
   149 	if (aType != EOwnerThread || aThread != iClient)
   149         return KErrAccessDenied;
   150 		{
   150     return KErrNone;
   151 		return KErrAccessDenied;
   151     }
   152 		}
   152 
   153 	return KErrNone;
   153 /**
   154 	}
   154   Second stage constructor called by the kernel's device driver framework.
   155 
   155   This is called in the context of the user thread (client) which requested the creation of a Logical Channel
   156 /**
   156   (E.g. through a call to RBusLogicalChannel::DoCreate)
   157 Second stage constructor called by the kernel's device driver framework.
   157   The thread is in a critical section.
   158 This is called in the context of the user thread (client) which requested the creation of a Logical Channel
   158 
   159 (E.g. through a call to RBusLogicalChannel::DoCreate)
   159   @param aUnit The unit argument supplied by the client
   160 The thread is in a critical section.
   160   @param aInfo The info argument supplied by the client
   161 
   161   @param aVer The version argument supplied by the client
   162 @param aUnit The unit argument supplied by the client
   162 
   163 @param aInfo The info argument supplied by the client
   163   @return KErrNone if successful, otherwise one of the other system wide error codes.
   164 @param aVer The version argument supplied by the client
       
   165 
       
   166 @return KErrNone if successful, otherwise one of the other system wide error codes.
   164 */
   167 */
   165 TInt DWebcameraLogicalChannel::DoCreate(TInt /*aUnit*/, const TDesC8* /*aInfo*/, const TVersion& aVer)
   168 TInt DWebcameraLogicalChannel::DoCreate(TInt /*aUnit*/, const TDesC8* /*aInfo*/, const TVersion& aVer)
   166 	{
   169 	{
   167 	DP("DWebcameraLogicalChannel::DoCreate() start");
   170 	DP("DWebcameraLogicalChannel::DoCreate() start");
   168     if(!Kern::CurrentThreadHasCapability(ECapability_None,__PLATSEC_DIAGNOSTIC_STRING("Checked by Webcamera")))
   171 	if (!Kern::CurrentThreadHasCapability(ECapability_None, __PLATSEC_DIAGNOSTIC_STRING("Checked by Webcamera")))
   169     	{
   172 		{
   170         return KErrPermissionDenied;
   173 		return KErrPermissionDenied;
   171     	}
   174 		}
   172     // Check version
   175 	// Check version
   173 	if (!Kern::QueryVersionSupported(RWebcameraDevice::VersionRequired(),aVer))
   176 	if (!Kern::QueryVersionSupported(RWebcameraDevice::VersionRequired(), aVer))
   174 		{
   177 		{
   175 		return KErrNotSupported;
   178 		return KErrNotSupported;
   176 		}
   179 		}
   177     // Setup LDD for receiving client messages
   180 	// Setup LDD for receiving client messages
   178 	SetDfcQ(Kern::DfcQue0());
   181 	SetDfcQ(Kern::DfcQue0());
   179 	iMsgQ.Receive();
   182 	iMsgQ.Receive();
   180     // Associate DFCs with the same queue we set above to receive client messages on
   183 	//Associate DFCs with the same queue we set above to receive client messages on
   181 	iReceiveDataDfc.SetDfcQ(iDfcQ);
   184 	iReceiveDataDfc.SetDfcQ(iDfcQ);
   182 	iCaptureDfc.SetDfcQ(iDfcQ);
   185 	iCaptureDfc.SetDfcQ(iDfcQ);
   183     // Give PDD a pointer to this channel
   186 	//Give PDD a pointer to this channel
   184 	Pdd()->iLdd=this;
   187 	Pdd()->iLdd = this;	
   185 
   188 	// Create shared chunk.
   186 	//allocate Memory
   189 	TInt rtn = CreatSharedChunks();
   187 	iSize=Kern::RoundToPageSize(BUFSIZE);
   190 	if (rtn)
   188 	TInt rtn=Epoc::AllocPhysicalRam(iSize, iPhysAddr);
       
   189 	if (rtn != KErrNone)
       
   190 		{
   191 		{
   191 		return rtn;
   192 		return rtn;
   192 		}
   193 		}
   193 	rtn=DPlatChunkHw::New(iChunk, iPhysAddr, iSize,EMapAttrUserRw|EMapAttrBufferedC);
       
   194 	if (rtn != KErrNone)
       
   195 		{
       
   196 		if (iPhysAddr)
       
   197 			{
       
   198 			Epoc::FreePhysicalRam(iPhysAddr, iSize);
       
   199 			}
       
   200 		return rtn;
       
   201 		}
       
   202 	iLAdr = reinterpret_cast<TUint8*>(iChunk->LinearAddress());
       
   203 	
       
   204 	iComm=HBuf8::New(BUFSIZE);
       
   205 	if (!iComm)
       
   206 		{
       
   207 		return KErrNotSupported;
       
   208 		}
       
   209 	iReceiveDataBuffer=iComm;
       
   210 	iCaptureBuffer=iComm;
       
   211 
   194 
   212 	DP("DWebcameraLogicalChannel::DoCreate() end");
   195 	DP("DWebcameraLogicalChannel::DoCreate() end");
   213 	return KErrNone;
   196 	return KErrNone;
   214 	}
   197 	}
   215 
   198 
   216 /**
   199 /**
   217   Process a message for this logical channel.
   200 Process a message for this logical channel.
   218   This function is called in the context of a DFC thread.
   201 This function is called in the context of a DFC thread.
   219 
   202 
   220   @param aMessage The message to process.
   203 @param aMessage	The message to process.
   221                   The iValue member of this distinguishes the message type:
   204 				The iValue member of this distinguishes the message type:
   222                   iValue==ECloseMsg, channel close message
   205 				iValue==ECloseMsg, channel close message
   223                   iValue==KMaxTInt, a 'DoCancel' message
   206 				iValue==KMaxTInt, a 'DoCancel' message
   224                   iValue>=0, a 'DoControl' message with function number equal to iValue
   207 				iValue>=0, a 'DoControl' message with function number equal to iValue
   225                   iValue<0, a 'DoRequest' message with function number equal to ~iValue
   208 				iValue<0, a 'DoRequest' message with function number equal to ~iValue
   226 */
   209 */
   227 void DWebcameraLogicalChannel::HandleMsg(TMessageBase* aMsg)
   210 void DWebcameraLogicalChannel::HandleMsg(TMessageBase* aMsg)
   228 	{
   211 	{
   229 	DP("DWebcameraLogicalChannel::HandleMsg() start");
   212 	DP("DWebcameraLogicalChannel::HandleMsg() start");
   230 	TThreadMessage& m=*(TThreadMessage*)aMsg;
   213 	TThreadMessage& m = *(TThreadMessage*)aMsg;
   231 
   214 
   232     // Get message type
   215 	// Get message type
   233 	TInt id=m.iValue;
   216 	TInt id = m.iValue;
   234     DP("id=%d",id);
   217 	DP("id=%d",id);
   235     
   218 
   236     // Decode the message type and dispatch it to the relevent handler function...
   219 	// Decode the message type and dispatch it to the relevent handler function...
   237 	if (id==(TInt)ECloseMsg)
   220 	if (id == (TInt)ECloseMsg)
   238 		{
   221 		{
   239 		DoCancel(RWebcameraDevice::EAllRequests);
   222 		DoCancel(RWebcameraDevice::EAllRequests);
   240 		m.Complete(KErrNone, EFalse);
   223 		m.Complete(KErrNone, EFalse);
   241 		return;
   224 		return;
   242 		}
   225 		}
   243 
   226 
   244 	if(m.Client()!=iClient)
   227 	if (m.Client() != iClient)
   245 		{
   228 		{
   246 		Kern::ThreadKill(m.Client(),
   229 		Kern::ThreadKill(m.Client(),
   247 						 EExitPanic,
   230 						 EExitPanic,
   248 						 ERequestFromWrongThread,
   231 						 ERequestFromWrongThread,
   249 						 KDriver1PanicCategory);
   232 						 KDriver1PanicCategory);
   250 		m.Complete(KErrNone,ETrue);
   233 		m.Complete(KErrNone, ETrue);
   251 		return;
   234 		return;
   252 		}
   235 		}
   253 
   236 
   254 	if (id==KMaxTInt)
   237 	if (id == KMaxTInt)
   255 		{
   238 		{
   256 		DoCancel(m.Int0());
   239 		DoCancel(m.Int0());
   257 		m.Complete(KErrNone,ETrue);
   240 		m.Complete(KErrNone, ETrue);
   258 		return;
   241 		return;
   259 		}
   242 		}
   260 
   243 
   261 	if (id<0)
   244 	if (id < 0)
   262 		{
   245 		{
   263 		// DoRequest
   246 		// DoRequest
   264 		TRequestStatus* pS=(TRequestStatus*)m.Ptr0();
   247 		TRequestStatus* pS = (TRequestStatus*)m.Ptr0();
   265 		TInt rtn =DoRequest(~id,pS,m.Ptr1(),aMsg);
   248 		TInt rtn = DoRequest(~id, pS, m.Ptr1(), aMsg);
   266 
   249 
   267 		if (rtn != KErrNone)
   250 		if (rtn != KErrNone)
   268 			Kern::RequestComplete(iClient,pS,rtn);
   251 			{
   269         m.Complete(KErrNone,ETrue);
   252 			Kern::RequestComplete(iClient, pS, rtn);
       
   253 			}
       
   254 		m.Complete(KErrNone, ETrue);
   270 		}
   255 		}
   271 	else
   256 	else
   272 		{
   257 		{
   273 		// DoControl
   258 		// DoControl
   274 		TInt rtn = DoControl(id,m.Ptr0(),aMsg);
   259 		TInt rtn = DoControl(id, m.Ptr0(), aMsg);
   275 		m.Complete(rtn,ETrue);
   260 		m.Complete(rtn, ETrue);
   276 		}
   261 		}
   277 	DP("DWebcameraLogicalChannel::HandleMsg() end");
   262 	DP("DWebcameraLogicalChannel::HandleMsg() end");
   278 	}
   263 	}
   279 
   264 
   280 /**
   265 /**
   281   Process synchronous 'control' requests
   266 Process synchronous 'control' requests
   282 */
   267 */
   283 TInt DWebcameraLogicalChannel::DoControl(TInt aFunction, TAny* a1, TAny* a2)
   268 TInt DWebcameraLogicalChannel::DoControl(TInt aFunction, TAny* a1, TAny* /*a2*/)
   284 	{
   269 	{
   285 	DP("DWebcameraLogicalChannel::DoControl() start");
   270 	DP("DWebcameraLogicalChannel::DoControl() start");
   286 	TInt rtn;
   271 	TInt rtn;
   287 	TThreadMessage& m=*(TThreadMessage*)a2;
   272 	rtn = KErrNone;
   288 	TRequestStatus* pS=(TRequestStatus*)m.Ptr0();
       
   289 
   273 
   290 	switch (aFunction)
   274 	switch (aFunction)
   291 		{
   275 		{
   292 		case RWebcameraDevice::EGetConfig:
   276 		case RWebcameraDevice::EGetConfig:
   293 //			rtn = GetConfig((TDes8*)a1);
   277 //			rtn = GetConfig((TDes8*)a1);
   294 			rtn = KErrNone;
   278 			rtn = KErrNone;
   295 			if ( rtn != KErrNone )
       
   296 				{
       
   297 				Kern::RequestComplete(iClient,pS,rtn);
       
   298 				}
       
   299 			break;
   279 			break;
   300         case RWebcameraDevice::ESetConfig:
   280         case RWebcameraDevice::ESetConfig:
   301  //       	rtn = SetConfig((const TDesC8*)a1);
   281 //			rtn = SetConfig((const TDesC8*)a1);
   302             break;
   282 			break;
   303             
   283 		case RWebcameraDevice::EOpenSharedChunck:
       
   284 			rtn=OpenSharedChunks((RWebcameraDevice::TChunkInfo*)a1);
       
   285 			break;
       
   286 		case RWebcameraDevice::EInitViewFinder:
       
   287 			rtn = Pdd()->InitViewFinder();
       
   288 			iDataPtr = Kern::Alloc(BUFSIZE);
       
   289 			iBmpBuf = (TUint8*)Kern::Alloc(BITMAPBUFSIZE);
       
   290 			break;
   304 		default:
   291 		default:
   305 			rtn = KErrNotSupported;
   292 			rtn = KErrNotSupported;
   306 			Kern::RequestComplete(iClient,pS,rtn);
       
   307 			break;
   293 			break;
   308 		}
   294 		}
   309 	DP("DWebcameraLogicalChannel::DoControl() end");
   295 	DP("DWebcameraLogicalChannel::DoControl() end");
   310 	return rtn;
   296 	return rtn;
   311 
   297 	}
   312 	}
   298 
   313 
   299 /**
   314 /**
   300 Process asynchronous requests.
   315   Process asynchronous requests.
       
   316 */
   301 */
   317 TInt DWebcameraLogicalChannel::DoRequest(TInt aReqNo,
   302 TInt DWebcameraLogicalChannel::DoRequest(TInt aReqNo,
   318 											TRequestStatus* aStatus,
   303 											TRequestStatus* aStatus,
   319 											TAny* a1,
   304 											TAny* a1,
   320 											TAny* a2)
   305 											TAny* /*a2*/)
   321 	{
   306 	{
   322 	DP("DWebcameraLogicalChannel::DoRequest() start");
       
   323 	TInt rtn;
   307 	TInt rtn;
   324 	TThreadMessage& m=*(TThreadMessage*)a2;
   308 	iRequesting = ETrue;
   325 
       
   326 	iRequesting =ETrue;
       
   327 	rtn = KErrNone;
   309 	rtn = KErrNone;
   328     DP("aReqNo=%d",aReqNo);
   310 
   329 	switch(aReqNo)
   311 	switch (aReqNo)
   330 		{
   312 		{
   331 		case RWebcameraDevice::EStart:
   313 		case RWebcameraDevice::EStart:
   332    			DP("EStart=%d",RWebcameraDevice::EStart);
       
   333 			iReceiveDataStatus = aStatus;
   314 			iReceiveDataStatus = aStatus;
   334 			iReceiving = ETrue ;
   315 			iReceiving = ETrue;
   335 			iReceiveDataBuffer->FillZ(iCaptureBuffer->MaxLength());
   316 			iWebCameraState = RWebcameraDevice::EStart;
   336 			iReceiveDataBuffer->Zero();
   317 			iReceiveDataDfc.Add();
   337 			DP("iReceiveDataBuffer Len=%d",iReceiveDataBuffer->MaxLength());
   318 			// Example Platform Security capability check which tests the
   338 			DP("iReceiveDataBuffer Len=%d",iReceiveDataBuffer->Length());
   319 			// client for ECapability_None (which always passes)...
   339 			rtn = Pdd()->StartViewerFinder(iPhysAddr,iSize);
   320 			if (iRequesting == EFalse)
   340 			if ( rtn != KErrNone ) 
       
   341 				{
   321 				{
   342 	   			DP("rtn=%d",rtn);
   322 				iReceiving = EFalse;
   343 				iReceiving = EFalse ;
   323 				Kern::RequestComplete(iClient,
   344 				Kern::RequestComplete(iClient,aStatus,rtn);
   324 									  iReceiveDataStatus,
       
   325 									  iReceiveDataResult);
   345 				}
   326 				}
   346 			else
   327 			else
   347 				{
   328 				{
   348 	   			DP("rtn=%d",rtn);
   329 				iReceiveDataDescriptor = (TInt*)a1;
   349 				// Example Platform Security capability check which tests the
       
   350 				// client for ECapability_None (which always passes)...
       
   351 				if ( iRequesting == EFalse )
       
   352 					{
       
   353 		   			DP("iRequesting=EFalse");
       
   354 					iReceiving = EFalse ;
       
   355 					Kern::RequestComplete(iClient,
       
   356 										  iReceiveDataStatus,
       
   357 										  iReceiveDataResult);
       
   358 					}
       
   359 				else
       
   360 					{
       
   361 					DP("iRequesting=ETrue");
       
   362 					iReceiveDataDescriptor=(TDes8*)a1;
       
   363 					}
       
   364 				}
   330 				}
   365 			break;
   331 			break;
   366 		case RWebcameraDevice::ECapture:
   332 		case RWebcameraDevice::ECapture:
   367 			iCaptureing = ETrue ;
       
   368 			iCaptureStatus = aStatus;
   333 			iCaptureStatus = aStatus;
   369 			iCaptureBuffer->FillZ(iCaptureBuffer->MaxLength());
   334 			iWebCameraState = RWebcameraDevice::ECapture;
   370 			iCaptureBuffer->Zero();
   335 			iCaptureDfc.Add();
   371 		    DP("iCaptureBuffer Len=%d",iCaptureBuffer->MaxLength());
   336 			if (iRequesting == EFalse)
   372 		    DP("iCaptureBuffer Len=%d",iCaptureBuffer->Length());
       
   373 			rtn = Pdd()->StartCapture(iPhysAddr,iSize);
       
   374 			DP("rtn=%d",rtn);
       
   375 			if ( rtn != KErrNone ) 
       
   376 				{
   337 				{
   377 				iCaptureing = EFalse ;
   338 				Kern::RequestComplete(iClient, iCaptureStatus, iCaptureResult);
   378 				Kern::RequestComplete(iClient,aStatus,rtn);
       
   379 				}
   339 				}
   380 			else
   340 			else
   381 				{
   341 				{
   382 				if ( iRequesting == EFalse )
   342 		        iCaptureDescriptor=(TInt*)a1;
   383 					{
       
   384 				    DP("iRequesting=EFalse");
       
   385 					iReceiving = EFalse ;
       
   386 					Kern::RequestComplete(iClient,iCaptureStatus,iCaptureResult);
       
   387 					}
       
   388 				else
       
   389 					{
       
   390 			        DP("Capture iRequesting=ETrue");
       
   391 				    iCaptureDescriptor=(TDes8*)a1;
       
   392 					}
       
   393 				}
   343 				}
   394 			break;
   344 			break;
       
   345 		case RWebcameraDevice::EPowerOn:
       
   346 			if (iPowerOn == EFalse)
       
   347 				{
       
   348 				iPowerOn = ETrue;
       
   349 				iWebCameraState = RWebcameraDevice::EPowerOn;
       
   350 				iHeaderPtr = Kern::Alloc(sizeof(TWebcameraUVC));
       
   351 				rtn = Pdd()->PowerOn(iHeaderPtr);
       
   352 				Kern::RequestComplete(iClient, aStatus, rtn);
       
   353 				}
       
   354 			else
       
   355 				{
       
   356 				Kern::RequestComplete(iClient, aStatus, KErrAlreadyExists);
       
   357 				}
       
   358 			break;
       
   359 		case RWebcameraDevice::EPowerOff:
       
   360 			Pdd()->Disconnect();
       
   361 			iPowerOn = EFalse;
       
   362 			iReceiving = EFalse;
       
   363 			iReceiveDataDfc.Cancel();
       
   364 			iCaptureDfc.Cancel();
       
   365 			iWebCameraState = RWebcameraDevice::EPowerOff;
       
   366 			Kern::RequestComplete(iClient, aStatus, rtn);
       
   367 			break;
   395 		default:
   368 		default:
   396 			rtn=KErrNotSupported;
   369 			rtn = KErrNotSupported;
   397 			Kern::RequestComplete(iClient,aStatus,rtn);
   370 			Kern::RequestComplete(iClient, aStatus, rtn);
   398 			break;
   371 			break;
   399 		}
   372 		}
   400 	iRequesting = EFalse;
   373 	iRequesting = EFalse;
   401 
       
   402 	DP("DWebcameraLogicalChannel::DoRequest() end");
       
   403 	return rtn;
   374 	return rtn;
   404 
   375 	}
   405 	}
   376 
   406 
   377 /**
   407 /**
   378 Process cancelling of asynchronous requests.
   408   Process cancelling of asynchronous requests.
       
   409 */
   379 */
   410 void DWebcameraLogicalChannel::DoCancel(TUint aMask)
   380 void DWebcameraLogicalChannel::DoCancel(TUint aMask)
   411 	{
   381 	{
   412 	DP("DWebcameraLogicalChannel::DoCancel() start");
   382 	DP("DWebcameraLogicalChannel::DoCancel() start");
   413 	TInt rtn;
       
   414 	DP("aMask=%d",aMask);
   383 	DP("aMask=%d",aMask);
   415     if (aMask&(1<<RWebcameraDevice::EStart))
   384 	if (aMask & (1 << RWebcameraDevice::EStart))
   416     	{
   385 		{
   417 		DP("RWebcameraDevice::EStart=%d",RWebcameraDevice::EStart);
   386 		DP("RWebcameraDevice::EStart=%d",RWebcameraDevice::EStart);
   418 		if (iReceiveDataStatus)
   387 		if (iReceiveDataStatus)
   419 			{
   388 			{
   420 			DP("iReceiveDataStatus=%d",iReceiveDataStatus);
   389 			DP("iReceiveDataStatus=%d",iReceiveDataStatus);
   421 			Pdd()->Stop(DWebcameraDriverBase::USB_cancel);
   390 			Pdd()->Stop(DWebcameraDriverBase::USB_cancel);
   422 			iReceiving = EFalse ;
   391 			iReceiving = EFalse;
   423 			iReceiveDataDfc.Cancel();
   392 			iReceiveDataDfc.Cancel();
   424 			Kern::RequestComplete(iClient,iReceiveDataStatus,KErrCancel);
   393 			Kern::RequestComplete(iClient, iReceiveDataStatus, KErrCancel);
   425 			}
   394 			}
   426     	}
   395 		}
   427     if (aMask&(1<<RWebcameraDevice::ECapture))
   396 	if (aMask&(1<<RWebcameraDevice::ECapture))
   428     	{
   397 		{
   429 		DP("RWebcameraDevice::ECapture=%d",RWebcameraDevice::ECapture);
   398 		DP("RWebcameraDevice::ECapture=%d",RWebcameraDevice::ECapture);
   430 		if (iCaptureStatus)
   399 		if (iCaptureStatus)
   431 			{
   400 			{
   432 			Pdd()->Stop(DWebcameraDriverBase::USB_cancel);
       
   433 			iReceiving = EFalse ;
       
   434 			iCaptureDfc.Cancel();
   401 			iCaptureDfc.Cancel();
   435 			Kern::RequestComplete(iClient,iCaptureStatus,KErrCancel);
   402 			Kern::RequestComplete(iClient, iCaptureStatus, KErrCancel);
   436 			}
   403 			}
   437     	}
   404 		}
   438 	DP("DWebcameraLogicalChannel::DoCancel() end");
   405 	DP("DWebcameraLogicalChannel::DoCancel() end");
   439 	}
   406 	}
   440 
   407 
   441 /**
   408 /**
   442   Called by PDD from ISR to indicate that a ReceiveData operation has completed.
   409 Called by PDD from ISR to indicate that a ReceiveData operation has completed.
   443 */
   410 */
   444 void DWebcameraLogicalChannel::GetOneFlameComplete(TInt aDataSize)
   411 void DWebcameraLogicalChannel::GetOneFlameComplete(TInt aDataSize)
   445     {
   412 	{
   446 	DP("DWebcameraLogicalChannel::GetOneFlameComplete() start");
   413 	iSaveSize = iSize - aDataSize;
   447 	DP("datasize=%d",aDataSize);
   414 	// Queue DFC
   448 	iSaveSize=iSize - aDataSize;
   415 	iWebCameraState = RWebcameraDevice::ETransferData;
   449     // Queue DFC
   416 	iReceiveDataDfc.Add();
   450     iReceiveDataDfc.Add();
   417 	//set size of received data
   451     //set size of received data
   418 	if (iSaveSize > 0)
   452     if (iSaveSize > 0)
   419 		{
   453     	{
   420 		iReceiveDataResult = KErrNone;
   454 	    iReceiveDataResult = KErrNone;
   421 		}
   455     	}
   422 	else
   456     else
   423 		{
   457     	{
   424 		iReceiveDataResult = KErrUnknown; //TODO:define of error
   458 		iReceiveDataResult = KErrUnknown;//TODO:define of error
   425 		}
   459     	}
   426 	}
   460 	DP("DWebcameraLogicalChannel::GetOneFlameComplete() end");
   427 
   461     }
   428 void DWebcameraLogicalChannel::DoStartViewFinder()
   462 
   429 	{
   463 /**
   430 	TInt rtn = Pdd()->StartViewerFinder(iDataPtr, BUFSIZE);
   464   Called by PDD from ISR to indicate that a get capture image operation has completed.
   431 	if (rtn != KErrNone)
   465 */
   432 		{
   466 void DWebcameraLogicalChannel::CaptureComplete(TInt aDataSize)
   433 		DP("rtn=%d",rtn);
   467     {
   434 		iReceiving = EFalse;
   468 	DP("DWebcameraLogicalChannel::CaptureComplete() start");
   435 		Kern::RequestComplete(iClient, iReceiveDataStatus, rtn);
   469 	DP("datasize=%d",aDataSize);
   436 		}
   470 	iSaveSize=iSize - aDataSize;
   437 	}
   471     // Queue DFC
   438 /**
   472 	iCaptureDfc.Add();
   439 DFC Callback which gets triggered after the PDD has signalled that getting oneflame completed.
   473     //set size of received data
   440 This just casts aPtr and calls DoGetOneFlameComplete().
   474     if (iSaveSize > 0)
   441 */
   475     	{
   442 void DWebcameraLogicalChannel::GetFlameDfc(TAny* aPtr)
   476 		iCaptureResult = KErrNone;
   443 	{
   477     	}
   444 	switch (((DWebcameraLogicalChannel*)aPtr)->iWebCameraState)
   478     else
   445 		{
   479     	{
   446 	case RWebcameraDevice::EStart:
   480         iCaptureResult = KErrUnknown;//TODO:define of error
   447 		((DWebcameraLogicalChannel*)aPtr)->DoStartViewFinder();
   481     	}
   448 		break;
   482 	DP("DWebcameraLogicalChannel::CaptureComplete() end");
   449 	case RWebcameraDevice::ETransferData:
   483     }
   450 		((DWebcameraLogicalChannel*)aPtr)->DoGetOneFlameComplete();
   484 
   451 		break;
   485 /**
   452 	default:
   486   DFC Callback which gets triggered after the PDD has signalled that getting oneflame completed.
   453 		break;
   487   This just casts aPtr and calls DoGetOneFlameComplete().
   454 		}
   488 */
   455 	}
   489 void DWebcameraLogicalChannel::GetOneFlameDfc(TAny* aPtr)
   456 /**
   490     {
   457 DFC Callback
   491 	DP("DWebcameraLogicalChannel::GetOneFlameDfc() start");
   458 gets Capture image completed.
   492     ((DWebcameraLogicalChannel*)aPtr)->DoGetOneFlameComplete();
   459 This just casts aPtr and calls DoCaptureComplete().
   493 	DP("DWebcameraLogicalChannel::GetOneFlameDfc() end");
       
   494     }
       
   495 
       
   496 /**
       
   497   DFC Callback which gets triggered after the PDD has signalled that getting Capture image completed.
       
   498   This just casts aPtr and calls DoCaptureComplete().
       
   499 */
   460 */
   500 void DWebcameraLogicalChannel::CaptureDfc(TAny* aPtr)
   461 void DWebcameraLogicalChannel::CaptureDfc(TAny* aPtr)
   501     {
   462 	{
   502 	DP("DWebcameraLogicalChannel::CaptureDfc() start");
   463 	DP("DWebcameraLogicalChannel::CaptureDfc() start");
   503     ((DWebcameraLogicalChannel*)aPtr)->DoCaptureComplete();
   464 	((DWebcameraLogicalChannel*)aPtr)->DoCaptureComplete();
   504 	DP("DWebcameraLogicalChannel::CaptureDfc() end");
   465 	DP("DWebcameraLogicalChannel::CaptureDfc() end");
   505     }
   466 	}
   506 
   467 
   507 /**
   468 /**
   508   Called from a DFC after the PDD has signalled that getting oneflame completed.
   469 Called from a DFC after the PDD has signalled that getting oneflame completed.
   509 */
   470 */
   510 void DWebcameraLogicalChannel::DoGetOneFlameComplete()
   471 void DWebcameraLogicalChannel::DoGetOneFlameComplete()
   511     {
   472 	{
   512 	DP("DWebcameraLogicalChannel::DoGetOneFlameComplete() start");
   473 	if (!iConvert)
   513 	iReceiveDataBuffer->Copy(iLAdr,iSaveSize);
   474 		{
   514     DP("iReceiveDataBuffer Len=%d",iReceiveDataBuffer->Length());
   475 		iConvert = new DWebCameraConvert((TWebcameraUVC*)iHeaderPtr);
   515 	// Write data to client from our buffer
   476 		}
   516     TInt result=Kern::ThreadDesWrite(iClient,iReceiveDataDescriptor,*iReceiveDataBuffer,0);
   477 
   517     // Finished with client descriptor, so NULL it to help detect coding errors
   478 	iConvert->ConvertData((TUint8*)iDataPtr, iBmpBuf);
   518     iReceiveDataDescriptor = NULL;
   479 	kumemget((TAny*)(iChunkLinAddr), iBmpBuf, iSaveSize);
   519 
   480 
   520     // Use result code from PDD if it was an error
   481 	TInt result = Kern::ThreadRawWrite(iClient, iReceiveDataDescriptor, &iSaveSize,sizeof(TInt), 0);
   521     if(iReceiveDataResult!=KErrNone)
   482 
   522         result = iReceiveDataResult;
   483 	// Finished with client descriptor, so NULL it to help detect coding errors
   523     
   484 	iReceiveDataDescriptor = NULL;
   524     // Complete clients request
   485 
   525     Kern::RequestComplete(iClient,iReceiveDataStatus,result);
   486 	// Use result code from PDD if it was an error
   526 	DP("DWebcameraLogicalChannel::DoGetOneFlameComplete() end");
   487 	if(iReceiveDataResult != KErrNone)
   527     }
   488 		{
   528 
   489 		result = iReceiveDataResult;
   529 /**
   490 		}
   530   Called from a DFC after the PDD has signalled that getting Capture image completed.
   491 	// Complete clients request
       
   492 	Kern::RequestComplete(iClient, iReceiveDataStatus, result);
       
   493 	}
       
   494 
       
   495 /**
       
   496 Called from a DFC after the PDD has signalled that getting Capture image completed.
   531 */
   497 */
   532 void DWebcameraLogicalChannel::DoCaptureComplete()
   498 void DWebcameraLogicalChannel::DoCaptureComplete()
   533     {
   499 	{
   534 	DP("DWebcameraLogicalChannel::DoCaptureComplete() start");
   500 	DP("DWebcameraLogicalChannel::DoCaptureComplete() start");
   535 	iCaptureBuffer->Copy(iLAdr,iSaveSize);
   501 
   536     DP("iCaptureBuffer Len=%d",iCaptureBuffer->Length());
   502 	TInt result = Kern::ThreadRawWrite(iClient, iCaptureDescriptor, &iSaveSize, sizeof(TInt), 0);
   537 	// Write data to client from our buffer
   503 
   538    TInt result=Kern::ThreadDesWrite(iClient,iCaptureDescriptor,*iCaptureBuffer,0);  	
   504 	// Finished with client descriptor, so NULL it to help detect coding errors
   539     // Finished with client descriptor, so NULL it to help detect coding errors
   505 	iCaptureDescriptor = NULL;
   540     iCaptureDescriptor = NULL;
   506 
   541 
   507 	// Use result code from PDD if it was an error
   542     // Use result code from PDD if it was an error
   508 	if(iCaptureResult != KErrNone)
   543     if(iCaptureResult!=KErrNone)
   509 		{
   544         result = iCaptureResult;
   510 		result = iCaptureResult;
   545 
   511 		}
   546     // Complete clients request
   512 	// Complete clients request
   547     Kern::RequestComplete(iClient,iCaptureStatus,result);
   513 	Kern::RequestComplete(iClient, iCaptureStatus, result);
   548 	DP("DWebcameraLogicalChannel::DoCaptureComplete() end");
   514 	DP("DWebcameraLogicalChannel::DoCaptureComplete() end");
   549     }
   515 	}
   550 
   516 
   551 /**
   517 /**
   552   Process a GetConfig control message. This writes the current driver configuration to a
   518 Process a GetConfig control message. This writes the current driver configuration to a
   553   RWebcameraDevice::TConfigBuf supplied by the client.
   519 RWebcameraDevice::TConfigBuf supplied by the client.
   554 */
   520 */
   555 TInt DWebcameraLogicalChannel::GetConfig(TDes8* aConfigBuf)
   521 TInt DWebcameraLogicalChannel::GetConfig(TDes8* aConfigBuf)
   556     {
   522 	{
   557 	//unsupported
   523 	//unsupported
   558     }
   524 	return KErrNotSupported;
   559 
   525 	}
   560 /**
   526 
   561   Process a SetConfig control message. This sets the driver configuration using a
   527 /**
   562   RWebcameraDevice::TConfigBuf supplied by the client.
   528 Process a SetConfig control message. This sets the driver configuration using a
       
   529 RWebcameraDevice::TConfigBuf supplied by the client.
   563 */
   530 */
   564 TInt DWebcameraLogicalChannel::SetConfig(const TDesC8* aConfigBuf)
   531 TInt DWebcameraLogicalChannel::SetConfig(const TDesC8* aConfigBuf)
   565     {
   532 	{
   566 	//unsupported
   533 	//unsupported
   567     }
   534 	return KErrNotSupported;
   568 
   535 	}
   569 /**
   536 
   570   Fill a TConfig with the drivers current configuration.
   537 /**
       
   538 Fill a TConfig with the drivers current configuration.
   571 */
   539 */
   572 /*void DWebcameraLogicalChannel::CurrentConfig(RWebcameraDevice::TConfig& aConfig)
   540 /*void DWebcameraLogicalChannel::CurrentConfig(RWebcameraDevice::TConfig& aConfig)
   573     {
   541 	{
   574 	//unsupported
   542 	//unsupported
   575     }
   543 	}
   576 */
   544 */
   577 
   545 
   578 /**
   546 TInt DWebcameraLogicalChannel::CreatSharedChunks()
   579  *Get the point to Physical channel.
   547 	{
       
   548 	DP("DWebcameraLogicalChannel::CreatSharedChunks() start");
       
   549 
       
   550 	iChunk=NULL;
       
   551 
       
   552 	NKern::ThreadEnterCS();
       
   553 
       
   554 	iSize = Kern::RoundToPageSize(BITMAPBUFSIZE);
       
   555 
       
   556 	TChunkCreateInfo info;
       
   557 	info.iType			= TChunkCreateInfo::ESharedKernelMultiple;
       
   558 	info.iMaxSize		= iSize;
       
   559 	info.iMapAttr		= EMapAttrFullyBlocking;
       
   560 	info.iOwnsMemory	= ETrue;
       
   561 	info.iDestroyedDfc	= NULL;
       
   562 	TInt r = Kern::ChunkCreate(info, iChunk, iChunkLinAddr, iChunkMappingAttr);
       
   563 	if (r != KErrNone)
       
   564 		{
       
   565 		NKern::ThreadLeaveCS();
       
   566 		return r;
       
   567 		}
       
   568 	iPhysAddr = 0x0;
       
   569 	r = Kern::ChunkCommitContiguous(iChunk, 0, iSize, iPhysAddr);
       
   570 
       
   571 	if (r != KErrNone)
       
   572 		{
       
   573 		Kern::ChunkClose(iChunk);
       
   574 		NKern::ThreadLeaveCS();
       
   575 		return r;
       
   576 		}
       
   577 	NKern::ThreadLeaveCS();
       
   578 
       
   579 	DP("DWebcameraLogicalChannel::CreatSharedChunks() end");
       
   580 	return KErrNone;
       
   581 	}
       
   582 
       
   583 TInt DWebcameraLogicalChannel::OpenSharedChunks(RWebcameraDevice::TChunkInfo* aChunkInfo)
       
   584 	{
       
   585 	DP("DWebcameraLogicalChannel::OpenSharedChunks() start");
       
   586 	RWebcameraDevice::TChunkInfo chunkInfo;
       
   587 	NKern::ThreadEnterCS();
       
   588 	// Make handle to chunifo for current thread
       
   589 	TInt r = Kern::MakeHandleAndOpen(iClient, iChunk);
       
   590 	if (r >= 0) 
       
   591 		{
       
   592 		chunkInfo.iChunkHandle = r;
       
   593 		r = KErrNone;
       
   594 		}
       
   595 
       
   596 	NKern::ThreadLeaveCS();
       
   597 
       
   598 	if (r != KErrNone)
       
   599 		{
       
   600 		memclr(&chunkInfo,sizeof(chunkInfo));
       
   601 		}
       
   602 	TInt result = Kern::ThreadRawWrite(iClient, aChunkInfo, &chunkInfo, sizeof(chunkInfo), 0);
       
   603 
       
   604 	DP("DWebcameraLogicalChannel::OpenSharedChunks() end");
       
   605 	return r;
       
   606 	}
       
   607 
       
   608 void DWebcameraLogicalChannel::ChunkDestroyed()
       
   609 	{
       
   610 	DP("DWebcameraLogicalChannel::ChunkDestroyed() start");
       
   611 	//unsupported
       
   612 	DP("DWebcameraLogicalChannel::ChunkDestroyed() end");
       
   613 	}
       
   614 
       
   615 void DWebcameraLogicalChannel::CloseSharedChunks()
       
   616 	{
       
   617 	DP("DWebcameraLogicalChannel::CloseSharedChunks() start");
       
   618 	if (iChunk)
       
   619 		{
       
   620 		Kern::ChunkClose(iChunk);
       
   621 		}
       
   622 	DP("DWebcameraLogicalChannel::CloseSharedChunks() end");
       
   623 	}
       
   624 
       
   625 /**
       
   626 Get the point to Physical channel.
   580  */
   627  */
   581 DWebcameraDriverBase* DWebcameraLogicalChannel::Pdd()
   628 DWebcameraDriverBase* DWebcameraLogicalChannel::Pdd()
   582 	{
   629 	{
   583 	DP("DWebcameraLogicalChannel::Pdd() start");
   630 	DP("DWebcameraLogicalChannel::Pdd() start");
   584 	return (DWebcameraDriverBase*)iPdd;
   631 	return (DWebcameraDriverBase*)iPdd;
   585 	}
   632 	}
   586