Oh yeah, this works. I forgot to instantiate instance = this. :D Thanks Phil!
On Wed, Oct 20, 2010 at 9:16 AM, Ervin <[email protected]> wrote: > Yes that is what i would do if the PrintInterface permits me to do so since > the interface says: > > public void print_value(); > > note that the method is not static. Thus, calling this method using the > static instance of the class > Check returns an error. > > This is how i instantiated statically the class Check: > > public class Check : PrintInterface{ > public static Check instance = null; > } > > and calling the method as: > > Check.instance.print_value(); > > Hmm.. :( > > > On Tue, Oct 19, 2010 at 5:46 PM, Phil Housley > <[email protected]>wrote: > >> On 19 October 2010 03:33, Ervin Orense Balaoro <[email protected]> >> wrote: >> > Yes, static variables will solve the problem. :D >> > >> > Thanks Phil! >> > >> > But there is a limitation to this approach by making Check implement an >> > interface(i.e. PrintInterface), >> > where printf_value() is from the interface implemented: >> > >> > public class Check : PrintInterface{ >> > ... >> > public static int x = 0; >> > >> > public open(){ >> > ... >> > signal(SIGUSR1, sighandler); >> > } >> > ... >> > public void sighandler(int signum) { >> > x++; >> > print_value(); >> > } >> > >> > public void print_value(){ >> > stdout.printf("%d", x); >> > } >> > ... >> > } >> > >> > Do vala have anyway to get this running? >> >> I don't know a general way to do this in any language, but you can do >> it easily for a limited case. Anything that is static'ly addressable >> can be used from the signal handler, so if you assign a particular >> instance of Check to a static variable, you can invoke the method. >> >> The only way to do the specific thing you illustrate is to have one >> callback method per instance of Check, which is only possible if you >> know in advance how many instances you will have. >> >> > On Mon, Oct 18, 2010 at 9:13 PM, Phil Housley < >> [email protected]> >> > wrote: >> >> >> >> On 18 October 2010 09:35, Ervin Orense Balaoro <[email protected]> >> wrote: >> >> > Hello, >> >> > >> >> > I dont know if this is the right place to ask questions regarding >> vala. >> >> > But >> >> > anyway, ill post the question here just in case someone has the same >> >> > experience i had while working with vala using signal from posix. >> >> > >> >> > Code: >> >> > >> >> > public class Check{ >> >> > ... >> >> > public int x = 0; >> >> > >> >> > public open(){ >> >> > ... >> >> > signal(SIGUSR1, sighandler); >> >> > } >> >> > ... >> >> > public void sighandler(int signum) { >> >> > stdout.printf("%d", x++); >> >> > } >> >> > ... >> >> > } >> >> > >> >> > How do we make our signal handlers access the global variables? >> >> > i write a similar code in C, but works okay there. >> >> >> >> The callback needed for signal() is a void -> void method, so there is >> >> no way to pass a pointer to your class instance, and so no way for the >> >> callback to invoke the method on the correct instance of the Check >> >> class. >> >> >> >> Using a static method and variable should work I assume. >> >> >> >> -- >> >> Phil Housley >> > >> > >
_______________________________________________ vala-list mailing list [email protected] http://mail.gnome.org/mailman/listinfo/vala-list
