File: diagnostics_service_converters.cc

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 (263 lines) | stat: -rw-r--r-- 13,370 bytes parent folder | download | duplicates (3)
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chromeos/ash/components/telemetry_extension/diagnostics/diagnostics_service_converters.h"

#include <optional>

#include "base/notreached.h"
#include "chromeos/ash/components/telemetry_extension/diagnostics/mojo_utils.h"
#include "chromeos/ash/services/cros_healthd/public/mojom/cros_healthd_diagnostics.mojom.h"
#include "chromeos/ash/services/cros_healthd/public/mojom/nullable_primitives.mojom.h"
#include "chromeos/crosapi/mojom/diagnostics_service.mojom.h"

namespace ash::converters::diagnostics {

namespace unchecked {

crosapi::mojom::DiagnosticsRoutineUpdatePtr UncheckedConvertPtr(
    cros_healthd::mojom::RoutineUpdatePtr input) {
  return crosapi::mojom::DiagnosticsRoutineUpdate::New(
      input->progress_percent,
      MojoUtils::GetStringFromMojoHandle(std::move(input->output)),
      ConvertDiagnosticsPtr(std::move(input->routine_update_union)));
}

crosapi::mojom::DiagnosticsRoutineUpdateUnionPtr UncheckedConvertPtr(
    cros_healthd::mojom::RoutineUpdateUnionPtr input) {
  switch (input->which()) {
    case cros_healthd::mojom::RoutineUpdateUnion::Tag::kInteractiveUpdate:
      return crosapi::mojom::DiagnosticsRoutineUpdateUnion::
          NewInteractiveUpdate(ConvertDiagnosticsPtr(
              std::move(input->get_interactive_update())));
    case cros_healthd::mojom::RoutineUpdateUnion::Tag::kNoninteractiveUpdate:
      return crosapi::mojom::DiagnosticsRoutineUpdateUnion::
          NewNoninteractiveUpdate(ConvertDiagnosticsPtr(
              std::move(input->get_noninteractive_update())));
  }
}

crosapi::mojom::DiagnosticsInteractiveRoutineUpdatePtr UncheckedConvertPtr(
    cros_healthd::mojom::InteractiveRoutineUpdatePtr input) {
  return crosapi::mojom::DiagnosticsInteractiveRoutineUpdate::New(
      Convert(input->user_message));
}

crosapi::mojom::DiagnosticsNonInteractiveRoutineUpdatePtr UncheckedConvertPtr(
    cros_healthd::mojom::NonInteractiveRoutineUpdatePtr input) {
  return crosapi::mojom::DiagnosticsNonInteractiveRoutineUpdate::New(
      Convert(input->status), std::move(input->status_message));
}

crosapi::mojom::DiagnosticsRunRoutineResponsePtr UncheckedConvertPtr(
    cros_healthd::mojom::RunRoutineResponsePtr input) {
  return crosapi::mojom::DiagnosticsRunRoutineResponse::New(
      input->id, Convert(input->status));
}

cros_healthd::mojom::NullableUint32Ptr UncheckedConvertPtr(
    crosapi::mojom::UInt32ValuePtr value) {
  return cros_healthd::mojom::NullableUint32::New(value->value);
}
}  // namespace unchecked

std::optional<crosapi::mojom::DiagnosticsRoutineEnum> Convert(
    cros_healthd::mojom::DiagnosticRoutineEnum input) {
  switch (input) {
    case cros_healthd::mojom::DiagnosticRoutineEnum::kUnknown:
      return crosapi::mojom::DiagnosticsRoutineEnum::kUnknown;
    case cros_healthd::mojom::DiagnosticRoutineEnum::kBatteryCapacity:
      return crosapi::mojom::DiagnosticsRoutineEnum::kBatteryCapacity;
    case cros_healthd::mojom::DiagnosticRoutineEnum::kBatteryHealth:
      return crosapi::mojom::DiagnosticsRoutineEnum::kBatteryHealth;
    case cros_healthd::mojom::DiagnosticRoutineEnum::kSmartctlCheck:
      return crosapi::mojom::DiagnosticsRoutineEnum::kSmartctlCheck;
    case cros_healthd::mojom::DiagnosticRoutineEnum::kAcPower:
      return crosapi::mojom::DiagnosticsRoutineEnum::kAcPower;
    case cros_healthd::mojom::DiagnosticRoutineEnum::kCpuCache:
      return crosapi::mojom::DiagnosticsRoutineEnum::kCpuCache;
    case cros_healthd::mojom::DiagnosticRoutineEnum::kCpuStress:
      return crosapi::mojom::DiagnosticsRoutineEnum::kCpuStress;
    case cros_healthd::mojom::DiagnosticRoutineEnum::kFloatingPointAccuracy:
      return crosapi::mojom::DiagnosticsRoutineEnum::kFloatingPointAccuracy;
    case cros_healthd::mojom::DiagnosticRoutineEnum::kNvmeSelfTest:
      return crosapi::mojom::DiagnosticsRoutineEnum::kNvmeSelfTest;
    case cros_healthd::mojom::DiagnosticRoutineEnum::kDiskRead:
      return crosapi::mojom::DiagnosticsRoutineEnum::kDiskRead;
    case cros_healthd::mojom::DiagnosticRoutineEnum::kPrimeSearch:
      return crosapi::mojom::DiagnosticsRoutineEnum::kPrimeSearch;
    case cros_healthd::mojom::DiagnosticRoutineEnum::kBatteryDischarge:
      return crosapi::mojom::DiagnosticsRoutineEnum::kBatteryDischarge;
    case cros_healthd::mojom::DiagnosticRoutineEnum::kBatteryCharge:
      return crosapi::mojom::DiagnosticsRoutineEnum::kBatteryCharge;
    case cros_healthd::mojom::DiagnosticRoutineEnum::kMemory:
      return crosapi::mojom::DiagnosticsRoutineEnum::kMemory;
    case cros_healthd::mojom::DiagnosticRoutineEnum::kLanConnectivity:
      return crosapi::mojom::DiagnosticsRoutineEnum::kLanConnectivity;
    case cros_healthd::mojom::DiagnosticRoutineEnum::kDnsResolution:
      return crosapi::mojom::DiagnosticsRoutineEnum::kDnsResolution;
    case cros_healthd::mojom::DiagnosticRoutineEnum::kDnsResolverPresent:
      return crosapi::mojom::DiagnosticsRoutineEnum::kDnsResolverPresent;
    case cros_healthd::mojom::DiagnosticRoutineEnum::kSignalStrength:
      return crosapi::mojom::DiagnosticsRoutineEnum::kSignalStrength;
    case cros_healthd::mojom::DiagnosticRoutineEnum::kGatewayCanBePinged:
      return crosapi::mojom::DiagnosticsRoutineEnum::kGatewayCanBePinged;
    case cros_healthd::mojom::DiagnosticRoutineEnum::kSensitiveSensor:
      return crosapi::mojom::DiagnosticsRoutineEnum::kSensitiveSensor;
    case cros_healthd::mojom::DiagnosticRoutineEnum::kFingerprintAlive:
      return crosapi::mojom::DiagnosticsRoutineEnum::kFingerprintAlive;
    case cros_healthd::mojom::DiagnosticRoutineEnum::
        kSmartctlCheckWithPercentageUsed:
      return crosapi::mojom::DiagnosticsRoutineEnum::
          kSmartctlCheckWithPercentageUsed;
    case cros_healthd::mojom::DiagnosticRoutineEnum::kEmmcLifetime:
      return crosapi::mojom::DiagnosticsRoutineEnum::kEmmcLifetime;
    case cros_healthd::mojom::DiagnosticRoutineEnum::kBluetoothPower:
      return crosapi::mojom::DiagnosticsRoutineEnum::kBluetoothPower;
    case cros_healthd::mojom::DiagnosticRoutineEnum::kUfsLifetime:
      return crosapi::mojom::DiagnosticsRoutineEnum::kUfsLifetime;
    case cros_healthd::mojom::DiagnosticRoutineEnum::kPowerButton:
      return crosapi::mojom::DiagnosticsRoutineEnum::kPowerButton;
    case cros_healthd::mojom::DiagnosticRoutineEnum::kAudioDriver:
      return crosapi::mojom::DiagnosticsRoutineEnum::kAudioDriver;
    case cros_healthd::mojom::DiagnosticRoutineEnum::kBluetoothDiscovery:
      return crosapi::mojom::DiagnosticsRoutineEnum::kBluetoothDiscovery;
    case cros_healthd::mojom::DiagnosticRoutineEnum::kBluetoothScanning:
      return crosapi::mojom::DiagnosticsRoutineEnum::kBluetoothScanning;
    case cros_healthd::mojom::DiagnosticRoutineEnum::kBluetoothPairing:
      return crosapi::mojom::DiagnosticsRoutineEnum::kBluetoothPairing;
    case cros_healthd::mojom::DiagnosticRoutineEnum::kFan:
      return crosapi::mojom::DiagnosticsRoutineEnum::kFan;
    // Below are deprecated routines.
    case cros_healthd::mojom::DiagnosticRoutineEnum::DEPRECATED_kNvmeWearLevel:
      return crosapi::mojom::DiagnosticsRoutineEnum::DEPRECATED_kNvmeWearLevel;
    default:
      return std::nullopt;
  }
}

std::vector<crosapi::mojom::DiagnosticsRoutineEnum> Convert(
    const std::vector<cros_healthd::mojom::DiagnosticRoutineEnum>& input) {
  std::vector<crosapi::mojom::DiagnosticsRoutineEnum> output;
  for (const auto element : input) {
    std::optional<crosapi::mojom::DiagnosticsRoutineEnum> converted =
        Convert(element);
    if (converted.has_value()) {
      output.push_back(converted.value());
    }
  }
  return output;
}

crosapi::mojom::DiagnosticsRoutineUserMessageEnum Convert(
    cros_healthd::mojom::DiagnosticRoutineUserMessageEnum input) {
  switch (input) {
    case cros_healthd::mojom::DiagnosticRoutineUserMessageEnum::kUnknown:
      return crosapi::mojom::DiagnosticsRoutineUserMessageEnum::kUnknown;
    case cros_healthd::mojom::DiagnosticRoutineUserMessageEnum::kUnplugACPower:
      return crosapi::mojom::DiagnosticsRoutineUserMessageEnum::kUnplugACPower;
    case cros_healthd::mojom::DiagnosticRoutineUserMessageEnum::kPlugInACPower:
      return crosapi::mojom::DiagnosticsRoutineUserMessageEnum::kPlugInACPower;
    case cros_healthd::mojom::DiagnosticRoutineUserMessageEnum::kCheckLedColor:
      NOTIMPLEMENTED();
      return crosapi::mojom::DiagnosticsRoutineUserMessageEnum::kUnknown;
    case cros_healthd::mojom::DiagnosticRoutineUserMessageEnum::
        kPressPowerButton:
      return crosapi::mojom::DiagnosticsRoutineUserMessageEnum::
          kPressPowerButton;
  }
  NOTREACHED();
}

crosapi::mojom::DiagnosticsRoutineStatusEnum Convert(
    cros_healthd::mojom::DiagnosticRoutineStatusEnum input) {
  switch (input) {
    case cros_healthd::mojom::DiagnosticRoutineStatusEnum::kUnknown:
      return crosapi::mojom::DiagnosticsRoutineStatusEnum::kUnknown;
    case cros_healthd::mojom::DiagnosticRoutineStatusEnum::kReady:
      return crosapi::mojom::DiagnosticsRoutineStatusEnum::kReady;
    case cros_healthd::mojom::DiagnosticRoutineStatusEnum::kRunning:
      return crosapi::mojom::DiagnosticsRoutineStatusEnum::kRunning;
    case cros_healthd::mojom::DiagnosticRoutineStatusEnum::kWaiting:
      return crosapi::mojom::DiagnosticsRoutineStatusEnum::kWaiting;
    case cros_healthd::mojom::DiagnosticRoutineStatusEnum::kPassed:
      return crosapi::mojom::DiagnosticsRoutineStatusEnum::kPassed;
    case cros_healthd::mojom::DiagnosticRoutineStatusEnum::kFailed:
      return crosapi::mojom::DiagnosticsRoutineStatusEnum::kFailed;
    case cros_healthd::mojom::DiagnosticRoutineStatusEnum::kError:
      return crosapi::mojom::DiagnosticsRoutineStatusEnum::kError;
    case cros_healthd::mojom::DiagnosticRoutineStatusEnum::kCancelled:
      return crosapi::mojom::DiagnosticsRoutineStatusEnum::kCancelled;
    case cros_healthd::mojom::DiagnosticRoutineStatusEnum::kFailedToStart:
      return crosapi::mojom::DiagnosticsRoutineStatusEnum::kFailedToStart;
    case cros_healthd::mojom::DiagnosticRoutineStatusEnum::kRemoved:
      return crosapi::mojom::DiagnosticsRoutineStatusEnum::kRemoved;
    case cros_healthd::mojom::DiagnosticRoutineStatusEnum::kCancelling:
      return crosapi::mojom::DiagnosticsRoutineStatusEnum::kCancelling;
    case cros_healthd::mojom::DiagnosticRoutineStatusEnum::kUnsupported:
      return crosapi::mojom::DiagnosticsRoutineStatusEnum::kUnsupported;
    case cros_healthd::mojom::DiagnosticRoutineStatusEnum::kNotRun:
      return crosapi::mojom::DiagnosticsRoutineStatusEnum::kNotRun;
  }
  NOTREACHED();
}

cros_healthd::mojom::DiagnosticRoutineCommandEnum Convert(
    crosapi::mojom::DiagnosticsRoutineCommandEnum input) {
  switch (input) {
    case crosapi::mojom::DiagnosticsRoutineCommandEnum::kUnknown:
      return cros_healthd::mojom::DiagnosticRoutineCommandEnum::kUnknown;
    case crosapi::mojom::DiagnosticsRoutineCommandEnum::kContinue:
      return cros_healthd::mojom::DiagnosticRoutineCommandEnum::kContinue;
    case crosapi::mojom::DiagnosticsRoutineCommandEnum::kCancel:
      return cros_healthd::mojom::DiagnosticRoutineCommandEnum::kCancel;
    case crosapi::mojom::DiagnosticsRoutineCommandEnum::kGetStatus:
      return cros_healthd::mojom::DiagnosticRoutineCommandEnum::kGetStatus;
    case crosapi::mojom::DiagnosticsRoutineCommandEnum::kRemove:
      return cros_healthd::mojom::DiagnosticRoutineCommandEnum::kRemove;
  }
  NOTREACHED();
}

cros_healthd::mojom::AcPowerStatusEnum Convert(
    crosapi::mojom::DiagnosticsAcPowerStatusEnum input) {
  switch (input) {
    case crosapi::mojom::DiagnosticsAcPowerStatusEnum::kUnknown:
      return cros_healthd::mojom::AcPowerStatusEnum::kUnknown;
    case crosapi::mojom::DiagnosticsAcPowerStatusEnum::kConnected:
      return cros_healthd::mojom::AcPowerStatusEnum::kConnected;
    case crosapi::mojom::DiagnosticsAcPowerStatusEnum::kDisconnected:
      return cros_healthd::mojom::AcPowerStatusEnum::kDisconnected;
  }
  NOTREACHED();
}

cros_healthd::mojom::NvmeSelfTestTypeEnum Convert(
    crosapi::mojom::DiagnosticsNvmeSelfTestTypeEnum input) {
  switch (input) {
    case crosapi::mojom::DiagnosticsNvmeSelfTestTypeEnum::kUnknown:
      return cros_healthd::mojom::NvmeSelfTestTypeEnum::kUnknown;
    case crosapi::mojom::DiagnosticsNvmeSelfTestTypeEnum::kShortSelfTest:
      return cros_healthd::mojom::NvmeSelfTestTypeEnum::kShortSelfTest;
    case crosapi::mojom::DiagnosticsNvmeSelfTestTypeEnum::kLongSelfTest:
      return cros_healthd::mojom::NvmeSelfTestTypeEnum::kLongSelfTest;
  }
  NOTREACHED();
}

cros_healthd::mojom::DiskReadRoutineTypeEnum Convert(
    crosapi::mojom::DiagnosticsDiskReadRoutineTypeEnum input) {
  switch (input) {
    case crosapi::mojom::DiagnosticsDiskReadRoutineTypeEnum::kLinearRead:
      return cros_healthd::mojom::DiskReadRoutineTypeEnum::kLinearRead;
    case crosapi::mojom::DiagnosticsDiskReadRoutineTypeEnum::kRandomRead:
      return cros_healthd::mojom::DiskReadRoutineTypeEnum::kRandomRead;
    case crosapi::mojom::DiagnosticsDiskReadRoutineTypeEnum::kUnknown:
      // Fall-through to not-supported case.
      break;
  }
  NOTREACHED();
}

}  // namespace ash::converters::diagnostics