source: mainline/uspace/srv/ns/ns.c@ 9f64c1e

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 9f64c1e was 9cfbf2f, checked in by Martin Decky <martin@…>, 10 years ago

improve code readability
coding style

  • Property mode set to 100644
File size: 3.5 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
[38edb96]38#include <ipc/ipc.h>
[40313e4]39#include <ipc/ns.h>
[6a8ce16e]40#include <ipc/services.h>
[2133e02]41#include <abi/ipc/interfaces.h>
[40313e4]42#include <stdio.h>
[69cdeec]43#include <errno.h>
[40313e4]44#include <macros.h>
45#include "ns.h"
46#include "service.h"
47#include "clonable.h"
48#include "task.h"
[bfd1546]49
[69cdeec]50int main(int argc, char **argv)
51{
[a47f522]52 printf("%s: HelenOS IPC Naming Service\n", NAME);
[e623197]53
[40313e4]54 int rc = service_init();
55 if (rc != EOK)
56 return rc;
[1fcfc94]57
[40313e4]58 rc = clonable_init();
59 if (rc != EOK)
60 return rc;
61
62 rc = task_init();
63 if (rc != EOK)
64 return rc;
[e623197]65
[d9fae235]66 printf("%s: Accepting connections\n", NAME);
[40313e4]67
[1fcfc94]68 while (true) {
[40313e4]69 process_pending_conn();
[1fcfc94]70
71 ipc_call_t call;
72 ipc_callid_t callid = ipc_wait_for_call(&call);
[40313e4]73
74 task_id_t id;
[96b02eb9]75 sysarg_t retval;
[1fcfc94]76
[2133e02]77 iface_t iface;
[6a8ce16e]78 service_t service;
79 sysarg_t phone;
80
[228e490]81 switch (IPC_GET_IMETHOD(call)) {
[7048773]82 case IPC_M_PHONE_HUNGUP:
[5d96851b]83 retval = ns_task_disconnect(&call);
[7048773]84 break;
[043dcc27]85 case IPC_M_CONNECT_TO_ME:
[2133e02]86 service = IPC_GET_ARG2(call);
[6a8ce16e]87 phone = IPC_GET_ARG5(call);
88
[babe786]89 /*
[043dcc27]90 * Server requests service registration.
[babe786]91 */
[6a8ce16e]92 if (service_clonable(service)) {
93 register_clonable(service, phone, &call, callid);
[bfd1546]94 continue;
[6a8ce16e]95 } else
96 retval = register_service(service, phone, &call);
97
[69cdeec]98 break;
[7048773]99 case IPC_M_CONNECT_ME_TO:
[2133e02]100 iface = IPC_GET_ARG1(call);
101 service = IPC_GET_ARG2(call);
102
[043dcc27]103 /*
104 * Client requests to be connected to a service.
105 */
[6a8ce16e]106 if (service_clonable(service)) {
[9cfbf2f]107 connect_to_clonable(service, iface, &call, callid);
[bfd1546]108 continue;
109 } else {
[9cfbf2f]110 connect_to_service(service, iface, &call, callid);
[1fcfc94]111 continue;
[bfd1546]112 }
[11eae82]113 break;
[40313e4]114 case NS_PING:
115 retval = EOK;
116 break;
117 case NS_TASK_WAIT:
118 id = (task_id_t)
119 MERGE_LOUP32(IPC_GET_ARG1(call), IPC_GET_ARG2(call));
120 wait_for_task(id, &call, callid);
121 continue;
[5d96851b]122 case NS_ID_INTRO:
123 retval = ns_task_id_intro(&call);
124 break;
[7114d83]125 case NS_RETVAL:
126 retval = ns_task_retval(&call);
127 break;
[69cdeec]128 default:
129 retval = ENOENT;
130 break;
131 }
[1fcfc94]132
133 if (!(callid & IPC_CALLID_NOTIFICATION))
[b74959bd]134 ipc_answer_0(callid, retval);
[69cdeec]135 }
[e623197]136
137 /* Not reached */
138 return 0;
[69cdeec]139}
[babe786]140
[1fcfc94]141/**
[ce5bcb4]142 * @}
143 */
Note: See TracBrowser for help on using the repository browser.