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_HOST_INTERFACE_H
17 #define OHOS_FORM_FWK_FORM_HOST_INTERFACE_H
18 
19 #include <vector>
20 
21 #include "form_js_info.h"
22 #include "form_state_info.h"
23 #include "ipc_types.h"
24 #include "iremote_broker.h"
25 
26 #include "want.h"
27 
28 namespace OHOS {
29 namespace AppExecFwk {
30 /**
31  * @class IFormHost
32  * IFormHost interface is used to access form host service.
33  */
34 class IFormHost : public OHOS::IRemoteBroker {
35 public:
36     DECLARE_INTERFACE_DESCRIPTOR(u"ohos.appexecfwk.FormHost");
37 
38     /**
39      * @brief Request to give back a Form.
40      * @param formInfo Form info.
41      * @param token Provider client token.
42      */
43     virtual void OnAcquired(const FormJsInfo &formInfo, const sptr<IRemoteObject> &token) = 0;
44 
45      /**
46      * @brief Form is updated.
47      * @param formInfo Form info.
48      */
49     virtual void OnUpdate(const FormJsInfo &formInfo) = 0;
50 
51     /**
52      * @brief Form provider is uninstalled.
53      * @param formIds The Id list of the forms.
54      */
55     virtual void OnUninstall(const std::vector<int64_t> &formIds) = 0;
56 
57     /**
58      * @brief Form provider is acquire state
59      * @param state The form state.
60      * @param want The form want.
61      */
62     virtual void OnAcquireState(AppExecFwk::FormState state, const AAFwk::Want &want) = 0;
63 
64     /**
65      * @brief Responsive form sharing.
66      * @param requestCode The request code of this share form.
67      * @param result Share form result.
68      */
69     virtual void OnShareFormResponse(int64_t requestCode, int32_t result) = 0;
70 
71     /**
72      * @brief Return error to host.
73      *
74      * @param errorCode Indicates error-code of the form.
75      * @param errorMsg Indicates error-message of the form.
76      */
77     virtual void OnError(int32_t errorCode, const std::string &errorMsg) = 0;
78 
79     /**
80      * @brief Return error to host.
81      *
82      * @param errorCode Indicates error-code of the form.
83      * @param errorMsg Indicates error-message of the form.
84      * @param formIds Indicates ids of the form.
85      */
86     virtual void OnError(int32_t errorCode, const std::string &errorMsg, std::vector<int64_t> &formIds) = 0;
87 
88     /**
89      * @brief Called when form provider acquired data
90      * @param wantParams Indicates the data information acquired by the form.
91      * @param requestCode Indicates the requested id.
92      */
93     virtual void OnAcquireDataResponse(const AAFwk::WantParams &wantParams, int64_t requestCode) = 0;
94 
95     /**
96      * @brief Recycle form
97      * @param formId The id of form to be recycled.
98      */
OnRecycleForm(const int64_t & formId)99     virtual void OnRecycleForm(const int64_t &formId) {}
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      */
OnEnableForm(const std::vector<int64_t> & formIds,const bool enable)106     virtual void OnEnableForm(const std::vector<int64_t> &formIds, const bool enable) {}
107 
108     enum class Message {
109         // ipc id 1-1000 for kit
110         // ipc id 1001-2000 for DMS
111         // ipc id 2001-3000 for tools
112         // ipc id for create (3001)
113         FORM_HOST_ON_ACQUIRED = 3681,
114 
115         // ipc id for update (3682)
116         FORM_HOST_ON_UPDATE,
117 
118         // ipc id for uninstall (3683)
119         FORM_HOST_ON_UNINSTALL,
120 
121         // ipc id for uninstall (3684)
122         FORM_HOST_ON_ACQUIRE_FORM_STATE,
123 
124         // ipc id for share form response(3685)
125         FORM_HOST_ON_SHARE_FORM_RESPONSE,
126 
127         // ipc id for return form error to host(3686)
128         FORM_HOST_ON_ERROR,
129 
130         // ipc id for acquire form data response (3687)
131         FORM_HOST_ON_ACQUIRE_FORM_DATA,
132 
133         // ipc id for acquire form data response (3688)
134         FORM_HOST_ON_RECYCLE_FORM,
135 
136         // ipc id for enable form style (3689)
137         FORM_HOST_ON_ENABLE_FORM,
138 
139         // ipc id for enable form style (3690)
140         FORM_HOST_ON_ERROR_FORMS,
141     };
142 };
143 }  // namespace AppExecFwk
144 }  // namespace OHOS
145 
146 #endif // OHOS_FORM_FWK_FORM_HOST_INTERFACE_H
147