Skip to content
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
4 changes: 2 additions & 2 deletions mgmt2/rpc/jsonrpc/JsonRPC.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ extern RPCRegistryInfo core_ats_rpc_service_provider_handle;
/// @see JsonRPCManager::add_method_handler for details
template <typename Func>
inline bool
add_method_handler(const std::string &name, Func &&call, const RPCRegistryInfo *info = nullptr)
add_method_handler(std::string_view name, Func &&call, const RPCRegistryInfo *info = nullptr)
{
return JsonRPCManager::instance().add_method_handler(name, std::forward<Func>(call), info);
}

/// @see JsonRPCManager::add_notification_handler for details
template <typename Func>
inline bool
add_notification_handler(const std::string &name, Func &&call, const RPCRegistryInfo *info = nullptr)
add_notification_handler(std::string_view name, Func &&call, const RPCRegistryInfo *info = nullptr)
{
return JsonRPCManager::instance().add_notification_handler(name, std::forward<Func>(call), info);
}
Expand Down
10 changes: 5 additions & 5 deletions mgmt2/rpc/jsonrpc/JsonRPCManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ RPCRegistryInfo core_ats_rpc_service_provider_handle = {
std::mutex g_rpcHandlingMutex;
std::condition_variable g_rpcHandlingCompletion;
ts::Rv<YAML::Node> g_rpcHandlerResponseData;
bool g_rpcHandlerProccessingCompleted{false};
bool g_rpcHandlerProcessingCompleted{false};

// jsonrpc log tag.
static constexpr auto logTag = "rpc";
Expand Down Expand Up @@ -164,7 +164,7 @@ JsonRPCManager::Dispatcher::invoke_notification_handler(JsonRPCManager::Dispatch
}

bool
JsonRPCManager::Dispatcher::remove_handler(std::string const &name)
JsonRPCManager::Dispatcher::remove_handler(std::string_view name)
{
std::lock_guard<std::mutex> lock(_mutex);
auto foundIt = std::find_if(std::begin(_handlers), std::end(_handlers), [&](auto const &p) { return p.first == name; });
Expand All @@ -177,7 +177,7 @@ JsonRPCManager::Dispatcher::remove_handler(std::string const &name)
}
// --- JsonRPCManager
bool
JsonRPCManager::remove_handler(std::string const &name)
JsonRPCManager::remove_handler(std::string_view name)
{
return _dispatcher.remove_handler(name);
}
Expand Down Expand Up @@ -289,8 +289,8 @@ JsonRPCManager::Dispatcher::InternalHandler::invoke(specs::RPCRequestInfo const
// cond var will give us green to proceed.
handler.cb(*request.id, request.params);
std::unique_lock<std::mutex> lock(g_rpcHandlingMutex);
g_rpcHandlingCompletion.wait(lock, []() { return g_rpcHandlerProccessingCompleted; });
g_rpcHandlerProccessingCompleted = false;
g_rpcHandlingCompletion.wait(lock, []() { return g_rpcHandlerProcessingCompleted; });
g_rpcHandlerProcessingCompleted = false;
// seems to be done, set the response. As the response data is a ts::Rv this will handle both,
// error and non error cases.
ret = g_rpcHandlerResponseData;
Expand Down
18 changes: 9 additions & 9 deletions mgmt2/rpc/jsonrpc/JsonRPCManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class JsonRPCManager
/// @param info RPCRegistryInfo pointer.
/// @return bool Boolean flag. true if the callback was successfully added, false otherwise
///
template <typename Func> bool add_method_handler(const std::string &name, Func &&call, const RPCRegistryInfo *info);
template <typename Func> bool add_method_handler(std::string_view name, Func &&call, const RPCRegistryInfo *info);

///
/// @brief Add new registered notification handler to the JSON RPC engine.
Expand All @@ -87,7 +87,7 @@ class JsonRPCManager
/// @param info RPCRegistryInfo pointer.
/// @return bool Boolean flag. true if the callback was successfully added, false otherwise
///
template <typename Func> bool add_notification_handler(const std::string &name, Func &&call, const RPCRegistryInfo *info);
template <typename Func> bool add_notification_handler(std::string_view name, Func &&call, const RPCRegistryInfo *info);

///
/// @brief This function handles the incoming jsonrpc request and dispatch the associated registered handler.
Expand Down Expand Up @@ -124,8 +124,8 @@ class JsonRPCManager
/// @return true If all is good.
/// @return false If we could not remove it.
///
bool remove_handler(std::string const &name);
friend bool test_remove_handler(std::string const &name);
bool remove_handler(std::string_view name);
friend bool test_remove_handler(std::string_view name);

private:
///
Expand Down Expand Up @@ -166,7 +166,7 @@ class JsonRPCManager
/// Add a method handler to the internal container
/// @return True if was successfully added, False otherwise.
template <typename FunctionWrapperType, typename Handler>
bool add_handler(std::string const &name, Handler &&handler, const RPCRegistryInfo *info);
bool add_handler(std::string_view name, Handler &&handler, const RPCRegistryInfo *info);

/// Find and call the request's callback. If any error occurs, the return type will have the specific error.
/// For notifications the @c RPCResponseInfo will not be set as part of the response. @c response_type
Expand All @@ -177,7 +177,7 @@ class JsonRPCManager
/// be false and the handler null.
InternalHandler const &find_handler(specs::RPCRequestInfo const &request, std::error_code &ec) const;
/// Removes a method handler. Unit test mainly.
bool remove_handler(std::string const &name);
bool remove_handler(std::string_view name);

// JSONRPC API - here for now.
ts::Rv<YAML::Node> show_registered_handlers(std::string_view const &, const YAML::Node &);
Expand Down Expand Up @@ -244,14 +244,14 @@ class JsonRPCManager
// ------------------------------ JsonRPCManager -------------------------------
template <typename Handler>
bool
JsonRPCManager::add_method_handler(const std::string &name, Handler &&call, const RPCRegistryInfo *info)
JsonRPCManager::add_method_handler(std::string_view name, Handler &&call, const RPCRegistryInfo *info)
{
return _dispatcher.add_handler<Dispatcher::Method, Handler>(name, std::forward<Handler>(call), info);
}

template <typename Handler>
bool
JsonRPCManager::add_notification_handler(const std::string &name, Handler &&call, const RPCRegistryInfo *info)
JsonRPCManager::add_notification_handler(std::string_view name, Handler &&call, const RPCRegistryInfo *info)
{
return _dispatcher.add_handler<Dispatcher::Notification, Handler>(name, std::forward<Handler>(call), info);
}
Expand All @@ -276,7 +276,7 @@ bool inline JsonRPCManager::Dispatcher::InternalHandler::operator!() const
// ----------------------------- Dispatcher ------------------------------------
template <typename FunctionWrapperType, typename Handler>
bool
JsonRPCManager::Dispatcher::add_handler(std::string const &name, Handler &&handler, const RPCRegistryInfo *info)
JsonRPCManager::Dispatcher::add_handler(std::string_view name, Handler &&handler, const RPCRegistryInfo *info)
{
std::lock_guard<std::mutex> lock(_mutex);
InternalHandler call{info};
Expand Down
2 changes: 1 addition & 1 deletion mgmt2/rpc/server/unit_tests/test_rpcserver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ namespace fs = ts::file;
namespace rpc
{
bool
test_remove_handler(std::string const &name)
test_remove_handler(std::string_view name)
{
return rpc::JsonRPCManager::instance().remove_handler(name);
}
Expand Down