Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

- The purpose of callbacks is for the quick and efficient use of functions within other function. Because you have a direct pointer to the callback function's address, you have immediate access to it. This makes callbacks versatile and re-usable. Lets take a look at some examples of the use of callbacks in our projects:

Ex 1) Status code:

Remove

Code Block
languagecpp
themeConfluence
#include "status.h"

#include <stdlib.h>

static Status s_global_status = {
  .source = "",   //
  .caller = "",   //
  .message = "",  //
};
static status_callback s_callback;

StatusCode status_impl_update(const StatusCode code, const char* source, const char* caller,
                              const char* message) {
  s_global_status.code = code;
  s_global_status.source = source;
  s_global_status.caller = caller;
  s_global_status.message = message;
  if (s_callback != NULL) {
    s_callback(&s_global_status);
  }
  return code;
}

Status status_get(void) {
  return s_global_status;
}

void status_register_callback(status_callback callback) {
  s_callback = callback;
}

...