开发者

Wrap C callback via SWIG

开发者 https://www.devze.com 2023-02-04 13:21 出处:网络
I\'m trying to wrap some Gstreamer functionlity into PHP using SWIG, but i can\'t figure out how to handle C callb开发者_StackOverflow社区acks. Can I call a PHP function from C? How will you handle a

I'm trying to wrap some Gstreamer functionlity into PHP using SWIG, but i can't figure out how to handle C callb开发者_StackOverflow社区acks. Can I call a PHP function from C? How will you handle a callback like the following?

#include <gst/gst.h>

// ...

static gboolean my_callback(GstBus *bus, GstMessage *message, gpointer user_data) {
  g_print("Got %s message\n", GST_MESSAGE_TYPE_NAME(message));

  switch(GST_MESSAGE_TYPE(message)) {
    // ...
  }

  return TRUE;
}

main(gint argc, gchar *argv[])
{
  GstElement *pipeline;
  GstBus *bus;

  gst_init (&argc, &argv);

  pipeline = gst_pipeline_new ("my_pipeline");

  /* add handler */
  bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline)); 
  gst_bus_add_watch (bus, my_bus_callback, NULL); // ------------<
  gst_object_unref (bus);

  // ...
}


If you download the latest swig source (2.0.1) there is an example of using callbacks with PHP. It's in the swig-2.0.1/Examples/php/callback directory.

0

精彩评论

暂无评论...
验证码 换一张
取 消