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 <string_view>
22#include <unordered_map>
23
26
27namespace cuttlefish {
28namespace webrtc_streaming {
29
31 public:
32 using MotionUpdatedCallback = std::function<void(const uint8_t*, size_t)>;
33
34 explicit SensorsHandler(SharedFD sensors_fd);
36
37 Result<void> SetMotion(double x, double y, double z);
38 Result<void> SetHingeAngle(double angle);
39
41 void RemoveMotionUpdatedCallback(int subscriber_id);
42
43 private:
44 Result<void> SendCommand(uint32_t cmd, std::string_view payload);
47
48 std::unordered_map<int, MotionUpdatedCallback> client_channels_;
50 std::mutex subscribers_mtx_;
52};
53
54} // namespace webrtc_streaming
55} // namespace cuttlefish
Definition: shared_fd.h:124
Definition: channel_sharedfd.h:24
Definition: sensors_handler.h:30
void NotifyMotionUpdated()
Definition: sensors_handler.cpp:109
SensorsHandler(SharedFD sensors_fd)
Definition: sensors_handler.cpp:39
std::function< void(const uint8_t *, size_t)> MotionUpdatedCallback
Definition: sensors_handler.h:32
~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:50
void RemoveMotionUpdatedCallback(int subscriber_id)
Definition: sensors_handler.cpp:104
std::unordered_map< int, MotionUpdatedCallback > client_channels_
Definition: sensors_handler.h:48
transport::SharedFdChannel channel_
Definition: sensors_handler.h:51
Result< void > SendCommand(uint32_t cmd, std::string_view payload)
Definition: sensors_handler.cpp:44
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:49
int SensorsMask
Definition: sensors.h:51
Definition: alloc_driver.h:20
tl::expected< T, StackTraceError > Result
Definition: result_type.h:30
__u32 mask
Definition: nl80211.h:0
uint32_t payload
Definition: pairing_connection.cpp:2