sl@0: // Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // Definition of the class that manages the keyclick plugin sl@0: // sl@0: // sl@0: sl@0: #include "KEYCLICK.H" sl@0: sl@0: #include "server.h" sl@0: #include "W32CLICK.H" sl@0: #include "panics.h" sl@0: #include "inifile.h" sl@0: #include "advancedpointereventhelper.h" sl@0: sl@0: CClickMaker* CClick::iHandler=NULL; sl@0: TBool CClick::iIsChangeable=ETrue; sl@0: TBool CClick::iKeyClickOveride=EFalse; sl@0: TBool CClick::iKeyClickEnabled=ETrue; sl@0: TBool CClick::iPenClickEnabled=ETrue; sl@0: RLibrary CClick::iPlugIn; sl@0: TBool CClick::iIsLoaded=EFalse; sl@0: sl@0: const TUid KClickPlugInDllUid={0x10004F63}; sl@0: static _LIT_SECURITY_POLICY_C1(KSecurityPolicy_WriteDeviceData,ECapabilityWriteDeviceData); sl@0: sl@0: sl@0: /*static part*/ sl@0: sl@0: void CClick::InitStaticsL() sl@0: { sl@0: _LIT(KClickPlugin,"KEYCLICKPLUGIN"); sl@0: TPtrC plugInName; sl@0: if (WsIniFile->FindVar(KClickPlugin,plugInName)) sl@0: LoadNewLibraryL(plugInName); sl@0: _LIT(KClickFixed,"KEYCLICKPLUGINFIXED"); sl@0: iIsChangeable=!WsIniFile->FindVar(KClickFixed); sl@0: } sl@0: sl@0: void CClick::DeleteStatics() sl@0: { sl@0: if (iIsLoaded) sl@0: { sl@0: delete iHandler; sl@0: iHandler=NULL; sl@0: iPlugIn.Close(); sl@0: } sl@0: } sl@0: sl@0: void CClick::KeyEvent(TEventCode aType,const TKeyEvent& aEvent) sl@0: { sl@0: WS_ASSERT_DEBUG(iHandler, EWsPanicClickPluginNotLoaded); sl@0: if (iKeyClickEnabled && !iKeyClickOveride) sl@0: { sl@0: TRAP_IGNORE(iHandler->KeyEvent(aType,aEvent)); // TRAP leaves in case the plugin is badly behaved sl@0: } sl@0: } sl@0: sl@0: void CClick::PointerEvent(const TPoint& aScreenPos,const TAdvancedPointerEvent& aEvent) sl@0: { sl@0: WS_ASSERT_DEBUG(iHandler, EWsPanicClickPluginNotLoaded); sl@0: if (iPenClickEnabled) sl@0: { sl@0: TAdvancedPointerEvent event; sl@0: TAdvancedPointerEventHelper::Copy(aEvent,event); sl@0: event.iParentPosition=aScreenPos; sl@0: TRAP_IGNORE(iHandler->PointerEvent(event)); // TRAP leaves in case the plugin is badly behaved sl@0: } sl@0: } sl@0: sl@0: void CClick::OtherEvent(TInt aType,TAny* aParam) sl@0: { sl@0: WS_ASSERT_DEBUG(iHandler, EWsPanicClickPluginNotLoaded); sl@0: if (aType!=EEventPointer || iPenClickEnabled) sl@0: TRAP_IGNORE(iHandler->OtherEvent(aType,aParam)); // TRAP leaves in case the plugin is badly behaved sl@0: } sl@0: sl@0: void CClick::LoadNewLibraryL(const TDesC &aDllName) sl@0: { sl@0: WS_ASSERT_DEBUG(iIsChangeable, EWsPanicChangeClickPlugin); sl@0: const TUidType uidType(KDllUid,KClickPlugInDllUid); sl@0: RLibrary plugIn; sl@0: User::LeaveIfError(plugIn.Load(aDllName,uidType)); sl@0: CleanupClosePushL(plugIn); sl@0: CreateCClickHandler function; sl@0: CClickMaker* handler; sl@0: function=(CreateCClickHandler)User::LeaveIfNull((TAny*)plugIn.Lookup(1)); //Can only cast function pointer with C-style casts sl@0: handler=(*function)(); sl@0: if (handler) sl@0: { sl@0: Unload(); sl@0: CleanupStack::Pop(&plugIn); sl@0: iPlugIn=plugIn; sl@0: iHandler=handler; sl@0: iIsLoaded=ETrue; sl@0: } sl@0: else sl@0: CleanupStack::PopAndDestroy(&plugIn); sl@0: } sl@0: sl@0: /*object part*/ sl@0: sl@0: void CClick::ConstructL(const TUid& aUid) sl@0: { sl@0: NewObjL(); sl@0: iThirdUid=aUid; sl@0: } sl@0: sl@0: void CClick::CommandL(TInt aOpcode,const TAny* aCmdData) sl@0: { sl@0: TWsClickCmdUnion pData; sl@0: pData.any=aCmdData; sl@0: switch(aOpcode) sl@0: { sl@0: case EWsClickOpFree: sl@0: delete this; sl@0: break; sl@0: case EWsClickOpIsLoaded: sl@0: { sl@0: TUint reply=0; sl@0: if (IsHandler()) sl@0: reply|=EClickLoaded; sl@0: if (iIsChangeable) sl@0: reply|=EClickLoadable; sl@0: SetReply(reply); sl@0: } sl@0: break; sl@0: case EWsClickOpUnLoad: sl@0: { sl@0: if(!KSecurityPolicy_WriteDeviceData().CheckPolicy(iWsOwner->ClientMessage(),__PLATSEC_DIAGNOSTIC_STRING("Capability check failed for RSoundPlugIn::UnLoad API"))) sl@0: { sl@0: User::Leave(KErrPermissionDenied); sl@0: } sl@0: if (iIsChangeable) sl@0: Unload(); sl@0: else sl@0: SetReply(KErrNotSupported); sl@0: } sl@0: break; sl@0: case EWsClickOpLoad: sl@0: { sl@0: if(!KSecurityPolicy_WriteDeviceData().CheckPolicy(iWsOwner->ClientMessage(),__PLATSEC_DIAGNOSTIC_STRING("Capability check failed for RSoundPlugIn::Load API"))) sl@0: { sl@0: User::Leave(KErrPermissionDenied); sl@0: } sl@0: if (iIsChangeable) sl@0: LoadNewLibraryL(iWsOwner->BufferTPtr((TText*)(pData.Int+1),*pData.Int)); sl@0: else sl@0: SetReply(KErrNotSupported); sl@0: } sl@0: break; sl@0: case EWsClickOpSetKeyClick: sl@0: { sl@0: if(KSecurityPolicy_WriteDeviceData().CheckPolicy(iWsOwner->ClientMessage(),__PLATSEC_DIAGNOSTIC_STRING("Capability check failed for RSoundPlugIn::SetKeyClick API"))) sl@0: { sl@0: iKeyClickEnabled=*pData.Bool; sl@0: } sl@0: } sl@0: break; sl@0: case EWsClickOpSetPenClick: sl@0: { sl@0: if(KSecurityPolicy_WriteDeviceData().CheckPolicy(iWsOwner->ClientMessage(),__PLATSEC_DIAGNOSTIC_STRING("Capability check failed for RSoundPlugIn::SetPenClick API"))) sl@0: { sl@0: iPenClickEnabled=*pData.Bool; sl@0: } sl@0: } sl@0: break; sl@0: case EWsClickOpKeyClickEnabled: sl@0: SetReply(iKeyClickEnabled); sl@0: break; sl@0: case EWsClickOpPenClickEnabled: sl@0: SetReply(iPenClickEnabled); sl@0: break; sl@0: case EWsClickOpCommandReply: sl@0: { sl@0: TInt reply=RSoundPlugIn::ESoundWrongPlugIn; sl@0: if (iHandler && iThirdUid==ThirdUid() && iThirdUid!=TUid::Null()) sl@0: TRAP(reply, reply = iHandler->CommandReplyL(*pData.Int,(TAny*)(pData.Int+1))); sl@0: SetReply(reply); sl@0: } sl@0: break; sl@0: default: sl@0: OwnerPanic(EWservPanicOpcode); sl@0: break; sl@0: } sl@0: }