10e98b08fSopenharmony_ci/*
20e98b08fSopenharmony_ci * Copyright (c) 2020 Huawei Device Co., Ltd.
30e98b08fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
40e98b08fSopenharmony_ci * you may not use this file except in compliance with the License.
50e98b08fSopenharmony_ci * You may obtain a copy of the License at
60e98b08fSopenharmony_ci *
70e98b08fSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
80e98b08fSopenharmony_ci *
90e98b08fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
100e98b08fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
110e98b08fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
120e98b08fSopenharmony_ci * See the License for the specific language governing permissions and
130e98b08fSopenharmony_ci * limitations under the License.
140e98b08fSopenharmony_ci */
150e98b08fSopenharmony_ci
160e98b08fSopenharmony_ci/**
170e98b08fSopenharmony_ci * @addtogroup Init OHOS Init
180e98b08fSopenharmony_ci * @{
190e98b08fSopenharmony_ci *
200e98b08fSopenharmony_ci * @brief Provides the entries for initializing and starting services and features.
210e98b08fSopenharmony_ci *
220e98b08fSopenharmony_ci * This module provides the entries for initializing services and features during service
230e98b08fSopenharmony_ci * development. \n
240e98b08fSopenharmony_ci * Services and features are initialized in the following sequence: core phase, core system
250e98b08fSopenharmony_ci * service, core system feature, system startup, system service, system feature, application-layer
260e98b08fSopenharmony_ci * service, and application-layer feature. \n
270e98b08fSopenharmony_ci *
280e98b08fSopenharmony_ci * @since 1.0
290e98b08fSopenharmony_ci * @version 1.0
300e98b08fSopenharmony_ci */
310e98b08fSopenharmony_ci
320e98b08fSopenharmony_ci/**
330e98b08fSopenharmony_ci * @file ohos_init.h
340e98b08fSopenharmony_ci *
350e98b08fSopenharmony_ci * @brief Provides the entries for initializing and starting services and features.
360e98b08fSopenharmony_ci *
370e98b08fSopenharmony_ci * This file provides the entries for initializing services and features during service
380e98b08fSopenharmony_ci * development. \n
390e98b08fSopenharmony_ci *
400e98b08fSopenharmony_ci * @since 1.0
410e98b08fSopenharmony_ci * @version 1.0
420e98b08fSopenharmony_ci */
430e98b08fSopenharmony_ci
440e98b08fSopenharmony_ci#ifndef OHOS_LAYER_INIT_H
450e98b08fSopenharmony_ci#define OHOS_LAYER_INIT_H
460e98b08fSopenharmony_ci#ifdef __cplusplus
470e98b08fSopenharmony_ci#if __cplusplus
480e98b08fSopenharmony_ciextern "C" {
490e98b08fSopenharmony_ci#endif
500e98b08fSopenharmony_ci#endif
510e98b08fSopenharmony_citypedef void (*InitCall)(void);
520e98b08fSopenharmony_ci
530e98b08fSopenharmony_ci#define USED_ATTR __attribute__((used))
540e98b08fSopenharmony_ci
550e98b08fSopenharmony_ci#ifdef LAYER_INIT_SHARED_LIB
560e98b08fSopenharmony_ci#define LAYER_INIT_LEVEL_0 0
570e98b08fSopenharmony_ci#define LAYER_INIT_LEVEL_1 1
580e98b08fSopenharmony_ci#define LAYER_INIT_LEVEL_2 2
590e98b08fSopenharmony_ci#define LAYER_INIT_LEVEL_3 3
600e98b08fSopenharmony_ci#define LAYER_INIT_LEVEL_4 4
610e98b08fSopenharmony_ci#define CTOR_VALUE_device 100
620e98b08fSopenharmony_ci#define CTOR_VALUE_core 110
630e98b08fSopenharmony_ci#define CTOR_VALUE_sys_service 120
640e98b08fSopenharmony_ci#define CTOR_VALUE_sys_feature 130
650e98b08fSopenharmony_ci#define CTOR_VALUE_app_service 140
660e98b08fSopenharmony_ci#define CTOR_VALUE_app_feature 150
670e98b08fSopenharmony_ci#define CTOR_VALUE_run  700
680e98b08fSopenharmony_ci#define LAYER_INITCALL(func, layer, clayer, priority)                                     \
690e98b08fSopenharmony_ci    static __attribute__((constructor(CTOR_VALUE_##layer + LAYER_INIT_LEVEL_##priority))) \
700e98b08fSopenharmony_ci        void BOOT_##layer##priority##func() {func();}
710e98b08fSopenharmony_ci#else
720e98b08fSopenharmony_ci#define LAYER_INITCALL(func, layer, clayer, priority)            \
730e98b08fSopenharmony_ci    static const InitCall USED_ATTR __zinitcall_##layer##_##func \
740e98b08fSopenharmony_ci        __attribute__((section(".zinitcall." clayer #priority ".init"))) = func
750e98b08fSopenharmony_ci#endif
760e98b08fSopenharmony_ci// Default priority is 2, priority range is [0, 4]
770e98b08fSopenharmony_ci#define LAYER_INITCALL_DEF(func, layer, clayer) \
780e98b08fSopenharmony_ci    LAYER_INITCALL(func, layer, clayer, 2)
790e98b08fSopenharmony_ci
800e98b08fSopenharmony_ci/**
810e98b08fSopenharmony_ci * @brief Identifies the entry for initializing and starting a core phase by the priority 2.
820e98b08fSopenharmony_ci *
830e98b08fSopenharmony_ci * This macro is used when Samgr is initialized and started. \n
840e98b08fSopenharmony_ci * This macro is used to identify the entry called at the priority 2 of the core phase of
850e98b08fSopenharmony_ci * the startup process. \n
860e98b08fSopenharmony_ci *
870e98b08fSopenharmony_ci * @param func Indicates the entry function for initializing and starting a core phase.
880e98b08fSopenharmony_ci * The type is void (*)(void).
890e98b08fSopenharmony_ci */
900e98b08fSopenharmony_ci#define CORE_INIT(func) LAYER_INITCALL_DEF(func, core, "core")
910e98b08fSopenharmony_ci/**
920e98b08fSopenharmony_ci * @brief Identifies the entry for initializing and starting a core phase by the specified
930e98b08fSopenharmony_ci * priority.
940e98b08fSopenharmony_ci *
950e98b08fSopenharmony_ci * This macro is used when Samgr is initialized and started. \n
960e98b08fSopenharmony_ci * This macro is used to identify the entry called at the specified priority of the core phase of
970e98b08fSopenharmony_ci * the startup process. \n
980e98b08fSopenharmony_ci *
990e98b08fSopenharmony_ci * @param func Indicates the entry function for initializing and starting a core phase.
1000e98b08fSopenharmony_ci * The type is void (*)(void).
1010e98b08fSopenharmony_ci * @param priority Indicates the calling priority when starting the core phase.
1020e98b08fSopenharmony_ci * The value range is [0,5), and the calling sequence is 0, 1, 2, 3, and 4.
1030e98b08fSopenharmony_ci */
1040e98b08fSopenharmony_ci#define CORE_INIT_PRI(func, priority) LAYER_INITCALL(func, core, "core", priority)
1050e98b08fSopenharmony_ci
1060e98b08fSopenharmony_ci/**
1070e98b08fSopenharmony_ci * @brief Identifies the entry for initializing and starting a core system service by the
1080e98b08fSopenharmony_ci * priority 2.
1090e98b08fSopenharmony_ci *
1100e98b08fSopenharmony_ci * This macro is used to identify the entry called at the priority 2 in the core system
1110e98b08fSopenharmony_ci * service phase of the startup process. \n
1120e98b08fSopenharmony_ci *
1130e98b08fSopenharmony_ci * @param func Indicates the entry function for initializing and starting a core system service.
1140e98b08fSopenharmony_ci * The type is void (*)(void).
1150e98b08fSopenharmony_ci */
1160e98b08fSopenharmony_ci#define SYS_SERVICE_INIT(func) LAYER_INITCALL_DEF(func, sys_service, "sys.service")
1170e98b08fSopenharmony_ci/**
1180e98b08fSopenharmony_ci * @brief Identifies the entry for initializing and starting a core system service by the
1190e98b08fSopenharmony_ci * specified priority.
1200e98b08fSopenharmony_ci *
1210e98b08fSopenharmony_ci * This macro is used to identify the entry called at the specified priority in the core system
1220e98b08fSopenharmony_ci * service phase of the startup process. \n
1230e98b08fSopenharmony_ci *
1240e98b08fSopenharmony_ci * @param func Indicates the entry function for initializing and starting a core system service.
1250e98b08fSopenharmony_ci * The type is void (*)(void).
1260e98b08fSopenharmony_ci * @param priority Indicates the calling priority when starting the core system service in the
1270e98b08fSopenharmony_ci * startup phase. The value range is [0,5), and the calling sequence is 0, 1, 2, 3, and 4.
1280e98b08fSopenharmony_ci */
1290e98b08fSopenharmony_ci#define SYS_SERVICE_INIT_PRI(func, priority) LAYER_INITCALL(func, sys_service, "sys.service", priority)
1300e98b08fSopenharmony_ci
1310e98b08fSopenharmony_ci/**
1320e98b08fSopenharmony_ci * @brief Identifies the entry for initializing and starting a core system feature by the
1330e98b08fSopenharmony_ci * priority 2.
1340e98b08fSopenharmony_ci *
1350e98b08fSopenharmony_ci * This macro is used to identify the entry called at the priority 2 in the core system
1360e98b08fSopenharmony_ci * feature phase of the startup process. \n
1370e98b08fSopenharmony_ci *
1380e98b08fSopenharmony_ci * @param func Indicates the entry function for initializing and starting a core system service.
1390e98b08fSopenharmony_ci * The type is void (*)(void).
1400e98b08fSopenharmony_ci */
1410e98b08fSopenharmony_ci#define SYS_FEATURE_INIT(func) LAYER_INITCALL_DEF(func, sys_feature, "sys.feature")
1420e98b08fSopenharmony_ci/**
1430e98b08fSopenharmony_ci * @brief Identifies the entry for initializing and starting a core system feature by the
1440e98b08fSopenharmony_ci * specified priority.
1450e98b08fSopenharmony_ci *
1460e98b08fSopenharmony_ci * This macro is used to identify the entry called at the specified priority in the core system
1470e98b08fSopenharmony_ci * feature phase of the startup process. \n
1480e98b08fSopenharmony_ci *
1490e98b08fSopenharmony_ci * @param func Indicates the entry function for initializing and starting a core system feature.
1500e98b08fSopenharmony_ci * The type is void (*)(void).
1510e98b08fSopenharmony_ci * @param priority Indicates the calling priority when starting the core system feature phase.
1520e98b08fSopenharmony_ci * The value range is [0, 5), and the calling sequence is 0, 1, 2, 3, and 4.
1530e98b08fSopenharmony_ci */
1540e98b08fSopenharmony_ci#define SYS_FEATURE_INIT_PRI(func, priority) LAYER_INITCALL(func, sys_feature, "sys.feature", priority)
1550e98b08fSopenharmony_ci
1560e98b08fSopenharmony_ci/**
1570e98b08fSopenharmony_ci * @brief Identifies the entry for initializing and starting a system running phase by the
1580e98b08fSopenharmony_ci * priority 2.
1590e98b08fSopenharmony_ci *
1600e98b08fSopenharmony_ci * This macro is used to identify the entry called at the priority 2 in the system startup
1610e98b08fSopenharmony_ci * phase of the startup process. \n
1620e98b08fSopenharmony_ci *
1630e98b08fSopenharmony_ci * @param func Indicates the entry function for initializing and starting a system running phase.
1640e98b08fSopenharmony_ci * The type is void (*)(void).
1650e98b08fSopenharmony_ci */
1660e98b08fSopenharmony_ci#define SYS_RUN(func) LAYER_INITCALL_DEF(func, run, "run")
1670e98b08fSopenharmony_ci/**
1680e98b08fSopenharmony_ci * @brief Identifies the entry for initializing and starting a system running phase by the
1690e98b08fSopenharmony_ci * specified priority.
1700e98b08fSopenharmony_ci *
1710e98b08fSopenharmony_ci * This macro is used to identify the entry called at the specified priority in the system startup
1720e98b08fSopenharmony_ci * phase of the startup process. \n
1730e98b08fSopenharmony_ci *
1740e98b08fSopenharmony_ci * @param func Indicates the entry function for initializing and starting a system running phase.
1750e98b08fSopenharmony_ci * The type is void (*)(void).
1760e98b08fSopenharmony_ci * @param priority Indicates the calling priority when starting the system startup phase.
1770e98b08fSopenharmony_ci * The value range is [0, 5), and the calling sequence is 0, 1, 2, 3, and 4.
1780e98b08fSopenharmony_ci */
1790e98b08fSopenharmony_ci#define SYS_RUN_PRI(func, priority) LAYER_INITCALL(func, run, "run", priority)
1800e98b08fSopenharmony_ci
1810e98b08fSopenharmony_ci/**
1820e98b08fSopenharmony_ci * @brief Identifies the entry for initializing and starting a system service by the priority 2.
1830e98b08fSopenharmony_ci *
1840e98b08fSopenharmony_ci * This macro is used to identify the entry called at the priority 2 in the system service
1850e98b08fSopenharmony_ci * phase of the startup process. \n
1860e98b08fSopenharmony_ci *
1870e98b08fSopenharmony_ci * @param func Indicates the entry function for initializing and starting a system service.
1880e98b08fSopenharmony_ci * The type is void (*)(void).
1890e98b08fSopenharmony_ci */
1900e98b08fSopenharmony_ci#define SYSEX_SERVICE_INIT(func) LAYER_INITCALL_DEF(func, app_service, "app.service")
1910e98b08fSopenharmony_ci/**
1920e98b08fSopenharmony_ci * @brief Identifies the entry for initializing and starting a system service by the specified
1930e98b08fSopenharmony_ci * priority.
1940e98b08fSopenharmony_ci *
1950e98b08fSopenharmony_ci * This macro is used to identify the entry called at the specified priority of the system service
1960e98b08fSopenharmony_ci * phase of the startup process. \n
1970e98b08fSopenharmony_ci *
1980e98b08fSopenharmony_ci * @param func Indicates the entry function for initializing and starting a system service.
1990e98b08fSopenharmony_ci * The type is void (*)(void).
2000e98b08fSopenharmony_ci * @param priority Indicates the calling priority when starting the system service phase.
2010e98b08fSopenharmony_ci * The value range is [0,5), and the calling sequence is 0, 1, 2, 3, and 4.
2020e98b08fSopenharmony_ci */
2030e98b08fSopenharmony_ci#define SYSEX_SERVICE_INIT_PRI(func, priority) LAYER_INITCALL(func, app_service, "app.service", priority)
2040e98b08fSopenharmony_ci
2050e98b08fSopenharmony_ci/**
2060e98b08fSopenharmony_ci * @brief Identifies the entry for initializing and starting a system feature by the priority 2.
2070e98b08fSopenharmony_ci *
2080e98b08fSopenharmony_ci * This macro is used to identify the entry called at the priority 2 of the system feature
2090e98b08fSopenharmony_ci * phase of the startup process. \n
2100e98b08fSopenharmony_ci *
2110e98b08fSopenharmony_ci * @param func Indicates the entry function for initializing and starting a system feature.
2120e98b08fSopenharmony_ci * The type is void (*)(void).
2130e98b08fSopenharmony_ci */
2140e98b08fSopenharmony_ci#define SYSEX_FEATURE_INIT(func) LAYER_INITCALL_DEF(func, app_feature, "app.feature")
2150e98b08fSopenharmony_ci/**
2160e98b08fSopenharmony_ci * @brief Identifies the entry for initializing and starting a system feature by the specified
2170e98b08fSopenharmony_ci * priority.
2180e98b08fSopenharmony_ci *
2190e98b08fSopenharmony_ci * This macro is used to identify the entry called at the specified priority of the system feature
2200e98b08fSopenharmony_ci * phase of the startup process. \n
2210e98b08fSopenharmony_ci *
2220e98b08fSopenharmony_ci * @param func Indicates the entry function for initializing and starting a system feature.
2230e98b08fSopenharmony_ci * The type is void (*)(void).
2240e98b08fSopenharmony_ci * @param priority Indicates the calling priority when starting the system feature phase.
2250e98b08fSopenharmony_ci * The value range is [0,5), and the calling sequence is 0, 1, 2, 3, and 4.
2260e98b08fSopenharmony_ci */
2270e98b08fSopenharmony_ci#define SYSEX_FEATURE_INIT_PRI(func, priority) LAYER_INITCALL(func, app_feature, "app.feature", priority)
2280e98b08fSopenharmony_ci
2290e98b08fSopenharmony_ci/**
2300e98b08fSopenharmony_ci * @brief Identifies the entry for initializing and starting an application-layer service by the
2310e98b08fSopenharmony_ci * priority 2.
2320e98b08fSopenharmony_ci *
2330e98b08fSopenharmony_ci * This macro is used to identify the entry called at the priority 2 of the application-layer
2340e98b08fSopenharmony_ci * service phase of the startup process. \n
2350e98b08fSopenharmony_ci *
2360e98b08fSopenharmony_ci * @param func Indicates the entry function for initializing and starting an application-layer
2370e98b08fSopenharmony_ci * service. The type is void (*)(void).
2380e98b08fSopenharmony_ci */
2390e98b08fSopenharmony_ci#define APP_SERVICE_INIT(func) LAYER_INITCALL_DEF(func, app_service, "app.service")
2400e98b08fSopenharmony_ci/**
2410e98b08fSopenharmony_ci * @brief Identifies the entry for initializing and starting an application-layer service by the
2420e98b08fSopenharmony_ci * specified priority.
2430e98b08fSopenharmony_ci *
2440e98b08fSopenharmony_ci * This macro is used to identify the entry called at the specified priority of the
2450e98b08fSopenharmony_ci * application-layer service phase of the startup process. \n
2460e98b08fSopenharmony_ci *
2470e98b08fSopenharmony_ci * @param func Indicates the entry function for initializing and starting an application-layer
2480e98b08fSopenharmony_ci * service. The type is void (*)(void).
2490e98b08fSopenharmony_ci * @param priority Indicates the calling priority when starting the application-layer service
2500e98b08fSopenharmony_ci * phase. The value range is [0,5), and the calling sequence is 0, 1, 2, 3, and 4.
2510e98b08fSopenharmony_ci */
2520e98b08fSopenharmony_ci#define APP_SERVICE_INIT_PRI(func, priority) LAYER_INITCALL(func, app_service, "app.service", priority)
2530e98b08fSopenharmony_ci
2540e98b08fSopenharmony_ci/**
2550e98b08fSopenharmony_ci * @brief Identifies the entry for initializing and starting an application-layer feature by the
2560e98b08fSopenharmony_ci * priority 2.
2570e98b08fSopenharmony_ci *
2580e98b08fSopenharmony_ci * This macro is used to identify the entry called at the priority 2 of the application-layer
2590e98b08fSopenharmony_ci * feature phase of the startup process. \n
2600e98b08fSopenharmony_ci *
2610e98b08fSopenharmony_ci * @param func Indicates the entry function for initializing and starting an application-layer
2620e98b08fSopenharmony_ci * feature. The type is void (*)(void).
2630e98b08fSopenharmony_ci */
2640e98b08fSopenharmony_ci#define APP_FEATURE_INIT(func) LAYER_INITCALL_DEF(func, app_feature, "app.feature")
2650e98b08fSopenharmony_ci/**
2660e98b08fSopenharmony_ci * @brief Identifies the entry for initializing and starting an application-layer feature by
2670e98b08fSopenharmony_ci * the specified priority.
2680e98b08fSopenharmony_ci *
2690e98b08fSopenharmony_ci * This macro is used to identify the entry called at the specified priority of the
2700e98b08fSopenharmony_ci * application-layer feature phase of the startup process. \n
2710e98b08fSopenharmony_ci *
2720e98b08fSopenharmony_ci * @param func Indicates the entry function for initializing and starting an application-layer
2730e98b08fSopenharmony_ci * feature. The type is void (*)(void).
2740e98b08fSopenharmony_ci * @param priority Indicates the calling priority when starting the application-layer feature.
2750e98b08fSopenharmony_ci * The value range is [0, 5), and the calling sequence is 0, 1, 2, 3, and 4.
2760e98b08fSopenharmony_ci */
2770e98b08fSopenharmony_ci#define APP_FEATURE_INIT_PRI(func, priority) LAYER_INITCALL(func, app_feature, "app.feature", priority)
2780e98b08fSopenharmony_ci
2790e98b08fSopenharmony_ci#ifdef __cplusplus
2800e98b08fSopenharmony_ci#if __cplusplus
2810e98b08fSopenharmony_ci}
2820e98b08fSopenharmony_ci#endif
2830e98b08fSopenharmony_ci#endif
2840e98b08fSopenharmony_ci#endif // OHOS_LAYER_INIT_H
2850e98b08fSopenharmony_ci/** @} */
286