• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "domain_manager.h"
17 
18 #include "tooling/client/session/session.h"
19 
20 using PtJson = panda::ecmascript::tooling::PtJson;
21 using Result = panda::ecmascript::tooling::Result;
22 namespace OHOS::ArkCompiler::Toolchain {
DomainManager(uint32_t sessionId)23 DomainManager::DomainManager(uint32_t sessionId)
24     : sessionId_(sessionId), heapProfilerClient_(sessionId), profilerClient_(sessionId),
25       debuggerClient_(sessionId), runtimeClient_(sessionId), testClient_(sessionId)
26 {
27 }
28 
DispatcherReply(char * msg)29 void DomainManager::DispatcherReply(char* msg)
30 {
31     std::string decMessage = std::string(msg);
32     std::unique_ptr<PtJson> json = PtJson::Parse(decMessage);
33     if (json == nullptr) {
34         LOGE("json parse error");
35         return;
36     }
37 
38     if (!json->IsObject()) {
39         LOGE("json parse format error");
40         json->ReleaseRoot();
41         return;
42     }
43 
44     std::string domain;
45     Result ret;
46     int32_t id;
47     ret = json->GetInt("id", &id);
48     if (ret == Result::SUCCESS) {
49         domain = GetDomainById(id);
50         RemoveDomainById(id);
51     }
52 
53     std::string wholeMethod;
54     ret = json->GetString("method", &wholeMethod);
55     if (ret == Result::SUCCESS) {
56         std::string::size_type length = wholeMethod.length();
57         if (length == 0) {
58             return;
59         }
60         std::string::size_type indexPoint = 0;
61         indexPoint = wholeMethod.find_first_of('.', 0);
62         if (indexPoint == std::string::npos || indexPoint == 0 || indexPoint == length - 1) {
63             return;
64         }
65         domain = wholeMethod.substr(0, indexPoint);
66     }
67 
68     if (domain == "HeapProfiler") {
69         heapProfilerClient_.RecvReply(std::move(json));
70     } else if (domain == "Profiler") {
71         profilerClient_.RecvProfilerResult(std::move(json));
72     } else if (domain == "Runtime") {
73         runtimeClient_.RecvReply(std::move(json));
74     } else if (domain == "Debugger") {
75         debuggerClient_.RecvReply(std::move(json));
76     }
77 }
78 }