windowing/windowserver/tauto/eventdd.cpp
changeset 0 5d03bc08d59c
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include <kernel/kernel.h>
       
    17 #include "eventdd.h"
       
    18 
       
    19 /**
       
    20   Logical Device (factory class) for 'EventDD'
       
    21 */
       
    22 class DEventFactory : public DLogicalDevice
       
    23 	{
       
    24 public:
       
    25 	DEventFactory();
       
    26 	//Pure virtual funcitons from DLogicalDevice
       
    27 	TInt Install();
       
    28 	void GetCaps(TDes8& aDes) const;
       
    29 	TInt Create(DLogicalChannelBase*& aChannel);
       
    30 	};
       
    31 
       
    32 class DEventDD : public DLogicalChannelBase
       
    33 	{
       
    34 public:
       
    35 	//Pure virtual function from DLogicalChannelBase
       
    36 	TInt Request(TInt aReqNo,TAny* a1,TAny* a2);
       
    37 private:
       
    38 	TInt DoControl(TInt aFunction, TAny* a1, TAny* a2);
       
    39 	TInt SendEvent(TRawEvent* aEvent);
       
    40 	};
       
    41 
       
    42 
       
    43 /* DLL Factory Function */
       
    44 
       
    45 DECLARE_STANDARD_LDD()
       
    46 	{
       
    47 	return new DEventFactory;
       
    48 	}
       
    49 
       
    50 
       
    51 /* DEventFactory */
       
    52 
       
    53 DEventFactory::DEventFactory() :DLogicalDevice()
       
    54 	{
       
    55 	iVersion=REventDD::VersionRequired();	//Set version number for this device
       
    56 	}
       
    57 
       
    58 TInt DEventFactory::Install()
       
    59 	{
       
    60 	return SetName(&REventDD::DriverName());
       
    61 	}
       
    62 
       
    63 void DEventFactory::GetCaps(TDes8& aDes) const
       
    64 	{
       
    65 	Kern::InfoCopy(aDes,KNullDesC8);
       
    66 	}
       
    67 
       
    68 TInt DEventFactory::Create(DLogicalChannelBase*& aChannel)
       
    69 	{
       
    70 	aChannel=new DEventDD;
       
    71 	return aChannel?KErrNone:KErrNoMemory;
       
    72 	}
       
    73 
       
    74 
       
    75 /* DEventDD */	// Logical Channel
       
    76 
       
    77 TInt DEventDD::Request(TInt aReqNo,TAny* a1,TAny* a2)
       
    78 	{
       
    79 	// Decode the message type and dispatch it to the relevent handler function...
       
    80 	// only using synchronous control messages
       
    81 	if (static_cast<TUint>(aReqNo)<static_cast<TUint>(KMaxTInt))
       
    82 		return DoControl(aReqNo,a1,a2);
       
    83 	return KErrNotSupported;
       
    84 	}
       
    85 
       
    86 /**
       
    87   Process synchronous 'control' requests
       
    88 */
       
    89 TInt DEventDD::DoControl(TInt aFunction,TAny* a1,TAny* /*a2*/)
       
    90 	{
       
    91 	TInt ret=KErrNotSupported;
       
    92 
       
    93 	switch (aFunction)
       
    94 		{
       
    95 	case REventDD::ESendEvent:
       
    96 		ret=SendEvent(static_cast<TRawEvent*>(a1));
       
    97 		break;
       
    98 	default:;
       
    99 		}
       
   100 	return ret;
       
   101 	}
       
   102 
       
   103 TInt DEventDD::SendEvent(TRawEvent* aEvent)
       
   104 	{
       
   105 	TRawEvent event;
       
   106 	kumemget(&event,aEvent,sizeof(TRawEvent));	//fetch event from user memory
       
   107 	NKern::ThreadEnterCS();
       
   108 	TInt err=Kern::AddEvent(event);
       
   109 	NKern::ThreadLeaveCS();
       
   110 	return err;
       
   111 	}