/* * Copyright (c) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef ECMASCRIPT_TOOLING_AGENT_RUNTIME_IMPL_H #define ECMASCRIPT_TOOLING_AGENT_RUNTIME_IMPL_H #include "libpandabase/macros.h" #include "ecmascript/tooling/agent/js_backend.h" #include "ecmascript/tooling/base/pt_params.h" #include "ecmascript/tooling/dispatcher.h" namespace panda::ecmascript::tooling { class RuntimeImpl final { public: explicit RuntimeImpl(JSBackend *backend) : backend_(backend) {} ~RuntimeImpl() = default; DispatchResponse Enable(); DispatchResponse RunIfWaitingForDebugger(); DispatchResponse GetProperties( std::unique_ptr params, CVector> *outPropertyDesc, std::optional>> *outInternalDescs, std::optional>> *outPrivateProps, std::optional> *outExceptionDetails); DispatchResponse CallFunctionOn( std::unique_ptr params, std::unique_ptr *outRemoteObject, std::optional> *outExceptionDetails); DispatchResponse GetHeapUsage(double *usedSize, double *totalSize); class DispatcherImpl final : public DispatcherBase { public: DispatcherImpl(FrontEnd *frontend, std::unique_ptr runtime); ~DispatcherImpl() override = default; void Dispatch(const DispatchRequest &request) override; void Enable(const DispatchRequest &request); void RunIfWaitingForDebugger(const DispatchRequest &request); void GetProperties(const DispatchRequest &request); void CallFunctionOn(const DispatchRequest &request); void GetHeapUsage(const DispatchRequest &request); private: using AgentHandler = void (RuntimeImpl::DispatcherImpl::*)(const DispatchRequest &request); CUnorderedMap dispatcherTable_ {}; std::unique_ptr runtime_ {}; NO_COPY_SEMANTIC(DispatcherImpl); NO_MOVE_SEMANTIC(DispatcherImpl); }; private: NO_COPY_SEMANTIC(RuntimeImpl); NO_MOVE_SEMANTIC(RuntimeImpl); JSBackend *backend_{nullptr}; }; } // namespace panda::ecmascript::tooling #endif