Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
uniset2
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UniSet project repositories
uniset2
Commits
22b49903
Commit
22b49903
authored
Oct 30, 2016
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(UHttpServer): initial commit
parent
9fdacb81
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
144 additions
and
14 deletions
+144
-14
configure.ac
configure.ac
+8
-12
Makefile.am
lib/Makefile.am
+1
-0
Makefile.am
src/Communications/Http/Makefile.am
+10
-0
UHttpRequestHandler.cc
src/Communications/Http/UHttpRequestHandler.cc
+67
-0
UHttpServer.cc
src/Communications/Http/UHttpServer.cc
+51
-0
Makefile.am
src/Communications/Makefile.am
+1
-1
Makefile.am
tests/Makefile.am
+2
-1
uniset2.files
uniset2.files
+4
-0
No files found.
configure.ac
View file @
22b49903
...
...
@@ -69,6 +69,13 @@ if test -n "$poco_old"; then
POCO_CFLAGS="${POCO_CFLAGS} -DPOCO_OLD_VERSION"
fi
AC_MSG_CHECKING([check json])
if test -a "/usr/include/json.hpp"; then
AC_MSG_RESULT([ok])
else
AC_MSG_ERROR([json.hpp not found])
fi
#check sqlite support
AC_MSG_CHECKING([sqlite support])
buildsqlite=true
...
...
@@ -95,18 +102,6 @@ test "x$IDL" = "x" && AC_MSG_ERROR([*** omniidl not found.])
#AC_SUBST(UNISET_IDLFLAGS)
#check mysql support
AC_MSG_CHECKING([mysql support])
buildmysql=true
AC_ARG_ENABLE(mysql, AC_HELP_STRING([--disable-mysql], [disable MySQL support]),
[ if test $enableval = yes; then buildmysql=true; else buildmysql=false; fi],[ buildmysql=true; ])
if test ${buildmysql} = true; then
AC_MSG_RESULT([enabled])
AC_CHECK_HEADERS([mysql/mysql.h])
AC_SEARCH_LIBS([mysql_init],mysqlclient,[],[],exit)
else
AC_MSG_RESULT([disabled])
fi
AM_CONDITIONAL(DISABLE_MYSQL, test ${buildmysql} = false)
...
...
@@ -378,6 +373,7 @@ AC_CONFIG_FILES([Makefile
src/Communications/Makefile
src/Communications/Modbus/Makefile
src/Communications/TCP/Makefile
src/Communications/Http/Makefile
src/Interfaces/Makefile
src/ObjectRepository/Makefile
src/Processes/Makefile
...
...
lib/Makefile.am
View file @
22b49903
...
...
@@ -16,6 +16,7 @@ libUniSet2_la_LIBADD = -lm \
$(top_builddir)
/src/Communications/libCommunications.la
\
$(top_builddir)
/src/Communications/Modbus/libModbus.la
\
$(top_builddir)
/src/Communications/TCP/libTCP.la
\
$(top_builddir)
/src/Communications/Http/libHttp.la
\
$(top_builddir)
/src/Interfaces/libInterfaces.la
\
$(top_builddir)
/src/ObjectRepository/libObjectsRepository.la
\
$(top_builddir)
/src/Processes/libProcesses.la
\
...
...
src/Communications/Http/Makefile.am
0 → 100644
View file @
22b49903
############################################################################
# This file is part of the UniSet library #
############################################################################
noinst_LTLIBRARIES
=
libHttp.la
libHttp_la_SOURCES
=
UHttpRequestHandler.cc UHttpServer.cc
libHttp_la_CXXFLAGS
=
$(POCO_CFLAGS)
libHttp_la_LIBADD
=
$(POCO_LIBS)
include
$(top_builddir)/include.mk
src/Communications/Http/UHttpRequestHandler.cc
0 → 100644
View file @
22b49903
/*
* Copyright (c) 2015 Pavel Vainerman.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, version 2.1.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Lesser Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// -------------------------------------------------------------------------
#include <ostream>
#include <Poco/URI.h>
#include "UHttpRequestHandler.h"
// -------------------------------------------------------------------------
using
namespace
Poco
::
Net
;
using
namespace
UniSetTypes
;
// -------------------------------------------------------------------------
UHttpRequestHandler
::
UHttpRequestHandler
(
std
::
shared_ptr
<
IHttpRequestRegistry
>
_supplier
)
:
supplier
(
_supplier
)
{
}
// -------------------------------------------------------------------------
void
UHttpRequestHandler
::
handleRequest
(
Poco
::
Net
::
HTTPServerRequest
&
req
,
Poco
::
Net
::
HTTPServerResponse
&
resp
)
{
if
(
!
supplier
)
{
resp
.
setStatus
(
HTTPResponse
::
HTTP_NOT_FOUND
);
resp
.
setContentType
(
"text/json"
);
std
::
ostream
&
out
=
resp
.
send
();
out
.
flush
();
return
;
}
Poco
::
URI
uri
(
req
.
getURI
());
// в текущей версии подразумевается, что запрос идёт в формате
// http://xxx.host:port/ObjectName
// поэтому сразу передаём uri.getQuery() в качестве имени объекта
resp
.
setStatus
(
HTTPResponse
::
HTTP_OK
);
resp
.
setContentType
(
"text/json"
);
std
::
ostream
&
out
=
resp
.
send
();
auto
json
=
supplier
->
getData
(
uri
.
getQuery
());
out
<<
json
.
dump
();
out
.
flush
();
}
// -------------------------------------------------------------------------
UHttpRequestHandlerFactory
::
UHttpRequestHandlerFactory
(
std
::
shared_ptr
<
IHttpRequestRegistry
>&
_supplier
)
:
supplier
(
_supplier
)
{
}
// -------------------------------------------------------------------------
HTTPRequestHandler
*
UHttpRequestHandlerFactory
::
createRequestHandler
(
const
HTTPServerRequest
&
req
)
{
return
new
UHttpRequestHandler
(
supplier
);
}
// -------------------------------------------------------------------------
src/Communications/Http/UHttpServer.cc
0 → 100644
View file @
22b49903
/*
* Copyright (c) 2015 Pavel Vainerman.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, version 2.1.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Lesser Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// -------------------------------------------------------------------------
#include <Poco/URI.h>
#include "UHttpServer.h"
// -------------------------------------------------------------------------
using
namespace
Poco
::
Net
;
using
namespace
UniSetTypes
;
// -------------------------------------------------------------------------
UHttpServer
::
UHttpServer
(
std
::
shared_ptr
<
IHttpRequestRegistry
>&
supplier
,
const
std
::
string
_host
,
int
_port
)
:
sa
(
_host
,
_port
)
{
/*! \FIXME: доделать конфигурирование параметров */
HTTPServerParams
*
httpParams
=
new
HTTPServerParams
;
httpParams
->
setMaxQueued
(
100
);
httpParams
->
setMaxThreads
(
1
);
reqFactory
=
std
::
make_shared
<
UHttpRequestHandlerFactory
>
(
supplier
);
http
=
std
::
make_shared
<
Poco
::
Net
::
HTTPServer
>
(
reqFactory
.
get
(),
ServerSocket
(
sa
),
httpParams
);
}
// -------------------------------------------------------------------------
UHttpServer
::~
UHttpServer
()
{
}
// -------------------------------------------------------------------------
UHttpServer
::
UHttpServer
()
{
}
// -------------------------------------------------------------------------
std
::
shared_ptr
<
DebugStream
>
UHttpServer
::
log
()
{
return
mylog
;
}
// -------------------------------------------------------------------------
src/Communications/Makefile.am
View file @
22b49903
############################################################################
# This file is part of the UniSet library #
############################################################################
SUBDIRS
=
TCP Modbus
SUBDIRS
=
TCP Modbus
Http
noinst_LTLIBRARIES
=
libCommunications.la
libCommunications_la_SOURCES
=
ComPort.cc ComPort485F.cc
...
...
tests/Makefile.am
View file @
22b49903
...
...
@@ -29,7 +29,8 @@ test_logserver.cc \
test_tcpcheck.cc
\
test_utcpsocket.cc
\
test_iocontroller_types.cc
\
test_debugstream.cc
test_debugstream.cc
\
test_uhttp.cc
tests_with_conf_LDADD
=
$(top_builddir)
/lib/libUniSet2.la
tests_with_conf_CPPFLAGS
=
-I
$(top_builddir)
/include
...
...
uniset2.files
View file @
22b49903
...
...
@@ -334,6 +334,8 @@ include/USocket.h
include/UDPCore.h
include/WDTInterface.h
include/UHelpers.h
include/UHttpRequestHandler.h
include/UHttpServer.h
lib/Makefile.am
python/examples/test.xml
python/lib/pyUniSet/Makefile.am
...
...
@@ -376,6 +378,7 @@ src/Communications/TCP/UTCPCore.cc
src/Communications/TCP/UTCPStream.cc
src/Communications/TCP/UTCPSocket.cc
src/Communications/TCP/USocket.cc
src/Communications/Http/UHttpRequestHandler.cc
src/Communications/ComPort.cc
src/Communications/ComPort485F.cc
src/Communications/Makefile.am
...
...
@@ -468,6 +471,7 @@ tests/test_uobject.cc
tests/test_utcpsocket.cc
tests/test_iocontroller_types.cc
tests/test_debugstream.cc
tests/test_uhttp.cc
tests/TestUObject.h
tests/tests-junit.xml
tests/tests.cc
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment