• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2023 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_CAMERA_DPS_DEFERRED_EVENT_REPORT_H
17 #define OHOS_CAMERA_DPS_DEFERRED_EVENT_REPORT_H
18 
19 #include <cstdint>
20 #include <string>
21 #include <string>
22 #include <schedule/photo_processor/photo_job_repository/deferred_photo_job.h>
23 #include "deferred_processing_service_ipc_interface_code.h"
24 #include <shared_mutex>
25 
26 namespace OHOS {
27 namespace CameraStandard {
28 namespace DeferredProcessing {
29 const std::string EVENT_KEY_IMAGEID = "IMAGEID";
30 const std::string EVENT_KEY_USERID = "USERID";
31 const std::string EVENT_KEY_DEFEVENTTYPE = "DEFEVENTTYPE";
32 const std::string EVENT_KEY_DISCARDABLE = "DISCARDABLE";
33 const std::string EVENT_KEY_TRIGGERMODE = "TRIGGERMODE";
34 const std::string EVENT_KEY_HIGHJOBNUM = "HIGHJOBNUM";
35 const std::string EVENT_KEY_NORMALJOBNUM = "NORMALJOBNUM";
36 const std::string EVENT_KEY_LOWJOBNUM = "LOWJOBNUM";
37 const std::string EVENT_KEY_TEMPERATURELEVEL = "TEMPERATURELEVEL";
38 const std::string EVENT_KEY_SYNCHRONIZETIME = "SYNCHRONIZETIME";
39 const std::string EVENT_KEY_DISPATCHTIME = "DISPATCHTIME";
40 const std::string EVENT_KEY_PROCESSTIME = "PROCESSTIME";
41 const std::string EVENT_KEY_IMAGEDONETIME = "IMAGEDONETIME";
42 const std::string EVENT_KEY_RESTORETIME = "RESTORETIME";
43 const std::string EVENT_KEY_REMOVETIME = "CANCELTIME";
44 const std::string EVENT_KEY_TRAILINGTIME = "TRAILINGTIME";
45 const std::string EVENT_KEY_PHOTOJOBTYPE = "PHOTOJOBTYPE";
46 const std::string EVENT_KEY_EXCUTIONMODE = "EXCUTIONMODE";
47 const std::string EVENT_KEY_CHANGEREASON = "CHANGEREASON";
48 const std::string EVENT_KEY_EXCEPTIONSOURCE = "EXCEPTIONSOURCE";
49 const std::string EVENT_KEY_EXCEPTIONCAUSE = "EXCEPTIONCAUSE";
50 const std::string EVENT_KEY_EXECUTIONMODE = "EXECUTIONMODE";
51 
52 struct DPSEventInfo {
53     std::string imageId;
54     int32_t userId;
55     TrigerMode triggerMode;
56     uint32_t operatorStage;
57     bool discardable;
58     uint64_t synchronizeTimeBeginTime;
59     uint64_t synchronizeTimeEndTime;
60     uint64_t dispatchTimeBeginTime;
61     uint64_t dispatchTimeEndTime;
62     uint64_t processTimeBeginTime;
63     uint64_t processTimeEndTime;
64     uint64_t imageDoneTimeBeginTime;
65     uint64_t imageDoneTimeEndTime;
66     uint64_t restoreTimeBeginTime;
67     uint64_t restoreTimeEndTime;
68     uint64_t removeTimeBeginTime;
69     uint64_t removeTimeEndTime;
70     uint64_t trailingTimeBeginTime;
71     uint64_t trailingTimeEndTime;
72     int32_t highJobNum;
73     int32_t normalJobNum;
74     int32_t lowJobNum;
75     int temperatureLevel;
76     PhotoJobType photoJobType;
77     EventType changeReason;
78     ExceptionSource exceptionSource;
79     ExceptionCause exceptionCause;
80     ExecutionMode executionMode = ExecutionMode::DUMMY;
81 };
82 
83 class DPSEventReport {
84 public:
GetInstance()85     static DPSEventReport &GetInstance()
86     {
87         static DPSEventReport instance;
88         return instance;
89     }
90     void ReportOperateImage(const std::string& imageId, int32_t userId, DPSEventInfo& dpsEventInfo);
91     void ReportImageProcessResult(const std::string& imageId, int32_t userId, uint64_t endTime = 0);
92     void ReportImageModeChange(ExecutionMode executionMode);
93     void ReportImageException(const std::string& imageId, int32_t userId);
94     void SetEventInfo(const std::string& imageId, int32_t userId);
95     void SetEventInfo(DPSEventInfo& dpsEventInfo);
96     void RemoveEventInfo(const std::string& imageId, int32_t userId);
97 
98     void SetTemperatureLevel(int temperatureLevel);
99     void SetExecutionMode(ExecutionMode executionMode);
100     void SetEventType(EventType eventType_);
101     void UpdateEventInfo(DPSEventInfo& dpsEventInfo);
102     void UpdateProcessDoneTime(const std::string& imageId, int32_t userId);
103     void UpdateRemoveTime(const std::string& imageId, int32_t userId);
104     void UpdateExecutionMode(const std::string& imageId, int32_t userId, ExecutionMode executionMode);
105 
106 private:
107     DPSEventInfo GetEventInfo(const std::string& imageId, int32_t userId);
108     void UpdateSynchronizeTime(DPSEventInfo& dpsEventInfo, DPSEventInfo& dpsEventInfoSrc);
109     void UpdateDispatchTime(DPSEventInfo& dpsEventInfo, DPSEventInfo& dpsEventInfoSrc);
110     void UpdateProcessTime(DPSEventInfo& dpsEventInfo, DPSEventInfo& dpsEventInfoSrc);
111     void UpdateImageDoneTime(DPSEventInfo& dpsEventInfo, DPSEventInfo& dpsEventInfoSrc);
112     void UpdateRestoreTime(DPSEventInfo& dpsEventInfo, DPSEventInfo& dpsEventInfoSrc);
113     void UpdateRemoveTime(DPSEventInfo& dpsEventInfo, DPSEventInfo& dpsEventInfoSrc);
114     void UpdateTrailingTime(DPSEventInfo& dpsEventInfo, DPSEventInfo& dpsEventInfoSrc);
115     void UpdateExecutionMode(DPSEventInfo& dpsEventInfo, DPSEventInfo& dpsEventInfoSrc);
116     int GetTotalTime (uint64_t beginTime, uint64_t endTime);
117     std::recursive_mutex mutex_;
118     std::map<int32_t, std::map<std::string, DPSEventInfo>> userIdToImageIdEventInfo; //userid--imageid--eventinfo
119     ExecutionMode executionMode_;
120     int temperatureLevel_;
121     EventType eventType_;
122 };
123 } // namespace DeferredProcessingService
124 } // namespace CameraStandard
125 } // namespace OHOS
126 #endif // OHOS_CAMERA_DPS_DEFERRED_PROCESSING_SERVICE_H