本文整理汇总了C++中PluginRequest类的典型用法代码示例。如果您正苦于以下问题:C++ PluginRequest类的具体用法?C++ PluginRequest怎么用?C++ PluginRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PluginRequest类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Status
Status ConfigPlugin::call(const PluginRequest& request,
PluginResponse& response) {
if (request.count("action") == 0) {
return Status(1, "Config plugins require an action in PluginRequest");
}
if (request.at("action") == "genConfig") {
std::map<std::string, std::string> config;
auto stat = genConfig(config);
response.push_back(config);
return stat;
} else if (request.at("action") == "genPack") {
if (request.count("name") == 0 || request.count("value") == 0) {
return Status(1, "Missing name or value");
}
std::string pack;
auto stat = genPack(request.at("name"), request.at("value"), pack);
response.push_back({{request.at("name"), pack}});
return stat;
} else if (request.at("action") == "update") {
if (request.count("source") == 0 || request.count("data") == 0) {
return Status(1, "Missing source or data");
}
return Config::getInstance().update(
{{request.at("source"), request.at("data")}});
}
return Status(1, "Config plugin action unknown: " + request.at("action"));
}
示例2: call
Status DatabasePlugin::call(const PluginRequest& request,
PluginResponse& response) {
if (request.count("action") == 0) {
return Status(1, "Database plugin must include a request action");
}
// Get a domain/key, which are used for most database plugin actions.
auto domain = (request.count("domain") > 0) ? request.at("domain") : "";
auto key = (request.count("key") > 0) ? request.at("key") : "";
// Switch over the possible database plugin actions.
if (request.at("action") == "get") {
std::string value;
auto status = this->get(domain, key, value);
response.push_back({{"v", value}});
return status;
} else if (request.at("action") == "put") {
if (request.count("value") == 0) {
return Status(1, "Database plugin put action requires a value");
}
return this->put(domain, key, request.at("value"));
} else if (request.at("action") == "remove") {
return this->remove(domain, key);
} else if (request.at("action") == "scan") {
// Accumulate scanned keys into a vector.
std::vector<std::string> keys;
// Optionally allow the caller to request a max number of keys.
size_t max = 0;
if (request.count("max") > 0) {
max = std::stoul(request.at("max"));
}
auto status = this->scan(domain, keys, max);
for (const auto& key : keys) {
response.push_back({{"k", key}});
}
return status;
}
return Status(1, "Unknown database plugin action");
}
示例3: call
Status DatabasePlugin::call(const PluginRequest& request,
PluginResponse& response) {
if (request.count("action") == 0) {
return Status(1, "Database plugin must include a request action");
}
// Get a domain/key, which are used for most database plugin actions.
auto domain = (request.count("domain") > 0) ? request.at("domain") : "";
auto key = (request.count("key") > 0) ? request.at("key") : "";
// Switch over the possible database plugin actions.
if (request.at("action") == "get") {
std::string value;
auto status = this->get(domain, key, value);
response.push_back({{"v", value}});
return status;
} else if (request.at("action") == "put") {
if (request.count("value") == 0) {
return Status(1, "Database plugin put action requires a value");
}
return this->put(domain, key, request.at("value"));
} else if (request.at("action") == "remove") {
return this->remove(domain, key);
} else if (request.at("action") == "scan") {
std::vector<std::string> keys;
auto status = this->scan(domain, keys);
for (const auto& key : keys) {
response.push_back({{"k", key}});
}
return status;
}
return Status(1, "Unknown database plugin action");
}
示例4: secretPower
/// Plugin types should contain generic request/response formatters and
/// decorators.
std::string secretPower(const PluginRequest& request) const {
if (request.count("secret_power") > 0U) {
return request.at("secret_power");
}
return "no_secret_power";
}
示例5: call
Status LoggerPlugin::call(const PluginRequest& request,
PluginResponse& response) {
QueryLogItem item;
std::vector<StatusLogLine> intermediate_logs;
if (request.count("string") > 0) {
auto status = Status(0, "OK");
if (request.count("category") && request.at("category") == "event") {
// Optionally overload the logEvent method, but receive a duplicate.
// message to log string.
deserializeQueryLogItemJSON(request.at("event"), item);
status = this->logEvent(item);
}
if (status.ok()) {
return this->logString(request.at("string"));
} else {
return status;
}
} else if (request.count("snapshot") > 0) {
deserializeQueryLogItemJSON(request.at("snapshot"), item);
return this->logSnapshot(item);
} else if (request.count("health") > 0) {
deserializeQueryLogItemJSON(request.at("health"), item);
return this->logHealth(item);
} else if (request.count("init") > 0) {
deserializeIntermediateLog(request, intermediate_logs);
return this->init(request.at("init"), intermediate_logs);
} else if (request.count("status") > 0) {
deserializeIntermediateLog(request, intermediate_logs);
return this->logStatus(intermediate_logs);
} else {
return Status(1, "Unsupported call to logger plugin");
}
}
示例6: call
Status DatabasePlugin::call(const PluginRequest& request,
PluginResponse& response) {
if (request.count("action") == 0) {
return Status(1, "Database plugin must include a request action");
}
// Get a domain/key, which are used for most database plugin actions.
auto domain = (request.count("domain") > 0) ? request.at("domain") : "";
auto key = (request.count("key") > 0) ? request.at("key") : "";
if (request.at("action") == "reset") {
WriteLock lock(kDatabaseReset);
DatabasePlugin::kDBInitialized = false;
// Prevent RocksDB reentrancy by logger plugins during plugin setup.
VLOG(1) << "Resetting the database plugin: " << getName();
auto status = this->reset();
if (!status.ok()) {
// The active database could not be reset, fallback to an ephemeral.
Registry::get().setActive("database", "ephemeral");
LOG(WARNING) << "Unable to reset database plugin: " << getName();
}
DatabasePlugin::kDBInitialized = true;
return status;
}
// Switch over the possible database plugin actions.
ReadLock lock(kDatabaseReset);
if (request.at("action") == "get") {
std::string value;
auto status = this->get(domain, key, value);
response.push_back({{"v", value}});
return status;
} else if (request.at("action") == "put") {
if (request.count("value") == 0) {
return Status(1, "Database plugin put action requires a value");
}
return this->put(domain, key, request.at("value"));
} else if (request.at("action") == "remove") {
return this->remove(domain, key);
} else if (request.at("action") == "remove_range") {
auto key_high = (request.count("high") > 0) ? request.at("key_high") : "";
if (!key_high.empty() && !key.empty()) {
return this->removeRange(domain, key, key_high);
}
return Status(1, "Missing range");
} else if (request.at("action") == "scan") {
// Accumulate scanned keys into a vector.
std::vector<std::string> keys;
// Optionally allow the caller to request a max number of keys.
size_t max = 0;
if (request.count("max") > 0) {
max = std::stoul(request.at("max"));
}
auto status = this->scan(domain, keys, request.at("prefix"), max);
for (const auto& k : keys) {
response.push_back({{"k", k}});
}
return status;
}
return Status(1, "Unknown database plugin action");
}