Bug 1874684 - Part 4: Prefer const references instead of copying Instant values....
[gecko.git] / dom / midi / MIDILog.cpp
blobcc9945ed5867921cb617e8747d4d16534dc2f05f
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #include "MIDILog.h"
7 #include "mozilla/dom/MIDITypes.h"
8 #include "mozilla/dom/MIDIPortBinding.h"
10 mozilla::LazyLogModule gWebMIDILog("WebMIDI");
12 void LogMIDIMessage(const mozilla::dom::MIDIMessage& aMessage,
13 const nsAString& aPortId,
14 mozilla::dom::MIDIPortType aDirection) {
15 if (MOZ_LOG_TEST(gWebMIDILog, mozilla::LogLevel::Debug)) {
16 if (MOZ_LOG_TEST(gWebMIDILog, mozilla::LogLevel::Verbose)) {
17 uint32_t byteCount = aMessage.data().Length();
18 nsAutoCString logMessage;
19 // Log long messages inline with the timestamp and the length, log
20 // longer messages a bit like xxd
21 logMessage.AppendPrintf(
22 "%s %s length=%u", NS_ConvertUTF16toUTF8(aPortId).get(),
23 aDirection == mozilla::dom::MIDIPortType::Input ? "->" : "<-",
24 byteCount);
26 if (byteCount <= 3) {
27 logMessage.AppendPrintf(" [");
28 // Regular messages
29 for (uint32_t i = 0; i < byteCount - 1; i++) {
30 logMessage.AppendPrintf("%x ", aMessage.data()[i]);
32 logMessage.AppendPrintf("%x]", aMessage.data()[byteCount - 1]);
33 } else {
34 // Longer messages
35 for (uint32_t i = 0; i < byteCount; i++) {
36 if (!(i % 8)) {
37 logMessage.AppendPrintf("\n%08u:\t", i);
39 logMessage.AppendPrintf("%x ", aMessage.data()[i]);
42 MOZ_LOG(gWebMIDILog, mozilla::LogLevel::Verbose,
43 ("%s", logMessage.get()));