blob: d9f3ab99d51263b2087f2f42018db95ebfb5e886 [file] [log] [blame]
// Copyright 2021 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <utility>
#include "hermes/hermes_common.h"
#include <base/logging.h>
namespace hermes {
std::string GetTrailingChars(const std::string& pii, int num_chars) {
DCHECK_GE(num_chars, 0);
if (num_chars > pii.length())
return pii;
return pii.substr(pii.length() - num_chars);
}
std::string GetObjectPathForLog(const dbus::ObjectPath& dbus_path) {
const std::string kPrefix = "dbus_path(Last 3 chars): ";
const int kDbusPathPrintLen = 3;
return kPrefix + GetTrailingChars(dbus_path.value(), kDbusPathPrintLen);
}
void IgnoreErrorRunClosure(base::OnceCallback<void()> cb, int err) {
VLOG(2) << "Modem message processed with code:" << err;
std::move(cb).Run();
}
void PrintMsgProcessingResult(int err) {
VLOG(2) << "Modem processed message processed with code:" << err;
}
void RunNextStep(
base::OnceCallback<void(base::OnceCallback<void(int)>)> next_step,
base::OnceCallback<void(int)> cb,
int err) {
VLOG(2) << "Modem message processed with code:" << err;
if (err) {
std::move(cb).Run(err);
return;
}
std::move(next_step).Run(std::move(cb));
}
} // namespace hermes