Issues using EventQueue within a class

30 Mar 2019

Hi there,

I'm trying to use the shared event queue for socket events as detailed in the example:

I have a class that takes data from a TCPSocket and processes it. So I have a server socket that presents client connections to my class for sending/receiving data.

In main() I have a TCPSocket that I call open, bind and then listen and I pass a method of my class as the event handler.

EventQueue *queue = mbed_event_queue();
Event<void()> handler = queue->event(&DaliMaster, &Dali::server_sigio, &socket);

What I want to do is have my class handle the socket->accept() and create a new event handler for the client connection. So I have the following code after I've got a new socket from accept():

Class::method() {
    Event<void()> client_handler = queue->event(this, &Dali::client_sigio, client);

What I'm getting is a runtime exception in Event.h on line 158 which is an assert to check "id". It fires when I call client_handler() the first time so perhaps I can't set up the event like I've done?

In the second call, client is a pointer to a TCPSocket.

Any ideas what I'm doing wrong?

30 Mar 2019

This is the exception:

++ MbedOS Error Info ++
Error Status: 0x80FF0144 Code: 324 Module: 255
Error Message: Assertion failed: id
Location: 0xF777
File: ./mbed-os/events/Event.h+158
Error Value: 0x0
Current Thread: shared_event_queue  Id: 0x10000EEC Entry: 0x12B59 StackSize: 0x800 StackMem: 0x10000F38 SP: 0x1000161C 
For more info, visit:
-- MbedOS Error Info --
30 Mar 2019

Hmm, okay, after some reading of the high level description of the API I thought I might be in a context where I can't call the event. So I changed the following and now it works. If anyone wants to explain to me why that would help. Thanks.

	Event<void()> client_handler = queue->event(this, &Dali::client_sigio, client);
31 Mar 2019

I think I've exhausted my C++ foo. I think I have an issue of scope maybe. I'm trying to create the client_handler event when in interrupt context after socket->accept but is the event lost as soon as I exit the current method?

I can connect to the server, but as soon as I send any data or disconnect I get an assertion firing.

	switch (next_state) {
        case LISTENING:
			this->client = socket->accept(&err);
			switch(err) {
                case NSAPI_ERROR_WOULD_BLOCK:
                    // Continue to listen
				case NSAPI_ERROR_OK: {
					// Accepted connection
					Event<void()> client_handler = this->queue->event(this, &Dali::client_sigio, this->client);
					next_state = ACCEPT;
                    // Error in connection phase
					_uart->printf("Dali::server_sigio: err = %d\n\r", err);	
					next_state = CLOSE;
02 Apr 2019

Perhaps a simpler question is in order.

Given I can declare an event in the above example like this:

Event<void()> client_handler = this->queue->event(this, &Dali::client_sigio, this->client);

How do I declare the same event in my class and assign to it later on in some method call? I can't get the syntax of the template correct.

class myClass {
  EventQueue *queue;
  Event<void()> client_handler;

myClass::my_method() {
  queue = mbed_event_queue();
  client_handler = queue->event(this, &myClass::some_other_method, this->socket);
07 Apr 2019

I've created an example of what I'm trying to do. In the following example, I'm posting the client_handler event to the shared queue but it never gets called. What am I doing wrong?

06 Nov 2019

I have a similar issue with Event.h and I get the same exact error code. I haven't been able to get around it, but I used a very similar implementation to the example under called "Using mbed-events" at I don't know if it will help you with your issue.

You need to log in to post a reply