1 /*
2 * Copyright (C) 2020 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <android-base/unique_fd.h>
18 #include <qemud.h>
19 #include <multihal_sensors.h>
20
21 using ::android::base::unique_fd;
22 using ::android::hardware::sensors::V2_1::implementation::ISensorsSubHal;
23
24 namespace {
25
26 class QemudSensorsTransport : public goldfish::SensorsTransport {
27 public:
QemudSensorsTransport()28 QemudSensorsTransport()
29 : m_qemuSensorsFd(qemud_channel_open("sensors")) {}
30
Send(const void * msg,int size)31 int Send(const void* msg, int size) override {
32 return qemud_channel_send(m_qemuSensorsFd.get(), msg, size);
33 }
34
Receive(void * msg,int maxsize)35 int Receive(void* msg, int maxsize) override {
36 return qemud_channel_recv(m_qemuSensorsFd.get(), msg, maxsize);
37 }
38
Ok() const39 bool Ok() const override {
40 return m_qemuSensorsFd.ok();
41 }
42
Fd() const43 int Fd() const override {
44 return m_qemuSensorsFd.get();
45 }
46
Name() const47 const char* Name() const override {
48 return "qemud_channel";
49 }
50
51 private:
52 const unique_fd m_qemuSensorsFd;
53 };
54
__anon498234880202()55 goldfish::MultihalSensors impl([](){ return std::make_unique<QemudSensorsTransport>(); });
56
57 } // namespace
58
sensorsHalGetSubHal_2_1(uint32_t * version)59 extern "C" ISensorsSubHal* sensorsHalGetSubHal_2_1(uint32_t* version) {
60 *version = SUB_HAL_2_1_VERSION;
61 return &impl;
62 }
63