You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your enhancement proposal related to a problem? Please describe.
I'm trying to write a C++ class which receives a struct device * member via dependency injection. In this case, the device is a sensor, and I'd like to setup a trigger callback. I must use a static function as the callback, since the sensor trigger callback does not provide the this argument. This means that I am unable to reference non-static member data of my class.
Describe the solution you'd like
Add a "user data" field to the device structure. This could be enabled via a config option as such:
struct device {
/** Name of the device instance */
const char *name;
/** Address of device instance config information */
const void *config;
/** Address of the API structure exposed by the device instance */
const void *api;
/** Address of the device instance private data */
void *const data;
#ifdef CONFIG_DEVICE_POWER_MANAGEMENT
/** Power Management function */
int (*device_pm_control)(const struct device *dev, uint32_t command,
void *context, device_pm_cb cb, void *arg);
/** Pointer to device instance power management data */
struct device_pm *const pm;
#endif
#ifdef CONFIG_DEVICE_USER_DATA
/** Pointer to user data */
void *user_data;
#endif
};
This would allow me to write this to the user data section of the device structure when an instance of my class is constructed, and my sensor trigger callback (which will still be static) can use this user data field (since the trigger callback does provide a pointer to the device structure) to access non-static member data.
I imagine that this user data field would be useful in other cases as well.
The text was updated successfully, but these errors were encountered:
Is your enhancement proposal related to a problem? Please describe.
I'm trying to write a C++ class which receives a
struct device *
member via dependency injection. In this case, the device is a sensor, and I'd like to setup a trigger callback. I must use a static function as the callback, since the sensor trigger callback does not provide thethis
argument. This means that I am unable to reference non-static member data of my class.Describe the solution you'd like
Add a "user data" field to the device structure. This could be enabled via a config option as such:
This would allow me to write
this
to the user data section of the device structure when an instance of my class is constructed, and my sensor trigger callback (which will still be static) can use this user data field (since the trigger callback does provide a pointer to the device structure) to access non-static member data.I imagine that this user data field would be useful in other cases as well.
The text was updated successfully, but these errors were encountered: