Commit b0ecd945 authored by Pavel Vainerman's avatar Pavel Vainerman

(UHttp): Из-за некомпилируемости json.hpp под p7 ( требуется gcc >= 4.9),

пришлось отказаться от её использования и перейти на Poco::JSON.
parent 43affb28
...@@ -84,12 +84,12 @@ void TestGen::sigterm( int signo ) ...@@ -84,12 +84,12 @@ void TestGen::sigterm( int signo )
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#ifndef DISABLE_REST_API #ifndef DISABLE_REST_API
void TestGen::httpGetUserData( nlohmann::json& jdata ) void TestGen::httpGetUserData( Poco::JSON::Object::Ptr& jdata )
{ {
jdata["myMode"] = "RUNNING"; jdata->set("myMode", "RUNNING");
jdata["myVar"] = 42; jdata->set("myVar", 42);
jdata["myFloatVar"] = 42.42; jdata->set("myFloatVar", 42.42);
jdata["myMessage"] = "This is text fot test httpGetUserData"; jdata->set("myMessage", "This is text fot test httpGetUserData");
} }
#endif #endif
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
......
...@@ -19,8 +19,8 @@ class TestGen: ...@@ -19,8 +19,8 @@ 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 #ifndef DISABLE_REST_API
virtual void httpGetUserData( nlohmann::json& jdata ) override; virtual void httpGetUserData( Poco::JSON::Object::Ptr& jdata ) override;
#endif #endif
private: private:
bool bool_var = { false }; bool bool_var = { false };
......
...@@ -359,7 +359,6 @@ mv -f %buildroot%python_sitelibdir_noarch/* %buildroot%python_sitelibdir/%oname ...@@ -359,7 +359,6 @@ mv -f %buildroot%python_sitelibdir_noarch/* %buildroot%python_sitelibdir/%oname
%dir %_includedir/%oname/ %dir %_includedir/%oname/
%_includedir/%oname/*.h %_includedir/%oname/*.h
%_includedir/%oname/*.hh %_includedir/%oname/*.hh
%_includedir/%oname/*.hpp
%_includedir/%oname/*.tcc %_includedir/%oname/*.tcc
%_includedir/%oname/modbus/ %_includedir/%oname/modbus/
......
...@@ -59,7 +59,7 @@ fi ...@@ -59,7 +59,7 @@ fi
AC_MSG_CHECKING([libpoco support]) AC_MSG_CHECKING([libpoco support])
#AC_SEARCH_LIBS(ServerSocket,PocoNet,,exit) #AC_SEARCH_LIBS(ServerSocket,PocoNet,,exit)
AC_CHECK_HEADER(Poco/Net/Socket.h,,exit) AC_CHECK_HEADER(Poco/Net/Socket.h,,exit)
POCO_LIBS="-lPocoFoundation -lPocoNet" POCO_LIBS="-lPocoFoundation -lPocoNet -lPocoJSON"
POCO_CFLAGS="-IPoco" POCO_CFLAGS="-IPoco"
AC_SUBST(POCO_LIBS) AC_SUBST(POCO_LIBS)
AC_SUBST(POCO_CFLAGS) AC_SUBST(POCO_CFLAGS)
......
...@@ -49,7 +49,7 @@ class IOController: ...@@ -49,7 +49,7 @@ class IOController:
return uniset::ObjectType("IOController"); return uniset::ObjectType("IOController");
} }
virtual uniset::SimpleInfo* getInfo( const char* userparam = 0 ) override; virtual uniset::SimpleInfo* getInfo( ::CORBA::Long userparam = 0 ) override;
virtual CORBA::Long getValue( uniset::ObjectId sid ) override; virtual CORBA::Long getValue( uniset::ObjectId sid ) override;
...@@ -82,7 +82,7 @@ class IOController: ...@@ -82,7 +82,7 @@ class IOController:
IOController_i::CalibrateInfo getCalibrateInfo( uniset::ObjectId sid ) override; IOController_i::CalibrateInfo getCalibrateInfo( uniset::ObjectId sid ) override;
inline IOController_i::SensorInfo SensorInfo( const uniset::ObjectId sid, inline IOController_i::SensorInfo SensorInfo( const uniset::ObjectId sid,
const uniset::ObjectId node = uniset::uniset_conf()->getLocalNode()) const uniset::ObjectId node = uniset::uniset_conf()->getLocalNode())
{ {
IOController_i::SensorInfo si; IOController_i::SensorInfo si;
si.id = sid; si.id = sid;
...@@ -92,15 +92,14 @@ class IOController: ...@@ -92,15 +92,14 @@ class IOController:
uniset::Message::Priority getPriority( const uniset::ObjectId id ); uniset::Message::Priority getPriority( const uniset::ObjectId id );
virtual IOController_i::ShortIOInfo getTimeChange( const uniset::ObjectId id ) override; virtual IOController_i::ShortIOInfo getChangedTime( const uniset::ObjectId id ) override;
virtual IOController_i::ShortMapSeq* getSensors() override; virtual IOController_i::ShortMapSeq* getSensors() override;
#ifndef DISABLE_REST_API #ifndef DISABLE_REST_API
// http API // http API
// virtual nlohmann::json getData( const Poco::URI::QueryParameters& p ) override; virtual Poco::JSON::Object::Ptr httpHelp( const Poco::URI::QueryParameters& p ) override;
virtual nlohmann::json httpHelp( const Poco::URI::QueryParameters& p ) override; virtual Poco::JSON::Object::Ptr 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 #endif
public: public:
...@@ -170,9 +169,9 @@ class IOController: ...@@ -170,9 +169,9 @@ class IOController:
#ifndef DISABLE_REST_API #ifndef DISABLE_REST_API
// http API // http API
virtual nlohmann::json request_get( const std::string& req, const Poco::URI::QueryParameters& p ); virtual Poco::JSON::Object::Ptr 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 Poco::JSON::Object::Ptr 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( Poco::JSON::Array::Ptr& jdata, std::shared_ptr<USensorInfo>& s , bool shortInfo = false );
#endif #endif
// переопределяем для добавления вызова регистрации датчиков // переопределяем для добавления вызова регистрации датчиков
...@@ -245,8 +244,8 @@ class IOController: ...@@ -245,8 +244,8 @@ class IOController:
IOStateList::iterator myiofind( uniset::ObjectId id ); IOStateList::iterator myiofind( uniset::ObjectId id );
size_t ioCount(); size_t ioCount();
// -------------------------- // --------------------------
private: private:
friend class NCRestorer; friend class NCRestorer;
friend class SMInterface; friend class SMInterface;
......
...@@ -164,8 +164,8 @@ class IONotifyController: ...@@ -164,8 +164,8 @@ class IONotifyController:
#ifndef DISABLE_REST_API #ifndef DISABLE_REST_API
// http API // http API
virtual nlohmann::json httpHelp( const Poco::URI::QueryParameters& p ) override; virtual Poco::JSON::Object::Ptr httpHelp( const Poco::URI::QueryParameters& p ) override;
nlohmann::json httpRequest( const string& req, const Poco::URI::QueryParameters& p ); Poco::JSON::Object::Ptr httpRequest( const string& req, const Poco::URI::QueryParameters& p );
#endif #endif
// -------------------------------------------- // --------------------------------------------
...@@ -326,9 +326,9 @@ class IONotifyController: ...@@ -326,9 +326,9 @@ class IONotifyController:
#ifndef DISABLE_REST_API #ifndef DISABLE_REST_API
// http api // http api
nlohmann::json request_consumers( const std::string& req, const Poco::URI::QueryParameters& p ); Poco::JSON::Object::Ptr request_consumers( const std::string& req, const Poco::URI::QueryParameters& p );
nlohmann::json request_lost( const string& req, const Poco::URI::QueryParameters& p ); Poco::JSON::Object::Ptr request_lost( const string& req, const Poco::URI::QueryParameters& p );
nlohmann::json getConsumers( uniset::ObjectId sid, ConsumerListInfo& clist, bool noEmpty = true ); Poco::JSON::Object::Ptr getConsumers( uniset::ObjectId sid, ConsumerListInfo& clist, bool noEmpty = true );
#endif #endif
private: private:
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
#include "LogServerTypes.h" #include "LogServerTypes.h"
#ifndef DISABLE_REST_API #ifndef DISABLE_REST_API
#include "json.hpp" #include <Poco/JSON/Object.h>
#endif #endif
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
namespace uniset namespace uniset
...@@ -129,7 +129,7 @@ class LogServer: ...@@ -129,7 +129,7 @@ class LogServer:
std::string getShortInfo(); std::string getShortInfo();
#ifndef DISABLE_REST_API #ifndef DISABLE_REST_API
nlohmann::json httpGetShortInfo(); Poco::JSON::Object::Ptr httpGetShortInfo();
#endif #endif
protected: protected:
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
#include "UTCPStream.h" #include "UTCPStream.h"
#include "LogAgregator.h" #include "LogAgregator.h"
#ifndef DISABLE_REST_API #ifndef DISABLE_REST_API
#include "json.hpp" #include <Poco/JSON/Object.h>
#endif #endif
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
namespace uniset namespace uniset
...@@ -86,7 +86,7 @@ class LogSession ...@@ -86,7 +86,7 @@ class LogSession
std::string getShortInfo() noexcept; std::string getShortInfo() noexcept;
#ifndef DISABLE_REST_API #ifndef DISABLE_REST_API
nlohmann::json httpGetShortInfo(); Poco::JSON::Object::Ptr httpGetShortInfo();
#endif #endif
protected: protected:
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
SUBDIRS=modbus SUBDIRS=modbus
# install # install
devel_include_HEADERS = *.h *.hh *.tcc *.hpp devel_include_HEADERS = *.h *.hh *.tcc
devel_includedir = $(pkgincludedir) devel_includedir = $(pkgincludedir)
all-local: all-local:
......
...@@ -24,7 +24,8 @@ ...@@ -24,7 +24,8 @@
#include <Poco/Net/HTTPServerRequest.h> #include <Poco/Net/HTTPServerRequest.h>
#include <Poco/Net/HTTPServerResponse.h> #include <Poco/Net/HTTPServerResponse.h>
#include <Poco/URI.h> #include <Poco/URI.h>
#include "json.hpp" #include <Poco/JSON/Object.h>
#include "ujson.h"
#include "DebugStream.h" #include "DebugStream.h"
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
/*! \page UHttpServer API /*! \page UHttpServer API
...@@ -42,75 +43,99 @@ ...@@ -42,75 +43,99 @@
* /api/version/ObjectName/help - получение списка доступных команд для объекта ObjectName * /api/version/ObjectName/help - получение списка доступных команд для объекта ObjectName
* /api/version/ObjectName/xxxx - 'xxx' запрос к объекту ObjectName * /api/version/ObjectName/xxxx - 'xxx' запрос к объекту ObjectName
* *
* HELP FORMAT:
* myname {
* help [
* {"command":
* {"desc": "text"},
* {"params": [
* {"p1","desc of p1"},
* {"p2","desc of p2"},
* {"p3","desc of p3"}
* ]}
* },
* {"command2":
* {"desc": "text"},
* {"params": [
* {"p1","desc of p1"},
* {"p2","desc of p2"},
* {"p3","desc of p3"}
* ]}
* },
* ...
* ]
* }
*
*
* \todo подумать над /api/version/tree - получение "дерева" объектов (древовидный список с учётом подчинения Manager/Objects) * \todo подумать над /api/version/tree - получение "дерева" объектов (древовидный список с учётом подчинения Manager/Objects)
*/ */
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
namespace uniset namespace uniset
{ {
namespace UHttp namespace UHttp
{ {
// текущая версия API // текущая версия API
const std::string UHTTP_API_VERSION = "v01"; const std::string UHTTP_API_VERSION="v0";
/*! интерфейс для объекта выдающего json-данные */ /*! интерфейс для объекта выдающего json-данные */
class IHttpRequest class IHttpRequest
{ {
public: public:
IHttpRequest() {} IHttpRequest(){}
virtual ~IHttpRequest() {} virtual ~IHttpRequest(){}
// throw SystemError // throw SystemError
virtual nlohmann::json httpGet( const Poco::URI::QueryParameters& p ) = 0; virtual Poco::JSON::Object::Ptr httpGet( const Poco::URI::QueryParameters& p ) = 0;
virtual nlohmann::json httpHelp( const Poco::URI::QueryParameters& p ) = 0; virtual Poco::JSON::Object::Ptr httpHelp( const Poco::URI::QueryParameters& p ) = 0;
// не обязательная функция. // не обязательная функция.
virtual nlohmann::json httpRequest( const std::string& req, const Poco::URI::QueryParameters& p ); virtual Poco::JSON::Object::Ptr httpRequest( const std::string& req, const Poco::URI::QueryParameters& p );
}; };
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
/*! интерфейс для обработки запросов к объектам */ /*! интерфейс для обработки запросов к объектам */
class IHttpRequestRegistry class IHttpRequestRegistry
{ {
public: public:
IHttpRequestRegistry() {} IHttpRequestRegistry(){}
virtual ~IHttpRequestRegistry() {} virtual ~IHttpRequestRegistry(){}
// throw SystemError, NameNotFound // throw SystemError, NameNotFound
virtual nlohmann::json httpGetByName( const std::string& name, const Poco::URI::QueryParameters& p ) = 0; virtual Poco::JSON::Object::Ptr httpGetByName( const std::string& name, const Poco::URI::QueryParameters& p ) = 0;
// throw SystemError // throw SystemError
virtual nlohmann::json httpGetObjectsList( const Poco::URI::QueryParameters& p ) = 0; virtual Poco::JSON::Array::Ptr httpGetObjectsList( const Poco::URI::QueryParameters& p ) = 0;
virtual nlohmann::json httpHelpByName( const std::string& name, const Poco::URI::QueryParameters& p ) = 0; virtual Poco::JSON::Object::Ptr httpHelpByName( const std::string& name, const Poco::URI::QueryParameters& p ) = 0;
virtual nlohmann::json httpRequestByName( const std::string& name, const std::string& req, const Poco::URI::QueryParameters& p ) = 0; virtual Poco::JSON::Object::Ptr httpRequestByName( const std::string& name, const std::string& req, const Poco::URI::QueryParameters& p ) = 0;
}; };
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
class UHttpRequestHandler: class UHttpRequestHandler:
public Poco::Net::HTTPRequestHandler public Poco::Net::HTTPRequestHandler
{ {
public: public:
UHttpRequestHandler( std::shared_ptr<IHttpRequestRegistry> _registry ); UHttpRequestHandler( std::shared_ptr<IHttpRequestRegistry> _registry );
virtual void handleRequest( Poco::Net::HTTPServerRequest& req, Poco::Net::HTTPServerResponse& resp ) override; virtual void handleRequest( Poco::Net::HTTPServerRequest &req, Poco::Net::HTTPServerResponse &resp ) override;
private: private:
std::shared_ptr<IHttpRequestRegistry> registry; std::shared_ptr<IHttpRequestRegistry> registry;
std::shared_ptr<DebugStream> log; std::shared_ptr<DebugStream> log;
}; };
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
class UHttpRequestHandlerFactory: class UHttpRequestHandlerFactory:
public Poco::Net::HTTPRequestHandlerFactory public Poco::Net::HTTPRequestHandlerFactory
{ {
public: public:
UHttpRequestHandlerFactory( std::shared_ptr<IHttpRequestRegistry>& _registry ); UHttpRequestHandlerFactory( std::shared_ptr<IHttpRequestRegistry>& _registry );
virtual Poco::Net::HTTPRequestHandler* createRequestHandler( const Poco::Net::HTTPServerRequest& ) override; virtual Poco::Net::HTTPRequestHandler* createRequestHandler( const Poco::Net::HTTPServerRequest & ) override;
private: private:
std::shared_ptr<IHttpRequestRegistry> registry; std::shared_ptr<IHttpRequestRegistry> registry;
}; };
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
} // end of uniset namespace } // end of uniset namespace
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
......
...@@ -92,10 +92,10 @@ class UniSetActivator: ...@@ -92,10 +92,10 @@ class UniSetActivator:
#ifndef DISABLE_REST_API #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 Poco::JSON::Object::Ptr httpGetByName( const std::string& name , const Poco::URI::QueryParameters& p ) override;
virtual nlohmann::json httpGetObjectsList( const Poco::URI::QueryParameters& p ) override; virtual Poco::JSON::Array::Ptr httpGetObjectsList( const Poco::URI::QueryParameters& p ) override;
virtual nlohmann::json httpHelpByName( const std::string& name, const Poco::URI::QueryParameters& p ) override; virtual Poco::JSON::Object::Ptr 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 Poco::JSON::Object::Ptr httpRequestByName( const std::string& name, const std::string& req, const Poco::URI::QueryParameters& p ) override;
#endif #endif
protected: protected:
......
...@@ -106,8 +106,8 @@ class UniSetObject: ...@@ -106,8 +106,8 @@ class UniSetObject:
#ifndef DISABLE_REST_API #ifndef DISABLE_REST_API
// HTTP API // HTTP API
virtual nlohmann::json httpGet( const Poco::URI::QueryParameters& p ) override; virtual Poco::JSON::Object::Ptr httpGet( const Poco::URI::QueryParameters& p ) override;
virtual nlohmann::json httpHelp( const Poco::URI::QueryParameters& p ) override; virtual Poco::JSON::Object::Ptr httpHelp( const Poco::URI::QueryParameters& p ) override;
#endif #endif
// -------------- вспомогательные -------------- // -------------- вспомогательные --------------
/*! получить ссылку (на себя) */ /*! получить ссылку (на себя) */
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -3011,9 +3011,10 @@ SWIG_Python_NonDynamicSetAttr(PyObject *obj, PyObject *name, PyObject *value) { ...@@ -3011,9 +3011,10 @@ SWIG_Python_NonDynamicSetAttr(PyObject *obj, PyObject *name, PyObject *value) {
#define SWIGTYPE_p_UModbus swig_types[1] #define SWIGTYPE_p_UModbus swig_types[1]
#define SWIGTYPE_p_USysError swig_types[2] #define SWIGTYPE_p_USysError swig_types[2]
#define SWIGTYPE_p_UTimeOut swig_types[3] #define SWIGTYPE_p_UTimeOut swig_types[3]
#define SWIGTYPE_p_char swig_types[4] #define SWIGTYPE_p_UValidateError swig_types[4]
static swig_type_info *swig_types[6]; #define SWIGTYPE_p_char swig_types[5]
static swig_module_info swig_module = {swig_types, 5, 0, 0, 0, 0}; static swig_type_info *swig_types[7];
static swig_module_info swig_module = {swig_types, 6, 0, 0, 0, 0};
#define SWIG_TypeQuery(name) SWIG_TypeQueryModule(&swig_module, &swig_module, name) #define SWIG_TypeQuery(name) SWIG_TypeQueryModule(&swig_module, &swig_module, name)
#define SWIG_MangledTypeQuery(name) SWIG_MangledTypeQueryModule(&swig_module, &swig_module, name) #define SWIG_MangledTypeQuery(name) SWIG_MangledTypeQueryModule(&swig_module, &swig_module, name)
...@@ -5601,6 +5602,109 @@ SWIGINTERN PyObject *USysError_swigregister(PyObject *SWIGUNUSEDPARM(self), PyOb ...@@ -5601,6 +5602,109 @@ SWIGINTERN PyObject *USysError_swigregister(PyObject *SWIGUNUSEDPARM(self), PyOb
return SWIG_Py_Void(); return SWIG_Py_Void();
} }
SWIGINTERN PyObject *_wrap_new_UValidateError__SWIG_0(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *resultobj = 0;
UValidateError *result = 0 ;
if (!PyArg_ParseTuple(args,(char *)":new_UValidateError")) SWIG_fail;
result = (UValidateError *)new UValidateError();
resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_UValidateError, SWIG_POINTER_NEW | 0 );
return resultobj;
fail:
return NULL;
}
SWIGINTERN PyObject *_wrap_new_UValidateError__SWIG_1(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *resultobj = 0;
std::string *arg1 = 0 ;
int res1 = SWIG_OLDOBJ ;
PyObject * obj0 = 0 ;
UValidateError *result = 0 ;
if (!PyArg_ParseTuple(args,(char *)"O:new_UValidateError",&obj0)) SWIG_fail;
{
std::string *ptr = (std::string *)0;
res1 = SWIG_AsPtr_std_string(obj0, &ptr);
if (!SWIG_IsOK(res1)) {
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "new_UValidateError" "', argument " "1"" of type '" "std::string const &""'");
}
if (!ptr) {
SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "new_UValidateError" "', argument " "1"" of type '" "std::string const &""'");
}
arg1 = ptr;
}
result = (UValidateError *)new UValidateError((std::string const &)*arg1);
resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_UValidateError, SWIG_POINTER_NEW | 0 );
if (SWIG_IsNewObj(res1)) delete arg1;
return resultobj;
fail:
if (SWIG_IsNewObj(res1)) delete arg1;
return NULL;
}
SWIGINTERN PyObject *_wrap_new_UValidateError(PyObject *self, PyObject *args) {
Py_ssize_t argc;
PyObject *argv[2] = {
0
};
Py_ssize_t ii;
if (!PyTuple_Check(args)) SWIG_fail;
argc = args ? PyObject_Length(args) : 0;
for (ii = 0; (ii < 1) && (ii < argc); ii++) {
argv[ii] = PyTuple_GET_ITEM(args,ii);
}
if (argc == 0) {
return _wrap_new_UValidateError__SWIG_0(self, args);
}
if (argc == 1) {
int _v;
int res = SWIG_AsPtr_std_string(argv[0], (std::string**)(0));
_v = SWIG_CheckState(res);
if (_v) {
return _wrap_new_UValidateError__SWIG_1(self, args);
}
}
fail:
SWIG_SetErrorMsg(PyExc_NotImplementedError,"Wrong number or type of arguments for overloaded function 'new_UValidateError'.\n"
" Possible C/C++ prototypes are:\n"
" UValidateError::UValidateError()\n"
" UValidateError::UValidateError(std::string const &)\n");
return 0;
}
SWIGINTERN PyObject *_wrap_delete_UValidateError(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *resultobj = 0;
UValidateError *arg1 = (UValidateError *) 0 ;
void *argp1 = 0 ;
int res1 = 0 ;
PyObject * obj0 = 0 ;
if (!PyArg_ParseTuple(args,(char *)"O:delete_UValidateError",&obj0)) SWIG_fail;
res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_UValidateError, SWIG_POINTER_DISOWN | 0 );
if (!SWIG_IsOK(res1)) {
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_UValidateError" "', argument " "1"" of type '" "UValidateError *""'");
}
arg1 = reinterpret_cast< UValidateError * >(argp1);
delete arg1;
resultobj = SWIG_Py_Void();
return resultobj;
fail:
return NULL;
}
SWIGINTERN PyObject *UValidateError_swigregister(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *obj;
if (!PyArg_ParseTuple(args,(char*)"O:swigregister", &obj)) return NULL;
SWIG_TypeNewClientData(SWIGTYPE_p_UValidateError, SWIG_NewClientData(obj));
return SWIG_Py_Void();
}
static PyMethodDef SwigMethods[] = { static PyMethodDef SwigMethods[] = {
{ (char *)"SWIG_PyInstanceMethod_New", (PyCFunction)SWIG_PyInstanceMethod_New, METH_O, NULL}, { (char *)"SWIG_PyInstanceMethod_New", (PyCFunction)SWIG_PyInstanceMethod_New, METH_O, NULL},
{ (char *)"new_UModbus", _wrap_new_UModbus, METH_VARARGS, NULL}, { (char *)"new_UModbus", _wrap_new_UModbus, METH_VARARGS, NULL},
...@@ -5631,6 +5735,9 @@ static PyMethodDef SwigMethods[] = { ...@@ -5631,6 +5735,9 @@ static PyMethodDef SwigMethods[] = {
{ (char *)"new_USysError", _wrap_new_USysError, METH_VARARGS, NULL}, { (char *)"new_USysError", _wrap_new_USysError, METH_VARARGS, NULL},
{ (char *)"delete_USysError", _wrap_delete_USysError, METH_VARARGS, NULL}, { (char *)"delete_USysError", _wrap_delete_USysError, METH_VARARGS, NULL},
{ (char *)"USysError_swigregister", USysError_swigregister, METH_VARARGS, NULL}, { (char *)"USysError_swigregister", USysError_swigregister, METH_VARARGS, NULL},
{ (char *)"new_UValidateError", _wrap_new_UValidateError, METH_VARARGS, NULL},
{ (char *)"delete_UValidateError", _wrap_delete_UValidateError, METH_VARARGS, NULL},
{ (char *)"UValidateError_swigregister", UValidateError_swigregister, METH_VARARGS, NULL},
{ NULL, NULL, 0, NULL } { NULL, NULL, 0, NULL }
}; };
...@@ -5643,10 +5750,14 @@ static void *_p_UTimeOutTo_p_UException(void *x, int *SWIGUNUSEDPARM(newmemory)) ...@@ -5643,10 +5750,14 @@ static void *_p_UTimeOutTo_p_UException(void *x, int *SWIGUNUSEDPARM(newmemory))
static void *_p_USysErrorTo_p_UException(void *x, int *SWIGUNUSEDPARM(newmemory)) { static void *_p_USysErrorTo_p_UException(void *x, int *SWIGUNUSEDPARM(newmemory)) {
return (void *)((UException *) ((USysError *) x)); return (void *)((UException *) ((USysError *) x));
} }
static void *_p_UValidateErrorTo_p_UException(void *x, int *SWIGUNUSEDPARM(newmemory)) {
return (void *)((UException *) ((UValidateError *) x));
}
static swig_type_info _swigt__p_UException = {"_p_UException", "UException *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_UException = {"_p_UException", "UException *", 0, 0, (void*)0, 0};
static swig_type_info _swigt__p_UModbus = {"_p_UModbus", "UModbus *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_UModbus = {"_p_UModbus", "UModbus *", 0, 0, (void*)0, 0};
static swig_type_info _swigt__p_USysError = {"_p_USysError", "USysError *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_USysError = {"_p_USysError", "USysError *", 0, 0, (void*)0, 0};
static swig_type_info _swigt__p_UTimeOut = {"_p_UTimeOut", "UTimeOut *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_UTimeOut = {"_p_UTimeOut", "UTimeOut *", 0, 0, (void*)0, 0};
static swig_type_info _swigt__p_UValidateError = {"_p_UValidateError", "UValidateError *", 0, 0, (void*)0, 0};
static swig_type_info _swigt__p_char = {"_p_char", "char *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_char = {"_p_char", "char *", 0, 0, (void*)0, 0};
static swig_type_info *swig_type_initial[] = { static swig_type_info *swig_type_initial[] = {
...@@ -5654,13 +5765,15 @@ static swig_type_info *swig_type_initial[] = { ...@@ -5654,13 +5765,15 @@ static swig_type_info *swig_type_initial[] = {
&_swigt__p_UModbus, &_swigt__p_UModbus,
&_swigt__p_USysError, &_swigt__p_USysError,
&_swigt__p_UTimeOut, &_swigt__p_UTimeOut,
&_swigt__p_UValidateError,
&_swigt__p_char, &_swigt__p_char,
}; };
static swig_cast_info _swigc__p_UException[] = { {&_swigt__p_UException, 0, 0, 0}, {&_swigt__p_UTimeOut, _p_UTimeOutTo_p_UException, 0, 0}, {&_swigt__p_USysError, _p_USysErrorTo_p_UException, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_UException[] = { {&_swigt__p_UException, 0, 0, 0}, {&_swigt__p_UTimeOut, _p_UTimeOutTo_p_UException, 0, 0}, {&_swigt__p_USysError, _p_USysErrorTo_p_UException, 0, 0}, {&_swigt__p_UValidateError, _p_UValidateErrorTo_p_UException, 0, 0},{0, 0, 0, 0}};
static swig_cast_info _swigc__p_UModbus[] = { {&_swigt__p_UModbus, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_UModbus[] = { {&_swigt__p_UModbus, 0, 0, 0},{0, 0, 0, 0}};
static swig_cast_info _swigc__p_USysError[] = { {&_swigt__p_USysError, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_USysError[] = { {&_swigt__p_USysError, 0, 0, 0},{0, 0, 0, 0}};
static swig_cast_info _swigc__p_UTimeOut[] = { {&_swigt__p_UTimeOut, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_UTimeOut[] = { {&_swigt__p_UTimeOut, 0, 0, 0},{0, 0, 0, 0}};
static swig_cast_info _swigc__p_UValidateError[] = { {&_swigt__p_UValidateError, 0, 0, 0},{0, 0, 0, 0}};
static swig_cast_info _swigc__p_char[] = { {&_swigt__p_char, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_char[] = { {&_swigt__p_char, 0, 0, 0},{0, 0, 0, 0}};
static swig_cast_info *swig_cast_initial[] = { static swig_cast_info *swig_cast_initial[] = {
...@@ -5668,6 +5781,7 @@ static swig_cast_info *swig_cast_initial[] = { ...@@ -5668,6 +5781,7 @@ static swig_cast_info *swig_cast_initial[] = {
_swigc__p_UModbus, _swigc__p_UModbus,
_swigc__p_USysError, _swigc__p_USysError,
_swigc__p_UTimeOut, _swigc__p_UTimeOut,
_swigc__p_UValidateError,
_swigc__p_char, _swigc__p_char,
}; };
......
...@@ -197,6 +197,28 @@ class USysError(UException): ...@@ -197,6 +197,28 @@ class USysError(UException):
USysError_swigregister = _pyUModbus.USysError_swigregister USysError_swigregister = _pyUModbus.USysError_swigregister
USysError_swigregister(USysError) USysError_swigregister(USysError)
class UValidateError(UException):
__swig_setmethods__ = {}
for _s in [UException]:
__swig_setmethods__.update(getattr(_s, '__swig_setmethods__', {}))
__setattr__ = lambda self, name, value: _swig_setattr(self, UValidateError, name, value)
__swig_getmethods__ = {}
for _s in [UException]:
__swig_getmethods__.update(getattr(_s, '__swig_getmethods__', {}))
__getattr__ = lambda self, name: _swig_getattr(self, UValidateError, name)
__repr__ = _swig_repr
def __init__(self, *args):
this = _pyUModbus.new_UValidateError(*args)
try:
self.this.append(this)
except Exception:
self.this = this
__swig_destroy__ = _pyUModbus.delete_UValidateError
__del__ = lambda self: None
UValidateError_swigregister = _pyUModbus.UValidateError_swigregister
UValidateError_swigregister(UValidateError)
# This file is compatible with both classic and new-style classes. # This file is compatible with both classic and new-style classes.
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
*/ */
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
#include <ostream> #include <ostream>
#include <Poco/JSON/Parser.h>
#include "Exceptions.h" #include "Exceptions.h"
#include "UHttpRequestHandler.h" #include "UHttpRequestHandler.h"
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
...@@ -37,11 +38,11 @@ void UHttpRequestHandler::handleRequest( Poco::Net::HTTPServerRequest& req, Poco ...@@ -37,11 +38,11 @@ void UHttpRequestHandler::handleRequest( Poco::Net::HTTPServerRequest& req, Poco
resp.setStatus(HTTPResponse::HTTP_INTERNAL_SERVER_ERROR); resp.setStatus(HTTPResponse::HTTP_INTERNAL_SERVER_ERROR);
resp.setContentType("text/json"); resp.setContentType("text/json");
std::ostream& out = resp.send(); std::ostream& out = resp.send();
nlohmann::json jdata; Poco::JSON::Object::Ptr jdata = new Poco::JSON::Object();
jdata["error"] = resp.getReasonForStatus(resp.getStatus()); jdata->set("error",resp.getReasonForStatus(resp.getStatus()));
jdata["ecode"] = resp.getStatus(); jdata->set("ecode",resp.getStatus());
jdata["message"] = "Unknown 'registry of objects'"; jdata->set("message", "Unknown 'registry of objects'");
out << jdata.dump(); jdata->stringify(out);
out.flush(); out.flush();
return; return;
} }
...@@ -52,11 +53,11 @@ void UHttpRequestHandler::handleRequest( Poco::Net::HTTPServerRequest& req, Poco ...@@ -52,11 +53,11 @@ void UHttpRequestHandler::handleRequest( Poco::Net::HTTPServerRequest& req, Poco
resp.setStatus(HTTPResponse::HTTP_BAD_REQUEST); resp.setStatus(HTTPResponse::HTTP_BAD_REQUEST);
resp.setContentType("text/json"); resp.setContentType("text/json");
std::ostream& out = resp.send(); std::ostream& out = resp.send();
nlohmann::json jdata; Poco::JSON::Object jdata;
jdata["error"] = resp.getReasonForStatus(resp.getStatus()); jdata.set("error", resp.getReasonForStatus(resp.getStatus()));
jdata["ecode"] = resp.getStatus(); jdata.set("ecode", (int)resp.getStatus());
jdata["message"] = "method must be 'GET'"; jdata.set("message", "method must be 'GET'");
out << jdata.dump(); jdata.stringify(out);
out.flush(); out.flush();
return; return;
} }
...@@ -71,18 +72,18 @@ void UHttpRequestHandler::handleRequest( Poco::Net::HTTPServerRequest& req, Poco ...@@ -71,18 +72,18 @@ void UHttpRequestHandler::handleRequest( Poco::Net::HTTPServerRequest& req, Poco
// example: http://host:port/api/version/ObjectName // example: http://host:port/api/version/ObjectName
if( seg.size() < 3 if( seg.size() < 3
|| seg[0] != "api" || seg[0] != "api"
|| seg[1] != UHTTP_API_VERSION || seg[1] != UHTTP_API_VERSION
|| seg[2].empty() ) || seg[2].empty() )
{ {
resp.setStatus(HTTPResponse::HTTP_BAD_REQUEST); resp.setStatus(HTTPResponse::HTTP_BAD_REQUEST);
resp.setContentType("text/json"); resp.setContentType("text/json");
std::ostream& out = resp.send(); std::ostream& out = resp.send();
nlohmann::json jdata; Poco::JSON::Object jdata;
jdata["error"] = resp.getReasonForStatus(resp.getStatus()); jdata.set("error", resp.getReasonForStatus(resp.getStatus()));
jdata["ecode"] = resp.getStatus(); jdata.set("ecode", (int)resp.getStatus());
jdata["message"] = "BAD REQUEST STRUCTURE"; jdata.set("message", "BAD REQUEST STRUCTURE");
out << jdata.dump(); jdata.stringify(out);
out.flush(); out.flush();
return; return;
} }
...@@ -98,49 +99,49 @@ void UHttpRequestHandler::handleRequest( Poco::Net::HTTPServerRequest& req, Poco ...@@ -98,49 +99,49 @@ void UHttpRequestHandler::handleRequest( Poco::Net::HTTPServerRequest& req, Poco
{ {
if( objectName == "help" ) if( objectName == "help" )
{ {
nlohmann::json jdata; out << "{ \"help\": ["
jdata["help"] = "{\"help\": {\"desc\": \"this help\"}},"
{ "{\"list\": {\"desc\": \"list of objects\"}},"
{"help", {"desc", "this help"}}, "{\"ObjectName\": {\"desc\": \"ObjectName information\"}},"
{"list", {"desc", "list of objects"}}, "{\"ObjectName/help\": {\"desc\": \"help for ObjectName\"}},"
{"ObjectName", {"desc", "'ObjectName' information"}}, "{\"apidocs\": {\"desc\": \"https://github.com/Etersoft/uniset2\"}}"
{"ObjectName/help", {"desc", "help for ObjectName"}}, "]}";
{"apidocs", {"desc", "https://github.com/Etersoft/uniset2"}}
};
out << jdata.dump();
} }
else if( objectName == "list" ) else if( objectName == "list" )
{ {
auto json = registry->httpGetObjectsList(qp); auto json = registry->httpGetObjectsList(qp);
out << json.dump(); json->stringify(out);
} }
else if( seg.size() == 4 && seg[3] == "help" ) // /api/version/ObjectName/help else if( seg.size() == 4 && seg[3] == "help" ) // /api/version/ObjectName/help
{ {
auto json = registry->httpHelpByName(objectName, qp); auto json = registry->httpHelpByName(objectName, qp);
out << json.dump(); json->stringify(out);
} }
else if( seg.size() >= 4 ) // /api/version/ObjectName/xxx.. else if( seg.size() >= 4 ) // /api/version/ObjectName/xxx..
{ {
auto json = registry->httpRequestByName(objectName, seg[3], qp); auto json = registry->httpRequestByName(objectName, seg[3], qp);
out << json.dump(); json->stringify(out);
} }
else else
{ {
auto json = registry->httpGetByName(objectName, qp); auto json = registry->httpGetByName(objectName, qp);
out << json.dump(); json->stringify(out);
} }
} }
// catch( Poco::JSON::JSONException jsone )
// {
// std::cout << "JSON ERROR: " << jsone.message() << std::endl;
// }
catch( std::exception& ex ) catch( std::exception& ex )
{ {
ostringstream err; ostringstream err;
err << ex.what(); err << ex.what();
resp.setStatus(HTTPResponse::HTTP_INTERNAL_SERVER_ERROR); resp.setStatus(HTTPResponse::HTTP_INTERNAL_SERVER_ERROR);
resp.setContentType("text/json"); resp.setContentType("text/json");
nlohmann::json jdata; Poco::JSON::Object jdata;
jdata["error"] = err.str(); jdata.set("error", err.str());
jdata["ecode"] = resp.getStatus(); jdata.set("ecode", (int)resp.getStatus());
out << jdata.dump(); jdata.stringify(out);
} }
out.flush(); out.flush();
...@@ -158,7 +159,7 @@ HTTPRequestHandler* UHttpRequestHandlerFactory::createRequestHandler( const HTTP ...@@ -158,7 +159,7 @@ HTTPRequestHandler* UHttpRequestHandlerFactory::createRequestHandler( const HTTP
return new UHttpRequestHandler(registry); return new UHttpRequestHandler(registry);
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
nlohmann::json IHttpRequest::httpRequest( const string& req, const Poco::URI::QueryParameters& p ) Poco::JSON::Object::Ptr IHttpRequest::httpRequest( const string& req, const Poco::URI::QueryParameters& p )
{ {
std::ostringstream err; std::ostringstream err;
err << "(IHttpRequest::Request): " << req << " not supported"; err << "(IHttpRequest::Request): " << req << " not supported";
......
...@@ -203,7 +203,7 @@ void LogServer::evprepare( const ev::loop_ref& eloop ) ...@@ -203,7 +203,7 @@ void LogServer::evprepare( const ev::loop_ref& eloop )
if( mylog.is_crit() ) if( mylog.is_crit() )
mylog.crit() << err.str() << endl; mylog.crit() << err.str() << endl;
throw uniset::SystemError( err.str() ); throw SystemError( err.str() );
} }
try try
...@@ -219,18 +219,7 @@ void LogServer::evprepare( const ev::loop_ref& eloop ) ...@@ -219,18 +219,7 @@ void LogServer::evprepare( const ev::loop_ref& eloop )
if( mylog.is_crit() ) if( mylog.is_crit() )
mylog.crit() << err.str() << endl; mylog.crit() << err.str() << endl;
throw uniset::SystemError( err.str() ); throw SystemError( err.str() );
}
catch( std::exception& ex )
{
ostringstream err;
err << myname << "(evprepare): " << ex.what();
if( mylog.is_crit() )
mylog.crit() << err.str() << endl;
throw uniset::SystemError( err.str() );
} }
sock->setBlocking(false); sock->setBlocking(false);
...@@ -357,24 +346,24 @@ string LogServer::getShortInfo() ...@@ -357,24 +346,24 @@ string LogServer::getShortInfo()
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#ifndef DISABLE_REST_API #ifndef DISABLE_REST_API
nlohmann::json LogServer::httpGetShortInfo() Poco::JSON::Object::Ptr LogServer::httpGetShortInfo()
{ {
nlohmann::json jdata; Poco::JSON::Object::Ptr jdata = new Poco::JSON::Object();
jdata["name"] = myname; jdata->set("name", myname);
jdata["host"] = addr; jdata->set("host", addr);
jdata["port"] = port; jdata->set("port", port);
jdata["sessMaxCount"] = sessMaxCount; jdata->set("sessMaxCount", sessMaxCount);
{ {
uniset_rwmutex_rlock l(mutSList); uniset_rwmutex_rlock l(mutSList);
auto& jsess = jdata["sessions"]; Poco::JSON::Array::Ptr jsess = new Poco::JSON::Array();
jdata->set("sessions",jsess);
for( const auto& s : slist ) for( const auto& s : slist )
jsess.push_back(s->httpGetShortInfo()); jsess->add(s->httpGetShortInfo());
} }
return std::move(jdata); return jdata;
} }
#endif // #ifndef DISABLE_REST_API #endif // #ifndef DISABLE_REST_API
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
......
...@@ -677,9 +677,9 @@ string LogSession::getShortInfo() noexcept ...@@ -677,9 +677,9 @@ string LogSession::getShortInfo() noexcept
} }
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
#ifndef DISABLE_REST_API #ifndef DISABLE_REST_API
nlohmann::json LogSession::httpGetShortInfo() Poco::JSON::Object::Ptr LogSession::httpGetShortInfo()
{ {
nlohmann::json jret; Poco::JSON::Object::Ptr jret = new Poco::JSON::Object();
size_t sz = 0; size_t sz = 0;
{ {
...@@ -687,17 +687,18 @@ nlohmann::json LogSession::httpGetShortInfo() ...@@ -687,17 +687,18 @@ nlohmann::json LogSession::httpGetShortInfo()
sz = logbuf.size(); sz = logbuf.size();
} }
auto& jdata = jret[caddr]; Poco::JSON::Object::Ptr jdata = new Poco::JSON::Object();
jret->set(caddr,jdata);
jdata["client"] = caddr; jdata->set("client", caddr);
jdata["maxbufsize"] = maxRecordsNum; jdata->set("maxbufsize", maxRecordsNum);
jdata["bufsize"] = sz; jdata->set("bufsize", sz);
jdata["maxCount"] = maxCount; jdata->set("maxCount", maxCount);
jdata["minSizeMsg"] = minSizeMsg; jdata->set("minSizeMsg", minSizeMsg);
jdata["maxSizeMsg"] = maxSizeMsg; jdata->set("maxSizeMsg", maxSizeMsg);
jdata["numLostMsg"] = numLostMsg; jdata->set("numLostMsg", numLostMsg);
return std::move(jret); return jret;
} }
#endif // #ifndef DISABLE_REST_API #endif // #ifndef DISABLE_REST_API
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
......
...@@ -529,16 +529,14 @@ void UniSetActivator::init() ...@@ -529,16 +529,14 @@ void UniSetActivator::init()
abortScript = conf->getArgParam("--uniset-abort-script", ""); abortScript = conf->getArgParam("--uniset-abort-script", "");
#ifndef DISABLE_REST_API #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");
ostringstream s; ostringstream s;
s << (getId() == DefaultObjectId ? 8080 : getId() ); s << (getId()==DefaultObjectId ? 8080 : getId() );
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 #endif
orb = conf->getORB(); orb = conf->getORB();
...@@ -670,13 +668,12 @@ void UniSetActivator::run( bool thread ) ...@@ -670,13 +668,12 @@ void UniSetActivator::run( bool thread )
set_signals(true); set_signals(true);
#ifndef DISABLE_REST_API #ifndef DISABLE_REST_API
if( !httpHost.empty() ) if( !httpHost.empty() )
{ {
try try
{ {
auto reg = dynamic_pointer_cast<UHttp::IHttpRequestRegistry>(shared_from_this()); auto reg = dynamic_pointer_cast<UHttp::IHttpRequestRegistry>(shared_from_this());
httpserv = make_shared<UHttp::UHttpServer>(reg, httpHost, httpPort); httpserv = make_shared<UHttp::UHttpServer>(reg,httpHost,httpPort);
httpserv->start(); httpserv->start();
} }
catch( std::exception& ex ) catch( std::exception& ex )
...@@ -684,7 +681,6 @@ void UniSetActivator::run( bool thread ) ...@@ -684,7 +681,6 @@ 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 #endif
if( thread ) if( thread )
...@@ -723,10 +719,8 @@ void UniSetActivator::stop() ...@@ -723,10 +719,8 @@ void UniSetActivator::stop()
ulogsys << myname << "(stop): discard request ok." << endl; ulogsys << myname << "(stop): discard request ok." << endl;
#ifndef DISABLE_REST_API #ifndef DISABLE_REST_API
if( httpserv ) if( httpserv )
httpserv->stop(); httpserv->stop();
#endif #endif
} }
...@@ -876,13 +870,12 @@ UniSetActivator::TerminateEvent_Signal UniSetActivator::signal_terminate_event() ...@@ -876,13 +870,12 @@ UniSetActivator::TerminateEvent_Signal UniSetActivator::signal_terminate_event()
} }
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
#ifndef DISABLE_REST_API #ifndef DISABLE_REST_API
nlohmann::json UniSetActivator::httpGetByName( const string& name, const Poco::URI::QueryParameters& p ) Poco::JSON::Object::Ptr UniSetActivator::httpGetByName( const string& name, const Poco::URI::QueryParameters& p )
{ {
if( name == myname ) if( name == myname )
return httpGet(p); return httpGet(p);
auto obj = deepFindObject(name); auto obj = deepFindObject(name);
if( obj ) if( obj )
return obj->httpGet(p); return obj->httpGet(p);
...@@ -892,30 +885,29 @@ nlohmann::json UniSetActivator::httpGetByName( const string& name, const Poco::U ...@@ -892,30 +885,29 @@ nlohmann::json UniSetActivator::httpGetByName( const string& name, const Poco::U
throw uniset::NameNotFound(err.str()); throw uniset::NameNotFound(err.str());
} }
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
nlohmann::json UniSetActivator::httpGetObjectsList( const Poco::URI::QueryParameters& p ) Poco::JSON::Array::Ptr UniSetActivator::httpGetObjectsList( const Poco::URI::QueryParameters& p )
{ {
nlohmann::json jdata; Poco::JSON::Array::Ptr jdata = new Poco::JSON::Array();
std::vector<std::shared_ptr<UniSetObject>> vec; std::vector<std::shared_ptr<UniSetObject>> vec;
vec.reserve(objectsCount()); vec.reserve(objectsCount());
//! \todo Доделать обработку параметров beg,lim на случай большого количества объектов (и частичных запросов) //! \todo Доделать обработку параметров beg,lim на случай большого количества объектов (и частичных запросов)
size_t lim = 1000; size_t lim = 1000;
getAllObjectsList(vec, lim); getAllObjectsList(vec,lim);
for( const auto& o : vec ) for( const auto& o: vec )
jdata.push_back(o->getName()); jdata->add(o->getName());
return jdata; return jdata;
} }
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
nlohmann::json UniSetActivator::httpHelpByName( const string& name, const Poco::URI::QueryParameters& p ) Poco::JSON::Object::Ptr UniSetActivator::httpHelpByName( const string& name, const Poco::URI::QueryParameters& p )
{ {
if( name == myname ) if( name == myname )
return httpHelp(p); return httpHelp(p);
auto obj = deepFindObject(name); auto obj = deepFindObject(name);
if( obj ) if( obj )
return obj->httpHelp(p); return obj->httpHelp(p);
...@@ -924,15 +916,14 @@ nlohmann::json UniSetActivator::httpHelpByName( const string& name, const Poco:: ...@@ -924,15 +916,14 @@ nlohmann::json UniSetActivator::httpHelpByName( const string& name, const Poco::
throw uniset::NameNotFound(err.str()); throw uniset::NameNotFound(err.str());
} }
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
nlohmann::json UniSetActivator::httpRequestByName( const string& name, const std::string& req, const Poco::URI::QueryParameters& p) Poco::JSON::Object::Ptr UniSetActivator::httpRequestByName( const string& name, const std::string& req, const Poco::URI::QueryParameters& p)
{ {
if( name == myname ) if( name == myname )
return httpRequest(req, p); return httpRequest(req,p);
auto obj = deepFindObject(name); auto obj = deepFindObject(name);
if( obj ) if( obj )
return obj->httpRequest(req, p); return obj->httpRequest(req,p);
ostringstream err; ostringstream err;
err << "Object '" << name << "' not found"; err << "Object '" << name << "' not found";
......
...@@ -383,27 +383,25 @@ void UniSetObject::push( const TransportMessage& tm ) ...@@ -383,27 +383,25 @@ void UniSetObject::push( const TransportMessage& tm )
} }
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
#ifndef DISABLE_REST_API #ifndef DISABLE_REST_API
nlohmann::json UniSetObject::httpGet( const Poco::URI::QueryParameters& p ) Poco::JSON::Object::Ptr UniSetObject::httpGet( const Poco::URI::QueryParameters& p )
{ {
nlohmann::json jret; Poco::JSON::Object::Ptr jret = new Poco::JSON::Object();
auto& jdata = jret[myname]; Poco::JSON::Object::Ptr jdata = uniset::json::make_child(jret,myname);
jdata["name"] = myname; jdata->set("name",myname);
jdata["id"] = getId(); jdata->set("id", getId());
jdata["msgCount"] = countMessages(); jdata->set("msgCount", countMessages());
jdata["lostMessages"] = getCountOfLostMessages(); jdata->set("lostMessages", getCountOfLostMessages());
jdata["maxSizeOfMessageQueue"] = getMaxSizeOfMessageQueue(); jdata->set("maxSizeOfMessageQueue", getMaxSizeOfMessageQueue());
jdata["isActive"] = isActive(); jdata->set("isActive", isActive());
jdata["objectType"] = getType(); jdata->set("objectType", getType());
return jret; return jret;
} }
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
nlohmann::json UniSetObject::httpHelp( const Poco::URI::QueryParameters& p ) Poco::JSON::Object::Ptr UniSetObject::httpHelp( const Poco::URI::QueryParameters& p )
{ {
nlohmann::json jdata; uniset::json::help::object myhelp(myname);
jdata[myname]["help"] = {}; return myhelp;
return jdata;
} }
#endif #endif
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
......
...@@ -6,7 +6,8 @@ noinst_LTLIBRARIES = libVarious.la ...@@ -6,7 +6,8 @@ noinst_LTLIBRARIES = libVarious.la
libVarious_la_CPPFLAGS = $(SIGC_CFLAGS) $(POCO_CFLAGS) libVarious_la_CPPFLAGS = $(SIGC_CFLAGS) $(POCO_CFLAGS)
libVarious_la_LIBADD = $(SIGC_LIBS) $(POCO_LIBS) libVarious_la_LIBADD = $(SIGC_LIBS) $(POCO_LIBS)
libVarious_la_SOURCES = UniXML.cc MessageType.cc Configuration.cc MQMutex.cc MQAtomic.cc \ libVarious_la_SOURCES = UniXML.cc MessageType.cc Configuration.cc MQMutex.cc MQAtomic.cc \
Restorer_XML.cc RunLock.cc Mutex.cc SViewer.cc SMonitor.cc LT_Object.cc WDTInterface.cc VMonitor.cc Restorer_XML.cc RunLock.cc Mutex.cc SViewer.cc SMonitor.cc LT_Object.cc WDTInterface.cc VMonitor.cc \
ujson.cc
local-clean: local-clean:
rm -rf *iSK.cc rm -rf *iSK.cc
......
...@@ -2,89 +2,92 @@ ...@@ -2,89 +2,92 @@
#include <iostream> #include <iostream>
#include <memory> #include <memory>
#include "UHttpServer.h" #include "UHttpServer.h"
#include <Poco/JSON/Object.h>
#include "ujson.h"
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
using namespace std; using namespace std;
using namespace uniset; using namespace uniset;
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
class UTestSupplier: class UTestSupplier:
public UHttp::IHttpRequest public UHttp::IHttpRequest
{ {
public: public:
UTestSupplier() {} UTestSupplier(){}
virtual ~UTestSupplier() {} virtual ~UTestSupplier(){}
virtual nlohmann::json httpGet( const Poco::URI::QueryParameters& params ) override virtual Poco::JSON::Object::Ptr httpGet( const Poco::URI::QueryParameters& params ) override
{ {
nlohmann::json j; Poco::JSON::Object::Ptr j = new Poco::JSON::Object();
for( const auto& p : params ) for( const auto& p: params )
j[p.first] = p.second; j->set(p.first,p.second);
j["test"] = 42; j->set("test",42);
return j; return j;
} }
virtual nlohmann::json httpHelp( const Poco::URI::QueryParameters& p ) override virtual Poco::JSON::Object::Ptr httpHelp( const Poco::URI::QueryParameters& p ) override
{ {
nlohmann::json j; uniset::json::help::object myhelp("test");
j["test"]["help"] =
{
{"cmd1", "help for cmd1"},
{"cmd2", "help for cmd2"}
};
return j; uniset::json::help::item cmd1("description for cmd1");
cmd1.param("p1","description of p1");
cmd1.param("p2","description of p1");
cmd1.param("p3","description of p1");
myhelp.add(cmd1);
uniset::json::help::item cmd2("description for cmd2");
cmd2.param("p1","description of p1");
cmd2.param("p2","description of p1");
cmd2.param("p3","description of p1");
myhelp.add(cmd2);
cmd1.param("p4","description of p4");
myhelp.add(cmd1);
return myhelp;
} }
virtual nlohmann::json httpRequest( const std::string& req, const Poco::URI::QueryParameters& p ) override virtual Poco::JSON::Object::Ptr httpRequest( const std::string& req, const Poco::URI::QueryParameters& p ) override
{ {
nlohmann::json j; Poco::JSON::Object::Ptr j = new Poco::JSON::Object();
j[req] = "OK"; j->set(req,"OK");
return j; return j;
} }
}; };
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
class UTestRequestRegistry: class UTestRequestRegistry:
public UHttp::IHttpRequestRegistry public UHttp::IHttpRequestRegistry
{ {
public: public:
UTestRequestRegistry() {} UTestRequestRegistry(){}
virtual ~UTestRequestRegistry() {} virtual ~UTestRequestRegistry(){}
virtual nlohmann::json httpGetByName( const std::string& name, const Poco::URI::QueryParameters& p ) override virtual Poco::JSON::Object::Ptr httpGetByName( const std::string& name, const Poco::URI::QueryParameters& p ) override
{ {
nlohmann::json j = sup.httpGet(p); Poco::JSON::Object::Ptr j = sup.httpGet(p);
j["name"] = name; j->set("name",name);
return j; return j;
} }
virtual nlohmann::json httpGetObjectsList( const Poco::URI::QueryParameters& p ) override virtual Poco::JSON::Array::Ptr httpGetObjectsList( const Poco::URI::QueryParameters& p ) override
{ {
nlohmann::json j; Poco::JSON::Array::Ptr j = new Poco::JSON::Array();
j.push_back("TestObject"); j->add("TestObject");
j.push_back("TestObject2"); j->add("TestObject2");
j.push_back("TestObject3"); j->add("TestObject3");
return j; return j;
} }
virtual nlohmann::json httpHelpByName( const std::string& name, const Poco::URI::QueryParameters& p ) override virtual Poco::JSON::Object::Ptr httpHelpByName( const std::string& name, const Poco::URI::QueryParameters& p ) override
{ {
nlohmann::json j; return sup.httpHelp(p);
j["TestObject"]["help"] =
{
{"cmd1", "help for cmd1"},
{"cmd2", "help for cmd2"}
};
return j;
} }
virtual nlohmann::json httpRequestByName( const std::string& name, const std::string& req, const Poco::URI::QueryParameters& p ) override virtual Poco::JSON::Object::Ptr httpRequestByName( const std::string& name, const std::string& req, const Poco::URI::QueryParameters& p ) override
{ {
nlohmann::json j; return sup.httpRequest(req,p);
j[name][req] = "OK";
return j;
} }
...@@ -96,13 +99,79 @@ int main(int argc, const char** argv) ...@@ -96,13 +99,79 @@ int main(int argc, const char** argv)
{ {
try try
{ {
// Poco::JSON::Object::Ptr j = new Poco::JSON::Object();
// {
// Poco::DynamicStruct data;
// Poco::Dynamic::Array objects;
// Poco::DynamicStruct object;
// object["id"] = 4565;
// object["size"] = 2.64;
// object["name"] = "Foo";
// object["active"] = false;
// objects.push_back(object);
// data["objects"] = objects;
// data["count"] = 1;
// std::string s = data.toString();
// std::cout << s << std::endl;
// Poco::DynamicAny result_s = Poco::DynamicAny::parse(s);
// std::cout << result_s.toString() << std::endl;
// j->set("test",object);
// }
// j->stringify(std::cout);
// cout << endl;
// Poco::JSON::Object::Ptr j = new Poco::JSON::Object();
// j->set("test",23);
// j->set("test2","sdfsdf");
// j->set("test3",232.4);
// Poco::JSON::Object::Ptr j2 = new Poco::JSON::Object();
// j2->set("rr",23);
// j2->set("rr2",23);
// j2->set("rr3",23);
// Poco::JSON::Array::Ptr j3 = new Poco::JSON::Array();
// j3->set(1,23);
// j3->set(2,23);
// j3->set(3,23);
// j->set("Object2",j2);
// j->set("Object3",j3);
// j->stringify(std::cerr);
// cerr << endl;
// return 0;
// auto j = uniset::json::make_object("key","weweew");
// j->set("key2","wefwefefr");
// auto j2 = uniset::json::make_object("key",j);
//// uniset::json j;
//// j["key"] = "werwe";
//// j["key"]["key2"] = "werwe";
// j2->stringify(cerr);
// return 0;
auto reg = std::make_shared<UTestRequestRegistry>(); auto reg = std::make_shared<UTestRequestRegistry>();
auto ireg = dynamic_pointer_cast<UHttp::IHttpRequestRegistry>(reg); auto ireg = dynamic_pointer_cast<UHttp::IHttpRequestRegistry>(reg);
auto http = make_shared<UHttp::UHttpServer>(ireg, "localhost", 5555); auto http = make_shared<UHttp::UHttpServer>(ireg,"localhost", 5555);
http->log()->level(Debug::ANY); http->log()->level(Debug::ANY);
cout << "start http test server localhost:5555" << endl; cout << "start http test server localhost:5555" << endl;
http->start(); http->start();
pause(); pause();
......
...@@ -342,6 +342,7 @@ include/WDTInterface.h ...@@ -342,6 +342,7 @@ include/WDTInterface.h
include/UHelpers.h include/UHelpers.h
include/UHttpRequestHandler.h include/UHttpRequestHandler.h
include/UHttpServer.h include/UHttpServer.h
include/ujson.h
lib/Makefile.am lib/Makefile.am
python/examples/test.xml python/examples/test.xml
python/lib/pyUniSet/Makefile.am python/lib/pyUniSet/Makefile.am
...@@ -443,6 +444,7 @@ src/Various/UniXML.cc ...@@ -443,6 +444,7 @@ src/Various/UniXML.cc
src/Various/WDTInterface.cc src/Various/WDTInterface.cc
src/Various/MQMutex.cc src/Various/MQMutex.cc
src/Various/MQAtomic.cc src/Various/MQAtomic.cc
src/Various/ujson.cc
src/Makefile.am src/Makefile.am
tests/UniXmlTest/Makefile.am tests/UniXmlTest/Makefile.am
tests/UniXmlTest/XmlTest.cc tests/UniXmlTest/XmlTest.cc
......
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