tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

MIDILog.cpp (1707B)


      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/. */
      4 
      5 #include "MIDILog.h"
      6 
      7 #include "mozilla/dom/MIDIPortBinding.h"
      8 #include "mozilla/dom/MIDITypes.h"
      9 
     10 mozilla::LazyLogModule gWebMIDILog("WebMIDI");
     11 
     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);
     25 
     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]);
     31        }
     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);
     38          }
     39          logMessage.AppendPrintf("%x ", aMessage.data()[i]);
     40        }
     41      }
     42      MOZ_LOG(gWebMIDILog, mozilla::LogLevel::Verbose,
     43              ("%s", logMessage.get()));
     44    }
     45  }
     46 }