windowing/windowserver/nga/SERVER/KEYCLICK.CPP
changeset 0 5d03bc08d59c
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     1 // Copyright (c) 2001-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 // Definition of the class that manages the keyclick plugin
       
    15 // 
       
    16 //
       
    17 
       
    18 #include "KEYCLICK.H"
       
    19 
       
    20 #include "server.h"
       
    21 #include "W32CLICK.H"
       
    22 #include "panics.h"
       
    23 #include "inifile.h"
       
    24 #include "advancedpointereventhelper.h"
       
    25 
       
    26 CClickMaker* CClick::iHandler=NULL;
       
    27 TBool CClick::iIsChangeable=ETrue;
       
    28 TBool CClick::iKeyClickOveride=EFalse;
       
    29 TBool CClick::iKeyClickEnabled=ETrue;
       
    30 TBool CClick::iPenClickEnabled=ETrue;
       
    31 RLibrary CClick::iPlugIn;
       
    32 TBool CClick::iIsLoaded=EFalse;
       
    33 
       
    34 const TUid KClickPlugInDllUid={0x10004F63};
       
    35 static _LIT_SECURITY_POLICY_C1(KSecurityPolicy_WriteDeviceData,ECapabilityWriteDeviceData);
       
    36 
       
    37 
       
    38 /*static part*/
       
    39 
       
    40 void CClick::InitStaticsL()
       
    41 	{
       
    42 	_LIT(KClickPlugin,"KEYCLICKPLUGIN");
       
    43 	TPtrC plugInName;
       
    44 	if (WsIniFile->FindVar(KClickPlugin,plugInName))
       
    45 		LoadNewLibraryL(plugInName);
       
    46 	_LIT(KClickFixed,"KEYCLICKPLUGINFIXED");
       
    47 	iIsChangeable=!WsIniFile->FindVar(KClickFixed);
       
    48 	}
       
    49 
       
    50 void CClick::DeleteStatics()
       
    51 	{
       
    52 	if (iIsLoaded)
       
    53 		{
       
    54 		delete iHandler;
       
    55 		iHandler=NULL;
       
    56 		iPlugIn.Close();
       
    57 		}
       
    58 	}
       
    59 
       
    60 void CClick::KeyEvent(TEventCode aType,const TKeyEvent& aEvent)
       
    61 	{
       
    62 	WS_ASSERT_DEBUG(iHandler, EWsPanicClickPluginNotLoaded);
       
    63 	if (iKeyClickEnabled && !iKeyClickOveride)
       
    64 		{
       
    65 		TRAP_IGNORE(iHandler->KeyEvent(aType,aEvent)); // TRAP leaves in case the plugin is badly behaved
       
    66 		}
       
    67 	}
       
    68 
       
    69 void CClick::PointerEvent(const TPoint& aScreenPos,const TAdvancedPointerEvent& aEvent)
       
    70 	{
       
    71 	WS_ASSERT_DEBUG(iHandler, EWsPanicClickPluginNotLoaded);
       
    72 	if (iPenClickEnabled)
       
    73 		{
       
    74 		TAdvancedPointerEvent event;
       
    75 		TAdvancedPointerEventHelper::Copy(aEvent,event);
       
    76 		event.iParentPosition=aScreenPos;
       
    77 		TRAP_IGNORE(iHandler->PointerEvent(event)); // TRAP leaves in case the plugin is badly behaved
       
    78 		}
       
    79 	}
       
    80 
       
    81 void CClick::OtherEvent(TInt aType,TAny* aParam)
       
    82 	{
       
    83 	WS_ASSERT_DEBUG(iHandler, EWsPanicClickPluginNotLoaded);
       
    84 	if (aType!=EEventPointer || iPenClickEnabled)
       
    85 		TRAP_IGNORE(iHandler->OtherEvent(aType,aParam)); // TRAP leaves in case the plugin is badly behaved
       
    86 	}
       
    87 
       
    88 void CClick::LoadNewLibraryL(const TDesC &aDllName)
       
    89 	{
       
    90 	WS_ASSERT_DEBUG(iIsChangeable, EWsPanicChangeClickPlugin);
       
    91 	const TUidType uidType(KDllUid,KClickPlugInDllUid);
       
    92 	RLibrary plugIn;
       
    93 	User::LeaveIfError(plugIn.Load(aDllName,uidType));
       
    94 	CleanupClosePushL(plugIn);
       
    95 	CreateCClickHandler function;
       
    96 	CClickMaker* handler;
       
    97 	function=(CreateCClickHandler)User::LeaveIfNull((TAny*)plugIn.Lookup(1));	//Can only cast function pointer with C-style casts
       
    98 	handler=(*function)();
       
    99 	if (handler)
       
   100 		{
       
   101 		Unload();
       
   102 		CleanupStack::Pop(&plugIn);
       
   103 		iPlugIn=plugIn;
       
   104 		iHandler=handler;
       
   105 		iIsLoaded=ETrue;
       
   106 		}
       
   107 	else
       
   108 		CleanupStack::PopAndDestroy(&plugIn);
       
   109 	}
       
   110 
       
   111 /*object part*/
       
   112 
       
   113 void CClick::ConstructL(const TUid& aUid)
       
   114 	{
       
   115 	NewObjL();
       
   116 	iThirdUid=aUid;
       
   117 	}
       
   118 
       
   119 void CClick::CommandL(TInt aOpcode,const TAny* aCmdData)
       
   120 	{
       
   121 	TWsClickCmdUnion pData;
       
   122 	pData.any=aCmdData;
       
   123 	switch(aOpcode)
       
   124 		{
       
   125 		case EWsClickOpFree:
       
   126 			delete this;
       
   127 			break;
       
   128 		case EWsClickOpIsLoaded:
       
   129 			{
       
   130 			TUint reply=0;
       
   131 			if (IsHandler())
       
   132 				reply|=EClickLoaded;
       
   133 			if (iIsChangeable)
       
   134 				reply|=EClickLoadable;
       
   135 			SetReply(reply);
       
   136 			}
       
   137 			break;
       
   138 		case EWsClickOpUnLoad:
       
   139 			{
       
   140 			if(!KSecurityPolicy_WriteDeviceData().CheckPolicy(iWsOwner->ClientMessage(),__PLATSEC_DIAGNOSTIC_STRING("Capability check failed for RSoundPlugIn::UnLoad API")))
       
   141 				{
       
   142 				User::Leave(KErrPermissionDenied);
       
   143 				}
       
   144 			if (iIsChangeable)
       
   145 				Unload();
       
   146 			else
       
   147 				SetReply(KErrNotSupported);
       
   148 			}
       
   149 			break;
       
   150 		case EWsClickOpLoad:
       
   151 			{
       
   152 			if(!KSecurityPolicy_WriteDeviceData().CheckPolicy(iWsOwner->ClientMessage(),__PLATSEC_DIAGNOSTIC_STRING("Capability check failed for RSoundPlugIn::Load API")))
       
   153 				{
       
   154 				User::Leave(KErrPermissionDenied);
       
   155 				}
       
   156 			if (iIsChangeable)
       
   157 				LoadNewLibraryL(iWsOwner->BufferTPtr((TText*)(pData.Int+1),*pData.Int));
       
   158 			else 
       
   159 				SetReply(KErrNotSupported);
       
   160 			}
       
   161 			break;
       
   162 		case EWsClickOpSetKeyClick:
       
   163 			{
       
   164 			if(KSecurityPolicy_WriteDeviceData().CheckPolicy(iWsOwner->ClientMessage(),__PLATSEC_DIAGNOSTIC_STRING("Capability check failed for RSoundPlugIn::SetKeyClick API")))
       
   165 				{
       
   166 				iKeyClickEnabled=*pData.Bool;
       
   167 				}
       
   168 			}
       
   169 			break;
       
   170 		case EWsClickOpSetPenClick:
       
   171 			{
       
   172 			if(KSecurityPolicy_WriteDeviceData().CheckPolicy(iWsOwner->ClientMessage(),__PLATSEC_DIAGNOSTIC_STRING("Capability check failed for RSoundPlugIn::SetPenClick API")))
       
   173 				{
       
   174 				iPenClickEnabled=*pData.Bool;
       
   175 				}
       
   176 			}
       
   177 			break;
       
   178 		case EWsClickOpKeyClickEnabled:
       
   179 			SetReply(iKeyClickEnabled);
       
   180 			break;
       
   181 		case EWsClickOpPenClickEnabled:
       
   182 			SetReply(iPenClickEnabled);
       
   183 			break;
       
   184 		case EWsClickOpCommandReply:
       
   185 			{
       
   186 			TInt reply=RSoundPlugIn::ESoundWrongPlugIn;
       
   187 			if (iHandler && iThirdUid==ThirdUid() && iThirdUid!=TUid::Null())
       
   188 				TRAP(reply, reply = iHandler->CommandReplyL(*pData.Int,(TAny*)(pData.Int+1)));
       
   189 			SetReply(reply);
       
   190 			}
       
   191 			break;
       
   192 		default:
       
   193 			OwnerPanic(EWservPanicOpcode);
       
   194 			break;
       
   195 		}
       
   196 	}