1 /*
2  * Copyright (C) 2017 The Android Open Source Project
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 #ifndef HIDUTIL_HIDLOCAL_H_
17 #define HIDUTIL_HIDLOCAL_H_
18 
19 #include "HidItem.h"
20 #include "TriState.h"
21 #include <cstddef>
22 #include <vector>
23 
24 namespace HidUtil {
25 
26 // A set of local states that parser has to keep track during parsing.
27 // They are all specified in HID spec v1.11 section 6.2.2.8
28 struct HidLocal {
29     // add a token to change local states, return value indicates if operation is successful
30     bool append(const HidItem &i);
31     // clear all local states. This need to be done after each main tag
32     void clear();
33 
34     // multiple usage, designator or strings may exist for single input/output/feature report
35     uint32_t getUsage(size_t index) const;
36     uint32_t getDesignator(size_t index) const;
37     uint32_t getString(size_t index) const;
38 
39     std::vector<uint32_t> usage;
40     // keep track of usage min when expecting a usage max
41     tri_uint usageMin;
42 
43     std::vector<uint32_t> designator;
44     // keep track of designator min when expecting designator max
45     tri_uint designatorMin;
46 
47     std::vector<uint32_t> string;
48     // keep track of string min when expecting string max
49     tri_uint stringMin;
50 
51     tri_uint delimeter;
52 };
53 } // namespace HidUtil
54 
55 #endif // HIDUTIL_HIDLOCAL_H_
56