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
f2bd929e
Commit
f2bd929e
authored
Nov 12, 2016
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Сделал возможность отключать REST API
(т.к. в p7 не поддерживается json.hpp из-за старого компилятора) Расставил ifdef.. для поддержки gcc-c++ < 5.0
parent
f1e26e54
Hide whitespace changes
Inline
Side-by-side
Showing
27 changed files
with
147 additions
and
23 deletions
+147
-23
ctl-cpp-common.xsl
Utilities/codegen/ctl-cpp-common.xsl
+14
-3
TestGen.cc
Utilities/codegen/tests/TestGen.cc
+2
-0
TestGen.h
Utilities/codegen/tests/TestGen.h
+2
-1
uniset2-codegen.in
Utilities/codegen/uniset2-codegen.in
+3
-0
libuniset2.spec
conf/libuniset2.spec
+2
-1
release_helper.sh
conf/release_helper.sh
+1
-1
configure.ac
configure.ac
+21
-2
UObject_SK.h
extensions/include/UObject_SK.h
+4
-1
UObject_SK.cc
extensions/lib/UObject_SK.cc
+4
-1
IOController.h
include/IOController.h
+4
-0
IONotifyController.h
include/IONotifyController.h
+4
-1
LogServer.h
include/LogServer.h
+6
-0
LogSession.h
include/LogSession.h
+7
-2
UHttpRequestHandler.h
include/UHttpRequestHandler.h
+2
-0
UHttpServer.h
include/UHttpServer.h
+2
-0
UniSetActivator.h
include/UniSetActivator.h
+8
-2
UniSetObject.h
include/UniSetObject.h
+6
-3
UHttpRequestHandler.cc
src/Communications/Http/UHttpRequestHandler.cc
+2
-0
UHttpServer.cc
src/Communications/Http/UHttpServer.cc
+2
-0
DebugStream.cc
src/Log/DebugStream.cc
+24
-3
LogServer.cc
src/Log/LogServer.cc
+2
-0
LogSession.cc
src/Log/LogSession.cc
+2
-0
UniSetActivator.cc
src/ObjectRepository/UniSetActivator.cc
+8
-1
UniSetObject.cc
src/ObjectRepository/UniSetObject.cc
+2
-0
IOController.cc
src/Processes/IOController.cc
+2
-0
IONotifyController.cc
src/Processes/IONotifyController.cc
+2
-0
uhttp-test.cc
tests/UHttpTest/uhttp-test.cc
+9
-1
No files found.
Utilities/codegen/ctl-cpp-common.xsl
View file @
f2bd929e
...
...
@@ -253,12 +253,13 @@
inline std::string dumpVars(){ return std::move(vmon.pretty_str()); }
// ------------------------------------------------------------
std::string help() noexcept;
<xsl:if
test=
"normalize-space($DISABLE_REST_API)!='1'"
>
// HTTP API
virtual nlohmann::json httpGet( const Poco::URI::QueryParameters
&
p ) override;
virtual nlohmann::json httpRequest( const std::string
&
req, const Poco::URI::QueryParameters
&
p ) override;
virtual nlohmann::json httpHelp( const Poco::URI::QueryParameters
&
p ) override;
</xsl:if>
</xsl:template>
<xsl:template
name=
"COMMON-HEAD-PROTECTED"
>
...
...
@@ -271,10 +272,11 @@
virtual void sigterm( int signo ) override;
virtual bool activateObject() override;
virtual std::string getMonitInfo(){ return ""; } /*!
<
пользовательская информация выводимая в getInfo() */
<xsl:if
test=
"normalize-space($DISABLE_REST_API)!='1'"
>
virtual void httpGetUserData( nlohmann::json
&
jdata ){} /*!
<
для пользовательских данных в httpGet() */
virtual nlohmann::json httpDumpIO();
virtual nlohmann::json httpRequestLog( const Poco::URI::QueryParameters
&
p );
</xsl:if>
// Выполнение очередного шага программы
virtual void step(){}
...
...
@@ -562,6 +564,7 @@ uniset::SimpleInfo* <xsl:value-of select="$CLASSNAME"/>_SK::getInfo( CORBA::Long
return i._retn();
}
// -----------------------------------------------------------------------------
<xsl:if
test=
"normalize-space($DISABLE_REST_API)!='1'"
>
nlohmann::json
<xsl:value-of
select=
"$CLASSNAME"
/>
_SK::httpGet( const Poco::URI::QueryParameters
&
params )
{
<xsl:if
test=
"not(normalize-space($BASECLASS)='')"
>
nlohmann::json json =
<xsl:value-of
select=
"$BASECLASS"
/>
::httpGet(params);
</xsl:if>
...
...
@@ -652,6 +655,8 @@ nlohmann::json <xsl:value-of select="$CLASSNAME"/>_SK::httpRequestLog( const Poc
return std::move(jret);
}
// -----------------------------------------------------------------------------
</xsl:if>
// -----------------------------------------------------------------------------
<xsl:if
test=
"normalize-space($TESTMODE)!=''"
>
bool
<xsl:value-of
select=
"$CLASSNAME"
/>
_SK::checkTestMode() const noexcept
{
...
...
@@ -1402,6 +1407,7 @@ void <xsl:value-of select="$CLASSNAME"/>_SK::testMode( bool _state )
</xsl:for-each>
}
// -----------------------------------------------------------------------------
<xsl:if
test=
"normalize-space($DISABLE_REST_API)!='1'"
>
nlohmann::json
<xsl:value-of
select=
"$CLASSNAME"
/>
_SK::httpDumpIO()
{
nlohmann::json jdata;
...
...
@@ -1434,6 +1440,8 @@ nlohmann::json <xsl:value-of select="$CLASSNAME"/>_SK::httpDumpIO()
return std::move(jdata);
}
// ----------------------------------------------------------------------------
</xsl:if>
std::string
<xsl:value-of
select=
"$CLASSNAME"
/>
_SK::dumpIO()
{
ostringstream s;
...
...
@@ -1785,6 +1793,7 @@ bool <xsl:value-of select="$CLASSNAME"/>_SK::setMsg( uniset::ObjectId _code, boo
return false;
}
// -----------------------------------------------------------------------------
<xsl:if
test=
"normalize-space($DISABLE_REST_API)!='1'"
>
nlohmann::json
<xsl:value-of
select=
"$CLASSNAME"
/>
_SK::httpDumpIO()
{
nlohmann::json jdata;
...
...
@@ -1816,6 +1825,8 @@ nlohmann::json <xsl:value-of select="$CLASSNAME"/>_SK::httpDumpIO()
return std::move(jdata);
}
// -----------------------------------------------------------------------------
</xsl:if>
std::string
<xsl:value-of
select=
"$CLASSNAME"
/>
_SK::dumpIO()
{
ostringstream s;
...
...
Utilities/codegen/tests/TestGen.cc
View file @
f2bd929e
...
...
@@ -83,6 +83,7 @@ void TestGen::sigterm( int signo )
TestGen_SK
::
sigterm
(
signo
);
}
// -----------------------------------------------------------------------------
#ifndef DISABLE_REST_API
void
TestGen
::
httpGetUserData
(
nlohmann
::
json
&
jdata
)
{
jdata
[
"myMode"
]
=
"RUNNING"
;
...
...
@@ -90,6 +91,7 @@ void TestGen::httpGetUserData( nlohmann::json& jdata )
jdata
[
"myFloatVar"
]
=
42.42
;
jdata
[
"myMessage"
]
=
"This is text fot test httpGetUserData"
;
}
#endif
// -----------------------------------------------------------------------------
void
TestGen
::
sysCommand
(
const
uniset
::
SystemMessage
*
sm
)
{
...
...
Utilities/codegen/tests/TestGen.h
View file @
f2bd929e
...
...
@@ -19,8 +19,9 @@ 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
virtual
void
httpGetUserData
(
nlohmann
::
json
&
jdata
)
override
;
#endif
private
:
bool
bool_var
=
{
false
};
int
int_var
=
{
0
};
...
...
Utilities/codegen/uniset2-codegen.in
View file @
f2bd929e
...
...
@@ -11,6 +11,8 @@ top_builddir=@top_builddir@
xsltdir
=
@datadir@/@PACKAGE@/xslt
[
-z
"@DISABLE_REST_API@"
]
&&
DISABLE_REST_API
=
0
||
DISABLE_REST_API
=
1
PROG
=
"
${
0
##*/
}
"
print_usage
()
...
...
@@ -206,6 +208,7 @@ PARAMS=$( echo \
--stringparam
LOCALINC
"
${
localinc
}
"
\
--stringparam
VARMAP
"
${
varmap
}
"
\
--stringparam
STAT
"
${
genstat
}
"
\
--stringparam
DISABLE_REST_API
"
${
DISABLE_REST_API
}
"
\
$xsltpath
\
)
# --stringparam ADD_CC_INC "${add_cc_inc}" \
...
...
conf/libuniset2.spec
View file @
f2bd929e
...
...
@@ -10,6 +10,7 @@
%def_disable tests
%def_disable mqtt
%def_disable netdata
%def_disable api
%define oname uniset2
...
...
@@ -314,7 +315,7 @@ SharedMemoryPlus extension ('all in one') for libuniset
%build
%autoreconf
%configure %{subst_enable docs} %{subst_enable mysql} %{subst_enable sqlite} %{subst_enable pgsql} %{subst_enable python} %{subst_enable rrd} %{subst_enable io} %{subst_enable logicproc} %{subst_enable tests} %{subst_enable mqtt}
%configure %{subst_enable docs} %{subst_enable mysql} %{subst_enable sqlite} %{subst_enable pgsql} %{subst_enable python} %{subst_enable rrd} %{subst_enable io} %{subst_enable logicproc} %{subst_enable tests} %{subst_enable mqtt}
%{subst_enable api}
%make
%install
...
...
conf/release_helper.sh
View file @
f2bd929e
...
...
@@ -64,7 +64,7 @@ function cp2ftp()
add_changelog_helper
"- new build"
$SPECNAME
rpmbb
$SPECNAME
||
fatal
"Can't build"
rpmbb
$
{
UNISET_BUILD_ADDON_OPTIONS
}
$
SPECNAME
||
fatal
"Can't build"
cp2ftp
...
...
configure.ac
View file @
f2bd929e
...
...
@@ -225,6 +225,25 @@ fi
AM_CONDITIONAL(DISABLE_MQTT, test ${buildmqtt} = false)
#check rest api support
AC_MSG_CHECKING([REST API support])
buildapi=true
AC_ARG_ENABLE(api, AC_HELP_STRING([--disable-api], [disable REST API support]),
[ if test $enableval = yes; then buildapi=true; else buildapi=false; fi],[ buildapi=true; ])
REST_API_CFLAGS=
DISABLE_REST_API=
if test ${buildapi} = true; then
AC_MSG_RESULT([enabled])
else
AC_MSG_RESULT([disabled])
REST_API_CFLAGS="-DDISABLE_REST_API"
DISABLE_REST_API=1
fi
AM_CONDITIONAL(DISABLE_REST_API, test ${buildapi} = false)
AC_SUBST(DISABLE_REST_API)
# check Doxygen
DOXYGEN=""
...
...
@@ -325,7 +344,7 @@ CXX_EXTRA_FLAGS="-Wnon-virtual-dtor -Woverloaded-virtual -Woverflow -D_GLIBCXX_U
# export
LDFLAGS="$LDFLAGS ${OMNI_LIBS} ${XML_LIBS} ${SIGC_LIBS} ${COV_LIBS} ${POCO_LIBS} ${EV_LIBS}"
# all developer liked options add to autogen.sh, please
CXXFLAGS="-I\$(top_builddir)/include $CXXFLAGS -funsigned-char -std=c++11 -g -D_GNU_SOURCE ${OMNI_CFLAGS} ${XML_CFLAGS} ${SIGC_CFLAGS} ${COV_CFLAGS} ${POCO_CFLAGS} ${EV_CFLAGS} $CXX_EXTRA_FLAGS"
CXXFLAGS="-I\$(top_builddir)/include $CXXFLAGS -funsigned-char -std=c++11 -g -D_GNU_SOURCE ${
REST_API_CFLAGS} ${
OMNI_CFLAGS} ${XML_CFLAGS} ${SIGC_CFLAGS} ${COV_CFLAGS} ${POCO_CFLAGS} ${EV_CFLAGS} $CXX_EXTRA_FLAGS"
AC_SUBST(LDFLAGS)
AC_SUBST(CXXFLAGS)
...
...
@@ -361,7 +380,7 @@ AC_C_VOLATILE
#AC_FUNC_MALLOC
AC_FUNC_SELECT_ARGTYPES
AC_TYPE_SIGNAL
AC_CHECK_FUNCS([atexit getcwd
gettimeofday atomic_set
])
AC_CHECK_FUNCS([atexit getcwd])
AC_CONFIG_FILES([Makefile
libUniSet2.pc
...
...
extensions/include/UObject_SK.h
View file @
f2bd929e
...
...
@@ -120,11 +120,12 @@ class UObject_SK:
// ------------------------------------------------------------
std
::
string
help
()
noexcept
;
#ifndef DISABLE_REST_API
// HTTP API
virtual
nlohmann
::
json
httpGet
(
const
Poco
::
URI
::
QueryParameters
&
p
)
override
;
virtual
nlohmann
::
json
httpRequest
(
const
std
::
string
&
req
,
const
Poco
::
URI
::
QueryParameters
&
p
)
override
;
virtual
nlohmann
::
json
httpHelp
(
const
Poco
::
URI
::
QueryParameters
&
p
)
override
;
#endif
// Используемые идентификаторы
...
...
@@ -157,9 +158,11 @@ class UObject_SK:
virtual
void
sigterm
(
int
signo
)
override
;
virtual
bool
activateObject
()
override
;
virtual
std
::
string
getMonitInfo
(){
return
""
;
}
/*!< пользовательская информация выводимая в getInfo() */
#ifndef DISABLE_REST_API
virtual
void
httpGetUserData
(
nlohmann
::
json
&
jdata
){}
/*!< для пользовательских данных в httpGet() */
virtual
nlohmann
::
json
httpDumpIO
();
virtual
nlohmann
::
json
httpRequestLog
(
const
Poco
::
URI
::
QueryParameters
&
p
);
#endif
// Выполнение очередного шага программы
virtual
void
step
(){}
...
...
extensions/lib/UObject_SK.cc
View file @
f2bd929e
...
...
@@ -292,6 +292,7 @@ void UObject_SK::testMode( bool _state )
}
// -----------------------------------------------------------------------------
#ifndef DISABLE_REST_API
nlohmann
::
json
UObject_SK
::
httpDumpIO
()
{
nlohmann
::
json
jdata
;
...
...
@@ -306,6 +307,7 @@ nlohmann::json UObject_SK::httpDumpIO()
return
std
::
move
(
jdata
);
}
// ----------------------------------------------------------------------------
#endif // #ifndef DISABLE_REST_API
std
::
string
UObject_SK
::
dumpIO
()
{
ostringstream
s
;
...
...
@@ -504,6 +506,7 @@ uniset::SimpleInfo* UObject_SK::getInfo( CORBA::Long userparam )
return
i
.
_retn
();
}
// -----------------------------------------------------------------------------
#ifndef DISABLE_REST_API
nlohmann
::
json
UObject_SK
::
httpGet
(
const
Poco
::
URI
::
QueryParameters
&
params
)
{
nlohmann
::
json
json
=
UniSetObject
::
httpGet
(
params
);
...
...
@@ -591,7 +594,7 @@ nlohmann::json UObject_SK::httpRequestLog( const Poco::URI::QueryParameters& p )
return
std
::
move
(
jret
);
}
// -----------------------------------------------------------------------------
#endif // #ifndef DISABLE_REST_API
// -----------------------------------------------------------------------------
void
UObject_SK
::
sigterm
(
int
signo
)
{
...
...
include/IOController.h
View file @
f2bd929e
...
...
@@ -96,10 +96,12 @@ class IOController:
virtual
IOController_i
::
ShortMapSeq
*
getSensors
()
override
;
#ifndef DISABLE_REST_API
// 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
httpRequest
(
const
std
::
string
&
req
,
const
Poco
::
URI
::
QueryParameters
&
p
)
override
;
#endif
public
:
...
...
@@ -166,10 +168,12 @@ class IOController:
virtual
long
localSetValue
(
std
::
shared_ptr
<
USensorInfo
>&
usi
,
CORBA
::
Long
value
,
uniset
::
ObjectId
sup_id
);
long
localGetValue
(
std
::
shared_ptr
<
USensorInfo
>&
usi
)
;
#ifndef DISABLE_REST_API
// http API
virtual
nlohmann
::
json
request_get
(
const
std
::
string
&
req
,
const
Poco
::
URI
::
QueryParameters
&
p
);
virtual
nlohmann
::
json
request_sensors
(
const
std
::
string
&
req
,
const
Poco
::
URI
::
QueryParameters
&
p
);
void
getSensorInfo
(
nlohmann
::
json
&
jdata
,
std
::
shared_ptr
<
USensorInfo
>&
s
,
bool
shortInfo
=
false
);
#endif
// переопределяем для добавления вызова регистрации датчиков
virtual
bool
deactivateObject
()
override
;
...
...
include/IONotifyController.h
View file @
f2bd929e
...
...
@@ -162,10 +162,11 @@ class IONotifyController:
// --------------------------------------------
#ifndef DISABLE_REST_API
// http API
virtual
nlohmann
::
json
httpHelp
(
const
Poco
::
URI
::
QueryParameters
&
p
)
override
;
nlohmann
::
json
httpRequest
(
const
string
&
req
,
const
Poco
::
URI
::
QueryParameters
&
p
);
#endif
// --------------------------------------------
/*! Информация о заказчике */
...
...
@@ -323,10 +324,12 @@ class IONotifyController:
udataThresholdList
=
1
};
#ifndef DISABLE_REST_API
// http api
nlohmann
::
json
request_consumers
(
const
std
::
string
&
req
,
const
Poco
::
URI
::
QueryParameters
&
p
);
nlohmann
::
json
request_lost
(
const
string
&
req
,
const
Poco
::
URI
::
QueryParameters
&
p
);
nlohmann
::
json
getConsumers
(
uniset
::
ObjectId
sid
,
ConsumerListInfo
&
clist
,
bool
noEmpty
=
true
);
#endif
private
:
friend
class
NCRestorer
;
...
...
include/LogServer.h
View file @
f2bd929e
...
...
@@ -29,7 +29,10 @@
#include "UTCPSocket.h"
#include "CommonEventLoop.h"
#include "LogServerTypes.h"
#ifndef DISABLE_REST_API
#include "json.hpp"
#endif
// -------------------------------------------------------------------------
namespace
uniset
{
...
...
@@ -124,7 +127,10 @@ class LogServer:
static
std
::
string
help_print
(
const
std
::
string
&
prefix
);
std
::
string
getShortInfo
();
#ifndef DISABLE_REST_API
nlohmann
::
json
httpGetShortInfo
();
#endif
protected
:
LogServer
();
...
...
include/LogSession.h
View file @
f2bd929e
...
...
@@ -27,7 +27,9 @@
#include "UTCPCore.h"
#include "UTCPStream.h"
#include "LogAgregator.h"
#ifndef DISABLE_REST_API
#include "json.hpp"
#endif
// -------------------------------------------------------------------------
namespace
uniset
{
...
...
@@ -79,10 +81,13 @@ class LogSession
bool
isAcive
()
const
noexcept
;
std
::
string
name
()
const
noexcept
;
std
::
string
getShortInfo
()
noexcept
;
nlohmann
::
json
httpGetShortInfo
();
std
::
string
name
()
const
noexcept
;
#ifndef DISABLE_REST_API
nlohmann
::
json
httpGetShortInfo
();
#endif
protected
:
// LogSession( ost::TCPSocket& server );
...
...
include/UHttpRequestHandler.h
View file @
f2bd929e
#ifndef DISABLE_REST_API
/*
* Copyright (c) 2015 Pavel Vainerman.
*
...
...
@@ -115,3 +116,4 @@ namespace uniset
// -------------------------------------------------------------------------
#endif // UHttpRequesrHandler_H_
// -------------------------------------------------------------------------
#endif
include/UHttpServer.h
View file @
f2bd929e
#ifndef DISABLE_REST_API
/*
* Copyright (c) 2015 Pavel Vainerman.
*
...
...
@@ -61,3 +62,4 @@ namespace uniset
// -------------------------------------------------------------------------
#endif // UHttpServer_H_
// -------------------------------------------------------------------------
#endif
include/UniSetActivator.h
View file @
f2bd929e
...
...
@@ -54,8 +54,10 @@ typedef std::shared_ptr<UniSetActivator> UniSetActivatorPtr;
* --uniset-abort-script - скрипт запускаемый при вылете, в качестве аргумента передаётся имя программы и pid
*/
class
UniSetActivator
:
public
UniSetManager
,
public
uniset
::
UHttp
::
IHttpRequestRegistry
public
UniSetManager
#ifndef DISABLE_REST_API
,
public
uniset
::
UHttp
::
IHttpRequestRegistry
#endif
{
public
:
...
...
@@ -88,11 +90,13 @@ class UniSetActivator:
return
abortScript
;
}
#ifndef DISABLE_REST_API
// Поддрежка REST API (IHttpRequestRegistry)
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
;
#endif
protected
:
...
...
@@ -131,9 +135,11 @@ class UniSetActivator:
std
::
string
abortScript
=
{
""
};
// скрипт вызываемый при прерывании программы (SIGSEGV,SIGABRT)
#ifndef DISABLE_REST_API
std
::
shared_ptr
<
uniset
::
UHttp
::
UHttpServer
>
httpserv
;
std
::
string
httpHost
=
{
""
};
int
httpPort
=
{
0
};
#endif
};
// -------------------------------------------------------------------------
}
// end of uniset namespace
...
...
include/UniSetObject.h
View file @
f2bd929e
...
...
@@ -73,8 +73,10 @@ typedef std::list< std::shared_ptr<UniSetObject> > ObjectsList; /*!< Спи
class
UniSetObject
:
public
std
::
enable_shared_from_this
<
UniSetObject
>
,
public
POA_UniSetObject_i
,
public
LT_Object
,
public
uniset
::
UHttp
::
IHttpRequest
public
LT_Object
#ifndef DISABLE_REST_API
,
public
uniset
::
UHttp
::
IHttpRequest
#endif
{
public
:
UniSetObject
(
const
std
::
string
&
name
,
const
std
::
string
&
section
);
...
...
@@ -102,10 +104,11 @@ class UniSetObject:
//! поместить сообщение в очередь
virtual
void
push
(
const
uniset
::
TransportMessage
&
msg
)
override
;
#ifndef DISABLE_REST_API
// HTTP API
virtual
nlohmann
::
json
httpGet
(
const
Poco
::
URI
::
QueryParameters
&
p
)
override
;
virtual
nlohmann
::
json
httpHelp
(
const
Poco
::
URI
::
QueryParameters
&
p
)
override
;
#endif
// -------------- вспомогательные --------------
/*! получить ссылку (на себя) */
uniset
::
ObjectPtr
getRef
()
const
;
...
...
src/Communications/Http/UHttpRequestHandler.cc
View file @
f2bd929e
#ifndef DISABLE_REST_API
/*
* Copyright (c) 2015 Pavel Vainerman.
*
...
...
@@ -160,3 +161,4 @@ nlohmann::json IHttpRequest::httpRequest( const string& req, const Poco::URI::Qu
throw
uniset
::
SystemError
(
err
.
str
());
}
// -------------------------------------------------------------------------
#endif
src/Communications/Http/UHttpServer.cc
View file @
f2bd929e
#ifndef DISABLE_REST_API
/*
* Copyright (c) 2015 Pavel Vainerman.
*
...
...
@@ -75,3 +76,4 @@ std::shared_ptr<DebugStream> UHttpServer::log()
return
mylog
;
}
// -------------------------------------------------------------------------
#endif // #ifndef DISABLE_REST_API
src/Log/DebugStream.cc
View file @
f2bd929e
...
...
@@ -174,9 +174,15 @@ std::ostream& DebugStream::printDate(Debug::type t, char brk) noexcept
std
::
time_t
tv
=
std
::
chrono
::
system_clock
::
to_time_t
(
std
::
chrono
::
system_clock
::
now
());
std
::
tm
tms
=
*
std
::
localtime
(
&
tv
);
#if __GLIBCXX__ >= 20151207
std
::
ostringstream
fmt
;
fmt
<<
"%Od"
<<
brk
<<
"%Om"
<<
brk
<<
"%Y"
;
return
*
this
<<
std
::
put_time
(
&
tms
,
fmt
.
str
().
c_str
());
return
(
*
this
)
<<
std
::
put_time
(
&
tms
,
fmt
.
str
().
c_str
());
#else
return
(
*
this
)
<<
std
::
setw
(
2
)
<<
std
::
setfill
(
'0'
)
<<
tms
.
tm_mday
<<
brk
<<
std
::
setw
(
2
)
<<
std
::
setfill
(
'0'
)
<<
tms
.
tm_mon
+
1
<<
brk
<<
std
::
setw
(
4
)
<<
std
::
setfill
(
'0'
)
<<
tms
.
tm_year
+
1900
;
#endif
}
return
nullstream
;
...
...
@@ -191,10 +197,15 @@ std::ostream& DebugStream::printTime(Debug::type t, char brk) noexcept
timespec
tv
=
uniset
::
now_to_timespec
();
// gettimeofday(tv,0);
std
::
tm
tms
=
*
std
::
localtime
(
&
tv
.
tv_sec
);
#if __GLIBCXX__ >= 20151207
std
::
ostringstream
fmt
;
fmt
<<
"%OH"
<<
brk
<<
"%OM"
<<
brk
<<
"%OS"
;
*
this
<<
std
::
put_time
(
&
tms
,
fmt
.
str
().
c_str
());
(
*
this
)
<<
std
::
put_time
(
&
tms
,
fmt
.
str
().
c_str
());
#else
*
this
<<
std
::
setw
(
2
)
<<
std
::
setfill
(
'0'
)
<<
tms
.
tm_hour
<<
brk
<<
std
::
setw
(
2
)
<<
std
::
setfill
(
'0'
)
<<
tms
.
tm_min
<<
brk
<<
std
::
setw
(
2
)
<<
std
::
setfill
(
'0'
)
<<
tms
.
tm_sec
;
#endif
if
(
show_usec
)
(
*
this
)
<<
"."
<<
std
::
setw
(
6
)
<<
(
tv
.
tv_nsec
/
1000
);
else
if
(
show_msec
)
...
...
@@ -214,7 +225,17 @@ std::ostream& DebugStream::printDateTime(Debug::type t) noexcept
timespec
tv
=
uniset
::
now_to_timespec
();
// gettimeofday(tv,0);
std
::
tm
tms
=
*
std
::
localtime
(
&
tv
.
tv_sec
);
#if __GLIBCXX__ >= 20151207
*
this
<<
std
::
put_time
(
&
tms
,
"%Od/%Om/%Y %OH:%OM:%OS"
);
#else
*
this
<<
std
::
setw
(
2
)
<<
std
::
setfill
(
'0'
)
<<
tms
.
tm_mday
<<
"/"
<<
std
::
setw
(
2
)
<<
std
::
setfill
(
'0'
)
<<
tms
.
tm_mon
+
1
<<
"/"
<<
std
::
setw
(
4
)
<<
std
::
setfill
(
'0'
)
<<
tms
.
tm_year
+
1900
<<
" "
<<
std
::
setw
(
2
)
<<
std
::
setfill
(
'0'
)
<<
tms
.
tm_hour
<<
":"
<<
std
::
setw
(
2
)
<<
std
::
setfill
(
'0'
)
<<
tms
.
tm_min
<<
":"
<<
std
::
setw
(
2
)
<<
std
::
setfill
(
'0'
)
<<
tms
.
tm_sec
;
#endif
if
(
show_usec
)
(
*
this
)
<<
"."
<<
std
::
setw
(
6
)
<<
std
::
setfill
(
'0'
)
<<
(
tv
.
tv_nsec
/
1000
);
...
...
src/Log/LogServer.cc
View file @
f2bd929e
...
...
@@ -345,6 +345,7 @@ string LogServer::getShortInfo()
return
std
::
move
(
inf
.
str
());
}
// -----------------------------------------------------------------------------
#ifndef DISABLE_REST_API
nlohmann
::
json
LogServer
::
httpGetShortInfo
()
{
nlohmann
::
json
jdata
;
...
...
@@ -363,6 +364,7 @@ nlohmann::json LogServer::httpGetShortInfo()
return
std
::
move
(
jdata
);
}
#endif // #ifndef DISABLE_REST_API
// -----------------------------------------------------------------------------
void
LogServer
::
saveDefaultLogLevels
(
const
std
::
string
&
logname
)
{
...
...
src/Log/LogSession.cc
View file @
f2bd929e
...
...
@@ -676,6 +676,7 @@ string LogSession::getShortInfo() noexcept
return
std
::
move
(
inf
.
str
());
}
// ---------------------------------------------------------------------
#ifndef DISABLE_REST_API
nlohmann
::
json
LogSession
::
httpGetShortInfo
()
{
nlohmann
::
json
jret
;
...
...
@@ -698,6 +699,7 @@ nlohmann::json LogSession::httpGetShortInfo()
return
std
::
move
(
jret
);
}
#endif // #ifndef DISABLE_REST_API
// ---------------------------------------------------------------------
string
LogSession
::
name
()
const
noexcept
{
...
...
src/ObjectRepository/UniSetActivator.cc
View file @
f2bd929e
...
...
@@ -528,6 +528,7 @@ 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"
);
...
...
@@ -536,6 +537,7 @@ void UniSetActivator::init()
httpPort
=
conf
->
getArgInt
(
"--activator-httpserver-port"
,
s
.
str
());
ulog1
<<
myname
<<
"(init): http server parameters "
<<
httpHost
<<
":"
<<
httpPort
<<
endl
;
}
#endif
orb
=
conf
->
getORB
();
CORBA
::
Object_var
obj
=
orb
->
resolve_initial_references
(
"RootPOA"
);
...
...
@@ -665,6 +667,7 @@ void UniSetActivator::run( bool thread )
set_signals
(
true
);
#ifndef DISABLE_REST_API
if
(
!
httpHost
.
empty
()
)
{
try
...
...
@@ -678,7 +681,7 @@ void UniSetActivator::run( bool thread )
uwarn
<<
myname
<<
"(run): init http server error: "
<<
ex
.
what
()
<<
endl
;
}
}
#endif
if
(
thread
)
{
...
...
@@ -715,8 +718,10 @@ void UniSetActivator::stop()
ulogsys
<<
myname
<<
"(stop): discard request ok."
<<
endl
;
#ifndef DISABLE_REST_API
if
(
httpserv
)
httpserv
->
stop
();
#endif
}
// ------------------------------------------------------------------------------------------
...
...
@@ -864,6 +869,7 @@ UniSetActivator::TerminateEvent_Signal UniSetActivator::signal_terminate_event()
return
s_term
;
}
// ------------------------------------------------------------------------------------------
#ifndef DISABLE_REST_API
nlohmann
::
json
UniSetActivator
::
httpGetByName
(
const
string
&
name
,
const
Poco
::
URI
::
QueryParameters
&
p
)
{
if
(
name
==
myname
)
...
...
@@ -923,6 +929,7 @@ nlohmann::json UniSetActivator::httpRequestByName( const string& name, const std
err
<<
"Object '"
<<
name
<<
"' not found"
;
throw
uniset
::
NameNotFound
(
err
.
str
());
}
#endif // #ifndef DISABLE_REST_API
// ------------------------------------------------------------------------------------------
void
UniSetActivator
::
terminated
(
int
signo
)
{
...
...
src/ObjectRepository/UniSetObject.cc
View file @
f2bd929e
...
...
@@ -380,6 +380,7 @@ void UniSetObject::push( const TransportMessage& tm )
termWaiting
();
}
// ------------------------------------------------------------------------------------------
#ifndef DISABLE_REST_API
nlohmann
::
json
UniSetObject
::
httpGet
(
const
Poco
::
URI
::
QueryParameters
&
p
)
{
nlohmann
::
json
jret
;
...
...
@@ -402,6 +403,7 @@ nlohmann::json UniSetObject::httpHelp( const Poco::URI::QueryParameters& p )
jdata
[
myname
][
"help"
]
=
{};
return
jdata
;
}
#endif
// ------------------------------------------------------------------------------------------
ObjectPtr
UniSetObject
::
getRef
()
const
{
...
...
src/Processes/IOController.cc
View file @
f2bd929e
...
...
@@ -842,6 +842,7 @@ uniset::SimpleInfo* IOController::getInfo( ::CORBA::Long userparam )
return
i
.
_retn
();
}
// -----------------------------------------------------------------------------
#ifndef DISABLE_REST_API
nlohmann
::
json
IOController
::
httpHelp
(
const
Poco
::
URI
::
QueryParameters
&
p
)
{
nlohmann
::
json
jdata
=
UniSetManager
::
httpHelp
(
p
);
...
...
@@ -1006,3 +1007,4 @@ nlohmann::json IOController::request_sensors( const string& req, const Poco::URI
return
std
::
move
(
jdata
);
}
// -----------------------------------------------------------------------------
#endif // #ifndef DISABLE_REST_API
src/Processes/IONotifyController.cc
View file @
f2bd929e
...
...
@@ -1165,6 +1165,7 @@ IDSeq* IONotifyController::askSensorsSeq( const uniset::IDSeq& lst,
return
badlist
.
getIDSeq
();
}
// -----------------------------------------------------------------------------
#ifndef DISABLE_REST_API
nlohmann
::
json
IONotifyController
::
httpHelp
(
const
Poco
::
URI
::
QueryParameters
&
p
)
{
nlohmann
::
json
jdata
=
IOController
::
httpHelp
(
p
);
...
...
@@ -1298,3 +1299,4 @@ nlohmann::json IONotifyController::request_lost( const string& req, const Poco::
return
std
::
move
(
json
);
}
// -----------------------------------------------------------------------------
#endif // #ifndef DISABLE_REST_API
tests/UHttpTest/uhttp-test.cc
View file @
f2bd929e
#ifndef DISABLE_REST_API
#include <iostream>
#include <memory>
#include "UHttpServer.h"
...
...
@@ -88,7 +89,6 @@ class UTestRequestRegistry:
private
:
UTestSupplier
sup
;
};
// --------------------------------------------------------------------------
int
main
(
int
argc
,
const
char
**
argv
)
{
...
...
@@ -118,3 +118,11 @@ int main(int argc, const char** argv)
return
1
;
}
#else
#include <iostream>
int
main
(
int
argc
,
const
char
**
argv
)
{
std
::
cerr
<<
"REST API DISABLED!!"
<<
std
::
endl
;
return
1
;
}
#endif // #ifndef DISABLE_REST_API
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