source: mainline/uspace/lib/c/generic/ipc_test.c@ 1edd6d0

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

Add separate IPC test service. Keep ns_ping for now for the sake of comparison.

  • Property mode set to 100644
File size: 2.9 KB
Line 
1/*
2 * Copyright (c) 2018 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/** @addtogroup libc
30 * @{
31 */
32/** @file IPC test service API
33 */
34
35#include <abi/ipc/interfaces.h>
36#include <errno.h>
37#include <ipc/services.h>
38#include <ipc/ipc_test.h>
39#include <loc.h>
40#include <stdlib.h>
41#include <ipc_test.h>
42
43/** Create IPC test service session.
44 *
45 * @param rvol Place to store pointer to volume service session.
46 * @return EOK on success, ENOMEM if out of memory, EIO if service
47 * cannot be contacted.
48 */
49errno_t ipc_test_create(ipc_test_t **rtest)
50{
51 ipc_test_t *test;
52 service_id_t test_svcid;
53 errno_t rc;
54
55 test = calloc(1, sizeof(ipc_test_t));
56 if (test == NULL) {
57 rc = ENOMEM;
58 goto error;
59 }
60
61 rc = loc_service_get_id(SERVICE_NAME_IPC_TEST, &test_svcid, 0);
62 if (rc != EOK) {
63 rc = ENOENT;
64 goto error;
65 }
66
67 test->sess = loc_service_connect(test_svcid, INTERFACE_IPC_TEST, 0);
68 if (test->sess == NULL) {
69 rc = EIO;
70 goto error;
71 }
72
73 *rtest = test;
74 return EOK;
75error:
76 free(test);
77 return rc;
78}
79
80/** Destroy IPC test service session.
81 *
82 * @param test IPC test service session
83 */
84void ipc_test_destroy(ipc_test_t *test)
85{
86 if (test == NULL)
87 return;
88
89 async_hangup(test->sess);
90 free(test);
91}
92
93/** Simple ping.
94 *
95 * @param test IPC test service
96 * @return EOK on success or an error code
97 */
98errno_t ipc_test_ping(ipc_test_t *test)
99{
100 async_exch_t *exch;
101 errno_t retval;
102
103 exch = async_exchange_begin(test->sess);
104 retval = async_req_0_0(exch, IPC_TEST_PING);
105 async_exchange_end(exch);
106
107 if (retval != EOK)
108 return retval;
109
110 return EOK;
111}
112
113/** @}
114 */
Note: See TracBrowser for help on using the repository browser.