<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Events handling</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/17817/events-handling</link><description>I am looking at this example: github.com/.../main.c 
 In ble_evt_dispatch (line 315), this function forwards an BLE event to all of the modules. By looking at ble_evt_t, none of the fields does not signify which event is for which. So how does the individual</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 21 Nov 2016 12:09:27 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/17817/events-handling" /><item><title>RE: Events handling</title><link>https://devzone.nordicsemi.com/thread/68668?ContentTypeID=1</link><pubDate>Mon, 21 Nov 2016 12:09:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:30091904-695b-470d-9856-d3ad6b30a307</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;The &lt;code&gt;BLE_GAP_EVT_CONNECTED&lt;/code&gt; is sent from the SoftDevice to the application code. This is a type of BLE stack event, and usually only the on_ble_evt() function handles these events. But the event itself is not sent specifically to any event handler. It’s up to the application code on how these events should be handled.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Events handling</title><link>https://devzone.nordicsemi.com/thread/68667?ContentTypeID=1</link><pubDate>Fri, 18 Nov 2016 19:04:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0b95e43a-5d66-42a6-a42e-f79cf21a9f1a</guid><dc:creator>jackbauerctu</dc:creator><description>&lt;p&gt;Thanks for your reply.&lt;/p&gt;
&lt;p&gt;I do understand that part. However, lets say that we organize the services into several different modules. So the event forwarding function would look like:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;static void ble_evt_dispatch(ble_evt_t * p_ble_evt)
{
    service1_on_ble_evt(p_ble_evt);
    service2_on_ble_evt(p_ble_evt);
    service3_on_ble_evt(p_ble_evt);
    service4_on_ble_evt(p_ble_evt);
    service5_on_ble_evt(p_ble_evt);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then, if the event is BLE_GAP_EVT_CONNECTED, then how does the individual event handler knows which service is BLE_GAP_EVT_CONNECTED event for?&lt;/p&gt;
&lt;p&gt;Traditionally, event handlers that I have done usually returns a boolean which signifies that the particular event handler knew the event and properly handled it.  So it saves from other handlers from determining that the event wasn&amp;#39;t meant for that handler.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Events handling</title><link>https://devzone.nordicsemi.com/thread/68666?ContentTypeID=1</link><pubDate>Fri, 18 Nov 2016 09:51:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:34fb50c8-d047-4e85-b654-4e7a5c17b2d3</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;In &lt;code&gt;ble_evt_t&lt;/code&gt; there is a header which holds the event id. The different modules use the event id to check if it should handle the event or not. This is usually done using a switch statement. Example code:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;switch (p_ble_evt-&amp;gt;header.evt_id)
{
    case BLE_GAP_EVT_CONNECTED:
        err_code = bsp_indication_set(BSP_INDICATE_CONNECTED);
        APP_ERROR_CHECK(err_code);
        m_conn_handle = p_ble_evt-&amp;gt;evt.gap_evt.conn_handle;
        break; // BLE_GAP_EVT_CONNECTED

    case BLE_GAP_EVT_DISCONNECTED:
        err_code = bsp_indication_set(BSP_INDICATE_IDLE);
        APP_ERROR_CHECK(err_code);
        m_conn_handle = BLE_CONN_HANDLE_INVALID;
        break; // BLE_GAP_EVT_DISCONNECTED

    default:
        // No implementation needed.
        break;
}
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>