File: telemetry_event_service_converters.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (169 lines) | stat: -rw-r--r-- 6,474 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROMEOS_ASH_COMPONENTS_TELEMETRY_EXTENSION_EVENTS_TELEMETRY_EVENT_SERVICE_CONVERTERS_H_
#define CHROMEOS_ASH_COMPONENTS_TELEMETRY_EXTENSION_EVENTS_TELEMETRY_EVENT_SERVICE_CONVERTERS_H_

#include <type_traits>
#include <vector>

#include "ash/system/diagnostics/mojom/input.mojom.h"
#include "chromeos/ash/services/cros_healthd/public/mojom/cros_healthd_events.mojom.h"
#include "chromeos/ash/services/cros_healthd/public/mojom/nullable_primitives.mojom.h"
#include "chromeos/crosapi/mojom/telemetry_event_service.mojom.h"
#include "chromeos/crosapi/mojom/telemetry_extension_exception.mojom.h"
#include "chromeos/crosapi/mojom/telemetry_keyboard_event.mojom.h"

namespace ash::converters::events {

// This file contains helper functions used by TelemetryEventServiceAsh to
// convert its types to/from cros_healthd EventService types.

namespace unchecked {

crosapi::mojom::UInt32ValuePtr LegacyUncheckedConvertPtr(
    cros_healthd::mojom::NullableUint32Ptr input);

std::optional<uint32_t> UncheckedConvertPtr(
    cros_healthd::mojom::NullableUint32Ptr input);

crosapi::mojom::TelemetryAudioJackEventInfoPtr UncheckedConvertPtr(
    cros_healthd::mojom::AudioJackEventInfoPtr input);

crosapi::mojom::TelemetryKeyboardInfoPtr UncheckedConvertPtr(
    diagnostics::mojom::KeyboardInfoPtr input);

crosapi::mojom::TelemetryKeyboardDiagnosticEventInfoPtr UncheckedConvertPtr(
    diagnostics::mojom::KeyboardDiagnosticEventInfoPtr input);

crosapi::mojom::TelemetryLidEventInfoPtr UncheckedConvertPtr(
    cros_healthd::mojom::LidEventInfoPtr input);

crosapi::mojom::TelemetryUsbEventInfoPtr UncheckedConvertPtr(
    cros_healthd::mojom::UsbEventInfoPtr input);

crosapi::mojom::TelemetryExternalDisplayEventInfoPtr UncheckedConvertPtr(
    cros_healthd::mojom::ExternalDisplayEventInfoPtr input);

crosapi::mojom::TelemetrySdCardEventInfoPtr UncheckedConvertPtr(
    cros_healthd::mojom::SdCardEventInfoPtr input);

crosapi::mojom::TelemetryPowerEventInfoPtr UncheckedConvertPtr(
    cros_healthd::mojom::PowerEventInfoPtr input);

crosapi::mojom::TelemetryStylusGarageEventInfoPtr UncheckedConvertPtr(
    cros_healthd::mojom::StylusGarageEventInfoPtr input);

crosapi::mojom::TelemetryTouchPointInfoPtr UncheckedConvertPtr(
    cros_healthd::mojom::TouchPointInfoPtr input);

crosapi::mojom::TelemetryTouchpadButtonEventInfoPtr UncheckedConvertPtr(
    cros_healthd::mojom::TouchpadButtonEventPtr input);

crosapi::mojom::TelemetryTouchpadTouchEventInfoPtr UncheckedConvertPtr(
    cros_healthd::mojom::TouchpadTouchEventPtr input);

crosapi::mojom::TelemetryTouchpadConnectedEventInfoPtr UncheckedConvertPtr(
    cros_healthd::mojom::TouchpadConnectedEventPtr input);

crosapi::mojom::TelemetryTouchscreenTouchEventInfoPtr UncheckedConvertPtr(
    cros_healthd::mojom::TouchscreenTouchEventPtr input);

crosapi::mojom::TelemetryTouchscreenConnectedEventInfoPtr UncheckedConvertPtr(
    cros_healthd::mojom::TouchscreenConnectedEventPtr input);

crosapi::mojom::TelemetryStylusTouchEventInfoPtr UncheckedConvertPtr(
    cros_healthd::mojom::StylusTouchEventPtr input);

crosapi::mojom::TelemetryStylusConnectedEventInfoPtr UncheckedConvertPtr(
    cros_healthd::mojom::StylusConnectedEventPtr input);

crosapi::mojom::TelemetryStylusTouchPointInfoPtr UncheckedConvertPtr(
    cros_healthd::mojom::StylusTouchPointInfoPtr input);

crosapi::mojom::TelemetryEventInfoPtr UncheckedConvertPtr(
    cros_healthd::mojom::EventInfoPtr input);

}  // namespace unchecked

crosapi::mojom::TelemetryAudioJackEventInfo::State Convert(
    cros_healthd::mojom::AudioJackEventInfo::State input);

crosapi::mojom::TelemetryAudioJackEventInfo::DeviceType Convert(
    cros_healthd::mojom::AudioJackEventInfo::DeviceType input);

crosapi::mojom::TelemetryKeyboardConnectionType Convert(
    diagnostics::mojom::ConnectionType input);

crosapi::mojom::TelemetryKeyboardPhysicalLayout Convert(
    diagnostics::mojom::PhysicalLayout input);

crosapi::mojom::TelemetryKeyboardMechanicalLayout Convert(
    diagnostics::mojom::MechanicalLayout input);

crosapi::mojom::TelemetryKeyboardNumberPadPresence Convert(
    diagnostics::mojom::NumberPadPresence input);

crosapi::mojom::TelemetryKeyboardTopRowKey Convert(
    diagnostics::mojom::TopRowKey input);

crosapi::mojom::TelemetryKeyboardTopRightKey Convert(
    diagnostics::mojom::TopRightKey input);

crosapi::mojom::TelemetryLidEventInfo::State Convert(
    cros_healthd::mojom::LidEventInfo::State input);

crosapi::mojom::TelemetryUsbEventInfo::State Convert(
    cros_healthd::mojom::UsbEventInfo::State input);

crosapi::mojom::TelemetrySdCardEventInfo::State Convert(
    cros_healthd::mojom::SdCardEventInfo::State input);

crosapi::mojom::TelemetryPowerEventInfo::State Convert(
    cros_healthd::mojom::PowerEventInfo::State input);

crosapi::mojom::TelemetryStylusGarageEventInfo::State Convert(
    cros_healthd::mojom::StylusGarageEventInfo::State input);

crosapi::mojom::TelemetryExternalDisplayEventInfo::State Convert(
    cros_healthd::mojom::ExternalDisplayEventInfo::State input);

crosapi::mojom::TelemetryInputTouchButton Convert(
    cros_healthd::mojom::InputTouchButton input);

cros_healthd::mojom::EventCategoryEnum Convert(
    crosapi::mojom::TelemetryEventCategoryEnum input);

template <class OutputT,
          class InputT,
          std::enable_if_t<std::is_enum_v<InputT>, bool> = true>
std::vector<OutputT> ConvertVector(std::vector<InputT> input) {
  std::vector<OutputT> result;
  for (auto elem : input) {
    result.push_back(Convert(elem));
  }
  return result;
}

template <class InputT>
auto LegacyConvertStructPtr(InputT input) {
  return (!input.is_null())
             ? unchecked::LegacyUncheckedConvertPtr(std::move(input))
             : nullptr;
}

template <class InputT,
          class... Types,
          class OutputT = decltype(unchecked::UncheckedConvertPtr(
              std::declval<InputT>(),
              std::declval<Types>()...)),
          class = std::enable_if_t<std::is_default_constructible_v<OutputT>>>
OutputT ConvertStructPtr(InputT input) {
  return (!input.is_null()) ? unchecked::UncheckedConvertPtr(std::move(input))
                            : OutputT();
}

}  // namespace ash::converters::events

#endif  // CHROMEOS_ASH_COMPONENTS_TELEMETRY_EXTENSION_EVENTS_TELEMETRY_EVENT_SERVICE_CONVERTERS_H_