source: mainline/uspace/srv/ns/ns.c@ 3b47db6

Last change on this file since 3b47db6 was 3b47db6, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 7 years ago

(optional) Remove EXIT_RC().

  • Property mode set to 100644
File size: 3.7 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>
[84a1a54]44#include <stdlib.h>
[69cdeec]45#include <errno.h>
[40313e4]46#include <macros.h>
47#include "ns.h"
48#include "service.h"
49#include "clonable.h"
50#include "task.h"
[bfd1546]51
[7b616e2]52static void ns_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg)
[69cdeec]53{
[7b616e2]54 ipc_call_t call;
55 ipc_callid_t callid;
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 if (service_clonable(service)) {
66 connect_to_clonable(service, iface, icall, iid);
67 } else {
68 connect_to_service(service, iface, icall, iid);
69 }
70 return;
71 }
[40313e4]72
[7b616e2]73 async_answer_0(iid, EOK);
74
[1fcfc94]75 while (true) {
[40313e4]76 process_pending_conn();
[1fcfc94]77
[7b616e2]78 callid = async_get_call(&call);
79 if (!IPC_GET_IMETHOD(call))
80 break;
[40313e4]81
82 task_id_t id;
[46577995]83 errno_t retval;
[1fcfc94]84
[6a8ce16]85 service_t service;
86 sysarg_t phone;
87
[228e490]88 switch (IPC_GET_IMETHOD(call)) {
[7b616e2]89 case NS_REGISTER:
90 service = IPC_GET_ARG1(call);
[6a8ce16]91 phone = IPC_GET_ARG5(call);
92
[babe786]93 /*
[043dcc27]94 * Server requests service registration.
[babe786]95 */
[6a8ce16]96 if (service_clonable(service)) {
97 register_clonable(service, phone, &call, callid);
[bfd1546]98 continue;
99 } else {
[7b616e2]100 retval = register_service(service, phone, &call);
[bfd1546]101 }
[7b616e2]102
[11eae82]103 break;
[40313e4]104 case NS_PING:
105 retval = EOK;
106 break;
107 case NS_TASK_WAIT:
108 id = (task_id_t)
109 MERGE_LOUP32(IPC_GET_ARG1(call), IPC_GET_ARG2(call));
110 wait_for_task(id, &call, callid);
111 continue;
[5d96851b]112 case NS_ID_INTRO:
113 retval = ns_task_id_intro(&call);
114 break;
[7114d83]115 case NS_RETVAL:
116 retval = ns_task_retval(&call);
117 break;
[69cdeec]118 default:
[7b616e2]119 printf("ns: method not supported\n");
120 retval = ENOTSUP;
[69cdeec]121 break;
122 }
[1fcfc94]123
[7b616e2]124 async_answer_0(callid, retval);
[69cdeec]125 }
[7b616e2]126
127 (void) ns_task_disconnect(&call);
128}
129
130int main(int argc, char **argv)
131{
132 printf("%s: HelenOS IPC Naming Service\n", NAME);
133
[46577995]134 errno_t rc = service_init();
[7b616e2]135 if (rc != EOK)
[3b47db6]136 return rc;
[7b616e2]137
138 rc = clonable_init();
139 if (rc != EOK)
[3b47db6]140 return rc;
[7b616e2]141
142 rc = task_init();
143 if (rc != EOK)
[3b47db6]144 return rc;
[7b616e2]145
146 async_set_fallback_port_handler(ns_connection, NULL);
147
148 printf("%s: Accepting connections\n", NAME);
149 async_manager();
[e623197]150
151 /* Not reached */
152 return 0;
[69cdeec]153}
[babe786]154
[1fcfc94]155/**
[ce5bcb4]156 * @}
157 */
Note: See TracBrowser for help on using the repository browser.