Commit c8dde088 authored by Pavel Vainerman's avatar Pavel Vainerman

(UHttp): встроил вывод информации о входах/выходах, переменных и т.п.

в codegen, произвёл рефакторинг названий функций связанных с http API, на httpXXX(...).
parent 03ea5933
......@@ -254,6 +254,10 @@
// ------------------------------------------------------------
std::string help() noexcept;
// HTTP API
virtual nlohmann::json httpGet( const Poco::URI::QueryParameters& p ) override;
virtual nlohmann::json httpDumpIO();
</xsl:template>
<xsl:template name="COMMON-HEAD-PROTECTED">
......@@ -266,6 +270,7 @@
virtual void sigterm( int signo ) override;
virtual bool activateObject() override;
virtual std::string getMonitInfo(){ return ""; } /*!&lt; пользовательская информация выводимая в getInfo() */
virtual void httpGetUserData( nlohmann::json&amp; jdata ){} /*!&lt; для пользовательских данных в httpGet() */
// Выполнение очередного шага программы
virtual void step(){}
......@@ -531,6 +536,53 @@ UniSetTypes::SimpleInfo* <xsl:value-of select="$CLASSNAME"/>_SK::getInfo( CORBA:
return i._retn();
}
// -----------------------------------------------------------------------------
nlohmann::json <xsl:value-of select="$CLASSNAME"/>_SK::httpGet( const Poco::URI::QueryParameters&amp; params )
{
<xsl:if test="not(normalize-space($BASECLASS)='')">nlohmann::json json = <xsl:value-of select="$BASECLASS"/>::httpGet(params);</xsl:if>
<xsl:if test="normalize-space($BASECLASS)=''">nlohmann::json json = UniSetObject::httpGet(params);</xsl:if>
std::string myid(to_string(getId()));
auto&amp; jdata = json[myid];
if( logserv )
{
jdata["LogServer"] = {
{"host",logserv_host},
{"port",logserv_port},
{"state",( logserv->isRunning() ? "RUNNIG" : "FAILED" )}
};
// logserv->getShortInfo()
}
else
jdata["LogServer"] = {};
jdata["io"] = httpDumpIO();
auto timers = getTimersList();
auto&amp; jtm = jdata["Timers"];
jtm["count"] = timers.size();
for( const auto&amp; t: timers )
{
std::string tid(to_string(t.id));
auto&amp; jt = jtm[tid];
jt["id"] = t.id;
jt["name"] = getTimerName(t.id);
jt["msec"] = t.tmr.getInterval();
jt["timeleft"] = t.curTimeMS;
jt["tick"] = ( t.curTick>=0 ? t.curTick : -1 );
}
auto vlist = vmon.getList();
auto&amp; jvmon = jdata["Variables"];
for( const auto&amp; v: vlist )
jvmon[v.first] = v.second;
httpGetUserData(jdata);
return std::move(json);
}
// -----------------------------------------------------------------------------
<xsl:if test="normalize-space($TESTMODE)!=''">
bool <xsl:value-of select="$CLASSNAME"/>_SK::checkTestMode() const noexcept
{
......@@ -1281,6 +1333,38 @@ void <xsl:value-of select="$CLASSNAME"/>_SK::testMode( bool _state )
</xsl:for-each>
}
// -----------------------------------------------------------------------------
nlohmann::json <xsl:value-of select="$CLASSNAME"/>_SK::httpDumpIO()
{
nlohmann::json jdata;
auto&amp; j_in = jdata["in"];
<xsl:for-each select="//smap/item">
<xsl:sort select="@name" order="ascending" data-type="text"/>
<xsl:if test="normalize-space(@vartype)='in'">
j_in["<xsl:call-template name="setprefix"/><xsl:value-of select="@name"/>"] = {
{"id",<xsl:value-of select="@name"/>},
{"name",ORepHelpers::getShortName( uniset_conf()->oind->getMapName(<xsl:value-of select="@name"/>))},
{"value",<xsl:call-template name="setprefix"/><xsl:value-of select="@name"/>}
};
</xsl:if>
</xsl:for-each>
auto&amp; j_out = jdata["out"];
<xsl:for-each select="//smap/item">
<xsl:sort select="@name" order="ascending" data-type="text"/>
<xsl:if test="normalize-space(@vartype)='out'">
j_out["<xsl:call-template name="setprefix"/><xsl:value-of select="@name"/>"] = {
{"id",<xsl:value-of select="@name"/>},
{"name",ORepHelpers::getShortName( uniset_conf()->oind->getMapName(<xsl:value-of select="@name"/>))},
{"value",<xsl:call-template name="setprefix"/><xsl:value-of select="@name"/>}
};
</xsl:if>
</xsl:for-each>
return std::move(jdata);
}
// ----------------------------------------------------------------------------
std::string <xsl:value-of select="$CLASSNAME"/>_SK::dumpIO()
{
ostringstream s;
......@@ -1632,6 +1716,37 @@ bool <xsl:value-of select="$CLASSNAME"/>_SK::setMsg( UniSetTypes::ObjectId _code
return false;
}
// -----------------------------------------------------------------------------
nlohmann::json <xsl:value-of select="$CLASSNAME"/>_SK::httpDumpIO()
{
nlohmann::json jdata;
auto&amp; j_in = jdata["in"];
auto&amp; j_out = jdata["out"];
<xsl:for-each select="//sensors/item/consumers/consumer">
<xsl:sort select="../../@name" order="ascending" data-type="text"/>
<xsl:if test="normalize-space(../../@msg)!='1'">
<xsl:if test="normalize-space(@name)=$OID">
<xsl:if test="normalize-space(@vartype)='in'">
j_in["<xsl:call-template name="setprefix"/><xsl:value-of select="../../@name"/>"] = {
{"id",<xsl:value-of select="../../@id"/>},
{"name", "<xsl:value-of select="../../@name"/>"},
{"value",<xsl:call-template name="setprefix"/><xsl:value-of select="../../@name"/>}
};
</xsl:if>
<xsl:if test="normalize-space(@vartype)='out'">
j_out["<xsl:call-template name="setprefix"/><xsl:value-of select="../../@name"/>"] = {
{"id",<xsl:value-of select="../../@id"/>},
{"name", "<xsl:value-of select="../../@name"/>"},
{"value",<xsl:call-template name="setprefix"/><xsl:value-of select="../../@name"/>}
};
</xsl:if>
</xsl:if>
</xsl:if>
</xsl:for-each>
return std::move(jdata);
}
// -----------------------------------------------------------------------------
std::string <xsl:value-of select="$CLASSNAME"/>_SK::dumpIO()
{
ostringstream s;
......
......@@ -83,6 +83,14 @@ void TestGen::sigterm( int signo )
TestGen_SK::sigterm(signo);
}
// -----------------------------------------------------------------------------
void TestGen::httpGetUserData( nlohmann::json& jdata )
{
jdata["myMode"] = "RUNNING";
jdata["myVar"] = 42;
jdata["myFloatVar"] = 42.42;
jdata["myMessage"] = "This is text fot test httpGetUserData";
}
// -----------------------------------------------------------------------------
void TestGen::sysCommand( const UniSetTypes::SystemMessage* sm )
{
if( sm->command == SystemMessage::StartUp )
......
......@@ -19,6 +19,7 @@ class TestGen:
virtual void timerInfo( const UniSetTypes::TimerMessage* tm ) override;
virtual void sysCommand( const UniSetTypes::SystemMessage* sm ) override;
virtual void sigterm( int signo ) override;
virtual void httpGetUserData( nlohmann::json& jdata ) override;
private:
bool bool_var = { false };
......
......@@ -3,7 +3,7 @@
ulimit -Sc 1000000
uniset2-start.sh -f ./test --name TestProc --confile test.xml --ulog-add-levels system,warn,crit \
--test-sm-ready-timeout 15000 --test-run-logserver --test-logserver-host 192.192.192.192
--test-sm-ready-timeout 15000 --test-run-logserver --test-logserver-host 192.192.192.192 $*
#--test-log-add-levels any $*
#info,warn,crit,system,level9 > 1.log
......
......@@ -100,7 +100,7 @@ class IOController:
// http API
// virtual nlohmann::json getData( const Poco::URI::QueryParameters& p ) override;
virtual nlohmann::json httpHelp( const Poco::URI::QueryParameters& p ) override;
virtual nlohmann::json request( const std::string& req, const Poco::URI::QueryParameters& p ) override;
virtual nlohmann::json httpRequest( const std::string& req, const Poco::URI::QueryParameters& p ) override;
public:
......
......@@ -273,7 +273,7 @@ class IONotifyController:
// http API
virtual nlohmann::json httpHelp( const Poco::URI::QueryParameters& p ) override;
nlohmann::json request( const string& req, const Poco::URI::QueryParameters& p );
nlohmann::json httpRequest( const string& req, const Poco::URI::QueryParameters& p );
protected:
IONotifyController();
......
......@@ -59,11 +59,11 @@ namespace UniSetTypes
virtual ~IHttpRequest(){}
// throw SystemError
virtual nlohmann::json getData( const Poco::URI::QueryParameters& p ) = 0;
virtual nlohmann::json httpGet( const Poco::URI::QueryParameters& p ) = 0;
virtual nlohmann::json httpHelp( const Poco::URI::QueryParameters& p ) = 0;
// не обязательная функция.
virtual nlohmann::json request( const std::string& req, const Poco::URI::QueryParameters& p );
virtual nlohmann::json httpRequest( const std::string& req, const Poco::URI::QueryParameters& p );
};
// -------------------------------------------------------------------------
/*! интерфейс для обработки запросов к объектам */
......@@ -74,12 +74,12 @@ namespace UniSetTypes
virtual ~IHttpRequestRegistry(){}
// throw SystemError, NameNotFound
virtual nlohmann::json getDataByName( const std::string& name, const Poco::URI::QueryParameters& p ) = 0;
virtual nlohmann::json httpGetByName( const std::string& name, const Poco::URI::QueryParameters& p ) = 0;
// throw SystemError
virtual nlohmann::json getObjectsList( const Poco::URI::QueryParameters& p ) = 0;
virtual nlohmann::json helpByName( const std::string& name, const Poco::URI::QueryParameters& p ) = 0;
virtual nlohmann::json requestByName( const std::string& name, const std::string& req, const Poco::URI::QueryParameters& p ) = 0;
virtual nlohmann::json httpGetObjectsList( const Poco::URI::QueryParameters& p ) = 0;
virtual nlohmann::json httpHelpByName( const std::string& name, const Poco::URI::QueryParameters& p ) = 0;
virtual nlohmann::json httpRequestByName( const std::string& name, const std::string& req, const Poco::URI::QueryParameters& p ) = 0;
};
// -------------------------------------------------------------------------
......
......@@ -86,10 +86,10 @@ class UniSetActivator:
}
// Поддрежка REST API (IHttpRequestRegistry)
virtual nlohmann::json getDataByName( const std::string& name , const Poco::URI::QueryParameters& p ) override;
virtual nlohmann::json getObjectsList( const Poco::URI::QueryParameters& p ) override;
virtual nlohmann::json helpByName( const std::string& name, const Poco::URI::QueryParameters& p ) override;
virtual nlohmann::json requestByName( const std::string& name, const std::string& req, const Poco::URI::QueryParameters& p ) override;
virtual nlohmann::json httpGetByName( const std::string& name , const Poco::URI::QueryParameters& p ) override;
virtual nlohmann::json httpGetObjectsList( const Poco::URI::QueryParameters& p ) override;
virtual nlohmann::json httpHelpByName( const std::string& name, const Poco::URI::QueryParameters& p ) override;
virtual nlohmann::json httpRequestByName( const std::string& name, const std::string& req, const Poco::URI::QueryParameters& p ) override;
protected:
......
......@@ -102,7 +102,7 @@ class UniSetObject:
virtual void push( const UniSetTypes::TransportMessage& msg ) override;
// HTTP API
virtual nlohmann::json getData( const Poco::URI::QueryParameters& p ) override;
virtual nlohmann::json httpGet( const Poco::URI::QueryParameters& p ) override;
virtual nlohmann::json httpHelp( const Poco::URI::QueryParameters& p ) override;
// -------------- вспомогательные --------------
......
......@@ -107,22 +107,22 @@ void UHttpRequestHandler::handleRequest( Poco::Net::HTTPServerRequest& req, Poco
}
else if( objectName == "list" )
{
auto json = registry->getObjectsList(qp);
auto json = registry->httpGetObjectsList(qp);
out << json.dump();
}
else if( seg.size() == 4 && seg[3] == "help" ) // /api/version/ObjectName/help
{
auto json = registry->helpByName(objectName, qp);
auto json = registry->httpHelpByName(objectName, qp);
out << json.dump();
}
else if( seg.size() >= 4 ) // /api/version/ObjectName/xxx..
{
auto json = registry->requestByName(objectName, seg[3], qp);
auto json = registry->httpRequestByName(objectName, seg[3], qp);
out << json.dump();
}
else
{
auto json = registry->getDataByName(objectName, qp);
auto json = registry->httpGetByName(objectName, qp);
out << json.dump();
}
}
......@@ -153,7 +153,7 @@ HTTPRequestHandler* UHttpRequestHandlerFactory::createRequestHandler( const HTTP
return new UHttpRequestHandler(registry);
}
// -------------------------------------------------------------------------
nlohmann::json IHttpRequest::request( const string& req, const Poco::URI::QueryParameters& p )
nlohmann::json IHttpRequest::httpRequest( const string& req, const Poco::URI::QueryParameters& p )
{
std::ostringstream err;
err << "(IHttpRequest::Request): " << req << " not supported";
......
......@@ -861,14 +861,14 @@ UniSetActivator::TerminateEvent_Signal UniSetActivator::signal_terminate_event()
return s_term;
}
// ------------------------------------------------------------------------------------------
nlohmann::json UniSetActivator::getDataByName( const string& name, const Poco::URI::QueryParameters& p )
nlohmann::json UniSetActivator::httpGetByName( const string& name, const Poco::URI::QueryParameters& p )
{
if( name == myname )
return getData(p);
return httpGet(p);
auto obj = deepFindObject(name);
if( obj )
return obj->getData(p);
return obj->httpGet(p);
ostringstream err;
err << "Object '" << name << "' not found";
......@@ -876,7 +876,7 @@ nlohmann::json UniSetActivator::getDataByName( const string& name, const Poco::U
throw UniSetTypes::NameNotFound(err.str());
}
// ------------------------------------------------------------------------------------------
nlohmann::json UniSetActivator::getObjectsList( const Poco::URI::QueryParameters& p )
nlohmann::json UniSetActivator::httpGetObjectsList( const Poco::URI::QueryParameters& p )
{
nlohmann::json jdata;
......@@ -893,7 +893,7 @@ nlohmann::json UniSetActivator::getObjectsList( const Poco::URI::QueryParameters
return jdata;
}
// ------------------------------------------------------------------------------------------
nlohmann::json UniSetActivator::helpByName( const string& name, const Poco::URI::QueryParameters& p )
nlohmann::json UniSetActivator::httpHelpByName( const string& name, const Poco::URI::QueryParameters& p )
{
if( name == myname )
return httpHelp(p);
......@@ -907,14 +907,14 @@ nlohmann::json UniSetActivator::helpByName( const string& name, const Poco::URI:
throw UniSetTypes::NameNotFound(err.str());
}
// ------------------------------------------------------------------------------------------
nlohmann::json UniSetActivator::requestByName( const string& name, const std::string& req, const Poco::URI::QueryParameters& p)
nlohmann::json UniSetActivator::httpRequestByName( const string& name, const std::string& req, const Poco::URI::QueryParameters& p)
{
if( name == myname )
return request(req,p);
return httpRequest(req,p);
auto obj = deepFindObject(name);
if( obj )
return obj->request(req,p);
return obj->httpRequest(req,p);
ostringstream err;
err << "Object '" << name << "' not found";
......
......@@ -379,9 +379,13 @@ void UniSetObject::push( const TransportMessage& tm )
termWaiting();
}
// ------------------------------------------------------------------------------------------
nlohmann::json UniSetObject::getData( const Poco::URI::QueryParameters& p )
nlohmann::json UniSetObject::httpGet( const Poco::URI::QueryParameters& p )
{
nlohmann::json jdata;
nlohmann::json jret;
std::string myid(to_string(getId()));
auto& jdata = jret[myid];
jdata["name"] = myname;
jdata["id"] = getId();
jdata["msgCount"] = countMessages();
......@@ -390,9 +394,7 @@ nlohmann::json UniSetObject::getData( const Poco::URI::QueryParameters& p )
jdata["isActive"] = isActive();
jdata["objectType"] = getType();
nlohmann::json ret;
ret[myname] = jdata;
return ret;
return jret;
}
// ------------------------------------------------------------------------------------------
nlohmann::json UniSetObject::httpHelp( const Poco::URI::QueryParameters& p )
......
......@@ -860,7 +860,7 @@ nlohmann::json IOController::httpHelp( const Poco::URI::QueryParameters& p )
return jdata;
}
// -----------------------------------------------------------------------------
nlohmann::json IOController::request( const string& req, const Poco::URI::QueryParameters& p )
nlohmann::json IOController::httpRequest( const string& req, const Poco::URI::QueryParameters& p )
{
if( req == "get" )
return request_get(req,p);
......@@ -868,7 +868,7 @@ nlohmann::json IOController::request( const string& req, const Poco::URI::QueryP
if( req == "sensors" )
return request_sensors(req,p);
return UniSetManager::request(req,p);
return UniSetManager::httpRequest(req,p);
}
// -----------------------------------------------------------------------------
nlohmann::json IOController::request_get( const string& req, const Poco::URI::QueryParameters& p )
......
......@@ -1092,12 +1092,12 @@ nlohmann::json IONotifyController::httpHelp(const Poco::URI::QueryParameters& p)
return std::move(jdata);
}
// -----------------------------------------------------------------------------
nlohmann::json IONotifyController::request( const string& req, const Poco::URI::QueryParameters& p )
nlohmann::json IONotifyController::httpRequest( const string& req, const Poco::URI::QueryParameters& p )
{
if( req == "consumers" )
return request_consumers(req,p);
return IOController::request(req,p);
return IOController::httpRequest(req,p);
}
// -----------------------------------------------------------------------------
nlohmann::json IONotifyController::request_consumers(const string& req, const Poco::URI::QueryParameters& p)
......
......@@ -12,7 +12,7 @@ class UTestSupplier:
UTestSupplier(){}
virtual ~UTestSupplier(){}
virtual nlohmann::json getData( const Poco::URI::QueryParameters& params ) override
virtual nlohmann::json httpGet( const Poco::URI::QueryParameters& params ) override
{
nlohmann::json j;
......@@ -34,7 +34,7 @@ class UTestSupplier:
return j;
}
virtual nlohmann::json request( const std::string& req, const Poco::URI::QueryParameters& p ) override
virtual nlohmann::json httpRequest( const std::string& req, const Poco::URI::QueryParameters& p ) override
{
nlohmann::json j;
j[req] = "OK";
......@@ -50,14 +50,14 @@ class UTestRequestRegistry:
virtual ~UTestRequestRegistry(){}
virtual nlohmann::json getDataByName( const std::string& name, const Poco::URI::QueryParameters& p ) override
virtual nlohmann::json httpGetByName( const std::string& name, const Poco::URI::QueryParameters& p ) override
{
nlohmann::json j = sup.getData(p);
nlohmann::json j = sup.httpGet(p);
j["name"] = name;
return j;
}
virtual nlohmann::json getObjectsList( const Poco::URI::QueryParameters& p ) override
virtual nlohmann::json httpGetObjectsList( const Poco::URI::QueryParameters& p ) override
{
nlohmann::json j;
j.push_back("TestObject");
......@@ -66,7 +66,7 @@ class UTestRequestRegistry:
return j;
}
virtual nlohmann::json helpByName( const std::string& name, const Poco::URI::QueryParameters& p ) override
virtual nlohmann::json httpHelpByName( const std::string& name, const Poco::URI::QueryParameters& p ) override
{
nlohmann::json j;
j["TestObject"]["help"] = {
......@@ -77,7 +77,7 @@ class UTestRequestRegistry:
return j;
}
virtual nlohmann::json requestByName( const std::string& name, const std::string& req, const Poco::URI::QueryParameters& p ) override
virtual nlohmann::json httpRequestByName( const std::string& name, const std::string& req, const Poco::URI::QueryParameters& p ) override
{
nlohmann::json j;
j[name][req] = "OK";
......
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