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 using ClientExcuteCB = std::function<void(int32_t)>; 30 class SensorBasicDataChannel : public RefBase { 31 public: 32 SensorBasicDataChannel(); 33 virtual ~SensorBasicDataChannel(); 34 int32_t CreateSensorBasicChannel(); 35 int32_t CreateSensorBasicChannel(MessageParcel &data); 36 int32_t DestroySensorBasicChannel(); 37 int32_t GetSendDataFd() const; 38 int32_t GetReceiveDataFd() const; 39 int32_t SendToBinder(MessageParcel &data); 40 void CloseSendFd(); 41 int32_t SendData(const void *vaddr, size_t size); 42 int32_t ReceiveData(ClientExcuteCB callBack, void *vaddr, size_t size); 43 bool GetSensorStatus() const; 44 void SetSensorStatus(bool isActive); 45 const std::unordered_map<int32_t, SensorData> &GetDataCacheBuf() const; 46 47 private: 48 int32_t sendFd_; 49 int32_t receiveFd_; 50 bool isActive_; 51 std::mutex statusLock_; 52 std::unordered_map<int32_t, SensorData> dataCacheBuf_; 53 }; 54 } // namespace Sensors 55 } // namespace OHOS 56 #endif // SENSOR_H 57