1 /* 2 * Copyright (c) 2025 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 API_CALLER_SERVER_H 17 #define API_CALLER_SERVER_H 18 19 #include <string> 20 #include <string_view> 21 #include <functional> 22 #include <future> 23 #include "frontend_api_defines.h" 24 #include "ipc_transactor.h" 25 26 namespace OHOS::perftest { 27 /**Represents the api transaction server.*/ 28 class ApiCallerServer { 29 public: ApiCallerServer()30 ApiCallerServer() {}; 31 ~ApiCallerServer(); 32 bool InitAndConnectPeer(std::string_view token, ApiCallHandler handler); 33 void Transact(const ApiCallInfo &call, ApiReplyInfo &reply); 34 void SetDeathCallback(std::function<void()> callback); 35 ConnectionStat GetConnectionStat() const; 36 void Finalize(); 37 private: 38 sptr<IRemoteObject> PublishCallerAndWaitForBackcaller(const sptr<ApiCallerStub> &caller, string_view token); 39 void OnPeerDeath(); 40 41 private: 42 ConnectionStat connectState_ = UNINIT; 43 // ipc objects 44 sptr<ApiCallerStub> caller_ = nullptr; 45 sptr<ApiCallerProxy> remoteCaller_ = nullptr; 46 sptr<OHOS::IRemoteObject::DeathRecipient> peerDeathCallback_ = nullptr; 47 std::function<void()> onDeathCallback_ = nullptr; 48 }; 49 } // namespace OHOS::perftest 50 51 #endif