Changeset 14cbf07 in mainline
- Timestamp:
- 2023-05-15T16:19:52Z (21 months ago)
- Branches:
- master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 2b5628c, 8a4ceaa
- Parents:
- aace43d8
- Location:
- uspace
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/display-cfg/display-cfg.c
raace43d8 r14cbf07 65 65 * 66 66 * @param display_spec Display specification 67 * @param dcfg_svc Display configuration service name or DISPCFG_DEFAULT 67 68 * @param rdcfg Place to store pointer to new display configuration 68 69 * @return EOK on success or an error code … … 82 83 printf("Out of memory.\n"); 83 84 return ENOMEM; 84 }85 86 rc = dispcfg_open(DISPCFG_DEFAULT, NULL, NULL, &dcfg->dispcfg);87 if (rc != EOK) {88 printf("Error opening display configuration service.\n");89 goto error;90 85 } 91 86 … … 150 145 ui_window_add(window, ui_fixed_ctl(dcfg->fixed)); 151 146 152 rc = ui_window_paint(window);153 if (rc != EOK) {154 printf("Error painting window.\n");155 return rc;156 }157 158 147 *rdcfg = dcfg; 159 148 return EOK; … … 167 156 if (dcfg->ui != NULL) 168 157 ui_destroy(ui); 158 free(dcfg); 159 return rc; 160 } 161 162 /** Open display configuration service. 163 * 164 * @param dcfg Display configuration dialog 165 * @param dcfg_svc Display configuration service name or DISPCFG_DEFAULT 166 * @return EOK on success or an error code 167 */ 168 errno_t display_cfg_open(display_cfg_t *dcfg, const char *dcfg_svc) 169 { 170 errno_t rc; 171 172 rc = dispcfg_open(dcfg_svc, NULL, NULL, &dcfg->dispcfg); 173 if (rc != EOK) { 174 printf("Error opening display configuration service.\n"); 175 goto error; 176 } 177 178 return EOK; 179 error: 180 return rc; 181 } 182 183 /** Populate display configuration from isplay configuration service. 184 * 185 * @param dcfg Display configuration dialog 186 * @return EOK on success or an error code 187 */ 188 errno_t display_cfg_populate(display_cfg_t *dcfg) 189 { 190 errno_t rc; 191 192 rc = dcfg_seats_populate(dcfg->seats); 193 if (rc != EOK) 194 return rc; 195 196 rc = ui_window_paint(dcfg->window); 197 if (rc != EOK) { 198 printf("Error painting window.\n"); 199 return rc; 200 } 201 202 return EOK; 203 } 204 205 /** Destroy display configuration dialog. 206 * 207 * @param dcfg Display configuration dialog 208 */ 209 void display_cfg_destroy(display_cfg_t *dcfg) 210 { 169 211 if (dcfg->dispcfg != NULL) 170 212 dispcfg_close(dcfg->dispcfg); 171 free(dcfg);172 return rc;173 }174 175 /** Destroy display configuration dialog.176 *177 * @param dcfg Display configuration dialog178 */179 void display_cfg_destroy(display_cfg_t *dcfg)180 {181 213 ui_window_destroy(dcfg->window); 182 214 ui_destroy(dcfg->ui); -
uspace/app/display-cfg/display-cfg.h
raace43d8 r14cbf07 40 40 41 41 extern errno_t display_cfg_create(const char *, display_cfg_t **); 42 extern errno_t display_cfg_open(display_cfg_t *, const char *); 43 extern errno_t display_cfg_populate(display_cfg_t *); 42 44 extern void display_cfg_destroy(display_cfg_t *); 43 45 -
uspace/app/display-cfg/main.c
raace43d8 r14cbf07 77 77 return 1; 78 78 79 rc = display_cfg_open(dcfg, DISPCFG_DEFAULT); 80 if (rc != EOK) 81 return 1; 82 83 rc = display_cfg_populate(dcfg); 84 if (rc != EOK) 85 return 1; 86 79 87 ui_run(dcfg->ui); 80 88 display_cfg_destroy(dcfg); -
uspace/app/display-cfg/seats.c
raace43d8 r14cbf07 50 50 #include "seats.h" 51 51 52 static errno_t dcfg_seats_list_populate(dcfg_seats_t *);53 52 static errno_t dcfg_seats_asgn_dev_list_populate(dcfg_seats_t *); 54 53 static errno_t dcfg_seats_avail_dev_list_populate(dcfg_seats_t *, … … 118 117 ui_resource_t *ui_res; 119 118 dcfg_seats_t *seats; 120 dcfg_seats_entry_t *entry;121 119 gfx_rect_t rect; 122 char *caption = NULL; 123 errno_t rc; 124 int rv; 120 errno_t rc; 125 121 126 122 ui_res = ui_window_get_res(dcfg->window); … … 204 200 ui_list_set_cb(seats->seat_list, &dcfg_seats_list_cb, (void *)seats); 205 201 206 rc = dcfg_seats_list_populate(seats);207 if (rc != EOK)208 goto error;209 210 202 /* 'Add...' seat button */ 211 203 … … 272 264 /* 'Devices assigned to seat 'xxx':' label */ 273 265 274 entry = dcfg_seats_get_selected(seats); 275 rv = asprintf(&caption, "Devices assigned to seat '%s':", entry->name); 276 if (rv < 0) { 277 rc = ENOMEM; 278 goto error; 279 } 280 281 rc = ui_label_create(ui_res, caption, &seats->devices_label); 266 rc = ui_label_create(ui_res, "Devices assigned to seat 'xxx':", 267 &seats->devices_label); 282 268 if (rc != EOK) { 283 269 printf("Error creating label.\n"); 284 270 goto error; 285 271 } 286 287 free(caption);288 caption = NULL;289 272 290 273 if (ui_resource_is_textmode(ui_res)) { … … 400 383 ui_tab_add(seats->tab, ui_fixed_ctl(seats->fixed)); 401 384 402 rc = dcfg_seats_asgn_dev_list_populate(seats);403 if (rc != EOK)404 goto error;405 406 385 *rseats = seats; 407 386 return EOK; … … 411 390 if (seats->add_device != NULL) 412 391 ui_pbutton_destroy(seats->add_device); 413 if (caption != NULL)414 free(caption);415 392 if (seats->devices_label != NULL) 416 393 ui_label_destroy(seats->devices_label); … … 431 408 } 432 409 410 /** Populate seats tab with display configuration service data 411 * 412 * @param dcfg Display configuration dialog 413 * @param rseats Place to store pointer to new seat configuration tab 414 * @return EOK on success or an error code 415 */ 416 errno_t dcfg_seats_populate(dcfg_seats_t *seats) 417 { 418 dcfg_seats_entry_t *entry; 419 errno_t rc; 420 421 printf("seats list populate\n"); 422 rc = dcfg_seats_list_populate(seats); 423 if (rc != EOK) 424 return rc; 425 426 /* 427 * Update "Devices assigned to seat 'xxx'" label and populate 428 * assigned devices list. 429 */ 430 entry = dcfg_seats_get_selected(seats); 431 dcfg_seats_list_selected(entry->lentry, (void *)entry); 432 return EOK; 433 } 434 433 435 /** Destroy display configuration dialog. 434 436 * … … 511 513 * @return EOK on success or an error code 512 514 */ 513 staticerrno_t dcfg_seats_list_populate(dcfg_seats_t *seats)515 errno_t dcfg_seats_list_populate(dcfg_seats_t *seats) 514 516 { 515 517 size_t i; … … 594 596 * @return EOK on success or an error code 595 597 */ 596 staticerrno_t dcfg_avail_devices_insert(dcfg_seats_t *seats,598 errno_t dcfg_avail_devices_insert(dcfg_seats_t *seats, 597 599 ui_select_dialog_t *dialog, const char *name, service_id_t svc_id) 598 600 { -
uspace/app/display-cfg/seats.h
raace43d8 r14cbf07 41 41 42 42 extern errno_t dcfg_seats_create(display_cfg_t *, dcfg_seats_t **); 43 extern errno_t dcfg_seats_populate(dcfg_seats_t *); 43 44 extern void dcfg_seats_destroy(dcfg_seats_t *); 44 45 extern errno_t dcfg_seats_insert(dcfg_seats_t *, const char *, sysarg_t, … … 46 47 extern errno_t dcfg_devices_insert(dcfg_seats_t *, const char *, 47 48 service_id_t); 49 extern errno_t dcfg_avail_devices_insert(dcfg_seats_t *seats, 50 ui_select_dialog_t *dialog, const char *name, service_id_t svc_id); 51 extern errno_t dcfg_seats_list_populate(dcfg_seats_t *); 48 52 49 53 #endif -
uspace/app/display-cfg/test/seats.c
raace43d8 r14cbf07 32 32 #include <errno.h> 33 33 #include <pcut/pcut.h> 34 #include <str.h> 34 35 #include <testdc.h> 35 36 #include "../display-cfg.h" … … 85 86 } 86 87 87 / /??? Requires us to create a test display config service88 /** dcfg_seats_list_populate() populates seat list */ 88 89 PCUT_TEST(seats_list_populate) 89 90 { 91 display_cfg_t *dcfg; 92 dcfg_seats_t *seats; 90 93 errno_t rc; 91 94 service_id_t sid; 92 dispcfg_t *dispcfg = NULL;93 95 test_response_t resp; 94 96 … … 102 104 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 103 105 104 rc = dispcfg_open(test_dispcfg_svc, NULL, NULL, &dispcfg); 105 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 106 PCUT_ASSERT_NOT_NULL(dispcfg); 107 108 dispcfg_close(dispcfg); 109 rc = loc_service_unregister(sid); 110 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 106 rc = display_cfg_create(UI_DISPLAY_NULL, &dcfg); 107 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 108 109 rc = display_cfg_open(dcfg, test_dispcfg_svc); 110 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 111 112 rc = dcfg_seats_create(dcfg, &seats); 113 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 114 115 /* 116 * dcfg_seat_list_populate() calls dispcfg_get_seat_list() 117 * and dispcfg_get_seat_info() 118 */ 119 resp.rc = EOK; 120 resp.get_seat_list_rlist = calloc(1, sizeof(dispcfg_seat_list_t)); 121 PCUT_ASSERT_NOT_NULL(resp.get_seat_list_rlist); 122 resp.get_seat_list_rlist->nseats = 1; 123 resp.get_seat_list_rlist->seats = calloc(1, sizeof(sysarg_t)); 124 PCUT_ASSERT_NOT_NULL(resp.get_seat_list_rlist->seats); 125 resp.get_seat_list_rlist->seats[0] = 42; 126 127 resp.get_seat_info_rinfo = calloc(1, sizeof(dispcfg_seat_info_t)); 128 PCUT_ASSERT_NOT_NULL(resp.get_seat_info_rinfo); 129 resp.get_seat_info_rinfo->name = str_dup("Alice"); 130 PCUT_ASSERT_NOT_NULL(resp.get_seat_info_rinfo->name); 131 132 rc = dcfg_seats_list_populate(seats); 133 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 134 135 dcfg_seats_destroy(seats); 136 display_cfg_destroy(dcfg); 111 137 } 112 138 … … 141 167 } 142 168 169 /** dcfg_avail_devices_insert() inserts entry into available devices list */ 143 170 PCUT_TEST(avail_devices_insert) 144 171 { 172 display_cfg_t *dcfg; 173 dcfg_seats_t *seats; 174 ui_list_entry_t *lentry; 175 dcfg_devices_entry_t *entry; 176 ui_select_dialog_t *dialog; 177 ui_select_dialog_params_t sdparams; 178 errno_t rc; 179 180 rc = display_cfg_create(UI_DISPLAY_NULL, &dcfg); 181 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 182 183 rc = dcfg_seats_create(dcfg, &seats); 184 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 185 186 ui_select_dialog_params_init(&sdparams); 187 sdparams.caption = "Dialog"; 188 sdparams.prompt = "Select"; 189 190 rc = ui_select_dialog_create(seats->dcfg->ui, &sdparams, &dialog); 191 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 192 193 rc = dcfg_avail_devices_insert(seats, dialog, "mydevice", 42); 194 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 195 196 lentry = ui_list_first(ui_select_dialog_list(dialog)); 197 PCUT_ASSERT_NOT_NULL(lentry); 198 entry = (dcfg_devices_entry_t *)ui_list_entry_get_arg(lentry); 199 PCUT_ASSERT_NOT_NULL(entry); 200 201 PCUT_ASSERT_STR_EQUALS("mydevice", entry->name); 202 PCUT_ASSERT_INT_EQUALS(42, entry->svc_id); 203 204 ui_select_dialog_destroy(dialog); 205 dcfg_seats_destroy(seats); 206 display_cfg_destroy(dcfg); 145 207 } 146 208 -
uspace/lib/ui/include/ui/selectdialog.h
raace43d8 r14cbf07 51 51 ui_list_entry_attr_t *); 52 52 extern errno_t ui_select_dialog_paint(ui_select_dialog_t *); 53 extern ui_list_t *ui_select_dialog_list(ui_select_dialog_t *); 53 54 54 55 #endif -
uspace/lib/ui/src/selectdialog.c
raace43d8 r14cbf07 329 329 } 330 330 331 /** Get the entry list from select dialog. 332 * 333 * @param dialog Select dialog 334 * @return UI list 335 */ 336 ui_list_t *ui_select_dialog_list(ui_select_dialog_t *dialog) 337 { 338 return dialog->list; 339 } 340 331 341 /** Select dialog window close handler. 332 342 * -
uspace/lib/ui/test/selectdialog.c
raace43d8 r14cbf07 310 310 } 311 311 312 /** ui_select_dialog_list() returns the UI list */ 313 PCUT_TEST(list) 314 { 315 errno_t rc; 316 ui_t *ui = NULL; 317 ui_select_dialog_params_t params; 318 ui_select_dialog_t *dialog = NULL; 319 ui_list_t *list; 320 ui_list_entry_attr_t attr; 321 322 rc = ui_create_disp(NULL, &ui); 323 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 324 325 ui_select_dialog_params_init(¶ms); 326 params.caption = "Select one"; 327 params.prompt = "Please select"; 328 329 rc = ui_select_dialog_create(ui, ¶ms, &dialog); 330 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 331 PCUT_ASSERT_NOT_NULL(dialog); 332 333 list = ui_select_dialog_list(dialog); 334 PCUT_ASSERT_NOT_NULL(list); 335 336 PCUT_ASSERT_INT_EQUALS(0, ui_list_entries_cnt(list)); 337 338 /* Add one entry */ 339 ui_list_entry_attr_init(&attr); 340 attr.caption = "Entry"; 341 rc = ui_select_dialog_append(dialog, &attr); 342 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 343 344 PCUT_ASSERT_INT_EQUALS(1, ui_list_entries_cnt(list)); 345 346 ui_select_dialog_destroy(dialog); 347 ui_destroy(ui); 348 } 349 312 350 static void test_dialog_bok(ui_select_dialog_t *dialog, void *arg, 313 351 void *earg)
Note:
See TracChangeset
for help on using the changeset viewer.