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_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 Accept form data from form provider. 62 * @param formId The Id of the from. 63 * @param wantParams Indicates the data information acquired by the form. 64 * @param requestCode Indicates the requested id. 65 * @return Returns ERR_OK on success, others on failure. 66 */ 67 int OnAcquireDataResult(const AAFwk::WantParams &wantParams, int64_t requestCode) override; 68 69 /** 70 * @brief Save ability Connection for the callback. 71 * @param connection ability connection. 72 */ 73 void AddConnection(sptr<FormAbilityConnection> connection); 74 /** 75 * @brief Delete ability connection after the callback come. 76 * @param connectId The ability connection id generated when save. 77 */ 78 void RemoveConnection(int32_t connectId); 79 /** 80 * @brief Delete ability connection by formId and hostToken. 81 * @param formId Indicates the ID of the form. 82 * @param hostToken Indicates the host token for matching connection. 83 */ 84 void RemoveConnection(int64_t formId, const sptr<IRemoteObject> &hostToken); 85 86 void OnShareAcquire(int64_t formId, const std::string &remoteDeviceId, 87 const AAFwk::WantParams &wantParams, int64_t requestCode, const bool &result) override; 88 89 /** 90 * @brief Handle form host died. 91 * @param hostToken Form host proxy object. 92 */ 93 void HandleHostDied(const sptr<IRemoteObject> &hostToken); 94 95 /** 96 * @brief Accept form render task done from render service. 97 * @param formId The Id of the form. 98 * @param want input data. 99 * @return Returns ERR_OK on success, others on failure. 100 */ 101 int32_t OnRenderTaskDone(int64_t formId, const Want &want) override; 102 103 /** 104 * @brief Accept form stop rendering task done from render service. 105 * @param formId The Id of the form. 106 * @param want input data. 107 * @return Returns ERR_OK on success, others on failure. 108 */ 109 int32_t OnStopRenderingTaskDone(int64_t formId, const Want &want) override; 110 111 /** 112 * @brief Accept rendering block from render service. 113 * @param bundleName The block of bundleName. 114 * @return Returns ERR_OK on success, others on failure. 115 */ 116 int32_t OnRenderingBlock(const std::string &bundleName) override; 117 118 /** 119 * @brief Accept status data of recycled form from render service 120 * @param formId The Id of the form. 121 * @param want Input data. 122 * @return Returns ERR_OK on success, others on failure. 123 */ 124 int32_t OnRecycleForm(const int64_t &formId, const Want &want) override; 125 private: 126 /** 127 * @brief check if disconnect ability or not. 128 * @param connection The ability connection. 129 */ 130 bool CanDisconnect(sptr<FormAbilityConnection> &connection); 131 132 bool IsRemoveConnection(int64_t formId, const sptr<IRemoteObject> &hostToken); 133 private: 134 static std::mutex mutex_; 135 static sptr<FormSupplyCallback> instance_; 136 137 mutable std::mutex conMutex_; 138 std::map<int32_t, sptr<FormAbilityConnection>> connections_; 139 DISALLOW_COPY_AND_MOVE(FormSupplyCallback); 140 }; 141 } // namespace AppExecFwk 142 } // namespace OHOS 143 #endif // OHOS_FORM_FWK_FORM_SUPPLY_CALLBACK_H 144