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