本文整理汇总了C++中plugin::SettingsRequestMessage类的典型用法代码示例。如果您正苦于以下问题:C++ SettingsRequestMessage类的具体用法?C++ SettingsRequestMessage怎么用?C++ SettingsRequestMessage使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SettingsRequestMessage类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
bool nscapi::settings_proxy::get_bool(std::string path, std::string key, bool def) {
Plugin::SettingsRequestMessage request;
nscapi::protobuf::functions::create_simple_header(request.mutable_header());
Plugin::SettingsRequestMessage::Request *payload = request.add_payload();
payload->set_plugin_id(plugin_id_);
Plugin::SettingsRequestMessage::Request::Query *item = payload->mutable_query();
item->mutable_node()->set_key(key);
item->mutable_node()->set_path(path);
item->set_type(Plugin::Common_DataType_BOOL);
item->set_recursive(false);
item->mutable_default_value()->set_bool_data(def);
std::string response_string;
core_->settings_query(request.SerializeAsString(), response_string);
Plugin::SettingsResponseMessage response;
response.ParseFromString(response_string);
if (response.payload_size() != 1 || !response.payload(0).has_query()) {
return def;
}
return response.payload(0).query().value().bool_data();
}
示例2: get_section
void settings_controller::get_section(Mongoose::Request &request, boost::smatch &what, Mongoose::StreamResponse &response) {
if (!session->is_loggedin("settings.list", request, response))
return;
if (!validate_arguments(1, what, response)) {
return;
}
std::string path = what.str(1);
Plugin::SettingsRequestMessage rm;
Plugin::SettingsRequestMessage::Request *payload = rm.add_payload();
payload->mutable_query()->mutable_node()->set_path(path);
payload->mutable_query()->set_recursive(false);
payload->set_plugin_id(plugin_id);
payload = rm.add_payload();
payload->mutable_query()->mutable_node()->set_path(path);
payload->mutable_query()->set_recursive(true);
payload->set_plugin_id(plugin_id);
std::string str_response;
core->settings_query(rm.SerializeAsString(), str_response);
Plugin::SettingsResponseMessage pb_response;
pb_response.ParseFromString(str_response);
json_spirit::Object node;
node["path"] = path;
if (pb_response.payload_size() != 2) {
response.setCode(HTTP_SERVER_ERROR);
response.append("Failed to fetch keys");
return;
}
const Plugin::SettingsResponseMessage::Response rKeys = pb_response.payload(0);
if (!rKeys.has_query()) {
response.setCode(HTTP_NOT_FOUND);
response.append("Key not found: " + path);
return;
}
json_spirit::Array keys;
BOOST_FOREACH(const std::string &s, rKeys.query().value().list_data()) {
keys.push_back(s);
}
node["keys"] = keys;
const Plugin::SettingsResponseMessage::Response rPath = pb_response.payload(1);
if (!rPath.has_query()) {
response.setCode(HTTP_NOT_FOUND);
response.append("Key not found: " + path);
return;
}
json_spirit::Array paths;
BOOST_FOREACH(const std::string &s, rPath.query().value().list_data()) {
paths.push_back(s);
}
node["paths"] = paths;
response.append(json_spirit::write(node));
}