<?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>Meaning of context argument in event handlers</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/65951/meaning-of-context-argument-in-event-handlers</link><description>Dear Nordic Team, 
 
 I was trying to understand event handlers from SDK5 examples. I understood that by using following macro we can register our event handlers, and afterwards receive BLE events and take appropriate actions either by using switch statements</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 18 Sep 2020 13:22:07 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/65951/meaning-of-context-argument-in-event-handlers" /><item><title>RE: Meaning of context argument in event handlers</title><link>https://devzone.nordicsemi.com/thread/270346?ContentTypeID=1</link><pubDate>Fri, 18 Sep 2020 13:22:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:65324f5a-561d-44c4-a6c6-562bd2a07a4f</guid><dc:creator>Rafig</dc:creator><description>&lt;p&gt;Thanks a lot!&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Meaning of context argument in event handlers</title><link>https://devzone.nordicsemi.com/thread/270059?ContentTypeID=1</link><pubDate>Thu, 17 Sep 2020 11:35:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:eccfe939-fb5d-4b95-bb4d-5fe3f32181d8</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;&amp;nbsp;From main.c NUS client:&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;BLE_NUS_C_DEF(m_ble_nus_c);                                             /**&amp;lt; BLE Nordic UART Service (NUS) client instance. */&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;From ble_nus_c.h:&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/**@brief   Macro for defining a ble_nus_c instance.
 *
 * @param   _name   Name of the instance.
 * @hideinitializer
 */
#define BLE_NUS_C_DEF(_name)                                                                        \
static ble_nus_c_t _name;                                                                           \
NRF_SDH_BLE_OBSERVER(_name ## _obs,                                                                 \
                     BLE_NUS_C_BLE_OBSERVER_PRIO,                                                   \
                     ble_nus_c_on_ble_evt, &amp;amp;_name)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;From nrf_sdh_ble.h:&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/**@brief   Macro for registering @ref nrf_sdh_soc_evt_observer_t. Modules that want to be
 *          notified about SoC events must register the handler using this macro.
 *
 * @details This macro places the observer in a section named &amp;quot;sdh_soc_observers&amp;quot;.
 *
 * @param[in]   _name       Observer name.
 * @param[in]   _prio       Priority of the observer event handler.
 *                          The smaller the number, the higher the priority.
 * @param[in]   _handler    BLE event handler.
 * @param[in]   _context    Parameter to the event handler.
 * @hideinitializer
 */
#define NRF_SDH_BLE_OBSERVER(_name, _prio, _handler, _context)                                      \
STATIC_ASSERT(NRF_SDH_BLE_ENABLED, &amp;quot;NRF_SDH_BLE_ENABLED not set!&amp;quot;);                                 \
STATIC_ASSERT(_prio &amp;lt; NRF_SDH_BLE_OBSERVER_PRIO_LEVELS, &amp;quot;Priority level unavailable.&amp;quot;);             \
NRF_SECTION_SET_ITEM_REGISTER(sdh_ble_observers, _prio, static nrf_sdh_ble_evt_observer_t _name) =  \
{                                                                                                   \
    .handler   = _handler,                                                                          \
    .p_context = _context                                                                           \
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;BLE_NUS_C_DEF declares a&amp;nbsp;ble_nus_c_t called&amp;nbsp;m_ble_nus_c that is then passed to NRF_SDH_BLE_OBSERVER as both the name of the &amp;#39;observer&amp;#39; and the address of the context pointer.&lt;/p&gt;
&lt;p&gt;Each time the context pointer in&amp;nbsp;ble_nus_c_on_ble_evt is dereferenced as a&amp;nbsp;&lt;span&gt;ble_nus_c_t&amp;nbsp;it is the&amp;nbsp;m_ble_nus_c&amp;nbsp;struct in main that is dereferenced.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>