Commit f2bd929e authored by Pavel Vainerman's avatar Pavel Vainerman

Сделал возможность отключать REST API

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