Android-cuttlefish cvd tool
sensors_handler.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2023 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#pragma once
18
19#include <functional>
20#include <mutex>
21#include <unordered_map>
22
23#include "absl/strings/string_view.h"
24
27
28namespace cuttlefish {
29namespace webrtc_streaming {
30
32 public:
33 using MotionUpdatedCallback = std::function<void(const uint8_t*, size_t)>;
34
35 explicit SensorsHandler(SharedFD sensors_fd);
37
38 Result<void> SetMotion(double x, double y, double z);
39 Result<void> SetHingeAngle(double angle);
40
42 void RemoveMotionUpdatedCallback(int subscriber_id);
43
44 private:
45 Result<void> SendCommand(uint32_t cmd, absl::string_view payload);
48
49 std::unordered_map<int, MotionUpdatedCallback> client_channels_;
51 std::mutex subscribers_mtx_;
53};
54
55} // namespace webrtc_streaming
56} // namespace cuttlefish
Definition: shared_fd.h:125
Definition: channel_sharedfd.h:25
Definition: sensors_handler.h:31
void NotifyMotionUpdated()
Definition: sensors_handler.cpp:109
SensorsHandler(SharedFD sensors_fd)
Definition: sensors_handler.cpp:39
Result< void > SendCommand(uint32_t cmd, absl::string_view payload)
Definition: sensors_handler.cpp:44
std::function< void(const uint8_t *, size_t)> MotionUpdatedCallback
Definition: sensors_handler.h:33
~SensorsHandler()
Definition: sensors_handler.cpp:42
Result< void > SetHingeAngle(double angle)
Definition: sensors_handler.cpp:66
Result< std::string > GetSensorsData(sensors::SensorsMask mask)
Definition: sensors_handler.cpp:71
std::mutex subscribers_mtx_
Definition: sensors_handler.h:51
void RemoveMotionUpdatedCallback(int subscriber_id)
Definition: sensors_handler.cpp:104
std::unordered_map< int, MotionUpdatedCallback > client_channels_
Definition: sensors_handler.h:49
transport::SharedFdChannel channel_
Definition: sensors_handler.h:52
int AddMotionUpdatedCallback(MotionUpdatedCallback callback)
Definition: sensors_handler.cpp:83
Result< void > SetMotion(double x, double y, double z)
Definition: sensors_handler.cpp:57
int last_client_channel_id_
Definition: sensors_handler.h:50
int SensorsMask
Definition: sensors.h:51
Definition: alloc_driver.h:21
tl::expected< T, StackTraceError< E > > Result
Definition: result_type.h:30
__u32 mask
Definition: nl80211.h:0
uint32_t payload
Definition: pairing_connection.cpp:2