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 FOUNDATION_ACE_ADAPTER_PREVIEW_INSPECTOR_INSPECTOR_CLIENT_H 17 #define FOUNDATION_ACE_ADAPTER_PREVIEW_INSPECTOR_INSPECTOR_CLIENT_H 18 19 #include <functional> 20 #include <string> 21 #include <utility> 22 #include <vector> 23 24 namespace OHOS::Ace::Framework { 25 26 using AssembleJSONTreeCallback = std::function<bool(std::string &jsonTreeStr)>; 27 using AssembleDefaultJSONTreeCallback = std::function<bool(std::string &jsonTreeStr)>; 28 using OperateComponentCallback = std::function<bool(const std::string &attrsJson)>; 29 using FastPreviewErrorCallback = std::function<void(const std::string &jsonStr)>; 30 31 class InspectorClient { 32 public: 33 InspectorClient &operator = (const InspectorClient &) = delete; 34 InspectorClient(const InspectorClient &) = delete; 35 ~InspectorClient() = default; 36 37 static InspectorClient &GetInstance(); 38 void RegisterJSONTreeCallback(AssembleJSONTreeCallback &&callback); 39 void RegisterDefaultJSONTreeCallback(AssembleDefaultJSONTreeCallback &&callback); 40 void RegisterOperateComponentCallback(OperateComponentCallback &&callback); 41 void RegisterFastPreviewErrorCallback(FastPreviewErrorCallback&& callback); 42 bool AssembleJSONTreeStr(std::string &jsonTreeStr); 43 bool AssembleDefaultJSONTreeStr(std::string &jsonTreeStr); 44 bool OperateComponent(const std::string &attrsJson); CallFastPreviewErrorCallback(const std::string & jsonStr)45 void CallFastPreviewErrorCallback(const std::string& jsonStr) 46 { 47 if (onError_) { 48 onError_(jsonStr); 49 } 50 } 51 52 private: 53 InspectorClient() = default; 54 AssembleJSONTreeCallback assembleJSONTreeCallback_; 55 AssembleDefaultJSONTreeCallback assembleDefaultJSONTreeCallback_; 56 OperateComponentCallback operateComponentCallback_; 57 FastPreviewErrorCallback onError_; 58 }; 59 60 } // namespace OHOS::Ace::Framework 61 62 #endif // FOUNDATION_ACE_ADAPTER_PREVIEW_INSPECTOR_INSPECTOR_CLIENT_H 63