Commit 7bda9575 authored by Pavel Vainerman's avatar Pavel Vainerman

backported to p8 as 2.7-alt6.M80P.7 (with rpmbph script)

parents d473d6ec 5b8d5825
......@@ -110,6 +110,8 @@ int main( int argc, char** argv )
if( f485 )
{
#ifndef DISABLE_COMPORT_485F
ComPort485F* cp;
if( dev == "/dev/ttyS2" )
......@@ -126,6 +128,10 @@ int main( int argc, char** argv )
mbs.setLog(dlog);
mbs.setVerbose(verb);
mbs.execute();
#else
cerr << "DISABLE_COMPORT_485F" << endl;
return 1;
#endif // #ifndef DISABLE_COMPORT_485F
}
else
{
......
......@@ -14,12 +14,13 @@
%def_disable netdata
%def_enable api
%def_enable logdb
%def_enable com485f
%define oname uniset2
Name: libuniset2
Version: 2.7
Release: alt3.M80P.4
Release: alt6.M80P.7
Summary: UniSet - library for building distributed industrial control systems
License: LGPL
......@@ -313,22 +314,12 @@ Requires: %name-extension-common-devel = %version-%release
Libraries needed to develop for uniset MQTT extension
%endif
%package extension-smplus
Group: Development/C++
Summary: libUniSet2 SharedMemoryPlus extension ('all in one')
Requires: %name-extension-common = %version-%release
%description extension-smplus
SharedMemoryPlus extension ('all in one') for libuniset
%prep
%setup
%build
%autoreconf
%configure %{subst_enable docs} %{subst_enable mysql} %{subst_enable sqlite} %{subst_enable pgsql} %{subst_enable python} %{subst_enable rrd} %{subst_enable io} %{subst_enable logicproc} %{subst_enable tests} %{subst_enable mqtt} %{subst_enable api} %{subst_enable netdata} %{subst_enable logdb}
%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} %{subst_enable netdata} %{subst_enable logdb} %{subst_enable com485f}
%make_build
# fix for ALTLinux build (noarch)
......@@ -520,9 +511,23 @@ rm -f %buildroot%_libdir/*.la
# history of current unpublished changes
%changelog
* Fri Feb 23 2018 Pavel Vainerman <pv@altlinux.ru> 2.7-alt3.M80P.4
* Wed May 09 2018 Pavel Vainerman <pv@altlinux.ru> 2.7-alt6.M80P.7
- backport to ALTLinux p8 (by rpmbph script)
* Tue May 08 2018 Pavel Vainerman <pv@altlinux.ru> 2.7-alt7
- (http): added support "CORS" (Access-Control-Allow-Origin)
- (logdb): added --logdb-httpserver-reply-addr host:port
- minor fixes in LogSession
* Tue Apr 03 2018 Pavel Vainerman <pv@altlinux.ru> 2.7-alt6
- new minor release
# * Wed Mar 28 2018 Vinogradov Aleksei <uzum@server> 2.7-alt5
# - test build after rebase pv/master
* Fri Mar 09 2018 Alexei Takaseev <taf@altlinux.org> 2.7-alt4.1
- Rebuild with poco 1.9.0
* Wed Feb 21 2018 Pavel Vainerman <pv@altlinux.ru> 2.7-alt4
- (omniThread): fix compile error for 'const' function and other minor fixes
......
......@@ -7,6 +7,7 @@ load_mod spec
REL=eter
MAILDOMAIN=server
OPTS=$*
[ -z "$TOPDIR" ] && TOPDIR=/var/ftp/pub/Ourside
......@@ -16,10 +17,10 @@ SPECNAME=libuniset2.spec
if [ -z "$PLATFORM" ]; then
PLATFORM=i586
[[ `uname -m` == "x86_64" ]] && PLATFORM=x86_64
[[ `uname -m` == "aarch64" ]] && PLATFORM=aarch64
fi
PROJECT=$1
test -n "$PROJECT" || PROJECT=$PKGNAME
PROJECT=$PKGNAME
[ -z "$GEN" ] && GEN=/var/ftp/pub/Ourside/$PLATFORM/genb.sh
[ -a "$GEN" ] || GEN="genbasedir --create --progress --topdir=$TOPDIR $PLATFORM $PROJECT"
......@@ -89,7 +90,7 @@ else
add_changelog_helper "- new build" $SPECNAME
fi
rpmbb ${UNISET_BUILD_ADDON_OPTIONS} $SPECNAME || fatal "Can't build"
rpmbb ${UNISET_BUILD_ADDON_OPTIONS} ${OPTS} $SPECNAME || fatal "Can't build"
cp2ftp
......
#!/bin/sh
./release_helper.sh --disable=com485f --disable=mqtt --disable=docs
......@@ -199,6 +199,31 @@ fi
AM_CONDITIONAL(DISABLE_IO, test ${buildio} = false)
AM_CONDITIONAL(ENABLE_IO, test ${buildio} = true)
#check sys/io.h support
AC_MSG_CHECKING([sys/io.h support])
buildcom485f=true
#AC_CHECK_HEADERS
AC_ARG_ENABLE(com485f, AC_HELP_STRING([--disable-com485f], [disable sys/io.h support]),
[ if test $enableval = yes; then buildcom485f=true; else buildcom485f=false; fi],[ buildcom485f=true; ])
COMPORT_485F_CFLAGS=
COMPORT_485F_CLIBS=
DISABLE_COMPORT_485F=
if test ${buildcom485f} = true; then
AC_MSG_RESULT([enabled])
else
AC_MSG_RESULT([disabled])
COMPORT_485F_CFLAGS="-DDISABLE_COMPORT_485F"
DISABLE_COMPORT_485F=1
fi
AM_CONDITIONAL(DISABLE_COMPORT_485F, test ${buildcom485f} = false)
AC_SUBST(DISABLE_COMPORT_485F)
AC_SUBST(COMPORT_485F_CFLAGS)
#AC_SUBST(COMPORT_485F_CLIBS)
#check logicproc build
AC_MSG_CHECKING([build logic processor extension])
buildlproc=true
......@@ -415,7 +440,7 @@ CXX_EXTRA_FLAGS="-Wnon-virtual-dtor -Woverloaded-virtual -Woverflow -D_GLIBCXX_U
# export
LDFLAGS="$LDFLAGS ${OMNI_LIBS} ${XML_LIBS} ${SIGC_LIBS} ${COV_LIBS} ${POCO_LIBS} ${EV_LIBS}"
# all developer liked options add to autogen.sh, please
CXXFLAGS="-I\$(top_builddir)/include $CXXFLAGS -funsigned-char -std=c++11 -g -DCATCH_VERSION_MAJOR=${CATCH_VERSION_MAJOR} -D_GNU_SOURCE ${REST_API_CFLAGS} ${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 -DCATCH_VERSION_MAJOR=${CATCH_VERSION_MAJOR} -D_GNU_SOURCE ${REST_API_CFLAGS} ${COMPORT_485F_CFLAGS} ${OMNI_CFLAGS} ${XML_CFLAGS} ${SIGC_CFLAGS} ${COV_CFLAGS} ${POCO_CFLAGS} ${EV_CFLAGS} $CXX_EXTRA_FLAGS"
AC_SUBST(LDFLAGS)
AC_SUBST(CXXFLAGS)
......
......@@ -42,10 +42,10 @@ ComediInterface::~ComediInterface()
}
// -----------------------------------------------------------------------------
int ComediInterface::getAnalogChannel( int subdev, int channel, int range, int aref ) const
int ComediInterface::getAnalogChannel( int subdev, int channel, int range, int aref, int adelay ) const
{
lsampl_t data = 0;
int ret = comedi_data_read(card, subdev, channel, range, aref, &data);
int ret = comedi_data_read_delayed(card, subdev, channel, range, aref, &data, adelay);
if( ret < 0 )
{
......
......@@ -32,7 +32,7 @@ namespace uniset
virtual ~ComediInterface();
// throw uniset::Exception
virtual int getAnalogChannel( int subdev, int channel, int range = 0, int aref = AREF_GROUND ) const;
virtual int getAnalogChannel( int subdev, int channel, int range = 0, int aref = AREF_GROUND, int adelay = 10 * 1000 ) const; // adelay = 10 мкс
// throw uniset::Exception
virtual void setAnalogChannel( int subdev, int channel, int data, int range = 0, int aref = AREF_GROUND ) const;
......
......@@ -37,7 +37,7 @@ namespace uniset
{
os << "(" << inf.si.id << ")" << uniset_conf()->oind->getMapName(inf.si.id)
<< " card=" << inf.ncard << " channel=" << inf.channel << " subdev=" << inf.subdev
<< " aref=" << inf.aref << " range=" << inf.range
<< " aref=" << inf.aref << " range=" << inf.range << " adelay=" << inf.adelay
<< " default=" << inf.defval << " safeval=" << inf.safeval;
if( inf.cal.minRaw != inf.cal.maxRaw )
......@@ -599,7 +599,7 @@ namespace uniset
{
if( it->stype == UniversalIO::AI )
{
int val = card->getAnalogChannel(it->subdev, it->channel, it->range, it->aref);
int val = card->getAnalogChannel(it->subdev, it->channel, it->range, it->aref, it->adelay);
iolog3 << myname << "(iopoll): read AI "
<< " sid=" << it->si.id
......@@ -869,6 +869,7 @@ namespace uniset
inf->disable_testmode = IOBase::initIntProp(it, "disable_testmode", prop_prefix, false);
inf->aref = 0;
inf->range = 0;
inf->adelay = 10000;
if( inf->stype == UniversalIO::AI || inf->stype == UniversalIO::AO )
{
......@@ -891,6 +892,8 @@ namespace uniset
<< ". Must be aref=[0..3]" << endl;
return false;
}
inf->adelay = IOBase::initIntProp(it, "adelay", prop_prefix, false);
}
iolog3 << myname << "(readItem): add: " << inf->stype << " " << inf << endl;
......@@ -1019,7 +1022,7 @@ namespace uniset
else if( it->stype == UniversalIO::AI )
{
card->configureChannel(it->subdev, it->channel, ComediInterface::AI);
it->df.init( card->getAnalogChannel(it->subdev, it->channel, it->range, it->aref) );
it->df.init( card->getAnalogChannel(it->subdev, it->channel, it->range, it->aref, it->adelay) );
}
else if( it->stype == UniversalIO::AO )
card->configureChannel(it->subdev, it->channel, ComediInterface::AO);
......
......@@ -276,6 +276,8 @@ namespace uniset
3 - analog ref = other (undefined)
*/
int aref;
int adelay; /*! Задержка на чтение аналоговых входов с мультиплексированием ( в мкс ) */
/*! Измерительный диапазон
0 - -10В - 10В
......
......@@ -72,6 +72,7 @@ int subdev = 0;
int chan = 0;
int range = 0;
int aref = AREF_GROUND;
int adelay = 10 * 1000; // 10 мкс
static struct option longopts[] =
{
......@@ -79,6 +80,7 @@ static struct option longopts[] =
{ "read", required_argument, 0, 'r' },
{ "subdev", required_argument, 0, 's' },
{ "aref", required_argument, 0, 'a' },
{ "adelay", required_argument, 0, 'y' },
{ "range", required_argument, 0, 'x' },
{ "device", required_argument, 0, 'd' },
{ "open_xml", required_argument, 0, 'o' },
......@@ -143,6 +145,10 @@ int main(int argc, char* argv[])
range = uni_atoi(optarg);
break;
case 'y':
adelay = atoi(optarg);
break;
case 'a':
aref = uni_atoi(optarg);
break;
......@@ -202,7 +208,7 @@ int main(int argc, char* argv[])
while(1)
{
if(comedi_data_read(card, subdev, chan, range, aref, &data) < 0)
if(comedi_data_read_delayed(card, subdev, chan, range, aref, &data, adelay) < 0)
{
fprintf(stderr, "can't read from channel %d\n", chan);
exit(EXIT_FAILURE);
......
......@@ -28,6 +28,7 @@
int subdev = 0;
int range = 0;
int aref = AREF_GROUND;
int adelay = 10 * 1000; // 10 мкс
int chan[50];
int blink_msec = 300;
......@@ -42,6 +43,7 @@ static struct option longopts[] =
{ "device", required_argument, 0, 'd' },
{ "verbose", no_argument, 0, 'v' },
{ "aref", required_argument, 0, 'z' },
{ "adelay", required_argument, 0, 'y' },
{ "range", required_argument, 0, 'x' },
{ "config", required_argument, 0, 'c' },
{ "autoconf", no_argument, 0, 'a' },
......@@ -174,6 +176,10 @@ int main(int argc, char* argv[])
range = atoi(optarg);
break;
case 'y':
adelay = atoi(optarg);
break;
case 'z':
aref = atoi(optarg);
break;
......@@ -312,7 +318,7 @@ int main(int argc, char* argv[])
if( autoconf )
insn_config(card, subdev, chan[k], 100, range, aref);
int ret = comedi_data_read(card, subdev, chan[k], range, aref, &data);
int ret = comedi_data_read_delayed(card, subdev, chan[k], range, aref, &data, adelay);
if( ret < 0)
{
......
......@@ -96,7 +96,7 @@ namespace uniset
}
// -----------------------------------------------------------------------------
int FakeComediInterface::getAnalogChannel(int subdev, int channel, int range, int aref) const
int FakeComediInterface::getAnalogChannel(int subdev, int channel, int range, int aref, int adelay ) const
{
if( channel < 0 || channel > maxChannelNum )
{
......
......@@ -46,7 +46,7 @@ namespace uniset
// --------------------------------------------
// при тестировании параметры range,aref,subdev игнорируются!
virtual int getAnalogChannel( int subdev, int channel, int range = 0, int aref = AREF_GROUND ) const override;
virtual int getAnalogChannel( int subdev, int channel, int range = 0, int aref = AREF_GROUND, int adelay = 10 * 1000 ) const override;
virtual void setAnalogChannel( int subdev, int channel, int data, int range = 0, int aref = AREF_GROUND ) const override;
......
......@@ -57,7 +57,6 @@ LogDB::LogDB( const string& name, int argc, const char* const* argv, const strin
auto conf = uniset_conf();
xml = conf->getConfXML();
conf->initLogStream(dblog, prefix + "log" );
}
else
{
......@@ -86,6 +85,17 @@ LogDB::LogDB( const string& name, int argc, const char* const* argv, const strin
UniXML::iterator it(cnode);
if( specconfig.empty() )
uniset_conf()->initLogStream(dblog, prefix + "log" );
else
{
// инициализируем сами, т.к. conf нету..
const std::string loglevels = uniset::getArg2Param("--" + prefix + "log-add-levels", argc, argv, it.getProp("log"),"");
if( !loglevels.empty() )
dblog->level(Debug::value(loglevels));
}
qbufSize = uniset::getArgPInt("--" + prefix + "db-buffer-size", argc, argv, it.getProp("dbBufferSize"), qbufSize);
maxdbRecords = uniset::getArgPInt("--" + prefix + "db-max-records", argc, argv, it.getProp("dbMaxRecords"), qbufSize);
maxwsocks = uniset::getArgPInt("--" + prefix + "ws-max", argc, argv, it.getProp("wsMax"), maxwsocks);
......@@ -220,6 +230,9 @@ LogDB::LogDB( const string& name, int argc, const char* const* argv, const strin
httpHost = uniset::getArgParam("--" + prefix + "httpserver-host", argc, argv, "localhost");
httpPort = uniset::getArgInt("--" + prefix + "httpserver-port", argc, argv, "8080");
httpCORS_allow = uniset::getArgParam("--" + prefix + "httpserver-cors-allow", argc, argv, httpCORS_allow);
httpReplyAddr = uniset::getArgParam("--" + prefix + "httpserver-reply-addr", argc, argv, "");
dblog1 << myname << "(init): http server parameters " << httpHost << ":" << httpPort << endl;
Poco::Net::SocketAddress sa(httpHost, httpPort);
......@@ -445,10 +458,12 @@ void LogDB::help_print()
cout << "--prefix-ls-read-buffer-size num - Размер буфера для чтения сообщений от логсервера. По умолчанию: 10001" << endl;
cout << "http: " << endl;
cout << "--prefix-httpserver-host ip - IP на котором слушает http сервер. По умолчанию: localhost" << endl;
cout << "--prefix-httpserver-port num - Порт на котором принимать запросы. По умолчанию: 8080" << endl;
cout << "--prefix-httpserver-max-queued num - Размер очереди запросов к http серверу. По умолчанию: 100" << endl;
cout << "--prefix-httpserver-max-threads num - Разрешённое количество потоков для http-сервера. По умолчанию: 3" << endl;
cout << "--prefix-httpserver-host ip - IP на котором слушает http сервер. По умолчанию: localhost" << endl;
cout << "--prefix-httpserver-port num - Порт на котором принимать запросы. По умолчанию: 8080" << endl;
cout << "--prefix-httpserver-max-queued num - Размер очереди запросов к http серверу. По умолчанию: 100" << endl;
cout << "--prefix-httpserver-max-threads num - Разрешённое количество потоков для http-сервера. По умолчанию: 3" << endl;
cout << "--prefix-httpserver-cors-allow addr - (CORS): Access-Control-Allow-Origin. Default: *" << endl;
cout << "--prefix-httpserver-reply-addr host[:port] - Адрес отдаваемый клиенту для подключения. По умолчанию адрес узла где запущен logdb" << endl;
}
// -----------------------------------------------------------------------------
void LogDB::run( bool async )
......@@ -708,9 +723,10 @@ void LogDB::Log::write( ev::io& io )
if( ret < 0 )
{
dbwarn << peername << "(write): write to socket error(" << errno << "): " << strerror(errno) << endl;
int errnum = errno;
dbwarn << peername << "(write): write to socket error(" << errnum << "): " << strerror(errnum) << endl;
if( errno == EPIPE || errno == EBADF )
if( errnum == EPIPE || errnum == EBADF )
{
dbwarn << peername << "(write): write error.. terminate session.." << endl;
io.set(EV_NONE);
......@@ -791,6 +807,9 @@ void LogDB::handleRequest( Poco::Net::HTTPServerRequest& req, Poco::Net::HTTPSer
std::ostream& out = resp.send();
resp.setContentType("text/json");
resp.set("Access-Control-Allow-Methods", "GET");
resp.set("Access-Control-Allow-Request-Method", "*");
resp.set("Access-Control-Allow-Origin", httpCORS_allow /* req.get("Origin") */);
try
{
......@@ -811,6 +830,7 @@ void LogDB::handleRequest( Poco::Net::HTTPServerRequest& req, Poco::Net::HTTPSer
uri.getPathSegments(seg);
// проверка подключения к страничке со списком websocket-ов
// http://[xxxx:port]/logdb/ws/
if( seg.size() > 1 && seg[0] == "logdb" && seg[1] == "ws" )
{
// подключение..
......@@ -1393,10 +1413,12 @@ void LogDB::LogWebSocket::write()
if( ret < 0 )
{
int errnum = errno;
dblog3 << "(websocket): " << req->clientAddress().toString()
<< " write to socket error(" << errno << "): " << strerror(errno) << endl;
<< " write to socket error(" << errnum << "): " << strerror(errnum) << endl;
if( errno == EPIPE || errno == EBADF )
if( errnum == EPIPE || errnum == EBADF )
{
dblog3 << "(websocket): "
<< req->clientAddress().toString()
......@@ -1520,7 +1542,7 @@ void LogDB::httpWebSocketPage( std::ostream& ostr, Poco::Net::HTTPServerRequest&
for( const auto& l : logservers )
{
ostr << " <li><a target='_blank' href=\"http://"
<< req.serverAddress().toString()
<< ( httpReplyAddr.empty() ? req.serverAddress().toString() : httpReplyAddr )
<< "/logdb/ws/" << l->name << "\">"
<< l->name << "</a> &#8211; "
<< "<i>" << l->description << "</i></li>"
......@@ -1569,7 +1591,7 @@ void LogDB::httpWebSocketConnectPage( ostream& ostr,
ostr << " if (\"WebSocket\" in window)" << endl;
ostr << " {" << endl;
ostr << " // LogScrollTimer = setInterval(LogAutoScroll,800);" << endl;
ostr << " var ws = new WebSocket(\"ws://" << req.serverAddress().toString() << "/logdb/ws/\" + logname);" << endl;
ostr << " var ws = new WebSocket(\"ws://" << ( httpReplyAddr.empty() ? req.serverAddress().toString() : httpReplyAddr ) << "/logdb/ws/\" + logname);" << endl;
ostr << " var l = document.getElementById('logname');" << endl;
ostr << " l.innerHTML = logname" << endl;
ostr << " ws.onmessage = function(evt)" << endl;
......
......@@ -315,6 +315,8 @@ namespace uniset
std::shared_ptr<Poco::Net::HTTPServer> httpserv;
std::string httpHost = { "" };
int httpPort = { 0 };
std::string httpCORS_allow = { "*" };
std::string httpReplyAddr = { "" };
double wsHeartbeatTime_sec = { 3.0 };
double wsSendTime_sec = { 0.5 };
......
......@@ -39,6 +39,7 @@
#include "modbus/ModbusClient.h"
#include "LogAgregator.h"
#include "LogServer.h"
#include "LogAgregator.h"
#include "VMonitor.h"
// -----------------------------------------------------------------------------
#ifndef vmonit
......
#ifndef DISABLE_COMPORT_485F
/*
* Copyright (c) 2015 Pavel Vainerman.
*
......@@ -71,3 +72,4 @@ namespace uniset
// --------------------------------------------------------------------------
#endif // COMPORT_485F_H_
// --------------------------------------------------------------------------
#endif // #ifndef DISABLE_COMPORT_485F
......@@ -85,6 +85,11 @@ namespace uniset
return step(); // ostate;
}
inline bool out() const noexcept
{
return ostate;
}
inline void set( bool state ) noexcept
{
enabled = state;
......
......@@ -113,7 +113,7 @@ namespace uniset
public Poco::Net::HTTPRequestHandler
{
public:
UHttpRequestHandler( std::shared_ptr<IHttpRequestRegistry> _registry );
UHttpRequestHandler( std::shared_ptr<IHttpRequestRegistry> _registry, const std::string& httpCORS_allow = "*");
virtual void handleRequest( Poco::Net::HTTPServerRequest& req, Poco::Net::HTTPServerResponse& resp ) override;
......@@ -121,6 +121,7 @@ namespace uniset
std::shared_ptr<IHttpRequestRegistry> registry;
std::shared_ptr<DebugStream> log;
const std::string httpCORS_allow = { "*" };
};
// -------------------------------------------------------------------------
class UHttpRequestHandlerFactory:
......@@ -132,8 +133,11 @@ namespace uniset
virtual Poco::Net::HTTPRequestHandler* createRequestHandler( const Poco::Net::HTTPServerRequest& ) override;
// (CORS): Access-Control-Allow-Origin. Default: *
void setCORS_allow( const std::string& allow );
private:
std::shared_ptr<IHttpRequestRegistry> registry;
std::string httpCORS_allow = { "*" };
};
}
// -------------------------------------------------------------------------
......
......@@ -45,6 +45,8 @@ namespace uniset
std::shared_ptr<DebugStream> log();
// (CORS): Access-Control-Allow-Origin. Default: *
void setCORS_allow( const std::string& CORS_allow );
protected:
UHttpServer();
......
......@@ -55,6 +55,7 @@ namespace uniset
* и перенаправление их указанным объектам. Помимо этого UniSetActivator реализует обработку команд /conf/..
* Для запуска http-сервера необходимо в аргументах командной строки указать --activator-run-httpserver
* Помимо этого можно задать параметры --activator-httpserver-host и --activator-httpserver-port.
* --activator-httpserver-cors-allow addr - (CORS): Access-Control-Allow-Origin. Default: *.
*
*/
class UniSetActivator:
......@@ -115,6 +116,7 @@ namespace uniset
std::shared_ptr<uniset::UHttp::UHttpServer> httpserv;
std::string httpHost = { "" };
int httpPort = { 0 };
std::string httpCORS_allow = { "*" };
#endif
};
// -------------------------------------------------------------------------
......
......@@ -53,44 +53,44 @@ ext_libs()
libs $1/$2
}
EXFILE="$EXPORTPATH/extensions libUniSetExtensions2.pc"
EXFILE="$EXPORTPATH/extensions libUniSet2Extensions.pc"
export UNISET_EXT_CFLAGS="$( ext_cflags $EXFILE )"
export UNISET_EXT_LIBS="-L$EXPORTPATH/extensions/lib $( ext_libs $EXFILE )"
EXFILE="$EXPORTPATH/extensions/IOControl libUniSetIOControl2.pc"
EXFILE="$EXPORTPATH/extensions/IOControl libUniSet2IOControl.pc"
export UNISET_EXT_IO_CFLAGS="$( ext_cflags $EXFILE )"
export UNISET_EXT_IO_LIBS="$( ext_libs $EXFILE )"
EXFILE="$EXPORTPATH/extensions/SharedMemory libUniSetSharedMemory2.pc"
EXFILE="$EXPORTPATH/extensions/SharedMemory libUniSet2SharedMemory.pc"
export UNISET_EXT_SM_CFLAGS="$( ext_cflags $EXFILE )"
export UNISET_EXT_SM_LIBS="$( ext_libs $EXFILE )"
EXFILE="$EXPORTPATH/extensions/ModbusSlave libUniSetMBSlave2.pc"
EXFILE="$EXPORTPATH/extensions/ModbusSlave libUniSet2MBSlave.pc"
export UNISET_EXT_MBS_CFLAGS="$( ext_cflags $EXFILE )"
export UNISET_EXT_MBS_LIBS="$( ext_libs $EXFILE )"
EXFILE="$EXPORTPATH/extensions/ModbusMaster libUniSetMBTCPMaster2.pc"
EXFILE="$EXPORTPATH/extensions/ModbusMaster libUniSet2MBTCPMaster.pc"
export UNISET_EXT_MBM_CFLAGS="$( ext_cflags $EXFILE )"
export UNISET_EXT_MBM_LIBS="$( ext_libs $EXFILE )"
EXFILE="$EXPORTPATH/extensions/UniNetwork libUniSetNetwork2.pc"
EXFILE="$EXPORTPATH/extensions/UniNetwork libUniSet2Network.pc"
export UNISET_EXT_NET_CFLAGS="$( ext_cflags $EXFILE )"
export UNISET_EXT_NET_LIBS="$( ext_libs $EXFILE )"
EXFILE="$EXPORTPATH/extensions/UNetUDP libUniSetUNetUDP2.pc"
EXFILE="$EXPORTPATH/extensions/UNetUDP libUniSet2UNetUDP.pc"
export UNISET_EXT_UNETUDP_CFLAGS="$( ext_cflags $EXFILE )"
export UNISET_EXT_UNETUDP_LIBS="$( ext_libs $EXFILE )"
EXFILE="$EXPORTPATH/extensions/ModbusMaster libUniSetRTU2.pc"
EXFILE="$EXPORTPATH/extensions/ModbusMaster libUniSet2RTU.pc"
export UNISET_EXT_RTU_CFLAGS="$( ext_cflags $EXFILE )"
export UNISET_EXT_RTU_LIBS="$( ext_libs $EXFILE )"
EXFILE="$EXPORTPATH/extensions/DBServer-MySQL libUniSetMySQL2.pc"
EXFILE="$EXPORTPATH/extensions/DBServer-MySQL libUniSet2MySQL.pc"
export UNISET_EXT_MYSQL_CFLAGS="$( ext_cflags $EXFILE )"
export UNISET_EXT_MYSQL_LIBS="$( ext_libs $EXFILE )"
EXFILE="$EXPORTPATH/extensions/LogicProcessor libUniSetLogicProcessor2.pc"
EXFILE="$EXPORTPATH/extensions/LogicProcessor libUniSet2LogicProcessor.pc"
export UNISET_EXT_LP_CFLAGS="$( ext_cflags $EXFILE )"
export UNISET_EXT_LP_LIBS="$( ext_libs $EXFILE )"
export UNISET_CODEGEN="sh $EXPORTPATH/Utilities/codegen/uniset-codegen --path $EXPORTPATH/Utilities/codegen"
export UNISET_CODEGEN="sh $EXPORTPATH/Utilities/codegen/uniset2-codegen --path $EXPORTPATH/Utilities/codegen"
#ifndef DISABLE_COMPORT_485F
/*
* Copyright (c) 2015 Pavel Vainerman.
*
......@@ -334,3 +335,4 @@ void ComPort485F::reopen()
ComPort::reopen();
}
// --------------------------------------------------------------------------------
#endif // #ifndef DISABLE_COMPORT_485F
......@@ -28,14 +28,21 @@ namespace uniset
using namespace UHttp;
// -------------------------------------------------------------------------
UHttpRequestHandler::UHttpRequestHandler(std::shared_ptr<IHttpRequestRegistry> _registry ):
registry(_registry)
UHttpRequestHandler::UHttpRequestHandler(std::shared_ptr<IHttpRequestRegistry> _registry
, const std::string& allow )
: registry(_registry)
, httpCORS_allow(allow)
{
log = make_shared<DebugStream>();
}
// -------------------------------------------------------------------------
void UHttpRequestHandler::handleRequest( Poco::Net::HTTPServerRequest& req, Poco::Net::HTTPServerResponse& resp )
void UHttpRequestHandler::handleRequest( Poco::Net::HTTPServerRequest& req
, Poco::Net::HTTPServerResponse& resp )
{
// В этой версии API поддерживается только GET
resp.set("Access-Control-Allow-Methods", "GET");
resp.set("Access-Control-Allow-Request-Method", "*");
resp.set("Access-Control-Allow-Origin", httpCORS_allow /* req.get("Origin") */);
if( !registry )
{
resp.setStatus(HTTPResponse::HTTP_INTERNAL_SERVER_ERROR);
......@@ -159,7 +166,12 @@ namespace uniset
// -------------------------------------------------------------------------
HTTPRequestHandler* UHttpRequestHandlerFactory::createRequestHandler( const HTTPServerRequest& req )
{
return new UHttpRequestHandler(registry);
return new UHttpRequestHandler(registry, httpCORS_allow);
}
// -------------------------------------------------------------------------
void UHttpRequestHandlerFactory::setCORS_allow( const std::string& allow )
{
httpCORS_allow = allow;
}
// -------------------------------------------------------------------------
Poco::JSON::Object::Ptr IHttpRequest::httpRequest( const string& req, const Poco::URI::QueryParameters& p )
......
......@@ -78,6 +78,11 @@ namespace uniset
return mylog;
}
// -------------------------------------------------------------------------
void UHttpServer::setCORS_allow( const std::string& allow )
{
reqFactory->setCORS_allow(allow);
}
// -------------------------------------------------------------------------
} // end of namespace uniset
// -------------------------------------------------------------------------
#endif // #ifndef DISABLE_REST_API
......@@ -36,6 +36,7 @@ namespace uniset
{
if( use485 )
{
#ifndef DISABLE_COMPORT_485F
ComPort485F* cp;
if( dev == "/dev/ttyS2" )
......@@ -46,6 +47,9 @@ namespace uniset
throw Exception("Open ComPort FAILED! dev must be /dev/ttyS2 or /dev/tytS3");
port = cp;
#else
throw Exception("Open ComPort485F FAILED! DISABLE_COMPORT_485F");
#endif // #ifndef DISABLE_COMPORT_485F
}
else
port = new ComPort(dev);
......
......@@ -36,6 +36,7 @@ namespace uniset
{
if( use485 )
{
#ifndef DISABLE_COMPORT_485F
ComPort485F* cp;
if( dev == "/dev/ttyS2" )
......@@ -46,6 +47,9 @@ namespace uniset
throw Exception("Open ComPort FAILED! dev must be /dev/ttyS2 or /dev/tytS3");
port = cp;
#else
throw Exception("Open ComPort485F FAILED! DISABLE_COMPORT_485F");
#endif // #ifndef DISABLE_COMPORT_485F
}
else
port = new ComPort(dev);
......
......@@ -307,8 +307,9 @@ namespace uniset
if( res < 0 )
{
if( errno != EAGAIN && dlog->is_warn() )
dlog->warn() << peername << "(getNextData): read from socket error(" << errno << "): " << strerror(errno) << endl;
int errnum = errno;
if( errnum != EAGAIN && dlog->is_warn() )
dlog->warn() << peername << "(getNextData): read from socket error(" << errnum << "): " << strerror(errnum) << endl;
return 0;
}
......
......@@ -89,6 +89,7 @@ namespace uniset
s << (getId() == DefaultObjectId ? 8080 : getId() );
httpPort = conf->getArgInt("--activator-httpserver-port", s.str());
ulog1 << myname << "(init): http server parameters " << httpHost << ":" << httpPort << endl;
httpCORS_allow = conf->getArgParam("--activator-httpserver-cors-allow", "*");
}
#endif
......@@ -153,6 +154,7 @@ namespace uniset
{
auto reg = dynamic_pointer_cast<UHttp::IHttpRequestRegistry>(shared_from_this());
httpserv = make_shared<UHttp::UHttpServer>(reg, httpHost, httpPort);
httpserv->setCORS_allow(httpCORS_allow);
httpserv->start();
}
catch( std::exception& ex )
......
......@@ -128,7 +128,8 @@ uniset::IDList::IDList( const std::vector<string>& svec ):
else
id = conf->getSensorID(s);
add(id);
if( id != DefaultObjectId )
add(id);
}
}
// -------------------------------------------------------------------------
......
......@@ -301,10 +301,18 @@ namespace uniset
if( ret < 0 )
{
// копируем, а потом проверяем
// хоть POSIX говорит о том, что errno thread-local
// но почему-то словил, что errno (по крайней мере для EPIPE "broken pipe")
// в лог выводилось, а в if( ... ) уже не ловилось
// возможно связано с тем, что ввод/вывод "прерываемая" операция при многопоточности
int errnum = errno;
// можно было бы конечно убрать вывод лога в else, после проверки в if
if( mylog.is_warn() )
mylog.warn() << peername << "(LogSession::writeEvent): write to socket error(" << errno << "): " << strerror(errno) << endl;
mylog.warn() << peername << "(LogSession::writeEvent): write to socket error(" << errnum << "): " << strerror(errnum) << endl;
if( errno == EPIPE || errno == EBADF )
if( errnum == EPIPE || errnum == EBADF )
{
if( mylog.is_warn() )
mylog.warn() << peername << "(LogSession::writeEvent): write error.. terminate session.." << endl;
......
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