1 /****************************************************************************** 2 * 3 * Copyright 2014 Google, Inc. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at: 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 ******************************************************************************/ 18 19 #pragma once 20 21 #include <stdbool.h> 22 23 #include "osi/include/future.h" 24 25 typedef future_t* (*module_lifecycle_fn)(void); 26 27 #define BTCORE_MAX_MODULE_DEPENDENCIES 10 28 29 typedef struct { 30 const char* name{nullptr}; 31 module_lifecycle_fn init{nullptr}; 32 module_lifecycle_fn start_up{nullptr}; 33 module_lifecycle_fn shut_down{nullptr}; 34 module_lifecycle_fn clean_up{nullptr}; 35 const char* dependencies[BTCORE_MAX_MODULE_DEPENDENCIES]{nullptr}; 36 } module_t; 37 38 // Prepares module management. Must be called before doing anything with 39 // modules. 40 void module_management_start(void); 41 // Cleans up all module management resources. 42 void module_management_stop(void); 43 44 const module_t* get_module(const char* name); 45 46 // Initialize the provided module. |module| may not be NULL 47 // and must not be initialized. 48 bool module_init(const module_t* module); 49 // Start up the provided module. |module| may not be NULL 50 // and must be initialized or have no init function. 51 bool module_start_up(const module_t* module); 52 // Shut down the provided module. |module| may not be NULL. 53 // If not started, does nothing. 54 void module_shut_down(const module_t* module); 55 // Clean up the provided module. |module| may not be NULL. 56 // If not initialized, does nothing. 57 void module_clean_up(const module_t* module); 58