Commit b16c96bf authored by Pavel Vainerman's avatar Pavel Vainerman Committed by Pavel Vainerman

[runtime-setup]: added support update variables function in uniset-codegen

parent 5a57e992
......@@ -1185,36 +1185,54 @@ int oinfo(const string& args, UInterface& ui, const string& userparam )
// --------------------------------------------------------------------------------------
int apiRequest( const string& args, UInterface& ui, const string& query )
{
auto conf = uniset_conf();
auto sl = uniset::getObjectsList( args, conf );
// if( verb )
// cout << "apiRequest: query: " << query << endl;
for( auto&& it : sl )
{
if( it.node == DefaultObjectId )
it.node = conf->getLocalNode();
try
{
cout << ui.apiRequest(it.id, query, it.node) << endl;
}
catch( const std::exception& ex )
{
if( !quiet )
cerr << "std::exception: " << ex.what() << endl;
}
catch(...)
{
if( !quiet )
cerr << "Unknown exception.." << endl;
}
cout << endl << endl;
}
return 0;
auto conf = uniset_conf();
auto sl = uniset::getObjectsList( args, conf );
// if( verb )
// cout << "apiRequest: query: " << query << endl;
if( query.size() < 1 )
{
if( !quiet )
cerr << "query is too small '" << query << "'" << endl;
return 1;
}
string q = query;
if( q.rfind("/api/", 0) != 0 )
{
q = "/api/" + uniset::UHttp::UHTTP_API_VERSION;
if( query[0] != '/' )
q += "/";
q += query;
}
for( auto && it : sl )
{
if( it.node == DefaultObjectId )
it.node = conf->getLocalNode();
try
{
cout << ui.apiRequest(it.id, q, it.node) << endl;
}
catch( const std::exception& ex )
{
if( !quiet )
cerr << "std::exception: " << ex.what() << endl;
}
catch(...)
{
if( !quiet )
cerr << "Unknown exception.." << endl;
}
cout << endl << endl;
}
return 0;
}
// --------------------------------------------------------------------------------------
......
......@@ -287,6 +287,7 @@
virtual void httpGetUserData( Poco::JSON::Object::Ptr&amp; jdata ){} /*!&lt; для пользовательских данных в httpGet() */
virtual Poco::JSON::Object::Ptr httpDumpIO();
virtual Poco::JSON::Object::Ptr httpRequestLog( const Poco::URI::QueryParameters&amp; p );
virtual Poco::JSON::Object::Ptr request_conf_set( const std::string&amp; req, const Poco::URI::QueryParameters&amp; p ) override;
#endif
</xsl:if>
// Выполнение очередного шага программы
......@@ -737,6 +738,66 @@ Poco::JSON::Object::Ptr <xsl:value-of select="$CLASSNAME"/>_SK::httpRequestLog(
return jret;
}
// -----------------------------------------------------------------------------
Poco::JSON::Object::Ptr <xsl:value-of select="$CLASSNAME"/>_SK::request_conf_set( const std::string&amp; req, const Poco::URI::QueryParameters&amp; params )
{
Poco::JSON::Object::Ptr jret = new Poco::JSON::Object();
Poco::JSON::Array::Ptr jupdated = uniset::json::make_child_array(jret, "updated");
for( const auto&amp; p: params )
{
if( p.first == "sleep_msec" )
{
int val = uni_atoi(p.second);
if( val &gt; 0 )
{
sleep_msec = uni_atoi(p.second);
jupdated->add(p.first);
}
continue;
}
if( p.first == "resetMsgTime" )
{
int val = uni_atoi(p.second);
if( val &gt; 0 )
{
resetMsgTime = uni_atoi(p.second);
jupdated->add(p.first);
}
continue;
}
if( p.first == "forceOut" )
{
int val = uni_atoi(p.second);
if( val &gt; 0 )
{
forceOut = uni_atoi(p.second);
jupdated->add(p.first);
}
continue;
}
<xsl:for-each select="//variables/item">
<xsl:if test="normalize-space(@const)=''">
if( p.first == "<xsl:value-of select="@name"/>" )
{
<xsl:if test="normalize-space(@type)='int'"><xsl:value-of select="@name"/> = uni_atoi(p.second);</xsl:if>
<xsl:if test="normalize-space(@type)='long'"><xsl:value-of select="@name"/> = uni_atoi(p.second);</xsl:if>
<xsl:if test="normalize-space(@type)='float'"><xsl:value-of select="@name"/> = atof(p.second.c_str());</xsl:if>
<xsl:if test="normalize-space(@type)='double'"><xsl:value-of select="@name"/> = atof(p.second.c_str());</xsl:if>
<xsl:if test="normalize-space(@type)='bool'"><xsl:value-of select="@name"/> = uni_atoi(p.second);</xsl:if>
<xsl:if test="normalize-space(@type)='str'"><xsl:value-of select="@name"/> = p.second;</xsl:if>
jupdated->add(p.first);
continue;
}
</xsl:if>
</xsl:for-each>
}
jret->set("Result", (jupdated->size() > 0 ? "OK" : "FAIL") );
return jret;
}
#endif
</xsl:if>
// -----------------------------------------------------------------------------
......
......@@ -2,11 +2,11 @@ noinst_PROGRAMS = test test2
#test2
test_LDADD = $(top_builddir)/lib/libUniSet2.la $(POCO_LIBS)
test_CXXFLAGS = -I$(top_builddir)/include $(POCO_CGLAGS)
test_CXXFLAGS = -I$(top_builddir)/include $(POCO_CGLAGS) -Wno-unused-function
test_SOURCES = TestGen_SK.cc TestGen.cc TestGen-main.cc
test2_LDADD = $(top_builddir)/lib/libUniSet2.la $(POCO_LIBS)
test2_CXXFLAGS = -I$(top_builddir)/include $(POCO_CGLAGS)
test2_CXXFLAGS = -I$(top_builddir)/include $(POCO_CGLAGS) -Wno-unused-function
test2_SOURCES = TestGenAlone_SK.cc TestGenAlone.cc TestGenAlone-main.cc
GENERATED=TestGen_SK.h TestGen_SK.cc TestGen-main.cc
......
......@@ -86,6 +86,7 @@ void TestGen::httpGetUserData( Poco::JSON::Object::Ptr& jdata )
jdata->set("myFloatVar", 42.42);
jdata->set("myMessage", "This is text fot test httpGetUserData");
}
// -----------------------------------------------------------------------------
#endif
// -----------------------------------------------------------------------------
void TestGen::sysCommand( const uniset::SystemMessage* sm )
......
......@@ -8,7 +8,7 @@
ВСЕ ВАШИ ИЗМЕНЕНИЯ БУДУТ ПОТЕРЯНЫ.
*/
// --------------------------------------------------------------------------
// generate timestamp: 2019-02-11+03:00
// generate timestamp: 2020-12-15+03:00
// -----------------------------------------------------------------------------
#ifndef UObject_SK_H_
#define UObject_SK_H_
......@@ -187,6 +187,7 @@ class UObject_SK:
virtual void httpGetUserData( Poco::JSON::Object::Ptr& jdata ) {} /*!< для пользовательских данных в httpGet() */
virtual Poco::JSON::Object::Ptr httpDumpIO();
virtual Poco::JSON::Object::Ptr httpRequestLog( const Poco::URI::QueryParameters& p );
virtual Poco::JSON::Object::Ptr request_conf_set( const std::string& req, const Poco::URI::QueryParameters& p );
#endif
// Выполнение очередного шага программы
......
......@@ -11,7 +11,7 @@
ВСЕ ВАШИ ИЗМЕНЕНИЯ БУДУТ ПОТЕРЯНЫ.
*/
// --------------------------------------------------------------------------
// generate timestamp: 2019-02-11+03:00
// generate timestamp: 2020-12-15+03:00
// -----------------------------------------------------------------------------
#include <memory>
#include <iomanip>
......@@ -702,6 +702,17 @@ Poco::JSON::Object::Ptr UObject_SK::httpRequestLog( const Poco::URI::QueryParame
return jret;
}
// -----------------------------------------------------------------------------
Poco::JSON::Object::Ptr UObject_SK::request_conf_set( const std::string& req, const Poco::URI::QueryParameters& params )
{
Poco::JSON::Object::Ptr jret = new Poco::JSON::Object();
for( const auto& p: params )
{
}
jret->set("Result","OK");
return jret;
}
#endif
// -----------------------------------------------------------------------------
......
......@@ -204,10 +204,12 @@ namespace uniset
void setActive( bool set );
#ifndef DISABLE_REST_API
// вспомогательные функции
virtual Poco::JSON::Object::Ptr httpGetMyInfo( Poco::JSON::Object::Ptr root );
Poco::JSON::Object::Ptr request_conf( const std::string& req, const Poco::URI::QueryParameters& p );
Poco::JSON::Object::Ptr request_conf_name( const std::string& name, const std::string& props );
// вспомогательные функции
virtual Poco::JSON::Object::Ptr httpGetMyInfo( Poco::JSON::Object::Ptr root );
Poco::JSON::Object::Ptr request_conf( const std::string& req, const Poco::URI::QueryParameters& p );
virtual Poco::JSON::Object::Ptr request_conf_get( const std::string& req, const Poco::URI::QueryParameters& p );
virtual Poco::JSON::Object::Ptr request_conf_set( const std::string& req, const Poco::URI::QueryParameters& p );
Poco::JSON::Object::Ptr request_conf_name( const std::string& name, const std::string& props );
#endif
private:
......
......@@ -449,20 +449,27 @@ namespace uniset
return my;
}
// ------------------------------------------------------------------------------------------
// обработка запроса вида: /conf/get?[ID|NAME]&props=testname,name] from condigure.xml
// обработка запроса вида: /conf/xxxx
Poco::JSON::Object::Ptr UniSetObject::request_conf( const std::string& req, const Poco::URI::QueryParameters& params )
{
if( req == "get" )
return request_conf_get(req, params);
if( req == "set" )
return request_conf_set(req, params);
ostringstream err;
err << "(request_conf): BAD REQUEST: Unknown command..";
throw uniset::SystemError(err.str());
}
// ------------------------------------------------------------------------------------------
// обработка запроса вида: /conf/get?[ID|NAME]&props=testname,name] from configure.xml
Poco::JSON::Object::Ptr UniSetObject::request_conf_get( const std::string& req, const Poco::URI::QueryParameters& params )
{
Poco::JSON::Object::Ptr json = new Poco::JSON::Object();
Poco::JSON::Array::Ptr jdata = uniset::json::make_child_array(json, "conf");
auto my = httpGetMyInfo(json);
if( req != "get" )
{
ostringstream err;
err << "(request_conf): Unknown command: '" << req << "'";
throw uniset::SystemError(err.str());
}
if( params.empty() )
{
ostringstream err;
......@@ -551,6 +558,14 @@ namespace uniset
return jdata;
}
// ------------------------------------------------------------------------------------------
// обработка запроса вида: /conf/set?[ID|NAME]&props=testname,name]
Poco::JSON::Object::Ptr UniSetObject::request_conf_set( const std::string& req, const Poco::URI::QueryParameters& p )
{
Poco::JSON::Object::Ptr jdata = new Poco::JSON::Object();
jdata->set("result", "OK");
return jdata;
}
// ------------------------------------------------------------------------------------------
#endif
// ------------------------------------------------------------------------------------------
ObjectPtr UniSetObject::getRef() const
......
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