Crystal Space
Welcome, Guest. Please login or register.
September 23, 2017, 08:18:38 am

Login with username, password and session length
Search:     Advanced search
9054 Posts in 2047 Topics by 74229 Members
Latest Member: Zihaokaraly334
* Home Help Search Login Register
  Show Posts
Pages: [1]
1  Crystal Space Development / Support / Re: sending and receiving Events on: November 24, 2010, 08:30:12 pm
I just went on reading the CS API and I read about iEventNameRegistry which is responsible for Event names.
Well, I'll try if this solves the whole problem.

No, I couldn't get it working. I can create i iEventNameRegistry in the Application,
but every time I want to use it the Application crashes with a segmentation fault.

After creation of the iEventNameRegistry object I check if it is created correctly:
eventname_reg = csQueryRegistry<iEventNameRegistry> (GetObjectRegistry());
if (!eventname_reg)
    return ReportError("Failed to locate Event Name Registry!");

Where is the Problem? How to receive Events?
2  Crystal Space Development / Support / sending and receiving Events on: November 24, 2010, 05:40:11 pm
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;

  ev_queue = csQueryRegistry<iEventQueue>(object_reg);
    fprintf(stderr,"MoGUI: 1. kein Ereignissystem verfügbar!\n");
    return false;

  ev_outlet = ev_queue->GetEventOutlet();
    fprintf(stderr,"MoGUI: 3. kein Ereignissystem verfügbar!\n");
    return false;

  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>
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
Pages: [1]
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 5.141 seconds with 18 queries.