1 /* 2 * Copyright (c) 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_HIVIEWDFX_ADAPTER_SERVICE_IDL_INCLUDE_TRACE_DELEGATE_H 17 #define OHOS_HIVIEWDFX_ADAPTER_SERVICE_IDL_INCLUDE_TRACE_DELEGATE_H 18 19 #include <vector> 20 21 #include "collect_result.h" 22 #include "hiview_service_ability_proxy.h" 23 #include "hiview_service_agent.h" 24 #include "parcel.h" 25 26 27 namespace OHOS { 28 namespace HiviewDFX { 29 class HiViewServiceTraceDelegate { 30 public: 31 static CollectResult<int32_t> OpenSnapshot(const std::vector<std::string>& tagGroups); 32 static CollectResult<std::vector<std::string>> DumpSnapshot(int32_t caller); 33 static CollectResult<int32_t> OpenRecording(const std::string& tags); 34 static CollectResult<int32_t> RecordingOn(); 35 static CollectResult<std::vector<std::string>> RecordingOff(); 36 static CollectResult<int32_t> Close(); 37 static CollectResult<int32_t> Recover(); 38 39 private: 40 template<typename T> TraceCalling(std::function<CollectResultParcelable<T> (HiviewServiceAbilityProxy &)> proxyHandler)41 static CollectResult<T> TraceCalling( 42 std::function<CollectResultParcelable<T>(HiviewServiceAbilityProxy&)> proxyHandler) 43 { 44 CollectResult<T> ret = { 45 .retCode = UCollect::UcError::UNSUPPORT, 46 }; 47 if (proxyHandler == nullptr) { 48 return ret; 49 } 50 auto service = HiviewServiceAgent::GetInstance().GetRemoteService(); 51 if (service == nullptr) { 52 return ret; 53 } 54 HiviewServiceAbilityProxy proxy(service); 55 auto traceRet = proxyHandler(proxy); 56 return traceRet.result_; 57 } 58 }; 59 } // namespace HiviewDFX 60 } // namespace OHOS 61 62 #endif // OHOS_HIVIEWDFX_ADAPTER_SERVICE_IDL_INCLUDE_TRACE_DELEGATE_H 63