source: mainline/uspace/srv/ns/ns.c@ 889cdb1

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 889cdb1 was 889cdb1, checked in by Jakub Jermar <jakub@…>, 7 years ago

Always answer the IPC_M_PHONE_HUNGUP message

  • Property mode set to 100644
File size: 3.8 KB
RevLine 
[babe786]1/*
[df4ed85]2 * Copyright (c) 2006 Ondrej Palkovsky
[babe786]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
[231a60a]29/** @addtogroup ns
[ce5bcb4]30 * @{
[1fcfc94]31 */
[ce5bcb4]32
[babe786]33/**
[1fcfc94]34 * @file ns.c
35 * @brief Naming service for HelenOS IPC.
[babe786]36 */
37
[7b616e2]38#include <abi/ipc/methods.h>
39#include <async.h>
[40313e4]40#include <ipc/ns.h>
[6a8ce16]41#include <ipc/services.h>
[2133e02]42#include <abi/ipc/interfaces.h>
[40313e4]43#include <stdio.h>
[69cdeec]44#include <errno.h>
[40313e4]45#include <macros.h>
46#include "ns.h"
47#include "service.h"
48#include "clonable.h"
49#include "task.h"
[bfd1546]50
[984a9ba]51static void ns_connection(ipc_call_t *icall, void *arg)
[69cdeec]52{
[7b616e2]53 ipc_call_t call;
54 iface_t iface;
55 service_t service;
56
57 iface = IPC_GET_ARG1(*icall);
58 service = IPC_GET_ARG2(*icall);
59 if (service != 0) {
60 /*
61 * Client requests to be connected to a service.
62 */
[9b1baac]63 if (ns_service_is_clonable(service, iface)) {
64 ns_clonable_forward(service, iface, icall);
[7b616e2]65 } else {
[9b1baac]66 ns_service_forward(service, iface, icall);
[7b616e2]67 }
[9b1baac]68
[7b616e2]69 return;
70 }
[a35b458]71
[984a9ba]72 async_answer_0(icall, EOK);
[7b616e2]73
[1fcfc94]74 while (true) {
[9b1baac]75 ns_pending_conn_process();
[a35b458]76
[984a9ba]77 async_get_call(&call);
[7b616e2]78 if (!IPC_GET_IMETHOD(call))
79 break;
[a35b458]80
[40313e4]81 task_id_t id;
[b7fd2a0]82 errno_t retval;
[a35b458]83
[6a8ce16]84 service_t service;
[a35b458]85
[228e490]86 switch (IPC_GET_IMETHOD(call)) {
[7b616e2]87 case NS_REGISTER:
88 service = IPC_GET_ARG1(call);
[9b1baac]89 iface = IPC_GET_ARG2(call);
[a35b458]90
[babe786]91 /*
[043dcc27]92 * Server requests service registration.
[babe786]93 */
[9b1baac]94 if (ns_service_is_clonable(service, iface)) {
95 ns_clonable_register(&call);
[bfd1546]96 continue;
97 } else {
[9b1baac]98 retval = ns_service_register(service, iface);
[bfd1546]99 }
[a35b458]100
[9b1baac]101 break;
102 case NS_REGISTER_BROKER:
103 service = IPC_GET_ARG1(call);
104 retval = ns_service_register_broker(service);
[11eae82]105 break;
[40313e4]106 case NS_PING:
107 retval = EOK;
108 break;
109 case NS_TASK_WAIT:
110 id = (task_id_t)
111 MERGE_LOUP32(IPC_GET_ARG1(call), IPC_GET_ARG2(call));
[984a9ba]112 wait_for_task(id, &call);
[40313e4]113 continue;
[5d96851b]114 case NS_ID_INTRO:
115 retval = ns_task_id_intro(&call);
116 break;
[7114d83]117 case NS_RETVAL:
118 retval = ns_task_retval(&call);
119 break;
[69cdeec]120 default:
[9b1baac]121 printf("%s: Method not supported (%" PRIun ")\n",
122 NAME, IPC_GET_IMETHOD(call));
[7b616e2]123 retval = ENOTSUP;
[69cdeec]124 break;
125 }
[a35b458]126
[984a9ba]127 async_answer_0(&call, retval);
[69cdeec]128 }
[7b616e2]129
130 (void) ns_task_disconnect(&call);
[889cdb1]131 async_answer_0(&call, EOK);
[7b616e2]132}
133
134int main(int argc, char **argv)
135{
136 printf("%s: HelenOS IPC Naming Service\n", NAME);
[a35b458]137
[9b1baac]138 errno_t rc = ns_service_init();
[7b616e2]139 if (rc != EOK)
140 return rc;
[a35b458]141
[9b1baac]142 rc = ns_clonable_init();
[7b616e2]143 if (rc != EOK)
144 return rc;
[a35b458]145
[7b616e2]146 rc = task_init();
147 if (rc != EOK)
148 return rc;
[a35b458]149
[7b616e2]150 async_set_fallback_port_handler(ns_connection, NULL);
[a35b458]151
[7b616e2]152 printf("%s: Accepting connections\n", NAME);
153 async_manager();
[a35b458]154
[e623197]155 /* Not reached */
156 return 0;
[69cdeec]157}
[babe786]158
[1fcfc94]159/**
[ce5bcb4]160 * @}
161 */
Note: See TracBrowser for help on using the repository browser.