• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2024 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 "client/trace_collector_client.h"
22 #include "collect_result.h"
23 #include "hiview_err_code.h"
24 #include "hiview_remote_service.h"
25 #include "iremote_proxy.h"
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 client);
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> CaptureDurationTrace(UCollectClient::AppCaller &appCaller);
38 
39 private:
40     template<typename T>
TraceCalling(std::function<int32_t (const sptr<IRemoteObject> &,CollectResult<T> &,int32_t &)> proxyHandler)41     static CollectResult<T> TraceCalling(
42         std::function<int32_t(const sptr<IRemoteObject>&, CollectResult<T>&, int32_t&)> proxyHandler)
43     {
44         CollectResult<T> collectResult;
45         auto service = RemoteService::GetHiViewRemoteService();
46         if (service == nullptr) {
47             return collectResult;
48         }
49         int32_t errNo = UCollect::UcError::UNSUPPORT;
50         int32_t ret = proxyHandler(service, collectResult, errNo);
51         if (ret == 0) {
52             collectResult.retCode = static_cast<UCollect::UcError>(errNo);
53             return collectResult;
54         }
55         if (ret == TraceErrCode::ERR_PERMISSION_CHECK) {
56             collectResult.retCode = UCollect::UcError::PERMISSION_CHECK_FAILED;
57         }
58         return collectResult;
59     }
60 };
61 } // namespace HiviewDFX
62 } // namespace OHOS
63 
64 #endif // OHOS_HIVIEWDFX_ADAPTER_SERVICE_IDL_INCLUDE_TRACE_DELEGATE_H
65