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_CLIENT_H 17 #define OHOS_FORM_FWK_FORM_HOST_CLIENT_H 18 19 #include <map> 20 #include "form_host_stub.h" 21 #include "iremote_object.h" 22 #include "iremote_stub.h" 23 #include "semaphore_ex.h" 24 25 namespace OHOS { 26 namespace AppExecFwk { 27 /** 28 * @class MockFormHostClient 29 * MockFormHostClient. 30 */ 31 class MockFormHostClient : public FormHostStub { 32 public: 33 MockFormHostClient() = default; 34 virtual ~MockFormHostClient() = default; 35 Wait()36 void Wait() 37 { 38 sem_.Wait(); 39 } 40 Post()41 int Post() 42 { 43 sem_.Post(); 44 return 0; 45 } 46 PostVoid()47 void PostVoid() 48 { 49 sem_.Post(); 50 } 51 52 /** 53 * Request to give back a Form. 54 * 55 * @param formId, The Id of the forms to create. 56 * @param formInfo, Form info. 57 * @return none. 58 */ 59 void OnAcquired(const FormJsInfo &formInfo, const sptr<IRemoteObject> &token) override; 60 61 /** 62 * Form is updated. 63 * 64 * @param formId, The Id of the form to update. 65 * @param formInfo, Form info. 66 * @return none. 67 */ 68 void OnUpdate(const FormJsInfo &formInfo) override; 69 70 /** 71 * Form provider is uninstalled. 72 * 73 * @param formIds, The Id list of the forms. 74 * @return none. 75 */ 76 void OnUninstall(const std::vector<int64_t> &formIds) override; 77 78 /** 79 * @brief Form provider is acquire state 80 * @param state The form state. 81 * @param want The form want. 82 */ 83 void OnAcquireState(AppExecFwk::FormState state, const AAFwk::Want &want) override; 84 85 /** 86 * @brief Responsive form sharing. 87 * @param requestCode The request code of this share form. 88 * @param result Share form result. 89 */ 90 void OnShareFormResponse(int64_t requestCode, int32_t result) override; 91 92 /** 93 * @brief Return error to host. 94 * @param errorCode Indicates error-code of the form. 95 * @param errorMsg Indicates error-message of the form. 96 */ 97 void OnError(int32_t errorCode, const std::string &errorMsg) override; 98 99 /** 100 * @brief Return error to host for forms. 101 * 102 * @param errorCode Indicates error-code of the form. 103 * @param errorMsg Indicates error-message of the form. 104 * @param formIds Indicates ids of the form. 105 */ 106 void OnError(int32_t errorCode, const std::string &errorMsg, std::vector<int64_t> &formIds) override; 107 108 /** 109 * @brief Form provider is acquire data 110 * @param wantParams Indicates the data information acquired by the form. 111 * @param requestCode Indicates the requested id. 112 */ 113 void OnAcquireDataResponse(const AAFwk::WantParams &wantParams, int64_t requestCode) override; 114 115 /** 116 * @brief enable form style 117 * @param formIds The Id list of the forms. 118 * @param enable True is enableform, false is disableform. 119 */ 120 void OnEnableForm(const std::vector<int64_t> &formIds, const bool enable) override; 121 private: 122 Semaphore sem_; 123 DISALLOW_COPY_AND_MOVE(MockFormHostClient); 124 }; 125 } // namespace AppExecFwk 126 } // namespace OHOS 127 #endif // OHOS_FORM_FWK_FORM_HOST_CLIENT_H 128