Skip to content

Commit 9705d17

Browse files
committed
event_manager: Event manager cleanup
Add changes cleaning event manager. Signed-off-by: Jan Zyczkowski <[email protected]>
1 parent c9bfdbd commit 9705d17

File tree

7 files changed

+378
-365
lines changed

7 files changed

+378
-365
lines changed

doc/reference/kernel/other/event_manager.rst

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Event Manager
77
:local:
88
:depth: 2
99

10-
The Event Manager is a piece of software that supports development of consistent, modular, event-based application.
10+
The Event Manager is a piece of software that supports development of consistent, modular, event-based applications.
1111
In an event-based application, parts of the application functionality are separated into isolated modules that communicate with each other using events.
1212
Events are submitted by modules and other modules can subscribe and react to them.
1313
The Event Manager acts as coordinator of the event-based communication.
@@ -35,33 +35,25 @@ Modules
3535
Modules are separate source files that can subscribe to every defined event.
3636
You can use events for communication between modules.
3737

38-
There is no limitation as to how many modules each module can subscribe to.
38+
There is no limitation as to how many events each module can subscribe to.
3939
An application can have as many modules as required.
4040

41-
The Event Manager provides API for subscribing modules to a specific events defined in the application.
42-
When a module is subscribing to a specific event, it is called a listener module.
41+
The Event Manager provides an API for subscribing modules to specific events defined in the application.
42+
When a module subscribes to a specific event, it is called a listener module.
4343
Every listener is identified by a unique name.
4444

4545
.. _event_manager_configuration:
4646

4747
Configuration
4848
*************
4949

50-
To use Event Manager, you must enable the following Kconfig options:
50+
To use Event Manager, enable it using the :kconfig:`CONFIG_EVENT_MANAGER` Kconfig option and initialize it in your :file:`main.c` file.
51+
Initializing the Event Manager allows it to handle submitted events and deliver them to modules that subscribe to the specified event type.
5152

52-
* :kconfig:`CONFIG_EVENT_MANAGER` - This option enables the Event Manager.
53-
* :kconfig:`CONFIG_LINKER_ORPHAN_SECTION_PLACE` - This option enables orphan memory sections used by the Event Manager.
54-
Set this option to suppress warnings and errors.
55-
56-
Initializing the Event Manager
57-
==============================
58-
59-
You must initialize the Event Manager in your :file:`main.c` file.
60-
Initializing the Event Manger allows it to handle submitted events and deliver them to modules that subscribe to the specified event type.
61-
62-
To initialize the Event Manager, complete the following steps:
53+
Complete the following steps:
6354

64-
1. Include :file:`event_manager.h` in your :file:`main.c` file.
55+
1. Enable the :kconfig:`CONFIG_EVENT_MANAGER` Kconfig option.
56+
#. Include :file:`event_manager.h` in your :file:`main.c` file.
6557
#. Call :c:func:`event_manager_init()`.
6658

6759
.. _event_manager_implementing_events:
@@ -90,17 +82,17 @@ To create a header file for the event type you want to define:
9082

9183
.. code-block:: c
9284
93-
#include event_manager.h
85+
#include <event_manager/event_manager.h>
9486

95-
#. Define the new event type by creating a structure that contains :c:struct:`event_header` ``header`` as the first field.
87+
#. Define the new event type by creating a structure that contains an :c:struct:`event_header` named ``header`` as the first field.
9688
#. Optionally, add additional custom data fields to the structure.
9789
#. Declare the event type with the :c:macro:`EVENT_TYPE_DECLARE` macro, passing the name of the created structure as an argument.
9890

9991
The following code example shows a header file for the event type :c:struct:`sample_event`:
10092

10193
.. code-block:: c
10294
103-
#include <event_manager.h>
95+
#include <event_manager/event_manager.h>
10496
10597
struct sample_event {
10698
struct event_header header;
@@ -116,11 +108,11 @@ The following code example shows a header file for the event type :c:struct:`sam
116108
In some use cases, the length of the data associated with an event may vary.
117109
You can use the :c:macro:`EVENT_TYPE_DYNDATA_DECLARE` macro instead of :c:macro:`EVENT_TYPE_DECLARE` to declare an event type with variable data size.
118110
In such case, add the data with the variable size as the last member of the event structure.
119-
For example, you can add the variable size data to a previously defined event by applying the following change to the code:
111+
For example, you can add variable sized data to the previously defined event by applying the following change to the code:
120112

121113
.. code-block:: c
122114
123-
#include <event_manager.h>
115+
#include <event_manager/event_manager.h>
124116
125117
struct sample_event {
126118
struct event_header header;
@@ -134,7 +126,7 @@ For example, you can add the variable size data to a previously defined event by
134126
135127
EVENT_TYPE_DYNDATA_DECLARE(sample_event);
136128
137-
In this example, the :c:struct:`event_dyndata` contains the following information:
129+
In this example, the :c:struct:`event_dyndata` structure contains the following information:
138130

139131
* A zero-length array that is used as a buffer with variable size (:c:member:`event_dyndata.data`).
140132
* A number representing the size of the buffer (:c:member:`event_dyndata.size`).
@@ -146,7 +138,7 @@ To create a source file for the event type you defined in the header file:
146138

147139
1. Include the header file for the new event type in your source file.
148140
#. Define the event type with the :c:macro:`EVENT_TYPE_DEFINE` macro.
149-
Passing the name of the event type as declared in the header and the additional parameters.
141+
Pass the name of the event type as declared in the header along with additional parameters.
150142
For example, you can provide a function that fills a buffer with a string version of the event data (used for logging).
151143

152144
The following code example shows a source file for the event type ``sample_event``:
@@ -160,15 +152,19 @@ The following code example shows a source file for the event type ``sample_event
160152
{
161153
struct sample_event *event = cast_sample_event(eh);
162154
163-
return snprintf(buf, buf_len, "val1=%d val2=%d val3=%d", event->value1,
155+
EVENT_MANAGER_LOG(eh, "val1=%d val2=%d val3=%d", event->value1,
164156
event->value2, event->value3);
157+
return 0;
165158
}
166159
167160
EVENT_TYPE_DEFINE(sample_event, /* Unique event name. */
168161
true, /* Event logged by default. */
169162
log_sample_event, /* Function logging event data. */
170163
NULL); /* No event info provided. */
171164
165+
.. note::
166+
There is a deprecated way of logging Event Manager events by writing string to the provided buffer which is supported until NCS2.0.
167+
172168
Submitting an event
173169
===================
174170

@@ -311,7 +307,7 @@ Tracing hooks
311307
312308
Event Manager provides tracing hooks that you can use at run time to get information about Event Manager initialization, event submission, and event execution.
313309
The hooks are provided as weak functions.
314-
You can override them for interacting with custom profiler or for other purposes.
310+
You can override them for interacting with a custom profiler or for other purposes.
315311

316312
The following weak functions are provided by Event Manager as hooks:
317313

@@ -330,7 +326,7 @@ Shell integration
330326

331327
Shell integration is available to display additional information and to dynamically enable or disable logging for given event types.
332328

333-
The Event Manager is integrated with :ref:`shell_api` module.
329+
The Event Manager is integrated with Zephyr's :ref:`shell_api` module.
334330
When the shell is turned on, an additional subcommand set (:command:`event_manager`) is added.
335331

336332
This subcommand set contains the following commands:
@@ -354,7 +350,7 @@ This subcommand set contains the following commands:
354350
API documentation
355351
*****************
356352

357-
| Header files: :file:`include/event_manager/`
353+
| Header file: :file:`include/event_manager.h`
358354
| Source files: :file:`subsys/event_manager/`
359355
360356
.. doxygengroup:: event_manager

0 commit comments

Comments
 (0)