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