tags:

views:

70

answers:

4

In specific I am working in linux environment. This is an opengl application. Upon a calculation of certain geometries, I want to be able to fire an event whenever a new geometry is created. Is there any .NET equivalent of events in C ??

Thanks, Vishnu

A: 

Events in C are implemented using function callbacks. The linked question has a couple answers that address how to code callbacks.

Cogwheel - Matthew Orlando
I have native C application in linux environement. More specifically, this is an OpenGL application. On the creation of certain input geometries, i want to be able to call an event, instead of calling a function explicitly. Is there anything analogous to events in .NET ??
de costo
@de costo - Please put that information in your actual question.
sheepsimulator
I added a link to my post. The answers in that other question describe using function pointers for callbacks (the 2nd answer is particularly relevant).
Cogwheel - Matthew Orlando
A: 

With gnome libraries or gtk+ (which is built on top of it)? You can do it all yourself with function pointers, but this is the only "standard" C library that I've personally used that standardized events and callbacks. There's probably others out there, too.

eruciform
A: 

To translate from .NET land:

An "event" is simply the calling of a function. To make this configurable, you need to give the thing that generates the "event" a function pointer. The function pointer is called, and is the thing that is "done" when the "event" occurs.

A thing to "do" is a function in C and C++.

If you only want to "do" one thing upon an "event". You'd pass in a pointer to your function, which is the thing you want to "do" upon your "event" as a function pointer to the thing that causes the "event." This is called a callback. Other posts have lots of examples on how this works.

If you need to "do" multiple things on an "event", you'll need to use a signal/slot implementation like boost::signal. Or if OpenGL has something similar, I'd use that. In that case, you have multiple callbacks.

sheepsimulator
A: 

Though I can't say I'd really recommend using them, a possible alternative to callbacks would be signals.

You can use signal to say how a particular signal should be handled, and raise to send a particular signal. Note, however, that there are serious restrictions on what you can do in a signal handler. Lots of code isn't really written to deal well with signals, and quite a bit of it assumes that almost any signal implies such a serious problem that continued execution after a signal may be problematic.

Jerry Coffin