Android-cuttlefish cvd tool
reporting.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2021 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 <string>
20#include <tuple>
21#include <vector>
22
23#include <fruit/fruit.h>
24
25namespace cuttlefish {
26
28 public:
30 virtual std::vector<std::string> Diagnostics() const = 0;
31
32 static void PrintAll(const std::vector<DiagnosticInformation*>&);
33};
34
35template <auto Fn, typename R, typename... Args>
37 public:
38 INJECT(DiagnosticInformationFn(Args... args))
39 : args_(std::forward_as_tuple(args...)) {}
40
41 std::vector<std::string> Diagnostics() const override {
42 if constexpr (std::is_same_v<R, std::vector<std::string>>) {
43 return std::apply(Fn, args_);
44 } else if constexpr (std::is_same_v<R, std::string>) {
45 return {std::apply(Fn, args_)};
46 } else {
47 static_assert(false, "Unexpected AutoDiagnostic return type");
48 }
49 }
50
51 private:
52 std::tuple<Args...> args_;
53};
54
55template <auto Fn1, typename Fn2>
57
58template <auto Fn, typename R, typename... Args>
59struct DiagnosticInformationFnImpl<Fn, R (*)(Args...)> {
60 using Type = DiagnosticInformationFn<Fn, R, Args...>;
61
62 static fruit::Component<
63 fruit::Required<typename std::remove_reference_t<Args>...>, Type>
65 return fruit::createComponent()
66 .template addMultibinding<DiagnosticInformation, Type>();
67 }
68};
69
70template <auto Fn>
72
73} // namespace cuttlefish
Definition: reporting.h:36
std::tuple< Args... > args_
Definition: reporting.h:52
Definition: reporting.h:27
virtual std::vector< std::string > Diagnostics() const =0
static void PrintAll(const std::vector< DiagnosticInformation * > &)
Definition: reporting.cpp:31
Definition: alloc_utils.cpp:23
std::vector< std::string_view > Args
Definition: incremental.h:28
static fruit::Component< fruit::Required< typename std::remove_reference_t< Args >... >, Type > Component()
Definition: reporting.h:64
Definition: reporting.h:56