• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2024-2025 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_OHOS_WS_OHOS_WS_SERVER_ENDPOINT_H
17 #define PANDA_TOOLING_INSPECTOR_CONNECTION_OHOS_WS_OHOS_WS_SERVER_ENDPOINT_H
18 
19 #include "server/websocket_server.h"
20 
21 #include "connection/server_endpoint_base.h"
22 #include "../../common/macros.h"
23 #include "inspector.h"
24 namespace ark::tooling::inspector {
25 // Server endpoint based on OHOS websocket implementation
26 // NOLINTNEXTLINE(fuchsia-multiple-inheritance)
27 class OhosWsServerEndpoint : public ServerEndpointBase {
28 protected:
29     using Endpoint = OHOS::ArkCompiler::Toolchain::WebSocketServer;
30 
31 public:
32     OhosWsServerEndpoint() noexcept;
33 
34 protected:
35     std::shared_ptr<Endpoint> endpoint_;  // NOLINT(misc-non-private-member-variables-in-classes)
36 
37 private:
SendMessage(const std::string & message)38     void SendMessage(const std::string &message) override
39     {
40         auto wasSent = false;
41         if (endpoint_ != nullptr) {
42             if (endpoint_->IsConnected()) {
43                 wasSent = endpoint_->SendReply(message);
44             }
45         }
46         if (!wasSent) {
47             LOG(INFO, DEBUGGER) << "Did not send message: " << message;
48         }
49     }
50 };
51 }  // namespace ark::tooling::inspector
52 
53 #endif  // PANDA_TOOLING_INSPECTOR_CONNECTION_OHOS_WS_OHOS_WS_SERVER_ENDPOINT_H
54