From f9418a7daf6541d02628210f53fbc377f582053e Mon Sep 17 00:00:00 2001 From: Alexander Bondarev Date: Tue, 12 Dec 2023 17:43:15 +0200 Subject: [PATCH 01/15] Fix rd-cpp tests compilation. --- rd-cpp/src/rd_framework_cpp/src/test/cases/BufferTest.cpp | 8 ++++---- .../rd_framework_cpp/src/test/kotlin_interaction/test.cpp | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/rd-cpp/src/rd_framework_cpp/src/test/cases/BufferTest.cpp b/rd-cpp/src/rd_framework_cpp/src/test/cases/BufferTest.cpp index c1ea1e87e..e47536c60 100644 --- a/rd-cpp/src/rd_framework_cpp/src/test/cases/BufferTest.cpp +++ b/rd-cpp/src/rd_framework_cpp/src/test/cases/BufferTest.cpp @@ -336,15 +336,15 @@ TEST(BufferTest, duration) { Buffer buffer; - Duration duration{5}; + TimeSpan duration{5}; - buffer.write_duration(duration); + buffer.write_time_span(duration); - EXPECT_EQ(2 * sizeof(int64_t), buffer.get_position()); + EXPECT_EQ(sizeof(int64_t), buffer.get_position()); buffer.rewind(); - auto nt1 = buffer.read_duration(); + auto nt1 = buffer.read_time_span(); EXPECT_EQ(duration, nt1); diff --git a/rd-cpp/src/rd_framework_cpp/src/test/kotlin_interaction/test.cpp b/rd-cpp/src/rd_framework_cpp/src/test/kotlin_interaction/test.cpp index cddfa1e12..927d0c2c9 100644 --- a/rd-cpp/src/rd_framework_cpp/src/test/kotlin_interaction/test.cpp +++ b/rd-cpp/src/rd_framework_cpp/src/test/kotlin_interaction/test.cpp @@ -28,11 +28,11 @@ int main() Protocol clientProtocol{Identities::CLIENT, &testScheduler, std::move(wire), lifetime}; RdProperty> property_main{0}; - property_main.rdid = RdId(1); + property_main.set_id(RdId(1)); property_main.bind(lifetime, &clientProtocol, "top"); RdProperty> property_rx{0}; - property_rx.rdid = RdId(2); + property_rx.set_id(RdId(2)); property_rx.bind(lifetime, &clientProtocol, "rx"); property_rx.advise(lifetime, [](optional const& x) { std::cout << "rx value changed to " << *x << "\n"; }); From 073fbb407b6fc181e6a6e27c55e8b6dd83025abd Mon Sep 17 00:00:00 2001 From: Alexander Bondarev Date: Wed, 13 Dec 2023 11:42:54 +0200 Subject: [PATCH 02/15] Fix PumpScheduler thread-safety. --- .../src/rd_framework_cpp/src/main/wire/PumpScheduler.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/rd-cpp/src/rd_framework_cpp/src/main/wire/PumpScheduler.cpp b/rd-cpp/src/rd_framework_cpp/src/main/wire/PumpScheduler.cpp index 2d9ac1da3..9f66b0043 100644 --- a/rd-cpp/src/rd_framework_cpp/src/main/wire/PumpScheduler.cpp +++ b/rd-cpp/src/rd_framework_cpp/src/main/wire/PumpScheduler.cpp @@ -14,9 +14,13 @@ PumpScheduler::PumpScheduler() : created_thread_id(std::this_thread::get_id()) void PumpScheduler::flush() { + std::function action; assert_thread(); - auto action = std::move(messages.front()); - messages.pop(); + { + std::lock_guard guard(lock); + action = std::move(messages.front()); + messages.pop(); + } action(); } From 877e76d3fb5c109f3a92c559096d653857318f10 Mon Sep 17 00:00:00 2001 From: Alexander Bondarev Date: Wed, 13 Dec 2023 11:44:03 +0200 Subject: [PATCH 03/15] Fix testSlowpokeExtension to not fail randomly because of multi-threading. --- .../src/test/cases/RdExtTest.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/rd-cpp/src/rd_framework_cpp/src/test/cases/RdExtTest.cpp b/rd-cpp/src/rd_framework_cpp/src/test/cases/RdExtTest.cpp index ef00122b2..109fc2f7a 100644 --- a/rd-cpp/src/rd_framework_cpp/src/test/cases/RdExtTest.cpp +++ b/rd-cpp/src/rd_framework_cpp/src/test/cases/RdExtTest.cpp @@ -107,10 +107,10 @@ TEST_F(SocketWireTestBase, /*DISABLED_*/ testSlowpokeExtension) { // int64_t const serialization_hash = 1ll << 40u; - Protocol serverProtocol = server(socketLifetime); - Protocol clientProtocol = client(socketLifetime, serverProtocol); + const Protocol serverProtocol = server(socketLifetime); + const Protocol clientProtocol = client(socketLifetime, serverProtocol); - RdProperty serverProperty{0}, clientProperty{0}; + const RdProperty serverProperty{0}, clientProperty{0}; init(serverProtocol, clientProtocol, &serverProperty, &clientProperty); auto const& serverExt = serverProperty.getOrCreateExtension>("data", L"SERVER"); @@ -119,16 +119,17 @@ TEST_F(SocketWireTestBase, /*DISABLED_*/ testSlowpokeExtension) serverExt.property.set(L"UPDATE"); serverExt.property.set(L"UPGRADE"); + // wait for attempt to bind extension property in background dispatch thread + rd::util::sleep_this_thread(200); + auto const& clientExt = clientProperty.getOrCreateExtension>("data", L"CLIENT"); // clientExt.serializationHash = serialization_hash; EXPECT_EQ(clientExt.property.get(), L"CLIENT"); - // clientScheduler.pump_one_message(); //send Ready - // serverScheduler.pump_one_message(); //send Ready - // serverScheduler.pump_one_message(); //send ReceivedCounterpart - // clientScheduler.pump_one_message(); //send ReceivedCounterpart - // no need in pumping due to synchronous scheduler + // proceed on client-server ext property connection after client ext property creation + clientScheduler.pump_one_message(); + clientScheduler.pump_one_message(); // send "UPDATE" EXPECT_EQ(serverExt.property.get(), L"UPGRADE"); From d1f2152f3c22485d89a54df2f384d9eafb259c61 Mon Sep 17 00:00:00 2001 From: Alexander Bondarev Date: Wed, 13 Dec 2023 17:52:43 +0200 Subject: [PATCH 04/15] Fix rd-cpp generator to not produce circular dependencies for enums. --- .../rd/generator/nova/cpp/Cpp17Generator.kt | 29 ++++--------------- 1 file changed, 5 insertions(+), 24 deletions(-) diff --git a/rd-kt/rd-gen/src/main/kotlin/com/jetbrains/rd/generator/nova/cpp/Cpp17Generator.kt b/rd-kt/rd-gen/src/main/kotlin/com/jetbrains/rd/generator/nova/cpp/Cpp17Generator.kt index 8573d361f..78e5c5af5 100644 --- a/rd-kt/rd-gen/src/main/kotlin/com/jetbrains/rd/generator/nova/cpp/Cpp17Generator.kt +++ b/rd-kt/rd-gen/src/main/kotlin/com/jetbrains/rd/generator/nova/cpp/Cpp17Generator.kt @@ -773,22 +773,6 @@ open class Cpp17Generator( file.copyTo(this.resolve(Files.PrecompiledHeaderCmake), overwrite = true) } - - private fun PrettyPrinter.predeclare(decl: Declaration) { - surroundWithNamespaces(decl.namespace) { - when (decl) { - is Enum -> { - val predecl = decl.getSetting(IsNonScoped)?.let { - "enum ${decl.platformTypeName} : $it" - } ?: "enum class ${decl.platformTypeName}" - +("$predecl;") - } - else -> { - } - } - } - } - object EnumConstantValue : ISetting object IsNonScoped : ISetting @@ -824,10 +808,6 @@ open class Cpp17Generator( .map { it.includeQuotes() } .forEach { +it } println() - initializedEnums.forEach { enum -> - predeclare(enum) - } - println() withNamespace("rd") { initializedEnums.forEach { enum -> val map = enum.constants @@ -997,7 +977,10 @@ open class Cpp17Generator( withIncludeGuard(decl.includeGuardName()) { println() - includesDecl(instantiationsFileName) + includesDecl() + if (decl !is Enum) { + +instantiationsFileName.includeWithExtension("h") + } println() dependenciesDecl(decl) @@ -1312,7 +1295,7 @@ open class Cpp17Generator( //endregion //region TraitDecl - protected fun PrettyPrinter.includesDecl(instantiationsFileName: String) { + private fun PrettyPrinter.includesDecl() { // +"class ${decl.name};" val standardHeaders = listOf( @@ -1366,8 +1349,6 @@ open class Cpp17Generator( println() //third-party +"thirdparty".includeWithExtension("hpp") - - +instantiationsFileName.includeWithExtension("h") } private fun Declaration.parseType(type: IType, allowPredefined: Boolean): IType? { From 7d090065ee9f8d178412ef3205a43708e7b5a1a5 Mon Sep 17 00:00:00 2001 From: Alexander Bondarev Date: Wed, 13 Dec 2023 17:53:43 +0200 Subject: [PATCH 05/15] Fix ArraySerializer for non-Wrapper types. --- rd-cpp/src/rd_framework_cpp/src/main/protocol/Buffer.h | 9 ++++----- .../src/main/serialization/ArraySerializer.h | 3 --- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/rd-cpp/src/rd_framework_cpp/src/main/protocol/Buffer.h b/rd-cpp/src/rd_framework_cpp/src/main/protocol/Buffer.h index b1e65c0bd..20e81d239 100644 --- a/rd-cpp/src/rd_framework_cpp/src/main/protocol/Buffer.h +++ b/rd-cpp/src/rd_framework_cpp/src/main/protocol/Buffer.h @@ -155,9 +155,8 @@ class RD_FRAMEWORK_API Buffer final } } - template