source: mainline/uspace/srv/ns/ns.c@ fb86ff19

Last change on this file since fb86ff19 was 34e91bf, checked in by Matthieu Riolo <matthieu.riolo@…>, 6 years ago

Deleting taskman_noasync

Since IPC and async should be mixed, it makes no sense
to have a function which does exactly that

  • Property mode set to 100644
File size: 3.4 KB
Line 
1/*
2 * Copyright (c) 2006 Ondrej Palkovsky
3 * Copyright (c) 2015 Michal Koutny
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * - The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30/** @addtogroup ns
31 * @{
32 */
33
34/**
35 * @file ns.c
36 * @brief Naming service for HelenOS IPC.
37 */
38
39#include <abi/ipc/methods.h>
40#include <async.h>
41#include <ipc/ns.h>
42#include <ipc/services.h>
43#include <abi/ipc/interfaces.h>
44#include <stdio.h>
45#include <errno.h>
46#include <ipc/taskman.h>
47#include <taskman.h>
48#include <task.h>
49
50#include "ns.h"
51#include "service.h"
52
53static void ns_connection(ipc_call_t *icall, void *arg)
54{
55 ipc_call_t call;
56 iface_t iface;
57 service_t service;
58
59 iface = ipc_get_arg1(icall);
60 service = ipc_get_arg2(icall);
61 if (service != 0) {
62 /*
63 * Client requests to be connected to a service.
64 */
65 ns_service_forward(service, iface, icall);
66 return;
67 }
68
69 async_accept_0(icall);
70
71 while (true) {
72 ns_pending_conn_process();
73
74 async_get_call(&call);
75 if (!ipc_get_imethod(&call))
76 break;
77
78 errno_t retval;
79 service_t service;
80
81 switch (ipc_get_imethod(&call)) {
82 case NS_REGISTER:
83 service = ipc_get_arg1(&call);
84 iface = ipc_get_arg2(&call);
85
86 /*
87 * Server requests service registration.
88 */
89 retval = ns_service_register(service, iface);
90
91 break;
92 case NS_REGISTER_BROKER:
93 service = ipc_get_arg1(&call);
94 retval = ns_service_register_broker(service);
95 break;
96 case NS_PING:
97 retval = EOK;
98 break;
99 default:
100 printf("%s: Method not supported (%" PRIun ")\n",
101 NAME, ipc_get_imethod(&call));
102 retval = ENOTSUP;
103 break;
104 }
105
106 async_answer_0(&call, retval);
107 }
108
109 /* TODO: Ignore so far, in future we might unregister services */
110 //(void) ns_task_disconnect(&call);
111 async_answer_0(&call, EOK);
112}
113
114int main(int argc, char **argv)
115{
116 printf("%s: HelenOS IPC Naming Service\n", NAME);
117
118 errno_t rc = ns_service_init();
119 if (rc != EOK)
120 return rc;
121
122 rc = taskman_intro_ns();
123 if (rc != EOK) {
124 printf("%s: not accepted by taskman (%i)\n", NAME, rc);
125 return rc;
126 }
127 task_retval(0);
128
129 async_set_fallback_port_handler(ns_connection, NULL);
130
131 printf("%s: Accepting connections\n", NAME);
132
133 async_manager();
134
135 /* Not reached */
136 return 0;
137}
138
139/**
140 * @}
141 */
Note: See TracBrowser for help on using the repository browser.