• 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 
21 #include "message_parcel.h"
22 #include "sensor.h"
23 #include "sensor_data_event.h"
24 
25 namespace OHOS {
26 namespace Sensors {
27 using ClientExcuteCB = std::function<void(int32_t)>;
28 class SensorBasicDataChannel : public RefBase {
29 public:
30     SensorBasicDataChannel();
31     virtual ~SensorBasicDataChannel();
32     int32_t CreateSensorBasicChannel();
33     int32_t CreateSensorBasicChannel(MessageParcel &data);
34     int32_t CreateSensorBasicChannelBySendFd(int32_t sendFd);
35     int32_t DestroySensorBasicChannel();
36     int32_t GetSendDataFd();
37     int32_t GetReceiveDataFd();
38     int32_t SendToBinder(MessageParcel &data);
39     void CloseSendFd();
40     int32_t SendData(const void *vaddr, size_t size);
41     int32_t ReceiveData(ClientExcuteCB callBack, void *vaddr, size_t size);
42     bool GetSensorStatus() const;
43     void SetSensorStatus(bool isActive);
44     const std::unordered_map<SensorDescription, SensorData> &GetDataCacheBuf() const;
45     std::string GetPackageName();
46     void SetPackageName(std::string packageName);
47 
48 private:
49     std::mutex fdLock_;
50     int32_t sendFd_;
51     int32_t receiveFd_;
52     bool isActive_;
53     std::mutex statusLock_;
54     std::unordered_map<SensorDescription, SensorData> dataCacheBuf_;
55     std::string packageName_;
56     std::mutex pkNameLock_;
57 };
58 } // namespace Sensors
59 } // namespace OHOS
60 #endif // SENSOR_H
61