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 "idump_callback_broker.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, const sptr<IDumpCallbackBroker>& callback) override; 42 public: 43 int32_t Dump(int32_t fd, const std::vector<std::u16string>& args) override; 44 // Used for dump request 45 int32_t Request(std::vector<std::u16string> &args, int outfd) override; 46 // Used for erase callback 47 void EraseCallback(const sptr<IDumpCallbackBroker>& callback); IsServiceStarted()48 bool IsServiceStarted() const 49 { 50 return started_; 51 } 52 #ifdef DUMP_TEST_MODE // for mock test 53 void SetTestMainFunc(DumpManagerServiceTestMainFunc testMainFunc); 54 #endif // for mock test 55 private: 56 friend DelayedSpSingleton<DumpManagerService>; 57 private: 58 std::shared_ptr<RawParam> AddRequestRawParam(std::vector<std::u16string> &args, 59 int outfd, const sptr<IDumpCallbackBroker> callback); 60 void EraseRequestRawParam(const std::shared_ptr<RawParam> rawParam); 61 void CancelAllRequest(); 62 int GetRequestSum(); 63 uint32_t GetRequestId(); 64 int32_t StartRequest(const std::shared_ptr<RawParam> rawParam); 65 void RequestMain(const std::shared_ptr<RawParam> rawParam); 66 private: 67 std::mutex mutex_; 68 bool started_ {false}; 69 bool blockRequest_ {false}; 70 uint32_t requestIndex_ {0}; 71 std::map<uint32_t, std::shared_ptr<RawParam>> requestRawParamMap_; 72 #ifdef DUMP_TEST_MODE // for mock test 73 DumpManagerServiceTestMainFunc testMainFunc_ {nullptr}; 74 #endif // for mock test 75 }; 76 } // namespace HiviewDFX 77 } // namespace OHOS 78 #endif // HIDUMPER_SERVICES_DUMP_MANAGER_SERVICE_H 79