Hi everyone
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;
csInitializer::CreateEventQueue(object_reg);
ev_queue = csQueryRegistry<iEventQueue>(object_reg);
if(!ev_queue)
{
fprintf(stderr,"MoGUI: 1. kein Ereignissystem verfügbar!\n");
return false;
}
ev_outlet = ev_queue->GetEventOutlet();
if(!ev_outlet)
{
fprintf(stderr,"MoGUI: 3. kein Ereignissystem verfügbar!\n");
return false;
}
test1 = ev_outlet->CreateEvent();
if(!test1)
{
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");
MoGUI::ev_outlet->Post(MoGUI::test1);
fprintf(stderr,"MoGUI: Ereignis gesendet!\n");
MoGUI::fts_gui->ReceiveMouseClick(mouse_x,mouse_y);
}
The relevant parts of the Header file:
class MoGUI : public scfImplementation2<MoGUI,iMoGUI,iComponent>
{
...
private:
iObjectRegistry *object_reg;
csRef <iEventQueue> ev_queue;
csRef <iEventPlug> ev_plug;
csRef<iEventOutlet> ev_outlet;
csRef<iEvent> test1;
};
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" .
My Questions:
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)
Best regards
Moritz