Re: [Vala] Check if event-handler is registered already
- From: "Gilzad Hamuni" <gilli4 gmx net>
- To: vala-list gnome org
- Subject: Re: [Vala] Check if event-handler is registered already
- Date: Fri, 18 Jul 2014 20:30:54 +0200
Hi again,
this was a GLib-related question, but for some reason I hadn't been careful enough, which made me ask here.
Sorry.
The answer is:
You have to memorize the given handler ID, if you like to check whether your handler is registered already.
Then you can use GLib.SignalHandler(instance, handlerId) to find out if the handler is connected:
ulong dataReceivedHandler = 0;
if(!SignalHandler.is_connected(someInstance, dataReceivedHandler))
{
dataReceivedHandler = someInstance.DataReceived.connect(OnDataReceived);
}
private void OnDataReceived(uint8 byte)
{
//do something.
}
It's safe to start off by checking a handler ID whose value is 0, because SignalHandler.is_connected() will
return false then.
Best,
gilzad
Gesendet: Dienstag, 15. Juli 2014 um 15:07 Uhr
Von: "Gilzad Hamuni" <gilli4 gmx net>
An: vala-list gnome org
Betreff: [Vala] Check if event-handler is registered already
Hi all,
suppose I have a class that can take callbacks to invoke them in case of any event:
public signal void DataReceived(uint8 byte);
//...
DataReceived(byte);
...and I have a client that registers its handler to it:
someInstance.DataReceived.connect(OnDataReceived);
//...
private void OnDataReceived(uint8 byte)
{
//do something.
}
..how can I check if my handler was registered already to avoid it from being registered a several times?
I'd like to do something like this:
if( !someInstance.DataReceived.handler_is_connected(OnDataReceived) )
{
someInstance.DataReceived.connect(OnDataReceived);
}
Thanks in advance for any hint.
gilzad
_______________________________________________
vala-list mailing list
vala-list gnome org
https://mail.gnome.org/mailman/listinfo/vala-list
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]