From b976f2cacd0029303c33ae6d44fd1d3d106d72ec Mon Sep 17 00:00:00 2001
From: Christian Nowke <nowke@vr.rwth-aachen.de>
Date: Fri, 11 Mar 2016 17:36:51 +0100
Subject: [PATCH] working slot_out

---
 CMake/CMakeHelpers.cmake        |  3 +++
 CMakeLists.txt                  | 11 ++++-----
 src/nett-python/nett-python.cpp | 43 +++++++++++++++++++++++++++------
 3 files changed, 44 insertions(+), 13 deletions(-)

diff --git a/CMake/CMakeHelpers.cmake b/CMake/CMakeHelpers.cmake
index b56e39e..4afd1a4 100644
--- a/CMake/CMakeHelpers.cmake
+++ b/CMake/CMakeHelpers.cmake
@@ -2,6 +2,9 @@
 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")
+  
 #  message ("output off protoc is: ${output}")
 #  message ("${dir}")
 #  message ("${dir_out}")
diff --git a/CMakeLists.txt b/CMakeLists.txt
index d052e59..04f78bb 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -29,8 +29,6 @@ set (NETT_LIBRARY_DEBUG "" CACHE FILEPATH "The nett debug library to link agains
 
 set( ZMQ_LIBRARY "" CACHE FILEPATH "The zmq library to link against" )
 
-
-
 include( "include/nett-python/_SourceFiles.cmake" )
 include( "src/nett-python/_SourceFiles.cmake" )
 
@@ -41,16 +39,17 @@ include_directories (${PROTOBUF_INCLUDE_DIR})
 include_directories ("${CMAKE_CURRENT_SOURCE_DIR}/include")
 include_directories ("${CMAKE_CURRENT_SOURCE_DIR}/include")
 
-add_library (nett_python SHARED ${ProjectSources})
+add_event ( nett_python routing_message ${NETT_SCHEMA_DIR} ${PROJECT_BINARY_DIR} )
+add_event ( nett_python string_message ${NETT_SCHEMA_DIR} ${PROJECT_BINARY_DIR} )
+
+add_library (nett_python SHARED ${ProjectSources} ${nett_python_EVENT_SOURCE_FILES})
+
 target_link_libraries( nett_python optimized ${NETT_LIBRARY} debug ${NETT_LIBRARY_DEBUG})
 target_link_libraries( nett_python optimized ${PYTHON_LIBRARY} debug ${PYTHON_LIBRARY_DEBUG})
 target_link_libraries( nett_python optimized ${BOOST_PYTHON_LIBRARY} debug ${BOOST_PYTHON_LIBRARY_DEBUG})
 target_link_libraries( nett_python optimized ${PROTOBUF_LIBRARY} debug ${PROTOBUF_LIBRARY_DEBUG})
 target_link_libraries( nett_python ${ZMQ_LIBRARY} )
 
-add_event ( nett_python routing_message ${NETT_SCHEMA_DIR} ${PROJECT_BINARY_DIR} )
-add_event ( nett_python string_message ${NETT_SCHEMA_DIR} ${PROJECT_BINARY_DIR} )
-
 if( WIN32 )
 add_custom_command( TARGET nett_python
                     POST_BUILD
diff --git a/src/nett-python/nett-python.cpp b/src/nett-python/nett-python.cpp
index 51e8973..714b91f 100644
--- a/src/nett-python/nett-python.cpp
+++ b/src/nett-python/nett-python.cpp
@@ -11,22 +11,51 @@
 
 #include <../schema/string_message.pb.h>
 
-
 using namespace boost::python;
 
-std::shared_ptr<nett::slot_in<string_message>> create_slot_in_string_message()
+const std::string& a = "tcp://127.0.0.1:65445";
+
+void initA(std::string endpoint)
 {
-    return nett::make_slot_in<string_message>();
+    nett::initialize( a );
 }
 
-//nett::make_slot_out<string_message>(const std::string &slot_tag);
-
 
+template <class event_type>
+class python_slot_out
+{
+public:
+    python_slot_out( std::string const &slot_tag )
+    {
+        slot_ = nett::make_slot_out<event_type>( slot_tag );
+    }
+
+    void send( std::string const & message )
+    {
+        slot_->send(convert(message));
+    }
+
+private:
+    event_type convert( std::string const & serialized )
+    {
+        event_type message;
+        if ( !message.ParseFromString( serialized ) )
+            throw std::runtime_error( "protobuf ParseFromString() failed" );
+
+        return message;
+    }
+
+    std::shared_ptr < nett::slot_out<event_type> > slot_;
+};
 
 BOOST_PYTHON_MODULE(nett_python)
 {
-     def("initialize", &nett::initialize);
+    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_ < nett::slot_in < string_message >, boost::noncopyable >( "slot_in_string", no_init );
 }
\ No newline at end of file
-- 
GitLab