1 /* 2 * Copyright (C) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef MODULE_H 17 #define MODULE_H 18 19 #ifdef __cplusplus 20 extern "C" { 21 #endif 22 23 #define MAX_MODULE_DEPENDENCIES (5) 24 #define MAX_MODULES (20) 25 26 typedef struct { 27 const char *name; 28 void (*init)(int trace_level); 29 void (*startup)(); 30 void (*shutdown)(); 31 void (*cleanup)(); 32 const char *dependencies[MAX_MODULE_DEPENDENCIES]; 33 } Module; 34 35 void ModuleRegister(Module *module); 36 Module *ModuleGet(const char *name); 37 void ModuleInit(const char *name, int trace_level); 38 void ModuleStartup(const char *name); 39 void ModuleShutdown(const char *name); 40 void ModuleCleanup(const char *name); 41 42 #define MODULE_DECL(module) \ 43 void __attribute__((constructor)) do_module_init_##module(void) \ 44 { \ 45 ModuleRegister(&module); \ 46 } 47 48 #ifndef NO_SANITIZE 49 #ifdef __has_attribute 50 #if __has_attribute(no_sanitize) 51 #define NO_SANITIZE(type) __attribute__((no_sanitize(type))) 52 #endif 53 #endif 54 #endif 55 56 #ifndef NO_SANITIZE 57 #define NO_SANITIZE(type) 58 #endif 59 60 #ifdef __cplusplus 61 } 62 #endif 63 64 #endif // MODULE_H 65