Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
uniset2
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UniSet project repositories
uniset2
Commits
b16c96bf
Commit
b16c96bf
authored
Dec 15, 2020
by
Pavel Vainerman
Committed by
Pavel Vainerman
Jan 07, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[runtime-setup]: added support update variables function in uniset-codegen
parent
5a57e992
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
155 additions
and
46 deletions
+155
-46
admin.cc
Utilities/Admin/admin.cc
+48
-30
ctl-cpp-common.xsl
Utilities/codegen/ctl-cpp-common.xsl
+61
-0
Makefile.am
Utilities/codegen/tests/Makefile.am
+2
-2
TestGen.cc
Utilities/codegen/tests/TestGen.cc
+1
-0
UObject_SK.h
extensions/include/UObject_SK.h
+2
-1
UObject_SK.cc
extensions/lib/UObject_SK.cc
+12
-1
UniSetObject.h
include/UniSetObject.h
+6
-4
UniSetObject.cc
src/Core/UniSetObject.cc
+23
-8
No files found.
Utilities/Admin/admin.cc
View file @
b16c96bf
...
...
@@ -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
;
}
// --------------------------------------------------------------------------------------
...
...
Utilities/codegen/ctl-cpp-common.xsl
View file @
b16c96bf
...
...
@@ -287,6 +287,7 @@
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 ) 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
&
req, const Poco::URI::QueryParameters
&
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
&
p: params )
{
if( p.first == "sleep_msec" )
{
int val = uni_atoi(p.second);
if( val
>
0 )
{
sleep_msec = uni_atoi(p.second);
jupdated->add(p.first);
}
continue;
}
if( p.first == "resetMsgTime" )
{
int val = uni_atoi(p.second);
if( val
>
0 )
{
resetMsgTime = uni_atoi(p.second);
jupdated->add(p.first);
}
continue;
}
if( p.first == "forceOut" )
{
int val = uni_atoi(p.second);
if( val
>
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>
// -----------------------------------------------------------------------------
...
...
Utilities/codegen/tests/Makefile.am
View file @
b16c96bf
...
...
@@ -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
...
...
Utilities/codegen/tests/TestGen.cc
View file @
b16c96bf
...
...
@@ -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
)
...
...
extensions/include/UObject_SK.h
View file @
b16c96bf
...
...
@@ -8,7 +8,7 @@
ВСЕ ВАШИ ИЗМЕНЕНИЯ БУДУТ ПОТЕРЯНЫ.
*/
// --------------------------------------------------------------------------
// generate timestamp: 20
19-02-11
+03:00
// generate timestamp: 20
20-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
// Выполнение очередного шага программы
...
...
extensions/lib/UObject_SK.cc
View file @
b16c96bf
...
...
@@ -11,7 +11,7 @@
ВСЕ ВАШИ ИЗМЕНЕНИЯ БУДУТ ПОТЕРЯНЫ.
*/
// --------------------------------------------------------------------------
// generate timestamp: 20
19-02-11
+03:00
// generate timestamp: 20
20-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
// -----------------------------------------------------------------------------
...
...
include/UniSetObject.h
View file @
b16c96bf
...
...
@@ -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
:
...
...
src/Core/UniSetObject.cc
View file @
b16c96bf
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment