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
8 changes: 3 additions & 5 deletions mgmt/rpc/jsonrpc/JsonRPCManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,14 @@ JsonRPCManager::Dispatcher::find_handler(specs::RPCRequestInfo const &request, s

std::lock_guard<std::mutex> lock(_mutex);

auto search = _handlers.find(request.method);
InternalHandlers::const_iterator search = _handlers.find(request.method);

if (search == std::end(_handlers)) {
// no more checks, no handler either notification or method
ec = error::RPCErrorCode::METHOD_NOT_FOUND;
return no_handler;
}

// Handler's method type should match the requested method type.
if ((request.is_method() && search->second.is_method()) || (request.is_notification() && !search->second.is_method())) {
} // Handler's method type should match the requested method type.
else if ((request.is_method() && search->second.is_method()) || (request.is_notification() && !search->second.is_method())) {
return search->second;
}

Expand Down
6 changes: 4 additions & 2 deletions mgmt/rpc/jsonrpc/JsonRPCManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ class JsonRPCManager
};

struct InternalHandler; ///< fw declaration
/// To avoid long lines.
using InternalHandlers = std::unordered_map<std::string, InternalHandler>;

public:
Dispatcher();
Expand Down Expand Up @@ -276,8 +278,8 @@ class JsonRPCManager
};
// We will keep all the handlers wrapped inside the InternalHandler class, this will help us
// to have a single container for all the types(method, notification & plugin method(cond var)).
std::unordered_map<std::string, InternalHandler> _handlers; ///< Registered handler container.
mutable std::mutex _mutex; ///< insert/find/delete mutex.
InternalHandlers _handlers; ///< Registered handler container.
mutable std::mutex _mutex; ///< insert/find/delete mutex.
};

Dispatcher _dispatcher; ///< Internal handler container and dispatcher logic object.
Expand Down