Line data Source code
1 : /**
2 : * Copyright (c) 2026 Huawei Technologies Co., Ltd.
3 : * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4 : * CANN Open Software License Agreement Version 2.0 (the "License").
5 : * Please refer to the License for details. You may not use this file except in compliance with the License.
6 : * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7 : * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8 : * See LICENSE in the root of the software repository for the full text of the License.
9 : */
10 :
11 : #include "topo_addr_info_log.h"
12 : #include <dlfcn.h>
13 : #include <stdio.h>
14 :
15 : /* ── 全局函数指针(初始为 NULL,TopoLogInit 填充) ── */
16 : void (*g_topo_DlogRecord)(int moduleId, int level, const char* fmt, ...) = NULL;
17 : int (*g_topo_CheckLogLevel)(int moduleId, int logLevel) = NULL;
18 :
19 330 : void TopoLogInit(void)
20 : {
21 : static int initialized = 0;
22 330 : if (initialized != 0) {
23 329 : return;
24 : }
25 :
26 1 : void* handle = dlopen("libunified_dlog.so", RTLD_NOW);
27 1 : if (handle == NULL) {
28 1 : initialized = -1;
29 1 : return;
30 : }
31 :
32 0 : g_topo_DlogRecord = (void (*)(int, int, const char*, ...))dlsym(handle, "DlogRecord");
33 0 : g_topo_CheckLogLevel = (int (*)(int, int))dlsym(handle, "CheckLogLevel");
34 :
35 0 : if (g_topo_DlogRecord == NULL || g_topo_CheckLogLevel == NULL) {
36 0 : g_topo_DlogRecord = NULL;
37 0 : g_topo_CheckLogLevel = NULL;
38 0 : initialized = -1;
39 0 : return;
40 : }
41 :
42 0 : initialized = 1;
43 : }
|