source: mainline/uspace/srv/ns/ns.c@ 76f566d

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

Prefer handle over ID in naming handle variables

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