initial implementation

This commit is contained in:
Roland Conybeare 2023-10-18 16:06:09 -04:00
commit 42cd9aedca
7 changed files with 123 additions and 0 deletions

43
CMakeLists.txt Normal file
View file

@ -0,0 +1,43 @@
# xo-pywebutil/CMakeLists.txt
cmake_minimum_required(VERSION 3.10)
project(xo_pywebutil VERSION 0.1)
enable_language(CXX)
# common XO cmake macros (see github.com:Rconybea/xo-cmake)
include(xo_macros/xo_cxx)
include(xo_macros/code-coverage)
# ----------------------------------------------------------------
# unit test setup
enable_testing()
# activate code coverage for all executables + libraries (when configured with -DCODE_COVERAGE=ON)
add_code_coverage()
# 1. assuming that /nix/store/ prefixes .hpp files belonging to gcc, catch2 etc.
# we're not interested in code coverage for these sources.
# 2. exclude the utest/ subdir, we don't need coverage on the unit tests themselves;
# rather, want coverage on the code that the unit tests exercise.
#
# NOTE: this seems to work only with the 'ccov-all' target. In particular, doesn't seem to do anything with the 'ccov' target
#
add_code_coverage_all_targets(EXCLUDE /nix/store/* ${PROJECT_SOURCE_DIR}/utest/* ${PROJECT_BINARY_DIR}/local/* ${PROJECT_SOURCE_DIR}/repo/*)
# ----------------------------------------------------------------
# c++ settings (usually temporary)
set(PROJECT_CXX_FLAGS "")
add_definitions(${PROJECT_CXX_FLAGS})
xo_toplevel_compile_options()
# ----------------------------------------------------------------
# sources
add_subdirectory(src/pywebutil)
# ----------------------------------------------------------------
# provide find_package() support
xo_export_cmake_config(${PROJECT_NAME} ${PROJECT_VERSION} ${PROJECT_NAME}Targets)

9
EXAMPLES Normal file
View file

@ -0,0 +1,9 @@
Creating this pybind11 library to hold low-dependency wrappers
used for interaction between {websock/, pywebsock/} and other subsystems.
1. This library needs to be a (runtime) dependency of pyxxx libraries that
use reactor::EventStore, for example pyprocess/, to supply wrappers
for EndpointDescr and Alist.
2. If we chose to put this code in pywebsock/, then pywebsock + libwebsocket
would become runtime dependencies of libraries like pyprocess/.

View file

@ -0,0 +1,4 @@
@PACKAGE_INIT@
include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake")
check_required_components("@PROJECT_NAME@")

1
include/README.md Normal file
View file

@ -0,0 +1 @@
placeholder for future pywebutil #include files

View file

@ -0,0 +1,7 @@
# xo-pywebutil/src/pywebutil/CMakeLists.txt
set(SELF_LIB pywebutil)
set(SELF_SRCS pywebutil.cpp)
xo_pybind11_library(${SELF_LIB} ${PROJECT_NAME}Targets ${SELF_SRCS})
xo_pybind11_dependency(${SELF_LIB} webutil)

View file

@ -0,0 +1,34 @@
/* @file pywebutil.cpp */
#include "pywebutil.hpp"
#include "xo/webutil/HttpEndpointDescr.hpp"
#include "xo/webutil/StreamEndpointDescr.hpp"
#include "xo/pyutil/pyutil.hpp"
#include <pybind11/chrono.h>
namespace xo {
//using xo::web::Alist;
using xo::web::HttpEndpointDescr;
using xo::ref::rp;
//using xo::time::utc_nanos;
namespace py = pybind11;
namespace web {
PYBIND11_MODULE(PYWEBUTIL_MODULE_NAME(), m) {
//PYxxx_IMPORT_MODULE();
/* module docstring */
m.doc() = "pybind11 plugin for xo.web_util";
py::class_<HttpEndpointDescr>(m, "EndpointDescr")
.def_property_readonly("uri_pattern", &HttpEndpointDescr::uri_pattern)
.def("__repr__", &HttpEndpointDescr::display_string);
py::class_<StreamEndpointDescr>(m, "StreamEndpointDescr")
.def_property_readonly("uri_pattern", &StreamEndpointDescr::uri_pattern)
.def("__repr__", &StreamEndpointDescr::display_string);
} /*web*/
} /*namespace web*/
} /*namespace xo*/
/* end pywebutil.cpp */

View file

@ -0,0 +1,25 @@
/* @file pywebutil.hpp
*
* automatically generated from src/pywebutil/pywebutil.hpp.in
* see src/pywebutil/CMakeLists.txt
*/
/* python requires module name = library name
* example:
* PYBIND11_MODULE(PYWEBUTIL_MODULE_NAME(), m) { ... }
*/
#define PYWEBUTIL_MODULE_NAME() @SELF_LIB@
/* example:
* py::module_::import(PYWEBUTIL_MODULE_NAME_STR)
*/
#define PYWEBUTIL_MODULE_NAME_STR "@SELF_LIB@"
/* example:
* PYWEBUTIL_IMPORT_MODULE()
* replaces
* py::module_::import("pywebutil")
*/
#define PYWEBUTIL_IMPORT_MODULE() py::module_::import("@SELF_LIB@")
/* end pywebutil.hpp */