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
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 <abi/ipc/interfaces.h>
42#include <stdio.h>
43#include <errno.h>
44#include <macros.h>
45#include "ns.h"
46#include "service.h"
47#include "clonable.h"
48#include "task.h"
49
50int main(int argc, char **argv)
51{
52 printf("%s: HelenOS IPC Naming Service\n", NAME);
53
54 int rc = service_init();
55 if (rc != EOK)
56 return rc;
57
58 rc = clonable_init();
59 if (rc != EOK)
60 return rc;
61
62 rc = task_init();
63 if (rc != EOK)
64 return rc;
65
66 printf("%s: Accepting connections\n", NAME);
67
68 while (true) {
69 process_pending_conn();
70
71 ipc_call_t call;
72 ipc_callid_t callid = ipc_wait_for_call(&call);
73
74 task_id_t id;
75 sysarg_t retval;
76
77 iface_t iface;
78 service_t service;
79 sysarg_t phone;
80
81 switch (IPC_GET_IMETHOD(call)) {
82 case IPC_M_PHONE_HUNGUP:
83 retval = ns_task_disconnect(&call);
84 break;
85 case IPC_M_CONNECT_TO_ME:
86 service = IPC_GET_ARG2(call);
87 phone = IPC_GET_ARG5(call);
88
89 /*
90 * Server requests service registration.
91 */
92 if (service_clonable(service)) {
93 register_clonable(service, phone, &call, callid);
94 continue;
95 } else
96 retval = register_service(service, phone, &call);
97
98 break;
99 case IPC_M_CONNECT_ME_TO:
100 iface = IPC_GET_ARG1(call);
101 service = IPC_GET_ARG2(call);
102
103 /*
104 * Client requests to be connected to a service.
105 */
106 if (service_clonable(service)) {
107 connect_to_clonable(service, iface, &call, callid);
108 continue;
109 } else {
110 connect_to_service(service, iface, &call, callid);
111 continue;
112 }
113 break;
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;
122 case NS_ID_INTRO:
123 retval = ns_task_id_intro(&call);
124 break;
125 case NS_RETVAL:
126 retval = ns_task_retval(&call);
127 break;
128 default:
129 retval = ENOENT;
130 break;
131 }
132
133 if (!(callid & IPC_CALLID_NOTIFICATION))
134 ipc_answer_0(callid, retval);
135 }
136
137 /* Not reached */
138 return 0;
139}
140
141/**
142 * @}
143 */
Note: See TracBrowser for help on using the repository browser.