/* * 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 client::Result &result, const vector<OlaDevice> &devices) { if (!result.Success()) { m_server.ServeError(response, result.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 universe info * @param response the HTTPResponse that is associated with the request. * @param universe the OlaUniverse object * @param error an error string. */ void OladHTTPServer::HandleUniverseInfo(HTTPResponse *response, const client::Result &result, const OlaUniverse &universe) { if (!result.Success()) { m_server.ServeError(response, result.Error()); return; } JsonObject *json = new JsonObject(); // fire off the device/port request now. the main server is running in a // separate thread. m_client.FetchDeviceInfo( ola::OLA_PLUGIN_ALL, NewSingleCallback(this, &OladHTTPServer::HandlePortsForUniverse, response, json, universe.Id())); json->Add("id", universe.Id()); json->Add("name", universe.Name()); json->Add("merge_mode", (universe.MergeMode() == OlaUniverse::MERGE_HTP ? "HTP" : "LTP")); }
/* * 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 client::Result &result, const ola::client::PluginState &state) { if (!result.Success()) { m_server.ServeError(response, result.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; }
/* * Handle the plugin list callback * @param response the HTTPResponse that is associated with the request. * @param plugins a list of plugins * @param error an error string. */ void OladHTTPServer::HandlePluginList(HTTPResponse *response, const client::Result &result, const vector<OlaPlugin> &plugins) { if (!result.Success()) { m_server.ServeError(response, result.Error()); return; } JsonObject *json = new JsonObject(); // fire off the universe request now. the main server is running in a // separate thread. m_client.FetchUniverseList( NewSingleCallback(this, &OladHTTPServer::HandleUniverseList, response, json)); JsonArray *plugins_json = json->AddArray("plugins"); vector<OlaPlugin>::const_iterator iter; for (iter = plugins.begin(); iter != plugins.end(); ++iter) { JsonObject *plugin = plugins_json->AppendObject(); plugin->Add("name", iter->Name()); plugin->Add("id", iter->Id()); } }
/* * Handle the set DMX response. * @param response the HTTPResponse that is associated with the request. * @param error an error string. */ void OladHTTPServer::HandleBoolResponse(HTTPResponse *response, const client::Result &result) { if (!result.Success()) { m_server.ServeError(response, result.Error()); return; } response->SetContentType(HTTPServer::CONTENT_TYPE_PLAIN); response->Append("ok"); response->Send(); 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::HandlePartialPluginInfo(HTTPResponse *response, int plugin_id, const client::Result &result, const string &description) { if (!result.Success()) { m_server.ServeError(response, result.Error()); return; } m_client.FetchPluginState( (ola_plugin_id) plugin_id, NewSingleCallback(this, &OladHTTPServer::HandlePluginInfo, response, description)); }
void OladHTTPServer::HandlePortsForUniverse( HTTPResponse *response, JsonObject *json, unsigned int universe_id, const client::Result &result, const vector<OlaDevice> &devices) { if (result.Success()) { vector<OlaDevice>::const_iterator iter = devices.begin(); vector<OlaInputPort>::const_iterator input_iter; vector<OlaOutputPort>::const_iterator output_iter; JsonArray *output_ports_json = json->AddArray("output_ports"); JsonArray *input_ports_json = json->AddArray("input_ports"); 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) { if (input_iter->IsActive() && input_iter->Universe() == universe_id) { JsonObject *obj = input_ports_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) { if (output_iter->IsActive() && output_iter->Universe() == universe_id) { JsonObject *obj = output_ports_json->AppendObject(); PortToJson(obj, *iter, *output_iter, true); } } } } response->SetNoCache(); response->SetContentType(HTTPServer::CONTENT_TYPE_PLAIN); response->SendJson(*json); delete json; delete response; }
/* * Handle the universe list callback * @param response the HTTPResponse that is associated with the request. * @param plugins a list of plugins * @param error an error string. */ void OladHTTPServer::HandleUniverseList(HTTPResponse *response, JsonObject *json, const client::Result &result, const vector<OlaUniverse> &universes) { if (result.Success()) { JsonArray *universe_json = json->AddArray("universes"); vector<OlaUniverse>::const_iterator iter; for (iter = universes.begin(); iter != universes.end(); ++iter) { JsonObject *universe = universe_json->AppendObject(); universe->Add("id", iter->Id()); universe->Add("input_ports", iter->InputPortCount()); universe->Add("name", iter->Name()); universe->Add("output_ports", iter->OutputPortCount()); universe->Add("rdm_devices", iter->RDMDeviceCount()); } } response->SetNoCache(); response->SetContentType(HTTPServer::CONTENT_TYPE_PLAIN); response->SendJson(*json); delete response; delete json; }
void BaseHttpAction::CallbackComplete(const client::Result &result) { RequestComplete(!result.Success()); }