• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2022 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 DISTRIBUTEDDATA_SERVICE_DUMPE_HELPER_H
17 #define DISTRIBUTEDDATA_SERVICE_DUMPE_HELPER_H
18 
19 #include <string>
20 #include <vector>
21 #include <map>
22 #include <list>
23 #include <functional>
24 #include "store_errno.h"
25 #include "singleton.h"
26 
27 namespace OHOS {
28 namespace DistributedKv {
29 class DumpHelper : public Singleton<DumpHelper> {
30 public:
31     using DumpNoParamFunc = std::function<void(int)>;
32     using DumpWithParamFunc = std::function<void(int, const std::string &)>;
33     DumpHelper() = default;
34     virtual ~DumpHelper() = default;
35     void AddDumpOperation(const DumpNoParamFunc &dumpAll, const DumpNoParamFunc &dumpUserInfo,
36         const DumpWithParamFunc &dumpAppInfo, const DumpWithParamFunc &dumpStoreInfo);
37     void AddErrorInfo(const std::string &error);
38     void ShowError(int fd);
39     bool Dump(int fd, const std::vector<std::string> &args);
40 private:
41     void ShowHelp(int fd);
42     void ShowIllealInfomation(int fd);
43     mutable std::mutex hidumperMutex_;
44     std::list<std::string> g_errorInfo;
45     DumpNoParamFunc dumpAll_;
46     DumpNoParamFunc dumpUserInfo_;
47     DumpWithParamFunc dumpAppInfo_;
48     DumpWithParamFunc dumpStoreInfo_;
49 };
50 }  // namespace DistributedKv
51 }  // namespace OHOS
52 #endif  // DISTRIBUTEDDATA_SERVICE_DUMPE_HELPER_H