• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 HIAPPEVENT_AGENT_H
17 #define HIAPPEVENT_AGENT_H
18 
19 #include <string>
20 #include <mutex>
21 #include "hitrace/tracechain.h"
22 #include "osal/task/task.h"
23 
24 #define API_RESULT_SUCCESS 0
25 #define API_RESULT_FAILED 1
26 
27 namespace OHOS {
28 namespace Media {
29 
30 class HiAppEventAgent : public std::enable_shared_from_this<HiAppEventAgent> {
31 public:
32     HiAppEventAgent();
33     ~HiAppEventAgent();
34     void TraceApiEvent(int errCode,
35         const std::string& apiName, int64_t startTime, HiviewDFX::HiTraceId traceId = HiviewDFX::HiTraceId());
36 
37 private:
38     std::string GenerateTransId();
39 #ifdef SUPPORT_HIAPPEVENT
40     void TraceApiEventAsync(int errCode,
41         const std::string& apiName, int64_t startTime, HiviewDFX::HiTraceId traceId);
42     int64_t AddProcessor();
43     void WriteEndEvent(const std::string& transId,
44         const int errCode, const std::string& apiName, int64_t startTime, HiviewDFX::HiTraceId traceId);
45 
46     std::unique_ptr<Task> hiAppEventTask_;
47     std::unordered_map<std::string, int64_t> lastReportTime_;
48 #endif
49 };
50 
51 } // namespace Media
52 } // namespace OHOS
53 
54 #endif // HIAPPEVENT_AGENT_H
55