[Vala] Allowable to add user data to callback?
- From: bsquared <bwcode4u gmail com>
- To: vala-list <vala-list gnome org>
- Subject: [Vala] Allowable to add user data to callback?
- Date: Sat, 20 Aug 2011 14:35:03 -0700
Hello,
I am trying to follow a c example for pulse audio and in it's setting
of a callback it adds a userdata parameter.
Can I do the same with vala? or should I use a field to store the
userdata from the callback?
The example [1] is approximating this...
/////////// 8< from libpulse.vapi ////////////
public delegate void NotifyCb(Context c);
public void set_state_callback(NotifyCb? cb = null);
///////////////////////////////////////////////////////////
private void pa_set_state_cb(Context ctx, void* userdata) {
Context.State state = ctx.get_state();
switch (state) {
case e: *pa_ready = 2; break;
case x: *pa_ready = 1; break;
case y:
case z:
default: *pa_ready = 0; break;
}
}
public int some_method() {
int pa_ready = 0;
PulseAudio.Context context = new PulseAudio.Context();
context.set_state_callback(this.pa_set_state_cb, &pa_ready);
int state = 0;
context.connect();
while (true) {
if (pa_ready == 0} {}
if (pa_ready == 1) {}
if (pa_ready == 2) {}
}
}
--
Regards,
-Brian
[1] - http://www.ypass.net/blog/2009/10/pulseaudio-an-async-example-to-get-device-lists/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]