summaryrefslogtreecommitdiffstats
path: root/profile
diff options
context:
space:
mode:
authorJune R. Tate-Gans <jtgans@google.com>2015-01-06 17:38:29 -0800
committerAndre Eisenbach <eisenbach@google.com>2015-03-16 16:51:41 -0700
commit98ffd8a0be0ea2202d0c6e0ee2abf92d16238389 (patch)
tree0548321106721ad6db2d5d0891e21894433ad86c /profile
parent8ff3fea05b0d01f7a011326542161f892e2b31d6 (diff)
downloadandroid_system_bt-98ffd8a0be0ea2202d0c6e0ee2abf92d16238389.tar.gz
android_system_bt-98ffd8a0be0ea2202d0c6e0ee2abf92d16238389.tar.bz2
android_system_bt-98ffd8a0be0ea2202d0c6e0ee2abf92d16238389.zip
First pass at the bluedroid profile manager.
Diffstat (limited to 'profile')
-rw-r--r--profile/Android.mk41
-rw-r--r--profile/include/manager.h41
-rw-r--r--profile/src/manager.c87
3 files changed, 169 insertions, 0 deletions
diff --git a/profile/Android.mk b/profile/Android.mk
new file mode 100644
index 000000000..5683d7fbf
--- /dev/null
+++ b/profile/Android.mk
@@ -0,0 +1,41 @@
+ ##############################################################################
+ #
+ # 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)
diff --git a/profile/include/manager.h b/profile/include/manager.h
new file mode 100644
index 000000000..587369fc4
--- /dev/null
+++ b/profile/include/manager.h
@@ -0,0 +1,41 @@
+/******************************************************************************
+ *
+ * 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);
diff --git a/profile/src/manager.c b/profile/src/manager.c
new file mode 100644
index 000000000..9e56b655e
--- /dev/null
+++ b/profile/src/manager.c
@@ -0,0 +1,87 @@
+/******************************************************************************
+ *
+ * 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);
+}