Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

call coro_rpc function return bool failed crossplatform #608

Merged
merged 5 commits into from
Feb 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion include/ylt/util/function_name.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,32 @@
#include <string_view>

#include "magic_names.hpp"

template <size_t N>
constexpr std::string_view string_view_array_has(
const std::array<std::string_view, N>& array, std::string_view value) {
for (const auto& v : array) {
if (value.find(v) == 0)
return v;
}
return std::string_view{""};
}

namespace coro_rpc {
template <auto func>
constexpr std::string_view get_func_name() {
return std::string_view{refvalue::qualified_name_of_v<func>};
constexpr std::array func_style_array{
std::string_view{"__cdecl "}, std::string_view{"__clrcall "},
std::string_view{"__stdcall "}, std::string_view{"__fastcall "},
std::string_view{"__thiscall "}, std::string_view{"__vectorcall "}};
constexpr auto qualified_name =
std::string_view{refvalue::qualified_name_of_v<func>};
constexpr auto func_style =
string_view_array_has(func_style_array, qualified_name);
if constexpr (func_style.length() > 0) {
return std::string_view{qualified_name.data() + func_style.length(),
qualified_name.length() - func_style.length()};
}
return qualified_name;
};
} // namespace coro_rpc
2 changes: 2 additions & 0 deletions src/coro_rpc/examples/base_examples/rpc_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ std::string hello_world() {
return "hello_world";
}

bool return_bool_hello_world() { return true; }

int A_add_B(int a, int b) {
ELOGV(INFO, "call A+B");
return a + b;
Expand Down
1 change: 1 addition & 0 deletions src/coro_rpc/examples/base_examples/rpc_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <ylt/coro_rpc/coro_rpc_context.hpp>

std::string hello_world();
bool return_bool_hello_world();
int A_add_B(int a, int b);
void hello_with_delay(coro_rpc::context<std::string> conn, std::string hello);
std::string echo(std::string_view sv);
Expand Down
2 changes: 2 additions & 0 deletions src/coro_rpc/examples/base_examples/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ int main() {

coro_rpc_server server2{/*thread=*/1, /*port=*/8802};

server.register_handler<return_bool_hello_world>();

// regist normal function for rpc
server.register_handler<hello_world, A_add_B, hello_with_delay, echo,
nested_echo, coro_echo, echo_with_attachment,
Expand Down
Loading