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_agent_type.h" 26 27 namespace OHOS { 28 namespace Sensors { 29 constexpr int32_t SENSOR_MAX_LENGTH = 64; 30 struct TransferSensorEvents { 31 uint32_t sensorTypeId; 32 int32_t version; 33 int64_t timestamp; 34 int32_t option; 35 int32_t mode; 36 uint32_t dataLen; 37 uint8_t data[SENSOR_MAX_LENGTH]; 38 }; 39 class SensorBasicDataChannel : public RefBase { 40 public: 41 SensorBasicDataChannel(); 42 virtual ~SensorBasicDataChannel(); 43 int32_t CreateSensorBasicChannel(); 44 int32_t CreateSensorBasicChannel(MessageParcel &data); 45 int32_t DestroySensorBasicChannel(); 46 int32_t GetSendDataFd() const; 47 int32_t GetReceiveDataFd() const; 48 int32_t SendToBinder(MessageParcel &data); 49 void CloseSendFd(); 50 int32_t SendData(const void *vaddr, size_t size); 51 int32_t ReceiveData(void *vaddr, size_t size); 52 bool GetSensorStatus() const; 53 void SetSensorStatus(bool isActive); 54 const std::unordered_map<uint32_t, SensorEvent> &GetDataCacheBuf() const; 55 56 private: 57 int32_t sendFd_; 58 int32_t receiveFd_; 59 bool isActive_; 60 std::mutex statusLock_; 61 std::unordered_map<uint32_t, SensorEvent> dataCacheBuf_; 62 }; 63 } // namespace Sensors 64 } // namespace OHOS 65 #endif // SENSOR_H 66