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 "agent/target_impl.h"
17
18 #include "base/pt_events.h"
19 #include "protocol_channel.h"
20
21 namespace panda::ecmascript::tooling {
Dispatch(const DispatchRequest & request)22 void TargetImpl::DispatcherImpl::Dispatch(const DispatchRequest &request)
23 {
24 static std::unordered_map<std::string, AgentHandler> dispatcherTable {
25 { "setAutoAttach", &TargetImpl::DispatcherImpl::SetAutoAttach },
26 };
27
28 const std::string &method = request.GetMethod();
29 LOG_DEBUGGER(INFO) << "dispatch [" << method << "] to TargetImpl";
30 auto entry = dispatcherTable.find(method);
31 if (entry != dispatcherTable.end() && entry->second != nullptr) {
32 (this->*(entry->second))(request);
33 } else {
34 SendResponse(request, DispatchResponse::Fail("Unknown method: " + method));
35 }
36 }
37
SetAutoAttach(const DispatchRequest & request)38 void TargetImpl::DispatcherImpl::SetAutoAttach(const DispatchRequest &request)
39 {
40 DispatchResponse response = DispatchResponse::Ok();
41 SendResponse(request, response);
42 }
43 } // namespace panda::ecmascript::tooling