Crystal Space
Welcome, Guest. Please login or register.
October 01, 2014, 05:24:27 pm

Login with username, password and session length
Search:     Advanced search
9020 Posts in 2053 Topics by 8569 Members
Latest Member: Embingos
* Home Help Search Login Register
+  Crystal Space
|-+  Crystal Space Development
| |-+  Support
| | |-+  sending and receiving Events
« previous next »
Pages: [1] Print
Author Topic: sending and receiving Events  (Read 1034 times)
Freethespeed-moritz
Newbie
*
Posts: 2


View Profile Email
« 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)
Code:
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:
Code:
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:
Code:
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:
Code:
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
« Last Edit: November 24, 2010, 05:44:58 pm by Freethespeed-moritz » Logged
Freethespeed-moritz
Newbie
*
Posts: 2


View Profile Email
« Reply #1 on: November 24, 2010, 08:30:12 pm »

Sorry,
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.

Edit:
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:
Code:
eventname_reg = csQueryRegistry<iEventNameRegistry> (GetObjectRegistry());
if (!eventname_reg)
  {
    return ReportError("Failed to locate Event Name Registry!");
  }

Where is the Problem? How to receive Events?
« Last Edit: November 24, 2010, 10:26:09 pm by Freethespeed-moritz » Logged
Pneumonia
Newbie
*
Posts: 1


View Profile WWW Email
« Reply #2 on: December 03, 2010, 10:36:36 am »

I also want to know what and how are u doing now>I am so excited with your plug and progress.
Logged

Pages: [1] Print 
« previous next »
Jump to:  

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.345 seconds with 15 queries.