/* * Handle the list of candidate ports * @param response the HTTPResponse that is associated with the request. * @param devices the possbile devices & ports * @param error an error string. */ void OladHTTPServer::HandleCandidatePorts( HTTPResponse *response, const vector<class OlaDevice> &devices, const string &error) { if (!error.empty()) { m_server.ServeError(response, error); return; } vector<OlaDevice>::const_iterator iter = devices.begin(); vector<OlaInputPort>::const_iterator input_iter; vector<OlaOutputPort>::const_iterator output_iter; JsonArray json; for (; iter != devices.end(); ++iter) { const vector<OlaInputPort> &input_ports = iter->InputPorts(); for (input_iter = input_ports.begin(); input_iter != input_ports.end(); ++input_iter) { JsonObject *obj = json.AppendObject(); PortToJson(obj, *iter, *input_iter, false); } const vector<OlaOutputPort> &output_ports = iter->OutputPorts(); for (output_iter = output_ports.begin(); output_iter != output_ports.end(); ++output_iter) { JsonObject *obj = json.AppendObject(); PortToJson(obj, *iter, *output_iter, true); } } response->SetNoCache(); response->SetContentType(HTTPServer::CONTENT_TYPE_PLAIN); response->SendJson(json); delete response; }
/* * Handle the plugin description response. * @param response the HTTPResponse that is associated with the request. * @param description the plugin description. * @param error an error string. */ void OladHTTPServer::HandlePluginInfo( HTTPResponse *response, string description, const OlaCallbackClient::PluginState &state, const string &error) { if (!error.empty()) { m_server.ServeError(response, error); return; } string escaped_description = description; Escape(&escaped_description); JsonObject json; json.Add("description", description); json.Add("name", state.name); json.Add("enabled", state.enabled); json.Add("active", state.active); json.Add("preferences_source", state.preferences_source); JsonArray *plugins = json.AddArray("conflicts_with"); vector<OlaPlugin>::const_iterator iter = state.conflicting_plugins.begin(); for (; iter != state.conflicting_plugins.end(); ++iter) { JsonObject *plugin = plugins->AppendObject(); plugin->Add("active", iter->IsActive()); plugin->Add("id", iter->Id()); plugin->Add("name", iter->Name()); } response->SetNoCache(); response->SetContentType(HTTPServer::CONTENT_TYPE_PLAIN); response->SendJson(json); delete response; }
/** * @brief Handle the plugin description response. * @param response the HTTPResponse that is associated with the request. * @param description the plugin description * @param result the result of the API call. * @param state the state of the plugin. */ void OladHTTPServer::HandlePluginInfo(HTTPResponse *response, string description, const client::Result &result, const ola::client::PluginState &state) { if (!result.Success()) { m_server.ServeError(response, result.Error()); return; } string escaped_description = description; // Replace \n before passing in so we get \\n out the far end ReplaceAll(&escaped_description, "\n", "\\n"); JsonObject json; json.Add("description", escaped_description); json.Add("name", state.name); json.Add("enabled", state.enabled); json.Add("active", state.active); json.Add("preferences_source", state.preferences_source); JsonArray *plugins = json.AddArray("conflicts_with"); vector<OlaPlugin>::const_iterator iter = state.conflicting_plugins.begin(); for (; iter != state.conflicting_plugins.end(); ++iter) { JsonObject *plugin = plugins->AppendObject(); plugin->Add("active", iter->IsActive()); plugin->Add("id", iter->Id()); plugin->Add("name", iter->Name()); } response->SetNoCache(); response->SetContentType(HTTPServer::CONTENT_TYPE_PLAIN); response->SendJson(json); delete response; }
void SelectItem::SetValue(JsonObject *item) const { JsonArray *options = item->AddArray("value"); vector<pair<string, string> >::const_iterator iter = m_values.begin(); for (; iter != m_values.end(); ++iter) { JsonObject *option = options->AppendObject(); option->Add("label", iter->first); option->Add("value", iter->second); } }
/* * Return the section as a string. */ string JsonSection::AsString() const { JsonObject json; json.Add("refresh", m_allow_refresh); json.Add("error", m_error); if (!m_save_button_text.empty()) json.Add("save_button", m_save_button_text); JsonArray *items = json.AddArray("items"); vector<const GenericItem*>::const_iterator iter = m_items.begin(); for (; iter != m_items.end(); ++iter) { JsonObject *item = items->AppendObject(); (*iter)->PopulateItem(item); } return JsonWriter::AsString(json); }