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