source: mainline/uspace/lib/graph/graph.c@ ab6edb6

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since ab6edb6 was 7c3fb9b, checked in by Jiri Svoboda <jiri@…>, 7 years ago

Fix block comment formatting (ccheck).

  • Property mode set to 100644
File size: 15.1 KB
RevLine 
[6d5e378]1/*
2 * Copyright (c) 2011 Petr Koupy
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup graph
30 * @{
31 */
32/**
33 * @file
34 */
35
36#include <assert.h>
37#include <errno.h>
38#include <inttypes.h>
39#include <stdio.h>
40#include <as.h>
[38d150e]41#include <stdlib.h>
[6d5e378]42#include "graph.h"
43
44#define NAMESPACE "graphemu"
45#define VISUALIZER_NAME "vsl"
46#define RENDERER_NAME "rnd"
47
48static sysarg_t namespace_idx = 0;
49static sysarg_t visualizer_idx = 0;
50static sysarg_t renderer_idx = 0;
51
52static LIST_INITIALIZE(visualizer_list);
53static LIST_INITIALIZE(renderer_list);
54
55static FIBRIL_MUTEX_INITIALIZE(visualizer_list_mtx);
56static FIBRIL_MUTEX_INITIALIZE(renderer_list_mtx);
57
58visualizer_t *graph_alloc_visualizer(void)
59{
[df2e621c]60 return ((visualizer_t *) malloc(sizeof(visualizer_t)));
[6d5e378]61}
62
63renderer_t *graph_alloc_renderer(void)
64{
65 // TODO
[df2e621c]66 return ((renderer_t *) malloc(sizeof(renderer_t)));
[6d5e378]67}
68
69void graph_init_visualizer(visualizer_t *vs)
70{
71 link_initialize(&vs->link);
72 atomic_set(&vs->ref_cnt, 0);
73 vs->notif_sess = NULL;
74 fibril_mutex_initialize(&vs->mode_mtx);
75 list_initialize(&vs->modes);
76 vs->mode_set = false;
77 vs->cells.data = NULL;
78 vs->dev_ctx = NULL;
79}
80
81void graph_init_renderer(renderer_t *rnd)
82{
83 // TODO
84 link_initialize(&rnd->link);
85 atomic_set(&rnd->ref_cnt, 0);
86}
87
[b7fd2a0]88errno_t graph_register_visualizer(visualizer_t *vs)
[6d5e378]89{
90 char node[LOC_NAME_MAXLEN + 1];
91 snprintf(node, LOC_NAME_MAXLEN, "%s%zu/%s%zu", NAMESPACE,
92 namespace_idx, VISUALIZER_NAME, visualizer_idx++);
[a35b458]93
[6d5e378]94 category_id_t cat;
[b7fd2a0]95 errno_t rc = loc_category_get_id("visualizer", &cat, 0);
[df2e621c]96 if (rc != EOK)
[6d5e378]97 return rc;
[a35b458]98
[6d5e378]99 rc = loc_service_register(node, &vs->reg_svc_handle);
[df2e621c]100 if (rc != EOK)
[6d5e378]101 return rc;
[a35b458]102
[6d5e378]103 rc = loc_service_add_to_cat(vs->reg_svc_handle, cat);
104 if (rc != EOK) {
105 loc_service_unregister(vs->reg_svc_handle);
106 return rc;
107 }
[a35b458]108
[6d5e378]109 fibril_mutex_lock(&visualizer_list_mtx);
110 list_append(&vs->link, &visualizer_list);
111 fibril_mutex_unlock(&visualizer_list_mtx);
[a35b458]112
[6d5e378]113 return rc;
114}
115
[b7fd2a0]116errno_t graph_register_renderer(renderer_t *rnd)
[6d5e378]117{
118 char node[LOC_NAME_MAXLEN + 1];
119 snprintf(node, LOC_NAME_MAXLEN, "%s%zu/%s%zu", NAMESPACE,
120 namespace_idx, RENDERER_NAME, renderer_idx++);
[a35b458]121
[6d5e378]122 category_id_t cat;
[b7fd2a0]123 errno_t rc = loc_category_get_id("renderer", &cat, 0);
[df2e621c]124 if (rc != EOK)
[6d5e378]125 return rc;
[a35b458]126
[6d5e378]127 rc = loc_service_register(node, &rnd->reg_svc_handle);
[df2e621c]128 if (rc != EOK)
[6d5e378]129 return rc;
[a35b458]130
[6d5e378]131 rc = loc_service_add_to_cat(rnd->reg_svc_handle, cat);
132 if (rc != EOK) {
133 loc_service_unregister(rnd->reg_svc_handle);
134 return rc;
135 }
[a35b458]136
[6d5e378]137 fibril_mutex_lock(&renderer_list_mtx);
138 list_append(&rnd->link, &renderer_list);
139 fibril_mutex_unlock(&renderer_list_mtx);
[a35b458]140
[6d5e378]141 return rc;
142}
143
144visualizer_t *graph_get_visualizer(sysarg_t handle)
145{
146 visualizer_t *vs = NULL;
[a35b458]147
[6d5e378]148 fibril_mutex_lock(&visualizer_list_mtx);
[a35b458]149
[feeac0d]150 list_foreach(visualizer_list, link, visualizer_t, vcur) {
151 if (vcur->reg_svc_handle == handle) {
152 vs = vcur;
[6d5e378]153 break;
154 }
155 }
[a35b458]156
[6d5e378]157 fibril_mutex_unlock(&visualizer_list_mtx);
[a35b458]158
[6d5e378]159 return vs;
160}
161
162renderer_t *graph_get_renderer(sysarg_t handle)
163{
164 renderer_t *rnd = NULL;
[a35b458]165
[6d5e378]166 fibril_mutex_lock(&renderer_list_mtx);
[a35b458]167
[feeac0d]168 list_foreach(renderer_list, link, renderer_t, rcur) {
169 if (rcur->reg_svc_handle == handle) {
170 rnd = rcur;
[6d5e378]171 break;
172 }
173 }
[a35b458]174
[6d5e378]175 fibril_mutex_unlock(&renderer_list_mtx);
[a35b458]176
[6d5e378]177 return rnd;
178}
179
[b7fd2a0]180errno_t graph_unregister_visualizer(visualizer_t *vs)
[6d5e378]181{
182 fibril_mutex_lock(&visualizer_list_mtx);
[b7fd2a0]183 errno_t rc = loc_service_unregister(vs->reg_svc_handle);
[6d5e378]184 list_remove(&vs->link);
185 fibril_mutex_unlock(&visualizer_list_mtx);
[a35b458]186
[6d5e378]187 return rc;
188}
189
[b7fd2a0]190errno_t graph_unregister_renderer(renderer_t *rnd)
[6d5e378]191{
192 fibril_mutex_lock(&renderer_list_mtx);
[b7fd2a0]193 errno_t rc = loc_service_unregister(rnd->reg_svc_handle);
[6d5e378]194 list_remove(&rnd->link);
195 fibril_mutex_unlock(&renderer_list_mtx);
[a35b458]196
[6d5e378]197 return rc;
198}
199
200void graph_destroy_visualizer(visualizer_t *vs)
201{
202 assert(atomic_get(&vs->ref_cnt) == 0);
203 assert(vs->notif_sess == NULL);
204 assert(!fibril_mutex_is_locked(&vs->mode_mtx));
205 assert(list_empty(&vs->modes));
206 assert(vs->mode_set == false);
207 assert(vs->cells.data == NULL);
208 assert(vs->dev_ctx == NULL);
[a35b458]209
[6d5e378]210 free(vs);
211}
212
213void graph_destroy_renderer(renderer_t *rnd)
214{
215 // TODO
216 assert(atomic_get(&rnd->ref_cnt) == 0);
[a35b458]217
[6d5e378]218 free(rnd);
219}
220
[b7fd2a0]221errno_t graph_notify_mode_change(async_sess_t *sess, sysarg_t handle, sysarg_t mode_idx)
[6d5e378]222{
223 async_exch_t *exch = async_exchange_begin(sess);
[b7fd2a0]224 errno_t ret = async_req_2_0(exch, VISUALIZER_MODE_CHANGE, handle, mode_idx);
[6d5e378]225 async_exchange_end(exch);
[a35b458]226
[6d5e378]227 return ret;
228}
229
[b7fd2a0]230errno_t graph_notify_disconnect(async_sess_t *sess, sysarg_t handle)
[6d5e378]231{
232 async_exch_t *exch = async_exchange_begin(sess);
[b7fd2a0]233 errno_t ret = async_req_1_0(exch, VISUALIZER_DISCONNECT, handle);
[6d5e378]234 async_exchange_end(exch);
[a35b458]235
[6d5e378]236 async_hangup(sess);
[a35b458]237
[6d5e378]238 return ret;
239}
240
[a46e56b]241static void vs_claim(visualizer_t *vs, cap_call_handle_t icall_handle, ipc_call_t *icall)
[6d5e378]242{
243 vs->client_side_handle = IPC_GET_ARG1(*icall);
[b7fd2a0]244 errno_t rc = vs->ops.claim(vs);
[a46e56b]245 async_answer_0(icall_handle, rc);
[6d5e378]246}
247
[a46e56b]248static void vs_yield(visualizer_t *vs, cap_call_handle_t icall_handle, ipc_call_t *icall)
[6d5e378]249{
250 /* Deallocate resources for the current mode. */
251 if (vs->mode_set) {
252 if (vs->cells.data != NULL) {
253 as_area_destroy((void *) vs->cells.data);
254 vs->cells.data = NULL;
255 }
256 }
[a35b458]257
[6d5e378]258 /* Driver might also deallocate resources for the current mode. */
[b7fd2a0]259 errno_t rc = vs->ops.yield(vs);
[a35b458]260
[7c3fb9b]261 /*
262 * Now that the driver was given a chance to deallocate resources,
263 * current mode can be unset.
264 */
[df2e621c]265 if (vs->mode_set)
[6d5e378]266 vs->mode_set = false;
[a35b458]267
[a46e56b]268 async_answer_0(icall_handle, rc);
[6d5e378]269}
270
[a46e56b]271static void vs_enumerate_modes(visualizer_t *vs, cap_call_handle_t icall_handle, ipc_call_t *icall)
[6d5e378]272{
[a46e56b]273 cap_call_handle_t chandle;
[df2e621c]274 size_t len;
[a35b458]275
[a46e56b]276 if (!async_data_read_receive(&chandle, &len)) {
277 async_answer_0(chandle, EREFUSED);
278 async_answer_0(icall_handle, EREFUSED);
[df2e621c]279 return;
280 }
[a35b458]281
[6d5e378]282 fibril_mutex_lock(&vs->mode_mtx);
283 link_t *link = list_nth(&vs->modes, IPC_GET_ARG1(*icall));
[a35b458]284
[6d5e378]285 if (link != NULL) {
286 vslmode_list_element_t *mode_elem =
287 list_get_instance(link, vslmode_list_element_t, link);
[a35b458]288
[a46e56b]289 errno_t rc = async_data_read_finalize(chandle, &mode_elem->mode, len);
290 async_answer_0(icall_handle, rc);
[6d5e378]291 } else {
[a46e56b]292 async_answer_0(chandle, ENOENT);
293 async_answer_0(icall_handle, ENOENT);
[6d5e378]294 }
[a35b458]295
[df2e621c]296 fibril_mutex_unlock(&vs->mode_mtx);
[6d5e378]297}
298
[a46e56b]299static void vs_get_default_mode(visualizer_t *vs, cap_call_handle_t icall_handle, ipc_call_t *icall)
[6d5e378]300{
[a46e56b]301 cap_call_handle_t chandle;
[df2e621c]302 size_t len;
[a35b458]303
[a46e56b]304 if (!async_data_read_receive(&chandle, &len)) {
305 async_answer_0(chandle, EREFUSED);
306 async_answer_0(icall_handle, EREFUSED);
[df2e621c]307 return;
308 }
[a35b458]309
[6d5e378]310 fibril_mutex_lock(&vs->mode_mtx);
311 vslmode_list_element_t *mode_elem = NULL;
[a35b458]312
[feeac0d]313 list_foreach(vs->modes, link, vslmode_list_element_t, cur) {
[6d5e378]314 if (cur->mode.index == vs->def_mode_idx) {
315 mode_elem = cur;
316 break;
317 }
318 }
[a35b458]319
[6d5e378]320 if (mode_elem != NULL) {
[a46e56b]321 errno_t rc = async_data_read_finalize(chandle, &mode_elem->mode, len);
322 async_answer_0(icall_handle, rc);
[6d5e378]323 } else {
324 fibril_mutex_unlock(&vs->mode_mtx);
[a46e56b]325 async_answer_0(chandle, ENOENT);
326 async_answer_0(icall_handle, ENOENT);
[6d5e378]327 }
[a35b458]328
[df2e621c]329 fibril_mutex_unlock(&vs->mode_mtx);
[6d5e378]330}
331
[a46e56b]332static void vs_get_current_mode(visualizer_t *vs, cap_call_handle_t icall_handle, ipc_call_t *icall)
[6d5e378]333{
[a46e56b]334 cap_call_handle_t chandle;
[df2e621c]335 size_t len;
[a35b458]336
[a46e56b]337 if (!async_data_read_receive(&chandle, &len)) {
338 async_answer_0(chandle, EREFUSED);
339 async_answer_0(icall_handle, EREFUSED);
[df2e621c]340 return;
341 }
[a35b458]342
[6d5e378]343 if (vs->mode_set) {
[a46e56b]344 errno_t rc = async_data_read_finalize(chandle, &vs->cur_mode, len);
345 async_answer_0(icall_handle, rc);
[6d5e378]346 } else {
[a46e56b]347 async_answer_0(chandle, ENOENT);
348 async_answer_0(icall_handle, ENOENT);
[6d5e378]349 }
350}
351
[a46e56b]352static void vs_get_mode(visualizer_t *vs, cap_call_handle_t icall_handle, ipc_call_t *icall)
[6d5e378]353{
[a46e56b]354 cap_call_handle_t chandle;
[df2e621c]355 size_t len;
[a35b458]356
[a46e56b]357 if (!async_data_read_receive(&chandle, &len)) {
358 async_answer_0(chandle, EREFUSED);
359 async_answer_0(icall_handle, EREFUSED);
[df2e621c]360 return;
361 }
[a35b458]362
[6d5e378]363 sysarg_t mode_idx = IPC_GET_ARG1(*icall);
[a35b458]364
[6d5e378]365 fibril_mutex_lock(&vs->mode_mtx);
366 vslmode_list_element_t *mode_elem = NULL;
[a35b458]367
[feeac0d]368 list_foreach(vs->modes, link, vslmode_list_element_t, cur) {
[6d5e378]369 if (cur->mode.index == mode_idx) {
370 mode_elem = cur;
371 break;
372 }
373 }
[a35b458]374
[6d5e378]375 if (mode_elem != NULL) {
[a46e56b]376 errno_t rc = async_data_read_finalize(chandle, &mode_elem->mode, len);
377 async_answer_0(icall_handle, rc);
[6d5e378]378 } else {
[a46e56b]379 async_answer_0(chandle, ENOENT);
380 async_answer_0(icall_handle, ENOENT);
[6d5e378]381 }
[a35b458]382
[df2e621c]383 fibril_mutex_unlock(&vs->mode_mtx);
[6d5e378]384}
385
[a46e56b]386static void vs_set_mode(visualizer_t *vs, cap_call_handle_t icall_handle, ipc_call_t *icall)
[6d5e378]387{
[a46e56b]388 cap_call_handle_t chandle;
[df2e621c]389 size_t size;
390 unsigned int flags;
[a35b458]391
[df2e621c]392 /* Retrieve the shared cell storage for the new mode. */
[a46e56b]393 if (!async_share_out_receive(&chandle, &size, &flags)) {
394 async_answer_0(chandle, EREFUSED);
395 async_answer_0(icall_handle, EREFUSED);
[df2e621c]396 return;
397 }
[a35b458]398
[6d5e378]399 /* Retrieve mode index and version. */
400 sysarg_t mode_idx = IPC_GET_ARG1(*icall);
401 sysarg_t mode_version = IPC_GET_ARG2(*icall);
[a35b458]402
[6d5e378]403 /* Find mode in the list. */
404 fibril_mutex_lock(&vs->mode_mtx);
405 vslmode_list_element_t *mode_elem = NULL;
[a35b458]406
[feeac0d]407 list_foreach(vs->modes, link, vslmode_list_element_t, cur) {
[6d5e378]408 if (cur->mode.index == mode_idx) {
409 mode_elem = cur;
410 break;
411 }
412 }
[a35b458]413
[df2e621c]414 if (mode_elem == NULL) {
[6d5e378]415 fibril_mutex_unlock(&vs->mode_mtx);
[a46e56b]416 async_answer_0(chandle, ENOENT);
417 async_answer_0(icall_handle, ENOENT);
[6d5e378]418 return;
419 }
[a35b458]420
[df2e621c]421 /* Extract mode description from the list node. */
422 vslmode_t new_mode = mode_elem->mode;
423 fibril_mutex_unlock(&vs->mode_mtx);
[a35b458]424
[6d5e378]425 /* Check whether the mode is still up-to-date. */
426 if (new_mode.version != mode_version) {
[a46e56b]427 async_answer_0(chandle, EINVAL);
428 async_answer_0(icall_handle, EINVAL);
[6d5e378]429 return;
430 }
[a35b458]431
[6d5e378]432 void *new_cell_storage;
[a46e56b]433 errno_t rc = async_share_out_finalize(chandle, &new_cell_storage);
[6d5e378]434 if ((rc != EOK) || (new_cell_storage == AS_MAP_FAILED)) {
[a46e56b]435 async_answer_0(icall_handle, ENOMEM);
[6d5e378]436 return;
437 }
[a35b458]438
[6d5e378]439 /* Change device internal state. */
440 rc = vs->ops.change_mode(vs, new_mode);
[a35b458]441
[6d5e378]442 /* Device driver could not establish new mode. Rollback. */
443 if (rc != EOK) {
444 as_area_destroy(new_cell_storage);
[a46e56b]445 async_answer_0(icall_handle, ENOMEM);
[6d5e378]446 return;
447 }
[a35b458]448
[df2e621c]449 /*
450 * Because resources for the new mode were successfully
451 * claimed, it is finally possible to free resources
452 * allocated for the old mode.
453 */
[6d5e378]454 if (vs->mode_set) {
455 if (vs->cells.data != NULL) {
456 as_area_destroy((void *) vs->cells.data);
457 vs->cells.data = NULL;
458 }
459 }
[a35b458]460
[6d5e378]461 /* Insert new mode into the visualizer. */
462 vs->cells.width = new_mode.screen_width;
463 vs->cells.height = new_mode.screen_height;
464 vs->cells.data = (pixel_t *) new_cell_storage;
465 vs->cur_mode = new_mode;
466 vs->mode_set = true;
[a35b458]467
[a46e56b]468 async_answer_0(icall_handle, EOK);
[6d5e378]469}
470
[a46e56b]471static void vs_update_damaged_region(visualizer_t *vs, cap_call_handle_t icall_handle, ipc_call_t *icall)
[6d5e378]472{
473 sysarg_t x_offset = (IPC_GET_ARG5(*icall) >> 16);
474 sysarg_t y_offset = (IPC_GET_ARG5(*icall) & 0x0000ffff);
[a35b458]475
[b7fd2a0]476 errno_t rc = vs->ops.handle_damage(vs,
[6d5e378]477 IPC_GET_ARG1(*icall), IPC_GET_ARG2(*icall),
478 IPC_GET_ARG3(*icall), IPC_GET_ARG4(*icall),
[df2e621c]479 x_offset, y_offset);
[a46e56b]480 async_answer_0(icall_handle, rc);
[6d5e378]481}
482
[a46e56b]483static void vs_suspend(visualizer_t *vs, cap_call_handle_t icall_handle, ipc_call_t *icall)
[6d5e378]484{
[b7fd2a0]485 errno_t rc = vs->ops.suspend(vs);
[a46e56b]486 async_answer_0(icall_handle, rc);
[6d5e378]487}
488
[a46e56b]489static void vs_wakeup(visualizer_t *vs, cap_call_handle_t icall_handle, ipc_call_t *icall)
[6d5e378]490{
[b7fd2a0]491 errno_t rc = vs->ops.wakeup(vs);
[a46e56b]492 async_answer_0(icall_handle, rc);
[6d5e378]493}
494
495void graph_visualizer_connection(visualizer_t *vs,
[a46e56b]496 cap_call_handle_t icall_handle, ipc_call_t *icall, void *arg)
[6d5e378]497{
498 ipc_call_t call;
[a46e56b]499 cap_call_handle_t chandle;
[a35b458]500
[6d5e378]501 /* Claim the visualizer. */
502 if (!cas(&vs->ref_cnt, 0, 1)) {
[a46e56b]503 async_answer_0(icall_handle, ELIMIT);
[6d5e378]504 return;
505 }
[a35b458]506
[6d5e378]507 /* Accept the connection. */
[a46e56b]508 async_answer_0(icall_handle, EOK);
[a35b458]509
[6d5e378]510 /* Establish callback session. */
[a46e56b]511 chandle = async_get_call(&call);
[6d5e378]512 vs->notif_sess = async_callback_receive_start(EXCHANGE_SERIALIZE, &call);
[df2e621c]513 if (vs->notif_sess != NULL)
[a46e56b]514 async_answer_0(chandle, EOK);
[df2e621c]515 else
[a46e56b]516 async_answer_0(chandle, ELIMIT);
[a35b458]517
[6d5e378]518 /* Enter command loop. */
519 while (true) {
[a46e56b]520 chandle = async_get_call(&call);
[a35b458]521
[6d5e378]522 if (!IPC_GET_IMETHOD(call)) {
[a46e56b]523 async_answer_0(chandle, EINVAL);
[6d5e378]524 break;
525 }
[a35b458]526
[6d5e378]527 switch (IPC_GET_IMETHOD(call)) {
528 case VISUALIZER_CLAIM:
[a46e56b]529 vs_claim(vs, chandle, &call);
[6d5e378]530 break;
531 case VISUALIZER_YIELD:
[a46e56b]532 vs_yield(vs, chandle, &call);
[6d5e378]533 goto terminate;
534 case VISUALIZER_ENUMERATE_MODES:
[a46e56b]535 vs_enumerate_modes(vs, chandle, &call);
[6d5e378]536 break;
537 case VISUALIZER_GET_DEFAULT_MODE:
[a46e56b]538 vs_get_default_mode(vs, chandle, &call);
[6d5e378]539 break;
540 case VISUALIZER_GET_CURRENT_MODE:
[a46e56b]541 vs_get_current_mode(vs, chandle, &call);
[6d5e378]542 break;
543 case VISUALIZER_GET_MODE:
[a46e56b]544 vs_get_mode(vs, chandle, &call);
[6d5e378]545 break;
546 case VISUALIZER_SET_MODE:
[a46e56b]547 vs_set_mode(vs, chandle, &call);
[6d5e378]548 break;
549 case VISUALIZER_UPDATE_DAMAGED_REGION:
[a46e56b]550 vs_update_damaged_region(vs, chandle, &call);
[6d5e378]551 break;
552 case VISUALIZER_SUSPEND:
[a46e56b]553 vs_suspend(vs, chandle, &call);
[6d5e378]554 break;
555 case VISUALIZER_WAKE_UP:
[a46e56b]556 vs_wakeup(vs, chandle, &call);
[6d5e378]557 break;
558 default:
[a46e56b]559 async_answer_0(chandle, EINVAL);
[6d5e378]560 goto terminate;
561 }
562 }
[a35b458]563
[6d5e378]564terminate:
565 async_hangup(vs->notif_sess);
566 vs->notif_sess = NULL;
567 atomic_set(&vs->ref_cnt, 0);
568}
569
570void graph_renderer_connection(renderer_t *rnd,
[a46e56b]571 cap_call_handle_t icall_handle, ipc_call_t *icall, void *arg)
[6d5e378]572{
573 // TODO
[a35b458]574
[6d5e378]575 ipc_call_t call;
[a46e56b]576 cap_call_handle_t chandle;
[a35b458]577
[6d5e378]578 /* Accept the connection. */
579 atomic_inc(&rnd->ref_cnt);
[a46e56b]580 async_answer_0(icall_handle, EOK);
[a35b458]581
[6d5e378]582 /* Enter command loop. */
583 while (true) {
[a46e56b]584 chandle = async_get_call(&call);
[a35b458]585
[6d5e378]586 if (!IPC_GET_IMETHOD(call)) {
[a46e56b]587 async_answer_0(chandle, EINVAL);
[6d5e378]588 break;
589 }
[a35b458]590
[6d5e378]591 switch (IPC_GET_IMETHOD(call)) {
592 default:
[a46e56b]593 async_answer_0(chandle, EINVAL);
[6d5e378]594 goto terminate;
595 }
596 }
[a35b458]597
[6d5e378]598terminate:
599 atomic_dec(&rnd->ref_cnt);
600}
601
[a46e56b]602void graph_client_connection(cap_call_handle_t icall_handle, ipc_call_t *icall, void *arg)
[6d5e378]603{
604 /* Find the visualizer or renderer with the given service ID. */
[f9b2cb4c]605 visualizer_t *vs = graph_get_visualizer(IPC_GET_ARG2(*icall));
606 renderer_t *rnd = graph_get_renderer(IPC_GET_ARG2(*icall));
[a35b458]607
[df2e621c]608 if (vs != NULL)
[a46e56b]609 graph_visualizer_connection(vs, icall_handle, icall, arg);
[df2e621c]610 else if (rnd != NULL)
[a46e56b]611 graph_renderer_connection(rnd, icall_handle, icall, arg);
[df2e621c]612 else
[a46e56b]613 async_answer_0(icall_handle, ENOENT);
[6d5e378]614}
615
616/** @}
617 */
Note: See TracBrowser for help on using the repository browser.