diff --git a/src/nett-python/nett-python.cpp b/src/nett-python/nett-python.cpp index 714b91fa262b72e7c5247533b377018eedc4bd19..d420661645259b7cb75b988480b71806545e6578 100644 --- a/src/nett-python/nett-python.cpp +++ b/src/nett-python/nett-python.cpp @@ -13,21 +13,13 @@ using namespace boost::python; -const std::string& a = "tcp://127.0.0.1:65445"; - -void initA(std::string endpoint) -{ - nett::initialize( a ); -} - - 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 ); + slot_ = nett::make_slot_out< event_type >( slot_tag ); } void send( std::string const & message ) @@ -45,7 +37,35 @@ private: return message; } - std::shared_ptr < nett::slot_out<event_type> > slot_; + std::shared_ptr < nett::slot_out< event_type > > slot_; +}; + +template <class event_type> +class python_slot_in +{ +public: + python_slot_in() + { + slot_ = nett::make_slot_in< event_type >(); + } + + void connect( std::string const & endpoint, std::string const & slot_tag ) + { + slot_->connect( endpoint, slot_tag ); + } + + std::string receive() + { + event_type message = slot_->receive(); + std::string binary_message; + if (! message.SerializeToString(&binary_message) ) + { + throw std::runtime_error( "protobuf SerializeToString() failed" ); + } + return binary_message; + } +private: + std::shared_ptr < nett::slot_in < event_type > > slot_; }; BOOST_PYTHON_MODULE(nett_python) @@ -57,5 +77,9 @@ BOOST_PYTHON_MODULE(nett_python) .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) + ; } \ No newline at end of file