michael@0: /* michael@0: * Copyright (C) 2008 The Android Open Source Project michael@0: * michael@0: * Licensed under the Apache License, Version 2.0 (the "License"); michael@0: * you may not use this file except in compliance with the License. michael@0: * You may obtain a copy of the License at michael@0: * michael@0: * http://www.apache.org/licenses/LICENSE-2.0 michael@0: * michael@0: * Unless required by applicable law or agreed to in writing, software michael@0: * distributed under the License is distributed on an "AS IS" BASIS, michael@0: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. michael@0: * See the License for the specific language governing permissions and michael@0: * limitations under the License. michael@0: */ michael@0: michael@0: #ifndef _ANDROIDFW_KEY_LAYOUT_MAP_H michael@0: #define _ANDROIDFW_KEY_LAYOUT_MAP_H michael@0: michael@0: #include michael@0: #include michael@0: #include michael@0: #include "Tokenizer.h" michael@0: #include michael@0: michael@0: namespace android { michael@0: michael@0: struct AxisInfo { michael@0: enum Mode { michael@0: // Axis value is reported directly. michael@0: MODE_NORMAL = 0, michael@0: // Axis value should be inverted before reporting. michael@0: MODE_INVERT = 1, michael@0: // Axis value should be split into two axes michael@0: MODE_SPLIT = 2, michael@0: }; michael@0: michael@0: // Axis mode. michael@0: Mode mode; michael@0: michael@0: // Axis id. michael@0: // When split, this is the axis used for values smaller than the split position. michael@0: int32_t axis; michael@0: michael@0: // When split, this is the axis used for values after higher than the split position. michael@0: int32_t highAxis; michael@0: michael@0: // The split value, or 0 if not split. michael@0: int32_t splitValue; michael@0: michael@0: // The flat value, or -1 if none. michael@0: int32_t flatOverride; michael@0: michael@0: AxisInfo() : mode(MODE_NORMAL), axis(-1), highAxis(-1), splitValue(0), flatOverride(-1) { michael@0: } michael@0: }; michael@0: michael@0: /** michael@0: * Describes a mapping from keyboard scan codes and joystick axes to Android key codes and axes. michael@0: * michael@0: * This object is immutable after it has been loaded. michael@0: */ michael@0: class KeyLayoutMap : public RefBase { michael@0: public: michael@0: static status_t load(const String8& filename, sp* outMap); michael@0: michael@0: status_t mapKey(int32_t scanCode, int32_t usageCode, michael@0: int32_t* outKeyCode, uint32_t* outFlags) const; michael@0: status_t findScanCodesForKey(int32_t keyCode, Vector* outScanCodes) const; michael@0: michael@0: status_t mapAxis(int32_t scanCode, AxisInfo* outAxisInfo) const; michael@0: michael@0: protected: michael@0: virtual ~KeyLayoutMap(); michael@0: michael@0: private: michael@0: struct Key { michael@0: int32_t keyCode; michael@0: uint32_t flags; michael@0: }; michael@0: michael@0: KeyedVector mKeysByScanCode; michael@0: KeyedVector mKeysByUsageCode; michael@0: KeyedVector mAxes; michael@0: michael@0: KeyLayoutMap(); michael@0: michael@0: const Key* getKey(int32_t scanCode, int32_t usageCode) const; michael@0: michael@0: class Parser { michael@0: KeyLayoutMap* mMap; michael@0: Tokenizer* mTokenizer; michael@0: michael@0: public: michael@0: Parser(KeyLayoutMap* map, Tokenizer* tokenizer); michael@0: ~Parser(); michael@0: status_t parse(); michael@0: michael@0: private: michael@0: status_t parseKey(); michael@0: status_t parseAxis(); michael@0: }; michael@0: }; michael@0: michael@0: } // namespace android michael@0: michael@0: #endif // _ANDROIDFW_KEY_LAYOUT_MAP_H