Files

99 lines
3.0 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
* Tencent is pleased to support the open source community by making
* Hippy available.
*
* Copyright (C) 2017-2019 THL A29 Limited, a Tencent company.
* All rights reserved.
*
* 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.
*/
#pragma once
#include <map>
#include <memory>
#include <string>
#include "api/devtools_data_channel.h"
#include "footstone/worker_manager.h"
#include "module/domain/base_domain.h"
#include "module/inspect_event.h"
namespace hippy::devtools {
class BaseDomain;
/**
* @brief domain dispatch, including two parts protocol, 1. chrome debugging protocol, 2. self define protocol start
* with TDF_
*/
class DomainDispatch : public std::enable_shared_from_this<DomainDispatch> {
public:
DomainDispatch(std::shared_ptr<DataChannel> data_channel, std::shared_ptr<footstone::WorkerManager> worker_manager)
: data_channel_(data_channel), worker_manager_(worker_manager) {}
inline std::shared_ptr<DataChannel> GetDataChannel() { return data_channel_; }
inline std::shared_ptr<footstone::WorkerManager> GetWorkerManager() { return worker_manager_; }
/**
* @brief register domain handler which can handle Domain.Method
*/
void RegisterDomainHandler(const std::shared_ptr<BaseDomain>& domain);
/**
* @brief clear domain register handler
*/
void ClearDomainHandler();
/**
* @brief receive msg from frontend
* @param data passing from frontend
*/
bool ReceiveDataFromFrontend(const std::string& data);
void DispatchToVm(const std::string& data);
/**
* @brief response to frontend after call ReceiveDataFromFrontend
* @param result response
*/
void SendDataToFrontend(int32_t id, bool is_success, const std::string& result);
/**
* @brief send event to frontend if you want
* @param event params that should be implemented ToJsonString
*/
void SendEventToFrontend(InspectEvent&& event);
/**
* @brief register domain handler relative with JS engine
*/
void RegisterJSDebuggerDomainListener();
void SetResponseHandler(std::function<void(const std::string)> rsp_handler) { rsp_handler_ = rsp_handler; }
/**
* @brief register domain handler default
*/
void RegisterDefaultDomainListener();
private:
static std::string AdaptProtocolName(std::string domain_name);
std::map<std::string, std::shared_ptr<BaseDomain>> domain_register_map_;
std::function<void(const std::string)> rsp_handler_;
std::shared_ptr<DataChannel> data_channel_;
std::shared_ptr<footstone::WorkerManager> worker_manager_;
};
} // namespace hippy::devtools