From 1084023ca77863427831646101c5a921bbe16aae Mon Sep 17 00:00:00 2001 From: Vivien Nicolas Date: Wed, 25 Jan 2023 15:40:39 +0100 Subject: [PATCH] [chip-tool] Move WebSocketServer code to src/app/tests/suites/server so it can be reused (#24617) --- examples/chip-tool/BUILD.gn | 12 +++---- .../interactive/InteractiveCommands.h | 2 +- examples/common/websocket-server/BUILD.gn | 31 +++++++++++++++++++ .../websocket-server}/WebSocketServer.cpp | 1 + .../websocket-server}/WebSocketServer.h | 1 - .../WebSocketServerDelegate.h | 0 6 files changed, 38 insertions(+), 9 deletions(-) create mode 100644 examples/common/websocket-server/BUILD.gn rename examples/{chip-tool/commands/interactive => common/websocket-server}/WebSocketServer.cpp (99%) rename examples/{chip-tool/commands/interactive => common/websocket-server}/WebSocketServer.h (97%) rename examples/{chip-tool/commands/interactive => common/websocket-server}/WebSocketServerDelegate.h (100%) diff --git a/examples/chip-tool/BUILD.gn b/examples/chip-tool/BUILD.gn index 76ec22f40c8223..97df8a48b5051d 100644 --- a/examples/chip-tool/BUILD.gn +++ b/examples/chip-tool/BUILD.gn @@ -28,6 +28,7 @@ assert(chip_build_tools) config("config") { include_dirs = [ ".", + "${chip_root}/examples/common", "${chip_root}/zzz_generated/app-common/app-common", "${chip_root}/zzz_generated/chip-tool", "${chip_root}/src/lib", @@ -87,13 +88,11 @@ static_library("chip-tool-utils") { deps = [] if (config_use_interactive_mode) { - sources += [ - "commands/interactive/InteractiveCommands.cpp", - "commands/interactive/WebSocketServer.cpp", - "commands/interactive/WebSocketServer.h", - "commands/interactive/WebSocketServerDelegate.h", + sources += [ "commands/interactive/InteractiveCommands.cpp" ] + deps += [ + "${chip_root}/examples/common/websocket-server", + "${editline_root}:editline", ] - deps += [ "${editline_root}:editline" ] } if (config_enable_yaml_tests) { @@ -116,7 +115,6 @@ static_library("chip-tool-utils") { "${chip_root}/src/platform", "${chip_root}/third_party/inipp", "${chip_root}/third_party/jsoncpp", - "${chip_root}/third_party/libwebsockets", ] public_configs = [ ":config" ] diff --git a/examples/chip-tool/commands/interactive/InteractiveCommands.h b/examples/chip-tool/commands/interactive/InteractiveCommands.h index 5e611e6895d2b2..49e6432ccb7f01 100644 --- a/examples/chip-tool/commands/interactive/InteractiveCommands.h +++ b/examples/chip-tool/commands/interactive/InteractiveCommands.h @@ -22,7 +22,7 @@ #include "../common/CHIPCommand.h" #include "../common/Commands.h" -#include "WebSocketServer.h" +#include class Commands; diff --git a/examples/common/websocket-server/BUILD.gn b/examples/common/websocket-server/BUILD.gn new file mode 100644 index 00000000000000..fdd17300cecd06 --- /dev/null +++ b/examples/common/websocket-server/BUILD.gn @@ -0,0 +1,31 @@ +# Copyright (c) 2023 Project CHIP Authors +# +# 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. + +import("//build_overrides/build.gni") +import("//build_overrides/chip.gni") + +static_library("websocket-server") { + output_name = "libWebSocketServer" + + sources = [ + "WebSocketServer.cpp", + "WebSocketServer.h", + "WebSocketServerDelegate.h", + ] + + public_deps = [ + "${chip_root}/src/lib/support", + "${chip_root}/third_party/libwebsockets", + ] +} diff --git a/examples/chip-tool/commands/interactive/WebSocketServer.cpp b/examples/common/websocket-server/WebSocketServer.cpp similarity index 99% rename from examples/chip-tool/commands/interactive/WebSocketServer.cpp rename to examples/common/websocket-server/WebSocketServer.cpp index a41754716ae961..867180b976c012 100644 --- a/examples/chip-tool/commands/interactive/WebSocketServer.cpp +++ b/examples/common/websocket-server/WebSocketServer.cpp @@ -19,6 +19,7 @@ #include "WebSocketServer.h" #include +#include constexpr uint16_t kDefaultWebSocketServerPort = 9002; constexpr uint16_t kMaxMessageBufferLen = 8192; diff --git a/examples/chip-tool/commands/interactive/WebSocketServer.h b/examples/common/websocket-server/WebSocketServer.h similarity index 97% rename from examples/chip-tool/commands/interactive/WebSocketServer.h rename to examples/common/websocket-server/WebSocketServer.h index d18b68bee2b611..712cf185d8f4a0 100644 --- a/examples/chip-tool/commands/interactive/WebSocketServer.h +++ b/examples/common/websocket-server/WebSocketServer.h @@ -22,7 +22,6 @@ #include #include -#include class WebSocketServer { diff --git a/examples/chip-tool/commands/interactive/WebSocketServerDelegate.h b/examples/common/websocket-server/WebSocketServerDelegate.h similarity index 100% rename from examples/chip-tool/commands/interactive/WebSocketServerDelegate.h rename to examples/common/websocket-server/WebSocketServerDelegate.h