espressif / esp-idf

Espressif IoT Development Framework. Official development framework for Espressif SoCs.
Apache License 2.0
13.79k stars 7.31k forks source link

Unable to move mesh elements into separate files for reusability (IDFGH-10805) #12017

Open parksj10 opened 1 year ago

parksj10 commented 1 year ago

Answers checklist.

General issue report

I have the following code:

// note: this implicity defines onoff_pub_0 as a static
ESP_BLE_MESH_MODEL_PUB_DEFINE(onoff_pub_0, 2 + 3, ROLE_NODE);
static esp_ble_mesh_gen_onoff_srv_t onoff_server_0 = {
    .rsp_ctrl.get_auto_rsp = ESP_BLE_MESH_SERVER_AUTO_RSP,
    .rsp_ctrl.set_auto_rsp = ESP_BLE_MESH_SERVER_AUTO_RSP,
};

// ...

static esp_ble_mesh_model_t root_models[] = {
    ESP_BLE_MESH_MODEL_GEN_ONOFF_SRV(&onoff_pub_0, &onoff_server_0),\
    // ...
};

I'd like to be able to isolate these definition into separate file, and root_models in a separate file (to allow for reusability of code), but I can't seem to get around accessing static variables from another file (and yes, I've read a lot of posts on StackOverflow about using statics in C for encapsulation)... Is there any better option when the library I'm using implements static variables in their macros?

FYI, here's a more complete example if someone wants to propose a more general architecture approach...

ankit-thealchemist commented 11 months ago

I am not able to understand what we want to achive here.