1 /*
2  * Copyright (c) 2024 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 HITRACECHAIN_FFI_H
17 #define HITRACECHAIN_FFI_H
18 
19 #include "hitraceid.h"
20 #include "cj_ffi/cj_common_ffi.h"
21 #include <cstdint>
22 
23 extern "C" {
24     struct CHiTraceId {
25         uint64_t chainId;
26         uint64_t spanId;
27         uint64_t parentSpanId;
28         int32_t flags;
29     };
30 
Parse(OHOS::HiviewDFX::HiTraceId id)31     static CHiTraceId Parse(OHOS::HiviewDFX::HiTraceId id)
32     {
33         CHiTraceId traceId;
34         traceId.chainId = id.GetChainId();
35         traceId.spanId = id.GetSpanId();
36         traceId.parentSpanId = id.GetParentSpanId();
37         traceId.flags = id.GetFlags();
38         return traceId;
39     }
40 
Parse(CHiTraceId id)41     static OHOS::HiviewDFX::HiTraceId Parse(CHiTraceId id)
42     {
43         OHOS::HiviewDFX::HiTraceId traceId;
44         traceId.SetChainId(id.chainId);
45         traceId.SetSpanId(id.spanId);
46         traceId.SetParentSpanId(id.parentSpanId);
47         traceId.SetFlags(id.flags);
48         return traceId;
49     }
50 
51     FFI_EXPORT CHiTraceId FfiOHOSHiTraceChainBegin(const char* name, int flag);
52     FFI_EXPORT void FfiOHOSHiTraceChainEnd(CHiTraceId id);
53     FFI_EXPORT CHiTraceId FfiOHOSHiTraceChainGetId();
54     FFI_EXPORT void FfiOHOSHiTraceChainSetId(CHiTraceId id);
55     FFI_EXPORT void FfiOHOSHiTraceChainClearId();
56     FFI_EXPORT CHiTraceId FfiOHOSHiTraceChainCreateSpan();
57     FFI_EXPORT void FfiOHOSHiTraceChainTracepoint(uint32_t mode, uint32_t type, CHiTraceId id, const char* str);
58     FFI_EXPORT bool FfiOHOSHiTraceChainIsValid(CHiTraceId id);
59     FFI_EXPORT bool FfiOHOSHiTraceChainIsFlagEnabled(CHiTraceId id, int32_t flag);
60     FFI_EXPORT void FfiOHOSHiTraceChainEnableFlag(CHiTraceId id, int32_t flag);
61 }
62 
63 #endif