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