Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/hid/display/main.c

    r1762ceb r4c6fd56  
    11/*
    2  * Copyright (c) 2019 Jiri Svoboda
     2 * Copyright (c) 2023 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3636#include <async.h>
    3737#include <disp_srv.h>
     38#include <dispcfg_srv.h>
    3839#include <errno.h>
    3940#include <gfx/context.h>
     
    4748#include <stdio.h>
    4849#include <task.h>
     50#include <wndmgt_srv.h>
     51#include "cfgclient.h"
     52#include "cfgops.h"
    4953#include "client.h"
    5054#include "display.h"
     
    5559#include "seat.h"
    5660#include "window.h"
     61#include "wmclient.h"
     62#include "wmops.h"
    5763
    5864static void display_client_conn(ipc_call_t *, void *);
    5965static void display_client_ev_pending(void *);
     66static void display_wmclient_ev_pending(void *);
     67static void display_cfgclient_ev_pending(void *);
     68static void display_gc_conn(ipc_call_t *, void *);
     69static void display_wndmgt_conn(ipc_call_t *, void *);
     70static void display_dispcfg_conn(ipc_call_t *, void *);
    6071
    6172#ifdef CONFIG_DISP_DOUBLE_BUF
     
    7687};
    7788
     89static ds_wmclient_cb_t display_wmclient_cb = {
     90        .ev_pending = display_wmclient_ev_pending
     91};
     92
     93static ds_cfgclient_cb_t display_cfgclient_cb = {
     94        .ev_pending = display_cfgclient_ev_pending
     95};
     96
    7897static void display_client_ev_pending(void *arg)
    7998{
     
    81100
    82101        display_srv_ev_pending(srv);
     102}
     103
     104static void display_wmclient_ev_pending(void *arg)
     105{
     106        wndmgt_srv_t *srv = (wndmgt_srv_t *) arg;
     107
     108        wndmgt_srv_ev_pending(srv);
     109}
     110
     111static void display_cfgclient_ev_pending(void *arg)
     112{
     113        dispcfg_srv_t *srv = (dispcfg_srv_t *) arg;
     114
     115        dispcfg_srv_ev_pending(srv);
    83116}
    84117
     
    90123        ds_output_t *output = NULL;
    91124        gfx_context_t *gc = NULL;
     125        port_id_t disp_port;
     126        port_id_t gc_port;
     127        port_id_t wm_port;
     128        port_id_t dc_port;
     129        loc_srv_t *srv = NULL;
     130        service_id_t sid = 0;
    92131        errno_t rc;
    93132
     
    98137                goto error;
    99138
    100         rc = ds_seat_create(disp, &seat);
     139        rc = ds_seat_create(disp, "Alice", &seat);
    101140        if (rc != EOK)
    102141                goto error;
     
    115154                goto error;
    116155
    117         async_set_fallback_port_handler(display_client_conn, disp);
    118 
    119         rc = loc_server_register(NAME);
     156        rc = async_create_port(INTERFACE_DISPLAY, display_client_conn, disp,
     157            &disp_port);
     158        if (rc != EOK)
     159                goto error;
     160
     161        rc = async_create_port(INTERFACE_GC, display_gc_conn, disp, &gc_port);
     162        if (rc != EOK)
     163                goto error;
     164
     165        rc = async_create_port(INTERFACE_WNDMGT, display_wndmgt_conn, disp,
     166            &wm_port);
     167        if (rc != EOK)
     168                goto error;
     169
     170        rc = async_create_port(INTERFACE_DISPCFG, display_dispcfg_conn, disp,
     171            &dc_port);
     172        if (rc != EOK)
     173                goto error;
     174
     175        rc = loc_server_register(NAME, &srv);
    120176        if (rc != EOK) {
    121177                log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering server: %s.", str_error(rc));
     
    124180        }
    125181
    126         service_id_t sid;
    127         rc = loc_service_register(SERVICE_NAME_DISPLAY, &sid);
     182        rc = loc_service_register(srv, SERVICE_NAME_DISPLAY, &sid);
    128183        if (rc != EOK) {
    129184                log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering service: %s.", str_error(rc));
     
    135190        return EOK;
    136191error:
     192        if (sid != 0)
     193                loc_service_unregister(srv, sid);
     194        if (srv != NULL)
     195                loc_server_unregister(srv);
     196        // XXX destroy disp_port
     197        // XXX destroy gc_port
     198        // XXX destroy wm_port
     199        // XXX destroy dc_port
    137200#if 0
    138201        if (disp->input != NULL)
     
    154217{
    155218        display_srv_t srv;
    156         sysarg_t wnd_id;
    157219        sysarg_t svc_id;
    158220        ds_client_t *client = NULL;
    159         ds_window_t *wnd;
    160221        ds_display_t *disp = (ds_display_t *) arg;
    161         gfx_context_t *gc;
    162222        errno_t rc;
    163223
     
    166226            ipc_get_arg4(icall));
    167227
    168         (void) icall;
    169         (void) arg;
    170 
    171228        svc_id = ipc_get_arg2(icall);
    172         wnd_id = ipc_get_arg3(icall);
    173229
    174230        if (svc_id != 0) {
    175231                /* Create client object */
     232                ds_display_lock(disp);
    176233                rc = ds_client_create(disp, &display_client_cb, &srv, &client);
     234                ds_display_unlock(disp);
    177235                if (rc != EOK) {
    178236                        async_answer_0(icall, ENOMEM);
     
    191249                ds_client_destroy(client);
    192250                ds_display_unlock(disp);
    193         } else {
    194                 /* Window GC connection */
    195 
    196                 wnd = ds_display_find_window(disp, wnd_id);
    197                 if (wnd == NULL) {
    198                         async_answer_0(icall, ENOENT);
    199                         return;
    200                 }
    201 
    202                 /*
    203                  * XXX We need a way to make sure that the connection does
    204                  * not stay active after the window had been destroyed
    205                  */
    206                 gc = ds_window_get_ctx(wnd);
    207                 gc_conn(icall, gc);
    208         }
     251        }
     252}
     253
     254/** Handle GC connection to display server */
     255static void display_gc_conn(ipc_call_t *icall, void *arg)
     256{
     257        sysarg_t wnd_id;
     258        ds_window_t *wnd;
     259        ds_display_t *disp = (ds_display_t *) arg;
     260        gfx_context_t *gc;
     261
     262        log_msg(LOG_DEFAULT, LVL_DEBUG, "display_gc_conn arg1=%zu arg2=%zu arg3=%zu arg4=%zu.",
     263            ipc_get_arg1(icall), ipc_get_arg2(icall), ipc_get_arg3(icall),
     264            ipc_get_arg4(icall));
     265
     266        wnd_id = ipc_get_arg3(icall);
     267
     268        /* Window GC connection */
     269
     270        wnd = ds_display_find_window(disp, wnd_id);
     271        if (wnd == NULL) {
     272                async_answer_0(icall, ENOENT);
     273                return;
     274        }
     275
     276        /*
     277         * XXX We need a way to make sure that the connection does
     278         * not stay active after the window had been destroyed
     279         */
     280        gc = ds_window_get_ctx(wnd);
     281        gc_conn(icall, gc);
     282}
     283
     284/** Handle window management connection to display server */
     285static void display_wndmgt_conn(ipc_call_t *icall, void *arg)
     286{
     287        ds_display_t *disp = (ds_display_t *) arg;
     288        errno_t rc;
     289        wndmgt_srv_t srv;
     290        ds_wmclient_t *wmclient = NULL;
     291
     292        /* Create WM client object */
     293        ds_display_lock(disp);
     294        rc = ds_wmclient_create(disp, &display_wmclient_cb, &srv, &wmclient);
     295        ds_display_unlock(disp);
     296        if (rc != EOK) {
     297                async_answer_0(icall, ENOMEM);
     298                return;
     299        }
     300
     301        /* Set up protocol structure */
     302        wndmgt_srv_initialize(&srv);
     303        srv.ops = &wndmgt_srv_ops;
     304        srv.arg = wmclient;
     305
     306        /* Handle connection */
     307        wndmgt_conn(icall, &srv);
     308
     309        ds_display_lock(disp);
     310        ds_wmclient_destroy(wmclient);
     311        ds_display_unlock(disp);
     312}
     313
     314/** Handle configuration connection to display server */
     315static void display_dispcfg_conn(ipc_call_t *icall, void *arg)
     316{
     317        ds_display_t *disp = (ds_display_t *) arg;
     318        errno_t rc;
     319        dispcfg_srv_t srv;
     320        ds_cfgclient_t *cfgclient = NULL;
     321
     322        /* Create CFG client object */
     323        ds_display_lock(disp);
     324        rc = ds_cfgclient_create(disp, &display_cfgclient_cb, &srv, &cfgclient);
     325        ds_display_unlock(disp);
     326        if (rc != EOK) {
     327                async_answer_0(icall, ENOMEM);
     328                return;
     329        }
     330
     331        /* Set up protocol structure */
     332        dispcfg_srv_initialize(&srv);
     333        srv.ops = &dispcfg_srv_ops;
     334        srv.arg = cfgclient;
     335
     336        /* Handle connection */
     337        dispcfg_conn(icall, &srv);
     338
     339        ds_display_lock(disp);
     340        ds_cfgclient_destroy(cfgclient);
     341        ds_display_unlock(disp);
    209342}
    210343
Note: See TracChangeset for help on using the changeset viewer.