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

Commit 76a9ab6a authored by June R. Tate-Gans's avatar June R. Tate-Gans Committed by Andre Eisenbach
Browse files

First pass at the bluedroid profile manager.

parent 0b1f6993
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ This document lists all of the log tags used by bluedroid.
* bt_osi_data_dispatcher
* bt_osi_reactor
* bt_osi_socket
* bt_profile_manager
* bt_sdp_client
* btsnoop
* btsnoop_net
+41 −0
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.
 #
 ##############################################################################

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_C_INCLUDES := \
    $(LOCAL_PATH)/.. \
    $(LOCAL_PATH)/include \
    $(LOCAL_PATH)/../btcore/include \
    $(LOCAL_PATH)/../include \
    $(LOCAL_PATH)/../osi/include \
    $(bdroid_C_INCLUDES)

LOCAL_SRC_FILES := \
    src/manager.c

LOCAL_CFLAGS := $(bdroid_CFLAGS)
LOCAL_CONLYFLAGS := $(bdroid_CONLYFLAGS)
LOCAL_MODULE := libbtprofile
LOCAL_MODULE_TAGS := optional
LOCAL_SHARED_LIBRARIES := libc liblog
LOCAL_MODULE_CLASS := STATIC_LIBRARIES

include $(BUILD_STATIC_LIBRARY)
+41 −0
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

static const char PROFILE_MANAGER_MODULE[] = "profile_manager_module";

typedef enum {
  PROFILE_POWER_ACTIVE,
  PROFILE_POWER_HOLD,
  PROFILE_POWER_SNIFF,
  PROFILE_POWER_PARK
} profile_power_level_t;

typedef struct profile_t {
  const char *name;
  profile_power_level_t lowest_acceptable_power_mode;
  bool in_use;
} profile_t;

// Registers a given Bluetooth |profile| with the manager.
void profile_register(const profile_t *profile);

// Looks up a previously registered profile by |name|. If no profile was
// registered by the given |name|, then this function returns NULL.
const profile_t *profile_by_name(const char *name);
+87 −0
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_profile_manager"

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

#include "btcore/include/module.h"
#include "profile/include/manager.h"
#include "osi/include/future.h"
#include "osi/include/hash_functions.h"
#include "osi/include/hash_map.h"
#include "osi/include/log.h"
#include "osi/include/osi.h"

static const size_t number_of_profile_buckets = 15;

static bool initialized;
static hash_map_t *profile_map;

// Lifecycle management functions

static future_t *init(void) {
  profile_map = hash_map_new(
    number_of_profile_buckets,
    hash_function_string,
    NULL,
    NULL,
    NULL);

  initialized = true;
  return NULL;
}

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

  hash_map_free(profile_map);
  profile_map = NULL;

  return NULL;
}

const module_t profile_manager_module = {
  .name = PROFILE_MANAGER_MODULE,
  .init = init,
  .start_up = NULL,
  .shut_down = NULL,
  .clean_up = clean_up,
  .dependencies = {
    NULL
  }
};

// Interface functions

void profile_register(const profile_t *profile) {
  assert(initialized);
  assert(profile != NULL);
  assert(profile->name != NULL);
  assert(!hash_map_has_key(profile_map, profile->name));

  hash_map_set(profile_map, profile->name, (void *) profile);
}

const profile_t *profile_by_name(const char *name) {
  assert(initialized);
  assert(name != NULL);

  return (profile_t *)hash_map_get(profile_map, name);
}