Note that there are some explanatory texts on larger screens.

plurals
  1. POClarifying on function calling
    primarykey
    data
    text
    <p>I am under learning of Android source code. And I want to know that how the lower level functions are getting calling from application.</p> <p>While learning in this aspect, now I am in the struggle to understand one file which I have given below:</p> <pre><code>static int open_lights(const struct hw_module_t* module, char const* name, struct hw_device_t** device) { int (*set_light)(struct light_device_t* dev, struct light_state_t const* state); if (0 == strcmp(LIGHT_ID_BACKLIGHT, name)) { set_light = set_light_backlight; } else if (0 == strcmp(LIGHT_ID_KEYBOARD, name)) { set_light = set_light_keyboard; } else if (0 == strcmp(LIGHT_ID_BUTTONS, name)) { set_light = set_light_buttons; } else if (0 == strcmp(LIGHT_ID_BATTERY, name)) { set_light = set_light_battery; } else if (0 == strcmp(LIGHT_ID_NOTIFICATIONS, name)) { set_light = set_light_notification; } else if (0 == strcmp(LIGHT_ID_ATTENTION, name)) { set_light = set_light_attention; } else { return -EINVAL; } pthread_once(&amp;g_init, init_globals); struct light_device_t *dev = malloc(sizeof(struct light_device_t)); memset(dev, 0, sizeof(*dev)); dev-&gt;common.tag = HARDWARE_DEVICE_TAG; dev-&gt;common.version = 0; dev-&gt;common.module = (struct hw_module_t*)module; dev-&gt;common.close = (int (*)(struct hw_device_t*))close_lights; dev-&gt;set_light = set_light; *device = (struct hw_device_t*)dev; return 0; } set_light_backlight(struct light_device_t* dev, struct light_state_t const* state) { int err = 0; int brightness = rgb_to_brightness(state); pthread_mutex_lock(&amp;g_lock); err = write_int(LCD_FILE, brightness); pthread_mutex_unlock(&amp;g_lock); return err; } </code></pre> <p>My questions are:</p> <ol> <li>What is the meaning of <code>int (*set_light)(struct light_device_t* dev, struct light_state_t const* state);</code> this statement?</li> <li>We are just assigning <code>set_light_backlight</code> to <code>set_light</code>. Then how can <code>set_light_backlight(struct light_device_t* dev, struct light_state_t const* state)</code> function get called?</li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload