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

Commit 13dfc30c authored by Jakub Pawlowski's avatar Jakub Pawlowski Committed by Andre Eisenbach
Browse files

Remove currently unused peer device module and tests

The module is currently not used and it is currently not obvious if this
should be a module in the first place.

Filed separate bug (#29057391) to re-visit the concept in a future
refactor, but removing unused code for now.

Bug: 29000421
Change-Id: Ie369574e62281fa1d7c3284c86c4509de558fa15
parent be3e6dce
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -33,7 +33,6 @@ LOCAL_C_INCLUDES := \
    $(bluetooth_C_INCLUDES)

LOCAL_SRC_FILES := \
    src/classic/peer.cc \
    src/controller.c \
    src/interop.c

@@ -58,8 +57,7 @@ LOCAL_C_INCLUDES := \

LOCAL_SRC_FILES := \
    ../osi/test/AllocationTestHarness.cc \
    ./test/interop_test.cc \
    ./test/classic/peer_test.cc
    ./test/interop_test.cc

LOCAL_MODULE := net_test_device
LOCAL_MODULE_TAGS := tests
+0 −2
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@

static_library("device") {
  sources = [
    "src/classic/peer.cc",
    "src/controller.c",
    "src/interop.c",
  ]
@@ -34,7 +33,6 @@ executable("net_test_device") {
  testonly = true
  sources = [
    "//osi/test/AllocationTestHarness.cc",
    "test/classic/peer_test.cc",
  ]

  include_dirs = [ "//" ]
+0 −42
Original line number Diff line number Diff line
/******************************************************************************
 *
 *  Copyright (C) 2014 Google, Inc.
 *
 *  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 "btcore/include/bdaddr.h"

#ifdef __cplusplus
extern "C" {
#endif

static const char CLASSIC_PEER_MODULE[] = "classic_peer_module";

typedef struct classic_peer_t classic_peer_t;

// Returns a classic_peer_t for the provided |address|. If the peer
// already exists, that instance is returned. Otherwise a classic_peer_t
// is constructed for that |address| and then returned. |address| may not
// be NULL.
classic_peer_t *classic_peer_by_address(bt_bdaddr_t *address);

// Returns the bluetooth address of the |peer|. |peer| may not be NULL.
const bt_bdaddr_t *classic_peer_get_address(classic_peer_t *peer);

#ifdef __cplusplus
}
#endif

system/device/src/classic/peer.cc

deleted100644 → 0
+0 −99
Original line number Diff line number Diff line
/******************************************************************************
 *
 *  Copyright (C) 2014 Google, Inc.
 *
 *  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.
 *
 ******************************************************************************/

#define LOG_TAG "bt_classic_peer"

#include "device/include/classic/peer.h"

#include <assert.h>
#include <pthread.h>
#include <stdbool.h>
#include <unordered_map>

#include "btcore/include/module.h"
#include "osi/include/allocator.h"
#include "osi/include/future.h"
#include "osi/include/osi.h"

struct classic_peer_t {
  bt_bdaddr_t address;
};


static bool initialized;
static pthread_mutex_t bag_of_peers_lock;

static std::unordered_map<bt_bdaddr_t*,classic_peer_t*> peers_by_addresz;

// Module lifecycle functions

static future_t *init(void) {
  pthread_mutex_init(&bag_of_peers_lock, NULL);

  initialized = true;
  return NULL;
}

static future_t *clean_up(void) {
  initialized = false;

  peers_by_addresz.clear();

  pthread_mutex_destroy(&bag_of_peers_lock);
  return NULL;
}

extern "C" EXPORT_SYMBOL const module_t classic_peer_module = {
  .name = CLASSIC_PEER_MODULE,
  .init = init,
  .start_up = NULL,
  .shut_down = NULL,
  .clean_up = clean_up
};

// Interface functions

classic_peer_t *classic_peer_by_address(bt_bdaddr_t *address) {
  assert(initialized);
  assert(address != NULL);

  auto map_ptr = peers_by_addresz.find(address);
  if (map_ptr != peers_by_addresz.end()) {
    return map_ptr->second;
  }

  pthread_mutex_lock(&bag_of_peers_lock);

  // Make sure it didn't get added in the meantime
  map_ptr = peers_by_addresz.find(address);
  if (map_ptr != peers_by_addresz.end())
    return map_ptr->second;

  // Splice in a new peer struct on behalf of the caller.
  classic_peer_t *peer = (classic_peer_t*)osi_calloc(sizeof(classic_peer_t));
  peer->address = *address;
  peers_by_addresz[&peer->address] = peer;

  pthread_mutex_unlock(&bag_of_peers_lock);
  return peer;
}

const bt_bdaddr_t *classic_peer_get_address(classic_peer_t *peer) {
  assert(peer != NULL);
  return &peer->address;
}
+0 −86
Original line number Diff line number Diff line
/******************************************************************************
 *
 *  Copyright (C) 2014 Google, Inc.
 *
 *  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.
 *
 ******************************************************************************/

#include <gtest/gtest.h>

#include "osi/test/AllocationTestHarness.h"

extern "C" {
#include "btcore/include/bdaddr.h"
#include "btcore/include/module.h"
#include "device/include/classic/peer.h"

extern const module_t classic_peer_module;
}

class ClassicPeerTest : public AllocationTestHarness {
  protected:
    virtual void SetUp() {
      AllocationTestHarness::SetUp();

      module_management_start();
      module_init(&classic_peer_module);
    }

    virtual void TearDown() {
      module_clean_up(&classic_peer_module);
      module_management_stop();

      AllocationTestHarness::TearDown();
    }
};

TEST_F(ClassicPeerTest, test_basic_get) {
  bt_bdaddr_t test_address;
  string_to_bdaddr("12:34:56:78:9A:BC", &test_address);

  classic_peer_t *peer = classic_peer_by_address(&test_address);

  EXPECT_TRUE(peer != NULL);
  // The stored address should be a copy (different memory address)
  EXPECT_NE(&test_address, classic_peer_get_address(peer));
  EXPECT_TRUE(bdaddr_equals(&test_address, classic_peer_get_address(peer)));
}

TEST_F(ClassicPeerTest, test_multi_get_are_same) {
  bt_bdaddr_t test_address;
  string_to_bdaddr("12:34:56:78:9A:BC", &test_address);

  classic_peer_t *peer = classic_peer_by_address(&test_address);
  classic_peer_t *peer_again = classic_peer_by_address(&test_address);

  EXPECT_TRUE(peer != NULL);
  EXPECT_TRUE(peer_again != NULL);
  EXPECT_EQ(peer, peer_again);
}

TEST_F(ClassicPeerTest, test_multi_get_different) {
  bt_bdaddr_t test_address0;
  bt_bdaddr_t test_address1;
  string_to_bdaddr("12:34:56:78:9A:BC", &test_address0);
  string_to_bdaddr("42:42:42:42:42:42", &test_address1);

  classic_peer_t *peer0 = classic_peer_by_address(&test_address0);
  classic_peer_t *peer1 = classic_peer_by_address(&test_address1);

  EXPECT_TRUE(peer0 != NULL);
  EXPECT_TRUE(peer1 != NULL);
  EXPECT_TRUE(bdaddr_equals(&test_address0, classic_peer_get_address(peer0)));
  EXPECT_TRUE(bdaddr_equals(&test_address1, classic_peer_get_address(peer1)));
}