• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_FORM_FWK_FORM_ROUTER_PROXY_MGR_H
17 #define OHOS_FORM_FWK_FORM_ROUTER_PROXY_MGR_H
18 
19 #include <singleton.h>
20 #include <vector>
21 
22 #include "iremote_object.h"
23 #include "want.h"
24 
25 namespace OHOS {
26 namespace AppExecFwk {
27 using Want = OHOS::AAFwk::Want;
28 /**
29  * @class FormRouterProxyMgr
30  * Form router proxy manager.
31  */
32 class FormRouterProxyMgr : public DelayedRefSingleton<FormRouterProxyMgr> {
33 public:
34 
35     /**
36      * @brief Set value of router proxies.
37      * @param formIds the form ids of Router proxy.
38      * @param callerToken Router proxy caller token.
39      */
40     ErrCode SetFormRouterProxy(const std::vector<int64_t> &formIds, const sptr<IRemoteObject> &callerToken);
41 
42     /**
43      * @brief Remove value of router proxies.
44      * @param formIds the form ids of Router proxy.
45      */
46     ErrCode RemoveFormRouterProxy(const std::vector<int64_t> &formIds);
47 
48     /**
49      * @brief Get the router proxy of the current form id.
50      * @param formId the form id of router proxy.
51      */
52     bool HasRouterProxy(int64_t formId);
53 
54     /**
55      * @brief Trigger the router event info of this form id.
56      * @param formId the form id of router proxy.
57      * @param want the want info for router event.
58      */
59     void OnFormRouterEvent(int64_t formId, const Want &want);
60 
61     /**
62      * @brief when form proxy died clean the resource.
63      * @param remote remote object.
64      */
65     void CleanResource(const wptr<IRemoteObject> &remote);
66 
67 private:
68     /**
69      * @brief Set value of deathRecipient_.
70      * @param callerToken Caller ability token.
71      * @param deathRecipient DeathRecipient object.
72      */
73     void SetDeathRecipient(const sptr<IRemoteObject> &callerToken,
74         const sptr<IRemoteObject::DeathRecipient> &deathRecipient);
75 
76     void PostRouterProxyToHost(const int64_t formId, const sptr<IRemoteObject> &remoteObject,
77         const Want &want);
78 
79     mutable std::mutex formRouterProxyMutex_;
80     mutable std::mutex deathRecipientsMutex_;
81     std::map<int64_t, sptr<IRemoteObject>> formRouterProxyMap_;
82     std::map<sptr<IRemoteObject>, sptr<IRemoteObject::DeathRecipient>> deathRecipients_;
83 
84     /**
85      * @class ClientDeathRecipient
86      * notices IRemoteBroker died.
87      */
88     class ClientDeathRecipient : public IRemoteObject::DeathRecipient {
89     public:
90         /**
91          * @brief Constructor
92          */
93         ClientDeathRecipient() = default;
94         virtual ~ClientDeathRecipient() = default;
95         /**
96          * @brief handle remote object died event.
97          * @param remote remote object.
98          */
99         void OnRemoteDied(const wptr<IRemoteObject> &remote) override;
100     };
101 };
102 }  // namespace AppExecFwk
103 }  // namespace OHOS
104 
105 #endif // OHOS_FORM_FWK_FORM_ROUTER_PROXY_MGR_H
106