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 PLUGIN_ADAPTER_
17#define PLUGIN_ADAPTER_
18#include <memory.h>
19#include <stdint.h>
20#include <stdio.h>
21
22#include "init_log.h"
23
24#define PROCESS_EXIT_CODE 0x7f // 0x7f: user specified
25
26#ifndef UNUSED
27#define UNUSED(x) (void)(x)
28#endif
29
30#ifndef PLUGIN_DOMAIN
31#define PLUGIN_DOMAIN (BASE_DOMAIN + 6)
32#endif
33#define READ_DURATION 100000
34#define PLUGIN_LABEL "PLUGIN"
35#define PLUGIN_LOGI(fmt, ...) STARTUP_LOGI(PLUGIN_DOMAIN, PLUGIN_LABEL, fmt, ##__VA_ARGS__)
36#define PLUGIN_LOGE(fmt, ...) STARTUP_LOGE(PLUGIN_DOMAIN, PLUGIN_LABEL, fmt, ##__VA_ARGS__)
37#define PLUGIN_LOGV(fmt, ...) STARTUP_LOGV(PLUGIN_DOMAIN, PLUGIN_LABEL, fmt, ##__VA_ARGS__)
38#define PLUGIN_LOGW(fmt, ...) STARTUP_LOGW(PLUGIN_DOMAIN, PLUGIN_LABEL, fmt, ##__VA_ARGS__)
39
40#define PLUGIN_CHECK(ret, exper, ...) \
41    if (!(ret)) { \
42        PLUGIN_LOGE(__VA_ARGS__); \
43        exper; \
44    }
45#define PLUGIN_ONLY_LOG(ret, ...) \
46    if (!(ret)) { \
47        PLUGIN_LOGE(__VA_ARGS__); \
48    }
49
50#define HOOKID(name) HOOK_ID_##name
51enum HOOK_ID_ {
52    HOOKID(BOOTCHART),
53    HOOKID(SELINUX),
54    HOOKID(BOOTEVENT),
55    HOOKID(BOOTEVENT_MAX) = HOOK_ID_BOOTEVENT + 10,
56};
57
58#ifdef STARTUP_INIT_TEST
59#define PLUGIN_STATIC
60#else
61#define PLUGIN_STATIC static
62#endif
63
64#endif
65