Changeset a35b458 in mainline for uspace/lib/graph/graph.c
- Timestamp:
- 2018-03-02T20:10:49Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f1380b7
- Parents:
- 3061bc1
- git-author:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-02-28 17:38:31)
- git-committer:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:10:49)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/graph/graph.c
r3061bc1 ra35b458 91 91 snprintf(node, LOC_NAME_MAXLEN, "%s%zu/%s%zu", NAMESPACE, 92 92 namespace_idx, VISUALIZER_NAME, visualizer_idx++); 93 93 94 94 category_id_t cat; 95 95 errno_t rc = loc_category_get_id("visualizer", &cat, 0); 96 96 if (rc != EOK) 97 97 return rc; 98 98 99 99 rc = loc_service_register(node, &vs->reg_svc_handle); 100 100 if (rc != EOK) 101 101 return rc; 102 102 103 103 rc = loc_service_add_to_cat(vs->reg_svc_handle, cat); 104 104 if (rc != EOK) { … … 106 106 return rc; 107 107 } 108 108 109 109 fibril_mutex_lock(&visualizer_list_mtx); 110 110 list_append(&vs->link, &visualizer_list); 111 111 fibril_mutex_unlock(&visualizer_list_mtx); 112 112 113 113 return rc; 114 114 } … … 119 119 snprintf(node, LOC_NAME_MAXLEN, "%s%zu/%s%zu", NAMESPACE, 120 120 namespace_idx, RENDERER_NAME, renderer_idx++); 121 121 122 122 category_id_t cat; 123 123 errno_t rc = loc_category_get_id("renderer", &cat, 0); 124 124 if (rc != EOK) 125 125 return rc; 126 126 127 127 rc = loc_service_register(node, &rnd->reg_svc_handle); 128 128 if (rc != EOK) 129 129 return rc; 130 130 131 131 rc = loc_service_add_to_cat(rnd->reg_svc_handle, cat); 132 132 if (rc != EOK) { … … 134 134 return rc; 135 135 } 136 136 137 137 fibril_mutex_lock(&renderer_list_mtx); 138 138 list_append(&rnd->link, &renderer_list); 139 139 fibril_mutex_unlock(&renderer_list_mtx); 140 140 141 141 return rc; 142 142 } … … 145 145 { 146 146 visualizer_t *vs = NULL; 147 147 148 148 fibril_mutex_lock(&visualizer_list_mtx); 149 149 150 150 list_foreach(visualizer_list, link, visualizer_t, vcur) { 151 151 if (vcur->reg_svc_handle == handle) { … … 154 154 } 155 155 } 156 156 157 157 fibril_mutex_unlock(&visualizer_list_mtx); 158 158 159 159 return vs; 160 160 } … … 163 163 { 164 164 renderer_t *rnd = NULL; 165 165 166 166 fibril_mutex_lock(&renderer_list_mtx); 167 167 168 168 list_foreach(renderer_list, link, renderer_t, rcur) { 169 169 if (rcur->reg_svc_handle == handle) { … … 172 172 } 173 173 } 174 174 175 175 fibril_mutex_unlock(&renderer_list_mtx); 176 176 177 177 return rnd; 178 178 } … … 184 184 list_remove(&vs->link); 185 185 fibril_mutex_unlock(&visualizer_list_mtx); 186 186 187 187 return rc; 188 188 } … … 194 194 list_remove(&rnd->link); 195 195 fibril_mutex_unlock(&renderer_list_mtx); 196 196 197 197 return rc; 198 198 } … … 207 207 assert(vs->cells.data == NULL); 208 208 assert(vs->dev_ctx == NULL); 209 209 210 210 free(vs); 211 211 } … … 215 215 // TODO 216 216 assert(atomic_get(&rnd->ref_cnt) == 0); 217 217 218 218 free(rnd); 219 219 } … … 224 224 errno_t ret = async_req_2_0(exch, VISUALIZER_MODE_CHANGE, handle, mode_idx); 225 225 async_exchange_end(exch); 226 226 227 227 return ret; 228 228 } … … 233 233 errno_t ret = async_req_1_0(exch, VISUALIZER_DISCONNECT, handle); 234 234 async_exchange_end(exch); 235 235 236 236 async_hangup(sess); 237 237 238 238 return ret; 239 239 } … … 255 255 } 256 256 } 257 257 258 258 /* Driver might also deallocate resources for the current mode. */ 259 259 errno_t rc = vs->ops.yield(vs); 260 260 261 261 /* Now that the driver was given a chance to deallocate resources, 262 262 * current mode can be unset. */ 263 263 if (vs->mode_set) 264 264 vs->mode_set = false; 265 265 266 266 async_answer_0(iid, rc); 267 267 } … … 271 271 ipc_callid_t callid; 272 272 size_t len; 273 273 274 274 if (!async_data_read_receive(&callid, &len)) { 275 275 async_answer_0(callid, EREFUSED); … … 277 277 return; 278 278 } 279 279 280 280 fibril_mutex_lock(&vs->mode_mtx); 281 281 link_t *link = list_nth(&vs->modes, IPC_GET_ARG1(*icall)); 282 282 283 283 if (link != NULL) { 284 284 vslmode_list_element_t *mode_elem = 285 285 list_get_instance(link, vslmode_list_element_t, link); 286 286 287 287 errno_t rc = async_data_read_finalize(callid, &mode_elem->mode, len); 288 288 async_answer_0(iid, rc); … … 291 291 async_answer_0(iid, ENOENT); 292 292 } 293 293 294 294 fibril_mutex_unlock(&vs->mode_mtx); 295 295 } … … 299 299 ipc_callid_t callid; 300 300 size_t len; 301 301 302 302 if (!async_data_read_receive(&callid, &len)) { 303 303 async_answer_0(callid, EREFUSED); … … 305 305 return; 306 306 } 307 307 308 308 fibril_mutex_lock(&vs->mode_mtx); 309 309 vslmode_list_element_t *mode_elem = NULL; 310 310 311 311 list_foreach(vs->modes, link, vslmode_list_element_t, cur) { 312 312 if (cur->mode.index == vs->def_mode_idx) { … … 315 315 } 316 316 } 317 317 318 318 if (mode_elem != NULL) { 319 319 errno_t rc = async_data_read_finalize(callid, &mode_elem->mode, len); … … 324 324 async_answer_0(iid, ENOENT); 325 325 } 326 326 327 327 fibril_mutex_unlock(&vs->mode_mtx); 328 328 } … … 332 332 ipc_callid_t callid; 333 333 size_t len; 334 334 335 335 if (!async_data_read_receive(&callid, &len)) { 336 336 async_answer_0(callid, EREFUSED); … … 338 338 return; 339 339 } 340 340 341 341 if (vs->mode_set) { 342 342 errno_t rc = async_data_read_finalize(callid, &vs->cur_mode, len); … … 352 352 ipc_callid_t callid; 353 353 size_t len; 354 354 355 355 if (!async_data_read_receive(&callid, &len)) { 356 356 async_answer_0(callid, EREFUSED); … … 358 358 return; 359 359 } 360 360 361 361 sysarg_t mode_idx = IPC_GET_ARG1(*icall); 362 362 363 363 fibril_mutex_lock(&vs->mode_mtx); 364 364 vslmode_list_element_t *mode_elem = NULL; 365 365 366 366 list_foreach(vs->modes, link, vslmode_list_element_t, cur) { 367 367 if (cur->mode.index == mode_idx) { … … 370 370 } 371 371 } 372 372 373 373 if (mode_elem != NULL) { 374 374 errno_t rc = async_data_read_finalize(callid, &mode_elem->mode, len); … … 378 378 async_answer_0(iid, ENOENT); 379 379 } 380 380 381 381 fibril_mutex_unlock(&vs->mode_mtx); 382 382 } … … 387 387 size_t size; 388 388 unsigned int flags; 389 389 390 390 /* Retrieve the shared cell storage for the new mode. */ 391 391 if (!async_share_out_receive(&callid, &size, &flags)) { … … 394 394 return; 395 395 } 396 396 397 397 /* Retrieve mode index and version. */ 398 398 sysarg_t mode_idx = IPC_GET_ARG1(*icall); 399 399 sysarg_t mode_version = IPC_GET_ARG2(*icall); 400 400 401 401 /* Find mode in the list. */ 402 402 fibril_mutex_lock(&vs->mode_mtx); 403 403 vslmode_list_element_t *mode_elem = NULL; 404 404 405 405 list_foreach(vs->modes, link, vslmode_list_element_t, cur) { 406 406 if (cur->mode.index == mode_idx) { … … 409 409 } 410 410 } 411 411 412 412 if (mode_elem == NULL) { 413 413 fibril_mutex_unlock(&vs->mode_mtx); … … 416 416 return; 417 417 } 418 418 419 419 /* Extract mode description from the list node. */ 420 420 vslmode_t new_mode = mode_elem->mode; 421 421 fibril_mutex_unlock(&vs->mode_mtx); 422 422 423 423 /* Check whether the mode is still up-to-date. */ 424 424 if (new_mode.version != mode_version) { … … 427 427 return; 428 428 } 429 429 430 430 void *new_cell_storage; 431 431 errno_t rc = async_share_out_finalize(callid, &new_cell_storage); … … 434 434 return; 435 435 } 436 436 437 437 /* Change device internal state. */ 438 438 rc = vs->ops.change_mode(vs, new_mode); 439 439 440 440 /* Device driver could not establish new mode. Rollback. */ 441 441 if (rc != EOK) { … … 444 444 return; 445 445 } 446 446 447 447 /* 448 448 * Because resources for the new mode were successfully … … 456 456 } 457 457 } 458 458 459 459 /* Insert new mode into the visualizer. */ 460 460 vs->cells.width = new_mode.screen_width; … … 463 463 vs->cur_mode = new_mode; 464 464 vs->mode_set = true; 465 465 466 466 async_answer_0(iid, EOK); 467 467 } … … 471 471 sysarg_t x_offset = (IPC_GET_ARG5(*icall) >> 16); 472 472 sysarg_t y_offset = (IPC_GET_ARG5(*icall) & 0x0000ffff); 473 473 474 474 errno_t rc = vs->ops.handle_damage(vs, 475 475 IPC_GET_ARG1(*icall), IPC_GET_ARG2(*icall), … … 496 496 ipc_call_t call; 497 497 ipc_callid_t callid; 498 498 499 499 /* Claim the visualizer. */ 500 500 if (!cas(&vs->ref_cnt, 0, 1)) { … … 502 502 return; 503 503 } 504 504 505 505 /* Accept the connection. */ 506 506 async_answer_0(iid, EOK); 507 507 508 508 /* Establish callback session. */ 509 509 callid = async_get_call(&call); … … 513 513 else 514 514 async_answer_0(callid, ELIMIT); 515 515 516 516 /* Enter command loop. */ 517 517 while (true) { 518 518 callid = async_get_call(&call); 519 519 520 520 if (!IPC_GET_IMETHOD(call)) { 521 521 async_answer_0(callid, EINVAL); 522 522 break; 523 523 } 524 524 525 525 switch (IPC_GET_IMETHOD(call)) { 526 526 case VISUALIZER_CLAIM: … … 559 559 } 560 560 } 561 561 562 562 terminate: 563 563 async_hangup(vs->notif_sess); … … 570 570 { 571 571 // TODO 572 572 573 573 ipc_call_t call; 574 574 ipc_callid_t callid; 575 575 576 576 /* Accept the connection. */ 577 577 atomic_inc(&rnd->ref_cnt); 578 578 async_answer_0(iid, EOK); 579 579 580 580 /* Enter command loop. */ 581 581 while (true) { 582 582 callid = async_get_call(&call); 583 583 584 584 if (!IPC_GET_IMETHOD(call)) { 585 585 async_answer_0(callid, EINVAL); 586 586 break; 587 587 } 588 588 589 589 switch (IPC_GET_IMETHOD(call)) { 590 590 default: … … 593 593 } 594 594 } 595 595 596 596 terminate: 597 597 atomic_dec(&rnd->ref_cnt); … … 603 603 visualizer_t *vs = graph_get_visualizer(IPC_GET_ARG2(*icall)); 604 604 renderer_t *rnd = graph_get_renderer(IPC_GET_ARG2(*icall)); 605 605 606 606 if (vs != NULL) 607 607 graph_visualizer_connection(vs, iid, icall, arg);
Note:
See TracChangeset
for help on using the changeset viewer.