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_HIDGLOBAL_H_
17 #define HIDUTIL_HIDGLOBAL_H_
18 
19 #include "HidItem.h"
20 #include "TriState.h"
21 
22 namespace HidUtil {
23 // A set of global states that parser has to keep track during parsing.
24 // They are all specified in HID spec v1.11 section 6.2.2.7
25 struct HidGlobal {
26     // add a token and change global states, returns value indicates if operation is successful
27     bool append(const HidItem &i);
28 
29     tri_uint usagePage;
30     tri_int  logicalMin;
31     tri_int  logicalMax;
32     tri_int  physicalMin;
33     tri_int  physicalMax;
34     tri_uint exponent;
35     tri_uint unit;
36     tri_uint reportSize;
37     tri_uint reportId;
38     tri_uint reportCount;
39 };
40 
41 // HID specs allows PUSH and POP to save a snapshot of current global states and come back to the
42 // saved sates later. HidStack manages this logic. Note that PUSH and POP are also HidItems, so
43 // there is no explicit push and pop function in this stack implementation.
44 class HidGlobalStack {
45 public:
46     HidGlobalStack();
47 
48     // add a token and change global states, returns value indicates if operation is successful
49     // it the token is push/pop, the stack push/pop accordingly.
50     bool append(const HidItem &i);
51 
52     // get reference to top element on the stack
53     const HidGlobal& top() const;
54 private:
55     std::vector<HidGlobal> mStack;
56 };
57 
58 } //namespace HidUtil
59 
60 #endif // HIDUTIL_HIDGLOABL_H_
61