Skip to content

Commit 4d94722

Browse files
committed
[Optimize]Add macro to decide whether to implement transceiver logic
Add ENABLE_MESSAGE_IMPL to control whether to implement message transceiver, enabled by default.
1 parent 1b41673 commit 4d94722

File tree

8 files changed

+53
-27
lines changed

8 files changed

+53
-27
lines changed

DebugRouter.podspec

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,9 @@ Pod::Spec.new do |s|
4949
ssp.private_header_files = 'third_party/jsoncpp/**/*.{h}', 'third_party/jsoncpp/**/*.{inl}'
5050
end
5151
end
52+
53+
s.subspec "MessageTransceiverEnable" do |sp|
54+
sp.source_files = ''
55+
sp.pod_target_xcconfig = { "GCC_PREPROCESSOR_DEFINITIONS" => "ENABLE_MESSAGE_IMPL=1 $(inherited)" }
56+
end
5257
end

debug_router/android/debug_router/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ if ((ENABLE_16KB_ALIGN MATCHES "true"))
7171
endif()
7272
endif()
7373

74+
MESSAGE(WARNING "Received ENABLE_MESSAGE_IMPL: ${ENABLE_MESSAGE_IMPL}")
75+
if ((ENABLE_MESSAGE_IMPL MATCHES "true"))
76+
MESSAGE(WARNING "Enable message implementation")
77+
add_definitions(-DENABLE_MESSAGE_IMPL=1)
78+
endif()
79+
7480
# liblynxdebugrouter
7581
target_link_libraries(lynxdebugrouter
7682
${log-lib}

debug_router/android/debug_router/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ android {
3434
'-DANDROID_TOOLCHAIN=clang',
3535
'-DANDROID_STL=c++_static',
3636
("-DENABLE_16KB_ALIGN="+enable16KBAlign).toString(),
37+
'-DENABLE_MESSAGE_IMPL=true',
3738
'-DCMAKE_BUILD_TYPE=Release',
3839
'-DLOCAL_ARM_NEON=true',
3940
'-LH'
@@ -54,6 +55,7 @@ android {
5455
'-DBUILD_LEPUS_COMPILE=false',
5556
'-DANDROID_TOOLCHAIN=clang',
5657
("-DENABLE_16KB_ALIGN="+enable16KBAlign).toString(),
58+
'-DENABLE_MESSAGE_IMPL=true',
5759
'-DLOCAL_ARM_NEON=true',
5860
'-LH'
5961

debug_router/common/BUILD.gn

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ config("debug_router_private_config") {
3030
]
3131
}
3232

33-
config("debug_router_config") {
33+
config("debug_router_message_impl_config") {
3434
include_dirs = [ "." ]
3535

36-
defines = [ "JSON_USE_EXCEPTION=0" ]
36+
defines = [ "ENABLE_MESSAGE_IMPL=1" ]
3737
}
3838

3939
source_set("debug_router_source") {
40-
public_configs = [ ":debug_router_config" ]
40+
public_configs = [ ":debug_router_message_impl_config" ]
4141
configs += [ ":debug_router_private_config" ]
4242

4343
sources = [

debug_router/native/BUILD.gn

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
import("//build/config/harmony/config.gni")
66

77
source_set("debug_router_core") {
8-
defines = [ "JSON_USE_EXCEPTION=0" ]
8+
defines = [
9+
"JSON_USE_EXCEPTION=0",
10+
"ENABLE_MESSAGE_IMPL=1",
11+
]
912

1013
include_dirs = [
1114
".",

debug_router/native/core/debug_router_core.cc

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,16 @@ DebugRouterCore::DebugRouterCore()
126126
retry_times_(0),
127127
handler_count_(1),
128128
is_first_connect_(UNINIT) {
129-
message_transceivers_.push_back(std::make_shared<net::WebSocketClient>());
130-
message_transceivers_.push_back(std::make_shared<net::SocketServerClient>());
131-
132-
for (auto it = message_transceivers_.begin();
133-
it != message_transceivers_.end(); ++it) {
134-
(*it)->Init();
135-
(*it)->SetDelegate(this);
129+
#if ENABLE_MESSAGE_IMPL
130+
size_t transceiver_count = 0;
131+
message_transceivers_[transceiver_count++] =
132+
std::make_shared<net::WebSocketClient>();
133+
message_transceivers_[transceiver_count++] =
134+
std::make_shared<net::SocketServerClient>();
135+
#endif
136+
for (size_t i = 0; i < kTransceiverCount; ++i) {
137+
message_transceivers_[i]->Init();
138+
message_transceivers_[i]->SetDelegate(this);
136139
}
137140
std::unique_ptr<processor::MessageHandler> handler =
138141
std::make_unique<MessageHandlerCore>();
@@ -219,9 +222,8 @@ void DebugRouterCore::Connect(const std::string &url, const std::string &room,
219222
"connect. retry times: " << retry_times_.load(std::memory_order_relaxed));
220223
Disconnect();
221224
connection_state_.store(CONNECTING, std::memory_order_relaxed);
222-
for (auto it = message_transceivers_.begin();
223-
it != message_transceivers_.end(); ++it) {
224-
if ((*it)->Connect(url)) {
225+
for (size_t i = 0; i < kTransceiverCount; ++i) {
226+
if (message_transceivers_[i]->Connect(url)) {
225227
break;
226228
}
227229
}

debug_router/native/core/debug_router_core.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#ifndef DEBUGROUTER_NATIVE_CORE_DEBUG_ROUTER_CORE_H_
66
#define DEBUGROUTER_NATIVE_CORE_DEBUG_ROUTER_CORE_H_
77

8+
#include <array>
89
#include <atomic>
910
#include <cstdint>
1011
#include <memory>
@@ -42,6 +43,12 @@ typedef enum {
4243

4344
class DebugRouterSlot;
4445

46+
#if ENABLE_MESSAGE_IMPL
47+
static constexpr size_t kTransceiverCount = 2;
48+
#else
49+
static constexpr size_t kTransceiverCount = 0;
50+
#endif
51+
4552
class DebugRouterCore : public MessageTransceiverDelegate {
4653
public:
4754
friend class MessageHandlerCore;
@@ -150,7 +157,8 @@ class DebugRouterCore : public MessageTransceiverDelegate {
150157
bool is_reconnect);
151158
std::atomic<ConnectionState> connection_state_;
152159
std::shared_ptr<MessageTransceiver> current_transceiver_;
153-
std::vector<std::shared_ptr<MessageTransceiver> > message_transceivers_;
160+
std::array<std::shared_ptr<MessageTransceiver>, kTransceiverCount>
161+
message_transceivers_;
154162
int32_t max_session_id_;
155163
std::unique_ptr<report::DebugRouterNativeReport> report_;
156164
std::unique_ptr<debugrouter::processor::Processor> processor_;
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
PODS:
2-
- DebugRouter (5.0.10):
3-
- DebugRouter/Framework (= 5.0.10)
4-
- DebugRouter/Native (= 5.0.10)
5-
- DebugRouter/third_party (= 5.0.10)
6-
- DebugRouter/Framework (5.0.10):
2+
- DebugRouter/Framework (5.0.11):
73
- DebugRouter/Native
8-
- DebugRouter/Native (5.0.10):
4+
- DebugRouter/MessageTransceiverEnable (5.0.11)
5+
- DebugRouter/Native (5.0.11):
96
- DebugRouter/third_party
10-
- DebugRouter/third_party (5.0.10):
11-
- DebugRouter/third_party/jsoncpp (= 5.0.10)
12-
- DebugRouter/third_party/jsoncpp (5.0.10)
7+
- DebugRouter/third_party (5.0.11):
8+
- DebugRouter/third_party/jsoncpp (= 5.0.11)
9+
- DebugRouter/third_party/jsoncpp (5.0.11)
1310

1411
DEPENDENCIES:
15-
- DebugRouter (from `../../../`)
12+
- DebugRouter/Framework (from `../../../`)
13+
- DebugRouter/MessageTransceiverEnable (from `../../../`)
14+
- DebugRouter/Native (from `../../../`)
15+
- DebugRouter/third_party (from `../../../`)
1616

1717
EXTERNAL SOURCES:
1818
DebugRouter:
1919
:path: "../../../"
2020

2121
SPEC CHECKSUMS:
22-
DebugRouter: bd96ce2f2e3150f5c49cfbd29b80b684705fa325
22+
DebugRouter: c27fcdfee7a0a0e54a8215b1c7f262d2e78f290c
2323

24-
PODFILE CHECKSUM: 453f33108fffde859263ad6670787b0438d93813
24+
PODFILE CHECKSUM: 687a4d2578a15db938e619b1da87062723f6ab77
2525

2626
COCOAPODS: 1.10.1

0 commit comments

Comments
 (0)