Fuerteflojo
Fuerteflojo

Reputation: 81

Wrap C callback via SWIG

I'm trying to wrap some Gstreamer functionlity into PHP using SWIG, but i can't figure out how to handle C callbacks. 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);

  // ...
}

Upvotes: 1

Views: 438

Answers (1)

1984isnotamanual
1984isnotamanual

Reputation: 615

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.

Upvotes: 1

Related Questions