rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
listener_array.h
Go to the documentation of this file.
1/*
2 * listener_array.h
3 *
4 * @date Jan 1, 2013
5 * @author Andrey Belomutskiy, (c) 2012-2020
6 */
7
8#pragma once
9
10#include <stddef.h>
11#include "rusefi_types.h"
12
13// todo: reorder parameters for consistency?
14typedef void (*IntIntVoidListener)(int value1, int value2, void *arg);
15
16// todo: rename 'Arg' to 'Void'?
17typedef void (*ArgListener)(void *arg);
18typedef void (*ArgIntListener)(void *arg, int value);
19
20// todo: rename this class, that's not just 'callback(int param) anymore
21template<int MAX_INT_LISTENER_COUNT>
23public:
25 void clear();
26 void registerCallback(VoidInt handler, void *arg);
28 void invokeJustArgCallbacks() const;
30 VoidInt callbacks[MAX_INT_LISTENER_COUNT];
31 void * args[MAX_INT_LISTENER_COUNT];
32};
33
34//template<int MAX_INT_LISTENER_COUNT>
35//void invokeCallbacks(IntListenerArray *array, int value);
36//
37//template<int MAX_INT_LISTENER_COUNT>
38//void invokeJustArgCallbacks(IntListenerArray *array);
39//
40//template<int MAX_INT_LISTENER_COUNT>
41//void invokeArgIntCallbacks(IntListenerArray *array, int value);
42//
43//template<int MAX_INT_LISTENER_COUNT>
44//void invokeIntIntCallbacks(IntListenerArray *array, int value, int value2);
45//
46//template<int MAX_INT_LISTENER_COUNT>
47//void invokeIntIntVoidCallbacks(IntListenerArray *array, int value, int value2);
48
49//template<int MAX_INT_LISTENER_COUNT>
50//void clearCallbacks(IntListenerArray *array);
51
52template<int MAX_INT_LISTENER_COUNT>
56
57template<int MAX_INT_LISTENER_COUNT>
59 currentListenersCount = 0;
60 memset(&args, 0, sizeof(args));
61 memset(&callbacks, 0, sizeof(callbacks));
62}
63
64template<int MAX_INT_LISTENER_COUNT>
66 efiAssertVoid(ObdCode::CUSTOM_ERR_6606, currentListenersCount < MAX_INT_LISTENER_COUNT, "Too many callbacks");
67 int index = currentListenersCount++;
68 callbacks[index] = handler;
69 args[index] = arg;
70}
71
72template<int MAX_INT_LISTENER_COUNT>
76
77template<int MAX_INT_LISTENER_COUNT>
79 for (int i = 0; i < array->currentListenersCount; i++)
80 (array->callbacks[i])(value);
81}
82
83template<int MAX_INT_LISTENER_COUNT>
85 for (int i = 0; i < currentListenersCount; i++) {
86 VoidPtr listener = (VoidPtr)(void*)callbacks[i];
87 void *arg = args[i];
88 (listener)(arg);
89 }
90}
91
92template<int MAX_INT_LISTENER_COUNT>
94 for (int i = 0; i < array->currentListenersCount; i++) {
96 void *arg = array->args[i];
97 (listener)(arg, value);
98 }
99}
100
101template<int MAX_INT_LISTENER_COUNT>
103 for (int i = 0; i < array->currentListenersCount; i++) {
105 (listener)(value, value2);
106 }
107}
108
109template<int MAX_INT_LISTENER_COUNT>
111 for (int i = 0; i < array->currentListenersCount; i++) {
113 (listener)(value, value2, array->args[i]);
114 }
115}
116
117template<int MAX_INT_LISTENER_COUNT>
121
void * args[MAX_INT_LISTENER_COUNT]
void registerCallback(VoidInt handler, void *arg)
void invokeJustArgCallbacks() const
VoidInt callbacks[MAX_INT_LISTENER_COUNT]
void(* VoidIntInt)(int, int)
void(* Void)(void)
void(* VoidPtr)(void *)
void(* VoidInt)(int)
void(* ArgIntListener)(void *arg, int value)
void(* IntIntVoidListener)(int value1, int value2, void *arg)
void clearCallbacks(IntListenerArray< MAX_INT_LISTENER_COUNT > *array)
void invokeArgIntCallbacks(IntListenerArray< MAX_INT_LISTENER_COUNT > *array, int value)
void invokeIntIntCallbacks(IntListenerArray< MAX_INT_LISTENER_COUNT > *array, int value, int value2)
void(* ArgListener)(void *arg)
void invokeCallbacks(IntListenerArray< MAX_INT_LISTENER_COUNT > *array, int value)
void invokeIntIntVoidCallbacks(IntListenerArray< MAX_INT_LISTENER_COUNT > *array, int value, int value2)
@ CUSTOM_ERR_6606
value1("SENT ch0 value1", SensorCategory.SENSOR_INPUTS, FieldType.INT16, 1974, 1.0, 0.0, 4095.0, "RAW")
static CanTsListener listener