source: mainline/uspace/lib/ddev/src/ddev.c@ 65ec18d

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

Resolve merge conflicts

  • Property mode set to 100644
File size: 3.7 KB
Line 
1/*
2 * Copyright (c) 2019 Jiri Svoboda
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#include <async.h>
30#include <ddev.h>
31#include <errno.h>
32#include <ipc/ddev.h>
33#include <ipc/services.h>
34#include <ipcgfx/client.h>
35#include <loc.h>
36#include <stdlib.h>
37
38/** Open display device.
39 *
40 * @param ddname Display device service name
41 * @param rdisplay Place to store pointer to display session
42 * @return EOK on success or an error code
43 */
44errno_t ddev_open(const char *ddname, ddev_t **rddev)
45{
46 service_id_t ddev_svc;
47 ddev_t *ddev;
48 errno_t rc;
49
50 ddev = calloc(1, sizeof(ddev_t));
51 if (ddev == NULL)
52 return ENOMEM;
53
54 rc = loc_service_get_id(ddname, &ddev_svc, IPC_FLAG_BLOCKING);
55 if (rc != EOK) {
56 free(ddev);
57 return ENOENT;
58 }
59
60 ddev->sess = loc_service_connect(ddev_svc, INTERFACE_DDEV,
61 IPC_FLAG_BLOCKING);
62 if (ddev->sess == NULL) {
63 free(ddev);
64 return ENOENT;
65 }
66
67 *rddev = ddev;
68 return EOK;
69}
70
71/** Close display device.
72 *
73 * @param ddev Display device session
74 */
75void ddev_close(ddev_t *ddev)
76{
77 async_hangup(ddev->sess);
78 free(ddev);
79}
80
81/** Create graphics context for drawing to display device.
82 *
83 * @param ddev Display device
84 * @param rgc Place to store pointer to new graphics context
85 */
86errno_t ddev_get_gc(ddev_t *ddev, gfx_context_t **rgc)
87{
88 async_sess_t *sess;
89 async_exch_t *exch;
90 sysarg_t arg2;
91 sysarg_t arg3;
92 ipc_gc_t *gc;
93 errno_t rc;
94
95 exch = async_exchange_begin(ddev->sess);
96 rc = async_req_0_2(exch, DDEV_GET_GC, &arg2, &arg3);
97 if (rc != EOK) {
98 async_exchange_end(exch);
99 return rc;
100 }
101
102 sess = async_connect_me_to(exch, INTERFACE_GC, arg2, arg3, &rc);
103 async_exchange_end(exch);
104
105 if (sess == NULL)
106 return rc;
107
108 rc = ipc_gc_create(sess, &gc);
109 if (rc != EOK) {
110 async_hangup(sess);
111 return ENOMEM;
112 }
113
114 *rgc = ipc_gc_get_ctx(gc);
115 return EOK;
116}
117
118/** Get display device information.
119 *
120 * @param ddev Display device
121 * @param info Place to store information
122 */
123errno_t ddev_get_info(ddev_t *ddev, ddev_info_t *info)
124{
125 async_exch_t *exch;
126 errno_t retval;
127 ipc_call_t answer;
128
129 exch = async_exchange_begin(ddev->sess);
130 aid_t req = async_send_0(exch, DDEV_GET_INFO, &answer);
131
132 errno_t rc = async_data_read_start(exch, info, sizeof(ddev_info_t));
133 async_exchange_end(exch);
134 if (rc != EOK) {
135 async_forget(req);
136 return rc;
137 }
138
139 async_wait_for(req, &retval);
140 if (retval != EOK)
141 return rc;
142
143 return EOK;
144}
145
146/** @}
147 */
Note: See TracBrowser for help on using the repository browser.