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 
16 #ifndef OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_DUMPMANAGER_DUMP_MANAGER_H
17 #define OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_DUMPMANAGER_DUMP_MANAGER_H
18 #include <functional>
19 #include <map>
20 #include <mutex>
21 #include <string>
22 #include <vector>
23 
24 #include "concurrent_map.h"
25 #include "visibility.h"
26 namespace OHOS {
27 namespace DistributedData {
28 class DumpManager {
29     using Handler = std::function<void(int, std::map<std::string, std::vector<std::string>> &)>;
30 
31 public:
32     struct Config {
33         std::string dumpName;
34         std::string fullCmd;
35         std::string abbrCmd;
36         int countPrintf = 1;
37         std::string infoName;
38         uint32_t minParamsNum = 0;
39         uint32_t maxParamsNum = 0;
40         std::string parentNode;
41         std::string childNode;
42         std::vector<std::string> dumpCaption;
IsVoidConfig43         bool IsVoid()
44         {
45             if (fullCmd.empty()) {
46                 return true;
47             }
48             return false;
49         }
50     };
51     API_EXPORT static DumpManager &GetInstance();
52     API_EXPORT void AddConfig(const std::string &name, Config &config);
53     API_EXPORT Config GetConfig(const std::string &name);
54     API_EXPORT ConcurrentMap<std::string, DumpManager::Config> LoadConfig();
55     API_EXPORT void AddHandler(const std::string &infoName, uintptr_t ptr, const Handler &handler);
56     API_EXPORT std::vector<Handler> GetHandler(const std::string &infoName);
57     API_EXPORT void RemoveHandler(const std::string &infoName, uintptr_t ptr);
58 
59 private:
60     ConcurrentMap<std::string, Config> factory_;
61     ConcurrentMap<std::string, std::string> indexTable_;
62     ConcurrentMap<std::string, std::map<uintptr_t, Handler>> handlers_;
63 };
64 } // namespace DistributedData
65 } // namespace OHOS
66 #endif // OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_DUMPMANAGER_DUMP_MANAGER_H
67