source: mainline/uspace/srv/ns/ns.c@ 241f1985

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

Correcting failure from previous merge

The commits from Michal Koutný from the branch system-daemon
where built on a old version of Helenos. Because of this
many types and API functions have changed. This commit
upgrades the merge code

  • Property mode set to 100644
File size: 3.5 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_noasync.h>
48
49#include "ns.h"
50#include "service.h"
51
52static void ns_connection(ipc_call_t *icall, void *arg)
53{
54 ipc_call_t call;
55 iface_t iface;
56 service_t service;
57
58 iface = ipc_get_arg1(icall);
59 service = ipc_get_arg2(icall);
60 if (service != 0) {
61 /*
62 * Client requests to be connected to a service.
63 */
64 ns_service_forward(service, iface, icall);
65 return;
66 }
67
68 async_accept_0(icall);
69
70 while (true) {
71 ns_pending_conn_process();
72
73 async_get_call(&call);
74 if (!ipc_get_imethod(&call))
75 break;
76
77 errno_t retval;
78 service_t service;
79
80 switch (ipc_get_imethod(&call)) {
81 case NS_REGISTER:
82 service = ipc_get_arg1(&call);
83 iface = ipc_get_arg2(&call);
84
85 /*
86 * Server requests service registration.
87 */
88 retval = ns_service_register(service, iface);
89
90 break;
91 case NS_REGISTER_BROKER:
92 service = ipc_get_arg1(&call);
93 retval = ns_service_register_broker(service);
94 break;
95 case NS_PING:
96 retval = EOK;
97 break;
98 default:
99 printf("%s: Method not supported (%" PRIun ")\n",
100 NAME, ipc_get_imethod(&call));
101 retval = ENOTSUP;
102 break;
103 }
104
105 async_answer_0(&call, retval);
106 }
107
108 /* TODO: Ignore so far, in future we might unregister services */
109 //(void) ns_task_disconnect(&call);
110 async_answer_0(&call, EOK);
111}
112
113int main(int argc, char **argv)
114{
115 printf("%s: HelenOS IPC Naming Service\n", NAME);
116
117 errno_t rc = ns_service_init();
118 if (rc != EOK)
119 return rc;
120
121 rc = taskman_intro_ns_noasync();
122 if (rc != EOK) {
123 printf("%s: not accepted by taskman (%i)\n", NAME, rc);
124 return rc;
125 }
126 task_retval_noasync(0);
127
128 async_set_fallback_port_handler(ns_connection, NULL);
129
130 printf("%s: Accepting connections\n", NAME);
131
132 async_manager();
133
134 /* Not reached */
135 return 0;
136}
137
138/**
139 * @}
140 */
Note: See TracBrowser for help on using the repository browser.