From a00a3f0067dbe1281d3b94bfe35098e8d5c87ba5 Mon Sep 17 00:00:00 2001 From: Agnelo Vaz Date: Tue, 11 Apr 2017 17:05:43 +0100 Subject: [PATCH] Adding deviceName to KeyEvent Integ Change-Id: If40b705d8e5ba0e42808365afecdf5fb2ead43ae --- automated-tests/src/dali/utc-Dali-KeyEvent.cpp | 24 ++++++++++- automated-tests/src/dali/utc-Dali-Stage.cpp | 18 ++++---- dali/devel-api/events/key-event-devel.h | 37 +++++++++++++++++ dali/integration-api/events/key-event-integ.cpp | 12 ++++-- dali/integration-api/events/key-event-integ.h | 13 ++++-- dali/internal/event/events/key-event-processor.cpp | 3 +- dali/public-api/events/key-event.cpp | 48 ++++++++++++++++++++++ 7 files changed, 138 insertions(+), 17 deletions(-) create mode 100644 dali/devel-api/events/key-event-devel.h diff --git a/automated-tests/src/dali/utc-Dali-KeyEvent.cpp b/automated-tests/src/dali/utc-Dali-KeyEvent.cpp index 69f8af1..dde1fec 100644 --- a/automated-tests/src/dali/utc-Dali-KeyEvent.cpp +++ b/automated-tests/src/dali/utc-Dali-KeyEvent.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include @@ -257,8 +258,9 @@ int UtcDaliIntegrationKeyEvent(void) const int keyModifier(312); const unsigned long timeStamp(132); const Integration::KeyEvent::State keyState(Integration::KeyEvent::Up); + const std::string deviceName("hwKeyboard"); - Integration::KeyEvent keyEvent(keyName, keyString, keyCode, keyModifier, timeStamp, keyState); + Integration::KeyEvent keyEvent(keyName, keyString, keyCode, keyModifier, timeStamp, keyState, deviceName ); DALI_TEST_EQUALS( keyEvent.type, Integration::Event::Key, TEST_LOCATION ); DALI_TEST_CHECK( keyEvent.keyName == keyName ); DALI_TEST_CHECK( keyEvent.keyString == keyString ); @@ -266,6 +268,7 @@ int UtcDaliIntegrationKeyEvent(void) DALI_TEST_EQUALS( keyEvent.keyModifier, keyModifier, TEST_LOCATION ); DALI_TEST_EQUALS( keyEvent.time, timeStamp, TEST_LOCATION ); DALI_TEST_EQUALS( keyEvent.state, keyState, TEST_LOCATION); + DALI_TEST_EQUALS( keyEvent.deviceName, deviceName, TEST_LOCATION); } END_TEST; } @@ -285,6 +288,25 @@ int UtcDaliIntegrationKeyEventConvertor(void) DALI_TEST_EQUALS( keyEvent.keyModifier, SHIFT_MODIFIER, TEST_LOCATION ); DALI_TEST_EQUALS( keyEvent.time, 0lu, TEST_LOCATION ); DALI_TEST_EQUALS( keyEvent.state, Integration::KeyEvent::Down, TEST_LOCATION); + DALI_TEST_EQUALS( keyEvent.deviceName, "", TEST_LOCATION); + + END_TEST; +} + +int UtcDaliKeyEventSetDeviceName(void) +{ + TestApplication application; + + KeyEvent event(TEST_STRING_1,"i", 99, SHIFT_MODIFIER, 0lu, KeyEvent::Down); + + DALI_TEST_EQUALS( DevelKeyEvent::GetDeviceName( event ), "", TEST_LOCATION); + + DevelKeyEvent::SetDeviceName( event, "finger" ); + + DALI_TEST_EQUALS( DevelKeyEvent::GetDeviceName( event ), "finger", TEST_LOCATION); + + KeyEvent event2; + DALI_TEST_EQUALS( DevelKeyEvent::GetDeviceName( event2 ), "", TEST_LOCATION); END_TEST; } diff --git a/automated-tests/src/dali/utc-Dali-Stage.cpp b/automated-tests/src/dali/utc-Dali-Stage.cpp index 459061f..b8c3504 100644 --- a/automated-tests/src/dali/utc-Dali-Stage.cpp +++ b/automated-tests/src/dali/utc-Dali-Stage.cpp @@ -44,6 +44,8 @@ void stage_test_cleanup(void) namespace { +const std::string DEFAULT_DEVICE_NAME("hwKeyboard"); + // Functor for EventProcessingFinished signal struct EventProcessingFinishedFunctor { @@ -881,7 +883,7 @@ int UtcDaliStageKeyEventGeneratedSignalP(void) KeyEventGeneratedReceivedFunctor functor2( data2 ); GetImplementation( stage ).ConnectSignal( &application, "keyEventGenerated", functor2 ); - Integration::KeyEvent event( "a", "a", 0, 0, 0, Integration::KeyEvent::Up ); + Integration::KeyEvent event( "a", "a", 0, 0, 0, Integration::KeyEvent::Up, DEFAULT_DEVICE_NAME ); application.ProcessEvent( event ); DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION ); @@ -892,7 +894,7 @@ int UtcDaliStageKeyEventGeneratedSignalP(void) data.Reset(); - Integration::KeyEvent event2( "i", "i", 0, 0, 0, Integration::KeyEvent::Up ); + Integration::KeyEvent event2( "i", "i", 0, 0, 0, Integration::KeyEvent::Up, DEFAULT_DEVICE_NAME ); application.ProcessEvent( event2 ); DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION ); @@ -903,7 +905,7 @@ int UtcDaliStageKeyEventGeneratedSignalP(void) data.Reset(); - Integration::KeyEvent event3( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ); + Integration::KeyEvent event3( "a", "a", 0, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME ); application.ProcessEvent( event3 ); DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION ); @@ -914,7 +916,7 @@ int UtcDaliStageKeyEventGeneratedSignalP(void) data.Reset(); - Integration::KeyEvent event4( "a", "a", 0, 0, 0, Integration::KeyEvent::Up ); + Integration::KeyEvent event4( "a", "a", 0, 0, 0, Integration::KeyEvent::Up, DEFAULT_DEVICE_NAME ); application.ProcessEvent( event4 ); DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION ); @@ -934,7 +936,7 @@ int UtcDaliStageSignalKeyEventP(void) KeyEventReceivedFunctor functor( data ); stage.KeyEventSignal().Connect( &application, functor ); - Integration::KeyEvent event( "i", "i", 0, 0, 0, Integration::KeyEvent::Down ); + Integration::KeyEvent event( "i", "i", 0, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME ); application.ProcessEvent( event ); DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION ); @@ -945,7 +947,7 @@ int UtcDaliStageSignalKeyEventP(void) data.Reset(); - Integration::KeyEvent event2( "i", "i", 0, 0, 0, Integration::KeyEvent::Up ); + Integration::KeyEvent event2( "i", "i", 0, 0, 0, Integration::KeyEvent::Up, DEFAULT_DEVICE_NAME ); application.ProcessEvent( event2 ); DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION ); @@ -956,7 +958,7 @@ int UtcDaliStageSignalKeyEventP(void) data.Reset(); - Integration::KeyEvent event3( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ); + Integration::KeyEvent event3( "a", "a", 0, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME ); application.ProcessEvent( event3 ); DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION ); @@ -967,7 +969,7 @@ int UtcDaliStageSignalKeyEventP(void) data.Reset(); - Integration::KeyEvent event4( "a", "a", 0, 0, 0, Integration::KeyEvent::Up ); + Integration::KeyEvent event4( "a", "a", 0, 0, 0, Integration::KeyEvent::Up, DEFAULT_DEVICE_NAME ); application.ProcessEvent( event4 ); DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION ); diff --git a/dali/devel-api/events/key-event-devel.h b/dali/devel-api/events/key-event-devel.h new file mode 100644 index 0000000..87af795 --- /dev/null +++ b/dali/devel-api/events/key-event-devel.h @@ -0,0 +1,37 @@ +#ifndef DALI_KEY_EVENT_DEVEL_H +#define DALI_KEY_EVENT_DEVEL_H + +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// INTERNAL_INCLUDES +#include + +namespace Dali +{ + +namespace DevelKeyEvent +{ + std::string GetDeviceName( KeyEvent& keyEvent ); + + void SetDeviceName( KeyEvent& keyEvent, std::string deviceName ); + +} + +} + +#endif //DALI_KEY_EVENT_DEVEL_H diff --git a/dali/integration-api/events/key-event-integ.cpp b/dali/integration-api/events/key-event-integ.cpp index 425f224..ed46ccf 100644 --- a/dali/integration-api/events/key-event-integ.cpp +++ b/dali/integration-api/events/key-event-integ.cpp @@ -31,18 +31,21 @@ KeyEvent::KeyEvent() keyCode(-1), keyModifier(0), time(0), - state(KeyEvent::Down) + state(KeyEvent::Down), + deviceName("") { } -KeyEvent::KeyEvent(const std::string& keyName, const std::string& keyString, int keyCode, int keyModifier, unsigned long timeStamp, const State& keyState) +KeyEvent::KeyEvent( const std::string& keyName, const std::string& keyString, int keyCode, int keyModifier, + unsigned long timeStamp, const State& keyState, const std::string deviceName ) : Event(Key), keyName(keyName), keyString(keyString), keyCode(keyCode), keyModifier(keyModifier), time(timeStamp), - state(keyState) + state(keyState), + deviceName(deviceName) { } @@ -53,7 +56,8 @@ KeyEvent::KeyEvent( const Dali::KeyEvent& event ) keyCode( event.keyCode ), keyModifier( event.keyModifier ), time( event.time ), - state( static_cast< Integration::KeyEvent::State >( event.state ) ) + state( static_cast< Integration::KeyEvent::State >( event.state ) ), + deviceName("") { } diff --git a/dali/integration-api/events/key-event-integ.h b/dali/integration-api/events/key-event-integ.h index 39543ca..e448a30 100644 --- a/dali/integration-api/events/key-event-integ.h +++ b/dali/integration-api/events/key-event-integ.h @@ -59,15 +59,17 @@ struct KeyEvent : public Event * @param[in] keyString A string of input characters or key pressed * @param[in] keyCode The unique key code for the key pressed. * @param[in] keyModifier The key modifier for special keys like shift and alt - * @param[in] timeStamp The time (in ms) that the key event occurred. - * @param[in] keyState The state of the key event. + * @param[in] timeStamp The time (in ms) that the key event occurred. + * @param[in] keyState The state of the key event. + * @param[in] deviceName Name of device KeyEvent originated from */ KeyEvent(const std::string& keyName, const std::string& keyString, int keyCode, int keyModifier, unsigned long timeStamp, - const State& keyState); + const State& keyState, + const std::string deviceName ); /* * Constructor, creates a Integration::KeyEvent from a Dali::KeyEvent @@ -113,6 +115,11 @@ struct KeyEvent : public Event */ State state; + /** + * Name of device KeyEvent originated from + */ + std::string deviceName; + }; } // namespace Integration diff --git a/dali/internal/event/events/key-event-processor.cpp b/dali/internal/event/events/key-event-processor.cpp index 86d9592..9d5b6de 100644 --- a/dali/internal/event/events/key-event-processor.cpp +++ b/dali/internal/event/events/key-event-processor.cpp @@ -19,6 +19,7 @@ #include // INTERNAL INCLUDES +#include #include #include #include @@ -43,7 +44,7 @@ void KeyEventProcessor::ProcessKeyEvent(const Integration::KeyEvent& event) { bool consumed = false; KeyEvent keyEvent(event.keyName, event.keyString, event.keyCode, event.keyModifier, event.time, static_cast(event.state)); - + DevelKeyEvent::SetDeviceName( keyEvent, event.deviceName ); // Emit the key event signal from stage. consumed = mStage.EmitKeyEventGeneratedSignal( keyEvent ); diff --git a/dali/public-api/events/key-event.cpp b/dali/public-api/events/key-event.cpp index 0645ed1..7ed937f 100644 --- a/dali/public-api/events/key-event.cpp +++ b/dali/public-api/events/key-event.cpp @@ -18,6 +18,10 @@ // CLASS HEADER #include +// INTERNAL INCLUDES +#include +#include + namespace Dali { @@ -28,6 +32,17 @@ const unsigned int MODIFIER_CTRL = 0x2; const unsigned int MODIFIER_ALT = 0x4; const int KEY_INVALID_CODE = -1; +struct KeyEventImpl +{ + std::string deviceName; +}; + +typedef std::map< KeyEvent*, KeyEventImpl*> KeyEventMap; +typedef KeyEventMap::const_iterator KeyEventMapIter; + + +KeyEventMap keyEventImplMap; + } KeyEvent::KeyEvent() @@ -38,6 +53,8 @@ KeyEvent::KeyEvent() time(0), state(KeyEvent::Down) { + KeyEventImpl* impl = new KeyEventImpl; + keyEventImplMap[this] = impl; } KeyEvent::KeyEvent(const std::string& keyName, const std::string& keyString, int keyCode, int keyModifier,unsigned long timeStamp, const State& keyState) @@ -48,10 +65,14 @@ KeyEvent::KeyEvent(const std::string& keyName, const std::string& keyString, int time(timeStamp), state(keyState) { + KeyEventImpl* impl = new KeyEventImpl; + keyEventImplMap[this] = impl; } KeyEvent::~KeyEvent() { + delete keyEventImplMap[this]; + keyEventImplMap.erase( this ); } bool KeyEvent::IsShiftModifier() const @@ -84,4 +105,31 @@ bool KeyEvent::IsAltModifier() const return false; } +std::string DevelKeyEvent::GetDeviceName( KeyEvent& keyEvent ) +{ + KeyEventMapIter search; + + search = keyEventImplMap.find( &keyEvent ); + + std::string result = ""; + + if( search != keyEventImplMap.end()) + { + result = search->second->deviceName; + } + + return result; +} + +void DevelKeyEvent::SetDeviceName( KeyEvent& keyEvent, std::string deviceName ) +{ + KeyEventMapIter search = keyEventImplMap.find( &keyEvent ); + + if( search != keyEventImplMap.end()) + { + search->second->deviceName = deviceName; + } +} + + } // namespace Dali -- 2.7.4