title: c++ back end call the python level defined callbacks with swig wrapper
body: <p>I am wrapping a library which was written in C++ to Python API
  <a href="https://github.com/gtkqq/libwebqq.git" rel="noreferrer">libwebqq</a></p>
  
  <p>There is a type which is defined in boost function .</p>
  
  <pre><code>typedef boost::function&lt;void (std::string)&gt; EventListener;
  </code></pre>
  
  <p>Python level can define "EventListener" variable callbacks.</p>
  
  <p>There is also a map structure in C++ level which is event_map in class Adapter.
  The key type of event_map is a QQEvent enum type and the value type of event_map is class "Action" which wraps EvenListener.</p>
  
  <pre><code>class Action
  {
  
      EventListener _callback;
  
      public:
      Action (){
          n_actions++;
      }
  
      Action(const EventListener &amp; cb ){
      setCallback(cb);
      }
  
      virtual void operator()(std::string data) {
      _callback(data);
      }
      void setCallback(const EventListener &amp; cb){
          _callback = cb;
      }
  
      virtual ~Action(){ std::cout&lt;&lt;"Destruct Action"&lt;&lt;std::endl; n_actions --; }
      static int n_actions;
  };
  
  
  class Adapter{
  
      std::map&lt;QQEvent, Action &gt; event_map;
  
  public:
      Adapter();
      ~Adapter();
      void trigger( const QQEvent &amp;event, const std::string data);
      void register_event_handler(QQEvent event, EventListener callback);
      bool is_event_registered(const QQEvent &amp; event);
      void delete_event_handler(QQEvent event);
  };
  </code></pre>
  
  <p>"register_event_handler" in class Adapter is the API to register a callback function to related event. 
  And C++ back end will call it if event happened. But we need to implement the callbacks in python level. And I wrapped the callback type in "callback.i"</p>
  
  <p>The problem is , when I call the register_event in test python <a href="https://github.com/gtkqq/libwebqq/blob/master/wrappers/python/testwrapper.py#L40" rel="noreferrer">script</a>, a type error always occurs:</p>
  
  <pre><code>Traceback (most recent call last):
  File "testwrapper.py", line 44, in &lt;module&gt;
  worker = Worker()
  File "testwrapper.py", line 28, in __init__
  a.setCallback(self.on_message)
  File "/home/devil/linux/libwebqq/wrappers/python/libwebqqpython.py", line 95, in setCallback
  def setCallback(self, *args): return _libwebqqpython.Action_setCallback(self, *args)
  TypeError: in method 'Action_setCallback', argument 2 of type 'EventListener const &amp;'
  Destruct Action
  </code></pre>
  
  <p>Please help to figure out the root cause of this type error and a solution to this problem. </p>