Changeset df2e621c in mainline
- Timestamp:
- 2014-07-08T15:09:29Z (10 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 53f68fd
- Parents:
- 6bcecc2
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/graph/graph.c
r6bcecc2 rdf2e621c 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); 149 167 150 list_foreach(visualizer_list, link, visualizer_t, vcur) { 168 151 if (vcur->reg_svc_handle == handle) { … … 171 154 } 172 155 } 156 173 157 fibril_mutex_unlock(&visualizer_list_mtx); 174 158 175 159 return vs; 176 160 } … … 179 163 { 180 164 renderer_t *rnd = NULL; 181 165 182 166 fibril_mutex_lock(&renderer_list_mtx); 167 183 168 list_foreach(renderer_list, link, renderer_t, rcur) { 184 169 if (rcur->reg_svc_handle == handle) { … … 187 172 } 188 173 } 174 189 175 fibril_mutex_unlock(&renderer_list_mtx); 190 176 191 177 return rnd; 192 178 } … … 194 180 int graph_unregister_visualizer(visualizer_t *vs) 195 181 { 196 int rc = EOK;197 198 182 fibril_mutex_lock(&visualizer_list_mtx); 199 rc = loc_service_unregister(vs->reg_svc_handle);183 int rc = loc_service_unregister(vs->reg_svc_handle); 200 184 list_remove(&vs->link); 201 185 fibril_mutex_unlock(&visualizer_list_mtx); 202 186 203 187 return rc; 204 188 } … … 206 190 int graph_unregister_renderer(renderer_t *rnd) 207 191 { 208 int rc = EOK;209 210 192 fibril_mutex_lock(&renderer_list_mtx); 211 rc = loc_service_unregister(rnd->reg_svc_handle);193 int rc = loc_service_unregister(rnd->reg_svc_handle); 212 194 list_remove(&rnd->link); 213 195 fibril_mutex_unlock(&renderer_list_mtx); 214 196 215 197 return rc; 216 198 } … … 225 207 assert(vs->cells.data == NULL); 226 208 assert(vs->dev_ctx == NULL); 227 209 228 210 free(vs); 229 211 } … … 233 215 // TODO 234 216 assert(atomic_get(&rnd->ref_cnt) == 0); 235 217 236 218 free(rnd); 237 219 } … … 242 224 int ret = async_req_2_0(exch, VISUALIZER_MODE_CHANGE, handle, mode_idx); 243 225 async_exchange_end(exch); 244 226 245 227 return ret; 246 228 } … … 251 233 int ret = async_req_1_0(exch, VISUALIZER_DISCONNECT, handle); 252 234 async_exchange_end(exch); 253 235 254 236 async_hangup(sess); 255 237 256 238 return ret; 257 239 } … … 273 255 } 274 256 } 275 257 276 258 /* Driver might also deallocate resources for the current mode. */ 277 259 int rc = vs->ops.yield(vs); 278 260 279 261 /* Now that the driver was given a chance to deallocate resources, 280 262 * current mode can be unset. */ 281 if (vs->mode_set) {263 if (vs->mode_set) 282 264 vs->mode_set = false; 283 } 284 265 285 266 async_answer_0(iid, rc); 286 267 } … … 288 269 static void vs_enumerate_modes(visualizer_t *vs, ipc_callid_t iid, ipc_call_t *icall) 289 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 290 280 fibril_mutex_lock(&vs->mode_mtx); 291 281 link_t *link = list_nth(&vs->modes, IPC_GET_ARG1(*icall)); 292 282 293 283 if (link != NULL) { 294 284 vslmode_list_element_t *mode_elem = 295 285 list_get_instance(link, vslmode_list_element_t, link); 296 vslmode_t mode = mode_elem->mode; 297 fibril_mutex_unlock(&vs->mode_mtx); 298 299 ipc_callid_t callid; 300 size_t len; 301 302 if (!async_data_read_receive(&callid, &len)) { 303 async_answer_0(iid, EINVAL); 304 return; 305 } 306 int rc = async_data_read_finalize(callid, &mode, len); 307 if (rc != EOK) { 308 async_answer_0(iid, ENOMEM); 309 return; 310 } 311 312 async_answer_0(iid, EOK); 286 287 int rc = async_data_read_finalize(callid, &mode_elem->mode, len); 288 async_answer_0(iid, rc); 313 289 } else { 314 fibril_mutex_unlock(&vs->mode_mtx);290 async_answer_0(callid, ENOENT); 315 291 async_answer_0(iid, ENOENT); 316 292 } 293 294 fibril_mutex_unlock(&vs->mode_mtx); 317 295 } 318 296 319 297 static void vs_get_default_mode(visualizer_t *vs, ipc_callid_t iid, ipc_call_t *icall) 320 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 321 308 fibril_mutex_lock(&vs->mode_mtx); 322 309 vslmode_list_element_t *mode_elem = NULL; 310 323 311 list_foreach(vs->modes, link, vslmode_list_element_t, cur) { 324 312 if (cur->mode.index == vs->def_mode_idx) { … … 327 315 } 328 316 } 329 330 vslmode_t mode; 317 331 318 if (mode_elem != NULL) { 332 mode = mode_elem->mode; 333 fibril_mutex_unlock(&vs->mode_mtx); 334 335 ipc_callid_t callid; 336 size_t len; 337 338 if (!async_data_read_receive(&callid, &len)) { 339 async_answer_0(iid, EINVAL); 340 return; 341 } 342 int rc = async_data_read_finalize(callid, &mode, len); 343 if (rc != EOK) { 344 async_answer_0(iid, ENOMEM); 345 return; 346 } 347 async_answer_0(iid, EOK); 319 int rc = async_data_read_finalize(callid, &mode_elem->mode, len); 320 async_answer_0(iid, rc); 348 321 } else { 349 322 fibril_mutex_unlock(&vs->mode_mtx); 323 async_answer_0(callid, ENOENT); 350 324 async_answer_0(iid, ENOENT); 351 325 } 326 327 fibril_mutex_unlock(&vs->mode_mtx); 352 328 } 353 329 354 330 static void vs_get_current_mode(visualizer_t *vs, ipc_callid_t iid, ipc_call_t *icall) 355 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 356 341 if (vs->mode_set) { 357 ipc_callid_t callid;358 size_t len;359 360 if (!async_data_read_receive(&callid, &len)) {361 async_answer_0(iid, EINVAL);362 return;363 }364 342 int rc = async_data_read_finalize(callid, &vs->cur_mode, len); 365 if (rc != EOK) { 366 async_answer_0(iid, ENOMEM); 367 return; 368 } 369 370 async_answer_0(iid, EOK); 343 async_answer_0(iid, rc); 371 344 } else { 345 async_answer_0(callid, ENOENT); 372 346 async_answer_0(iid, ENOENT); 373 347 } … … 376 350 static void vs_get_mode(visualizer_t *vs, ipc_callid_t iid, ipc_call_t *icall) 377 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 378 361 sysarg_t mode_idx = IPC_GET_ARG1(*icall); 379 362 380 363 fibril_mutex_lock(&vs->mode_mtx); 381 364 vslmode_list_element_t *mode_elem = NULL; 365 382 366 list_foreach(vs->modes, link, vslmode_list_element_t, cur) { 383 367 if (cur->mode.index == mode_idx) { … … 386 370 } 387 371 } 388 389 vslmode_t mode; 372 390 373 if (mode_elem != NULL) { 391 mode = mode_elem->mode; 392 fibril_mutex_unlock(&vs->mode_mtx); 393 394 ipc_callid_t callid; 395 size_t len; 396 397 if (!async_data_read_receive(&callid, &len)) { 398 async_answer_0(iid, EINVAL); 399 return; 400 } 401 int rc = async_data_read_finalize(callid, &mode, len); 402 if (rc != EOK) { 403 async_answer_0(iid, ENOMEM); 404 return; 405 } 406 async_answer_0(iid, EOK); 374 int rc = async_data_read_finalize(callid, &mode_elem->mode, len); 375 async_answer_0(iid, rc); 407 376 } else { 408 fibril_mutex_unlock(&vs->mode_mtx);377 async_answer_0(callid, ENOENT); 409 378 async_answer_0(iid, ENOENT); 410 379 } 380 381 fibril_mutex_unlock(&vs->mode_mtx); 411 382 } 412 383 413 384 static void vs_set_mode(visualizer_t *vs, ipc_callid_t iid, ipc_call_t *icall) 414 385 { 415 int rc = EOK; 416 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 417 397 /* Retrieve mode index and version. */ 418 398 sysarg_t mode_idx = IPC_GET_ARG1(*icall); 419 399 sysarg_t mode_version = IPC_GET_ARG2(*icall); 420 400 421 401 /* Find mode in the list. */ 422 402 fibril_mutex_lock(&vs->mode_mtx); 423 403 vslmode_list_element_t *mode_elem = NULL; 404 424 405 list_foreach(vs->modes, link, vslmode_list_element_t, cur) { 425 406 if (cur->mode.index == mode_idx) { … … 428 409 } 429 410 } 430 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 431 419 /* Extract mode description from the list node. */ 432 vslmode_t new_mode; 433 if (mode_elem != NULL) { 434 new_mode = mode_elem->mode; 435 fibril_mutex_unlock(&vs->mode_mtx); 436 } else { 437 fibril_mutex_unlock(&vs->mode_mtx); 438 async_answer_0(iid, ENOENT); 439 return; 440 } 441 420 vslmode_t new_mode = mode_elem->mode; 421 fibril_mutex_unlock(&vs->mode_mtx); 422 442 423 /* Check whether the mode is still up-to-date. */ 443 424 if (new_mode.version != mode_version) { 425 async_answer_0(callid, EINVAL); 444 426 async_answer_0(iid, EINVAL); 445 427 return; 446 428 } 447 448 ipc_callid_t callid; 449 size_t size; 450 unsigned int flags; 451 452 /* Retrieve the shared cell storage for the new mode. */ 453 if (!async_share_out_receive(&callid, &size, &flags)) { 454 async_answer_0(iid, EINVAL); 455 return; 456 } 429 457 430 void *new_cell_storage; 458 rc = async_share_out_finalize(callid, &new_cell_storage);431 int rc = async_share_out_finalize(callid, &new_cell_storage); 459 432 if ((rc != EOK) || (new_cell_storage == AS_MAP_FAILED)) { 460 433 async_answer_0(iid, ENOMEM); 461 434 return; 462 435 } 463 436 464 437 /* Change device internal state. */ 465 438 rc = vs->ops.change_mode(vs, new_mode); 466 439 467 440 /* Device driver could not establish new mode. Rollback. */ 468 441 if (rc != EOK) { … … 471 444 return; 472 445 } 473 474 /* Because resources for the new mode were successfully claimed, 475 * 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 */ 476 452 if (vs->mode_set) { 477 453 if (vs->cells.data != NULL) { … … 480 456 } 481 457 } 482 458 483 459 /* Insert new mode into the visualizer. */ 484 460 vs->cells.width = new_mode.screen_width; … … 487 463 vs->cur_mode = new_mode; 488 464 vs->mode_set = true; 489 465 490 466 async_answer_0(iid, EOK); 491 467 } … … 500 476 sysarg_t y_offset = (IPC_GET_ARG5(*icall) & 0xffffffff); 501 477 #endif 502 478 503 479 int rc = vs->ops.handle_damage(vs, 504 480 IPC_GET_ARG1(*icall), IPC_GET_ARG2(*icall), 505 481 IPC_GET_ARG3(*icall), IPC_GET_ARG4(*icall), 506 482 x_offset, y_offset); 507 483 async_answer_0(iid, rc); 508 484 } … … 525 501 ipc_call_t call; 526 502 ipc_callid_t callid; 527 503 528 504 /* Claim the visualizer. */ 529 505 if (!cas(&vs->ref_cnt, 0, 1)) { … … 531 507 return; 532 508 } 533 509 534 510 /* Accept the connection. */ 535 511 async_answer_0(iid, EOK); 536 512 537 513 /* Establish callback session. */ 538 514 callid = async_get_call(&call); 539 515 vs->notif_sess = async_callback_receive_start(EXCHANGE_SERIALIZE, &call); 540 if (vs->notif_sess != NULL) {516 if (vs->notif_sess != NULL) 541 517 async_answer_0(callid, EOK); 542 } else {518 else 543 519 async_answer_0(callid, ELIMIT); 544 } 545 520 546 521 /* Enter command loop. */ 547 522 while (true) { 548 523 callid = async_get_call(&call); 549 524 550 525 if (!IPC_GET_IMETHOD(call)) { 551 526 async_answer_0(callid, EINVAL); 552 527 break; 553 528 } 554 529 555 530 switch (IPC_GET_IMETHOD(call)) { 556 531 case VISUALIZER_CLAIM: … … 589 564 } 590 565 } 591 566 592 567 terminate: 593 568 async_hangup(vs->notif_sess); … … 600 575 { 601 576 // TODO 602 577 603 578 ipc_call_t call; 604 579 ipc_callid_t callid; 605 580 606 581 /* Accept the connection. */ 607 582 atomic_inc(&rnd->ref_cnt); 608 583 async_answer_0(iid, EOK); 609 584 610 585 /* Enter command loop. */ 611 586 while (true) { 612 587 callid = async_get_call(&call); 613 588 614 589 if (!IPC_GET_IMETHOD(call)) { 615 590 async_answer_0(callid, EINVAL); 616 591 break; 617 592 } 618 593 619 594 switch (IPC_GET_IMETHOD(call)) { 620 595 default: … … 623 598 } 624 599 } 625 600 626 601 terminate: 627 602 atomic_dec(&rnd->ref_cnt); … … 633 608 visualizer_t *vs = graph_get_visualizer(IPC_GET_ARG1(*icall)); 634 609 renderer_t *rnd = graph_get_renderer(IPC_GET_ARG1(*icall)); 635 636 if (vs != NULL) {610 611 if (vs != NULL) 637 612 graph_visualizer_connection(vs, iid, icall, arg); 638 } else if (rnd != NULL) {613 else if (rnd != NULL) 639 614 graph_renderer_connection(rnd, iid, icall, arg); 640 } else {615 else 641 616 async_answer_0(iid, ENOENT); 642 }643 617 } 644 618
Note:
See TracChangeset
for help on using the changeset viewer.