[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 |
|
---|
| 48 | static sysarg_t namespace_idx = 0;
|
---|
| 49 | static sysarg_t visualizer_idx = 0;
|
---|
| 50 | static sysarg_t renderer_idx = 0;
|
---|
| 51 |
|
---|
| 52 | static LIST_INITIALIZE(visualizer_list);
|
---|
| 53 | static LIST_INITIALIZE(renderer_list);
|
---|
| 54 |
|
---|
| 55 | static FIBRIL_MUTEX_INITIALIZE(visualizer_list_mtx);
|
---|
| 56 | static FIBRIL_MUTEX_INITIALIZE(renderer_list_mtx);
|
---|
| 57 |
|
---|
| 58 | visualizer_t *graph_alloc_visualizer(void)
|
---|
| 59 | {
|
---|
[df2e621c] | 60 | return ((visualizer_t *) malloc(sizeof(visualizer_t)));
|
---|
[6d5e378] | 61 | }
|
---|
| 62 |
|
---|
| 63 | renderer_t *graph_alloc_renderer(void)
|
---|
| 64 | {
|
---|
| 65 | // TODO
|
---|
[df2e621c] | 66 | return ((renderer_t *) malloc(sizeof(renderer_t)));
|
---|
[6d5e378] | 67 | }
|
---|
| 68 |
|
---|
| 69 | void graph_init_visualizer(visualizer_t *vs)
|
---|
| 70 | {
|
---|
| 71 | link_initialize(&vs->link);
|
---|
[508b0df1] | 72 | atomic_flag_clear(&vs->claimed);
|
---|
[6d5e378] | 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 |
|
---|
| 81 | void graph_init_renderer(renderer_t *rnd)
|
---|
| 82 | {
|
---|
| 83 | // TODO
|
---|
| 84 | link_initialize(&rnd->link);
|
---|
[508b0df1] | 85 | refcount_init(&rnd->ref_cnt);
|
---|
[6d5e378] | 86 | }
|
---|
| 87 |
|
---|
[b7fd2a0] | 88 | errno_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] | 116 | errno_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 |
|
---|
| 144 | visualizer_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 |
|
---|
| 162 | renderer_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 |
|
---|
[508b0df1] | 175 | if (rnd)
|
---|
| 176 | refcount_up(&rnd->ref_cnt);
|
---|
| 177 |
|
---|
[6d5e378] | 178 | fibril_mutex_unlock(&renderer_list_mtx);
|
---|
[a35b458] | 179 |
|
---|
[6d5e378] | 180 | return rnd;
|
---|
| 181 | }
|
---|
| 182 |
|
---|
[b7fd2a0] | 183 | errno_t graph_unregister_visualizer(visualizer_t *vs)
|
---|
[6d5e378] | 184 | {
|
---|
| 185 | fibril_mutex_lock(&visualizer_list_mtx);
|
---|
[b7fd2a0] | 186 | errno_t rc = loc_service_unregister(vs->reg_svc_handle);
|
---|
[6d5e378] | 187 | list_remove(&vs->link);
|
---|
| 188 | fibril_mutex_unlock(&visualizer_list_mtx);
|
---|
[a35b458] | 189 |
|
---|
[6d5e378] | 190 | return rc;
|
---|
| 191 | }
|
---|
| 192 |
|
---|
[b7fd2a0] | 193 | errno_t graph_unregister_renderer(renderer_t *rnd)
|
---|
[6d5e378] | 194 | {
|
---|
| 195 | fibril_mutex_lock(&renderer_list_mtx);
|
---|
[b7fd2a0] | 196 | errno_t rc = loc_service_unregister(rnd->reg_svc_handle);
|
---|
[6d5e378] | 197 | list_remove(&rnd->link);
|
---|
| 198 | fibril_mutex_unlock(&renderer_list_mtx);
|
---|
[a35b458] | 199 |
|
---|
[6d5e378] | 200 | return rc;
|
---|
| 201 | }
|
---|
| 202 |
|
---|
| 203 | void graph_destroy_visualizer(visualizer_t *vs)
|
---|
| 204 | {
|
---|
[508b0df1] | 205 | assert(!atomic_flag_test_and_set(&vs->claimed));
|
---|
[6d5e378] | 206 | assert(vs->notif_sess == NULL);
|
---|
| 207 | assert(!fibril_mutex_is_locked(&vs->mode_mtx));
|
---|
| 208 | assert(list_empty(&vs->modes));
|
---|
| 209 | assert(vs->mode_set == false);
|
---|
| 210 | assert(vs->cells.data == NULL);
|
---|
| 211 | assert(vs->dev_ctx == NULL);
|
---|
[a35b458] | 212 |
|
---|
[6d5e378] | 213 | free(vs);
|
---|
| 214 | }
|
---|
| 215 |
|
---|
| 216 | void graph_destroy_renderer(renderer_t *rnd)
|
---|
| 217 | {
|
---|
| 218 | // TODO
|
---|
[508b0df1] | 219 | if (refcount_down(&rnd->ref_cnt))
|
---|
| 220 | free(rnd);
|
---|
[6d5e378] | 221 | }
|
---|
| 222 |
|
---|
[b7fd2a0] | 223 | errno_t graph_notify_mode_change(async_sess_t *sess, sysarg_t handle, sysarg_t mode_idx)
|
---|
[6d5e378] | 224 | {
|
---|
| 225 | async_exch_t *exch = async_exchange_begin(sess);
|
---|
[b7fd2a0] | 226 | errno_t ret = async_req_2_0(exch, VISUALIZER_MODE_CHANGE, handle, mode_idx);
|
---|
[6d5e378] | 227 | async_exchange_end(exch);
|
---|
[a35b458] | 228 |
|
---|
[6d5e378] | 229 | return ret;
|
---|
| 230 | }
|
---|
| 231 |
|
---|
[b7fd2a0] | 232 | errno_t graph_notify_disconnect(async_sess_t *sess, sysarg_t handle)
|
---|
[6d5e378] | 233 | {
|
---|
| 234 | async_exch_t *exch = async_exchange_begin(sess);
|
---|
[b7fd2a0] | 235 | errno_t ret = async_req_1_0(exch, VISUALIZER_DISCONNECT, handle);
|
---|
[6d5e378] | 236 | async_exchange_end(exch);
|
---|
[a35b458] | 237 |
|
---|
[6d5e378] | 238 | async_hangup(sess);
|
---|
[a35b458] | 239 |
|
---|
[6d5e378] | 240 | return ret;
|
---|
| 241 | }
|
---|
| 242 |
|
---|
[984a9ba] | 243 | static void vs_claim(visualizer_t *vs, ipc_call_t *icall)
|
---|
[6d5e378] | 244 | {
|
---|
| 245 | vs->client_side_handle = IPC_GET_ARG1(*icall);
|
---|
[b7fd2a0] | 246 | errno_t rc = vs->ops.claim(vs);
|
---|
[984a9ba] | 247 | async_answer_0(icall, rc);
|
---|
[6d5e378] | 248 | }
|
---|
| 249 |
|
---|
[984a9ba] | 250 | static void vs_yield(visualizer_t *vs, ipc_call_t *icall)
|
---|
[6d5e378] | 251 | {
|
---|
| 252 | /* Deallocate resources for the current mode. */
|
---|
| 253 | if (vs->mode_set) {
|
---|
| 254 | if (vs->cells.data != NULL) {
|
---|
| 255 | as_area_destroy((void *) vs->cells.data);
|
---|
| 256 | vs->cells.data = NULL;
|
---|
| 257 | }
|
---|
| 258 | }
|
---|
[a35b458] | 259 |
|
---|
[6d5e378] | 260 | /* Driver might also deallocate resources for the current mode. */
|
---|
[b7fd2a0] | 261 | errno_t rc = vs->ops.yield(vs);
|
---|
[a35b458] | 262 |
|
---|
[7c3fb9b] | 263 | /*
|
---|
| 264 | * Now that the driver was given a chance to deallocate resources,
|
---|
| 265 | * current mode can be unset.
|
---|
| 266 | */
|
---|
[df2e621c] | 267 | if (vs->mode_set)
|
---|
[6d5e378] | 268 | vs->mode_set = false;
|
---|
[a35b458] | 269 |
|
---|
[984a9ba] | 270 | async_answer_0(icall, rc);
|
---|
[6d5e378] | 271 | }
|
---|
| 272 |
|
---|
[984a9ba] | 273 | static void vs_enumerate_modes(visualizer_t *vs, ipc_call_t *icall)
|
---|
[6d5e378] | 274 | {
|
---|
[df2e621c] | 275 | size_t len;
|
---|
[a35b458] | 276 |
|
---|
[984a9ba] | 277 | ipc_call_t call;
|
---|
| 278 | if (!async_data_read_receive(&call, &len)) {
|
---|
| 279 | async_answer_0(&call, EREFUSED);
|
---|
| 280 | async_answer_0(icall, EREFUSED);
|
---|
[df2e621c] | 281 | return;
|
---|
| 282 | }
|
---|
[a35b458] | 283 |
|
---|
[6d5e378] | 284 | fibril_mutex_lock(&vs->mode_mtx);
|
---|
| 285 | link_t *link = list_nth(&vs->modes, IPC_GET_ARG1(*icall));
|
---|
[a35b458] | 286 |
|
---|
[6d5e378] | 287 | if (link != NULL) {
|
---|
| 288 | vslmode_list_element_t *mode_elem =
|
---|
| 289 | list_get_instance(link, vslmode_list_element_t, link);
|
---|
[a35b458] | 290 |
|
---|
[984a9ba] | 291 | errno_t rc = async_data_read_finalize(&call, &mode_elem->mode, len);
|
---|
| 292 | async_answer_0(icall, rc);
|
---|
[6d5e378] | 293 | } else {
|
---|
[984a9ba] | 294 | async_answer_0(&call, ENOENT);
|
---|
| 295 | async_answer_0(icall, ENOENT);
|
---|
[6d5e378] | 296 | }
|
---|
[a35b458] | 297 |
|
---|
[df2e621c] | 298 | fibril_mutex_unlock(&vs->mode_mtx);
|
---|
[6d5e378] | 299 | }
|
---|
| 300 |
|
---|
[984a9ba] | 301 | static void vs_get_default_mode(visualizer_t *vs, ipc_call_t *icall)
|
---|
[6d5e378] | 302 | {
|
---|
[984a9ba] | 303 | ipc_call_t call;
|
---|
[df2e621c] | 304 | size_t len;
|
---|
[984a9ba] | 305 | if (!async_data_read_receive(&call, &len)) {
|
---|
| 306 | async_answer_0(&call, EREFUSED);
|
---|
| 307 | async_answer_0(icall, EREFUSED);
|
---|
[df2e621c] | 308 | return;
|
---|
| 309 | }
|
---|
[a35b458] | 310 |
|
---|
[6d5e378] | 311 | fibril_mutex_lock(&vs->mode_mtx);
|
---|
| 312 | vslmode_list_element_t *mode_elem = NULL;
|
---|
[a35b458] | 313 |
|
---|
[feeac0d] | 314 | list_foreach(vs->modes, link, vslmode_list_element_t, cur) {
|
---|
[6d5e378] | 315 | if (cur->mode.index == vs->def_mode_idx) {
|
---|
| 316 | mode_elem = cur;
|
---|
| 317 | break;
|
---|
| 318 | }
|
---|
| 319 | }
|
---|
[a35b458] | 320 |
|
---|
[6d5e378] | 321 | if (mode_elem != NULL) {
|
---|
[984a9ba] | 322 | errno_t rc = async_data_read_finalize(&call, &mode_elem->mode, len);
|
---|
| 323 | async_answer_0(icall, rc);
|
---|
[6d5e378] | 324 | } else {
|
---|
| 325 | fibril_mutex_unlock(&vs->mode_mtx);
|
---|
[984a9ba] | 326 | async_answer_0(&call, ENOENT);
|
---|
| 327 | async_answer_0(icall, ENOENT);
|
---|
[6d5e378] | 328 | }
|
---|
[a35b458] | 329 |
|
---|
[df2e621c] | 330 | fibril_mutex_unlock(&vs->mode_mtx);
|
---|
[6d5e378] | 331 | }
|
---|
| 332 |
|
---|
[984a9ba] | 333 | static void vs_get_current_mode(visualizer_t *vs, ipc_call_t *icall)
|
---|
[6d5e378] | 334 | {
|
---|
[984a9ba] | 335 | ipc_call_t call;
|
---|
[df2e621c] | 336 | size_t len;
|
---|
[984a9ba] | 337 | if (!async_data_read_receive(&call, &len)) {
|
---|
| 338 | async_answer_0(&call, EREFUSED);
|
---|
| 339 | async_answer_0(icall, EREFUSED);
|
---|
[df2e621c] | 340 | return;
|
---|
| 341 | }
|
---|
[a35b458] | 342 |
|
---|
[6d5e378] | 343 | if (vs->mode_set) {
|
---|
[984a9ba] | 344 | errno_t rc = async_data_read_finalize(&call, &vs->cur_mode, len);
|
---|
| 345 | async_answer_0(icall, rc);
|
---|
[6d5e378] | 346 | } else {
|
---|
[984a9ba] | 347 | async_answer_0(&call, ENOENT);
|
---|
| 348 | async_answer_0(icall, ENOENT);
|
---|
[6d5e378] | 349 | }
|
---|
| 350 | }
|
---|
| 351 |
|
---|
[984a9ba] | 352 | static void vs_get_mode(visualizer_t *vs, ipc_call_t *icall)
|
---|
[6d5e378] | 353 | {
|
---|
[984a9ba] | 354 | ipc_call_t call;
|
---|
[df2e621c] | 355 | size_t len;
|
---|
[984a9ba] | 356 | if (!async_data_read_receive(&call, &len)) {
|
---|
| 357 | async_answer_0(&call, EREFUSED);
|
---|
| 358 | async_answer_0(icall, EREFUSED);
|
---|
[df2e621c] | 359 | return;
|
---|
| 360 | }
|
---|
[a35b458] | 361 |
|
---|
[6d5e378] | 362 | sysarg_t mode_idx = IPC_GET_ARG1(*icall);
|
---|
[a35b458] | 363 |
|
---|
[6d5e378] | 364 | fibril_mutex_lock(&vs->mode_mtx);
|
---|
| 365 | vslmode_list_element_t *mode_elem = NULL;
|
---|
[a35b458] | 366 |
|
---|
[feeac0d] | 367 | list_foreach(vs->modes, link, vslmode_list_element_t, cur) {
|
---|
[6d5e378] | 368 | if (cur->mode.index == mode_idx) {
|
---|
| 369 | mode_elem = cur;
|
---|
| 370 | break;
|
---|
| 371 | }
|
---|
| 372 | }
|
---|
[a35b458] | 373 |
|
---|
[6d5e378] | 374 | if (mode_elem != NULL) {
|
---|
[984a9ba] | 375 | errno_t rc = async_data_read_finalize(&call, &mode_elem->mode, len);
|
---|
| 376 | async_answer_0(icall, rc);
|
---|
[6d5e378] | 377 | } else {
|
---|
[984a9ba] | 378 | async_answer_0(&call, ENOENT);
|
---|
| 379 | async_answer_0(icall, ENOENT);
|
---|
[6d5e378] | 380 | }
|
---|
[a35b458] | 381 |
|
---|
[df2e621c] | 382 | fibril_mutex_unlock(&vs->mode_mtx);
|
---|
[6d5e378] | 383 | }
|
---|
| 384 |
|
---|
[984a9ba] | 385 | static void vs_set_mode(visualizer_t *vs, ipc_call_t *icall)
|
---|
[6d5e378] | 386 | {
|
---|
[984a9ba] | 387 | ipc_call_t call;
|
---|
[df2e621c] | 388 | size_t size;
|
---|
| 389 | unsigned int flags;
|
---|
[a35b458] | 390 |
|
---|
[df2e621c] | 391 | /* Retrieve the shared cell storage for the new mode. */
|
---|
[984a9ba] | 392 | if (!async_share_out_receive(&call, &size, &flags)) {
|
---|
| 393 | async_answer_0(&call, EREFUSED);
|
---|
| 394 | async_answer_0(icall, EREFUSED);
|
---|
[df2e621c] | 395 | return;
|
---|
| 396 | }
|
---|
[a35b458] | 397 |
|
---|
[6d5e378] | 398 | /* Retrieve mode index and version. */
|
---|
| 399 | sysarg_t mode_idx = IPC_GET_ARG1(*icall);
|
---|
| 400 | sysarg_t mode_version = IPC_GET_ARG2(*icall);
|
---|
[a35b458] | 401 |
|
---|
[6d5e378] | 402 | /* Find mode in the list. */
|
---|
| 403 | fibril_mutex_lock(&vs->mode_mtx);
|
---|
| 404 | vslmode_list_element_t *mode_elem = NULL;
|
---|
[a35b458] | 405 |
|
---|
[feeac0d] | 406 | list_foreach(vs->modes, link, vslmode_list_element_t, cur) {
|
---|
[6d5e378] | 407 | if (cur->mode.index == mode_idx) {
|
---|
| 408 | mode_elem = cur;
|
---|
| 409 | break;
|
---|
| 410 | }
|
---|
| 411 | }
|
---|
[a35b458] | 412 |
|
---|
[df2e621c] | 413 | if (mode_elem == NULL) {
|
---|
[6d5e378] | 414 | fibril_mutex_unlock(&vs->mode_mtx);
|
---|
[984a9ba] | 415 | async_answer_0(&call, ENOENT);
|
---|
| 416 | async_answer_0(icall, ENOENT);
|
---|
[6d5e378] | 417 | return;
|
---|
| 418 | }
|
---|
[a35b458] | 419 |
|
---|
[df2e621c] | 420 | /* Extract mode description from the list node. */
|
---|
| 421 | vslmode_t new_mode = mode_elem->mode;
|
---|
| 422 | fibril_mutex_unlock(&vs->mode_mtx);
|
---|
[a35b458] | 423 |
|
---|
[6d5e378] | 424 | /* Check whether the mode is still up-to-date. */
|
---|
| 425 | if (new_mode.version != mode_version) {
|
---|
[984a9ba] | 426 | async_answer_0(&call, EINVAL);
|
---|
| 427 | async_answer_0(icall, EINVAL);
|
---|
[6d5e378] | 428 | return;
|
---|
| 429 | }
|
---|
[a35b458] | 430 |
|
---|
[6d5e378] | 431 | void *new_cell_storage;
|
---|
[984a9ba] | 432 | errno_t rc = async_share_out_finalize(&call, &new_cell_storage);
|
---|
[6d5e378] | 433 | if ((rc != EOK) || (new_cell_storage == AS_MAP_FAILED)) {
|
---|
[984a9ba] | 434 | async_answer_0(icall, ENOMEM);
|
---|
[6d5e378] | 435 | return;
|
---|
| 436 | }
|
---|
[a35b458] | 437 |
|
---|
[6d5e378] | 438 | /* Change device internal state. */
|
---|
| 439 | rc = vs->ops.change_mode(vs, new_mode);
|
---|
[a35b458] | 440 |
|
---|
[6d5e378] | 441 | /* Device driver could not establish new mode. Rollback. */
|
---|
| 442 | if (rc != EOK) {
|
---|
| 443 | as_area_destroy(new_cell_storage);
|
---|
[984a9ba] | 444 | async_answer_0(icall, ENOMEM);
|
---|
[6d5e378] | 445 | return;
|
---|
| 446 | }
|
---|
[a35b458] | 447 |
|
---|
[df2e621c] | 448 | /*
|
---|
| 449 | * Because resources for the new mode were successfully
|
---|
| 450 | * claimed, it is finally possible to free resources
|
---|
| 451 | * allocated for the old mode.
|
---|
| 452 | */
|
---|
[6d5e378] | 453 | if (vs->mode_set) {
|
---|
| 454 | if (vs->cells.data != NULL) {
|
---|
| 455 | as_area_destroy((void *) vs->cells.data);
|
---|
| 456 | vs->cells.data = NULL;
|
---|
| 457 | }
|
---|
| 458 | }
|
---|
[a35b458] | 459 |
|
---|
[6d5e378] | 460 | /* Insert new mode into the visualizer. */
|
---|
| 461 | vs->cells.width = new_mode.screen_width;
|
---|
| 462 | vs->cells.height = new_mode.screen_height;
|
---|
| 463 | vs->cells.data = (pixel_t *) new_cell_storage;
|
---|
| 464 | vs->cur_mode = new_mode;
|
---|
| 465 | vs->mode_set = true;
|
---|
[a35b458] | 466 |
|
---|
[984a9ba] | 467 | async_answer_0(icall, EOK);
|
---|
[6d5e378] | 468 | }
|
---|
| 469 |
|
---|
[984a9ba] | 470 | static void vs_update_damaged_region(visualizer_t *vs, ipc_call_t *icall)
|
---|
[6d5e378] | 471 | {
|
---|
| 472 | sysarg_t x_offset = (IPC_GET_ARG5(*icall) >> 16);
|
---|
| 473 | sysarg_t y_offset = (IPC_GET_ARG5(*icall) & 0x0000ffff);
|
---|
[a35b458] | 474 |
|
---|
[b7fd2a0] | 475 | errno_t rc = vs->ops.handle_damage(vs,
|
---|
[6d5e378] | 476 | IPC_GET_ARG1(*icall), IPC_GET_ARG2(*icall),
|
---|
| 477 | IPC_GET_ARG3(*icall), IPC_GET_ARG4(*icall),
|
---|
[df2e621c] | 478 | x_offset, y_offset);
|
---|
[984a9ba] | 479 | async_answer_0(icall, rc);
|
---|
[6d5e378] | 480 | }
|
---|
| 481 |
|
---|
[984a9ba] | 482 | static void vs_suspend(visualizer_t *vs, ipc_call_t *icall)
|
---|
[6d5e378] | 483 | {
|
---|
[b7fd2a0] | 484 | errno_t rc = vs->ops.suspend(vs);
|
---|
[984a9ba] | 485 | async_answer_0(icall, rc);
|
---|
[6d5e378] | 486 | }
|
---|
| 487 |
|
---|
[984a9ba] | 488 | static void vs_wakeup(visualizer_t *vs, ipc_call_t *icall)
|
---|
[6d5e378] | 489 | {
|
---|
[b7fd2a0] | 490 | errno_t rc = vs->ops.wakeup(vs);
|
---|
[984a9ba] | 491 | async_answer_0(icall, rc);
|
---|
[6d5e378] | 492 | }
|
---|
| 493 |
|
---|
[984a9ba] | 494 | void graph_visualizer_connection(visualizer_t *vs, ipc_call_t *icall, void *arg)
|
---|
[6d5e378] | 495 | {
|
---|
| 496 | /* Claim the visualizer. */
|
---|
[508b0df1] | 497 | if (atomic_flag_test_and_set(&vs->claimed)) {
|
---|
[984a9ba] | 498 | async_answer_0(icall, ELIMIT);
|
---|
[6d5e378] | 499 | return;
|
---|
| 500 | }
|
---|
[a35b458] | 501 |
|
---|
[6d5e378] | 502 | /* Accept the connection. */
|
---|
[f5837524] | 503 | async_answer_5(icall, EOK, 0, 0, 0, 0, async_get_label());
|
---|
[a35b458] | 504 |
|
---|
[6d5e378] | 505 | /* Establish callback session. */
|
---|
[984a9ba] | 506 | ipc_call_t call;
|
---|
| 507 | async_get_call(&call);
|
---|
[6d5e378] | 508 | vs->notif_sess = async_callback_receive_start(EXCHANGE_SERIALIZE, &call);
|
---|
[df2e621c] | 509 | if (vs->notif_sess != NULL)
|
---|
[984a9ba] | 510 | async_answer_0(&call, EOK);
|
---|
[df2e621c] | 511 | else
|
---|
[984a9ba] | 512 | async_answer_0(&call, ELIMIT);
|
---|
[a35b458] | 513 |
|
---|
[6d5e378] | 514 | /* Enter command loop. */
|
---|
| 515 | while (true) {
|
---|
[984a9ba] | 516 | async_get_call(&call);
|
---|
[a35b458] | 517 |
|
---|
[6d5e378] | 518 | if (!IPC_GET_IMETHOD(call)) {
|
---|
[889cdb1] | 519 | async_answer_0(&call, EOK);
|
---|
[6d5e378] | 520 | break;
|
---|
| 521 | }
|
---|
[a35b458] | 522 |
|
---|
[6d5e378] | 523 | switch (IPC_GET_IMETHOD(call)) {
|
---|
| 524 | case VISUALIZER_CLAIM:
|
---|
[984a9ba] | 525 | vs_claim(vs, &call);
|
---|
[6d5e378] | 526 | break;
|
---|
| 527 | case VISUALIZER_YIELD:
|
---|
[984a9ba] | 528 | vs_yield(vs, &call);
|
---|
[6d5e378] | 529 | goto terminate;
|
---|
| 530 | case VISUALIZER_ENUMERATE_MODES:
|
---|
[984a9ba] | 531 | vs_enumerate_modes(vs, &call);
|
---|
[6d5e378] | 532 | break;
|
---|
| 533 | case VISUALIZER_GET_DEFAULT_MODE:
|
---|
[984a9ba] | 534 | vs_get_default_mode(vs, &call);
|
---|
[6d5e378] | 535 | break;
|
---|
| 536 | case VISUALIZER_GET_CURRENT_MODE:
|
---|
[984a9ba] | 537 | vs_get_current_mode(vs, &call);
|
---|
[6d5e378] | 538 | break;
|
---|
| 539 | case VISUALIZER_GET_MODE:
|
---|
[984a9ba] | 540 | vs_get_mode(vs, &call);
|
---|
[6d5e378] | 541 | break;
|
---|
| 542 | case VISUALIZER_SET_MODE:
|
---|
[984a9ba] | 543 | vs_set_mode(vs, &call);
|
---|
[6d5e378] | 544 | break;
|
---|
| 545 | case VISUALIZER_UPDATE_DAMAGED_REGION:
|
---|
[984a9ba] | 546 | vs_update_damaged_region(vs, &call);
|
---|
[6d5e378] | 547 | break;
|
---|
| 548 | case VISUALIZER_SUSPEND:
|
---|
[984a9ba] | 549 | vs_suspend(vs, &call);
|
---|
[6d5e378] | 550 | break;
|
---|
| 551 | case VISUALIZER_WAKE_UP:
|
---|
[984a9ba] | 552 | vs_wakeup(vs, &call);
|
---|
[6d5e378] | 553 | break;
|
---|
| 554 | default:
|
---|
[984a9ba] | 555 | async_answer_0(&call, EINVAL);
|
---|
[6d5e378] | 556 | goto terminate;
|
---|
| 557 | }
|
---|
| 558 | }
|
---|
[a35b458] | 559 |
|
---|
[6d5e378] | 560 | terminate:
|
---|
| 561 | async_hangup(vs->notif_sess);
|
---|
| 562 | vs->notif_sess = NULL;
|
---|
[508b0df1] | 563 | atomic_flag_clear(&vs->claimed);
|
---|
[6d5e378] | 564 | }
|
---|
| 565 |
|
---|
[984a9ba] | 566 | void graph_renderer_connection(renderer_t *rnd, ipc_call_t *icall, void *arg)
|
---|
[6d5e378] | 567 | {
|
---|
| 568 | // TODO
|
---|
[a35b458] | 569 |
|
---|
[6d5e378] | 570 | /* Accept the connection. */
|
---|
[f5837524] | 571 | async_answer_5(icall, EOK, 0, 0, 0, 0, async_get_label());
|
---|
[a35b458] | 572 |
|
---|
[6d5e378] | 573 | /* Enter command loop. */
|
---|
| 574 | while (true) {
|
---|
[984a9ba] | 575 | ipc_call_t call;
|
---|
| 576 | async_get_call(&call);
|
---|
[a35b458] | 577 |
|
---|
[6d5e378] | 578 | if (!IPC_GET_IMETHOD(call)) {
|
---|
[889cdb1] | 579 | async_answer_0(&call, EOK);
|
---|
[6d5e378] | 580 | break;
|
---|
| 581 | }
|
---|
[a35b458] | 582 |
|
---|
[6d5e378] | 583 | switch (IPC_GET_IMETHOD(call)) {
|
---|
| 584 | default:
|
---|
[984a9ba] | 585 | async_answer_0(&call, EINVAL);
|
---|
[6d5e378] | 586 | goto terminate;
|
---|
| 587 | }
|
---|
| 588 | }
|
---|
[a35b458] | 589 |
|
---|
[6d5e378] | 590 | terminate:
|
---|
[508b0df1] | 591 | graph_destroy_renderer(rnd);
|
---|
[6d5e378] | 592 | }
|
---|
| 593 |
|
---|
[984a9ba] | 594 | void graph_client_connection(ipc_call_t *icall, void *arg)
|
---|
[6d5e378] | 595 | {
|
---|
| 596 | /* Find the visualizer or renderer with the given service ID. */
|
---|
[f9b2cb4c] | 597 | visualizer_t *vs = graph_get_visualizer(IPC_GET_ARG2(*icall));
|
---|
| 598 | renderer_t *rnd = graph_get_renderer(IPC_GET_ARG2(*icall));
|
---|
[a35b458] | 599 |
|
---|
[df2e621c] | 600 | if (vs != NULL)
|
---|
[984a9ba] | 601 | graph_visualizer_connection(vs, icall, arg);
|
---|
[df2e621c] | 602 | else if (rnd != NULL)
|
---|
[984a9ba] | 603 | graph_renderer_connection(rnd, icall, arg);
|
---|
[df2e621c] | 604 | else
|
---|
[984a9ba] | 605 | async_answer_0(icall, ENOENT);
|
---|
[6d5e378] | 606 | }
|
---|
| 607 |
|
---|
| 608 | /** @}
|
---|
| 609 | */
|
---|