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