From f9f800e6471a9c189702a4e3ad1b0a2f3e545066 Mon Sep 17 00:00:00 2001 From: Christian Nowke <nowke@vr.rwth-aachen.de> Date: Mon, 14 Mar 2016 14:07:39 +0100 Subject: [PATCH] proudly presenting the nett-python bindings! --- CMake/CMakeHelpers.cmake | 16 +++++++++++++++ CMakeLists.txt | 8 ++++++-- include/nett-python/_SourceFiles.cmake | 24 ---------------------- src/nett-python/nett-python.cpp | 22 ++++++++++++-------- src/nett-python/specializations_template.h | 1 + 5 files changed, 36 insertions(+), 35 deletions(-) delete mode 100644 include/nett-python/_SourceFiles.cmake create mode 100644 src/nett-python/specializations_template.h diff --git a/CMake/CMakeHelpers.cmake b/CMake/CMakeHelpers.cmake index 4afd1a4..a237e6e 100644 --- a/CMake/CMakeHelpers.cmake +++ b/CMake/CMakeHelpers.cmake @@ -4,8 +4,24 @@ macro (add_event arg1 event_name dir dir_out) exec_program( "protoc" "${PROTOBUF_BIN}" ARGS "${dir}/${event_name}.proto" "--proto_path=${dir}" "--python_out=${dir_out}" OUTPUT_VARIABLE output ) list (APPEND ${arg1}_EVENT_SOURCE_FILES "${dir}/${event_name}.pb.h" "${dir}/${event_name}.pb.cc") + list (APPEND EVENT_NAME_LIST ${event_name}) # message ("output off protoc is: ${output}") # message ("${dir}") # message ("${dir_out}") endmacro() + + +macro ( generate_specializations ) + + foreach ( entry ${EVENT_NAME_LIST} ) + set (_EVENT_NAMES "${_EVENT_NAMES}\nSPECIALIZE_MESSAGE_TYPE( ${entry} )" ) + endforeach() + + configure_file( + src/nett-python/specializations_template.h + specializations.h + @ONLY ) +message ( "successfully generated python_slot specializations" ) + +endmacro() \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 04f78bb..bba7633 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,8 +36,10 @@ include_directories (${NETT_INCLUDE_DIR}) include_directories (${BOOST_INCLUDE_DIR}) include_directories (${PYTHON_INCLUDE_DIR}) include_directories (${PROTOBUF_INCLUDE_DIR}) -include_directories ("${CMAKE_CURRENT_SOURCE_DIR}/include") -include_directories ("${CMAKE_CURRENT_SOURCE_DIR}/include") + +#included for generated specialization header file +include_directories ("${CMAKE_CURRENT_BINARY_DIR}") + add_event ( nett_python routing_message ${NETT_SCHEMA_DIR} ${PROJECT_BINARY_DIR} ) add_event ( nett_python string_message ${NETT_SCHEMA_DIR} ${PROJECT_BINARY_DIR} ) @@ -69,3 +71,5 @@ add_custom_command( TARGET nett_python COMMENT "copying dll to pyd module extension" ) endif() + +generate_specializations() diff --git a/include/nett-python/_SourceFiles.cmake b/include/nett-python/_SourceFiles.cmake deleted file mode 100644 index 23ec81a..0000000 --- a/include/nett-python/_SourceFiles.cmake +++ /dev/null @@ -1,24 +0,0 @@ -set( RelativeDir "include/nett-python" ) -set( RelativeSourceGroup "include/nett-python" ) - -set( DirFiles -# _SourceFiles.cmake -) -set( DirFiles_SourceGroup "${RelativeSourceGroup}" ) - -set( LocalSourceGroupFiles ) -foreach( File ${DirFiles} ) - list( APPEND LocalSourceGroupFiles "${RelativeDir}/${File}" ) - list( APPEND ProjectSources "${RelativeDir}/${File}" ) -endforeach() -source_group( ${DirFiles_SourceGroup} FILES ${LocalSourceGroupFiles} ) - -set( SubDirFiles "" ) -foreach( Dir ${SubDirs} ) - list( APPEND SubDirFiles "${RelativeDir}/${Dir}/_SourceFiles.cmake" ) -endforeach() - -foreach( SubDirFile ${SubDirFiles} ) - include( ${SubDirFile} ) -endforeach() - diff --git a/src/nett-python/nett-python.cpp b/src/nett-python/nett-python.cpp index d420661..d407447 100644 --- a/src/nett-python/nett-python.cpp +++ b/src/nett-python/nett-python.cpp @@ -68,18 +68,22 @@ private: std::shared_ptr < nett::slot_in < event_type > > slot_; }; +#define SPECIALIZE_MESSAGE_TYPE( message_name ) \ + class_< python_slot_out < ##message_name > >( "slot_out_"#message_name"", init<std::string>() ) \ + .def( "send", &python_slot_out< ##message_name >::send ) \ + ; \ +\ +class_< python_slot_in < ##message_name > >( "slot_in_"#message_name"" ) \ + .def( "connect", &python_slot_in< ##message_name >::connect ) \ + .def( "receive", &python_slot_in< ##message_name >::receive ) \ + ; + + BOOST_PYTHON_MODULE(nett_python) { def( "initialize", &nett::initialize ); //def( "shutdown", &nett::shutdown); - class_< python_slot_out < string_message > >( "slot_out_string", init<std::string>() ) - .def( "send", &python_slot_out< string_message >::send) - ; - - class_< python_slot_in < string_message > >( "slot_in_string" ) - .def( "connect", &python_slot_in< string_message >::connect ) - .def( "receive", &python_slot_in< string_message >::receive) - ; - + //include auto-generated definitions + #include "specializations.h" } \ No newline at end of file diff --git a/src/nett-python/specializations_template.h b/src/nett-python/specializations_template.h new file mode 100644 index 0000000..f2a10de --- /dev/null +++ b/src/nett-python/specializations_template.h @@ -0,0 +1 @@ +@_EVENT_NAMES@ -- GitLab