1 /* 2 * Copyright (c) 2022 Chipsea Technologies (Shenzhen) Corp., 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_DATA_CHANNEL_H 17 #define SENSOR_DATA_CHANNEL_H 18 19 #include <memory> 20 #include <thread> 21 #include "medical_sensor_basic_data_channel.h" 22 #include "medical_native_type.h" 23 #include "my_event_handler.h" 24 25 namespace OHOS { 26 namespace Sensors { 27 typedef void (*DataChannelCB)(struct SensorEvent *events, int32_t num, void *data); 28 class MedicalSensorDataChannel : public MedicalSensorBasicDataChannel { 29 public: 30 MedicalSensorDataChannel(); 31 ~MedicalSensorDataChannel(); 32 static int32_t HandleEvent(int32_t fd, int32_t events, void *data); 33 int32_t CreateSensorDataChannel(DataChannelCB callBack, void *data); 34 int32_t DestroySensorDataChannel(); 35 bool IsThreadExit(); 36 bool IsThreadStart(); 37 int32_t RestoreSensorDataChannel(); 38 int32_t test = 10; 39 DataChannelCB dataCB_; 40 void *privateData_ = nullptr; 41 42 private: 43 static void threadProcessTask(MedicalSensorDataChannel *afeChannel); 44 int32_t InnerSensorDataChannel(); 45 std::mutex eventRunnerMutex_; 46 static std::shared_ptr<MyEventHandler> eventHandler_; 47 static std::shared_ptr<AppExecFwk::EventRunner> eventRunner_; 48 static int32_t receiveFd_; 49 }; 50 } // namespace Sensors 51 } // namespace OHOS 52 #endif // SENSOR_DATA_CHANNEL_H 53