1 /*
2  * Copyright (c) 2021-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_HOST_PROXY_H
17 #define OHOS_FORM_FWK_FORM_HOST_PROXY_H
18 
19 #include "fms_log_wrapper.h"
20 #include "form_host_interface.h"
21 #include "form_state_info.h"
22 #include "iremote_proxy.h"
23 
24 namespace OHOS {
25 namespace AppExecFwk {
26 /**
27  * @class FormHostProxy
28  * Form host proxy is used to access form host service.
29  */
30 class FormHostProxy : public IRemoteProxy<IFormHost> {
31 public:
FormHostProxy(const sptr<IRemoteObject> & impl)32     explicit FormHostProxy(const sptr<IRemoteObject> &impl) : IRemoteProxy<IFormHost>(impl)
33     {}
34 
35     virtual ~FormHostProxy() = default;
36 
37     /**
38      * @brief Request to give back a Form.
39      * @param formInfo Form info.
40      * @param token Provider client token.
41      */
42     void OnAcquired(const FormJsInfo &formInfo, const sptr<IRemoteObject> &token) override;
43 
44     /**
45      * @brief Form is updated.
46      * @param formInfo Form info.
47      */
48     virtual void OnUpdate(const FormJsInfo &formInfo) override;
49 
50     /**
51      * @brief Form provider is uninstalled.
52      * @param formIds The Id list of the forms.
53      */
54     virtual void OnUninstall(const std::vector<int64_t> &formIds) override;
55 
56     /**
57      * @brief Form provider is acquire state
58      * @param state The form state.
59      * @param want The form want.
60      */
61     virtual void OnAcquireState(FormState state, const AAFwk::Want &want) override;
62 
63     /**
64      * @brief Responsive form sharing.
65      * @param requestCode The request code of this share form.
66      * @param result Share form result.
67      */
68     void OnShareFormResponse(int64_t requestCode, int32_t result) override;
69 
70     /**
71      * @brief Form provider has acquired data
72      * @param wantParams Indicates the data information acquired by the form.
73      * @param requestCode Indicates the requested id.
74      */
75     void OnAcquireDataResponse(const AAFwk::WantParams &wantParams, int64_t requestCode) override;
76 
77     /**
78      * @brief Return error to host.
79      *
80      * @param errorCode Indicates error-code of the form.
81      * @param errorMsg Indicates error-message of the form.
82      */
83     void OnError(int32_t errorCode, const std::string &errorMsg) override;
84 
85     /**
86      * @brief Return error to host.
87      *
88      * @param errorCode Indicates error-code of the form.
89      * @param errorMsg Indicates error-message of the form.
90      * @param formIds Indicates ids of the form.
91      */
92     void OnError(int32_t errorCode, const std::string &errorMsg, std::vector<int64_t> &formIds) override;
93 
94     /**
95      * @brief Recycle form.
96      *
97      * @param formId The id of form to be recycled.
98      */
99     void OnRecycleForm(const int64_t &formId) override;
100 
101     /**
102      * @brief enable form style
103      * @param formIds The Id list of the forms.
104      * @param enable True is enableform, false is disableform.
105      */
106     void OnEnableForm(const std::vector<int64_t> &formIds, const bool enable) override;
107 private:
108     template <typename T>
109     int GetParcelableInfos(MessageParcel &reply, std::vector<T> &parcelableInfos);
110     bool WriteInterfaceToken(MessageParcel &data);
111     int SendTransactCmd(IFormHost::Message code, MessageParcel &data, MessageParcel &reply, MessageOption &option);
112 
113 private:
114     static inline BrokerDelegator<FormHostProxy> delegator_;
115 };
116 }  // namespace AppExecFwk
117 }  // namespace OHOS
118 #endif  // OHOS_FORM_FWK_FORM_HOST_PROXY_H
119