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

Commit 8973fb83 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Initial entry dump module proto"

parents c8d60183 370c655d
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
cc_defaults {
    name: "gd_defaults",
    include_dirs: ["external/protobuf/src"],
    target: {
        android: {
            test_config_template: "AndroidTestTemplate.xml",
+17 −0
Original line number Diff line number Diff line
@@ -26,6 +26,10 @@ constexpr std::chrono::milliseconds kModuleStopTimeout = std::chrono::millisecon
ModuleFactory::ModuleFactory(std::function<Module*()> ctor) : ctor_(ctor) {
}

std::unique_ptr<google::protobuf::Message> Module::DumpState() const {
  return nullptr;
}

std::string Module::ToString() const {
  return "Module";
}
@@ -120,4 +124,17 @@ os::Handler* ModuleRegistry::GetModuleHandler(const ModuleFactory* module) const
  }
  return nullptr;
}

void ModuleDumper::DumpState() const {
  for (auto it = module_registry_.start_order_.rbegin(); it != module_registry_.start_order_.rend(); it++) {
    auto instance = module_registry_.started_modules_.find(*it);
    ASSERT(instance != module_registry_.started_modules_.end());
    std::unique_ptr<google::protobuf::Message> message = instance->second->DumpState();
    if (message == nullptr) {
      continue;
    }
    // TODO(cmanton) Process module message into master proto
  }
}

}  // namespace bluetooth
+25 −7
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

#pragma once

#include <google/protobuf/message.h>
#include <functional>
#include <future>
#include <map>
@@ -30,6 +31,7 @@
namespace bluetooth {

class Module;
class ModuleDumper;
class ModuleRegistry;

class ModuleFactory {
@@ -42,8 +44,9 @@ class ModuleFactory {
};

class ModuleList {
 friend ModuleRegistry;
 friend Module;
 friend ModuleRegistry;

public:
 template <class T>
 void add() {
@@ -62,7 +65,9 @@ class ModuleList {
// The module registry will also use the factory as the identifier
// for that module.
class Module {
  friend ModuleDumper;
  friend ModuleRegistry;

 public:
  virtual ~Module() = default;
 protected:
@@ -76,6 +81,9 @@ class Module {
  // Release all resources, you're about to be deleted
  virtual void Stop() = 0;

  // Get relevant state data from the module
  virtual std::unique_ptr<google::protobuf::Message> DumpState() const;

  virtual std::string ToString() const;

  ::bluetooth::os::Handler* GetHandler() const;
@@ -97,6 +105,7 @@ class Module {

class ModuleRegistry {
 friend Module;
 friend ModuleDumper;
 friend class StackManager;
 public:
  template <class T>
@@ -131,6 +140,15 @@ class ModuleRegistry {
  std::vector<const ModuleFactory*> start_order_;
};

class ModuleDumper {
 public:
  ModuleDumper(ModuleRegistry& module_registry) : module_registry_(module_registry) {}
  void DumpState() const;

 private:
  ModuleRegistry& module_registry_;
};

class TestModuleRegistry : public ModuleRegistry {
 public:
  void InjectTestModule(const ModuleFactory* module, Module* instance) {
+13 −0
Original line number Diff line number Diff line
@@ -16,3 +16,16 @@ cc_library_static {
    },
    srcs: ["bluetooth/metrics/bluetooth.proto"],
}

cc_library_static {
    name: "libbluetooth-protos",
    host_supported: true,
    proto: {
        export_proto_headers: true,
        include_dirs: ["external/protobuf/src"],
    },
    srcs: [
        "bluetooth/dumpmod.proto",
        "bluetooth/metrics/bluetooth.proto"
    ],
}
+30 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

syntax = "proto3";

package bluetooth;

import "google/protobuf/any.proto";

message ModuleDumpState {
  string name = 1;
  google.protobuf.Any data = 2;
}

message Dumpmod {
  map<string, ModuleDumpState> module_dump_states = 1;
}