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
c807fc98
Commit
c807fc98
authored
Jan 06, 2021
by
Pavel Vainerman
Committed by
Pavel Vainerman
Jan 07, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[http-api]: some refactoring, parameters get/set, update docs
parent
952e79a4
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
130 additions
and
28 deletions
+130
-28
admin.cc
Utilities/Admin/admin.cc
+1
-0
ctl-cpp-common.xsl
Utilities/codegen/ctl-cpp-common.xsl
+53
-2
uniset-codegen.dox
docs/DocPages/uniset-codegen.dox
+10
-0
UObject_SK.h
extensions/include/UObject_SK.h
+2
-2
UObject_SK.cc
extensions/lib/UObject_SK.cc
+2
-2
UniSetActivator.h
include/UniSetActivator.h
+1
-1
UniSetObject.h
include/UniSetObject.h
+6
-4
UniSetActivator.cc
src/Core/UniSetActivator.cc
+2
-2
UniSetObject.cc
src/Core/UniSetObject.cc
+53
-15
No files found.
Utilities/Admin/admin.cc
View file @
c807fc98
...
...
@@ -1208,6 +1208,7 @@ int apiRequest( const string& args, UInterface& ui, const string& query )
#else
q
=
"/api/v01"
;
#endif
if
(
query
[
0
]
!=
'/'
)
q
+=
"/"
;
...
...
Utilities/codegen/ctl-cpp-common.xsl
View file @
c807fc98
...
...
@@ -287,7 +287,8 @@
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;
virtual Poco::JSON::Object::Ptr request_params_set( const std::string
&
req, const Poco::URI::QueryParameters
&
p ) override;
virtual Poco::JSON::Object::Ptr request_params_get( const std::string
&
req, const Poco::URI::QueryParameters
&
p ) override;
#endif
</xsl:if>
// Выполнение очередного шага программы
...
...
@@ -738,7 +739,7 @@ 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
<xsl:value-of
select=
"$CLASSNAME"
/>
_SK::request_
params
_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");
...
...
@@ -798,6 +799,56 @@ Poco::JSON::Object::Ptr <xsl:value-of select="$CLASSNAME"/>_SK::request_conf_set
jret->set("Result", (jupdated->size() > 0 ? "OK" : "FAIL") );
return jret;
}
// -----------------------------------------------------------------------------
Poco::JSON::Object::Ptr
<xsl:value-of
select=
"$CLASSNAME"
/>
_SK::request_params_get( const std::string
&
req, const Poco::URI::QueryParameters
&
params )
{
Poco::JSON::Object::Ptr jret = new Poco::JSON::Object();
if( params.empty() )
{
jret->set("sleep_msec",sleep_msec);
jret->set("resetMsgTime",resetMsgTime);
jret->set("forceOut",forceOut);
<xsl:for-each
select=
"//variables/item"
>
<xsl:if
test=
"normalize-space(@const)=''"
>
jret->set("
<xsl:value-of
select=
"@name"
/>
",
<xsl:value-of
select=
"@name"
/>
);
</xsl:if>
</xsl:for-each>
return jret;
}
for( const auto
&
p: params )
{
if( p.first == "sleep_msec" )
{
jret->set(p.first,sleep_msec);
continue;
}
if( p.first == "resetMsgTime" )
{
jret->set(p.first,resetMsgTime);
continue;
}
if( p.first == "forceOut" )
{
jret->set(p.first,forceOut);
continue;
}
<xsl:for-each
select=
"//variables/item"
>
<xsl:if
test=
"normalize-space(@const)=''"
>
if( p.first == "
<xsl:value-of
select=
"@name"
/>
" )
{
jret->set(p.first,
<xsl:value-of
select=
"@name"
/>
);
continue;
}
</xsl:if>
</xsl:for-each>
}
return jret;
}
#endif
</xsl:if>
// -----------------------------------------------------------------------------
...
...
docs/DocPages/uniset-codegen.dox
View file @
c807fc98
...
...
@@ -16,6 +16,7 @@
- \ref pg_Codegen_loglevel
- \ref pg_Codegen_logserver
- \ref pg_Codegen_vmonitor
- \ref pg_Codegen_rest_api
\section pg_Codegen_Common Общее описание утилиты uniset-codegen
Утилита uniset-codegen предназначена для генерирования "скелета" процесса управления на основе
...
...
@@ -507,4 +508,13 @@ Note: 'logfilter' - regexp for name of log. Default: ALL logs.
Для пользовательской информации введена виртуальная функция std::string getMonitInfo(), переопределив которую,
можно сформировать свою информацию, которую можно будет удалённо читать.
\section pg_Codegen_rest_api HTTP API
Все обращения к api должны быть по такому пути \b `/api/VERSION/command?params..`
\code
/help - Получение списка доступных команд
/ - Получение стандартной информации
/params/get?param1¶m2 - Получить текущее значение указанных параметров. Если параметры не указаны, будут возвращены все доступные.
/params/set?param1=val1¶m2=val2&.. - Установить значения для указанных параметров.
\endcode
*/
extensions/include/UObject_SK.h
View file @
c807fc98
...
...
@@ -8,7 +8,7 @@
ВСЕ ВАШИ ИЗМЕНЕНИЯ БУДУТ ПОТЕРЯНЫ.
*/
// --------------------------------------------------------------------------
// generate timestamp: 202
0-12-15
+03:00
// generate timestamp: 202
1-01-06
+03:00
// -----------------------------------------------------------------------------
#ifndef UObject_SK_H_
#define UObject_SK_H_
...
...
@@ -187,7 +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
)
override
;
virtual
Poco
::
JSON
::
Object
::
Ptr
request_
params
_set
(
const
std
::
string
&
req
,
const
Poco
::
URI
::
QueryParameters
&
p
)
override
;
#endif
// Выполнение очередного шага программы
...
...
extensions/lib/UObject_SK.cc
View file @
c807fc98
...
...
@@ -11,7 +11,7 @@
ВСЕ ВАШИ ИЗМЕНЕНИЯ БУДУТ ПОТЕРЯНЫ.
*/
// --------------------------------------------------------------------------
// generate timestamp: 202
0-12-15
+03:00
// generate timestamp: 202
1-01-06
+03:00
// -----------------------------------------------------------------------------
#include <memory>
#include <iomanip>
...
...
@@ -702,7 +702,7 @@ 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
UObject_SK
::
request_
params
_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"
);
...
...
include/UniSetActivator.h
View file @
c807fc98
...
...
@@ -52,7 +52,7 @@ namespace uniset
*
* \section act_HttpAPI REST API
* UniSetActivator выступает в роли http-сервера и реализует первичную обработку запросов
* и перенаправление их указанным объектам. Помимо этого UniSetActivator реализует обработку команд /conf/..
* и перенаправление их указанным объектам. Помимо этого UniSetActivator реализует обработку команд /conf
igure
/..
* Для запуска http-сервера необходимо в аргументах командной строки указать --activator-run-httpserver
* Помимо этого можно задать параметры --activator-httpserver-host и --activator-httpserver-port.
* --activator-httpserver-cors-allow addr - (CORS): Access-Control-Allow-Origin. Default: *.
...
...
include/UniSetObject.h
View file @
c807fc98
...
...
@@ -206,10 +206,12 @@ namespace uniset
#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
);
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
);
Poco
::
JSON
::
Object
::
Ptr
request_configure
(
const
std
::
string
&
req
,
const
Poco
::
URI
::
QueryParameters
&
p
);
Poco
::
JSON
::
Object
::
Ptr
request_configure_get
(
const
std
::
string
&
req
,
const
Poco
::
URI
::
QueryParameters
&
p
);
Poco
::
JSON
::
Object
::
Ptr
request_configure_by_name
(
const
std
::
string
&
name
,
const
std
::
string
&
props
);
Poco
::
JSON
::
Object
::
Ptr
request_params
(
const
std
::
string
&
req
,
const
Poco
::
URI
::
QueryParameters
&
p
);
virtual
Poco
::
JSON
::
Object
::
Ptr
request_params_get
(
const
std
::
string
&
req
,
const
Poco
::
URI
::
QueryParameters
&
p
);
virtual
Poco
::
JSON
::
Object
::
Ptr
request_params_set
(
const
std
::
string
&
req
,
const
Poco
::
URI
::
QueryParameters
&
p
);
#endif
private
:
...
...
src/Core/UniSetActivator.cc
View file @
c807fc98
...
...
@@ -451,8 +451,8 @@ namespace uniset
// а вдруг встретится объект с именем "conf" а мы перекрываем имя?!
// (пока считаем что такого не будет)
if
(
name
==
"conf"
)
return
request_conf
(
req
,
p
);
if
(
name
==
"conf
igure
"
)
return
request_conf
igure
(
req
,
p
);
auto
obj
=
deepFindObject
(
name
);
...
...
src/Core/UniSetObject.cc
View file @
c807fc98
...
...
@@ -433,6 +433,18 @@ namespace uniset
Poco
::
JSON
::
Object
::
Ptr
UniSetObject
::
httpHelp
(
const
Poco
::
URI
::
QueryParameters
&
p
)
{
uniset
::
json
::
help
::
object
myhelp
(
myname
);
{
uniset
::
json
::
help
::
item
cmd
(
"params/get"
,
"get value for parameter"
);
cmd
.
param
(
"param1,param2,..."
,
"paremeter names. Default: all"
);
myhelp
.
add
(
cmd
);
}
{
uniset
::
json
::
help
::
item
cmd
(
"params/set"
,
"set value for parameter"
);
cmd
.
param
(
"param1=val1,param2=val2,..."
,
"paremeters"
);
myhelp
.
add
(
cmd
);
}
return
myhelp
;
}
// ------------------------------------------------------------------------------------------
...
...
@@ -449,14 +461,25 @@ namespace uniset
return
my
;
}
// ------------------------------------------------------------------------------------------
// обработка запроса вида: /conf/xxxx
Poco
::
JSON
::
Object
::
Ptr
UniSetObject
::
request_conf
(
const
std
::
string
&
req
,
const
Poco
::
URI
::
QueryParameters
&
params
)
// обработка запроса вида: /configure/xxxx
Poco
::
JSON
::
Object
::
Ptr
UniSetObject
::
request_configure
(
const
std
::
string
&
req
,
const
Poco
::
URI
::
QueryParameters
&
params
)
{
if
(
req
==
"get"
)
return
request_configure_get
(
req
,
params
);
ostringstream
err
;
err
<<
"(request_conf): BAD REQUEST: Unknown command.."
;
throw
uniset
::
SystemError
(
err
.
str
());
}
// ------------------------------------------------------------------------------------------
// обработка запроса вида: /params/xxxx
Poco
::
JSON
::
Object
::
Ptr
UniSetObject
::
request_params
(
const
std
::
string
&
req
,
const
Poco
::
URI
::
QueryParameters
&
params
)
{
if
(
req
==
"get"
)
return
request_
conf
_get
(
req
,
params
);
return
request_
params
_get
(
req
,
params
);
if
(
req
==
"set"
)
return
request_
conf
_set
(
req
,
params
);
return
request_
params
_set
(
req
,
params
);
ostringstream
err
;
err
<<
"(request_conf): BAD REQUEST: Unknown command.."
;
...
...
@@ -464,7 +487,7 @@ namespace uniset
}
// ------------------------------------------------------------------------------------------
// обработка запроса вида: /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
UniSetObject
::
request_conf
igure
_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"
);
...
...
@@ -499,7 +522,7 @@ namespace uniset
for
(
const
auto
&
id
:
idlist
)
{
Poco
::
JSON
::
Object
::
Ptr
j
=
request_conf_name
(
id
,
props
);
Poco
::
JSON
::
Object
::
Ptr
j
=
request_conf
igure_by
_name
(
id
,
props
);
if
(
j
)
jdata
->
add
(
j
);
...
...
@@ -508,7 +531,7 @@ namespace uniset
return
json
;
}
// ------------------------------------------------------------------------------------------
Poco
::
JSON
::
Object
::
Ptr
UniSetObject
::
request_conf_name
(
const
string
&
name
,
const
std
::
string
&
props
)
Poco
::
JSON
::
Object
::
Ptr
UniSetObject
::
request_conf
igure_by
_name
(
const
string
&
name
,
const
std
::
string
&
props
)
{
Poco
::
JSON
::
Object
::
Ptr
jdata
=
new
Poco
::
JSON
::
Object
();
auto
conf
=
uniset_conf
();
...
...
@@ -558,12 +581,20 @@ 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
)
// обработка запроса вида: /conf/set?
prop1=val1&prop2=val2
Poco
::
JSON
::
Object
::
Ptr
UniSetObject
::
request_
params
_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
;
ostringstream
err
;
err
<<
"(request_params): 'set' not realized yet"
;
throw
uniset
::
SystemError
(
err
.
str
());
}
// ------------------------------------------------------------------------------------------
// обработка запроса вида: /conf/get?prop1&prop2&prop3
Poco
::
JSON
::
Object
::
Ptr
UniSetObject
::
request_params_get
(
const
std
::
string
&
req
,
const
Poco
::
URI
::
QueryParameters
&
p
)
{
ostringstream
err
;
err
<<
"(request_params): 'get' not realized yet"
;
throw
uniset
::
SystemError
(
err
.
str
());
}
// ------------------------------------------------------------------------------------------
#endif
...
...
@@ -1037,11 +1068,18 @@ namespace uniset
auto
reply
=
httpHelp
(
uri
.
getQueryParameters
());
reply
->
stringify
(
out
);
}
else
if
(
query
==
"conf"
)
else
if
(
query
==
"configure"
)
{
// запрос вида: /configure/query?params
string
qconf
=
(
seg
.
size
()
>
(
qind
+
1
)
)
?
seg
[
qind
+
1
]
:
""
;
auto
reply
=
request_configure
(
qconf
,
uri
.
getQueryParameters
());
reply
->
stringify
(
out
);
}
else
if
(
query
==
"params"
)
{
// запрос вида: /
conf
/query?params
// запрос вида: /
params
/query?params
string
qconf
=
(
seg
.
size
()
>
(
qind
+
1
)
)
?
seg
[
qind
+
1
]
:
""
;
auto
reply
=
request_
conf
(
qconf
,
uri
.
getQueryParameters
());
auto
reply
=
request_
params
(
qconf
,
uri
.
getQueryParameters
());
reply
->
stringify
(
out
);
}
else
if
(
!
query
.
empty
()
)
...
...
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