/* * Copyright (c) 2024 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_CLIENT_TCPSERVER_H #define ECMASCRIPT_TOOLING_CLIENT_TCPSERVER_H #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "arkcompiler/toolchain/common/log_wrapper.h" namespace OHOS::ArkCompiler::Toolchain { extern uv_async_t* g_inputSignal; extern uv_async_t* g_releaseHandle; class TcpServer { public: static TcpServer& getInstance() { static TcpServer instance; return instance; } int CreateTcpServer([[maybe_unused]] void* arg); void StartTcpServer([[maybe_unused]] void* arg); void TcpServerWrite(std::string msg = "inner"); bool IsServerActive() const { return isServerActive; } void SetServerState(const bool state) { isServerActive = state; } private: TcpServer() = default; TcpServer(const TcpServer&) = delete; TcpServer& operator=(const TcpServer&) = delete; void SendCommand(std::string inputStr); void CloseServer(); void ServerConnect(); bool FindCommand(std::vector cmds, std::string cmd); uv_thread_t serverTid_ = 0; bool isServerActive = false; int lfd = -1; int cfd = -1; }; } // namespace OHOS::ArkCompiler::Toolchain #endif // ECMASCRIPT_TOOLING_CLIENT_TCPSERVER_H