Refactor web server configuration. #1188

This commit is contained in:
Penn, John M 047828115 2021-09-29 18:00:33 -05:00
parent 90639e35d5
commit 0b373d96cf
16 changed files with 179 additions and 103 deletions

View File

@ -148,8 +148,8 @@ ifeq ($(USE_JAVA), 1)
all: java
endif
ifeq ($(TRICK_CIVET), 1)
icg_sim_serv: ${TRICK_LIB_DIR}/libtrickCivet.a
ifeq ($(USE_CIVETWEB), 1)
all: civetweb
endif
#-------------------------------------------------------------------------------
@ -221,39 +221,12 @@ dp: ${TRICK_HOME}/trick_source/trick_utils/units
#-------------------------------------------------------------------------------
# 1.2 Build Trick's CivetWeb webserver.
CIVET_CLONE_DIR = civetweb_clone
.PHONY: civetweb
civetweb: ${TRICK_LIB_DIR}/libtrickCivet.a
${TRICK_LIB_DIR}/libtrickCivet.a: ${TRICK_LIB_DIR}/libcivetweb.a ${TRICK_HOME}/include/civet/civetweb.h ${TRICK_HOME}/include/civet/CivetServer.h
${TRICK_LIB_DIR}/libtrickCivet.a:
$(MAKE) -C ${TRICK_HOME}/trick_source/web/CivetServer
${TRICK_LIB_DIR}/libcivetweb.a: ${CIVET_CLONE_DIR}/libcivetweb.a | ${TRICK_LIB_DIR}
cp ${CIVET_CLONE_DIR}/libcivetweb.a $(TRICK_LIB_DIR)/libcivetweb.a
${TRICK_HOME}/include/civet:
mkdir -p ${TRICK_HOME}/include/civet
${TRICK_HOME}/include/civet/civetweb.h: ${CIVET_CLONE_DIR} ${TRICK_HOME}/include/civet
cp ${CIVET_CLONE_DIR}/include/civetweb.h ${TRICK_HOME}/include/civet/civetweb.h
${TRICK_HOME}/include/civet/CivetServer.h: ${CIVET_CLONE_DIR} ${TRICK_HOME}/include/civet
cp ${CIVET_CLONE_DIR}/include/CivetServer.h ${TRICK_HOME}/include/civet/CivetServer.h
ifeq (${TRICK_FORCE_32BIT},1)
CIVET_COMPILE_FAGS=-m32
else
CIVET_COMPILE_FAGS=
endif
${CIVET_CLONE_DIR}/libcivetweb.a: ${CIVET_CLONE_DIR}
$(MAKE) -C ${CIVET_CLONE_DIR} lib COPT=${CIVET_COMPILE_FAGS} WITH_CPP=1 WITH_WEBSOCKET=1
${CIVET_CLONE_DIR}:
git clone --branch v1.14 --depth 1 -c advice.detachedHead=false https://github.com/civetweb/civetweb.git $@
#-------------------------------------------------------------------------------
# 1.3 Build Trick's Java Tools

View File

@ -89,6 +89,37 @@ AC_DEFUN([AX_GTEST_HOME],[
AC_SUBST([GTEST_HOME])
])
AC_DEFUN([AX_CIVETWEB_HOME],[
AC_ARG_WITH([civetweb],
AS_HELP_STRING([--with-civetweb@<:@=DIR@:>@],
[CIVETWEB root directory]),
# --with option was provided.
[CIVETWEB_HOME="$withval"
USE_CIVETWEB="0"
# check whether directory arg was also provided.
AS_IF([test "$CIVETWEB_HOME" = "yes"],
AC_CHECK_HEADER(civetweb.h,
[CIVETWEB_HOME="/usr"; USE_CIVETWEB="1"],
AC_MSG_ERROR([could not find civetweb.h])),
# else check whether --without-civet or --with-civet=no specified.
AS_IF([test "$CIVETWEB_HOME" = "no"],
[CIVETWEB_HOME=""],
# else --with-civet was provided with a directory path.
AC_CHECK_FILE([$CIVETWEB_HOME/include/civetweb.h],
[USE_CIVETWEB="1"],
AC_MSG_ERROR([could not find $CIVETWEB_HOME/include/civetweb.h]))))
],
# --with option not provided.
[AC_CHECK_HEADER(civetweb.h,
[CIVETWEB_HOME="/usr"; USE_CIVETWEB="1"],
[CIVETWEB_HOME=""; USE_CIVETWEB="0"])
]
)
AC_SUBST([CIVETWEB_HOME])
AC_SUBST([USE_CIVETWEB])
])
AC_DEFUN([AX_SWIG_BIN],[
AC_ARG_WITH([swig],
[AS_HELP_STRING([--with-swig@<:@=DIR@:>@], [path of directory containing the SWIG executable.])],
@ -312,26 +343,26 @@ AC_ARG_ENABLE([offline],
)
AC_SUBST([TRICK_OFFLINE])
AC_ARG_ENABLE([civet],
AS_HELP_STRING([--enable-civet], [Compile Trick with webserver capabilites.]),
AS_IF([test "x$enable_civet" = xyes],
[
TRICK_DISABLE_CIVET="0"
],
[TRICK_DISABLE_CIVET="1"]
),
[TRICK_DISABLE_CIVET="0"]
)
AC_SUBST([TRICK_DISABLE_CIVET])
# AC_ARG_ENABLE([civet],
# AS_HELP_STRING([--enable-civet], [Compile Trick with webserver capabilites.]),
# AS_IF([test "x$enable_civet" = xyes],
# [
# TRICK_DISABLE_CIVET="0"
# ],
# [TRICK_DISABLE_CIVET="1"]
# ),
# [TRICK_DISABLE_CIVET="0"]
# )
# AC_SUBST([TRICK_DISABLE_CIVET])
# If offline is specified, set some compilation flags
AC_ARG_ENABLE([offline],
AS_HELP_STRING([--enable-offline], [Compile Trick in offline mode. Un-tar the trick-offline directory in TRICK_HOME to use this feature]),
AS_IF([test "x$enable_offline" = xyes],
[TRICK_DISABLE_CIVET="1"],
),
)
AC_SUBST([TRICK_OFFLINE])
# AC_ARG_ENABLE([offline],
# AS_HELP_STRING([--enable-offline], [Compile Trick in offline mode. Un-tar the trick-offline directory in TRICK_HOME to use this feature]),
# AS_IF([test "x$enable_offline" = xyes],
# [TRICK_DISABLE_CIVET="1"],
# ),
# )
# AC_SUBST([TRICK_OFFLINE])
dnl look for programs we need to compile and run
AC_PROG_AWK
@ -529,6 +560,7 @@ dnl process the other optional command line arguments
AX_HDF5_HOME([])
AX_GSL_HOME([])
AX_GTEST_HOME([])
AX_CIVETWEB_HOME([])
AX_ER7_UTILS([])
AC_CONFIG_FILES([share/trick/makefiles/config_user.mk])

127
configure vendored
View File

@ -648,6 +648,8 @@ ac_header_cxx_list=
ac_subst_vars='LTLIBOBJS
LIBOBJS
USE_ER7_UTILS
USE_CIVETWEB
CIVETWEB_HOME
GTEST_HOME
GSL_HOME
HDF5_HOME
@ -699,7 +701,6 @@ LD
TEE
GCC_VERSION
AWK
TRICK_DISABLE_CIVET
TRICK_OFFLINE
TRICK_FORCE_32BIT
LIBXML
@ -772,7 +773,6 @@ enable_option_checking
with_x
enable_32bit
enable_offline
enable_civet
with_python
with_prepend_path
with_swig
@ -783,6 +783,7 @@ with_udunits
with_hdf5
with_gsl
with_gtest
with_civetweb
enable_er7utils
'
ac_precious_vars='build_alias
@ -1432,7 +1433,6 @@ Optional Features:
--enable-offline Compile Trick in offline mode. Un-tar the
trick-offline directory in TRICK_HOME to use this
feature
--enable-civet Compile Trick with webserver capabilites.
--enable-java use java (default is yes)
--enable-er7utils use er7_utils (default is yes)
@ -1454,6 +1454,7 @@ Optional Packages:
--with-hdf5[=DIR] HDF5 root directory
--with-gsl[=DIR] GSL root directory
--with-gtest[=DIR] GTEST root directory
--with-civetweb[=DIR] CIVETWEB root directory
Some influential environment variables:
CC C compiler command
@ -2897,6 +2898,9 @@ ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
@ -5058,36 +5062,26 @@ fi
# Check whether --enable-civet was given.
if test ${enable_civet+y}
then :
enableval=$enable_civet; if test "x$enable_civet" = xyes
then :
TRICK_DISABLE_CIVET="0"
else $as_nop
TRICK_DISABLE_CIVET="1"
fi
else $as_nop
TRICK_DISABLE_CIVET="0"
fi
# AC_ARG_ENABLE([civet],
# AS_HELP_STRING([--enable-civet], [Compile Trick with webserver capabilites.]),
# AS_IF([test "x$enable_civet" = xyes],
# [
# TRICK_DISABLE_CIVET="0"
# ],
# [TRICK_DISABLE_CIVET="1"]
# ),
# [TRICK_DISABLE_CIVET="0"]
# )
# AC_SUBST([TRICK_DISABLE_CIVET])
# If offline is specified, set some compilation flags
# Check whether --enable-offline was given.
if test ${enable_offline+y}
then :
enableval=$enable_offline; if test "x$enable_offline" = xyes
then :
TRICK_DISABLE_CIVET="1"
fi
fi
# AC_ARG_ENABLE([offline],
# AS_HELP_STRING([--enable-offline], [Compile Trick in offline mode. Un-tar the trick-offline directory in TRICK_HOME to use this feature]),
# AS_IF([test "x$enable_offline" = xyes],
# [TRICK_DISABLE_CIVET="1"],
# ),
# )
# AC_SUBST([TRICK_OFFLINE])
for ac_prog in gawk mawk nawk awk
do
@ -10120,6 +10114,77 @@ fi
# Check whether --with-civetweb was given.
if test ${with_civetweb+y}
then :
withval=$with_civetweb; # --with option was provided.
CIVETWEB_HOME="$withval"
USE_CIVETWEB="0"
# check whether directory arg was also provided.
if test "$CIVETWEB_HOME" = "yes"
then :
ac_fn_cxx_check_header_compile "$LINENO" "civetweb.h" "ac_cv_header_civetweb_h" "$ac_includes_default"
if test "x$ac_cv_header_civetweb_h" = xyes
then :
CIVETWEB_HOME="/usr"; USE_CIVETWEB="1"
else $as_nop
as_fn_error $? "could not find civetweb.h" "$LINENO" 5
fi
else $as_nop
# else check whether --without-civet or --with-civet=no specified.
if test "$CIVETWEB_HOME" = "no"
then :
CIVETWEB_HOME=""
else $as_nop
# else --with-civet was provided with a directory path.
as_ac_File=`printf "%s\n" "ac_cv_file_$CIVETWEB_HOME/include/civetweb.h" | $as_tr_sh`
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $CIVETWEB_HOME/include/civetweb.h" >&5
printf %s "checking for $CIVETWEB_HOME/include/civetweb.h... " >&6; }
if eval test \${$as_ac_File+y}
then :
printf %s "(cached) " >&6
else $as_nop
test "$cross_compiling" = yes &&
as_fn_error $? "cannot check for file existence when cross compiling" "$LINENO" 5
if test -r "$CIVETWEB_HOME/include/civetweb.h"; then
eval "$as_ac_File=yes"
else
eval "$as_ac_File=no"
fi
fi
eval ac_res=\$$as_ac_File
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
printf "%s\n" "$ac_res" >&6; }
if eval test \"x\$"$as_ac_File"\" = x"yes"
then :
USE_CIVETWEB="1"
else $as_nop
as_fn_error $? "could not find $CIVETWEB_HOME/include/civetweb.h" "$LINENO" 5
fi
fi
fi
else $as_nop
# --with option not provided.
ac_fn_cxx_check_header_compile "$LINENO" "civetweb.h" "ac_cv_header_civetweb_h" "$ac_includes_default"
if test "x$ac_cv_header_civetweb_h" = xyes
then :
CIVETWEB_HOME="/usr"; USE_CIVETWEB="1"
else $as_nop
CIVETWEB_HOME=""; USE_CIVETWEB="0"
fi
fi
# Check whether --enable-er7utils was given.
if test ${enable_er7utils+y}
then :

View File

@ -4,7 +4,7 @@ PURPOSE: (Represent the state and initial conditions of an http server.)
#ifndef CIVET_SERVER_H
#define CIVET_SERVER_H
#ifdef USE_CIVET
#ifdef USE_CIVETWEB
#include <string>
#include <map>
@ -12,8 +12,8 @@ PURPOSE: (Represent the state and initial conditions of an http server.)
#include <sys/socket.h>
#include <arpa/inet.h>
#include <vector>
#include "trick/WebSocketSession.hh"
class WebSocketSession;
typedef WebSocketSession* (*WebSocketSessionMaker)(struct mg_connection *nc);
typedef void (*httpMethodHandler)(struct mg_connection *, void* cbdata);
@ -76,10 +76,10 @@ class MyCivetServer {
};
struct Data {
MyCivetServer* server;
std::string name;
};
//struct Data {
// MyCivetServer* server;
// std::string name;
//};
#endif
#endif

View File

@ -96,7 +96,7 @@
#include "trick/lqueue.h"
#include "trick/lstack.h"
#ifdef USE_CIVET
#ifdef USE_CIVETWEB
#include "trick/MyCivetServer.hh"
#include "trick/WebSocketSession.hh"
#endif

View File

@ -171,7 +171,11 @@ ifneq ($(GSL_HOME),)
TRICK_SYSTEM_CXXFLAGS += -D_HAVE_GSL
endif
TRICK_CIVET=0
ifeq (${USE_CIVETWEB},1)
TRICK_LIBS += ${CIVETWEB_HOME}/libcivetweb.a ${TRICK_LIB_DIR}/libtrickCivet.a
TRICK_SWIG_FLAGS += -DUSE_CIVETWEB
TRICK_SYSTEM_CXXFLAGS += -DUSE_CIVETWEB
endif
# We pipe the output of compiler through tee. If the user wanted gcc color, make sure they get it.
ifdef GCC_COLORS

View File

@ -17,7 +17,9 @@ USE_JAVA = @USE_JAVA@
JAVAC = @JAVA_CC@
TRICK_OFFLINE = @TRICK_OFFLINE@
TRICK_DISABLE_CIVET = @TRICK_DISABLE_CIVET@
USE_CIVETWEB = @USE_CIVETWEB@
CIVETWEB_HOME = @CIVETWEB_HOME@
USE_X_WINDOWS = @USE_X_WINDOWS@

View File

@ -52,8 +52,8 @@ ifeq ($(USE_ER7_UTILS_CHECKPOINTHELPER), 1)
SWIG_DEFS += -DUSE_ER7_UTILS_CHECKPOINTHELPER
endif
ifeq ($(TRICK_CIVET), 1)
SWIG_DEFS += -DUSE_CIVET
ifeq ($(USE_CIVETWEB), 1)
SWIG_DEFS += -DUSE_CIVETWEB
endif
default: $(SWIG_OBJECT_FILES) $(TRICK_LIB) $(TEST_DIR)

View File

@ -12,7 +12,7 @@ PURPOSE: (Represent the state of a variable server websocket connection.)
#include "civet/CivetServer.h"
#endif
#include "trick/WebSocketSession.hh"
#include "WebSocketSession.hh"
#include "VariableServerVariable.hh"
class VariableServerSession : public WebSocketSession {

View File

@ -4,7 +4,7 @@ PURPOSE: (Represent Websocket connection.)
#ifndef WEB_SOCKET_SESSION_HH
#define WEB_SOCKET_SESSION_HH
#ifdef USE_CIVET
#if USE_CIVETWEB
#include <string>
#ifndef SWIG
#include "civet/CivetServer.h"
@ -28,4 +28,4 @@ class WebSocketSession {
};
#endif
#endif
#endif

View File

@ -11,7 +11,7 @@ MKDIR = mkdir
CFLAGS = -g -Wall
CPPFLAGS = -g -Wall -std=c++11
INCLUDE_DIRS = -Iinclude -I${TRICK_HOME}/include
INCLUDE_DIRS = -I${PWD}/include -I${CIVETWEB_HOME}/include -I${TRICK_HOME}/include
OBJDIR = obj
LIBDIR = lib

View File

@ -16,9 +16,9 @@ PURPOSE: (Represent the state and initial conditions for my server)
#include "trick/message_type.h"
#include "trick/input_processor_proto.h"
#include "trick/exec_proto.h"
#include "../include/simpleJSON.hh"
#include "../include/VariableServerSession.hh"
#include "trick/WebSocketSession.hh"
#include "simpleJSON.hh"
#include "VariableServerSession.hh"
#include "WebSocketSession.hh"
#ifndef SWIG
#include "civet/CivetServer.h"
@ -391,4 +391,4 @@ void MyCivetServer::handleHTTPGETrequest(struct mg_connection *conn, const struc
ss << "Error: http api " << handlerName << " is not implemented.";
http_send_error(conn, 404, ss.str().c_str(), ss.str().size(), 100);
}
}
}

View File

@ -16,8 +16,8 @@ LIBRARY DEPENDENCIES:
#include "trick/memorymanager_c_intf.h"
#include "trick/input_processor_proto.h"
#include "trick/exec_proto.h"
#include "../include/VariableServerSession.hh"
#include "../include/simpleJSON.hh"
#include "VariableServerSession.hh"
#include "simpleJSON.hh"
// CONSTRUCTOR
VariableServerSession::VariableServerSession( struct mg_connection *nc ) : WebSocketSession(nc) {

View File

@ -1,5 +1,5 @@
#include "trick/memorymanager_c_intf.h" // for get_size.
#include "../include/VariableServerVariable.hh"
#include "VariableServerVariable.hh"
#include <math.h> // for fpclassify
#include <iomanip> // for setprecision
#include <stdarg.h>

View File

@ -4,7 +4,7 @@ LIBRARY DEPENDENCIES:
( (../src/http_GET_handlers.o))
**************************************************************************/
#include "../include/http_GET_handlers.hh"
#include "http_GET_handlers.hh"
#include "trick/MyCivetServer.hh"
#include "trick/message_proto.h"
#include "trick/message_type.h"

View File

@ -2,7 +2,7 @@
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include "../include/simpleJSON.hh"
#include "simpleJSON.hh"
class LexicalAnalyzer {
public: