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

Commit 50294fde authored by Chris Manton's avatar Chris Manton
Browse files

gd: Initial entry for legacy storage shim

Bug: 147315979
Test: Compiles bluetooth_test_gd
Change-Id: Id3f6918e3216c30d214632a6a8bd36e7e8010f41
parent 83f5a955
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@ filegroup {
            "scanning.cc",
            "security.cc",
            "stack.cc",
            "storage.cc",
    ],
}

+2 −0
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ struct IL2cap;
struct IPage;
struct IScanning;
struct ISecurity;
struct IStorage;

struct IStack {
  virtual void Start() = 0;
@@ -50,6 +51,7 @@ struct IStack {
  virtual IPage* GetPage() = 0;
  virtual IScanning* GetScanning() = 0;
  virtual ISecurity* GetSecurity() = 0;
  virtual IStorage* GetStorage() = 0;

  virtual ~IStack() {}
};
+45 −0
Original line number Diff line number Diff line
/*
 * Copyright 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.
 */
#pragma once

#include <functional>
#include <memory>
#include <string>

struct config_t;

/**
 * The gd API exported to the legacy api
 */
namespace bluetooth {
namespace shim {

using ConfigReadCallback = std::function<void(std::unique_ptr<config_t>)>;
using ConfigWriteCallback = std::function<void(bool)>;
using ChecksumReadCallback = std::function<void(std::string)>;
using ChecksumWriteCallback = std::function<void(bool)>;

struct IStorage {
  virtual void ConfigRead(const std::string filename, ConfigReadCallback callback) = 0;
  virtual void ConfigWrite(const std::string filename, const config_t* config, ConfigWriteCallback callback) = 0;
  virtual void ChecksumRead(const std::string filename, ChecksumReadCallback callback) = 0;
  virtual void ChecksumWrite(const std::string filename, const std::string& checksum, ChecksumWriteCallback) = 0;

  virtual ~IStorage() {}
};

}  // namespace shim
}  // namespace bluetooth
+1 −0
Original line number Diff line number Diff line
@@ -36,3 +36,4 @@
#include "gd/shim/iscanning.h"
#include "gd/shim/isecurity.h"
#include "gd/shim/istack.h"
#include "gd/shim/istorage.h"
+11 −0
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@
#include "shim/page.h"
#include "shim/scanning.h"
#include "shim/security.h"
#include "shim/storage.h"
#include "stack_manager.h"

using ::bluetooth::os::Thread;
@@ -81,6 +82,7 @@ struct bluetooth::shim::Stack::impl {
    modules.add<::bluetooth::shim::Page>();
    modules.add<::bluetooth::shim::Scanning>();
    modules.add<::bluetooth::shim::Security>();
    modules.add<::bluetooth::shim::Storage>();

    stack_thread_ = new Thread("gd_stack_thread", Thread::Priority::NORMAL);
    stack_manager_.StartUp(&modules, stack_thread_);
@@ -157,6 +159,11 @@ struct bluetooth::shim::Stack::impl {
    return stack_manager_.GetInstance<bluetooth::shim::Security>();
  }

  IStorage* GetStorage() {
    ASSERT(is_running_);
    return stack_manager_.GetInstance<bluetooth::shim::Storage>();
  }

 private:
  os::Thread* stack_thread_ = nullptr;
  bool is_running_ = false;
@@ -220,6 +227,10 @@ bluetooth::shim::ISecurity* bluetooth::shim::Stack::GetSecurity() {
  return pimpl_->GetSecurity();
}

bluetooth::shim::IStorage* bluetooth::shim::Stack::GetStorage() {
  return pimpl_->GetStorage();
}

bluetooth::shim::IStack* bluetooth::shim::GetGabeldorscheStack() {
  static IStack* instance = new Stack();
  return instance;
Loading