Changeset 6af4b4f in mainline for uspace/srv/hid/display/display.c


Ignore:
Timestamp:
2019-10-05T08:45:25Z (6 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
bef51cf
Parents:
c8cf261
git-author:
Jiri Svoboda <jiri@…> (2019-10-04 17:52:54)
git-committer:
Jiri Svoboda <jiri@…> (2019-10-05 08:45:25)
Message:

Introduce ds_display_t, ds_window_t

File:
1 edited

Legend:

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

    rc8cf261 r6af4b4f  
    3737#include <errno.h>
    3838#include <io/log.h>
     39#include <stdlib.h>
     40#include "display.h"
     41#include "window.h"
    3942
    4043static errno_t disp_window_create(void *, sysarg_t *);
     
    4851static errno_t disp_window_create(void *arg, sysarg_t *rwnd_id)
    4952{
     53        errno_t rc;
     54        ds_display_t *disp = (ds_display_t *) arg;
     55        ds_window_t *wnd;
     56
    5057        log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_create()");
    51         *rwnd_id = 42;
     58
     59        rc = ds_window_create(disp, &wnd);
     60        log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_create() - ds_window_create -> %d", rc);
     61        if (rc != EOK)
     62                return rc;
     63
     64        log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_create() -> EOK, id=%zu",
     65            wnd->id);
     66        *rwnd_id = wnd->id;
    5267        return EOK;
    5368}
     
    5570static errno_t disp_window_destroy(void *arg, sysarg_t wnd_id)
    5671{
     72        ds_display_t *disp = (ds_display_t *) arg;
     73        ds_window_t *wnd;
     74
     75        wnd = ds_display_find_window(disp, wnd_id);
     76        if (wnd == NULL)
     77                return ENOENT;
     78
    5779        log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_destroy()");
     80        ds_display_remove_window(wnd);
     81        ds_window_delete(wnd);
    5882        return EOK;
     83}
     84
     85/** Create display.
     86 *
     87 * @param rdisp Place to store pointer to new display.
     88 * @return EOK on success, ENOMEM if out of memory
     89 */
     90errno_t ds_display_create(ds_display_t **rdisp)
     91{
     92        ds_display_t *disp;
     93
     94        disp = calloc(1, sizeof(ds_display_t));
     95        if (disp == NULL)
     96                return ENOMEM;
     97
     98        list_initialize(&disp->windows);
     99        disp->next_wnd_id = 1;
     100        *rdisp = disp;
     101        return EOK;
     102}
     103
     104/** Destroy display.
     105 *
     106 * @param disp Display
     107 */
     108void ds_display_destroy(ds_display_t *disp)
     109{
     110        assert(list_empty(&disp->windows));
     111        free(disp);
     112}
     113
     114/** Add window to display.
     115 *
     116 * @param disp Display
     117 * @param wnd Window
     118 * @return EOK on success, ENOMEM if there are no free window identifiers
     119 */
     120errno_t ds_display_add_window(ds_display_t *disp, ds_window_t *wnd)
     121{
     122        assert(wnd->display == NULL);
     123        assert(!link_used(&wnd->lwindows));
     124
     125        wnd->display = disp;
     126        wnd->id = disp->next_wnd_id++;
     127        list_append(&wnd->lwindows, &disp->windows);
     128
     129        return EOK;
     130}
     131
     132/** Remove window from display.
     133 *
     134 * @param wnd Window
     135 */
     136void ds_display_remove_window(ds_window_t *wnd)
     137{
     138        list_remove(&wnd->lwindows);
     139        wnd->display = NULL;
     140}
     141
     142/** Find window by ID.
     143 *
     144 * @param disp Display
     145 * @param id Window ID
     146 */
     147ds_window_t *ds_display_find_window(ds_display_t *disp, ds_wnd_id_t id)
     148{
     149        ds_window_t *wnd;
     150
     151        // TODO Make this faster
     152        wnd = ds_display_first_window(disp);
     153        while (wnd != NULL) {
     154                if (wnd->id == id)
     155                        return wnd;
     156                wnd = ds_display_next_window(wnd);
     157        }
     158
     159        return NULL;
     160}
     161
     162/** Get first window in display.
     163 *
     164 * @param disp Display
     165 * @return First window or @c NULL if there is none
     166 */
     167ds_window_t *ds_display_first_window(ds_display_t *disp)
     168{
     169        link_t *link = list_first(&disp->windows);
     170
     171        if (link == NULL)
     172                return NULL;
     173
     174        return list_get_instance(link, ds_window_t, lwindows);
     175}
     176
     177/** Get next window in display.
     178 *
     179 * @param wnd Current window
     180 * @return Next window or @c NULL if there is none
     181 */
     182ds_window_t *ds_display_next_window(ds_window_t *wnd)
     183{
     184        link_t *link = list_next(&wnd->lwindows, &wnd->display->windows);
     185
     186        if (link == NULL)
     187                return NULL;
     188
     189        return list_get_instance(link, ds_window_t, lwindows);
    59190}
    60191
Note: See TracChangeset for help on using the changeset viewer.