How to make a quick reference to a task

There is a list of tasks that are launched depending on the state bool active;. The list is constantly updated and accessing the index is not very convenient, what is the best and simplest way to implement this mechanism?

struct App
{
    char const *text;       //command
    char const *name;       //name task-function

    void (*f)(void);        //task-function

    bool active;            //activ status task-function
    int priority;           //execution priority
    const uint8_t *bitMap;  //icon task-function
    bool state;             //0-task-function any 1-Application
};

/* enumeration of objects - commands */
App commands[]
{
    {"clearcomm", "Clear command",  clearCommandTerminal, false,   0, NULL, 0},
    {"desctop",   "Desctop",        desctop,              true,    0, NULL, 1},
    {"deepsleep", "Deep sleep PWS-mode", powerSaveDeepSleep, true, 0, NULL, 0},
    {"rawadc",    "Raw data ADC",   systemRawADC,         false,   0, NULL, 0},
    {"clearbuffer","Clear Buffer",  clearBufferString,    false,   0, NULL, 0},

    {"test","Test",  testApp,    false,   0, NULL, 2},

    {"wifisetup", "WiFi",           wifiSetup,            true,    0, NULL, 0},
    {"wificonect","WiFi",           wifiConnect,          true,    0, NULL, 0},
    {"ntpsetup",  "Time NTP Setup", timeNtpSetup,         true,    0, NULL, 0},
    {"ntptime",   "Time NTP",       timeNtpUpdate,        true,    0, NULL, 0},

    {"systray",   "Tray",           systemTray,           true,    0, NULL, 0},
    {"syscursor", "Cursor",         systemCursor,         true,    0, NULL, 0},
};

Maybe std::map.

If you iterate over the list regularly, to update them etc.

for ( i=0; i < 12; i++){
//...
doSomethingWith(commands[i]);
//...
}

Then having an array of your data structure makes sense... However, I would think these are not handled as an iterative list, but handled as each command is relevant, so I might named them directly so I am not lost on which commands[] is which.

App clearComm = {"clearcomm", "Clear command", clearCommandTerminal, false, 0, NULL, 0};

This way, active can be accessed by clearComm.active

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.