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_ACQUIRE_CONNECTION_H 17 #define OHOS_FORM_FWK_FORM_ACQUIRE_CONNECTION_H 18 19 #include "event_handler.h" 20 #include "form_ability_connection.h" 21 #include "form_item_info.h" 22 #include "want.h" 23 24 namespace OHOS { 25 namespace AppExecFwk { 26 using WantParams = OHOS::AAFwk::WantParams; 27 28 /** 29 * @class FormAcquireConnection 30 * Form Acquire Connection Stub. 31 */ 32 class FormAcquireConnection : public FormAbilityConnection { 33 public: 34 FormAcquireConnection(const int64_t formId, const FormItemInfo &info, const WantParams &wantParams, 35 const sptr<IRemoteObject> hostToken); 36 FormAcquireConnection() = delete; // disable default constructor. 37 virtual ~FormAcquireConnection() = default; 38 39 /** 40 * @brief OnAbilityConnectDone, AbilityMs notify caller ability the result of connect. 41 * @param element service ability's ElementName. 42 * @param remoteObject the session proxy of service ability. 43 * @param resultCode ERR_OK on success, others on failure. 44 */ 45 void OnAbilityConnectDone( 46 const AppExecFwk::ElementName &element, const sptr<IRemoteObject> &remoteObject, int resultCode) override; 47 48 /** 49 * @brief OnAbilityDisconnectDone, AbilityMs notify caller ability the result of disconnect. 50 * @param element service ability's ElementName. 51 * @param resultCode ERR_OK on success, others on failure. 52 */ 53 void OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode) override; 54 55 /** 56 * @brief Set form ability connection callback. 57 */ 58 void SetFormAbilityConnectCb(std::function<void(const std::string &bundleName)> &&callback); 59 60 /** 61 * @brief Set form ability disconnection callback. 62 */ 63 void SetFormAbilityDisconnectCb(std::function<void(const std::string &bundleName)> &&callback); 64 65 /** 66 * @brief On form ability connect callback. 67 */ 68 void OnFormAbilityConnectDoneCallback(); 69 70 /** 71 * @brief On form ability disconnect callback. 72 */ 73 void OnFormAbilityDisconnectDoneCallback(); 74 75 private: 76 FormItemInfo info_; 77 WantParams wantParams_; 78 std::function<void(const std::string &bundleName)> onFormAblityConnectCb_; 79 std::function<void(const std::string &bundleName)> onFormAblityDisconnectCb_; 80 81 DISALLOW_COPY_AND_MOVE(FormAcquireConnection); 82 }; 83 } // namespace AppExecFwk 84 } // namespace OHOS 85 86 #endif // OHOS_FORM_FWK_FORM_ACQUIRE_CONNECTION_H 87