void web_pipeline_stats(struct evhttp_request *req, void *arg) { moModule *module; cJSON *root, *data, *mod; root = cJSON_CreateObject(); cJSON_AddNumberToObject(root, "success", 1); cJSON_AddStringToObject(root, "message", "ok"); cJSON_AddItemToObject(root, "stats", data=cJSON_CreateObject()); for ( unsigned int i = 0; i < pipeline->size(); i++ ) { module = pipeline->getModule(i); cJSON_AddItemToObject(data, module->property("id").asString().c_str(), mod=cJSON_CreateObject()); cJSON_AddNumberToObject(mod, "average_fps", module->stats.average_fps); cJSON_AddNumberToObject(mod, "average_process_time", module->stats.average_process_time); cJSON_AddNumberToObject(mod, "average_wait_time", module->stats.average_wait_time); cJSON_AddNumberToObject(mod, "total_process_frame", module->stats.total_process_frame); cJSON_AddNumberToObject(mod, "total_process_time", module->stats.total_process_time); cJSON_AddNumberToObject(mod, "total_wait_time", module->stats.total_wait_time); } web_json(req, root); }
void web_factory_list(struct evhttp_request *req, void *arg) { std::vector<std::string>::iterator it; std::vector<std::string> list = moFactory::getInstance()->list(); cJSON *root, *data; root = cJSON_CreateObject(); cJSON_AddNumberToObject(root, "success", 1); cJSON_AddStringToObject(root, "message", "ok"); cJSON_AddItemToObject(root, "list", data=cJSON_CreateArray()); for ( it = list.begin(); it != list.end(); it++ ) cJSON_AddItemToArray(data, cJSON_CreateString(it->c_str())); web_json(req, root); }
void web_factory_desribe(struct evhttp_request *req, void *arg) { std::map<std::string, moProperty*>::iterator it; cJSON *root, *mod, *properties, *io, *array; moDataStream *ds; moModule *module; struct evkeyvalq headers; const char *uri; uri = evhttp_request_uri(req); evhttp_parse_query(uri, &headers); if ( evhttp_find_header(&headers, "name") == NULL ) { evhttp_clear_headers(&headers); return web_error(req, "missing name"); } module = moFactory::getInstance()->create(evhttp_find_header(&headers, "name")); if ( module == NULL ) { evhttp_clear_headers(&headers); return web_error(req, "invalid name"); } root = cJSON_CreateObject(); cJSON_AddNumberToObject(root, "success", 1); cJSON_AddStringToObject(root, "message", "ok"); cJSON_AddItemToObject(root, "describe", mod=cJSON_CreateObject()); cJSON_AddStringToObject(mod, "name", module->getName().c_str()); cJSON_AddStringToObject(mod, "description", module->getDescription().c_str()); cJSON_AddStringToObject(mod, "author", module->getAuthor().c_str()); cJSON_AddNumberToObject(mod, "running", module->isStarted() ? 1 : 0); cJSON_AddItemToObject(mod, "properties", properties=cJSON_CreateObject()); for ( it = module->getProperties().begin(); it != module->getProperties().end(); it++ ) { cJSON_AddStringToObject(properties, it->first.c_str(), it->second->asString().c_str()); } if ( module->getInputCount() ) { cJSON_AddItemToObject(mod, "inputs", array=cJSON_CreateArray()); for ( int i = 0; i < module->getInputCount(); i++ ) { ds = module->getInput(i); cJSON_AddItemToArray(array, io=cJSON_CreateObject()); cJSON_AddNumberToObject(io, "index", i); cJSON_AddStringToObject(io, "name", module->getInputInfos(i)->getName().c_str()); cJSON_AddStringToObject(io, "type", module->getInputInfos(i)->getType().c_str()); } } if ( module->getOutputCount() ) { cJSON_AddItemToObject(mod, "outputs", array=cJSON_CreateArray()); for ( int i = 0; i < module->getOutputCount(); i++ ) { ds = module->getOutput(i); cJSON_AddItemToArray(array, io=cJSON_CreateObject()); cJSON_AddNumberToObject(io, "index", i); cJSON_AddStringToObject(io, "name", module->getOutputInfos(i)->getName().c_str()); cJSON_AddStringToObject(io, "type", module->getOutputInfos(i)->getType().c_str()); } } delete module; evhttp_clear_headers(&headers); web_json(req, root); }
void web_pipeline_status(struct evhttp_request *req, void *arg) { std::map<std::string, moProperty*>::iterator it; char buffer[64]; cJSON *root, *data, *modules, *mod, *properties, *io, *observers, *array, *property; moDataStream *ds; root = cJSON_CreateObject(); cJSON_AddNumberToObject(root, "success", 1); cJSON_AddStringToObject(root, "message", "ok"); cJSON_AddItemToObject(root, "status", data=cJSON_CreateObject()); cJSON_AddNumberToObject(data, "size", pipeline->size()); cJSON_AddNumberToObject(data, "running", pipeline->isStarted() ? 1 : 0); cJSON_AddItemToObject(data, "modules", modules=cJSON_CreateObject()); for ( unsigned int i = 0; i < pipeline->size(); i++ ) { moModule *module = pipeline->getModule(i); assert( module != NULL ); cJSON_AddItemToObject(modules, module->property("id").asString().c_str(), mod=cJSON_CreateObject()); cJSON_AddStringToObject(mod, "name", module->getName().c_str()); cJSON_AddStringToObject(mod, "description", module->getDescription().c_str()); cJSON_AddStringToObject(mod, "author", module->getAuthor().c_str()); cJSON_AddNumberToObject(mod, "running", module->isStarted() ? 1 : 0); cJSON_AddItemToObject(mod, "properties", properties=cJSON_CreateObject()); for ( it = module->getProperties().begin(); it != module->getProperties().end(); it++ ) { cJSON_AddStringToObject(properties, it->first.c_str(), it->second->asString().c_str()); } cJSON_AddItemToObject(mod, "propertiesInfos", properties=cJSON_CreateObject()); for ( it = module->getProperties().begin(); it != module->getProperties().end(); it++ ) { moProperty *p = it->second; cJSON_AddItemToObject(properties, it->first.c_str(), property=cJSON_CreateObject()); cJSON_AddStringToObject(property, "type", moProperty::getPropertyTypeName(p->getType()).c_str()); cJSON_AddNumberToObject(property, "readonly", p->isReadOnly() ? 1 : 0); if ( p->haveMax() ) cJSON_AddNumberToObject(property, "max", p->getMax()); if ( p->haveMin() ) cJSON_AddNumberToObject(property, "min", p->getMin()); if ( p->haveChoices() ) cJSON_AddStringToObject(property, "choices", p->getChoices().c_str()); } if ( module->getInputCount() ) { cJSON_AddItemToObject(mod, "inputs", array=cJSON_CreateArray()); for ( int i = 0; i < module->getInputCount(); i++ ) { ds = module->getInput(i); cJSON_AddItemToArray(array, io=cJSON_CreateObject()); cJSON_AddNumberToObject(io, "index", i); cJSON_AddStringToObject(io, "name", module->getInputInfos(i)->getName().c_str()); cJSON_AddStringToObject(io, "type", module->getInputInfos(i)->getType().c_str()); cJSON_AddNumberToObject(io, "used", ds == NULL ? 0 : 1); } } if ( module->getOutputCount() ) { cJSON_AddItemToObject(mod, "outputs", array=cJSON_CreateArray()); for ( int i = 0; i < module->getOutputCount(); i++ ) { ds = module->getOutput(i); cJSON_AddItemToArray(array, io=cJSON_CreateObject()); cJSON_AddNumberToObject(io, "index", i); cJSON_AddStringToObject(io, "name", module->getOutputInfos(i)->getName().c_str()); cJSON_AddStringToObject(io, "type", module->getOutputInfos(i)->getType().c_str()); cJSON_AddNumberToObject(io, "used", ds == NULL ? 0 : 1); cJSON_AddItemToObject(io, "observers", observers=cJSON_CreateObject()); if ( ds != NULL ) { for ( unsigned int j = 0; j < ds->getObserverCount(); j++ ) { snprintf(buffer, sizeof(buffer), "%d", j); cJSON_AddStringToObject(observers, buffer, ds->getObserver(j)->property("id").asString().c_str()); } } } } } web_json(req, root); }
void web_message(struct evhttp_request *req, const char *message, int success=1) { cJSON *root = cJSON_CreateObject(); cJSON_AddNumberToObject(root, "success", success); cJSON_AddStringToObject(root, "message", message); web_json(req, root); }