Changeset c3db721 in mainline


Ignore:
Timestamp:
2025-10-10T20:35:05Z (2 months ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master
Children:
c1383cd
Parents:
0cf3d5f
Message:

Allow aborting file management operation.

Location:
uspace
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/nav/nav.c

    r0cf3d5f rc3db721  
    7979        .activate_req = navigator_panel_activate_req,
    8080        .file_open = navigator_panel_file_open
     81};
     82
     83static void navigator_progress_babort(progress_dlg_t *, void *);
     84static void navigator_progress_close(progress_dlg_t *, void *);
     85
     86progress_dlg_cb_t navigator_progress_cb = {
     87        .babort = navigator_progress_babort,
     88        .close = navigator_progress_close
    8189};
    8290
     
    596604}
    597605
     606/** Abort button pressed in progress dialog.
     607 *
     608 * @param dlg Progress dialog
     609 * @param arg Argument (navigator_t *)
     610 */
     611static void navigator_progress_babort(progress_dlg_t *dlg, void *arg)
     612{
     613        navigator_t *nav = (navigator_t *)arg;
     614
     615        (void)dlg;
     616        nav->abort_op = true;
     617}
     618
     619/** Progress dialog closed,
     620 *
     621 * @param dlg Progress dialog
     622 * @param arg Argument (navigator_t *)
     623 */
     624static void navigator_progress_close(progress_dlg_t *dlg, void *arg)
     625{
     626        navigator_t *nav = (navigator_t *)arg;
     627
     628        (void)dlg;
     629        nav->abort_op = true;
     630}
     631
    598632/** @}
    599633 */
  • uspace/app/nav/nav.h

    r0cf3d5f rc3db721  
    3838
    3939#include <errno.h>
     40#include "types/dlg/progress.h"
    4041#include "types/nav.h"
    4142#include "types/panel.h"
     43
     44extern progress_dlg_cb_t navigator_progress_cb;
    4245
    4346extern errno_t navigator_create(const char *, navigator_t **);
  • uspace/app/nav/newfile.c

    r0cf3d5f rc3db721  
    6464};
    6565
     66static bool new_file_abort_query(void *);
    6667static void new_file_progress(void *, fmgt_progress_t *);
    6768
    6869static fmgt_cb_t new_file_fmgt_cb = {
    69         .progress = new_file_progress
     70        .abort_query = new_file_abort_query,
     71        .progress = new_file_progress,
    7072};
    7173
     
    124126        return;
    125127error:
     128        fmgt_destroy(fmgt);
    126129        ui_lock(nav->ui);
    127130        progress_dlg_destroy(nav->progress_dlg);
     131        navigator_refresh_panels(nav);
    128132        ui_msg_dialog_params_init(&params);
    129133        params.caption = "Error";
     
    192196        }
    193197
     198        progress_dlg_set_cb(nav->progress_dlg, &navigator_progress_cb,
     199            (void *)nav);
     200
    194201        rc = navigator_worker_start(nav, new_file_wfunc, (void *)job);
    195202        if (rc != EOK) {
     
    231238}
    232239
     240/** New file abort query.
     241 *
     242 * @param arg Argument (navigator_t *)
     243 * @return @c true iff abort is requested
     244 */
     245static bool new_file_abort_query(void *arg)
     246{
     247        navigator_t *nav = (navigator_t *)arg;
     248
     249        return nav->abort_op;
     250}
     251
    233252/** New file progress update.
    234253 *
  • uspace/app/nav/types/nav.h

    r0cf3d5f rc3db721  
    3838
    3939#include <fibril.h>
     40#include <stdbool.h>
    4041#include <ui/fixed.h>
    4142#include <ui/ui.h>
     
    6263        /** Worker fibril ID */
    6364        fid_t worker_fid;
     65        /** Abort current file management operation */
     66        bool abort_op;
    6467} navigator_t;
    6568
  • uspace/app/newfile/meson.build

    r0cf3d5f rc3db721  
    2727#
    2828
    29 deps = [ 'fmgt' ]
     29deps = [ 'console', 'fmgt', 'input' ]
    3030src = files('newfile.c')
  • uspace/app/newfile/newfile.c

    r0cf3d5f rc3db721  
    3636#include <errno.h>
    3737#include <fmgt.h>
     38#include <io/console.h>
     39#include <io/cons_event.h>
     40#include <io/kbd_event.h>
    3841#include <stdbool.h>
    3942#include <stdio.h>
     
    4447#define NAME  "newfile"
    4548
     49static bool newfile_abort_query(void *);
    4650static void newfile_progress(void *, fmgt_progress_t *);
    4751
     
    4953static bool quiet = false;
    5054
     55static console_ctrl_t *con;
     56
    5157static fmgt_cb_t newfile_fmgt_cb = {
     58        .abort_query = newfile_abort_query,
    5259        .progress = newfile_progress
    5360};
     
    6269        printf("\t-q           quiet\n");
    6370        printf("\t-size=<cap>  file size (<number>[<kB>|<MB>|...])\n");
     71}
     72
     73/** Called by fmgt to query for user abort.
     74 *
     75 * @param arg Argument (not used)
     76 * @return @c true iff user requested abort
     77 */
     78static bool newfile_abort_query(void *arg)
     79{
     80        cons_event_t event;
     81        kbd_event_t *ev;
     82        errno_t rc;
     83        usec_t timeout;
     84
     85        if (con == NULL)
     86                return false;
     87
     88        timeout = 0;
     89        rc = console_get_event_timeout(con, &event, &timeout);
     90        if (rc != EOK)
     91                return false;
     92
     93        if (event.type == CEV_KEY && event.ev.key.type == KEY_PRESS) {
     94                ev = &event.ev.key;
     95                if ((ev->mods & KM_ALT) == 0 &&
     96                    (ev->mods & KM_SHIFT) == 0 &&
     97                    (ev->mods & KM_CTRL) != 0) {
     98                        if (ev->key == KC_C)
     99                                return true;
     100                }
     101        }
     102
     103        return false;
    64104}
    65105
     
    93133        uint64_t nbytes = 0;
    94134
     135        con = console_init(stdin, stdout);
     136
    95137        i = 1;
    96138        while (i < argc && argv[i][0] == '-') {
     
    167209
    168210        rc = fmgt_new_file(fmgt, fname, nbytes, sparse ? nf_sparse : nf_none);
     211        if (prog_upd)
     212                printf("\n");
    169213        if (rc != EOK) {
    170214                printf("Error creating file: %s.\n", str_error(rc));
    171215                goto error;
    172216        }
    173 
    174         if (prog_upd)
    175                 printf("\n");
    176217
    177218        free(fname);
  • uspace/lib/fmgt/include/types/fmgt.h

    r0cf3d5f rc3db721  
    4040#include <capa.h>
    4141#include <fibril_synch.h>
     42#include <stdbool.h>
    4243
    4344/** File management progress update */
     
    5354/** File management callbacks */
    5455typedef struct {
     56        bool (*abort_query)(void *);
    5557        void (*progress)(void *, fmgt_progress_t *);
    5658} fmgt_cb_t;
  • uspace/lib/fmgt/src/fmgt.c

    r0cf3d5f rc3db721  
    221221}
    222222
     223/** Query caller whether operation should be aborted.
     224 *
     225 * @param fmgt File management object
     226 * @return @c true iff operation should be aborted
     227 */
     228static bool fmgt_abort_query(fmgt_t *fmgt)
     229{
     230        if (fmgt->cb != NULL && fmgt->cb->abort_query!= NULL)
     231                return fmgt->cb->abort_query(fmgt->cb_arg);
     232        else
     233                return false;
     234}
     235
    223236/** Create new file.
    224237 *
     
    276289
    277290                fmgt->curf_procb += nw;
     291
     292                /* User requested abort? */
     293                if (fmgt_abort_query(fmgt)) {
     294                        free(buffer);
     295                        vfs_put(fd);
     296                        fmgt_final_progress_update(fmgt);
     297                        return EINTR;
     298                }
    278299        }
    279300
Note: See TracChangeset for help on using the changeset viewer.