Added device information in TouchData/KeyEvent
[platform/core/uifw/dali-core.git] / dali / internal / event / events / key-event-impl.cpp
1 /*
2  * Copyright (c) 2017 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/internal/event/events/key-event-impl.h>
20
21 // INTERNAL INCLUDES
22 #include <dali/devel-api/common/map-wrapper.h>
23
24 namespace Dali
25 {
26
27 namespace
28 {
29
30 typedef std::map< const KeyEvent*, Internal::KeyEventImpl*> KeyEventMap;
31 typedef KeyEventMap::iterator KeyEventMapIter;
32
33 KeyEventMap keyEventImplMap;
34
35 }
36
37 namespace Internal
38 {
39
40 KeyEventImpl::KeyEventImpl( KeyEvent* keyEvent )
41 : mDeviceName( "" ),
42   mDeviceClass( DevelDevice::Class::NONE ),
43   mDeviceSubclass( DevelDevice::Subclass::NONE )
44 {
45   keyEventImplMap[keyEvent] = this;
46 }
47
48 KeyEventImpl::~KeyEventImpl()
49 {
50   for( KeyEventMapIter iter = keyEventImplMap.begin(); iter != keyEventImplMap.end(); ++iter )
51   {
52     if( this == iter->second )
53     {
54       keyEventImplMap.erase( iter );
55       break;
56     }
57   }
58 }
59
60 KeyEventImpl& KeyEventImpl::operator=( const KeyEventImpl& rhs )
61 {
62   if( this != &rhs )
63   {
64     mDeviceName = rhs.mDeviceName;
65     mDeviceClass = rhs.mDeviceClass;
66     mDeviceSubclass = rhs.mDeviceSubclass;
67   }
68
69   return *this;
70 }
71
72 std::string KeyEventImpl::GetDeviceName() const
73 {
74   return mDeviceName;
75 }
76
77 void KeyEventImpl::SetDeviceName( const std::string& deviceName )
78 {
79   mDeviceName = deviceName;
80 }
81
82 DevelDevice::Class::Type KeyEventImpl::GetDeviceClass() const
83 {
84   return mDeviceClass;
85 }
86
87 void KeyEventImpl::SetDeviceClass( DevelDevice::Class::Type deviceClass )
88 {
89   mDeviceClass = deviceClass;
90 }
91
92 DevelDevice::Subclass::Type KeyEventImpl::GetDeviceSubclass() const
93 {
94   return mDeviceSubclass;
95 }
96
97 void KeyEventImpl::SetDeviceSubclass( DevelDevice::Subclass::Type deviceSubclass )
98 {
99   mDeviceSubclass = deviceSubclass;
100 }
101
102 } // namsespace Internal
103
104 Internal::KeyEventImpl* GetImplementation( KeyEvent* keyEvent )
105 {
106   return keyEventImplMap[keyEvent];
107 }
108
109 const Internal::KeyEventImpl* GetImplementation( const KeyEvent* keyEvent )
110 {
111   return keyEventImplMap[keyEvent];
112 }
113
114 } // namespace Dali