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

printing / printer_status.cc [blame]

// 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 "printing/printer_status.h"

#include <algorithm>
#include <iterator>

#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"

namespace printing {

PrinterStatus::PrinterStatus() = default;

PrinterStatus::PrinterStatus(const PrinterStatus& other) = default;

PrinterStatus::~PrinterStatus() = default;

std::string_view PrinterStatus::PrinterReason::ReasonName() const {
  switch (reason) {
    case Reason::kUnknownReason:
      return "unknown";
    case Reason::kNone:
      return "none";
    case Reason::kMediaNeeded:
      return "media-needed";
    case Reason::kMediaJam:
      return "media-jam";
    case Reason::kMovingToPaused:
      return "moving-to-paused";
    case Reason::kPaused:
      return "paused";
    case Reason::kShutdown:
      return "shutdown";
    case Reason::kConnectingToDevice:
      return "connecting-to-device";
    case Reason::kTimedOut:
      return "timed-out";
    case Reason::kStopping:
      return "stopping";
    case Reason::kStoppedPartly:
      return "stopped-partly";
    case Reason::kTonerLow:
      return "toner-low";
    case Reason::kTonerEmpty:
      return "toner-empty";
    case Reason::kSpoolAreaFull:
      return "spool-area-full";
    case Reason::kCoverOpen:
      return "cover-open";
    case Reason::kInterlockOpen:
      return "interlock-open";
    case Reason::kDoorOpen:
      return "door-open";
    case Reason::kInputTrayMissing:
      return "input-tray-missing";
    case Reason::kMediaLow:
      return "media-low";
    case Reason::kMediaEmpty:
      return "media-empty";
    case Reason::kOutputTrayMissing:
      return "output-tray-missing";
    case Reason::kOutputAreaAlmostFull:
      return "output-area-almost-full";
    case Reason::kOutputAreaFull:
      return "output-area-full";
    case Reason::kMarkerSupplyLow:
      return "marker-supply-low";
    case Reason::kMarkerSupplyEmpty:
      return "marker-supply-empty";
    case Reason::kMarkerWasteAlmostFull:
      return "marker-waste-almost-full";
    case Reason::kMarkerWasteFull:
      return "marker-waste-full";
    case Reason::kFuserOverTemp:
      return "fuser-over-temp";
    case Reason::kFuserUnderTemp:
      return "fuser-under-temp";
    case Reason::kOpcNearEol:
      return "opc-near-eol";
    case Reason::kOpcLifeOver:
      return "opc-life-over";
    case Reason::kDeveloperLow:
      return "developer-low";
    case Reason::kDeveloperEmpty:
      return "developer-empty";
    case Reason::kInterpreterResourceUnavailable:
      return "interpreter-resource-unavailable";
    case Reason::kCupsPkiExpired:
      return "cups-pki-expired";
  }
}

std::string_view PrinterStatus::PrinterReason::SeverityName() const {
  switch (severity) {
    case Severity::kUnknownSeverity:
      return "unknown";
    case Severity::kReport:
      return "report";
    case Severity::kWarning:
      return "warning";
    case Severity::kError:
      return "error";
  }
}

std::string PrinterStatus::AllReasonsAsString() const {
  std::vector<std::string> reason_strings;
  std::transform(reasons.begin(), reasons.end(),
                 std::back_inserter(reason_strings),
                 [](const PrinterStatus::PrinterReason& reason) {
                   return base::StringPrintf("%s/%s", reason.ReasonName(),
                                             reason.SeverityName());
                 });
  return base::JoinString(reason_strings, ";");
}

}  // namespace printing