• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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_SUPPLY_CALLBACK_H
17 #define OHOS_FORM_FWK_FORM_SUPPLY_CALLBACK_H
18 
19 #include "form_ability_connection.h"
20 #include "form_supply_stub.h"
21 
22 namespace OHOS {
23 namespace AppExecFwk {
24 /**
25  * @class FormSupplyCallback
26  * form supply service stub.
27  */
28 class FormSupplyCallback : public FormSupplyStub {
29 public:
30     FormSupplyCallback() = default;
31     virtual ~FormSupplyCallback() = default;
32     static sptr<FormSupplyCallback> GetInstance();
33 
34     /**
35      * @brief Accept form binding data from form provider.
36      * @param providerFormInfo Form binding data.
37      * @param want input data.
38      * @return Returns ERR_OK on success, others on failure.
39      */
40     int OnAcquire(const FormProviderInfo &formInfo, const Want &want) override;
41 
42     /**
43      * @brief Accept other event.
44      * @param want input data.
45      * @return Returns ERR_OK on success, others on failure.
46      */
47     int OnEventHandle(const Want &want) override;
48 
49     /**
50      * @brief Accept form state from form provider.
51      * @param state Form state.
52      * @param provider provider info.
53      * @param wantArg The want of onAcquireFormState.
54      * @param want input data.
55      * @return Returns ERR_OK on success, others on failure.
56      */
57     int OnAcquireStateResult(FormState state, const std::string &provider, const Want &wantArg,
58                              const Want &want) override;
59 
60     /**
61      * @brief Save ability Connection for the callback.
62      * @param connection ability connection.
63      */
64     void AddConnection(sptr<FormAbilityConnection> connection);
65     /**
66      * @brief Delete ability connection after the callback come.
67      * @param connectId The ability connection id generated when save.
68      */
69     void RemoveConnection(int32_t connectId);
70     /**
71      * @brief Delete ability connection by formId and hostToken.
72      * @param formId Indicates the ID of the form.
73      * @param hostToken Indicates the host token for matching connection.
74      */
75     void RemoveConnection(int64_t formId, const sptr<IRemoteObject> &hostToken);
76 
77     void OnShareAcquire(int64_t formId, const std::string &remoteDeviceId,
78         const AAFwk::WantParams &wantParams, int64_t requestCode, const bool &result) override;
79 
80     /**
81      * @brief Handle form host died.
82      * @param hostToken Form host proxy object.
83      */
84     void HandleHostDied(const sptr<IRemoteObject> &hostToken);
85 
86     /**
87      * @brief Accept form render task done from render service.
88      * @param formId The Id of the form.
89      * @param want input data.
90      * @return Returns ERR_OK on success, others on failure.
91      */
92     int32_t OnRenderTaskDone(int64_t formId, const Want &want) override;
93 
94     /**
95      * @brief Accept form stop rendering task done from render service.
96      * @param formId The Id of the form.
97      * @param want input data.
98      * @return Returns ERR_OK on success, others on failure.
99      */
100     int32_t OnStopRenderingTaskDone(int64_t formId, const Want &want) override;
101 private:
102     /**
103      * @brief check if disconnect ability or not.
104      * @param connection The ability connection.
105      */
106     bool CanDisconnect(sptr<FormAbilityConnection> &connection);
107 
108     bool IsRemoveConnection(int64_t formId, const sptr<IRemoteObject> &hostToken);
109 private:
110     static std::mutex mutex_;
111     static sptr<FormSupplyCallback> instance_;
112 
113     mutable std::mutex conMutex_;
114     std::map<int32_t, sptr<FormAbilityConnection>> connections_;
115     DISALLOW_COPY_AND_MOVE(FormSupplyCallback);
116 };
117 }  // namespace AppExecFwk
118 }  // namespace OHOS
119 #endif  // OHOS_FORM_FWK_FORM_SUPPLY_CALLBACK_H
120