Changes in uspace/lib/graph/graph.c [6d5e378:f9b2cb4c] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/graph/graph.c
r6d5e378 rf9b2cb4c 58 58 visualizer_t *graph_alloc_visualizer(void) 59 59 { 60 visualizer_t *vs = (visualizer_t *) malloc(sizeof(visualizer_t)); 61 if (vs == NULL) { 62 return NULL; 63 } 64 65 return vs; 60 return ((visualizer_t *) malloc(sizeof(visualizer_t))); 66 61 } 67 62 … … 69 64 { 70 65 // TODO 71 renderer_t *rnd = (renderer_t *) malloc(sizeof(renderer_t)); 72 if (rnd == NULL) { 73 return NULL; 74 } 75 76 return rnd; 66 return ((renderer_t *) malloc(sizeof(renderer_t))); 77 67 } 78 68 … … 98 88 int graph_register_visualizer(visualizer_t *vs) 99 89 { 100 int rc = EOK;101 102 90 char node[LOC_NAME_MAXLEN + 1]; 103 91 snprintf(node, LOC_NAME_MAXLEN, "%s%zu/%s%zu", NAMESPACE, 104 92 namespace_idx, VISUALIZER_NAME, visualizer_idx++); 105 93 106 94 category_id_t cat; 107 rc = loc_category_get_id("visualizer", &cat, 0);108 if (rc != EOK) {95 int rc = loc_category_get_id("visualizer", &cat, 0); 96 if (rc != EOK) 109 97 return rc; 110 } 111 98 112 99 rc = loc_service_register(node, &vs->reg_svc_handle); 113 if (rc != EOK) {100 if (rc != EOK) 114 101 return rc; 115 } 116 102 117 103 rc = loc_service_add_to_cat(vs->reg_svc_handle, cat); 118 104 if (rc != EOK) { … … 120 106 return rc; 121 107 } 122 108 123 109 fibril_mutex_lock(&visualizer_list_mtx); 124 110 list_append(&vs->link, &visualizer_list); 125 111 fibril_mutex_unlock(&visualizer_list_mtx); 126 112 127 113 return rc; 128 114 } … … 130 116 int graph_register_renderer(renderer_t *rnd) 131 117 { 132 int rc = EOK;133 134 118 char node[LOC_NAME_MAXLEN + 1]; 135 119 snprintf(node, LOC_NAME_MAXLEN, "%s%zu/%s%zu", NAMESPACE, 136 120 namespace_idx, RENDERER_NAME, renderer_idx++); 137 121 138 122 category_id_t cat; 139 rc = loc_category_get_id("renderer", &cat, 0);140 if (rc != EOK) {123 int rc = loc_category_get_id("renderer", &cat, 0); 124 if (rc != EOK) 141 125 return rc; 142 } 143 126 144 127 rc = loc_service_register(node, &rnd->reg_svc_handle); 145 if (rc != EOK) {128 if (rc != EOK) 146 129 return rc; 147 } 148 130 149 131 rc = loc_service_add_to_cat(rnd->reg_svc_handle, cat); 150 132 if (rc != EOK) { … … 152 134 return rc; 153 135 } 154 136 155 137 fibril_mutex_lock(&renderer_list_mtx); 156 138 list_append(&rnd->link, &renderer_list); 157 139 fibril_mutex_unlock(&renderer_list_mtx); 158 140 159 141 return rc; 160 142 } … … 163 145 { 164 146 visualizer_t *vs = NULL; 165 147 166 148 fibril_mutex_lock(&visualizer_list_mtx); 167 list_foreach(visualizer_list, link) { 168 visualizer_t *cur = list_get_instance(link, visualizer_t, link); 169 if (cur->reg_svc_handle == handle) { 170 vs = cur; 171 break; 172 } 173 } 149 150 list_foreach(visualizer_list, link, visualizer_t, vcur) { 151 if (vcur->reg_svc_handle == handle) { 152 vs = vcur; 153 break; 154 } 155 } 156 174 157 fibril_mutex_unlock(&visualizer_list_mtx); 175 158 176 159 return vs; 177 160 } … … 180 163 { 181 164 renderer_t *rnd = NULL; 182 165 183 166 fibril_mutex_lock(&renderer_list_mtx); 184 list_foreach(renderer_list, link) { 185 renderer_t *cur = list_get_instance(link, renderer_t, link); 186 if (cur->reg_svc_handle == handle) { 187 rnd = cur; 188 break; 189 } 190 } 167 168 list_foreach(renderer_list, link, renderer_t, rcur) { 169 if (rcur->reg_svc_handle == handle) { 170 rnd = rcur; 171 break; 172 } 173 } 174 191 175 fibril_mutex_unlock(&renderer_list_mtx); 192 176 193 177 return rnd; 194 178 } … … 196 180 int graph_unregister_visualizer(visualizer_t *vs) 197 181 { 198 int rc = EOK;199 200 182 fibril_mutex_lock(&visualizer_list_mtx); 201 rc = loc_service_unregister(vs->reg_svc_handle);183 int rc = loc_service_unregister(vs->reg_svc_handle); 202 184 list_remove(&vs->link); 203 185 fibril_mutex_unlock(&visualizer_list_mtx); 204 186 205 187 return rc; 206 188 } … … 208 190 int graph_unregister_renderer(renderer_t *rnd) 209 191 { 210 int rc = EOK;211 212 192 fibril_mutex_lock(&renderer_list_mtx); 213 rc = loc_service_unregister(rnd->reg_svc_handle);193 int rc = loc_service_unregister(rnd->reg_svc_handle); 214 194 list_remove(&rnd->link); 215 195 fibril_mutex_unlock(&renderer_list_mtx); 216 196 217 197 return rc; 218 198 } … … 227 207 assert(vs->cells.data == NULL); 228 208 assert(vs->dev_ctx == NULL); 229 209 230 210 free(vs); 231 211 } … … 235 215 // TODO 236 216 assert(atomic_get(&rnd->ref_cnt) == 0); 237 217 238 218 free(rnd); 239 219 } … … 244 224 int ret = async_req_2_0(exch, VISUALIZER_MODE_CHANGE, handle, mode_idx); 245 225 async_exchange_end(exch); 246 226 247 227 return ret; 248 228 } … … 253 233 int ret = async_req_1_0(exch, VISUALIZER_DISCONNECT, handle); 254 234 async_exchange_end(exch); 255 235 256 236 async_hangup(sess); 257 237 258 238 return ret; 259 239 } … … 275 255 } 276 256 } 277 257 278 258 /* Driver might also deallocate resources for the current mode. */ 279 259 int rc = vs->ops.yield(vs); 280 260 281 261 /* Now that the driver was given a chance to deallocate resources, 282 262 * current mode can be unset. */ 283 if (vs->mode_set) {263 if (vs->mode_set) 284 264 vs->mode_set = false; 285 } 286 265 287 266 async_answer_0(iid, rc); 288 267 } … … 290 269 static void vs_enumerate_modes(visualizer_t *vs, ipc_callid_t iid, ipc_call_t *icall) 291 270 { 271 ipc_callid_t callid; 272 size_t len; 273 274 if (!async_data_read_receive(&callid, &len)) { 275 async_answer_0(callid, EREFUSED); 276 async_answer_0(iid, EREFUSED); 277 return; 278 } 279 292 280 fibril_mutex_lock(&vs->mode_mtx); 293 281 link_t *link = list_nth(&vs->modes, IPC_GET_ARG1(*icall)); 294 282 295 283 if (link != NULL) { 296 284 vslmode_list_element_t *mode_elem = 297 285 list_get_instance(link, vslmode_list_element_t, link); 298 vslmode_t mode = mode_elem->mode; 299 fibril_mutex_unlock(&vs->mode_mtx); 300 301 ipc_callid_t callid; 302 size_t len; 303 304 if (!async_data_read_receive(&callid, &len)) { 305 async_answer_0(iid, EINVAL); 306 return; 307 } 308 int rc = async_data_read_finalize(callid, &mode, len); 309 if (rc != EOK) { 310 async_answer_0(iid, ENOMEM); 311 return; 312 } 313 314 async_answer_0(iid, EOK); 286 287 int rc = async_data_read_finalize(callid, &mode_elem->mode, len); 288 async_answer_0(iid, rc); 315 289 } else { 290 async_answer_0(callid, ENOENT); 316 291 async_answer_0(iid, ENOENT); 317 292 } 293 294 fibril_mutex_unlock(&vs->mode_mtx); 318 295 } 319 296 320 297 static void vs_get_default_mode(visualizer_t *vs, ipc_callid_t iid, ipc_call_t *icall) 321 298 { 299 ipc_callid_t callid; 300 size_t len; 301 302 if (!async_data_read_receive(&callid, &len)) { 303 async_answer_0(callid, EREFUSED); 304 async_answer_0(iid, EREFUSED); 305 return; 306 } 307 322 308 fibril_mutex_lock(&vs->mode_mtx); 323 309 vslmode_list_element_t *mode_elem = NULL; 324 list_foreach(vs->modes, link) {325 vslmode_list_element_t *cur = list_get_instance(link, vslmode_list_element_t, link);310 311 list_foreach(vs->modes, link, vslmode_list_element_t, cur) { 326 312 if (cur->mode.index == vs->def_mode_idx) { 327 313 mode_elem = cur; … … 329 315 } 330 316 } 331 332 vslmode_t mode; 317 333 318 if (mode_elem != NULL) { 334 mode = mode_elem->mode; 335 fibril_mutex_unlock(&vs->mode_mtx); 336 337 ipc_callid_t callid; 338 size_t len; 339 340 if (!async_data_read_receive(&callid, &len)) { 341 async_answer_0(iid, EINVAL); 342 return; 343 } 344 int rc = async_data_read_finalize(callid, &mode, len); 345 if (rc != EOK) { 346 async_answer_0(iid, ENOMEM); 347 return; 348 } 349 async_answer_0(iid, EOK); 319 int rc = async_data_read_finalize(callid, &mode_elem->mode, len); 320 async_answer_0(iid, rc); 350 321 } else { 351 322 fibril_mutex_unlock(&vs->mode_mtx); 323 async_answer_0(callid, ENOENT); 352 324 async_answer_0(iid, ENOENT); 353 325 } 326 327 fibril_mutex_unlock(&vs->mode_mtx); 354 328 } 355 329 356 330 static void vs_get_current_mode(visualizer_t *vs, ipc_callid_t iid, ipc_call_t *icall) 357 331 { 332 ipc_callid_t callid; 333 size_t len; 334 335 if (!async_data_read_receive(&callid, &len)) { 336 async_answer_0(callid, EREFUSED); 337 async_answer_0(iid, EREFUSED); 338 return; 339 } 340 358 341 if (vs->mode_set) { 359 ipc_callid_t callid;360 size_t len;361 362 if (!async_data_read_receive(&callid, &len)) {363 async_answer_0(iid, EINVAL);364 return;365 }366 342 int rc = async_data_read_finalize(callid, &vs->cur_mode, len); 367 if (rc != EOK) { 368 async_answer_0(iid, ENOMEM); 369 return; 370 } 371 372 async_answer_0(iid, EOK); 343 async_answer_0(iid, rc); 373 344 } else { 345 async_answer_0(callid, ENOENT); 374 346 async_answer_0(iid, ENOENT); 375 347 } … … 378 350 static void vs_get_mode(visualizer_t *vs, ipc_callid_t iid, ipc_call_t *icall) 379 351 { 352 ipc_callid_t callid; 353 size_t len; 354 355 if (!async_data_read_receive(&callid, &len)) { 356 async_answer_0(callid, EREFUSED); 357 async_answer_0(iid, EREFUSED); 358 return; 359 } 360 380 361 sysarg_t mode_idx = IPC_GET_ARG1(*icall); 381 362 382 363 fibril_mutex_lock(&vs->mode_mtx); 383 364 vslmode_list_element_t *mode_elem = NULL; 384 list_foreach(vs->modes, link) {385 vslmode_list_element_t *cur = list_get_instance(link, vslmode_list_element_t, link);365 366 list_foreach(vs->modes, link, vslmode_list_element_t, cur) { 386 367 if (cur->mode.index == mode_idx) { 387 368 mode_elem = cur; … … 389 370 } 390 371 } 391 392 vslmode_t mode; 372 393 373 if (mode_elem != NULL) { 394 mode = mode_elem->mode; 395 fibril_mutex_unlock(&vs->mode_mtx); 396 397 ipc_callid_t callid; 398 size_t len; 399 400 if (!async_data_read_receive(&callid, &len)) { 401 async_answer_0(iid, EINVAL); 402 return; 403 } 404 int rc = async_data_read_finalize(callid, &mode, len); 405 if (rc != EOK) { 406 async_answer_0(iid, ENOMEM); 407 return; 408 } 409 async_answer_0(iid, EOK); 374 int rc = async_data_read_finalize(callid, &mode_elem->mode, len); 375 async_answer_0(iid, rc); 410 376 } else { 411 fibril_mutex_unlock(&vs->mode_mtx);377 async_answer_0(callid, ENOENT); 412 378 async_answer_0(iid, ENOENT); 413 379 } 380 381 fibril_mutex_unlock(&vs->mode_mtx); 414 382 } 415 383 416 384 static void vs_set_mode(visualizer_t *vs, ipc_callid_t iid, ipc_call_t *icall) 417 385 { 418 int rc = EOK; 419 386 ipc_callid_t callid; 387 size_t size; 388 unsigned int flags; 389 390 /* Retrieve the shared cell storage for the new mode. */ 391 if (!async_share_out_receive(&callid, &size, &flags)) { 392 async_answer_0(callid, EREFUSED); 393 async_answer_0(iid, EREFUSED); 394 return; 395 } 396 420 397 /* Retrieve mode index and version. */ 421 398 sysarg_t mode_idx = IPC_GET_ARG1(*icall); 422 399 sysarg_t mode_version = IPC_GET_ARG2(*icall); 423 400 424 401 /* Find mode in the list. */ 425 402 fibril_mutex_lock(&vs->mode_mtx); 426 403 vslmode_list_element_t *mode_elem = NULL; 427 list_foreach(vs->modes, link) {428 vslmode_list_element_t *cur = list_get_instance(link, vslmode_list_element_t, link);404 405 list_foreach(vs->modes, link, vslmode_list_element_t, cur) { 429 406 if (cur->mode.index == mode_idx) { 430 407 mode_elem = cur; … … 432 409 } 433 410 } 434 411 412 if (mode_elem == NULL) { 413 fibril_mutex_unlock(&vs->mode_mtx); 414 async_answer_0(callid, ENOENT); 415 async_answer_0(iid, ENOENT); 416 return; 417 } 418 435 419 /* Extract mode description from the list node. */ 436 vslmode_t new_mode; 437 if (mode_elem != NULL) { 438 new_mode = mode_elem->mode; 439 fibril_mutex_unlock(&vs->mode_mtx); 440 } else { 441 fibril_mutex_unlock(&vs->mode_mtx); 442 async_answer_0(iid, ENOENT); 443 return; 444 } 445 420 vslmode_t new_mode = mode_elem->mode; 421 fibril_mutex_unlock(&vs->mode_mtx); 422 446 423 /* Check whether the mode is still up-to-date. */ 447 424 if (new_mode.version != mode_version) { 425 async_answer_0(callid, EINVAL); 448 426 async_answer_0(iid, EINVAL); 449 427 return; 450 428 } 451 452 ipc_callid_t callid; 453 size_t size; 454 unsigned int flags; 455 456 /* Retrieve the shared cell storage for the new mode. */ 457 if (!async_share_out_receive(&callid, &size, &flags)) { 458 async_answer_0(iid, EINVAL); 459 return; 460 } 429 461 430 void *new_cell_storage; 462 rc = async_share_out_finalize(callid, &new_cell_storage);431 int rc = async_share_out_finalize(callid, &new_cell_storage); 463 432 if ((rc != EOK) || (new_cell_storage == AS_MAP_FAILED)) { 464 433 async_answer_0(iid, ENOMEM); 465 434 return; 466 435 } 467 436 468 437 /* Change device internal state. */ 469 438 rc = vs->ops.change_mode(vs, new_mode); 470 439 471 440 /* Device driver could not establish new mode. Rollback. */ 472 441 if (rc != EOK) { … … 475 444 return; 476 445 } 477 478 /* Because resources for the new mode were successfully claimed, 479 * it is finally possible to free resources allocated for the old mode. */ 446 447 /* 448 * Because resources for the new mode were successfully 449 * claimed, it is finally possible to free resources 450 * allocated for the old mode. 451 */ 480 452 if (vs->mode_set) { 481 453 if (vs->cells.data != NULL) { … … 484 456 } 485 457 } 486 458 487 459 /* Insert new mode into the visualizer. */ 488 460 vs->cells.width = new_mode.screen_width; … … 491 463 vs->cur_mode = new_mode; 492 464 vs->mode_set = true; 493 465 494 466 async_answer_0(iid, EOK); 495 467 } … … 504 476 sysarg_t y_offset = (IPC_GET_ARG5(*icall) & 0xffffffff); 505 477 #endif 506 478 507 479 int rc = vs->ops.handle_damage(vs, 508 480 IPC_GET_ARG1(*icall), IPC_GET_ARG2(*icall), 509 481 IPC_GET_ARG3(*icall), IPC_GET_ARG4(*icall), 510 482 x_offset, y_offset); 511 483 async_answer_0(iid, rc); 512 484 } … … 529 501 ipc_call_t call; 530 502 ipc_callid_t callid; 531 503 532 504 /* Claim the visualizer. */ 533 505 if (!cas(&vs->ref_cnt, 0, 1)) { … … 535 507 return; 536 508 } 537 509 538 510 /* Accept the connection. */ 539 511 async_answer_0(iid, EOK); 540 512 541 513 /* Establish callback session. */ 542 514 callid = async_get_call(&call); 543 515 vs->notif_sess = async_callback_receive_start(EXCHANGE_SERIALIZE, &call); 544 if (vs->notif_sess != NULL) {516 if (vs->notif_sess != NULL) 545 517 async_answer_0(callid, EOK); 546 } else {518 else 547 519 async_answer_0(callid, ELIMIT); 548 } 549 520 550 521 /* Enter command loop. */ 551 522 while (true) { 552 523 callid = async_get_call(&call); 553 524 554 525 if (!IPC_GET_IMETHOD(call)) { 555 526 async_answer_0(callid, EINVAL); 556 527 break; 557 528 } 558 529 559 530 switch (IPC_GET_IMETHOD(call)) { 560 531 case VISUALIZER_CLAIM: … … 593 564 } 594 565 } 595 566 596 567 terminate: 597 568 async_hangup(vs->notif_sess); … … 604 575 { 605 576 // TODO 606 577 607 578 ipc_call_t call; 608 579 ipc_callid_t callid; 609 580 610 581 /* Accept the connection. */ 611 582 atomic_inc(&rnd->ref_cnt); 612 583 async_answer_0(iid, EOK); 613 584 614 585 /* Enter command loop. */ 615 586 while (true) { 616 587 callid = async_get_call(&call); 617 588 618 589 if (!IPC_GET_IMETHOD(call)) { 619 590 async_answer_0(callid, EINVAL); 620 591 break; 621 592 } 622 593 623 594 switch (IPC_GET_IMETHOD(call)) { 624 595 default: … … 627 598 } 628 599 } 629 600 630 601 terminate: 631 602 atomic_dec(&rnd->ref_cnt); … … 635 606 { 636 607 /* Find the visualizer or renderer with the given service ID. */ 637 visualizer_t *vs = graph_get_visualizer(IPC_GET_ARG 1(*icall));638 renderer_t *rnd = graph_get_renderer(IPC_GET_ARG 1(*icall));639 640 if (vs != NULL) {608 visualizer_t *vs = graph_get_visualizer(IPC_GET_ARG2(*icall)); 609 renderer_t *rnd = graph_get_renderer(IPC_GET_ARG2(*icall)); 610 611 if (vs != NULL) 641 612 graph_visualizer_connection(vs, iid, icall, arg); 642 } else if (rnd != NULL) {613 else if (rnd != NULL) 643 614 graph_renderer_connection(rnd, iid, icall, arg); 644 } else {615 else 645 616 async_answer_0(iid, ENOENT); 646 }647 617 } 648 618
Note:
See TracChangeset
for help on using the changeset viewer.