Changeset 552b69f in mainline for uspace/lib/ui/src/ui.c


Ignore:
Timestamp:
2021-11-03T20:56:59Z (3 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1aa8c86
Parents:
ec8a1bf
Message:

Dual-mode applications should automatically fall back to console

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/ui/src/ui.c

    rec8a1bf r552b69f  
    6969        const char *cp;
    7070
    71         if (ospec == UI_DISPLAY_DEFAULT) {
    72                 *ws = ui_ws_display;
    73                 *osvc = DISPLAY_DEFAULT;
    74                 return;
    75         }
    76 
    7771        cp = ospec;
    7872        while (isalpha(*cp))
     
    8680                } else if (str_lcmp(ospec, "null@", str_length("null@")) == 0) {
    8781                        *ws = ui_ws_null;
     82                } else if (str_lcmp(ospec, "@", str_length("@")) == 0) {
     83                        *ws = ui_ws_any;
    8884                } else {
    8985                        *ws = ui_ws_unknown;
     
    123119        ui_ospec_parse(ospec, &ws, &osvc);
    124120
    125         if (ws == ui_ws_display) {
    126                 rc = display_open(osvc, &display);
     121        if (ws == ui_ws_display || ws == ui_ws_any) {
     122                rc = display_open(osvc != NULL ? osvc : DISPLAY_DEFAULT,
     123                    &display);
    127124                if (rc != EOK)
    128                         return rc;
     125                        goto disp_fail;
    129126
    130127                rc = ui_create_disp(display, &ui);
    131128                if (rc != EOK) {
    132129                        display_close(display);
    133                         return rc;
    134                 }
    135         } else if (ws == ui_ws_console) {
     130                        goto disp_fail;
     131                }
     132
     133                ui->myoutput = true;
     134                *rui = ui;
     135                return EOK;
     136        }
     137
     138disp_fail:
     139        if (ws == ui_ws_console || ws == ui_ws_any) {
    136140                console = console_init(stdin, stdout);
    137141                if (console == NULL)
    138                         return EIO;
     142                        goto cons_fail;
    139143
    140144                rc = console_get_size(console, &cols, &rows);
    141145                if (rc != EOK) {
    142146                        console_done(console);
    143                         return rc;
     147                        goto cons_fail;
    144148                }
    145149
     
    150154                if (rc != EOK) {
    151155                        console_done(console);
    152                         return rc;
     156                        goto cons_fail;
    153157                }
    154158
     
    157161                        ui_destroy(ui);
    158162                        console_done(console);
    159                         return rc;
     163                        goto cons_fail;
    160164                }
    161165
     
    167171
    168172                (void) ui_paint(ui);
    169         } else if (ws == ui_ws_null) {
     173                ui->myoutput = true;
     174                *rui = ui;
     175                return EOK;
     176        }
     177
     178cons_fail:
     179        if (ws == ui_ws_null) {
    170180                rc = ui_create_disp(NULL, &ui);
    171181                if (rc != EOK)
    172182                        return rc;
    173         } else {
    174                 return EINVAL;
    175         }
    176 
    177         ui->myoutput = true;
    178         *rui = ui;
    179         return EOK;
     183
     184                ui->myoutput = true;
     185                *rui = ui;
     186                return EOK;
     187        }
     188
     189        return EINVAL;
    180190}
    181191
Note: See TracChangeset for help on using the changeset viewer.