• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef SENSOR_H
17 #define SENSOR_H
18 
19 #include "parcel.h"
20 
21 struct SensorDescription {
22     int32_t deviceId;
23     int32_t sensorType;
24     int32_t sensorId;
25     int32_t location;
26     bool operator < (const SensorDescription& other) const
27     {
28         if (deviceId != other.deviceId) return deviceId < other.deviceId;
29         if (sensorType != other.sensorType) return sensorType < other.sensorType;
30         if (sensorId != other.sensorId) return sensorId < other.sensorId;
31         return location < other.location;
32     }
33 
34     bool operator == (const SensorDescription& other) const
35     {
36         return deviceId == other.deviceId && sensorType == other.sensorType && sensorId == other.sensorId &&
37                 location == other.location;
38     }
39 };
40 
41 namespace std {
42     template <>
43     struct hash<SensorDescription> {
44         std::size_t operator()(const SensorDescription& obj) const
45         {
46             std::size_t h1 = std::hash<int32_t>{}(obj.deviceId);
47             std::size_t h2 = std::hash<int32_t>{}(obj.sensorType);
48             std::size_t h3 = std::hash<int32_t>{}(obj.sensorId);
49             std::size_t h4 = std::hash<int32_t>{}(obj.location);
50 
51             return h1 ^ h2 ^ h3 ^ h4;
52         }
53     };
54 }
55 
56 namespace OHOS {
57 namespace Sensors {
58 struct SensorDescriptionIPC : public Parcelable {
59     int32_t deviceId;
60     int32_t sensorType;
61     int32_t sensorId;
62     int32_t location;
63     SensorDescriptionIPC();
64     SensorDescriptionIPC(int32_t deviceId, int32_t sensorType, int32_t sensorId, int32_t location);
65     static SensorDescriptionIPC* Unmarshalling(Parcel &parcel);
66     bool Marshalling(Parcel &parcel) const;
67 };
68 class Sensor : public Parcelable {
69 public:
70     Sensor();
71     virtual ~Sensor() = default;
72     int32_t GetSensorId() const;
73     void SetSensorId(int32_t sensorId);
74     int32_t GetSensorTypeId() const;
75     void SetSensorTypeId(int32_t sensorTypeId);
76     std::string GetSensorName() const;
77     void SetSensorName(const std::string &sensorName);
78     std::string GetVendorName() const;
79     void SetVendorName(const std::string &vendorName);
80     std::string GetHardwareVersion() const;
81     void SetHardwareVersion(const std::string &hardwareVersion);
82     std::string GetFirmwareVersion() const;
83     void SetFirmwareVersion(const std::string &firmwareVersion);
84     float GetMaxRange() const;
85     void SetMaxRange(float maxRange);
86     float GetResolution() const;
87     void SetResolution(float resolution);
88     float GetPower() const;
89     void SetPower(float power);
90     uint32_t GetFlags() const;
91     void SetFlags(uint32_t flags);
92     int32_t GetFifoMaxEventCount() const;
93     void SetFifoMaxEventCount(int32_t fifoMaxEventCount);
94     int64_t GetMinSamplePeriodNs() const;
95     void SetMinSamplePeriodNs(int64_t minSamplePeriodNs);
96     int64_t GetMaxSamplePeriodNs() const;
97     void SetMaxSamplePeriodNs(int64_t maxSamplePeriodNs);
98     int32_t GetDeviceId() const;
99     void SetDeviceId(int32_t deviceId);
100     int32_t GetLocation() const;
101     void SetLocation(int32_t location);
102     bool ReadFromParcel(Parcel &parcel);
103     static Sensor* Unmarshalling(Parcel &parcel);
104     virtual bool Marshalling(Parcel &parcel) const override;
105 
106 private:
107     int32_t sensorId_;
108     int32_t sensorTypeId_;
109     std::string sensorName_;
110     std::string vendorName_;
111     std::string firmwareVersion_;
112     std::string hardwareVersion_;
113     float maxRange_;
114     float resolution_;
115     float power_;
116     uint32_t flags_;
117     int32_t fifoMaxEventCount_;
118     int64_t minSamplePeriodNs_;
119     int64_t maxSamplePeriodNs_;
120     int32_t deviceId_;
121     int32_t location_;
122 };
123 } // namespace Sensors
124 } // namespace OHOS
125 #endif // SENSOR_H
126