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 FORM_ECOLOGICAL_RULE_PROXY_H
17 #define FORM_ECOLOGICAL_RULE_PROXY_H
18 
19 #include <mutex>
20 #include <singleton.h>
21 #include "iremote_proxy.h"
22 #include "form_ecological_rule_interface.h"
23 
24 namespace OHOS {
25 namespace AppExecFwk {
26 using CallerInfo = OHOS::AppExecFwk::FormErmsCallerInfo;
27 class FormEcologicalRuleClient final : public DelayedRefSingleton<FormEcologicalRuleClient> {
28 DECLARE_DELAYED_REF_SINGLETON(FormEcologicalRuleClient)
29 public:
30     DISALLOW_COPY_AND_MOVE(FormEcologicalRuleClient);
31     void OnRemoteSaDied(const wptr<IRemoteObject> &object);
32 
33     int32_t IsSupportPublishForm(const std::vector<Want> &wants, const CallerInfo &callerInfo, bool &bSupport);
34 
35 private:
36     static sptr<IFormEcologicalRule> ConnectService();
37     static bool CheckConnectService();
38 
39     static std::mutex instanceLock_;
40     static sptr<IFormEcologicalRule> ecologicalRuleMgrServiceProxy_;
41     static sptr<IRemoteObject::DeathRecipient> deathRecipient_;
42 
43     static std::string ERMS_ORIGINAL_TARGET;
44 };
45 
46 class FormEcologicalRuleDeathRecipient : public IRemoteObject::DeathRecipient {
47 public:
FormEcologicalRuleDeathRecipient()48     FormEcologicalRuleDeathRecipient() {};
49     ~FormEcologicalRuleDeathRecipient() = default;
50     void OnRemoteDied(const wptr<IRemoteObject> &object) override;
51 
52 private:
53     DISALLOW_COPY_AND_MOVE(FormEcologicalRuleDeathRecipient);
54 };
55 
56 class FormEcologicalRuleProxy : public OHOS::IRemoteProxy<IFormEcologicalRule> {
57 public:
58     using Want = OHOS::AAFwk::Want;
59 
FormEcologicalRuleProxy(const sptr<IRemoteObject> &object)60     explicit FormEcologicalRuleProxy(const sptr<IRemoteObject> &object) : IRemoteProxy<IFormEcologicalRule>(object)
61     {}
62     ~FormEcologicalRuleProxy() = default;
63     DISALLOW_COPY_AND_MOVE(FormEcologicalRuleProxy);
64 
65     int32_t IsSupportPublishForm(const std::vector<Want> &wants, const CallerInfo &callerInfo, bool &bSupport) override;
66 
67 private:
68     static inline BrokerDelegator<FormEcologicalRuleProxy> delegator_;
69 };
70 } // namespace AppExecFwk
71 } // namespace OHOS
72 
73 #endif // FORM_ECOLOGICAL_RULE_PROXY_H
74