Browse Source

Replaced boost.python with pybind11 in the statistics db

Stefan Schmidt 6 years ago
parent
commit
c9a7ee07b7
2 changed files with 10 additions and 7 deletions
  1. 4 1
      code_boost/src/CMakeLists.txt
  2. 6 6
      code_boost/src/cxx/pcap_processor.cpp

+ 4 - 1
code_boost/src/CMakeLists.txt

@@ -33,6 +33,9 @@ option(SQLITECPP_RUN_CPPLINT OFF)
 include_directories(SQLiteCpp/include)
 add_subdirectory(SQLiteCpp)
 
+# Include pybind11
+include_directories(pybind11/include)
+
 # Find libtins library
 FIND_LIBRARY(TINS_LIBRARY tins)
 IF(TINS_LIBRARY)
@@ -92,4 +95,4 @@ ENDIF ()
 
 # comment this out to build executable (for development)
 #ADD_EXECUTABLE(cpp-pcapreader ${SOURCE_FILES})
-#TARGET_LINK_LIBRARIES(cpp-pcapreader ${Boost_LIBRARIES} "${TINS_LIBRARY}" SQLiteCpp sqlite3 pthread dl)
+#TARGET_LINK_LIBRARIES(cpp-pcapreader ${Boost_LIBRARIES} "${TINS_LIBRARY}" SQLiteCpp sqlite3 pthread dl)

+ 6 - 6
code_boost/src/cxx/pcap_processor.cpp

@@ -412,15 +412,15 @@ bool inline pcap_processor::file_exists(const std::string &filePath) {
  * Comment out if executable should be build & run
  * Comment in if library should be build
  */
-#include <boost/python.hpp>
+#include <pybind11/pybind11.h>
+namespace py = pybind11;
 
-using namespace boost::python;
-
-BOOST_PYTHON_MODULE (libpcapreader) {
-    class_<pcap_processor>("pcap_processor", init<std::string, std::string>())
+PYBIND11_MODULE (libpcapreader, m) {
+    py::class_<pcap_processor>(m, "pcap_processor")
+            .def(py::init<std::string, std::string>())
             .def("merge_pcaps", &pcap_processor::merge_pcaps)
             .def("collect_statistics", &pcap_processor::collect_statistics)
             .def("get_timestamp_mu_sec", &pcap_processor::get_timestamp_mu_sec)
             .def("write_to_database", &pcap_processor::write_to_database)
-            .def("get_db_version", &pcap_processor::get_db_version).staticmethod("get_db_version");
+            .def_static("get_db_version", &pcap_processor::get_db_version);
 }