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 CAMERA_HAL_HISYSEVENT_H
17 #define CAMERA_HAL_HISYSEVENT_H
18 #include <chrono>
19 #include <string>
20 #include <map>
21 #include "hisysevent.h"
22 #include "camera.h"
23 #include "camera_metadata_info.h"
24 #include <memory>
25 
26 namespace OHOS::Camera {
27 
28 enum ErrorEventType {
29     CREATE_PIPELINE_ERROR,
30     TURN_BUFFER_ERROR,
31     REQUEST_BUFFER_ERROR,
32     REQUEST_GRAPHIC_BUFFER_ERROR,
33     COPY_BUFFER_ERROR,
34     TYPE_CAST_ERROR,
35     OPEN_DEVICE_NODE_ERROR,
36     FORMAT_CAST_ERROR
37 };
38 
39 enum PerformanceEventType {
40     TIME_FOR_OPEN_CAMERA,
41     TIME_FOR_CAPTURE,
42     TIME_FOR_FIRST_FRAME
43 };
44 
45 enum StatisicEventType {
46     TIME_OF_CAPTURE,
47     TIME_OF_VEDIOA_AND_DURATION,
48     INFORMATION_OF_CAMERA,
49     PARAMS_OFCAPTURE_OR_VEDIO
50 };
51 
52 class CameraHalHisysevent {
53 public:
54     static std::string CreateMsg(const char* format, ...);
55     static void WriteFaultHisysEvent(const std::string &name, const std::string &msg);
56     static std::string GetEventName(ErrorEventType errorEventType);
57 };
58 
59 class CameraHalPerfSysevent final {
60     PerformanceEventType perfEventType_;
61     bool isPrint_;
62     const char *const funcName_;
63     std::chrono::system_clock::time_point begin;
64 public:
65     CameraHalPerfSysevent(PerformanceEventType perfEventType, bool isPrint, const char *name);
66     ~CameraHalPerfSysevent();
67     CameraHalPerfSysevent(const CameraHalPerfSysevent&) = delete;
68     CameraHalPerfSysevent(CameraHalPerfSysevent&&) = delete;
69     CameraHalPerfSysevent& operator = (const CameraHalPerfSysevent&) = delete;
70     CameraHalPerfSysevent& operator = (CameraHalPerfSysevent&&) = delete;
71 };
72 
73 #define CAMERAHALPERFSYSEVENT_COND(pet, cond) CameraHalPerfSysevent cameraHalPerfSysevent(pet, cond, __FUNCTION__)
74 
75 #define CAMERAHALPERFSYSEVENT(pet) CAMERAHALPERFSYSEVENT_COND(pet, true)
76 
77 #define CAMERAHALPERFSYSEVENT_EQUAL(arg, x, pet) CAMERAHALPERFSYSEVENT_COND(pet, ((arg) == (x)))
78 
79 class CameraHalTimeSysevent {
80 public:
81     static void WriteTimeStatisicEvent(const std::string &name);
82     static void WriteCameraInformationEvent(const std::string &name, common_metadata_header_t *data);
83     static void WriteCameraParameterEvent(const std::string &name, common_metadata_header_t *data);
84     static std::string GetEventName(StatisicEventType statisicEventType);
85 };
86 
87 }  // namespace OHOS::Camera
88 #endif
89