1 /*
2  * Copyright (C) 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 #ifndef POST_EVENT_UTILS_H
16 #define POST_EVENT_UTILS_H
17 #include <map>
18 #include <string>
19 #include <variant>
20 
21 #include "singleton.h"
22 namespace OHOS {
23 namespace Media {
24 #define COMPILE_HIDDEN __attribute__ ((visibility ("hidden")))
25 const std::string KEY_OPT_TYPE = "optType";
26 
27 const std::string KEY_ERR_FILE = "errFile";
28 const std::string KEY_ERR_LINE = "errLine";
29 const std::string KEY_ERR_CODE = "errCode";
30 const std::string KEY_OPT_FILE = "optFile";
31 
32 const std::string KEY_GNUMS = "gnums";
33 const std::string KEY_ANUMS = "anums";
34 
35 const std::string KEY_PRE_VERSION = "preVersion";
36 const std::string KEY_AFTER_VERSION = "afterVersion";
37 
38 const std::string KEY_COUNT = "count";
39 
40 const std::string KEY_TIME_INTERVAL = "TIME_INTERVAL";
41 
42 const std::string KEY_CALLING_PACKAGE = "CALLING_PACKAGE";
43 const std::string KEY_HIGH_QUALITY_COUNT = "HIGH_QUALITY_COUNT";
44 const std::string KEY_BALANCE_QUALITY_COUNT = "BALANCE_QUALITY_COUNT";
45 const std::string KEY_EMERGENCY_QUALITY_COUNT = "EMERGENCY_QUALITY_COUNT";
46 
47 const std::string KEY_THIRD_PART_COUNT = "THIRD_PART_COUNT";
48 const std::string KEY_AUTO_COUNT = "AUTO_COUNT";
49 
50 const std::string KEY_PHOTO_ID = "PHOTO_ID";
51 const std::string KEY_TOTAL_TIME_COST = "TOTAL_TIME_COST";
52 
53 const std::string KEY_RESULT = "RESULT";
54 const std::string KEY_MEDIA_TYPE = "MEDIA_TYPE";
55 
56 const std::string KEY_DB_CORRUPT = "DB_CORRUPT_DATE";
57 
58 const std::string KEY_CLOUD_ENHANCEMENT_COMPLETE_TYPE = "COMPLETE_TYPE";
59 
60 enum OptType {
61     CREATE = 0,
62     THUMB,
63     SCAN,
64     QUERY,
65 };
66 
67 enum ErrType {
68     DEFAULT_ERR = 0,
69     FILE_OPT_ERR,
70     DB_OPT_ERR,
71     DB_UPGRADE_ERR,
72     DB_CORRUPT_ERR,
73 };
74 
75 enum StatType {
76     DEFAULT_STAT = 0,
77     THUMBNAIL_STAT,
78     DB_UPGRADE_STAT,
79     SYNC_STAT,
80     AGING_STAT,
81     MSC_FIRST_VISIT_STAT,
82     MSC_REQUEST_POLICY_STAT,
83     MSC_TRIGGER_RATIO_STAT,
84     MSC_TOTAL_TIME_COST_STAT,
85     MSC_RESULT_STAT,
86     CLOUD_ENHANCEMENT_GET_COUNT_STAT,
87 };
88 using VariantMap = std::map<std::string, std::variant<int32_t, int64_t, std::string>>;
89 
90 class PostEventUtils : public Singleton<PostEventUtils> {
91 public:
92     void PostErrorProcess(const uint32_t &errType, const VariantMap &error);
93     void PostStatProcess(const uint32_t &statType, const VariantMap &stat);
94 
95 private:
96     COMPILE_HIDDEN std::string GetOptType(const uint32_t &optType);
97     COMPILE_HIDDEN void PostFileOptError(const VariantMap &errMap);
98     COMPILE_HIDDEN void PostDbOptError(const VariantMap &errMap);
99     COMPILE_HIDDEN void PostDbUpgradeError(const VariantMap &errMap);
100     COMPILE_HIDDEN void PostThumbnailStat(const VariantMap &stat);
101     COMPILE_HIDDEN void PostDbUpgradeStat(const VariantMap &stat);
102     COMPILE_HIDDEN void PostSyncStat();
103     COMPILE_HIDDEN void PostAgingStat(const VariantMap &stat);
104     COMPILE_HIDDEN void PostMscFirstVisitStat(const VariantMap &stat);
105     COMPILE_HIDDEN void PostMscRequestPolicyStat(const VariantMap &stat);
106     COMPILE_HIDDEN void PostMscTriggerRatioStat(const VariantMap &stat);
107     COMPILE_HIDDEN void PostMscTotalTimeCostStat(const VariantMap &stat);
108     COMPILE_HIDDEN void PostMscResultStat(const VariantMap &stat);
109     COMPILE_HIDDEN void PostDatabaseCorruption(const VariantMap &errMap);
110     COMPILE_HIDDEN void PostCloudEnhanceStat(const VariantMap &stat);
111 
112     COMPILE_HIDDEN int GetIntValue(const std::string &key, const VariantMap &map);
113     COMPILE_HIDDEN int64_t GetInt64Value(const std::string &key, const VariantMap &map);
114     COMPILE_HIDDEN std::string GetStringValue(const std::string &key, const VariantMap &map);
115 
116     COMPILE_HIDDEN uint32_t thumbnailTimes_ = 0;
117     COMPILE_HIDDEN uint32_t dbUpgradeTimes_ = 0;
118     COMPILE_HIDDEN uint32_t syncTimes_ = 0;
119     COMPILE_HIDDEN uint32_t recycleTimes_ = 0;
120 };
121 } // namespace Media
122 } // namespace OHOS
123 #endif