summaryrefslogtreecommitdiff
path: root/modules/sensors/dynamic_sensor/HidUtils/HidGlobal.h
blob: b9139d0a5da9dd1b417d0ad6a0807b76e2d1a816 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#ifndef HIDUTIL_HIDGLOBAL_H_
#define HIDUTIL_HIDGLOBAL_H_

#include "HidItem.h"
#include "TriState.h"

namespace HidUtil {
// A set of global states that parser has to keep track during parsing.
// They are all specified in HID spec v1.11 section 6.2.2.7
struct HidGlobal {
    // add a token and change global states, returns value indicates if operation is successful
    bool append(const HidItem &i);

    tri_uint usagePage;
    tri_int  logicalMin;
    tri_int  logicalMax;
    tri_int  physicalMin;
    tri_int  physicalMax;
    tri_uint exponent;
    tri_uint unit;
    tri_uint reportSize;
    tri_uint reportId;
    tri_uint reportCount;
};

// HID specs allows PUSH and POP to save a snapshot of current global states and come back to the
// saved sates later. HidStack manages this logic. Note that PUSH and POP are also HidItems, so
// there is no explicit push and pop function in this stack implementation.
class HidGlobalStack {
public:
    HidGlobalStack();

    // add a token and change global states, returns value indicates if operation is successful
    // it the token is push/pop, the stack push/pop accordingly.
    bool append(const HidItem &i);

    // get reference to top element on the stack
    const HidGlobal& top() const;
private:
    std::vector<HidGlobal> mStack;
};

} //namespace HidUtil

#endif // HIDUTIL_HIDGLOABL_H_