1 /** 2 * Copyright (c) 2022-2024 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 PANDA_TOOLING_INSPECTOR_CONNECTION_ASIO_SERVER_ENDPOINT_INL_H 17 #define PANDA_TOOLING_INSPECTOR_CONNECTION_ASIO_SERVER_ENDPOINT_INL_H 18 19 #ifndef CONFIG 20 #error Define CONFIG before including this header 21 #endif 22 23 #include "connection/asio/server_endpoint.h" 24 25 namespace ark::tooling::inspector { 26 template <> // NOLINTNEXTLINE(misc-definitions-in-headers) ServerEndpoint()27ServerEndpoint<CONFIG>::ServerEndpoint() noexcept 28 { 29 endpoint_.set_message_handler( 30 [this](auto /* hdl */, auto message) { this->HandleMessage(message->get_payload()); }); 31 32 endpoint_.set_validate_handler([this](auto hdl) { 33 onValidate_(); 34 35 if (Pin(hdl)) { 36 return true; 37 } 38 39 endpoint_.get_con_from_hdl(hdl)->set_body("Another debug session is in progress"); 40 return false; 41 }); 42 43 endpoint_.set_open_handler([this](auto) { onOpen_(); }); 44 endpoint_.set_fail_handler([this](auto hdl) { 45 onFail_(); 46 Unpin(hdl); 47 }); 48 49 endpoint_.set_close_handler([this](auto hdl) { Unpin(hdl); }); 50 } 51 52 template <> // NOLINTNEXTLINE(misc-definitions-in-headers) Close()53bool ServerEndpoint<CONFIG>::Close() 54 { 55 if (auto connection = GetPinnedConnection()) { 56 std::error_code ec; 57 connection->close(websocketpp::close::status::going_away, "", ec); 58 if (ec) { 59 LOG(ERROR, DEBUGGER) << "Error closing websocket connection: " << ec.message(); 60 return false; 61 } 62 } 63 return true; 64 } 65 } // namespace ark::tooling::inspector 66 67 #endif // PANDA_TOOLING_INSPECTOR_CONNECTION_ASIO_SERVER_ENDPOINT_INL_H 68