typedef struct public_base_t public_base_t;
struct public_base_t {
// public members
int member_id;
// public methods
err_t (*func)(public_base_t* obj, void* param);
// always have this dtor
err_t (*del)(public_base_t* obj);
};
obj
<=> self
(Python), this
(Java)// declare opaque pointer for object handle
typedef struct public_base_t* public_base_handle_t;
// wrapper of public methods declared in `public_base_t`
err_t public_base_func(public_base_handle_t obj, void* param);
// destructor function of public base object
err_t del_public_base(public_base_handle_t obj);
#include "interface/public_base.h"
#include "public_api.h"
err_t public_base_func(public_base_handle_t obj, void* param)
{
return obj->func(obj, param);
}
public_base_handle_t
object?#include "interface/public_base.h"
typedef struct my_type_t my_type_t;
struct my_type_t {
// Inherit one base type
public_base_t base1;
// Inherit another base type
another_public_base_t base2;
// private members
char name[MAX_NAME_LEN];
// private methods
int (*my_func)(my_type_t* obj, void* param);
};
my_type2_t
that also inherits the public_base_t
public_base_handle_t
object of type my_type_t
driver/xxx.h
for public APIesp_private/xxx.h
for private APIesp_err_t <periph>_new_<obj>(const <periph>_<obj>_config_t *config,
<periph>_<obj>_handle_t *ret_handle);
esp_err_t <periph>_del_<obj>(<periph>_<obj>_handle_t handle);
esp_err_t <periph>_<obj>_<verb>(<periph>_<obj>_handle_t handle,
optional_configurations);
typedef bool (*<periph>_<event>_cb_t) (<periph>_<obj>_handle_t handle,
<periph>_<event>_data_t *edata,
void *user_ctx);
esp_err_t gptimer_register_event_callbacks(<periph>_<obj>_handle_t handle,
<periph>_event_callbacks_t *cbs,
void *user_data);