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 HISYSEVENT_INTERFACES_NATIVE_INNERKITS_EASY_BUILDER_H
17 #define HISYSEVENT_INTERFACES_NATIVE_INNERKITS_EASY_BUILDER_H
18 
19 #include <stddef.h>
20 #include <stdint.h>
21 
22 #include "easy_def.h"
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 #define DOMAIN_ARRAY_LEN  (MAX_DOMAIN_LENGTH + 1)
29 #define NAME_ARRAY_LEN    (MAX_EVENT_NAME_LENGTH + 1)
30 
31 #pragma pack(1)
32 struct HiSysEventEasyHeader {
33     char domain[DOMAIN_ARRAY_LEN];
34     char name[NAME_ARRAY_LEN];
35     uint64_t timestamp;
36     uint8_t timeZone;
37     uint32_t uid;
38     uint32_t pid;
39     uint32_t tid;
40     uint64_t id;
41     uint8_t type : 2;
42     uint8_t isTraceOpened : 1;
43 };
44 #pragma pack()
45 
46 /**
47  * @brief Append event header to event
48  *
49  * @param eventBuffer  allocated memory of event
50  * @param bufferLen    max length of the event buffer
51  * @param offset       position to append header
52  * @param header       event header
53  * @return 0 means success, others means failure
54  */
55 int AppendHeader(uint8_t* eventBuffer, const size_t bufferLen, size_t* offset,
56     const struct HiSysEventEasyHeader* header);
57 
58 /**
59  * @brief Append customized param with string type to event
60  *
61  * @param eventBuffer  allocated memory of event
62  * @param bufferLen    max length of the event buffer
63  * @param offset       position to append string value
64  * @param key          param key
65  * @param val          string value
66  * @return 0 means success, others means failure
67  */
68 int AppendStringParam(uint8_t* eventBuffer, const size_t bufferLen, size_t* offset, const char* key, const char* val);
69 
70 #ifdef __cplusplus
71 }
72 #endif
73 #endif // HISYSEVENT_INTERFACES_NATIVE_INNERKITS_EASY_BUILDER_H