Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0da4cf20 authored by Henri Chataing's avatar Henri Chataing Committed by Gerrit Code Review
Browse files

Merge "bt_trace: Delete ScopedIndent" into main

parents 87d679e8 9e36a1e0
Loading
Loading
Loading
Loading
+2 −5
Original line number Original line Diff line number Diff line
@@ -682,11 +682,8 @@ void AvrcpService::DebugDump(int fd) {
          device_list.size());
          device_list.size());


  std::stringstream stream;
  std::stringstream stream;
  {
    ScopedIndent indent(stream);
  for (const auto& device : device_list) {
  for (const auto& device : device_list) {
      stream << *device << std::endl;
    stream << "  " << *device << std::endl;
    }
  }
  }


  dprintf(fd, "%s", stream.str().c_str());
  dprintf(fd, "%s", stream.str().c_str());
+0 −49
Original line number Original line Diff line number Diff line
@@ -95,53 +95,4 @@ inline std::string& AppendField(std::string* p_result, bool append,
  return *p_result;
  return *p_result;
}
}


// This object puts the stream in a state where every time that a new line
// occurs, the next line is indented a certain number of spaces. The stream is
// reset to its previous state when the object is destroyed.
class ScopedIndent {
 public:
  ScopedIndent(std::ostream& stream, int indent_size = DEFAULT_TAB)
      : indented_buf_(stream, indent_size) {
    old_stream_ = &stream;
    old_stream_buf_ = stream.rdbuf();
    stream.rdbuf(&indented_buf_);
  }

  ~ScopedIndent() { old_stream_->rdbuf(old_stream_buf_); }

  static const size_t DEFAULT_TAB = 2;

 private:
  class IndentedStreamBuf : public std::streambuf {
   public:
    IndentedStreamBuf(std::ostream& stream, int indent_size)
        : wrapped_buf_(stream.rdbuf()),
          indent_size_(indent_size),
          indent_next_line_(true){};

   protected:
    virtual int overflow(int character) override {
      if (indent_next_line_ && character != '\n') {
        for (int i = 0; i < indent_size_; i++) wrapped_buf_->sputc(' ');
      }

      indent_next_line_ = false;
      if (character == '\n') {
        indent_next_line_ = true;
      }

      return wrapped_buf_->sputc(character);
    }

   private:
    std::streambuf* wrapped_buf_;
    int indent_size_;
    bool indent_next_line_;
  };

  std::ostream* old_stream_;
  std::streambuf* old_stream_buf_;
  IndentedStreamBuf indented_buf_;
};

#endif
#endif
+16 −20
Original line number Original line Diff line number Diff line
@@ -1878,16 +1878,13 @@ static std::string volumeToStr(int8_t volume) {


std::ostream& operator<<(std::ostream& out, const Device& d) {
std::ostream& operator<<(std::ostream& out, const Device& d) {
  // TODO: whether this should be turned into LOGGABLE STRING?
  // TODO: whether this should be turned into LOGGABLE STRING?
  out << ADDRESS_TO_LOGGABLE_STR(d.address_);
  out << "  " << ADDRESS_TO_LOGGABLE_STR(d.address_);
  if (d.IsActive()) out << " <Active>";
  if (d.IsActive()) out << " <Active>";
  out << std::endl;
  out << std::endl;
  ScopedIndent indent(out);
  out << "    Current Volume: " << volumeToStr(d.volume_) << std::endl;
  out << "    Current Volume: " << volumeToStr(d.volume_) << std::endl;
  out << "    Current Browsed Player ID: " << d.curr_browsed_player_id_
  out << "    Current Browsed Player ID: " << d.curr_browsed_player_id_
      << std::endl;
      << std::endl;
  out << "    Registered Notifications:\n";
  out << "    Registered Notifications:\n";
  {
    ScopedIndent indent(out);
  if (d.track_changed_.first) out << "        Track Changed\n";
  if (d.track_changed_.first) out << "        Track Changed\n";
  if (d.play_status_changed_.first) out << "        Play Status\n";
  if (d.play_status_changed_.first) out << "        Play Status\n";
  if (d.play_pos_changed_.first) out << "        Play Position\n";
  if (d.play_pos_changed_.first) out << "        Play Position\n";
@@ -1896,7 +1893,6 @@ std::ostream& operator<<(std::ostream& out, const Device& d) {
  if (d.addr_player_changed_.first) out << "        Addressed Player\n";
  if (d.addr_player_changed_.first) out << "        Addressed Player\n";
  if (d.avail_players_changed_.first) out << "        Available Players\n";
  if (d.avail_players_changed_.first) out << "        Available Players\n";
  if (d.uids_changed_.first) out << "        UIDs Changed\n";
  if (d.uids_changed_.first) out << "        UIDs Changed\n";
  }
  out << "    Last Play State: " << d.last_play_status_.state << std::endl;
  out << "    Last Play State: " << d.last_play_status_.state << std::endl;
  out << "    Last Song Sent ID: \"" << d.last_song_info_.media_id << "\"\n";
  out << "    Last Song Sent ID: \"" << d.last_song_info_.media_id << "\"\n";
  out << "    Current Folder: \"" << d.CurrentFolder() << "\"\n";
  out << "    Current Folder: \"" << d.CurrentFolder() << "\"\n";