source: mainline/uspace/srv/ns/ns.c@ 84dc30c

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

rename services_t to service_t for consistency
cleanup the naming service code

  • Property mode set to 100644
File size: 3.4 KB
Line 
1/*
2 * Copyright (c) 2006 Ondrej Palkovsky
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
29/** @addtogroup ns
30 * @{
31 */
32
33/**
34 * @file ns.c
35 * @brief Naming service for HelenOS IPC.
36 */
37
38#include <ipc/ipc.h>
39#include <ipc/ns.h>
40#include <ipc/services.h>
41#include <stdio.h>
42#include <errno.h>
43#include <macros.h>
44#include "ns.h"
45#include "service.h"
46#include "clonable.h"
47#include "task.h"
48
49int main(int argc, char **argv)
50{
51 printf("%s: HelenOS IPC Naming Service\n", NAME);
52
53 int rc = service_init();
54 if (rc != EOK)
55 return rc;
56
57 rc = clonable_init();
58 if (rc != EOK)
59 return rc;
60
61 rc = task_init();
62 if (rc != EOK)
63 return rc;
64
65 printf("%s: Accepting connections\n", NAME);
66
67 while (true) {
68 process_pending_conn();
69
70 ipc_call_t call;
71 ipc_callid_t callid = ipc_wait_for_call(&call);
72
73 task_id_t id;
74 sysarg_t retval;
75
76 service_t service;
77 sysarg_t phone;
78
79 switch (IPC_GET_IMETHOD(call)) {
80 case IPC_M_PHONE_HUNGUP:
81 retval = ns_task_disconnect(&call);
82 break;
83 case IPC_M_CONNECT_TO_ME:
84 service = IPC_GET_ARG1(call);
85 phone = IPC_GET_ARG5(call);
86
87 /*
88 * Server requests service registration.
89 */
90 if (service_clonable(service)) {
91 register_clonable(service, phone, &call, callid);
92 continue;
93 } else
94 retval = register_service(service, phone, &call);
95
96 break;
97 case IPC_M_CONNECT_ME_TO:
98 service = IPC_GET_ARG1(call);
99
100 /*
101 * Client requests to be connected to a service.
102 */
103 if (service_clonable(service)) {
104 connect_to_clonable(service, &call, callid);
105 continue;
106 } else {
107 connect_to_service(service, &call, callid);
108 continue;
109 }
110 break;
111 case NS_PING:
112 retval = EOK;
113 break;
114 case NS_TASK_WAIT:
115 id = (task_id_t)
116 MERGE_LOUP32(IPC_GET_ARG1(call), IPC_GET_ARG2(call));
117 wait_for_task(id, &call, callid);
118 continue;
119 case NS_ID_INTRO:
120 retval = ns_task_id_intro(&call);
121 break;
122 case NS_RETVAL:
123 retval = ns_task_retval(&call);
124 break;
125 default:
126 retval = ENOENT;
127 break;
128 }
129
130 if (!(callid & IPC_CALLID_NOTIFICATION))
131 ipc_answer_0(callid, retval);
132 }
133
134 /* Not reached */
135 return 0;
136}
137
138/**
139 * @}
140 */
Note: See TracBrowser for help on using the repository browser.