Commit c7904389 authored by Pavel Vainerman's avatar Pavel Vainerman

make style

parent b0ecd945
......@@ -19,7 +19,7 @@ class TestGen:
virtual void timerInfo( const uniset::TimerMessage* tm ) override;
virtual void sysCommand( const uniset::SystemMessage* sm ) override;
virtual void sigterm( int signo ) override;
#ifndef DISABLE_REST_API
#ifndef DISABLE_REST_API
virtual void httpGetUserData( Poco::JSON::Object::Ptr& jdata ) override;
#endif
private:
......
......@@ -244,8 +244,8 @@ class IOController:
IOStateList::iterator myiofind( uniset::ObjectId id );
size_t ioCount();
// --------------------------
private:
private:
friend class NCRestorer;
friend class SMInterface;
......
......@@ -72,70 +72,70 @@
// -------------------------------------------------------------------------
namespace uniset
{
namespace UHttp
{
// текущая версия API
const std::string UHTTP_API_VERSION="v0";
namespace UHttp
{
// текущая версия API
const std::string UHTTP_API_VERSION = "v0";
/*! интерфейс для объекта выдающего json-данные */
class IHttpRequest
{
public:
IHttpRequest(){}
virtual ~IHttpRequest(){}
/*! интерфейс для объекта выдающего json-данные */
class IHttpRequest
{
public:
IHttpRequest() {}
virtual ~IHttpRequest() {}
// throw SystemError
virtual Poco::JSON::Object::Ptr httpGet( const Poco::URI::QueryParameters& p ) = 0;
virtual Poco::JSON::Object::Ptr httpHelp( const Poco::URI::QueryParameters& p ) = 0;
// throw SystemError
virtual Poco::JSON::Object::Ptr httpGet( const Poco::URI::QueryParameters& p ) = 0;
virtual Poco::JSON::Object::Ptr httpHelp( const Poco::URI::QueryParameters& p ) = 0;
// не обязательная функция.
virtual Poco::JSON::Object::Ptr httpRequest( const std::string& req, const Poco::URI::QueryParameters& p );
};
// -------------------------------------------------------------------------
/*! интерфейс для обработки запросов к объектам */
class IHttpRequestRegistry
{
public:
IHttpRequestRegistry(){}
virtual ~IHttpRequestRegistry(){}
// не обязательная функция.
virtual Poco::JSON::Object::Ptr httpRequest( const std::string& req, const Poco::URI::QueryParameters& p );
};
// -------------------------------------------------------------------------
/*! интерфейс для обработки запросов к объектам */
class IHttpRequestRegistry
{
public:
IHttpRequestRegistry() {}
virtual ~IHttpRequestRegistry() {}
// throw SystemError, NameNotFound
virtual Poco::JSON::Object::Ptr httpGetByName( const std::string& name, const Poco::URI::QueryParameters& p ) = 0;
// throw SystemError, NameNotFound
virtual Poco::JSON::Object::Ptr httpGetByName( const std::string& name, const Poco::URI::QueryParameters& p ) = 0;
// throw SystemError
virtual Poco::JSON::Array::Ptr httpGetObjectsList( const Poco::URI::QueryParameters& p ) = 0;
virtual Poco::JSON::Object::Ptr httpHelpByName( const std::string& name, const Poco::URI::QueryParameters& p ) = 0;
virtual Poco::JSON::Object::Ptr httpRequestByName( const std::string& name, const std::string& req, const Poco::URI::QueryParameters& p ) = 0;
};
// throw SystemError
virtual Poco::JSON::Array::Ptr httpGetObjectsList( const Poco::URI::QueryParameters& p ) = 0;
virtual Poco::JSON::Object::Ptr httpHelpByName( const std::string& name, const Poco::URI::QueryParameters& p ) = 0;
virtual Poco::JSON::Object::Ptr httpRequestByName( const std::string& name, const std::string& req, const Poco::URI::QueryParameters& p ) = 0;
};
// -------------------------------------------------------------------------
class UHttpRequestHandler:
public Poco::Net::HTTPRequestHandler
{
public:
UHttpRequestHandler( std::shared_ptr<IHttpRequestRegistry> _registry );
// -------------------------------------------------------------------------
class UHttpRequestHandler:
public Poco::Net::HTTPRequestHandler
{
public:
UHttpRequestHandler( std::shared_ptr<IHttpRequestRegistry> _registry );
virtual void handleRequest( Poco::Net::HTTPServerRequest &req, Poco::Net::HTTPServerResponse &resp ) override;
virtual void handleRequest( Poco::Net::HTTPServerRequest& req, Poco::Net::HTTPServerResponse& resp ) override;
private:
private:
std::shared_ptr<IHttpRequestRegistry> registry;
std::shared_ptr<DebugStream> log;
};
// -------------------------------------------------------------------------
class UHttpRequestHandlerFactory:
public Poco::Net::HTTPRequestHandlerFactory
{
public:
std::shared_ptr<IHttpRequestRegistry> registry;
std::shared_ptr<DebugStream> log;
};
// -------------------------------------------------------------------------
class UHttpRequestHandlerFactory:
public Poco::Net::HTTPRequestHandlerFactory
{
public:
UHttpRequestHandlerFactory( std::shared_ptr<IHttpRequestRegistry>& _registry );
UHttpRequestHandlerFactory( std::shared_ptr<IHttpRequestRegistry>& _registry );
virtual Poco::Net::HTTPRequestHandler* createRequestHandler( const Poco::Net::HTTPServerRequest & ) override;
virtual Poco::Net::HTTPRequestHandler* createRequestHandler( const Poco::Net::HTTPServerRequest& ) override;
private:
std::shared_ptr<IHttpRequestRegistry> registry;
};
}
private:
std::shared_ptr<IHttpRequestRegistry> registry;
};
}
// -------------------------------------------------------------------------
} // end of uniset namespace
// -------------------------------------------------------------------------
......
......@@ -39,8 +39,8 @@ void UHttpRequestHandler::handleRequest( Poco::Net::HTTPServerRequest& req, Poco
resp.setContentType("text/json");
std::ostream& out = resp.send();
Poco::JSON::Object::Ptr jdata = new Poco::JSON::Object();
jdata->set("error",resp.getReasonForStatus(resp.getStatus()));
jdata->set("ecode",resp.getStatus());
jdata->set("error", resp.getReasonForStatus(resp.getStatus()));
jdata->set("ecode", resp.getStatus());
jdata->set("message", "Unknown 'registry of objects'");
jdata->stringify(out);
out.flush();
......@@ -72,9 +72,9 @@ void UHttpRequestHandler::handleRequest( Poco::Net::HTTPServerRequest& req, Poco
// example: http://host:port/api/version/ObjectName
if( seg.size() < 3
|| seg[0] != "api"
|| seg[1] != UHTTP_API_VERSION
|| seg[2].empty() )
|| seg[0] != "api"
|| seg[1] != UHTTP_API_VERSION
|| seg[2].empty() )
{
resp.setStatus(HTTPResponse::HTTP_BAD_REQUEST);
resp.setContentType("text/json");
......@@ -100,12 +100,12 @@ void UHttpRequestHandler::handleRequest( Poco::Net::HTTPServerRequest& req, Poco
if( objectName == "help" )
{
out << "{ \"help\": ["
"{\"help\": {\"desc\": \"this help\"}},"
"{\"list\": {\"desc\": \"list of objects\"}},"
"{\"ObjectName\": {\"desc\": \"ObjectName information\"}},"
"{\"ObjectName/help\": {\"desc\": \"help for ObjectName\"}},"
"{\"apidocs\": {\"desc\": \"https://github.com/Etersoft/uniset2\"}}"
"]}";
"{\"help\": {\"desc\": \"this help\"}},"
"{\"list\": {\"desc\": \"list of objects\"}},"
"{\"ObjectName\": {\"desc\": \"ObjectName information\"}},"
"{\"ObjectName/help\": {\"desc\": \"help for ObjectName\"}},"
"{\"apidocs\": {\"desc\": \"https://github.com/Etersoft/uniset2\"}}"
"]}";
}
else if( objectName == "list" )
{
......@@ -128,10 +128,10 @@ void UHttpRequestHandler::handleRequest( Poco::Net::HTTPServerRequest& req, Poco
json->stringify(out);
}
}
// catch( Poco::JSON::JSONException jsone )
// {
// std::cout << "JSON ERROR: " << jsone.message() << std::endl;
// }
// catch( Poco::JSON::JSONException jsone )
// {
// std::cout << "JSON ERROR: " << jsone.message() << std::endl;
// }
catch( std::exception& ex )
{
ostringstream err;
......
......@@ -358,7 +358,8 @@ Poco::JSON::Object::Ptr LogServer::httpGetShortInfo()
uniset_rwmutex_rlock l(mutSList);
Poco::JSON::Array::Ptr jsess = new Poco::JSON::Array();
jdata->set("sessions",jsess);
jdata->set("sessions", jsess);
for( const auto& s : slist )
jsess->add(s->httpGetShortInfo());
}
......
......@@ -688,7 +688,7 @@ Poco::JSON::Object::Ptr LogSession::httpGetShortInfo()
}
Poco::JSON::Object::Ptr jdata = new Poco::JSON::Object();
jret->set(caddr,jdata);
jret->set(caddr, jdata);
jdata->set("client", caddr);
jdata->set("maxbufsize", maxRecordsNum);
......
......@@ -529,14 +529,16 @@ void UniSetActivator::init()
abortScript = conf->getArgParam("--uniset-abort-script", "");
#ifndef DISABLE_REST_API
if( findArgParam("--activator-run-httpserver", conf->getArgc(), conf->getArgv()) != -1 )
{
httpHost = conf->getArgParam("--activator-httpserver-host", "localhost");
ostringstream s;
s << (getId()==DefaultObjectId ? 8080 : getId() );
s << (getId() == DefaultObjectId ? 8080 : getId() );
httpPort = conf->getArgInt("--activator-httpserver-port", s.str());
ulog1 << myname << "(init): http server parameters " << httpHost << ":" << httpPort << endl;
}
#endif
orb = conf->getORB();
......@@ -668,12 +670,13 @@ void UniSetActivator::run( bool thread )
set_signals(true);
#ifndef DISABLE_REST_API
if( !httpHost.empty() )
{
try
{
auto reg = dynamic_pointer_cast<UHttp::IHttpRequestRegistry>(shared_from_this());
httpserv = make_shared<UHttp::UHttpServer>(reg,httpHost,httpPort);
httpserv = make_shared<UHttp::UHttpServer>(reg, httpHost, httpPort);
httpserv->start();
}
catch( std::exception& ex )
......@@ -681,6 +684,7 @@ void UniSetActivator::run( bool thread )
uwarn << myname << "(run): init http server error: " << ex.what() << endl;
}
}
#endif
if( thread )
......@@ -719,8 +723,10 @@ void UniSetActivator::stop()
ulogsys << myname << "(stop): discard request ok." << endl;
#ifndef DISABLE_REST_API
if( httpserv )
httpserv->stop();
#endif
}
......@@ -876,6 +882,7 @@ Poco::JSON::Object::Ptr UniSetActivator::httpGetByName( const string& name, cons
return httpGet(p);
auto obj = deepFindObject(name);
if( obj )
return obj->httpGet(p);
......@@ -894,9 +901,9 @@ Poco::JSON::Array::Ptr UniSetActivator::httpGetObjectsList( const Poco::URI::Que
//! \todo Доделать обработку параметров beg,lim на случай большого количества объектов (и частичных запросов)
size_t lim = 1000;
getAllObjectsList(vec,lim);
getAllObjectsList(vec, lim);
for( const auto& o: vec )
for( const auto& o : vec )
jdata->add(o->getName());
return jdata;
......@@ -908,6 +915,7 @@ Poco::JSON::Object::Ptr UniSetActivator::httpHelpByName( const string& name, con
return httpHelp(p);
auto obj = deepFindObject(name);
if( obj )
return obj->httpHelp(p);
......@@ -919,11 +927,12 @@ Poco::JSON::Object::Ptr UniSetActivator::httpHelpByName( const string& name, con
Poco::JSON::Object::Ptr UniSetActivator::httpRequestByName( const string& name, const std::string& req, const Poco::URI::QueryParameters& p)
{
if( name == myname )
return httpRequest(req,p);
return httpRequest(req, p);
auto obj = deepFindObject(name);
if( obj )
return obj->httpRequest(req,p);
return obj->httpRequest(req, p);
ostringstream err;
err << "Object '" << name << "' not found";
......
......@@ -386,9 +386,9 @@ void UniSetObject::push( const TransportMessage& tm )
Poco::JSON::Object::Ptr UniSetObject::httpGet( const Poco::URI::QueryParameters& p )
{
Poco::JSON::Object::Ptr jret = new Poco::JSON::Object();
Poco::JSON::Object::Ptr jdata = uniset::json::make_child(jret,myname);
Poco::JSON::Object::Ptr jdata = uniset::json::make_child(jret, myname);
jdata->set("name",myname);
jdata->set("name", myname);
jdata->set("id", getId());
jdata->set("msgCount", countMessages());
jdata->set("lostMessages", getCountOfLostMessages());
......
......@@ -410,8 +410,8 @@ void IOController::ioRegistration( std::shared_ptr<USensorInfo>& usi, bool force
try
{
ulogrep << myname
<< "(ioRegistration): регистрирую "
<< uniset_conf()->oind->getNameById(usi->si.id) << endl;
<< "(ioRegistration): регистрирую "
<< uniset_conf()->oind->getNameById(usi->si.id) << endl;
ui->registered( usi->si.id, getRef(), true );
return;
......@@ -850,17 +850,17 @@ Poco::JSON::Object::Ptr IOController::httpHelp( const Poco::URI::QueryParameters
{
// 'get'
uniset::json::help::item cmd("get value for sensor");
cmd.param("id1,name2,id3","get value for id1,name2,id3 sensors");
cmd.param("shortInfo","get short information for sensors");
cmd.param("id1,name2,id3", "get value for id1,name2,id3 sensors");
cmd.param("shortInfo", "get short information for sensors");
myhelp.add(cmd);
}
{
// 'sensors'
uniset::json::help::item cmd("et all sensors");
cmd.param("nameonly","get only name sensors");
cmd.param("offset=N","get from N record");
cmd.param("limit=M","limit of records");
cmd.param("nameonly", "get only name sensors");
cmd.param("offset=N", "get from N record");
cmd.param("limit=M", "limit of records");
myhelp.add(cmd);
}
......@@ -870,12 +870,12 @@ Poco::JSON::Object::Ptr IOController::httpHelp( const Poco::URI::QueryParameters
Poco::JSON::Object::Ptr IOController::httpRequest( const string& req, const Poco::URI::QueryParameters& p )
{
if( req == "get" )
return request_get(req,p);
return request_get(req, p);
if( req == "sensors" )
return request_sensors(req,p);
return request_sensors(req, p);
return UniSetManager::httpRequest(req,p);
return UniSetManager::httpRequest(req, p);
}
// -----------------------------------------------------------------------------
Poco::JSON::Object::Ptr IOController::request_get( const string& req, const Poco::URI::QueryParameters& p )
......@@ -889,6 +889,7 @@ Poco::JSON::Object::Ptr IOController::request_get( const string& req, const Poco
auto conf = uniset_conf();
auto slist = uniset::getSInfoList( p[0].first, conf );
if( slist.empty() )
{
ostringstream err;
......@@ -897,34 +898,36 @@ Poco::JSON::Object::Ptr IOController::request_get( const string& req, const Poco
}
bool shortInfo = false;
if( p.size() > 1 && p[1].first=="shortInfo" )
if( p.size() > 1 && p[1].first == "shortInfo" )
shortInfo = true;
// ulog1 << myname << "(GET): " << p[0].first << " size=" << slist.size() << endl;
// ulog1 << myname << "(GET): " << p[0].first << " size=" << slist.size() << endl;
// myname {
// sensors: [
// sid:
// value: long
// error: string
// ]
// }
// myname {
// sensors: [
// sid:
// value: long
// error: string
// ]
// }
Poco::JSON::Object::Ptr jdata = new Poco::JSON::Object();
Poco::JSON::Array::Ptr jsens = new Poco::JSON::Array();
jdata->set("sensors",jsens);
jdata->set("sensors", jsens);
Poco::JSON::Object::Ptr nullObject = new Poco::JSON::Object();
for( const auto& s: slist )
for( const auto& s : slist )
{
try
{
auto sinf = ioList.find(s.si.id);
if( sinf == ioList.end() )
{
string sid( std::to_string(s.si.id) );
jsens->add(json::make_object(sid, json::make_object("value",nullObject)));
jsens->add(json::make_object(sid, json::make_object("error","Sensor not found")));
jsens->add(json::make_object(sid, json::make_object("value", nullObject)));
jsens->add(json::make_object(sid, json::make_object("error", "Sensor not found")));
continue;
}
......@@ -933,18 +936,18 @@ Poco::JSON::Object::Ptr IOController::request_get( const string& req, const Poco
catch( IOController_i::NameNotFound& ex )
{
string sid( std::to_string(s.si.id) );
jsens->add(json::make_object(sid, uniset::json::make_object("value",nullObject)));
jsens->add(json::make_object(sid, uniset::json::make_object("error",string(ex.err))));
jsens->add(json::make_object(sid, uniset::json::make_object("value", nullObject)));
jsens->add(json::make_object(sid, uniset::json::make_object("error", string(ex.err))));
}
catch( std::exception& ex )
{
string sid( std::to_string(s.si.id) );
jsens->add(json::make_object(sid, uniset::json::make_object("value",nullObject)));
jsens->add(json::make_object(sid, uniset::json::make_object("error",ex.what())));
jsens->add(json::make_object(sid, uniset::json::make_object("value", nullObject)));
jsens->add(json::make_object(sid, uniset::json::make_object("error", ex.what())));
}
}
return uniset::json::make_object(myname,jdata);
return uniset::json::make_object(myname, jdata);
}
// -----------------------------------------------------------------------------
void IOController::getSensorInfo( Poco::JSON::Array::Ptr& jdata, std::shared_ptr<USensorInfo>& s, bool shortInfo )
......@@ -955,15 +958,15 @@ void IOController::getSensorInfo( Poco::JSON::Array::Ptr& jdata, std::shared_ptr
jdata->add(mydata);
std::string sid(to_string(s->si.id));
mydata->set(sid,jsens);
mydata->set(sid, jsens);
{
uniset_rwmutex_rlock lock(s->val_lock);
jsens->set("value", s->value);
jsens->set("real_value",s->real_value);
jsens->set("real_value", s->real_value);
}
jsens->set("id",sid);
jsens->set("id", sid);
jsens->set("name", ORepHelpers::getShortName(uniset_conf()->oind->getMapName(s->si.id)));
jsens->set("tv_sec", s->tv_sec);
jsens->set("tv_nsec", s->tv_nsec);
......@@ -976,12 +979,12 @@ void IOController::getSensorInfo( Poco::JSON::Array::Ptr& jdata, std::shared_ptr
jsens->set("dbignore", s->dbignore);
jsens->set("nchanges", s->nchanges);
Poco::JSON::Object::Ptr calibr = uniset::json::make_child(jsens,"calibration");
calibr->set("cmin",s->ci.minCal);
calibr->set("cmax",s->ci.maxCal);
calibr->set("rmin",s->ci.minRaw);
calibr->set("rmax",s->ci.maxRaw);
calibr->set("precision",s->ci.precision);
Poco::JSON::Object::Ptr calibr = uniset::json::make_child(jsens, "calibration");
calibr->set("cmin", s->ci.minCal);
calibr->set("cmax", s->ci.maxCal);
calibr->set("rmin", s->ci.minRaw);
calibr->set("rmax", s->ci.maxRaw);
calibr->set("precision", s->ci.precision);
// ::CORBA::Boolean undefined;
// ::CORBA::Boolean blocked;
......@@ -994,13 +997,13 @@ void IOController::getSensorInfo( Poco::JSON::Array::Ptr& jdata, std::shared_ptr
Poco::JSON::Object::Ptr IOController::request_sensors( const string& req, const Poco::URI::QueryParameters& params )
{
Poco::JSON::Object::Ptr jdata = new Poco::JSON::Object();
Poco::JSON::Array::Ptr jsens = uniset::json::make_child_array(jdata,"sensors");
Poco::JSON::Array::Ptr jsens = uniset::json::make_child_array(jdata, "sensors");
size_t num = 0;
size_t offset = 0;
size_t limit = 0;
for( const auto& p: params )
for( const auto& p : params )
{
if( p.first == "offset" )
offset = uni_atoi(p.second);
......@@ -1010,7 +1013,7 @@ Poco::JSON::Object::Ptr IOController::request_sensors( const string& req, const
size_t endnum = offset + limit;
for( auto it=myioBegin(); it!=myioEnd(); ++it,num++ )
for( auto it = myioBegin(); it != myioEnd(); ++it, num++ )
{
if( limit > 0 && num >= endnum )
break;
......@@ -1018,7 +1021,7 @@ Poco::JSON::Object::Ptr IOController::request_sensors( const string& req, const
if( offset > 0 && num < offset )
continue;
getSensorInfo(jsens, it->second,false);
getSensorInfo(jsens, it->second, false);
}
jdata->set("count", num);
......
......@@ -88,10 +88,12 @@ SimpleInfo* IONotifyController::getInfo( ::CORBA::Long userparam )
{
std::lock_guard<std::mutex> lock(lostConsumersMutex);
if( lostConsumers.size() > 0 )
{
inf << "-------------------------- lost consumers list [maxAttemtps=" << maxAttemtps << "] ------------------" << endl;
for( const auto& l: lostConsumers )
for( const auto& l : lostConsumers )
{
inf << " " << "(" << setw(6) << l.first << ")"
<< setw(35) << std::left << ORepHelpers::getShortName(oind->getMapName(l.first))
......@@ -99,6 +101,7 @@ SimpleInfo* IONotifyController::getInfo( ::CORBA::Long userparam )
<< endl;
}
}
inf << "----------------------------------------------------------------------------------" << endl;
}
......@@ -198,7 +201,7 @@ bool IONotifyController::addConsumer( ConsumerListInfo& lst, const ConsumerInfo&
{
uniset_rwmutex_wrlock l(lst.mut);
for( auto&& it : lst.clst )
for( auto && it : lst.clst )
{
if( it.id == ci.id && it.node == ci.node )
{
......@@ -209,7 +212,8 @@ bool IONotifyController::addConsumer( ConsumerListInfo& lst, const ConsumerInfo&
// выставляем флаг, что заказчик опять "на связи"
std::lock_guard<std::mutex> lock(lostConsumersMutex);
auto c = lostConsumers.find(ci.id);
if( c!= lostConsumers.end() )
if( c != lostConsumers.end() )
c->second.lost = false;
return false;
......@@ -231,7 +235,8 @@ bool IONotifyController::addConsumer( ConsumerListInfo& lst, const ConsumerInfo&
// выставляем флаг, что клиент опять "на связи"
std::lock_guard<std::mutex> lock(lostConsumersMutex);
auto c = lostConsumers.find(ci.id);
if( c!= lostConsumers.end() )
if( c != lostConsumers.end() )
c->second.lost = false;
return true;
......@@ -545,6 +550,7 @@ void IONotifyController::send( ConsumerListInfo& lst, const uniset::SensorMessag
{
std::lock_guard<std::mutex> lock(lostConsumersMutex);
auto& c = lostConsumers[li->id];
// если уже выставлен флаг что "заказчик" пропал, то не надо увеличивать "счётчик"
// видимо мы уже зафиксировали его пропажу на другом датчике...
if( !c.lost )
......@@ -1173,7 +1179,7 @@ Poco::JSON::Object::Ptr IONotifyController::httpHelp(const Poco::URI::QueryParam
{
// 'consumers'
uniset::json::help::item cmd("get consumers list");
cmd.param("sensor1,sensor2,sensor3","get consumers for sensors");
cmd.param("sensor1,sensor2,sensor3", "get consumers for sensors");
myhelp.add(cmd);
}
......@@ -1189,23 +1195,24 @@ Poco::JSON::Object::Ptr IONotifyController::httpHelp(const Poco::URI::QueryParam
Poco::JSON::Object::Ptr IONotifyController::httpRequest( const string& req, const Poco::URI::QueryParameters& p )
{
if( req == "consumers" )
return request_consumers(req,p);
return request_consumers(req, p);
if( req == "lost" )
return request_lost(req,p);
return request_lost(req, p);
return IOController::httpRequest(req,p);
return IOController::httpRequest(req, p);
}
// -----------------------------------------------------------------------------
Poco::JSON::Object::Ptr IONotifyController::request_consumers( const string& req, const Poco::URI::QueryParameters& p )
{
Poco::JSON::Object::Ptr json = new Poco::JSON::Object();
Poco::JSON::Object::Ptr mydata = uniset::json::make_child(json,myname);
Poco::JSON::Array::Ptr jdata = uniset::json::make_child_array(mydata,"consumers");
Poco::JSON::Object::Ptr mydata = uniset::json::make_child(json, myname);
Poco::JSON::Array::Ptr jdata = uniset::json::make_child_array(mydata, "consumers");
auto oind = uniset_conf()->oind;
std::list<ParamSInfo> slist;
if( p.size() > 0 )
{
if( !p[0].first.empty() )
......@@ -1224,11 +1231,12 @@ Poco::JSON::Object::Ptr IONotifyController::request_consumers( const string& req
// Проход по списку заданных..
if( !slist.empty() )
{
auto jnotfound = uniset::json::make_child_array(mydata,"notfound");
auto jnotfound = uniset::json::make_child_array(mydata, "notfound");
for( const auto& s: slist )
for( const auto& s : slist )
{
auto a = askIOList.find(s.si.id);
if( a == askIOList.end() )
{
jnotfound->add(std::to_string(s.si.id));
......@@ -1236,15 +1244,16 @@ Poco::JSON::Object::Ptr IONotifyController::request_consumers( const string& req
}
// Включаем в ответ все, даже если список заказчиков пустой
jdata->add( getConsumers(a->first,a->second,false) );
jdata->add( getConsumers(a->first, a->second, false) );
}
}
else // Проход по всему списку
{
for( auto&& a : askIOList )
for( auto && a : askIOList )
{
// добавляем только датчики с непустым списком заказчиков
auto jret = getConsumers(a.first,a.second,true);
auto jret = getConsumers(a.first, a.second, true);
if( jret )
jdata->add(jret);
}
......@@ -1264,9 +1273,9 @@ Poco::JSON::Object::Ptr IONotifyController::getConsumers( ObjectId sid, Consumer
return jret;
string strID( std::to_string(sid) );
auto jsens = uniset::json::make_child(jret,strID);
auto jsens = uniset::json::make_child(jret, strID);
jsens->set("id",strID);
jsens->set("id", strID);
jsens->set("sensor_name", ORepHelpers::getShortName(oind->getMapName(sid)));
auto jcons = uniset::json::make_child(jsens, "consumers");
......@@ -1274,7 +1283,7 @@ Poco::JSON::Object::Ptr IONotifyController::getConsumers( ObjectId sid, Consumer
for( const auto& c : ci.clst )
{
string cid( std::to_string(c.id) );
auto jconsinfo = uniset::json::make_child(jcons,cid);
auto jconsinfo = uniset::json::make_child(jcons, cid);
jconsinfo->set("id", c.id);
jconsinfo->set("name", ORepHelpers::getShortName(oind->getMapName(c.id)));
jconsinfo->set("lostEvents", c.lostEvents);
......@@ -1289,14 +1298,14 @@ Poco::JSON::Object::Ptr IONotifyController::request_lost( const string& req, con
{
Poco::JSON::Object::Ptr json = new Poco::JSON::Object();
Poco::JSON::Object::Ptr mydata = uniset::json::make_child(json,myname);
Poco::JSON::Array::Ptr jdata = uniset::json::make_child_array(mydata,"lost consumers");
Poco::JSON::Object::Ptr mydata = uniset::json::make_child(json, myname);
Poco::JSON::Array::Ptr jdata = uniset::json::make_child_array(mydata, "lost consumers");
auto oind = uniset_conf()->oind;
std::lock_guard<std::mutex> lock(lostConsumersMutex);
for( const auto& c: lostConsumers )
for( const auto& c : lostConsumers )
{
Poco::JSON::Object::Ptr jcons = new Poco::JSON::Object();
jcons->set("id", c.first);
......
......@@ -9,20 +9,20 @@ using namespace std;
using namespace uniset;
// --------------------------------------------------------------------------
class UTestSupplier:
public UHttp::IHttpRequest
public UHttp::IHttpRequest
{
public:
UTestSupplier(){}
virtual ~UTestSupplier(){}
UTestSupplier() {}
virtual ~UTestSupplier() {}
virtual Poco::JSON::Object::Ptr httpGet( const Poco::URI::QueryParameters& params ) override
{
Poco::JSON::Object::Ptr j = new Poco::JSON::Object();
for( const auto& p: params )
j->set(p.first,p.second);
for( const auto& p : params )
j->set(p.first, p.second);
j->set("test",42);
j->set("test", 42);
return j;
}
......@@ -31,18 +31,18 @@ class UTestSupplier:
uniset::json::help::object myhelp("test");
uniset::json::help::item cmd1("description for cmd1");
cmd1.param("p1","description of p1");
cmd1.param("p2","description of p1");
cmd1.param("p3","description of p1");
cmd1.param("p1", "description of p1");
cmd1.param("p2", "description of p1");
cmd1.param("p3", "description of p1");
myhelp.add(cmd1);
uniset::json::help::item cmd2("description for cmd2");
cmd2.param("p1","description of p1");
cmd2.param("p2","description of p1");
cmd2.param("p3","description of p1");
cmd2.param("p1", "description of p1");
cmd2.param("p2", "description of p1");
cmd2.param("p3", "description of p1");
myhelp.add(cmd2);
cmd1.param("p4","description of p4");
cmd1.param("p4", "description of p4");
myhelp.add(cmd1);
return myhelp;
......@@ -51,23 +51,23 @@ class UTestSupplier:
virtual Poco::JSON::Object::Ptr httpRequest( const std::string& req, const Poco::URI::QueryParameters& p ) override
{
Poco::JSON::Object::Ptr j = new Poco::JSON::Object();
j->set(req,"OK");
j->set(req, "OK");
return j;
}
};
// --------------------------------------------------------------------------
class UTestRequestRegistry:
public UHttp::IHttpRequestRegistry
public UHttp::IHttpRequestRegistry
{
public:
UTestRequestRegistry(){}
virtual ~UTestRequestRegistry(){}
UTestRequestRegistry() {}
virtual ~UTestRequestRegistry() {}
virtual Poco::JSON::Object::Ptr httpGetByName( const std::string& name, const Poco::URI::QueryParameters& p ) override
{
Poco::JSON::Object::Ptr j = sup.httpGet(p);
j->set("name",name);
j->set("name", name);
return j;
}
......@@ -87,7 +87,7 @@ class UTestRequestRegistry:
virtual Poco::JSON::Object::Ptr httpRequestByName( const std::string& name, const std::string& req, const Poco::URI::QueryParameters& p ) override
{
return sup.httpRequest(req,p);
return sup.httpRequest(req, p);
}
......@@ -99,79 +99,79 @@ int main(int argc, const char** argv)
{
try
{
// Poco::JSON::Object::Ptr j = new Poco::JSON::Object();
// {
// Poco::DynamicStruct data;
// Poco::Dynamic::Array objects;
// Poco::JSON::Object::Ptr j = new Poco::JSON::Object();
// {
// Poco::DynamicStruct data;
// Poco::Dynamic::Array objects;
// Poco::DynamicStruct object;
// object["id"] = 4565;
// object["size"] = 2.64;
// object["name"] = "Foo";
// object["active"] = false;
// objects.push_back(object);
// Poco::DynamicStruct object;
// object["id"] = 4565;
// object["size"] = 2.64;
// object["name"] = "Foo";
// object["active"] = false;
// objects.push_back(object);
// data["objects"] = objects;
// data["count"] = 1;
// data["objects"] = objects;
// data["count"] = 1;
// std::string s = data.toString();
// std::string s = data.toString();
// std::cout << s << std::endl;
// std::cout << s << std::endl;
// Poco::DynamicAny result_s = Poco::DynamicAny::parse(s);
// Poco::DynamicAny result_s = Poco::DynamicAny::parse(s);
// std::cout << result_s.toString() << std::endl;
// std::cout << result_s.toString() << std::endl;
// j->set("test",object);
// }
// j->set("test",object);
// }
// j->stringify(std::cout);
// cout << endl;
// j->stringify(std::cout);
// cout << endl;
// Poco::JSON::Object::Ptr j = new Poco::JSON::Object();
// j->set("test",23);
// j->set("test2","sdfsdf");
// j->set("test3",232.4);
// Poco::JSON::Object::Ptr j = new Poco::JSON::Object();
// j->set("test",23);
// j->set("test2","sdfsdf");
// j->set("test3",232.4);
// Poco::JSON::Object::Ptr j2 = new Poco::JSON::Object();
// j2->set("rr",23);
// j2->set("rr2",23);
// j2->set("rr3",23);
// Poco::JSON::Object::Ptr j2 = new Poco::JSON::Object();
// j2->set("rr",23);
// j2->set("rr2",23);
// j2->set("rr3",23);
// Poco::JSON::Array::Ptr j3 = new Poco::JSON::Array();
// j3->set(1,23);
// j3->set(2,23);
// j3->set(3,23);
// Poco::JSON::Array::Ptr j3 = new Poco::JSON::Array();
// j3->set(1,23);
// j3->set(2,23);
// j3->set(3,23);
// j->set("Object2",j2);
// j->set("Object3",j3);
// j->set("Object2",j2);
// j->set("Object3",j3);
// j->stringify(std::cerr);
// cerr << endl;
// return 0;
// j->stringify(std::cerr);
// cerr << endl;
// return 0;
// auto j = uniset::json::make_object("key","weweew");
// j->set("key2","wefwefefr");
// auto j = uniset::json::make_object("key","weweew");
// j->set("key2","wefwefefr");
// auto j2 = uniset::json::make_object("key",j);
// auto j2 = uniset::json::make_object("key",j);
//// uniset::json j;
//// j["key"] = "werwe";
//// j["key"]["key2"] = "werwe";
//// uniset::json j;
//// j["key"] = "werwe";
//// j["key"]["key2"] = "werwe";
// j2->stringify(cerr);
// j2->stringify(cerr);
// return 0;
// return 0;
auto reg = std::make_shared<UTestRequestRegistry>();
auto ireg = dynamic_pointer_cast<UHttp::IHttpRequestRegistry>(reg);
auto http = make_shared<UHttp::UHttpServer>(ireg,"localhost", 5555);
auto http = make_shared<UHttp::UHttpServer>(ireg, "localhost", 5555);
http->log()->level(Debug::ANY);
cout << "start http test server localhost:5555" << endl;
cout << "start http test server localhost:5555" << endl;
http->start();
pause();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment