• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_CLOUD_SYNC_SERVICE_SYSEVENT_H
17 #define OHOS_CLOUD_SYNC_SERVICE_SYSEVENT_H
18 
19 #include <atomic>
20 
21 #include "hisysevent.h"
22 
23 #include "dfs_error.h"
24 #include "utils_log.h"
25 
26 namespace OHOS {
27 namespace FileManagement {
28 namespace CloudSync {
29 #define CLOUD_SYNC_SYS_EVENT(eventName, type, ...)    \
30     HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::FILEMANAGEMENT, eventName,   \
31                     type, ##__VA_ARGS__)    \
32 
33 class SysEventData {
34 public:
35     virtual void Report() = 0;
36 };
37 
38 template <typename T>
vector_atomic_to_origin(std::vector<std::atomic<T>> & v)39 static inline std::vector<T> vector_atomic_to_origin(std::vector<std::atomic<T>> &v)
40 {
41     std::vector<T> ret;
42     ret.reserve(v.size());
43     for (auto &atomic_value : v) {
44         ret.push_back(atomic_value.load());
45     }
46     return ret;
47 }
48 
49 class SyncStat : public SysEventData {
50 public:
SyncStat()51     SyncStat()
52     {
53     }
54 
~SyncStat()55     virtual ~SyncStat() {}
56 
AppendSyncInfo(std::string & info)57     void AppendSyncInfo(std::string &info)
58     {
59         sync_info_.append(info);
60     }
61 
IsFullSync()62     bool IsFullSync()
63     {
64         return isFullSync_;
65     }
66 
SetFullSync()67     void SetFullSync()
68     {
69         isFullSync_ = true;
70     }
71 
SetSyncReason(uint32_t reason)72     void SetSyncReason(uint32_t reason)
73     {
74         syncReason_ = reason;
75     }
76 
SetStopReason(uint32_t reason)77     void SetStopReason(uint32_t reason)
78     {
79         stopReason_ = reason;
80     }
81 
SetStartTime(uint64_t time)82     void SetStartTime(uint64_t time)
83     {
84         startTime_ = time;
85     }
86 
SetDuration(uint64_t time)87     void SetDuration(uint64_t time)
88     {
89         duration_ = time - startTime_;
90     }
91 
92 protected:
93     bool isFullSync_;
94 
95     uint32_t syncReason_;
96     uint32_t stopReason_;
97     uint64_t startTime_;
98     uint64_t duration_;
99     std::string sync_info_;
100 };
101 
102 template<typename T>
103 class SyncStatContainer {
104 public:
SetSyncStat(std::shared_ptr<T> stat)105     void SetSyncStat(std::shared_ptr<T> stat)
106     {
107         syncStat_ = stat;
108     }
109 
PutSyncStat()110     void PutSyncStat()
111     {
112         syncStat_ = nullptr;
113     }
114 
GetSyncStat()115     std::shared_ptr<T> GetSyncStat()
116     {
117         return syncStat_;
118     }
119 
120 private:
121     std::shared_ptr<T> syncStat_;
122 };
123 
124 template<typename T>
125 class CheckStatContainer {
126 public:
SetCheckStat(std::shared_ptr<T> stat)127     void SetCheckStat(std::shared_ptr<T> stat)
128     {
129         checkStat_ = stat;
130     }
131 
PutCheckStat()132     void PutCheckStat()
133     {
134         checkStat_ = nullptr;
135     }
136 
GetCheckStat()137     std::shared_ptr<T> GetCheckStat()
138     {
139         return checkStat_;
140     }
141 
142 private:
143     std::shared_ptr<T> checkStat_;
144 };
145 } // namespace CloudSync
146 } // namespace FileManagement
147 } // namespace OHOS
148 #endif // OHOS_CLOUD_SYNC_SERVICE_SYSEVENT_H
149