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

Commit 6ba7c206 authored by Chris Manton's avatar Chris Manton
Browse files

Introduce btm circular buffer history

Toward loggable code

Bug: 163134718
Tag: #refactor
Test: gd/cert/run --host

Change-Id: If9ed3213f8a8a96a1ea5d6ad530c7952bf312346
parent 35de2884
Loading
Loading
Loading
Loading
+26 −0
Original line number Diff line number Diff line
@@ -19,7 +19,10 @@
#define BTM_INT_TYPES_H

#include <cstdint>
#include <memory>
#include <string>

#include "gd/common/circular_buffer.h"
#include "osi/include/list.h"
#include "stack/acl/acl.h"
#include "stack/btm/btm_ble_int_types.h"
@@ -39,6 +42,27 @@

#define BTM_MAX_SCN_ 31  // PORT_MAX_RFC_PORTS packages/modules/Bluetooth/system/stack/include/rfcdefs.h

constexpr size_t kMaxLogSize = 255;
class TimestampedStringCircularBuffer
    : public bluetooth::common::TimestampedCircularBuffer<std::string> {
 public:
  explicit TimestampedStringCircularBuffer(size_t size)
      : bluetooth::common::TimestampedCircularBuffer<std::string>(size) {}

  void Push(std::string s) {
    bluetooth::common::TimestampedCircularBuffer<std::string>::Push(
        s.substr(0, kMaxLogSize));
  }

  template <typename... Args>
  void Push(Args... args) {
    char buf[kMaxLogSize];
    std::snprintf(buf, sizeof(buf), args...);
    bluetooth::common::TimestampedCircularBuffer<std::string>::Push(
        std::string(buf));
  }
};

/*
 * Define device configuration structure
*/
@@ -288,6 +312,8 @@ typedef struct {

  tACL_CB acl_cb_;

  std::shared_ptr<TimestampedStringCircularBuffer> history_{nullptr};

 private:
  friend uint8_t BTM_AllocateSCN(void);
  friend bool BTM_TryAllocateSCN(uint8_t scn);