Why not registering the keypad as part of the constructor?
I see the following advantages:
- The semantic necessity (the engine needs the keypad to operate) would be represented technically.
The user of the engine can not forget to register the keypad.
IKeypad &myKeypad could then be a member of GuiEngine which is initialized by the member initializer list of GuiEngine(). Declaring the functions keypad_read_*() as members of GuiEngine would eliminate the need to check for NULL pointer in those functions. Also because a reference would be used instead of a pointer. Using member functions as callback would require to define a private static member function, which would act as relay and use the callback argument to call the actual member as for example
reinterpret_cast<GuiEngine *>(indev_drv->disp->driver->user_data)->keypad_read_enter(...)
or (requires to define indev_drv->user_data)
reinterpret_cast<GuiEngine *>(indev_drv->user_data)->keypad_read_enter(...)
GuiEngine(const Configuration &configuration, TwoWire &i2c, IKeypad &keypad);
Did we already talk about it? I have a vague memory 🤔
Originally posted by @dhebbeker in #123 (comment)
I see the following advantages:
The user of the engine can not forget to register the keypad.
IKeypad &myKeypadcould then be a member ofGuiEnginewhich is initialized by the member initializer list ofGuiEngine(). Declaring the functionskeypad_read_*()as members ofGuiEnginewould eliminate the need to check for NULL pointer in those functions. Also because a reference would be used instead of a pointer. Using member functions as callback would require to define a private static member function, which would act as relay and use the callback argument to call the actual member as for exampleindev_drv->user_data)Did we already talk about it? I have a vague memory 🤔
Originally posted by @dhebbeker in #123 (comment)