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
57 changes: 29 additions & 28 deletions mgmt/rpc/jsonrpc/JsonRPCManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <mutex>
#include <condition_variable>

#include <swoc/swoc_meta.h>
#include "json/YAMLCodec.h"

namespace
Expand Down Expand Up @@ -265,33 +266,33 @@ inline ts::Rv<YAML::Node>
JsonRPCManager::Dispatcher::InternalHandler::invoke(specs::RPCRequestInfo const &request) const
{
ts::Rv<YAML::Node> ret;
std::visit(ts::meta::overloaded{[](std::monostate) -> void { /* no op */ },
[&request](Notification const &handler) -> void {
// Notification handler call. Ignore response, there is no completion cv check in here basically
// because we do not deal with any response, the callee can just re-schedule the work if
// needed. We fire and forget.
handler.cb(request.params);
},
[&ret, &request](Method const &handler) -> void {
// Regular Method Handler call, No cond variable check here, this should have not be created by
// a plugin.
ret = handler.cb(request.id, request.params);
},
[&ret, &request](PluginMethod const &handler) -> void {
// We call the method handler, we'll lock and wait till the condition_variable
// gets set on the other side. The handler may return immediately with no response being set.
// 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_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;
// clean up the shared data.
g_rpcHandlerResponseData.clear();
lock.unlock();
}},
std::visit(swoc::meta::vary{[](std::monostate) -> void { /* no op */ },
[&request](Notification const &handler) -> void {
// Notification handler call. Ignore response, there is no completion cv check in here basically
// because we do not deal with any response, the callee can just re-schedule the work if
// needed. We fire and forget.
handler.cb(request.params);
},
[&ret, &request](Method const &handler) -> void {
// Regular Method Handler call, No cond variable check here, this should have not be created by
// a plugin.
ret = handler.cb(request.id, request.params);
},
[&ret, &request](PluginMethod const &handler) -> void {
// We call the method handler, we'll lock and wait till the condition_variable
// gets set on the other side. The handler may return immediately with no response being set.
// 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_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;
// clean up the shared data.
g_rpcHandlerResponseData.clear();
lock.unlock();
}},
this->_func);
return ret;
}
Expand Down Expand Up @@ -330,7 +331,7 @@ JsonRPCManager::Dispatcher::get_service_descriptor(std::string_view const &, con
{
YAML::Node rpcService;
std::lock_guard<std::mutex> lock(_mutex);
// std::for_each(std::begin(_handlers), std::end(_handlers), [&rpcService](auto const &h) {

for (auto const &[name, handler] : _handlers) {
YAML::Node method;
method[RPC_SERVICE_NAME_KEY] = name;
Expand Down
1 change: 0 additions & 1 deletion mgmt/rpc/jsonrpc/JsonRPCManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

#include "tscore/Errata.h"
#include "tscore/Diags.h"
#include "tscpp/util/ts_meta.h"
#include "ts/apidefs.h"

#include "Defs.h"
Expand Down
4 changes: 2 additions & 2 deletions src/traffic_ctl/CtrlPrinters.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include <string_view>

#include "jsonrpc/ctrl_yaml_codecs.h"
#include "tscpp/util/ts_meta.h"
#include <swoc/swoc_meta.h>
#include <swoc/bwf_base.h>
#include <swoc/bwf_ex.h>
#include <swoc/BufferWriter.h>
Expand Down Expand Up @@ -248,7 +248,7 @@ RecordDescribePrinter::write_output(YAML::Node const &result)
std::cout << swoc::bwprint(text, "{:16s}: {}\n", "Record Type ", rec_labelof(recordInfo.rclass));
std::cout << swoc::bwprint(text, "{:16s}: {}\n", "Data Type ", recordInfo.dataType);

std::visit(ts::meta::overloaded{
std::visit(swoc::meta::vary{
[&](shared::rpc::RecordLookUpResponse::RecordParamInfo::ConfigMeta const &meta) {
std::cout << swoc::bwprint(text, "{:16s}: {}\n", "Access Control ", rec_accessof(meta.accessType));
std::cout << swoc::bwprint(text, "{:16s}: {}\n", "Update Type ", rec_updateof(meta.updateType));
Expand Down