• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 HIDUMPER_SERVICES_DUMP_MANAGER_SERVICE_H
16 #define HIDUMPER_SERVICES_DUMP_MANAGER_SERVICE_H
17 #include <map>
18 #include <vector>
19 #include <system_ability.h>
20 #include "delayed_sp_singleton.h"
21 #include "dump_common_utils.h"
22 #include "dump_broker_stub.h"
23 #include "dump_event_handler.h"
24 namespace OHOS {
25 namespace HiviewDFX {
26 class RawParam;
27 #ifdef DUMP_TEST_MODE // for mock test
28 using DumpManagerServiceTestMainFunc = std::function<void(int argc, char *argv[],
29     const std::shared_ptr<RawParam>& reqCtl)>;
30 #endif // for mock test
31 class DumpManagerService final : public SystemAbility, public DumpBrokerStub {
32     DECLARE_SYSTEM_ABILITY(DumpManagerService)
33 public:
34     DumpManagerService();
35     ~DumpManagerService();
36 public:
37     virtual void OnStart() override;
38     virtual void OnStop() override;
39 public:
40     // Used for dump request
41     int32_t Request(std::vector<std::u16string> &args, int outfd) override;
42 public:
43     int32_t Dump(int32_t fd, const std::vector<std::u16string>& args) override;
IsServiceStarted()44     bool IsServiceStarted() const
45     {
46         return started_;
47     }
48     std::shared_ptr<DumpEventHandler> GetHandler() const;
49 #ifdef DUMP_TEST_MODE // for mock test
50     void SetTestMainFunc(DumpManagerServiceTestMainFunc testMainFunc);
51 #endif // for mock test
52 private:
53     friend DelayedSpSingleton<DumpManagerService>;
54 private:
55     bool Init();
56     std::shared_ptr<RawParam> AddRequestRawParam(std::vector<std::u16string> &args, int outfd);
57     void EraseRequestRawParam(const std::shared_ptr<RawParam> rawParam);
58     void CancelAllRequest();
59     int GetRequestSum();
60     uint32_t GetRequestId();
61     int32_t StartRequest(const std::shared_ptr<RawParam> rawParam);
62     void RequestMain(const std::shared_ptr<RawParam> rawParam);
63 private:
64     std::mutex mutex_;
65     std::shared_ptr<AppExecFwk::EventRunner> eventRunner_;
66     std::shared_ptr<DumpEventHandler> handler_;
67     bool started_ {false};
68     bool blockRequest_ {false};
69     uint32_t requestIndex_ {0};
70     std::map<uint32_t, std::shared_ptr<RawParam>> requestRawParamMap_;
71 #ifdef DUMP_TEST_MODE // for mock test
72     DumpManagerServiceTestMainFunc testMainFunc_ {nullptr};
73 #endif // for mock test
74 };
75 } // namespace HiviewDFX
76 } // namespace OHOS
77 #endif // HIDUMPER_SERVICES_DUMP_MANAGER_SERVICE_H
78