1b0e7dd80Sopenharmony_ci/*
2b0e7dd80Sopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd.
3b0e7dd80Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4b0e7dd80Sopenharmony_ci * you may not use this file except in compliance with the License.
5b0e7dd80Sopenharmony_ci * You may obtain a copy of the License at
6b0e7dd80Sopenharmony_ci *
7b0e7dd80Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0
8b0e7dd80Sopenharmony_ci *
9b0e7dd80Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10b0e7dd80Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11b0e7dd80Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12b0e7dd80Sopenharmony_ci * See the License for the specific language governing permissions and
13b0e7dd80Sopenharmony_ci * limitations under the License.
14b0e7dd80Sopenharmony_ci */
15b0e7dd80Sopenharmony_ci
16b0e7dd80Sopenharmony_ci#ifndef HITRACECHAIN_FFI_H
17b0e7dd80Sopenharmony_ci#define HITRACECHAIN_FFI_H
18b0e7dd80Sopenharmony_ci
19b0e7dd80Sopenharmony_ci#include "hitraceid.h"
20b0e7dd80Sopenharmony_ci#include "cj_ffi/cj_common_ffi.h"
21b0e7dd80Sopenharmony_ci#include <cstdint>
22b0e7dd80Sopenharmony_ci
23b0e7dd80Sopenharmony_ciextern "C" {
24b0e7dd80Sopenharmony_ci    struct CHiTraceId {
25b0e7dd80Sopenharmony_ci        uint64_t chainId;
26b0e7dd80Sopenharmony_ci        uint64_t spanId;
27b0e7dd80Sopenharmony_ci        uint64_t parentSpanId;
28b0e7dd80Sopenharmony_ci        int32_t flags;
29b0e7dd80Sopenharmony_ci    };
30b0e7dd80Sopenharmony_ci
31b0e7dd80Sopenharmony_ci    static CHiTraceId Parse(OHOS::HiviewDFX::HiTraceId id)
32b0e7dd80Sopenharmony_ci    {
33b0e7dd80Sopenharmony_ci        CHiTraceId traceId;
34b0e7dd80Sopenharmony_ci        traceId.chainId = id.GetChainId();
35b0e7dd80Sopenharmony_ci        traceId.spanId = id.GetSpanId();
36b0e7dd80Sopenharmony_ci        traceId.parentSpanId = id.GetParentSpanId();
37b0e7dd80Sopenharmony_ci        traceId.flags = id.GetFlags();
38b0e7dd80Sopenharmony_ci        return traceId;
39b0e7dd80Sopenharmony_ci    }
40b0e7dd80Sopenharmony_ci
41b0e7dd80Sopenharmony_ci    static OHOS::HiviewDFX::HiTraceId Parse(CHiTraceId id)
42b0e7dd80Sopenharmony_ci    {
43b0e7dd80Sopenharmony_ci        OHOS::HiviewDFX::HiTraceId traceId;
44b0e7dd80Sopenharmony_ci        traceId.SetChainId(id.chainId);
45b0e7dd80Sopenharmony_ci        traceId.SetSpanId(id.spanId);
46b0e7dd80Sopenharmony_ci        traceId.SetParentSpanId(id.parentSpanId);
47b0e7dd80Sopenharmony_ci        traceId.SetFlags(id.flags);
48b0e7dd80Sopenharmony_ci        return traceId;
49b0e7dd80Sopenharmony_ci    }
50b0e7dd80Sopenharmony_ci
51b0e7dd80Sopenharmony_ci    FFI_EXPORT CHiTraceId FfiOHOSHiTraceChainBegin(const char* name, int flag);
52b0e7dd80Sopenharmony_ci    FFI_EXPORT void FfiOHOSHiTraceChainEnd(CHiTraceId id);
53b0e7dd80Sopenharmony_ci    FFI_EXPORT CHiTraceId FfiOHOSHiTraceChainGetId();
54b0e7dd80Sopenharmony_ci    FFI_EXPORT void FfiOHOSHiTraceChainSetId(CHiTraceId id);
55b0e7dd80Sopenharmony_ci    FFI_EXPORT void FfiOHOSHiTraceChainClearId();
56b0e7dd80Sopenharmony_ci    FFI_EXPORT CHiTraceId FfiOHOSHiTraceChainCreateSpan();
57b0e7dd80Sopenharmony_ci    FFI_EXPORT void FfiOHOSHiTraceChainTracepoint(uint32_t mode, uint32_t type, CHiTraceId id, const char* str);
58b0e7dd80Sopenharmony_ci    FFI_EXPORT bool FfiOHOSHiTraceChainIsValid(CHiTraceId id);
59b0e7dd80Sopenharmony_ci    FFI_EXPORT bool FfiOHOSHiTraceChainIsFlagEnabled(CHiTraceId id, int32_t flag);
60b0e7dd80Sopenharmony_ci    FFI_EXPORT void FfiOHOSHiTraceChainEnableFlag(CHiTraceId id, int32_t flag);
61b0e7dd80Sopenharmony_ci}
62b0e7dd80Sopenharmony_ci
63b0e7dd80Sopenharmony_ci#endif