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 OHOS_MEDIA_DFX_TRANSACTION_H
17 #define OHOS_MEDIA_DFX_TRANSACTION_H
18 
19 #include <string>
20 
21 namespace OHOS {
22 namespace Media {
23 #define EXPORT __attribute__ ((visibility ("default")))
24 class DfxTransaction {
25 public:
26     enum EXPORT AbnormalType : uint8_t {
27         CREATE_ERROR,
28         COMMIT_ERROR,
29         ROLLBACK_ERROR,
30         EXECUTE_ERROR,
31         NULLPTR_ERROR,
32         TIMEOUT_WARN,
33     };
34     EXPORT DfxTransaction(std::string funcName);
35     EXPORT ~DfxTransaction();
36     EXPORT void Restart();
37     EXPORT void ReportIfTimeout();
38     EXPORT void ReportError(uint8_t abnormalType, int32_t errCode);
39 
40 private:
41     void Report(uint8_t abnormalType, int32_t errCode = 0);
42     std::string funcName_;
43     int64_t startTime_{ 0 };
44     int64_t timeCost_{ 0 };
45 };
46 } // namespace Media
47 } // namespace OHOS
48 
49 #endif // OHOS_MEDIA_DFX_TRANSACTION_H
50