~alan-griffiths/mir/knee-jerk-mir_surface_state_automatic

« back to all changes in this revision

Viewing changes to tests/utils/fake_event_hub.cpp

  • Committer: Kevin DuBois
  • Date: 2012-11-13 01:36:29 UTC
  • mfrom: (245 trunk)
  • mto: This revision was merged to the branch mainline in revision 246.
  • Revision ID: kevin.dubois@canonical.com-20121113013629-q4496w4mp5e33auk
merge in base branch. move the demo clients to a new directory, examples/

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "mir_test/fake_event_hub.h"
 
2
 
 
3
using droidinput::AxisInfo;
 
4
using droidinput::InputDeviceIdentifier;
 
5
using droidinput::PropertyMap;
 
6
using droidinput::Vector;
 
7
using droidinput::String8;
 
8
using droidinput::RawAbsoluteAxisInfo;
 
9
using droidinput::RawEvent;
 
10
using droidinput::sp;
 
11
using droidinput::status_t;
 
12
using droidinput::KeyCharacterMap;
 
13
using droidinput::VirtualKeyDefinition;
 
14
 
 
15
namespace mi = mir::input;
 
16
namespace mia = mir::input::android;
 
17
 
 
18
mia::FakeEventHub::FakeEventHub()
 
19
{
 
20
}
 
21
 
 
22
mia::FakeEventHub::~FakeEventHub()
 
23
{
 
24
}
 
25
 
 
26
uint32_t mia::FakeEventHub::getDeviceClasses(int32_t deviceId) const
 
27
{
 
28
    if (deviceId == droidinput::BUILT_IN_KEYBOARD_ID)
 
29
    {
 
30
        return droidinput::INPUT_DEVICE_CLASS_KEYBOARD;
 
31
    }
 
32
    auto fake_device_iterator = device_from_id.find(deviceId);
 
33
 
 
34
    if (fake_device_iterator != device_from_id.end())
 
35
    {
 
36
        return fake_device_iterator->second.classes;
 
37
    }
 
38
    else
 
39
    {
 
40
        return 0;
 
41
    }
 
42
}
 
43
 
 
44
InputDeviceIdentifier mia::FakeEventHub::getDeviceIdentifier(int32_t deviceId) const
 
45
{
 
46
    auto fake_device_iterator = device_from_id.find(deviceId);
 
47
 
 
48
    if (fake_device_iterator != device_from_id.end())
 
49
    {
 
50
        return fake_device_iterator->second.identifier;
 
51
    }
 
52
    else
 
53
    {
 
54
        return InputDeviceIdentifier();
 
55
    }
 
56
}
 
57
 
 
58
void mia::FakeEventHub::getConfiguration(int32_t deviceId, PropertyMap* outConfiguration) const
 
59
{
 
60
    (void)deviceId;
 
61
    (void)outConfiguration;
 
62
}
 
63
 
 
64
status_t mia::FakeEventHub::getAbsoluteAxisInfo(int32_t deviceId, int axis,
 
65
        RawAbsoluteAxisInfo* outAxisInfo) const
 
66
{
 
67
    (void)deviceId;
 
68
    (void)axis;
 
69
    (void)outAxisInfo;
 
70
    return -1;
 
71
}
 
72
 
 
73
bool mia::FakeEventHub::hasRelativeAxis(int32_t deviceId, int axis) const
 
74
{
 
75
    (void)deviceId;
 
76
    (void)axis;
 
77
    return false;
 
78
}
 
79
 
 
80
bool mia::FakeEventHub::hasInputProperty(int32_t deviceId, int property) const
 
81
{
 
82
    auto fake_device_iterator = device_from_id.find(deviceId);
 
83
 
 
84
    if (fake_device_iterator != device_from_id.end())
 
85
    {
 
86
        auto property_iterator =
 
87
            fake_device_iterator->second.input_properties.find(property);
 
88
 
 
89
        if (property_iterator != fake_device_iterator->second.input_properties.end())
 
90
        {
 
91
            return property_iterator->second;
 
92
        }
 
93
        else
 
94
        {
 
95
            return false;
 
96
        }
 
97
    }
 
98
    else
 
99
    {
 
100
        return false;
 
101
    }
 
102
}
 
103
 
 
104
status_t mia::FakeEventHub::mapKey(int32_t deviceId, int32_t scanCode, int32_t usageCode,
 
105
                              int32_t* outKeycode, uint32_t* outFlags) const
 
106
{
 
107
    (void)deviceId;
 
108
    (void)usageCode;
 
109
    *outKeycode = scanCode;
 
110
    *outFlags = 0;
 
111
    return droidinput::OK;
 
112
}
 
113
 
 
114
status_t mia::FakeEventHub::mapAxis(int32_t deviceId, int32_t scanCode,
 
115
                               AxisInfo* outAxisInfo) const
 
116
{
 
117
    (void)deviceId;
 
118
    (void)scanCode;
 
119
    (void)outAxisInfo;
 
120
    return -1;
 
121
}
 
122
 
 
123
void mia::FakeEventHub::setExcludedDevices(const Vector<String8>& devices)
 
124
{
 
125
    (void)devices;
 
126
}
 
127
 
 
128
size_t mia::FakeEventHub::getEvents(int timeoutMillis, RawEvent* buffer, size_t bufferSize)
 
129
{
 
130
    std::lock_guard<std::mutex> lg(guard);
 
131
    
 
132
    (void) timeoutMillis;
 
133
    size_t num_events_obtained = 0;
 
134
    
 
135
    for (size_t i = 0; i < bufferSize && events_available.size() > 0; ++i)
 
136
    {
 
137
        buffer[i] = events_available.front();
 
138
        events_available.pop_front();
 
139
        ++num_events_obtained;
 
140
    }
 
141
    
 
142
    return num_events_obtained;
 
143
}
 
144
 
 
145
int32_t mia::FakeEventHub::getScanCodeState(int32_t deviceId, int32_t scanCode) const
 
146
{
 
147
    (void)deviceId;
 
148
    (void)scanCode;
 
149
    return AKEY_STATE_UNKNOWN;
 
150
}
 
151
 
 
152
int32_t mia::FakeEventHub::getKeyCodeState(int32_t deviceId, int32_t keyCode) const
 
153
{
 
154
    (void)deviceId;
 
155
    (void)keyCode;
 
156
    return AKEY_STATE_UNKNOWN;
 
157
}
 
158
 
 
159
int32_t mia::FakeEventHub::getSwitchState(int32_t deviceId, int32_t sw) const
 
160
{
 
161
    (void)deviceId;
 
162
    (void)sw;
 
163
    return AKEY_STATE_UNKNOWN;
 
164
}
 
165
 
 
166
status_t mia::FakeEventHub::getAbsoluteAxisValue(int32_t deviceId, int32_t axis,
 
167
        int32_t* outValue) const
 
168
{
 
169
    (void)deviceId;
 
170
    (void)axis;
 
171
    (void)outValue;
 
172
    return -1;
 
173
}
 
174
 
 
175
bool mia::FakeEventHub::markSupportedKeyCodes(int32_t deviceId, size_t numCodes,
 
176
        const int32_t* keyCodes,
 
177
        uint8_t* outFlags) const
 
178
{
 
179
    (void)deviceId;
 
180
    (void)numCodes;
 
181
    (void)keyCodes;
 
182
    (void)outFlags;
 
183
    return true;
 
184
}
 
185
 
 
186
bool mia::FakeEventHub::hasScanCode(int32_t deviceId, int32_t scanCode) const
 
187
{
 
188
    (void)deviceId;
 
189
    (void)scanCode;
 
190
    return false;
 
191
}
 
192
 
 
193
bool mia::FakeEventHub::hasLed(int32_t deviceId, int32_t led) const
 
194
{
 
195
    (void)deviceId;
 
196
    (void)led;
 
197
    return false;
 
198
}
 
199
 
 
200
void mia::FakeEventHub::setLedState(int32_t deviceId, int32_t led, bool on)
 
201
{
 
202
    (void)deviceId;
 
203
    (void)led;
 
204
    (void)on;
 
205
}
 
206
 
 
207
void mia::FakeEventHub::getVirtualKeyDefinitions(int32_t deviceId,
 
208
        Vector<VirtualKeyDefinition>& outVirtualKeys) const
 
209
{
 
210
    (void)deviceId;
 
211
    (void)outVirtualKeys;
 
212
}
 
213
 
 
214
sp<KeyCharacterMap> mia::FakeEventHub::getKeyCharacterMap(int32_t deviceId) const
 
215
{
 
216
    (void)deviceId;
 
217
    return sp<KeyCharacterMap>();
 
218
}
 
219
 
 
220
bool mia::FakeEventHub::setKeyboardLayoutOverlay(int32_t deviceId,
 
221
        const sp<KeyCharacterMap>& map)
 
222
{
 
223
    (void)deviceId;
 
224
    (void)map;
 
225
    return true;
 
226
}
 
227
 
 
228
void mia::FakeEventHub::vibrate(int32_t deviceId, nsecs_t duration)
 
229
{
 
230
    (void)deviceId;
 
231
    (void)duration;
 
232
}
 
233
 
 
234
void mia::FakeEventHub::cancelVibrate(int32_t deviceId)
 
235
{
 
236
    (void)deviceId;
 
237
}
 
238
 
 
239
void mia::FakeEventHub::requestReopenDevices()
 
240
{
 
241
}
 
242
 
 
243
void mia::FakeEventHub::wake()
 
244
{
 
245
}
 
246
 
 
247
void mia::FakeEventHub::dump(droidinput::String8& dump)
 
248
{
 
249
    (void)dump;
 
250
}
 
251
 
 
252
void mia::FakeEventHub::monitor()
 
253
{
 
254
}
 
255
 
 
256
void mia::FakeEventHub::synthesize_builtin_keyboard_added()
 
257
{
 
258
    std::lock_guard<std::mutex> lg(guard);
 
259
    
 
260
    RawEvent event;
 
261
    event.when = 0;
 
262
    event.deviceId = droidinput::BUILT_IN_KEYBOARD_ID;
 
263
    event.type = EventHubInterface::DEVICE_ADDED;
 
264
    events_available.push_back(event);
 
265
 
 
266
    event.when = 0;
 
267
    event.type = EventHubInterface::FINISHED_DEVICE_SCAN;
 
268
    
 
269
    events_available.push_back(event);
 
270
}
 
271
 
 
272
void mia::FakeEventHub::synthesize_key_event(int keycode)
 
273
{
 
274
    RawEvent event;
 
275
    event.when = 0;
 
276
    event.type = EV_KEY;
 
277
    event.code = keycode;
 
278
    event.value = 1;
 
279
    event.deviceId = droidinput::BUILT_IN_KEYBOARD_ID;
 
280
    
 
281
    std::lock_guard<std::mutex> lg(guard);
 
282
    events_available.push_back(event);
 
283
}
 
284
 
 
285