I am working on a way to send and receive events.
I want the following:
Events shall be sent from a self-written plugin to my application.
The Application shall decide what to do with these Events by comparing the csEventID from the Event.
This is done in the OnUnhandledEvent Function. The Application is derived from public csBaseEventHandler, too.
The Plugin is called MoGUI and this is how I initialized the Event system (the first three lines are taken from the crystalspace 1.4 documentation on how to write plugins)
bool MoGUI::Initialize (iObjectRegistry* r)
object_reg = r;
ev_queue = csQueryRegistry<iEventQueue>(object_reg);
fprintf(stderr,"MoGUI: 1. kein Ereignissystem verfügbar!\n");
ev_outlet = ev_queue->GetEventOutlet();
fprintf(stderr,"MoGUI: 3. kein Ereignissystem verfügbar!\n");
test1 = ev_outlet->CreateEvent();
fprintf(stderr,"MoGUI: kein Ereignis gesendet!\n");
An Event is sent in another function:
void MoGUI::MouseClicked(int mouse_x, int mouse_y)
MoGUI::test1->Name = csEventID("crystalspace.mogui.hallowelt");
fprintf(stderr,"MoGUI: Ereignis gesendet!\n");
The relevant parts of the Header file:
class MoGUI : public scfImplementation2<MoGUI,iMoGUI,iComponent>
csRef <iEventQueue> ev_queue;
csRef <iEventPlug> ev_plug;
The Code in the Application which is responsible for handling all Events that aren't handled in other ways:
bool freethespeed::OnUnhandledEvent(iEvent &event)
if((&event)->Name == csEventID("crystalspace.mogui.hallowelt"))
fprintf(stdout, "Die GUI sagte HalloWelt!\n");
Changing the event name doesn't have any effect. I tried "mogui.hallowelt" and "freethespeed.gui.hallowelt" .
1) Event sending in the manner shown above doesn't work. The Application doesn't receive the Event, but the function MoGUI::MouseClicked is called (the message "Ereignis gesendet" appears. Why is my approach not working?
2) I based the event handling Code on the CS API. Is my approach to send events correct or is a object or a function missing?
3) When I try to initialize ev_queue with CreateEventQueue i get an segmentation fault. Commenting out CreateEventQueue doesn't have an effect.
Informations about the software I use:
crystalspace: 1.4 (self-compiled)
compiler: g++ 4.4.5 (I'm compiling using the makefile for own applications and plugins)
operating system: Debian GNU/Linux Squeeze (6.0)