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 #ifndef ARKCOMPILER_TOOLCHAIN_CONNECT_SERVER_CONNECT_SERVER_H 17 #define ARKCOMPILER_TOOLCHAIN_CONNECT_SERVER_CONNECT_SERVER_H 18 19 #include <atomic> 20 #include <functional> 21 #include <iostream> 22 #include <memory> 23 #ifdef WINDOWS_PLATFORM 24 #include <pthread.h> 25 #endif 26 #include <string> 27 28 namespace OHOS::ArkCompiler::Toolchain { 29 class WebSocketServer; 30 31 class ConnectServer { 32 public: 33 ConnectServer(int socketfd, std::function<void(std::string&&)> onMessage); 34 ConnectServer(const std::string& bundleName, std::function<void(std::string&&)> onMessage); 35 ~ConnectServer(); 36 void RunServer(); 37 void StopServer(); 38 void SendMessage(const std::string& message) const; 39 40 private: 41 std::atomic<bool> terminateExecution_ = false; 42 [[maybe_unused]] int socketfd_ {-2}; 43 [[maybe_unused]] std::string bundleName_; 44 pthread_t tid_ {0}; 45 std::function<void(std::string&&)> wsOnMessage_ {}; 46 std::unique_ptr<WebSocketServer> webSocket_ { nullptr }; 47 }; 48 } // namespace OHOS::ArkCompiler::Toolchain 49 50 #endif // ARKCOMPILER_TOOLCHAIN_CONNECT_SERVER_CONNECT_INSPECTOR_H 51