summaryrefslogtreecommitdiffstats
path: root/btcore/include
diff options
context:
space:
mode:
authorZach Johnson <zachoverflow@google.com>2014-09-22 22:14:04 -0700
committerAndre Eisenbach <eisenbach@google.com>2015-03-16 16:51:35 -0700
commit72f308ee6d3983ae2c0d67be3de2451f2dd72dcb (patch)
tree083e9f92cc57225be573cd1ff48fb8f5278f7af4 /btcore/include
parentc8ac8a276f61a9fc81b542f394de19c6732417ba (diff)
downloadandroid_system_bt-72f308ee6d3983ae2c0d67be3de2451f2dd72dcb.tar.gz
android_system_bt-72f308ee6d3983ae2c0d67be3de2451f2dd72dcb.tar.bz2
android_system_bt-72f308ee6d3983ae2c0d67be3de2451f2dd72dcb.zip
First pass at implementing modules
This first step creates the notion of a module and corresponding lifecycle functions, with helpers to simplify working with them. Once everything is converted over to this module format, then we can make the stack manager automagically find the correct order for init/start_up/shut_down/clean_up
Diffstat (limited to 'btcore/include')
-rw-r--r--btcore/include/module.h55
1 files changed, 55 insertions, 0 deletions
diff --git a/btcore/include/module.h b/btcore/include/module.h
new file mode 100644
index 000000000..2a0cf09cb
--- /dev/null
+++ b/btcore/include/module.h
@@ -0,0 +1,55 @@
+/******************************************************************************
+ *
+ * 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 <stdbool.h>
+
+#include "future.h"
+
+typedef future_t *(*module_lifecycle_fn)(void);
+
+typedef struct {
+ char *name;
+ module_lifecycle_fn init;
+ module_lifecycle_fn start_up;
+ module_lifecycle_fn shut_down;
+ module_lifecycle_fn clean_up;
+ const char *dependencies[];
+} module_t;
+
+// Prepares module management. Must be called before doing anything with modules.
+void module_management_start(void);
+// Cleans up all module management resources.
+void module_management_stop(void);
+
+const module_t *get_module(const char *name);
+
+// Initialize the provided module. |module| may not be NULL
+// and must not be initialized.
+bool module_init(const module_t *module);
+// Start up the provided module. |module| may not be NULL
+// and must be initialized or have no init function.
+bool module_start_up(const module_t *module);
+// Shut down the provided module. |module| may not be NULL.
+// If not started, does nothing.
+void module_shut_down(const module_t *module);
+// Clean up the provided module. |module| may not be NULL.
+// If not initialized, does nothing.
+void module_clean_up(const module_t *module);
+