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_CLIENT_H
16 #define HIDUMPER_SERVICES_DUMP_MANAGER_CLIENT_H
17 #include <string>
18 #include <singleton.h>
19 #include <iservice_registry.h>
20 #include "dump_common_utils.h"
21 #include "idump_broker.h"
22 namespace OHOS {
23 namespace HiviewDFX {
24 class DumpManagerClient final : public DelayedRefSingleton<DumpManagerClient> {
25     DECLARE_DELAYED_REF_SINGLETON(DumpManagerClient)
26 public:
27     DISALLOW_COPY_AND_MOVE(DumpManagerClient);
28     // Used for dump request
29     int32_t Request(std::vector<std::u16string> &args, int outfd);
30 public:
31     bool IsConnected();
32     // Used for connect to hidump SA.
33     ErrCode Connect();
34     // Used for reset connect.
35     void Reset();
36 private:
37     class DumpManagerDeathRecipient : public IRemoteObject::DeathRecipient {
38     public:
39         DumpManagerDeathRecipient() = default;
40         ~DumpManagerDeathRecipient() = default;
41         // Used for remote connect exits
42         void OnRemoteDied(const wptr<IRemoteObject>& remote);
43     private:
44         DISALLOW_COPY_AND_MOVE(DumpManagerDeathRecipient);
45     };
46 private:
47     // Used for reset proxy.
48     void ResetProxy(const wptr<IRemoteObject>& remote);
49     ErrCode OnDemandStart(sptr<ISystemAbilityManager> sam, sptr<IRemoteObject> &remoteObject);
50 private:
51     sptr<IDumpBroker> proxy_ {nullptr};
52     sptr<IRemoteObject::DeathRecipient> deathRecipient_ {nullptr};
53     std::mutex mutex_;
54 };
55 } // namespace HiviewDFX
56 } // namespace OHOS
57 #endif // HIDUMPER_SERVICES_DUMP_MANAGER_CLIENT_H
58