• 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_BASIC_DATA_CHANNEL_H
17 #define SENSOR_BASIC_DATA_CHANNEL_H
18 
19 #include <mutex>
20 #include <unordered_map>
21 
22 #include "message_parcel.h"
23 #include "refbase.h"
24 
25 #include "sensor_data_event.h"
26 
27 namespace OHOS {
28 namespace Sensors {
29 class SensorBasicDataChannel : public RefBase {
30 public:
31     SensorBasicDataChannel();
32     virtual ~SensorBasicDataChannel();
33     int32_t CreateSensorBasicChannel();
34     int32_t CreateSensorBasicChannel(MessageParcel &data);
35     int32_t DestroySensorBasicChannel();
36     int32_t GetSendDataFd() const;
37     int32_t GetReceiveDataFd() const;
38     int32_t SendToBinder(MessageParcel &data);
39     void CloseSendFd();
40     int32_t SendData(const void *vaddr, size_t size);
41     int32_t ReceiveData(void *vaddr, size_t size);
42     bool GetSensorStatus() const;
43     void SetSensorStatus(bool isActive);
44     const std::unordered_map<int32_t, SensorData> &GetDataCacheBuf() const;
45 
46 private:
47     int32_t sendFd_;
48     int32_t receiveFd_;
49     bool isActive_;
50     std::mutex statusLock_;
51     std::unordered_map<int32_t, SensorData> dataCacheBuf_;
52 };
53 }  // namespace Sensors
54 }  // namespace OHOS
55 #endif  // SENSOR_H
56