diff --git a/CMake/CMakeHelpers.cmake b/CMake/CMakeHelpers.cmake index 4afd1a43fd79a53254e584723f29599021a46e66..a237e6e1dea877214388fe77b2fe9308fcccfa08 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 04f78bb385fbf7deddf26bcc11af87b2d27ae408..bba763301eaeafb3ba79f4ce7e5e6c0e54510b7b 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 23ec81af21eed258d0d27d7dee4539a464daebb1..0000000000000000000000000000000000000000 --- 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 d420661645259b7cb75b988480b71806545e6578..d4074473ea77dbba32d7481f71e6df04026d044e 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 0000000000000000000000000000000000000000..f2a10dee461a33ae1a6278704b2f370a262324ad --- /dev/null +++ b/src/nett-python/specializations_template.h @@ -0,0 +1 @@ +@_EVENT_NAMES@