source: mainline/uspace/srv/ns/ns.c@ 87a31ef2

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

ns: Created simplified taskman API using low-level IPC API only

Conflicts:

uspace/lib/c/generic/async.c
uspace/lib/c/generic/private/async.h
uspace/lib/c/include/task.h
uspace/srv/ns/ns.c

  • Property mode set to 100644
File size: 3.4 KB
RevLine 
[babe786]1/*
[df4ed85]2 * Copyright (c) 2006 Ondrej Palkovsky
[012dd8e]3 * Copyright (c) 2015 Michal Koutny
[babe786]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
[231a60a]30/** @addtogroup ns
[ce5bcb4]31 * @{
[1fcfc94]32 */
[ce5bcb4]33
[babe786]34/**
[1fcfc94]35 * @file ns.c
36 * @brief Naming service for HelenOS IPC.
[babe786]37 */
38
[7b616e2]39#include <abi/ipc/methods.h>
40#include <async.h>
[40313e4]41#include <ipc/ns.h>
[6a8ce16e]42#include <ipc/services.h>
[2133e02]43#include <abi/ipc/interfaces.h>
[40313e4]44#include <stdio.h>
[69cdeec]45#include <errno.h>
[87a31ef2]46#include <ipc/taskman.h>
47#include <taskman_noasync.h>
[012dd8e]48
[40313e4]49#include "ns.h"
50#include "service.h"
[bfd1546]51
[984a9ba]52static void ns_connection(ipc_call_t *icall, void *arg)
[69cdeec]53{
[7b616e2]54 ipc_call_t call;
55 iface_t iface;
56 service_t service;
57
[fafb8e5]58 iface = ipc_get_arg1(icall);
59 service = ipc_get_arg2(icall);
[7b616e2]60 if (service != 0) {
61 /*
62 * Client requests to be connected to a service.
63 */
[0a8f070]64 ns_service_forward(service, iface, icall);
[7b616e2]65 return;
66 }
[a35b458]67
[beb83c1]68 async_accept_0(icall);
[7b616e2]69
[1fcfc94]70 while (true) {
[9b1baac]71 ns_pending_conn_process();
[a35b458]72
[984a9ba]73 async_get_call(&call);
[fafb8e5]74 if (!ipc_get_imethod(&call))
[7b616e2]75 break;
[a35b458]76
[40313e4]77 task_id_t id;
[b7fd2a0]78 errno_t retval;
[a35b458]79
[6a8ce16e]80 service_t service;
[a35b458]81
[fafb8e5]82 switch (ipc_get_imethod(&call)) {
[7b616e2]83 case NS_REGISTER:
[fafb8e5]84 service = ipc_get_arg1(&call);
85 iface = ipc_get_arg2(&call);
[a35b458]86
[babe786]87 /*
[043dcc27]88 * Server requests service registration.
[babe786]89 */
[0a8f070]90 retval = ns_service_register(service, iface);
[a35b458]91
[9b1baac]92 break;
93 case NS_REGISTER_BROKER:
[fafb8e5]94 service = ipc_get_arg1(&call);
[9b1baac]95 retval = ns_service_register_broker(service);
[11eae82]96 break;
[40313e4]97 case NS_PING:
98 retval = EOK;
99 break;
[69cdeec]100 default:
[9b1baac]101 printf("%s: Method not supported (%" PRIun ")\n",
[fafb8e5]102 NAME, ipc_get_imethod(&call));
[7b616e2]103 retval = ENOTSUP;
[69cdeec]104 break;
105 }
[a35b458]106
[984a9ba]107 async_answer_0(&call, retval);
[69cdeec]108 }
[7b616e2]109
110 (void) ns_task_disconnect(&call);
[889cdb1]111 async_answer_0(&call, EOK);
[7b616e2]112}
113
114int main(int argc, char **argv)
115{
116 printf("%s: HelenOS IPC Naming Service\n", NAME);
[a35b458]117
[9b1baac]118 errno_t rc = ns_service_init();
[7b616e2]119 if (rc != EOK)
120 return rc;
[012dd8e]121
[87a31ef2]122 rc = taskman_intro_ns_noasync();
[012dd8e]123 if (rc != EOK) {
124 printf("%s: not accepted by taskman (%i)\n", NAME, rc);
125 return rc;
126 }
[87a31ef2]127 task_retval_noasync(0);
128
[7b616e2]129 async_set_fallback_port_handler(ns_connection, NULL);
[a35b458]130
[7b616e2]131 printf("%s: Accepting connections\n", NAME);
[87a31ef2]132
[7b616e2]133 async_manager();
[a35b458]134
[e623197]135 /* Not reached */
136 return 0;
[69cdeec]137}
[babe786]138
[1fcfc94]139/**
[ce5bcb4]140 * @}
141 */
Note: See TracBrowser for help on using the repository browser.