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

Commit 1cc3eff4 authored by Abhishek Pandit-Subedi's avatar Abhishek Pandit-Subedi Committed by Abhishek Pandit-Subedi
Browse files

floss: Accept --hci init flag

Parse and expose --hci flag in InitFlags.

Bug: 193261880
Test: Verify correct pid file gets generated
Tag: #floss
Change-Id: Ie3e2e890feb0876f25be7ad6b4734f3763faf6b6
parent 0aec55d7
Loading
Loading
Loading
Loading
+18 −0
Original line number Original line Diff line number Diff line
@@ -18,6 +18,7 @@


#include "init_flags.h"
#include "init_flags.h"


#include <cstdlib>
#include <string>
#include <string>


#include "common/strings.h"
#include "common/strings.h"
@@ -27,6 +28,7 @@ namespace bluetooth {
namespace common {
namespace common {


bool InitFlags::logging_debug_enabled_for_all = false;
bool InitFlags::logging_debug_enabled_for_all = false;
int InitFlags::hci_adapter = 0;
std::unordered_map<std::string, bool> InitFlags::logging_debug_explicit_tag_settings = {};
std::unordered_map<std::string, bool> InitFlags::logging_debug_explicit_tag_settings = {};


bool ParseBoolFlag(const std::vector<std::string>& flag_pair, const std::string& flag, bool* variable) {
bool ParseBoolFlag(const std::vector<std::string>& flag_pair, const std::string& flag, bool* variable) {
@@ -41,6 +43,19 @@ bool ParseBoolFlag(const std::vector<std::string>& flag_pair, const std::string&
  return true;
  return true;
}
}


bool ParseIntFlag(const std::vector<std::string>& flag_pair, const std::string& flag, int* variable) {
  if (flag != flag_pair[0]) {
    return false;
  }
  auto value = Int64FromString(flag_pair[1]);
  if (!value || *value > INT32_MAX) {
    return false;
  }

  *variable = *value;
  return true;
}

void InitFlags::Load(const char** flags) {
void InitFlags::Load(const char** flags) {
  const char** flags_copy = flags;
  const char** flags_copy = flags;
  SetAll(false);
  SetAll(false);
@@ -52,6 +67,9 @@ void InitFlags::Load(const char** flags) {
      continue;
      continue;
    }
    }


    // Parse adapter index (defaults to 0)
    ParseIntFlag(flag_pair, "--hci", &hci_adapter);

    ParseBoolFlag(flag_pair, "INIT_logging_debug_enabled_for_all", &logging_debug_enabled_for_all);
    ParseBoolFlag(flag_pair, "INIT_logging_debug_enabled_for_all", &logging_debug_enabled_for_all);
    if ("INIT_logging_debug_enabled_for_tags" == flag_pair[0]) {
    if ("INIT_logging_debug_enabled_for_tags" == flag_pair[0]) {
      auto tags = StringSplit(flag_pair[1], ",");
      auto tags = StringSplit(flag_pair[1], ",");
+5 −0
Original line number Original line Diff line number Diff line
@@ -41,11 +41,16 @@ class InitFlags final {
    return logging_debug_enabled_for_all;
    return logging_debug_enabled_for_all;
  }
  }


  inline static int GetAdapterIndex() {
    return hci_adapter;
  }

  static void SetAllForTesting();
  static void SetAllForTesting();


 private:
 private:
  static void SetAll(bool value);
  static void SetAll(bool value);
  static bool logging_debug_enabled_for_all;
  static bool logging_debug_enabled_for_all;
  static int hci_adapter;
  // save both log allow list and block list in the map to save hashing time
  // save both log allow list and block list in the map to save hashing time
  static std::unordered_map<std::string, bool> logging_debug_explicit_tag_settings;
  static std::unordered_map<std::string, bool> logging_debug_explicit_tag_settings;
};
};